FileDocCategorySizeDatePackage
RollBackAction.javaAPI DocGlassfish v2 API11152Fri May 04 22:34:36 BST 2007com.sun.enterprise.deployment.client

RollBackAction

public class RollBackAction extends Object

Fields Summary
private String
moduleID
private Map
options
private int
currentOperation
private Map
targetState
private Vector
targetList
public static final int
APP_REF_CREATED
public static final int
APP_STARTED
public static final int
APP_REF_DELETED
public static final int
APP_STOPPED
public static final int
DEPLOY_OPERATION
public static final int
UNDEPLOY_OPERATION
public static final int
CREATE_APP_REF_OPERATION
public static final int
DELETE_APP_REF_OPERATION
Constructors Summary
public RollBackAction(int operation, String moduleID, Map options)

    
           
        this.currentOperation = operation;
        this.moduleID = moduleID;
        this.options = options;
    
Methods Summary
public voidaddTarget(com.sun.enterprise.deployapi.SunTarget target, int state)

        if(targetList == null) {
            targetList = new Vector();
            targetState= new HashMap();
        }
        targetState.put(target.getName(), new Integer(state));
        targetList.add(target);
        return;
    
private booleancreateAppRefs(com.sun.appserv.management.client.ConnectionSource dasConnection, com.sun.enterprise.deployment.backend.DeploymentStatus rollbackStatus)

        if(targetList == null) {
            return true;
        }
        try {
            SunTarget[] targetObjs = (SunTarget[]) targetList.toArray(new SunTarget[targetList.size()]);
            for(int i=0; i<targetObjs.length; i++) {
                int state = ((Integer)targetState.get(targetObjs[i].getName())).intValue();
                if(state == APP_REF_DELETED) {
                    DeploymentStatus status = 
                        DeploymentClientUtils.createApplicationReference(
                            dasConnection.getExistingMBeanServerConnection(),
                            moduleID, targetObjs[i], options);
                    rollbackStatus.addSubStage(status);
                    if (status!=null && status.getStatus() < DeploymentStatus.WARNING) {
                        return false;
                    }
                    targetState.put(targetObjs[i].getName(), new Integer(APP_STOPPED));
                }
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    
private booleandeleteAppRefs(com.sun.appserv.management.client.ConnectionSource dasConnection, com.sun.enterprise.deployment.backend.DeploymentStatus rollbackStatus)

        if(targetList == null) {
            return true;
        }
        if("true".equals(options.get(DeploymentProperties.DEPLOY_OPTION_FORCE_KEY))) {
            options.put(DeploymentProperties.DEPLOY_OPTION_CASCADE_KEY, "false");
        } else {
            options.put(DeploymentProperties.DEPLOY_OPTION_CASCADE_KEY, "true");
        }
        try {
            SunTarget[] targetObjs = (SunTarget[]) targetList.toArray(new SunTarget[targetList.size()]);
            for(int i=0; i<targetObjs.length; i++) {
                int state = ((Integer)targetState.get(targetObjs[i].getName())).intValue();
                if(state == APP_REF_CREATED) {
                    DeploymentStatus status = 
                        DeploymentClientUtils.deleteApplicationReference(
                            dasConnection.getExistingMBeanServerConnection(),
                            moduleID, targetObjs[i], options);
                    rollbackStatus.addSubStage(status);
                    if (status!=null && status.getStatus() < DeploymentStatus.WARNING) {
                        return false;
                    }
                    targetState.remove(targetObjs[i].getName());
                }
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    
public booleanrollback(com.sun.appserv.management.client.ConnectionSource dasConnection, com.sun.enterprise.deployment.backend.DeploymentStatus rollbackStatus)

        boolean retVal = false;
        
        switch(currentOperation) {
            case DEPLOY_OPERATION :
                if(!stopModules(dasConnection, rollbackStatus)) {
                    return false;
                }
                if(!deleteAppRefs(dasConnection, rollbackStatus)) {
                    return false;
                }
                retVal = undeployModule(dasConnection, rollbackStatus);
                break;
            
            case CREATE_APP_REF_OPERATION :
                if(!stopModules(dasConnection, rollbackStatus)) {
                    return false;
                }
                retVal = deleteAppRefs(dasConnection, rollbackStatus);
                break;
                
            case UNDEPLOY_OPERATION :
                retVal = true; // failures during undeploy from domain will never be rolled back
                break;
                
            case DELETE_APP_REF_OPERATION :
                if(!createAppRefs(dasConnection, rollbackStatus)) {
                    return false;
                }
                retVal = startModules(dasConnection, rollbackStatus);
                break;
                
            default :
                break;
        }
        return retVal;
    
private booleanstartModules(com.sun.appserv.management.client.ConnectionSource dasConnection, com.sun.enterprise.deployment.backend.DeploymentStatus rollbackStatus)

        if(targetList == null) {
            return true;
        }
        try {
            SunTarget[] targetObjs = (SunTarget[]) targetList.toArray(new SunTarget[targetList.size()]);
            for(int i=0; i<targetObjs.length; i++) {
                int state = ((Integer)targetState.get(targetObjs[i].getName())).intValue();
                if(state == APP_STOPPED) {
                    DeploymentStatus status = 
                        DeploymentClientUtils.startApplication(
                            dasConnection.getExistingMBeanServerConnection(),
                            moduleID, targetObjs[i], options);
                    rollbackStatus.addSubStage(status);
                    // We don't check the start return because we can't do anything if the instance is down
                    targetState.remove(targetObjs[i].getName());
                }
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    
private booleanstopModules(com.sun.appserv.management.client.ConnectionSource dasConnection, com.sun.enterprise.deployment.backend.DeploymentStatus rollbackStatus)

        if(targetList == null) {
            return true;
        }
        
        Map tmpOptions = new HashMap();
        tmpOptions.putAll(options);
        tmpOptions.put(DeploymentProperties.DEPLOY_OPTION_CASCADE_KEY, "true");
        tmpOptions.put(DeploymentProperties.DEPLOY_OPTION_FORCE_KEY, "true");
        try {
            SunTarget[] targetObjs = (SunTarget[]) targetList.toArray(new SunTarget[targetList.size()]);
            for(int i=0; i<targetObjs.length; i++) {
                int state = ((Integer)targetState.get(targetObjs[i].getName())).intValue();
                if(state == APP_STARTED) {
                    DeploymentStatus status = 
                        DeploymentClientUtils.stopApplication(
                            dasConnection.getExistingMBeanServerConnection(),
                            moduleID, targetObjs[i], tmpOptions);
                    rollbackStatus.addSubStage(status);
                    if (status!=null && status.getStatus() < DeploymentStatus.WARNING) {
                        return false;
                    }
                    targetState.put(targetObjs[i].getName(), new Integer(APP_REF_CREATED));
                }
            }
        } catch (Exception e) {
            return false;
        }
        return true;
    
private booleanundeployModule(com.sun.appserv.management.client.ConnectionSource dasConnection, com.sun.enterprise.deployment.backend.DeploymentStatus rollbackStatus)

        DeploymentMgr deplMgr = ProxyFactory.getInstance(dasConnection).getDomainRoot().getDeploymentMgr();        
        Map undeployStatus = deplMgr.undeploy(moduleID, options);            
        com.sun.appserv.management.deploy.DeploymentStatus finalStatusFromMBean = 
                            DeploymentSupport.mapToDeploymentStatus(undeployStatus);
        DeploymentStatus tmp = DeploymentClientUtils.getDeploymentStatusFromAdminStatus(finalStatusFromMBean);
        rollbackStatus.addSubStage(tmp);
        if (tmp!=null && tmp.getStatus() < DeploymentStatus.WARNING) {
            return false;
        }
        return true;