Search in sources :

Example 6 with Port

use of com.hashicorp.nomad.apimodel.Port in project twister2 by DSC-SPIDAL.

the class NomadController method getShellDriver.

private Task getShellDriver(JobAPI.Job job) {
    String taskName = job.getJobId();
    Task task = new Task();
    // get the job working directory
    String workingDirectory = NomadContext.workingDirectory(config);
    String jobWorkingDirectory = Paths.get(workingDirectory, job.getJobId()).toString();
    String configDirectoryName = Paths.get(workingDirectory, job.getJobId(), SchedulerContext.clusterType(config)).toString();
    String corePackageFile = SchedulerContext.temporaryPackagesPath(config) + "/" + SchedulerContext.corePackageFileName(config);
    String jobPackageFile = SchedulerContext.temporaryPackagesPath(config) + "/" + SchedulerContext.jobPackageFileName(config);
    String nomadScriptContent = getNomadScriptContent(config, configDirectoryName);
    task.setName(taskName);
    task.setDriver("raw_exec");
    task.addConfig(NomadContext.NOMAD_TASK_COMMAND, NomadContext.SHELL_CMD);
    String[] args = workerProcessCommand(workingDirectory, job);
    task.addConfig(NomadContext.NOMAD_TASK_COMMAND_ARGS, args);
    Template template = new Template();
    template.setEmbeddedTmpl(nomadScriptContent);
    template.setDestPath(NomadContext.NOMAD_SCRIPT_NAME);
    task.addTemplates(template);
    Resources resourceReqs = new Resources();
    String portNamesConfig = NomadContext.networkPortNames(config);
    String[] portNames = portNamesConfig.split(",");
    // configure nomad to allocate dynamic ports
    Port[] ports = new Port[portNames.length];
    int i = 0;
    for (String p : portNames) {
        ports[i] = new Port().setLabel(p);
        i++;
    }
    NetworkResource networkResource = new NetworkResource();
    networkResource.addDynamicPorts(ports);
    resourceReqs.addNetworks(networkResource);
    JobAPI.ComputeResource computeResource = JobUtils.getComputeResource(job, 0);
    if (computeResource == null) {
        LOG.log(Level.SEVERE, "Error: there is no compute resource");
        return null;
    }
    int cpu = (int) computeResource.getCpu();
    int disk = (int) computeResource.getDiskGigaBytes();
    int memory = computeResource.getRamMegaBytes();
    resourceReqs.setCpu(cpu * 200);
    resourceReqs.setMemoryMb(memory);
    resourceReqs.setDiskMb(disk * 1024);
    LOG.log(Level.INFO, "Compute resources are " + cpu + " " + memory + " " + disk);
    Map<String, String> envVars = new HashMap<>();
    envVars.put(NomadContext.WORKING_DIRECTORY_ENV, NomadContext.workingDirectory(config));
    if (!NomadContext.sharedFileSystem(config)) {
        envVars.put(NomadContext.DOWNLOAD_PACKAGE_ENV, "false");
    } else {
        envVars.put(NomadContext.DOWNLOAD_PACKAGE_ENV, "true");
    }
    // we are putting the core packages as env variable
    envVars.put(NomadContext.CORE_PACKAGE_ENV, corePackageFile);
    envVars.put(NomadContext.JOB_PACKAGE_ENV, jobPackageFile);
    task.setEnv(envVars);
    task.setResources(resourceReqs);
    return task;
}
Also used : Task(com.hashicorp.nomad.apimodel.Task) HashMap(java.util.HashMap) Port(com.hashicorp.nomad.apimodel.Port) JobAPI(edu.iu.dsc.tws.proto.system.job.JobAPI) Template(com.hashicorp.nomad.apimodel.Template) NetworkResource(com.hashicorp.nomad.apimodel.NetworkResource) Resources(com.hashicorp.nomad.apimodel.Resources)

Aggregations

Port (com.hashicorp.nomad.apimodel.Port)6 Resources (com.hashicorp.nomad.apimodel.Resources)4 Task (com.hashicorp.nomad.apimodel.Task)4 NetworkResource (com.hashicorp.nomad.apimodel.NetworkResource)3 Template (com.hashicorp.nomad.apimodel.Template)3 HashMap (java.util.HashMap)3 SchedulerUtils (org.apache.heron.scheduler.utils.SchedulerUtils)3 SchedulerUtils (com.twitter.heron.scheduler.utils.SchedulerUtils)2 Service (com.hashicorp.nomad.apimodel.Service)1 ServiceCheck (com.hashicorp.nomad.apimodel.ServiceCheck)1 JobAPI (edu.iu.dsc.tws.proto.system.job.JobAPI)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Resource (org.apache.heron.spi.packing.Resource)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1