Search in sources :

Example 21 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class XTSSubsystemTestCase method testBoot1_1_0.

private void testBoot1_1_0(ModelTestControllerVersion controllerVersion) throws Exception {
    String subsystemXml = readResource("subsystem.xml");
    ModelVersion modelVersion = ModelVersion.create(1, 1, 0);
    //Use the non-runtime version of the extension which will happen on the HC
    KernelServicesBuilder builder = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT).setSubsystemXml(subsystemXml);
    builder.createLegacyKernelServicesBuilder(null, controllerVersion, modelVersion).configureReverseControllerCheck(AdditionalInitialization.MANAGEMENT, null, new OperationFixer() {

        @Override
        public ModelNode fixOperation(ModelNode operation) {
            String name = operation.get(ModelDescriptionConstants.OP).asString();
            PathAddress addr = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
            if (name.equals(ModelDescriptionConstants.ADD) && addr.size() == 1 && addr.getElement(0).equals(XTSExtension.SUBSYSTEM_PATH)) {
                operation.get(ModelDescriptionConstants.HOST).set("default-host");
                operation.get(XTSSubsystemDefinition.DEFAULT_CONTEXT_PROPAGATION.getName()).set(false);
            }
            return operation;
        }
    }).addMavenResourceURL("org.jboss.as:jboss-as-xts:" + controllerVersion.getMavenGavVersion());
    KernelServices mainServices = builder.build();
    KernelServices legacyServices = mainServices.getLegacyServices(modelVersion);
    Assert.assertTrue(mainServices.isSuccessfulBoot());
    Assert.assertTrue(legacyServices.isSuccessfulBoot());
    checkSubsystemModelTransformation(mainServices, modelVersion);
}
Also used : OperationFixer(org.jboss.as.model.test.OperationFixer) PathAddress(org.jboss.as.controller.PathAddress) KernelServices(org.jboss.as.subsystem.test.KernelServices) ModelVersion(org.jboss.as.controller.ModelVersion) ModelNode(org.jboss.dmr.ModelNode) KernelServicesBuilder(org.jboss.as.subsystem.test.KernelServicesBuilder)

Example 22 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class ProtocolResourceRegistrationHandler method findProtocol.

@Override
public Protocol findProtocol(OperationContext context) throws ClassNotFoundException, ModuleLoadException {
    PathAddress address = context.getCurrentAddress();
    String channelName = address.getParent().getLastElement().getValue();
    String protocolName = address.getLastElement().getValue();
    ServiceRegistry registry = context.getServiceRegistry(false);
    ServiceController<?> controller = registry.getService(JGroupsRequirement.CHANNEL.getServiceName(context, channelName));
    if (controller != null) {
        Channel channel = (Channel) controller.getValue();
        if (channel != null) {
            controller = registry.getService(JGroupsRequirement.CHANNEL_SOURCE.getServiceName(context, channelName));
            ChannelFactory factory = (ChannelFactory) controller.getValue();
            if (factory != null) {
                ProtocolStackConfiguration configuration = factory.getProtocolStackConfiguration();
                ProtocolConfiguration<? extends TP> transport = configuration.getTransport();
                if (transport.getName().equals(protocolName)) {
                    Class<? extends Protocol> protocolClass = transport.createProtocol().getClass();
                    return channel.getProtocolStack().findProtocol(protocolClass);
                }
                for (ProtocolConfiguration<? extends Protocol> protocol : configuration.getProtocols()) {
                    if (protocol.getName().equals(protocolName)) {
                        Class<? extends Protocol> protocolClass = protocol.createProtocol().getClass();
                        return channel.getProtocolStack().findProtocol(protocolClass);
                    }
                }
            }
        }
    }
    return null;
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) Channel(org.jgroups.Channel) ProtocolStackConfiguration(org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory)

Example 23 with PathAddress

use of org.jboss.as.controller.PathAddress 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);
}
Also used : RemoteSiteConfiguration(org.wildfly.clustering.jgroups.spi.RemoteSiteConfiguration) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource)

