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

The following examples show how to use org.jboss.dmr.ModelNode#set() . 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: ManagedServerOperationsFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void addManagementConnections(List<ModelNode> updates) {
    if (hostModel.get(CORE_SERVICE, MANAGEMENT, LDAP_CONNECTION).isDefined()) {
        ModelNode baseAddress = new ModelNode();
        baseAddress.add(CORE_SERVICE, MANAGEMENT);

        ModelNode connections = hostModel.get(CORE_SERVICE, MANAGEMENT, LDAP_CONNECTION);
        for (String connectionName : connections.keys()) {
            ModelNode addConnection = new ModelNode();
            // First take the properties to pass over.
            addConnection.set(connections.get(connectionName));

            // Now convert it to an operation by adding a name and address.
            ModelNode identityAddress = baseAddress.clone().add(LDAP_CONNECTION, connectionName);
            addAddNameAndAddress(addConnection, identityAddress);

            updates.add(addConnection);
        }
    }
}
 
Example 2
Source File: ParsedRolloutPlanHeader.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
    public void addTo(CommandContext ctx, ModelNode headers) throws CommandFormatException {

        if(planRef != null) {
/*            final OperationRequestHeader rolloutPlan = ctx.getConfig().getRolloutPlan(planRef);
            if(rolloutPlan == null) {
                throw new CommandFormatException("Rollout plan with id '" + planRef + "' could not be found.");
            }
            rolloutPlan.addTo(ctx, headers);
*/
            ModelNode rolloutPlan = Util.getRolloutPlan(ctx.getModelControllerClient(), planRef);
            headers.set(rolloutPlan);
            return;
        }
        ModelNode header = headers.get(Util.ROLLOUT_PLAN);
        final ModelNode series = header.get(Util.IN_SERIES);
        for(RolloutPlanGroup group : groups) {
            group.addTo(series);
        }

        if(props != null) {
            for(String propName : props.keySet()) {
                header.get(propName).set(props.get(propName));
            }
        }
    }
 
Example 3
Source File: AnalysisContext.java    From revapi with Apache License 2.0 6 votes vote down vote up
private static void mergeNodes(String extension, String id, List<String> path, ModelNode a, ModelNode b) {
    switch (b.getType()) {
        case LIST:
            for (ModelNode v : b.asList()) {
                a.add(v.clone());
            }
            break;
        case OBJECT:
            for (String k : b.keys()) {
                ModelNode ak = a.get(k);
                path.add(k);
                mergeNodes(extension, id, path, ak, b.get(k));
                path.remove(path.size() - 1);
            }
            break;
        default:
            if (a.isDefined()) {
                String p = path.stream().collect(Collectors.joining("/"));
                throw new IllegalArgumentException(
                        "A conflict detected while merging configurations of extension '" + extension +
                                "' with id '" + id + "'. A value on path '" + p + "' would overwrite an already existing one.");
            } else {
                a.set(b);
            }
    }
}
 
Example 4
Source File: CommandHeadersParsingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testArgumentValueConverterWithCustomHeader() throws Exception {

    final ModelNode node = converter.fromString(ctx, "{ foo=\"1 2 3\"; rollback-on-runtime-failure=false}");

    final ModelNode expectedHeaders = new ModelNode();
    final ModelNode foo = expectedHeaders.get("foo");
    foo.set("1 2 3");
    final ModelNode rollback = expectedHeaders.get(Util.ROLLBACK_ON_RUNTIME_FAILURE);
    rollback.set("false");

    assertEquals(expectedHeaders, node);
}
 
Example 5
Source File: PatchingHistory.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void fillHistoryIn(ModelNode result, Entry entry) throws PatchingException {
    ModelNode history = new ModelNode();
    history.get(Constants.PATCH_ID).set(entry.getPatchId());
    history.get(Constants.TYPE).set(entry.getType().getName());
    final ModelNode appliedAtNode = history.get(Constants.APPLIED_AT);
    if(entry.getAppliedAt() != null) {
        appliedAtNode.set(entry.getAppliedAt());
    }
    history.get(Constants.AGED_OUT).set(entry.isAgedOut());
    result.add(history);
}
 
