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

The following examples show how to use org.jboss.as.controller.operations.common.Util#getReadAttributeOperation() . 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: XCorrelationIdTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testPost() throws Exception {
    ModelNode op = Util.getReadAttributeOperation(PathAddress.EMPTY_ADDRESS, "server-state");
    HttpPost post = new HttpPost(url.toURI());

    String cmdStr = op.toJSONString(true);
    StringEntity entity = new StringEntity(cmdStr);
    entity.setContentType(APPLICATION_JSON);
    post.setEntity(entity);

    assertNull(getCorrelationHeader(post));

    post.addHeader(HEADER, VALUE1);
    assertEquals(VALUE1, getCorrelationHeader(post));

    post.setHeader(HEADER, VALUE2);
    assertEquals(VALUE2, getCorrelationHeader(post));

    post.setHeader(HEADER, VALUE1);
    assertEquals(VALUE1, getCorrelationHeader(post));

    post.removeHeaders(HEADER);
    assertNull(getCorrelationHeader(post));
}
 
Example 2
Source File: ReadResourceHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void addReadAttributeStep(OperationContext context, PathAddress address, boolean defaults, boolean resolve, boolean includeUndefinedMetricValues, FilteredData localFilteredData,
                                  ImmutableManagementResourceRegistration registry,
                                  AttributeDefinition.NameAndGroup attributeKey, Map<AttributeDefinition.NameAndGroup, GlobalOperationHandlers.AvailableResponse> responseMap) {
    // See if there was an override registered for the standard :read-attribute handling (unlikely!!!)
    OperationStepHandler overrideHandler = registry.getOperationHandler(PathAddress.EMPTY_ADDRESS, READ_ATTRIBUTE_OPERATION);
    if (overrideHandler != null &&
            (overrideHandler == ReadAttributeHandler.INSTANCE || overrideHandler == ReadAttributeHandler.RESOLVE_INSTANCE)) {
        // not an override
        overrideHandler = null;
    }

    OperationStepHandler readAttributeHandler = new ReadAttributeHandler(localFilteredData, overrideHandler, (resolve && resolvable));

    final ModelNode attributeOperation = Util.getReadAttributeOperation(address, attributeKey.getName());
    attributeOperation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).set(defaults);
    attributeOperation.get(ModelDescriptionConstants.RESOLVE_EXPRESSIONS).set(resolve);
    attributeOperation.get(ModelDescriptionConstants.INCLUDE_UNDEFINED_METRIC_VALUES).set(includeUndefinedMetricValues);

    final ModelNode attrResponse = new ModelNode();
    GlobalOperationHandlers.AvailableResponse availableResponse = new GlobalOperationHandlers.AvailableResponse(attrResponse);
    responseMap.put(attributeKey, availableResponse);

    GlobalOperationHandlers.AvailableResponseWrapper wrapper = new GlobalOperationHandlers.AvailableResponseWrapper(readAttributeHandler, availableResponse);

    context.addStep(attrResponse, attributeOperation, wrapper, OperationContext.Stage.MODEL, true);
}
 
Example 3
Source File: RuntimeOnlyOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void attributeTest(String attribute, String accessType) throws IOException {
    ModelNode op = Util.getReadResourceDescriptionOperation(PROFILE.append(SUBSYSTEM));
    ModelNode resp = executeOp(op, SUCCESS);
    assertTrue(resp.toString(), resp.hasDefined(RESULT, ATTRIBUTES));
    // non storage=configuration attributes should not get registered even though the ResourceDefinition tries
    assertFalse(resp.toString(), resp.has(RESULT, ATTRIBUTES, attribute));

    op = Util.getReadAttributeOperation(PROFILE.append(SUBSYSTEM), attribute);
    executeOp(op, FAILED);

    op = Util.getReadResourceDescriptionOperation(SLAVE.append(MAIN_THREE).append(SUBSYSTEM));
    resp = executeOp(op, SUCCESS);
    assertEquals(resp.toString(), accessType, resp.get(RESULT, ATTRIBUTES, attribute, ACCESS_TYPE).asString());

    op = Util.getReadAttributeOperation(SLAVE.append(MAIN_THREE).append(SUBSYSTEM), attribute);
    resp = executeOp(op, SUCCESS);
    assertTrue(resp.toString(), resp.get(RESULT).asBoolean());
}
 
