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

The following examples show how to use org.jboss.as.controller.PathAddress#subAddress() . 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: CoreModelTestDelegate.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void harmonizeModel(ModelVersion modelVersion, ModelNode legacyModel, ModelNode transformed,
                                              PathAddress address, ModelHarmonizer harmonizer) {

    if (address.size() > 0) {
        PathElement pathElement = address.getElement(0);
        if (legacyModel.hasDefined(pathElement.getKey()) && transformed.hasDefined(pathElement.getKey())) {
            ModelNode legacyType = legacyModel.get(pathElement.getKey());
            ModelNode transformedType = transformed.get(pathElement.getKey());
            PathAddress childAddress = address.size() > 1 ? address.subAddress(1) : PathAddress.EMPTY_ADDRESS;
            if (pathElement.isWildcard()) {
                for (String key : legacyType.keys()) {
                    if (transformedType.has(key)) {
                        harmonizeModel(modelVersion, legacyType.get(key),
                                transformedType.get(key), childAddress, harmonizer);
                    }
                }
            } else {
                harmonizeModel(modelVersion, legacyType.get(pathElement.getValue()),
                        transformedType.get(pathElement.getValue()), address, harmonizer);
            }
        }
    } else {
        harmonizer.harmonizeModel(modelVersion, legacyModel, transformed);
    }
}
 
Example 2
Source File: OperationRouting.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static PathAddress findSubsystemRootAddress(PathAddress address) {
    PathAddress result = null;
    int size = address.size();
    if (size > 1) {
        int subsystemKey = Integer.MAX_VALUE;
        String firstKey = address.getElement(0).getKey();
        if (HOST.equals(firstKey) || PROFILE.equals(firstKey)) {
            subsystemKey = 1;
        }
        if (size > subsystemKey
                && SUBSYSTEM.equals(address.getElement(subsystemKey).getKey())) {
            result = subsystemKey == size - 1 ? address : address.subAddress(0, subsystemKey + 1);
        }
    }
    return result;
}
 
Example 3
Source File: ServerOperationResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Map<Set<ServerIdentity>, ModelNode> getServerProfileOperations(ModelNode operation, PathAddress address,
                                                                       ModelNode domain, ModelNode host) {
    if (address.size() == 1) {
        return Collections.emptyMap();
    }
    String profileName = address.getElement(0).getValue();
    PathElement subsystem = address.getElement(1);
    Set<String> relatedProfiles = getRelatedElements(PROFILE, profileName, subsystem.getKey(), subsystem.getValue(), domain);
    Set<ServerIdentity> allServers = new HashSet<ServerIdentity>();
    for (String profile : relatedProfiles) {
        allServers.addAll(getServersForType(PROFILE, profile, domain, host, localHostName, serverProxies));
    }
    ModelNode serverOp = operation.clone();
    PathAddress serverAddress = address.subAddress(1);
    serverOp.get(OP_ADDR).set(serverAddress.toModelNode());
    return Collections.singletonMap(allServers, serverOp);
}
 
Example 4
Source File: ServerOperationsResolverHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Map<Set<ServerIdentity>, ModelNode> getServerOperations(OperationContext context, ModelNode domainOp, PathAddress domainOpAddress, boolean pushToServers) {
    Map<Set<ServerIdentity>, ModelNode> result = null;
    final PathAddress relativeAddress = domainOpAddress.subAddress(originalAddress.size());
    if(! pushToServers) {
        Set<OperationEntry.Flag> flags = originalRegistration.getOperationFlags(relativeAddress, domainOp.require(OP).asString());
        if (flags != null
                && flags.contains(OperationEntry.Flag.READ_ONLY)
                && !flags.contains(OperationEntry.Flag.DOMAIN_PUSH_TO_SERVERS)
                && !flags.contains(OperationEntry.Flag.RUNTIME_ONLY)) {
            result = Collections.emptyMap();
        }
    }
    if (result == null) {
        result = resolver.getServerOperations(context, domainOp, domainOpAddress);
    }
    return result;
}
 
