1 23 24 29 30 package com.sun.enterprise.tools.upgrade.cluster; 31 32 36 37 40 41 import java.util.*; 42 import java.io.*; 43 44 public class ClusterInfo { 45 46 private String clusterName; 49 private List clusteredInstanceList; 50 private String domainName; 52 private static java.util.logging.Logger log = com.sun.enterprise.tools.upgrade.common.CommonInfoModel.getDefaultLogger(); 53 54 public ClusterInfo(){ 55 } 56 public List getClusteredInstanceList(){ 57 return this.clusteredInstanceList; 58 } 59 public void parseClinstanceConfFile(File file) throws FileNotFoundException, IOException{ 60 if(clusteredInstanceList == null){ 61 clusteredInstanceList = new ArrayList(); 62 } 63 clusteredInstanceList.clear(); 64 BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); 65 String line = null; 66 ClusteredInstance clInstance = null; 67 while((line = reader.readLine()) != null){ 68 if(line.trim().startsWith("#")){ 69 continue; 71 } 72 if(line.trim().startsWith("instancename")){ 73 String instanceName = line.substring("instancename".length()).trim(); 74 clInstance = createNewInstance(instanceName); 75 continue; 76 } 77 if(clInstance != null) 78 clInstance.extractDataFromLine(line); 79 } 80 } 81 private ClusteredInstance createNewInstance(String instanceName){ 82 ClusteredInstance clInstance = new ClusteredInstance(instanceName); 83 clusteredInstanceList.add(clInstance); 84 return clInstance; 85 } 86 public ClusteredInstance getMasterInstance(){ 87 ClusteredInstance clInstance = null; 88 for(Iterator it = this.clusteredInstanceList.iterator(); it.hasNext();){ 89 clInstance = (ClusteredInstance)it.next(); 90 if(clInstance.isMaster()) 91 return clInstance; 92 } 93 return null; 94 } 95 public String getDomainName(){ 96 if(this.domainName == null){ 97 ClusteredInstance clInstance = this.getMasterInstance(); 98 if((clInstance == null) && (this.clusteredInstanceList.size() > 0)){ 99 clInstance = (ClusteredInstance)this.clusteredInstanceList.get(0); 100 } 101 this.domainName = clInstance.getDomain(); 102 return clInstance.getDomain(); 103 } 104 return this.domainName; 105 } 106 public void setDomainName(String dName){ 107 this.domainName = dName; 108 } 109 public String getClusterName(){ 110 return this.clusterName; 111 } 112 public void setClusterName(String clName){ 113 this.clusterName = clName; 114 } 115 public void print(){ 116 if(clusteredInstanceList != null){ 117 for(Iterator it = clusteredInstanceList.iterator(); it.hasNext();){ 118 ClusteredInstance clInst = (ClusteredInstance)it.next(); 119 log.info(clInst.getInstanceName()); 120 log.info(clInst.getUser()); 121 log.info(clInst.getHost()); 122 log.info(clInst.getPort()); 123 log.info(clInst.getDomain()); 124 log.info(clInst.getInstancePort()); 125 log.info(String.valueOf(clInst.isMaster())); 126 log.info("\n"); 127 } 128 } 129 } 130 } 131 | Popular Tags |