Example 4
Source File: OperationTimeoutTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void validateTimeoutProperties(String host, String server, String baseTimeout, String domainAdder) throws IOException, MgmtOperationException {
    PathAddress pa = PathAddress.pathAddress(HOST, host);
    if (server != null) {
        pa = pa.append(RUNNING_SERVER, server);
    }
    ModelNode op = Util.getReadAttributeOperation(pa.append(RUNTIME_MXBEAN), "system-properties");
    ModelNode props = executeForResult(op, masterClient);
    if (baseTimeout == null) {
        assertFalse(props.toString(), props.hasDefined("jboss.as.management.blocking.timeout"));
    } else {
        assertEquals(props.toString(), baseTimeout, props.get("jboss.as.management.blocking.timeout").asString());
    }
    if (domainAdder == null) {
        assertFalse(props.toString(), props.hasDefined("org.wildfly.unsupported.test.domain-timeout-adder"));
    } else {
        assertEquals(props.toString(), domainAdder, props.get("org.wildfly.unsupported.test.domain-timeout-adder").asString());
    }
}
 
Example 5
Source File: ExtensionManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void verifyOnServers() throws IOException, MgmtOperationException {
    DomainClient client = domainMasterLifecycleUtil.getDomainClient();

    ModelNode readExtOne = Util.getReadAttributeOperation(SERVER_ONE_EXT_ADDRESS, MODULE);
    ModelNode result = executeForResult(readExtOne, client);
    assertEquals(result.toString(), TestExtension.MODULE_NAME, result.asString());

    ModelNode readSubOne = Util.getReadAttributeOperation(SERVER_ONE_SUBSYSTEM_ADDRESS, NAME);
    result = executeForResult(readSubOne, client);
    assertEquals(result.toString(), TestExtension.MODULE_NAME, result.asString());

    ModelNode readExtThree = Util.getReadAttributeOperation(SERVER_THREE_EXT_ADDRESS, MODULE);
    result = executeForResult(readExtThree, client);
    assertEquals(result.toString(), TestExtension.MODULE_NAME, result.asString());

    ModelNode readSubThree = Util.getReadAttributeOperation(SERVER_THREE_SUBSYSTEM_ADDRESS, NAME);
    result = executeForResult(readSubThree, client);
    assertEquals(result.toString(), TestExtension.MODULE_NAME, result.asString());
}
 
Example 6
Source File: SyncModelServerStateTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode readRolloutPlan(String planName, byte[] expectedRootHash) throws OperationFailedException {
    PathAddress plansAddr = PathAddress.pathAddress(MANAGEMENT_CLIENT_CONTENT, ROLLOUT_PLANS);
    ModelNode hashRead = Util.getReadAttributeOperation(plansAddr, HASH);
    ModelNode result = executeForResult(hashRead);
    Assert.assertArrayEquals(expectedRootHash, result.asBytes());

    ModelNode readPlanOp = Util.createOperation(READ_RESOURCE_OPERATION, plansAddr.append(ROLLOUT_PLAN, planName));
    readPlanOp.get(INCLUDE_RUNTIME).set(true);
    return executeForResult(readPlanOp);
}
 
Example 7
Source File: ResponseAttachmentTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testNativeInterface() throws Exception {
    ModelNode opNode = Util.getReadAttributeOperation(PathAddress.pathAddress(SUBSYSTEM, LogStreamExtension.SUBSYSTEM_NAME), "log-file");
    readLogFile(opNode);

    opNode = Util.createEmptyOperation(LogStreamExtension.STREAM_LOG_FILE, PathAddress.pathAddress(SUBSYSTEM, LogStreamExtension.SUBSYSTEM_NAME));
    readLogFile(opNode);
}
 
Example 8
Source File: DeploymentOverlayScenario.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String getServerProperty(DomainClient slaveClient, String propName) throws Exception {
    PathAddress addr = SLAVE_ADDR.append(SERVER, "server-affected")
            .append(CORE_SERVICE, PLATFORM_MBEAN).append(TYPE, "runtime");
    ModelNode op = Util.getReadAttributeOperation(addr, SYSTEM_PROPERTIES);
    ModelNode props = DomainTestUtils.executeForResult(op, slaveClient);
    for (ModelNode prop : props.asList()) {
        Property property = prop.asProperty();
        if (property.getName().equals(propName)) {
            return property.getValue().asString();
        }
    }
    return null;

}
 
