Search in sources :

Example 6 with ApplyService

use of io.fabric8.maven.core.service.ApplyService in project fabric8 by jboss-fuse.

the class Controller method applyService.

public void applyService(Service service, String sourceName) throws Exception {
    String namespace = getNamespace();
    String id = getName(service);
    Objects.notNull(id, "No name for " + service + " " + sourceName);
    if (isIgnoreServiceMode()) {
        LOG.debug("Ignoring Service: " + namespace + ":" + id);
        return;
    }
    Service old = kubernetesClient.services().inNamespace(namespace).withName(id).get();
    if (isRunning(old)) {
        if (UserConfigurationCompare.configEqual(service, old)) {
            LOG.info("Service has not changed so not doing anything");
        } else {
            if (isRecreateMode()) {
                LOG.info("Deleting Service: " + id);
                kubernetesClient.services().inNamespace(namespace).withName(id).delete();
                doCreateService(service, namespace, sourceName);
            } else {
                LOG.info("Updating a Service from " + sourceName);
                try {
                    Object answer = kubernetesClient.services().inNamespace(namespace).withName(id).replace(service);
                    logGeneratedEntity("Updated Service: ", namespace, service, answer);
                } catch (Exception e) {
                    onApplyError("Failed to update Service from " + sourceName + ". " + e + ". " + service, e);
                }
            }
        }
    } else {
        if (!isAllowCreate()) {
            LOG.warn("Creation disabled so not creating a Service from " + sourceName + " namespace " + namespace + " name " + getName(service));
        } else {
            doCreateService(service, namespace, sourceName);
        }
    }
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) JSONObject(org.json.JSONObject) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) FileNotFoundException(java.io.FileNotFoundException) OpenShiftNotAvailableException(io.fabric8.openshift.client.OpenShiftNotAvailableException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 7 with ApplyService

use of io.fabric8.maven.core.service.ApplyService in project fabric8-maven-plugin by fabric8io.

the class ApplyService method applyService.

public void applyService(Service service, String sourceName) throws Exception {
    String namespace = getNamespace(service);
    String id = getName(service);
    Objects.requireNonNull(id, "No name for " + service + " " + sourceName);
    if (isIgnoreServiceMode()) {
        log.debug("Ignoring Service: " + namespace + ":" + id);
        return;
    }
    Service old = kubernetesClient.services().inNamespace(namespace).withName(id).get();
    if (isRunning(old)) {
        if (UserConfigurationCompare.configEqual(service, old)) {
            log.info("Service has not changed so not doing anything");
        } else {
            if (isRecreateMode()) {
                log.info("Deleting Service: " + id);
                kubernetesClient.services().inNamespace(namespace).withName(id).delete();
                doCreateService(service, namespace, sourceName);
            } else {
                log.info("Updating a Service from " + sourceName);
                try {
                    Object answer = patchService.compareAndPatchEntity(namespace, service, old);
                    logGeneratedEntity("Updated Service: ", namespace, service, answer);
                } catch (Exception e) {
                    onApplyError("Failed to update Service from " + sourceName + ". " + e + ". " + service, e);
                }
            }
        }
    } else {
        if (!isAllowCreate()) {
            log.warn("Creation disabled so not creating a Service from " + sourceName + " namespace " + namespace + " name " + getName(service));
        } else {
            doCreateService(service, namespace, sourceName);
        }
    }
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 IOException (java.io.IOException)7 Service (io.fabric8.kubernetes.api.model.Service)6 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 OpenShiftNotAvailableException (io.fabric8.openshift.client.OpenShiftNotAvailableException)4 FileNotFoundException (java.io.FileNotFoundException)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 Namespace (io.fabric8.kubernetes.api.model.Namespace)3 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)3 Pod (io.fabric8.kubernetes.api.model.Pod)3 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)3 Secret (io.fabric8.kubernetes.api.model.Secret)3 ServiceAccount (io.fabric8.kubernetes.api.model.ServiceAccount)3 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)3 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)3 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)3 DoneableImageStream (io.fabric8.openshift.api.model.DoneableImageStream)3 ImageStream (io.fabric8.openshift.api.model.ImageStream)3 OAuthClient (io.fabric8.openshift.api.model.OAuthClient)3