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;
}
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;
}
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;
}
Aggregations