Java Code Examples for org.jboss.as.controller.operations.common.Util#createRemoveOperation()

The following examples show how to use org.jboss.as.controller.operations.common.Util#createRemoveOperation() . 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: RemoveResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void testRemoveWithWriteAttributeSensitivity(StandardRole role, boolean success) throws Exception {
    ChildResourceDefinition def = new ChildResourceDefinition(ONE);
    def.addAttribute("test", WRITE_CONSTRAINT);
    rootRegistration.registerSubModel(def);

    Resource resourceA = Resource.Factory.create();
    resourceA.getModel().get("test").set("a");
    rootResource.registerChild(ONE_A, resourceA);

    Resource resourceB = Resource.Factory.create();
    resourceB.getModel().get("test").set("b");
    rootResource.registerChild(ONE_B, resourceB);

    ModelNode op = Util.createRemoveOperation(ONE_B_ADDR);
    op.get(OPERATION_HEADERS, "roles").set(role.toString());
    if (success) {
        executeForResult(op);
    } else {
        executeForFailure(op);
    }
}
 
Example 2
Source File: StandaloneRootResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testNoNameSetInXml() throws Exception {
    String originalXml = "<server xmlns=\"" + Namespace.CURRENT.getUriString() + "\"/>";
    KernelServices kernelServices = createKernelServicesBuilder()
            .setXml(originalXml)
            .build();
    Assert.assertTrue(kernelServices.isSuccessfulBoot());

    ModelNode read = Util.createOperation(READ_ATTRIBUTE_OPERATION, PathAddress.EMPTY_ADDRESS);
    read.get(NAME).set(NAME);
    Assert.assertEquals(getDefaultServerName(), kernelServices.executeForResult(read).asString());

    //Add and remove a system property so that some ops get executed on the model to trigger persistence, as it is there are none
    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.SYSTEM_PROPERTY, "test")));
    add.get(VALUE).set("123");
    ModelTestUtils.checkOutcome(kernelServices.executeOperation(add));
    ModelNode remove = Util.createRemoveOperation(PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.SYSTEM_PROPERTY, "test")));
    ModelTestUtils.checkOutcome(kernelServices.executeOperation(remove));

    String persistedXml = kernelServices.getPersistedSubsystemXml();
    ModelTestUtils.compareXml(originalXml, persistedXml);
}
 
Example 3
Source File: AbstractVaultTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testAddAndRemoveEmptyVault() throws Exception {
    KernelServices kernelServices = createEmptyRoot();

    ModelNode model = readVaultModel(kernelServices);
    Assert.assertFalse(model.isDefined());

    ModelNode add = Util.createAddOperation(vaultAddress);
    ModelTestUtils.checkOutcome(kernelServices.executeOperation(add));
    model = readVaultModel(kernelServices);
    Assert.assertTrue(model.isDefined());

    Assert.assertFalse(model.get(CODE).isDefined());
    Assert.assertFalse(model.get(VAULT_OPTIONS).isDefined());

    ModelNode remove = Util.createRemoveOperation(vaultAddress);
    ModelTestUtils.checkOutcome(kernelServices.executeOperation(remove));
    model = readVaultModel(kernelServices);
    Assert.assertFalse(model.isDefined());
}
 
Example 4
Source File: HcExtensionAndSubsystemManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void removeExtension(ModelControllerClient client, PathAddress extensionAddress, boolean success) throws Exception {
    ModelNode op = Util.createRemoveOperation(extensionAddress);
    if (success) {
        DomainTestUtils.executeForResult(op, client);
    } else {
        DomainTestUtils.executeForFailure(op, client);
    }
}
 
Example 5
Source File: ProfileIncludesHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testGoodProfileIncludesRemove() throws Exception {
    PathAddress addr = getProfileAddress("profile-four");
    ModelNode op = Util.createRemoveOperation(addr);
    MockOperationContext operationContext = getOperationContextWithIncludes(addr);
    ProfileRemoveHandler.INSTANCE.execute(operationContext, op);
    // WFCORE-833 no next validation step any more
    //operationContext.executeNextStep();
}
 
