Search in sources :

Example 16 with V1Service

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());
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1Service(io.kubernetes.client.models.V1Service) Test(org.junit.Test)

Example 17 with V1Service

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"));
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1Service(io.kubernetes.client.models.V1Service) Test(org.junit.Test)

Example 18 with V1Service

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;
}
Also used : V1beta2StatefulSet(io.kubernetes.client.models.V1beta2StatefulSet) V1Service(io.kubernetes.client.models.V1Service) File(java.io.File)

Example 19 with V1Service

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);
}
Also used : Type(java.lang.reflect.Type) V1Service(io.kubernetes.client.models.V1Service)

Example 20 with V1Service

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 &#39;true&#39;, 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;
}
Also used : V1Service(io.kubernetes.client.models.V1Service) ProgressResponseBody(io.kubernetes.client.ProgressResponseBody) Type(java.lang.reflect.Type) ProgressRequestBody(io.kubernetes.client.ProgressRequestBody)

Aggregations

V1Service (io.kubernetes.client.models.V1Service)34 Test (org.junit.Test)15 Type (java.lang.reflect.Type)14 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)11 ProgressRequestBody (io.kubernetes.client.ProgressRequestBody)7 ProgressResponseBody (io.kubernetes.client.ProgressResponseBody)7 DomainPresenceInfo (oracle.kubernetes.operator.helpers.DomainPresenceInfo)3 V1ServiceList (io.kubernetes.client.models.V1ServiceList)2 V1ServicePort (io.kubernetes.client.models.V1ServicePort)2 V1ServiceSpec (io.kubernetes.client.models.V1ServiceSpec)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ServerKubernetesObjects (oracle.kubernetes.operator.helpers.ServerKubernetesObjects)2 Engine (oracle.kubernetes.operator.work.Engine)2 Domain (oracle.kubernetes.weblogic.domain.v1.Domain)2 DomainSpec (oracle.kubernetes.weblogic.domain.v1.DomainSpec)2 HttpUserAgentTest (com.meterware.pseudoserver.HttpUserAgentTest)1 ApiException (io.kubernetes.client.ApiException)1 JSON (io.kubernetes.client.JSON)1 IntOrString (io.kubernetes.client.custom.IntOrString)1