use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class AddressSettingsWriteHandler method applyUpdateToRuntime.
@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue, final ModelNode currentValue, final HandbackHolder<RevertHandback> handbackHolder) throws OperationFailedException {
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
final ActiveMQServer server = getActiveMQServer(context, operation);
if (server != null) {
final ModelNode model = resource.getModel();
final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
final AddressSettings settings = AddressSettingAdd.createSettings(context, model);
final HierarchicalRepository<AddressSettings> repository = server.getAddressSettingsRepository();
final String match = address.getLastElement().getValue();
final AddressSettings existingSettings = repository.getMatch(match);
repository.addMatch(match, settings);
if (existingSettings != null) {
handbackHolder.setHandback(new RevertHandback() {
@Override
public void doRevertUpdateToRuntime() {
// Restore the old settings
repository.addMatch(address.getLastElement().getValue(), existingSettings);
}
});
}
}
return false;
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class ImportJournalOperation method createInVMTransportConfiguration.
/**
* The XmlDataImporter requires a connector to connect to the artemis broker.
*
* We require to use a in-vm one so that importing a journal is not subject to any network connection problem.
*/
private TransportConfiguration createInVMTransportConfiguration(OperationContext context) throws OperationFailedException {
final Resource serverResource = context.readResource(EMPTY_ADDRESS, false);
Set<Resource.ResourceEntry> invmConnectors = serverResource.getChildren(CommonAttributes.IN_VM_CONNECTOR);
if (invmConnectors.isEmpty()) {
throw MessagingLogger.ROOT_LOGGER.noInVMConnector();
}
Resource.ResourceEntry connectorEntry = invmConnectors.iterator().next();
Resource connectorResource = context.readResource(PathAddress.pathAddress(connectorEntry.getPathElement()), false);
ModelNode model = connectorResource.getModel();
Map<String, Object> params = new HashMap<>(CommonAttributes.PARAMS.unwrap(context, model));
params.put(InVMTransportDefinition.SERVER_ID.getName(), InVMTransportDefinition.SERVER_ID.resolveModelAttribute(context, model).asInt());
TransportConfiguration transportConfiguration = new TransportConfiguration(InVMConnectorFactory.class.getName(), params);
return transportConfiguration;
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class SecurityDomainAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, final ModelNode model) {
PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
final String securityDomain = address.getLastElement().getValue();
// This needs to run after all child resources so that they can detect a fresh state
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
launchServices(context, securityDomain, Resource.Tools.readModel(resource));
// Rollback handled by the parent step
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
}, OperationContext.Stage.RUNTIME);
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class LogStoreParticipantRefreshHandler method execute.
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
MBeanServer mbs = TransactionExtension.getMBeanServer(context);
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
try {
final ObjectName on = LogStoreResource.getObjectName(resource);
final ModelNode model = resource.getModel().clone();
AttributeList attributes = mbs.getAttributes(on, LogStoreConstants.PARTICIPANT_JMX_NAMES);
for (javax.management.Attribute attribute : attributes.asList()) {
String modelName = LogStoreConstants.jmxNameToModelName(LogStoreConstants.MODEL_TO_JMX_PARTICIPANT_NAMES, attribute.getName());
if (modelName != null) {
ModelNode aNode = model.get(modelName);
Object value = attribute.getValue();
if (aNode != null)
aNode.set(value == null ? "" : value.toString());
}
}
// Replace the model
resource.writeModel(model);
} catch (Exception e) {
throw new OperationFailedException("JMX error: " + e.getMessage());
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of org.jboss.as.controller.registry.Resource in project wildfly by wildfly.
the class LogStoreProbeHandler method addParticipants.
private void addParticipants(final Resource parent, Set<ObjectInstance> participants, MBeanServer mbs) throws IntrospectionException, InstanceNotFoundException, IOException, ReflectionException {
int i = 1;
for (ObjectInstance participant : participants) {
final Resource resource = new LogStoreResource.LogStoreRuntimeResource(participant.getObjectName());
final ModelNode model = resource.getModel();
Map<String, String> pAttributes = getMBeanValues(mbs, participant.getObjectName(), LogStoreConstants.PARTICIPANT_JMX_NAMES);
String pAddress = pAttributes.get(JNDI_PROPNAME);
if (pAddress == null || pAddress.length() == 0) {
pAttributes.put(JNDI_PROPNAME, String.valueOf(i++));
pAddress = pAttributes.get(JNDI_PROPNAME);
}
addAttributes(model, LogStoreConstants.MODEL_TO_JMX_PARTICIPANT_NAMES, pAttributes);
// model.get(LogStoreConstants.JMX_ON_ATTRIBUTE).set(participant.getObjectName().getCanonicalName());
final PathElement element = PathElement.pathElement(LogStoreConstants.PARTICIPANTS, pAddress);
parent.registerChild(element, resource);
}
}
Aggregations