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());
}
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);
}
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;
}
}
}
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();
}
}
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;
}
Aggregations