KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > cluster > ClustersInfoManager


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 /*
25  * ClustersInfoManager.java
26  *
27  * Created on May 21, 2004, 3:02 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.cluster;
31
32 /**
33  *
34  * @author prakash
35  */

36 import java.io.*;
37 import java.util.*;
38 import com.sun.enterprise.tools.upgrade.common.CommonInfoModel;
39 import com.sun.enterprise.tools.upgrade.common.DomainInfo;
40 import com.sun.enterprise.tools.upgrade.common.UpgradeUtils;
41
42 /*
43  * This class manages multpile clinstance conf files represented by cluster info.
44  * Processes cluster files and stores the list.
45  */

46
47 public class ClustersInfoManager {
48     
49     private static ClustersInfoManager clusterManager;
50     private List clusterInfoList;
51     
52     // This table maintains domain name as key and List of IIOPClusters defined in server.xml as the value.
53
private Hashtable iiopClustersMapping;
54     
55     // This table maintains persistenceStoreProperties for each domain
56
private Hashtable persistenceStoreMapping;
57     
58     // Class representing Loadbalancer.conf file.
59
private LBInfo loadBalancerInfo;
60     
61     /** Creates a new instance of ClustersInfoManager */
62     public ClustersInfoManager() {
63     }
64     public static ClustersInfoManager getClusterInfoManager(){
65         if(clusterManager == null)
66             clusterManager = new ClustersInfoManager();
67         return clusterManager;
68     }
69     public ClusterInfo parseClinstanceConfFile(String JavaDoc fileName)throws FileNotFoundException, IOException{
70         return this.parseClinstanceConfFile(new File(fileName));
71     }
72     public ClusterInfo parseClinstanceConfFile(File file) throws FileNotFoundException, IOException{
73         if(!file.exists())
74             throw new FileNotFoundException();
75         ClusterInfo clInfo = new ClusterInfo();
76         clInfo.parseClinstanceConfFile(file);
77         return clInfo;
78     }
79     public List getClusterInfoList(){
80         return this.clusterInfoList;
81     }
82     public boolean processClinstanceConfFiles(List clinstanceConfFiles){
83         if(clusterInfoList == null)
84             clusterInfoList = new ArrayList();
85         clusterInfoList.clear();
86         for(Iterator it = clinstanceConfFiles.iterator(); it.hasNext();){
87             try{
88                 clusterInfoList.add(this.parseClinstanceConfFile((String JavaDoc)it.next()));
89             }catch(FileNotFoundException fne){
90                 fne.printStackTrace();
91                 // if file is not found, that cluster is not added to the list. Continue processing other cluster files
92
}catch(Exception JavaDoc ex){
93                 ex.printStackTrace();
94                 return false;
95             }
96         }
97         return true;
98     }
99     // This is for AS8.x to AS90 cluster upgrade
100
public void gatherClusterInfo(CommonInfoModel commonInfo){
101         if(clusterInfoList == null)
102             clusterInfoList = new ArrayList();
103         clusterInfoList.clear();
104         for(java.util.Iterator JavaDoc dItr = commonInfo.getDomainMapping().keySet().iterator(); dItr.hasNext();){
105             DomainInfo dInfo = (DomainInfo)commonInfo.getDomainMapping().get(dItr.next());
106             String JavaDoc domainName = dInfo.getDomainName();
107             String JavaDoc domainXmlFile = dInfo.getDomainPath()+File.separator+"config"+File.separator+"domain.xml";
108             UpgradeUtils.getUpgradeUtils(commonInfo).updateClusterList(domainXmlFile,domainName,clusterInfoList);
109         }
110     }
111     public LBInfo getLoadBalancerInfo(){
112         return this.loadBalancerInfo;
113     }
114     public boolean processLoadBalancerFile(String JavaDoc fileName){
115         if(this.loadBalancerInfo == null)
116             this.loadBalancerInfo = new LBInfo();
117         if(! new File(fileName).exists())
118             return false;
119         return this.loadBalancerInfo.processLoadBalancerFile(fileName);
120     }
121     public Hashtable getIIOPClustersMapping(){
122         return this.iiopClustersMapping;
123     }
124     public IIOPCluster getIIOPCluster(String JavaDoc domainName, String JavaDoc clusterName){
125         // If IIOPCluster for the domain not created, create one.
126
// Domain name is the target domain name
127
if(this.iiopClustersMapping == null)
128             this.iiopClustersMapping = new Hashtable();
129         List clList = (List)this.iiopClustersMapping.get(domainName);
130         IIOPCluster iiopCluster = null;
131         if((clList != null) && (!clList.isEmpty())){
132             for(Iterator iIt = clList.iterator(); iIt.hasNext();){
133                 java.lang.Object JavaDoc iiopClusterObject = iIt.next();
134                 IIOPCluster iCluster = (IIOPCluster)iiopClusterObject;
135                 if(iCluster.getClusterName().equals(clusterName)){
136                     iiopCluster = iCluster;
137                     break;
138                 }
139             }
140         }else{
141             clList = new ArrayList();
142         }
143         if(iiopCluster == null){
144             iiopCluster = new IIOPCluster(clusterName);
145             clList.add(iiopCluster);
146             this.iiopClustersMapping.put(domainName,clList);
147         }
148         return iiopCluster;
149     }
150     public boolean isIIOPClusterExists(String JavaDoc domainName, String JavaDoc clusterName){
151         if(this.iiopClustersMapping == null)
152             return false;
153         List clList = (List)this.iiopClustersMapping.get(domainName);
154         if((clList == null) && (clList.isEmpty())){
155             return false;
156         }
157         for(Iterator iIt = clList.iterator(); iIt.hasNext();){
158             if(((IIOPCluster)iIt.next()).getClusterName().equals(clusterName)){
159                 return true;
160             }
161         }
162         return false;
163     }
164     public Hashtable getPersistenceStorePropertiesMapping(){
165         return this.persistenceStoreMapping;
166     }
167     public void addPersistenceStoreProperty(String JavaDoc domainName, String JavaDoc name, String JavaDoc value){
168         if(this.persistenceStoreMapping == null){
169             persistenceStoreMapping = new Hashtable();
170         }
171         Properties propsList = (Properties)this.persistenceStoreMapping.get(domainName);
172         if(propsList == null)
173             propsList = new Properties();
174         propsList.setProperty(name,value);
175         this.persistenceStoreMapping.put(domainName,propsList);
176     }
177     /**
178      * @param args the command line arguments
179      */

180     public static void main(String JavaDoc[] args) {
181         List aList = new ArrayList();
182         aList.add("c:\\temp\\clinstance.conf");
183         aList.add("c:\\temp\\clinstance.conf");
184         ClustersInfoManager cIM = ClustersInfoManager.getClusterInfoManager();
185         cIM.processClinstanceConfFiles(aList);
186         cIM.print();
187         
188     }
189     public void print(){
190         if(clusterInfoList != null){
191             for(Iterator it = clusterInfoList.iterator(); it.hasNext();){
192                 ClusterInfo clInfo = (ClusterInfo)it.next();
193                 com.sun.enterprise.tools.upgrade.common.CommonInfoModel.getDefaultLogger().info("\n\n\n *****************");
194                 clInfo.print();
195             }
196         }
197     }
198 }
199
Popular Tags