Class Operations
- java.lang.Object
-
- org.jboss.as.controller.client.helpers.Operations
-
public class Operations extends Object
A helper class for various operation tasks. Includes helpers to create standard operations, check whether the operation was executed successfully, get the failure description if unsuccessful, etc. Example: Read the server statefinal ModelControllerClient client = ModelControllerClient.Factory.create(hostname, port); final ModelNode address = new ModelNode().setEmptyList(); // Read the server state final ModelNode op = Operations.createReadAttributeOperation(address, "server-state"); final ModelNode result = client.execute(op); if (Operations.isSuccessfulOutcome(result)) { System.out.printf("Server state: %s%n", Operations.readResult(result)); } else { System.out.printf("Failure! %s%n", Operations.getFailureDescription(result)); }- Author:
- James R. Perkins
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOperations.CompositeOperationBuilderA builder for building composite operations.
-
Constructor Summary
Constructors Constructor Description Operations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.jboss.dmr.ModelNodecreateAddOperation(org.jboss.dmr.ModelNode address)Creates an add operation.static org.jboss.dmr.ModelNodecreateAddress(Iterable<String> pairs)Creates an address that can be used as the address for an operation.static org.jboss.dmr.ModelNodecreateAddress(String... pairs)Creates an address that can be used as the address for an operation.static org.jboss.dmr.ModelNodecreateCompositeOperation()Creates a composite operation with an empty address and empty steps that will rollback on a runtime failure.static org.jboss.dmr.ModelNodecreateOperation(String operation)Creates a generic operation with an empty (root) address.static org.jboss.dmr.ModelNodecreateOperation(String operation, org.jboss.dmr.ModelNode address)Creates an operation.static org.jboss.dmr.ModelNodecreateReadAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName)Creates an operation to read the attribute represented by theattributeNameparameter.static org.jboss.dmr.ModelNodecreateReadResourceOperation(org.jboss.dmr.ModelNode address)Creates a non-recursive operation to read a resource.static org.jboss.dmr.ModelNodecreateReadResourceOperation(org.jboss.dmr.ModelNode address, boolean recursive)Creates an operation to read a resource.static org.jboss.dmr.ModelNodecreateRemoveOperation(org.jboss.dmr.ModelNode address)Creates a remove operation.static org.jboss.dmr.ModelNodecreateUndefineAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName)Creates an operation to undefine an attribute value represented by theattributeNameparameter.static org.jboss.dmr.ModelNodecreateWriteAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName, boolean value)Creates an operation to write an attribute value represented by theattributeNameparameter.static org.jboss.dmr.ModelNodecreateWriteAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName, int value)Creates an operation to write an attribute value represented by theattributeNameparameter.static org.jboss.dmr.ModelNodecreateWriteAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName, long value)Creates an operation to write an attribute value represented by theattributeNameparameter.static org.jboss.dmr.ModelNodecreateWriteAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName, String value)Creates an operation to write an attribute value represented by theattributeNameparameter.static org.jboss.dmr.ModelNodecreateWriteAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName, org.jboss.dmr.ModelNode value)Creates an operation to write an attribute value represented by theattributeNameparameter.static org.jboss.dmr.ModelNodegetFailureDescription(org.jboss.dmr.ModelNode result)Parses the result and returns the failure description.static org.jboss.dmr.ModelNodegetOperationAddress(org.jboss.dmr.ModelNode op)Returns the address for the operation.static StringgetOperationName(org.jboss.dmr.ModelNode op)Returns the name of the operation.static booleanisSuccessfulOutcome(org.jboss.dmr.ModelNode outcome)Checks the result for a successful operation outcome.static org.jboss.dmr.ModelNodereadResult(org.jboss.dmr.ModelNode result)Reads the result of an operation and returns the result.
-
-
-
Method Detail
-
isSuccessfulOutcome
public static boolean isSuccessfulOutcome(org.jboss.dmr.ModelNode outcome)
Checks the result for a successful operation outcome.- Parameters:
outcome- the result of executing an operation- Returns:
trueif the operation was successful, otherwisefalse
-
getFailureDescription
public static org.jboss.dmr.ModelNode getFailureDescription(org.jboss.dmr.ModelNode result)
Parses the result and returns the failure description.- Parameters:
result- the result of executing an operation- Returns:
- the failure description if defined, otherwise a new undefined model node
- Throws:
IllegalArgumentException- if the outcome of the operation was successful
-
createAddress
public static org.jboss.dmr.ModelNode createAddress(String... pairs)
Creates an address that can be used as the address for an operation. The address is simply aModelNodeof typeModelType.LIST.The string is split into key/value pairs. If the final key does not have a value an
*is used to indicate a wildcard for the address.- Parameters:
pairs- the key/value pairs to use- Returns:
- an address for the key/value pairs
-
createAddress
public static org.jboss.dmr.ModelNode createAddress(Iterable<String> pairs)
Creates an address that can be used as the address for an operation. The address is simply aModelNodeof typeModelType.LIST.The string is split into key/value pairs. If the final key does not have a value an
*is used to indicate a wildcard for the address.- Parameters:
pairs- the key/value pairs to use- Returns:
- an address for the key/value pairs
-
getOperationAddress
public static org.jboss.dmr.ModelNode getOperationAddress(org.jboss.dmr.ModelNode op)
Returns the address for the operation.- Parameters:
op- the operation- Returns:
- the operation address or a new undefined model node
-
getOperationName
public static String getOperationName(org.jboss.dmr.ModelNode op)
Returns the name of the operation.- Parameters:
op- the operation- Returns:
- the name of the operation
- Throws:
IllegalArgumentException- if the operation was not defined.
-
createAddOperation
public static org.jboss.dmr.ModelNode createAddOperation(org.jboss.dmr.ModelNode address)
Creates an add operation.- Parameters:
address- the address for the operation- Returns:
- the operation
-
createRemoveOperation
public static org.jboss.dmr.ModelNode createRemoveOperation(org.jboss.dmr.ModelNode address)
Creates a remove operation.- Parameters:
address- the address for the operation- Returns:
- the operation
-
createCompositeOperation
public static org.jboss.dmr.ModelNode createCompositeOperation()
Creates a composite operation with an empty address and empty steps that will rollback on a runtime failure. By default theClientConstants.ROLLBACK_ON_RUNTIME_FAILUREis set totrueto rollback all operations if one fails.- Returns:
- the operation
-
createReadAttributeOperation
public static org.jboss.dmr.ModelNode createReadAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName)Creates an operation to read the attribute represented by theattributeNameparameter.- Parameters:
address- the address to create the read attribute forattributeName- the name of the parameter to read- Returns:
- the operation
-
createReadResourceOperation
public static org.jboss.dmr.ModelNode createReadResourceOperation(org.jboss.dmr.ModelNode address)
Creates a non-recursive operation to read a resource.- Parameters:
address- the address to create the read for- Returns:
- the operation
-
createReadResourceOperation
public static org.jboss.dmr.ModelNode createReadResourceOperation(org.jboss.dmr.ModelNode address, boolean recursive)Creates an operation to read a resource.- Parameters:
address- the address to create the read forrecursive- whether to search recursively or not- Returns:
- the operation
-
createUndefineAttributeOperation
public static org.jboss.dmr.ModelNode createUndefineAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName)Creates an operation to undefine an attribute value represented by theattributeNameparameter.- Parameters:
address- the address to create the write attribute forattributeName- the name attribute to undefine- Returns:
- the operation
-
createWriteAttributeOperation
public static org.jboss.dmr.ModelNode createWriteAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName, boolean value)Creates an operation to write an attribute value represented by theattributeNameparameter.- Parameters:
address- the address to create the write attribute forattributeName- the name of the attribute to writevalue- the value to set the attribute to- Returns:
- the operation
-
createWriteAttributeOperation
public static org.jboss.dmr.ModelNode createWriteAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName, int value)Creates an operation to write an attribute value represented by theattributeNameparameter.- Parameters:
address- the address to create the write attribute forattributeName- the name of the attribute to writevalue- the value to set the attribute to- Returns:
- the operation
-
createWriteAttributeOperation
public static org.jboss.dmr.ModelNode createWriteAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName, long value)Creates an operation to write an attribute value represented by theattributeNameparameter.- Parameters:
address- the address to create the write attribute forattributeName- the name of the attribute to writevalue- the value to set the attribute to- Returns:
- the operation
-
createWriteAttributeOperation
public static org.jboss.dmr.ModelNode createWriteAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName, String value)Creates an operation to write an attribute value represented by theattributeNameparameter.- Parameters:
address- the address to create the write attribute forattributeName- the name of the attribute to writevalue- the value to set the attribute to- Returns:
- the operation
-
createWriteAttributeOperation
public static org.jboss.dmr.ModelNode createWriteAttributeOperation(org.jboss.dmr.ModelNode address, String attributeName, org.jboss.dmr.ModelNode value)Creates an operation to write an attribute value represented by theattributeNameparameter.- Parameters:
address- the address to create the write attribute forattributeName- the name of the attribute to writevalue- the value to set the attribute to- Returns:
- the operation
-
createOperation
public static org.jboss.dmr.ModelNode createOperation(String operation)
Creates a generic operation with an empty (root) address.- Parameters:
operation- the operation to create- Returns:
- the operation
-
createOperation
public static org.jboss.dmr.ModelNode createOperation(String operation, org.jboss.dmr.ModelNode address)
Creates an operation.- Parameters:
operation- the operation nameaddress- the address for the operation- Returns:
- the operation
- Throws:
IllegalArgumentException- if the address is not of typeModelType.LIST
-
readResult
public static org.jboss.dmr.ModelNode readResult(org.jboss.dmr.ModelNode result)
Reads the result of an operation and returns the result. If the operation does not have aClientConstants.RESULTattribute, a new undefinedModelNodeis returned.- Parameters:
result- the result of executing an operation- Returns:
- the result of the operation or a new undefined model node
-
-