Search in sources :

Example 6 with UploaderException

use of edu.iu.dsc.tws.api.scheduler.UploaderException in project twister2 by DSC-SPIDAL.

the class S3Uploader method uploadPackage.

@Override
public URI uploadPackage(String sourceLocation) throws UploaderException {
    localJobPackFile = sourceLocation + "/" + SchedulerContext.jobPackageFileName(config);
    s3File = S3Context.s3BucketName(config) + "/" + JobUtils.createJobPackageFileName(jobID);
    long linkExpDur = S3Context.linkExpirationDuration(config);
    String cmd = String.format("aws s3 presign %s --expires-in %s", s3File, linkExpDur);
    LOG.fine("cmd for s3 URL Generation: " + cmd);
    String[] fullCmd = { "bash", "-c", cmd };
    String url;
    Process p = null;
    try {
        p = Runtime.getRuntime().exec(fullCmd);
        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
        url = reader.readLine();
        p.waitFor();
    } catch (IOException e) {
        throw new UploaderException("Exception when executing the command: " + cmd, e);
    } catch (InterruptedException e) {
        throw new UploaderException("Exception when waiting the script to complete: " + cmd, e);
    }
    int exitCode = p.exitValue();
    if (exitCode == 0) {
        LOG.fine("Job Package Download URL: " + url);
        try {
            URI uri = new URI(url);
            // start uploader thread
            start();
            // if this is a resubmitted job, wait for the transfer to complete
            if (CheckpointingContext.startingFromACheckpoint(config)) {
                waitComplete();
            }
            return uri;
        } catch (URISyntaxException e) {
            throw new UploaderException("Can not generate URI for download link: " + url, e);
        }
    } else {
        String failMsg = String.format("Some error occurred when presigning job package %s at s3: %s", localJobPackFile, s3File);
        throw new UploaderException(failMsg);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) UploaderException(edu.iu.dsc.tws.api.scheduler.UploaderException) URI(java.net.URI)

Example 7 with UploaderException

use of edu.iu.dsc.tws.api.scheduler.UploaderException in project twister2 by DSC-SPIDAL.

the class UploaderToWebServers method uploadPackage.

@Override
public URI uploadPackage(String sourceLocation) throws UploaderException {
    localJobPackageFile = sourceLocation + File.separator + SchedulerContext.jobPackageFileName(config);
    // start uploader thread
    start();
    // partial files may be served to workers
    if (CheckpointingContext.startingFromACheckpoint(config)) {
        // wait for the uploaders to start
        while (webServerPodNames.size() != uploadersToWebServers.size()) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
            // ignore the exception
            }
        }
        LOG.fine("Wait uploading to web servers to finish ...");
        complete();
        LOG.info("Uploading to web servers finished ...");
    }
    String uri = KubernetesContext.uploaderWebServer(config) + "/" + JobUtils.createJobPackageFileName(jobID);
    try {
        return new URI(uri);
    } catch (URISyntaxException e) {
        LOG.log(Level.SEVERE, "Can not generate URI for uploader web server: " + uri, e);
        throw new UploaderException("Can not generate URI for download link: " + uri, e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) UploaderException(edu.iu.dsc.tws.api.scheduler.UploaderException) URI(java.net.URI)

Aggregations

UploaderException (edu.iu.dsc.tws.api.scheduler.UploaderException)7 URI (java.net.URI)6 URISyntaxException (java.net.URISyntaxException)5 File (java.io.File)3 IUploader (edu.iu.dsc.tws.api.scheduler.IUploader)2 IOException (java.io.IOException)2 ILauncher (edu.iu.dsc.tws.api.scheduler.ILauncher)1 LauncherException (edu.iu.dsc.tws.api.scheduler.LauncherException)1 LocalFileSystemUploader (edu.iu.dsc.tws.rsched.uploaders.localfs.LocalFileSystemUploader)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Path (java.nio.file.Path)1