Class ResourceGroupService
- java.lang.Object
-
- org.apache.pulsar.broker.resourcegroup.ResourceGroupService
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class ResourceGroupService extends java.lang.Object implements java.lang.AutoCloseableTheResourceGroupServicecontains 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classResourceGroupService.ResourceGroupOpStatusprotected static classResourceGroupService.ResourceGroupUsageStatsType
-
Field Summary
Fields Modifier and Type Field Description protected static longmaxIntervalForSuppressingReportsMSecsprotected static intMaxUsageReportSuppressRoundsprotected ResourceQuotaCalculatorquotaCalculatorprotected static floatUsageReportSuppressionTolerancePercentage
-
Constructor Summary
Constructors Constructor Description ResourceGroupService(PulsarService pulsar)Default constructor.ResourceGroupService(PulsarService pulsar, java.util.concurrent.TimeUnit timescale, ResourceUsageTopicTransportManager transportMgr, ResourceQuotaCalculator quotaCalc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaggregateResourceGroupLocalUsages()protected voidcalculateQuotaForAllResourceGroups()voidclose()ResourceGroupgetNamespaceResourceGroup(org.apache.pulsar.common.naming.NamespaceName namespaceName)Return the resource group associated with a namespace.protected longgetNumResourceGroups()Get the current number of RGs.protected ResourceGroup.BytesAndMessagesCountgetPublishRateLimiters(java.lang.String rgName)protected static doublegetRgLocalUsageByteCount(java.lang.String rgName, java.lang.String monClassName)protected static doublegetRgLocalUsageMessageCount(java.lang.String rgName, java.lang.String monClassName)protected static doublegetRgNamespaceRegistersCount(java.lang.String rgName)protected static doublegetRgNamespaceUnRegistersCount(java.lang.String rgName)protected static doublegetRgQuotaByteCount(java.lang.String rgName, java.lang.String monClassName)protected static io.prometheus.client.Summary.Child.ValuegetRgQuotaCalculationTime()protected static doublegetRgQuotaMessageCount(java.lang.String rgName, java.lang.String monClassName)protected static doublegetRgTenantRegistersCount(java.lang.String rgName)protected static doublegetRgTenantUnRegistersCount(java.lang.String rgName)protected static doublegetRgUpdatesCount(java.lang.String rgName)protected ResourceGroup.BytesAndMessagesCountgetRGUsage(java.lang.String rgName, ResourceGroup.ResourceGroupMonitoringClass monClass, ResourceGroupService.ResourceGroupUsageStatsType statsType)protected static io.prometheus.client.Summary.Child.ValuegetRgUsageAggregationLatency()protected booleanincrementUsage(java.lang.String tenantName, java.lang.String nsName, ResourceGroup.ResourceGroupMonitoringClass monClass, ResourceGroup.BytesAndMessagesCount incStats)Increments usage stats for the resource groups associated with the given namespace and tenant.voidregisterNameSpace(java.lang.String resourceGroupName, org.apache.pulsar.common.naming.NamespaceName fqNamespaceName)Registers a namespace as a user of a resource group.voidregisterTenant(java.lang.String resourceGroupName, java.lang.String tenantName)Registers a tenant as a user of a resource group.voidresourceGroupCreate(java.lang.String rgName, org.apache.pulsar.common.policies.data.ResourceGroup rgConfig)Create RG.voidresourceGroupCreate(java.lang.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(java.lang.String name)Delete RG.ResourceGroupresourceGroupGet(java.lang.String resourceGroupName)Get a copy of the RG with the given name.java.util.Set<java.lang.String>resourceGroupGetAll()voidresourceGroupUpdate(java.lang.String rgName, org.apache.pulsar.common.policies.data.ResourceGroup rgConfig)Update RG.voidunRegisterNameSpace(java.lang.String resourceGroupName, org.apache.pulsar.common.naming.NamespaceName fqNamespaceName)UnRegisters a namespace from a resource group.voidunRegisterTenant(java.lang.String resourceGroupName, java.lang.String tenantName)UnRegisters a tenant from a resource group.
-
-
-
Field Detail
-
quotaCalculator
protected final ResourceQuotaCalculator quotaCalculator
-
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
-
-
Constructor Detail
-
ResourceGroupService
public ResourceGroupService(PulsarService pulsar)
Default constructor.
-
ResourceGroupService
public ResourceGroupService(PulsarService pulsar, java.util.concurrent.TimeUnit timescale, ResourceUsageTopicTransportManager transportMgr, ResourceQuotaCalculator quotaCalc)
-
-
Method Detail
-
resourceGroupCreate
public void resourceGroupCreate(java.lang.String rgName, org.apache.pulsar.common.policies.data.ResourceGroup rgConfig) throws org.apache.pulsar.client.admin.PulsarAdminExceptionCreate 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.PulsarAdminExceptionCreate 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.PulsarAdminExceptionUpdate 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.PulsarAdminExceptionDelete 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.PulsarAdminExceptionRegisters 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.PulsarAdminExceptionUnRegisters 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.PulsarAdminExceptionRegisters 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.PulsarAdminExceptionUnRegisters 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:
closein interfacejava.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.PulsarAdminExceptionIncrements 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(java.lang.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(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()
-
-