Search in sources :

Example 1 with StatsListenerWithContext

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);
}
Also used : GenericTestOperator(com.datatorrent.stram.engine.GenericTestOperator) TestPlanContext(com.datatorrent.stram.plan.TestPlanContext) StramTestSupport(com.datatorrent.stram.support.StramTestSupport) LogicalPlan(com.datatorrent.stram.plan.logical.LogicalPlan) StatsListenerWithContext(com.datatorrent.api.StatsListener.StatsListenerWithContext) StatsListener(com.datatorrent.api.StatsListener) GenericNodeTest(com.datatorrent.stram.engine.GenericNodeTest) Test(org.junit.Test) PartitioningTest(com.datatorrent.stram.PartitioningTest)

Example 2 with 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);
                }
            }
        }
    }
}
Also used : OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) StramToNodeRequest(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.StramToNodeRequest) OperatorRequest(com.datatorrent.api.StatsListener.OperatorRequest) StatsListenerWithContext(com.datatorrent.api.StatsListener.StatsListenerWithContext) StatsListener(com.datatorrent.api.StatsListener)

Aggregations

StatsListener (com.datatorrent.api.StatsListener)2 StatsListenerWithContext (com.datatorrent.api.StatsListener.StatsListenerWithContext)2 OperatorRequest (com.datatorrent.api.StatsListener.OperatorRequest)1 PartitioningTest (com.datatorrent.stram.PartitioningTest)1 StramToNodeRequest (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.StramToNodeRequest)1 GenericNodeTest (com.datatorrent.stram.engine.GenericNodeTest)1 GenericTestOperator (com.datatorrent.stram.engine.GenericTestOperator)1 TestPlanContext (com.datatorrent.stram.plan.TestPlanContext)1 LogicalPlan (com.datatorrent.stram.plan.logical.LogicalPlan)1 OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)1 StramTestSupport (com.datatorrent.stram.support.StramTestSupport)1 Test (org.junit.Test)1