Java Code Examples for org.jboss.as.controller.PathElement#getValue()

The following examples show how to use org.jboss.as.controller.PathElement#getValue() . 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: ServiceUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * From a given operation extract the address of the operation, identify the simple name of the {@link Service} being
 * referenced and convert it into a {@link ServiceName} for that {@link Service}.
 *
 * @param operation - the operation to extract the simple name from.
 * @return The fully qualified {@link ServiceName} of the service.
 */
ServiceName serviceName(final ModelNode operation) {
    String name = null;
    PathAddress pa = PathAddress.pathAddress(operation.require(OP_ADDR));
    for (int i = pa.size() - 1; i > 0; i--) {
        PathElement pe = pa.getElement(i);
        if (key.equals(pe.getKey())) {
            name = pe.getValue();
            break;
        }
    }

    if (name == null) {
        throw ROOT_LOGGER.operationAddressMissingKey(key);
    }

    return serviceName(name);
}
 
Example 2
Source File: HandlerUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static void checkNoOtherHandlerWithTheSameName(OperationContext context) throws OperationFailedException {
    final PathAddress address = context.getCurrentAddress();
    final PathAddress parentAddress = address.subAddress(0, address.size() - 1);
    final Resource resource = context.readResourceFromRoot(parentAddress);

    final PathElement element = address.getLastElement();
    final String handlerType = element.getKey();
    final String handlerName = element.getValue();

    for (String otherHandler: HANDLER_TYPES) {
        if (handlerType.equals(otherHandler)) {
            // we need to check other handler types for the same name
            continue;
        }
        final PathElement check = PathElement.pathElement(otherHandler, handlerName);
        if (resource.hasChild(check)) {
            throw DomainManagementLogger.ROOT_LOGGER.handlerAlreadyExists(check.getValue(), parentAddress.append(check));
        }
    }
}
 
Example 3
Source File: ApplyExtensionsHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Resource getResource(PathAddress resourceAddress, Resource rootResource, OperationContext context) {
    if(resourceAddress.size() == 0) {
        return rootResource;
    }
    Resource temp = rootResource;
    int idx = 0;
    for(PathElement element : resourceAddress) {
        temp = temp.getChild(element);
        if(temp == null) {
            if (idx == 0) {
                String type = element.getKey();
                if (type.equals(EXTENSION)) {
                    // Needs a specialized resource type
                    temp = new ExtensionResource(element.getValue(), extensionRegistry);
                    context.addResource(resourceAddress, temp);
                }
            }
            if (temp == null) {
                temp = context.createResource(resourceAddress);
            }
            break;
        }
        idx++;
    }
    return temp;
}
 
Example 4
Source File: AbstractBindingWriteHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue,
                                       final ModelNode currentValue, final HandbackHolder<RollbackInfo> handbackHolder) throws OperationFailedException {

    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final PathElement element = address.getLastElement();
    final String bindingName = element.getValue();
    final ModelNode bindingModel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
    final ServiceName serviceName = SOCKET_BINDING_CAPABILITY.getCapabilityServiceName(bindingName, SocketBinding.class);
    final ServiceController<?> controller = context.getServiceRegistry(true).getRequiredService(serviceName);
    final SocketBinding binding = controller.getState() == ServiceController.State.UP ? SocketBinding.class.cast(controller.getValue()) : null;
    final boolean bound = binding != null && binding.isBound();
    if (binding == null) {
        // existing is not started, so can't update it. Instead reinstall the service
        handleBindingReinstall(context, bindingName, bindingModel, serviceName);
    } else if (bound) {
        // Cannot edit bound sockets
        return true;
    } else {
        handleRuntimeChange(context, operation, attributeName, resolvedValue, binding);
    }
    handbackHolder.setHandback(new RollbackInfo(bindingName, bindingModel, binding));
    return requiresRestart();
}
 
