Search in sources :

Example 6 with JobConfig

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);
}
Also used : SubmissionParameter(com.ibm.streamsx.topology.jobconfig.SubmissionParameter) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TraceLevel(com.ibm.streams.operator.logging.TraceLevel) File(java.io.File) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig)

Example 7 with JobConfig

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();
    }
}
Also used : Scanner(java.util.Scanner) Version(com.ibm.streams.operator.version.Version) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) File(java.io.File) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig) IOException(java.io.IOException)

Example 8 with JobConfig

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));
}
Also used : JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig) Test(org.junit.Test)

Example 9 with JobConfig

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));
}
Also used : JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig) Test(org.junit.Test)

Example 10 with JobConfig

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());
}
Also used : HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig) Test(org.junit.Test)

Aggregations

JobConfig (com.ibm.streamsx.topology.jobconfig.JobConfig)15 Test (org.junit.Test)10 HashMap (java.util.HashMap)5 JsonObject (com.google.gson.JsonObject)3 Topology (com.ibm.streamsx.topology.Topology)3 File (java.io.File)3 TestTopology (com.ibm.streamsx.topology.test.TestTopology)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 JsonArray (com.google.gson.JsonArray)1 TraceLevel (com.ibm.streams.operator.logging.TraceLevel)1 Version (com.ibm.streams.operator.version.Version)1 StreamsContext (com.ibm.streamsx.topology.context.StreamsContext)1 JobConfigOverlay (com.ibm.streamsx.topology.internal.streams.JobConfigOverlay)1 SubmissionParameter (com.ibm.streamsx.topology.jobconfig.SubmissionParameter)1 IOException (java.io.IOException)1 Scanner (java.util.Scanner)1 Level (java.util.logging.Level)1