Search in sources :

Example 6 with ApiException

use of io.kubernetes.client.ApiException in project weblogic-kubernetes-operator by oracle.

the class SecretHelperTest method createSecret.

// Create a named secret with username / password in specified name
private V1Secret createSecret(String name, String namespace) throws Exception {
    CallBuilderFactory factory = new CallBuilderFactory(null);
    try {
        V1Secret existing = factory.create().readSecret(name, namespace);
        if (existing != null)
            return existing;
    } catch (ApiException ignore) {
    // Just ignore and try to create it
    }
    if (isVersion18)
        return null;
    V1Secret body = new V1Secret();
    // Set the required api version and kind of resource
    body.setApiVersion("v1");
    body.setKind("Secret");
    // Setup the standard object metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(name);
    meta.setNamespace(namespace);
    body.setMetadata(meta);
    Map<String, byte[]> data = new HashMap<String, byte[]>();
    data.put(SecretHelper.ADMIN_SERVER_CREDENTIALS_USERNAME, USERNAME.getBytes());
    data.put(SecretHelper.ADMIN_SERVER_CREDENTIALS_PASSWORD, PASSWORD.getBytes());
    body.setData(data);
    try {
        return factory.create().createSecret(namespace, body);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw e;
    }
}
Also used : HashMap(java.util.HashMap) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) V1Secret(io.kubernetes.client.models.V1Secret) ApiException(io.kubernetes.client.ApiException) ApiException(io.kubernetes.client.ApiException)

Example 7 with ApiException

use of io.kubernetes.client.ApiException in project weblogic-kubernetes-operator by oracle.

the class SecretHelperTest method createNamespace.

// Create a named namespace
private V1Namespace createNamespace(String name) throws Exception {
    CallBuilderFactory factory = new CallBuilderFactory(null);
    try {
        V1Namespace existing = factory.create().readNamespace(name);
        if (existing != null)
            return existing;
    } catch (ApiException ignore) {
    // Just ignore and try to create it
    }
    V1Namespace body = new V1Namespace();
    // Set the required api version and kind of resource
    body.setApiVersion("v1");
    body.setKind("Namespace");
    // Setup the standard object metadata
    V1ObjectMeta meta = new V1ObjectMeta();
    meta.setName(name);
    body.setMetadata(meta);
    return factory.create().createNamespace(body);
}
Also used : V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1Namespace(io.kubernetes.client.models.V1Namespace) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) ApiException(io.kubernetes.client.ApiException)

Example 8 with ApiException

use of io.kubernetes.client.ApiException in project twister2 by DSC-SPIDAL.

the class KubernetesController method createStatefulSetJob.

/**
 * create the given service on Kubernetes master
 */
public boolean createStatefulSetJob(String namespace, V1beta2StatefulSet statefulSet) {
    String statefulSetName = statefulSet.getMetadata().getName();
    try {
        Response response = beta2Api.createNamespacedStatefulSetCall(namespace, statefulSet, null, null, null).execute();
        if (response.isSuccessful()) {
            LOG.log(Level.INFO, "StatefulSet [" + statefulSetName + "] is created for the same named job.");
            return true;
        } else {
            LOG.log(Level.SEVERE, "Error when creating the StatefulSet [" + statefulSetName + "]: " + response);
            LOG.log(Level.SEVERE, "Submitted StatefulSet Object: " + statefulSet);
            return false;
        }
    } catch (IOException e) {
        LOG.log(Level.SEVERE, "Exception when creating the StatefulSet: " + statefulSetName, e);
    } catch (ApiException e) {
        LOG.log(Level.SEVERE, "Exception when creating the StatefulSet: " + statefulSetName, e);
    }
    return false;
}
Also used : Response(com.squareup.okhttp.Response) IOException(java.io.IOException) ApiException(io.kubernetes.client.ApiException)

Example 9 with ApiException

use of io.kubernetes.client.ApiException in project twister2 by DSC-SPIDAL.

the class KubernetesController method deleteStatefulSetJob.

/**
 * delete the given StatefulSet from Kubernetes master
 */
