You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/12/18 13:30:12 UTC

[21/50] git commit: [KARAF-2262] - cellar-cloud: The IP is not enough, sometimes the IP is hidden but a valid dns name is available

[KARAF-2262] - cellar-cloud: The IP is not enough, sometimes the IP is hidden but a valid dns name is available

git-svn-id: https://svn.apache.org/repos/asf/karaf/cellar/branches/cellar-2.2.x@1466083 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/cellar-2.2.x
Commit: b8ae18741d7eb4739e23932e866ef20bfd9866ec
Parents: cf24381
Author: anierbeck <an...@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Tue Apr 9 15:38:17 2013 +0000
Committer: anierbeck <an...@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Tue Apr 9 15:38:17 2013 +0000

----------------------------------------------------------------------
 .../cellar/cloud/BlobStoreDiscoveryService.java | 19 ++++++++++-
 .../karaf/cellar/cloud/ServiceContainer.java    | 35 ++++++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/b8ae1874/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryService.java
----------------------------------------------------------------------
diff --git a/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryService.java b/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryService.java
index 67157f7..09d83f4 100644
--- a/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryService.java
+++ b/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryService.java
@@ -102,6 +102,14 @@ public class BlobStoreDiscoveryService implements DiscoveryService {
                 } else {
                     blobStore.removeBlob(container, ip);
                 }
+            } else if (obj instanceof ServiceContainer) {
+            	ServiceContainer serviceContainer = (ServiceContainer) obj;
+            	DateTime registeredTime = serviceContainer.getRegisteredTime();
+            	if (registeredTime != null && registeredTime.plusSeconds(validityPeriod).isAfterNow()) {
+                    members.add(serviceContainer.getHostName());
+                } else {
+                    blobStore.removeBlob(container, ip);
+                }
             }
         }
         return members;
@@ -112,7 +120,7 @@ public class BlobStoreDiscoveryService implements DiscoveryService {
      */
     public void signIn() {
         DateTime now = new DateTime();
-        createBlob(container, ipAddress, now);
+        createBlob(container, ipAddress, new ServiceContainer(getHostAdress(),now));
     }
 
     /**
@@ -226,6 +234,15 @@ public class BlobStoreDiscoveryService implements DiscoveryService {
             return null;
         }
     }
+    
+    protected String getHostAdress() {
+    	try {
+			return InetAddress.getLocalHost().getHostName();
+		} catch (UnknownHostException ex) {
+			LOGGER.error("CELLAR CLOUD: unable to determine host address for current node", ex);
+            return null;
+		}
+    }
 
     public String getProvider() {
         return provider;

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/b8ae1874/cloud/src/main/java/org/apache/karaf/cellar/cloud/ServiceContainer.java
----------------------------------------------------------------------
diff --git a/cloud/src/main/java/org/apache/karaf/cellar/cloud/ServiceContainer.java b/cloud/src/main/java/org/apache/karaf/cellar/cloud/ServiceContainer.java
new file mode 100644
index 0000000..9ef62f4
--- /dev/null
+++ b/cloud/src/main/java/org/apache/karaf/cellar/cloud/ServiceContainer.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed 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.karaf.cellar.cloud;
+
+import org.joda.time.DateTime;
+
+public class ServiceContainer {
+
+	private DateTime registeredTime;
+	private String hostName;
+
+	public DateTime getRegisteredTime() {
+		return registeredTime;
+	}
+
+	public String getHostName() {
+		return hostName;
+	}
+	
+	public ServiceContainer(String hostName, DateTime registeredTime) {
+		this.registeredTime = registeredTime;
+		this.hostName = hostName;
+	}
+}