Example 6
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 7
Source File: AccessIdentityConfigurator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String setAccessIdentity(ModelControllerClient client, String domainToSet) throws Exception {
    String origDomainValue = null;
    ModelNode op = Util.createEmptyOperation("read-attribute", IDENTITY_ADDR);
    op.get("name").set("security-domain");
    ModelNode result = client.execute(op);
    boolean identityExists = Operations.isSuccessfulOutcome(result);
    op = null;
    if (identityExists) {
        result = Operations.readResult(result);
        origDomainValue = result.isDefined() ? result.asString() : null;

        if (domainToSet == null) {
            op = Util.createRemoveOperation(IDENTITY_ADDR);
        } else if (!domainToSet.equals(origDomainValue)) {
            op = Util.createEmptyOperation("write-attribute", IDENTITY_ADDR);
            op.get("name").set("security-domain");
            op.get("value").set(domainToSet);
        }
    } else if (domainToSet != null) {
        op = Util.createAddOperation(IDENTITY_ADDR);
        op.get("security-domain").set(domainToSet);
    }

    if (op!=null) {
        CoreUtils.applyUpdate(op, client);
    }
    return origDomainValue;
}
 
Example 8
Source File: DeploymentRolloutFailureTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void cleanDeployment() throws IOException, MgmtOperationException {
    ModelNode op = Util.createRemoveOperation(PathAddress.pathAddress(DEPLOYMENT_PATH));
    DomainTestUtils.executeForResult(op, masterClient);
}
 
Example 9
Source File: RBACModelOutOfSyncScenario.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
void setUpDomain(DomainTestSupport testSupport, DomainClient masterClient, DomainClient slaveClient) throws Exception {
    cleanSnapshotDirectory(masterClient, null);
    cleanSnapshotDirectory(masterClient, "master");
    cleanSnapshotDirectory(slaveClient, "slave");

    takeSnapshot(masterClient, null);
    takeSnapshot(masterClient, "master");
    takeSnapshot(slaveClient, "slave");

    domainSnapshots = listSnapshots(masterClient, null);
    masterSnapshots = listSnapshots(masterClient, "master");
    slaveSnapshots = listSnapshots(slaveClient, "slave");

    Assert.assertEquals(1, domainSnapshots.size());
    Assert.assertEquals(1, masterSnapshots.size());
    Assert.assertEquals(1, slaveSnapshots.size());

    ModelNode operation = Util.createRemoveOperation(MASTER_ADDR.append(CORE_SRV_MNGMT).append(SEC_REALM_MNGMT_REALM).append(AUTHENTICATION_LOCAL));
    DomainTestUtils.executeForResult(operation, masterClient);

    operation = Util.createRemoveOperation(SLAVE_ADDR.append(CORE_SRV_MNGMT).append(SEC_REALM_MNGMT_REALM).append(AUTHENTICATION_LOCAL));
    DomainTestUtils.executeForResult(operation, masterClient);

    operation = Util.getWriteAttributeOperation(SLAVE_ADDR, "domain-controller.remote.username", "slave");
    DomainTestUtils.executeForResult(operation, masterClient);

    operation = Util.getWriteAttributeOperation(SLAVE_ADDR, "domain-controller.remote.security-realm", "ManagementRealm");
    DomainTestUtils.executeForResult(operation, masterClient);

    operation = Util.getWriteAttributeOperation(CORE_SRV_MNGMT.append(ACCESS_AUTHORIZATION), PROVIDER, "rbac");
    DomainTestUtils.executeForResult(operation, masterClient);

    operation = Util.createAddOperation(CORE_SRV_MNGMT.append(ACCESS_AUTHORIZATION).append(ROLE_MAPPING, "SuperUser").append(INCLUDE, "ManagementRealm"));
    operation.get(NAME).set("slave");
    operation.get(TYPE).set("USER");
    DomainTestUtils.executeForResult(operation, masterClient);

    reloadHost(testSupport.getDomainMasterLifecycleUtil(), "master", null, null);
    reloadHost(testSupport.getDomainSlaveLifecycleUtil(), "slave", null, null);
}
 
