Java Code Examples for org.jboss.as.controller.registry.Resource#getChildren()

The following examples show how to use org.jboss.as.controller.registry.Resource#getChildren() . 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: DeploymentAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void validateRuntimeNames(String deploymentName, OperationContext context) throws OperationFailedException {
    ModelNode deployment = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();

    if (ENABLED.resolveModelAttribute(context, deployment).asBoolean()) {
        String runtimeName = getRuntimeName(deploymentName, deployment);
        Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
        for (Resource.ResourceEntry re : root.getChildren(DEPLOYMENT)) {
            String reName = re.getName();
            if (!deploymentName.equals(reName)) {
                ModelNode otherDepl = re.getModel();
                if (ENABLED.resolveModelAttribute(context, otherDepl).asBoolean()) {
                    String otherRuntimeName = getRuntimeName(reName, otherDepl);
                    if (runtimeName.equals(otherRuntimeName)) {
                        throw ServerLogger.ROOT_LOGGER.runtimeNameMustBeUnique(reName, runtimeName);
                    }
                }
            }
        }
    }
}
 
Example 2
Source File: AffectedDeploymentOverlay.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static Set<String> listDeploymentNames(Resource deploymentRootResource, Set<Pattern> patterns) {
    Set<String> deploymentNames = new HashSet<>();
    if (deploymentRootResource.hasChildren(DEPLOYMENT)) {
        for (Resource.ResourceEntry deploymentResource : deploymentRootResource.getChildren(DEPLOYMENT)) {
            if (isAcceptableDeployment(deploymentResource.getModel(), patterns)) {
                deploymentNames.add(deploymentResource.getName());
            } else if (deploymentResource.hasChildren(SUBDEPLOYMENT)) {
                for (Resource.ResourceEntry subdeploymentResource : deploymentResource.getChildren(SUBDEPLOYMENT)) {
                    if (isAcceptableDeployment(subdeploymentResource.getModel(), patterns)) {
                        deploymentNames.add(deploymentResource.getName());
                    }
                }
            }
        }
    }
    return deploymentNames;
}
 
Example 3
Source File: ReadConfigAsFeaturesOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void describeChildren(final Resource resource, final ImmutableManagementResourceRegistration registration,
        final PathAddress address, OperationContext context,
        final AtomicReference<ModelNode> failureRef, final ModelNode results, ModelNode operation, Boolean nest) {
    for(String childType : resource.getChildTypes()) {
        for(Resource.ResourceEntry entry : resource.getChildren(childType)) {
            if(addressFilter != null && !addressFilter.accepts(address.append(entry.getPathElement()))) {
                continue;
            }
            final ImmutableManagementResourceRegistration childRegistration = registration.getSubModel(PathAddress.EMPTY_ADDRESS.append(entry.getPathElement()));
            if(childRegistration == null) {
                ControllerLogger.ROOT_LOGGER.debugf("Couldn't find a registration for %s at %s for resource %s at %s", entry.getPathElement().toString(), registration.getPathAddress().toCLIStyleString(), resource, address.toCLIStyleString());
                continue;
            }
            if(childRegistration.isRuntimeOnly() || childRegistration.isRemote() || childRegistration.isAlias()) {
                continue;
            }
            describeChildResource(entry, registration, address, context, failureRef, results, operation, nest);
        }
    }
}
 
Example 4
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static void processHostModel(final RequiredConfigurationHolder holder, final Resource domain, final Resource hostModel, ExtensionRegistry extensionRegistry) {

        final Set<String> serverGroups = holder.serverGroups;

        for (final Resource.ResourceEntry entry : hostModel.getChildren(SERVER_CONFIG)) {
            final ModelNode model = entry.getModel();
            final String serverGroup = model.get(GROUP).asString();

            if (!serverGroups.contains(serverGroup)) {
                serverGroups.add(serverGroup);
            }
            if (model.hasDefined(SOCKET_BINDING_GROUP)) {
                final String socketBindingGroup = model.get(SOCKET_BINDING_GROUP).asString();
                processSocketBindingGroup(domain, socketBindingGroup, holder);
            }
            // Always process the server group, since it may be different between the current vs. original model
            processServerGroup(holder, serverGroup, domain, extensionRegistry);
        }
    }
 
