use of org.jboss.as.controller.client.ModelControllerClient in project wildfly by wildfly.
the class DeploymentOperationsTestCase method testDeploymentRollbackOnRuntimeFailure.
@Test
public void testDeploymentRollbackOnRuntimeFailure() throws Exception {
final File deploymentOne = new File(deployDir, "deployment-one.jar");
final File deploymentTwo = new File(deployDir, "deployment-two.jar");
createDeployment(deploymentOne, "org.jboss.modules");
createDeployment(deploymentTwo, "non.existing.dependency");
final ModelNode composite = new ModelNode();
composite.get(OP).set(COMPOSITE);
composite.get(OPERATION_HEADERS).get(ROLLBACK_ON_RUNTIME_FAILURE).set(false);
final ModelNode nested = composite.get(STEPS).setEmptyList().add();
nested.get(OP).set(COMPOSITE);
nested.get(OP_ADDR).setEmptyList();
final ModelNode steps = nested.get(STEPS).setEmptyList();
final ModelNode deployOne = steps.add();
deployOne.get(OP).set(ADD);
deployOne.get(OP_ADDR).set(DEPLOYMENT_ONE.toModelNode());
deployOne.get(ENABLED).set(true);
deployOne.get(CONTENT).add().get(INPUT_STREAM_INDEX).set(0);
final ModelNode deployTwo = steps.add();
deployTwo.get(OP).set(ADD);
deployTwo.get(OP_ADDR).set(DEPLOYMENT_TWO.toModelNode());
deployTwo.get(ENABLED).set(true);
deployTwo.get(CONTENT).add().get(INPUT_STREAM_INDEX).set(1);
final Operation operation = OperationBuilder.create(composite, true).addFileAsAttachment(deploymentOne).addFileAsAttachment(deploymentTwo).build();
final ModelControllerClient client = getModelControllerClient();
try {
// Deploy
final ModelNode overallResult = client.execute(operation);
Assert.assertTrue(overallResult.asString(), SUCCESS.equals(overallResult.get(OUTCOME).asString()));
final ModelNode result = overallResult.get(RESULT, "step-1");
Assert.assertTrue(result.asString(), SUCCESS.equals(result.get(OUTCOME).asString()));
final ModelNode step1 = result.get(RESULT, "step-1");
Assert.assertEquals(SUCCESS, step1.get(OUTCOME).asString());
final ModelNode step2 = result.get(RESULT, "step-2");
Assert.assertEquals(FAILED, step2.get(OUTCOME).asString());
} finally {
safeClose(operation);
}
// Check if deployment-one and -two exist
executeOperation(Util.createEmptyOperation(READ_RESOURCE_OPERATION, DEPLOYMENT_ONE));
executeOperation(Util.createEmptyOperation(READ_RESOURCE_OPERATION, DEPLOYMENT_TWO));
//do cleanup
executeOperation(Util.createRemoveOperation(DEPLOYMENT_ONE));
executeOperation(Util.createRemoveOperation(DEPLOYMENT_TWO));
}
use of org.jboss.as.controller.client.ModelControllerClient in project wildfly by wildfly.
the class DeleteJMSResourceHandler method buildRequestWithoutHeaders.
@Override
public ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws OperationFormatException {
try {
if (!ctx.getParsedCommandLine().hasProperties()) {
throw new OperationFormatException("Arguments are missing");
}
} catch (CommandFormatException e) {
throw new OperationFormatException(e.getLocalizedMessage());
}
//String target = null;
String jndiName = null;
// TODO read server name from props
String serverName = "default";
String[] args = ctx.getArgumentsString().split("\\s+");
int i = 0;
while (i < args.length) {
String arg = args[i++];
if (arg.equals("--target")) {
// if(i < args.length) {
// target = args[i++];
// }
} else {
jndiName = arg;
}
}
if (jndiName == null) {
throw new OperationFormatException("name is missing.");
}
ModelControllerClient client = ctx.getModelControllerClient();
final String resource;
if (Util.isTopic(client, jndiName)) {
resource = "jms-topic";
} else if (Util.isQueue(client, jndiName)) {
resource = "jms-queue";
} else if (Util.isConnectionFactory(client, jndiName)) {
resource = "connection-factory";
} else {
throw new OperationFormatException("'" + jndiName + "' wasn't found among existing JMS resources.");
}
DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
builder.addNode("subsystem", "messaging");
builder.addNode("server", serverName);
builder.addNode(resource, jndiName);
builder.setOperationName("remove");
return builder.buildRequest();
}
use of org.jboss.as.controller.client.ModelControllerClient in project wildfly by wildfly.
the class EJBManagementUtil method getEJBRemoteConnectorPort.
/**
* Returns the EJB remoting connector port that can be used for EJB remote invocations
*
* @param managementServerHostName The hostname of the server
* @param managementPort The management port
* @return
*/
public static int getEJBRemoteConnectorPort(final String managementServerHostName, final int managementPort, final CallbackHandler handler) {
final ModelControllerClient modelControllerClient = getModelControllerClient(managementServerHostName, managementPort, handler);
try {
// first get the remote-connector from the EJB3 subsystem to find the remote connector ref
// /subsystem=ejb3/service=remote:read-attribute(name=connector-ref)
final ModelNode readConnectorRefAttribute = new ModelNode();
readConnectorRefAttribute.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION);
readConnectorRefAttribute.get(NAME).set(EJB3SubsystemModel.CONNECTOR_REF);
final PathAddress ejbRemotingServiceAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, EJB3Extension.SUBSYSTEM_NAME), EJB3SubsystemModel.REMOTE_SERVICE_PATH);
readConnectorRefAttribute.get(OP_ADDR).set(ejbRemotingServiceAddress.toModelNode());
// execute the read-attribute
final ModelNode connectorRefResult = execute(modelControllerClient, readConnectorRefAttribute);
final String connectorRef = connectorRefResult.get(RESULT).asString();
// now get the socket-binding ref for this connector ref, from the remoting subsystem
// /subsystem=remoting/connector=<connector-ref>:read-attribute(name=socket-binding)
final ModelNode readSocketBindingRefAttribute = new ModelNode();
readSocketBindingRefAttribute.get(OP).set(READ_ATTRIBUTE_OPERATION);
readSocketBindingRefAttribute.get(NAME).set(SOCKET_BINDING);
final PathAddress remotingSubsystemAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME), PathElement.pathElement("connector", connectorRef));
readSocketBindingRefAttribute.get(OP_ADDR).set(remotingSubsystemAddress.toModelNode());
// execute the read-attribute
final ModelNode socketBindingRefResult = execute(modelControllerClient, readSocketBindingRefAttribute);
final String socketBindingRef = socketBindingRefResult.get(RESULT).asString();
// now get the port value of that socket binding ref
// /socket-binding-group=standard-sockets/socket-binding=<socket-binding-ref>:read-attribute(name=port)
final ModelNode readPortAttribute = new ModelNode();
readPortAttribute.get(OP).set(READ_ATTRIBUTE_OPERATION);
readPortAttribute.get(NAME).set(PORT);
// TODO: "standard-sockets" group is hardcoded for now
final PathAddress socketBindingAddress = PathAddress.pathAddress(PathElement.pathElement(SOCKET_BINDING_GROUP, "standard-sockets"), PathElement.pathElement(SOCKET_BINDING, socketBindingRef));
readPortAttribute.get(OP_ADDR).set(socketBindingAddress.toModelNode());
// execute the read-attribute
final ModelNode portResult = execute(modelControllerClient, readPortAttribute);
return portResult.get(RESULT).asInt();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} finally {
// close the controller client connection
try {
modelControllerClient.close();
} catch (IOException e) {
logger.warn("Error closing model controller client", e);
}
}
}
use of org.jboss.as.controller.client.ModelControllerClient in project wildfly by wildfly.
the class JdrRunner method obtainProductVersion.
private String obtainProductVersion() {
try {
ModelNode operation = Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), PRODUCT_VERSION);
operation.get(INCLUDE_RUNTIME).set(false);
ModelControllerClient client = env.getClient();
if (client == null) {
client = env.getCli().getCommandContext().getModelControllerClient();
}
ModelNode result = client.execute(operation);
if (Operations.isSuccessfulOutcome(result)) {
return Operations.readResult(result).asString();
}
return "undefined";
} catch (IOException e) {
// In that case "undefined" is returned
return "undefined";
}
}
use of org.jboss.as.controller.client.ModelControllerClient in project wildfly by wildfly.
the class JdrRunner method obtainServerUUID.
private String obtainServerUUID() throws OperationFailedException {
try {
ModelNode operation = Operations.createReadAttributeOperation(new ModelNode().setEmptyList(), UUID);
operation.get(INCLUDE_RUNTIME).set(true);
ModelControllerClient client = env.getClient();
if (client == null) {
client = env.getCli().getCommandContext().getModelControllerClient();
}
ModelNode result = client.execute(operation);
if (Operations.isSuccessfulOutcome(result)) {
return Operations.readResult(result).asString();
}
return null;
} catch (IOException ex) {
return null;
}
}
Aggregations