Search in sources :

Example 1 with SyncClient

use of edu.iu.harp.client.SyncClient in project twister2 by DSC-SPIDAL.

the class HarpWorker method execute.

@Override
public void execute(Config config, JobAPI.Job job, IWorkerController workerController, IPersistentVolume persistentVolume, IVolatileVolume volatileVolume) {
    int workerID = workerController.getWorkerInfo().getWorkerID();
    List<JobMasterAPI.WorkerInfo> workersList = null;
    try {
        workersList = workerController.getAllWorkers();
    } catch (TimeoutException timeoutException) {
        LOG.log(Level.SEVERE, timeoutException.getMessage(), timeoutException);
        return;
    }
    LOG.info(String.format("Worker %s starting with %d workers, " + "after waiting for all to start. \n %s", workerID, workersList.size(), workersList.toString()));
    JobMasterAPI.WorkerInfo workerInfo = workerController.getWorkerInfo();
    // Building Harp Specific parameters
    Map<String, Integer> rackToIntegerMap = this.getRackToIntegerMap(workersList);
    LinkedList<Integer> nodeRackIDs = new LinkedList<>(rackToIntegerMap.values());
    // todo check the suitability
    int noOfPhysicalNodes = nodeRackIDs.size();
    Map<Integer, List<String>> nodesOfRackMap = this.getNodesOfRackMap(workersList, rackToIntegerMap);
    Workers workers = new Workers(nodesOfRackMap, nodeRackIDs, noOfPhysicalNodes, workerID);
    DataMap dataMap = new DataMap();
    int harpPort = Constant.DEFAULT_WORKER_POART_BASE + workerID;
    Server server;
    try {
        server = new Server(workerInfo.getWorkerIP(), harpPort, new EventQueue(), dataMap, workers);
    } catch (Exception e) {
        LOG.log(Level.SEVERE, String.format("Failed to start harp server %s:%d " + "on twister worker %s:%d", workerInfo.getWorkerIP(), harpPort, workerInfo.getWorkerIP(), workerInfo.getPort()), e);
        throw new RuntimeException("Failed to start Harp Server");
    }
    SyncClient syncClient = new SyncClient(workers);
    LOG.info("Starting Harp Sync client");
    syncClient.start();
    LOG.info(String.format("Starting harp server on port : %d", harpPort));
    server.start();
    LOG.info(String.format("Harp server started. %s:%d " + "on twister worker %s:%d", workerInfo.getWorkerIP(), harpPort, workerInfo.getWorkerIP(), workerInfo.getPort()));
    try {
        LOG.info("Trying master barrier");
        doMasterBarrier("start-worker", "handshake", dataMap, workers);
        LOG.info("Master barrier done");
    } catch (IOException e) {
        LOG.log(Level.SEVERE, "Failed to do master barrier", e);
        server.stop();
        syncClient.stop();
        throw new RuntimeException("Failed to do master barrier");
    }
    // call executeHarp that will be coded by user
    this.executeHarp(config, workerID, workerController.getNumberOfWorkers(), workerController, persistentVolume, volatileVolume, dataMap, workers);
    // stopping servers, releasing resources
    LOG.info("Execution completed. Shutting harp Sync Client down....");
    syncClient.stop();
    LOG.info("Harp Sync Client stopped.");
    LOG.info("Shutting harp server down....");
    server.stop(true);
    LOG.info("Harp server stopped.");
}
Also used : Server(edu.iu.harp.server.Server) IOException(java.io.IOException) SyncClient(edu.iu.harp.client.SyncClient) LinkedList(java.util.LinkedList) EventQueue(edu.iu.harp.io.EventQueue) IOException(java.io.IOException) TimeoutException(edu.iu.dsc.tws.api.exceptions.TimeoutException) DataMap(edu.iu.harp.io.DataMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JobMasterAPI(edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI) Workers(edu.iu.harp.worker.Workers) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) TimeoutException(edu.iu.dsc.tws.api.exceptions.TimeoutException)

Aggregations

TimeoutException (edu.iu.dsc.tws.api.exceptions.TimeoutException)1 JobMasterAPI (edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI)1 SyncClient (edu.iu.harp.client.SyncClient)1 DataMap (edu.iu.harp.io.DataMap)1 EventQueue (edu.iu.harp.io.EventQueue)1 Server (edu.iu.harp.server.Server)1 Workers (edu.iu.harp.worker.Workers)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1