use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class LogStoreProbeHandler method probeTransactions.
private Resource probeTransactions(MBeanServer mbs, boolean exposeAllLogs) throws OperationFailedException {
try {
ObjectName on = new ObjectName(osMBeanName);
mbs.setAttribute(on, new javax.management.Attribute("ExposeAllRecordsAsMBeans", Boolean.valueOf(exposeAllLogs)));
mbs.invoke(on, "probe", null, null);
Set<ObjectInstance> transactions = mbs.queryMBeans(new ObjectName(osMBeanName + ",*"), null);
final Resource resource = Resource.Factory.create();
addTransactions(resource, transactions, mbs);
return resource;
} catch (JMException e) {
throw new OperationFailedException("Transaction discovery error: ", e);
} catch (IOException e) {
throw new OperationFailedException("Transaction discovery error: ", e);
}
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class LogStoreTransactionDeleteHandler method execute.
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
MBeanServer mbs = TransactionExtension.getMBeanServer(context);
final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
try {
final ObjectName on = LogStoreResource.getObjectName(resource);
// Invoke operation
Object res = mbs.invoke(on, "remove", null, null);
try {
// validate that the MBean was removed:
mbs.getObjectInstance(on);
String reason = res != null ? res.toString() : LOG_DELETE_FAILURE_MESSAGE;
throw new OperationFailedException(reason);
} catch (InstanceNotFoundException e) {
// success, the MBean was deleted
final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
final PathElement element = address.getLastElement();
logStoreResource.removeChild(element);
}
} catch (OperationFailedException e) {
throw e;
} catch (Exception e) {
throw new OperationFailedException(e.getMessage());
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class RelayConfigurationBuilder method configure.
@Override
public Builder<RelayConfiguration> configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.siteName = SITE.resolveModelAttribute(context, model).asString();
PathAddress address = context.getCurrentAddress();
Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
this.sites = resource.getChildren(RemoteSiteResourceDefinition.WILDCARD_PATH.getKey()).stream().map(entry -> new InjectedValueDependency<>(new RemoteSiteServiceNameProvider(address, entry.getPathElement()), RemoteSiteConfiguration.class)).collect(Collectors.toList());
return super.configure(context, model);
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class ProtocolResourceRegistrationHandler method execute.
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
OverrideDescriptionProvider provider = new OverrideDescriptionProvider() {
@Override
public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
return Collections.emptyMap();
}
@Override
public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
StandardResourceDescriptionResolver resolver = new JGroupsResourceDescriptionResolver();
String description = resolver.getChildTypeDescription(ProtocolResourceDefinition.WILDCARD_PATH.getKey(), locale, resolver.getResourceBundle(locale));
ModelNode result = new ModelNode();
result.get(ModelDescriptionConstants.DESCRIPTION).set(description);
return Collections.singletonMap(ProtocolResourceDefinition.WILDCARD_PATH.getKey(), result);
}
};
Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
String stack = STACK.resolveModelAttribute(context, resource.getModel()).asString();
ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate().registerOverrideModel(context.getCurrentAddressValue(), provider);
PathAddress stackAddress = context.getCurrentAddress().getParent().append(StackResourceDefinition.pathElement(stack));
Resource stackResource = context.readResourceFromRoot(stackAddress, false);
for (String name : stackResource.getChildrenNames(TransportResourceDefinition.WILDCARD_PATH.getKey())) {
PathAddress transportAddress = stackAddress.append(TransportResourceDefinition.pathElement(name));
ModelNode transport = context.readResourceFromRoot(transportAddress, false).getModel();
String moduleName = MODULE.resolveModelAttribute(context, transport).asString();
Class<? extends Protocol> transportClass = findProtocolClass(context, name, moduleName);
registration.registerSubModel(this.createProtocolResourceDefinition(name, transportClass));
resource.registerChild(ProtocolResourceDefinition.pathElement(name), PlaceholderResource.INSTANCE);
}
for (String name : stackResource.getChildrenNames(ProtocolResourceDefinition.WILDCARD_PATH.getKey())) {
Resource protocolResource = context.readResourceFromRoot(stackAddress.append(ProtocolResourceDefinition.pathElement(name)), false);
String moduleName = MODULE.resolveModelAttribute(context, protocolResource.getModel()).asString();
Class<? extends Protocol> protocolClass = findProtocolClass(context, name, moduleName);
registration.registerSubModel(this.createProtocolResourceDefinition(name, protocolClass));
resource.registerChild(ProtocolResourceDefinition.pathElement(name), PlaceholderResource.INSTANCE);
}
if (stackResource.hasChild(RelayResourceDefinition.PATH)) {
registration.registerSubModel(this.createProtocolResourceDefinition(RelayConfiguration.PROTOCOL_NAME, RELAY2.class));
resource.registerChild(ProtocolResourceDefinition.pathElement(RelayConfiguration.PROTOCOL_NAME), PlaceholderResource.INSTANCE);
}
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class TransactionResourceDefinition method buildTransformation.
@SuppressWarnings("deprecation")
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
ResourceTransformationDescriptionBuilder builder = InfinispanModel.VERSION_4_0_0.requiresTransformation(version) ? parent.addChildRedirection(PATH, LEGACY_PATH, RequiredChildResourceDiscardPolicy.NEVER) : parent.addChildResource(PATH);
List<org.jboss.as.controller.transform.OperationTransformer> addOperationTransformers = new LinkedList<>();
List<org.jboss.as.controller.transform.OperationTransformer> removeOperationTransformers = new LinkedList<>();
Map<String, org.jboss.as.controller.transform.OperationTransformer> readAttributeTransformers = new HashMap<>();
Map<String, org.jboss.as.controller.transform.OperationTransformer> writeAttributeTransformers = new HashMap<>();
Map<String, org.jboss.as.controller.transform.OperationTransformer> undefineAttributeTransformers = new HashMap<>();
if (InfinispanModel.VERSION_3_0_0.requiresTransformation(version)) {
// Convert BATCH -> NONE, and include write-attribute:name=batching
OperationTransformer addTransformer = new OperationTransformer() {
@Override
public ModelNode transformOperation(ModelNode operation) {
if (operation.hasDefined(Attribute.MODE.getName())) {
ModelNode mode = operation.get(Attribute.MODE.getName());
if ((mode.getType() == ModelType.STRING) && (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH)) {
mode.set(TransactionMode.NONE.name());
PathAddress address = Operations.getPathAddress(operation);
return Operations.createCompositeOperation(operation, Operations.createWriteAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING, new ModelNode(true)));
}
}
return operation;
}
};
addOperationTransformers.add(new SimpleOperationTransformer(addTransformer));
// Additionally include undefine-attribute:name=batching
OperationTransformer removeTransformer = new OperationTransformer() {
@Override
public ModelNode transformOperation(ModelNode operation) {
PathAddress address = Operations.getPathAddress(operation);
return Operations.createCompositeOperation(operation, Operations.createUndefineAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING));
}
};
removeOperationTransformers.add(new SimpleOperationTransformer(removeTransformer));
// If read-attribute:name=batching is true, return BATCH, otherwise use result from read-attribute:name=mode
OperationTransformer readAttributeOperationTransformer = new OperationTransformer() {
@Override
public ModelNode transformOperation(ModelNode operation) {
PathAddress address = Operations.getPathAddress(operation);
return Operations.createCompositeOperation(Operations.createReadAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING), operation);
}
};
OperationResultTransformer readAttributeResultTransformer = new OperationResultTransformer() {
@Override
public ModelNode transformResult(ModelNode result) {
ModelNode readBatchingResult = result.get(0);
return readBatchingResult.asBoolean() ? new ModelNode(TransactionMode.BATCH.name()) : result.get(1);
}
};
readAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(readAttributeOperationTransformer, readAttributeResultTransformer));
// Convert BATCH -> NONE, and include write-attribute:name=batching
OperationTransformer writeAttributeTransformer = new OperationTransformer() {
@Override
public ModelNode transformOperation(ModelNode operation) {
ModelNode mode = Operations.getAttributeValue(operation);
boolean batching = (mode.isDefined() && (mode.getType() == ModelType.STRING)) ? (TransactionMode.valueOf(mode.asString()) == TransactionMode.BATCH) : false;
if (batching) {
mode.set(TransactionMode.NONE.name());
}
PathAddress address = Operations.getPathAddress(operation);
return Operations.createCompositeOperation(operation, Operations.createWriteAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING, new ModelNode(batching)));
}
};
writeAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(writeAttributeTransformer));
// Include undefine-attribute:name=batching
OperationTransformer undefineAttributeTransformer = new OperationTransformer() {
@Override
public ModelNode transformOperation(ModelNode operation) {
PathAddress address = Operations.getPathAddress(operation);
return Operations.createCompositeOperation(operation, Operations.createUndefineAttributeOperation(cacheAddress(address), CacheResourceDefinition.DeprecatedAttribute.BATCHING));
}
};
undefineAttributeTransformers.put(Attribute.MODE.getName(), new SimpleOperationTransformer(undefineAttributeTransformer));
// Convert BATCH -> NONE
ResourceTransformer modeTransformer = new ResourceTransformer() {
@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
ModelNode model = resource.getModel();
if (model.hasDefined(Attribute.MODE.getName())) {
ModelNode value = model.get(Attribute.MODE.getName());
if ((value.getType() == ModelType.STRING) && (TransactionMode.valueOf(value.asString()) == TransactionMode.BATCH)) {
value.set(TransactionMode.NONE.name());
}
}
context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource).processChildren(resource);
}
};
builder.setCustomResourceTransformer(modeTransformer);
// change default value of stop-timeout attribute
builder.getAttributeBuilder().setValueConverter(new DefaultValueAttributeConverter(Attribute.STOP_TIMEOUT.getDefinition()), Attribute.STOP_TIMEOUT.getDefinition());
}
buildOperationTransformation(builder, ModelDescriptionConstants.ADD, addOperationTransformers);
buildOperationTransformation(builder, ModelDescriptionConstants.REMOVE, removeOperationTransformers);
buildOperationTransformation(builder, ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION, readAttributeTransformers);
buildOperationTransformation(builder, ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION, writeAttributeTransformers);
buildOperationTransformation(builder, ModelDescriptionConstants.UNDEFINE_ATTRIBUTE_OPERATION, undefineAttributeTransformers);
}
Aggregations