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

The following examples show how to use org.jboss.as.controller.PathAddress#size() . 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: DMRDriver.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
private ModelNode makePathAddressFullyQualified_WFLY6628(
        PathAddress queryPathAddress, ModelNode individualPathAddressNode) {
    // PathAddress strips out any /host=X/server=X found at the start of the address. We want it back in.
    if (queryPathAddress.size() > 2
            && ModelDescriptionConstants.HOST.equals(queryPathAddress.getElement(0).getKey())
            && ModelDescriptionConstants.SERVER.equals(queryPathAddress.getElement(1).getKey())) {

        PathAddress partialPathAddress = PathAddress.pathAddress(individualPathAddressNode);

        if (partialPathAddress.size() > 2
                && ModelDescriptionConstants.HOST.equals(partialPathAddress.getElement(0).getKey())
                && ModelDescriptionConstants.SERVER.equals(partialPathAddress.getElement(1).getKey())) {
            return individualPathAddressNode; // looks like the address is already fully qualified
        }

        PathAddress hostServerAddress = queryPathAddress.subAddress(0, 2);
        PathAddress fullPathAddress = hostServerAddress.append(partialPathAddress);
        return fullPathAddress.toModelNode();
    } else {
        return individualPathAddressNode; // nothing needs to be fixed
    }
}
 
Example 2
Source File: DefaultResourceDescriptionProvider.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates an alias address by replacing all wildcard values by $ + key so that the address can be used to obtain a capability pattern.
 * @param pa the registration address to be aliased.
 * @return  the aliased address.
 */
private PathAddress createAliasPathAddress(PathAddress pa) {
    ImmutableManagementResourceRegistration registry = registration.getParent();
    List<PathElement> elements = new ArrayList<>();
    for(int i = pa.size() - 1; i >=0; i--) {
        PathElement elt = pa.getElement(i);
        ImmutableManagementResourceRegistration childRegistration = registry.getSubModel(PathAddress.pathAddress(PathElement.pathElement(elt.getKey())));
        if(childRegistration == null) {
            elements.add(elt);
        } else {
            elements.add(PathElement.pathElement(elt.getKey(), "$" + elt.getKey()));
        }
        registry = registry.getParent();
    }
    Collections.reverse(elements);
    return PathAddress.pathAddress(elements.toArray(new PathElement[elements.size()]));
}
 
Example 3
Source File: DMRLocationResolver.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isParent(DMRNodeLocation parent, DMRNodeLocation child) {
    if (parent == null) {
        throw new IllegalArgumentException(
                "Cannot compute [" + getClass().getName() + "].isParent() with a null parent argument");
    }

    if (child == null) {
        throw new IllegalArgumentException(
                "Cannot compute [" + getClass().getName() + "].isParent() with a null child argument");
    }

    PathAddress parentPath = parent.getPathAddress();
    PathAddress childPath = child.getPathAddress();
    int parentLength = parentPath.size();
    if (parentLength < childPath.size()) {
        return matches(parentLength, parentPath, childPath);
    } else {
        return false;
    }
}
 
Example 4
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 5
Source File: TransformationTargetImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public OperationTransformer resolveTransformer(TransformationContext context, final PathAddress address, final String operationName) {
    if(address.size() == 0) {
        // TODO use registry registry to register this operations.
        if(ModelDescriptionConstants.COMPOSITE.equals(operationName)) {
            return new CompositeOperationTransformer();
        }
    }
    if (operationIgnoredRegistry.isOperationExcluded(address, operationName)) {
        ControllerLogger.MGMT_OP_LOGGER.tracef("Excluding operation %s to %s", operationName, address);
        return OperationTransformer.DISCARD;
    }
    if (version.getMajor() < 3 && ModelDescriptionConstants.QUERY.equals(operationName)) { // TODO use transformer inheritance and register this normally
        return QueryOperationHandler.TRANSFORMER;
    }
    final OperationTransformerRegistry.OperationTransformerEntry entry = registry.resolveOperationTransformer(address, operationName, placeholderResolver);
    return entry.getTransformer();
}
 