Example 6
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 7
Source File: CaseParameterCorrector.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ModelNode correct(final ModelNode newValue, final ModelNode currentValue) {
    if (newValue.getType() == ModelType.UNDEFINED) {
        return newValue;
    }
    if (newValue.getType() != ModelType.STRING || currentValue.getType() != ModelType.STRING) {
        return newValue;
    }
    final String stringValue = newValue.asString();
    final String uCase = stringValue.toLowerCase(Locale.ENGLISH);
    if (!stringValue.equals(uCase)) {
        newValue.set(uCase);
    }
    return newValue;
}
 
Example 8
Source File: LegacyTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testPropertyTypeConverter() {
    ModelNode description = createDescription(ModelType.PROPERTY);
    TypeConverter converter = getConverter(description);

    ModelNode node = new ModelNode();
    node.set("name", "value");
    node.protect();

    Assert.assertEquals(SimpleType.STRING, converter.getOpenType());
    String dmr = assertCast(String.class, converter.fromModelNode(node));
    Assert.assertEquals(node, ModelNode.fromString(dmr));
    Assert.assertEquals(dmr, assertCast(String.class, converter.fromModelNode(node)));
    assertToArray(converter, dmr);
}
 
Example 9
Source File: BaseOperationCommand.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void addHeaders(CommandContext ctx, ModelNode request) throws CommandFormatException {
    if(headers == null || !headers.isPresent(ctx.getParsedCommandLine())) {
        return;
    }
    final ModelNode headersNode = headers.toModelNode(ctx);
    if (headersNode != null && headersNode.getType() != ModelType.OBJECT) {
        throw new CommandFormatException("--headers option has wrong value '"+headersNode+"'");
    }
    final ModelNode opHeaders = request.get(Util.OPERATION_HEADERS);
    opHeaders.set(headersNode);
}
 
Example 10
Source File: BindingRuntimeHandlers.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
void execute(final ModelNode operation, final SocketBinding binding, final ModelNode result) {
    ManagedBinding managedBinding = binding.getManagedBinding();
    if (managedBinding != null) {
        int port = managedBinding.getBindAddress().getPort();
        result.set(port);
    }
}
 
Example 11
Source File: ElytronUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static ModelNode removeMechanisms(CommandContext ctx, ModelNode factory,
        String factoryName, AuthFactorySpec spec, Set<String> toRemove) throws Exception {
    if (factory.hasDefined(Util.MECHANISM_CONFIGURATIONS)) {
        List<ModelNode> remains = new ArrayList<>();
        Set<String> seen = new HashSet<>();
        ModelNode mechanisms = factory.get(Util.MECHANISM_CONFIGURATIONS);
        for (ModelNode m : mechanisms.asList()) {
            String name = m.get(Util.MECHANISM_NAME).asString();
            if (!toRemove.contains(name)) {
                remains.add(m);
            }
            seen.add(name);
        }
        for (String r : toRemove) {
            if (!seen.contains(r)) {
                throw new Exception("Mechanism " + r
                        + " is not contained in factory " + factoryName);
            }
        }
        if (remains.isEmpty()) {
            throw new Exception("Error: All mechanisms would be removed, this would fully disable access. "
                    + "To fully disable authentication, don't provide mechanism.");
        }
        ModelNode newValue = new ModelNode();
        newValue.set(remains);
        DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
        builder.setOperationName(Util.WRITE_ATTRIBUTE);
        builder.addNode(Util.SUBSYSTEM, Util.ELYTRON);
        builder.addNode(spec.getResourceType(), factoryName);
        builder.addProperty(Util.NAME, Util.MECHANISM_CONFIGURATIONS);
        builder.getModelNode().get(Util.VALUE).set(newValue);
        return builder.buildRequest();
    } else {
        throw new Exception("No mechanism to remove in Factory " + factoryName);
    }
}
 
