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

The following examples show how to use org.jboss.dmr.ModelNode#remove() . 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: BasicResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address,
                                               ModelNode operation) throws OperationFailedException {
    ModelNode remove = operation.clone();
    remove.get(OP).set(REMOVE);
    remove.remove("test");

    ModelNode add = operation.clone();
    add.get(OP).set(ADD);
    add.get("new").set("shiny");

    ModelNode composite = new ModelNode();
    composite.get(OP).set(COMPOSITE);
    composite.get(OP_ADDR).setEmptyList();
    composite.get(STEPS).add(remove);
    composite.get(STEPS).add(add);

    return new TransformedOperation(composite, OperationResultTransformer.ORIGINAL_RESULT);
}
 
Example 2
Source File: AbstractCoreModelTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ModelNode fixApplicationConstraint(ModelNode modelNode) {
    if (modelNode.hasDefined("core-service","management","access","authorization","constraint","application-classification","type")) {
        ModelNode typeNode = modelNode.get("core-service","management","access","authorization","constraint","application-classification","type");
        for (String type : typeNode.keys()) {
            if (typeNode.hasDefined(type, "classification")) {
                ModelNode classificationNode = typeNode.get(type, "classification");
                for (String classification : classificationNode.keys()) {
                    ModelNode target = classificationNode.get(classification);
                    if (target.has("default-application")) {
                        target.remove("default-application");
                    }
                }
            }
        }
    }
    return modelNode;
}
 
Example 3
Source File: ValidateModelTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void removeSubsystems(ModelNode description) {
    //TODO should remove all subsystems since they are tested in unit tests
    //but for now leave threads and remoting in since unit tests could not be created
    //for them due to circular maven dependencies

    ModelNode subsystemDescriptions = description.get(CHILDREN, SUBSYSTEM, MODEL_DESCRIPTION);
    Set<String> removes = new HashSet<String>();
    for (String key : subsystemDescriptions.keys()) {
        if (!key.equals(RemotingExtension.SUBSYSTEM_NAME) && !key.equals(ThreadsExtension.SUBSYSTEM_NAME)) {
            removes.add(key);
        }
    }

    for (String remove : removes) {
        subsystemDescriptions.remove(remove);
    }
}
 
Example 4
Source File: DomainControllerWriteAttributeHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    super.execute(context, operation);
    final ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel();
    ModelNode dc = model.get(DOMAIN_CONTROLLER);
    if (operation.hasDefined(VALUE, LOCAL)) {
        dc.get(LOCAL).setEmptyObject();
        if (dc.has(REMOTE)) {
            dc.remove(REMOTE);
        }
        if (context.isBooting()) {
            initializeLocalDomain(null);
        }
    } else if (operation.hasDefined(VALUE, REMOTE)) {
        if (dc.has(LOCAL)) {
            dc.remove(LOCAL);
        }
        final ModelNode remoteDC = dc.get(REMOTE);
        secureRemoteDomain(context, operation, remoteDC);
        if (context.isBooting()) {
            initializeRemoteDomain(context, remoteDC);
        }
    }
}
 
Example 5
Source File: NewExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
    ModelNode properties = operation.remove("properties");

    ModelNode composite = Util.createEmptyOperation("composite", PathAddress.EMPTY_ADDRESS);
    ModelNode steps = composite.get("steps");
    steps.add(operation);

    for (ModelNode property : properties.asList()) {
        Property prop = property.asProperty();
        ModelNode addProp = Util.createAddOperation(address.append("property", prop.getName()));
        addProp.get("value").set(prop.getValue());
        steps.add(addProp);
    }

    return new TransformedOperation(composite, TransformedOperation.ORIGINAL_RESULT);
}
 
Example 6
Source File: PersistentResourceXMLParserTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode opsToModel(List<ModelNode> operations) {
    ModelNode subsystem = new ModelNode();

    for (ModelNode addResourceOp : operations) {
        ModelNode resource = addResourceOp.clone();

        resource.remove("operation");
        PathAddress address = PathAddress.pathAddress(resource.remove("address"));
        subsystem.get(getAddress(address)).set(resource);
    }
    return subsystem;
}
 
Example 7
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 8
Source File: ManagedServerBootCmdFactory.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Resolve expressions in the given model (if there are any)
 *
 * @param unresolved node with possibly unresolved expressions. Cannot be {@code null}
 * @param expressionResolver resolver to use. Cannot be {@code null}
 * @param excludePostBootSystemProps {@code true} if child system-property nodes should be checked
 *                                               for the 'boot-time' attribute, with resolution being
 *                                               skipped if that is set to 'false'. WFCORE-450
 *
 * @return a clone of {@code unresolved} with all expression resolved
 */
