00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.runtime;
00032
00033 import java.io.File;
00034 import java.io.IOException;
00035 import java.net.URL;
00036
00037 import org.apache.log4j.Logger;
00038 import org.apache.log4j.PropertyConfigurator;
00039 import org.objectweb.proactive.ProActive;
00040 import org.objectweb.proactive.core.ProActiveException;
00041 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00042 import org.objectweb.proactive.core.process.ExternalProcess;
00043 import org.objectweb.proactive.core.process.JVMProcess;
00044 import org.objectweb.proactive.core.util.UrlBuilder;
00045 import org.objectweb.proactive.core.util.log.Loggers;
00046 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00047
00048
00058 public class StartHierarchical {
00059 static Logger logger = ProActiveLogger.getLogger(Loggers.RUNTIME);
00060 protected String nodeURL;
00061 protected String creatorID;
00062 protected String defaultRuntimeURL;
00063 protected String sNodeNumber;
00064 protected int nodeNumber;
00065 protected String protocolId;
00066 protected String vmName;
00067 protected String padURL;
00068 protected ProActiveRuntime proActiveRuntime;
00069
00070 protected StartHierarchical() {
00071 }
00072
00073 private StartHierarchical(String[] args) {
00074 if (args.length != 0) {
00075 this.nodeURL = args[0];
00076 this.creatorID = args[0].trim();
00077 this.defaultRuntimeURL = UrlBuilder.removeUsername(args[1]);
00078 this.sNodeNumber = args[2];
00079 this.nodeNumber = (new Integer(sNodeNumber)).intValue();
00080 this.protocolId = args[3];
00081 this.vmName = args[4];
00082 }
00083 }
00084
00085 public static void main(String[] args) {
00086
00087
00088 System.setProperty("proactive.hierarchicalRuntime", "true");
00089
00090
00091 if ("true".equals(System.getProperty("log4j.defaultInitOverride")) &&
00092 (System.getProperty("log4j.configuration") != null)) {
00093
00094 try {
00095 String log4jConfiguration = System.getProperty(
00096 "log4j.configuration");
00097 File f = new File(log4jConfiguration);
00098 PropertyConfigurator.configure(new URL(f.getPath()));
00099 } catch (IOException e) {
00100 System.out.println(
00101 "Error : incorrect path for log4j configuration : " +
00102 System.getProperty("log4j.configuration"));
00103 }
00104 }
00105
00106 ProActiveConfiguration.load();
00107
00108 try {
00109 logger.info("**** Starting hierarchical jvm on " +
00110 UrlBuilder.getHostNameorIP(java.net.InetAddress.getLocalHost()));
00111
00112 if (logger.isDebugEnabled()) {
00113 logger.debug("**** Starting jvm with classpath " +
00114 System.getProperty("java.class.path"));
00115 logger.debug("**** with bootclasspath " +
00116 System.getProperty("sun.boot.class.path"));
00117 }
00118 } catch (java.net.UnknownHostException e) {
00119 e.printStackTrace();
00120 }
00121
00122 new StartHierarchical(args).run();
00123 }
00124
00125 private void run() {
00126 padURL = System.getProperty("proactive.pad");
00127
00128 ProActiveRuntimeImpl impl = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime();
00129 impl.getVMInformation().setCreationProtocolID(protocolId);
00130
00131 try {
00132 proActiveRuntime = RuntimeFactory.getProtocolSpecificRuntime(System.getProperty(
00133 "proactive.communication.protocol") + ":");
00134 proActiveRuntime.getVMInformation().setCreationProtocolID(protocolId);
00135
00136 LocalProActiveRuntime localPart = (LocalProActiveRuntime) ProActiveRuntimeImpl.getProActiveRuntime();
00137
00138 ProActiveRuntime PART = RuntimeFactory.getRuntime(defaultRuntimeURL,
00139 UrlBuilder.getProtocol(defaultRuntimeURL));
00140 localPart.setParent(PART);
00141
00142
00143 ExternalProcess process = PART.getProcessToDeploy(proActiveRuntime,
00144 creatorID, vmName, padURL);
00145
00146 if (process == null) {
00147 logger.info("getProcessToDeploy failed. Aborting");
00148 System.exit(0);
00149 }
00150
00151 ((ProActiveRuntimeForwarderImpl) ProActiveRuntimeImpl.getProActiveRuntime()).setProcessesToDeploy(padURL,
00152 vmName, process);
00153
00154 try {
00155 setParameters(process);
00156 process.startProcess();
00157 } catch (IOException e) {
00158 logger.info("process starting failed: " + e.getMessage());
00159 System.exit(0);
00160 }
00161 } catch (ProActiveException e) {
00162 e.printStackTrace();
00163
00164
00165 System.exit(0);
00166 }
00167 }
00168
00169 private void setParameters(ExternalProcess process) {
00170 String localruntimeURL = null;
00171
00172 try {
00173 localruntimeURL = RuntimeFactory.getDefaultRuntime().getURL();
00174 } catch (ProActiveException e) {
00175 e.printStackTrace();
00176 }
00177
00178 JVMProcess jvmProcess = (JVMProcess) process.getFinalProcess();
00179
00180 jvmProcess.setJvmOptions("-Dproactive.jobid=" + ProActive.getJobId());
00181 jvmProcess.setParameters(creatorID + " " + localruntimeURL + " " +
00182 nodeNumber + " " + protocolId + " " + vmName);
00183 }
00184 }