Search in sources :

Example 11 with Instance

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

the class JobConfigSubmissionTest method testSubmitUsingInstanceWithRemoteBuild.

@Test
public void testSubmitUsingInstanceWithRemoteBuild() throws Exception {
    assumeTrue(getTesterContext().getType() == Type.DISTRIBUTED_TESTER);
    assumeTrue(System.getenv("CP4D_URL") != null);
    JobConfig config = new JobConfig();
    String jobName = "nameSC" + System.currentTimeMillis();
    config.setJobName(jobName);
    boolean verify = true;
    if (getConfig().containsKey(ContextProperties.SSL_VERIFY))
        verify = (Boolean) getConfig().get(ContextProperties.SSL_VERIFY);
    Instance instance = Instance.ofEndpoint((String) null, (String) null, (String) null, (String) null, verify);
    getConfig().put(ContextProperties.STREAMS_INSTANCE, instance);
    getConfig().put(ContextProperties.FORCE_REMOTE_BUILD, true);
    getConfig().remove(ContextProperties.SSL_VERIFY);
    final String cpd_url = setEnv("CP4D_URL", null);
    final String sid = setEnv("STREAMS_INSTANCE_ID", null);
    assertNull(System.getenv("CP4D_URL"));
    assertNull(System.getenv("STREAMS_INSTANCE_ID"));
    try {
        testItDirect("testSubmitUsingInstanceWithRemoteBuild", config, "<jobId>", jobName, "default", "<empty>");
    } finally {
        setEnv("CP4D_URL", cpd_url);
        setEnv("STREAMS_INSTANCE_ID", sid);
    }
}
Also used : Instance(com.ibm.streamsx.rest.Instance) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig) Test(org.junit.Test)

Example 12 with Instance

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

the class JobConfigSubmissionTest method testSubmitUsingInstance.

@Test
public void testSubmitUsingInstance() throws Exception {
    assumeTrue(getTesterContext().getType() == Type.DISTRIBUTED_TESTER);
    assumeTrue(System.getenv("CP4D_URL") != null);
    JobConfig config = new JobConfig();
    String jobName = "nameSC" + System.currentTimeMillis();
    config.setJobName(jobName);
    boolean verify = true;
    if (getConfig().containsKey(ContextProperties.SSL_VERIFY))
        verify = (Boolean) getConfig().get(ContextProperties.SSL_VERIFY);
    Instance instance = Instance.ofEndpoint((String) null, (String) null, (String) null, (String) null, verify);
    assertEquals(verify, instance.getStreamsConnection().isVerify());
    getConfig().put(ContextProperties.STREAMS_INSTANCE, instance);
    getConfig().remove(ContextProperties.SSL_VERIFY);
    final String cpd_url = setEnv("CP4D_URL", null);
    final String sid = setEnv("STREAMS_INSTANCE_ID", null);
    try {
        testItDirect("testSubmitUsingInstance", config, "<jobId>", jobName, "default", "<empty>");
    } finally {
        setEnv("CP4D_URL", cpd_url);
        setEnv("STREAMS_INSTANCE_ID", sid);
    }
}
Also used : Instance(com.ibm.streamsx.rest.Instance) JobConfig(com.ibm.streamsx.topology.jobconfig.JobConfig) Test(org.junit.Test)

Example 13 with Instance

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

the class StreamsConnectionSample method main.

