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;
}
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());
}
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);
}
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);
}
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());
}
}
}
Aggregations