static ModelNode resolveExpressions(final ModelNode unresolved, final ExpressionResolver expressionResolver, boolean excludePostBootSystemProps) {

    ModelNode toResolve = unresolved.clone();
    ModelNode sysProps = null;
    if (excludePostBootSystemProps && toResolve.hasDefined(SYSTEM_PROPERTY)) {
        sysProps = toResolve.remove(SYSTEM_PROPERTY);
    }
    try {
        ModelNode result = expressionResolver.resolveExpressions(toResolve);
        if (sysProps != null) {
            ModelNode resolvedSysProps = new ModelNode().setEmptyObject();
            for (Property property : sysProps.asPropertyList()) {
                ModelNode val = property.getValue();
                boolean bootTime = SystemPropertyResourceDefinition.BOOT_TIME.resolveModelAttribute(expressionResolver, val).asBoolean();
                if (bootTime) {
                    val.get(VALUE).set(SystemPropertyResourceDefinition.VALUE.resolveModelAttribute(expressionResolver, val));
                }
                // store the resolved boot-time to save re-resolving later
                val.get(BOOT_TIME).set(bootTime);
                resolvedSysProps.get(property.getName()).set(val);
            }
            result.get(SYSTEM_PROPERTY).set(resolvedSysProps);
        }
        return result;
    } catch (OperationFailedException e) {
        // Fail
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
Example 9
Source File: DiscoveryOptionsResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected Resource removeOption(String type, String name) {
    final ModelNode options = delegate.getModel().get(ModelDescriptionConstants.OPTIONS);
    if (!options.isDefined()) {
        return null;
    }
    final List<Property> list = options.asPropertyList();
    if (list.isEmpty()) {
        return null;
    }
    final boolean staticOption = ModelDescriptionConstants.STATIC_DISCOVERY.equals(type);
    Resource res = null;
    int i = 0;
    while (i < list.size() && res == null) {
        Property prop = list.get(i++);
        if (staticOption) {
            if (prop.getName().equals(ModelDescriptionConstants.STATIC_DISCOVERY)
                    && prop.getValue().has(ModelDescriptionConstants.NAME)
                    && prop.getValue().get(ModelDescriptionConstants.NAME).asString().equals(name)) {
                res = getResource(prop);
            }
        } else if (prop.getName().equals(ModelDescriptionConstants.CUSTOM_DISCOVERY) && prop.getValue().has(ModelDescriptionConstants.NAME)
                && prop.getValue().get(ModelDescriptionConstants.NAME).asString().equals(name)) {
            res = getResource(prop);
        }
    }
    if (res != null) {
        options.remove(i-1);
    }
    return res;
}
 
Example 10
Source File: LoggingSubsystemTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ModelNode fixModel(final ModelNode modelNode) {
    // Find the async-handler
    if (modelNode.hasDefined(AsyncHandlerResourceDefinition.NAME)) {
        final ModelNode asyncHandlers = modelNode.get(AsyncHandlerResourceDefinition.NAME);
        for (Property asyncHandler : asyncHandlers.asPropertyList()) {
            final ModelNode async = asyncHandler.getValue();
            async.remove(CommonAttributes.ENCODING.getName());
            async.remove(AbstractHandlerDefinition.FORMATTER.getName());
            asyncHandlers.get(asyncHandler.getName()).set(async);
        }
    }
    return modelNode;
}
 
Example 11
Source File: DomainDeploymentOverlayTransformersTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ModelNode fixModel(ModelNode modelNode) {
    modelNode = super.fixModel(modelNode);
    modelNode.remove(SOCKET_BINDING_GROUP);
    modelNode.remove(PROFILE);
    return modelNode;
}
 
Example 12
Source File: PolicyDefinitions.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.getType() == ModelType.LIST && newValue.asInt() == 1) {
        // extract the single element
        result = newValue.get(0);
        if (result.has(NAME)) {
            result.remove(NAME);
        }
    }
    return result;
}
 
