Java Code Examples for org.jboss.as.controller.operations.common.Util#createOperation()
The following examples show how to use
org.jboss.as.controller.operations.common.Util#createOperation() .
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: ServerGroupDeploymentTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testRedeploy() throws Exception { KernelServices kernelServices = createKernelServices(); ModelNode op = createAddOperation(kernelServices, "Test1"); op.get(ENABLED).set(true); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op, new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5}))); checkSingleDeployment(kernelServices, "Test1", true); op = Util.createOperation(DeploymentRedeployHandler.OPERATION_NAME, getPathAddress("Test1")); kernelServices.validateOperation(op); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); checkSingleDeployment(kernelServices, "Test1", true); op = Util.createOperation(DeploymentRemoveHandler.OPERATION_NAME, getPathAddress("Test1")); kernelServices.validateOperation(op); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); checkNoDeployments(kernelServices); }
Example 2
Source File: BasicRbacTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Before public void setup() { ModelNode operation = Util.createOperation(ADD, pathAddress(UNCONSTRAINED_RESOURCE, FOO)); executeWithRole(operation, StandardRole.SUPERUSER); operation = Util.createOperation(ADD, pathAddress(APPLICATION_CONSTRAINED_RESOURCE, FOO)); executeWithRole(operation, StandardRole.SUPERUSER); operation = Util.createOperation(ADD, pathAddress(SENSITIVE_NON_ADDRESSABLE_RESOURCE, FOO)); executeWithRole(operation, StandardRole.SUPERUSER); operation = Util.createOperation(ADD, pathAddress(SENSITIVE_ADDRESSABLE_RESOURCE, FOO)); executeWithRole(operation, StandardRole.SUPERUSER); operation = Util.createOperation(ADD, pathAddress(SENSITIVE_READ_ONLY_RESOURCE, FOO)); executeWithRole(operation, StandardRole.SUPERUSER); operation = Util.createOperation(ADD, PathAddress.pathAddress(CORE_MANAGEMENT)); executeWithRole(operation, StandardRole.SUPERUSER); operation = Util.createOperation(ADD, PathAddress.pathAddress(ACCESS_AUDIT_ADDR)); executeWithRole(operation, StandardRole.SUPERUSER); }
Example 3
Source File: DisappearingResourceTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void testReadChildrenResourcesRecursive() throws Exception { attributeOutLatch.countDown(); ModelNode op = Util.createOperation(READ_CHILDREN_RESOURCES_OPERATION, SUBSYSTEM_ADDRESS); op.get(CHILD_TYPE).set(PARENT); op.get(INCLUDE_RUNTIME).set(true); op.get(RECURSIVE).set(true); ModelNode result = executeForResult(op); assertEquals(result.toString(), ModelType.OBJECT, result.getType()); assertEquals(result.toString(), 1, result.asInt()); ModelNode parentResult = result.get(PARENT_ELEMENT.getValue()); assertTrue(result.toString(), parentResult.hasDefined(CHILD, "C", ATTR)); assertTrue(result.toString(), parentResult.get(CHILD, "C", ATTR).asInt() == 1); assertFalse(result.toString(), parentResult.get(CHILD).has("B")); }
Example 4
Source File: AbstractConfigurationChangesTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public List<ModelNode> readConfigurationChanges(DomainClient client, PathElement prefix) throws IOException { PathAddress address = getAddress(); if (prefix != null) { address = PathAddress.pathAddress().append(prefix).append(getAddress()); } ModelNode readConfigChanges = Util.createOperation(LegacyConfigurationChangeResourceDefinition.OPERATION_NAME, address); ModelNode response = client.execute(readConfigChanges); assertThat(response.asString(), response.get(ClientConstants.OUTCOME).asString(), is(ClientConstants.SUCCESS)); logger.info("For " + prefix + " we have " + response.get(ClientConstants.RESULT)); return response.get(ClientConstants.RESULT).asList(); }
Example 5
Source File: DisappearingResourceTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testReadChildrenResourcesDisappearingInAssembly() throws Exception { ModelNode op = Util.createOperation(READ_CHILDREN_RESOURCES_OPERATION, SUBSYSTEM_ADDRESS); op.get(CHILD_TYPE).set(PARENT); op.get(RECURSIVE).set(true); op.get(INCLUDE_RUNTIME).set(true); Runnable r = new Runnable() { @Override public void run() { try { attributeInLatch.await(300, TimeUnit.SECONDS); discardParent = true; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } finally { attributeOutLatch.countDown(); } } }; Thread t = new Thread(r); t.start(); ModelNode result = executeForResult(op); assertEquals(result.toString(), ModelType.OBJECT, result.getType()); assertEquals(result.toString(), 0, result.asInt()); }
Example 6
Source File: ServerGroupScopedRolesTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void testModifyServerGroupsOfServerGroupScopedRole() { testAddServerGroupScopedRole(); ModelNode operation = Util.createOperation(WRITE_ATTRIBUTE_OPERATION, pathAddress( pathElement(CORE_SERVICE, MANAGEMENT), pathElement(ACCESS, AUTHORIZATION), pathElement(SERVER_GROUP_SCOPED_ROLE, FOO) )); operation.get(NAME).set(SERVER_GROUPS); operation.get(VALUE).add(SOME_SERVER_GROUP); ModelNode result = execute(operation); checkOutcome(result); operation = Util.createOperation(READ_RESOURCE_OPERATION, pathAddress( pathElement(CORE_SERVICE, MANAGEMENT), pathElement(ACCESS, AUTHORIZATION), pathElement(SERVER_GROUP_SCOPED_ROLE, FOO) )); operation.get(RECURSIVE).set(true); result = execute(operation); checkOutcome(result); result = result.get(RESULT); assertEquals(MONITOR, result.get(BASE_ROLE).asString()); assertEquals(1, result.get(SERVER_GROUPS).asList().size()); assertEquals(SOME_SERVER_GROUP, result.get(SERVER_GROUPS).get(0).asString()); }
Example 7
Source File: ValidateAddressOrOperationTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static void validateAddress(ModelControllerClient client, ModelNode address, boolean expectedOutcome) throws IOException { ModelNode operation = Util.createOperation(ValidateAddressOperationHandler.OPERATION_NAME, PathAddress.EMPTY_ADDRESS); operation.get(VALUE).set(address); ModelNode result = client.execute(operation); assertModelNodeOnlyContainsKeys(result, LEGAL_ADDRESS_RESP_FIELDS); assertModelNodeOnlyContainsKeys(result.get(RESULT), VALID, PROBLEM); assertEquals(result.toString(), expectedOutcome, result.get(RESULT, VALID).asBoolean()); assertEquals(result.toString(), !expectedOutcome, result.get(RESULT).hasDefined(PROBLEM)); if (!expectedOutcome) { assertTrue(result.get(RESULT, PROBLEM).asString().contains("WFLYCTL0335")); } }
Example 8
Source File: AbstractMgmtTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
protected ModelNode executeAndRollbackOperation(final ModelNode op) throws IOException { ModelNode broken = Util.createOperation("read-attribute", PathAddress.EMPTY_ADDRESS); broken.get("no-such-attribute").set("fail"); /*ModelNode addDeploymentOp = createOpNode("deployment=malformedDeployment.war", "add"); addDeploymentOp.get("content").get(0).get("input-stream-index").set(0); DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(); builder.setOperationName("deploy"); builder.addNode("deployment", "malformedDeployment.war"); ModelNode[] steps = new ModelNode[3]; steps[0] = op; steps[1] = addDeploymentOp; steps[2] = builder.buildRequest(); ModelNode compositeOp = ModelUtil.createCompositeNode(steps); OperationBuilder ob = new OperationBuilder(compositeOp, true); ob.addInputStream(new FileInputStream(getBrokenWar()));*/ ModelNode[] steps = new ModelNode[2]; steps[0] = op; steps[1] = broken; ModelNode compositeOp = ModelUtil.createCompositeNode(steps); OperationBuilder ob = new OperationBuilder(compositeOp, true); return getModelControllerClient().execute(ob.build()); }
Example 9
Source File: ConfigurationChangesHistoryTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void readConfigurationChanges(ManagementInterface client, boolean authorized, boolean auditAuthorized) { ModelNode readConfigChanges = Util.createOperation("list-changes", ADDRESS); ModelNode response = client.execute(readConfigChanges); assertThat(response.asString(), response.get(OUTCOME).asString(), is(SUCCESS)); List<ModelNode> changes = response.get(RESULT).asList(); assertThat(changes.size(), is(MAX_HISTORY_SIZE)); for (ModelNode change : changes) { assertThat(change.hasDefined(OPERATION_DATE), is(true)); assertThat(change.hasDefined(USER_ID), is(false)); assertThat(change.hasDefined(DOMAIN_UUID), is(false)); assertThat(change.hasDefined(ACCESS_MECHANISM), is(true)); assertThat(change.get(ACCESS_MECHANISM).asString(), is("NATIVE")); assertThat(change.hasDefined(REMOTE_ADDRESS), is(true)); assertThat(change.get(OPERATIONS).asList().size(), is(1)); } ModelNode currentChange = changes.get(0); assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS)); ModelNode currentChangeOp = currentChange.get(OPERATIONS).asList().get(0); assertThat(currentChangeOp.get(OP).asString(), is(REMOVE)); if (auditAuthorized) { assertThat(PathAddress.pathAddress(currentChangeOp.get(OP_ADDR)).toString(), is(IN_MEMORY_HANDLER_ADDRESS.toString())); } else { assertThat(currentChangeOp.get(OP_ADDR).asString(), containsString("WFLYCTL0332")); } currentChange = changes.get(1); assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS)); currentChangeOp = currentChange.get(OPERATIONS).asList().get(0); assertThat(currentChangeOp.get(OP).asString(), is(WRITE_ATTRIBUTE_OPERATION)); if (auditAuthorized) { assertThat(PathAddress.pathAddress(currentChangeOp.get(OP_ADDR)).toString(), is(IN_MEMORY_HANDLER_ADDRESS.toString())); assertThat(currentChangeOp.get(VALUE).asInt(), is(50)); } else { assertThat(currentChangeOp.get(OP_ADDR).asString(), containsString("WFLYCTL0332")); } currentChange = changes.get(2); assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS)); currentChangeOp = currentChange.get(OPERATIONS).asList().get(0); assertThat(currentChangeOp.get(OP).asString(), is(ADD)); if (auditAuthorized) { assertThat(PathAddress.pathAddress(currentChangeOp.get(OP_ADDR)).toString(), is(IN_MEMORY_HANDLER_ADDRESS.toString())); } else { assertThat(currentChangeOp.get(OP_ADDR).asString(), containsString("WFLYCTL0332")); } currentChange = changes.get(3); assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS)); currentChangeOp = currentChange.get(OPERATIONS).asList().get(0); assertThat(currentChangeOp.get(OP).asString(), is(REMOVE)); if (authorized || auditAuthorized) { assertThat(currentChangeOp.get(OP_ADDR).asString(), is(SYSTEM_PROPERTY_ADDRESS.toString())); } else { assertThat(currentChangeOp.get(OP_ADDR).asString(), containsString("WFLYCTL0332")); } currentChange = changes.get(4); assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS)); currentChangeOp = currentChange.get(OPERATIONS).asList().get(0); assertThat(currentChangeOp.get(OP).asString(), is(WRITE_ATTRIBUTE_OPERATION)); if (auditAuthorized) { assertThat(currentChangeOp.get(OP_ADDR).asString(), is(AUDIT_LOG_ADDRESS.toModelNode().asString())); assertThat(currentChangeOp.get(VALUE).asBoolean(), is(true)); } else { assertThat(currentChangeOp.get(OP_ADDR).asString(), containsString("WFLYCTL0332")); } currentChange = changes.get(5); assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS)); currentChangeOp = currentChange.get(OPERATIONS).asList().get(0); assertThat(currentChangeOp.get(OP).asString(), is(UNDEFINE_ATTRIBUTE_OPERATION)); assertThat(currentChangeOp.get(OP_ADDR).asString(), is(ALLOWED_ORIGINS_ADDRESS.toModelNode().asString())); if (authorized) { assertThat(currentChangeOp.get(NAME).asString(), is(ALLOWED_ORIGINS)); } else { assertThat(currentChangeOp.get(NAME).isDefined(), is(false)); } currentChange = changes.get(6); assertThat(currentChange.get(OUTCOME).asString(), is(SUCCESS)); currentChangeOp = currentChange.get(OPERATIONS).asList().get(0); assertThat(currentChangeOp.get(OP).asString(), is(ADD)); if (authorized || auditAuthorized) { assertThat(currentChangeOp.get(OP_ADDR).asString(), is(SYSTEM_PROPERTY_ADDRESS.toModelNode().asString())); if (authorized) { assertThat(currentChangeOp.get(VALUE).asString(), is("changeConfig")); } else { assertThat(currentChangeOp.hasDefined(NAME), is(false)); assertThat(currentChangeOp.hasDefined(VALUE), is(false)); } } else { assertThat(currentChangeOp.get(OP_ADDR).asString(), containsString("WFLYCTL0332")); assertThat(currentChangeOp.asString(), currentChangeOp.hasDefined(NAME), is(false)); } currentChange = changes.get(7); assertThat(currentChange.get(OUTCOME).asString(), is(FAILED)); currentChangeOp = currentChange.get(OPERATIONS).asList().get(0); if (authorized) { assertThat(currentChangeOp.get(NAME).asString(), is(ALLOWED_ORIGINS)); } else { assertThat(currentChangeOp.get(NAME).isDefined(), is(false)); } }
Example 10
Source File: AuditLogHandlerBootEnabledTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void runSyslogTest(SimpleSyslogServer server, int port, ModelNode handlerAddOperation) throws Exception { try { File file = new File(logDir, "test-file.log"); executeForResult(handlerAddOperation); List<ModelNode> records1 = readFile(file, 2); List<ModelNode> ops = checkBootRecordHeader(records1.get(1), 1, "core", false, false, true); checkOpsEqual(handlerAddOperation, ops.get(0)); ModelNode op = createAddHandlerReferenceOperation("syslog-test"); executeForResult(op); records1 = readFile(file, 3); ops = checkBootRecordHeader(records1.get(2), 1, "core", false, false, true); checkOpsEqual(op, ops.get(0)); byte[] receivedBytes = server.receiveData(); List<ModelNode> syslogOps = checkBootRecordHeader(getSyslogRecord(receivedBytes), 1, "core", false, false, true); Assert.assertEquals(ops, syslogOps); //TODO check syslog format and contents op = Util.createOperation(READ_RESOURCE_DESCRIPTION_OPERATION, PathAddress.EMPTY_ADDRESS); executeForResult(op); records1 = readFile(file, 4); ops = checkBootRecordHeader(records1.get(3), 1, "core", true, false, true); checkOpsEqual(op, ops.get(0)); receivedBytes = server.receiveData(); syslogOps = checkBootRecordHeader(getSyslogRecord(receivedBytes), 1, "core", true, false, true); Assert.assertEquals(ops, syslogOps); //Make sure that removing the syslog handler it still gets logged op = createRemoveHandlerReferenceOperation("syslog-test"); executeForResult(op); records1 = readFile(file, 5); ops = checkBootRecordHeader(records1.get(4), 1, "core", false, false, true); checkOpsEqual(op, ops.get(0)); receivedBytes = server.receiveData(); syslogOps = checkBootRecordHeader(getSyslogRecord(receivedBytes), 1, "core", false, false, true); Assert.assertEquals(ops, syslogOps); op = Util.createOperation(READ_RESOURCE_DESCRIPTION_OPERATION, PathAddress.EMPTY_ADDRESS); executeForResult(op); records1 = readFile(file, 6); ops = checkBootRecordHeader(records1.get(5), 1, "core", true, false, true); checkOpsEqual(op, ops.get(0)); //Should be nothing in syslog Assert.assertNull(server.pollData()); //TODO remove handler and check nothing in syslog and expected in file } finally { server.close(); } }
Example 11
Source File: RuntimeSensitivityReconfigurationTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private ModelNode addInterface(StandardRole role) { ModelNode operation = Util.createOperation(ADD, pathAddress(INTERFACE, "test" + (counter++))); operation.get(ANY_ADDRESS).set(true); return executeWithRoles(operation, role); }
Example 12
Source File: JmxAuditLogHandlerTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testSeparateFileCoreAndJmxAuditLog() throws Exception { File fileJmx = new File(logDir, "test-file.log"); File fileCore = new File(logDir, "test-file2.log"); readFile(fileJmx, 1); ModelNode op = createAddFileHandlerOperation("test-file2", "test-formatter", "test-file2.log"); executeForResult(op); readFile(fileJmx, 1); Assert.assertFalse(fileCore.exists()); op = createAddCoreHandlerReferenceOperation("test-file2"); executeForResult(op); readFile(fileJmx, 1); List<ModelNode> records = readFile(fileCore, 1); List<ModelNode> ops = checkCoreBootRecordHeader(records.get(0), 1, false, false, true); checkOpsEqual(op, ops.get(0)); //Remove and add the jmx handler reference, making sure that core logging still gets logged op = Util.createOperation(ModelDescriptionConstants.READ_RESOURCE_DESCRIPTION_OPERATION, PathAddress.EMPTY_ADDRESS); executeForResult(op); readFile(fileJmx, 1); records = readFile(fileCore, 2); ops = checkCoreBootRecordHeader(records.get(1), 1, true, false, true); checkOpsEqual(op, ops.get(0)); Assert.assertTrue(server.queryNames(OBJECT_NAME, null).contains(OBJECT_NAME)); readFile(fileCore, 2); records = readFile(fileJmx, 2); checkJmxBootRecordHeader(records.get(1), true, new String[] {ObjectName.class.getName(), QueryExp.class.getName()}, new String[] {OBJECT_NAME.toString(), null}); op = createRemoveJmxHandlerReferenceOperation("test-file"); executeForResult(op); readFile(fileJmx, 2); records = readFile(fileCore, 3); ops = checkCoreBootRecordHeader(records.get(2), 1, false, false, true); checkOpsEqual(op, ops.get(0)); Assert.assertTrue(server.queryNames(OBJECT_NAME, null).contains(OBJECT_NAME)); readFile(fileJmx, 2); op = createAddJmxHandlerReferenceOperation("test-file"); executeForResult(op); readFile(fileJmx, 2); records = readFile(fileCore, 4); ops = checkCoreBootRecordHeader(records.get(3), 1, false, false, true); checkOpsEqual(op, ops.get(0)); Assert.assertTrue(server.queryNames(OBJECT_NAME, null).contains(OBJECT_NAME)); readFile(fileCore, 4); records = readFile(fileJmx, 1); //File has been recycled checkJmxBootRecordHeader(records.get(0), true, new String[] {ObjectName.class.getName(), QueryExp.class.getName()}, new String[] {OBJECT_NAME.toString(), null}); //Remove and add the core handler reference, making sure that jmx logging still gets logged op = createRemoveCoreHandlerReferenceOperation("test-file2"); executeForResult(op); readFile(fileJmx, 1); records = readFile(fileCore, 5); ops = checkCoreBootRecordHeader(records.get(4), 1, false, false, true); checkOpsEqual(op, ops.get(0)); Assert.assertTrue(server.queryNames(OBJECT_NAME, null).contains(OBJECT_NAME)); readFile(fileCore, 5); records = readFile(fileJmx, 2); //File has been recycled checkJmxBootRecordHeader(records.get(1), true, new String[] {ObjectName.class.getName(), QueryExp.class.getName()}, new String[] {OBJECT_NAME.toString(), null}); op = Util.createOperation(ModelDescriptionConstants.READ_RESOURCE_DESCRIPTION_OPERATION, PathAddress.EMPTY_ADDRESS); executeForResult(op); readFile(fileJmx, 2); records = readFile(fileCore, 5); op = createAddCoreHandlerReferenceOperation("test-file2"); executeForResult(op); readFile(fileJmx, 2); records = readFile(fileCore, 1); //File has been recycled ops = checkCoreBootRecordHeader(records.get(0), 1, false, false, true); checkOpsEqual(op, ops.get(0)); }
Example 13
Source File: StandaloneRootResourceTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testSchemaLocations() throws Exception { KernelServices kernelServices = createEmptyRoot(); ModelNode read = Util.createOperation(READ_ATTRIBUTE_OPERATION, PathAddress.EMPTY_ADDRESS); read.get(NAME).set(ModelDescriptionConstants.SCHEMA_LOCATIONS); Assert.assertEquals(new ModelNode().setEmptyList(), kernelServices.executeForResult(read)); ModelNode add = Util.createOperation(SchemaLocationAddHandler.DEFINITION, PathAddress.EMPTY_ADDRESS); add.get(ModelDescriptionConstants.URI).set("one"); add.get(ModelDescriptionConstants.SCHEMA_LOCATION).set("loc-one"); ModelTestUtils.checkOutcome(kernelServices.executeOperation(add)); ModelNode result = kernelServices.executeForResult(read); List<ModelNode> list = result.asList(); Assert.assertEquals(1, list.size()); Property prop = list.get(0).asProperty(); Assert.assertEquals("one", prop.getName()); Assert.assertEquals("loc-one", prop.getValue().asString()); add.get(ModelDescriptionConstants.URI).set("two"); add.get(ModelDescriptionConstants.SCHEMA_LOCATION).set("loc-two"); ModelTestUtils.checkOutcome(kernelServices.executeOperation(add)); result = kernelServices.executeForResult(read); list = result.asList(); Assert.assertEquals(2, list.size()); prop = list.get(0).asProperty(); Assert.assertEquals("one", prop.getName()); Assert.assertEquals("loc-one", prop.getValue().asString()); prop = list.get(1).asProperty(); Assert.assertEquals("two", prop.getName()); Assert.assertEquals("loc-two", prop.getValue().asString()); ModelNode remove = Util.createOperation(SchemaLocationRemoveHandler.DEFINITION.getName(), PathAddress.EMPTY_ADDRESS); remove.get(ModelDescriptionConstants.URI).set("one"); ModelTestUtils.checkOutcome(kernelServices.executeOperation(remove)); result = kernelServices.executeForResult(read); list = result.asList(); Assert.assertEquals(1, list.size()); prop = list.get(0).asProperty(); Assert.assertEquals("two", prop.getName()); Assert.assertEquals("loc-two", prop.getValue().asString()); remove.get(ModelDescriptionConstants.URI).set("two"); ModelTestUtils.checkOutcome(kernelServices.executeOperation(remove)); Assert.assertEquals(new ModelNode().setEmptyList(), kernelServices.executeForResult(read)); remove.get(ModelDescriptionConstants.URI).set("blah"); kernelServices.executeForFailure(remove); }
Example 14
Source File: StandaloneDeploymentTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void removeDeployment(KernelServices kernelServices, String name) { ModelNode remove = Util.createOperation(DeploymentRemoveHandler.OPERATION_NAME, getPathAddress(name)); kernelServices.validateOperation(remove); ModelTestUtils.checkOutcome(kernelServices.executeOperation(remove)); }
Example 15
Source File: DomainDeploymentTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testDeploymentFullReplaceHandlerManaged() throws Exception { KernelServices kernelServices = createKernelServices(); //Create the original deployment ModelNode content = getByteContent(1, 2, 3, 4, 5); ModelNode op = createAddOperation(kernelServices, "Test1", content); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); ModelNode originalHash = checkSingleDeployment(kernelServices, "Test1"); //Now start replacing it op = Util.createOperation(DeploymentFullReplaceHandler.OPERATION_NAME, PathAddress.EMPTY_ADDRESS); op.get(NAME).set("Test1"); op.get(CONTENT).add(getByteContent(6, 7, 8, 9, 10)); kernelServices.validateOperation(op); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); ModelNode newHash = checkSingleDeployment(kernelServices, "Test1"); Assert.assertFalse(originalHash.equals(newHash)); op = op.clone(); op.get(CONTENT).clear(); ModelNode hashContent = new ModelNode(); hashContent.get(HASH).set(newHash); op.get(CONTENT).add(hashContent); kernelServices.validateOperation(op); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); Assert.assertEquals(newHash, checkSingleDeployment(kernelServices, "Test1")); op = op.clone(); op.get(CONTENT).clear(); op.get(CONTENT).add(getFileUrl("Test1", 1, 2, 3, 4, 5)); kernelServices.validateOperation(op); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); Assert.assertEquals(originalHash, checkSingleDeployment(kernelServices, "Test1")); //Replace again with a runtime name op = op.clone(); op.get(CONTENT).clear(); op.get(CONTENT).add(getInputStreamIndexContent()); op.get(RUNTIME_NAME).set("number1"); kernelServices.validateOperation(op); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op, new ByteArrayInputStream(new byte[] {6, 7, 8, 9, 10}))); Assert.assertEquals(newHash, checkSingleDeployment(kernelServices, "Test1", "number1")); }
Example 16
Source File: BasicRbacTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testBadRole() throws Exception { ModelNode operation = Util.createOperation(READONLY_OPERATION, pathAddress(UNCONSTRAINED_RESOURCE, FOO)); operation.get(OPERATION_HEADERS, "roles").add("Minataur"); executeForFailure(operation); }
Example 17
Source File: AuditLogSyslogReconnectTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testAutoReconnect() throws Exception { final int timeoutSeconds = 2; ModelNode op = createAddSyslogHandlerTcpOperation("syslog", "test-formatter", InetAddress.getByName("localhost"), SYSLOG_PORT, null, MessageTransfer.OCTET_COUNTING); op.get(STEPS).asList().get(0).get(SyslogAuditLogHandlerResourceDefinition.MAX_FAILURE_COUNT.getName()).set(3); op.get(STEPS).asList().get(1).get(SyslogAuditLogProtocolResourceDefinition.Tcp.RECONNECT_TIMEOUT.getName()).set(timeoutSeconds); executeForResult(op); SimpleSyslogServer server = SimpleSyslogServer.createTcp(SYSLOG_PORT, true); executeForResult(createAddHandlerReferenceOperation("syslog")); Assert.assertNotNull(server.receiveData()); try { final ModelNode readResource = Util.createOperation(READ_RESOURCE_OPERATION, AUDIT_ADDR); readResource.get(ModelDescriptionConstants.RECURSIVE).set(true); readResource.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(true); ModelNode result = executeForResult(readResource); Assert.assertNotNull(server.receiveData()); checkHandlerRuntimeFailureMetrics(result.get(ModelDescriptionConstants.SYSLOG_HANDLER, "syslog"), 3, 0, false); int failures = result.get(ModelDescriptionConstants.SYSLOG_HANDLER, "syslog").get(AuditLogHandlerResourceDefinition.FAILURE_COUNT.getName()).asInt(); server.close(); result = sendUntilFailure(readResource, failures); checkHandlerRuntimeFailureMetrics(result.get(ModelDescriptionConstants.SYSLOG_HANDLER, "syslog"), 3, 1, false); result = executeForResult(readResource); checkHandlerRuntimeFailureMetrics(result.get(ModelDescriptionConstants.SYSLOG_HANDLER, "syslog"), 3, 2, false); long before = System.currentTimeMillis(); result = executeForResult(readResource); //syslog handler should be disabled after 3 failures checkHandlerRuntimeFailureMetrics(result.get(ModelDescriptionConstants.SYSLOG_HANDLER, "syslog"), 3, 3, true); //Still disabled result = executeForResult(readResource); if (System.currentTimeMillis() - before < timeoutSeconds * 1000) { checkHandlerRuntimeFailureMetrics(result.get(ModelDescriptionConstants.SYSLOG_HANDLER, "syslog"), 3, 3, true); } Thread.sleep(timeoutSeconds * 1000 + 100); //Past the timeout, its hould now attempt and fail to reconnect, failure counts should remain the same result = executeForResult(readResource); checkHandlerRuntimeFailureMetrics(result.get(ModelDescriptionConstants.SYSLOG_HANDLER, "syslog"), 3, 3, true); result = executeForResult(readResource); checkHandlerRuntimeFailureMetrics(result.get(ModelDescriptionConstants.SYSLOG_HANDLER, "syslog"), 3, 3, true); SimpleSyslogServer oldServer = server; server = SimpleSyslogServer.createTcp(SYSLOG_PORT, true); Thread.sleep(timeoutSeconds * 1000 + 100); result = executeForResult(readResource); Assert.assertNotNull(server.receiveData()); //Although it should work again now, this read is what triggered it so the failure count will still be 3, and the handler disabled checkHandlerRuntimeFailureMetrics(result.get(ModelDescriptionConstants.SYSLOG_HANDLER, "syslog"), 3, 3, true); result = executeForResult(readResource); Assert.assertNotNull(server.receiveData()); //Now that it is all working again, the failure count should be 0 and the handler enabled checkHandlerRuntimeFailureMetrics(result.get(ModelDescriptionConstants.SYSLOG_HANDLER, "syslog"), 3, 0, false); //Make sure that the old server has no messages Assert.assertNull(oldServer.pollData()); } finally { if (server != null) { server.close(); } } }
Example 18
Source File: DomainDeploymentTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void removeDeployment(KernelServices kernelServices, String name) { ModelNode remove = Util.createOperation(DeploymentRemoveHandler.OPERATION_NAME, getPathAddress(name)); ModelTestUtils.checkOutcome(kernelServices.executeOperation(remove)); }
Example 19
Source File: StandaloneDeploymentTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testUnmanagedDeploymentRelativePath() throws Exception { KernelServices kernelServices = createKernelServices(); File file = writeToFile("Test-file1", 1, 2, 3, 4, 5); File dir = file.getParentFile(); ModelNode content = new ModelNode(); content.get(RELATIVE_TO).set(dir.getAbsolutePath()); ModelNode op = createAddOperation(kernelServices, "Test1", content); kernelServices.executeForFailure(op); content.get(ARCHIVE).set(false); op = createAddOperation(kernelServices, "Test1", content); kernelServices.executeForFailure(op); content.get(PATH).set(file.getName()); op = createAddOperation(kernelServices, "Test1", content); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); ModelNode deployedContent = checkSingleUnmanagedDeployment(kernelServices, "Test1", false); checkUnmanagedContents(file, deployedContent, false, false); op = Util.createOperation(DeploymentDeployHandler.OPERATION_NAME, getPathAddress("Test1")); kernelServices.validateOperation(op); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); deployedContent = checkSingleUnmanagedDeployment(kernelServices, "Test1", true); checkUnmanagedContents(file, deployedContent, false, false); op = Util.createOperation(DeploymentUndeployHandler.OPERATION_NAME, getPathAddress("Test1")); kernelServices.validateOperation(op); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); deployedContent = checkSingleUnmanagedDeployment(kernelServices, "Test1", false); checkUnmanagedContents(file, deployedContent, false, false); op = Util.createOperation(DeploymentDeployHandler.OPERATION_NAME, getPathAddress("Test1")); kernelServices.validateOperation(op); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); deployedContent = checkSingleUnmanagedDeployment(kernelServices, "Test1", true); checkUnmanagedContents(file, deployedContent, false, false); op = Util.createOperation(DeploymentRemoveHandler.OPERATION_NAME, getPathAddress("Test1")); kernelServices.validateOperation(op); ModelTestUtils.checkOutcome(kernelServices.executeOperation(op)); checkNoDeployments(kernelServices); }
Example 20
Source File: KeycloakSubsystemRemoveHandler.java From keycloak with Apache License 2.0 | 4 votes |
private void addStepToRemoveServerWar(OperationContext context, String deploymentName) { PathAddress deploymentAddress = PathAddress.pathAddress(PathElement.pathElement(DEPLOYMENT, deploymentName)); ModelNode op = Util.createOperation(REMOVE, deploymentAddress); context.addStep(op, getRemoveHandler(context, deploymentAddress), OperationContext.Stage.MODEL); }