Search in sources :

Example 1 with InputPort

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

the class StreamsConnectionTest method validateOperators.

private void validateOperators() throws Exception {
    List<Operator> operators = job.getOperators();
    // there should be 3 operators for this test, ordered by name
    assertEquals(3, operators.size());
    List<ProcessingElement> jobpes = job.getPes();
    for (Operator op : operators) {
        assertSame(this.connection, op.getStreamsConnection());
        ProcessingElement pe = op.getPE();
        assertNotNull(pe);
        assertSame(this.connection, pe.getStreamsConnection());
        boolean inJobList = false;
        for (ProcessingElement pej : jobpes) {
            if (pej.getId().equals(pe.getId())) {
                inJobList = true;
                break;
            }
        }
        assertTrue("PE not in job list:" + pe.getId(), inJobList);
    }
    // the first operator will have an output port
    Operator op0 = operators.get(0);
    assertEquals("operator", op0.getResourceType());
    assertEquals("IntegerPeriodicMultiSource", op0.getName());
    assertEquals(0, op0.getIndexWithinJob());
    assertEquals("com.ibm.streamsx.topology.functional.java::FunctionPeriodicSource", op0.getOperatorKind());
    List<InputPort> inputSource = op0.getInputPorts();
    assertEquals(0, inputSource.size());
    List<OutputPort> outputSource = op0.getOutputPorts();
    assertEquals(1, outputSource.size());
    OutputPort opSource = outputSource.get(0);
    assertEquals(0, opSource.getIndexWithinOperator());
    assertEquals("operatorOutputPort", opSource.getResourceType());
    assertNameValid(opSource.getName());
    List<Metric> operatorMetrics = opSource.getMetrics();
    for (Metric m : operatorMetrics) {
        assertEquals(m.getMetricKind(), "counter");
        assertEquals(m.getMetricType(), "system");
        assertEquals(m.getResourceType(), "metric");
        assertNotNull(m.getName());
        assertNotNull(m.getDescription());
        assertTrue(m.getLastTimeRetrieved() > 0);
    }
    // this operator will have an input and an output port
    Operator op1 = operators.get(1);
    assertEquals("operator", op1.getResourceType());
    assertEquals("IntegerTransformInteger", op1.getName());
    assertEquals(1, op1.getIndexWithinJob());
    assertEquals("com.ibm.streamsx.topology.functional.java::Map", op1.getOperatorKind());
    List<InputPort> inputTransform = op1.getInputPorts();
    assertEquals(1, inputTransform.size());
    InputPort ip = inputTransform.get(0);
    assertNameValid(ip.getName());
    assertEquals(0, ip.getIndexWithinOperator());
    assertEquals("operatorInputPort", ip.getResourceType(), "operatorInputPort");
    List<Metric> inputPortMetrics = ip.getMetrics();
    for (Metric m : inputPortMetrics) {
        assertTrue("Unexpected metric kind for metric " + m.getName() + ": " + m.getMetricKind(), (m.getMetricKind().equals("counter")) || (m.getMetricKind().equals("gauge")) || (m.getMetricKind().equals("time")));
        assertEquals("system", m.getMetricType());
        assertEquals("metric", m.getResourceType());
        assertNotNull(m.getName());
        assertNotNull(m.getDescription());
        assertTrue(m.getLastTimeRetrieved() > 0);
    }
    List<OutputPort> outputTransform = op1.getOutputPorts();
    assertEquals(1, outputTransform.size());
    OutputPort opTransform = outputTransform.get(0);
    assertEquals(0, opTransform.getIndexWithinOperator());
    assertEquals("operatorOutputPort", opTransform.getResourceType());
    assertNameValid(opTransform.getName());
    assertNameValid(opTransform.getStreamName());
    List<Metric> outputPortMetrics = opTransform.getMetrics();
    for (Metric m : outputPortMetrics) {
        assertEquals("counter", m.getMetricKind());
        assertEquals("system", m.getMetricType());
        assertEquals("metric", m.getResourceType());
        assertNotNull(m.getName());
        assertNotNull(m.getDescription());
        assertTrue(m.getLastTimeRetrieved() > 0);
    }
}
Also used : Operator(com.ibm.streamsx.rest.Operator) ProcessingElement(com.ibm.streamsx.rest.ProcessingElement) PEOutputPort(com.ibm.streamsx.rest.PEOutputPort) OutputPort(com.ibm.streamsx.rest.OutputPort) PEInputPort(com.ibm.streamsx.rest.PEInputPort) InputPort(com.ibm.streamsx.rest.InputPort) Metric(com.ibm.streamsx.rest.Metric)

Example 2 with InputPort

use of com.ibm.streamsx.rest.InputPort 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 3 with InputPort

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

Aggregations

InputPort (com.ibm.streamsx.rest.InputPort)3 Metric (com.ibm.streamsx.rest.Metric)3 Operator (com.ibm.streamsx.rest.Operator)3 OutputPort (com.ibm.streamsx.rest.OutputPort)3 Instance (com.ibm.streamsx.rest.Instance)2 Job (com.ibm.streamsx.rest.Job)2 ProcessingElement (com.ibm.streamsx.rest.ProcessingElement)2 JsonPrimitive (com.google.gson.JsonPrimitive)1 PEInputPort (com.ibm.streamsx.rest.PEInputPort)1 PEOutputPort (com.ibm.streamsx.rest.PEOutputPort)1 RESTException (com.ibm.streamsx.rest.RESTException)1 StreamingAnalyticsService (com.ibm.streamsx.rest.StreamingAnalyticsService)1 StreamsConnection (com.ibm.streamsx.rest.StreamsConnection)1 IOException (java.io.IOException)1