Example 9
Source File: ExtensionManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void verifyNotOnServers() throws IOException {
    ModelNode readExtOne = Util.getReadAttributeOperation(SERVER_ONE_EXT_ADDRESS, MODULE);
    executeOp(readExtOne, FAILED);

    ModelNode readSubOne = Util.getReadAttributeOperation(SERVER_ONE_SUBSYSTEM_ADDRESS, NAME);
    executeOp(readSubOne, FAILED);

    ModelNode readExtThree = Util.getReadAttributeOperation(SERVER_THREE_EXT_ADDRESS, MODULE);
    executeOp(readExtThree, FAILED);

    ModelNode readSubThree = Util.getReadAttributeOperation(SERVER_THREE_SUBSYSTEM_ADDRESS, NAME);
    executeOp(readSubThree, FAILED);

}
 
Example 10
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 11
Source File: ServerManagementTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ModelNode readSystemProperties(DomainClient client, PathAddress parent) throws IOException {
    PathAddress addr = parent.append("core-service", "platform-mbean").append("type", "runtime");
    ModelNode op = Util.getReadAttributeOperation(addr, "system-properties");
    ModelNode response = client.execute(op);
    ModelNode result = DomainTestSupport.validateResponse(response, true);
    Assert.assertNotNull(result);
    Assert.assertEquals(response.toString(), ModelType.OBJECT, result.getType());
    return result;
}
 
Example 12
Source File: DiscoveryOptionTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testDiscoveryOptionsOrdering() throws Exception {
    DomainClient slaveClient = domainSlaveLifecycleUtil.getDomainClient();
    ModelNode discoveryOptionsAddress = new ModelNode();
    discoveryOptionsAddress.add("host", "slave");
    discoveryOptionsAddress.add("core-service", "discovery-options");
    ModelNode readDiscoveryOptionsOrdering = Util.getReadAttributeOperation(PathAddress.pathAddress(discoveryOptionsAddress), DISCOVERY_OPTIONS);
    ModelNode expectedDiscoveryOptionsOrdering = new ModelNode();
    expectedDiscoveryOptionsOrdering.add("static-discovery", "start-option");
    ModelNode originalOptionsOrdering = new ModelNode();
    originalOptionsOrdering.add("static-discovery", "start-option");

    ModelNode discoveryOptionProperties = new ModelNode();
    discoveryOptionProperties.get(ACCESS_KEY).set("access_key");
    discoveryOptionProperties.get(SECRET_ACCESS_KEY).set("secret_access_key");
    discoveryOptionProperties.get(LOCATION).set("location");
    ModelNode addS3DiscoveryOption = getS3DiscoveryOptionAddOperation(discoveryOptionProperties);

    ModelNode addStaticDiscoveryOption = new ModelNode();
    addStaticDiscoveryOption.get(OP).set(ADD);
    addStaticDiscoveryOption.get(HOST).set("127.0.0.2");
    addStaticDiscoveryOption.get(PORT).set("9999");

    ModelNode result = slaveClient.execute(readDiscoveryOptionsOrdering);
    ModelNode returnVal = validateResponse(result);
    Assert.assertEquals(originalOptionsOrdering, returnVal);

    // (host=slave),(core-service=discovery-options),(discovery-option=option-one)
    ModelNode discoveryOptionAddressOne = discoveryOptionsAddress.clone().add("discovery-option", "option-one");
    addDiscoveryOptionTest(slaveClient, discoveryOptionAddressOne, addS3DiscoveryOption);
    expectedDiscoveryOptionsOrdering.add("discovery-option", "option-one");

    // (host=slave),(core-service=discovery-options),(static-discovery=option-two)
    ModelNode discoveryOptionAddressTwo = discoveryOptionsAddress.clone().add("static-discovery", "option-two");
    addDiscoveryOptionTest(slaveClient, discoveryOptionAddressTwo, addStaticDiscoveryOption);
    expectedDiscoveryOptionsOrdering.add("static-discovery", "option-two");

    // (host=slave),(core-service=discovery-options),(discovery-option=option-three)
    ModelNode discoveryOptionAddressThree = discoveryOptionsAddress.clone().add("discovery-option", "option-three");
    addDiscoveryOptionTest(slaveClient, discoveryOptionAddressThree, addS3DiscoveryOption);
    expectedDiscoveryOptionsOrdering.add("discovery-option", "option-three");

    result = slaveClient.execute(readDiscoveryOptionsOrdering);
    returnVal = validateResponse(result);
    Assert.assertEquals(expectedDiscoveryOptionsOrdering, returnVal);

    removeDiscoveryOptionTest(slaveClient, discoveryOptionAddressOne);
    removeDiscoveryOptionTest(slaveClient, discoveryOptionAddressTwo);
    removeDiscoveryOptionTest(slaveClient, discoveryOptionAddressThree);

    result = slaveClient.execute(readDiscoveryOptionsOrdering);
    returnVal = validateResponse(result);
    Assert.assertEquals(originalOptionsOrdering, returnVal);
}
 
