Class ResourceGroupService

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class ResourceGroupService
    extends java.lang.Object
    implements java.lang.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:
    PulsarService
    • Field Detail

      • MaxUsageReportSuppressRounds

        protected static final int MaxUsageReportSuppressRounds
        See Also:
        Constant Field Values
      • maxIntervalForSuppressingReportsMSecs

        protected static long maxIntervalForSuppressingReportsMSecs
      • UsageReportSuppressionTolerancePercentage

        protected static final float UsageReportSuppressionTolerancePercentage
        See Also:
        Constant Field Values
    • Method Detail

      • resourceGroupCreate

        public void resourceGroupCreate​(java.lang.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​(java.lang.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​(java.lang.String resourceGroupName)
        Get a copy of the RG with the given name.
      • resourceGroupUpdate

        public void resourceGroupUpdate​(java.lang.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 java.util.Set<java.lang.String> resourceGroupGetAll()
      • resourceGroupDelete

        public void resourceGroupDelete​(java.lang.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​(java.lang.String resourceGroupName,
                                   java.lang.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​(java.lang.String resourceGroupName,
                                     java.lang.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​(java.lang.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​(java.lang.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 java.lang.Exception
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.Exception
      • incrementUsage

        protected boolean incrementUsage​(java.lang.String tenantName,
                                         java.lang.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
      • getPublishRateLimiters

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

        protected static double getRgQuotaByteCount​(java.lang.String rgName,
                                                    java.lang.String monClassName)
      • getRgQuotaMessageCount

        protected static double getRgQuotaMessageCount​(java.lang.String rgName,
                                                       java.lang.String monClassName)
      • getRgLocalUsageByteCount

        protected static double getRgLocalUsageByteCount​(java.lang.String rgName,
                                                         java.lang.String monClassName)
      • getRgLocalUsageMessageCount

        protected static double getRgLocalUsageMessageCount​(java.lang.String rgName,
                                                            java.lang.String monClassName)
      • getRgUpdatesCount

        protected static double getRgUpdatesCount​(java.lang.String rgName)
      • getRgTenantRegistersCount

        protected static double getRgTenantRegistersCount​(java.lang.String rgName)
      • getRgTenantUnRegistersCount

        protected static double getRgTenantUnRegistersCount​(java.lang.String rgName)
      • getRgNamespaceRegistersCount

        protected static double getRgNamespaceRegistersCount​(java.lang.String rgName)
      • getRgNamespaceUnRegistersCount

        protected static double getRgNamespaceUnRegistersCount​(java.lang.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()