Example 5
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void describe(final PathAddress base, final Resource resource, List<ModelNode> nodes, boolean isRuntimeChange) {
    if (resource.isProxy() || resource.isRuntime()) {
        return; // ignore runtime and proxies
    } else if (base.size() >= 1 && base.getElement(0).getKey().equals(ModelDescriptionConstants.HOST)) {
        return; // ignore hosts
    }
    if (base.size() == 1) {
        newRootResources.add(base.getLastElement());
    }
    final ModelNode description = new ModelNode();
    description.get(DOMAIN_RESOURCE_ADDRESS).set(base.toModelNode());
    description.get(DOMAIN_RESOURCE_MODEL).set(resource.getModel());
    Set<String> orderedChildren = resource.getOrderedChildTypes();
    if (orderedChildren.size() > 0) {
        ModelNode orderedChildTypes = description.get(DOMAIN_RESOURCE_PROPERTIES, ORDERED_CHILD_TYPES_PROPERTY);
        for (String type : orderedChildren) {
            orderedChildTypes.add(type);
        }
    }
    nodes.add(description);
    for (final String childType : resource.getChildTypes()) {
        for (final Resource.ResourceEntry entry : resource.getChildren(childType)) {
            describe(base.append(entry.getPathElement()), entry, nodes, isRuntimeChange);
        }
    }
}
 
Example 6
Source File: ServerGroupDeploymentAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
static void validateRuntimeNames(String deploymentName, OperationContext context, PathAddress address) throws OperationFailedException {
    ModelNode deployment = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();

    if (ENABLED.resolveModelAttribute(context, deployment).asBoolean()) {
        Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
        ModelNode domainDeployment = root.getChild(PathElement.pathElement(DEPLOYMENT, deploymentName)).getModel();
        String runtimeName = getRuntimeName(deploymentName, deployment, domainDeployment);
        PathAddress sgAddress = address.subAddress(0, address.size() - 1);
        Resource serverGroup = root.navigate(sgAddress);
        for (Resource.ResourceEntry re : serverGroup.getChildren(DEPLOYMENT)) {
            String reName = re.getName();
            if (!deploymentName.equals(reName)) {
                ModelNode otherDepl = re.getModel();
                if (ENABLED.resolveModelAttribute(context, otherDepl).asBoolean()) {
                    domainDeployment = root.getChild(PathElement.pathElement(DEPLOYMENT, reName)).getModel();
                    String otherRuntimeName = getRuntimeName(reName, otherDepl, domainDeployment);
                    if (runtimeName.equals(otherRuntimeName)) {
                        throw DomainControllerLogger.ROOT_LOGGER.runtimeNameMustBeUnique(reName, runtimeName, sgAddress.getLastElement().getValue());
                    }
                }
            }
        }
    }
}
 
Example 7
Source File: DeploymentRemoveHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void checkCanRemove(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String deploymentName = PathAddress.pathAddress(operation.require(OP_ADDR)).getLastElement().getValue();
    final Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);

    if(root.hasChild(PathElement.pathElement(SERVER_GROUP))) {
        final List<String> badGroups = new ArrayList<String>();
        for(final Resource.ResourceEntry entry : root.getChildren(SERVER_GROUP)) {
            if(entry.hasChild(PathElement.pathElement(DEPLOYMENT, deploymentName))) {
                badGroups.add(entry.getName());
            }
        }

        if (badGroups.size() > 0) {
            throw new OperationFailedException(DomainControllerLogger.ROOT_LOGGER.cannotRemoveDeploymentInUse(deploymentName, badGroups));
        }
    }
}
 
Example 8
Source File: ExtensionRegistry.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean hasSubsystemsRegistered(Resource rootResource, String subsystem, boolean dcExtension) {
    if (!dcExtension) {
        return rootResource.getChild(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, subsystem)) != null;
    }

    for (Resource profile : rootResource.getChildren(PROFILE)) {
        if (profile.getChild(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, subsystem)) != null) {
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: VersionedExtension2.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void transformResource(ResourceTransformationContext context, PathAddress address, Resource resource) throws OperationFailedException {
    final ResourceTransformationContext childContext = context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource);
    for(final Resource.ResourceEntry entry : resource.getChildren("renamed")) {
        childContext.processChild(PathElement.pathElement("element", "renamed"), entry);
    }
}
 
