rootRegistration.registerOperationHandler(READ_CHILDREN_TYPES_OPERATION, GlobalOperationHandlers.READ_CHILDREN_TYPES, CommonProviders.READ_CHILDREN_TYPES_PROVIDER, true, EnumSet.of(Flag.RUNTIME_ONLY));
rootRegistration.registerOperationHandler(READ_CHILDREN_RESOURCES_OPERATION, GlobalOperationHandlers.READ_CHILDREN_RESOURCES, CommonProviders.READ_CHILDREN_RESOURCES_PROVIDER, true, EnumSet.of(Flag.RUNTIME_ONLY));
rootRegistration.registerOperationHandler(READ_OPERATION_NAMES_OPERATION, GlobalOperationHandlers.READ_OPERATION_NAMES, CommonProviders.READ_OPERATION_NAMES_PROVIDER, true, EnumSet.of(Flag.RUNTIME_ONLY));
rootRegistration.registerOperationHandler(READ_OPERATION_DESCRIPTION_OPERATION, GlobalOperationHandlers.READ_OPERATION_DESCRIPTION, CommonProviders.READ_OPERATION_PROVIDER, true, EnumSet.of(Flag.RUNTIME_ONLY));
rootRegistration.registerOperationHandler(WRITE_ATTRIBUTE_OPERATION, GlobalOperationHandlers.WRITE_ATTRIBUTE, CommonProviders.WRITE_ATTRIBUTE_PROVIDER, true);
rootRegistration.registerOperationHandler("setup", new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ModelNode model = new ModelNode();
//Atttributes
model.get("profile", "profileA", "subsystem", "subsystem1", "attr1").add(1);
model.get("profile", "profileA", "subsystem", "subsystem1", "attr1").add(2);
//Children
model.get("profile", "profileA", "subsystem", "subsystem1", "type1", "thing1", "name").set("Name11");
model.get("profile", "profileA", "subsystem", "subsystem1", "type1", "thing1", "value").set("201");
model.get("profile", "profileA", "subsystem", "subsystem1", "type1", "thing2", "name").set("Name12");
model.get("profile", "profileA", "subsystem", "subsystem1", "type1", "thing2", "value").set("202");
model.get("profile", "profileA", "subsystem", "subsystem1", "type2", "other", "name").set("Name2");
model.get("profile", "profileA", "subsystem", "subsystem2", "bigdecimal").set(new BigDecimal(100));
model.get("profile", "profileA", "subsystem", "subsystem2", "biginteger").set(new BigInteger("101"));
model.get("profile", "profileA", "subsystem", "subsystem2", "boolean").set(true);
model.get("profile", "profileA", "subsystem", "subsystem2", "bytes").set(new byte[] {1, 2, 3});
model.get("profile", "profileA", "subsystem", "subsystem2", "double").set(Double.MAX_VALUE);
model.get("profile", "profileA", "subsystem", "subsystem2", "expression").setExpression("{expr}");
model.get("profile", "profileA", "subsystem", "subsystem2", "int").set(102);
model.get("profile", "profileA", "subsystem", "subsystem2", "list").add("l1A");
model.get("profile", "profileA", "subsystem", "subsystem2", "list").add("l1B");
model.get("profile", "profileA", "subsystem", "subsystem2", "long").set(Long.MAX_VALUE);
model.get("profile", "profileA", "subsystem", "subsystem2", "object", "value").set("objVal");
model.get("profile", "profileA", "subsystem", "subsystem2", "property").set(new Property("prop1", new ModelNode().set("value1")));
model.get("profile", "profileA", "subsystem", "subsystem2", "string1").set("s1");
model.get("profile", "profileA", "subsystem", "subsystem2", "string2").set("s2");
model.get("profile", "profileA", "subsystem", "subsystem2", "type").set(ModelType.TYPE);
model.get("profile", "profileB", "name").set("Profile B");
model.get("profile", "profileC", "subsystem", "subsystem4");
model.get("profile", "profileC", "subsystem", "subsystem5", "name").set("Test");
createModel(context, model);
context.completeStep();
}
}, new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
return new ModelNode();
}
}, false, OperationEntry.EntryType.PRIVATE);
ManagementResourceRegistration profileReg = rootRegistration.registerSubModel(PathElement.pathElement("profile", "*"), new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(DESCRIPTION).set("A named set of subsystem configs");
node.get(ATTRIBUTES, NAME, TYPE).set(ModelType.STRING);
node.get(ATTRIBUTES, NAME, DESCRIPTION).set("The name of the profile");
node.get(ATTRIBUTES, NAME, REQUIRED).set(true);
node.get(ATTRIBUTES, NAME, MIN_LENGTH).set(1);
node.get(CHILDREN, SUBSYSTEM, DESCRIPTION).set("The subsystems that make up the profile");
node.get(CHILDREN, SUBSYSTEM, MIN_OCCURS).set(1);
node.get(CHILDREN, SUBSYSTEM, MODEL_DESCRIPTION);
return node;
}
});
ManagementResourceRegistration profileSub1Reg = profileReg.registerSubModel(PathElement.pathElement("subsystem", "subsystem1"), new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(DESCRIPTION).set("A test subsystem 1");
node.get(ATTRIBUTES, "attr1", TYPE).set(ModelType.LIST);
node.get(ATTRIBUTES, "attr1", VALUE_TYPE).set(ModelType.INT);
node.get(ATTRIBUTES, "attr1", DESCRIPTION).set("The values");
node.get(ATTRIBUTES, "attr1", REQUIRED).set(true);
node.get(ATTRIBUTES, "read-only", TYPE).set(ModelType.INT);
node.get(ATTRIBUTES, "read-only", DESCRIPTION).set("A r/o int");
node.get(ATTRIBUTES, "read-only", REQUIRED).set(false);
node.get(ATTRIBUTES, "metric1", TYPE).set(ModelType.INT);
node.get(ATTRIBUTES, "metric1", DESCRIPTION).set("A random metric");
node.get(ATTRIBUTES, "read-write", TYPE).set(ModelType.INT);
node.get(ATTRIBUTES, "metric2", TYPE).set(ModelType.INT);
node.get(ATTRIBUTES, "read-write", DESCRIPTION).set("A r/w int");
node.get(ATTRIBUTES, "read-write", REQUIRED).set(false);
node.get(CHILDREN, "type1", DESCRIPTION).set("The children1");
node.get(CHILDREN, "type1", MIN_OCCURS).set(1);
node.get(CHILDREN, "type1", MODEL_DESCRIPTION);
node.get(CHILDREN, "type2", DESCRIPTION).set("The children2");
node.get(CHILDREN, "type2", MIN_OCCURS).set(1);
node.get(CHILDREN, "type2", MODEL_DESCRIPTION);
return node;
}
});
profileSub1Reg.registerReadOnlyAttribute("read-only", null, AttributeAccess.Storage.CONFIGURATION);
profileSub1Reg.registerReadWriteAttribute("read-write", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(ModelType.INT), AttributeAccess.Storage.CONFIGURATION);
profileSub1Reg.registerMetric("metric1", TestMetricHandler.INSTANCE);
profileSub1Reg.registerMetric("metric2", TestMetricHandler.INSTANCE);
//TODO Validation if we try to set a handler for an attribute that does not exist in model?
DescriptionProvider thingProvider = new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(DESCRIPTION).set("A type 1");
node.get(ATTRIBUTES, "name", TYPE).set(ModelType.STRING);
node.get(ATTRIBUTES, "name", DESCRIPTION).set("The name of the thing");
node.get(ATTRIBUTES, "name", REQUIRED).set(true);
node.get(ATTRIBUTES, "value", TYPE).set(ModelType.INT);
node.get(ATTRIBUTES, "value", DESCRIPTION).set("The value of the thing");
node.get(ATTRIBUTES, "value", REQUIRED).set(true);
return node;
}
};
ManagementResourceRegistration profileSub1RegChildType11 = profileSub1Reg.registerSubModel(PathElement.pathElement("type1", "*"), thingProvider);
ManagementResourceRegistration profileSub1RegChildType2 = profileSub1Reg.registerSubModel(PathElement.pathElement("type2", "other"), new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(DESCRIPTION).set("A type 2");
node.get(ATTRIBUTES, "name", TYPE).set(ModelType.STRING);
node.get(ATTRIBUTES, "name", DESCRIPTION).set("The name of the thing");
node.get(ATTRIBUTES, "name", REQUIRED).set(true);
return node;
}
});
ManagementResourceRegistration profileASub2Reg = profileReg.registerSubModel(PathElement.pathElement("subsystem", "subsystem2"), new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(DESCRIPTION).set("A test subsystem 2");
node.get(ATTRIBUTES, "bigdecimal", TYPE).set(ModelType.BIG_DECIMAL);
node.get(ATTRIBUTES, "bigdecimal", DESCRIPTION).set("A big decimal");
node.get(ATTRIBUTES, "bigdecimal", REQUIRED).set(true);
node.get(ATTRIBUTES, "biginteger", TYPE).set(ModelType.BIG_DECIMAL);
node.get(ATTRIBUTES, "biginteger", DESCRIPTION).set("A big integer");
node.get(ATTRIBUTES, "biginteger", REQUIRED).set(true);
node.get(ATTRIBUTES, "boolean", TYPE).set(ModelType.BOOLEAN);
node.get(ATTRIBUTES, "boolean", DESCRIPTION).set("A boolean");
node.get(ATTRIBUTES, "boolean", REQUIRED).set(true);
node.get(ATTRIBUTES, "bytes", TYPE).set(ModelType.BYTES);
node.get(ATTRIBUTES, "bytes", DESCRIPTION).set("A bytes");
node.get(ATTRIBUTES, "bytes", REQUIRED).set(true);
node.get(ATTRIBUTES, "double", TYPE).set(ModelType.DOUBLE);
node.get(ATTRIBUTES, "double", DESCRIPTION).set("A double");
node.get(ATTRIBUTES, "double", REQUIRED).set(true);
node.get(ATTRIBUTES, "expression", TYPE).set(ModelType.EXPRESSION);
node.get(ATTRIBUTES, "expression", DESCRIPTION).set("A double");
node.get(ATTRIBUTES, "expression", REQUIRED).set(true);
node.get(ATTRIBUTES, "int", TYPE).set(ModelType.INT);
node.get(ATTRIBUTES, "int", DESCRIPTION).set("A int");
node.get(ATTRIBUTES, "int", REQUIRED).set(true);
node.get(ATTRIBUTES, "list", TYPE).set(ModelType.LIST);
node.get(ATTRIBUTES, "list", VALUE_TYPE).set(ModelType.STRING);
node.get(ATTRIBUTES, "list", DESCRIPTION).set("A list");
node.get(ATTRIBUTES, "list", REQUIRED).set(true);
node.get(ATTRIBUTES, "long", TYPE).set(ModelType.LONG);
node.get(ATTRIBUTES, "long", DESCRIPTION).set("A long");
node.get(ATTRIBUTES, "long", REQUIRED).set(true);
node.get(ATTRIBUTES, "object", TYPE).set(ModelType.OBJECT);
node.get(ATTRIBUTES, "object", VALUE_TYPE).set(ModelType.STRING);
node.get(ATTRIBUTES, "object", DESCRIPTION).set("A object");
node.get(ATTRIBUTES, "object", REQUIRED).set(true);
node.get(ATTRIBUTES, "property", TYPE).set(ModelType.PROPERTY);
node.get(ATTRIBUTES, "property", VALUE_TYPE).set(ModelType.STRING);
node.get(ATTRIBUTES, "property", DESCRIPTION).set("A property");
node.get(ATTRIBUTES, "property", REQUIRED).set(true);
node.get(ATTRIBUTES, "string1", TYPE).set(ModelType.STRING);
node.get(ATTRIBUTES, "string1", DESCRIPTION).set("A string");
node.get(ATTRIBUTES, "string1", REQUIRED).set(true);
node.get(ATTRIBUTES, "string2", TYPE).set(ModelType.STRING);
node.get(ATTRIBUTES, "string2", DESCRIPTION).set("A string");
node.get(ATTRIBUTES, "string2", REQUIRED).set(true);
node.get(ATTRIBUTES, "type", TYPE).set(ModelType.TYPE);
node.get(ATTRIBUTES, "type", DESCRIPTION).set("A type");
node.get(ATTRIBUTES, "type", REQUIRED).set(true);
return node;
}
});
profileASub2Reg.registerReadWriteAttribute("long", null, new WriteAttributeHandlers.ModelTypeValidatingHandler(ModelType.LONG, false), AttributeAccess.Storage.CONFIGURATION);
ManagementResourceRegistration profileBSub3Reg = profileReg.registerSubModel(PathElement.pathElement("subsystem", "subsystem3"), new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(DESCRIPTION).set("A test subsystem 1");
node.get(ATTRIBUTES, "attr1", TYPE).set(ModelType.INT);
node.get(ATTRIBUTES, "attr1", DESCRIPTION).set("The value");
node.get(ATTRIBUTES, "attr1", REQUIRED).set(true);
node.get(CHILDREN).setEmptyObject();
return node;
}
});
profileSub1Reg.registerOperationHandler("testA1-1",
new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
return;
}
},
new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(OPERATION_NAME).set("testA1");
node.get(REQUEST_PROPERTIES, "paramA1", TYPE).set(ModelType.INT);
return node;
}
},
false);
profileSub1Reg.registerOperationHandler("testA1-2",
new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
return;
}
},
new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(OPERATION_NAME).set("testA2");
node.get(REQUEST_PROPERTIES, "paramA2", TYPE).set(ModelType.STRING);
return node;
}
},
false);
profileASub2Reg.registerOperationHandler("testA2",
new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
return;
}
},
new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(OPERATION_NAME).set("testB");
node.get(REQUEST_PROPERTIES, "paramB", TYPE).set(ModelType.LONG);
return node;
}
},
false);
ManagementResourceRegistration profileCSub4Reg = profileReg.registerSubModel(PathElement.pathElement("subsystem", "subsystem4"), new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(DESCRIPTION).set("A subsystem");
node.get(ATTRIBUTES, "name", TYPE).set(ModelType.STRING);
node.get(ATTRIBUTES, "name", DESCRIPTION).set("The name of the thing");
node.get(ATTRIBUTES, "name", REQUIRED).set(false);
node.get(CHILDREN, "type1", DESCRIPTION).set("The children1");
node.get(CHILDREN, "type1", MIN_OCCURS).set(0);
node.get(CHILDREN, "type1", MODEL_DESCRIPTION);
return node;
}
});
ManagementResourceRegistration profileCSub5Reg = profileReg.registerSubModel(PathElement.pathElement("subsystem", "subsystem5"), new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
ModelNode node = new ModelNode();
node.get(DESCRIPTION).set("A subsystem");
node.get(ATTRIBUTES, "name", TYPE).set(ModelType.STRING);
node.get(ATTRIBUTES, "name", DESCRIPTION).set("The name of the thing");
node.get(ATTRIBUTES, "name", REQUIRED).set(false);
node.get(CHILDREN, "type1", DESCRIPTION).set("The children1");
node.get(CHILDREN, "type1", MIN_OCCURS).set(0);
node.get(CHILDREN, "type1", MODEL_DESCRIPTION);
return node;
}
});
profileCSub5Reg.registerReadOnlyAttribute("name", new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) {
context.getResult().set("Overridden by special read handler");
context.completeStep();