You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2015/12/17 13:32:34 UTC

[3/7] incubator-brooklyn git commit: Group to be tracked by GeoDns can be set at entity creation

Group to be tracked by GeoDns can be set at entity creation

Which means the service can be configured in YAML


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

Branch: refs/heads/master
Commit: ecfca898c9508ba3bd4d78f94d8176c4e1c4b5c8
Parents: 06a8f61
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Wed Dec 9 16:34:42 2015 +0000
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Wed Dec 9 16:55:57 2015 +0000

----------------------------------------------------------------------
 .../entity/dns/AbstractGeoDnsService.java       |  9 +++-
 .../entity/dns/AbstractGeoDnsServiceImpl.java   | 16 +++++--
 .../camp/brooklyn/AbstractYamlTest.java         | 10 ++---
 .../camp/brooklyn/GeoDnsServiceYamlTest.java    | 45 ++++++++++++++++++++
 .../apache/brooklyn/camp/brooklyn/geodns.yaml   | 42 ++++++++++++++++++
 5 files changed, 111 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ecfca898/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsService.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsService.java b/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsService.java
index 43c7b97..0535f2c 100644
--- a/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsService.java
+++ b/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsService.java
@@ -30,17 +30,24 @@ import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.entity.trait.Startable;
 import org.apache.brooklyn.core.location.geo.HostGeoInfo;
 import org.apache.brooklyn.core.sensor.Sensors;
+import org.apache.brooklyn.util.core.flags.SetFromFlag;
 
 import com.google.common.reflect.TypeToken;
 
 public interface AbstractGeoDnsService extends Entity {
     
+    @SetFromFlag("includeHomelessEntities")
     ConfigKey<Boolean> INCLUDE_HOMELESS_ENTITIES = ConfigKeys.newBooleanConfigKey(
             "geodns.includeHomeless", "Whether to include entities whose geo-coordinates cannot be inferred", false);
 
+    @SetFromFlag("useHostnames")
     ConfigKey<Boolean> USE_HOSTNAMES = ConfigKeys.newBooleanConfigKey(
             "geodns.useHostnames", "Whether to use the hostname for the returned value for routing, rather than IP address (defaults to true)", true);
-    
+
+    @SetFromFlag("provider")
+    ConfigKey<Group> ENTITY_PROVIDER = ConfigKeys.newConfigKey(Group.class,
+            "geodns.entityProvider", "The group whose members should be tracked");
+
     AttributeSensor<Lifecycle> SERVICE_STATE_ACTUAL = Attributes.SERVICE_STATE_ACTUAL;
     AttributeSensor<Boolean> SERVICE_UP = Startable.SERVICE_UP;
     AttributeSensor<String> HOSTNAME = Attributes.HOSTNAME;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ecfca898/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceImpl.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceImpl.java b/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceImpl.java
index 729351a..e18d3e1 100644
--- a/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceImpl.java
+++ b/software/webapp/src/main/java/org/apache/brooklyn/entity/dns/AbstractGeoDnsServiceImpl.java
@@ -83,6 +83,15 @@ public abstract class AbstractGeoDnsServiceImpl extends AbstractEntity implement
     }
     
     @Override
+    public void init() {
+        super.init();
+        Group initialProvider = config().get(ENTITY_PROVIDER);
+        if (initialProvider != null) {
+            setTargetEntityProvider(initialProvider);
+        }
+    }
+
+    @Override
     public Map<Entity, HostGeoInfo> getTargetHosts() {
         return targetHosts;
     }
@@ -174,14 +183,13 @@ public abstract class AbstractGeoDnsServiceImpl extends AbstractEntity implement
             }
             // anything left in previousOnes is no longer applicable
             for (Entity e: previousOnes) {
-                changed = true;
-                removeTargetHost(e, false);
+                changed |= removeTargetHost(e, false);
             }
             
             // do a periodic full update hourly once we are active (the latter is probably not needed)