Example 10
Source File: OperationContextImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
Resource readResourceFromRoot(ManagementModel managementModel, PathAddress address, boolean recursive) {
    //
    // TODO double check authorization checks for this!
    //
    Resource model = managementModel.getRootResource();
    final Iterator<PathElement> iterator = address.iterator();
    while(iterator.hasNext()) {
        final PathElement element = iterator.next();
        // Allow wildcard navigation for the last element
        if(element.isWildcard() && ! iterator.hasNext()) {
            final Set<Resource.ResourceEntry> children = model.getChildren(element.getKey());
            if(children.isEmpty()) {
                final PathAddress parent = address.subAddress(0, address.size() -1);
                final Set<String> childrenTypes = managementModel.getRootResourceRegistration().getChildNames(parent);
                if(! childrenTypes.contains(element.getKey())) {
                    throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
                }
                // Return an empty model
                return Resource.Factory.create();
            }
            model = Resource.Factory.create();
            for(final Resource.ResourceEntry entry : children) {
                model.registerChild(entry.getPathElement(), entry);
            }
        } else {
            model = requireChild(model, element, address);
        }
    }
    if(recursive) {
        return model.clone();
    } else {
        return model.shallowCopy();
    }
}
 
Example 11
Source File: ModelControllerImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void addAllAddresses(ImmutableManagementResourceRegistration mrr, PathAddress current, Resource resource, Set<PathAddress> addresses) {
    addresses.add(current);
    for (String name : getNonIgnoredChildTypes(mrr)) {
        for (ResourceEntry entry : resource.getChildren(name)) {
            if (!entry.isProxy() && !entry.isRuntime()) {
                addAllAddresses(mrr.getSubModel(PathAddress.pathAddress(entry.getPathElement())), current.append(entry.getPathElement()), entry, addresses);
            }
        }
    }
}
 
Example 12
Source File: DomainModelIncludesValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Set<String> checkSocketBindingGroupIncludes(Resource domain, Set<String> missingSocketBindingGroups) throws OperationFailedException {
    SocketBindingGroupIncludeValidator validator = new SocketBindingGroupIncludeValidator();
    for (ResourceEntry entry : domain.getChildren(SOCKET_BINDING_GROUP)) {
        validator.processResource(entry);
    }

    validator.validate(missingSocketBindingGroups);
    return new HashSet<>(validator.resourceIncludes.keySet());
}
 
Example 13
Source File: DomainModelIncludesValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Set<String> checkProfileIncludes(Resource domain, Set<String> missingProfiles) throws OperationFailedException {
    ProfileIncludeValidator validator = new ProfileIncludeValidator();
    for (ResourceEntry entry : domain.getChildren(PROFILE)) {
        validator.processResource(entry);
    }

    validator.validate(missingProfiles);
    return validator.resourceIncludes.keySet();
}
 
Example 14
Source File: OperationTransformationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode readModelRecursively(Resource resource) {
    ModelNode model = new ModelNode();
    model.set(resource.getModel().clone());

    for (String type : resource.getChildTypes()) {
        for (ResourceEntry entry : resource.getChildren(type)) {
            model.get(type, entry.getName()).set(readModelRecursively(entry));
        }
    }
    return model;
}
 
Example 15
Source File: JsonAuditLogFormatterResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void checkFormatterNotReferenced(String name, Resource auditLog, String...handlerTypes) throws OperationFailedException {
    for (String handlerType : handlerTypes) {
        for (ResourceEntry entry : auditLog.getChildren(handlerType)) {
            ModelNode auditLogModel = entry.getModel();
            if (auditLogModel.get(FORMATTER).asString().equals(name)) {
                throw DomainManagementLogger.ROOT_LOGGER.cannotRemoveReferencedFormatter(entry.getPathElement());
            }
        }
    }
}
 
Example 16
Source File: JmxAuditLogHandlerReferenceResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private boolean lookForHandlerForHc(OperationContext context, String name) {
    final Resource root = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
    for (ResourceEntry entry : root.getChildren(ModelDescriptionConstants.HOST)) {
        if (entry.getModel().isDefined()) {
            return lookForHandler(PathAddress.pathAddress(ModelDescriptionConstants.HOST, entry.getName()), root, name);
        }
    }
    return false;
}
 
