1 23 24 package com.sun.enterprise.tools.upgrade; 25 26 import java.util.*; 27 import java.io.*; 28 import java.util.logging.*; 29 30 import com.sun.enterprise.tools.upgrade.common.*; 31 import com.sun.enterprise.tools.upgrade.logging.*; 32 import com.sun.enterprise.cli.framework.*; 33 import com.sun.enterprise.util.i18n.StringManager; 34 import com.sun.enterprise.tools.upgrade.cluster.*; 35 36 public class UpgradeHarness { 37 private static Logger logger = LogService.getLogger(LogService.UPGRADE_LOGGER); 38 private StringManager stringManager = StringManager.getManager(LogService.UPGRADE_LOGGER); 39 private List moduleList; 40 private CommonInfoModel commonInfo; 41 42 public UpgradeHarness() { 43 moduleList = new LinkedList(); 44 } 45 public void setCommonInfoModel(CommonInfoModel commonInfo){ 46 this.commonInfo=commonInfo; 47 } 48 public void startUpgrade(){ 49 if(commonInfo.checkSourceInputAsDomainRoot(commonInfo.getSourceInstallDir())) 50 commonInfo.setSourceDomainRoot(commonInfo.getSourceInstallDir()); 51 loadModules(); 52 System.setProperty("com.sun.aas.configRoot", commonInfo.getTargetInstallDir() + File.separator + "config"); 53 try { 54 if(commonInfo.getSourceVersionAndEdition().equals(UpgradeConstants.VERSION_AS81_EE)){ 56 ClustersInfoManager.getClusterInfoManager().gatherClusterInfo(this.commonInfo); 57 } 58 DomainsProcessor dProcessor = new DomainsProcessor(this.commonInfo); 59 dProcessor.processTargetDomains(); 60 UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(30); 62 if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){ 64 if(!commonInfo.getSourceEdition().equals(UpgradeConstants.EDITION_PE)){ 65 if(commonInfo.getSourceEdition().equals(UpgradeConstants.EDITION_EE)){ 67 if(dProcessor.processClusters()){ 69 this.upgradeEESource(); 70 return; 71 }else{ 72 dProcessor.processDomainInstances(); 74 } 75 }else{ 76 dProcessor.processDomainInstances(); 78 } 79 }else{ 80 if((commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)) && (!commonInfo.getTargetEdition().equals(UpgradeConstants.EDITION_PE))){ 81 dProcessor.processDomainInstances(); 83 } 84 } 85 }else{ 86 if(commonInfo.getSourceEdition().equals(UpgradeConstants.EDITION_EE)){ 88 dProcessor.processClusters(); 90 } 91 } 92 }catch(HarnessException he) { 93 logger.log(Level.SEVERE,stringManager.getString("enterprise.tools.upgrade.generalException" ,he.getMessage())); 94 UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(-1); 95 return; 96 } 97 UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(50); 99 100 int totalIterations = this.getTotalIterationsFromDomainMapping(); 101 int currentIteration =0; 102 for(java.util.Iterator dItr = commonInfo.getDomainMapping().keySet().iterator(); dItr.hasNext();){ 103 DomainInfo dInfo = (DomainInfo)commonInfo.getDomainMapping().get(dItr.next()); 104 commonInfo.setCurrentDomain(dInfo.getDomainName()); 105 List instanceList = this.getProcessableInstanceList(dInfo); 106 logger.log(Level.INFO, stringManager.getString("enterprise.tools.upgrade.currentlyProcessingDomain",dInfo.getDomainName())); 107 for(int instIndex = 0; instIndex < instanceList.size(); instIndex++){ 108 currentIteration++; 109 String currentInstanceName = (String )instanceList.get(instIndex); 110 commonInfo.setCurrentSourceInstance(currentInstanceName); 111 logger.log(Level.INFO, stringManager.getString("enterprise.tools.upgrade.currentlyProcessingInstance",currentInstanceName)); 112 if(!invokeModules(currentIteration,totalIterations)) 113 return; 114 } 115 } 116 logger.log(Level.INFO, stringManager.getString("enterprise.tools.upgrade.finishedUpgrade")); 117 UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(100); 119 } 120 private int getTotalIterationsFromDomainMapping(){ 121 int totalIt = 1; 122 for(java.util.Iterator dItr = commonInfo.getDomainMapping().keySet().iterator(); dItr.hasNext();){ 123 DomainInfo dInfo = (DomainInfo)commonInfo.getDomainMapping().get(dItr.next()); 124 List instanceList = this.getProcessableInstanceList(dInfo); 125 totalIt += instanceList.size(); 126 } 127 return totalIt; 128 } 129 private boolean invokeModules(int currentIteration, int totalIterations){ 130 String moduleName = "Default"; 131 List successfulModuleList = new ArrayList(); 132 int moduleSize = moduleList.size(); 133 int nthModule = 0; 134 int progress =0 ; 135 for(int i=0; i<moduleSize; i++){ 136 nthModule++; 137 if(!UpdateProgressManager.getProgressManager().canContinueUpgrade()){ 138 logger.log(Level.SEVERE, stringManager.getString("enterprise.tools.upgrade.didNotfinishUpgrade", commonInfo.getTargetDomainRoot())); 142 UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(-1); 143 return false; 144 } 145 BaseModule baseModule = (BaseModule)this.moduleList.get(i); 147 moduleName = baseModule.getName(); 148 if(baseModule.upgrade(commonInfo)) 149 successfulModuleList.add(baseModule); 150 else { logger.log(Level.INFO,stringManager.getString("enterprise.tools.upgrade.module_upgrade_failed",moduleName)); 152 UpdateProgressManager.getProgressManager().setContinueUpgrade(false); 153 baseModule.recovery(commonInfo); 154 for(int k=0; k<successfulModuleList.size(); k++){ 155 BaseModule successModule = (BaseModule)successfulModuleList.get(k); 156 logger.log(Level.INFO,stringManager.getString("enterprise.tools.upgrade.module_rollback",successModule.getName(),commonInfo.getCurrentDomain())); 157 successModule.recovery(commonInfo); 158 } 159 } 160 logger.log(Level.INFO, stringManager.getString("enterprise.tools.upgrade.finishedModule")+moduleName); 161 int pFirst = (50 * currentIteration) / totalIterations ; 164 int pLast = (50/totalIterations) - (50*nthModule)/(moduleSize*totalIterations); 165 progress = 50 + pFirst - pLast; 166 UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(progress); 167 } 168 return true; 169 } 170 private void upgradeEESource(){ 171 int totalIterations = ClustersInfoManager.getClusterInfoManager().getClusterInfoList().size()+ 173 UpgradeUtils.getUpgradeUtils(commonInfo).getStandAloneInstances(commonInfo.getDomainMapping()).size()+1; 174 int currentIteration =0; 175 for(java.util.Iterator dItr = ClustersInfoManager.getClusterInfoManager().getClusterInfoList().iterator(); dItr.hasNext();){ 177 ClusterInfo cInfo = (ClusterInfo)dItr.next(); 178 ClusteredInstance clInstance = cInfo.getMasterInstance(); 179 if(clInstance == null){ 180 clInstance = (ClusteredInstance)cInfo.getClusteredInstanceList().get(0); 181 } 182 commonInfo.setCurrentCluster(cInfo.getClusterName()); 183 commonInfo.setCurrentDomain(clInstance.getDomain()); 184 commonInfo.setCurrentSourceInstance(clInstance.getInstanceName()); 185 currentIteration++; 186 logger.log(Level.INFO, stringManager.getString("enterprise.tools.upgrade.currentlyProcessingCLUSTER",cInfo.getClusterName())); 187 if(!invokeModules(currentIteration,totalIterations)) 188 return; 189 } 190 commonInfo.setCurrentCluster(null); 191 for(java.util.Iterator sItr = UpgradeUtils.getUpgradeUtils(commonInfo).getStandAloneInstances(commonInfo.getDomainMapping()).iterator(); sItr.hasNext();){ 193 Vector instDInfo = (Vector)sItr.next(); 194 commonInfo.setCurrentDomain(((DomainInfo)instDInfo.elementAt(1)).getDomainName()); 195 commonInfo.setCurrentSourceInstance((String )instDInfo.elementAt(0)); 196 currentIteration++; 197 logger.log(Level.INFO, stringManager.getString("enterprise.tools.upgrade.currentlyProcessingInstance",(String )instDInfo.elementAt(0))); 198 if(!invokeModules(currentIteration,totalIterations)) 199 return; 200 } 201 this.updateMiscellaneousClusterInfo(); 203 logger.log(Level.INFO, stringManager.getString("enterprise.tools.upgrade.finishedUpgrade")); 204 UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(100); 206 } 207 private void updateMiscellaneousClusterInfo(){ 208 Hashtable iiopMapping = ClustersInfoManager.getClusterInfoManager().getIIOPClustersMapping(); 210 if(iiopMapping != null){ 211 for(Iterator it = iiopMapping.keySet().iterator(); it.hasNext();){ 212 String domainName = (String )it.next(); 213 List iCls = (List)iiopMapping.get(domainName); 214 String domainXMLfile = this.commonInfo.getDestinationDomainPath(domainName)+File.separator+"config"+File.separator+"domain.xml"; 215 for(int i=0; i<iCls.size(); i++){ 216 IIOPCluster iiopCluster = (IIOPCluster)iCls.get(i); 217 UpgradeUtils.getUpgradeUtils(this.commonInfo).updateDomainXMLWithIIOPCluster(this.commonInfo, domainXMLfile, iiopCluster); 218 } 219 } 220 } 221 Hashtable persistenceStoreMapping = ClustersInfoManager.getClusterInfoManager().getPersistenceStorePropertiesMapping(); 223 if(persistenceStoreMapping != null){ 224 for(Iterator pit = persistenceStoreMapping.keySet().iterator(); pit.hasNext();){ 225 String domainName = (String )pit.next(); 226 java.util.Properties props = (java.util.Properties )persistenceStoreMapping.get(domainName); 227 String domainXMLfile = this.commonInfo.getDestinationDomainPath(domainName)+File.separator+"domain.xml"; 228 UpgradeUtils.getUpgradeUtils(this.commonInfo).updateDomainXMLWithPersistenceStoreProps(props); 229 } 230 } 231 } 232 private List getProcessableInstanceList(DomainInfo dInfo){ 233 List instanceList = new ArrayList(); 234 List domainInstanceList = dInfo.getInstanceNames(); 235 if(commonInfo.getSourceVersionAndEdition().equals(UpgradeConstants.VERSION_AS80_PE)|| 236 commonInfo.getSourceVersionAndEdition().equals(UpgradeConstants.VERSION_AS81_PE) || 237 commonInfo.getSourceVersionAndEdition().equals(UpgradeConstants.VERSION_AS80_SE) || 238 commonInfo.getSourceVersionAndEdition().equals(UpgradeConstants.VERSION_AS81_EE) || 239 commonInfo.getSourceVersionAndEdition().equals(UpgradeConstants.VERSION_AS90_PE)){ 240 instanceList.add(new String ("")); 241 return instanceList; 242 } 243 for(int i=0; i<domainInstanceList.size(); i++){ 244 String instanceName = (String )domainInstanceList.get(i); 245 if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){ 246 if(instanceName.equals("admin-server")) 248 continue; 249 instanceList.add(instanceName); 250 if(commonInfo.getSourceEdition().equals(UpgradeConstants.EDITION_PE)){ 251 if (domainInstanceList.size() > 2) { 253 logger.log(Level.INFO,stringManager.getString("enterprise.tools.upgrade.more_thanone_instance",instanceName)); 254 } 255 break; 256 } 257 } 258 } 259 if(instanceList.isEmpty()) 260 logger.log(Level.WARNING, stringManager.getString("enterprise.tools.upgrade.no_server_instance", dInfo.getDomainName())); 261 return instanceList; 262 } 263 private void loadModules(){ 264 List list = CommonProperties.getRegisteredModules(commonInfo); 265 int size = list.size(); 266 for(int i=0; i<size; i++){ 267 String moduleClassName = (String )list.get(i); 268 try{ 269 Class cls = Class.forName(moduleClassName); 270 BaseModule baseModule = (BaseModule)cls.newInstance(); 271 moduleList.add(baseModule); 272 }catch(ClassNotFoundException e){ 273 logger.log(Level.SEVERE,stringManager.getString("enterprise.tools.upgrade.load_instantiate_error", e.getMessage()),e); 274 }catch(InstantiationException e){ 275 logger.log(Level.SEVERE,stringManager.getString("enterprise.tools.upgrade.load_instantiate_error", e.getMessage()),e); 276 }catch(IllegalAccessException e){ 277 logger.log(Level.SEVERE,stringManager.getString("enterprise.tools.upgrade.load_instantiate_error", e.getMessage()),e); 278 } 279 } 280 } 281 } 282 | Popular Tags |