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 2016/02/01 18:51:53 UTC

[34/50] brooklyn-ui git commit: Issue #194: refactors EntityClass

Issue #194: refactors EntityClass

* Deletes EntityLocal.getConfigKeys(), EntityLocal.getSensors() and
  EntityLocal.getEffectors(). These methods are already on EntityClass.
* Renames EntityClass to EntityType.
* cleans up the javadoc and the comments.
* Returns an immutable snapshot of the set of sensors/effectors/configs.
* Subsequent call to entity.getEntityType().getSensors() will include
  any sensors added/removed on-the-fly.
  This includes for entity.setAttribute() with new AttributeSensors.


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

Branch: refs/heads/0.4.0
Commit: f0e81a6d45c6f6b562a77a82d07c3ad5c1968789
Parents: 9ff76b2
Author: Aled Sage <al...@gmail.com>
Authored: Tue Jul 10 10:23:15 2012 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Jul 13 16:19:15 2012 +0100

----------------------------------------------------------------------
 .../web/console/EntityController.groovy         |   2 +-
 .../brooklyn/web/console/EntityService.groovy   |   4 +-
 .../web/console/TestWebApplication.groovy       | 107 ++++++++-----------
 .../web/console/entity/EntitySummary.groovy     |   6 +-
 .../web/console/entity/LocationSummary.groovy   |   7 --
 .../web/console/entity/PolicySummary.groovy     |  11 +-
 6 files changed, 53 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/f0e81a6d/usage/web-console/grails-app/controllers/brooklyn/web/console/EntityController.groovy
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/controllers/brooklyn/web/console/EntityController.groovy b/usage/web-console/grails-app/controllers/brooklyn/web/console/EntityController.groovy
index 121546e..5e4e72a 100644
--- a/usage/web-console/grails-app/controllers/brooklyn/web/console/EntityController.groovy
+++ b/usage/web-console/grails-app/controllers/brooklyn/web/console/EntityController.groovy
@@ -168,7 +168,7 @@ class EntityController {
 
         try {
             Entity ent = entityService.getEntity(params.entityId);
-            def v = ent.getAttribute(ent.getSensors().get(params.sensorId));
+            def v = ent.getAttribute(ent.getEntityType().getSensor(params.sensorId));
             try { render(v as JSON) }
             catch (Exception e) {
                 //not json, just return as text

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/f0e81a6d/usage/web-console/grails-app/services/brooklyn/web/console/EntityService.groovy
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/services/brooklyn/web/console/EntityService.groovy b/usage/web-console/grails-app/services/brooklyn/web/console/EntityService.groovy
index 10ae733..b64aa95 100644
--- a/usage/web-console/grails-app/services/brooklyn/web/console/EntityService.groovy
+++ b/usage/web-console/grails-app/services/brooklyn/web/console/EntityService.groovy
@@ -81,7 +81,7 @@ public class EntityService {
             }
 
             sensorCache.putIfAbsent(entity.id, new ConcurrentHashMap<String, SensorSummary>())
-            for (Sensor s : entity.entityClass.sensors) {
+            for (Sensor s : entity.getEntityType().getSensors()) {
                 if (s instanceof AttributeSensor) {
                     sensorCache[entity.id].putIfAbsent(s.name, new SensorSummary(s, entity.getAttribute(s)))
                 }
@@ -141,7 +141,7 @@ public class EntityService {
         Entity entity = getEntity(entityId)
         if (!entity) throw new NoSuchEntity()
         
-        return entity.entityClass.effectors
+        return entity.getEntityType().getEffectors()
     }
 
     public Collection<Policy> getPoliciesOfEntity(Entity entity) {

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/f0e81a6d/usage/web-console/grails-app/utils/brooklyn/web/console/TestWebApplication.groovy
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/utils/brooklyn/web/console/TestWebApplication.groovy b/usage/web-console/grails-app/utils/brooklyn/web/console/TestWebApplication.groovy
index f484c74..baa1381 100644
--- a/usage/web-console/grails-app/utils/brooklyn/web/console/TestWebApplication.groovy
+++ b/usage/web-console/grails-app/utils/brooklyn/web/console/TestWebApplication.groovy
@@ -1,10 +1,11 @@
 package brooklyn.web.console
 
 import grails.converters.JSON
-import groovy.time.TimeDuration;
 
 import java.util.concurrent.TimeUnit
 
+import com.google.common.collect.ImmutableList
+
 import brooklyn.entity.Effector
 import brooklyn.entity.Entity
 import brooklyn.entity.ParameterType
@@ -14,7 +15,6 @@ import brooklyn.entity.basic.AbstractGroup
 import brooklyn.entity.basic.BasicParameterType
 import brooklyn.entity.basic.EntityLocal
 import brooklyn.entity.webapp.tomcat.TomcatServer
-import brooklyn.event.AttributeSensor
 import brooklyn.event.Sensor
 import brooklyn.event.basic.BasicAttributeSensor
 import brooklyn.location.Location
@@ -28,10 +28,14 @@ import brooklyn.util.task.ScheduledTask
 import brooklyn.web.console.entity.TestEffector
 
 // TODO remove these test classes as soon as the group agrees they're unnecessary!
-private class TestWebApplication extends AbstractApplication {
+public class TestWebApplication extends AbstractApplication {
     
     static { BrooklynLanguageExtensions.reinit() }
-    
+
+    public static final BasicAttributeSensor<Integer> CHILDREN = new BasicAttributeSensor<Integer>(Integer.class, "Children",
+                "Owned children of this application");
+    public static final BasicAttributeSensor<String> DATA_RATE = new BasicAttributeSensor<String>(String.class, "DataRate");
+
     TestWebApplication(Map props=[:]) {
         super(props)
         displayName = "Application";
@@ -79,11 +83,7 @@ private class TestWebApplication extends AbstractApplication {
             addOwnedChild(tier)
         }
 
-        sensors.putAll([
-                Children: new BasicAttributeSensor<Integer>(Integer.class, "Children",
-                        "Owned children of this application"),
-                        DataRate: new BasicAttributeSensor<String>(String.class, "DataRate")])
-        setAttribute(getSensor("Children"), getOwnedChildren().size())
+        setAttribute(CHILDREN, getOwnedChildren().size())
     }
 
     public <T> Task<T> invoke(Effector<T> eff, Map<String, ?> parameters) {
@@ -131,19 +131,21 @@ private class TestWebApplication extends AbstractApplication {
         new Thread(r).start();
     }
 
-    private class TestGroupEntity extends AbstractGroup {
+    public static class TestGroupEntity extends AbstractGroup {
+        public static final BasicAttributeSensor<Integer> CHILDREN = new BasicAttributeSensor<Integer>(Integer.class, "Children",
+            "Direct children of this group");
+        public static final BasicAttributeSensor<String> DATA_RATE = new BasicAttributeSensor<String>(String.class, "DataRate");
+
         TestGroupEntity(Entity owner, String displayName) {
             super([:], owner)
             this.displayName = displayName
-            sensors.putAll([Children: new BasicAttributeSensor<Integer>(Integer.class, "Children",
-                    "Direct children of this group"), DataRate: new BasicAttributeSensor<String>(String.class, "DataRate")])
         }
 
         public Entity addOwnedChild(Entity child) {
             // TODO using super.addOwnedChild gives StackOverflowException. Sounds similar to http://jira.codehaus.org/browse/GROOVY-5385,
             // except that changing the return type to match super's doesn't fix it...
             child.setOwner(this)
-            setAttribute(getSensor("Children"), ownedChildren.size())
+            setAttribute(CHILDREN, ownedChildren.size())
             return this
         }
 
@@ -153,7 +155,18 @@ private class TestWebApplication extends AbstractApplication {
     }
 
 
-    private class TestDataEntity extends AbstractEntity {
+    public static class TestDataEntity extends AbstractEntity {
+        public static final BasicAttributeSensor<String> HAPPINESS = new BasicAttributeSensor<String>(String.class, "Happiness");
+        public static final BasicAttributeSensor<String> CACHE = new BasicAttributeSensor<String>(String.class, "Cache", "Some cache metric");
+        public static final BasicAttributeSensor<String> SYNC = new BasicAttributeSensor<String>(String.class, "Sync", "Synchronization strategy");
+
+        public static final TestEffector START_DB = new TestEffector("Start DB", "This will start the database",
+                new ArrayList<ParameterType<?>>());
+        public static final TestEffector STOP_DB = new TestEffector("Stop DB", "This will stop the database",
+                new ArrayList<ParameterType<?>>());
+        public static final TestEffector RESTART_DB = new TestEffector("Restart DB", "This will restart the DB",
+                new ArrayList<ParameterType<?>>());
+            
         private List<Location> testLocations = [
             new SimulatedLocation([id: "us-east-1", name:"US-East-1", iso3166: "US-CA", displayName:"US-East-1", streetAddress:"Northern Virginia, USA", description:"Northern Virginia (approx)",
                                         latitude:38.0,longitude:-76.0]),
@@ -172,24 +185,10 @@ private class TestWebApplication extends AbstractApplication {
             this.displayName = displayName
             this.locations = testLocations;
             this.policies = testPolicies;
-            TestEffector startDB = new TestEffector("Start DB", "This will start the database",
-                    new ArrayList<ParameterType<?>>())
-            TestEffector stopDB = new TestEffector("Stop DB", "This will stop the database",
-                    new ArrayList<ParameterType<?>>())
-            TestEffector restartDB = new TestEffector("Restart DB", "This will restart the DB",
-                    new ArrayList<ParameterType<?>>())
-
-            this.effectors.putAll(["Start DB": startDB, "Stop DB": stopDB, "Restart DB": restartDB])
-
-            this.sensors.putAll(
-                   [Happiness: new BasicAttributeSensor<String>(String.class, "Happiness"),
-                    Cache: new BasicAttributeSensor<String>(String.class, "Cache", "Some cache metric"),
-                    Sync: new BasicAttributeSensor<String>(String.class, "Sync", "Synchronization strategy")]
-            )
-
-            setAttribute(getSensor("Happiness"), 50)
-            setAttribute(getSensor("Cache"), 200)
-            setAttribute(getSensor("Sync"), "Moop")
+
+            setAttribute(HAPPINESS, 50)
+            setAttribute(CACHE, 200)
+            setAttribute(SYNC, "Moop")
         }
 
         public <T> Task<T> invoke(Effector<T> eff, Map<String, ?> parameters) {
@@ -197,7 +196,17 @@ private class TestWebApplication extends AbstractApplication {
         }
     }
 
-    private class TestTomcatEntity extends AbstractEntity {
+    public static class TestTomcatEntity extends AbstractEntity {
+        public static final TestEffector START_TOMCAT = new TestEffector("Start Tomcat",
+                "This will start Tomcat at a specified location",
+                ImmutableList.of(new BasicParameterType("Location", new ArrayList<String>().class), new BasicParameterType("Date", Date.class)));
+        public static final TestEffector STOP_TOMCAT = new TestEffector("Stop Tomcat",
+                "This will stop tomcat at its current location",
+                new Collections.SingletonList(new BasicParameterType("Date", Date.class)));
+        public static final TestEffector RESTART_TOMCAT = new TestEffector("Restart Tomcat",
+                "This will restart tomcat in its current location",
+                new ArrayList<ParameterType<?>>());
+
         //FIXME should use typed keys not strings
         private Map hackMeIn = [
                 "http.port": 8080,
@@ -224,29 +233,7 @@ private class TestWebApplication extends AbstractApplication {
             this.policies = testPolicies;
 
             // Stealing the sensors from TomcatNode
-            this.sensors.putAll(new TomcatServer().sensors);
-
-            List<ParameterType<?>> parameterTypeList = new ArrayList<ParameterType<?>>()
-            ParameterType tomcatStartLocation = new BasicParameterType("Location", new ArrayList<String>().class)
-            ParameterType actionDate = new BasicParameterType("Date", Date.class)
-            parameterTypeList.add(tomcatStartLocation)
-            parameterTypeList.add(actionDate)
-
-
-            // Don't appear to be any effectors in TomcatServer
-            TestEffector startTomcat = new TestEffector("Start Tomcat",
-                                                        "This will start Tomcat at a specified location",
-                                                        parameterTypeList)
-            TestEffector stopTomcat = new TestEffector("Stop Tomcat",
-                                                        "This will stop tomcat at its current location",
-                                                        new Collections.SingletonList(actionDate))
-            TestEffector restartTomcat = new TestEffector("Restart Tomcat",
-                                                          "This will restart tomcat in its current location",
-                                                          new ArrayList<ParameterType<?>>())
-
-            this.effectors.putAll([  "Start Tomcat": startTomcat,
-                                "Stop Tomcat": stopTomcat,
-                                "Restart Tomcat": restartTomcat])
+            this.getMutableEntityType().addSensors(new TomcatServer().getEntityType().getSensors());
 
             //updates sensors (this doesn't seem to be working?)
             TestTomcatEntity tc = this;  //NB: ref to TestTomcatEntity.this breaks mvn build
@@ -259,7 +246,7 @@ private class TestWebApplication extends AbstractApplication {
                     { updateSensorsWithRandoms(tc); }));
                 
             updateSensorsWithRandoms(this);
-            setAttribute(sensors.get("webapp.url"), "http://localhost:8080/my-web-app-here");
+            setAttribute(TomcatServer.ROOT_URL, "http://localhost:8080/my-web-app-here");
         }
 
         public <T> Task<T> invoke(Effector<T> eff, Map<String, ?> parameters) {
@@ -281,11 +268,9 @@ private class TestWebApplication extends AbstractApplication {
         }
     }
     
-    public void updateSensorsWithRandoms(EntityLocal entity) {
-        Map ss = entity.getSensors()
+    public static void updateSensorsWithRandoms(EntityLocal entity) {
         for (String key: entity.hackMeIn.keySet()) {
-            def s = ss[key]
-//                        System.out.println("updating $entity $ss $s");
+            Sensor s = entity.getEntityType().getSensor(key)
             if (s != null){
                 entity.setAttribute(s,
                     entity.hackMeIn[key] + ManagementContextService.ID_GENERATOR +

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/f0e81a6d/usage/web-console/grails-app/utils/brooklyn/web/console/entity/EntitySummary.groovy
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/utils/brooklyn/web/console/entity/EntitySummary.groovy b/usage/web-console/grails-app/utils/brooklyn/web/console/entity/EntitySummary.groovy
index c77c18f..690672c 100644
--- a/usage/web-console/grails-app/utils/brooklyn/web/console/entity/EntitySummary.groovy
+++ b/usage/web-console/grails-app/utils/brooklyn/web/console/entity/EntitySummary.groovy
@@ -1,7 +1,7 @@
 package brooklyn.web.console.entity;
 
 import brooklyn.entity.Entity
-import brooklyn.entity.EntityClass
+import brooklyn.entity.EntityType
 import brooklyn.entity.Group
 import brooklyn.entity.basic.Attributes
 import brooklyn.entity.trait.Startable
@@ -10,7 +10,7 @@ import brooklyn.entity.trait.Startable
 public class EntitySummary {
 
     final String id;
-    final EntityClass entityClass;
+    final EntityType entityType;
     final String displayName;
     final String applicationId;
     final String ownerId;
@@ -21,7 +21,7 @@ public class EntitySummary {
 
     public EntitySummary(Entity entity) {
         this.id = entity.getId();
-        this.entityClass = entity.entityClass;
+        this.entityType = entity.entityType;
         this.displayName = entity.displayName;
         this.applicationId = entity.application?.getId();
         this.ownerId = entity.owner ? entity.owner.id : null;

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/f0e81a6d/usage/web-console/grails-app/utils/brooklyn/web/console/entity/LocationSummary.groovy
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/utils/brooklyn/web/console/entity/LocationSummary.groovy b/usage/web-console/grails-app/utils/brooklyn/web/console/entity/LocationSummary.groovy
index 8ca4844..f071cb2 100644
--- a/usage/web-console/grails-app/utils/brooklyn/web/console/entity/LocationSummary.groovy
+++ b/usage/web-console/grails-app/utils/brooklyn/web/console/entity/LocationSummary.groovy
@@ -1,12 +1,5 @@
 package brooklyn.web.console.entity;
 
-import brooklyn.entity.Entity
-import brooklyn.entity.EntityClass
-import brooklyn.entity.Group
-import brooklyn.entity.Effector
-import brooklyn.entity.basic.AbstractEntity
-import brooklyn.event.AttributeSensor
-import brooklyn.event.Sensor
 import brooklyn.location.Location
 import brooklyn.location.basic.AbstractLocation
 

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/f0e81a6d/usage/web-console/grails-app/utils/brooklyn/web/console/entity/PolicySummary.groovy
----------------------------------------------------------------------
diff --git a/usage/web-console/grails-app/utils/brooklyn/web/console/entity/PolicySummary.groovy b/usage/web-console/grails-app/utils/brooklyn/web/console/entity/PolicySummary.groovy
index 2b15b2d..b8bf302 100644
--- a/usage/web-console/grails-app/utils/brooklyn/web/console/entity/PolicySummary.groovy
+++ b/usage/web-console/grails-app/utils/brooklyn/web/console/entity/PolicySummary.groovy
@@ -1,18 +1,9 @@
 package brooklyn.web.console.entity;
 
-import brooklyn.entity.Entity
-import brooklyn.entity.EntityClass
-import brooklyn.entity.Group
-import brooklyn.entity.Effector
-import brooklyn.entity.basic.AbstractEntity
-import brooklyn.event.AttributeSensor
-import brooklyn.event.Sensor
-import brooklyn.location.Location
-import brooklyn.location.basic.AbstractLocation
 import brooklyn.policy.Policy
 import brooklyn.policy.basic.AbstractPolicy
 
-/** Summary of a Brookln Entity Location   */
+/** Summary of a Brookln Entity Policy   */
 public class PolicySummary {
     final String displayName
     final String policyStatus