Search in sources :

Example 1 with PEInputPort

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

the class StreamsConnectionTest method validateProcessingElements.

private void validateProcessingElements() throws Exception {
    final List<ProcessingElement> pes = job.getPes();
    // there should be 2 processing element for this test
    assertEquals(2, pes.size());
    ProcessingElement pe1 = pes.get(0);
    assertEquals(0, pe1.getIndexWithinJob());
    assertTrue(pe1.getStatus().equals("running") || pe1.getStatus().equals("starting"));
    assertEquals("none", pe1.getStatusReason());
    assertTrue(pe1.getProcessId() != null);
    assertEquals("pe", pe1.getResourceType());
    // PE metrics
    List<Metric> peMetrics = pe1.getMetrics();
    for (int i = 0; i < 10; i++) {
        if (peMetrics.size() > 0) {
            break;
        }
        Thread.sleep(50);
        peMetrics = pe1.getMetrics();
    }
    assertTrue(peMetrics.size() > 0);
    for (Metric m : peMetrics) {
        assertTrue((m.getMetricKind().equals("counter")) || (m.getMetricKind().equals("gauge")));
        assertEquals("system", m.getMetricType());
        assertEquals("metric", m.getResourceType());
        assertNotNull(m.getName());
        assertNotNull(m.getDescription());
        assertTrue(m.getLastTimeRetrieved() > 0);
    }
    Metric m = peMetrics.get(0);
    long lastTime = m.getLastTimeRetrieved();
    Thread.sleep(3500);
    m.refresh();
    assertTrue(lastTime < m.getLastTimeRetrieved());
    String pid = pe1.getProcessId();
    pe1.refresh();
    assertEquals(pid, pe1.getProcessId());
    List<PEInputPort> inputPorts = pe1.getInputPorts();
    assertTrue(inputPorts.size() == 0);
    List<PEOutputPort> outputPorts = pe1.getOutputPorts();
    assertTrue(outputPorts.size() == 1);
    PEOutputPort op = outputPorts.get(0);
    assertEquals(0, op.getIndexWithinPE());
    assertEquals("peOutputPort", op.getResourceType());
    assertEquals("tcp", op.getTransportType());
    // PE Output Port metrics
    List<Metric> outputPortMetrics = op.getMetrics();
    assertTrue(outputPortMetrics.size() > 0);
    for (Metric opMetric : outputPortMetrics) {
        assertTrue((opMetric.getMetricKind().equals("counter")) || (opMetric.getMetricKind().equals("gauge")));
        assertEquals("system", opMetric.getMetricType());
        assertEquals("metric", opMetric.getResourceType());
        assertNotNull(opMetric.getName());
        assertNotNull(opMetric.getDescription());
        assertTrue(opMetric.getLastTimeRetrieved() > 0);
    }
    ProcessingElement pe2 = pes.get(1);
    assertEquals(1, pe2.getIndexWithinJob());
    assertEquals("running", pe2.getStatus());
    assertEquals("none", pe2.getStatusReason());
    assertTrue(pe2.getProcessId() != null);
    assertEquals("pe", pe2.getResourceType());
    List<PEOutputPort> PE2OutputPorts = pe2.getOutputPorts();
    assertTrue(PE2OutputPorts.size() == 0);
    List<PEInputPort> PE2inputPorts = pe2.getInputPorts();
    assertTrue(PE2inputPorts.size() == 1);
    // PE Input Port metrics
    PEInputPort ip = PE2inputPorts.get(0);
    List<Metric> inputPortMetrics = ip.getMetrics();
    assertTrue(inputPortMetrics.size() > 0);
    for (Metric ipMetric : inputPortMetrics) {
        assertTrue((ipMetric.getMetricKind().equals("counter")) || (ipMetric.getMetricKind().equals("gauge")));
        assertEquals("system", ipMetric.getMetricType());
        assertEquals("metric", ipMetric.getResourceType());
        assertNotNull(ipMetric.getName());
        assertNotNull(ipMetric.getDescription());
        assertTrue(ipMetric.getLastTimeRetrieved() > 0);
    }
    // operator for 2nd PE should point to the 3rd operator for job
    List<Operator> peOperators = pe2.getOperators();
    assertTrue(peOperators.size() == 1);
    List<Operator> jobOperators = job.getOperators();
    assertTrue(jobOperators.size() == 3);
    Operator peOp = peOperators.get(0);
    Operator jobOp = jobOperators.get(2);
    assertEquals(peOp.getName(), jobOp.getName());
    assertEquals(peOp.getIndexWithinJob(), jobOp.getIndexWithinJob());
    assertEquals(peOp.getResourceType(), jobOp.getResourceType());
    assertEquals(peOp.getOperatorKind(), jobOp.getOperatorKind());
    for (ProcessingElement pe : pes) {
        checkResourceAllocation(pe.getResourceAllocation(), true);
    }
}
Also used : ProcessingElement(com.ibm.streamsx.rest.ProcessingElement) Operator(com.ibm.streamsx.rest.Operator) PEInputPort(com.ibm.streamsx.rest.PEInputPort) Metric(com.ibm.streamsx.rest.Metric) PEOutputPort(com.ibm.streamsx.rest.PEOutputPort)

Aggregations

Metric (com.ibm.streamsx.rest.Metric)1 Operator (com.ibm.streamsx.rest.Operator)1 PEInputPort (com.ibm.streamsx.rest.PEInputPort)1 PEOutputPort (com.ibm.streamsx.rest.PEOutputPort)1 ProcessingElement (com.ibm.streamsx.rest.ProcessingElement)1