public static void main(String[] args) throws IOException {
    String userName = args[0];
    String authToken = args[1];
    String url = args[2];
    String instanceName = args[3];
    /*
         * Create the connection to the instance indicated
         */
    StreamsConnection sClient = StreamsConnection.createInstance(userName, authToken, url);
    /*
         * This option is only used to by-pass the certificate certification
         */
    if (args.length == 5 && "true".equals(args[4])) {
        sClient.allowInsecureHosts(true);
    }
    try {
        System.out.println("Instance: ");
        Instance instance = sClient.getInstance(instanceName);
        /*
             * From the Instance, get a list of jobs
             */
        List<Job> jobs = instance.getJobs();
        for (Job job : jobs) {
            System.out.println("Job: " + job.toString());
            /*
                 * For each job, get a list of operators
                 */
            List<Operator> operators = job.getOperators();
            for (Operator op : operators) {
                System.out.println("Operator: " + op.toString());
                List<Metric> metrics = op.getMetrics();
                /*
                     * For each operator, you can get a list of metrics, output
                     * ports and input ports
                     */
                for (Metric m : metrics) {
                    System.out.println("Metric: " + m.toString());
                }
                List<OutputPort> outP = op.getOutputPorts();
                for (OutputPort oport : outP) {
                    System.out.println("Output Port: " + oport.toString());
                    /*
                         * For each output port, you can get a list of metrics
                         */
                    for (Metric om : oport.getMetrics()) {
                        System.out.println("Output Port Metric: " + om.toString());
                    }
                }
                List<InputPort> inP = op.getInputPorts();
                /*
                     * For each input port, get a list of metrics
                     */
                for (InputPort ip : inP) {
                    System.out.println("Input Port: " + ip.toString());
                    for (Metric im : ip.getMetrics()) {
                        System.out.println("Input Port Metric: " + im.toString());
                    }
                }
            }
            /*
                 * For each job, get a list of processing elements
                 */
            for (ProcessingElement pe : job.getPes()) {
                System.out.println("ProcessingElement:" + pe.toString());
            }
        }
        try {
            /*
                 * Get a specific job in the instance
                 */
            instance.getJob("99999");
        } catch (RESTException e) {
            /*
                 * This shows what is available in the RESTException should
                 * something fail
                 */
            System.out.println("Status Code: " + e.getStatusCode());
            System.out.println("Message Id: " + e.getStreamsErrorMessageId());
            System.out.println("MessageAsJson: " + e.getStreamsErrorMessageAsJson().toString());
            System.out.println("Message: " + e.getMessage());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Operator(com.ibm.streamsx.rest.Operator) OutputPort(com.ibm.streamsx.rest.OutputPort) ProcessingElement(com.ibm.streamsx.rest.ProcessingElement) RESTException(com.ibm.streamsx.rest.RESTException) Instance(com.ibm.streamsx.rest.Instance) InputPort(com.ibm.streamsx.rest.InputPort) StreamsConnection(com.ibm.streamsx.rest.StreamsConnection) IOException(java.io.IOException) RESTException(com.ibm.streamsx.rest.RESTException) Metric(com.ibm.streamsx.rest.Metric) Job(com.ibm.streamsx.rest.Job)

Example 14 with Instance

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

the class StreamingAnalyticsConnectionSample method main.

public static void main(String[] args) {
    String credentials = args[0];
    String serviceName = args[1];
    System.out.println(credentials);
    System.out.println(serviceName);
    try {
        StreamingAnalyticsService sClient = StreamingAnalyticsService.of(new JsonPrimitive(credentials), serviceName);
        Instance instance = sClient.getInstance();
        System.out.println("Instance:" + instance.toString());
        if (!instance.getStatus().equals("running")) {
            System.out.println("Instance is not started, please start the instance to retrieve more information");
            System.exit(0);
        }
        /* Retrieve a list of jobs in the instance */
        List<Job> jobs = instance.getJobs();
        for (Job job : jobs) {
            System.out.println("Job: " + job.toString());
            /* Retrieve a list of operators for the current job */
            List<Operator> operators = job.getOperators();
            for (Operator op : operators) {
                System.out.println("Operator: " + op.toString());
                /* Retrieve a list of metrics for the current operator */
                List<Metric> metrics = op.getMetrics();
                for (Metric m : metrics) {
                    System.out.println("Metric: " + m.toString());
                }
                /*
                     * Retrieve a list of output ports for the current operator
                     */
                List<OutputPort> outP = op.getOutputPorts();
                for (OutputPort oport : outP) {
                    System.out.println("Output Port: " + oport.toString());
                    /* Retrieve the metrics for this output port */
                    for (Metric om : oport.getMetrics()) {
                        System.out.println("Output Port Metric: " + om.toString());
                    }
                }
                /*
                     * Retrieve a list of input ports for the current operator
                     */
                List<InputPort> inP = op.getInputPorts();
                for (InputPort ip : inP) {
                    System.out.println("Input Port: " + ip.toString());
                    /* Retrieve the metrics for this input port */
                    for (Metric im : ip.getMetrics()) {
                        System.out.println("Input Port Metric: " + im.toString());
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Operator(com.ibm.streamsx.rest.Operator) OutputPort(com.ibm.streamsx.rest.OutputPort) StreamingAnalyticsService(com.ibm.streamsx.rest.StreamingAnalyticsService) JsonPrimitive(com.google.gson.JsonPrimitive) Instance(com.ibm.streamsx.rest.Instance) InputPort(com.ibm.streamsx.rest.InputPort) Metric(com.ibm.streamsx.rest.Metric) Job(com.ibm.streamsx.rest.Job)

Example 15 with Instance

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

the class AppBundleTest method getInstance.

protected Instance getInstance() throws IOException {
    assumeNotNull(System.getenv("STREAMS_REST_URL"));
    StreamsConnection sc = StreamsConnection.createInstance(null, null, null);
    sc.allowInsecureHosts(true);
    List<Instance> instances = sc.getInstances();
    if (instances.size() == 1)
        return instances.get(0);
    return sc.getInstance(System.getenv("STREAMS_INSTANCE_ID"));
}
Also used : Instance(com.ibm.streamsx.rest.Instance) StreamsConnection(com.ibm.streamsx.rest.StreamsConnection)

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