Example 13
Source File: ExtensionManagementTestCase.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 masterClient = domainMasterLifecycleUtil.getDomainClient();
    Exception err = null;
    try {
        // 1) Sanity check -- subsystem not there
        ModelNode read = Util.getReadAttributeOperation(PROFILE_SUBSYSTEM_ADDRESS, NAME);
        testBadOp(read);

        // 2) Sanity check -- Confirm slave has resources
        verifyNotOnSlave();

        // 3) Sanity check -- Confirm servers no longer have resource
        verifyNotOnServers();

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

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

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

        // 7) Confirm slave has resources
        verifyOnSlave();

        // 8) Confirm servers have the resources
        verifyOnServers();

        // 9) sub remove + ext remove + sub add in composite -- fail
        ModelNode subRemove = Util.createRemoveOperation(PROFILE_SUBSYSTEM_ADDRESS);
        ModelNode extRemove = Util.createRemoveOperation(EXTENSION_ADDRESS);
        ModelNode badRemove = buildComposite(read, subRemove, extRemove, subAdd);
        testBadOp(badRemove);

        // 10) Confirm servers still have resources
        verifyOnServers();

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

        // 12) Confirm slave no longer has resources
        verifyNotOnSlave();

        // 13) Confirm servers no longer have resource
        verifyNotOnServers();

        // 14) confirm ext add + sub add + sub read still works
        testGoodComposite(goodAdd);

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

        // 16) Confirm slave again has resources
        verifyOnSlave();

        // 17) Confirm servers again have resources
        verifyOnServers();

    } catch (Exception e) {
        err = e;
    } finally {
        //Cleanup
        removeIgnoreFailure(masterClient, PROFILE_SUBSYSTEM_ADDRESS);
        removeIgnoreFailure(masterClient, EXTENSION_ADDRESS);
    }

    if (err != null) {
        throw err;
    }
}
 
Example 14
Source File: ResponseStreamTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode createReadAttributeOp(PathAddress base) {
    PathAddress pa = base.append(SUBSYSTEM, LogStreamExtension.SUBSYSTEM_NAME);
    return Util.getReadAttributeOperation(pa, LogStreamExtension.LOG_FILE.getName());
}
 
Example 15
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 16
Source File: AutoIgnoredResourcesDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private String getSlaveHostStatus() throws Exception {
    ModelNode op = Util.getReadAttributeOperation(PathAddress.pathAddress(SLAVE_ROOT_ADDRESS), HOST_STATE);
    ModelNode result = slaveClient.execute(op);
    return validateResponse(result).asString();
}
 
Example 17
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 18
Source File: AutoIgnoredResourcesDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private String getSlaveServerStatus(String serverName) throws Exception {
    ModelNode op = Util.getReadAttributeOperation(PathAddress.pathAddress(getSlaveRunningServerAddress(serverName)), "server-state");
    ModelNode result = slaveClient.execute(op);
    return validateResponse(result).asString();
}
 
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 checkMaxHistorySize(DomainClient client,  int expectedSize, PathElement ... prefix) throws UnsuccessfulOperationException {
    PathAddress address = PathAddress.pathAddress().append(prefix).append(getAddress());
    ModelNode readMaxHistorySize = Util.getReadAttributeOperation(address, MAX_HISTORY);
    ModelNode result = executeForResult(client, readMaxHistorySize);
    assertThat(result.asInt(), is(expectedSize));
}
 
Example 20
Source File: CliBootOperationsTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
String getRunningMode() throws Exception {
    ModelNode op = Util.getReadAttributeOperation(PathAddress.EMPTY_ADDRESS, RUNNING_MODE);
    ModelNode result = container.getClient().executeForResult(op);
    return result.asString();
}