use of io.kubernetes.client.models.V1beta2StatefulSet in project java by kubernetes-client.
the class AppsV1beta2ApiTest method replaceNamespacedStatefulSetTest.
/**
* replace the specified StatefulSet
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void replaceNamespacedStatefulSetTest() throws ApiException {
String name = null;
String namespace = null;
V1beta2StatefulSet body = null;
String pretty = null;
V1beta2StatefulSet response = api.replaceNamespacedStatefulSet(name, namespace, body, pretty);
// TODO: test validations
}
use of io.kubernetes.client.models.V1beta2StatefulSet in project java by kubernetes-client.
the class AppsV1beta2ApiTest method readNamespacedStatefulSetTest.
/**
* read the specified StatefulSet
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void readNamespacedStatefulSetTest() throws ApiException {
String name = null;
String namespace = null;
String pretty = null;
Boolean exact = null;
Boolean export = null;
V1beta2StatefulSet response = api.readNamespacedStatefulSet(name, namespace, pretty, exact, export);
// TODO: test validations
}
use of io.kubernetes.client.models.V1beta2StatefulSet in project twister2 by DSC-SPIDAL.
the class KubernetesLauncher method launch.
/**
* Launch the processes according to the resource plan.
*
* @param resourceRequest requested resources
* @return true if the request is granted
*/
@Override
public boolean launch(RequestedResources resourceRequest, JobAPI.Job job) {
String jobName = job.getJobName();
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 + "\nAborting submission.");
return false;
}
long jobFileSize = jobFile.length();
// first check whether there is a running service
String serviceName = KubernetesUtils.createServiceName(jobName);
String serviceLabel = KubernetesUtils.createServiceLabel(jobName);
String namespace = KubernetesContext.namespace(config);
V1Service service = controller.getService(namespace, serviceName);
// if there is no service, start one
if (service == null) {
int port = KubernetesContext.servicePort(config);
int targetPort = KubernetesContext.serviceTargetPort(config);
service = KubernetesUtils.createServiceObject(serviceName, serviceLabel, port, targetPort);
boolean serviceCreated = controller.createService(namespace, service);
if (!serviceCreated) {
LOG.log(Level.SEVERE, "Service could not be created. Aborting submission");
throw new RuntimeException();
}
// if there is already a service with the same name
} else {
LOG.log(Level.INFO, "There is already a service with the name: " + serviceName + "\nNo need to create a new service. Will use the existing one.");
}
// first check whether there is a StatefulSet with the same name,
// if so, do not submit new job. Give a message and terminate
// user needs to explicitly terminate that job
String serviceLabelWithApp = KubernetesUtils.createServiceLabelWithApp(jobName);
V1beta2StatefulSet existingStatefulSet = controller.getStatefulSet(namespace, jobName, serviceLabelWithApp);
if (existingStatefulSet != null) {
LOG.log(Level.SEVERE, "There is already a StatefulSet object in Kubernetes master " + "with the name: " + jobName + "\nFirst terminate this running job and resubmit. ");
return false;
}
// create the StatefulSet for this job
V1beta2StatefulSet statefulSet = KubernetesUtils.createStatefulSetObjectForJob(jobName, resourceRequest, jobFileSize, config);
if (statefulSet == null) {
controller.deleteService(namespace, serviceName);
return false;
}
boolean statefulSetCreated = controller.createStatefulSetJob(namespace, statefulSet);
if (!statefulSetCreated) {
controller.deleteService(namespace, serviceName);
return false;
}
int numberOfPods = statefulSet.getSpec().getReplicas();
long start = System.currentTimeMillis();
// boolean transferred =
// controller.transferJobPackageSequentially(namespace, jobName, numberOfPods, jobPackageFile);
boolean transferred = controller.transferJobPackageInParallel(namespace, jobName, numberOfPods, jobPackageFile);
long duration = System.currentTimeMillis() - start;
System.out.println("Transferring all files took: " + duration + " ms.");
if (!transferred) {
LOG.log(Level.SEVERE, "Transferring the job package to some pods failed. " + "Terminating the job");
// terminateJob(jobName);
return false;
}
return true;
}
use of io.kubernetes.client.models.V1beta2StatefulSet in project twister2 by DSC-SPIDAL.
the class KubernetesUtils method createStatefulSetObjectForJob.
/**
* TBD: calculate containers per pod or issue error
* when the numberOfContainers can not be divisible by the number of containersPerPod
* @param jobName
* @param resourceRequest
* @return
*/
public static V1beta2StatefulSet createStatefulSetObjectForJob(String jobName, RequestedResources resourceRequest, long jobFileSize, Config config) {
V1beta2StatefulSet statefulSet = new V1beta2StatefulSet();
statefulSet.setApiVersion("apps/v1beta2");
statefulSet.setKind("StatefulSet");
// construct metadata and set for jobName setting
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(jobName);
statefulSet.setMetadata(meta);
// construct JobSpec and set
V1beta2StatefulSetSpec setSpec = new V1beta2StatefulSetSpec();
setSpec.serviceName(createServiceName(jobName));
// pods will be started in parallel
// by default they are started sequentially
setSpec.setPodManagementPolicy("Parallel");
// number of containers has to be divisible by the containersPerPod
// all pods will have equal number of containers
// all pods will be identical
int containersPerPod = KubernetesContext.containersPerPod(config);
if (resourceRequest.getNoOfContainers() % containersPerPod != 0) {
LOG.log(Level.SEVERE, "Number of containers has to be divisible by containersPerPod.\n" + "Number of containers: " + resourceRequest.getNoOfContainers() + "\n" + "containersPerPod: " + containersPerPod + "\n" + "Aborting submission.");
return null;
}
int numberOfPods = resourceRequest.getNoOfContainers() / containersPerPod;
setSpec.setReplicas(numberOfPods);
// add selector for the job
V1LabelSelector selector = new V1LabelSelector();
String serviceLabel = createServiceLabel(jobName);
selector.putMatchLabelsItem("app", serviceLabel);
setSpec.setSelector(selector);
// construct the pod template
V1PodTemplateSpec template = constructPodTemplate(resourceRequest.getContainer(), serviceLabel, jobFileSize, config);
setSpec.setTemplate(template);
statefulSet.setSpec(setSpec);
return statefulSet;
}
use of io.kubernetes.client.models.V1beta2StatefulSet in project java by kubernetes-client.
the class AppsV1beta2Api method patchNamespacedStatefulSetStatusWithHttpInfo.
/**
* partially update status of the specified StatefulSet
* @param name name of the StatefulSet (required)
* @param namespace object name and auth scope, such as for teams and projects (required)
* @param body (required)
* @param pretty If 'true', then the output is pretty printed. (optional)
* @return ApiResponse<V1beta2StatefulSet>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse<V1beta2StatefulSet> patchNamespacedStatefulSetStatusWithHttpInfo(String name, String namespace, Object body, String pretty) throws ApiException {
com.squareup.okhttp.Call call = patchNamespacedStatefulSetStatusValidateBeforeCall(name, namespace, body, pretty, null, null);
Type localVarReturnType = new TypeToken<V1beta2StatefulSet>() {
}.getType();
return apiClient.execute(call, localVarReturnType);
}
Aggregations