stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject [2/2] stratos git commit: Adding logic to remove kubernetes services when un-deploying an application
Date Wed, 24 Jun 2015 10:38:11 GMT
Adding logic to remove kubernetes services when un-deploying an application


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/04b8b25c
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/04b8b25c
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/04b8b25c

Branch: refs/heads/master
Commit: 04b8b25ce7946bfdd58c7b1ff5e5e186d4e154f0
Parents: 99d48ab
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Wed Jun 24 16:05:37 2015 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Wed Jun 24 16:08:06 2015 +0530

----------------------------------------------------------------------
 .../iaases/kubernetes/KubernetesIaas.java       | 31 ++++++++++++++++++++
 .../messaging/topology/TopologyBuilder.java     |  9 ++++++
 2 files changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/04b8b25c/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
index faeed2c..ef5e30a 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
@@ -866,4 +866,35 @@ public class KubernetesIaas extends Iaas {
     @Override
     public void allocateIpAddresses(String clusterId, MemberContext memberContext, Partition
partition) {
     }
+
+    /**
+     * Remove kubernetes services if available for application cluster.
+     * @param applicationId
+     * @param clusterId
+     */
+    public static void removeKubernetesServices(String applicationId, String clusterId) {
+
+        ClusterContext clusterContext =
+                CloudControllerContext.getInstance().getClusterContext(clusterId);
+        if(clusterContext != null) {
+            String kubernetesClusterId = clusterContext.getKubernetesClusterId();
+            if(org.apache.commons.lang3.StringUtils.isNotBlank(kubernetesClusterId)) {
+                KubernetesClusterContext kubernetesClusterContext =
+                        CloudControllerContext.getInstance().getKubernetesClusterContext(kubernetesClusterId);
+                if(kubernetesClusterContext != null) {
+                    KubernetesApiClient kubernetesApiClient = kubernetesClusterContext.getKubApi();
+                    for (KubernetesService kubernetesService : clusterContext.getKubernetesServices())
{
+                        log.info(String.format("Deleting kubernetes service: [application-id]
%s " +
+                                "[service-id] %s", applicationId, kubernetesService.getId()));
+                        try {
+                            kubernetesApiClient.deleteService(kubernetesService.getId());
+                        } catch (KubernetesClientException e) {
+                            log.error(String.format("Could not delete kubernetes service:
[application-id] %s " +
+                                    "[service-id] %s", applicationId, kubernetesService.getId()));
+                        }
+                    }
+                }
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/04b8b25c/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
index cfa7732..cee82d6 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
@@ -18,6 +18,7 @@
  */
 package org.apache.stratos.cloud.controller.messaging.topology;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.cloud.controller.context.CloudControllerContext;
@@ -25,6 +26,7 @@ import org.apache.stratos.cloud.controller.domain.*;
 import org.apache.stratos.cloud.controller.exception.CloudControllerException;
 import org.apache.stratos.cloud.controller.exception.InvalidCartridgeTypeException;
 import org.apache.stratos.cloud.controller.exception.InvalidMemberException;
+import org.apache.stratos.cloud.controller.iaases.kubernetes.KubernetesIaas;
 import org.apache.stratos.cloud.controller.messaging.publisher.TopologyEventPublisher;
 import org.apache.stratos.cloud.controller.statistics.publisher.BAMUsageDataPublisher;
 import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
@@ -1040,6 +1042,13 @@ public class TopologyBuilder {
                         event.getServiceName(), event.getClusterId(), event.getInstanceId());
 
                 TopologyEventPublisher.sendClusterTerminatingEvent(clusterTerminaingEvent);
+
+                // Remove kubernetes services if available
+                ClusterContext clusterContext =
+                        CloudControllerContext.getInstance().getClusterContext(event.getClusterId());
+                if(StringUtils.isNotBlank(clusterContext.getKubernetesClusterId())) {
+                    KubernetesIaas.removeKubernetesServices(event.getAppId(), event.getClusterId());
+                }
             } else {
                 log.error(String.format("Cluster state transition is not valid: [cluster-id]
%s " +
                                 " [instance-id] %s [current-status] %s [status-requested]
%s",


Mime
View raw message