Search in sources :

Example 21 with V1StatefulSet

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

the class KubernetesController method getJobWorkerStatefulSets.

/**
 * return the list of worker StatefulSet names for this job
 * they must be in the form of "jobID-index"
 * otherwise return an empty ArrayList
 */
public ArrayList<String> getJobWorkerStatefulSets(String jobID) {
    List<V1StatefulSet> ssList = getJobStatefulSets(jobID);
    ArrayList<String> ssNameList = new ArrayList<>();
    for (V1StatefulSet statefulSet : ssList) {
        String ssName = statefulSet.getMetadata().getName();
        if (ssName.matches(jobID + "-" + "[0-9]+")) {
            ssNameList.add(ssName);
        }
    }
    return ssNameList;
}
Also used : V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) ArrayList(java.util.ArrayList)

Example 22 with V1StatefulSet

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

the class KubernetesLauncher method initStatefulSets.

private boolean initStatefulSets(JobAPI.Job job) {
    // create StatefulSet for the job master
    if (!JobMasterContext.jobMasterRunsInClient(config)) {
        // create the StatefulSet object for this job
        V1StatefulSet jobMasterStatefulSet = JobMasterRequestObject.createStatefulSetObject();
        if (jobMasterStatefulSet == null) {
            return false;
        }
        boolean statefulSetCreated = controller.createStatefulSet(jobMasterStatefulSet);
        if (statefulSetCreated) {
            jobSubmissionStatus.addCreatedStatefulSetName(jobMasterStatefulSet.getMetadata().getName());
        } else {
            LOG.severe("Please run terminate job to clear up any artifacts from previous jobs." + "\n++++++++++++++++++ Aborting submission ++++++++++++++++++");
            return false;
        }
    }
    // create StatefulSets for workers
    for (int i = 0; i < job.getComputeResourceList().size(); i++) {
        JobAPI.ComputeResource computeResource = JobUtils.getComputeResource(job, i);
        if (computeResource == null) {
            LOG.severe("Something wrong with the job object. Can not get ComputeResource from job" + "\n++++++++++++++++++ Aborting submission ++++++++++++++++++");
            return false;
        }
        // create the StatefulSet object for this job
        V1StatefulSet statefulSet = RequestObjectBuilder.createStatefulSetForWorkers(computeResource);
        if (statefulSet == null) {
            return false;
        }
        boolean statefulSetCreated = controller.createStatefulSet(statefulSet);
        if (statefulSetCreated) {
            jobSubmissionStatus.addCreatedStatefulSetName(statefulSet.getMetadata().getName());
        } else {
            LOG.severe("Please run terminate job to clear up any artifacts from previous jobs." + "\n++++++++++++++++++ Aborting submission ++++++++++++++++++");
            return false;
        }
    }
    return true;
}
Also used : V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) JobAPI(edu.iu.dsc.tws.proto.system.job.JobAPI)

Example 23 with V1StatefulSet

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

the class RequestObjectBuilder method createStatefulSetForWorkers.

/**
 * create StatefulSet object for a job
 */
public static V1StatefulSet createStatefulSetForWorkers(ComputeResource computeResource) {
    if (config == null) {
        LOG.severe("RequestObjectBuilder.init method has not been called.");
        return null;
    }
    String statefulSetName = KubernetesUtils.createWorkersStatefulSetName(jobID, computeResource.getIndex());
    V1StatefulSet statefulSet = new V1StatefulSet();
    // set labels for the worker stateful set
    HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);
    // worker statefulset
    labels.put("t2-wss", jobID);
    // construct metadata and set for jobID setting
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(statefulSetName);
    meta.setLabels(labels);
    statefulSet.setMetadata(meta);
    // construct JobSpec and set
    V1StatefulSetSpec setSpec = new V1StatefulSetSpec();
    setSpec.serviceName(KubernetesUtils.createServiceName(jobID));
    // pods will be started in parallel
    // by default they are started sequentially
    setSpec.setPodManagementPolicy("Parallel");
    int numberOfPods = computeResource.getInstances();
    setSpec.setReplicas(numberOfPods);
    // add selector for the job
    V1LabelSelector selector = new V1LabelSelector();
    selector.putMatchLabelsItem("t2-wp", jobID);
    setSpec.setSelector(selector);
    // construct the pod template
    V1PodTemplateSpec template = constructPodTemplate(computeResource);
    setSpec.setTemplate(template);
    statefulSet.setSpec(setSpec);
    return statefulSet;
}
Also used : V1StatefulSet(io.kubernetes.client.openapi.models.V1StatefulSet) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1StatefulSetSpec(io.kubernetes.client.openapi.models.V1StatefulSetSpec) V1PodTemplateSpec(io.kubernetes.client.openapi.models.V1PodTemplateSpec) V1LabelSelector(io.kubernetes.client.openapi.models.V1LabelSelector)

Aggregations

V1StatefulSet (io.kubernetes.client.openapi.models.V1StatefulSet)23 Type (java.lang.reflect.Type)14 V1StatefulSetSpec (io.kubernetes.client.openapi.models.V1StatefulSetSpec)5 ApiException (io.kubernetes.client.openapi.ApiException)3 V1LabelSelector (io.kubernetes.client.openapi.models.V1LabelSelector)3 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)3 V1PodTemplateSpec (io.kubernetes.client.openapi.models.V1PodTemplateSpec)3 TopologyRuntimeManagementException (org.apache.heron.scheduler.TopologyRuntimeManagementException)2 JobAPI (edu.iu.dsc.tws.proto.system.job.JobAPI)1 IntOrString (io.kubernetes.client.custom.IntOrString)1 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)1 V1Service (io.kubernetes.client.openapi.models.V1Service)1 V1Volume (io.kubernetes.client.openapi.models.V1Volume)1 V1VolumeMount (io.kubernetes.client.openapi.models.V1VolumeMount)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 TopologySubmissionException (org.apache.heron.scheduler.TopologySubmissionException)1 Config (org.apache.heron.spi.common.Config)1