use of com.datatorrent.api.StatsListener.StatsListenerWithContext in project apex-core by apache.
the class PhysicalPlanTest method testStatsListenerContextWrappers.
/**
* Test that internally all stats listeners are handled through StatsListenerWithContext.
* Following cases are tested
*
* Operator implementing StatsListener
* Operator implementing StatsListenerWithContext
* Operator with STATS_LISTENERS attribute set to StatsListener
* Operator with STATS_LISTENERS attribute set to StatsListenerWithContext
*/
@Test
public void testStatsListenerContextWrappers() {
LogicalPlan dag = new LogicalPlan();
dag.setAttribute(OperatorContext.STORAGE_AGENT, new StramTestSupport.MemoryStorageAgent());
StatsListenerOperator o1 = dag.addOperator("o1", new StatsListenerOperator());
GenericTestOperator o2 = dag.addOperator("o2", new GenericTestOperator());
dag.setAttribute(o2, OperatorContext.STATS_LISTENERS, Lists.<StatsListener>newArrayList(mock(StatsListener.class)));
GenericTestOperator o3 = dag.addOperator("o3", new GenericTestOperator());
dag.setAttribute(o3, OperatorContext.STATS_LISTENERS, Lists.<StatsListener>newArrayList(mock(StatsListenerWithContext.class)));
StatsListenerOperatorOld o4 = dag.addOperator("o4", new StatsListenerOperatorOld());
PhysicalPlan plan = new PhysicalPlan(dag, new TestPlanContext());
PTOperator p1 = plan.getOperators(dag.getMeta(o1)).get(0);
StatsListener l = p1.statsListeners.get(0);
Assert.assertTrue("Operator stats listener is wrapped ", l instanceof StatsListenerWithContext);
PTOperator p2 = plan.getOperators(dag.getMeta(o2)).get(0);
l = p1.statsListeners.get(0);
Assert.assertTrue("Operator stats listener is wrapped ", l instanceof StatsListenerWithContext);
PTOperator p3 = plan.getOperators(dag.getMeta(o3)).get(0);
l = p1.statsListeners.get(0);
Assert.assertTrue("Operator stats listener is wrapped ", l instanceof StatsListenerWithContext);
PTOperator p4 = plan.getOperators(dag.getMeta(o4)).get(0);
l = p1.statsListeners.get(0);
Assert.assertTrue("Operator stats listener is wrapped ", l instanceof StatsListenerWithContext);
}
use of com.datatorrent.api.StatsListener.StatsListenerWithContext in project apex-core by apache.
the class PhysicalPlan method onStatusUpdate.
public void onStatusUpdate(PTOperator oper) {
for (StatsListenerWithContext l : oper.statsListeners) {
final StatsListener.Response rsp = l.processStats(oper.stats, statsListenerContext);
if (rsp != null) {
// LOG.debug("Response to processStats = {}", rsp.repartitionRequired);
oper.loadIndicator = rsp.loadIndicator;
if (rsp.repartitionRequired) {
final OperatorMeta om = oper.getOperatorMeta();
// concurrent heartbeat processing
if (this.pendingRepartition.putIfAbsent(om, om) != null) {
LOG.debug("Skipping repartitioning for {} load {}", oper, oper.loadIndicator);
} else {
LOG.debug("Scheduling repartitioning for {} load {}", oper, oper.loadIndicator);
// hand over to monitor thread
Runnable r = new Runnable() {
@Override
public void run() {
redoPartitions(logicalToPTOperator.get(om), rsp.repartitionNote);
pendingRepartition.remove(om);
}
};
ctx.dispatch(r);
}
}
if (rsp.operatorRequests != null) {
for (OperatorRequest cmd : rsp.operatorRequests) {
StramToNodeRequest request = new StramToNodeRequest();
request.operatorId = oper.getId();
request.requestType = StramToNodeRequest.RequestType.CUSTOM;
request.cmd = cmd;
ctx.addOperatorRequest(oper, request);
}
}
// for backward compatibility
if (rsp.operatorCommands != null) {
for (@SuppressWarnings("deprecation") com.datatorrent.api.StatsListener.OperatorCommand cmd : rsp.operatorCommands) {
StramToNodeRequest request = new StramToNodeRequest();
request.operatorId = oper.getId();
request.requestType = StramToNodeRequest.RequestType.CUSTOM;
OperatorCommandConverter converter = new OperatorCommandConverter();
converter.cmd = cmd;
request.cmd = converter;
ctx.addOperatorRequest(oper, request);
}
}
}
}
}
Aggregations