You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/10/10 16:20:53 UTC

[4/5] git commit: PodActivationWatcher is responsible for checking Pod's state and setting IPs and sending member spawned event.

PodActivationWatcher is responsible for checking Pod's state and setting IPs and sending member spawned event.


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

Branch: refs/heads/container-autoscaling
Commit: ff2a02fa1e1428ccb129774618c258aa83da3e6d
Parents: 78ee28b
Author: Nirmal Fernando <ni...@gmail.com>
Authored: Fri Oct 10 19:44:39 2014 +0530
Committer: Nirmal Fernando <ni...@gmail.com>
Committed: Fri Oct 10 19:50:27 2014 +0530

----------------------------------------------------------------------
 .../controller/util/PodActivationWatcher.java   | 74 ++++++++++++++++++++
 1 file changed, 74 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/ff2a02fa/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java
new file mode 100644
index 0000000..13d1ac6
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one 
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
+ * KIND, either express or implied.  See the License for the 
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cloud.controller.util;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.pojo.MemberContext;
+import org.apache.stratos.cloud.controller.registry.RegistryManager;
+import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
+import org.apache.stratos.cloud.controller.topology.TopologyBuilder;
+import org.apache.stratos.kubernetes.client.KubernetesApiClient;
+import org.apache.stratos.kubernetes.client.model.Pod;
+
+/**
+ * Checks whether a container is active and update the {@link FasterLookUpDataHolder}.
+ */
+public class PodActivationWatcher implements Runnable {
+
+    private static final Log LOG = LogFactory
+            .getLog(PodActivationWatcher.class);
+    private String podId;
+    private MemberContext ctxt;
+    private KubernetesApiClient kubApi;
+    
+    public PodActivationWatcher(String podId, MemberContext ctxt, KubernetesApiClient kubApi) {
+        this.podId = podId;
+        this.ctxt = ctxt;
+        this.kubApi = kubApi;
+    }
+
+    @Override
+    public void run() {
+        try {
+            Pod pod = kubApi.getPod(podId);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("PodActivationWatcher running : "+pod.getCurrentState().getStatus());
+            }
+            if ("Running".equals(pod.getCurrentState().getStatus())) {
+                String hostIP = pod.getCurrentState().getHost();
+                ctxt.setPublicIpAddress(hostIP);
+                ctxt.setPrivateIpAddress(hostIP);
+                FasterLookUpDataHolder.getInstance().addMemberContext(ctxt);
+                // trigger topology
+                TopologyBuilder.handleMemberSpawned(ctxt.getCartridgeType(), ctxt.getClusterId(), 
+                        null, hostIP, hostIP, ctxt);
+                
+                RegistryManager.getInstance().persist(FasterLookUpDataHolder.getInstance());
+                
+            }
+            
+        } catch (Exception e) {
+            LOG.error("Container Activation Watcher Failed.. ", e);
+        }
+        
+    }
+    
+}