Example 5
Source File: SubsystemDescriptionDump.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void dumpManagementResourceRegistration(final ImmutableManagementResourceRegistration profileRegistration,
                                                      final ExtensionRegistry registry, final String path) throws OperationFailedException{
    try {
        for (PathElement pe : profileRegistration.getChildAddresses(PathAddress.EMPTY_ADDRESS)) {
            ImmutableManagementResourceRegistration registration = profileRegistration.getSubModel(PathAddress.pathAddress(pe));
            String subsystem = pe.getValue();
            SubsystemInformation info = registry.getSubsystemInfo(subsystem);
            ModelNode desc = readFullModelDescription(PathAddress.pathAddress(pe), registration);
            String name = subsystem + "-" + info.getManagementInterfaceMajorVersion() + "." + info.getManagementInterfaceMinorVersion() +"."+info.getManagementInterfaceMicroVersion()+ ".dmr";
            PrintWriter pw = new PrintWriter(Files.newBufferedWriter(Paths.get(path,name), StandardCharsets.UTF_8));
            desc.writeString(pw, false);
            pw.close();
        }
    } catch (IOException e) {
        throw new OperationFailedException("could not save,", e);
    }
}
 
Example 6
Source File: LoggingConfigurationReadStepHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static ServiceName getServiceName(final OperationContext context) {
    String deploymentName = null;
    String subdeploymentName = null;
    final PathAddress address = context.getCurrentAddress();
    for (PathElement element : address) {
        if (ModelDescriptionConstants.DEPLOYMENT.equals(element.getKey())) {
            deploymentName = getRuntimeName(context, element);
            //deploymentName = element.getValue();
        } else if (ModelDescriptionConstants.SUBDEPLOYMENT.endsWith(element.getKey())) {
            subdeploymentName = element.getValue();
        }
    }
    if (deploymentName == null) {
        throw LoggingLogger.ROOT_LOGGER.deploymentNameNotFound(address);
    }
    final ServiceName result;
    if (subdeploymentName == null) {
        result = Services.deploymentUnitName(deploymentName);
    } else {
        result = Services.deploymentUnitName(deploymentName, subdeploymentName);
    }
    return result.append("logging", "configuration");
}
 
Example 7
Source File: PathAddressFilter.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void addReject(final PathAddress address) {
    final Iterator<PathElement> i = address.iterator();
    Node node = this.node;
    while (i.hasNext()) {

        final PathElement element = i.next();
        final String elementKey = element.getKey();
        Node key = node.children.get(elementKey);
        if (key == null) {
            key = new Node(element.getKey());
            node.children.put(elementKey, key);
        }
        final String elementValue = element.getValue();
        Node value = key.children.get(elementValue);
        if (value == null) {
            value = new Node(elementValue);
            key.children.put(elementValue, value);
        }
        if (!i.hasNext()) {
            value.accept = false;
        }
    }
}
 
Example 8
Source File: PatchStreamResourceOperationStepHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected String getPatchStreamName(OperationContext context) {
    final PathElement stream = context.getCurrentAddress().getLastElement();
    final String streamName;
    if(Constants.PATCH_STREAM.equals(stream.getKey())) {
        streamName = stream.getValue();
    } else {
        streamName = null;
    }
    return streamName;
}
 
Example 9
Source File: DMRLocationResolver.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
private static boolean matches(int length, PathAddress pattern, PathAddress address) {
    for (int i = 0; i < length; i++) {
        PathElement otherElem = address.getElement(i);
        Property prop = new Property(otherElem.getKey(), new ModelNode(otherElem.getValue()));
        if (!pattern.getElement(i).matches(prop)) {
            return false;
        }
    }
    return true;
}
 
Example 10
Source File: RejectExpressionValuesTransformer.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String findSubsystemName(PathAddress pathAddress) {
    for (PathElement element : pathAddress) {
        if (element.getKey().equals(SUBSYSTEM)) {
            return element.getValue();
        }
    }
    return null;
}
 
Example 11
Source File: WorkerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static XnioWorker getXnioWorker(OperationContext context) {
    String name = context.getCurrentAddressValue();
    if (!context.getCurrentAddress().getLastElement().getKey().equals(IOExtension.WORKER_PATH.getKey())) { //we are somewhere deeper, lets find worker name
        for (PathElement pe : context.getCurrentAddress()) {
            if (pe.getKey().equals(IOExtension.WORKER_PATH.getKey())) {
                name = pe.getValue();
                break;
            }
        }
    }
    return getXnioWorker(context.getServiceRegistry(false), name);
}
 
Example 12
Source File: RejectedAttributesLogContext.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String findSubsystemName(PathAddress pathAddress) {
    for (PathElement element : pathAddress) {
        if (element.getKey().equals(SUBSYSTEM)) {
            return element.getValue();
        }
    }
    return null;
}
 
Example 13
Source File: LoggingProfileOperations.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets the logging profile name. If the address is not in a logging profile path, {@code null} is returned.
 *
 * @param address the address to check for the logging profile name
 *
 * @return the logging profile name or {@code null}
 */
