Java Code Examples for org.jboss.as.controller.client.helpers.Operations#CompositeOperationBuilder
The following examples show how to use
org.jboss.as.controller.client.helpers.Operations#CompositeOperationBuilder .
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: DeploymentResourceTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void setup(ManagementClient managementClient) throws Exception { final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create(); // create dummy-profile1 builder.addStep(Operations.createAddOperation(createAddress("logging-profile", PROFILE_NAME))); // add file handler ModelNode op = Operations.createAddOperation(createAddress("logging-profile", PROFILE_NAME, "periodic-rotating-file-handler", "FILE")); op.get("level").set("FATAL"); op.get("append").set("true"); op.get("suffix").set(".yyyy-MM-dd"); final ModelNode file = op.get("file").setEmptyObject(); file.get("relative-to").set("jboss.server.log.dir"); file.get("path").set(PROFILE_LOG_NAME); op.get("file").set(file); op.get("formatter").set("%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"); builder.addStep(op); executeOperation(builder.build()); }
Example 2
Source File: AuditLogBootingSyslogTest.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Before public void beforeTest() throws Exception { container.startInAdminMode(); final ModelControllerClient client = container.getClient().getControllerClient(); Operations.CompositeOperationBuilder compositeOp = Operations.CompositeOperationBuilder.create(); configureServerName(compositeOp); configureElytron(compositeOp); executeForSuccess(client, compositeOp.build()); SYSLOG_SETUP.setup(container.getClient()); compositeOp = Operations.CompositeOperationBuilder.create(); configureAliases(compositeOp); compositeOp.addStep(Util.getWriteAttributeOperation(auditLogConfigAddress, AuditLogLoggerResourceDefinition.LOG_BOOT.getName(), ModelNode.TRUE)); compositeOp.addStep(Util.getWriteAttributeOperation(auditLogConfigAddress, AuditLogLoggerResourceDefinition.ENABLED.getName(), ModelNode.TRUE)); executeForSuccess(client, compositeOp.build()); final BlockingQueue<SyslogServerEventIF> queue = BlockedSyslogServerEventHandler.getQueue(); queue.clear(); container.stop(); }
Example 3
Source File: AuditLogBootingSyslogTest.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@After public void afterTest() throws Exception { final ModelControllerClient client = container.getClient().getControllerClient(); SYSLOG_SETUP.tearDown(container.getClient()); final Operations.CompositeOperationBuilder compositeOp = Operations.CompositeOperationBuilder.create(); compositeOp.addStep(Util.getWriteAttributeOperation(auditLogConfigAddress, AuditLogLoggerResourceDefinition.ENABLED.getName(), ModelNode.FALSE)); resetElytron(compositeOp); resetServerName(compositeOp); try { executeForSuccess(client, compositeOp.build()); } finally { try { // Stop the container container.stop(); } finally { IoUtils.safeClose(client); } } }
Example 4
Source File: FullReplaceUndeployTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private static Operation createDeployAddOperation(final InputStream content, final String name, final String runtimeName) { final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create(true); final ModelNode address = createAddress(DEPLOYMENT, name); final ModelNode addOperation = createAddOperation(address); if (runtimeName != null) { addOperation.get(RUNTIME_NAME).set(runtimeName); } addContent(builder, addOperation, content); builder.addStep(addOperation); final ModelNode sgAddress = Operations.createAddress(SERVER_GROUP, "main-server-group", DEPLOYMENT, name); final ModelNode op = Operations.createAddOperation(sgAddress); op.get("enabled").set(true); if (runtimeName != null) { op.get(RUNTIME_NAME).set(runtimeName); } builder.addStep(op); return builder.build(); }
Example 5
Source File: AffectedDeploymentOverlay.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * It will look for all the deployments under the deploymentsRootAddress with a runtimeName in the specified list of * runtime names and then transform the operation so that every server having those deployments will redeploy the * affected deployments. * * @see #transformOperation * @param removeOperation * @param context * @param deploymentsRootAddress * @param runtimeNames * @throws OperationFailedException */ public static void redeployLinksAndTransformOperation(OperationContext context, ModelNode removeOperation, PathAddress deploymentsRootAddress, Set<String> runtimeNames) throws OperationFailedException { Set<String> deploymentNames = listDeployments(context.readResourceFromRoot(deploymentsRootAddress), runtimeNames); Operations.CompositeOperationBuilder opBuilder = Operations.CompositeOperationBuilder.create(); if (deploymentNames.isEmpty()) { for (String s : runtimeNames) { ServerLogger.ROOT_LOGGER.debugf("We haven't found any deployment for %s in server-group %s", s, deploymentsRootAddress.getLastElement().getValue()); } } if(removeOperation != null) { opBuilder.addStep(removeOperation); } for (String deploymentName : deploymentNames) { opBuilder.addStep(addRedeployStep(deploymentsRootAddress.append(DEPLOYMENT, deploymentName))); } List<DomainOperationTransmuter> transformers = context.getAttachment(OperationAttachments.SLAVE_SERVER_OPERATION_TRANSMUTERS); if (transformers == null) { context.attach(OperationAttachments.SLAVE_SERVER_OPERATION_TRANSMUTERS, transformers = new ArrayList<>()); } final ModelNode slave = opBuilder.build().getOperation(); transformers.add(new OverlayOperationTransmuter(slave, context.getCurrentAddress())); }
Example 6
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 7
Source File: RotatingFileHandlerTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void setup(final ManagementClient managementClient) throws Exception { final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create(); final ModelNode formatterAddress = createAddress("json-formatter", FORMATTER_NAME); builder.addStep(Operations.createAddOperation(formatterAddress)); removeOps.addLast(Operations.createRemoveOperation(formatterAddress)); ModelNode address = createAddress("size-rotating-file-handler", SIZE_FILE_NAME); ModelNode op = Operations.createAddOperation(address); ModelNode file = op.get("file").setEmptyObject(); file.get("relative-to").set("jboss.server.log.dir"); file.get("path").set(SIZE_FILE_NAME); op.get("max-backup-index").set(1); op.get("rotate-size").set("5k"); op.get("named-formatter").set(FORMATTER_NAME); builder.addStep(op); removeOps.addFirst(Operations.createRemoveOperation(address)); address = createAddress("size-rotating-file-handler", SIZE_COMPRESSED_FILE_NAME); op = Operations.createAddOperation(address); file = op.get("file").setEmptyObject(); file.get("relative-to").set("jboss.server.log.dir"); file.get("path").set(SIZE_COMPRESSED_FILE_NAME); op.get("max-backup-index").set(1); op.get("rotate-size").set("5k"); op.get("named-formatter").set(FORMATTER_NAME); op.get("suffix").set(".zip"); builder.addStep(op); removeOps.addFirst(Operations.createRemoveOperation(address)); address = createAddress("periodic-size-rotating-file-handler", PERIODIC_SIZE_FILE_NAME); op = Operations.createAddOperation(address); file = op.get("file").setEmptyObject(); file.get("relative-to").set("jboss.server.log.dir"); file.get("path").set(PERIODIC_SIZE_FILE_NAME); op.get("max-backup-index").set(1); op.get("rotate-size").set("5k"); op.get("named-formatter").set(FORMATTER_NAME); op.get("suffix").set("mm"); builder.addStep(op); removeOps.addFirst(Operations.createRemoveOperation(address)); address = createAddress("periodic-size-rotating-file-handler", PERIODIC_SIZE_COMPRESSED_FILE_NAME); op = Operations.createAddOperation(address); file = op.get("file").setEmptyObject(); file.get("relative-to").set("jboss.server.log.dir"); file.get("path").set(PERIODIC_SIZE_COMPRESSED_FILE_NAME); op.get("max-backup-index").set(1); op.get("rotate-size").set("5k"); op.get("named-formatter").set(FORMATTER_NAME); op.get("suffix").set("mm.zip"); builder.addStep(op); removeOps.addFirst(Operations.createRemoveOperation(address)); address = createAddress("logger", SIZE_LOGGER_NAME); op = Operations.createAddOperation(address); op.get("handlers").setEmptyList().add(SIZE_FILE_NAME); op.get("use-parent-handlers").set(false); builder.addStep(op); removeOps.addFirst(Operations.createRemoveOperation(address)); address = createAddress("logger", SIZE_COMPRESSED_LOGGER_NAME); op = Operations.createAddOperation(address); op.get("handlers").setEmptyList().add(SIZE_COMPRESSED_FILE_NAME); op.get("use-parent-handlers").set(false); builder.addStep(op); removeOps.addFirst(Operations.createRemoveOperation(address)); address = createAddress("logger", PERIODIC_SIZE_LOGGER_NAME); op = Operations.createAddOperation(address); op.get("handlers").setEmptyList().add(PERIODIC_SIZE_FILE_NAME); op.get("use-parent-handlers").set(false); builder.addStep(op); removeOps.addFirst(Operations.createRemoveOperation(address)); address = createAddress("logger", PERIODIC_SIZE_COMPRESSED_LOGGER_NAME); op = Operations.createAddOperation(address); op.get("handlers").setEmptyList().add(PERIODIC_SIZE_COMPRESSED_FILE_NAME); op.get("use-parent-handlers").set(false); builder.addStep(op); removeOps.addFirst(Operations.createRemoveOperation(address)); executeOperation(managementClient, builder.build()); }
Example 8
Source File: RotatingFileHandlerTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void tearDown(final ManagementClient managementClient) throws Exception { final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create(); ModelNode op; while ((op = removeOps.pollFirst()) != null) { builder.addStep(op); } executeOperation(managementClient, builder.build()); }
Example 9
Source File: DeploymentScannerOperationRollbackTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void prepareRollback(ModelControllerClient client) throws Exception { final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create(); ModelNode addParentPath = Operations.createAddOperation(PathAddress.pathAddress(PATH, "parent.path").toModelNode()); addParentPath.get(PATH).set("parent"); addParentPath.get(RELATIVE_TO).set("jboss.home.dir"); builder.addStep(addParentPath); ModelNode addChildPath = Operations.createAddOperation(PathAddress.pathAddress(PATH, "child.path").toModelNode()); addChildPath.get(PATH).set("child"); addChildPath.get(RELATIVE_TO).set("parent.path"); builder.addStep(addChildPath); DomainTestSupport.validateResponse(client.execute(builder.build()), false); }
Example 10
Source File: DeploymentScannerOperationRollbackTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private void runFailingScan(ModelControllerClient client) throws Exception { final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create(); builder.addStep(Operations.createAddOperation(PathAddress.pathAddress(SYSTEM_PROPERTY, "my.property").toModelNode())); builder.addStep(Operations.createWriteAttributeOperation(PathAddress.pathAddress(SYSTEM_PROPERTY, "my.property").toModelNode(), "value", "test")); builder.addStep(Util.createEmptyOperation(FileSystemDeploymentScanHandler.OPERATION_NAME, getTestDeploymentScannerResourcePath())); builder.addStep(Operations.createRemoveOperation(PathAddress.pathAddress(PATH, "parent.path").toModelNode())); final ModelNode result = client.execute(builder.build().getOperation()); assertThat(result.get(OUTCOME).asString(), is(FAILED)); }
Example 11
Source File: FullReplaceUndeployTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static Operation createReplaceAndDisableOperation(final InputStream content, final String name, final String runtimeName) throws IOException { final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create(true); final ModelNode op = createOperation(DEPLOYMENT_FULL_REPLACE_OPERATION); op.get(NAME).set(name); if (runtimeName != null) { op.get(RUNTIME_NAME).set(runtimeName); } addContent(builder, op, content); op.get("enabled").set(false); builder.addStep(op); return builder.build(); }
Example 12
Source File: ServerOperationResolver.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Convert an operation for deployment overlays to be executed on local servers. * Since this might be called in the case of redeployment of affected deployments, we need to take into account * the composite op resulting from such a transformation * @see AffectedDeploymentOverlay#redeployLinksAndTransformOperationForDomain * @param operation * @param host * @return */ private Map<Set<ServerIdentity>, ModelNode> getDeploymentOverlayOperations(ModelNode operation, ModelNode host) { final PathAddress realAddress = PathAddress.pathAddress(operation.get(OP_ADDR)); if (realAddress.size() == 0 && COMPOSITE.equals(operation.get(OP).asString())) { //We have a composite operation resulting from a transformation to redeploy affected deployments //See redeploying deployments affected by an overlay. ModelNode serverOp = operation.clone(); Map<ServerIdentity, Operations.CompositeOperationBuilder> composite = new HashMap<>(); for (ModelNode step : serverOp.get(STEPS).asList()) { ModelNode newStep = step.clone(); String groupName = PathAddress.pathAddress(step.get(OP_ADDR)).getElement(0).getValue(); newStep.get(OP_ADDR).set(PathAddress.pathAddress(step.get(OP_ADDR)).subAddress(1).toModelNode()); Set<ServerIdentity> servers = getServersForGroup(groupName, host, localHostName, serverProxies); for(ServerIdentity server : servers) { if(!composite.containsKey(server)) { composite.put(server, Operations.CompositeOperationBuilder.create()); } composite.get(server).addStep(newStep); } if(!servers.isEmpty()) { newStep.get(OP_ADDR).set(PathAddress.pathAddress(step.get(OP_ADDR)).subAddress(1).toModelNode()); } } if(!composite.isEmpty()) { Map<Set<ServerIdentity>, ModelNode> result = new HashMap<>(); for(Entry<ServerIdentity, Operations.CompositeOperationBuilder> entry : composite.entrySet()) { result.put(Collections.singleton(entry.getKey()), entry.getValue().build().getOperation()); } return result; } return Collections.emptyMap(); } final Set<ServerIdentity> allServers = getAllRunningServers(host, localHostName, serverProxies); return Collections.singletonMap(allServers, operation.clone()); }
Example 13
Source File: AffectedDeploymentOverlay.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * It will look for all the deployments (in every server-group) with a runtimeName in the specified list of runtime * names and then transform the operation so that every server in those server groups will redeploy the affected * deployments. * * @param removeOperation * @see #transformOperation * @param context * @param runtimeNames * @throws OperationFailedException */ public static void redeployLinksAndTransformOperationForDomain(OperationContext context, Set<String> runtimeNames, ModelNode removeOperation) throws OperationFailedException { Set<String> serverGroupNames = listServerGroupsReferencingOverlay(context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS), context.getCurrentAddressValue()); Map<String, Set<String>> deploymentPerServerGroup = new HashMap<>(); for (String serverGoupName : serverGroupNames) { deploymentPerServerGroup.put(serverGoupName, listDeployments(context.readResourceFromRoot(PathAddress.pathAddress(PathElement.pathElement(SERVER_GROUP, serverGoupName))),runtimeNames)); } if (deploymentPerServerGroup.isEmpty()) { for (String s : runtimeNames) { ServerLogger.ROOT_LOGGER.debugf("We haven't found any server-group for %s", s); } } Operations.CompositeOperationBuilder opBuilder = Operations.CompositeOperationBuilder.create(); if(removeOperation != null) { opBuilder.addStep(removeOperation); } //Add a deploy step for each affected deployment in its server-group. for (Map.Entry<String, Set<String>> entry : deploymentPerServerGroup.entrySet()) { if ((! entry.getValue().isEmpty())) { for (String deploymentName : entry.getValue()) { opBuilder.addStep(addRedeployStep(context.getCurrentAddress().getParent().append(SERVER_GROUP, entry.getKey()).append(DEPLOYMENT, deploymentName))); } } } // Add the domain op transformer List<DomainOperationTransmuter> transformers = context.getAttachment(OperationAttachments.SLAVE_SERVER_OPERATION_TRANSMUTERS); if (transformers == null) { context.attach(OperationAttachments.SLAVE_SERVER_OPERATION_TRANSMUTERS, transformers = new ArrayList<>()); } final ModelNode slave = opBuilder.build().getOperation(); transformers.add(new OverlayOperationTransmuter(slave, context.getCurrentAddress())); }
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: ServerHelper.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Checks to see if a domain server is running. * * @param client the client used to communicate with the server * @param forShutdown if this is checking for a shutdown * * @return {@code true} if the server, and it's auto-start servers, are running, otherwise {@code false} */ public static boolean isDomainRunning(final ModelControllerClient client, final boolean forShutdown) { final DomainClient domainClient = (client instanceof DomainClient ? (DomainClient) client : DomainClient.Factory.create(client)); try { // Check for admin-only final ModelNode hostAddress = determineHostAddress(domainClient); final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create() .addStep(Operations.createReadAttributeOperation(hostAddress, "running-mode")) .addStep(Operations.createReadAttributeOperation(hostAddress, "host-state")); ModelNode response = domainClient.execute(builder.build()); if (Operations.isSuccessfulOutcome(response)) { response = Operations.readResult(response); if ("ADMIN_ONLY".equals(Operations.readResult(response.get("step-1")).asString())) { if (Operations.isSuccessfulOutcome(response.get("step-2"))) { final String state = Operations.readResult(response).asString(); return !CONTROLLER_PROCESS_STATE_STARTING.equals(state) && !CONTROLLER_PROCESS_STATE_STOPPING.equals(state); } } } final Map<ServerIdentity, ServerStatus> servers = new HashMap<>(); final Map<ServerIdentity, ServerStatus> statuses = domainClient.getServerStatuses(); for (ServerIdentity id : statuses.keySet()) { final ServerStatus status = statuses.get(id); switch (status) { case DISABLED: case STARTED: { servers.put(id, status); break; } } } if (forShutdown) { return statuses.isEmpty(); } return statuses.size() == servers.size(); } catch (IllegalStateException | IOException ignore) { } return false; }