Search in sources :

Example 1 with ResourceAllocator

use of edu.iu.dsc.tws.rsched.core.ResourceAllocator in project twister2 by DSC-SPIDAL.

the class Twister2Submitter method terminateJob.

/**
 * Submit a basic job with only container and communications
 */
public static void terminateJob(String jobName, Config config) {
    // launch the luancher
    ResourceAllocator resourceAllocator = new ResourceAllocator();
    resourceAllocator.terminateJob(jobName, config);
}
Also used : ResourceAllocator(edu.iu.dsc.tws.rsched.core.ResourceAllocator)

Example 2 with ResourceAllocator

use of edu.iu.dsc.tws.rsched.core.ResourceAllocator in project twister2 by DSC-SPIDAL.

the class Twister2Submitter method restartJob.

/**
 * Restart a Twister2 job
 */
public static Twister2JobState restartJob(String jobID, Config config) {
    // job package filename from failed submission
    String prevJobDir = FsContext.uploaderJobDirectory(config) + File.separator + jobID;
    String jobPackage = prevJobDir + File.separator + SchedulerContext.jobPackageFileName(config);
    Path jobPackageFile = Paths.get(jobPackage);
    if (Files.notExists(jobPackageFile)) {
        LOG.severe("Job Package File does not exist: " + jobPackage);
        return new Twister2JobState(false);
    }
    // unpack the previous job package to a temp directory
    Path tempDirPath;
    try {
        tempDirPath = Files.createTempDirectory(jobID);
    } catch (IOException e) {
        throw new Twister2RuntimeException("Can not create temp directory", e);
    }
    // todo: we can exclude user-job-file from being unpacked
    // usually that is the lastest file, so we can be more efficient
    TarGzipPacker.unpack(jobPackageFile, tempDirPath);
    // load Job object
    String unpackedJobDir = tempDirPath + File.separator + Context.JOB_ARCHIVE_DIRECTORY;
    String jobFile = unpackedJobDir + File.separator + SchedulerContext.createJobDescriptionFileName(jobID);
    JobAPI.Job job = JobUtils.readJobFile(jobFile);
    // load previous configurations
    Config prevConfig = ConfigLoader.loadConfig(Context.twister2Home(config), unpackedJobDir, Context.clusterType(config));
    // delete temp directory
    try {
        Files.delete(tempDirPath);
        LOG.info("Unpacked job directory deleted: " + tempDirPath);
    } catch (IOException e) {
        LOG.warning("Exception when deleting temp directory: " + tempDirPath);
    }
    URI packageURI = null;
    try {
        packageURI = new URI(prevJobDir);
    } catch (URISyntaxException e) {
        throw new Twister2RuntimeException("Can not ceate URI for directory: " + prevJobDir, e);
    }
    // add restore parameter
    // local packages path
    prevConfig = Config.newBuilder().putAll(prevConfig).put(CheckpointingContext.CHECKPOINTING_RESTORE_JOB, true).put(SchedulerContext.TEMPORARY_PACKAGES_PATH, prevJobDir).put(SchedulerContext.USER_JOB_FILE, job.getJobFormat().getJobFile()).put(SchedulerContext.JOB_PACKAGE_URI, packageURI).put(Context.TWISTER2_HOME.getKey(), Context.twister2Home(config)).put(Context.JOB_ID, jobID).put(Context.TWISTER2_CLUSTER_TYPE, Context.clusterType(config)).build();
    writeJobIdToFile(jobID);
    printJobInfo(job, prevConfig);
    // launch the launcher
    ResourceAllocator resourceAllocator = new ResourceAllocator(prevConfig, job);
    return resourceAllocator.resubmitJob();
}
Also used : Path(java.nio.file.Path) Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) Twister2JobState(edu.iu.dsc.tws.api.scheduler.Twister2JobState) Config(edu.iu.dsc.tws.api.config.Config) ResourceAllocator(edu.iu.dsc.tws.rsched.core.ResourceAllocator) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) JobAPI(edu.iu.dsc.tws.proto.system.job.JobAPI) URI(java.net.URI)

Example 3 with ResourceAllocator

use of edu.iu.dsc.tws.rsched.core.ResourceAllocator in project twister2 by DSC-SPIDAL.

the class Twister2Submitter method submitContainerJob.

/**
 * Submit a basic job with only container and communications
 * @param basicJob basic job
 */
public static void submitContainerJob(BasicJob basicJob, Config config) {
    // save the job to state manager
    JobAPI.Job job = basicJob.serialize();
    // launch the luancher
    ResourceAllocator resourceAllocator = new ResourceAllocator();
    resourceAllocator.submitJob(job, config);
}
Also used : ResourceAllocator(edu.iu.dsc.tws.rsched.core.ResourceAllocator) JobAPI(edu.iu.dsc.tws.proto.system.job.JobAPI)

Example 4 with ResourceAllocator

use of edu.iu.dsc.tws.rsched.core.ResourceAllocator in project twister2 by DSC-SPIDAL.

the class Twister2Submitter method submitJob.

/**
 * Submit a Twister2 job
 *
 * @param twister2Job job
 */
public static Twister2JobState submitJob(Twister2Job twister2Job, Config config) {
    // otherwise it will be automatically generated
    if (Context.jobId(config) != null) {
        twister2Job.setJobID(Context.jobId(config));
    }
    // set username
    String userName = Context.userName(config);
    if (userName == null) {
        userName = System.getProperty("user.name");
    }
    twister2Job.setUserName(userName);
    JobAPI.Job job = twister2Job.serialize();
    // update the config object with the values from job
    Config updatedConfig = JobUtils.updateConfigs(job, config);
    writeJobIdToFile(job.getJobId());
    printJobInfo(job, updatedConfig);
    // launch the launcher
    ResourceAllocator resourceAllocator = new ResourceAllocator(updatedConfig, job);
    return resourceAllocator.submitJob();
}
Also used : Config(edu.iu.dsc.tws.api.config.Config) ResourceAllocator(edu.iu.dsc.tws.rsched.core.ResourceAllocator) JobAPI(edu.iu.dsc.tws.proto.system.job.JobAPI)

Aggregations

ResourceAllocator (edu.iu.dsc.tws.rsched.core.ResourceAllocator)4 JobAPI (edu.iu.dsc.tws.proto.system.job.JobAPI)3 Config (edu.iu.dsc.tws.api.config.Config)2 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)1 Twister2JobState (edu.iu.dsc.tws.api.scheduler.Twister2JobState)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Path (java.nio.file.Path)1