Example 5
Source File: RemotingSubsystemTransformersTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void checkRejectOutboundConnectionProtocolNotRemote(KernelServices mainServices, ModelVersion version, String type, String name) throws OperationFailedException {
    ModelNode operation = new ModelNode();
    operation.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
    ModelNode address = new ModelNode();
    address.add(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME);
    address.add(type, name);
    operation.get(OP_ADDR).set(address);
    operation.get(NAME).set(CommonAttributes.PROTOCOL);
    operation.get(VALUE).set(Protocol.HTTP_REMOTING.toString());

    checkReject(operation, mainServices, version);

    PathAddress addr = PathAddress.pathAddress(operation.get(OP_ADDR));
    PathElement element = addr.getLastElement();
    addr = addr.subAddress(0, addr.size() - 1);
    addr = addr.append(PathElement.pathElement(element.getKey(), "remoting-outbound2"));

    operation = Util.createAddOperation(addr);
    operation.get(CommonAttributes.OUTBOUND_SOCKET_BINDING_REF).set("dummy-outbound-socket");
    operation.get(CommonAttributes.USERNAME).set("myuser");
    operation.get(CommonAttributes.PROTOCOL).set(Protocol.HTTP_REMOTING.toString());
    checkReject(operation, mainServices, version);

}
 
Example 6
Source File: AbstractDiscoveryOptionRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void updateOptionsAttribute(OperationContext context, ModelNode operation, String type) {

        final PathAddress operationAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
        final PathAddress discoveryOptionsAddress = operationAddress.subAddress(0, operationAddress.size() - 1);
        final ModelNode discoveryOptions = Resource.Tools.readModel(context.readResourceFromRoot(discoveryOptionsAddress));

        // Get the current list of discovery options and remove the given discovery option
        // from the list to maintain the order
        final ModelNode currentList = discoveryOptions.get(ModelDescriptionConstants.OPTIONS);
        final String name = operationAddress.getLastElement().getValue();

        final ModelNode newList = new ModelNode().setEmptyList();
        for (ModelNode e : currentList.asList()) {
            final Property prop = e.asProperty();
            final String discoveryOptionType = prop.getName();
            final String discoveryOptionName = prop.getValue().get(ModelDescriptionConstants.NAME).asString();
            if (!(discoveryOptionType.equals(type) && discoveryOptionName.equals(name))) {
                newList.add(e);
            }
        }

        final ModelNode writeOp = Util.getWriteAttributeOperation(discoveryOptionsAddress, ModelDescriptionConstants.OPTIONS, newList);
        final OperationStepHandler writeHandler = context.getRootResourceRegistration().getSubModel(discoveryOptionsAddress).getOperationHandler(PathAddress.EMPTY_ADDRESS, WRITE_ATTRIBUTE_OPERATION);
        context.addStep(writeOp, writeHandler, OperationContext.Stage.MODEL);
    }
 
Example 7
Source File: PrincipalAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    ModelNode model = context.createResource(PathAddress.EMPTY_ADDRESS).getModel();

    PrincipalResourceDefinition.TYPE.validateAndSet(operation, model);
    PrincipalResourceDefinition.REALM.validateAndSet(operation, model);
    PrincipalResourceDefinition.NAME.validateAndSet(operation, model);

    final String roleName = RoleMappingResourceDefinition.getRoleName(operation);
    final AuthorizerConfiguration.PrincipalType principalType = PrincipalResourceDefinition.getPrincipalType(context, model);
    final String realm = PrincipalResourceDefinition.getRealm(context, model);
    final String name = PrincipalResourceDefinition.getName(context, model);

    PathAddress completeAddress = PathAddress.pathAddress(operation.get(ADDRESS));
    PathAddress roleAddress = completeAddress.subAddress(0, completeAddress.size() - 1);
    validateUniqueness(context, roleName, roleAddress, principalType, realm, name);

    registerRuntimeAdd(context, roleName.toUpperCase(Locale.ENGLISH), principalType, name, realm);
}
 
Example 8
Source File: SyslogAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Void handback) throws OperationFailedException {
    if (super.handlerRevertUpdateToRuntime(context, operation, attributeName, valueToRestore, valueToRevert, handback)) {
        return;
    }

    if (attributeName.equals(APP_NAME.getName())) {
        auditLogger.updateSyslogHandlerAppName(Util.getNameFromAddress(operation.require(OP_ADDR)), resolveAppName(context, valueToRestore, environmentReader));
    } else if (attributeName.equals(FACILITY.getName())) {
        auditLogger.updateSyslogHandlerFacility(Util.getNameFromAddress(operation.require(OP_ADDR)), Facility.valueOf(valueToRestore.asString()));
    } else if (attributeName.equals(RECONNECT_TIMEOUT)) {
        PathAddress addr = PathAddress.pathAddress(operation.require(OP_ADDR));
        addr = addr.subAddress(0, addr.size() - 1);
        auditLogger.updateSyslogHandlerReconnectTimeout(Util.getNameFromAddress(addr), valueToRestore.asInt());
    } else if (attributeName.equals(KEYSTORE_PASSWORD_CREDENTIAL_REFERENCE_NAME) || attributeName.equals(KEY_PASSWORD_CREDENTIAL_REFERENCE_NAME)) {
        rollbackCredentialStoreUpdate(getAttributeDefinition(attributeName), context, valueToRevert);
    } else {
        auditLogger.getUpdater().rollbackChanges();
    }
}
 