Example 12
Source File: ObjectTypeAttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ModelNode correct(ModelNode newValue, ModelNode currentValue) {
    ModelNode result = newValue;
    if (newValue.isDefined()) {
        for (AttributeDefinition ad : valueTypes) {
            ParameterCorrector fieldCorrector = ad.getCorrector();
            if (fieldCorrector != null) {
                String name = ad.getName();
                boolean has = newValue.has(name);
                ModelNode toCorrect = has ? newValue.get(name) : new ModelNode();
                ModelNode curField = currentValue.has(name) ? currentValue.get(name) : new ModelNode();
                ModelNode corrected = fieldCorrector.correct(toCorrect, curField);
                if (!corrected.equals(toCorrect) || (!has && corrected.isDefined())) {
                    if (has) {
                        toCorrect.set(corrected);
                    } else {
                        // the corrector defined it, so add it
                        newValue.get(name).set(corrected);
                    }
                }
            }
        }
    }
    if (topCorrector != null) {
        result = topCorrector.correct(result, currentValue);
    }
    return result;
}
 
Example 13
Source File: HostDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void initCoreModel(final ModelNode root, HostControllerEnvironment environment) {

        try {
            root.get(RELEASE_VERSION).set(Version.AS_VERSION);
            root.get(RELEASE_CODENAME).set(Version.AS_RELEASE_CODENAME);
        } catch (RuntimeException e) {
            if (HostAddHandler.class.getClassLoader() instanceof ModuleClassLoader) {
                //The standalone tests can't get this info
                throw e;
            }
        }
        root.get(MANAGEMENT_MAJOR_VERSION).set(Version.MANAGEMENT_MAJOR_VERSION);
        root.get(MANAGEMENT_MINOR_VERSION).set(Version.MANAGEMENT_MINOR_VERSION);
        root.get(MANAGEMENT_MICRO_VERSION).set(Version.MANAGEMENT_MICRO_VERSION);

        // Community uses UNDEF values
        ModelNode nameNode = root.get(PRODUCT_NAME);
        ModelNode versionNode = root.get(PRODUCT_VERSION);

        if (environment != null) {
            String productName = environment.getProductConfig().getProductName();
            String productVersion = environment.getProductConfig().getProductVersion();

            if (productName != null) {
                nameNode.set(productName);
            }
            if (productVersion != null) {
                versionNode.set(productVersion);
            }
        }

        //Set empty lists for namespaces and schema-locations to pass model validation
        root.get(NAMESPACES).setEmptyList();
        root.get(SCHEMA_LOCATIONS).setEmptyList();
    }
 
Example 14
Source File: ProxyStepHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode processResponseHeaders(ModelNode responseHeaders) {
    if (!responseHeaders.hasDefined(ACCESS_CONTROL) || !forServer) {
        return responseHeaders;
    } else {
        ModelNode result = responseHeaders.clone();
        for (ModelNode accItem : result.get(ACCESS_CONTROL).asList()) {
            ModelNode itemAddrNode = accItem.get(ABSOLUTE_ADDRESS);
            PathAddress itemAddr = PathAddress.pathAddress(itemAddrNode);
            itemAddrNode.set(proxyController.getProxyNodeAddress().append(itemAddr).toModelNode());
        }
        return result;
    }
}
 
Example 15
Source File: MainKernelServicesImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ModelNode readTransformedModel(ModelVersion modelVersion) {
    checkIsMainController();

    ModelNode domainModel = new ModelNode();
    //Reassemble the model from the reead master domain model handler result
    for (ModelNode entry : callReadMasterDomainModelHandler(modelVersion).asList()) {
        PathAddress address = PathAddress.pathAddress(entry.require("domain-resource-address"));
        ModelNode toSet = domainModel;
        for (PathElement pathElement : address) {
            toSet = toSet.get(pathElement.getKey(), pathElement.getValue());
        }
        toSet.set(entry.require("domain-resource-model"));
    }
    return domainModel;
}
 
Example 16
Source File: BasicResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void convertAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
    attributeValue.set(attributeValue.asString().toUpperCase());
}
 
Example 17
Source File: PlatformMBeanUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void nullSafeSet(final ModelNode node, final String value) {
    if (value != null) {
        node.set(value);
    }
}
 
