use of com.datatorrent.stram.plan.physical.PlanModifier 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.PlanModifier 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.PlanModifier in project apex-core by apache.
the class LogicalPlanModificationTest method testAddOperator.
@Test
public void testAddOperator() {
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
GenericTestOperator o3 = dag.addOperator("o3", GenericTestOperator.class);
dag.addStream("o1.outport1", o1.outport1, o2.inport1);
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", 3, plan.getContainers().size());
PlanModifier pm = new PlanModifier(plan);
GenericTestOperator added1 = new GenericTestOperator();
pm.addOperator("added1", added1);
pm.addStream("added1.outport1", added1.outport1, o3.inport2);
Assert.assertEquals("undeploy " + ctx.undeploy, 0, ctx.undeploy.size());
Assert.assertEquals("deploy " + ctx.deploy, 0, ctx.deploy.size());
pm.applyChanges(ctx);
Assert.assertEquals("containers post change", 4, plan.getContainers().size());
Assert.assertEquals("undeploy " + ctx.undeploy, 1, ctx.undeploy.size());
Assert.assertEquals("deploy " + ctx.deploy, 2, ctx.deploy.size());
}
use of com.datatorrent.stram.plan.physical.PlanModifier 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);
}
Aggregations