1 23 24 package com.sun.enterprise.deployment.client; 25 26 import java.util.*; 27 import java.io.IOException ; 28 29 import com.sun.enterprise.deployment.backend.DeploymentStatus; 30 import com.sun.enterprise.deployment.util.DeploymentProperties; 31 import com.sun.enterprise.util.i18n.StringManager; 32 33 import javax.enterprise.deploy.spi.Target ; 34 import javax.enterprise.deploy.spi.TargetModuleID ; 35 import javax.enterprise.deploy.shared.CommandType ; 36 import javax.enterprise.deploy.shared.StateType ; 37 38 import com.sun.enterprise.deployapi.SunTarget; 39 import com.sun.enterprise.deployapi.ProgressObjectImpl; 40 import com.sun.enterprise.deployapi.SunTargetModuleID; 41 42 import com.sun.appserv.management.client.ConnectionSource; 43 import com.sun.appserv.management.client.AppserverConnectionSource; 44 45 public class ApplicationReferenceAction extends ProgressObjectImpl { 46 47 private static StringManager localStrings = StringManager.getManager(ApplicationReferenceAction.class); 48 49 public ApplicationReferenceAction(SunTarget[] targets) { 50 super(targets); 51 } 52 53 private void handleAppRefActionForLifeCycleModules(ConnectionSource dasConnection, SunTarget[] targetList, 54 String id, CommandType cmd, Map options) { 55 String action = (CommandType.DISTRIBUTE.equals(cmd)) ? "Creation" : "Removal"; 56 57 58 try { 59 for(int i=0; i<targetList.length; i++) { 60 DeploymentStatus stat = null; 61 if(CommandType.DISTRIBUTE.equals(cmd)) { 62 stat = DeploymentClientUtils.createLifecycleModuleReference( 63 dasConnection.getExistingMBeanServerConnection(), id, targetList[i].getName(), options); 64 } else { 65 stat = DeploymentClientUtils.removeLifecycleModuleReference( 66 dasConnection.getExistingMBeanServerConnection(), id, targetList[i].getName()); 67 } 68 if(!checkStatusAndAddStage(targetList[i], null, localStrings.getString("enterprise.deployment.client.change_reference", action, targetList[i].getName()), dasConnection, stat)) { 69 return; 70 } 71 } 72 setupForNormalExit(localStrings.getString("enterprise.deployment.client.change_reference_lifemodule", action), targetList[0]); 73 } catch(Throwable ioex) { 74 finalDeploymentStatus.setStageException(ioex); 75 setupForAbnormalExit(localStrings.getString("enterprise.deployment.client.change_reference_lifemodule_failed", action, ioex.getMessage()), targetList[0]); 76 } 77 return; 78 } 79 80 public void run() { 81 ConnectionSource dasConnection= (ConnectionSource) args[0]; 82 SunTarget[] targetList = (SunTarget[]) args[1]; 83 String moduleID = (String ) args[2]; 84 CommandType cmd = (CommandType ) args[3]; 85 Map deployOptions = (Map) args[4]; 86 87 String action = (CommandType.DISTRIBUTE.equals(cmd)) ? "Creation" : "Removal"; 88 try { 89 if(DeploymentClientUtils.isLifecycleModule(dasConnection.getExistingMBeanServerConnection(), moduleID)) { 91 handleAppRefActionForLifeCycleModules(dasConnection, targetList, moduleID, cmd, deployOptions); 92 return; 93 } 94 95 ArrayList resultTargetModuleIDs = new ArrayList(); 97 98 RollBackAction rollback; 99 if(CommandType.DISTRIBUTE.equals(cmd)) { 100 rollback = new RollBackAction(RollBackAction.CREATE_APP_REF_OPERATION, moduleID, deployOptions); 101 } else{ 102 rollback = new RollBackAction(RollBackAction.DELETE_APP_REF_OPERATION, moduleID, deployOptions); 103 } 104 105 for(int i=0; i<targetList.length; i++) { 106 if(CommandType.DISTRIBUTE.equals(cmd)) { 107 DeploymentStatus stat = 108 DeploymentClientUtils.createApplicationReference( 109 dasConnection.getExistingMBeanServerConnection(), 110 moduleID, targetList[i], deployOptions); 111 if(!checkStatusAndAddStage(targetList[i], rollback, 112 localStrings.getString("enterprise.deployment.client.create_reference", targetList[i].getName()), dasConnection, stat)) { 113 return; 114 } 115 rollback.addTarget(targetList[i], RollBackAction.APP_REF_CREATED); 116 117 130 DeploymentClientUtils.setResourceOptions( 131 deployOptions, 132 DeploymentProperties.RES_CREATE_REF, 133 targetList[i].getName()); 134 stat = DeploymentClientUtils.startApplication( 135 dasConnection.getExistingMBeanServerConnection(), 136 moduleID, targetList[i], deployOptions); 137 138 141 checkStatusAndAddStage(targetList[i], null, 142 localStrings.getString("enterprise.deployment.client.reference_start", targetList[i].getName()), dasConnection, stat, true); 143 144 } else { 145 deployOptions.put(DeploymentProperties.DEPLOY_OPTION_FORCE_KEY, "false"); 146 147 150 DeploymentClientUtils.setResourceOptions( 151 deployOptions, 152 DeploymentProperties.RES_DELETE_REF, 153 targetList[i].getName()); 154 DeploymentStatus stat = 155 DeploymentClientUtils.stopApplication( 156 dasConnection.getExistingMBeanServerConnection(), 157 moduleID, targetList[i], deployOptions); 158 checkStatusAndAddStage(targetList[i], null, 159 localStrings.getString("enterprise.deployment.client.reference_stop", targetList[i].getName()), dasConnection, stat); 160 161 stat = DeploymentClientUtils.deleteApplicationReference( 162 dasConnection.getExistingMBeanServerConnection(), 163 moduleID, targetList[i], deployOptions); 164 if(!checkStatusAndAddStage(targetList[i], rollback, 165 localStrings.getString("enterprise.deployment.client.remove_reference", targetList[i].getName()), dasConnection, stat)) { 166 return; 167 } 168 rollback.addTarget(targetList[i], RollBackAction.APP_REF_DELETED); 169 } 170 resultTargetModuleIDs.add(new SunTargetModuleID(moduleID, targetList[i])); 171 } 172 173 this.targetModuleIDs = new TargetModuleID [resultTargetModuleIDs.size()]; 176 this.targetModuleIDs = 177 (TargetModuleID [])resultTargetModuleIDs.toArray(this.targetModuleIDs); 178 179 setupForNormalExit(localStrings.getString("enterprise.deployment.client.change_reference_application", action), targetList[0]); 180 } catch (Throwable ioex) { 181 finalDeploymentStatus.setStageException(ioex); 182 setupForAbnormalExit(localStrings.getString("enterprise.deployment.client.change_reference_application_failed", action, ioex.getMessage()), targetList[0]); 183 return; 184 } 185 } 186 } 187 | Popular Tags |