Search in sources :

Example 1 with Version

use of com.ibm.streams.operator.version.Version 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)

Aggregations

Version (com.ibm.streams.operator.version.Version)1 JobConfig (com.ibm.streamsx.topology.jobconfig.JobConfig)1 File (java.io.File)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Scanner (java.util.Scanner)1