Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jboss.as.test.integration.management;
 
 import java.util.List;
 
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;

Shared class that provides utility methods for executing management operations

Author(s):
Stuart Douglas
public class ManagementOperations {
    private ManagementOperations() {
    }
    public static void executeOperations(final ModelControllerClient clientfinal List<ModelNodeoperationsthrows IOExceptionMgmtOperationException {
        for(ModelNode op : operations) {
            executeOperation(clientop);
        }
    }

    
Executes a management operation and returns the 'result' ModelNode of the server output. If the operation fails an exception will be thrown
    public static ModelNode executeOperation(final ModelControllerClient clientfinal ModelNode opthrows IOExceptionMgmtOperationException {
        return executeOperation(clientoptrue);
    }

    
Executes a management operation and returns the 'result' ModelNode of the server output. If the operation fails an exception will be thrown
    public static ModelNode executeOperation(final ModelControllerClient clientfinal Operation opthrows IOExceptionMgmtOperationException {
        return executeOperation(clientoptrue);
    }


    
Executes a management operation and returns the raw ModelNode that is returned from the server. It is up to the client to check it the result is a success or not
    public static ModelNode executeOperationRaw(final ModelControllerClient clientfinal ModelNode opthrows IOException {
        try {
            return executeOperation(clientopfalse);
        } catch (MgmtOperationException e) {
            throw new RuntimeException(e);
        }
    }
    private static ModelNode executeOperation(final ModelControllerClient clientfinal ModelNode opboolean unwrapResultthrows IOExceptionMgmtOperationException {
        ModelNode ret = client.execute(op);
        if (!unwrapResultreturn ret;
        if (!.equals(ret.get().asString())) {
            throw new MgmtOperationException("Management operation failed: " + ret.get(), opret);
        }
        return ret.get();
    }
    private static ModelNode executeOperation(final ModelControllerClient clientfinal Operation opboolean unwrapResultthrows IOExceptionMgmtOperationException {
        ModelNode ret = client.execute(op);
        if (!unwrapResultreturn ret;
        if (!.equals(ret.get().asString())) {
            throw new MgmtOperationException("Management operation failed: " + ret.get(), op.getOperation(), ret);
        }
        return ret.get();
    }
New to GrepCode? Check out our FAQ X