-            if (changed || (lastUpdate>0 && Time.hasElapsedSince(lastUpdate, Duration.ONE_HOUR)))
+            if (changed || (lastUpdate > 0 && Time.hasElapsedSince(lastUpdate, Duration.ONE_HOUR))) {
                 update();
-            
+            }
         } catch (Exception e) {
             log.error("Problem refreshing group membership: "+e, e);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ecfca898/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
index 06dfaa3..909564c 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
@@ -110,13 +110,13 @@ public abstract class AbstractYamlTest {
         return createAndStartApplication(joinLines(multiLineYaml));
     }
     
-    protected Entity createAndStartApplication(String input) throws Exception {
-        return createAndStartApplication(new StringReader(input));
+    protected Entity createAndStartApplication(Reader input) throws Exception {
+        return createAndStartApplication(Streams.readFully(input));
     }
 
-    protected Entity createAndStartApplication(Reader input) throws Exception {
+    protected Entity createAndStartApplication(String input) throws Exception {
         EntitySpec<?> spec = 
-            mgmt().getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT, Streams.readFully(input), RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
+            mgmt().getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT, input, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class);
         final Entity app = brooklynMgmt.getEntityManager().createEntity(spec);
         // start the app (happens automatically if we use camp to instantiate, but not if we use crate spec approach)
         app.invoke(Startable.START, MutableMap.<String,String>of()).get();
@@ -126,9 +126,7 @@ public abstract class AbstractYamlTest {
     protected Entity createStartWaitAndLogApplication(Reader input) throws Exception {
         Entity app = createAndStartApplication(input);
         waitForApplicationTasks(app);
-
         getLogger().info("App started: "+app);
-        
         return app;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ecfca898/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/GeoDnsServiceYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/GeoDnsServiceYamlTest.java b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/GeoDnsServiceYamlTest.java
new file mode 100644
index 0000000..3f41e8d
--- /dev/null
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/GeoDnsServiceYamlTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.brooklyn.camp.brooklyn;
+
+import static org.testng.Assert.assertEquals;
+
+import org.apache.brooklyn.api.entity.Application;
+import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
+import org.apache.brooklyn.entity.dns.AbstractGeoDnsService;
+import org.apache.brooklyn.entity.dns.geoscaling.GeoscalingDnsService;
+import org.apache.brooklyn.entity.group.DynamicFabric;
+import org.apache.brooklyn.util.stream.Streams;
+import org.testng.annotations.Test;
+
+public class GeoDnsServiceYamlTest extends AbstractYamlTest {
+
+    @Test
+    public void testTargetGroupCanBeSetInYaml() throws Exception {
+        final String resourceName = "classpath:/" + getClass().getPackage().getName().replace('.', '/') + "/geodns.yaml";
+        final String blueprint = Streams.readFully(loadYaml(resourceName));
+        Application app = EntityManagementUtils.createUnstarted(mgmt(), blueprint);
+        GeoscalingDnsService geodns = Entities.descendants(app, GeoscalingDnsService.class).iterator().next();
+        DynamicFabric fabric = Entities.descendants(app, DynamicFabric.class).iterator().next();
+        assertEquals(geodns.config().get(AbstractGeoDnsService.ENTITY_PROVIDER), fabric);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ecfca898/usage/camp/src/test/resources/org/apache/brooklyn/camp/brooklyn/geodns.yaml
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/resources/org/apache/brooklyn/camp/brooklyn/geodns.yaml b/usage/camp/src/test/resources/org/apache/brooklyn/camp/brooklyn/geodns.yaml
new file mode 100644
index 0000000..3fdc7b7
--- /dev/null
+++ b/usage/camp/src/test/resources/org/apache/brooklyn/camp/brooklyn/geodns.yaml
@@ -0,0 +1,42 @@
+#
+# 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.
+#
+services:
+
+- name: Web cluster
+  type: org.apache.brooklyn.entity.group.DynamicRegionsFabric
+  id: web-fabric
+
+  # Location required but test should not do any provisioning.
+  locations:
+  - localhost
+
+  memberSpec:
+    $brooklyn:entitySpec:
+      type: org.apache.brooklyn.entity.webapp.ControlledDynamicWebAppCluster
+      brooklyn.config:
+        initialSize: 0
+
+- name: Geo DNS
+  type: org.apache.brooklyn.entity.dns.geoscaling.GeoscalingDnsService
+  brooklyn.config:
+    provider: $brooklyn:component("web-fabric")
+    username: madeUp
+    password: madeUp
+    primaryDomainName: example.com
+    smartSubdomainName: test