Search in sources :

Example 1 with ExecutionGraph

use of edu.iu.dsc.tws.task.executiongraph.ExecutionGraph in project twister2 by DSC-SPIDAL.

the class SimpleTGraphExample method init.

/**
 * Init method to submit the task to the executor
 */
public void init(Config cfg, int containerId, ResourcePlan plan) {
    LOG.log(Level.INFO, "Starting the example with container id: " + plan.getThisId());
    taskExecutor = new TaskExecutorFixedThread();
    this.status = Status.INIT;
    TaskPlan taskPlan = Utils.createTaskPlan(cfg, plan);
    TWSNetwork network = new TWSNetwork(cfg, taskPlan);
    TWSCommunication channel = network.getDataFlowTWSCommunication();
    Set<Integer> sources = new HashSet<>();
    sources.add(0);
    int destination = 1;
    Map<String, Object> newCfg = new HashMap<>();
    LinkedQueue<Message> pongQueue = new LinkedQueue<Message>();
    taskExecutor.registerQueue(0, pongQueue);
    direct = channel.direct(newCfg, MessageType.OBJECT, 0, sources, destination, new SimpleTGraphExample.PingPongReceive());
    taskExecutor.initCommunication(channel, direct);
    TMapper tMapper = new TMapper("1");
    TReducer tReducer = new TReducer("2");
    TShuffler tShuffler = new TShuffler("3");
    TReducer tMergeFinal = new TReducer("4");
    // Add the real input data files in the array list...
    tMapper.addInputData("mapper1", new ArrayList<>());
    tMapper.addInputData("mapper2", new ArrayList<>());
    // Add the real input data files in the array list...
    tReducer.addInputData("reducer1", new ArrayList<>());
    tReducer.addInputData("reducer2", new ArrayList<>());
    // Add the real input data files in the array list...
    tShuffler.addInputData("shuffler1", new ArrayList<>());
    tShuffler.addInputData("shuffler2", new ArrayList<>());
    // Add the real input data files in the array list...
    tMergeFinal.addInputData("merge1", new ArrayList<>());
    tMergeFinal.addInputData("merge2", new ArrayList<>());
    // Mention the output data files to be generated in the array list...
    tMapper.addOutputData("mapperOut1", new ArrayList<>());
    tMapper.addOutputData("mapperOut2", new ArrayList<>());
    if (taskGraphFlag >= 0) {
        // just for verification (replace with proper value)
        /*dataflowTaskGraphGenerator = new DataflowTaskGraphGenerator()
          .generateTGraph(tMapper, tShuffler, new DataflowOperation("Map"))
          .generateTGraph(tMapper, tReducer, new DataflowOperation("Shuffle"))
          .generateTGraph(tShuffler, tReducerFinal, new DataflowOperation("finalReduce"))
          .generateTGraph(tReducer, tReducerFinal, new DataflowOperation("finalReduce"));*/
        dataflowTaskGraphGenerator = new DataflowTaskGraphGenerator().generateTGraph(tMapper).generateTGraph(tMapper, tReducer, new DataflowOperation("Reduce")).generateTGraph(tMapper, tShuffler, new DataflowOperation("Shuffle")).generateTGraph(tReducer, tMergeFinal, new DataflowOperation("Merge1")).generateTGraph(tShuffler, tMergeFinal, new DataflowOperation("Merge2"));
        LOG.info("Generated Dataflow Task Graph Vertices:" + dataflowTaskGraphGenerator.getTGraph().getTaskVertexSet());
        if (dataflowTaskGraphGenerator != null) {
            dataflowTGraphParser = new DataflowTGraphParser(dataflowTaskGraphGenerator);
            parsedTaskSet = dataflowTGraphParser.dataflowTGraphParseAndSchedule();
            LOG.info("parsed task set:" + parsedTaskSet);
        }
        // parsedTaskSet = executionGraph.parseTaskGraph(dataflowTaskGraphGenerator);
        if (!parsedTaskSet.isEmpty()) {
            // newly added for testing
            executionGraph = new ExecutionGraph(parsedTaskSet);
            String message = executionGraph.generateExecutionGraph(containerId);
            // String message = executionGraph.generateExecutionGraph(containerId, parsedTaskSet);
            /*TaskExecutorFixedThread taskExecutionGraph =
            executionGraph.generateExecutionGraph(containerId, parsedTaskSet);*/
            LOG.info(message);
        }
    }
// It removes only the first tax vertex in the parsedTaskSet.
// dataflowTaskGraphGenerator.removeTaskVertex(parsedTaskSet.iterator().next());
// It is getting concurrent modification exception...!
/*for (TaskGraphMapper processedTask : parsedTaskSet) {
      dataflowTaskGraphGenerator.removeTaskVertex(processedTask);
    }*/
}
Also used : Message(edu.iu.dsc.tws.task.api.Message) TaskExecutorFixedThread(edu.iu.dsc.tws.task.core.TaskExecutorFixedThread) HashMap(java.util.HashMap) TWSCommunication(edu.iu.dsc.tws.comms.core.TWSCommunication) TaskPlan(edu.iu.dsc.tws.comms.core.TaskPlan) TWSNetwork(edu.iu.dsc.tws.comms.core.TWSNetwork) LinkedQueue(edu.iu.dsc.tws.task.api.LinkedQueue) DataflowTaskGraphGenerator(edu.iu.dsc.tws.task.taskgraphbuilder.DataflowTaskGraphGenerator) DataflowTGraphParser(edu.iu.dsc.tws.task.taskgraphbuilder.DataflowTGraphParser) DataflowOperation(edu.iu.dsc.tws.task.taskgraphbuilder.DataflowOperation) ExecutionGraph(edu.iu.dsc.tws.task.executiongraph.ExecutionGraph) HashSet(java.util.HashSet)

Aggregations

TWSCommunication (edu.iu.dsc.tws.comms.core.TWSCommunication)1 TWSNetwork (edu.iu.dsc.tws.comms.core.TWSNetwork)1 TaskPlan (edu.iu.dsc.tws.comms.core.TaskPlan)1 LinkedQueue (edu.iu.dsc.tws.task.api.LinkedQueue)1 Message (edu.iu.dsc.tws.task.api.Message)1 TaskExecutorFixedThread (edu.iu.dsc.tws.task.core.TaskExecutorFixedThread)1 ExecutionGraph (edu.iu.dsc.tws.task.executiongraph.ExecutionGraph)1 DataflowOperation (edu.iu.dsc.tws.task.taskgraphbuilder.DataflowOperation)1 DataflowTGraphParser (edu.iu.dsc.tws.task.taskgraphbuilder.DataflowTGraphParser)1 DataflowTaskGraphGenerator (edu.iu.dsc.tws.task.taskgraphbuilder.DataflowTaskGraphGenerator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1