Example 6
Source File: AbstractControllerTestBase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected ModelNode createOperation(String operationName, PathAddress address) {
    ModelNode operation = new ModelNode();
    operation.get(OP).set(operationName);
    if (address.size() > 0) {
        operation.get(OP_ADDR).set(address.toModelNode());
    } else {
        operation.get(OP_ADDR).setEmptyList();
    }

    return operation;
}
 
Example 7
Source File: AbstractClassificationResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Resource navigate(PathAddress address) {
    if (address.size() == 0) {
        return this;
    } else {
        Resource child = requireChild(address.getElement(0));
        return address.size() == 1 ? child : child.navigate(address.subAddress(1));
    }
}
 
Example 8
Source File: OutboundSocketBindingWriteHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected boolean requiresRuntime(OperationContext context) {
    if (context.getProcessType().isServer()) {
        return super.requiresRuntime(context);
    }
    //Check if we are a host's socket binding and install the service if we are
    PathAddress pathAddress = context.getCurrentAddress();
    return pathAddress.size() > 0 && pathAddress.getElement(0).getKey().equals(HOST);
}
 
Example 9
Source File: PrepareStepHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean isServerOperation(ModelNode operation) {
    PathAddress addr = PathAddress.pathAddress(operation.get(OP_ADDR));
    return addr.size() > 1
            && HOST.equals(addr.getElement(0).getKey())
            && localHostControllerInfo.getLocalHostName().equals(addr.getElement(0).getValue())
            && RUNNING_SERVER.equals(addr.getElement(1).getKey());
}
 
Example 10
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 11
Source File: ServerOperationResolver.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Convert an operation for deployment overlays to be executed on local servers.
 * Since this might be called in the case of redeployment of affected deployments, we need to take into account
 * the composite op resulting from such a transformation
 * @see AffectedDeploymentOverlay#redeployLinksAndTransformOperationForDomain
 * @param operation
 * @param host
 * @return
 */
private Map<Set<ServerIdentity>, ModelNode> getDeploymentOverlayOperations(ModelNode operation,
                                                                           ModelNode host) {
    final PathAddress realAddress = PathAddress.pathAddress(operation.get(OP_ADDR));
    if (realAddress.size() == 0 && COMPOSITE.equals(operation.get(OP).asString())) {
        //We have a composite operation resulting from a transformation to redeploy affected deployments
        //See redeploying deployments affected by an overlay.
        ModelNode serverOp = operation.clone();
        Map<ServerIdentity, Operations.CompositeOperationBuilder> composite = new HashMap<>();
        for (ModelNode step : serverOp.get(STEPS).asList()) {
            ModelNode newStep = step.clone();
            String groupName = PathAddress.pathAddress(step.get(OP_ADDR)).getElement(0).getValue();
            newStep.get(OP_ADDR).set(PathAddress.pathAddress(step.get(OP_ADDR)).subAddress(1).toModelNode());
            Set<ServerIdentity> servers = getServersForGroup(groupName, host, localHostName, serverProxies);
            for(ServerIdentity server : servers) {
                if(!composite.containsKey(server)) {
                    composite.put(server, Operations.CompositeOperationBuilder.create());
                }
                composite.get(server).addStep(newStep);
            }
            if(!servers.isEmpty()) {
                newStep.get(OP_ADDR).set(PathAddress.pathAddress(step.get(OP_ADDR)).subAddress(1).toModelNode());
            }
        }
        if(!composite.isEmpty()) {
            Map<Set<ServerIdentity>, ModelNode> result = new HashMap<>();
            for(Entry<ServerIdentity, Operations.CompositeOperationBuilder> entry : composite.entrySet()) {
                result.put(Collections.singleton(entry.getKey()), entry.getValue().build().getOperation());
            }
            return result;
        }
        return Collections.emptyMap();
    }
    final Set<ServerIdentity> allServers = getAllRunningServers(host, localHostName, serverProxies);
    return Collections.singletonMap(allServers, operation.clone());
}
 
