Search in sources :

Example 1 with OperatorStats

use of com.datatorrent.api.Stats.OperatorStats in project apex-core by apache.

the class StreamingContainerManagerTest method shutdownOperator.

private static void shutdownOperator(StreamingContainerManager scm, PTOperator p1, PTOperator p2) {
    assignContainer(scm, "c1");
    assignContainer(scm, "c2");
    ContainerHeartbeat c1hb = new ContainerHeartbeat();
    c1hb.setContainerStats(new ContainerStats(p1.getContainer().getExternalId()));
    scm.processHeartbeat(c1hb);
    ContainerHeartbeat c2hb = new ContainerHeartbeat();
    c2hb.setContainerStats(new ContainerStats(p2.getContainer().getExternalId()));
    scm.processHeartbeat(c2hb);
    OperatorHeartbeat o1hb = new OperatorHeartbeat();
    c1hb.getContainerStats().addNodeStats(o1hb);
    o1hb.setNodeId(p1.getId());
    o1hb.setState(DeployState.ACTIVE);
    OperatorStats o1stats = new OperatorStats();
    o1hb.getOperatorStatsContainer().add(o1stats);
    o1stats.checkpoint = new Checkpoint(2, 0, 0);
    o1stats.windowId = 3;
    scm.processHeartbeat(c1hb);
    Assert.assertEquals(PTOperator.State.ACTIVE, p1.getState());
    OperatorHeartbeat o2hb = new OperatorHeartbeat();
    c2hb.getContainerStats().addNodeStats(o2hb);
    o2hb.setNodeId(p2.getId());
    o2hb.setState(DeployState.ACTIVE);
    OperatorStats o2stats = new OperatorStats();
    o2stats.checkpoint = new Checkpoint(2, 0, 0);
    o2stats.windowId = 3;
    scm.processHeartbeat(c2hb);
    Assert.assertEquals(PTOperator.State.ACTIVE, p1.getState());
    Assert.assertEquals(PTOperator.State.ACTIVE, p2.getState());
    o1hb.setState(DeployState.SHUTDOWN);
    o1stats.checkpoint = new Checkpoint(4, 0, 0);
    o1stats.windowId = 5;
    scm.processHeartbeat(c1hb);
    Assert.assertEquals(PTOperator.State.INACTIVE, p1.getState());
}
Also used : Checkpoint(com.datatorrent.stram.api.Checkpoint) ContainerStats(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerStats) OperatorHeartbeat(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.OperatorHeartbeat) MockOperatorStats(com.datatorrent.stram.MockContainer.MockOperatorStats) OperatorStats(com.datatorrent.api.Stats.OperatorStats) ContainerHeartbeat(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerHeartbeat)

Example 2 with OperatorStats

use of com.datatorrent.api.Stats.OperatorStats in project apex-core by apache.

the class MockContainer method sendHeartbeat.

public void sendHeartbeat() {
    ContainerStats cstats = new ContainerStats(sca.container.getExternalId());
    ContainerHeartbeat hb = new ContainerHeartbeat();
    hb.setContainerStats(cstats);
    for (Map.Entry<Integer, MockOperatorStats> oe : this.stats.entrySet()) {
        OperatorHeartbeat ohb = new OperatorHeartbeat();
        ohb.setNodeId(oe.getKey());
        ohb.setState(oe.getValue().deployState);
        OperatorStats lstats = new OperatorStats();
        lstats.checkpoint = new Checkpoint(oe.getValue().checkpointWindowId, 0, 0);
        lstats.windowId = oe.getValue().currentWindowId;
        // stats.outputPorts = Lists.newArrayList();
        // PortStats ps = new PortStats(TestGeneratorInputOperator.OUTPUT_PORT);
        // ps.bufferServerBytes = 101;
        // ps.tupleCount = 1;
        // stats.outputPorts.add(ps);
        ohb.windowStats = Lists.newArrayList(lstats);
        cstats.operators.add(ohb);
    }
    ContainerHeartbeatResponse chr = sca.dnmgr.processHeartbeat(hb);
    Assert.assertNull(chr.deployRequest);
}
Also used : Checkpoint(com.datatorrent.stram.api.Checkpoint) ContainerStats(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerStats) OperatorHeartbeat(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.OperatorHeartbeat) ContainerHeartbeatResponse(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerHeartbeatResponse) OperatorStats(com.datatorrent.api.Stats.OperatorStats) Map(java.util.Map) ContainerHeartbeat(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerHeartbeat)

