Search in sources :

Example 31 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap in project twister2 by DSC-SPIDAL.

the class KubernetesController method getConfigMapParams.

/**
 * return all configMap parameters for the given jobID
 * if there is no ConfigMap, throw an exception
 */
public Map<String, String> getConfigMapParams(String jobID) {
    String configMapName = jobID;
    V1ConfigMap configMap = getJobConfigMap(jobID);
    if (configMap == null) {
        throw new RuntimeException("Could not get ConfigMap from K8s master: " + configMapName);
    }
    Map<String, String> pairs = configMap.getData();
    if (pairs == null) {
        throw new RuntimeException("Could not get data from ConfigMap");
    }
    return pairs;
}
Also used : Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 32 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap in project twister2 by DSC-SPIDAL.

the class KubernetesLauncher method launch.

/**
 * Launch the processes according to the resource plan.
 *
 * @return true if the request is granted
 */
@Override
public Twister2JobState launch(JobAPI.Job job) {
    Twister2JobState state = new Twister2JobState(false);
    if (!configParametersOK(job)) {
        return state;
    }
    String jobID = job.getJobId();
    String jobPackageFile = SchedulerContext.temporaryPackagesPath(config) + "/" + SchedulerContext.jobPackageFileName(config);
    File jobFile = new File(jobPackageFile);
    if (!jobFile.exists()) {
        LOG.log(Level.SEVERE, "Can not access job package file: " + jobPackageFile + "\n++++++++++++++++++ Aborting submission ++++++++++++++++++");
        return state;
    }
    long jobFileSize = jobFile.length();
    // check all relevant entities on Kubernetes master
    boolean allEntitiesOK = checkEntitiesForJob(job);
    if (!allEntitiesOK) {
        return state;
    }
    long jobSubmitTime = System.currentTimeMillis();
    String encodedNodeList = getNodeInfoList();
    RequestObjectBuilder.init(config, job.getJobId(), jobFileSize, jobSubmitTime, encodedNodeList);
    JobMasterRequestObject.init(config, job.getJobId());
    // initialize the service in Kubernetes master
    boolean servicesCreated = initServices(jobID);
    if (!servicesCreated) {
        clearupWhenSubmissionFails(jobID);
        return state;
    }
    // create the ConfigMap
    V1ConfigMap configMap = RequestObjectBuilder.createConfigMap(job);
    boolean cmCreated = controller.createConfigMap(configMap);
    if (cmCreated) {
        jobSubmissionStatus.setConfigMapCreated(true);
    } else {
        LOG.severe("Following ConfigMap could not be created: " + configMap.getMetadata().getName() + "\n++++++++++++++++++ Aborting submission ++++++++++++++++++");
        clearupWhenSubmissionFails(jobID);
        return state;
    }
    // if persistent volume is requested, create a persistent volume claim
    if (SchedulerContext.persistentVolumeRequested(config)) {
        // create pvc
        if (!CheckpointingContext.startingFromACheckpoint(config) || !CheckpointingContext.isNfsUsed(config)) {
            boolean volumesSetup = initPersistentVolumeClaim(job);
            if (!volumesSetup) {
                clearupWhenSubmissionFails(jobID);
                return state;
            }
        }
    }
    // initialize StatefulSets for this job
    boolean statefulSetInitialized = initStatefulSets(job);
    if (!statefulSetInitialized) {
        clearupWhenSubmissionFails(jobID);
        return state;
    }
    // start the Job Master locally if requested
    if (JobMasterContext.jobMasterRunsInClient(config)) {
        boolean jobMasterCompleted = startJobMasterOnClient(job);
        if (!jobMasterCompleted) {
            LOG.log(Level.SEVERE, "JobMaster can not be started. " + "\n++++++++++++++++++ Aborting submission ++++++++++++++++++");
            clearupWhenSubmissionFails(jobID);
            return state;
        }
    }
    if (KubernetesContext.logInClient(config)) {
        jobLogger = new JobLogger(namespace, job);
        jobLogger.start();
    }
    state.setRequestGranted(true);
    return state;
}
Also used : Twister2JobState(edu.iu.dsc.tws.api.scheduler.Twister2JobState) JobLogger(edu.iu.dsc.tws.rsched.schedulers.k8s.logger.JobLogger) File(java.io.File) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 33 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap in project twister2 by DSC-SPIDAL.

the class KubernetesController method existConfigMap.

/**
 * return true if there is already a ConfigMap object with the same name on Kubernetes master,
 * otherwise return false
 */
