Java Code Examples for org.jboss.dmr.ModelNode#hasDefined()

The following examples show how to use org.jboss.dmr.ModelNode#hasDefined() . 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: HostControllerUpdateTask.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public ModelNode transformResult(ModelNode result) {
    final boolean reject = rejectOperation(result);
    if(reject) {
        result.get(FAILURE_DESCRIPTION).set(getFailureDescription());
    }
    if(result.has(RESULT, DOMAIN_RESULTS)) {
        final ModelNode domainResults = result.get(RESULT, DOMAIN_RESULTS);
        if(domainResults.getType() == ModelType.STRING && IGNORED.equals(domainResults.asString())) {
            // Untransformed
            return result;
        }
        final ModelNode userResult = new ModelNode();
        userResult.get(OUTCOME).set(result.get(OUTCOME));
        userResult.get(RESULT).set(domainResults);
        if(result.hasDefined(FAILURE_DESCRIPTION)) {
            userResult.get(FAILURE_DESCRIPTION).set(result.get(FAILURE_DESCRIPTION));
        }
        // Transform the result
        final ModelNode transformed = resultTransformer.transformResult(userResult);
        result.get(RESULT, DOMAIN_RESULTS).set(transformed.get(RESULT));
        return result;
    } else {
        return resultTransformer.transformResult(result);
    }
}
 
Example 2
Source File: ManagedServerOperationsFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void convertApplicationClassificationConstraints(ModelNode model, ModelNode baseAddress, ModelNodeList updates) {
    PathAddress constraintAddress = PathAddress.pathAddress(baseAddress).append(CONSTRAINT, APPLICATION_CLASSIFICATION);
    if (model.hasDefined(TYPE)) {
        for (Property prop : model.get(TYPE).asPropertyList()) {
            PathAddress constraintTypeAddress = constraintAddress.append(TYPE, prop.getName());
            if (prop.getValue().hasDefined(CLASSIFICATION)) {
                for (Property classification : prop.getValue().get(CLASSIFICATION).asPropertyList()) {
                    PathAddress classificationAddress = constraintTypeAddress.append(CLASSIFICATION, classification.getName());
                    if (classification.getValue().hasDefined(CONFIGURED_APPLICATION)) {
                        ModelNode addOp = Util.getWriteAttributeOperation(classificationAddress, CONFIGURED_APPLICATION, classification.getValue().get(CONFIGURED_APPLICATION).asBoolean());
                        updates.add(addOp);
                    }
                }
            }
        }
    }
}
 
Example 3
Source File: LdapCacheResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void flushCache(OperationContext context, ModelNode operation) throws OperationFailedException {
    LdapSearcherCache<?, LdapEntry> ldapCacheService = lookupService(context, operation);

    String name = null;
    String distinguishedName = null;

    if (operation.hasDefined(ModelDescriptionConstants.NAME)) {
        name = operation.require(ModelDescriptionConstants.NAME).asString();
    }
    if (operation.hasDefined(ModelDescriptionConstants.DISTINGUISHED_NAME)) {
        distinguishedName = operation.require(ModelDescriptionConstants.DISTINGUISHED_NAME).asString();
    }

    if (name == null && distinguishedName == null) {
        ldapCacheService.clearAll();
    } else if (name != null && distinguishedName != null) {
        ldapCacheService.clear(new LdapEntry(name, distinguishedName));
    } else {
        ldapCacheService.clear(new LdapEntryPredicate(name, distinguishedName));
    }
}
 
Example 4
Source File: ElytronUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static String findConstantRealmMapper(CommandContext ctx, String realmName) throws IOException, OperationFormatException {
    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
    builder.setOperationName(Util.READ_CHILDREN_RESOURCES);
    builder.addNode(Util.SUBSYSTEM, Util.ELYTRON);
    builder.addProperty(Util.CHILD_TYPE, Util.CONSTANT_REALM_MAPPER);
    ModelNode request = builder.buildRequest();
    ModelNode response = ctx.getModelControllerClient().execute(request);
    if (Util.isSuccess(response)) {
        if (response.hasDefined(Util.RESULT)) {
            ModelNode res = response.get(Util.RESULT);
            for (String csName : res.keys()) {
                ModelNode mn = res.get(csName);
                String constantName = mn.get(Util.REALM_NAME).asString();
                if (realmName.equals(constantName)) {
                    return csName;
                }
            }
        }
    }
    return null;
}
 
