Class ResourceGroupService
java.lang.Object
org.apache.pulsar.broker.resourcegroup.ResourceGroupService
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumprotected static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static longprotected static final intprotected final ResourceQuotaCalculatorprotected static final float -
Constructor Summary
ConstructorsConstructorDescriptionResourceGroupService(PulsarService pulsar) Default constructor.ResourceGroupService(PulsarService pulsar, TimeUnit timescale, ResourceUsageTopicTransportManager transportMgr, ResourceQuotaCalculator quotaCalc) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidvoidclose()getNamespaceResourceGroup(org.apache.pulsar.common.naming.NamespaceName namespaceName) Return the resource group associated with a namespace.protected longGet the current number of RGs.protected ResourceGroup.BytesAndMessagesCountgetPublishRateLimiters(String rgName) protected static doublegetRgLocalUsageByteCount(String rgName, String monClassName) protected static doublegetRgLocalUsageMessageCount(String rgName, String monClassName) protected static doublegetRgNamespaceRegistersCount(String rgName) protected static doublegetRgNamespaceUnRegistersCount(String rgName) protected static doublegetRgQuotaByteCount(String rgName, String monClassName) protected static io.prometheus.client.Summary.Child.Valueprotected static doublegetRgQuotaMessageCount(String rgName, String monClassName) protected static doublegetRgTenantRegistersCount(String rgName) protected static doublegetRgTenantUnRegistersCount(String rgName) protected static doublegetRgUpdatesCount(String rgName) protected ResourceGroup.BytesAndMessagesCountgetRGUsage(String rgName, ResourceGroup.ResourceGroupMonitoringClass monClass, ResourceGroupService.ResourceGroupUsageStatsType statsType) protected static io.prometheus.client.Summary.Child.Valueprotected booleanincrementUsage(String tenantName, String nsName, ResourceGroup.ResourceGroupMonitoringClass monClass, ResourceGroup.BytesAndMessagesCount incStats) Increments usage stats for the resource groups associated with the given namespace and tenant.voidregisterNameSpace(String resourceGroupName, org.apache.pulsar.common.naming.NamespaceName fqNamespaceName) Registers a namespace as a user of a resource group.voidregisterTenant(String resourceGroupName, String tenantName) Registers a tenant as a user of a resource group.voidresourceGroupCreate(String rgName, org.apache.pulsar.common.policies.data.ResourceGroup rgConfig) Create RG.voidresourceGroupCreate(String rgName, org.apache.pulsar.common.policies.data.ResourceGroup rgConfig, ResourceUsagePublisher rgPublisher, ResourceUsageConsumer rgConsumer) Create RG, with non-default functions for resource-usage transport-manager.voidresourceGroupDelete(String name) Delete RG.resourceGroupGet(String resourceGroupName) Get a copy of the RG with the given name.voidresourceGroupUpdate(String rgName, org.apache.pulsar.common.policies.data.ResourceGroup rgConfig) Update RG.voidunRegisterNameSpace(String resourceGroupName, org.apache.pulsar.common.naming.NamespaceName fqNamespaceName) UnRegisters a namespace from a resource group.voidunRegisterTenant(String resourceGroupName, String tenantName) UnRegisters a tenant from a resource group.
-
Field Details
-
quotaCalculator
-
MaxUsageReportSuppressRounds
protected static final int MaxUsageReportSuppressRounds- See Also:
-
maxIntervalForSuppressingReportsMSecs
protected static long maxIntervalForSuppressingReportsMSecs -
UsageReportSuppressionTolerancePercentage
protected static final float UsageReportSuppressionTolerancePercentage- See Also:
-
-
Constructor Details
-
ResourceGroupService
Default constructor. -
ResourceGroupService
public ResourceGroupService(PulsarService pulsar, TimeUnit timescale, ResourceUsageTopicTransportManager transportMgr, ResourceQuotaCalculator quotaCalc)
-
-
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
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
-
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
- Specified by:
closein interfaceAutoCloseable- 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
-
getRgQuotaMessageCount
-
getRgLocalUsageByteCount
-
getRgLocalUsageMessageCount
-
getRgUpdatesCount
-
getRgTenantRegistersCount
-
getRgTenantUnRegistersCount
-
getRgNamespaceRegistersCount
-
getRgNamespaceUnRegistersCount
-
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()
-