public boolean deleteStatefulSetJob(String namespace, String statefulSetName) {
    try {
        V1DeleteOptions deleteOptions = new V1DeleteOptions();
        deleteOptions.setGracePeriodSeconds(0L);
        deleteOptions.setPropagationPolicy(KubernetesConstants.DELETE_OPTIONS_PROPAGATION_POLICY);
        Response response = beta2Api.deleteNamespacedStatefulSetCall(statefulSetName, namespace, deleteOptions, null, null, null, null, null, null).execute();
        if (response.isSuccessful()) {
            LOG.log(Level.INFO, "StatefulSet for the Job [" + statefulSetName + "] is deleted.");
            return true;
        } else {
            if (response.code() == 404 && response.message().equals("Not Found")) {
                LOG.log(Level.SEVERE, "There is no StatefulSet for the Job [" + statefulSetName + "] to delete on Kubernetes master. It may have already terminated.");
                return true;
            }
            LOG.log(Level.SEVERE, "Error when deleting the StatefulSet of the job [" + statefulSetName + "]: " + response);
            return false;
        }
    } catch (ApiException e) {
        LOG.log(Level.SEVERE, "Exception when deleting the the StatefulSet of the job: " + statefulSetName, e);
        return false;
    } catch (IOException e) {
        LOG.log(Level.SEVERE, "Exception when deleting the the StatefulSet of the job: " + statefulSetName, e);
        return false;
    }
}
Also used : Response(com.squareup.okhttp.Response) V1DeleteOptions(io.kubernetes.client.models.V1DeleteOptions) IOException(java.io.IOException) ApiException(io.kubernetes.client.ApiException)

Example 10 with ApiException

use of io.kubernetes.client.ApiException in project incubator-heron by apache.

the class AppsV1beta1Controller method deleteStatefulSet.

boolean deleteStatefulSet() {
    try {
        final V1DeleteOptions options = new V1DeleteOptions();
        options.setGracePeriodSeconds(0L);
        options.setPropagationPolicy(KubernetesConstants.DELETE_OPTIONS_PROPAGATION_POLICY);
        final Response response = client.deleteNamespacedStatefulSetCall(getTopologyName(), getNamespace(), options, null, null, null, null, null, null).execute();
        if (!response.isSuccessful()) {
            LOG.log(Level.SEVERE, "Error killing topology message: " + response.message());
            KubernetesUtils.logResponseBodyIfPresent(LOG, response);
            throw new TopologyRuntimeManagementException(KubernetesUtils.errorMessageFromResponse(response));
        }
    } catch (IOException | ApiException e) {
        KubernetesUtils.logExceptionWithDetails(LOG, "Error deleting topology", e);
        return false;
    }
    return true;
}
Also used : Response(com.squareup.okhttp.Response) V1DeleteOptions(io.kubernetes.client.models.V1DeleteOptions) TopologyRuntimeManagementException(com.twitter.heron.scheduler.TopologyRuntimeManagementException) IOException(java.io.IOException) ApiException(io.kubernetes.client.ApiException)

Aggregations

ApiException (io.kubernetes.client.ApiException)29 IOException (java.io.IOException)11 CallBuilderFactory (oracle.kubernetes.operator.helpers.CallBuilderFactory)9 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)7 Response (com.squareup.okhttp.Response)5 ApiClient (io.kubernetes.client.ApiClient)5 TopologyRuntimeManagementException (com.twitter.heron.scheduler.TopologyRuntimeManagementException)4 V1DeleteOptions (io.kubernetes.client.models.V1DeleteOptions)3 V1Secret (io.kubernetes.client.models.V1Secret)3 V1beta1StatefulSet (io.kubernetes.client.models.V1beta1StatefulSet)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 JSON (io.kubernetes.client.JSON)2 CustomObjectsApi (io.kubernetes.client.apis.CustomObjectsApi)2 V1Namespace (io.kubernetes.client.models.V1Namespace)2 V1Pod (io.kubernetes.client.models.V1Pod)2 V1PodList (io.kubernetes.client.models.V1PodList)2 V1ServiceAccount (io.kubernetes.client.models.V1ServiceAccount)2 V1ServiceAccountList (io.kubernetes.client.models.V1ServiceAccountList)2