Example 5
Source File: ElytronUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static String findKeyStoreRealm(CommandContext ctx, String trustStore) throws IOException, OperationFormatException {
    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
    String name = null;
    builder.setOperationName(Util.READ_CHILDREN_RESOURCES);
    builder.addNode(Util.SUBSYSTEM, Util.ELYTRON);
    builder.addProperty(Util.CHILD_TYPE, Util.KEY_STORE_REALM);
    ModelNode response = ctx.getModelControllerClient().execute(builder.buildRequest());
    if (Util.isSuccess(response)) {
        if (response.hasDefined(Util.RESULT)) {
            ModelNode mn = response.get(Util.RESULT);
            for (String key : mn.keys()) {
                ModelNode ksr = mn.get(key);
                if (ksr.hasDefined(Util.KEY_STORE)) {
                    String ks = ksr.get(Util.KEY_STORE).asString();
                    if (ks.equals(trustStore)) {
                        name = key;
                        break;
                    }
                }
            }
        }
    }
    return name;
}
 
Example 6
Source File: ManagedServerBootCmdFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void addSystemProperties(final ModelNode source, final Map<String, String> props, boolean boottimeOnly) {
    if (source.hasDefined(SYSTEM_PROPERTY)) {
        for (Property prop : source.get(SYSTEM_PROPERTY).asPropertyList()) {
            ModelNode propResource = prop.getValue();
            try {
                if (boottimeOnly && !SystemPropertyResourceDefinition.BOOT_TIME.resolveModelAttribute(expressionResolver, propResource).asBoolean()) {
                    continue;
                }
            } catch (OperationFailedException e) {
                throw new IllegalStateException(e);
            }
            String val = propResource.hasDefined(VALUE) ? propResource.get(VALUE).asString() : null;
            props.put(prop.getName(), val);
        }
    }
}
 