Example 10
Source File: AbstractAuditLogHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected ModelNode createRemovePeriodicRotatingFileHandlerOperation(String handlerName) {
    return Util.createRemoveOperation(createPeriodicRotatingFileHandlerAddress(handlerName));
}
 
Example 11
Source File: ReadConfigAsFeaturesStandaloneTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void coreManagementTest() throws UnsuccessfulOperationException {
    ModelNode removeSecurityRealm = Util.createRemoveOperation(
            PathAddress.pathAddress(CORE_SERVICE, MANAGEMENT).append(SECURITY_REALM, "ApplicationRealm"));
    ModelNode addCustomSecurityRealm = Util.createAddOperation(
            PathAddress.pathAddress(CORE_SERVICE, MANAGEMENT).append(SECURITY_REALM, "CustomRealm"));
    addCustomSecurityRealm.get("map-groups-to-roles").set(false);
    ModelNode configureCustomSecurityRealm = Util.createAddOperation(
            PathAddress.pathAddress(CORE_SERVICE, MANAGEMENT).append(SECURITY_REALM, "CustomRealm").append("authentication", "local"));
    configureCustomSecurityRealm.get("default-user").set("john");
    configureCustomSecurityRealm.get("allowed-users").set("john");
    configureCustomSecurityRealm.get("skip-group-loading").set(true);

    ModelNode expectedConfigAsFeatures = defaultConfigAsFeatures.clone();
    ModelNode managementCoreService = getFeatureNodeChild(expectedConfigAsFeatures.get(0), "core-service.management");

    // remove ApplicationRealm
    ModelNode applicationSecurityRealmId = new ModelNode();
    applicationSecurityRealmId.get(SECURITY_REALM).set("ApplicationRealm");
    int applicationSecurityRealmIndex = getFeatureNodeChildIndex(managementCoreService, "core-service.management.security-realm", applicationSecurityRealmId);
    managementCoreService.get(CHILDREN).remove(applicationSecurityRealmIndex);

    // create model nodes for the new CustomRealm
    ModelNode customRealmId = new ModelNode();
    customRealmId.get(SECURITY_REALM).set("CustomRealm");
    ModelNode customRealmParams = new ModelNode();
    customRealmParams.get("map-groups-to-roles").set(false);

    // create the authentication model node for the new CustomRealm
    ModelNode customRealmAuthentication = new ModelNode();
    customRealmAuthentication.get(SPEC).set("core-service.management.security-realm.authentication.local");
    ModelNode authenticationId = new ModelNode();
    authenticationId.get(AUTHENTICATION).set(LOCAL);
    customRealmAuthentication.get(ID).set(authenticationId);
    ModelNode authenticationParams = new ModelNode();
    authenticationParams.get("default-user").set("john");
    authenticationParams.get("allowed-users").set("john");
    authenticationParams.get("skip-group-loading").set(true);
    customRealmAuthentication.get(PARAMS).set(authenticationParams);

    // set up the CustomRealm model node
    ModelNode customRealm = new ModelNode();
    customRealm.get(SPEC).set("core-service.management.security-realm");
    customRealm.get(ID).set(customRealmId);
    customRealm.get(PARAMS).set(customRealmParams);
    customRealm.get(CHILDREN).add(customRealmAuthentication);

    // append the CustomRealm model node to the expected model
    managementCoreService.get(CHILDREN).add(customRealm);

    doTest(Arrays.asList(removeSecurityRealm, addCustomSecurityRealm, configureCustomSecurityRealm), expectedConfigAsFeatures);
}
 
Example 12
Source File: LegacyConfigurationChangesHistoryTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@After
public void clearConfigurationChanges() throws IOException {
    ModelControllerClient client = getModelControllerClient();
    final ModelNode remove = Util.createRemoveOperation(ADDRESS);
    client.execute(remove);
}
 
Example 13
Source File: ConfigurationChangesHistoryTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@After
public void clearConfigurationChanges() throws IOException {
    ModelControllerClient client = getModelControllerClient();
    final ModelNode remove = Util.createRemoveOperation(ADDRESS);
    client.execute(remove);
}
 
