@Override public void onReceive(Object message) throws Exception { if (message instanceof EtlJobMessage) { EtlJobMessage msg = (EtlJobMessage) message; try { Properties props = EtlJobPropertyDao.getJobProperties(msg.getEtlJobName(), msg.getRefId()); Properties whProps = EtlJobPropertyDao.getWherehowsProperties(); props.putAll(whProps); EtlJobDao.startRun(msg.getWhEtlExecId(), "Job started!"); // start a new process here String cmd = CmdUtil.generateCMD( msg.getEtlJobName(), msg.getRefId(), msg.getWhEtlExecId(), props, msg.getCmdParam()); // Logger.debug("run command : " + cmd); process = Runtime.getRuntime().exec(cmd); // wait until this process finished. int execResult = process.waitFor(); // if the process failed, log the error and throw exception if (execResult > 0) { BufferedReader br = new BufferedReader(new InputStreamReader(process.getErrorStream())); String errString = "Error Details:\n"; String line; while ((line = br.readLine()) != null) errString = errString.concat(line).concat("\n"); Logger.error("*** Process + " + getPid(process) + " failed, status: " + execResult); Logger.error(errString); throw new Exception("Process + " + getPid(process) + " failed"); } EtlJobDao.endRun(msg.getWhEtlExecId(), EtlJobStatus.SUCCEEDED, "Job succeed!"); Logger.info("ETL job {} finished", msg.toDebugString()); if (msg.getEtlJobName().affectDataset()) { ActorRegistry.treeBuilderActor.tell("dataset", getSelf()); } if (msg.getEtlJobName().affectFlow()) { ActorRegistry.treeBuilderActor.tell("flow", getSelf()); } } catch (Throwable e) { // catch all throwable at the highest level. Logger.error("ETL job {} got a problem", msg.toDebugString()); if (process.isAlive()) { process.destroy(); } EtlJobDao.endRun(msg.getWhEtlExecId(), EtlJobStatus.ERROR, e.getMessage()); } } }
public void runJava(String debugPort, String mainClass, String args) { StringBuilder command = new StringBuilder( "java -Xdebug -Xrunjdwp:transport=dt_socket,address=debugPort,server=y,suspend=n " + "-classpath myclasspath main args"); // Albert not the nice solution // String java = "\"C:\\Program Files\\Java\\jdk1.8.0_31\\bin\\javaw.exe\" "; // String java = System.getProperty("java.home"); String java = System.getProperty("java.home").replace("\\", "/") + "/bin/java"; String classPath = System.getProperty("java.class.path"); CGUtil.replaceAll( command, "java", java, "debugPort", debugPort, "myclasspath", classPath, "main", mainClass, "args", args); try { Process pid = Runtime.getRuntime().exec(command.toString()); InputStream inputStream = pid.getInputStream(); boolean alive = pid.isAlive(); mySubProcesses.add(pid); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }