Search in sources :

Example 1 with Job

use of com.ibm.streamsx.rest.Job in project streamsx.topology by IBMStreams.

the class AppBundleTest method testAppBundles.

@Test
public void testAppBundles() throws Exception {
    String namespace = "App.NS_" + (int) (Math.random() * 10000.0);
    String name = "AppBundleTest" + System.currentTimeMillis();
    final String appName = namespace + "::" + name;
    File bundle = createBundle(namespace, name);
    Instance instance = getInstance();
    Result<Job, JsonObject> result = instance.submitJob(bundle, null);
    verifyJob(result, appName, null);
    String jobName = "ABJN_" + (int) (Math.random() * 10000.0) + "_" + System.currentTimeMillis();
    JobConfig jc = new JobConfig();
    jc.setJobName(jobName);
    JsonObject overlay = new JsonObject();
    overlay.add("jobConfig", new Gson().toJsonTree(jc));
    JsonArray a = new JsonArray();
    a.add(overlay);
    JsonObject jco = new JsonObject();
    jco.add("jobConfigOverlays", a);
    result = instance.submitJob(bundle, jco);
    verifyJob(result, appName, jobName);
    final ApplicationBundle appBundle = instance.uploadBundle(bundle);
    assertNotNull(appBundle);
    verifyJob(appBundle.submitJob(null), appName, null);
    jobName = "ABJN2_" + (int) (Math.random() * 10000.0) + "_" + System.currentTimeMillis();
    jc.setJobName(jobName);
    overlay.add("jobConfig", new Gson().toJsonTree(jc));
    verifyJob(appBundle.submitJob(jco), appName, jobName);
}
Also used : JsonArray(com.google.gson.JsonArray) Instance(com.ibm.streamsx.rest.Instance) ApplicationBundle(com.ibm.streamsx.rest.ApplicationBundle) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) Job(com.ibm.streamsx.rest.Job) File(java.io.File) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig) Test(org.junit.Test)

Example 2 with Job

use of com.ibm.streamsx.rest.Job in project streamsx.topology by IBMStreams.

the class AppBundleTest method verifyJob.

private void verifyJob(Result<Job, JsonObject> result, String appName, String jobName) throws Exception {
    assertTrue(result.isOk());
    assertNotNull(result.getId());
    Job job = result.getElement();
    assertEquals(result.getId(), job.getId());
    // Verify we can call it.
    job.refresh();
    assertEquals(appName, job.getApplicationName());
    if (jobName != null)
        assertEquals(jobName, job.getName());
    job.cancel();
}
Also used : Job(com.ibm.streamsx.rest.Job)

Example 3 with Job

use of com.ibm.streamsx.rest.Job in project streamsx.topology by IBMStreams.

the class RESTTesterRuntime method start.

@Override
public void start(Object info) throws Exception {
    JsonObject deployment = (JsonObject) info;
    JsonObject submission = jobject(deployment, "submissionResults");
    requireNonNull(submission);
    String jobId = jstring(submission, SubmissionResultsKeys.JOB_ID);
    requireNonNull(jobId);
    trace.info("Testing topology:" + topology().getNamespace() + "::" + topology().getName() + " JobId:" + jobId);
    Job job = instanceSupplier.apply(deployment).call().getJob(jobId);
    metricsChecker.setup(job);
}
Also used : JsonObject(com.google.gson.JsonObject) Job(com.ibm.streamsx.rest.Job)

Example 4 with Job

use of com.ibm.streamsx.rest.Job in project streamsx.topology by IBMStreams.

the class ServiceSubmissionAPITest method cancel.

private void cancel(BigInteger jobId) throws Exception {
    JsonElement vse;
    if (vcapServices.startsWith(File.separator))
        vse = new JsonPrimitive(vcapServices);
    else
        vse = new JsonParser().parse(vcapServices);
    StreamingAnalyticsService sas = StreamingAnalyticsService.of(vse, serviceName);
    Job job = sas.getInstance().getJob(jobId.toString());
    assertNotNull(job);
    boolean canceled = job.cancel();
    assertTrue(canceled);
}
Also used : StreamingAnalyticsService(com.ibm.streamsx.rest.StreamingAnalyticsService) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) Job(com.ibm.streamsx.rest.Job) JsonParser(com.google.gson.JsonParser)

Example 5 with Job

use of com.ibm.streamsx.rest.Job in project streamsx.topology by IBMStreams.

the class StreamsConnectionTest method checkResourceAllocation.

private static void checkResourceAllocation(ResourceAllocation ra, boolean app) throws IOException {
    if (ra == null)
        return;
    assertEquals("resourceAllocation", ra.getResourceType());
    if (app)
        assertTrue(ra.isApplicationResource());
    assertNotNull(ra.getSchedulerStatus());
    assertNotNull(ra.getStatus());
    Instance rai = ra.getInstance();
    for (ProcessingElement pe : ra.getPes()) {
        assertNotNull(pe);
        assertNotNull(pe.getStatus());
    }
    for (Job job : ra.getJobs()) {
        assertNotNull(job);
        assertNotNull(job.getStatus());
    }
    assertSame(rai, ra.getInstance());
    Resource r = ra.getResource();
    assertNotNull(r.getId());
    assertNotNull(r.getDisplayName());
    assertNotNull(r.getIpAddress());
    assertEquals("resource", r.getResourceType());
    for (Metric metric : r.getMetrics()) {
        assertTrue((metric.getMetricKind().equals("counter")) || (metric.getMetricKind().equals("gauge")));
        assertEquals("system", metric.getMetricType());
        assertEquals("metric", metric.getResourceType());
        assertNotNull(metric.getName());
        assertNotNull(metric.getDescription());
        assertTrue(metric.getLastTimeRetrieved() > 0);
    }
}
Also used : ProcessingElement(com.ibm.streamsx.rest.ProcessingElement) Instance(com.ibm.streamsx.rest.Instance) Resource(com.ibm.streamsx.rest.Resource) Metric(com.ibm.streamsx.rest.Metric) Job(com.ibm.streamsx.rest.Job)

Aggregations

Job (com.ibm.streamsx.rest.Job)11 JsonObject (com.google.gson.JsonObject)5 Instance (com.ibm.streamsx.rest.Instance)4 JsonElement (com.google.gson.JsonElement)3 Metric (com.ibm.streamsx.rest.Metric)3 Operator (com.ibm.streamsx.rest.Operator)3 ProcessingElement (com.ibm.streamsx.rest.ProcessingElement)3 StreamingAnalyticsService (com.ibm.streamsx.rest.StreamingAnalyticsService)3 JsonArray (com.google.gson.JsonArray)2 JsonPrimitive (com.google.gson.JsonPrimitive)2 ApplicationBundle (com.ibm.streamsx.rest.ApplicationBundle)2 InputPort (com.ibm.streamsx.rest.InputPort)2 OutputPort (com.ibm.streamsx.rest.OutputPort)2 StreamsConnection (com.ibm.streamsx.rest.StreamsConnection)2 File (java.io.File)2 BigInteger (java.math.BigInteger)2 Test (org.junit.Test)2 Gson (com.google.gson.Gson)1 JsonParser (com.google.gson.JsonParser)1 RESTException (com.ibm.streamsx.rest.RESTException)1