Java Code Examples for org.jboss.as.controller.PathAddress#pathAddress()

The following examples show how to use org.jboss.as.controller.PathAddress#pathAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
void readSecureDeployment(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
    String name = readRequiredAttribute(reader, Constants.XML.NAME);

    PathAddress addr = PathAddress.pathAddress(
            PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, KeycloakSamlExtension.SUBSYSTEM_NAME),
            PathElement.pathElement(Constants.Model.SECURE_DEPLOYMENT, name));
    ModelNode addSecureDeployment = Util.createAddOperation(addr);
    list.add(addSecureDeployment);

    Set<String> parsedElements = new HashSet<>();
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();
        if (parsedElements.contains(tagName)) {
            // all sub-elements of the secure deployment type should occur only once.
            throw ParseUtils.unexpectedElement(reader);
        }
        if (tagName.equals(Constants.XML.SERVICE_PROVIDER)) {
            readServiceProvider(reader, list, addr);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parsedElements.add(tagName);
    }
}
 
Example 2
Source File: DomainApiHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Determine whether the prepared response should be sent, before the operation completed. This is needed in order
 * that operations like :reload() can be executed without causing communication failures.
 *
 * @param operation the operation to be executed
 * @return {@code true} if the prepared result should be sent, {@code false} otherwise
 */
private boolean sendPreparedResponse(final ModelNode operation) {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String op = operation.get(OP).asString();
    final int size = address.size();
    if (size == 0) {
        if (op.equals("reload")) {
            return true;
        } else if (op.equals(COMPOSITE)) {
            // TODO
            return false;
        } else {
            return false;
        }
    } else if (size == 1) {
        if (address.getLastElement().getKey().equals(HOST)) {
            return op.equals("reload");
        }
    }
    return false;
}
 
Example 3
Source File: ReloadRequiredServerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void testChangeServerGroupProfileNoChange(boolean master) throws Exception {
    PathAddress pa = PathAddress.pathAddress(PathElement.pathElement(SERVER_GROUP, "group-one"));
    final MockOperationContext operationContext = getOperationContext(false, pa);

    final ModelNode operation = new ModelNode();
    operation.get(OP_ADDR).set(pa.toModelNode());
    operation.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
    operation.get(NAME).set(PROFILE);
    operation.get(VALUE).set("profile-one");

    try {
        operationContext.executeStep(ServerGroupResourceDefinition.createRestartRequiredHandler(), operation);
    } catch (RuntimeException e) {
        final Throwable t = e.getCause();
        if (t instanceof OperationFailedException) {
            throw (OperationFailedException) t;
        }
        throw e;
    }

    Assert.assertTrue(operationContext.getAttachment(ServerOperationResolver.DONT_PROPAGATE_TO_SERVERS_ATTACHMENT).contains(operation));
    checkServerOperationResolver(operationContext, operation, pa, false);
}
 
Example 4
Source File: ReloadRequiredServerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testChangeServerConfigSocketBindingPortNegativeValue() throws Exception {
    PathAddress pa = PathAddress.pathAddress(PathElement.pathElement(HOST, "localhost"), PathElement.pathElement(SERVER_CONFIG, "server-one"));
    final MockOperationContext operationContext = getOperationContext(false, pa);

    operationContext.root.getChild(PathElement.pathElement(HOST, "localhost")).getChild(PathElement.pathElement(SERVER_CONFIG, "server-one")).getModel().get(SOCKET_BINDING_PORT_OFFSET).set(10);

    final ModelNode operation = new ModelNode();
    operation.get(OP_ADDR).set(pa.toModelNode());
    operation.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
    operation.get(NAME).set(SOCKET_BINDING_PORT_OFFSET);
    operation.get(VALUE).set(-65535);

    ServerRestartRequiredServerConfigWriteAttributeHandler.INSTANCE.execute(operationContext, operation);
    Assert.assertNull(operationContext.getAttachment(ServerOperationResolver.DONT_PROPAGATE_TO_SERVERS_ATTACHMENT));
    checkServerOperationResolver(operationContext, operation, pa, true);
}
 