Example 17
Source File: ChildRedirectTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testWildcardRedirect() throws Exception {
    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.addChildRedirection(CHILD, NEW_CHILD);
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);

    Set<String> types = toto.getChildTypes();
    Assert.assertEquals(1, types.size());
    Assert.assertTrue(types.contains(NEW_CHILD.getKey()));

    Set<ResourceEntry> entries = toto.getChildren(NEW_CHILD.getKey());
    Assert.assertEquals(2, entries.size());

    PathElement[] expectedChildren = new PathElement[] {PathElement.pathElement(NEW_CHILD.getKey(), CHILD_ONE.getValue()), PathElement.pathElement(NEW_CHILD.getKey(), CHILD_TWO.getValue())};
    for (PathElement expectedChild : expectedChildren) {
        boolean found = false;
        for (ResourceEntry entry : entries) {
            if (entry.getPathElement().equals(expectedChild)) {
                found = true;
                break;
            }
        }
        Assert.assertTrue(found);
    }

    //Test operations get redirected
    final ModelNode addOp = Util.createAddOperation(PathAddress.pathAddress(PATH, CHILD));
    OperationTransformer.TransformedOperation txOp = transformOperation(ModelVersion.create(1), addOp.clone());
    Assert.assertFalse(txOp.rejectOperation(success()));
    final ModelNode expectedTx = Util.createAddOperation(PathAddress.pathAddress(PATH, NEW_CHILD));
    Assert.assertEquals(expectedTx, txOp.getTransformedOperation());

    //Test operations in a composite get redirected
    final ModelNode composite = createComposite(addOp, addOp);
    txOp = transformOperation(ModelVersion.create(1), composite);
    Assert.assertFalse(txOp.rejectOperation(success()));
    Assert.assertEquals(createComposite(expectedTx, expectedTx), txOp.getTransformedOperation());
}
 
