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

The following examples show how to use org.jboss.as.controller.PathAddress#append() . 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: ChildFirstClassLoaderKernelServicesFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void populateModel(ManagementModel managementModel) {
    populateModel(managementModel.getRootResource());
    for (LegacyModelInitializerEntry entry : entries) {
        if (entry.getCapabilities() != null) {
            PathAddress parent = entry.getParentAddress();
            if (parent == null) {
                parent = PathAddress.EMPTY_ADDRESS;
            }
            PathAddress pa = parent.append(entry.getRelativeResourceAddress());
            CapabilityScope scope = CapabilityScope.Factory.create(ProcessType.HOST_CONTROLLER, pa);
            RuntimeCapabilityRegistry cr = managementModel.getCapabilityRegistry();

            for (String capabilityName : entry.getCapabilities()) {
                RuntimeCapability<Void> capability =
                        RuntimeCapability.Builder.of(capabilityName).build();
                RuntimeCapabilityRegistration reg = new RuntimeCapabilityRegistration(capability, scope,
                        new RegistrationPoint(pa, null));
                cr.registerCapability(reg);
            }
        }
    }
}
 
Example 2
Source File: ManagedServerOperationsFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void convertApplicationClassificationConstraints(ModelNode model, ModelNode baseAddress, ModelNodeList updates) {
    PathAddress constraintAddress = PathAddress.pathAddress(baseAddress).append(CONSTRAINT, APPLICATION_CLASSIFICATION);
    if (model.hasDefined(TYPE)) {
        for (Property prop : model.get(TYPE).asPropertyList()) {
            PathAddress constraintTypeAddress = constraintAddress.append(TYPE, prop.getName());
            if (prop.getValue().hasDefined(CLASSIFICATION)) {
                for (Property classification : prop.getValue().get(CLASSIFICATION).asPropertyList()) {
                    PathAddress classificationAddress = constraintTypeAddress.append(CLASSIFICATION, classification.getName());
                    if (classification.getValue().hasDefined(CONFIGURED_APPLICATION)) {
                        ModelNode addOp = Util.getWriteAttributeOperation(classificationAddress, CONFIGURED_APPLICATION, classification.getValue().get(CONFIGURED_APPLICATION).asBoolean());
                        updates.add(addOp);
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: OperationTimeoutTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void validateTimeoutProperties(String host, String server, String baseTimeout, String domainAdder) throws IOException, MgmtOperationException {
    PathAddress pa = PathAddress.pathAddress(HOST, host);
    if (server != null) {
        pa = pa.append(RUNNING_SERVER, server);
    }
    ModelNode op = Util.getReadAttributeOperation(pa.append(RUNTIME_MXBEAN), "system-properties");
    ModelNode props = executeForResult(op, masterClient);
    if (baseTimeout == null) {
        assertFalse(props.toString(), props.hasDefined("jboss.as.management.blocking.timeout"));
    } else {
        assertEquals(props.toString(), baseTimeout, props.get("jboss.as.management.blocking.timeout").asString());
    }
    if (domainAdder == null) {
        assertFalse(props.toString(), props.hasDefined("org.wildfly.unsupported.test.domain-timeout-adder"));
    } else {
        assertEquals(props.toString(), domainAdder, props.get("org.wildfly.unsupported.test.domain-timeout-adder").asString());
    }
}
 
Example 4
Source File: WildflyCompatibilityUtils.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
private static PathAddress addpathAddressElement(PathAddress parsedAddress, String address,
        StringBuilder keyBuffer, StringBuilder valueBuffer) {
    if (keyBuffer.length() > 0) {
        if (valueBuffer.length() > 0) {
            return parsedAddress.append(PathElement.pathElement(keyBuffer.toString(), valueBuffer.toString()));
        }
        // https://github.com/wildfly/wildfly-core/blob/588145a00ca5ed3beb0027f8f44be87db6689db3/controller/src/main/java/org/jboss/as/controller/logging/ControllerLogger.java#L3296-L3297
        throw new IllegalArgumentException(
                "Illegal path address '" + address + "' , it is not in a correct CLI format");
    }
    return parsedAddress;
}
 
Example 5
Source File: OperationCancellationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void validateNoActiveOperation(DomainClient client, String host, String server) throws Exception {

        PathAddress baseAddress = getManagementControllerAddress(host, server);

        // The op should clear w/in a few ms but we'll wait up to 5 secs just in case
        // something strange is happening on the machine is overloaded
        long timeout = System.currentTimeMillis() + TimeoutUtil.adjust(5000);
        MgmtOperationException failure;
        do {
            String id = findActiveOperation(client, baseAddress, "block");
            if (id == null) {
                return;
            }
            failure = null;
            PathAddress address = baseAddress.append(PathElement.pathElement(ACTIVE_OPERATION, id));
            ModelNode op = Util.createEmptyOperation(READ_ATTRIBUTE_OPERATION, address);
            op.get(NAME).set(OP);
            try {
                executeForFailure(op, client);
            } catch (MgmtOperationException moe) {
                failure = moe;
            }
            Thread.sleep(50);
        } while (System.currentTimeMillis() < timeout);

        throw failure;
    }
 
Example 6
Source File: RemotingTransformers.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
    ModelNode transformed;
    ModelNode trimmedAdd = null;
    ModelNode endPointAdd = null;
    for (AttributeDefinition ad : RemotingEndpointResource.ATTRIBUTES.values()) {
        String adName = ad.getName();
        if (operation.hasDefined(adName)) {
            if (endPointAdd == null) {
                trimmedAdd = operation.clone();
                PathAddress endpointAddress = address.append(RemotingEndpointResource.ENDPOINT_PATH);
                endPointAdd = Util.createEmptyOperation(operation.get(OP).asString(), endpointAddress);
            }
            endPointAdd.get(adName).set(operation.get(adName));
            trimmedAdd.remove(adName);
        }
    }
    if (endPointAdd != null) {
        transformed = Util.createEmptyOperation(COMPOSITE, PathAddress.EMPTY_ADDRESS);
        ModelNode steps = transformed.get(STEPS);
        steps.add(trimmedAdd);
        steps.add(endPointAdd);
    } else {
        transformed = operation;
    }
    return new TransformedOperation(transformed, OperationResultTransformer.ORIGINAL_RESULT);
}
 
Example 7
Source File: OperationTransformationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void testPropertiesModel() throws Exception {
    final DomainClient client = master.getDomainClient();
    final DomainClient slaveClient = slave.getDomainClient();

    final PathAddress address = PathAddress.pathAddress(PathElement.pathElement(PROFILE, "default"));

    // Test the properties model
    final PathAddress properties = address.append(PathElement.pathElement(SUBSYSTEM, VersionedExtensionCommon.SUBSYSTEM_NAME));

    final ModelNode writePropertiesInt = writeAttribute(properties, "int", "${org.jboss.domain.tests.int:1}");
    executeForFailure(writePropertiesInt, client);
    // Check both master and slave
    Assert.assertFalse(executeForResult(readAttribute(properties, "int"), client).isDefined());
    Assert.assertFalse(executeForResult(readAttribute(properties, "int"), slaveClient).isDefined());

    final ModelNode writePropertiesString = writeAttribute(properties, "string", "${org.jboss.domain.tests.string:abc}");
    executeForFailure(writePropertiesString, client);
    // Check both master and slave
    Assert.assertFalse(executeForResult(readAttribute(properties, "string"), client).isDefined());
    Assert.assertFalse(executeForResult(readAttribute(properties, "string"), slaveClient).isDefined());

    // Test the ignored model
    final PathAddress ignored = PathAddress.pathAddress(PathElement.pathElement(PROFILE, "ignored"), PathElement.pathElement(SUBSYSTEM, VersionedExtensionCommon.SUBSYSTEM_NAME));

    final ModelNode writeIgnoredString = writeAttribute(ignored, "string", "${org.jboss.domain.tests.string:abc}");
    executeForResult(writeIgnoredString, client);
    Assert.assertTrue(executeForResult(readAttribute(ignored, "string"), client).isDefined());
    executeForFailure(readAttribute(ignored, "string"), slaveClient);

    final ModelNode writeIgnoredInt = writeAttribute(ignored, "int", "${org.jboss.domain.tests.int:1}");
    executeForResult(writeIgnoredInt, client);
    Assert.assertTrue(executeForResult(readAttribute(ignored, "int"), client).isDefined());
    executeForFailure(readAttribute(ignored, "int"), slaveClient);
}
 
Example 8
Source File: SyncModelOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
Node getOrCreate(final PathElement element, final Iterator<PathElement> i, PathAddress current,
                 OrderedChildTypesAttachment orderedChildTypesAttachment) {

    if (i.hasNext()) {
        final PathElement next = i.next();
        final PathAddress addr = current.append(next);
        Map<PathElement, Node> children = childrenByType.get(next.getKey());
        if (children == null) {
            children = new LinkedHashMap<PathElement, SyncModelOperationHandler.Node>();
            childrenByType.put(next.getKey(), children);
        }
        Node node = children.get(next);
        if (node == null) {
            node = new Node(next, addr);
            children.put(next, node);
            Set<String> orderedChildTypes = orderedChildTypesAttachment.getOrderedChildTypes(addr);
            if (orderedChildTypes != null) {
                node.orderedChildTypes.addAll(orderedChildTypes);
            }
        }
        return node.getOrCreate(next, i, addr, orderedChildTypesAttachment);
    } else if (element == null) {
        throw new IllegalStateException();
    } else {
        if (address.equals(current)) {
            return this;
        } else {
            throw new IllegalStateException(current.toString());
        }
    }
}
 
Example 9
Source File: ManagementXml_5.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void parseIdentity(final XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> list) throws XMLStreamException {
    PathAddress operationAddress = PathAddress.pathAddress(address);
    operationAddress = operationAddress.append(AccessIdentityResourceDefinition.PATH_ELEMENT);
    final ModelNode add = Util.createAddOperation(PathAddress.pathAddress(operationAddress));
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case SECURITY_DOMAIN: {
                    AccessIdentityResourceDefinition.SECURITY_DOMAIN.parseAndSetParameter(value, add, reader);
                    break;
                }
                default: {
                    throw unexpectedAttribute(reader, i);
                }
            }
        }
    }
    list.add(add);
    if(reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        throw unexpectedElement(reader);
   }
}
 
Example 10
Source File: JmxAuditLogHandlerReferenceResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean lookForHandler(PathAddress rootAddress, Resource root, String name) {
    PathAddress addr = rootAddress.append(
                            CoreManagementResourceDefinition.PATH_ELEMENT,
                            AccessAuditResourceDefinition.PATH_ELEMENT);
    PathAddress referenceAddress = addr.append(FILE_HANDLER, name);
    if (lookForResource(root, referenceAddress)) {
        return true;
    }
    referenceAddress  = addr.append(SYSLOG_HANDLER, name);
    return lookForResource(root, referenceAddress);
}
 
Example 11
Source File: AbstractLoggingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static ModelNode createAddress(final String... paths) {
    PathAddress address = SUBSYSTEM_ADDRESS;
    for (int i = 0; i < paths.length; i++) {
        final String key = paths[i];
        if (++i < paths.length) {
            address = address.append(PathElement.pathElement(key, paths[i]));
        } else {
            address = address.append(PathElement.pathElement(key));
        }
    }
    return address.toModelNode();
}
 
Example 12
Source File: WildcardOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testSpecificResourceOperationsUnderServer() throws IOException, MgmtOperationException {
    PathAddress servers = PathAddress.pathAddress(HOST, WILDCARD).append(RUNNING_SERVER, WILDCARD);

    PathAddress publicInterface = servers.append(INTERFACE, "public");
    executeReadResource(publicInterface.toModelNode(), domainMasterLifecycleUtil.getDomainClient());
    executeReadResourceDescription(publicInterface.toModelNode(), domainMasterLifecycleUtil.getDomainClient());

    PathAddress jmxSubsystem = servers.append(SUBSYSTEM, "jmx");
    executeReadResource(jmxSubsystem.toModelNode(), domainMasterLifecycleUtil.getDomainClient());
    executeReadResourceDescription(jmxSubsystem.toModelNode(), domainMasterLifecycleUtil.getDomainClient());
}
 
Example 13
Source File: OperationErrorTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static PathAddress getManagementControllerAddress(String host, String server) {
    PathAddress address = PathAddress.pathAddress(PathElement.pathElement(HOST, host));
    if (server != null) {
        address = address.append(PathElement.pathElement(SERVER, server));
    }
    address = address.append(MGMT_CONTROLLER);
    return address;
}
 
Example 14
Source File: SyslogAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void createServerAddOperations(List<ModelNode> addOps, PathAddress syslogHandlerAddress, ModelNode syslogHandler) {
    ModelNode syslogHandlerAdd = createServerAddOperation(syslogHandlerAddress, syslogHandler);
    addOps.add(syslogHandlerAdd);

    Property protocol = syslogHandler.get(PROTOCOL).asPropertyList().iterator().next();
    PathAddress protocolAddress = syslogHandlerAddress.append(PathElement.pathElement(PROTOCOL, protocol.getName()));
    SyslogAuditLogProtocolResourceDefinition.createServerAddOperations(addOps, protocolAddress, protocol.getValue());
}
 
Example 15
Source File: CoreResourceManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode getPropertyAddress(ModelNode basePropAddress, String propName) {
    PathAddress addr = PathAddress.pathAddress(basePropAddress);
    PathAddress copy = PathAddress.EMPTY_ADDRESS;
    for (PathElement element : addr) {
        if (!element.getKey().equals(SYSTEM_PROPERTY)) {
            copy = copy.append(element);
        } else {
            copy = copy.append(PathElement.pathElement(SYSTEM_PROPERTY, propName));
        }
    }
    return copy.toModelNode();
}
 
Example 16
Source File: ServerOperationResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Map<Set<ServerIdentity>, ModelNode> resolveCoreServiceOperations(ModelNode operation, PathAddress address, ModelNode domain, ModelNode host) {
    if (MANAGEMENT.equals(address.getElement(0).getValue()) && address.size() >= 2) {
        ModelNode op = operation.clone();
        switch (address.getElement(1).getKey()) {
            case ACCESS:
                if (AUDIT.equals(address.getElement(1).getValue())) {
                    op.get(OP_ADDR).set(address.toModelNode());
                    if (address.size() >= 3) {
                        PathAddress newAddr = PathAddress.EMPTY_ADDRESS;
                        for (PathElement element : address) {
                            if (LOGGER.equals(element.getKey())) {
                                //logger=>audit-log is only for the HC
                                return Collections.emptyMap();
                            } else {
                                PathElement myElement = element;
                                if (SERVER_LOGGER.equals(myElement.getKey())) {
                                    //server-logger=audit-log gets sent to the servers as logger=>audit-log
                                    myElement = PathElement.pathElement(LOGGER, element.getValue());
                                }
                                newAddr = newAddr.append(myElement);
                            }
                        }
                        op.get(OP_ADDR).set(newAddr.toModelNode());
                    }
                    return Collections.singletonMap(getAllRunningServers(host, localHostName, serverProxies), op);
                }
                break;
            case SERVICE:
                if (CONFIGURATION_CHANGES.equals(address.getElement(1).getValue())) {
                    if ("list-changes".equals(operation.get(OP).asString())) {
                        return Collections.emptyMap();
                    }
                    op.get(OP_ADDR).set(address.toModelNode());
                    return Collections.singletonMap(getAllRunningServers(host, localHostName, serverProxies), op);
                }
                break;
            case SECURITY_REALM:
                op.get(OP_ADDR).set(address.toModelNode());
                return Collections.singletonMap(getAllRunningServers(host, localHostName, serverProxies), op);
            default:
                return Collections.emptyMap();
        }
    }
    return Collections.emptyMap();
}
 
Example 17
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 18
Source File: BasicResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testDynamicDiscardRedirectOperations() throws Exception {
    PathAddress subsystem = PathAddress.pathAddress("toto", "testSubsystem");

    final PathAddress keepNewAddress = subsystem.append("dynamic-redirect-new", "keep");
    final PathAddress keepOriginalAddress = subsystem.append("dynamic-redirect-original", "keep");
    final ModelNode opKeep = Util.createAddOperation(keepOriginalAddress);
    opKeep.get("attribute").set("keep");
    OperationTransformer.TransformedOperation txKeep = transformOperation(ModelVersion.create(1), opKeep.clone());
    Assert.assertFalse(txKeep.rejectOperation(success()));
    Assert.assertNotNull(txKeep.getTransformedOperation());
    Assert.assertEquals("KEEP", txKeep.getTransformedOperation().get("attribute").asString());
    Assert.assertEquals(keepNewAddress, PathAddress.pathAddress(txKeep.getTransformedOperation().get(OP_ADDR)));
    txKeep = transformOperation(ModelVersion.create(1, 0, 1), opKeep.clone());
    Assert.assertFalse(txKeep.rejectOperation(success()));
    Assert.assertNotNull(txKeep.getTransformedOperation());
    Assert.assertEquals("KEEP", txKeep.getTransformedOperation().get("attribute").asString());
    Assert.assertEquals(keepNewAddress, PathAddress.pathAddress(txKeep.getTransformedOperation().get(OP_ADDR)));
    txKeep = transformOperation(ModelVersion.create(1, 0, 5), opKeep.clone());
    Assert.assertFalse(txKeep.rejectOperation(success()));
    Assert.assertNotNull(txKeep.getTransformedOperation());
    Assert.assertEquals("KEEP", txKeep.getTransformedOperation().get("attribute").asString());
    Assert.assertEquals(keepNewAddress, PathAddress.pathAddress(txKeep.getTransformedOperation().get(OP_ADDR)));
    txKeep = transformOperation(ModelVersion.create(1, 1), opKeep.clone());
    Assert.assertFalse(txKeep.rejectOperation(success()));
    Assert.assertNotNull(txKeep.getTransformedOperation());
    Assert.assertEquals("keep", txKeep.getTransformedOperation().get("attribute").asString());
    Assert.assertEquals(keepOriginalAddress, PathAddress.pathAddress(txKeep.getTransformedOperation().get(OP_ADDR)));

    final ModelNode opDiscard = Util.createAddOperation(subsystem.append("dynamic-redirect-original", "discard"));
    OperationTransformer.TransformedOperation txDiscard = transformOperation(ModelVersion.create(1), opDiscard.clone());
    Assert.assertFalse(txDiscard.rejectOperation(success()));
    Assert.assertNull(txDiscard.getTransformedOperation());
    txDiscard = transformOperation(ModelVersion.create(1, 0, 1), opDiscard.clone());
    Assert.assertFalse(txDiscard.rejectOperation(success()));
    Assert.assertNull(txDiscard.getTransformedOperation());
    txDiscard = transformOperation(ModelVersion.create(1, 0, 5), opDiscard.clone());
    Assert.assertFalse(txDiscard.rejectOperation(success()));
    Assert.assertNull(txDiscard.getTransformedOperation());
    txDiscard = transformOperation(ModelVersion.create(1, 1), opDiscard.clone());
    Assert.assertFalse(txDiscard.rejectOperation(success()));
    Assert.assertNotNull(txDiscard.getTransformedOperation());

    final ModelNode opReject = Util.createAddOperation(subsystem.append("dynamic-redirect-original", "reject"));
    OperationTransformer.TransformedOperation txReject = transformOperation(ModelVersion.create(1), opReject.clone());
    Assert.assertTrue(txReject.rejectOperation(success()));
    Assert.assertNotNull(txReject.getTransformedOperation());
    txReject = transformOperation(ModelVersion.create(1, 0, 1), opReject.clone());
    Assert.assertTrue(txReject.rejectOperation(success()));
    Assert.assertNotNull(txReject.getTransformedOperation());
    txReject = transformOperation(ModelVersion.create(1, 0, 5), opReject.clone());
    Assert.assertTrue(txReject.rejectOperation(success()));
    Assert.assertNotNull(txReject.getTransformedOperation());
    txReject = transformOperation(ModelVersion.create(1, 1), opReject.clone());
    Assert.assertFalse(txReject.rejectOperation(success()));
    Assert.assertNotNull(txReject.getTransformedOperation());
}
 
Example 19
Source File: ResponseStreamTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode createReadAttributeOp(PathAddress base) {
    PathAddress pa = base.append(SUBSYSTEM, LogStreamExtension.SUBSYSTEM_NAME);
    return Util.getReadAttributeOperation(pa, LogStreamExtension.LOG_FILE.getName());
}
 
Example 20
Source File: ValidateAddressOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

    ModelNode addr = VALUE_PARAM.validateOperation(operation);
    final PathAddress pathAddr = PathAddress.pathAddress(addr);
    Resource model = context.readResource(PathAddress.EMPTY_ADDRESS);
    final Iterator<PathElement> iterator = pathAddr.iterator();
    PathAddress current = PathAddress.EMPTY_ADDRESS;
    out: while(iterator.hasNext()) {
        final PathElement next = iterator.next();
        current = current.append(next);

        // Check if the registration is a proxy and dispatch directly
        final ImmutableManagementResourceRegistration registration = context.getResourceRegistration().getSubModel(current);

        if(registration != null && registration.isRemote()) {

            // If the target is a registered proxy return immediately
            if(! iterator.hasNext()) {
                break out;
            }

            // Create the proxy op
            final PathAddress newAddress = pathAddr.subAddress(current.size());
            final ModelNode newOperation = operation.clone();
            newOperation.get(OP_ADDR).set(current.toModelNode());
            newOperation.get(VALUE).set(newAddress.toModelNode());

            // On the DC the host=master is not a proxy but the validate-address is registered at the root
            // Otherwise delegate to the proxy handler
            final OperationStepHandler proxyHandler = registration.getOperationHandler(PathAddress.EMPTY_ADDRESS, OPERATION_NAME);
            if(proxyHandler != null) {
                context.addStep(newOperation, proxyHandler, OperationContext.Stage.MODEL, true);
                return;
            }

        } else if (model.hasChild(next)) {
            model = model.getChild(next);
        } else {
            // Invalid
            context.getResult().get(VALID).set(false);
            context.getResult().get(PROBLEM).set(ControllerLogger.ROOT_LOGGER.childResourceNotFound(next));
            return;
        }
    }

    if (authorize(context, current, operation).getDecision() == Decision.DENY) {
        context.getResult().get(VALID).set(false);
        context.getResult().get(PROBLEM).set(ControllerLogger.ROOT_LOGGER.managementResourceNotFoundMessage(current));
    } else {
        context.getResult().get(VALID).set(true);
    }
}