Example 5
Source File: GenericOutboundConnectionAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
void installRuntimeService(final OperationContext context, final ModelNode operation, final ModelNode fullModel) throws OperationFailedException {
    final PathAddress pathAddress = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String connectionName = pathAddress.getLastElement().getValue();

    // Get the destination URI
    final URI uri = getDestinationURI(context, operation);

    // create the service
    final ServiceName serviceName = OUTBOUND_CONNECTION_CAPABILITY.getCapabilityServiceName(connectionName);
    // also add an alias service name to easily distinguish between a generic, remote and local type of connection services
    final ServiceName aliasServiceName = GenericOutboundConnectionService.GENERIC_OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionName);
    final ServiceName deprecatedServiceName = AbstractOutboundConnectionService.OUTBOUND_CONNECTION_BASE_SERVICE_NAME.append(connectionName);

    final ServiceBuilder<?> builder = context.getServiceTarget().addService(serviceName);
    final Consumer<GenericOutboundConnectionService> serviceConsumer = builder.provides(deprecatedServiceName, aliasServiceName);
    builder.setInstance(new GenericOutboundConnectionService(serviceConsumer, uri));
    builder.requires(RemotingServices.SUBSYSTEM_ENDPOINT);
    builder.install();
}
 
Example 6
Source File: AbstractLoggingSubsystemTest.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static String resolveRelativePath(final KernelServices kernelServices, final String relativeTo) {
    final PathAddress address = PathAddress.pathAddress(PathElement.pathElement(ClientConstants.PATH, relativeTo));
    final ModelNode op = SubsystemOperations.createReadAttributeOperation(address.toModelNode(), ClientConstants.PATH);
    final ModelNode result = kernelServices.executeOperation(op);
    if (SubsystemOperations.isSuccessfulOutcome(result)) {
        return SubsystemOperations.readResultAsString(result);
    }
    return null;
}
 
Example 7
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void readKey(List<ModelNode> list, XMLExtendedStreamReader reader, PathAddress parentAddr) throws XMLStreamException {
    PathAddress addr = PathAddress.pathAddress(parentAddr,
            PathElement.pathElement(Constants.Model.KEY, "key-" + list.size()));
    ModelNode addKey = Util.createAddOperation(addr);
    list.add(addKey);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);

        SimpleAttributeDefinition attr = KeyDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, addKey, reader);
    }

    Set<String> parsedElements = new HashSet<>();
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();
        if (parsedElements.contains(tagName)) {
            // all sub-elements of the key type should occur only once.
            throw ParseUtils.unexpectedElement(reader);
        }

        if (Constants.XML.KEY_STORE.equals(tagName)) {
            readKeyStore(addKey, reader);
        } else if (Constants.XML.PRIVATE_KEY_PEM.equals(tagName)
                || Constants.XML.PUBLIC_KEY_PEM.equals(tagName)
                || Constants.XML.CERTIFICATE_PEM.equals(tagName)) {

            readNoAttrElementContent(KeyDefinition.lookupElement(tagName), addKey, reader);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parsedElements.add(tagName);
    }
}
 
Example 8
Source File: SubsystemDescriptionDump.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    String path = PATH.resolveModelAttribute(context, operation).asString();
    PathAddress profileAddress = PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.PROFILE));
    ImmutableManagementResourceRegistration profileRegistration = context.getResourceRegistration().getSubModel(profileAddress);
    dumpManagementResourceRegistration(profileRegistration, extensionRegistry, path);
}
 
Example 9
Source File: NotificationRegistryTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRegisterAndEmitFromOneLevelResource() {
    // register listener at /subsystem=messaging
    // find listener at /subsystem=messaging
    PathAddress oneLevelAddress = PathAddress.pathAddress("subsystem", "messaging");
    doTestNotificationRegistration(oneLevelAddress, oneLevelAddress, true);

    // do not find listener at /
    doTestNotificationRegistration(oneLevelAddress, PathAddress.EMPTY_ADDRESS, false);

    // do not find listener at /subsystem=web
    PathAddress otherAddress = PathAddress.pathAddress("subsystem", "web");
    doTestNotificationRegistration(oneLevelAddress, otherAddress, false);
}
 
