use of org.jboss.dmr.ModelType in project wildfly by wildfly.
the class ManagementResourceDefinition method registerOperations.
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
super.registerOperations(resourceRegistration);
for (final String statisticName : statistics.getNames()) {
final ModelType modelType = getModelType(statistics.getType(statisticName));
if (statistics.isOperation(statisticName)) {
AttributeDefinition attributeDefinition = new SimpleAttributeDefinitionBuilder(statisticName, modelType, true).setXmlName(statisticName).setAllowExpression(true).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build();
OperationStepHandler operationHandler = new AbstractMetricsHandler() {
@Override
void handle(final ModelNode response, OperationContext context, final ModelNode operation) {
Object result = statistics.getValue(statisticName, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
if (result != null) {
setResponse(response, result, modelType);
}
}
};
SimpleOperationDefinition definition = new SimpleOperationDefinition(statisticName, descriptionResolver, attributeDefinition);
resourceRegistration.registerOperationHandler(definition, operationHandler);
}
}
}
use of org.jboss.dmr.ModelType in project wildfly by wildfly.
the class ManagementResourceDefinition method registerAttributes.
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
super.registerAttributes(resourceRegistration);
for (final String statisticName : statistics.getNames()) {
final ModelType modelType = getModelType(statistics.getType(statisticName));
final SimpleAttributeDefinitionBuilder simpleAttributeDefinitionBuilder = new SimpleAttributeDefinitionBuilder(statisticName, modelType, true).setXmlName(statisticName).setAllowExpression(true).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME);
if (statistics.isAttribute(statisticName)) {
// WFLY-561 improves usability by using "statistics-enabled" instead of "enabled"
if (ENABLED_ATTRIBUTE.equals(statisticName)) {
simpleAttributeDefinitionBuilder.setDeprecated(ENABLED_ATTRIBUTE_DEPRECATED_MODEL_VERSION);
}
OperationStepHandler readHandler = new AbstractMetricsHandler() {
@Override
void handle(final ModelNode response, OperationContext context, final ModelNode operation) {
Object result = statistics.getValue(statisticName, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
if (result != null) {
setResponse(response, result, modelType);
}
}
};
// handle writeable attributes
if (statistics.isWriteable(statisticName)) {
OperationStepHandler writeHandler = new AbstractMetricsHandler() {
@Override
void handle(final ModelNode response, OperationContext context, final ModelNode operation) {
Object oldSetting = statistics.getValue(statisticName, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
{
final ModelNode value = operation.get(ModelDescriptionConstants.VALUE).resolve();
if (Boolean.class.equals(statistics.getType(statisticName))) {
statistics.setValue(statisticName, value.asBoolean(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
} else if (Integer.class.equals(statistics.getType(statisticName))) {
statistics.setValue(statisticName, value.asInt(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
} else if (Long.class.equals(statistics.getType(statisticName))) {
statistics.setValue(statisticName, value.asLong(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
} else {
statistics.setValue(statisticName, value.asString(), entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
}
}
final Object rollBackValue = oldSetting;
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
statistics.setValue(statisticName, rollBackValue, entityManagerFactoryLookup, StatisticNameLookup.statisticNameLookup(statisticName), Path.path(PathAddress.pathAddress(operation.get(ADDRESS))));
}
});
}
};
resourceRegistration.registerReadWriteAttribute(simpleAttributeDefinitionBuilder.build(), readHandler, writeHandler);
} else {
resourceRegistration.registerMetric(simpleAttributeDefinitionBuilder.build(), readHandler);
}
}
}
}
use of org.jboss.dmr.ModelType in project wildfly by wildfly.
the class EjbJarRuntimeResourceTestBase method validatePool.
private void validatePool(ModelNode address, ModelNode resourceDescription, ModelNode resource) {
for (String attr : POOL_ATTRIBUTES) {
final ModelType expectedType = POOL_NAME.equals(attr) ? ModelType.STRING : ModelType.INT;
assertTrue(resourceDescription.get(ATTRIBUTES, attr).isDefined());
assertEquals(ModelType.STRING, resourceDescription.get(ATTRIBUTES, attr, DESCRIPTION).getType());
assertEquals(expectedType, resourceDescription.get(ATTRIBUTES, attr, TYPE).asType());
assertTrue(attr + " is not defined", resource.get(attr).isDefined());
assertEquals(expectedType, resource.get(attr).getType());
}
}
use of org.jboss.dmr.ModelType in project wildfly by wildfly.
the class ExpressionSupportSmokeTestCase method handleSimpleCollection.
private void handleSimpleCollection(PathAddress address, String attrName, ModelNode attrValue, ModelType valueType, Map<String, ModelNode> expressionAttrs, Map<String, ModelNode> otherAttrs, Map<String, ModelNode> expectedAttrs) {
if (COMPLEX_TYPES.contains(valueType)) {
// Too complicated
noSimpleCollection++;
logNoExpressions(address, attrName);
otherAttrs.put(attrName, attrValue);
} else {
boolean hasExpression = false;
ModelNode updated = new ModelNode();
ModelNode expected = new ModelNode();
for (ModelNode item : attrValue.asList()) {
ModelType itemType = item.getType();
if (itemType == ModelType.PROPERTY) {
Property prop = item.asProperty();
ModelNode propVal = prop.getValue();
ModelType propValType = propVal.getType();
if (propVal.isDefined() && propValType != ModelType.EXPRESSION) {
// Convert property value to expression
if (propValType == ModelType.STRING) {
checkForUnconvertedExpression(address, attrName, propVal);
}
String expression = "${exp.test:" + propVal.asString() + "}";
updated.get(prop.getName()).set(expression);
expected.get(prop.getName()).set(new ModelNode().set(new ValueExpression(expression)));
hasExpression = true;
} else {
updated.get(prop.getName()).set(propVal);
expected.get(prop.getName()).set(propVal);
}
} else if (item.isDefined() && itemType != ModelType.EXPRESSION) {
// Convert item to expression
if (itemType == ModelType.STRING) {
checkForUnconvertedExpression(address, attrName, item);
}
String expression = "${exp.test:" + item.asString() + "}";
updated.add(expression);
expected.add(new ModelNode().set(new ValueExpression(expression)));
hasExpression = true;
} else {
updated.add(item);
expected.add(item);
}
}
if (hasExpression) {
simpleCollection++;
logHandling("Added expression to SIMPLE " + attrValue.getType() + " attribute " + attrName + " at " + address.toModelNode().asString());
expressionAttrs.put(attrName, updated);
expectedAttrs.put(attrName, expected);
} else {
// We didn't change anything
noSimpleCollection++;
logNoExpressions(address, attrName);
otherAttrs.put(attrName, attrValue);
expectedAttrs.put(attrName, attrValue);
}
}
}
use of org.jboss.dmr.ModelType in project wildfly by wildfly.
the class AbstractExpressionSupportTestCase method handleSimpleCollection.
private void handleSimpleCollection(PathAddress address, String attrName, ModelNode attrValue, ModelType valueType, Map<String, ModelNode> expressionAttrs, Map<String, ModelNode> otherAttrs, Map<String, ModelNode> expectedAttrs) {
if (COMPLEX_TYPES.contains(valueType)) {
// Too complicated
noSimpleCollection++;
logNoExpressions(address, attrName);
otherAttrs.put(attrName, attrValue);
} else {
boolean hasExpression = false;
ModelNode updated = new ModelNode();
ModelNode expected = new ModelNode();
for (ModelNode item : attrValue.asList()) {
ModelType itemType = item.getType();
if (itemType == ModelType.PROPERTY) {
Property prop = item.asProperty();
ModelNode propVal = prop.getValue();
ModelType propValType = propVal.getType();
if (propVal.isDefined() && propValType != ModelType.EXPRESSION) {
// Convert property value to expression
if (propValType == ModelType.STRING) {
checkForUnconvertedExpression(address, attrName, propVal);
}
String expression = "${exp.test:" + propVal.asString() + "}";
updated.get(prop.getName()).set(expression);
expected.get(prop.getName()).set(new ModelNode().set(new ValueExpression(expression)));
hasExpression = true;
} else {
updated.get(prop.getName()).set(propVal);
expected.get(prop.getName()).set(propVal);
}
} else if (item.isDefined() && itemType != ModelType.EXPRESSION) {
// Convert item to expression
if (itemType == ModelType.STRING) {
checkForUnconvertedExpression(address, attrName, item);
}
String expression = "${exp.test:" + item.asString() + "}";
updated.add(expression);
expected.add(new ModelNode().set(new ValueExpression(expression)));
hasExpression = true;
} else {
updated.add(item);
expected.add(item);
}
}
if (hasExpression) {
simpleCollection++;
logHandling("Added expression to SIMPLE " + attrValue.getType() + " attribute " + attrName + " at " + address.toModelNode().asString());
expressionAttrs.put(attrName, updated);
expectedAttrs.put(attrName, expected);
} else {
// We didn't change anything
noSimpleCollection++;
logNoExpressions(address, attrName);
otherAttrs.put(attrName, attrValue);
expectedAttrs.put(attrName, attrValue);
}
}
}
Aggregations