Example 3 with OperatorStats

use of com.datatorrent.api.Stats.OperatorStats in project apex-core by apache.

the class TupleRecorderCollection method collected.

@Handler
public void collected(ContainerStatsEvent cse) {
    ContainerStats stats = cse.getContainerStats();
    for (OperatorHeartbeat node : stats.operators) {
        for (OperatorStats os : node.windowStats) {
            if (os.inputPorts != null) {
                for (PortStats ps : os.inputPorts) {
                    ps.recordingId = null;
                }
            }
            if (os.outputPorts != null) {
                for (PortStats ps : os.outputPorts) {
                    ps.recordingId = null;
                }
            }
        }
    }
    for (OperatorHeartbeat node : stats.operators) {
        String recordingId;
        TupleRecorder tupleRecorder = get(new OperatorIdPortNamePair(node.nodeId, null));
        if (tupleRecorder == null) {
            recordingId = null;
            for (Map.Entry<OperatorIdPortNamePair, TupleRecorder> entry : this.entrySet()) {
                if (entry.getKey().operatorId == node.nodeId) {
                    for (OperatorStats os : node.windowStats) {
                        if (os.inputPorts != null) {
                            for (PortStats ps : os.inputPorts) {
                                if (ps.id.equals(entry.getKey().portName)) {
                                    ps.recordingId = entry.getValue().getId();
                                    break;
                                }
                            }
                        }
                        if (os.outputPorts != null) {
                            for (PortStats ps : os.outputPorts) {
                                if (ps.id.equals(entry.getKey().portName)) {
                                    ps.recordingId = entry.getValue().getId();
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        } else {
            recordingId = tupleRecorder.getId();
        }
        for (OperatorStats os : node.windowStats) {
            os.recordingId = recordingId;
        }
    }
}
Also used : ContainerStats(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerStats) OperatorHeartbeat(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.OperatorHeartbeat) OperatorStats(com.datatorrent.api.Stats.OperatorStats) PortStats(com.datatorrent.api.Stats.OperatorStats.PortStats) HashMap(java.util.HashMap) Map(java.util.Map) Handler(net.engio.mbassy.listener.Handler)

Example 4 with OperatorStats

use of com.datatorrent.api.Stats.OperatorStats in project apex-core by apache.

the class StatsTest method testPortStatsPropagation.

/**
 * Verify buffer server bytes and tuple count.
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("SleepWhileInLoop")
public void testPortStatsPropagation() throws Exception {
    int tupleCount = 10;
    LogicalPlan dag = new LogicalPlan();
    String workingDir = new File("target").getAbsolutePath();
    dag.setAttribute(OperatorContext.STORAGE_AGENT, new AsyncFSStorageAgent(workingDir, null));
    TestOperator testOper = dag.addOperator("TestOperator", TestOperator.class);
    TestInputStatsListener testInputStatsListener = new TestInputStatsListener();
    dag.setOperatorAttribute(testOper, OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[] { testInputStatsListener }));
    testOper.setMaxTuples(tupleCount);
    testOper.setEmitInterval(0);
    TestCollector collector = dag.addOperator("Collector", new TestCollector());
    TestCollectorStatsListener testCollectorStatsListener = new TestCollectorStatsListener();
    dag.setOperatorAttribute(collector, OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[] { testCollectorStatsListener }));
    dag.addStream("TestTuples", testOper.outport, collector.inport1).setLocality(null);
    StramLocalCluster lc = new StramLocalCluster(dag);
    lc.run();
    Assert.assertFalse("input operator stats", testInputStatsListener.inputOperatorStats.isEmpty());
    Assert.assertFalse("collector operator stats", testCollectorStatsListener.collectorOperatorStats.isEmpty());
    try {
        int outputPortTupleCount = 0;
        long outputPortBufferServerBytes = 0L;
        for (Iterator<OperatorStats> it = testInputStatsListener.inputOperatorStats.iterator(); it.hasNext(); ) {
            OperatorStats operatorStats = it.next();
            for (PortStats outputPortStats : operatorStats.outputPorts) {
                outputPortTupleCount += outputPortStats.tupleCount;
                outputPortBufferServerBytes += outputPortStats.bufferServerBytes;
            }
        }
        int inputPortTupleCount = 0;
        long inputPortBufferServerBytes = 0L;
        for (Iterator<OperatorStats> it = testCollectorStatsListener.collectorOperatorStats.iterator(); it.hasNext(); ) {
            OperatorStats operatorStats = it.next();
            for (PortStats inputPortStats : operatorStats.inputPorts) {
                inputPortTupleCount += inputPortStats.tupleCount;
                inputPortBufferServerBytes += inputPortStats.bufferServerBytes;
            }
        }
        Assert.assertEquals("Tuple Count emitted", tupleCount, outputPortTupleCount);
        Assert.assertTrue("Buffer server bytes", inputPortBufferServerBytes > 0);
        Assert.assertEquals("Tuple Count processed", tupleCount, inputPortTupleCount);
        Assert.assertTrue("Buffer server bytes", outputPortBufferServerBytes > 0);
    } finally {
        lc.shutdown();
    }
}
Also used : AsyncFSStorageAgent(com.datatorrent.common.util.AsyncFSStorageAgent) OperatorStats(com.datatorrent.api.Stats.OperatorStats) StatsListener(com.datatorrent.api.StatsListener) TestInputStatsListener(com.datatorrent.stram.engine.StatsTest.TestOperator.TestInputStatsListener) TestCollectorStatsListener(com.datatorrent.stram.engine.StatsTest.TestCollector.TestCollectorStatsListener) StramLocalCluster(com.datatorrent.stram.StramLocalCluster) TestInputStatsListener(com.datatorrent.stram.engine.StatsTest.TestOperator.TestInputStatsListener) TestCollectorStatsListener(com.datatorrent.stram.engine.StatsTest.TestCollector.TestCollectorStatsListener) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) PortStats(com.datatorrent.api.Stats.OperatorStats.PortStats) File(java.io.File) Test(org.junit.Test)

Example 5 with OperatorStats

use of com.datatorrent.api.Stats.OperatorStats in project apex-malhar by apache.

the class AbstractThroughputFileInputOperator method processStats.

@Override
@SuppressWarnings("unchecked")
public Response processStats(BatchedOperatorStats batchedOperatorStats) {
    BasicCounters<MutableLong> fileCounters = null;
    for (OperatorStats operatorStats : batchedOperatorStats.getLastWindowedStats()) {
        if (operatorStats.counters != null) {
            fileCounters = (BasicCounters<MutableLong>) operatorStats.counters;
        }
    }
    Response response = new Response();
    if (fileCounters != null && fileCounters.getCounter(FileCounters.PENDING_FILES).longValue() > 0L || System.currentTimeMillis() - repartitionInterval <= lastRepartition) {
        response.repartitionRequired = false;
        return response;
    }
    response.repartitionRequired = true;
    return response;
}
Also used : MutableLong(org.apache.commons.lang.mutable.MutableLong) OperatorStats(com.datatorrent.api.Stats.OperatorStats)

Aggregations

OperatorStats (com.datatorrent.api.Stats.OperatorStats)7 Checkpoint (com.datatorrent.stram.api.Checkpoint)4 ContainerStats (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerStats)4 OperatorHeartbeat (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.OperatorHeartbeat)4 PortStats (com.datatorrent.api.Stats.OperatorStats.PortStats)3 StatsListener (com.datatorrent.api.StatsListener)3 ContainerHeartbeat (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerHeartbeat)3 Map (java.util.Map)3 MockOperatorStats (com.datatorrent.stram.MockContainer.MockOperatorStats)2 ContainerHeartbeatResponse (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerHeartbeatResponse)2 PTOperator (com.datatorrent.stram.plan.physical.PTOperator)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 AsyncFSStorageAgent (com.datatorrent.common.util.AsyncFSStorageAgent)1 StramLocalCluster (com.datatorrent.stram.StramLocalCluster)1 ContainerResource (com.datatorrent.stram.StreamingContainerManager.ContainerResource)1 TestCollectorStatsListener (com.datatorrent.stram.engine.StatsTest.TestCollector.TestCollectorStatsListener)1 TestInputStatsListener (com.datatorrent.stram.engine.StatsTest.TestOperator.TestInputStatsListener)1 TestGeneratorInputOperator (com.datatorrent.stram.engine.TestGeneratorInputOperator)1 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)1