Example 14
Source File: HcExtensionAndSubsystemManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testExtensionSubsystemComposite() throws Exception {
    DomainClient slaveClient = domainSlaveLifecycleUtil.getDomainClient();
    Exception err = null;
    try {
        // 1) Sanity check -- subsystem not there
        ModelNode read = Util.getReadAttributeOperation(SLAVE_SUBSYSTEM_ADDRESS, NAME);
        testBadOp(read);

        // 2) sanity check -- subsystem add w/o extension -- fail
        ModelNode subAdd = Util.createAddOperation(SLAVE_SUBSYSTEM_ADDRESS);
        subAdd.get(NAME).set(TestHostCapableExtension.MODULE_NAME);
        testBadOp(subAdd);

        // 3) ext add + sub add + sub other in composite
        ModelNode extAdd = Util.createAddOperation(SLAVE_EXTENSION_ADDRESS);
        ModelNode goodAdd = buildComposite(extAdd, subAdd, read);
        testGoodComposite(goodAdd);

        // 4) Sanity check -- try read again outside the composite
        ModelNode response = executeOp(read, "success");
        assertTrue(response.toString(), response.has("result"));
        assertEquals(response.toString(), TestHostCapableExtension.MODULE_NAME, response.get("result").asString());

        // 5) sub remove + ext remove + sub add in composite -- fail
        ModelNode subRemove = Util.createRemoveOperation(SLAVE_SUBSYSTEM_ADDRESS);
        ModelNode extRemove = Util.createRemoveOperation(SLAVE_EXTENSION_ADDRESS);
        ModelNode badRemove = buildComposite(read, subRemove, extRemove, subAdd);
        response = testBadOp(badRemove);
        // But the 'public' op should have worked
        validateInvokePublicStep(response, 1, true);

        // 6) sub remove + ext remove in composite
        ModelNode goodRemove = buildComposite(read, subRemove, extRemove);
        response = executeOp(goodRemove, "success");
        validateInvokePublicStep(response, 1, false);

        // 7) confirm ext add + sub add + sub other still works
        testGoodComposite(goodAdd);

        // 8) Sanity check -- try read again outside the composite
        response = executeOp(read, "success");
        assertTrue(response.toString(), response.has("result"));
        assertEquals(response.toString(), TestHostCapableExtension.MODULE_NAME, response.get("result").asString());
    } catch (Exception e) {
        err = e;
    } finally {
        //Cleanup
        removeIgnoreFailure(slaveClient, SLAVE_SUBSYSTEM_ADDRESS);
        removeIgnoreFailure(slaveClient, SLAVE_EXTENSION_ADDRESS);
    }

    if (err != null) {
        throw err;
    }
}
 
Example 15
Source File: DeploymentRolloutFailureTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void cleanDeploymentFromServerGroup() throws IOException, MgmtOperationException {
    ModelNode op = Util.createRemoveOperation(PathAddress.pathAddress(MAIN_SERVER_GROUP, DEPLOYMENT_PATH));
    op.get(ENABLED).set(true);
    op.get(OPERATION_HEADERS, ROLLOUT_PLAN).set(getRolloutPlanO());
    DomainTestUtils.executeForResult(op, masterClient);
}
 
Example 16
Source File: OperationWarningTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void remove(final PathAddress address) throws Exception {
    ModelNode removeOp = Util.createRemoveOperation(address);
    ModelNode resp = ManagementOperations.executeOperationRaw(serverController.getClient().getControllerClient(), removeOp);
    assertEquals("Unexpected outcome " + resp + " of remove operation: " + removeOp, ModelDescriptionConstants.SUCCESS,
            resp.get("outcome").asString());
}
 
Example 17
Source File: ConfigurationChangesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void clearProfileConfigurationChange(PathElement profile) throws IOException, UnsuccessfulOperationException {
    DomainClient client = domainMasterLifecycleUtil.getDomainClient();
    final ModelNode remove = Util.createRemoveOperation(PathAddress.pathAddress().append(profile).append(getAddress()));
    executeForResult(client, remove);
}
 
