use of io.cdap.cdap.etl.proto.Connection in project cdap by cdapio.
the class DagTest method testIdentitySplitByControl.
@Test
public void testIdentitySplitByControl() {
// |-- n0 --|
// a0 --| |-- n2
// |-- n1 --|
Dag dag = new Dag(ImmutableSet.of(new Connection("a0", "n0"), new Connection("a0", "n1"), new Connection("n0", "n2"), new Connection("n1", "n2")));
Set<Dag> actual = dag.splitByControlNodes(ImmutableSet.<String>of(), ImmutableSet.of("a0"));
Set<Dag> expectedDags = new HashSet<>();
expectedDags.add(dag);
Assert.assertEquals(expectedDags, actual);
// a0 -- n0 --|
// |-- n2
// n1 --|
dag = new Dag(ImmutableSet.of(new Connection("a0", "n0"), new Connection("n0", "n2"), new Connection("n1", "n2")));
actual = dag.splitByControlNodes(ImmutableSet.<String>of(), ImmutableSet.of("a0"));
expectedDags.clear();
expectedDags.add(dag);
Assert.assertEquals(expectedDags, actual);
// a0 -- n0 -- a1
dag = new Dag(ImmutableSet.of(new Connection("a0", "n0"), new Connection("n0", "a1")));
actual = dag.splitByControlNodes(ImmutableSet.<String>of(), ImmutableSet.of("a0", "a1"));
expectedDags.clear();
expectedDags.add(dag);
Assert.assertEquals(expectedDags, actual);
// n0 --|
// |-- a0
// |---|
// n1
// |---|
// |-- n2
// a1 --|
dag = new Dag(ImmutableSet.of(new Connection("n0", "a0"), new Connection("n1", "a0"), new Connection("n1", "n2"), new Connection("a1", "n2")));
actual = dag.splitByControlNodes(ImmutableSet.<String>of(), ImmutableSet.of("a0", "a1"));
expectedDags.clear();
expectedDags.add(dag);
Assert.assertEquals(expectedDags, actual);
}
use of io.cdap.cdap.etl.proto.Connection in project cdap by cdapio.
the class PipelinePlannerTest method testConditionsToConditions.
@Test
public void testConditionsToConditions() {
/*
n1 - c1----c2---n2
|
|-----c3---n3
*/
Set<StageSpec> stageSpecs = ImmutableSet.of(StageSpec.builder("n1", NODE).build(), StageSpec.builder("n2", NODE).build(), StageSpec.builder("condition1", CONDITION1).build(), StageSpec.builder("n3", NODE).build(), StageSpec.builder("condition2", CONDITION2).build(), StageSpec.builder("condition3", CONDITION3).build());
Set<Connection> connections = ImmutableSet.of(new Connection("n1", "condition1"), new Connection("condition1", "condition2", true), new Connection("condition1", "condition3", false), new Connection("condition2", "n2", true), new Connection("condition3", "n3", true));
Set<String> pluginTypes = ImmutableSet.of(NODE.getType(), REDUCE.getType(), Constants.Connector.PLUGIN_TYPE, CONDITION1.getType(), CONDITION2.getType(), CONDITION3.getType(), CONDITION4.getType(), CONDITION5.getType());
Set<String> reduceTypes = ImmutableSet.of(REDUCE.getType());
Set<String> emptySet = ImmutableSet.of();
PipelinePlanner planner = new PipelinePlanner(pluginTypes, reduceTypes, emptySet, emptySet, emptySet);
PipelineSpec pipelineSpec = PipelineSpec.builder().addStages(stageSpecs).addConnections(connections).build();
Map<String, PipelinePhase> phases = new HashMap<>();
/*
n1--condition1.connector
*/
PipelinePhase phase1 = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("n1", NODE).build()).addStage(StageSpec.builder("condition1.connector", connectorSpec("condition1.connector", Constants.Connector.SINK_TYPE)).build()).addConnection("n1", "condition1.connector").build();
Dag controlPhaseDag = new Dag(ImmutableSet.of(new Connection("n1", "condition1")));
String phase1Name = PipelinePlanner.getPhaseName(controlPhaseDag);
phases.put(phase1Name, phase1);
/*
condition1
*/
PipelinePhase phase2 = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("condition1", CONDITION1).build()).build();
String phase2Name = "condition1";
phases.put(phase2Name, phase2);
/*
condition2
*/
PipelinePhase phase3 = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("condition2", CONDITION2).build()).build();
String phase3Name = "condition2";
phases.put(phase3Name, phase3);
/*
condition3
*/
PipelinePhase phase4 = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("condition3", CONDITION3).build()).build();
String phase4Name = "condition3";
phases.put(phase4Name, phase4);
/*
condition1.connector -- n2
*/
PipelinePhase phase5 = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("condition1.connector", connectorSpec("condition1.connector", Constants.Connector.SOURCE_TYPE)).build()).addStage(StageSpec.builder("n2", NODE).build()).addConnection("condition1.connector", "n2").build();
controlPhaseDag = new Dag(ImmutableSet.of(new Connection("condition2", "n2")));
String phase5Name = PipelinePlanner.getPhaseName(controlPhaseDag);
phases.put(phase5Name, phase5);
/*
condition1.connector -- n3
*/
PipelinePhase phase6 = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("condition1.connector", connectorSpec("condition1.connector", Constants.Connector.SOURCE_TYPE)).build()).addStage(StageSpec.builder("n3", NODE).build()).addConnection("condition1.connector", "n3").build();
controlPhaseDag = new Dag(ImmutableSet.of(new Connection("condition3", "n3")));
String phase6Name = PipelinePlanner.getPhaseName(controlPhaseDag);
phases.put(phase6Name, phase6);
Set<Connection> phaseConnections = new HashSet<>();
phaseConnections.add(new Connection(phase1Name, phase2Name));
phaseConnections.add(new Connection(phase2Name, phase3Name, true));
phaseConnections.add(new Connection(phase2Name, phase4Name, false));
phaseConnections.add(new Connection(phase3Name, phase5Name, true));
phaseConnections.add(new Connection(phase4Name, phase6Name, true));
PipelinePlan expected = new PipelinePlan(phases, phaseConnections);
PipelinePlan actual = planner.plan(pipelineSpec);
Assert.assertEquals(expected, actual);
}
use of io.cdap.cdap.etl.proto.Connection in project cdap by cdapio.
the class PipelinePlannerTest method testMultipleActionConditions.
@Test
public void testMultipleActionConditions() {
/*
|-- n2 -- a3
|-- a1 --| |-- n0 -- n1 -- c1 --| |-- a5 --|
a0--| |-- c0 --| |-- n3 -- c2 -- n8 -- a4 --| |-- a7
|-- a2 --| | |-- a6 --|
| |-- n4 -- n5 -- c4 -- c5 -- n9
|-- c3 --|
| |-- a8
|-- n6 -- n7 --|
|-- a9
*/
Set<StageSpec> stageSpecs = ImmutableSet.of(StageSpec.builder("a0", ACTION).build(), StageSpec.builder("a1", ACTION).build(), StageSpec.builder("a2", ACTION).build(), StageSpec.builder("a3", ACTION).build(), StageSpec.builder("a4", ACTION).build(), StageSpec.builder("a5", ACTION).build(), StageSpec.builder("a6", ACTION).build(), StageSpec.builder("a7", ACTION).build(), StageSpec.builder("a8", ACTION).build(), StageSpec.builder("a9", ACTION).build(), StageSpec.builder("c0", CONDITION).build(), StageSpec.builder("c1", CONDITION).build(), StageSpec.builder("c2", CONDITION).build(), StageSpec.builder("c3", CONDITION).build(), StageSpec.builder("c4", CONDITION).build(), StageSpec.builder("c5", CONDITION).build(), StageSpec.builder("n0", NODE).build(), StageSpec.builder("n1", NODE).build(), StageSpec.builder("n2", NODE).build(), StageSpec.builder("n3", NODE).build(), StageSpec.builder("n4", NODE).build(), StageSpec.builder("n5", NODE).build(), StageSpec.builder("n6", NODE).build(), StageSpec.builder("n7", NODE).build(), StageSpec.builder("n8", NODE).build(), StageSpec.builder("n9", NODE).build());
Set<Connection> connections = ImmutableSet.of(new Connection("a0", "a1"), new Connection("a0", "a2"), new Connection("a1", "c0"), new Connection("a2", "c0"), new Connection("c0", "n0", true), new Connection("c0", "c3", false), new Connection("n0", "n1"), new Connection("n1", "c1"), new Connection("c1", "n2", true), new Connection("c1", "n3", false), new Connection("n2", "a3"), new Connection("n3", "c2"), new Connection("c2", "n8", true), new Connection("n8", "a4"), new Connection("a4", "a5"), new Connection("a4", "a6"), new Connection("a5", "a7"), new Connection("a6", "a7"), new Connection("c3", "n4", true), new Connection("c3", "n6", false), new Connection("n4", "n5"), new Connection("n5", "c4"), new Connection("c4", "c5", true), new Connection("c5", "n9", true), new Connection("n6", "n7"), new Connection("n7", "a8"), new Connection("n7", "a9"));
Set<String> pluginTypes = ImmutableSet.of(NODE.getType(), ACTION.getType(), Constants.Connector.PLUGIN_TYPE, CONDITION.getType());
Set<String> reduceTypes = ImmutableSet.of();
Set<String> emptySet = ImmutableSet.of();
Set<String> actionTypes = ImmutableSet.of(ACTION.getType());
PipelinePlanner planner = new PipelinePlanner(pluginTypes, reduceTypes, emptySet, actionTypes, emptySet);
PipelineSpec pipelineSpec = PipelineSpec.builder().addStages(stageSpecs).addConnections(connections).build();
Map<String, PipelinePhase> phases = new HashMap<>();
Set<Connection> phaseConnections = new HashSet<>();
phaseConnections.add(new Connection("a0", "a1"));
phaseConnections.add(new Connection("a0", "a2"));
phaseConnections.add(new Connection("a1", "c0"));
phaseConnections.add(new Connection("a2", "c0"));
phaseConnections.add(new Connection("a0", "a1"));
phaseConnections.add(new Connection("a0", "a1"));
phaseConnections.add(new Connection("a4", "a5"));
phaseConnections.add(new Connection("a4", "a6"));
phaseConnections.add(new Connection("a5", "a7"));
phaseConnections.add(new Connection("a6", "a7"));
phaseConnections.add(new Connection("c0", "c3", false));
phaseConnections.add(new Connection("c4", "c5", true));
for (String action : ImmutableList.of("a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9")) {
phases.put(action, PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder(action, ACTION).build()).build());
}
for (String condition : ImmutableList.of("c0", "c1", "c2", "c3", "c4", "c5")) {
phases.put(condition, PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder(condition, CONDITION).build()).build());
}
// [c0] --true--> [c0 -- n0 -- n1 -- c1]
PipelinePhase phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("n0", NODE).build()).addStage(StageSpec.builder("n1", NODE).build()).addStage(StageSpec.builder("c1.connector", connectorSpec("c1.connector", Constants.Connector.SINK_TYPE)).build()).addConnection("n0", "n1").addConnection("n1", "c1.connector").build();
Dag controlPhaseDag = new Dag(ImmutableSet.of(new Connection("c0", "n0"), new Connection("n0", "n1"), new Connection("n1", "c1")));
String phaseName = PipelinePlanner.getPhaseName(controlPhaseDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c0", phaseName, true));
// [c0 -- n0 -- n1 -- c1] --> [c1]
phaseConnections.add(new Connection(phaseName, "c1"));
// [c1] --true--> [c1 -- n2 -- a3]
phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("c1.connector", connectorSpec("c1.connector", Constants.Connector.SOURCE_TYPE)).build()).addStage(StageSpec.builder("n2", NODE).build()).addConnection("c1.connector", "n2").build();
controlPhaseDag = new Dag(ImmutableSet.of(new Connection("c1", "n2"), new Connection("n2", "a3")));
phaseName = PipelinePlanner.getPhaseName(controlPhaseDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c1", phaseName, true));
// [c1 -- n2 -- a3] -- [a3]
phaseConnections.add(new Connection(phaseName, "a3"));
// [c1] --false--> [c1 -- n3 -- c2]
phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("c1.connector", connectorSpec("c1.connector", Constants.Connector.SOURCE_TYPE)).build()).addStage(StageSpec.builder("n3", NODE).build()).addStage(StageSpec.builder("c2.connector", connectorSpec("c2.connector", Constants.Connector.SINK_TYPE)).build()).addConnection("c1.connector", "n3").addConnection("n3", "c2.connector").build();
controlPhaseDag = new Dag(ImmutableSet.of(new Connection("c1", "n3"), new Connection("n3", "c2")));
phaseName = PipelinePlanner.getPhaseName(controlPhaseDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c1", phaseName, false));
// [c1.connector -- n3 -- c2.connector] --> [c2]
phaseConnections.add(new Connection(phaseName, "c2"));
// [c2] --true--> [c2 -- n8 -- a4]
phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("c2.connector", connectorSpec("c2.connector", Constants.Connector.SOURCE_TYPE)).build()).addStage(StageSpec.builder("n8", NODE).build()).addConnection("c2.connector", "n8").build();
controlPhaseDag = new Dag(ImmutableSet.of(new Connection("c2", "n8"), new Connection("n8", "a4")));
phaseName = PipelinePlanner.getPhaseName(controlPhaseDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c2", phaseName, true));
// [c2 -- n8 -- a4] --> [a4]
phaseConnections.add(new Connection(phaseName, "a4"));
// [c3] --true--> [c3 -- n4 -- n5 -- c4]
phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("n4", NODE).build()).addStage(StageSpec.builder("n5", NODE).build()).addStage(StageSpec.builder("c4.connector", connectorSpec("c4.connector", Constants.Connector.SINK_TYPE)).build()).addConnection("n4", "n5").addConnection("n5", "c4.connector").build();
controlPhaseDag = new Dag(ImmutableSet.of(new Connection("c3", "n4"), new Connection("n4", "n5"), new Connection("n5", "c4")));
phaseName = PipelinePlanner.getPhaseName(controlPhaseDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c3", phaseName, true));
// [c3 -- n4 -- n5 -- c4] --> c4
phaseConnections.add(new Connection(phaseName, "c4"));
// [c5] --true--> [c5 (via c4.connector) -- n9]
phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("c4.connector", connectorSpec("c4.connector", Constants.Connector.SOURCE_TYPE)).build()).addStage(StageSpec.builder("n9", NODE).build()).addConnection("c4.connector", "n9").build();
controlPhaseDag = new Dag(ImmutableSet.of(new Connection("c5", "n9")));
phaseName = PipelinePlanner.getPhaseName(controlPhaseDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c5", phaseName, true));
// [c3] --false--> [c3 -- n6 -- n7 -- a8, a9]
phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("n6", NODE).build()).addStage(StageSpec.builder("n7", NODE).build()).addConnection("n6", "n7").build();
controlPhaseDag = new Dag(ImmutableSet.of(new Connection("c3", "n6"), new Connection("n6", "n7"), new Connection("n7", "a8"), new Connection("n7", "a9")));
phaseName = PipelinePlanner.getPhaseName(controlPhaseDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c3", phaseName, false));
// [c3 -- n6 -- n7 -- a8, a9] --> [a8]
// [c3 -- n6 -- n7 -- a8, a9] --> [a9]
phaseConnections.add(new Connection(phaseName, "a8"));
phaseConnections.add(new Connection(phaseName, "a9"));
PipelinePlan expected = new PipelinePlan(phases, phaseConnections);
PipelinePlan actual = planner.plan(pipelineSpec);
Assert.assertEquals(expected, actual);
}
use of io.cdap.cdap.etl.proto.Connection in project cdap by cdapio.
the class PipelinePlannerTest method testConditionsOnBranches.
@Test
public void testConditionsOnBranches() {
/*
|-- true --> n2
|--> c1 --|
n1 --| |-- false --> n3
|
| |-- true --> n5
|--> n4 --> c2 --|
|-- false --> n6
*/
Set<StageSpec> stageSpecs = ImmutableSet.of(StageSpec.builder("c1", CONDITION).build(), StageSpec.builder("c2", CONDITION).build(), StageSpec.builder("n1", NODE).build(), StageSpec.builder("n2", NODE).build(), StageSpec.builder("n3", NODE).build(), StageSpec.builder("n4", NODE).build(), StageSpec.builder("n5", NODE).build(), StageSpec.builder("n6", NODE).build());
Set<Connection> connections = ImmutableSet.of(new Connection("n1", "c1"), new Connection("n1", "n4"), new Connection("c1", "n2", true), new Connection("c1", "n3", false), new Connection("n4", "c2"), new Connection("c2", "n5", true), new Connection("c2", "n6", false));
Set<String> pluginTypes = ImmutableSet.of(NODE.getType(), Constants.Connector.PLUGIN_TYPE, CONDITION.getType());
Set<String> reduceTypes = ImmutableSet.of();
PipelinePlanner planner = new PipelinePlanner(pluginTypes, reduceTypes, Collections.<String>emptySet(), Collections.<String>emptySet(), Collections.<String>emptySet());
PipelineSpec pipelineSpec = PipelineSpec.builder().addStages(stageSpecs).addConnections(connections).build();
Map<String, PipelinePhase> phases = new HashMap<>();
Set<Connection> phaseConnections = new HashSet<>();
for (String condition : ImmutableList.of("c1", "c2")) {
phases.put(condition, PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder(condition, CONDITION).build()).build());
}
PipelinePhase phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("n1", NODE).build()).addStage(StageSpec.builder("n4", NODE).build()).addStage(StageSpec.builder("c1.connector", connectorSpec("c1.connector", Constants.Connector.SINK_TYPE)).build()).addStage(StageSpec.builder("c2.connector", connectorSpec("c2.connector", Constants.Connector.SINK_TYPE)).build()).addConnection("n1", "n4").addConnection("n1", "c1.connector").addConnection("n4", "c2.connector").build();
Dag nonConnectorDag = new Dag(ImmutableSet.of(new Connection("n1", "n4"), new Connection("n1", "c1"), new Connection("n4", "c2")));
String phaseName = PipelinePlanner.getPhaseName(nonConnectorDag);
phases.put(phaseName, phase);
// [n1, n4, c1, c2] -> [c1]
phaseConnections.add(new Connection(phaseName, "c1"));
// [n1, n4, c1, c2] -> [c2]
phaseConnections.add(new Connection(phaseName, "c2"));
// [c1] -- true --> [c1 -> n2]
phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("c1.connector", connectorSpec("c1.connector", Connector.SOURCE_TYPE)).build()).addStage(StageSpec.builder("n2", NODE).build()).addConnection("c1.connector", "n2").build();
nonConnectorDag = new Dag(ImmutableSet.of(new Connection("c1", "n2")));
phaseName = PipelinePlanner.getPhaseName(nonConnectorDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c1", phaseName, true));
// [c1] -- false --> [c1 -> n3]
phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("c1.connector", connectorSpec("c1.connector", Connector.SOURCE_TYPE)).build()).addStage(StageSpec.builder("n3", NODE).build()).addConnection("c1.connector", "n3").build();
nonConnectorDag = new Dag(ImmutableSet.of(new Connection("c1", "n3")));
phaseName = PipelinePlanner.getPhaseName(nonConnectorDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c1", phaseName, false));
// [c2] -- true --> [c2 -> n5]
phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("c2.connector", connectorSpec("c2.connector", Connector.SOURCE_TYPE)).build()).addStage(StageSpec.builder("n5", NODE).build()).addConnection("c2.connector", "n5").build();
nonConnectorDag = new Dag(ImmutableSet.of(new Connection("c2", "n5")));
phaseName = PipelinePlanner.getPhaseName(nonConnectorDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c2", phaseName, true));
// [c2] -- false --> [c2 -> n6]
phase = PipelinePhase.builder(pluginTypes).addStage(StageSpec.builder("c2.connector", connectorSpec("c2.connector", Connector.SOURCE_TYPE)).build()).addStage(StageSpec.builder("n6", NODE).build()).addConnection("c2.connector", "n6").build();
nonConnectorDag = new Dag(ImmutableSet.of(new Connection("c2", "n6")));
phaseName = PipelinePlanner.getPhaseName(nonConnectorDag);
phases.put(phaseName, phase);
phaseConnections.add(new Connection("c2", phaseName, false));
PipelinePlan expected = new PipelinePlan(phases, phaseConnections);
PipelinePlan actual = planner.plan(pipelineSpec);
Assert.assertEquals(expected, actual);
}
use of io.cdap.cdap.etl.proto.Connection in project cdap by cdapio.
the class ConnectorDagTest method testSimpleCondition.
@Test
public void testSimpleCondition() {
/*
file - csv - condition - sink1
|
|-------sink2
*/
Set<Connection> connections = ImmutableSet.of(new Connection("file", "csv"), new Connection("csv", "condition"), new Connection("condition", "sink1"), new Connection("condition", "sink2"));
Set<String> conditions = Collections.singleton("condition");
Set<String> reduceNodes = new HashSet<>();
Set<String> isolationNodes = new HashSet<>();
Set<String> multiPortNodes = new HashSet<>();
Set<Dag> actual = PipelinePlanner.split(connections, conditions, reduceNodes, isolationNodes, EMPTY_ACTIONS, multiPortNodes, EMPTY_CONNECTORS);
Dag dag1 = new Dag(ImmutableSet.of(new Connection("file", "csv"), new Connection("csv", "condition")));
Dag dag2 = new Dag(ImmutableSet.of(new Connection("condition", "sink1")));
Dag dag3 = new Dag(ImmutableSet.of(new Connection("condition", "sink2")));
Set<Dag> expected = ImmutableSet.of(dag1, dag2, dag3);
Assert.assertEquals(actual, expected);
}
Aggregations