Example 10
Source File: DomainServerGroupTransformersTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRejectKillDestroyTransformers() throws Exception {
    if (modelVersion.getMajor() > 5) {
        return;
    }
    KernelServicesBuilder builder = createKernelServicesBuilder(TestModelType.DOMAIN)
            .setModelInitializer(StandardServerGroupInitializers.XML_MODEL_INITIALIZER, StandardServerGroupInitializers.XML_MODEL_WRITE_SANITIZER)
            .createContentRepositoryContent("12345678901234567890")
            .createContentRepositoryContent("09876543210987654321");

    // Add legacy subsystems
    StandardServerGroupInitializers.addServerGroupInitializers(builder.createLegacyKernelServicesBuilder(modelVersion, testControllerVersion));
    KernelServices mainServices = builder.build();

    PathAddress serverGroupAddress = PathAddress.pathAddress(PathElement.pathElement(SERVER_GROUP));


    OperationTransformer.TransformedOperation transOp;

    //check that we reject /server-group=main-server-group:kill-servers()
    ModelNode killServersOp = Util.createOperation("kill-servers", serverGroupAddress);
    transOp = mainServices.transformOperation(modelVersion, killServersOp);
    Assert.assertTrue(transOp.getFailureDescription(), transOp.rejectOperation(success()));

    //check that we reject /server-group=main-server-group:destroy-servers()
    ModelNode destroyServersOp = Util.createOperation("destroy-servers", serverGroupAddress);
    transOp = mainServices.transformOperation(modelVersion, destroyServersOp);
    Assert.assertTrue(transOp.getFailureDescription(), transOp.rejectOperation(success()));
}
 
