KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > UpgradeHarness


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

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             //new DomainsProcessor(this.commonInfo,false);
55
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             // If domains are created then 50% done
61
UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(30);
62             // This if statement is added for AS9.0 uprade scenario form source AS8.x
63
if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){
64                 if(!commonInfo.getSourceEdition().equals(UpgradeConstants.EDITION_PE)){
65                     // This need to be done only for SE and EE.
66
if(commonInfo.getSourceEdition().equals(UpgradeConstants.EDITION_EE)){
67                         // Its EE, process clusters.
68
if(dProcessor.processClusters()){
69                             this.upgradeEESource();
70                             return;
71                         }else{
72                             // No clinstance files are provided, so just create stand alone instances.
73
dProcessor.processDomainInstances();
74                         }
75                     }else{
76                         // Its SE. need to process only instances, no clusters
77
dProcessor.processDomainInstances();
78                     }
79                 }else{
80                     if((commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)) && (!commonInfo.getTargetEdition().equals(UpgradeConstants.EDITION_PE))){
81                         // In this case AS7.x has server1. Will crete server1 instance in AS8.1 SE/EE
82
dProcessor.processDomainInstances();
83                     }
84                 }
85             }else{
86                 // Now its AS8.x to AS 9.0 upgrade.
87
if(commonInfo.getSourceEdition().equals(UpgradeConstants.EDITION_EE)){
88                     // Its EE, process clusters.
89
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         // If domains are processed then 50% done
98
UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(50);
99         
100         int totalIterations = this.getTotalIterationsFromDomainMapping();
101         int currentIteration =0;
102         for(java.util.Iterator JavaDoc 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 JavaDoc currentInstanceName = (String JavaDoc)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         //logger.log(Level.CONFIG, Integer.toString(100));
118
UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(100);
119     }
120     private int getTotalIterationsFromDomainMapping(){
121         int totalIt = 1;
122         for(java.util.Iterator JavaDoc 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 JavaDoc 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                 // If any of the module failed to complete, would have updated this status.
139
// In that case should not proceed further. Should exit out of upgrade.
140
// This would be a good place for rollback ..... TBD
141
logger.log(Level.SEVERE, stringManager.getString("enterprise.tools.upgrade.didNotfinishUpgrade", commonInfo.getTargetDomainRoot()));
142                 UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(-1);
143                 return false;
144             }
145             //logger.log(Level.FINE, "processing module :"+moduleName);
146
BaseModule baseModule = (BaseModule)this.moduleList.get(i);
147             moduleName = baseModule.getName();
148             if(baseModule.upgrade(commonInfo))
149                 successfulModuleList.add(baseModule);
150             else { // Rollback all previous successful operations.
151
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             //logger.log(Level.CONFIG, Integer.toString((nthModule/size)*100));
162
//progress = 50 + (((currentIteration * 50)/totalIterations) - ((50-(50*nthModule)/moduleSize)));
163
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         // Add 1 for post updateMiscellaneousClusterInfo
172
int totalIterations = ClustersInfoManager.getClusterInfoManager().getClusterInfoList().size()+
173                                 UpgradeUtils.getUpgradeUtils(commonInfo).getStandAloneInstances(commonInfo.getDomainMapping()).size()+1;
174         int currentIteration =0;
175         // Start with upgrading clustered instances
176
for(java.util.Iterator JavaDoc 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         // now upgrade stand alone instances
192
for(java.util.Iterator JavaDoc 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 JavaDoc)instDInfo.elementAt(0));
196             currentIteration++;
197             logger.log(Level.INFO, stringManager.getString("enterprise.tools.upgrade.currentlyProcessingInstance",(String JavaDoc)instDInfo.elementAt(0)));
198             if(!invokeModules(currentIteration,totalIterations))
199                 return;
200         }
201         // Migrate iiop-cluster info saved in clustered info manager.
202
this.updateMiscellaneousClusterInfo();
203         logger.log(Level.INFO, stringManager.getString("enterprise.tools.upgrade.finishedUpgrade"));
204         //logger.log(Level.CONFIG, Integer.toString(100));
205
UpdateProgressManager.getProgressManager().processUpgradeUpdateEvent(100);
206     }
207     private void updateMiscellaneousClusterInfo(){
208         // Get IIOPClusters from clusterinfo manager and process them
209
Hashtable iiopMapping = ClustersInfoManager.getClusterInfoManager().getIIOPClustersMapping();
210         if(iiopMapping != null){
211             for(Iterator it = iiopMapping.keySet().iterator(); it.hasNext();){
212                 String JavaDoc domainName = (String JavaDoc)it.next();
213                 List iCls = (List)iiopMapping.get(domainName);
214                 String JavaDoc 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         // Get PersistenceStore info from cluster info manager and process them
222
Hashtable persistenceStoreMapping = ClustersInfoManager.getClusterInfoManager().getPersistenceStorePropertiesMapping();
223         if(persistenceStoreMapping != null){
224             for(Iterator pit = persistenceStoreMapping.keySet().iterator(); pit.hasNext();){
225                 String JavaDoc domainName = (String JavaDoc)pit.next();
226                 java.util.Properties JavaDoc props = (java.util.Properties JavaDoc)persistenceStoreMapping.get(domainName);
227                 String JavaDoc 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 JavaDoc(""));
241             return instanceList;
242         }
243         for(int i=0; i<domainInstanceList.size(); i++){
244             String JavaDoc instanceName = (String JavaDoc)domainInstanceList.get(i);
245             if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){
246                 // For 7x remove admin server from the list
247
if(instanceName.equals("admin-server"))
248                     continue;
249                 instanceList.add(instanceName);
250                 if(commonInfo.getSourceEdition().equals(UpgradeConstants.EDITION_PE)){
251                     // IF PE only return the first element fromt he list
252
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 JavaDoc moduleClassName = (String JavaDoc)list.get(i);
268             try{
269                 Class JavaDoc cls = Class.forName(moduleClassName);
270                 BaseModule baseModule = (BaseModule)cls.newInstance();
271                 moduleList.add(baseModule);
272             }catch(ClassNotFoundException JavaDoc e){
273                 logger.log(Level.SEVERE,stringManager.getString("enterprise.tools.upgrade.load_instantiate_error", e.getMessage()),e);
274             }catch(InstantiationException JavaDoc e){
275                 logger.log(Level.SEVERE,stringManager.getString("enterprise.tools.upgrade.load_instantiate_error", e.getMessage()),e);
276             }catch(IllegalAccessException JavaDoc e){
277                 logger.log(Level.SEVERE,stringManager.getString("enterprise.tools.upgrade.load_instantiate_error", e.getMessage()),e);
278             }
279         }
280     }
281 }
282
Popular Tags