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

The following examples show how to use org.jboss.as.controller.operations.common.Util#createEmptyOperation() . 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: DomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Regression test for WFCORE-2614 - don't allow duplicating realms referenced from a single domain.
 */
@Test
public void testDuplicateRealmValidation() throws Exception {
    init();

    ModelNode realmNode = new ModelNode();

    ModelNode operation = Util.createEmptyOperation("list-add", PathAddress.pathAddress("subsystem", "elytron")
            .append(ElytronDescriptionConstants.SECURITY_DOMAIN, "MyDomain"));
    operation.get(ClientConstants.NAME).set(ElytronDescriptionConstants.REALMS);

    realmNode.get("realm").set("PropRealm");
    operation.get("value").set(realmNode);
    Assert.assertNotNull(assertFail(services.executeOperation(operation)).get(ClientConstants.RESULT).asString());

    realmNode.get("realm").set("FileRealm");
    operation.get("value").set(realmNode);
    Assert.assertNotNull(assertFail(services.executeOperation(operation)).get(ClientConstants.RESULT).asString());

    realmNode.get("realm").set("NonDomainRealm");
    operation.get("value").set(realmNode);
    Assert.assertNotNull(assertSuccess(services.executeOperation(operation)).get(ClientConstants.RESULT).asString());
}
 
Example 2
Source File: ServerManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testBZ1015098() throws Exception {

    ModelNode compositeOp = Util.createEmptyOperation(COMPOSITE, PathAddress.EMPTY_ADDRESS);
    ModelNode steps = compositeOp.get(STEPS);
    steps.add(Util.createAddOperation(PathAddress.pathAddress(PathElement.pathElement(PROFILE, "BZ1015098"))));
    steps.add(Util.createEmptyOperation(RESTART, PathAddress.pathAddress(
            PathElement.pathElement(HOST, "slave"),
            PathElement.pathElement(SERVER_CONFIG, "other-two")
    )));

    ModelControllerClient client = testSupport.getDomainMasterLifecycleUtil().getDomainClient();
    DomainTestSupport.validateResponse(client.execute(compositeOp));

    final ModelNode read = new ModelNode();
    read.get(OP).set(READ_RESOURCE_OPERATION);
    read.get(OP_ADDR).set(PathAddress.pathAddress(PathElement.pathElement(PROFILE, "BZ1015098")).toModelNode());

    DomainTestSupport.validateResponse(client.execute(read));

}
 
Example 3
Source File: MetricsUndefinedValueUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void checkTestMetric(String expectedValue, Boolean includeUndefinedMetric) throws Exception {
    ModelNode result = getResult(client.execute(Util.getReadAttributeOperation(ADDRESS, TEST_METRIC)));
    Assert.assertEquals(expectedValue, result.asString());

    ModelNode rr = Util.createEmptyOperation(READ_RESOURCE_OPERATION, ADDRESS);
    rr.get(INCLUDE_RUNTIME).set(true);
    if (includeUndefinedMetric != null) {
        rr.get(INCLUDE_UNDEFINED_METRIC_VALUES).set(includeUndefinedMetric.booleanValue());
    }
    result = getResult(client.execute(rr));
    if (includeUndefinedMetric != null && includeUndefinedMetric.booleanValue()) {
        Assert.assertFalse(result.hasDefined(TEST_METRIC));
    } else {
        Assert.assertTrue(result.hasDefined(TEST_METRIC));
        Assert.assertEquals(expectedValue, result.get(TEST_METRIC).asString());
    }
}
 
