use of com.datatorrent.stram.plan.physical.PTContainer in project apex-core by apache.
the class StreamingContainerManagerTest method testOperatorShutdown.
@Test
public void testOperatorShutdown() {
dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
GenericTestOperator o3 = dag.addOperator("o3", GenericTestOperator.class);
dag.addStream("stream1", o1.outport1, o2.inport1);
dag.addStream("stream2", o2.outport1, o3.inport1);
dag.setOperatorAttribute(o2, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
StreamingContainerManager scm = new StreamingContainerManager(dag);
PhysicalPlan physicalPlan = scm.getPhysicalPlan();
Map<PTContainer, MockContainer> mockContainers = new HashMap<>();
for (PTContainer c : physicalPlan.getContainers()) {
MockContainer mc = new MockContainer(scm, c);
mockContainers.put(c, mc);
}
// deploy all containers
for (Map.Entry<PTContainer, MockContainer> ce : mockContainers.entrySet()) {
ce.getValue().deploy();
}
for (Map.Entry<PTContainer, MockContainer> ce : mockContainers.entrySet()) {
// skip buffer server purge in monitorHeartbeat
ce.getKey().bufferServerAddress = null;
}
List<PTOperator> o1p = physicalPlan.getOperators(dag.getMeta(o1));
Assert.assertEquals("o1 partitions", 1, o1p.size());
PTOperator o1p1 = o1p.get(0);
MockContainer mc1 = mockContainers.get(o1p1.getContainer());
MockOperatorStats o1p1mos = mc1.stats(o1p1.getId());
o1p1mos.currentWindowId(1).checkpointWindowId(1).deployState(DeployState.ACTIVE);
mc1.sendHeartbeat();
PTOperator o2p1 = physicalPlan.getOperators(dag.getMeta(o2)).get(0);
MockContainer mc2 = mockContainers.get(o2p1.getContainer());
MockOperatorStats o2p1mos = mc2.stats(o2p1.getId());
o2p1mos.currentWindowId(1).checkpointWindowId(1).deployState(DeployState.ACTIVE);
mc2.sendHeartbeat();
Assert.assertEquals("o2 partitions", 2, physicalPlan.getOperators(dag.getMeta(o2)).size());
PTOperator o2p2 = physicalPlan.getOperators(dag.getMeta(o2)).get(1);
MockContainer mc3 = mockContainers.get(o2p2.getContainer());
MockOperatorStats o2p2mos = mc3.stats(o2p2.getId());
o2p2mos.currentWindowId(1).checkpointWindowId(1).deployState(DeployState.ACTIVE);
mc3.sendHeartbeat();
Assert.assertEquals("o3 partitions", 1, physicalPlan.getOperators(dag.getMeta(o3)).size());
PTOperator o3p1 = physicalPlan.getOperators(dag.getMeta(o3)).get(0);
MockContainer mc4 = mockContainers.get(o3p1.getContainer());
MockOperatorStats o3p1mos = mc4.stats(o3p1.getId());
MockOperatorStats unifierp1mos = mc4.stats(o3p1.upstreamMerge.values().iterator().next().getId());
unifierp1mos.currentWindowId(1).checkpointWindowId(1).deployState(DeployState.ACTIVE);
o3p1mos.currentWindowId(1).checkpointWindowId(1).deployState(DeployState.ACTIVE);
mc4.sendHeartbeat();
o1p1mos.currentWindowId(2).deployState(DeployState.SHUTDOWN);
mc1.sendHeartbeat();
o1p = physicalPlan.getOperators(dag.getMeta(o1));
Assert.assertEquals("o1 partitions", 1, o1p.size());
Assert.assertEquals("o1p1 present", o1p1, o1p.get(0));
Assert.assertEquals("input operator state", PTOperator.State.INACTIVE, o1p1.getState());
scm.monitorHeartbeat(false);
Assert.assertEquals("committedWindowId", -1, scm.getCommittedWindowId());
// committedWindowId updated in next cycle
scm.monitorHeartbeat(false);
Assert.assertEquals("committedWindowId", 1, scm.getCommittedWindowId());
scm.processEvents();
Assert.assertEquals("containers at committedWindowId=1", 4, physicalPlan.getContainers().size());
// checkpoint window 2
o1p1mos.checkpointWindowId(2);
mc1.sendHeartbeat();
scm.monitorHeartbeat(false);
Assert.assertEquals("committedWindowId", 1, scm.getCommittedWindowId());
o2p1mos.currentWindowId(2).checkpointWindowId(2);
o2p2mos.currentWindowId(2).checkpointWindowId(2);
o3p1mos.currentWindowId(2).checkpointWindowId(2);
unifierp1mos.currentWindowId(2).checkpointWindowId(2);
mc2.sendHeartbeat();
mc3.sendHeartbeat();
mc4.sendHeartbeat();
scm.monitorHeartbeat(false);
// Operators are shutdown when both operators reach window Id 2
Assert.assertEquals(0, o1p1.getContainer().getOperators().size());
Assert.assertEquals(0, o2p1.getContainer().getOperators().size());
Assert.assertEquals(0, physicalPlan.getContainers().size());
}
use of com.datatorrent.stram.plan.physical.PTContainer in project apex-core by apache.
the class StreamingContainerManagerTest method testDownStreamPartition.
private void testDownStreamPartition(Locality locality) throws Exception {
TestGeneratorInputOperator o1 = dag.addOperator("o1", TestGeneratorInputOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
dag.setOperatorAttribute(o2, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
dag.addStream("o1Output1", o1.outport, o2.inport1).setLocality(locality);
int maxContainers = 5;
dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, maxContainers);
dag.setAttribute(OperatorContext.STORAGE_AGENT, new StramTestSupport.MemoryStorageAgent());
dag.validate();
PhysicalPlan plan = new PhysicalPlan(dag, new TestPlanContext());
Assert.assertEquals("number of containers", 1, plan.getContainers().size());
PTContainer container1 = plan.getContainers().get(0);
Assert.assertEquals("number operators " + container1, 3, container1.getOperators().size());
StramLocalCluster slc = new StramLocalCluster(dag);
slc.run(5000);
}
use of com.datatorrent.stram.plan.physical.PTContainer in project apex-core by apache.
the class StreamCodecTest method testPartitioningMultipleStreamCodecs.
@Test
public void testPartitioningMultipleStreamCodecs() {
GenericTestOperator node1 = dag.addOperator("node1", GenericTestOperator.class);
GenericTestOperator node2 = dag.addOperator("node2", GenericTestOperator.class);
GenericTestOperator node3 = dag.addOperator("node3", GenericTestOperator.class);
dag.setOperatorAttribute(node1, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
TestStreamCodec serDe = new TestStreamCodec();
dag.setInputPortAttribute(node2.inport1, Context.PortContext.STREAM_CODEC, serDe);
TestStreamCodec2 serDe2 = new TestStreamCodec2();
dag.setInputPortAttribute(node3.inport1, Context.PortContext.STREAM_CODEC, serDe2);
dag.addStream("n1n2n3", node1.outport1, node2.inport1, node3.inport1);
dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, Integer.MAX_VALUE);
StramTestSupport.MemoryStorageAgent msa = new StramTestSupport.MemoryStorageAgent();
dag.setAttribute(Context.OperatorContext.STORAGE_AGENT, msa);
StreamingContainerManager dnm = new StreamingContainerManager(dag);
PhysicalPlan plan = dnm.getPhysicalPlan();
List<PTContainer> containers = plan.getContainers();
Assert.assertEquals("number containers", 4, containers.size());
for (int i = 0; i < containers.size(); ++i) {
StreamingContainerManagerTest.assignContainer(dnm, "container" + (i + 1));
}
LogicalPlan.OperatorMeta n1meta = dag.getMeta(node1);
LogicalPlan.OperatorMeta n2meta = dag.getMeta(node2);
LogicalPlan.OperatorMeta n3meta = dag.getMeta(node3);
for (PTContainer container : containers) {
List<PTOperator> operators = container.getOperators();
for (PTOperator operator : operators) {
if (!operator.isUnifier()) {
if (operator.getOperatorMeta() == n1meta) {
OperatorDeployInfo odi = getOperatorDeployInfo(operator, n1meta.getName(), dnm);
OperatorDeployInfo.OutputDeployInfo otdi = getOutputDeployInfo(odi, n1meta.getMeta(node1.outport1));
String id = n1meta.getName() + " " + otdi.portName;
Assert.assertEquals("number stream codecs " + id, otdi.streamCodecs.size(), 2);
checkPresentStreamCodec(n2meta, node2.inport1, otdi.streamCodecs, id, plan);
checkPresentStreamCodec(n3meta, node3.inport1, otdi.streamCodecs, id, plan);
} else if (operator.getOperatorMeta() == n2meta) {
OperatorDeployInfo odi = getOperatorDeployInfo(operator, n2meta.getName(), dnm);
OperatorDeployInfo.InputDeployInfo idi = getInputDeployInfo(odi, n2meta.getMeta(node2.inport1));
String id = n2meta.getName() + " " + idi.portName;
Assert.assertEquals("number stream codecs " + id, idi.streamCodecs.size(), 1);
checkPresentStreamCodec(n2meta, node2.inport1, idi.streamCodecs, id, plan);
} else if (operator.getOperatorMeta() == n3meta) {
OperatorDeployInfo odi = getOperatorDeployInfo(operator, n3meta.getName(), dnm);
OperatorDeployInfo.InputDeployInfo idi = getInputDeployInfo(odi, n3meta.getMeta(node3.inport1));
String id = n3meta.getName() + " " + idi.portName;
Assert.assertEquals("number stream codecs " + id, idi.streamCodecs.size(), 1);
checkPresentStreamCodec(n3meta, node3.inport1, idi.streamCodecs, id, plan);
}
} else {
OperatorDeployInfo odi = getOperatorDeployInfo(operator, operator.getName(), dnm);
Assert.assertEquals("unifier outputs " + operator.getName(), 1, operator.getOutputs().size());
PTOperator.PTOutput out = operator.getOutputs().get(0);
Assert.assertEquals("unifier sinks " + operator.getName(), 1, out.sinks.size());
PTOperator.PTInput idInput = out.sinks.get(0);
LogicalPlan.OperatorMeta idMeta = idInput.target.getOperatorMeta();
Operator.InputPort<?> idInputPort = null;
if (idMeta == n2meta) {
idInputPort = node2.inport1;
} else if (idMeta == n3meta) {
idInputPort = node3.inport1;
}
List<OperatorDeployInfo.InputDeployInfo> idis = odi.inputs;
for (OperatorDeployInfo.InputDeployInfo idi : idis) {
String id = operator.getName() + " " + idi.portName;
Assert.assertEquals("number stream codecs " + id, idi.streamCodecs.size(), 1);
checkPresentStreamCodec(idMeta, idInputPort, idi.streamCodecs, id, plan);
}
}
}
}
}
use of com.datatorrent.stram.plan.physical.PTContainer in project apex-core by apache.
the class StreamCodecTest method testInlineStreamCodec.
@Test
public void testInlineStreamCodec() {
GenericTestOperator node1 = dag.addOperator("node1", GenericTestOperator.class);
GenericTestOperator node2 = dag.addOperator("node2", GenericTestOperator.class);
GenericTestOperator node3 = dag.addOperator("node3", GenericTestOperator.class);
TestStreamCodec serDe = new TestStreamCodec();
dag.setInputPortAttribute(node2.inport1, Context.PortContext.STREAM_CODEC, serDe);
dag.setInputPortAttribute(node3.inport1, Context.PortContext.STREAM_CODEC, serDe);
dag.addStream("n1n2n3", node1.outport1, node2.inport1, node3.inport1);
// Relying on container max count for the manager to layout node1 and node3 in the
// same container in inline fashion and node2 in a separate container
dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, 2);
StramTestSupport.MemoryStorageAgent msa = new StramTestSupport.MemoryStorageAgent();
dag.setAttribute(Context.OperatorContext.STORAGE_AGENT, msa);
StreamingContainerManager dnm = new StreamingContainerManager(dag);
PhysicalPlan plan = dnm.getPhysicalPlan();
List<PTContainer> containers = plan.getContainers();
Assert.assertEquals("number containers", 2, containers.size());
for (int i = 0; i < containers.size(); ++i) {
StreamingContainerManagerTest.assignContainer(dnm, "container" + (i + 1));
}
LogicalPlan.OperatorMeta n1meta = dag.getMeta(node1);
LogicalPlan.OperatorMeta nonInlineMeta = null;
for (int i = 0; i < containers.size(); ++i) {
PTContainer container = containers.get(i);
List<PTOperator> operators = container.getOperators();
if (operators.size() == 1) {
nonInlineMeta = operators.get(0).getOperatorMeta();
break;
}
}
Assert.assertNotNull("non inline operator meta is null", nonInlineMeta);
GenericTestOperator nonInlineOperator = null;
Operator.InputPort<?> niInputPort = null;
if (nonInlineMeta.getName().equals("node2")) {
nonInlineOperator = node2;
niInputPort = node2.inport1;
} else if (nonInlineMeta.getName().equals("node3")) {
nonInlineOperator = node3;
niInputPort = node3.inport1;
}
Assert.assertNotNull("non inline operator is null", nonInlineOperator);
OperatorDeployInfo n1di = getSingleOperatorDeployInfo(node1, dnm);
OperatorDeployInfo.OutputDeployInfo n1odi = getOutputDeployInfo(n1di, n1meta.getMeta(node1.outport1));
String id = n1meta.getName() + " " + n1odi.portName;
Assert.assertEquals("number stream codecs " + id, n1odi.streamCodecs.size(), 1);
checkPresentStreamCodec(nonInlineMeta, niInputPort, n1odi.streamCodecs, id, plan);
OperatorDeployInfo odi = getSingleOperatorDeployInfo(nonInlineOperator, dnm);
OperatorDeployInfo.InputDeployInfo idi = getInputDeployInfo(odi, nonInlineMeta.getMeta(niInputPort));
id = nonInlineMeta.getName() + " " + idi.portName;
Assert.assertEquals("number stream codecs " + id, idi.streamCodecs.size(), 1);
checkPresentStreamCodec(nonInlineMeta, niInputPort, idi.streamCodecs, id, plan);
/*
OperatorDeployInfo n3di = getSingleOperatorDeployInfo(node3, node3.getName(), dnm);
OperatorDeployInfo.InputDeployInfo n3idi = getInputDeployInfo(n3di, n3meta.getMeta(node3.inport1));
id = n3meta.getName() + " " + n3idi.portName;
Assert.assertEquals("number stream codecs " + id, n3idi.streamCodecs.size(), 1);
streamIdentifier.operName = n3meta.getName();
streamIdentifier.portName = n3meta.getMeta(node3.inport1).getPortName();
checkStreamCodecInfo(n3idi.streamCodecs, id, streamIdentifier, serDe2);
*/
}
use of com.datatorrent.stram.plan.physical.PTContainer in project apex-core by apache.
the class StreamCodecTest method assignNewContainers.
private int assignNewContainers(StreamingContainerManager dnm, int lastId) {
PhysicalPlan plan = dnm.getPhysicalPlan();
List<PTContainer> containers = plan.getContainers();
int numPending = 0;
for (PTContainer container : containers) {
if (container.getState() == PTContainer.State.NEW) {
numPending++;
}
}
for (int j = 0; j < numPending; ++j) {
StreamingContainerManagerTest.assignContainer(dnm, "container" + (++lastId));
}
return lastId;
}
Aggregations