Example 18
Source File: OrderedChildMoreLevelsResourceSyncModelTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testComplexInsertOrderedChildrenModelSync() throws Exception {
    //Complex test
    ModelNode originalModel = readResourceRecursive();

    Resource rootResource = createMasterDcResources();
    createAndRegisterSubsystemChildFromRoot(rootResource, ORDERED_CHILD.getKey(), "grape", 1);
    createAndRegisterSubsystemChildFromRoot(rootResource, ORDERED_CHILD.getKey(), "lemon", 1);
    createAndRegisterSubsystemChildFromRoot(rootResource, ORDERED_CHILD.getKey(), "pear", 0);
    Resource cherry = createAndRegisterSubsystemChildFromRoot(rootResource, ORDERED_CHILD.getKey(), "cherry");
    createChildResource(cherry, EXTRA_CHILD.getKey(), "compot", 1);
    createChildResource(cherry, EXTRA_CHILD.getKey(), "cake", 1);
    createChildResource(cherry, EXTRA_CHILD.getKey(), "pancake", 0);
    createChildResource(cherry, EXTRA_CHILD.getKey(), "cider", -1);
    Resource apple = findSubsystemResource(rootResource).getChild(PathElement.pathElement(ORDERED_CHILD.getKey(), "apple"));
    createChildResource(apple, EXTRA_CHILD.getKey(), "compot", 1);
    createChildResource(apple, EXTRA_CHILD.getKey(), "cake", 1);
    createChildResource(apple, EXTRA_CHILD.getKey(), "pancake", 0);
    createChildResource(apple, EXTRA_CHILD.getKey(), "cider", -1);
    ModelNode master = Resource.Tools.readModel(rootResource);

    executeTriggerSyncOperation(rootResource);
    ModelNode currentModel = readResourceRecursive();

    Assert.assertNotEquals(originalModel, currentModel);
    compare(findSubsystemResource(currentModel).get(ORDERED_CHILD.getKey()).keys(), "pear", "apple", "lemon", "grape", "orange", "cherry");
    Set<String> appleKeys = findSubsystemResource(currentModel).get(ORDERED_CHILD.getKey(), "apple", EXTRA_CHILD.getKey()).keys();
    compare(appleKeys, "pancake", "jam", "cake", "compot", "juice", "cider");
    Set<String> cherryKeys = findSubsystemResource(currentModel).get(ORDERED_CHILD.getKey(), "cherry", EXTRA_CHILD.getKey()).keys();
    compare(cherryKeys, "pancake", "jam", "cake", "compot", "juice", "cider");
    compareSubsystemModels(master, currentModel);

    Resource subsystemResource = findSubsystemResource(rootResource);
    subsystemResource.removeChild(PathElement.pathElement(ORDERED_CHILD.getKey(), "pear"));
    subsystemResource.removeChild(PathElement.pathElement(ORDERED_CHILD.getKey(), "apple"));
    subsystemResource.removeChild(PathElement.pathElement(ORDERED_CHILD.getKey(), "lemon"));
    createAndRegisterSubsystemChildFromRoot(rootResource, ORDERED_CHILD.getKey(), "kiwi", 1);
    createAndRegisterSubsystemChildFromRoot(rootResource, ORDERED_CHILD.getKey(), "melon", 100);
    Resource orange = findSubsystemResource(rootResource).getChild(PathElement.pathElement(ORDERED_CHILD.getKey(), "orange"));
    orange.removeChild(PathElement.pathElement(EXTRA_CHILD.getKey(), "juice"));
    createChildResource(orange, EXTRA_CHILD.getKey(), "marmelade", 0);

    for (Resource.ResourceEntry child : subsystemResource.getChildren(ORDERED_CHILD.getKey())) {
        child.getModel().get(ATTR.getName()).set(child.getModel().get(ATTR.getName()).asString() + "$" + child.getName());
        for (Resource.ResourceEntry extraChild : child.getChildren(EXTRA_CHILD.getKey())) {
            extraChild.getModel().get(ATTR.getName()).set(extraChild.getModel().get(ATTR.getName()).asString() + "$" + extraChild.getName());
        }
    }
    master = Resource.Tools.readModel(rootResource);

    executeTriggerSyncOperation(rootResource);
    currentModel = readResourceRecursive();

    Assert.assertNotEquals(originalModel, currentModel);
    compare(findSubsystemResource(currentModel).get(ORDERED_CHILD.getKey()).keys(), "grape", "kiwi", "orange", "cherry", "melon");
    cherryKeys = findSubsystemResource(currentModel).get(ORDERED_CHILD.getKey(), "cherry", EXTRA_CHILD.getKey()).keys();
    compare(cherryKeys, "pancake", "jam", "cake", "compot", "juice", "cider");
    Set<String> orangeKeys = findSubsystemResource(currentModel).get(ORDERED_CHILD.getKey(), "orange", EXTRA_CHILD.getKey()).keys();
    compare(orangeKeys, "marmelade", "jam"); // <-- The order in current model is wrong
    compareSubsystemModels(master, currentModel);
}
 
