Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-8376 Add DMR cluster counters management
- Loading branch information
1 parent
5cbd2fe
commit a3b64d5
Showing
29 changed files
with
1,452 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
<module name="org.infinispan"/> | ||
<module name="org.jboss.logging"/> | ||
</dependencies> | ||
</module> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...nispan/src/main/java/org/infinispan/server/infinispan/spi/service/CounterServiceName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.infinispan.server.infinispan.spi.service; | ||
|
||
import org.jboss.msc.service.ServiceName; | ||
|
||
/** | ||
* Enumeration of service name factories for services associated with a counter. | ||
* | ||
* @author Vladimir Blagojevic | ||
*/ | ||
public class CounterServiceName { | ||
|
||
public static ServiceName getServiceName(String container, String counterName) { | ||
return CacheContainerServiceName.CACHE_CONTAINER.getServiceName(container).append(counterName); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ain/java/org/jboss/as/clustering/infinispan/subsystem/CacheContainerCountersResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.jboss.as.clustering.infinispan.subsystem; | ||
|
||
import org.infinispan.counter.configuration.CounterManagerConfigurationBuilder; | ||
import org.infinispan.counter.configuration.Reliability; | ||
import org.jboss.as.controller.PathElement; | ||
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler; | ||
import org.jboss.as.controller.SimpleAttributeDefinition; | ||
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; | ||
import org.jboss.as.controller.SimpleResourceDefinition; | ||
import org.jboss.as.controller.registry.AttributeAccess; | ||
import org.jboss.as.controller.registry.ManagementResourceRegistration; | ||
import org.jboss.as.controller.services.path.ResolvePathHandler; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.dmr.ModelType; | ||
|
||
/** | ||
* CacheContainerCountersResource | ||
* | ||
* @author Vladimir Blagojevic | ||
* @since 9.2 | ||
*/ | ||
public class CacheContainerCountersResource extends SimpleResourceDefinition { | ||
static final PathElement PATH = PathElement.pathElement(ModelKeys.COUNTERS, ModelKeys.COUNTERS_NAME); | ||
|
||
//attributes | ||
static final SimpleAttributeDefinition RELIABILITY = new SimpleAttributeDefinitionBuilder(ModelKeys.RELIABILITY, | ||
ModelType.STRING, false) | ||
.setXmlName(Attribute.RELIABILITY.getLocalName()) | ||
.setAllowExpression(false) | ||
.setAllowedValues(Reliability.AVAILABLE.toString(), Reliability.CONSISTENT.toString()) | ||
.setDefaultValue(new ModelNode().set(CounterManagerConfigurationBuilder.defaultConfiguration().reliability().toString())) | ||
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) | ||
.build(); | ||
|
||
static final SimpleAttributeDefinition NUM_OWNERS = new SimpleAttributeDefinitionBuilder(ModelKeys.NUM_OWNERS, | ||
ModelType.LONG, false) | ||
.setXmlName(Attribute.NUM_OWNERS.getLocalName()) | ||
.setAllowExpression(false) | ||
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) | ||
.setDefaultValue(new ModelNode().set(CounterManagerConfigurationBuilder.defaultConfiguration().numOwners())) | ||
.build(); | ||
|
||
private final boolean runtimeRegistration; | ||
|
||
CacheContainerCountersResource(ResolvePathHandler resolvePathHandler, boolean runtimeRegistration) { | ||
super(PATH, new InfinispanResourceDescriptionResolver(ModelKeys.CACHE_CONTAINER, ModelKeys.COUNTERS), | ||
CacheConfigOperationHandlers.CONTAINER_CONFIGURATIONS_ADD, ReloadRequiredRemoveStepHandler.INSTANCE); | ||
this.runtimeRegistration = runtimeRegistration; | ||
} | ||
|
||
@Override | ||
public void registerChildren(ManagementResourceRegistration rr) { | ||
rr.registerSubModel(new StrongCounterResource(runtimeRegistration)); | ||
rr.registerSubModel(new WeakCounterResource(runtimeRegistration)); | ||
} | ||
|
||
@Override | ||
public void registerAttributes(ManagementResourceRegistration resourceRegistration) { | ||
super.registerAttributes(resourceRegistration); | ||
if (runtimeRegistration) { | ||
CountersMetricsHandler.INSTANCE.registerMetrics(resourceRegistration); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
...inispan/src/main/java/org/jboss/as/clustering/infinispan/subsystem/CounterAddHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package org.jboss.as.clustering.infinispan.subsystem; | ||
|
||
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import org.infinispan.counter.api.CounterConfiguration; | ||
import org.infinispan.counter.api.CounterConfiguration.Builder; | ||
import org.infinispan.counter.api.CounterType; | ||
import org.infinispan.counter.api.Storage; | ||
import org.infinispan.manager.EmbeddedCacheManager; | ||
import org.infinispan.server.infinispan.spi.service.CacheContainerServiceName; | ||
import org.infinispan.server.infinispan.spi.service.CounterServiceName; | ||
import org.jboss.as.controller.AbstractAddStepHandler; | ||
import org.jboss.as.controller.AttributeDefinition; | ||
import org.jboss.as.controller.OperationContext; | ||
import org.jboss.as.controller.OperationFailedException; | ||
import org.jboss.as.controller.PathAddress; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.msc.service.Service; | ||
import org.jboss.msc.service.ServiceBuilder; | ||
import org.jboss.msc.service.ServiceController; | ||
import org.jboss.msc.service.ServiceTarget; | ||
import org.jboss.msc.value.InjectedValue; | ||
|
||
/** | ||
* Add operation handler for /subsystem=infinispan/cache-container=clustered/counter=* | ||
* | ||
* @author Vladimir Blagojevic | ||
* | ||
*/ | ||
public class CounterAddHandler extends AbstractAddStepHandler implements RestartableServiceHandler{ | ||
|
||
CounterAddHandler() { | ||
} | ||
|
||
@Override | ||
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) | ||
throws OperationFailedException { | ||
|
||
super.performRuntime(context, operation, model); | ||
|
||
this.installRuntimeServices(context, operation, model, null); | ||
} | ||
|
||
@Override | ||
public Collection<ServiceController<?>> installRuntimeServices(OperationContext context, ModelNode operation, | ||
ModelNode containerModel, ModelNode cacheModel) throws OperationFailedException { | ||
|
||
String counterName = getCounterName(operation); | ||
String containerName = getContainerName(operation); | ||
String counterType = getCounterType(operation); | ||
|
||
Builder b = getBuilder(containerModel, counterType); | ||
processModelNode(context, containerModel, b); | ||
String name = CounterResource.COUNTER_NAME.resolveModelAttribute(context, containerModel).asString(); | ||
if (!counterName.equals(name)) { | ||
throw new OperationFailedException("Counter node name and node's name attribute should be the same"); | ||
} | ||
|
||
// wire counter service for this counter | ||
Collection<ServiceController<?>> controllers = new ArrayList<>(1); | ||
ServiceController<?> service = this.installCounterService(context.getServiceTarget(), | ||
containerName, counterName, b.build()); | ||
controllers.add(service); | ||
|
||
return controllers; | ||
} | ||
|
||
@Override | ||
public void removeRuntimeServices(OperationContext context, ModelNode operation, ModelNode containerModel, | ||
ModelNode cacheModel) throws OperationFailedException { | ||
|
||
String counterName = getCounterName(operation); | ||
String containerName = getContainerName(operation); | ||
|
||
context.removeService(CounterServiceName.getServiceName(containerName, counterName)); | ||
} | ||
|
||
private ServiceController<?> installCounterService(ServiceTarget target, String containerName, | ||
String configurationName, CounterConfiguration configuration) { | ||
final InjectedValue<EmbeddedCacheManager> container = new InjectedValue<>(); | ||
final CounterConfigurationDependencies dependencies = new CounterConfigurationDependencies(container); | ||
final Service<?> service = new CounterService(configuration, configurationName, dependencies); | ||
final ServiceBuilder<?> builder = target.addService(CounterServiceName.getServiceName(containerName, configurationName), service) | ||
.addDependency(CacheContainerServiceName.CACHE_CONTAINER.getServiceName(containerName), EmbeddedCacheManager.class, container); | ||
return builder.install(); | ||
} | ||
|
||
@Override | ||
protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { | ||
this.populate(operation, model); | ||
} | ||
|
||
void populate(ModelNode fromModel, ModelNode toModel) throws OperationFailedException { | ||
for (AttributeDefinition attr : CounterResource.ATTRIBUTES) { | ||
attr.validateAndSet(fromModel, toModel); | ||
} | ||
} | ||
|
||
private String getCounterName(ModelNode operation) { | ||
PathAddress counterAddress = getCounterAddressFromOperation(operation); | ||
return counterAddress.getLastElement().getValue(); | ||
} | ||
|
||
private String getContainerName(ModelNode operation) { | ||
PathAddress containerAddress = getCacheContainerAddressFromOperation(operation); | ||
return containerAddress.getLastElement().getValue(); | ||
} | ||
|
||
private PathAddress getCacheContainerAddressFromOperation(ModelNode operation) { | ||
PathAddress counterAddress = getCounterAddressFromOperation(operation); | ||
return counterAddress.subAddress(0, counterAddress.size() - 2); | ||
} | ||
|
||
private String getCounterType(ModelNode operation) { | ||
PathAddress counterAddress = getCounterAddressFromOperation(operation); | ||
int size = counterAddress.size(); | ||
PathAddress subAddress = counterAddress.subAddress(size - 1, size); | ||
return subAddress.getLastElement().getKey(); | ||
} | ||
|
||
private PathAddress getCounterAddressFromOperation(ModelNode operation) { | ||
return PathAddress.pathAddress(operation.get(OP_ADDR)); | ||
} | ||
|
||
private Builder getBuilder(ModelNode counter, String counterType) { | ||
boolean isWeakCounter = ModelKeys.WEAK_COUNTER.equals(counterType); | ||
if (isWeakCounter) { | ||
return CounterConfiguration.builder(CounterType.WEAK); | ||
} else { | ||
ModelNode lowerBoundModel = counter.get(ModelKeys.LOWER_BOUND); | ||
ModelNode upperBoundModel = counter.get(ModelKeys.UPPER_BOUND); | ||
boolean isBounded = lowerBoundModel.isDefined() || upperBoundModel.isDefined(); | ||
return isBounded ? CounterConfiguration.builder(CounterType.BOUNDED_STRONG) | ||
: CounterConfiguration.builder(CounterType.UNBOUNDED_STRONG); | ||
} | ||
} | ||
|
||
void processModelNode(OperationContext context, ModelNode counter, | ||
CounterConfiguration.Builder builder) throws OperationFailedException { | ||
|
||
long initialValue = CounterResource.INITIAL_VALUE.resolveModelAttribute(context, counter).asLong(); | ||
String storageType = CounterResource.STORAGE.resolveModelAttribute(context, counter).asString(); | ||
|
||
builder.initialValue(initialValue); | ||
builder.storage(Storage.valueOf(storageType)); | ||
} | ||
|
||
private static class CounterConfigurationDependencies implements CounterService.Dependencies { | ||
|
||
private InjectedValue<EmbeddedCacheManager> container; | ||
public CounterConfigurationDependencies(InjectedValue<EmbeddedCacheManager> container) { | ||
this.container = container; | ||
} | ||
|
||
@Override | ||
public EmbeddedCacheManager getCacheContainer() { | ||
return this.container.getValue(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.