public static String parseStringParameter(ModelNode operation, String name) { return has(operation, name) ? operation.get(name).toString() : null; } }
private static void testProtocolAddRemoveOperation(KernelServices services, String protocol) { ModelNode result = services.executeOperation(getProtocolAddOperation("minimal", protocol)); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); result = services.executeOperation(getProtocolRemoveOperation("minimal", protocol)); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); } }
@Test public void testProtocolReadWriteOperation() throws Exception { KernelServices services = this.buildKernelServices(); // add a protocol stack specifying TRANSPORT and PROTOCOLS parameters ModelNode result = services.executeOperation(getProtocolStackAddOperationWithParameters("maximal2")); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); // read the socket binding attribute result = services.executeOperation(getProtocolReadOperation("maximal", "MPING", SocketBindingProtocolResourceDefinition.Attribute.SOCKET_BINDING)); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("jgroups-mping", result.get(RESULT).asString()); // write the attribute result = services.executeOperation(getProtocolWriteOperation("maximal", "MPING", SocketBindingProtocolResourceDefinition.Attribute.SOCKET_BINDING, "new-socket-binding")); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); // re-read the attribute result = services.executeOperation(getProtocolReadOperation("maximal", "MPING", SocketBindingProtocolResourceDefinition.Attribute.SOCKET_BINDING)); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("new-socket-binding", result.get(RESULT).asString()); }
/** * Tests access to transport attributes */ @Test public void testTransportReadWriteOperation() throws Exception { KernelServices services = this.buildKernelServices(); // read the transport rack attribute ModelNode result = services.executeOperation(getTransportReadOperation("maximal", "TCP", TransportResourceDefinition.Attribute.RACK)); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("rack1", ExpressionResolver.TEST_RESOLVER.resolveExpressions(result.get(RESULT)).asString()); // write the rack attribute result = services.executeOperation(getTransportWriteOperation("maximal", "TCP", TransportResourceDefinition.Attribute.RACK, "new-rack")); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); // re-read the rack attribute result = services.executeOperation(getTransportReadOperation("maximal", "TCP", TransportResourceDefinition.Attribute.RACK)); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("new-rack", result.get(RESULT).asString()); }
@Test public void testTransportReadWriteWithParameters() throws Exception { // Parse and install the XML into the controller KernelServices services = this.buildKernelServices(); Assert.assertTrue("Could not create services", services.isSuccessfulBoot()); // add a protocol stack specifying TRANSPORT and PROTOCOLS parameters ModelNode result = services.executeOperation(getProtocolStackAddOperationWithParameters("maximal2")); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); // write the rack attribute result = services.executeOperation(getTransportWriteOperation("maximal", "TCP", TransportResourceDefinition.Attribute.RACK, "new-rack")); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); // re-read the rack attribute result = services.executeOperation(getTransportReadOperation("maximal", "TCP", TransportResourceDefinition.Attribute.RACK)); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("new-rack", result.get(RESULT).asString()); }
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("value", ExpressionResolver.TEST_RESOLVER.resolveExpressions(result.get(RESULT)).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("new-value", result.get(RESULT).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertFalse(result.get(RESULT).isDefined()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("false", result.get(RESULT).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("false", result.get(RESULT).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("true", result.get(RESULT).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("true", result.get(RESULT).asString());
Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("true", ExpressionResolver.TEST_RESOLVER.resolveExpressions(result.get(RESULT)).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("false", result.get(RESULT).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertFalse(result.get(RESULT).isDefined()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("false", result.get(RESULT).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("false", result.get(RESULT).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("true", result.get(RESULT).asString()); Assert.assertEquals(result.toString(), SUCCESS, result.get(OUTCOME).asString()); Assert.assertEquals("true", result.get(RESULT).asString());
private String getFailureDescription(ModelNode result) { if (result.hasDefined(FAILURE_DESCRIPTION)) { return result.get(FAILURE_DESCRIPTION).toString(); } return null; }
public ModelType getType(ModelNode typeNode) { if (typeNode == null) { return ModelType.UNDEFINED; } try { return ModelType.valueOf(typeNode.toString()); } catch (RuntimeException e) { return null; } }
private void checkSuccessful(final ModelNode result, final ModelNode operation) throws UnSuccessfulOperationException { if (!SUCCESS.equals(result.get(OUTCOME).asString())) { logger.error("Operation " + operation + " did not succeed. Result was " + result); throw new UnSuccessfulOperationException(result.get( FAILURE_DESCRIPTION).toString()); } }
@Override protected void handleFailureResult(final ModelNode result) { // Remove the in-progress marker removeInProgressMarker(); writeFailedMarker(deploymentFile, result.get(FAILURE_DESCRIPTION).toString(), doDeployTimestamp); } }
@Override protected void handleFailureResult(ModelNode result) { // Remove the in-progress marker removeInProgressMarker(); writeFailedMarker(new File(parent, deploymentName), result.get(FAILURE_DESCRIPTION).toString(), markerLastModified); } }
private String valueFromOpAddress(String addrElement, ModelNode operation) { String deploymentName = getValueOfAddrElement(operation.get(ADDRESS), addrElement); if (deploymentName == null) throw new RuntimeException("Can't find '" + addrElement + "' in address " + operation.toString()); return deploymentName; }
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { // TODO: localize exception. get id number if (!operation.get(OP).asString().equals(ADD)) { throw new OperationFailedException("Unexpected operation for add realm. operation=" + operation.toString()); } for (AttributeDefinition attrib : RealmDefinition.ALL_ATTRIBUTES) { attrib.validateAndSet(operation, model); } }
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { // TODO: localize exception. get id number if (!operation.get(OP).asString().equals(ADD)) { throw new OperationFailedException("Unexpected operation for add secure deployment. operation=" + operation.toString()); } for (AttributeDefinition attr : SecureDeploymentDefinition.ALL_ATTRIBUTES) { attr.validateAndSet(operation, model); } }
public static ModelNode validateFailedResponse(ModelNode response) { if(! FAILED.equals(response.get(OUTCOME).asString())) { System.out.println("Response succeeded:"); System.out.println(response); Assert.fail(response.get(OUTCOME).toString()); } Assert.assertTrue("failure description exists", response.has(FAILURE_DESCRIPTION)); return response.get(FAILURE_DESCRIPTION); }
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { // TODO: localize exception. get id number if (!operation.get(OP).asString().equals(ADD)) { throw new OperationFailedException("Unexpected operation for add SPI. operation=" + operation.toString()); } SpiResourceDefinition.DEFAULT_PROVIDER.validateAndSet(operation, model); KeycloakAdapterConfigService.INSTANCE.updateConfig(operation, model); } }
public void updateCredential(ModelNode operation, String attrName, ModelNode resolvedValue) { ModelNode credentials = credentialsFromOp(operation); if (!credentials.isDefined()) { throw new RuntimeException("Can not update credential. No credential defined for deployment in op " + operation.toString()); } String credentialName = credentialNameFromOp(operation); credentials.get(credentialName).set(resolvedValue); }
public void updateCredential(ModelNode operation, String attrName, ModelNode resolvedValue) { ModelNode credentials = credentialsFromOp(operation); if (!credentials.isDefined()) { throw new RuntimeException("Can not update credential. No credential defined for deployment in op " + operation.toString()); } String credentialName = credentialNameFromOp(operation); credentials.get(credentialName).set(resolvedValue); }
@Override protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException { // TODO: localize exception. get id number if (!operation.get(OP).asString().equals(ADD)) { throw new OperationFailedException("Unexpected operation for add SPI. operation=" + operation.toString()); } ProviderResourceDefinition.ENABLED.validateAndSet(operation, model); ProviderResourceDefinition.PROPERTIES.validateAndSet(operation, model); KeycloakAdapterConfigService.INSTANCE.updateConfig(operation, model); } }