Example 4
Source File: CapabilityRegistryTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void runtimeCircularCapabilities(ReloadRestartAction<PathAddress, OperationFailedException> action) throws OperationFailedException {
    add(CIRCULAR_CAP_ELEMENT);
    add(CIRCULAR_CAP_ELEMENT, INDEPENDENT_ELEMENT);

    ModelNode addOp1 = Util.createEmptyOperation("add", PathAddress.pathAddress(CIRCULAR_CAP_ELEMENT, CHILD_ELEMENT));
    ModelNode addOp2 = Util.createEmptyOperation("add", PathAddress.pathAddress(CIRCULAR_CAP_ELEMENT, CHILD_ELEMENT, GRANDCHILD_ELEMENT));

    ModelNode composite = createOperation(ModelDescriptionConstants.COMPOSITE);
    composite.get(STEPS).add(addOp1);
    composite.get(STEPS).add(addOp2);
    executeCheckNoFailure(composite);

    try {
        action.accept(PathAddress.pathAddress(CIRCULAR_CAP_ELEMENT, INDEPENDENT_ELEMENT));
        runtimeCheck(true, CIRCULAR_CAP_ELEMENT, CHILD_ELEMENT, GRANDCHILD_ELEMENT);
        runtimeOnlyCheck(true, CIRCULAR_CAP_ELEMENT, CHILD_ELEMENT, GRANDCHILD_ELEMENT);
    } finally {
        addOp1 = Util.createEmptyOperation("remove", PathAddress.pathAddress(CIRCULAR_CAP_ELEMENT, CHILD_ELEMENT, GRANDCHILD_ELEMENT));
        addOp2 = Util.createEmptyOperation("remove", PathAddress.pathAddress(CIRCULAR_CAP_ELEMENT, CHILD_ELEMENT));

        composite = createOperation(ModelDescriptionConstants.COMPOSITE);
        composite.get(STEPS).add(addOp1);
        composite.get(STEPS).add(addOp2);
        executeCheckNoFailure(composite);

        remove(CIRCULAR_CAP_ELEMENT, INDEPENDENT_ELEMENT);
        remove(CIRCULAR_CAP_ELEMENT);
    }
}
 
Example 5
Source File: SlaveRegistrationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testSlaveRegistrationWhenDcIsStarting() throws Exception {
    ModelNode op = Util.createEmptyOperation("reload", MASTER_ADDR);
    op.get(RESTART_SERVERS).set(true);
    DomainTestUtils.executeForResult(op, masterClient);

    masterLifecycleUtil.awaitHostController(System.currentTimeMillis(), ControlledProcessState.State.STARTING);

    // wait until main-one is starting, main-two is going to started but it will be blocked by the byteman rule.
    // This scenario will put the DC boot phase in the middle of server starting
    DomainTestUtils.waitUntilState(masterClient, MASTER_ADDR.append(SERVER_CONFIG_MAIN_ONE), "STARTED");

    op = Util.createEmptyOperation("reload", SLAVE_ADDR);
    op.get(RESTART_SERVERS).set(false);
    DomainTestUtils.executeForResult(op, slaveClient);

    slaveLifecycleUtil.awaitHostController(System.currentTimeMillis(), ControlledProcessState.State.RUNNING);

    op = Util.createEmptyOperation(READ_RESOURCE_OPERATION, SLAVE_ADDR);
    DomainTestUtils.executeForResult(op, masterClient);

    //assert the main-one server at this point reports STOPPED, which means it has not been registered yet in the domain
    Assert.assertTrue("main-two should be stopped at this point to validate this test conditions.",
            DomainTestUtils.executeForResult(Util.getReadAttributeOperation(MASTER_ADDR.append(SERVER_MAIN_TWO), "server-state"), masterClient).asString().equals("STOPPED")
    );

    // wait until DC full start
    masterLifecycleUtil.awaitHostController(System.currentTimeMillis(), ControlledProcessState.State.RUNNING);
}
 
Example 6
Source File: ServerAutoStartTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void executeFailingBatch(final ModelControllerClient client) throws IOException {
    ModelNode composite = Util.createEmptyOperation(COMPOSITE, PathAddress.EMPTY_ADDRESS);
    ModelNode steps = composite.get(STEPS).setEmptyList();

    ModelNode stopServerOne = Util.createOperation(STOP, PathAddress.pathAddress(mainOne));
    stopServerOne.get(BLOCKING).set(true);
    steps.add(stopServerOne);

    ModelNode removeServerOne = Util.createRemoveOperation(PathAddress.pathAddress(mainOne));
    steps.add(removeServerOne);
    validateResponse(client.execute(composite));
}
 