Example 18
Source File: ConfigurationChangesHistoryTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Before
public void createConfigurationChanges() throws Exception {
    ManagementInterface client = getClientForUser(SUPERUSER_USER);
    final ModelNode add = Util.createAddOperation(PathAddress.pathAddress(ADDRESS));
    add.get("max-history").set(MAX_HISTORY_SIZE);
    client.execute(add);
    // WFCORE-3995 sensitivity classification system property default configured-requires-read is false.
    // Need to write configured-requires-read before configured-requires-addressable
    ModelNode configureSensitivity = Util.getWriteAttributeOperation(SYSTEM_PROPERTY_CLASSIFICATION_ADDRESS, CONFIGURED_REQUIRES_READ, true);
    client.execute(configureSensitivity);
    configureSensitivity = Util.getWriteAttributeOperation(SYSTEM_PROPERTY_CLASSIFICATION_ADDRESS, CONFIGURED_REQUIRES_ADDRESSABLE, true);
    client.execute(configureSensitivity);
    ModelNode setAllowedOrigins = Util.createEmptyOperation("list-add", ALLOWED_ORIGINS_ADDRESS);
    setAllowedOrigins.get(NAME).set(ALLOWED_ORIGINS);
    setAllowedOrigins.get(VALUE).set( "http://www.wildfly.org");
    client.execute(setAllowedOrigins);
    ModelNode disableLogBoot = Util.getWriteAttributeOperation(AUDIT_LOG_ADDRESS, LOG_BOOT, false);
    client.execute(disableLogBoot);
    //read
    client.execute(Util.getReadAttributeOperation(ALLOWED_ORIGINS_ADDRESS, ALLOWED_ORIGINS));
    //invalid operation
    client.execute(Util.getUndefineAttributeOperation(ALLOWED_ORIGINS_ADDRESS, "not-exists-attribute"));
    //invalid operation
    client.execute(Util.getWriteAttributeOperation(ALLOWED_ORIGINS_ADDRESS, "not-exists-attribute", "123456"));
    //write operation, failed
    ModelNode setAllowedOriginsFails = Util.getWriteAttributeOperation(ALLOWED_ORIGINS_ADDRESS, ALLOWED_ORIGINS, "123456");//wrong type, expected is LIST, op list-add
    client.execute(setAllowedOriginsFails);
    ModelNode setSystemProperty = Util.createAddOperation(SYSTEM_PROPERTY_ADDRESS);
    setSystemProperty.get(VALUE).set("changeConfig");
    client.execute(setSystemProperty);
    ModelNode unsetAllowedOrigins = Util.getUndefineAttributeOperation(ALLOWED_ORIGINS_ADDRESS, ALLOWED_ORIGINS);
    client.execute(unsetAllowedOrigins);
    ModelNode enableLogBoot = Util.getWriteAttributeOperation(AUDIT_LOG_ADDRESS, LOG_BOOT, true);
    client.execute(enableLogBoot);
    ModelNode unsetSystemProperty = Util.createRemoveOperation(SYSTEM_PROPERTY_ADDRESS);
    client.execute(unsetSystemProperty);
    ModelNode addInMemoryHandler = Util.createAddOperation(IN_MEMORY_HANDLER_ADDRESS);
    client.execute(addInMemoryHandler);
    ModelNode editInMemoryHandler = Util.getWriteAttributeOperation(IN_MEMORY_HANDLER_ADDRESS, MAX_HISTORY, 50);
    client.execute(editInMemoryHandler);
    ModelNode removeInMemoryHandler = Util.createRemoveOperation(IN_MEMORY_HANDLER_ADDRESS);
    client.execute(removeInMemoryHandler);
}
 
Example 19
Source File: AbstractConfigurationChangesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void clearConfigurationChanges(PathElement host) throws UnsuccessfulOperationException {
    DomainClient client = domainMasterLifecycleUtil.getDomainClient();
    final ModelNode remove = Util.createRemoveOperation(PathAddress.pathAddress().append(host).append(getAddress()));
    executeForResult(client, remove);
}
 
Example 20
Source File: AbstractAuditLogHandlerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected ModelNode createRemoveSizeRotatingFileHandlerOperation(String handlerName) {
    return Util.createRemoveOperation(createSizeRotatingFileHandlerAddress(handlerName));
}