Example 11
Source File: SubsystemMarshaller.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public void marshal(List<ModelNode> list) {
    for (Fraction each : this.fractions) {

        MarshalDMR anno = each.getClass().getAnnotation(MarshalDMR.class);

        if (anno != null) {
            try {
                try (AutoCloseable handle = Performance.time("marshall " + each.getClass().getSimpleName())) {
                    LinkedList<ModelNode> subList = Marshaller.marshal(each);
                    if (!isAlreadyConfigured(subList, list)) {
                        list.addAll(subList);
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {
            WildFlySubsystem subsysAnno = each.getClass().getAnnotation(WildFlySubsystem.class);

            if (subsysAnno != null) {
                PathAddress address = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, subsysAnno.value()));
                if (!isAlreadyConfigured(address.toModelNode(), list)) {
                    ModelNode node = new ModelNode();
                    node.get(OP_ADDR).set(address.toModelNode());
                    node.get(OP).set(ADD);
                    list.add(node);
                }
            }
        }
    }

}
 
Example 12
Source File: MainKernelServicesImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ModelNode readTransformedModel(ModelVersion modelVersion) {
    checkIsMainController();

    ModelNode domainModel = new ModelNode();
    //Reassemble the model from the reead master domain model handler result
    for (ModelNode entry : callReadMasterDomainModelHandler(modelVersion).asList()) {
        PathAddress address = PathAddress.pathAddress(entry.require("domain-resource-address"));
        ModelNode toSet = domainModel;
        for (PathElement pathElement : address) {
            toSet = toSet.get(pathElement.getKey(), pathElement.getValue());
        }
        toSet.set(entry.require("domain-resource-model"));
    }
    return domainModel;
}
 
Example 13
Source File: OperationTimeoutTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void restoreServerTimeouts(String host, String server) throws IOException, MgmtOperationException {
    PathAddress pa = PathAddress.pathAddress(PathElement.pathElement(HOST, host), PathElement.pathElement(SERVER_CONFIG, server));
    ModelNode op = Util.createAddOperation(pa.append(PathAddress.pathAddress(SYSTEM_PROPERTY, "jboss.as.management.blocking.timeout")));
    op.get(VALUE).set("300");
    executeForResult(safeTimeout(op), masterClient);

    op.get(OP_ADDR).set(pa.append(PathAddress.pathAddress(SYSTEM_PROPERTY, "org.wildfly.unsupported.test.domain-timeout-adder")).toModelNode());
    op.get(VALUE).set("5000");
    executeForResult(safeTimeout(op), masterClient);
}
 
Example 14
Source File: UtilTest.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test of getResourceRemoveOperation method, of class Util.
 */
@Test
public void testGetResourceRemoveOperation() {
    PathAddress address = PathAddress.pathAddress("subsystem", "test");
    ModelNode operation = Util.getResourceRemoveOperation(address);
    assertThat(operation.hasDefined(OP), is(true));
    assertThat(operation.get(OP).asString(), is(REMOVE));
    assertThat(operation.hasDefined(OP_ADDR), is(true));
    assertThat(operation.get(OP_ADDR), is(address.toModelNode()));
    operation = Util.getResourceRemoveOperation(null);
    assertThat(operation.hasDefined(OP), is(true));
    assertThat(operation.get(OP).asString(), is(REMOVE));
    assertThat(operation.hasDefined(OP_ADDR), is(false));
}
 
Example 15
Source File: ModelContentReferenceTest.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test of fromDeploymentName method, of class ModelContentReference.
 */
@Test
public void testFromDeploymentName_String_byteArr() {
    String name = "wildfly-ejb-in-war.war";
    byte[] hash = HashUtil.hexStringToByteArray("48d7b49e084860769d5ce03dc2223466aa46be3a");
    PathAddress address = PathAddress.pathAddress(PathElement.pathElement("deployment", "wildfly-ejb-in-war.war"));
    ContentReference result = ModelContentReference.fromDeploymentName(name, hash);
    ContentReference expResult = new ContentReference(address.toCLIStyleString(), "48d7b49e084860769d5ce03dc2223466aa46be3a");
    assertThat(result, is(expResult));
}
 
Example 16
Source File: PathAddressValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException {
    try {
        PathAddress.pathAddress(value);
    } catch (IllegalArgumentException iae) {
        throw ControllerLogger.MGMT_OP_LOGGER.invalidAddressFormat(value);
    }
}
 
Example 17
Source File: UtilTest.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test of createOperation method, of class Util.
 */
@Test
public void testCreateOperationWithNamePathAddress() {
    String operationName = "fake";
    PathAddress address = PathAddress.pathAddress("subsystem", "test");
    ModelNode operation = Util.createOperation(operationName, address);
    assertThat(operation.hasDefined(OP), is(true));
    assertThat(operation.get(OP).asString(), is(operationName));
    assertThat(operation.hasDefined(OP_ADDR), is(true));
    assertThat(operation.get(OP_ADDR), is(address.toModelNode()));
}
 
Example 18
Source File: AbstractSystemPropertyTransformersTest.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testSystemPropertyTransformer() throws Exception {
    KernelServicesBuilder builder = createKernelServicesBuilder(TestModelType.DOMAIN)
            .setXmlResource(serverGroup ? "domain-servergroup-systemproperties.xml" : "domain-systemproperties.xml");
    if (serverGroup) {
        builder.setModelInitializer(StandardServerGroupInitializers.XML_MODEL_INITIALIZER, StandardServerGroupInitializers.XML_MODEL_WRITE_SANITIZER);
    }

    LegacyKernelServicesInitializer legacyInitializer = builder.createLegacyKernelServicesBuilder(modelVersion, testControllerVersion);
    if (serverGroup) {
        StandardServerGroupInitializers.addServerGroupInitializers(legacyInitializer);
    }

    KernelServices mainServices = builder.build();
    Assert.assertTrue(mainServices.isSuccessfulBoot());

    KernelServices legacyServices = mainServices.getLegacyServices(modelVersion);
    Assert.assertTrue(legacyServices.isSuccessfulBoot());

    ModelFixer fixer = new StandardServerGroupInitializers.Fixer(modelVersion);
    ModelNode legacyModel = checkCoreModelTransformation(mainServices, modelVersion, fixer, fixer);
    ModelNode properties = legacyModel;
    if (serverGroup) {
        properties = legacyModel.get(SERVER_GROUP, "test");
    }
    properties = properties.get(SYSTEM_PROPERTY);
    Assert.assertEquals(expectedUndefined, properties.get("sys.prop.test.one", BOOT_TIME));
    Assert.assertEquals(1, properties.get("sys.prop.test.one", VALUE).asInt());
    Assert.assertEquals(ModelNode.TRUE, properties.get("sys.prop.test.two", BOOT_TIME));
    Assert.assertEquals(2, properties.get("sys.prop.test.two", VALUE).asInt());
    Assert.assertEquals(ModelNode.FALSE, properties.get("sys.prop.test.three", BOOT_TIME));
    Assert.assertEquals(3, properties.get("sys.prop.test.three", VALUE).asInt());
    Assert.assertEquals(expectedUndefined, properties.get("sys.prop.test.four", BOOT_TIME));
    Assert.assertFalse(properties.get("sys.prop.test.four", VALUE).isDefined());

    //Test the write attribute handler, the 'add' got tested at boot time
    PathAddress baseAddress = serverGroup ? PathAddress.pathAddress(PathElement.pathElement(SERVER_GROUP, "test")) : PathAddress.EMPTY_ADDRESS;
    PathAddress propAddress = baseAddress.append(SYSTEM_PROPERTY, "sys.prop.test.two");
    //value should just work
    ModelNode op = Util.getWriteAttributeOperation(propAddress, VALUE, new ModelNode("test12"));
    ModelTestUtils.checkOutcome(mainServices.executeOperation(modelVersion, mainServices.transformOperation(modelVersion, op)));
    Assert.assertEquals("test12", ModelTestUtils.getSubModel(legacyServices.readWholeModel(), propAddress).get(VALUE).asString());

    //boot time should be 'true' if undefined
    op = Util.getWriteAttributeOperation(propAddress, BOOT_TIME, new ModelNode());
    ModelTestUtils.checkOutcome(mainServices.executeOperation(modelVersion, mainServices.transformOperation(modelVersion, op)));
    Assert.assertTrue(ModelTestUtils.getSubModel(legacyServices.readWholeModel(), propAddress).get(BOOT_TIME).asBoolean());
    op = Util.getUndefineAttributeOperation(propAddress, BOOT_TIME);
    ModelTestUtils.checkOutcome(mainServices.executeOperation(modelVersion, mainServices.transformOperation(modelVersion, op)));
    Assert.assertTrue(ModelTestUtils.getSubModel(legacyServices.readWholeModel(), propAddress).get(BOOT_TIME).asBoolean());
}
 
Example 19
Source File: AbstractLoggingSubsystemTest.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static PathAddress createAddress(final String resourceKey, final String resourceName) {
    return PathAddress.pathAddress(
            SUBSYSTEM_PATH,
            PathElement.pathElement(resourceKey, resourceName)
    );
}
 
Example 20
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 4 votes vote down vote up
void readIdentityProvider(List<ModelNode> list, XMLExtendedStreamReader reader, PathAddress parentAddr) throws XMLStreamException {
    String entityId = readRequiredAttribute(reader, Constants.XML.ENTITY_ID);

    PathAddress addr = PathAddress.pathAddress(parentAddr,
            PathElement.pathElement(Constants.Model.IDENTITY_PROVIDER, entityId));
    ModelNode addIdentityProvider = Util.createAddOperation(addr);
    list.add(addIdentityProvider);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);

        if (Constants.XML.ENTITY_ID.equals(name)
                // don't break if encountering this noop attr from client-adapter/core keycloak_saml_adapter_1_6.xsd
                || "encryption".equals(name)) {
            continue;
        }
        SimpleAttributeDefinition attr = IdentityProviderDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, addIdentityProvider, reader);
    }

    Set<String> parsedElements = new HashSet<>();
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();
        if (parsedElements.contains(tagName)) {
            // all sub-elements of the identity provider type should occur only once.
            throw ParseUtils.unexpectedElement(reader);
        }

        if (Constants.XML.SINGLE_SIGN_ON.equals(tagName)) {
            readSingleSignOn(addIdentityProvider, reader);
        } else if (Constants.XML.SINGLE_LOGOUT.equals(tagName)) {
            readSingleLogout(addIdentityProvider, reader);
        } else if (Constants.XML.KEYS.equals(tagName)) {
            readKeys(list, reader, addr);
        } else if (Constants.XML.HTTP_CLIENT.equals(tagName)) {
            readHttpClient(addIdentityProvider, reader);
        } else if (Constants.XML.ALLOWED_CLOCK_SKEW.equals(tagName)) {
            readAllowedClockSkew(addIdentityProvider, reader);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parsedElements.add(tagName);
    }
}