Class ResourceGroupService

java.lang.Object
org.apache.pulsar.broker.resourcegroup.ResourceGroupService
All Implemented Interfaces:
AutoCloseable

public class ResourceGroupService extends Object implements AutoCloseable
The ResourceGroupService contains APIs to manipulate resource groups. It is assumed that there is a single instance of the ResourceGroupService on each broker. The control plane operations are somewhat stringent, and throw exceptions if (for instance) the op refers to a resource group which does not exist. The data plane operations (e.g., increment stats) throw exceptions as a last resort; if (e.g.) increment stats refers to a non-existent resource group, the stats are quietly not incremented.
See Also:
  • Field Details

    • quotaCalculator

      protected final ResourceQuotaCalculator quotaCalculator
    • MaxUsageReportSuppressRounds

      protected static final int MaxUsageReportSuppressRounds
      See Also:
    • maxIntervalForSuppressingReportsMSecs

      protected static long maxIntervalForSuppressingReportsMSecs
    • UsageReportSuppressionTolerancePercentage

      protected static final float UsageReportSuppressionTolerancePercentage
      See Also:
  • Constructor Details

  • Method Details

    • resourceGroupCreate

      public void resourceGroupCreate(String rgName, org.apache.pulsar.common.policies.data.ResourceGroup rgConfig) throws org.apache.pulsar.client.admin.PulsarAdminException
      Create RG.
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • resourceGroupCreate

      public void resourceGroupCreate(String rgName, org.apache.pulsar.common.policies.data.ResourceGroup rgConfig, ResourceUsagePublisher rgPublisher, ResourceUsageConsumer rgConsumer) throws org.apache.pulsar.client.admin.PulsarAdminException
      Create RG, with non-default functions for resource-usage transport-manager.
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • resourceGroupGet

      public ResourceGroup resourceGroupGet(String resourceGroupName)
      Get a copy of the RG with the given name.
    • resourceGroupUpdate

      public void resourceGroupUpdate(String rgName, org.apache.pulsar.common.policies.data.ResourceGroup rgConfig) throws org.apache.pulsar.client.admin.PulsarAdminException
      Update RG.
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • resourceGroupGetAll

      public Set<String> resourceGroupGetAll()
    • resourceGroupDelete

      public void resourceGroupDelete(String name) throws org.apache.pulsar.client.admin.PulsarAdminException
      Delete RG.
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • getNumResourceGroups

      protected long getNumResourceGroups()
      Get the current number of RGs. For testing.
    • registerTenant

      public void registerTenant(String resourceGroupName, String tenantName) throws org.apache.pulsar.client.admin.PulsarAdminException
      Registers a tenant as a user of a resource group.
      Parameters:
      resourceGroupName -
      tenantName -
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • unRegisterTenant

      public void unRegisterTenant(String resourceGroupName, String tenantName) throws org.apache.pulsar.client.admin.PulsarAdminException
      UnRegisters a tenant from a resource group.
      Parameters:
      resourceGroupName -
      tenantName -
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • registerNameSpace

      public void registerNameSpace(String resourceGroupName, org.apache.pulsar.common.naming.NamespaceName fqNamespaceName) throws org.apache.pulsar.client.admin.PulsarAdminException
      Registers a namespace as a user of a resource group.
      Parameters:
      resourceGroupName -
      fqNamespaceName - (i.e., in "tenant/Namespace" format)
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • unRegisterNameSpace

      public void unRegisterNameSpace(String resourceGroupName, org.apache.pulsar.common.naming.NamespaceName fqNamespaceName) throws org.apache.pulsar.client.admin.PulsarAdminException
      UnRegisters a namespace from a resource group.
      Parameters:
      resourceGroupName -
      fqNamespaceName - i.e., in "tenant/Namespace" format)
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • getNamespaceResourceGroup

      public ResourceGroup getNamespaceResourceGroup(org.apache.pulsar.common.naming.NamespaceName namespaceName)
      Return the resource group associated with a namespace.
      Parameters:
      namespaceName -
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • incrementUsage

      protected boolean incrementUsage(String tenantName, String nsName, ResourceGroup.ResourceGroupMonitoringClass monClass, ResourceGroup.BytesAndMessagesCount incStats) throws org.apache.pulsar.client.admin.PulsarAdminException
      Increments usage stats for the resource groups associated with the given namespace and tenant. Expected to be called when a message is produced or consumed on a topic, or when we calculate usage periodically in the background by going through broker-service stats. [Not yet decided which model we will follow.] Broker-service stats will be cumulative, while calls from the topic produce/consume code will be per-produce/consume. If the tenant and NS are associated with different RGs, the statistics on both RGs are updated. If the tenant and NS are associated with the same RG, the stats on the RG are updated only once (to avoid a direct double-counting). ToDo: will this distinction result in "expected semantics", or shock from users? For now, the only caller is internal to this class.
      Parameters:
      tenantName -
      nsName -
      monClass -
      incStats -
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • getRGUsage

      protected ResourceGroup.BytesAndMessagesCount getRGUsage(String rgName, ResourceGroup.ResourceGroupMonitoringClass monClass, ResourceGroupService.ResourceGroupUsageStatsType statsType) throws org.apache.pulsar.client.admin.PulsarAdminException
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • getPublishRateLimiters

      protected ResourceGroup.BytesAndMessagesCount getPublishRateLimiters(String rgName) throws org.apache.pulsar.client.admin.PulsarAdminException
      Throws:
      org.apache.pulsar.client.admin.PulsarAdminException
    • getRgQuotaByteCount

      protected static double getRgQuotaByteCount(String rgName, String monClassName)
    • getRgQuotaMessageCount

      protected static double getRgQuotaMessageCount(String rgName, String monClassName)
    • getRgLocalUsageByteCount

      protected static double getRgLocalUsageByteCount(String rgName, String monClassName)
    • getRgLocalUsageMessageCount

      protected static double getRgLocalUsageMessageCount(String rgName, String monClassName)
    • getRgUpdatesCount

      protected static double getRgUpdatesCount(String rgName)
    • getRgTenantRegistersCount

      protected static double getRgTenantRegistersCount(String rgName)
    • getRgTenantUnRegistersCount

      protected static double getRgTenantUnRegistersCount(String rgName)
    • getRgNamespaceRegistersCount

      protected static double getRgNamespaceRegistersCount(String rgName)
    • getRgNamespaceUnRegistersCount

      protected static double getRgNamespaceUnRegistersCount(String rgName)
    • getRgUsageAggregationLatency

      protected static io.prometheus.client.Summary.Child.Value getRgUsageAggregationLatency()
    • getRgQuotaCalculationTime

      protected static io.prometheus.client.Summary.Child.Value getRgQuotaCalculationTime()
    • aggregateResourceGroupLocalUsages

      protected void aggregateResourceGroupLocalUsages()
    • calculateQuotaForAllResourceGroups

      protected void calculateQuotaForAllResourceGroups()