public boolean existConfigMap(String jobID) {
    String configMapName = jobID;
    V1ConfigMapList configMapList = null;
    try {
        configMapList = coreApi.listNamespacedConfigMap(namespace, null, null, null, null, null, null, null, null, null);
    } catch (ApiException e) {
        LOG.log(Level.SEVERE, "Exception when getting ConfigMap list.", e);
        throw new RuntimeException(e);
    }
    for (V1ConfigMap configMap : configMapList.getItems()) {
        if (configMapName.equals(configMap.getMetadata().getName())) {
            return true;
        }
    }
    return false;
}
Also used : Twister2RuntimeException(edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException) V1ConfigMapList(io.kubernetes.client.openapi.models.V1ConfigMapList) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) ApiException(io.kubernetes.client.openapi.ApiException)

Example 34 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap in project twister2 by DSC-SPIDAL.

the class K8sControllerExample method createCM.

public static void createCM(KubernetesController controller, JobAPI.Job job) {
    Config cnfg = Config.newBuilder().put("nothing", "nothing").build();
    RequestObjectBuilder.init(cnfg, job.getJobId(), 0, 0, null);
    V1ConfigMap cm = RequestObjectBuilder.createConfigMap(job);
    controller.createConfigMap(cm);
}
Also used : Config(edu.iu.dsc.tws.api.config.Config) JobConfig(edu.iu.dsc.tws.api.JobConfig) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 35 with V1ConfigMap

use of io.kubernetes.client.openapi.models.V1ConfigMap in project twister2 by DSC-SPIDAL.

the class K8sControllerExample method main.

public static void main(String[] args) throws InterruptedException {
    KubernetesController controller = KubernetesController.init("default");
    if (args.length != 1) {
        LOG.severe("Provide jobID as a parameter.");
        return;
    }
    String jobID = args[0];
    String configDir = "";
    String twister2Home = Paths.get(configDir).toAbsolutePath().toString();
    Config config = ConfigLoader.loadConfig(twister2Home, "conf", "kubernetes");
    LOG.info("Loaded: " + config.size() + " configuration parameters.");
    testUploader(config, controller, jobID);
    if (config != null) {
        controller.close();
        return;
    }
    int numberOfWorkers = 4;
    Twister2Job twister2Job = Twister2Job.newBuilder().setJobName("hello-world-job").setWorkerClass(HelloWorld.class).addComputeResource(.2, 128, numberOfWorkers).setConfig(new JobConfig()).build();
    twister2Job.setUserName("au");
    JobAPI.Job job = twister2Job.serialize();
    LOG.info("jobID: " + job.getJobId());
    V1ConfigMap cm = controller.getJobConfigMap(job.getJobId());
    if (cm == null) {
        LOG.info("there is no cm for this job on k8s");
    } else {
        LOG.info("cm: " + cm.getMetadata().getName());
    }
    // testPVC(config, controller, jobID);
    createCM(controller, job);
    getJobFromConfigMap(controller, job.getJobId());
    // testWorker(controller, jobID, 0);
    // testWorker(controller, jobID, 1);
    // testWorker(controller, jobID, 3);
    // testJM(controller, jobID);
    // controller.addParamToConfigMap(jobID, "KILL_JOB", "true");
    // Thread.sleep(5000);
    // createCMWatcher(controller, jobID);
    // Thread.sleep(5000);
    controller.deleteConfigMap(job.getJobId());
    controller.close();
}
Also used : KubernetesController(edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController) Config(edu.iu.dsc.tws.api.config.Config) JobConfig(edu.iu.dsc.tws.api.JobConfig) JobAPI(edu.iu.dsc.tws.proto.system.job.JobAPI) Twister2Job(edu.iu.dsc.tws.api.Twister2Job) JobConfig(edu.iu.dsc.tws.api.JobConfig) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) HelloWorld(edu.iu.dsc.tws.examples.basic.HelloWorld)

Aggregations

V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)35 Test (org.junit.Test)11 Type (java.lang.reflect.Type)8 V1ConfigMapBuilder (io.kubernetes.client.openapi.models.V1ConfigMapBuilder)6 TopologySubmissionException (org.apache.heron.scheduler.TopologySubmissionException)6 Matchers.anyString (org.mockito.Matchers.anyString)6 ApiException (io.kubernetes.client.openapi.ApiException)5 LinkedList (java.util.LinkedList)5 TestTuple (org.apache.heron.scheduler.kubernetes.KubernetesUtils.TestTuple)5 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)4 JobConfig (edu.iu.dsc.tws.api.JobConfig)3 Config (edu.iu.dsc.tws.api.config.Config)3 CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)3 HashMap (java.util.HashMap)3 Pair (org.apache.heron.common.basics.Pair)3 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)2 Twister2RuntimeException (edu.iu.dsc.tws.api.exceptions.Twister2RuntimeException)2 KubernetesController (edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController)2 JSON (io.kubernetes.client.openapi.JSON)2 V1ConfigMapList (io.kubernetes.client.openapi.models.V1ConfigMapList)2