Search in sources :

Example 1 with CommandTaskDone

use of es.bsc.compss.nio.commands.CommandTaskDone in project compss by bsc-wdc.

the class NIOWorker method sendTaskDone.

public void sendTaskDone(NIOTask nt, boolean successful) {
    int taskID = nt.getJobId();
    // Notify task done
    int retries = 0;
    Connection c = null;
    while (retries < MAX_RETRIES) {
        try {
            c = TM.startConnection(masterNode);
            if (c == null) {
                throw new Exception("Nullable connection");
            }
            break;
        } catch (Exception e) {
            if (retries >= MAX_RETRIES) {
                WORKER_LOGGER.error("Exception sending Task notification", e);
                return;
            } else {
                try {
                    Random randomGenerator = new Random(System.currentTimeMillis());
                    int waitNanos = (int) (50000 * randomGenerator.nextFloat());
                    Thread.sleep(0, waitNanos);
                } catch (InterruptedException e1) {
                    Thread.currentThread().interrupt();
                }
                retries++;
            }
        }
    }
    NIOTaskResult tr = new NIOTaskResult(taskID, nt.getParams());
    if (WORKER_LOGGER.isDebugEnabled()) {
        WORKER_LOGGER.debug("TASK RESULT FOR TASK ID " + taskID);
        WORKER_LOGGER.debug(tr);
    }
    CommandTaskDone cmd = new CommandTaskDone(this, tr, successful);
    c.sendCommand(cmd);
    // Check that output files already exists. If not exists generate an empty one.
    String taskFileOutName = workingDir + File.separator + "jobs" + File.separator + "job" + nt.getJobId() + "_" + nt.getHist() + ".out";
    String taskFileErrName = workingDir + File.separator + "jobs" + File.separator + "job" + nt.getJobId() + "_" + nt.getHist() + ".err";
    File fout = new File(taskFileOutName);
    if (!fout.exists()) {
        String errorMessage = "Autogenerated Empty file. An error was produced before generating any log in the stdout";
        try (FileOutputStream outputStream = new FileOutputStream(fout)) {
            outputStream.write(errorMessage.getBytes());
            outputStream.close();
        } catch (IOException ioe) {
            WORKER_LOGGER.error("IOException writing worker output file: " + fout, ioe);
        }
    }
    File ferr = new File(taskFileErrName);
    if (!ferr.exists()) {
        String errorMessage = "Autogenerated Empty file. An error was produced before generating any log in the stderr";
        try (FileOutputStream errorStream = new FileOutputStream(ferr)) {
            errorStream.write(errorMessage.getBytes());
            errorStream.close();
        } catch (IOException ioe) {
            WORKER_LOGGER.error("IOException writing worker error file: " + ferr, ioe);
        }
    }
    if (isWorkerDebugEnabled) {
        WORKER_LOGGER.debug("Sending file " + taskFileOutName);
        c.sendDataFile(taskFileOutName);
        WORKER_LOGGER.debug("Sending file " + taskFileErrName);
        c.sendDataFile(taskFileErrName);
    } else {
        if (!successful) {
            WORKER_LOGGER.debug("Sending file " + taskFileOutName);
            c.sendDataFile(taskFileOutName);
            WORKER_LOGGER.debug("Sending file " + taskFileErrName);
            c.sendDataFile(taskFileErrName);
        }
    }
    c.finishConnection();
    WORKER_LOGGER.debug("Task " + taskID + " send task done with " + retries + " retries");
}
Also used : Random(java.util.Random) NIOTaskResult(es.bsc.compss.nio.NIOTaskResult) CommandTaskDone(es.bsc.compss.nio.commands.CommandTaskDone) FileOutputStream(java.io.FileOutputStream) Connection(es.bsc.comm.Connection) IOException(java.io.IOException) File(java.io.File) StorageException(storage.StorageException) SerializedObjectException(es.bsc.compss.nio.exceptions.SerializedObjectException) IOException(java.io.IOException) CommException(es.bsc.comm.exceptions.CommException) InitializationException(es.bsc.compss.nio.worker.exceptions.InitializationException) AtomicMoveNotSupportedException(java.nio.file.AtomicMoveNotSupportedException) InvalidMapException(es.bsc.compss.nio.worker.exceptions.InvalidMapException)

Aggregations

Connection (es.bsc.comm.Connection)1 CommException (es.bsc.comm.exceptions.CommException)1 NIOTaskResult (es.bsc.compss.nio.NIOTaskResult)1 CommandTaskDone (es.bsc.compss.nio.commands.CommandTaskDone)1 SerializedObjectException (es.bsc.compss.nio.exceptions.SerializedObjectException)1 InitializationException (es.bsc.compss.nio.worker.exceptions.InitializationException)1 InvalidMapException (es.bsc.compss.nio.worker.exceptions.InvalidMapException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 AtomicMoveNotSupportedException (java.nio.file.AtomicMoveNotSupportedException)1 Random (java.util.Random)1 StorageException (storage.StorageException)1