use of com.ibm.streamsx.topology.jobconfig.JobConfig in project streamsx.topology by IBMStreams.
the class InvokeStandalone method invoke.
public Future<Integer> invoke(JsonObject deploy) throws Exception, InterruptedException {
String si = System.getProperty("java.home");
File jvm = new File(si, "bin/java");
JobConfig jc = JobConfigOverlay.fromFullOverlay(deploy);
List<String> commands = new ArrayList<>();
commands.add(jvm.getAbsolutePath());
commands.add("-jar");
commands.add(bundle.getAbsolutePath());
Level traceLevel = jc.getTracing();
if (traceLevel != null) {
commands.add("-t");
// -t, --trace-level=INT Trace level: 0 - OFF, 1 - ERROR, 2 - WARN,
// 3 - INFO, 4 - DEBUG, 5 - TRACE.
int tli = traceLevel.intValue();
String tls;
if (tli == Level.OFF.intValue())
tls = "0";
else if (tli == Level.ALL.intValue())
tls = "5";
else if (tli >= TraceLevel.ERROR.intValue())
tls = "1";
else if (tli >= TraceLevel.WARN.intValue())
tls = "2";
else if (tli >= TraceLevel.INFO.intValue())
tls = "3";
else if (tli >= TraceLevel.DEBUG.intValue())
tls = "4";
else
tls = "5";
commands.add(tls);
}
if (jc.hasSubmissionParameters()) {
for (SubmissionParameter param : jc.getSubmissionParameters()) {
// note: this execution path does correctly
// handle / preserve the semantics of escaped \t and \n.
// e.g., "\\n" is NOT treated as a newline
// rather it's the two char '\','n'
commands.add(param.getName() + "=" + param.getValue());
}
}
trace.info("Invoking standalone application");
trace.info(Util.concatenate(commands));
ProcessBuilder pb = new ProcessBuilder(commands);
pb.inheritIO();
for (Entry<String, String> ev : envVars.entrySet()) {
trace.fine("Setting environment variable for standalone: " + ev.getKey() + "=" + ev.getValue());
pb.environment().put(ev.getKey(), ev.getValue());
}
Process standaloneProcess = pb.start();
return new ProcessFuture(standaloneProcess, keepBundle ? null : bundle);
}
use of com.ibm.streamsx.topology.jobconfig.JobConfig in project streamsx.topology by IBMStreams.
the class InvokeSubmit method invoke.
public BigInteger invoke(JsonObject deploy) throws Exception, InterruptedException {
String si = Util.getStreamsInstall();
File sj = new File(si, "bin/streamtool");
checkPreconditions();
File jobidFile = Files.createTempFile("streamsjobid", "txt").toFile();
List<String> commands = new ArrayList<>();
commands.add(sj.getAbsolutePath());
commands.add("submitjob");
commands.add("--outfile");
commands.add(jobidFile.getAbsolutePath());
final JobConfig jobConfig = JobConfigOverlay.fromFullOverlay(deploy);
// For IBM Streams 4.2 or later use the job config overlay
// V.R.M.F
File jcoFile = null;
Version ver = Product.getVersion();
if (ver.getVersion() > 4 || (ver.getVersion() == 4 && ver.getRelease() >= 2)) {
jcoFile = fileJobConfig(commands, deploy);
} else {
explicitJobConfig(commands, jobConfig);
}
if (jobConfig.getOverrideResourceLoadProtection() != null) {
if (jobConfig.getOverrideResourceLoadProtection()) {
commands.add("--override");
commands.add("HostLoadProtection");
}
}
commands.add(bundle.getAbsolutePath());
trace.info("Invoking streamtool submitjob " + bundle.getAbsolutePath());
trace.info(Util.concatenate(commands));
ProcessBuilder pb = new ProcessBuilder(commands);
try {
Process sjProcess = pb.start();
ProcessOutputToLogger.log(trace, sjProcess);
sjProcess.getOutputStream().close();
int rc = sjProcess.waitFor();
trace.info("streamtool submitjob complete: return code=" + rc);
if (rc != 0)
throw new Exception("streamtool submitjob failed!");
try (Scanner jobIdScanner = new Scanner(jobidFile)) {
if (!jobIdScanner.hasNextBigInteger())
throw new Exception("streamtool failed to supply a job identifier!");
BigInteger jobId = jobIdScanner.nextBigInteger();
trace.info("Bundle: " + bundle.getName() + " submitted with jobid: " + jobId);
return jobId;
}
} finally {
jobidFile.delete();
if (jcoFile != null)
jcoFile.delete();
}
}
use of com.ibm.streamsx.topology.jobconfig.JobConfig in project streamsx.topology by IBMStreams.
the class JobConfigSubmissionTest method testNameJobConfig.
@Test
public void testNameJobConfig() throws Exception {
JobConfig config = new JobConfig();
config.setJobName("nameG");
List<String> result = testItDirect("testNameJobConfig", config);
// job id
assertFalse(result.get(0).isEmpty());
// job name
assertEquals("nameG", result.get(1));
// job group
assertEquals("default", result.get(2));
// data-directory
assertEquals("<empty>", result.get(3));
}
use of com.ibm.streamsx.topology.jobconfig.JobConfig in project streamsx.topology by IBMStreams.
the class JobConfigSubmissionTest method testDataDirJobConfig.
@Test
public void testDataDirJobConfig() throws Exception {
JobConfig config = new JobConfig();
config.setJobName("nameDD");
config.setDataDirectory("/tmp/some/dir");
List<String> result = testItDirect("testNameJobConfig", config);
// job id
assertFalse(result.get(0).isEmpty());
// job name
assertEquals("nameDD", result.get(1));
// job group
assertEquals("default", result.get(2));
// data-directory
assertEquals("/tmp/some/dir", result.get(3));
}
use of com.ibm.streamsx.topology.jobconfig.JobConfig in project streamsx.topology by IBMStreams.
the class JobConfigOverlaysFileTest method testJobNameGroup.
@Test
public void testJobNameGroup() throws Exception {
// Just a simple graph, which won't be executed.
Topology topology = newTopology("testJobNameGroup");
topology.constants(Collections.emptyList());
Map<String, Object> cfg = new HashMap<>();
{
JobConfig jc = new JobConfig();
jc.addToConfig(cfg);
jc.setJobName("JN432");
jc.setJobGroup("JG436");
}
sab = bundler().submit(topology, cfg).get();
JsonObject jcos = assertSabGetJcos(topology);
assertDefaultDeployment(jcos);
JsonObject jco = jobConfigOverlay(jcos);
assertMissing(jco, "operatorConfigs");
assertMissing(jco, "configInstructions");
assertTrue(jco.has("jobConfig"));
assertTrue(jco.get("jobConfig").isJsonObject());
JsonObject jc = jco.get("jobConfig").getAsJsonObject();
assertJsonString(jc, "jobName", "JN432");
assertJsonString(jc, "jobGroup", "JG436");
assertEquals(2, jc.entrySet().size());
}
Aggregations