Example 7
Source File: OperationCancellationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String findActiveOperation(DomainClient client, PathAddress address, String opName) throws Exception {
    ModelNode op = Util.createEmptyOperation(READ_CHILDREN_RESOURCES_OPERATION, address);
    op.get(CHILD_TYPE).set(ACTIVE_OPERATION);
    ModelNode result = executeForResult(op, client);
    if (result.isDefined()) {
        assertEquals(result.asString(), ModelType.OBJECT, result.getType());
        for (Property prop : result.asPropertyList()) {
            if (prop.getValue().get(OP).asString().equals(opName)) {
                return prop.getName();
            }
        }
    }
    return null;
}
 
Example 8
Source File: IgnoredResourcesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@AfterClass
public static void tearDownDomain() throws Exception {
    // reset ignore-unused-configuration back to true, and reload
    final ModelNode slaveModel = DomainTestUtils.executeForResult(Util.getReadAttributeOperation(PathAddress.pathAddress(HOST, "slave"), DOMAIN_CONTROLLER),
            domainMasterLifecycleUtil.getDomainClient()).get(REMOTE);

    slaveModel.get(IGNORE_UNUSED_CONFIG).set(true);
    DomainTestUtils.executeForResult(Util.createEmptyOperation("remove-remote-domain-controller", PathAddress.pathAddress(HOST, "slave")), domainSlaveLifecycleUtil.getDomainClient());
    ModelNode writeRemoteDc = Util.createEmptyOperation("write-remote-domain-controller", PathAddress.pathAddress(HOST, "slave"));
    for (String key : slaveModel.keys()) {
        writeRemoteDc.get(key).set(slaveModel.get(key));
    }
    DomainTestUtils.executeForResult(writeRemoteDc, domainSlaveLifecycleUtil.getDomainClient());

    ModelNode restartSlave = Util.createEmptyOperation("reload", PathAddress.pathAddress(HOST, "slave"));
    restartSlave.get(RESTART_SERVERS).set(false);
    domainSlaveLifecycleUtil.executeAwaitConnectionClosed(restartSlave);
    domainSlaveLifecycleUtil.connect();
    domainSlaveLifecycleUtil.awaitHostController(System.currentTimeMillis());

    domainMasterLifecycleUtil = testSupport.getDomainMasterLifecycleUtil();
    domainSlaveLifecycleUtil = testSupport.getDomainSlaveLifecycleUtil();

    ModelNode slaveIgnore = Util.createEmptyOperation(READ_RESOURCE_OPERATION, PathAddress.pathAddress(HOST, "slave"));
    ModelNode result = DomainTestUtils.executeForResult(slaveIgnore, domainSlaveLifecycleUtil.getDomainClient());
    // make sure that ignore-unused-configuration is true
    Assert.assertTrue(result.get(DOMAIN_CONTROLLER).get(REMOTE).get(IGNORE_UNUSED_CONFIG).asBoolean());

    testSupport = null;
    domainMasterLifecycleUtil = null;
    domainSlaveLifecycleUtil = null;
    DomainTestSuite.stopSupport();
}
 
Example 9
Source File: RemotingTransformers.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) throws OperationFailedException {
    ModelNode transformed;
    ModelNode trimmedAdd = null;
    ModelNode endPointAdd = null;
    for (AttributeDefinition ad : RemotingEndpointResource.ATTRIBUTES.values()) {
        String adName = ad.getName();
        if (operation.hasDefined(adName)) {
            if (endPointAdd == null) {
                trimmedAdd = operation.clone();
                PathAddress endpointAddress = address.append(RemotingEndpointResource.ENDPOINT_PATH);
                endPointAdd = Util.createEmptyOperation(operation.get(OP).asString(), endpointAddress);
            }
            endPointAdd.get(adName).set(operation.get(adName));
            trimmedAdd.remove(adName);
        }
    }
    if (endPointAdd != null) {
        transformed = Util.createEmptyOperation(COMPOSITE, PathAddress.EMPTY_ADDRESS);
        ModelNode steps = transformed.get(STEPS);
        steps.add(trimmedAdd);
        steps.add(endPointAdd);
    } else {
        transformed = operation;
    }
    return new TransformedOperation(transformed, OperationResultTransformer.ORIGINAL_RESULT);
}
 
Example 10
Source File: AbstractCapabilityResolutionTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected static ModelNode getCapabilityOperation(PathAddress pathAddress, String capability, String requirement) {

        ModelNode op = Util.createEmptyOperation(CAPABILITY, pathAddress);
        if (capability != null) {
            op.get(CAPABILITY).set(capability);
        }
        if (requirement != null) {
            op.get(REQUIREMENT).set(requirement);
        }
        return op;
    }
 
Example 11
Source File: ExtensionManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void verifyOnSlave() throws IOException, MgmtOperationException {
    DomainClient client = domainSlaveLifecycleUtil.getDomainClient();
    ModelNode readExt = Util.createEmptyOperation(READ_RESOURCE_OPERATION, EXTENSION_ADDRESS);
    ModelNode result = executeForResult(readExt, client);
    assertEquals(result.toString(), TestExtension.MODULE_NAME, result.get(MODULE).asString());
    ModelNode read = Util.getReadAttributeOperation(PROFILE_SUBSYSTEM_ADDRESS, NAME);
    result = executeForResult(read, client);
    assertEquals(result.toString(), TestExtension.MODULE_NAME, result.asString());
}
 
Example 12
Source File: ExtensionManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void verifyNotOnSlave() throws IOException {
    ModelNode readExt = Util.createEmptyOperation(READ_RESOURCE_OPERATION, EXTENSION_ADDRESS);
    executeOp(readExt, FAILED);
    ModelNode read = Util.getReadAttributeOperation(PROFILE_SUBSYSTEM_ADDRESS, NAME);
    executeOp(read, FAILED);
}
 
Example 13
Source File: IgnoreUnusedConfigurationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static void startServer(DomainClient client, String name) throws Exception {
    ModelNode start = Util.createEmptyOperation(START, MASTER_ADDR.append(SERVER_CONFIG, name));
    start.get(BLOCKING).set(true);
    DomainTestUtils.executeForResult(start, client);
}
 
Example 14
Source File: AliasContextTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode getReadResourceDescriptionOperation(PathAddress addr, boolean recursive, boolean aliases) {
    ModelNode rr = Util.createEmptyOperation(READ_RESOURCE_DESCRIPTION_OPERATION, addr);
    rr.get(RECURSIVE).set(recursive);
    rr.get(INCLUDE_ALIASES).set(aliases);
    return rr;
}
 
Example 15
Source File: DeploymentScannerOperationTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void runScan(ModelControllerClient client) throws Exception {
    ModelNode runScanOp = Util.createEmptyOperation(FileSystemDeploymentScanHandler.OPERATION_NAME, getTestDeploymentScannerResourcePath());
    ModelNode result = client.execute(runScanOp);
    assertEquals("Unexpected outcome of running the scanner: " + runScanOp, SUCCESS, result.get(OUTCOME).asString());
}
 
