use of com.datatorrent.stram.plan.physical.PTContainer in project apex-core by apache.
the class StreamCodecTest method checkMxNStreamCodecs.
private void checkMxNStreamCodecs(GenericTestOperator node1, GenericTestOperator node2, GenericTestOperator node3, StreamingContainerManager dnm) {
LogicalPlan dag = dnm.getLogicalPlan();
PhysicalPlan plan = dnm.getPhysicalPlan();
List<PTContainer> containers = plan.getContainers();
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 testDynamicPartitioningStreamCodec.
@Test
public void testDynamicPartitioningStreamCodec() {
GenericTestOperator node1 = dag.addOperator("node1", GenericTestOperator.class);
dag.setOperatorAttribute(node1, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
dag.setOperatorAttribute(node1, Context.OperatorContext.STATS_LISTENERS, Lists.newArrayList((StatsListener) new PartitioningTest.PartitionLoadWatch()));
GenericTestOperator node2 = dag.addOperator("node2", GenericTestOperator.class);
dag.setOperatorAttribute(node2, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(3));
dag.setOperatorAttribute(node2, Context.OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[] { new PartitioningTest.PartitionLoadWatch() }));
TestStreamCodec serDe = new TestStreamCodec();
dag.setInputPortAttribute(node2.inport1, Context.PortContext.STREAM_CODEC, serDe);
GenericTestOperator node3 = dag.addOperator("node3", GenericTestOperator.class);
dag.setOperatorAttribute(node3, Context.OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(3));
dag.setOperatorAttribute(node3, Context.OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[] { new PartitioningTest.PartitionLoadWatch() }));
TestStreamCodec serDe2 = new TestStreamCodec();
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();
int lastId = 0;
for (int i = 0; i < containers.size(); ++i) {
StreamingContainerManagerTest.assignContainer(dnm, "container" + (++lastId));
}
LogicalPlan.OperatorMeta n1meta = dag.getMeta(node1);
LogicalPlan.OperatorMeta n2meta = dag.getMeta(node2);
LogicalPlan.OperatorMeta n3meta = dag.getMeta(node3);
// Sanity check that physical operators have been allocated for n1meta and n2meta
Assert.assertEquals("number operators " + n1meta.getName(), 2, plan.getOperators(n1meta).size());
Assert.assertEquals("number operators " + n2meta.getName(), 3, plan.getOperators(n2meta).size());
Assert.assertEquals("number operators " + n3meta.getName(), 3, plan.getOperators(n3meta).size());
// scale down N (node2) from 3 to 2 and then from 2 to 1
for (int i = 0; i < 2; i++) {
markAllOperatorsActive(plan);
List<PTOperator> ptos = plan.getOperators(n2meta);
for (PTOperator ptOperator : ptos) {
PartitioningTest.PartitionLoadWatch.put(ptOperator, -1);
plan.onStatusUpdate(ptOperator);
}
dnm.processEvents();
lastId = assignNewContainers(dnm, lastId);
List<PTOperator> operators = plan.getOperators(n2meta);
List<PTOperator> upstreamOperators = new ArrayList<>();
for (PTOperator operator : operators) {
upstreamOperators.addAll(operator.upstreamMerge.values());
/*
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);
*/
}
Assert.assertEquals("Number of unifiers ", 2 - i, upstreamOperators.size());
}
// scale down N (node3) from 3 to 2 and then from 2 to 1
for (int i = 0; i < 2; i++) {
markAllOperatorsActive(plan);
List<PTOperator> ptos = plan.getOperators(n3meta);
for (PTOperator ptOperator : ptos) {
PartitioningTest.PartitionLoadWatch.put(ptOperator, -1);
plan.onStatusUpdate(ptOperator);
}
dnm.processEvents();
lastId = assignNewContainers(dnm, lastId);
List<PTOperator> operators = plan.getOperators(n3meta);
List<PTOperator> upstreamOperators = new ArrayList<>();
for (PTOperator operator : operators) {
upstreamOperators.addAll(operator.upstreamMerge.values());
}
Assert.assertEquals("Number of unifiers ", 2 - i, upstreamOperators.size());
}
// Check that different unifiers were created for the two output operators with different codecs
// even though there are only one partition of each one
Set<PTOperator> unifiers = getUnifiers(plan);
Assert.assertEquals("Number of unifiers ", 2, unifiers.size());
// scale up N (node2) from 1 to 2 and then from 2 to 3
for (int i = 0; i < 2; i++) {
markAllOperatorsActive(plan);
PTOperator o2p1 = plan.getOperators(n2meta).get(0);
PartitioningTest.PartitionLoadWatch.put(o2p1, 1);
plan.onStatusUpdate(o2p1);
dnm.processEvents();
lastId = assignNewContainers(dnm, lastId);
List<PTOperator> operators = plan.getOperators(n2meta);
List<PTOperator> upstreamOperators = new ArrayList<>();
for (PTOperator operator : operators) {
upstreamOperators.addAll(operator.upstreamMerge.values());
/*
if (operator.getState() != PTOperator.State.ACTIVE) {
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);
}
*/
}
Assert.assertEquals("Number of unifiers ", 2 + i, upstreamOperators.size());
}
// scale down M to 1
{
markAllOperatorsActive(plan);
for (PTOperator o1p : plan.getOperators(n1meta)) {
PartitioningTest.PartitionLoadWatch.put(o1p, -1);
plan.onStatusUpdate(o1p);
}
dnm.processEvents();
lastId = assignNewContainers(dnm, lastId);
unifiers = getUnifiers(plan);
Assert.assertEquals("Number of unifiers", 0, unifiers.size());
}
// scale up M to 2
{
markAllOperatorsActive(plan);
for (PTOperator o1p : plan.getOperators(n1meta)) {
PartitioningTest.PartitionLoadWatch.put(o1p, 1);
plan.onStatusUpdate(o1p);
}
dnm.processEvents();
lastId = assignNewContainers(dnm, lastId);
unifiers = getUnifiers(plan);
Assert.assertEquals("Number of unifiers", 4, unifiers.size());
}
}
use of com.datatorrent.stram.plan.physical.PTContainer in project apex-core by apache.
the class StreamingContainerManagerTest method testValidInputOperatorDeployInfoType.
@Test
public void testValidInputOperatorDeployInfoType() {
TestGeneratorInputOperator.ValidInputOperator o1 = dag.addOperator("o1", TestGeneratorInputOperator.ValidInputOperator.class);
GenericTestOperator o2 = dag.addOperator("o2", GenericTestOperator.class);
dag.addStream("stream1", o1.outport, o2.inport1);
dag.setAttribute(OperatorContext.STORAGE_AGENT, new MemoryStorageAgent());
StreamingContainerManager scm = new StreamingContainerManager(dag);
PhysicalPlan physicalPlan = scm.getPhysicalPlan();
List<PTContainer> containers = physicalPlan.getContainers();
for (int i = 0; i < containers.size(); ++i) {
assignContainer(scm, "container" + (i + 1));
}
OperatorMeta o1Meta = dag.getMeta(o1);
PTOperator o1Physical = physicalPlan.getOperators(o1Meta).get(0);
String containerId = o1Physical.getContainer().getExternalId();
OperatorDeployInfo o1DeployInfo = getDeployInfo(scm.getContainerAgent(containerId)).get(0);
Assert.assertEquals("type " + o1DeployInfo, OperatorDeployInfo.OperatorType.INPUT, o1DeployInfo.type);
}
use of com.datatorrent.stram.plan.physical.PTContainer in project apex-core by apache.
the class OutputUnifiedTest method testParallelPartition.
@Test
public void testParallelPartition() throws Exception {
TestInputOperator i1 = new TestInputOperator();
dag.addOperator("i1", i1);
dag.setOperatorAttribute(i1, OperatorContext.PARTITIONER, new StatelessPartitioner<GenericTestOperator>(2));
GenericTestOperator op1 = new GenericTestOperator();
dag.addOperator("op1", op1);
dag.setInputPortAttribute(op1.inport1, PortContext.PARTITION_PARALLEL, true);
TestOutputOperator op2 = new TestOutputOperator();
dag.addOperator("op2", op2);
dag.addStream("s1", i1.output, op1.inport1);
dag.addStream("s2", op1.outport1, op2.inport);
StreamingContainerManager scm = new StreamingContainerManager(dag);
PhysicalPlan physicalPlan = scm.getPhysicalPlan();
List<PTContainer> containers = physicalPlan.getContainers();
Assert.assertEquals("Number of containers", 5, containers.size());
assignContainers(scm, containers);
testOutputAttribute(dag, i1, scm, physicalPlan, false);
testOutputAttribute(dag, op1, scm, physicalPlan, true);
}
use of com.datatorrent.stram.plan.physical.PTContainer in project apex-core by apache.
the class PartitioningTest method testDynamicDefaultPartitioning.
//@Ignore
@Test
@SuppressWarnings("SleepWhileInLoop")
public void testDynamicDefaultPartitioning() throws Exception {
LogicalPlan dag = new LogicalPlan();
dag.setAttribute(LogicalPlan.CONTAINERS_MAX_COUNT, 5);
File checkpointDir = new File(TEST_OUTPUT_DIR, "testDynamicDefaultPartitioning");
dag.setAttribute(Context.OperatorContext.STORAGE_AGENT, new AsyncFSStorageAgent(checkpointDir.getPath(), null));
CollectorOperator.receivedTuples.clear();
TestInputOperator<Integer> input = dag.addOperator("input", new TestInputOperator<Integer>());
input.blockEndStream = true;
CollectorOperator collector = dag.addOperator("partitionedCollector", new CollectorOperator());
collector.prefix = "" + System.identityHashCode(collector);
dag.setOperatorAttribute(collector, OperatorContext.PARTITIONER, new StatelessPartitioner<CollectorOperator>(2));
dag.setOperatorAttribute(collector, OperatorContext.STATS_LISTENERS, Arrays.asList(new StatsListener[] { new PartitionLoadWatch() }));
dag.addStream("fromInput", input.output, collector.input);
CollectorOperator singleCollector = dag.addOperator("singleCollector", new CollectorOperator());
singleCollector.prefix = "" + System.identityHashCode(singleCollector);
dag.addStream("toSingleCollector", collector.output, singleCollector.input);
StramLocalCluster lc = new StramLocalCluster(dag);
lc.setHeartbeatMonitoringEnabled(false);
lc.runAsync();
List<PTOperator> partitions = assertNumberPartitions(2, lc, dag.getMeta(collector));
Set<PTContainer> containers = Sets.newHashSet();
for (PTOperator oper : partitions) {
containers.add(oper.getContainer());
}
Assert.assertTrue("Number of containers are 4", 4 == lc.dnmgr.getPhysicalPlan().getContainers().size());
PTOperator splitPartition = partitions.get(0);
PartitionLoadWatch.put(splitPartition, 1);
LOG.debug("Triggered split for {}", splitPartition);
int count = 0;
long startMillis = System.currentTimeMillis();
while (count == 0 && startMillis > System.currentTimeMillis() - StramTestSupport.DEFAULT_TIMEOUT_MILLIS) {
// yield
sleep(20);
count += lc.dnmgr.processEvents();
}
partitions = assertNumberPartitions(3, lc, dag.getMeta(collector));
Assert.assertTrue("container reused", lc.dnmgr.getPhysicalPlan().getContainers().containsAll(containers));
// check deployment
for (PTOperator p : partitions) {
StramTestSupport.waitForActivation(lc, p);
}
PartitionLoadWatch.remove(splitPartition);
for (PTContainer container : lc.dnmgr.getPhysicalPlan().getContainers()) {
int memory = 0;
for (PTOperator operator : container.getOperators()) {
memory += operator.getBufferServerMemory();
memory += operator.getOperatorMeta().getValue(OperatorContext.MEMORY_MB);
}
Assert.assertEquals("memory", memory, container.getRequiredMemoryMB());
}
PTOperator planInput = lc.findByLogicalNode(dag.getMeta(input));
LocalStreamingContainer c = StramTestSupport.waitForActivation(lc, planInput);
Map<Integer, Node<?>> nodeMap = c.getNodes();
Assert.assertEquals("number operators " + nodeMap, 1, nodeMap.size());
@SuppressWarnings({ "unchecked" }) TestInputOperator<Integer> inputDeployed = (TestInputOperator<Integer>) nodeMap.get(planInput.getId()).getOperator();
Assert.assertNotNull("" + nodeMap, inputDeployed);
// add tuple that matches the partition key and check that each partition receives it
ArrayList<Integer> inputTuples = new ArrayList<>();
LOG.debug("Number of partitions {}", partitions.size());
for (PTOperator p : partitions) {
// default partitioning has one port mapping with a single partition key
LOG.debug("Partition key map size: {}", p.getPartitionKeys().size());
inputTuples.add(p.getPartitionKeys().values().iterator().next().partitions.iterator().next());
}
inputDeployed.testTuples = Collections.synchronizedList(new ArrayList<List<Integer>>());
inputDeployed.testTuples.add(inputTuples);
for (PTOperator p : partitions) {
Integer expectedTuple = p.getPartitionKeys().values().iterator().next().partitions.iterator().next();
List<Object> receivedTuples;
int i = 0;
while ((receivedTuples = CollectorOperator.receivedTuples.get(collector.prefix + p.getId())) == null || receivedTuples.isEmpty()) {
if (i++ % 100 == 0) {
LOG.debug("Waiting for tuple: " + p);
}
sleep(10);
}
Assert.assertEquals("received " + p, Arrays.asList(expectedTuple), receivedTuples);
}
// single output operator to receive tuple from each partition
List<PTOperator> operators = lc.getPlanOperators(dag.getMeta(singleCollector));
Assert.assertEquals("number output operator instances " + operators, 1, operators.size());
// ensure redeploy
StramTestSupport.waitForActivation(lc, operators.get(0));
List<Object> receivedTuples;
while ((receivedTuples = CollectorOperator.receivedTuples.get(singleCollector.prefix + operators.get(0).getId())) == null || receivedTuples.size() < inputTuples.size()) {
LOG.debug("Waiting for tuple: " + operators.get(0) + " expected: " + inputTuples + " received: " + receivedTuples);
sleep(20);
}
Assert.assertEquals("output tuples " + receivedTuples, Sets.newHashSet(inputTuples), Sets.newHashSet(receivedTuples));
lc.shutdown();
}
Aggregations