Example 9
Source File: OrderedChildTypesAttachment.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 *
 */
public Set<String> getOrderedChildTypes(PathAddress resourceAddress) {
    //The describe handlers don't append the profile element at the stage when the addOrderedChildResourceTypes()
    //method gets called, so strip it off here.
    final PathAddress lookupAddress =
            resourceAddress.size() > 0 && resourceAddress.getElement(0).getKey().equals(ModelDescriptionConstants.PROFILE) ?
                    resourceAddress.subAddress(1) :
                    resourceAddress;

    return orderedChildren.get(lookupAddress);
}
 
Example 10
Source File: HandlerUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static boolean lookForHandler(final OperationContext context, final PathAddress addr, final String name) {
    final PathAddress subAddress = addr.subAddress(0, addr.size() - 2);
    final Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);

    for (String handlerType: HANDLER_TYPES) {
        final PathAddress referenceAddress = subAddress.append(handlerType, name);
        if (lookForResource(root, referenceAddress)) {
            return true;
        }
    }
    return false;
}
 
Example 11
Source File: ChainedTransformingDescription.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void copy(Resource src, Resource dest, PathAddress address) {
    PathAddress parentAddress = address.size() > 1 ? address.subAddress(0, address.size() - 1) : PathAddress.EMPTY_ADDRESS;
    PathElement childElement = address.getLastElement();
    Resource source = src.navigate(parentAddress);
    Resource destination = dest.navigate(parentAddress);
    Resource sourceChild = source.getChild(childElement);
    if (sourceChild != null) {
        Resource destChild = Resource.Factory.create();
        destination.registerChild(childElement, destChild);
        copy(sourceChild, destChild);
    }
    //copy(src, dest);
}
 
Example 12
Source File: SyslogAuditLogProtocolResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void checkNoOtherProtocol(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress opAddr = PathAddress.pathAddress(operation.require(OP_ADDR));
    PathAddress addr = opAddr.subAddress(0, opAddr.size() - 1);
    Resource resource = context.readResourceFromRoot(addr);
    Set<ResourceEntry> existing = resource.getChildren(PROTOCOL);
    if (existing.size() > 1) {
        for (ResourceEntry entry : existing) {
            PathElement mine = addr.getLastElement();
            if (!entry.getPathElement().equals(mine)) {
                throw DomainManagementLogger.ROOT_LOGGER.sysLogProtocolAlreadyConfigured(addr.append(mine));
            }
        }
    }
}
 
Example 13
Source File: LdapCacheResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates an operations that targets the valiadating handler.
 *
 * @param operationToValidate the operation that this handler will validate
 * @return  the validation operation
 */
private static ModelNode createOperation(final ModelNode operationToValidate) {
    PathAddress pa = PathAddress.pathAddress(operationToValidate.require(OP_ADDR));
    PathAddress validationAddress = pa.subAddress(0, pa.size() - 1);

    return Util.getEmptyOperation("validate-cache", validationAddress.toModelNode());
}
 
Example 14
Source File: RemotingConnectorAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
        throws OperationFailedException {

    boolean useManagementEndpoint = RemotingConnectorResource.USE_MANAGEMENT_ENDPOINT.resolveModelAttribute(context, model).asBoolean();

    ServiceName remotingCapability;
    if (!useManagementEndpoint) {
        // Use the remoting capability
        // if (context.getProcessType() == ProcessType.DOMAIN_SERVER) then DomainServerCommunicationServices
        // installed the "remoting subsystem" endpoint and we don't even necessarily *have to* have a remoting
        // subsystem and possibly we could skip adding the requirement for its capability. But really, specifying
        // not to use the management endpoint and then not configuring a remoting subsystem is a misconfiguration,
        // and we should treat it as such. So, we add the requirement no matter what.
        context.requireOptionalCapability(RemotingConnectorResource.REMOTING_CAPABILITY, RemotingConnectorResource.REMOTE_JMX_CAPABILITY.getName(),
                    RemotingConnectorResource.USE_MANAGEMENT_ENDPOINT.getName());
        remotingCapability = context.getCapabilityServiceName(RemotingConnectorResource.REMOTING_CAPABILITY, Endpoint.class);
    } else {
        remotingCapability = ManagementRemotingServices.MANAGEMENT_ENDPOINT;
    }
    // Read the model for the JMX subsystem to find the domain name for the resolved/expressions models (if they are exposed).
    PathAddress address = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
    PathAddress parentAddress = address.subAddress(0, address.size() - 1);
    ModelNode jmxSubsystemModel = Resource.Tools.readModel(context.readResourceFromRoot(parentAddress, true));
    String resolvedDomain = getDomainName(context, jmxSubsystemModel, CommonAttributes.RESOLVED);
    String expressionsDomain = getDomainName(context, jmxSubsystemModel, CommonAttributes.EXPRESSION);

    RemotingConnectorService.addService(context.getServiceTarget(), remotingCapability, resolvedDomain, expressionsDomain);
}
 
