Search in sources :

Example 1 with IStateManager

use of edu.iu.dsc.tws.rsched.spi.statemanager.IStateManager in project twister2 by DSC-SPIDAL.

the class ResourceAllocator method terminateJob.

/**
 * Terminate a job
 *
 * @param jobName the name of the job to terminate
 */
public void terminateJob(String jobName, Config config) {
    String statemgrClass = SchedulerContext.stateManagerClass(config);
    if (statemgrClass == null) {
        throw new RuntimeException("The state manager class must be spcified");
    }
    String launcherClass = SchedulerContext.launcherClass(config);
    if (launcherClass == null) {
        throw new RuntimeException("The launcher class must be specified");
    }
    ILauncher launcher;
    IStateManager statemgr;
    // create an instance of state manager
    try {
        statemgr = ReflectionUtils.newInstance(statemgrClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new JobSubmissionException(String.format("Failed to instantiate state manager class '%s'", statemgrClass), e);
    }
    // create an instance of launcher
    try {
        launcher = ReflectionUtils.newInstance(launcherClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new LauncherException(String.format("Failed to instantiate launcher class '%s'", launcherClass), e);
    }
    // let the state manager know that we are killing this job??
    // statemgr.initialize(config);
    // initialize the launcher and terminate the job
    launcher.initialize(config);
    boolean terminated = launcher.terminateJob(jobName);
    if (!terminated) {
        LOG.log(Level.SEVERE, "Could not terminate the job");
    }
}
Also used : IStateManager(edu.iu.dsc.tws.rsched.spi.statemanager.IStateManager) LauncherException(edu.iu.dsc.tws.rsched.spi.scheduler.LauncherException) ILauncher(edu.iu.dsc.tws.rsched.spi.scheduler.ILauncher)

Example 2 with IStateManager

use of edu.iu.dsc.tws.rsched.spi.statemanager.IStateManager in project twister2 by DSC-SPIDAL.

the class ResourceAllocator method submitJob.

/**
 * Submit the job to the cluster
 *
 * @param job the actual job description
 */
public void submitJob(JobAPI.Job job, Config config) {
    // lets prepare the job files
    // String jobDirectory = prepareJobFilesOld(config, job);
    String jobDirectory = prepareJobFiles(config, job);
    String statemgrClass = SchedulerContext.stateManagerClass(config);
    if (statemgrClass == null) {
        throw new RuntimeException("The state manager class must be spcified");
    }
    String launcherClass = SchedulerContext.launcherClass(config);
    if (launcherClass == null) {
        throw new RuntimeException("The launcher class must be specified");
    }
    String uploaderClass = SchedulerContext.uploaderClass(config);
    if (uploaderClass == null) {
        throw new RuntimeException("The uploader class must be specified");
    }
    ILauncher launcher;
    IUploader uploader;
    IStateManager statemgr;
    // create an instance of state manager
    try {
        statemgr = ReflectionUtils.newInstance(statemgrClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new JobSubmissionException(String.format("Failed to instantiate state manager class '%s'", statemgrClass), e);
    }
    // create an instance of launcher
    try {
        launcher = ReflectionUtils.newInstance(launcherClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new LauncherException(String.format("Failed to instantiate launcher class '%s'", launcherClass), e);
    }
    // create an instance of uploader
    try {
        uploader = ReflectionUtils.newInstance(uploaderClass);
    } catch (IllegalAccessException | InstantiationException | ClassNotFoundException e) {
        throw new UploaderException(String.format("Failed to instantiate uploader class '%s'", uploaderClass), e);
    }
    LOG.log(Level.INFO, "Initialize state manager");
    // initialize the state manager
    statemgr.initialize(config);
    LOG.log(Level.INFO, "Initialize uploader");
    // now upload the content of the package
    uploader.initialize(config);
    // gives the url of the file to be uploaded
    LOG.log(Level.INFO, "Calling uploader to upload the package content");
    URI packageURI = uploader.uploadPackage(jobDirectory);
    // add scp address as a prefix to returned URI: user@ip
    String scpServerAdress = ScpContext.scpConnection(updatedConfig);
    String scpPath = scpServerAdress + ":" + packageURI.toString() + "/";
    LOG.log(Level.INFO, "SCP PATH to copy files from: " + scpPath);
    // this is a temporary solution
    // String packagesPath = "root@149.165.150.81:/root/.twister2/repository/";
    // String packagesPath = "149.165.150.81:~/.twister2/repository/";
    // now launch the launcher
    // Update the runtime config with the packageURI
    updatedConfig = Config.newBuilder().putAll(updatedConfig).put(SchedulerContext.TWISTER2_PACKAGES_PATH, scpPath).put(SchedulerContext.JOB_PACKAGE_URI, packageURI).build();
    // this is a handler chain based execution in resource allocator. We need to
    // make it more formal as such
    launcher.initialize(updatedConfig);
    RequestedResources requestedResources = buildRequestedResources(updatedJob);
    if (requestedResources == null) {
        throw new RuntimeException("Failed to build the requested resources");
    }
    launcher.launch(requestedResources, updatedJob);
}
Also used : IUploader(edu.iu.dsc.tws.rsched.spi.uploaders.IUploader) IStateManager(edu.iu.dsc.tws.rsched.spi.statemanager.IStateManager) LauncherException(edu.iu.dsc.tws.rsched.spi.scheduler.LauncherException) UploaderException(edu.iu.dsc.tws.rsched.spi.uploaders.UploaderException) URI(java.net.URI) ILauncher(edu.iu.dsc.tws.rsched.spi.scheduler.ILauncher) RequestedResources(edu.iu.dsc.tws.rsched.spi.resource.RequestedResources)

Aggregations

ILauncher (edu.iu.dsc.tws.rsched.spi.scheduler.ILauncher)2 LauncherException (edu.iu.dsc.tws.rsched.spi.scheduler.LauncherException)2 IStateManager (edu.iu.dsc.tws.rsched.spi.statemanager.IStateManager)2 RequestedResources (edu.iu.dsc.tws.rsched.spi.resource.RequestedResources)1 IUploader (edu.iu.dsc.tws.rsched.spi.uploaders.IUploader)1 UploaderException (edu.iu.dsc.tws.rsched.spi.uploaders.UploaderException)1 URI (java.net.URI)1