Example 19
Source File: SyslogAuditLogHandlerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static SyslogAuditLogHandler createHandler(final PathManagerService pathManager,
                                           final OperationContext context,
                                           final String name,
                                           final Resource handlerResource,
                                           final EnvironmentNameReader environmentReader) throws OperationFailedException {
    ServiceName serviceName = SYSLOG_AUDIT_HANDLER.append(name);
    if(context.getServiceRegistry(true).getService(serviceName) != null) {
        context.removeService(serviceName);
    }
    SyslogAuditLogHandlerService service = SyslogAuditLogHandlerService.installService(context, serviceName, handlerResource);
    final ModelNode handlerModel = handlerResource.getModel();
    final String formatterName = FORMATTER.resolveModelAttribute(context, handlerModel).asString();
    final int maxFailureCount = MAX_FAILURE_COUNT.resolveModelAttribute(context, handlerModel).asInt();

    final SyslogAuditLogHandler handler = new SyslogAuditLogHandler(name, formatterName, maxFailureCount, pathManager, service);

    handler.setFacility(SyslogAuditLogHandler.Facility.valueOf(FACILITY.resolveModelAttribute(context, handlerModel).asString()));

    if (environmentReader.isServer()) {
        handler.setHostName(environmentReader.getHostName() != null ? environmentReader.getHostName() + ":" + environmentReader.getServerName() : environmentReader.getServerName());
    } else {
        handler.setHostName(environmentReader.getHostName());
    }

    handler.setAppName(resolveAppName(context, handlerModel.get(APP_NAME.getName()), environmentReader));


    handler.setSyslogType(SyslogHandler.SyslogType.valueOf(SYSLOG_FORMAT.resolveModelAttribute(context, handlerModel).asString()));
    handler.setTruncate(TRUNCATE.resolveModelAttribute(context, handlerModel).asBoolean());
    if (handlerModel.hasDefined(MAX_LENGTH.getName())) {
        handler.setMaxLength(MAX_LENGTH.resolveModelAttribute(context, handlerModel).asInt());
    }
    final Set<ResourceEntry> protocols = handlerResource.getChildren(PROTOCOL);
    if (protocols.isEmpty()) {
        //We already check in SyslogAuditLogProtocolResourceDefinition that there is only one protocol
        throw DomainManagementLogger.ROOT_LOGGER.noSyslogProtocol();
    }
    final ResourceEntry protocol = protocols.iterator().next();
    final SyslogAuditLogHandler.Transport transport = SyslogAuditLogHandler.Transport.valueOf(protocol.getPathElement().getValue().toUpperCase(Locale.ENGLISH));
    handler.setTransport(transport);
    try {
        handler.setSyslogServerAddress(
                InetAddress.getByName(
                        SyslogAuditLogProtocolResourceDefinition.HOST.resolveModelAttribute(context, protocol.getModel()).asString()));
    } catch (UnknownHostException e) {
        throw new OperationFailedException(e);
    }
    handler.setPort(SyslogAuditLogProtocolResourceDefinition.PORT.resolveModelAttribute(context, protocol.getModel()).asInt());
    if (transport != SyslogAuditLogHandler.Transport.UDP) {
        handler.setMessageTransfer(
                SyslogAuditLogHandler.MessageTransfer.valueOf(
                        SyslogAuditLogProtocolResourceDefinition.Tcp.MESSAGE_TRANSFER.resolveModelAttribute(context, protocol.getModel()).asString()));
        handler.setReconnectTimeout(SyslogAuditLogProtocolResourceDefinition.Tcp.RECONNECT_TIMEOUT.resolveModelAttribute(context, protocol.getModel()).asInt());
    }
    if (transport == SyslogAuditLogHandler.Transport.TLS) {
        final Set<ResourceEntry> tlsStores = protocol.getChildren(AUTHENTICATION);
        for (ResourceEntry storeEntry : tlsStores) {
            final ModelNode storeModel = storeEntry.getModel();
            String type = storeEntry.getPathElement().getValue();
            if (type.equals(CLIENT_CERT_STORE)) {
                handler.setTlsClientCertStorePassword(
                        resolveUndefinableAttribute(context,
                                SyslogAuditLogProtocolResourceDefinition.TlsKeyStore.KEYSTORE_PASSWORD, storeModel));
                handler.setTlsClientCertStorePath(
                        SyslogAuditLogProtocolResourceDefinition.TlsKeyStore.KEYSTORE_PATH.resolveModelAttribute(context, storeModel).asString());
                handler.setTlsClientCertStoreRelativeTo(
                        resolveUndefinableAttribute(context,
                                SyslogAuditLogProtocolResourceDefinition.TlsKeyStore.KEYSTORE_RELATIVE_TO, storeModel));
                handler.setTlsClientCertStoreKeyPassword(
                        resolveUndefinableAttribute(context,
                                SyslogAuditLogProtocolResourceDefinition.TlsKeyStore.KEY_PASSWORD, storeModel));
            } else if (type.equals(TRUSTSTORE)) {
                handler.setTlsTruststorePassword(
                        resolveUndefinableAttribute(context,
                                SyslogAuditLogProtocolResourceDefinition.TlsKeyStore.KEYSTORE_PASSWORD, storeModel));
                handler.setTlsTrustStorePath(
                        SyslogAuditLogProtocolResourceDefinition.TlsKeyStore.KEYSTORE_PATH.resolveModelAttribute(context, storeModel).asString());
                handler.setTlsTrustStoreRelativeTo(
                        resolveUndefinableAttribute(context,
                                SyslogAuditLogProtocolResourceDefinition.TlsKeyStore.KEYSTORE_RELATIVE_TO, storeModel));
            }
        }
    }
    return handler;
}
 
Example 20
Source File: AbstractOperationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static void hack(final Resource rootResource, final String type) {
    rootResource.registerChild(PathElement.pathElement(type, "hack"), Resource.Factory.create());
    for (Resource.ResourceEntry entry : rootResource.getChildren(type)) {
        rootResource.removeChild(entry.getPathElement());
    }
}