use of com.datatorrent.stram.plan.physical.PTOperator in project apex-core by apache.
the class LogicalPlanModificationTest method testAddStream.
@Test
public void testAddStream() {
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
TestPlanContext ctx = new TestPlanContext();
dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);
PhysicalPlan plan = new PhysicalPlan(dag, ctx);
List<PTOperator> o1Instances = plan.getOperators(dag.getMeta(o1));
Assert.assertEquals("o1Instances " + o1Instances, 1, o1Instances.size());
PTOperator o1p1 = o1Instances.get(0);
OperatorMeta om2 = dag.getMeta(o2);
List<PTOperator> o2Instances = plan.getOperators(om2);
Assert.assertEquals("o2Instances " + o2Instances, 1, o2Instances.size());
PTOperator o2p1 = o2Instances.get(0);
Assert.assertEquals("outputs " + o1p1, 0, o1p1.getOutputs().size());
Assert.assertEquals("inputs " + o2p1, 0, o2p1.getInputs().size());
PlanModifier pm = new PlanModifier(plan);
pm.addStream("o1.outport1", o1.outport1, o2.inport1);
pm.addStream("o1.outport1", o1.outport1, o2.inport2);
pm.applyChanges(ctx);
Assert.assertEquals("undeploy " + ctx.undeploy, 2, ctx.undeploy.size());
Assert.assertEquals("deploy " + ctx.deploy, 2, ctx.deploy.size());
Assert.assertEquals("outputs " + o1p1, 1, o1p1.getOutputs().size());
Assert.assertEquals("inputs " + o2p1, 2, o2p1.getInputs().size());
Set<String> portNames = Sets.newHashSet();
for (PTOperator.PTInput in : o2p1.getInputs()) {
portNames.add(in.portName);
}
Set<String> expPortNames = Sets.newHashSet(GenericTestOperator.IPORT1, GenericTestOperator.IPORT2);
Assert.assertEquals("input port names " + o2p1.getInputs(), expPortNames, portNames);
}
use of com.datatorrent.stram.plan.physical.PTOperator in project apex-core by apache.
the class LogicalPlanModificationTest method testRemoveOperator.
@Test
public void testRemoveOperator() {
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
OperatorMeta o1Meta = dag.getMeta(o1);
GenericTestOperator o12 = dag.addOperator("o12", GenericTestOperator.class);
OperatorMeta o12Meta = dag.getMeta(o12);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
OperatorMeta o2Meta = dag.getMeta(o2);
GenericTestOperator o3 = dag.addOperator("o3", GenericTestOperator.class);
OperatorMeta o3Meta = dag.getMeta(o3);
LogicalPlan.StreamMeta s1 = dag.addStream("o1.outport1", o1.outport1, o2.inport1, o12.inport1);
LogicalPlan.StreamMeta s2 = dag.addStream("o2.outport1", o2.outport1, o3.inport1);
TestPlanContext ctx = new TestPlanContext();
dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);
PhysicalPlan plan = new PhysicalPlan(dag, ctx);
ctx.deploy.clear();
ctx.undeploy.clear();
Assert.assertEquals("containers " + plan.getContainers(), 4, plan.getContainers().size());
Assert.assertEquals("physical operators " + plan.getAllOperators(), 4, plan.getAllOperators().size());
Assert.assertEquals("sinks s1 " + s1.getSinks(), 2, s1.getSinks().size());
List<PTOperator> o2PhysicalOpers = plan.getOperators(o2Meta);
Assert.assertEquals("instances " + o2Meta, 1, o2PhysicalOpers.size());
PlanModifier pm = new PlanModifier(plan);
try {
pm.removeOperator(o2Meta.getName());
Assert.fail("validation error (connected output stream) expected");
} catch (ValidationException ve) {
// all good
}
// remove output stream required before removing operator
pm.removeStream(s2.getName());
pm.removeOperator(o2Meta.getName());
pm.applyChanges(ctx);
Assert.assertEquals("sinks s1 " + s1.getSinks(), 1, s1.getSinks().size());
Assert.assertTrue("undeploy " + ctx.undeploy, ctx.undeploy.containsAll(o2PhysicalOpers));
Assert.assertTrue("deploy " + ctx.deploy, !ctx.deploy.containsAll(o2PhysicalOpers));
Assert.assertEquals("streams " + dag.getAllStreams(), 1, dag.getAllStreams().size());
Assert.assertEquals("operators " + dag.getAllOperators(), 3, dag.getAllOperators().size());
Assert.assertTrue("operators " + dag.getAllOperators(), dag.getAllOperators().containsAll(Sets.newHashSet(o1Meta, o3Meta)));
try {
plan.getOperators(o2Meta);
Assert.fail("removed from physical plan: " + o2Meta);
} catch (Exception e) {
// all good
}
Assert.assertEquals("containers " + plan.getContainers(), 3, plan.getContainers().size());
Assert.assertEquals("physical operators " + plan.getAllOperators(), 3, plan.getAllOperators().size());
Assert.assertEquals("removed containers " + ctx.releaseContainers, 1, ctx.releaseContainers.size());
try {
pm.removeOperator(o12Meta.getName());
Assert.fail("cannot remove operator prior to removing input stream");
} catch (ValidationException ve) {
Assert.assertTrue("" + ve.getMessage(), ve.getMessage().matches(".*Operator o12 connected to input streams.*"));
}
pm.removeStream(s1.getName());
pm.removeOperator(o12Meta.getName());
}
use of com.datatorrent.stram.plan.physical.PTOperator in project apex-core by apache.
the class LogicalPlanModificationTest method testNewOperatorRecoveryWindowIds.
@Test
public void testNewOperatorRecoveryWindowIds() {
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
TestPlanContext ctx = new TestPlanContext();
dag.setAttribute(OperatorContext.STORAGE_AGENT, ctx);
PhysicalPlan plan = new PhysicalPlan(dag, ctx);
ctx.deploy.clear();
ctx.undeploy.clear();
LogicalPlan.OperatorMeta o1Meta = dag.getMeta(o1);
List<PTOperator> o1Partitions = plan.getOperators(o1Meta);
PhysicalPlanTest.setActivationCheckpoint(o1Partitions.get(0), 10);
PlanModifier pm = new PlanModifier(plan);
GenericTestOperator o2 = new GenericTestOperator();
GenericTestOperator o3 = new GenericTestOperator();
pm.addOperator("o2", o2);
pm.addOperator("o3", o3);
pm.addStream("s1", o1.outport1, o2.inport2);
pm.addStream("s2", o2.outport1, o3.inport1);
pm.applyChanges(ctx);
LogicalPlan.OperatorMeta o2Meta = plan.getLogicalPlan().getMeta(o2);
List<PTOperator> o2Partitions = plan.getOperators(o2Meta);
Assert.assertEquals("o2 activation checkpoint " + o2Meta, 10, o2Partitions.get(0).getRecoveryCheckpoint().windowId);
LogicalPlan.OperatorMeta o3Meta = plan.getLogicalPlan().getMeta(o3);
List<PTOperator> o3Partitions = plan.getOperators(o3Meta);
Assert.assertEquals("o3 activation checkpoint " + o2Meta, 10, o3Partitions.get(0).getRecoveryCheckpoint().windowId);
}
use of com.datatorrent.stram.plan.physical.PTOperator in project apex-core by apache.
the class CheckpointTest method testUpdateCheckpointsProcessingTimeout.
@Test
public void testUpdateCheckpointsProcessingTimeout() {
MockClock clock = new MockClock();
dag.setAttribute(com.datatorrent.api.Context.OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
dag.addStream("o1.outport1", o1.outport1, o2.inport1);
StreamingContainerManager dnm = new StreamingContainerManager(dag);
PhysicalPlan plan = dnm.getPhysicalPlan();
// set all operators as active to enable recovery window id update
for (PTOperator oper : plan.getAllOperators().values()) {
oper.setState(PTOperator.State.ACTIVE);
}
List<PTOperator> partitions = plan.getOperators(dag.getMeta(o1));
Assert.assertNotNull(partitions);
Assert.assertEquals(1, partitions.size());
PTOperator o1p1 = partitions.get(0);
partitions = plan.getOperators(dag.getMeta(o2));
Assert.assertNotNull(partitions);
Assert.assertEquals(1, partitions.size());
PTOperator o2p1 = partitions.get(0);
UpdateCheckpointsContext ctx = new UpdateCheckpointsContext(clock);
dnm.updateRecoveryCheckpoints(o1p1, ctx, false);
Assert.assertTrue("no blocked operators", ctx.blocked.isEmpty());
o1p1.stats.statsRevs.checkout();
o1p1.stats.currentWindowId.set(1);
o1p1.stats.lastWindowIdChangeTms = 1;
o1p1.stats.statsRevs.commit();
clock.time = o1p1.stats.windowProcessingTimeoutMillis + 1;
ctx = new UpdateCheckpointsContext(clock);
dnm.updateRecoveryCheckpoints(o1p1, ctx, false);
Assert.assertEquals("o2 blocked", Sets.newHashSet(o2p1), ctx.blocked);
// assign future activation window (state-less or at-most-once).
Checkpoint cp2 = o2p1.getRecoveryCheckpoint();
o2p1.setRecoveryCheckpoint(new Checkpoint(o1p1.getRecoveryCheckpoint().windowId + 1, cp2.applicationWindowCount, cp2.checkpointWindowCount));
ctx = new UpdateCheckpointsContext(clock);
dnm.updateRecoveryCheckpoints(o1p1, ctx, false);
Assert.assertEquals("no operators blocked (o2 activation window ahead)", Sets.newHashSet(), ctx.blocked);
// reset to blocked
o2p1.setRecoveryCheckpoint(cp2);
ctx = new UpdateCheckpointsContext(clock);
dnm.updateRecoveryCheckpoints(o1p1, ctx, false);
Assert.assertEquals("o2 blocked", Sets.newHashSet(o2p1), ctx.blocked);
clock.time++;
ctx = new UpdateCheckpointsContext(clock);
dnm.updateRecoveryCheckpoints(o1p1, ctx, false);
Assert.assertEquals("operators blocked", Sets.newHashSet(o1p1, o2p1), ctx.blocked);
o2p1.stats.statsRevs.checkout();
o2p1.stats.currentWindowId.set(o1p1.stats.getCurrentWindowId());
o2p1.stats.statsRevs.commit();
ctx = new UpdateCheckpointsContext(clock);
dnm.updateRecoveryCheckpoints(o1p1, ctx, false);
Assert.assertEquals("operators blocked", Sets.newHashSet(o1p1), ctx.blocked);
clock.time--;
ctx = new UpdateCheckpointsContext(clock);
dnm.updateRecoveryCheckpoints(o1p1, ctx, false);
Assert.assertEquals("operators blocked", Sets.newHashSet(), ctx.blocked);
}
use of com.datatorrent.stram.plan.physical.PTOperator in project apex-core by apache.
the class CheckpointTest method testUpdateCheckpointsRecovery.
@Test
public void testUpdateCheckpointsRecovery() {
MockClock clock = new MockClock();
dag.setAttribute(com.datatorrent.api.Context.OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
dag.setAttribute(LogicalPlan.STREAMING_WINDOW_SIZE_MILLIS, 1);
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
StatelessOperator o2SL = dag.addOperator("o2SL", StatelessOperator.class);
StatelessOperator o3SL = dag.addOperator("o3SL", StatelessOperator.class);
GenericTestOperator o4 = dag.addOperator("o4", GenericTestOperator.class);
dag.addStream("o1.outport1", o1.outport1, o2SL.inport1);
dag.addStream("o2SL.outport1", o2SL.outport1, o3SL.inport1, o4.inport1);
StreamingContainerManager dnm = new StreamingContainerManager(dag, clock);
PhysicalPlan plan = dnm.getPhysicalPlan();
for (PTOperator oper : plan.getAllOperators().values()) {
Assert.assertEquals("activation windowId " + oper, Checkpoint.INITIAL_CHECKPOINT, oper.getRecoveryCheckpoint());
Assert.assertEquals("checkpoints " + oper, Collections.emptyList(), oper.checkpoints);
}
PTOperator o1p1 = plan.getOperators(dag.getMeta(o1)).get(0);
PTOperator o2SLp1 = plan.getOperators(dag.getMeta(o2SL)).get(0);
PTOperator o3SLp1 = plan.getOperators(dag.getMeta(o3SL)).get(0);
PTOperator o4p1 = plan.getOperators(dag.getMeta(o4)).get(0);
Checkpoint leafCheckpoint = new Checkpoint(2L, 0, 0);
clock.time = 3;
o4p1.checkpoints.add(leafCheckpoint);
UpdateCheckpointsContext ctx;
dnm.updateRecoveryCheckpoints(o1p1, ctx = new UpdateCheckpointsContext(clock, true, Collections.<OperatorMeta, Set<OperatorMeta>>emptyMap()), false);
Assert.assertEquals("initial checkpoint " + o1p1, Checkpoint.INITIAL_CHECKPOINT, o1p1.getRecoveryCheckpoint());
Assert.assertEquals("initial checkpoint " + o2SLp1, leafCheckpoint, o2SLp1.getRecoveryCheckpoint());
Assert.assertEquals("initial checkpoint " + o3SLp1, new Checkpoint(clock.getTime(), 0, 0), o3SLp1.getRecoveryCheckpoint());
Assert.assertEquals("number dependencies " + ctx.visited, plan.getAllOperators().size(), ctx.visited.size());
}
Aggregations