Example 7
Source File: DomainClientImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
ModelNode executeForResult(Operation op) {
    try {
        ModelNode result = delegate.execute(op);
        if (result.hasDefined("outcome") && "success".equals(result.get("outcome").asString())) {
            return result.get("result");
        }
        else if (result.hasDefined("failure-description")) {
            throw new RuntimeException(result.get("failure-description").toString());
        }
        else if (result.hasDefined("domain-failure-description")) {
            throw new RuntimeException(result.get("domain-failure-description").toString());
        }
        else if (result.hasDefined("host-failure-descriptions")) {
            throw new RuntimeException(result.get("host-failure-descriptions").toString());
        }
        else {
            throw ControllerClientLogger.ROOT_LOGGER.operationOutcome(result.get("outcome").asString());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Source File: OperationValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private DescriptionProvider getDescriptionProvider(final ModelNode operation) {
    if (!operation.hasDefined(OP)) {
        throw ControllerLogger.ROOT_LOGGER.validationFailedOperationHasNoField(OP, formatOperationForMessage(operation));
    }
    if (!operation.hasDefined(OP_ADDR)) {
        throw ControllerLogger.ROOT_LOGGER.validationFailedOperationHasNoField(OP_ADDR, formatOperationForMessage(operation));
    }
    final String name = operation.get(OP).asString();
    if (name == null || name.trim().length() == 0) {
        throw ControllerLogger.ROOT_LOGGER.validationFailedOperationHasANullOrEmptyName(formatOperationForMessage(operation));
    }

    final PathAddress addr = getPathAddress(operation);

    final DescriptionProvider provider = root.getOperationDescription(addr, name);
    if (provider == null) {
        throw ControllerLogger.ROOT_LOGGER.validationFailedNoOperationFound(name, addr, formatOperationForMessage(operation));
    }
    return provider;
}
 
Example 9
Source File: ManagedServerOperationsFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void addSystemProperties(final ModelNode source, final Map<String, String> props, boolean boottimeOnly) {
    if (source.hasDefined(SYSTEM_PROPERTY)) {
        for (Property prop : source.get(SYSTEM_PROPERTY).asPropertyList()) {
            ModelNode propResource = prop.getValue();
            try {
                if (boottimeOnly && !SystemPropertyResourceDefinition.BOOT_TIME.resolveModelAttribute(domainController.getExpressionResolver(), propResource).asBoolean()) {
                    continue;
                }
            } catch (OperationFailedException e) {
                throw new IllegalStateException(e);
            }
            String val = propResource.hasDefined(VALUE) ? propResource.get(VALUE).asString() : null;
            props.put(prop.getName(), val);
        }
    }
}
 
Example 10
Source File: KeycloakAdapterConfigService.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void massageProviderProps(ModelNode provider) {
    if (!provider.hasDefined("properties")) return;
    ModelNode providerProps = provider.remove("properties");
    for (Property prop : providerProps.asPropertyList()) {
        ModelNode value = prop.getValue();
        if (isArray(value.asString().trim())) {
            provider.get(prop.getName()).set(ModelNode.fromString(value.asString()).asList());
        } else {
            provider.get(prop.getName()).set(value);
        }
    }
}
 
Example 11
Source File: DeploymentTransformers.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void convertAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
    if (attributeValue.isDefined()) {
        for (ModelNode content : attributeValue.asList()) {
            if (!isUnmanagedContent(content)) {
                if (content.hasDefined(ARCHIVE) && content.get(ARCHIVE).asBoolean(true)) {
                    content.remove(ARCHIVE);
                }
            }
        }
    }
}
 
Example 12
Source File: GenericTypeOperationHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
    protected void printHelp(CommandContext ctx) throws CommandLineException {

        ParsedCommandLine args = ctx.getParsedCommandLine();
        if(helpProperties.isPresent(args)) {
            printProperties(ctx, getNodeProperties(ctx));
            return;
        }

        if(helpCommands.isPresent(args)) {
            printSupportedCommands(ctx);
            return;
        }

        final String operationName = operation.getValue(args);
        if(operationName == null) {
            printNodeDescription(ctx);
            return;
        }

/*        if(customHandlers != null && customHandlers.containsKey(operationName)) {
            OperationCommand operationCommand = customHandlers.get(operationName);
            operationCommand.handle(ctx);
            return;
        }
*/
        final ModelNode result = getOperationDescription(ctx, operationName);
        if(!result.hasDefined(Util.DESCRIPTION)) {
            throw new CommandLineException("Operation description is not available.");
        }

        ctx.printLine("\nDESCRIPTION:\n");
        formatText(ctx, result.get(Util.DESCRIPTION).asString(), 2);

        if(result.hasDefined(Util.REQUEST_PROPERTIES)) {
            printProperties(ctx, getAttributeIterator(result.get(Util.REQUEST_PROPERTIES).asPropertyList(), null));
        } else {
            printProperties(ctx, Collections.<AttributeDescription>emptyIterator());
        }
    }
 
Example 13
Source File: MBeanInfoFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private OpenType<?> getReturnType(ModelNode opNode) {
    if (!opNode.hasDefined(REPLY_PROPERTIES)) {
        return SimpleType.VOID;
    }
    if (opNode.get(REPLY_PROPERTIES).asList().size() == 0) {
        return SimpleType.VOID;
    }

    //TODO might have more than one REPLY_PROPERTIES?
    ModelNode reply = opNode.get(REPLY_PROPERTIES);
    return converters.convertToMBeanType(reply);
}
 
Example 14
Source File: IgnoredResourcesProfileCloneTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void test01_ProfileCloneIgnoredWithIgnoreUnusedConfiguration() throws Exception {
    final DomainClient masterClient = masterLifecycleUtil.getDomainClient();
    final DomainClient slaveClient = slaveLifecycleUtil.getDomainClient();

    try {
        final ModelNode originalSlaveDc = DomainTestUtils.executeForResult(
                Util.getReadAttributeOperation(SLAVE_ADDR, DOMAIN_CONTROLLER),
                masterClient).get(REMOTE);
        originalSlaveDc.protect();
        if (originalSlaveDc.hasDefined(IGNORE_UNUSED_CONFIG) && !originalSlaveDc.get(IGNORE_UNUSED_CONFIG).asBoolean()) {
            Assert.fail("ignore-unused-config should be undefined or true");
        }
        // clone profile
        ModelNode clone = Util.createEmptyOperation(CLONE, PathAddress.pathAddress(PROFILE, ORIGINAL_PROFILE));
        clone.get(TO_PROFILE).set(CLONED_PROFILE);
        DomainTestUtils.executeForResult(clone, masterClient);
        try {
            // get and check submodules
            List<String> originalSubsystems = getSubsystems(ORIGINAL_PROFILE, masterClient);
            List<String> newSubsystems = getSubsystems(CLONED_PROFILE, masterClient);
            assertEquals(originalSubsystems, newSubsystems);

            //Since the slave ignores unused config, the new profile should not exist on the slave
            List<String> slaveSubsystems = getChildNames(PathAddress.EMPTY_ADDRESS, PROFILE, slaveClient);
            Assert.assertTrue(slaveSubsystems.contains(ORIGINAL_PROFILE));
            Assert.assertFalse(slaveSubsystems.contains(CLONED_PROFILE));
        } finally {
            DomainTestUtils.executeForResult(Util.createRemoveOperation(PathAddress.pathAddress(PROFILE, CLONED_PROFILE)), masterClient);
        }
    } finally {
        IoUtils.safeClose(slaveClient);
        IoUtils.safeClose(masterClient);
    }
}
 
Example 15
Source File: JobAcquisitionAdd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model,
        ServiceVerificationHandler verificationHandler, List<ServiceController<?>> newControllers)
        throws OperationFailedException {

  String acquisitionName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();

  MscRuntimeContainerJobExecutor mscRuntimeContainerJobExecutor = new MscRuntimeContainerJobExecutor();

  if (model.hasDefined(PROPERTIES)) {

    List<Property> properties = SubsystemAttributeDefinitons.PROPERTIES.resolveModelAttribute(context, model).asPropertyList();

    for (Property property : properties) {
      String name = property.getName();
      String value = property.getValue().asString();
      PropertyHelper.applyProperty(mscRuntimeContainerJobExecutor, name, value);
    }

  }

  // start new service for job executor
  ServiceController<RuntimeContainerJobExecutor> serviceController = context.getServiceTarget().addService(ServiceNames.forMscRuntimeContainerJobExecutorService(acquisitionName), mscRuntimeContainerJobExecutor)
    .addDependency(ServiceNames.forMscRuntimeContainerDelegate())
    .addDependency(ServiceNames.forMscExecutorService())
    .addListener(verificationHandler)
    .setInitialMode(Mode.ACTIVE)
    .install();

  newControllers.add(serviceController);

}
 
Example 16
Source File: AccessControlXml.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static Map<String, Map<String, Set<String>>> getSensitivityClassificationConstraints(final ModelNode constraint) {
    Map<String, Map<String, Set<String>>> configuredConstraints = new HashMap<String, Map<String, Set<String>>>();

    if (constraint.hasDefined(SENSITIVITY_CLASSIFICATION)) {
        ModelNode sensitivityParent = constraint.require(SENSITIVITY_CLASSIFICATION);

        if (sensitivityParent.hasDefined(TYPE)) {
            for (Property typeProperty : sensitivityParent.get(TYPE).asPropertyList()) {
                if (typeProperty.getValue().hasDefined(CLASSIFICATION)) {
                    for (Property sensitivityProperty : typeProperty.getValue().get(CLASSIFICATION).asPropertyList()) {
                        ModelNode classification = sensitivityProperty.getValue();
                        if (classification.hasDefined(SensitivityResourceDefinition.CONFIGURED_REQUIRES_ADDRESSABLE.getName())
                                || classification.hasDefined(SensitivityResourceDefinition.CONFIGURED_REQUIRES_WRITE
                                        .getName())
                                || classification.hasDefined(SensitivityResourceDefinition.CONFIGURED_REQUIRES_READ
                                        .getName())) {
                            Map<String, Set<String>> constraintMap = configuredConstraints.get(SENSITIVITY_CLASSIFICATION);
                            if (constraintMap == null) {
                                constraintMap = new TreeMap<String, Set<String>>();
                                configuredConstraints.put(SENSITIVITY_CLASSIFICATION, constraintMap);
                            }
                            Set<String> types = constraintMap.get(typeProperty.getName());
                            if (types == null) {
                                types = new TreeSet<String>();
                                constraintMap.put(typeProperty.getName(), types);
                            }
                            types.add(sensitivityProperty.getName());
                        }
                    }
                }
            }
        }
    }

    return configuredConstraints;
}
 
Example 17
Source File: ModelTestModelDescriptionValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String validate(ModelType currentType, ModelNode currentNode, String descriptor) {
    if (currentNode.hasDefined(descriptor)) {
        if (currentType != ModelType.LIST && currentType != ModelType.STRING &&
                currentType != ModelType.BYTES) {
            return "Unnecessary '" + descriptor + "' for non-numeric type=" + currentType;
        }
        try {
            currentNode.get(descriptor).asLong();
        } catch (Exception e) {
            return "'" + descriptor + "' is not an int/long";
        }
    }
    return null;
}
 
Example 18
Source File: CoreModelTestDelegate.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode findModelNode(ModelNode model, String...name){
    ModelNode currentModel = model;
    for (String part : name){
        if (!currentModel.hasDefined(part)){
            return new ModelNode();
        } else {
            currentModel = currentModel.get(part);
        }
    }
    return currentModel;
}
 
Example 19
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 20
Source File: DomainDeploymentOverlayRedeployLinksHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Check if this is a redeployment triggered after the removal of a link.
 * @param operation the current operation.
 * @return true if this is a redeploy after the removal of a link.
 * @see org.jboss.as.server.deploymentoverlay.DeploymentOverlayDeploymentRemoveHandler
 */
private boolean isRedeployAfterRemoval(ModelNode operation) {
    return operation.hasDefined(DEPLOYMENT_OVERLAY_LINK_REMOVAL) &&
            operation.get(DEPLOYMENT_OVERLAY_LINK_REMOVAL).asBoolean();
}