Example 13
Source File: CoreModelTestDelegate.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void temporaryHack(ModelNode transformedModel, ModelNode legacyModel) {
    if (legacyModel.hasDefined(NAMESPACES) && !transformedModel.hasDefined(NAMESPACES)) {
        if (legacyModel.get(NAMESPACES).asList().isEmpty()) {
            legacyModel.get(NAMESPACES).set(new ModelNode());
        }
    }
    if (legacyModel.hasDefined(SCHEMA_LOCATIONS) && !transformedModel.hasDefined(SCHEMA_LOCATIONS)) {
        if (legacyModel.get(SCHEMA_LOCATIONS).asList().isEmpty()) {
            legacyModel.get(SCHEMA_LOCATIONS).set(new ModelNode());
        }
    }


    //We will test these in mixed-domain instead since something differs in the test setup for these attributes
    legacyModel.remove(MANAGEMENT_MAJOR_VERSION);
    legacyModel.remove(MANAGEMENT_MINOR_VERSION);
    legacyModel.remove(MANAGEMENT_MICRO_VERSION);
    legacyModel.remove(NAME);
    legacyModel.remove(RELEASE_CODENAME);
    legacyModel.remove(RELEASE_VERSION);
    transformedModel.remove(MANAGEMENT_MAJOR_VERSION);
    transformedModel.remove(MANAGEMENT_MINOR_VERSION);
    transformedModel.remove(MANAGEMENT_MICRO_VERSION);
    transformedModel.remove(NAME);
    transformedModel.remove(RELEASE_CODENAME);
    transformedModel.remove(RELEASE_VERSION);
}
 
Example 14
Source File: ReadConfigAsFeaturesDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void nonNestedHostTest() {
    ModelNode removeJvm = Util.createRemoveOperation(PathAddress.pathAddress(HOST, MASTER).append(JVM, DEFAULT));
    ModelNode addCustomJvm = Util.createAddOperation(PathAddress.pathAddress(HOST, MASTER).append(JVM, "custom"));
    ModelNode environmentVariables = new ModelNode();
    environmentVariables.get("DOMAIN_TEST_JVM").set("custom");
    addCustomJvm.get("heap-size").set("64m");
    addCustomJvm.get("jvm-options").add("-ea");
    addCustomJvm.get("max-heap-size").set("128m");
    addCustomJvm.get("environment-variables").set(environmentVariables);

    ModelNode expectedHostConfigAsFeatures = nonNestedHostConfigAsFeatures.clone();

    // remove the default jvm
    ModelNode defaultJvmId = new ModelNode();
    defaultJvmId.get(HOST).set(MASTER);
    defaultJvmId.get(JVM).set(DEFAULT);
    int defaultJvmIndex = getListElementIndex(expectedHostConfigAsFeatures, "host.jvm", defaultJvmId);
    expectedHostConfigAsFeatures.remove(defaultJvmIndex);

    // add the custom jvm
    ModelNode customJvm = new ModelNode();
    ModelNode customJvmId = new ModelNode();
    ModelNode customJvmParams = new ModelNode();
    ModelNode customJvmEnvVars = new ModelNode();
    customJvmEnvVars.get("DOMAIN_TEST_JVM").set("custom");
    customJvmParams.get("heap-size").set("64m");
    customJvmParams.get("jvm-options").add("-ea");
    customJvmParams.get("max-heap-size").set("128m");
    customJvmParams.get("environment-variables").set(customJvmEnvVars);
    customJvmId.get(HOST).set(MASTER);
    customJvmId.get(JVM).set("custom");
    customJvm.get(SPEC).set("host.jvm");
    customJvm.get(ID).set(customJvmId);
    customJvm.get(PARAMS).set(customJvmParams);
    expectedHostConfigAsFeatures.add(customJvm);

    doTest(Arrays.asList(removeJvm, addCustomJvm), expectedHostConfigAsFeatures, PathAddress.pathAddress(HOST, MASTER), false);
}
 
Example 15
Source File: JvmTransformersTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public ModelNode fixModel(ModelNode modelNode) {
    modelNode = super.fixModel(modelNode);
    modelNode.remove(SOCKET_BINDING_GROUP);
    if (!isIgnoredResourceListAvailableAtRegistration()) {
        modelNode.get(SERVER_GROUP, "test", JVM, "full").remove(LAUNCH_COMMAND.getName());
        modelNode.get(SERVER_GROUP, "test", JVM, "full").remove(MODULE_OPTIONS.getName());
    }
    return isFailExpressions() ? resolve(modelNode) : modelNode;
}
 