static String getLoggingProfileName(final PathAddress address) {
    for (PathElement pathElement : address) {
        if (CommonAttributes.LOGGING_PROFILE.equals(pathElement.getKey())) {
            return pathElement.getValue();
        }
    }
    return null;
}
 
Example 14
Source File: LoggingProfileCapabilityRecorder.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public String[] getRequirementPatternSegments(final String name, final PathAddress address) {
    // Find the logging profile if it exists and add the profile name to the capability name
    for (PathElement pathElement : address) {
        if (CommonAttributes.LOGGING_PROFILE.equals(pathElement.getKey())) {
            return new String[] {pathElement.getValue(), name};
        }
    }
    return new String[] {name};
}
 
Example 15
Source File: LoggingProfileNameMapper.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public String[] apply(final PathAddress address) {
    // Find the logging profile if it exists and add the profile name to the capability name
    for (PathElement pathElement : address) {
        if (CommonAttributes.LOGGING_PROFILE.equals(pathElement.getKey())) {
            return new String[] {pathElement.getValue(), address.getLastElement().getValue()};
        }
    }
    return new String[] {address.getLastElement().getValue()};
}
 
Example 16
Source File: RoleMappingResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static String getRoleName(final ModelNode operation) {
    PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    for (PathElement current : address) {
        if (ROLE_MAPPING.equals(current.getKey())) {
            return current.getValue();
        }
    }
    throw new IllegalStateException();
}
 
Example 17
Source File: LdapCacheResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected LdapSearcherCache<?, K> lookupService(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    String realmName = null;
    boolean forAuthentication = false;
    boolean forUserSearch = false;

    PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    for (PathElement current : address) {
        String key = current.getKey();
        if (SECURITY_REALM.equals(key)) {
            realmName = current.getValue();
        } else if (AUTHENTICATION.equals(key)) {
            forAuthentication = true;
            forUserSearch = true;
        } else if (AUTHORIZATION .equals(key)) {
            forAuthentication = false;
        } else if (USERNAME_TO_DN.equals(key)) {
            forUserSearch = true;
        } else if (GROUP_SEARCH.equals(key)) {
            forUserSearch = false;
        }
    }
    ServiceName serviceName = LdapSearcherCache.ServiceUtil.createServiceName(forAuthentication, forUserSearch, realmName);

    ServiceRegistry registry = context.getServiceRegistry(true);
    ServiceController<LdapSearcherCache<?, K>> service = (ServiceController<LdapSearcherCache<?, K>>) registry.getRequiredService(serviceName);

    try {
        return service.awaitValue();
    } catch (InterruptedException e) {
        throw new OperationFailedException(e);
    }
}
 
Example 18
Source File: DMRLocationResolver.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
@Override
public String findWildcardMatch(DMRNodeLocation multiTargetLocation, DMRNodeLocation singleLocation)
        throws ProtocolException {

    if (multiTargetLocation == null) {
        throw new ProtocolException("multiTargetLocation is null");
    }

    PathAddress multiTargetPaths = multiTargetLocation.getPathAddress();
    for (int i = 0; i < multiTargetPaths.size(); i++) {
        PathElement multiTargetPathElement = multiTargetPaths.getElement(i);
        if (multiTargetPathElement.isWildcard()) {
            PathElement singleLocationPathElement;
            try {
                singleLocationPathElement = singleLocation.getPathAddress().getElement(i);
            } catch (Exception e) {
                throw new ProtocolException(String.format("[%s] doesn't have the same path size as [%s]",
                        singleLocation, multiTargetLocation));
            }

            // DMR wildcards are only in values ("/name=*" not "/*=value")
            if (singleLocationPathElement.getKey().equals(multiTargetPathElement.getKey())) {
                return singleLocationPathElement.getValue();
            } else {
                throw new ProtocolException(String.format("[%s] doesn't match the multi-target key in [%s]",
                        singleLocation, multiTargetLocation));
            }
        }
    }

    // nothing matched - single location must not have resulted from a query using the given multi-target location
    throw new ProtocolException(String.format("[%s] doesn't match the wildcard from [%s]", singleLocation,
            multiTargetLocation));
}
 
Example 19
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 20
Source File: Util.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static String getNameFromAddress(PathAddress address) {
    PathElement pe = PathAddress.pathAddress(address).getLastElement();
    return pe == null ? null : pe.getValue();
}