Search in sources :

Example 16 with Resource

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;
}
Also used : ActiveMQActivationService.getActiveMQServer(org.wildfly.extension.messaging.activemq.ActiveMQActivationService.getActiveMQServer) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 17 with Resource

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;
}
Also used : HashMap(java.util.HashMap) Resource(org.jboss.as.controller.registry.Resource) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) ModelNode(org.jboss.dmr.ModelNode)

Example 18 with Resource

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);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 19 with Resource

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);
}
Also used : AttributeList(javax.management.AttributeList) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 20 with Resource

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);
    }
}
Also used : PathElement(org.jboss.as.controller.PathElement) ObjectInstance(javax.management.ObjectInstance) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

Resource (org.jboss.as.controller.registry.Resource)93 PathAddress (org.jboss.as.controller.PathAddress)52 ModelNode (org.jboss.dmr.ModelNode)52 PathElement (org.jboss.as.controller.PathElement)25 OperationFailedException (org.jboss.as.controller.OperationFailedException)24 OperationContext (org.jboss.as.controller.OperationContext)15 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)12 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)11 Map (java.util.Map)10 ServiceName (org.jboss.msc.service.ServiceName)10 ServiceTarget (org.jboss.msc.service.ServiceTarget)10 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)9 ResourceTransformationContext (org.jboss.as.controller.transform.ResourceTransformationContext)6 ResourceTransformer (org.jboss.as.controller.transform.ResourceTransformer)6 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)6 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)6 ObjectName (javax.management.ObjectName)5 Activation (org.jboss.jca.common.api.metadata.resourceadapter.Activation)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5 ArrayList (java.util.ArrayList)4