Search in sources :

Example 1 with Instance

use of com.ibm.streamsx.rest.Instance 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 Instance

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

the class StreamingAnalyticsServiceTest method use_it.

private void use_it(StreamingAnalyticsService service) throws Exception {
    assertNotNull(service);
    Result<StreamingAnalyticsService, JsonObject> cs = service.checkStatus(false);
    assertNotNull(cs);
    assertSame(service, cs.getElement());
    assertNull(cs.getId());
    assertTrue(cs.isOk());
    assertNotNull(cs.getRawResult());
    cs = service.checkStatus(true);
    assertNotNull(cs);
    assertSame(service, cs.getElement());
    assertNull(cs.getId());
    assertTrue(cs.isOk());
    assertNotNull(cs.getRawResult());
    Instance instance = service.getInstance();
    assertNotNull(instance);
    assertNotNull(instance.getJobs());
}
Also used : StreamingAnalyticsService(com.ibm.streamsx.rest.StreamingAnalyticsService) Instance(com.ibm.streamsx.rest.Instance) JsonObject(com.google.gson.JsonObject)

Example 3 with Instance

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

the class InstanceTest method testOfEndpoint_standalone.

@Test
public void testOfEndpoint_standalone() throws IOException {
    assumeTrue(null == System.getenv("CP4D_URL"));
    assumeNotNull(System.getenv("STREAMS_REST_URL"));
    Instance instance = Instance.ofEndpoint(null, null, null, null, sslVerify());
    check(instance);
}
Also used : Instance(com.ibm.streamsx.rest.Instance) Test(org.junit.Test)

Example 4 with Instance

use of com.ibm.streamsx.rest.Instance 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)

Example 5 with Instance

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

the class DistributedStreamsContext method createInstance.

private synchronized Instance createInstance(AppEntity entity) throws IOException {
    if (!useRestApi())
        throw new IllegalStateException();
    Instance instance = RemoteDistributedStreamsContext.getConfigInstance(entity);
    if (instance == null) {
        boolean verify = true;
        if (deploy(entity.submission).has(ContextProperties.SSL_VERIFY))
            verify = deploy(entity.submission).get(ContextProperties.SSL_VERIFY).getAsBoolean();
        instance = Instance.ofEndpoint((String) null, (String) null, (String) null, (String) null, verify);
    }
    return instance;
}
Also used : Instance(com.ibm.streamsx.rest.Instance)

Aggregations

Instance (com.ibm.streamsx.rest.Instance)16 Test (org.junit.Test)6 StreamsConnection (com.ibm.streamsx.rest.StreamsConnection)5 JsonObject (com.google.gson.JsonObject)4 Job (com.ibm.streamsx.rest.Job)4 StreamingAnalyticsService (com.ibm.streamsx.rest.StreamingAnalyticsService)4 Metric (com.ibm.streamsx.rest.Metric)3 ProcessingElement (com.ibm.streamsx.rest.ProcessingElement)3 JobConfig (com.ibm.streamsx.topology.jobconfig.JobConfig)3 JsonParser (com.google.gson.JsonParser)2 InputPort (com.ibm.streamsx.rest.InputPort)2 Operator (com.ibm.streamsx.rest.Operator)2 OutputPort (com.ibm.streamsx.rest.OutputPort)2 RESTException (com.ibm.streamsx.rest.RESTException)2 ICP4DAuthenticator (com.ibm.streamsx.rest.internal.ICP4DAuthenticator)2 StandaloneAuthenticator (com.ibm.streamsx.rest.internal.StandaloneAuthenticator)2 IOException (java.io.IOException)2 Executor (org.apache.http.client.fluent.Executor)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1