Example 24 with PathAddress

use of org.jboss.as.controller.PathAddress in project wildfly by wildfly.

the class RemoteSiteResourceDefinition method buildTransformation.

@SuppressWarnings("deprecation")
static void buildTransformation(ModelVersion version, ResourceTransformationDescriptionBuilder parent) {
    ResourceTransformationDescriptionBuilder builder = parent.addChildResource(WILDCARD_PATH);
    if (JGroupsModel.VERSION_3_0_0.requiresTransformation(version)) {
        AttributeConverter converter = new AttributeConverter() {

            @Override
            public void convertOperationParameter(PathAddress address, String name, ModelNode value, ModelNode operation, TransformationContext context) {
            // Nothing to convert
            }

            @Override
            public void convertResourceAttribute(PathAddress address, String name, ModelNode value, TransformationContext context) {
                ModelNode remoteSite = context.readResourceFromRoot(address).getModel();
                String channelName = remoteSite.get(Attribute.CHANNEL.getName()).asString();
                if (DeprecatedAttribute.STACK.getName().equals(name)) {
                    PathAddress subsystemAddress = address.subAddress(0, address.size() - 3);
                    PathAddress channelAddress = subsystemAddress.append(ChannelResourceDefinition.pathElement(channelName));
                    ModelNode channel = context.readResourceFromRoot(channelAddress).getModel();
                    if (channel.hasDefined(ChannelResourceDefinition.Attribute.STACK.getName())) {
                        value.set(channel.get(ChannelResourceDefinition.Attribute.STACK.getName()).asString());
                    } else {
                        ModelNode subsystem = context.readResourceFromRoot(subsystemAddress).getModel();
                        value.set(subsystem.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK.getName()).asString());
                    }
                } else if (DeprecatedAttribute.CLUSTER.getName().equals(name)) {
                    value.set(channelName);
                } else {
                    throw new IllegalStateException();
                }
            }
        };
        builder.getAttributeBuilder().setValueConverter(converter, DeprecatedAttribute.STACK.getDefinition(), DeprecatedAttribute.CLUSTER.getDefinition()).setDiscard(DiscardAttributeChecker.ALWAYS, Attribute.CHANNEL.getDefinition()).end();
    }
}
Also used : AttributeConverter(org.jboss.as.controller.transform.description.AttributeConverter) PathAddress(org.jboss.as.controller.PathAddress) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) ModelNode(org.jboss.dmr.ModelNode) TransformationContext(org.jboss.as.controller.transform.TransformationContext)

Example 25 with PathAddress

use of org.jboss.as.controller.PathAddress 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);
    }
}
Also used : Locale(java.util.Locale) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) PlaceholderResource(org.jboss.as.controller.registry.PlaceholderResource) OverrideDescriptionProvider(org.jboss.as.controller.descriptions.OverrideDescriptionProvider) StandardResourceDescriptionResolver(org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) RELAY2(org.jgroups.protocols.relay.RELAY2)

Aggregations

PathAddress (org.jboss.as.controller.PathAddress)644 ModelNode (org.jboss.dmr.ModelNode)492 Resource (org.jboss.as.controller.registry.Resource)70 Test (org.junit.Test)66 PathElement (org.jboss.as.controller.PathElement)63 KernelServices (org.jboss.as.subsystem.test.KernelServices)51 ServiceName (org.jboss.msc.service.ServiceName)51 OperationFailedException (org.jboss.as.controller.OperationFailedException)43 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)35 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)35 FailedOperationTransformationConfig (org.jboss.as.model.test.FailedOperationTransformationConfig)34 KernelServicesBuilder (org.jboss.as.subsystem.test.KernelServicesBuilder)33 ServiceTarget (org.jboss.msc.service.ServiceTarget)32 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)31 Map (java.util.Map)30 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)29 IOException (java.io.IOException)28 ResourceTransformationDescriptionBuilder (org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder)26 ArrayList (java.util.ArrayList)25 OperationContext (org.jboss.as.controller.OperationContext)23