1 4 package com.tcsimulator; 5 6 import com.tc.object.config.ConfigVisitor; 7 import com.tc.object.config.DSOApplicationConfig; 8 import com.tc.simulator.app.ApplicationConfig; 9 import com.tcsimulator.distrunner.ServerSpec; 10 11 import java.util.ArrayList ; 12 import java.util.Collection ; 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 import java.util.Map ; 17 18 public class TestSpec { 19 private ApplicationConfigImpl appConfig; 22 private Map containerSpecsByHostname; 23 private Map containerSpecsByVmName; 24 private int globalVmCount; 25 private Map serverSpecsByHostName; 26 private Map serverSpecsByType; 27 28 public static void visitDSOApplicationConfig(ConfigVisitor visitor, DSOApplicationConfig config) { 29 String classname = TestSpec.class.getName(); 30 config.addIncludePattern(classname); 31 config.addIncludePattern(ContainerSpec.class.getName()); 32 config.addWriteAutolock("* " + classname + ".*(..)"); 33 visitor.visitDSOApplicationConfig(config, ApplicationConfigImpl.class); 34 } 35 36 public TestSpec(String className, int intensity, Collection cSpecs, Collection sSpecs) { 37 containerSpecsByHostname = new HashMap (); 38 containerSpecsByVmName = new HashMap (); 39 serverSpecsByHostName = new HashMap (); 40 serverSpecsByType = new HashMap (); 41 GlobalVmNameGenerator vmNameGenerator = new GlobalVmNameGenerator(); 42 int globalParticipantCount = 0; 43 44 for (Iterator i = cSpecs.iterator(); i.hasNext();) { 45 ClientSpec cSpec = (ClientSpec) i.next(); 46 String hostName = cSpec.getHostName(); 47 48 int vmCount = cSpec.getVMCount(); 49 globalVmCount += vmCount; 50 int executionCount = cSpec.getExecutionCount(); 51 List jvmArgs = cSpec.getJvmOpts(); 52 globalParticipantCount += (vmCount * executionCount); 53 54 Collection specList = (Collection ) containerSpecsByHostname.get(hostName); 55 if (specList == null) { 56 specList = new ArrayList (); 57 this.containerSpecsByHostname.put(hostName, specList); 58 } 59 60 for (int j = 0; j < vmCount; j++) { 61 String vmName = vmNameGenerator.nextVmName(); 62 ContainerSpec newSpec = new ContainerSpec(vmName, cSpec.getTestHome(), executionCount, jvmArgs); 63 specList.add(newSpec); 64 containerSpecsByVmName.put(vmName, newSpec); 65 } 66 } 67 68 for (Iterator i = sSpecs.iterator(); i.hasNext();) { 69 ServerSpec sSpec = (ServerSpec) i.next(); 70 String hostName = sSpec.getHostName(); 71 int type = sSpec.getType(); 72 73 Collection specList = (Collection ) serverSpecsByHostName.get(hostName); 74 if (specList == null) { 75 specList = new ArrayList (); 76 this.serverSpecsByHostName.put(hostName, specList); 77 } 78 specList.add(sSpec); 79 80 specList = (Collection ) serverSpecsByType.get(new Integer (type)); 81 if (specList == null) { 82 specList = new ArrayList (); 83 this.serverSpecsByType.put(new Integer (type), specList); 84 } 85 specList.add(sSpec); 86 } 87 88 this.appConfig = new ApplicationConfigImpl(className, intensity, globalParticipantCount); 89 } 90 91 public TestSpec() { 92 } 94 95 public synchronized ApplicationConfig getTestConfig() { 96 return appConfig.copy(); 97 } 98 99 public Collection getContainerSpecsFor(String hostname) { 100 Collection rv = new ArrayList (); 101 Collection containerSpecsByHostName = (Collection ) containerSpecsByHostname.get(hostname); 102 if (containerSpecsByHostName != null) { 103 for (Iterator i = ((Collection ) containerSpecsByHostname.get(hostname)).iterator(); i.hasNext();) { 104 rv.add(((ContainerSpec) i.next()).copy()); 105 } 106 } 107 return rv; 108 } 109 110 public Collection getServerSpecsFor(String hostname) { 111 Collection rv = new ArrayList (); 112 Collection serverSpecs = (Collection ) serverSpecsByHostName.get(hostname); 113 if (serverSpecs != null) { 114 for (Iterator i = serverSpecs.iterator(); i.hasNext();) { 115 rv.add(((ServerSpec) i.next()).copy()); 116 } 117 } 118 return rv; 119 } 120 121 public Collection getServerSpecsFor(int type) { 122 Collection rv = new ArrayList (); 123 Collection serverSpecs = (Collection ) serverSpecsByType.get(new Integer (type)); 124 if (serverSpecs != null) { 125 for (Iterator i = serverSpecs.iterator(); i.hasNext();) { 126 rv.add(((ServerSpec) i.next()).copy()); 127 } 128 } 129 return rv; 130 } 131 132 public ContainerSpec getContainerSpecFor(String vmName) { 133 return ((ContainerSpec) containerSpecsByVmName.get(vmName)).copy(); 134 } 135 136 public synchronized int getGlobalVmCount() { 137 return globalVmCount; 138 } 139 140 public long getAppExecutionTimeout() { 141 return 1000 * 60 * 24 * 365 * 10; 142 } 143 144 public synchronized String toString() { 145 StringBuffer result = new StringBuffer (); 146 result.append(getClass().getName() + " [containerSpecsByVmName: "); 147 result.append(containerSpecsByVmName); 148 result.append(", containerSpecsByHostname: "); 149 result.append(containerSpecsByHostname); 150 result.append(", globalVmCount: "); 151 result.append(globalVmCount + "]"); 152 return result.toString(); 153 } 154 155 } 156 | Popular Tags |