Example 16
Source File: HostControllerBootOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testManagementOperationsWhenSlaveHCisBooting() throws Exception {
    ModelNode op = Util.createEmptyOperation("reload", SLAVE_ADDR);
    op.get(RESTART_SERVERS).set(true);
    DomainTestUtils.executeForResult(op, masterClient);

    slaveLifecycleUtil.awaitHostController(System.currentTimeMillis(), ControlledProcessState.State.STARTING);
    // At this point server-three should be waiting before being registered in the domain and HC is still booting up, this gives us a window
    // where we can tests the operations that were failing and reporting errors in HAL on WFCORE-4283
    // The slave write lock is acquired at this time because the servers are starting, although they have not been registered in the domain yet
    // Read operations should pass, even those that use proxies because at this point, the servers are not registered, proxies does not exists yet

    checkReadOperations(false);

    //assert the server at this point reports STOPPED, which means it has not been registered yet in the domain
    Assert.assertTrue("server-three should be stopped at this point to validate this test conditions. Check if a previous read operation acquired the write lock or if the \"Delay Server Registration Request\" byteman rule needs more time sleeping the server registration request",
            DomainTestUtils.executeForResult(Util.getReadAttributeOperation(SLAVE_ADDR.append(SERVER_MAIN_THREE), "server-state"), masterClient).asString().equals("STOPPED")
    );

    // Wait until the delayed server is registered in the domain
    DomainTestUtils.waitUntilState(masterClient, SLAVE_ADDR.append(SERVER_CONFIG_MAIN_THREE), ServerStatus.STARTING.toString());

    // At this point server-three should be waiting before transitioning to STARTED, this gives us a window to test operations that are
    // likely to fail since the server is still starting, write operations should fail, read operations should pass except those executed with proxies enabled

    op = Util.getWriteAttributeOperation(SERVER_GROUP_MAIN_SERVER_GROUP.append(JVM_DEFAULT), "heap-size", "64m");
    ModelNode failureDescription = DomainTestUtils.executeForFailure(op, masterClient);
    Assert.assertTrue("The slave host does not return the expected error. Failure Description was:"+failureDescription, failureDescription.get("host-failure-descriptions").get("slave").asString().startsWith("WFLYCTL0379"));

    checkReadOperations(true);

    // assert server is still starting at this moment
    Assert.assertTrue("server-three should be starting at this point to validate this test conditions. Check if the \"Delay Server Started Request\" byteman rule needs more time sleeping the server started request",
            DomainTestUtils.executeForResult(Util.getReadAttributeOperation(SLAVE_ADDR.append(SERVER_CONFIG_MAIN_THREE), "status"), masterClient).asString().equals(ServerStatus.STARTING.toString())
    );

    // Wait for all the servers until they are started and HC is running
    slaveLifecycleUtil.awaitHostController(System.currentTimeMillis(), ControlledProcessState.State.RUNNING);
    DomainTestUtils.waitUntilState(masterClient, SLAVE_ADDR.append(SERVER_CONFIG_MAIN_THREE), ServerStatus.STARTED.toString());

    // write operation should success at this moment
    op = Util.getWriteAttributeOperation(SERVER_GROUP_MAIN_SERVER_GROUP.append(JVM_DEFAULT), "heap-size", "64m");
    DomainTestUtils.executeForResult(op, masterClient);
}
 
Example 17
Source File: AliasContextTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode getReadResourceOperation(PathAddress addr, boolean recursive, boolean aliases) {
    ModelNode rr = Util.createEmptyOperation(READ_RESOURCE_OPERATION, addr);
    rr.get(RECURSIVE).set(recursive);
    rr.get(INCLUDE_ALIASES).set(aliases);
    return rr;
}
 
Example 18
Source File: ProcessStateListenerTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void restartMainServerGroup() throws TimeoutException, InterruptedException {
    ModelNode suspend = Util.createEmptyOperation("restart-servers", MAIN_SERVER_GROUP_ADDRESS);
    executeForResult(suspend);
    testSupport.getDomainMasterLifecycleUtil().awaitServers(System.currentTimeMillis());
}
 
Example 19
Source File: ApplicationTypeConstraintUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private Action getWriteConfigAction() {
    OperationEntry oe = rootTarget.getResourceRegistration().getOperationEntry(PathAddress.EMPTY_ADDRESS, "write-config");
    ModelNode op = Util.createEmptyOperation("write-config", null);
    return new Action(op, oe, EnumSet.of(Action.ActionEffect.WRITE_CONFIG));
}
 
Example 20
Source File: ScopedRoleRequiredHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
static void addOperation(OperationContext context, String roleName) {
    ModelNode operation = Util.createEmptyOperation("scoped-role-check", PathAddress.pathAddress(
            CoreManagementResourceDefinition.PATH_ELEMENT, AccessAuthorizationResourceDefinition.PATH_ELEMENT));

    context.addStep(operation, new ScopedRoleRequiredHandler(roleName), Stage.MODEL);
}