Example 12
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 13
Source File: ModelTestOperationValidatorFilter.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean addressMatch(PathAddress opAddr, OperationEntry entry) {
    boolean match = entry.address.size() == opAddr.size();
    if (match) {
        for (int i = 0; i < opAddr.size(); i++) {
            if (!pathElementMatch(opAddr.getElement(i), entry.address.getElement(i))) {
                match = false;
                break;
            }
        }
    }
    return match;
}
 
Example 14
Source File: SSLSessionDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static byte[] sessionId(ModelNode operation) {
    PathAddress pa = PathAddress.pathAddress(operation.require(OP_ADDR));
    for (int i = pa.size() - 1; i > 0; i--) {
        PathElement pe = pa.getElement(i);
        if (ElytronDescriptionConstants.SSL_SESSION.equals(pe.getKey())) {
            return ByteIterator.ofBytes(pe.getValue().getBytes(StandardCharsets.UTF_8)).asUtf8String().hexDecode().drain();
        }
    }

    throw ROOT_LOGGER.operationAddressMissingKey(ElytronDescriptionConstants.SSL_SESSION);
}
 
Example 15
Source File: ProxyControllerRegistration.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ImmutableManagementResourceRegistration getParent() {
    PathAddress parentAddress = ProxyControllerRegistration.this.getPathAddress();
    if (pathAddress.size() == parentAddress.size() + 1) {
        return ProxyControllerRegistration.this;
    } else {
        return new ChildRegistration(pathAddress.getParent());
    }
}
 
Example 16
Source File: DomainFinalResultHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean isDomainOperation(final ModelNode operation) {
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    return address.size() == 0 || !address.getElement(0).getKey().equals(HOST);
}
 
Example 17
Source File: CompositeOperationTransformer.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private TransformedOperation transformOperation(final TransformationContext context, final ModelNode operation) throws OperationFailedException {
    final ModelNode composite = operation.clone();
    composite.get(STEPS).setEmptyList();
    final TransformationTarget target = context.getTarget();
    final List<Step> steps = new ArrayList<Step>();
    int stepIdx = 0, resultIdx  = 0;
    for(final ModelNode step : operation.require(STEPS).asList()) {
        stepIdx++;
        final String operationName = step.require(OP).asString();
        final PathAddress stepAddress = step.hasDefined(OP_ADDR) ? PathAddress.pathAddress(step.require(OP_ADDR)) : PathAddress.EMPTY_ADDRESS;
        final TransformedOperation result;
        if(stepAddress.size() == 0 && COMPOSITE.equals(operationName)) {
            // Process nested steps directly
            result = transformOperation(context, step);
        } else {
            //If this is an alias, get the real address before transforming
            ImmutableManagementResourceRegistration reg = context.getResourceRegistrationFromRoot(stepAddress);
            final PathAddress useAddress;
            if (reg != null && reg.isAlias()) {
                useAddress = reg.getAliasEntry().convertToTargetAddress(stepAddress, AliasEntry.AliasContext.create(step, context));
            } else {
                useAddress = stepAddress;
            }

            final OperationTransformer transformer = target.resolveTransformer(context, useAddress, operationName);
            final PathAddress transformed = TransformersImpl.transformAddress(useAddress, target);
            // Update the operation using the new path address
            step.get(OP_ADDR).set(transformed.toModelNode()); // TODO should this happen by default?

            result = transformer.transformOperation(context, transformed, step);
        }
        final ModelNode transformedOperation = result.getTransformedOperation();
        if (transformedOperation != null) {
            composite.get(STEPS).add(transformedOperation);
            resultIdx++;
        }
        steps.add(new Step(stepIdx, resultIdx, result));
    }
    final CompositeResultTransformer resultHandler = new CompositeResultTransformer(steps);
    return new TransformedOperation(composite, resultHandler, resultHandler);
}
 
