use of io.kubernetes.client.models.V1Service in project weblogic-kubernetes-operator by oracle.
the class ServiceWatcherTest method whenServiceHasNoServerName_returnNull.
@Test
public void whenServiceHasNoServerName_returnNull() throws Exception {
V1Service service = new V1Service().metadata(new V1ObjectMeta());
assertThat(ServiceWatcher.getServiceServerName(service), nullValue());
}
use of io.kubernetes.client.models.V1Service in project weblogic-kubernetes-operator by oracle.
the class ServiceWatcherTest method whenServiceHasChannelName_returnIt.
@Test
public void whenServiceHasChannelName_returnIt() throws Exception {
V1Service service = new V1Service().metadata(new V1ObjectMeta().labels(ImmutableMap.of(CHANNELNAME_LABEL, "channel1")));
assertThat(ServiceWatcher.getServiceChannelName(service), equalTo("channel1"));
}
use of io.kubernetes.client.models.V1Service 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.V1Service in project java by kubernetes-client.
the class CoreV1Api method patchNamespacedServiceStatusWithHttpInfo.
/**
* partially update status of the specified Service
* @param name name of the Service (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<V1Service>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse<V1Service> patchNamespacedServiceStatusWithHttpInfo(String name, String namespace, Object body, String pretty) throws ApiException {
com.squareup.okhttp.Call call = patchNamespacedServiceStatusValidateBeforeCall(name, namespace, body, pretty, null, null);
Type localVarReturnType = new TypeToken<V1Service>() {
}.getType();
return apiClient.execute(call, localVarReturnType);
}
use of io.kubernetes.client.models.V1Service in project java by kubernetes-client.
the class CoreV1Api method patchNamespacedServiceAsync.
/**
* (asynchronously)
* partially update the specified Service
* @param name name of the Service (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)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/
public com.squareup.okhttp.Call patchNamespacedServiceAsync(String name, String namespace, Object body, String pretty, final ApiCallback<V1Service> callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}
com.squareup.okhttp.Call call = patchNamespacedServiceValidateBeforeCall(name, namespace, body, pretty, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken<V1Service>() {
}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
Aggregations