1 23 24 package com.sun.enterprise.deployment.client; 25 26 import com.sun.appserv.management.client.ConnectionSource; 27 import com.sun.appserv.management.client.ProxyFactory; 28 import com.sun.appserv.management.config.ConfigConfig; 29 import com.sun.appserv.management.config.DomainConfig; 30 import com.sun.appserv.management.config.HTTPServiceConfig; 31 import com.sun.appserv.management.config.VirtualServerConfig; 32 import com.sun.appserv.management.deploy.DeploymentMgr; 33 import com.sun.appserv.management.deploy.DeploymentProgress; 34 import com.sun.appserv.management.deploy.DeploymentProgressImpl; 35 import com.sun.appserv.management.deploy.DeploymentSource; 36 import com.sun.appserv.management.deploy.DeploymentSupport; 37 import com.sun.enterprise.deployapi.ProgressObjectImpl; 38 import com.sun.enterprise.deployapi.SunTarget; 39 import com.sun.enterprise.deployapi.SunTargetModuleID; 40 import com.sun.enterprise.deployment.backend.DeploymentStatus; 41 import com.sun.enterprise.deployment.util.DeploymentProperties; 42 import com.sun.enterprise.util.i18n.StringManager; 43 44 import java.util.ArrayList ; 45 import java.util.Iterator ; 46 import java.util.Map ; 47 import java.util.Set ; 48 49 import javax.enterprise.deploy.shared.ModuleType ; 50 import javax.enterprise.deploy.shared.StateType ; 51 import javax.enterprise.deploy.spi.Target ; 52 import javax.enterprise.deploy.spi.TargetModuleID ; 53 54 public class UndeployAction extends ProgressObjectImpl { 55 56 private DeploymentMgr deplMgr = null; 57 private static StringManager localStrings = StringManager.getManager(UndeployAction.class); 58 59 public UndeployAction(SunTarget[] targets) { 60 super(targets); 61 } 62 63 public void run() { 64 ConnectionSource dasConnection= (ConnectionSource) args[0]; 65 String moduleID = (String ) args[1]; 66 Map deployOptions = (Map ) args[2]; 67 SunTarget[] targetList = (SunTarget[]) args[3]; 68 SunTarget domain = (SunTarget) args[4]; 69 boolean isLocalConnectionSource = ((Boolean ) args[5]).booleanValue(); 70 71 try { 72 if((DeploymentClientUtils.getModuleType(dasConnection.getExistingMBeanServerConnection(), moduleID) 74 == ModuleType.WAR) && 75 (isDefaultWebModule(domain, dasConnection, moduleID))) { 76 return; 77 } 78 deplMgr = ProxyFactory.getInstance(dasConnection).getDomainRoot().getDeploymentMgr(); 79 Map deployedTargets = DeploymentClientUtils.getDeployedTargetList(dasConnection, moduleID); 81 82 ArrayList resultTargetModuleIDs = new ArrayList (); 84 85 if (deployedTargets.size() > 0) { 87 if ((TargetType.DOMAIN.equals(targetList[0].getName()))) { 90 DeploymentFacility deploymentFacility; 91 if(isLocalConnectionSource) { 92 deploymentFacility = DeploymentFacilityFactory.getLocalDeploymentFacility(); 93 } else { 94 deploymentFacility = DeploymentFacilityFactory.getDeploymentFacility(); 95 } 96 deploymentFacility.connect( 97 targetList[0].getConnectionInfo()); 98 Set nameSet = deployedTargets.keySet(); 99 String [] targetNames = (String [])nameSet.toArray( 100 new String [nameSet.size()]); 101 Target[] targetList2 = 102 deploymentFacility.createTargets(targetNames); 103 if (targetList2 == null) { 104 setupForAbnormalExit(localStrings.getString("enterprise.deployment.client.createTargetsFailed"), domain); 105 return; 106 } 107 targetList = new SunTarget[targetList2.length]; 108 for (int ii = 0; ii < targetList2.length; ii++) { 109 targetList[ii] = (SunTarget)targetList2[ii]; 110 } 111 } 112 113 else if (!DeploymentClientUtils.isTargetListComplete(deployedTargets, targetList)) { 116 setupForAbnormalExit( 117 localStrings.getString("enterprise.deployment.client.specifyAllTargets", moduleID, "undeploy"), 118 domain); 119 return; 120 } 121 122 RollBackAction rollback = new RollBackAction(RollBackAction.DELETE_APP_REF_OPERATION, 124 moduleID, deployOptions); 125 deployOptions.put(DeploymentProperties.DEPLOY_OPTION_FORCE_KEY, "false"); 126 for(int i=0; i<targetList.length; i++) { 127 128 131 DeploymentClientUtils.setResourceOptions( 132 deployOptions, 133 DeploymentProperties.RES_UNDEPLOYMENT, 134 targetList[i].getName()); 135 DeploymentStatus stat = DeploymentClientUtils.stopApplication( 136 dasConnection.getExistingMBeanServerConnection(), 137 moduleID, targetList[i], deployOptions); 138 checkStatusAndAddStage(targetList[i], null, 139 localStrings.getString("enterprise.deployment.client.undeploy_stop", targetList[i].getName()), dasConnection, stat); 140 141 stat = DeploymentClientUtils.deleteApplicationReference( 142 dasConnection.getExistingMBeanServerConnection(), 143 moduleID, targetList[i], deployOptions); 144 if(!checkStatusAndAddStage(targetList[i], rollback, 145 localStrings.getString("enterprise.deployment.client.undeploy_remove_ref", targetList[i].getName()), dasConnection, stat)) { 146 return; 147 } 148 rollback.addTarget(targetList[i], RollBackAction.APP_REF_DELETED); 149 resultTargetModuleIDs.add(new SunTargetModuleID(moduleID, targetList[i])); 150 } 151 } 152 153 if ((TargetType.DOMAIN.equals(targetList[0].getName()))) { 155 DeploymentClientUtils.setResourceOptions( 156 deployOptions, 157 DeploymentProperties.RES_UNDEPLOYMENT, 158 targetList); 159 } else { 160 DeploymentClientUtils.setResourceOptions( 161 deployOptions, 162 DeploymentProperties.RES_NO_OP, 163 targetList); 164 } 165 166 fireProgressEvent(StateType.RUNNING, localStrings.getString("enterprise.deployment.client.undeploying"), domain); 168 Map undeployStatus = deplMgr.undeploy(moduleID, deployOptions); 169 170 com.sun.appserv.management.deploy.DeploymentStatus finalStatusFromMBean = 171 DeploymentSupport.mapToDeploymentStatus(undeployStatus); 172 DeploymentStatus tmp = DeploymentClientUtils.getDeploymentStatusFromAdminStatus(finalStatusFromMBean); 173 if(!checkStatusAndAddStage(domain, null, localStrings.getString("enterprise.deployment.client.undeploy_from_domain"), dasConnection, tmp)) { 174 return; 175 } 176 177 resultTargetModuleIDs.add(new SunTargetModuleID(moduleID, domain)); 179 180 this.targetModuleIDs = new TargetModuleID[resultTargetModuleIDs.size()]; 183 this.targetModuleIDs = 184 (TargetModuleID[])resultTargetModuleIDs.toArray(this.targetModuleIDs); 185 186 setupForNormalExit(localStrings.getString("enterprise.deployment.client.undeploy_application", moduleID), domain); 187 } catch (Throwable ioex) { 188 finalDeploymentStatus.setStageException(ioex); 189 setupForAbnormalExit(localStrings.getString("enterprise.deployment.client.undeploy_application_failed", ioex.getMessage()), domain); 190 return; 191 } 192 } 193 194 private boolean isDefaultWebModule(SunTarget domain, ConnectionSource dasConnection, String moduleID) { 195 try { 196 DomainConfig cfg = ProxyFactory.getInstance(dasConnection).getDomainRoot().getDomainConfig(); 197 Map cfgcfg = cfg.getConfigConfigMap(); 198 for(Iterator it1 = cfgcfg.keySet().iterator(); it1.hasNext(); ) { 199 ConfigConfig cf1 = (ConfigConfig) cfgcfg.get(it1.next()); 200 HTTPServiceConfig httpSvc = cf1.getHTTPServiceConfig(); 201 Map vsMap = httpSvc.getVirtualServerConfigMap(); 202 for(Iterator it2 = vsMap.keySet().iterator(); it2.hasNext(); ) { 203 VirtualServerConfig vs = (VirtualServerConfig) vsMap.get(it2.next()); 204 if(moduleID.equals(vs.getDefaultWebModule())) { 205 setupForAbnormalExit( 206 localStrings.getString("enterprise.deployment.client.def_web_module_refs_exist", moduleID), domain); 207 return true; 208 } 209 } 210 } 211 } catch (Throwable ioex) { 212 finalDeploymentStatus.setStageException(ioex); 213 setupForAbnormalExit(localStrings.getString("enterprise.deployment.client.undeploy_application_failed", ioex.getMessage()), domain); 214 return true; 215 } 216 return false; 217 } 218 } 219 | Popular Tags |