Example 18
Source File: SyncServerStateOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
void checkContent(ModelNode operation, PathAddress operationAddress) {
    if (!operation.get(OP).asString().equals(ADD) || operationAddress.size() == 0) {
        return;
    }
    final PathElement firstElement = operationAddress.getElement(0);
    final String contentType = firstElement.getKey();
    if (contentType == null) {
        return;
    }
    if (operationAddress.size() == 1) {
        switch (contentType) {
            case DEPLOYMENT:
                final String deployment = firstElement.getValue();
                Set<ContentReference> hashes = deploymentHashes.get(deployment);
                if (hashes == null) {
                    hashes = new HashSet<>();
                    deploymentHashes.put(deployment, hashes);
                    for (ModelNode contentItem : operation.get(CONTENT).asList()) {
                        hashes.add(ModelContentReference.fromModelAddress(operationAddress, contentItem.get(HASH).asBytes()));
                        if (parameters.getHostControllerEnvironment().isBackupDomainFiles()) {
                            relevantDeployments.add(firstElement.getValue());
                        }
                    }
                }
                makeExistingDeploymentUpdatedAffected(firstElement, operation);
                break;
            case DEPLOYMENT_OVERLAY:
                break;
            case MANAGEMENT_CLIENT_CONTENT:
                if (firstElement.getValue().equals(ROLLOUT_PLANS)) {
                    updateRolloutPlans = true;
                    //This needs special handling. Drop the existing resource and add a new one
                    if (operation.hasDefined(HASH)) {
                        rolloutPlansHash = operation.get(HASH).asBytes();
                        requiredContent.add(ModelContentReference.fromModelAddress(operationAddress, rolloutPlansHash));
                    }
                }
                break;
            default:
                return;
        }
    } else if (operationAddress.size() == 2) {
        if( firstElement.getKey().equals(SERVER_GROUP) &&
            serversByGroup.containsKey(firstElement.getValue())) {
            PathElement secondElement = operationAddress.getElement(1);
            if (secondElement.getKey().equals(DEPLOYMENT)) {
                relevantDeployments.add(secondElement.getValue());
                affectedGroups.add(firstElement.getValue());
            }
        } else if (firstElement.getKey().equals(DEPLOYMENT_OVERLAY)) {
            requiredContent.add(ModelContentReference.fromModelAddress(operationAddress, operation.get(CONTENT).asBytes()));
        }
    }
    return;
}
 
Example 19
Source File: ModelControllerMBeanHelper.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public ObjectName onAddress(PathAddress address) {
    if (isExcludeAddress(address)) {
        return null;
    }

    ObjectName result = null;
    ObjectName toMatch = ObjectNameAddressUtil.createObjectName(domain, address, creationContext);
    if (baseName == null) {
        result = toMatch;
    } else if (address.size() == 0) {
        // We can't compare the ObjectName properties a la the final 'else' block,
        // because the special management=server property will not match
        // Just confirm correct domain
        if (domainOnlyName.apply(toMatch)) {
            result = toMatch;
        }
    } else if (!propertyListPattern && address.size() >= properties.size()) {
        // We have same or more elements than our target has properties; let it do the match
        if (baseName.apply(toMatch)) {
            result = toMatch;
        }
    } else {
        // Address may be a parent of an interesting address, so see if it matches all elements it has
        boolean matches = domainOnlyName.apply(toMatch);
        if (matches) {
            for (Map.Entry<String, String> entry : toMatch.getKeyPropertyList().entrySet()) {

                String propertyValue = properties.get(entry.getKey());
                if ((propertyValue == null && !propertyListPattern)
                        || (propertyValue != null
                                && !entry.getValue().equals(propertyValue))
                                && !baseName.isPropertyValuePattern(entry.getKey())) {
                    matches = false;
                    break;
                }
            }
        }
        if (matches) {
            result = toMatch;
        }
    }
    return result;
}
 
Example 20
Source File: FilteredData.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
FilteredData(PathAddress baseAddress) {
    this.baseAddressLength = baseAddress.size();
}