Example 18
Source File: ThreadMXBeanAttributeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static void storeResult(final String name, final ModelNode store) {

        if (PlatformMBeanConstants.OBJECT_NAME.getName().equals(name)) {
            store.set(ManagementFactory.THREAD_MXBEAN_NAME);
        } else if (PlatformMBeanConstants.THREAD_COUNT.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().getThreadCount());
        } else if (PlatformMBeanConstants.PEAK_THREAD_COUNT.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().getPeakThreadCount());
        } else if (PlatformMBeanConstants.TOTAL_STARTED_THREAD_COUNT.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().getTotalStartedThreadCount());
        } else if (PlatformMBeanConstants.DAEMON_THREAD_COUNT.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().getDaemonThreadCount());
        } else if (PlatformMBeanConstants.ALL_THREAD_IDS.equals(name)) {
            store.setEmptyList();
            for (Long id : ManagementFactory.getThreadMXBean().getAllThreadIds()) {
                store.add(id);
            }
        } else if (PlatformMBeanConstants.THREAD_CONTENTION_MONITORING_SUPPORTED.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().isThreadContentionMonitoringSupported());
        } else if (PlatformMBeanConstants.THREAD_CONTENTION_MONITORING_ENABLED.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().isThreadContentionMonitoringEnabled());
        } else if (PlatformMBeanConstants.CURRENT_THREAD_CPU_TIME.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime());
        } else if (PlatformMBeanConstants.CURRENT_THREAD_USER_TIME.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().getCurrentThreadUserTime());
        } else if (PlatformMBeanConstants.THREAD_CPU_TIME_SUPPORTED.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().isThreadCpuTimeSupported());
        } else if (PlatformMBeanConstants.CURRENT_THREAD_CPU_TIME_SUPPORTED.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().isCurrentThreadCpuTimeSupported());
        } else if (PlatformMBeanConstants.THREAD_CPU_TIME_ENABLED.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().isThreadCpuTimeEnabled());
        } else if (PlatformMBeanConstants.OBJECT_MONITOR_USAGE_SUPPORTED.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().isObjectMonitorUsageSupported());
        } else if (PlatformMBeanConstants.SYNCHRONIZER_USAGE_SUPPORTED.equals(name)) {
            store.set(ManagementFactory.getThreadMXBean().isSynchronizerUsageSupported());
        } else if (ThreadResourceDefinition.THREADING_READ_ATTRIBUTES.contains(name)
                || ThreadResourceDefinition.THREADING_READ_WRITE_ATTRIBUTES.contains(name)
                || ThreadResourceDefinition.THREADING_METRICS.contains(name)) {
            // Bug
            throw PlatformMBeanLogger.ROOT_LOGGER.badReadAttributeImpl(name);
        }

    }
 
Example 19
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void convertAttribute(PathAddress address, String name, ModelNode attributeValue, TransformationContext context) {
    if (!name.equals("dontAdd")) {
        attributeValue.set(name);
    }
}
 
Example 20
Source File: AttributeConverter.java    From wildfly-core with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Creates an AttributeConverter where the conversion is to a hard-coded value, with
 * the ability to restrict the conversion to cases where the value being converted is
 * {@link org.jboss.dmr.ModelType#UNDEFINED}.
 * <p>
 * The expected use case for setting the {@code undefinedOnly} param to {@code true} is to
 * ensure a legacy slave sees the correct value following a change in a default between releases.
 * If the attribute being converted is undefined, then the default value is relevant, and in order
 * to function consistently with newer slaves, the legacy slave will need to be given the new
 * default in place of "undefined".
 * </p>
 *
 * @param hardCodedValue the value to set the attribute to
 * @param undefinedOnly {@code true} if the conversion should only occur if the {@code attributeValue}
 *                                  param is {@link org.jboss.dmr.ModelType#UNDEFINED}
 * @return the created attribute converter
 */
public static AttributeConverter createHardCoded(final ModelNode hardCodedValue, final boolean undefinedOnly) {
    return new DefaultAttributeConverter() {
        @Override
        public void convertAttribute(PathAddress address, String name, ModelNode attributeValue, TransformationContext context) {
            if (!undefinedOnly || !attributeValue.isDefined()) {
                attributeValue.set(hardCodedValue);
            }
        }
    };
}