Example 15
Source File: HcExtensionAndSubsystemManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void checkNoSubsystem(ModelControllerClient client, PathAddress subsystemAddress) throws Exception {
    PathAddress parent = subsystemAddress.subAddress(0, subsystemAddress.size() - 1);
    ModelNode op = Util.createEmptyOperation("read-children-resources", parent);
    op.get("child-type").set(SUBSYSTEM);
    ModelNode result = DomainTestUtils.executeForResult(op, client);
    Assert.assertFalse(result.hasDefined(subsystemAddress.getLastElement().getValue()));
}
 
Example 16
Source File: ReadAliasResourceDescriptionAddressTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void checkAddress(PathAddress expectedAddress, boolean server, ModelNode result) {
    if (server) {
        expectedAddress = expectedAddress.subAddress(2);
    }
    List<ModelNode> list = result.asList();
    Assert.assertEquals(1, list.size());
    ModelNode entry = list.get(0);
    Assert.assertEquals(SUCCESS, entry.get(OUTCOME).asString());
    Assert.assertTrue(entry.hasDefined(ADDRESS));
    PathAddress returnedAddress = PathAddress.pathAddress(entry.get(ADDRESS));
    Assert.assertEquals(expectedAddress, returnedAddress);
}
 
Example 17
Source File: Util.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static PathAddress getParentAddressByKey(PathAddress address, String parentKey) {
    for (int i = address.size() - 1; i >= 0; i--) {
        PathElement pe = address.getElement(i);
        if (parentKey.equals(pe.getKey())) {
            return address.subAddress(0, i + 1);
        }
    }

    return null;
}
 
Example 18
Source File: ServerOperationResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Map<Set<ServerIdentity>, ModelNode> getServerHostOperations(ModelNode operation, PathAddress address,
                                                                    ModelNode domain, ModelNode host) {
    if (address.size() == 1) {
        return resolveHostRootOperation(operation, domain, host);
    } else {
        HostKey hostKey = HostKey.forName(address.getElement(1).getKey());
        address = address.subAddress(1); // Get rid of the host=hostName
        switch (hostKey) {
            case PATH: {
                return getServerPathOperations(operation, address, host, false);
            }
            case SYSTEM_PROPERTY: {
                return getServerSystemPropertyOperations(operation, address, Level.HOST, domain, null, host);
            }
            case CORE_SERVICE: {
                return resolveCoreServiceOperations(operation, address, domain, host);
            }
            case INTERFACE: {
                return getServerInterfaceOperations(operation, address, host, false);
            }
            case JVM: {
                return getJVMRestartOperations(address, host);
            }
            case SERVER_CONFIG: {
                return resolveServerConfigOperation(operation, address, domain, host);
            }
            case EXTENSION:
            case SUBSYSTEM:
            case SOCKET_BINDING_GROUP: {
                //Changes made to the extensions, subsystems and socket-bindings on a host should not be propagated to the servers
                return Collections.emptyMap();
            }
            case SERVER:
            default:
                throw DomainControllerLogger.HOST_CONTROLLER_LOGGER.unexpectedInitialPathKey(address.getElement(0).getKey());
        }
    }
}
 
Example 19
Source File: AuditLogToSyslogSetup.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void removeResource(ManagementClient managementClient, PathAddress address) throws Exception {
    PathElement element = address.getLastElement();
    PathAddress parentAddress = address.subAddress(0, address.size() - 1);
    ModelNode op = Util.createOperation(READ_CHILDREN_NAMES_OPERATION, parentAddress);
    op.get(CHILD_TYPE).set(element.getKey());
    ModelNode result = managementClient.getControllerClient().execute(op);
    if (result.hasDefined("result") && result.get("result").asList().contains(new ModelNode(element.getValue()))) {
        // It exists so remove it
        op = Util.createRemoveOperation(address);
        op.get(OPERATION_HEADERS, ROLLBACK_ON_RUNTIME_FAILURE).set(false);
        op.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
        CoreUtils.applyUpdate(op, managementClient.getControllerClient());
    }

}
 
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);
    }
}