Example 16
Source File: ReadFeatureDescriptionHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void addReferences(ModelNode feature, ImmutableManagementResourceRegistration registration) {
    PathAddress address = registration.getPathAddress();
    if (address == null || PathAddress.EMPTY_ADDRESS.equals(address)) {
        return;
    }
    ModelNode refs = feature.get(REFS).setEmptyList();
    if (registration.getParent() != null && registration.getParent().isFeature()) {
        addReference(refs, registration.getParent());
    }
    PathElement element = registration.getPathAddress().getLastElement();
    if (SUBSYSTEM.equals(element.getKey())) {
        ModelNode ref = new ModelNode();
        final String rootType = registration.getPathAddress().getElement(0).getKey();
        if (HOST.equals(rootType)) {
            ref.get(FEATURE).set(HOST_EXTENSION);
        } else if (PROFILE.equals(rootType)) {
            ref.get(FEATURE).set(DOMAIN_EXTENSION);
        } else {
            ref.get(FEATURE).set(EXTENSION);
        }
        ref.get(INCLUDE).set(true);
        refs.add(ref);
    }
    if (refs.asList().isEmpty()) {
        feature.remove(REFS);
    }
}
 
Example 17
Source File: DomainRootTransformersTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testRejectTransformersEAP() throws Exception {
    if (modelVersion.getMajor() > 1) {
        return;
    }
    KernelServicesBuilder builder = createKernelServicesBuilder(TestModelType.DOMAIN)
            .setModelInitializer(StandardServerGroupInitializers.XML_MODEL_INITIALIZER, StandardServerGroupInitializers.XML_MODEL_WRITE_SANITIZER);


    // Add legacy subsystems
    StandardServerGroupInitializers.addServerGroupInitializers(builder.createLegacyKernelServicesBuilder(modelVersion, testControllerVersion));
    KernelServices mainServices = builder.build();

    PathAddress address = PathAddress.EMPTY_ADDRESS;
    //List<ModelNode> ops = builder.parseXmlResource("domain-root.xml");

    //check that we reject /:suspend-servers(timeout=?)
    OperationTransformer.TransformedOperation transOp = mainServices.transformOperation(modelVersion, Util.createOperation("suspend-servers", address));
    Assert.assertTrue(transOp.getFailureDescription(), transOp.rejectOperation(success()));

    //check that we reject /:resume-servers()
    transOp = mainServices.transformOperation(modelVersion, Util.createOperation("resume-servers", address));
    Assert.assertNull("operation should have been discarded", transOp.getTransformedOperation());

    // check that we reject new attribute /:stop-servers(blocking=true, timeout=?) (new timeout attribute)
    ModelNode stopServerOp = Util.createOperation("stop-servers", address);
    stopServerOp.get(TIMEOUT).set(1000);
    transOp = mainServices.transformOperation(modelVersion, stopServerOp);
    Assert.assertTrue(transOp.getFailureDescription(), transOp.rejectOperation(success()));
    stopServerOp.remove(TIMEOUT);
    transOp = mainServices.transformOperation(modelVersion, stopServerOp); //this operation shouldn't be rejected
    Assert.assertFalse(transOp.getFailureDescription(), transOp.rejectOperation(success()));

}
 
Example 18
Source File: ModelTestUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static ModelNode trimUndefinedChildren(ModelNode model) {
    ModelNode copy = model.clone();
    for (String key : new HashSet<String>(copy.keys())) {
        if (!copy.hasDefined(key)) {
            copy.remove(key);
        } else if (copy.get(key).getType() == ModelType.OBJECT) {
            for (ModelNode mn : model.get(key).asList()) {
                boolean undefined = true;
                Property p = mn.asProperty();
                if (p.getValue().getType() != ModelType.OBJECT) { continue; }
                for (String subKey : new HashSet<String>(p.getValue().keys())) {
                    if (copy.get(key, p.getName()).hasDefined(subKey)) {
                        undefined = false;
                        break;
                    } else {
                        copy.get(key, p.getName()).remove(subKey);
                    }
                }
                if (undefined) {
                    copy.get(key).remove(p.getName());
                    if (!copy.hasDefined(key)) {
                        copy.remove(key);
                    } else if (copy.get(key).getType() == ModelType.OBJECT) {     //this is stupid workaround
                        if (copy.get(key).keys().size() == 0) {
                            copy.remove(key);
                        }
                    }
                }
            }
        }
    }
    return copy;
}
 
Example 19
Source File: DiscardAttributesTransformer.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode transformInternal(ModelNode model) {
    for (String attr : attributeNames) {
        model.remove(attr);
    }
    return model;
}
 
Example 20
Source File: DomainServerLifecycleHandlers.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void renameTimeoutToSuspendTimeout(ModelNode operation) {
    if (!operation.hasDefined(SUSPEND_TIMEOUT.getName()) && operation.hasDefined(TIMEOUT.getName())) {
        operation.get(SUSPEND_TIMEOUT.getName()).set(operation.get(TIMEOUT.getName()));
        operation.remove(TIMEOUT.getName());
    }
}