1 23 24 29 30 package com.sun.enterprise.tools.upgrade.cluster; 31 32 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 46 47 public class ClustersInfoManager { 48 49 private static ClustersInfoManager clusterManager; 50 private List clusterInfoList; 51 52 private Hashtable iiopClustersMapping; 54 55 private Hashtable persistenceStoreMapping; 57 58 private LBInfo loadBalancerInfo; 60 61 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 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 )it.next())); 89 }catch(FileNotFoundException fne){ 90 fne.printStackTrace(); 91 }catch(Exception ex){ 93 ex.printStackTrace(); 94 return false; 95 } 96 } 97 return true; 98 } 99 public void gatherClusterInfo(CommonInfoModel commonInfo){ 101 if(clusterInfoList == null) 102 clusterInfoList = new ArrayList(); 103 clusterInfoList.clear(); 104 for(java.util.Iterator dItr = commonInfo.getDomainMapping().keySet().iterator(); dItr.hasNext();){ 105 DomainInfo dInfo = (DomainInfo)commonInfo.getDomainMapping().get(dItr.next()); 106 String domainName = dInfo.getDomainName(); 107 String 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 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 domainName, String clusterName){ 125 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 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 domainName, String 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 domainName, String name, String 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 180 public static void main(String [] 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 |