Java Code Examples for org.jboss.as.controller.client.helpers.Operations#createReadResourceOperation()
The following examples show how to use
org.jboss.as.controller.client.helpers.Operations#createReadResourceOperation() .
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: ExtensionSetup.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public static void addExtensionSubsystemAndResources(final ManagementClient client) throws IOException, MgmtOperationException { PathAddress extensionAddress = PathAddress.pathAddress(EXTENSION, TestExtension.MODULE_NAME); PathAddress subsystemAddress = PathAddress.pathAddress(SUBSYSTEM, "rbac"); ModelNode readResource = Operations.createReadResourceOperation(subsystemAddress.toModelNode()); readResource.get(RECURSIVE).set(true); readResource.get(INCLUDE_RUNTIME).set(true); ModelNode result = client.getControllerClient().execute(readResource); if (!SUCCESS.equals(result.get(OUTCOME).asString())) { ModelNode addExtension = Util.createAddOperation(extensionAddress); executeForResult(client.getControllerClient(), addExtension); ModelNode addSubsystem = Util.createAddOperation(subsystemAddress); addSubsystem.get("name").set("dummy name"); executeForResult(client.getControllerClient(), addSubsystem); } addResources(client); }
Example 2
Source File: LoggingDependenciesTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@After public void stopContainer() throws Exception { // No need to undeploy the deployment should be in error, but check the deployments and undeploy if necessary, // for example if the test failed final ModelNode op = Operations.createReadResourceOperation(PathAddress.pathAddress("deployment", "*").toModelNode()); final List<ModelNode> result = Operations.readResult(executeOperation(op)).asList(); if (!result.isEmpty()) { try { undeploy(); } catch (ServerDeploymentException e) { log.warn("Error undeploying", e); } } executeOperation(Operations.createWriteAttributeOperation(createAddress(), API_DEPENDENCIES, true)); container.stop(); }
Example 3
Source File: RemoveManagementRealmTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Before public void beforeTest() throws Exception { container.start(); String jbossDist = TestSuiteEnvironment.getSystemProperty("jboss.dist"); source = Paths.get(jbossDist, "standalone", "configuration", "standalone.xml"); target = Paths.get(temporaryUserHome.getRoot().getAbsolutePath(), "standalone.xml"); Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); // Determine the command to use final ModelControllerClient client = container.getClient().getControllerClient(); ModelNode op = Operations.createReadResourceOperation(Operations.createAddress("core-service", "management", "management-interface", "http-interface")); ModelNode result = client.execute(op); if (Operations.isSuccessfulOutcome(result)) { result = Operations.readResult(result); if (result.hasDefined("http-upgrade")) { final ModelNode httpUpgrade = result.get("http-upgrade"); if (httpUpgrade.hasDefined("sasl-authentication-factory")) { // We could query this further to get the actual name of the configurable-sasl-server-factory. Since this // is a test we're making some assumptions to limit the number of query calls made to the server. removeLocalAuthCommand = "/subsystem=elytron/configurable-sasl-server-factory=configured:map-remove(name=properties, key=wildfly.sasl.local-user.default-user)"; } } } else { fail(Operations.getFailureDescription(result).asString()); } }
Example 4
Source File: DisableLocalAuthServerSetupTask.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void tearDown(final ManagementClient managementClient) throws Exception { try (final ModelControllerClient client = createNativeClient()) { final Operations.CompositeOperationBuilder compositeOp = Operations.CompositeOperationBuilder.create(); // Remove the native interface compositeOp.addStep(Operations.createRemoveOperation(nativeInterfaceAddress)); // Remove the native-interface compositeOp.addStep(Operations.createRemoveOperation(nativeSecurityRealmAddress)); // Remove the socket binding for the native-interface compositeOp.addStep(Operations.createRemoveOperation(nativeSocketBindingAddress)); // Re-enable Elytron local-auth ModelNode op = Operations.createReadResourceOperation(saslFactoryAddress); ModelNode result = client.execute(op); if (Operations.isSuccessfulOutcome(result)) { op = Operations.createOperation("map-put", saslFactoryAddress); op.get("name").set("properties"); op.get("key").set(defaultUserKey); op.get("value").set("$local"); compositeOp.addStep(op.clone()); } // Re-enable the legacy local-auth op = Operations.createReadResourceOperation(managementRealmAddress); result = client.execute(op); if (Operations.isSuccessfulOutcome(result)) { ///core-service=management/security-realm=ManagementRealm/authentication=local:undefine-attribute(name=default-user) compositeOp.addStep(Operations.createWriteAttributeOperation(managementRealmAddress, "default-user", "$local")); } executeForSuccess(client, compositeOp.build()); // Use the native client to execute the reload, completion waiting should create a new http+remote client ServerReload.executeReloadAndWaitForCompletion(client); } }
Example 5
Source File: AbstractLoggingTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Reads the deployment resource. * * @param deploymentName the name of the deployment * * @return the model for the deployment * * @throws IOException if an error occurs connecting to the server */ public static ModelNode readDeploymentResource(final String deploymentName) throws IOException { // Don't guess on the address, just parse it as it comes back final ModelNode address = Operations.createAddress("deployment", deploymentName, "subsystem", "logging", "configuration", "*"); final ModelNode op = Operations.createReadResourceOperation(address); op.get("include-runtime").set(true); final ModelNode result = executeOperation(op); // Get the resulting model final List<ModelNode> loggingConfigurations = Operations.readResult(result).asList(); Assert.assertEquals("There should only be one logging configuration defined", 1, loggingConfigurations.size()); final LinkedList<Property> resultAddress = new LinkedList<>(Operations.getOperationAddress(loggingConfigurations.get(0)).asPropertyList()); return readDeploymentResource(deploymentName, resultAddress.getLast().getValue().asString()); }
Example 6
Source File: RemoveManagementInterfaceTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void serverSetup(ModelControllerClient client) throws Exception { // add native socket binding ModelNode operation = createOpNode("socket-binding-group=standard-sockets/socket-binding=management-native", ModelDescriptionConstants.ADD); operation.get("port").set(MANAGEMENT_NATIVE_PORT); operation.get("interface").set("management"); CoreUtils.applyUpdate(operation, client); // Determine the we should be using a security-realm or SASL ModelNode op = Operations.createReadResourceOperation(Operations.createAddress("core-service", "management", "management-interface", "http-interface")); ModelNode result = ManagementOperations.executeOperation(client, op); if (result.hasDefined("security-realm")) { securityRealm = result.get("security-realm").asString(); } else if (result.hasDefined("http-upgrade")) { final ModelNode httpUpgrade = result.get("http-upgrade"); if (httpUpgrade.hasDefined("sasl-authentication-factory")) { saslAuthFactory = httpUpgrade.get("sasl-authentication-factory").asString(); } } // create native interface to control server while http interface will be removed operation = createOpNode("core-service=management/management-interface=native-interface", ModelDescriptionConstants.ADD); if (saslAuthFactory != null) { operation.get("sasl-authentication-factory").set(saslAuthFactory); } else { operation.get("security-realm").set(securityRealm); } operation.get("socket-binding").set("management-native"); CoreUtils.applyUpdate(operation, client); }
Example 7
Source File: AbstractLogFieldsOfLogTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
void configureUser(final ModelControllerClient client, final CompositeOperationBuilder compositeOp) throws IOException { // Determine the we should be using a security-realm or SASL (we assume SASL means Elytron is enabled) String securityRealm = "ManagementRealm"; ModelNode op = Operations.createReadResourceOperation(Operations.createAddress("core-service", "management", "management-interface", "http-interface")); ModelNode result = executeForSuccess(client, OperationBuilder.create(op).build()); if (result.hasDefined("security-realm")) { securityRealm = result.get("security-realm").asString(); } else if (result.hasDefined("http-upgrade")) { final ModelNode httpUpgrade = result.get("http-upgrade"); // We could query this further to get the actual name of the configurable-sasl-server-factory. Since this // is a test we're making some assumptions to limit the number of query calls made to the server. if (httpUpgrade.hasDefined("sasl-authentication-factory")) { elytronEnabled = true; } } if (elytronEnabled) { userAuthAddress = Operations.createAddress("subsystem", "elytron", "configurable-sasl-server-factory", "configured"); op = Operations.createOperation("map-remove", userAuthAddress); op.get("name").set("properties"); op.get("key").set(DEFAULT_USER_KEY); compositeOp.addStep(op.clone()); op = Operations.createOperation("map-put", userAuthAddress); op.get("name").set("properties"); op.get("key").set(DEFAULT_USER_KEY); op.get("value").set("IAmAdmin"); compositeOp.addStep(op.clone()); userIdentRealmAddress = Operations.createAddress("subsystem", "elytron", "identity-realm", "local"); compositeOp.addStep(Operations.createWriteAttributeOperation(userIdentRealmAddress, "identity", "IAmAdmin")); } else { userAuthAddress = Operations.createAddress(CORE_SERVICE, MANAGEMENT, SECURITY_REALM, securityRealm, AUTHENTICATION, LOCAL); compositeOp.addStep(Operations.createWriteAttributeOperation(userAuthAddress, "default-user", "IAmAdmin")); } }
Example 8
Source File: DeploymentOverlayTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private ModelNode readDeploymentResource(PathAddress address) { ModelNode operation = Operations.createReadResourceOperation(address.toModelNode()); operation.get(INCLUDE_RUNTIME).set(true); operation.get(INCLUDE_DEFAULTS).set(true); AsyncFuture<ModelNode> future = masterClient.executeAsync(operation, null); ModelNode result = awaitSimpleOperationExecution(future); assertTrue(Operations.isSuccessfulOutcome(result)); return Operations.readResult(result); }
Example 9
Source File: ExplodedDeploymentTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private ModelNode readDeploymentResource(PathAddress address) { ModelNode operation = Operations.createReadResourceOperation(address.toModelNode()); operation.get(INCLUDE_RUNTIME).set(true); operation.get(INCLUDE_DEFAULTS).set(true); AsyncFuture<ModelNode> future = masterClient.executeAsync(operation, null); ModelNode result = awaitSimpleOperationExecution(future); assertTrue(Operations.isSuccessfulOutcome(result)); return Operations.readResult(result); }
Example 10
Source File: CachedDcDomainTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private ModelNode readResourceTestLoggerFromSlaveHost(DomainClient client) throws IOException { final ModelNode hostLoggerAddress = new ModelNode() .add(HOST, "slave") .add(SERVER, "other-two") .add(SUBSYSTEM, "logging") .add(LOGGER, TEST_LOGGER_NAME); final ModelNode readResourceOp = Operations.createReadResourceOperation(hostLoggerAddress); final ModelNode result = client.execute(readResourceOp); assertEquals(SUCCESS, result.get(OUTCOME).asString()); return result; }
Example 11
Source File: DefaultInterfaceOveridingDomainTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private String getServerDefaultInterface(DomainLifecycleUtil hostUtil, String serverName) throws IOException { ModelNode opAdress = PathAddress.pathAddress(PathElement.pathElement(HOST, "slave"), PathElement.pathElement(SERVER, serverName)).toModelNode(); ModelNode readOp = Operations.createReadResourceOperation(opAdress, true); ModelNode domain = hostUtil.executeForResult(readOp); Assert.assertThat(domain.get(SOCKET_BINDING_GROUP).isDefined(), is(true)); Property socketBindingGroup = domain.get(SOCKET_BINDING_GROUP).asProperty(); Assert.assertThat(socketBindingGroup.getName(), is("standard-sockets")); Assert.assertThat(socketBindingGroup.getValue().hasDefined(DEFAULT_INTERFACE), is(true)); return socketBindingGroup.getValue().get(DEFAULT_INTERFACE).asString(); }
Example 12
Source File: LogFilterTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void addLoggingFilter() { ModelNode consoleAddress = createAddress("console-handler", "CONSOLE").toModelNode(); ModelNode replaceValue = new ModelNode(); replaceValue.get("pattern").set("JBAS"); replaceValue.get("replacement").set("DUMMY"); replaceValue.get("replace-all").set(true); ModelNode filterAttributeValue = new ModelNode(); filterAttributeValue.get("replace").set(replaceValue); final ModelNode writeOp = Operations.createWriteAttributeOperation(consoleAddress, "filter", filterAttributeValue); executeOperation(kernelServices, writeOp); // Create the read operation final ModelNode readAttributeOp = Operations.createReadAttributeOperation(consoleAddress, "filter"); ModelNode result = executeOperation(kernelServices, readAttributeOp); assertThat(result, is(notNullValue())); assertThat(result.get(OUTCOME).asString(), is("success")); assertEquals("{\"replace\" => {\"replace-all\" => true,\"pattern\" => \"JBAS\",\"replacement\" => \"DUMMY\"}}", Operations.readResult(result).asString()); ModelNode readResourceOp = Operations.createReadResourceOperation(consoleAddress); result = executeOperation(kernelServices, readResourceOp); assertThat(result, is(notNullValue())); assertThat(result.get(OUTCOME).asString(), is("success")); assertThat(result.get(RESULT).hasDefined("filter-spec"), is(true)); ModelNode filterSpec = result.get(RESULT).get("filter-spec"); assertThat(filterSpec.asString(), is("substituteAll(\"JBAS\",\"DUMMY\")")); assertThat(result.get(RESULT).hasDefined("filter"), is(true)); assertThat(result.get(RESULT).get("filter").hasDefined("replace"), is(true)); ModelNode replaceResult = result.get(RESULT).get("filter").get("replace"); assertThat(replaceResult.hasDefined("pattern"), is(true)); assertThat(replaceResult.get("pattern").asString(), is("JBAS")); assertThat(replaceResult.hasDefined("replacement"), is(true)); assertThat(replaceResult.get("replacement").asString(), is("DUMMY")); assertThat(replaceResult.hasDefined("pattern"), is(true)); assertThat(replaceResult.get("pattern").asString(), is("JBAS")); }
Example 13
Source File: DefaultContainerDescription.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 5 votes |
/** * Queries the running container and attempts to lookup the information from the running container. * * @param client the client used to execute the management operation * * @return the container description * * @throws IOException if an error occurs while executing the management operation * @throws OperationExecutionException if the operation used to query the container fails */ static DefaultContainerDescription lookup(final ModelControllerClient client) throws IOException, OperationExecutionException { final ModelNode op = Operations.createReadResourceOperation(new ModelNode().setEmptyList()); op.get(ClientConstants.INCLUDE_RUNTIME).set(true); final ModelNode result = client.execute(op); if (Operations.isSuccessfulOutcome(result)) { final ModelNode model = Operations.readResult(result); final String productName = getValue(model, "product-name", "WildFly"); final String productVersion = getValue(model, "product-version"); final String releaseVersion = getValue(model, "release-version"); final String launchType = getValue(model, "launch-type"); return new DefaultContainerDescription(productName, productVersion, releaseVersion, launchType, "DOMAIN".equalsIgnoreCase(launchType)); } throw new OperationExecutionException(op, result); }
Example 14
Source File: DisableLocalAuthServerSetupTask.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void setup(final ManagementClient managementClient) throws Exception { final ModelControllerClient client = managementClient.getControllerClient(); final Operations.CompositeOperationBuilder compositeOp = Operations.CompositeOperationBuilder.create(); // Add the socket binding for the native-interface ModelNode op = Operations.createAddOperation(nativeSocketBindingAddress); op.get("port").set(9999); op.get("interface").set("management"); compositeOp.addStep(op.clone()); // Add the native-interface compositeOp.addStep(Operations.createAddOperation(nativeSecurityRealmAddress)); // Add the native-interface local authentication final ModelNode nativeRealmLocalAuthAddress = nativeSecurityRealmAddress.clone().add("authentication", "local"); op = Operations.createAddOperation(nativeRealmLocalAuthAddress); op.get("default-user").set("$local"); compositeOp.addStep(op.clone()); // Add the native interface op = Operations.createAddOperation(nativeInterfaceAddress); op.get("security-realm").set("native-realm"); op.get("socket-binding").set("management-native"); compositeOp.addStep(op.clone()); // Undefine Elytron local-auth op = Operations.createReadResourceOperation(saslFactoryAddress); ModelNode result = client.execute(op); if (Operations.isSuccessfulOutcome(result)) { op = Operations.createOperation("map-remove", saslFactoryAddress); op.get("name").set("properties"); op.get("key").set(defaultUserKey); compositeOp.addStep(op.clone()); } // Undefine the legacy local-auth op = Operations.createReadResourceOperation(managementRealmAddress); result = client.execute(op); if (Operations.isSuccessfulOutcome(result)) { compositeOp.addStep(Operations.createUndefineAttributeOperation(managementRealmAddress, "default-user")); } executeForSuccess(client, compositeOp.build()); // Use the current client to execute the reload, but the native client to ensure the reload is complete ServerReload.executeReloadAndWaitForCompletion(client, ServerReload.TIMEOUT, false, protocol, host, port); }
Example 15
Source File: AbstractLoggingOperationsTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
protected void verifyRemoved(final ModelNode address) throws IOException { final ModelNode op = Operations.createReadResourceOperation(address); final ModelNode result = client.getControllerClient().execute(op); assertFalse("Resource not removed: " + address, Operations.isSuccessfulOutcome(result)); }
Example 16
Source File: AbstractLoggingTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 3 votes |
/** * Reads the deployment resource. * * @param deploymentName the name of the deployment * @param configurationName the name of the configuration for the address * * @return the model for the deployment * * @throws IOException if an error occurs connecting to the server */ public static ModelNode readDeploymentResource(final String deploymentName, final String configurationName) throws IOException { ModelNode address = Operations.createAddress("deployment", deploymentName, "subsystem", "logging", "configuration", configurationName); ModelNode op = Operations.createReadResourceOperation(address, true); op.get("include-runtime").set(true); final ModelNode result = Operations.readResult(executeOperation(op)); // Add the address on the result as the tests might need it result.get(ModelDescriptionConstants.OP_ADDR).set(address); return result; }