Search in sources :

Example 1 with JobConfig

use of com.ibm.streamsx.topology.jobconfig.JobConfig in project streamsx.topology by IBMStreams.

the class JobConfigOverlay method fromFullOverlay.

/**
     * Get a JobConfig from the JOB_CONFIG_OVERLAYS
     * object in the deploy object. The deploy object
     * always uses JOB_CONFIG_OVERLAYS style even if
     * the Streams version doesn't support overlays (pre 4.2).
     * In that case individual items are taken from the 
     * JobConfig created from the overlay.
     */
public static JobConfig fromFullOverlay(JsonObject deploy) {
    JobConfig jobConfig;
    JsonArray jcos = array(deploy, JOB_CONFIG_OVERLAYS);
    if (jcos == null || jcos.size() == 0) {
        jobConfig = new JobConfig();
    // assume a single config, only one supported in 4.2
    } else {
        JsonObject jco = jcos.get(0).getAsJsonObject();
        if (jco.has(JOB_CONFIG))
            jobConfig = gson().fromJson(object(jco, JOB_CONFIG), JobConfig.class);
        else
            jobConfig = new JobConfig();
        if (jco.has(OPERATION_CONFIG)) {
            JsonObject operationConfig = object(jco, OPERATION_CONFIG);
            if (operationConfig != null) {
                if (operationConfig.has(OVERRIDE_RESOURCE_LOAD_PROTECTION)) {
                    jobConfig.setOverrideResourceLoadProtection(jboolean(operationConfig, OVERRIDE_RESOURCE_LOAD_PROTECTION));
                }
            }
        }
    }
    return jobConfig;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig)

Example 2 with JobConfig

use of com.ibm.streamsx.topology.jobconfig.JobConfig in project streamsx.topology by IBMStreams.

the class JobConfigOverlaysFileTest method testJobConfigOther.

@Test
public void testJobConfigOther() throws Exception {
    // Just a simple graph, which won't be executed.
    Topology topology = newTopology("testJobConfigOther");
    topology.constants(Collections.emptyList());
    Map<String, Object> cfg = new HashMap<>();
    {
        JobConfig jc = new JobConfig();
        jc.addToConfig(cfg);
        jc.setDataDirectory("/tmp/abc");
        jc.setPreloadApplicationBundles(true);
        jc.setTracing(Level.INFO);
        assertEquals("info", jc.getStreamsTracing());
    }
    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();
    assertMissing(jc, "jobName");
    assertMissing(jc, "jobGroup");
    assertJsonString(jc, "dataDirectory", "/tmp/abc");
    assertJsonBoolean(jc, "preloadApplicationBundles", true);
    assertJsonString(jc, "tracing", "info");
    assertEquals(3, 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)

Example 3 with JobConfig

use of com.ibm.streamsx.topology.jobconfig.JobConfig in project streamsx.topology by IBMStreams.

the class JobSubmissionAPITest method testFromConfigProperties.

@Test
public void testFromConfigProperties() {
    Map<String, Object> config = new HashMap<>();
    JobConfig jc = JobConfig.fromProperties(config);
    assertNull(jc.getJobGroup());
    assertNull(jc.getJobName());
    _testMostlyEmptyJobConfig(jc);
    config.put(JobProperties.GROUP, "groupB");
    jc = JobConfig.fromProperties(config);
    assertEquals("groupB", jc.getJobGroup());
    assertNull(jc.getJobName());
    _testMostlyEmptyJobConfig(jc);
    config.clear();
    config.put(JobProperties.NAME, "nameA");
    jc = JobConfig.fromProperties(config);
    assertNull(jc.getJobGroup());
    assertEquals("nameA", jc.getJobName());
    _testMostlyEmptyJobConfig(jc);
    config.clear();
    config.put(JobProperties.GROUP, "groupC");
    config.put(JobProperties.NAME, "nameD");
    jc = JobConfig.fromProperties(config);
    assertEquals("groupC", jc.getJobGroup());
    assertEquals("nameD", jc.getJobName());
    _testMostlyEmptyJobConfig(jc);
}
Also used : HashMap(java.util.HashMap) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig) Test(org.junit.Test)

Example 4 with JobConfig

use of com.ibm.streamsx.topology.jobconfig.JobConfig in project streamsx.topology by IBMStreams.

the class Submit2StreamingAnalyticService method main.

public static void main(String[] args) throws Exception {
    String vcapFile = args[0];
    String serviceName = args[1];
    /*
         * Create a simple topology, focus of the
         * sample is the submission of the job
         * to the service.
         * 
         * This topology is just like simple.HelloWorld
         * with different values printed to the console log.
         */
    Topology topology = new Topology("Submit2StreamingAnalyticService");
    topology.strings("Hello", "Streaming Analytic Service", serviceName, "running on IBM Bluemix").print();
    // Require a configuration object.
    Map<String, Object> config = new HashMap<>();
    // Here the VCAP_SERVICES information is in a local file
    // (as serialized JSON)
    config.put(AnalyticsServiceProperties.VCAP_SERVICES, new File(vcapFile));
    // Explicitly state which service is the job will be submitted to
    // The service must be in the Streaming Analytic Service section
    // of the VCAP services.
    config.put(AnalyticsServiceProperties.SERVICE_NAME, serviceName);
    // Optionally we can specify a job name
    // (note job names must be unique within the instance).
    JobConfig jco = new JobConfig();
    jco.setJobName("BluemixSubmitSample");
    config.put(JobProperties.CONFIG, jco);
    // Submit to the ANALYICS_SERVICE context
    @SuppressWarnings("unchecked") StreamsContext<BigInteger> context = (StreamsContext<BigInteger>) StreamsContextFactory.getStreamsContext(Type.STREAMING_ANALYTICS_SERVICE);
    BigInteger jobId = context.submit(topology, config).get();
    System.out.println("Submitted job with jobId=" + jobId);
}
Also used : HashMap(java.util.HashMap) StreamsContext(com.ibm.streamsx.topology.context.StreamsContext) BigInteger(java.math.BigInteger) Topology(com.ibm.streamsx.topology.Topology) File(java.io.File) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig)

Example 5 with JobConfig

use of com.ibm.streamsx.topology.jobconfig.JobConfig in project streamsx.topology by IBMStreams.

the class JSONStreamsContext method addConfigToDeploy.

/**
     * Convert the config information into the JSON deploy.
     */
private static void addConfigToDeploy(JsonObject deploy, Map<String, Object> config) {
    // For job configuration information we convert to a job
    // config overlay
    JobConfig jc = JobConfig.fromProperties(config);
    JobConfigOverlay jco = new JobConfigOverlay(jc);
    jco.fullOverlayAsJSON(deploy);
    for (String key : config.keySet()) {
        if (CONFIG_SKIP_KEYS.contains(key))
            continue;
        try {
            deploy.add(key, convertConfigValue(config.get(key)));
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("Unknown type for config:" + key + " - " + e.getMessage());
        }
    }
}
Also used : JobConfigOverlay(com.ibm.streamsx.topology.internal.streams.JobConfigOverlay) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig)

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