actually force catalog load by default, and report errors better

and remove two incompatible items from the catalog, with comments in them - 
FollowTheSunPolicy and LoadBalancingPolicy


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

Branch: refs/heads/master
Commit: 65d7ee3c15afda7c5ed4507889fb632f1e2d5c8f
Parents: e629602
Author: Alex Heneveld <[email protected]>
Authored: Mon Apr 27 12:53:09 2015 +0100
Committer: Alex Heneveld <[email protected]>
Committed: Mon Apr 27 14:29:55 2015 +0100

----------------------------------------------------------------------
 .../policy/followthesun/FollowTheSunPolicy.java |  8 +++--
 .../loadbalancing/LoadBalancingPolicy.java      | 16 ++++++---
 usage/cli/src/main/java/brooklyn/cli/Main.java  | 34 +++++++++++++++++++-
 3 files changed, 49 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/65d7ee3c/policy/src/main/java/brooklyn/policy/followthesun/FollowTheSunPolicy.java
----------------------------------------------------------------------
diff --git 
a/policy/src/main/java/brooklyn/policy/followthesun/FollowTheSunPolicy.java 
b/policy/src/main/java/brooklyn/policy/followthesun/FollowTheSunPolicy.java
index 87881bf..f77eb40 100644
--- a/policy/src/main/java/brooklyn/policy/followthesun/FollowTheSunPolicy.java
+++ b/policy/src/main/java/brooklyn/policy/followthesun/FollowTheSunPolicy.java
@@ -33,7 +33,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import brooklyn.catalog.Catalog;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.Attributes;
 import brooklyn.entity.basic.EntityLocal;
@@ -53,8 +52,11 @@ import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 
-@Catalog(name="Follow the Sun", description="Policy for moving \"work\" around 
to follow the demand; "
-        + "the work can be any \"Movable\" entity")
+    // removed from catalog because it cannot currently be configured via 
catalog mechanisms - 
+    // PolicySpec.create fails due to no no-arg constructor
+    // TODO make model and parameters things which can be initialized from 
config then reinstate in catalog
+//@Catalog(name="Follow the Sun", description="Policy for moving \"work\" 
around to follow the demand; "
+//        + "the work can be any \"Movable\" entity")
 public class FollowTheSunPolicy extends AbstractPolicy {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(FollowTheSunPolicy.class);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/65d7ee3c/policy/src/main/java/brooklyn/policy/loadbalancing/LoadBalancingPolicy.java
----------------------------------------------------------------------
diff --git 
a/policy/src/main/java/brooklyn/policy/loadbalancing/LoadBalancingPolicy.java 
b/policy/src/main/java/brooklyn/policy/loadbalancing/LoadBalancingPolicy.java
index 0e36928..8a68461 100644
--- 
a/policy/src/main/java/brooklyn/policy/loadbalancing/LoadBalancingPolicy.java
+++ 
b/policy/src/main/java/brooklyn/policy/loadbalancing/LoadBalancingPolicy.java
@@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import brooklyn.catalog.Catalog;
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.EntityInternal;
@@ -67,10 +66,13 @@ import 
com.google.common.util.concurrent.ThreadFactoryBuilder;
  * of container resource in the pool respectively. These events may be 
consumed by a separate policy that is capable
  * of resizing the container pool.
  */
-@Catalog(name="Load Balancer", description="Policy that is attached to a pool 
of \"containers\", each of which "
-        + "can host one or more migratable \"items\". The policy monitors the 
workrates of the items and effects "
-        + "migrations in an attempt to ensure that the containers are all 
sufficiently utilized without any of "
-        + "them being overloaded.")
+    // removed from catalog because it cannot currently be configured via 
catalog mechanisms
+    // PolicySpec.create fails due to no no-arg constructor
+    // TODO make metric and model things which can be initialized from config 
then reinstate in catalog
+//@Catalog(name="Load Balancer", description="Policy that is attached to a 
pool of \"containers\", each of which "
+//        + "can host one or more migratable \"items\". The policy monitors 
the workrates of the items and effects "
+//        + "migrations in an attempt to ensure that the containers are all 
sufficiently utilized without any of "
+//        + "them being overloaded.")
 public class LoadBalancingPolicy<NodeType extends Entity, ItemType extends 
Movable> extends AbstractPolicy {
     
     private static final Logger LOG = 
LoggerFactory.getLogger(LoadBalancingPolicy.class);
@@ -120,6 +122,10 @@ public class LoadBalancingPolicy<NodeType extends Entity, 
ItemType extends Movab
         }
     };
 
+    public LoadBalancingPolicy() {
+        this(null, null);
+    }
+    
     public LoadBalancingPolicy(AttributeSensor<? extends Number> metric,
             BalanceablePoolModel<NodeType, ItemType> model) {
         this(MutableMap.of(), metric, model);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/65d7ee3c/usage/cli/src/main/java/brooklyn/cli/Main.java
----------------------------------------------------------------------
diff --git a/usage/cli/src/main/java/brooklyn/cli/Main.java 
b/usage/cli/src/main/java/brooklyn/cli/Main.java
index 45c6128..d89703e 100644
--- a/usage/cli/src/main/java/brooklyn/cli/Main.java
+++ b/usage/cli/src/main/java/brooklyn/cli/Main.java
@@ -38,7 +38,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import brooklyn.BrooklynVersion;
+import brooklyn.basic.BrooklynTypes;
 import brooklyn.catalog.BrooklynCatalog;
+import brooklyn.catalog.CatalogItem;
 import brooklyn.cli.CloudExplorer.BlobstoreGetBlobCommand;
 import brooklyn.cli.CloudExplorer.BlobstoreListContainerCommand;
 import brooklyn.cli.CloudExplorer.BlobstoreListContainersCommand;
@@ -72,6 +74,7 @@ import brooklyn.util.ResourceUtils;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.exceptions.FatalConfigurationRuntimeException;
 import brooklyn.util.exceptions.FatalRuntimeException;
+import brooklyn.util.exceptions.RuntimeInterruptedException;
 import brooklyn.util.exceptions.UserFacingException;
 import brooklyn.util.guava.Maybe;
 import brooklyn.util.javalang.Enums;
@@ -79,12 +82,15 @@ import brooklyn.util.net.Networking;
 import brooklyn.util.text.Identifiers;
 import brooklyn.util.text.StringEscapes.JavaStringEscapes;
 import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
 
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Function;
 import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 
 /**
  * This class is the primary CLI for brooklyn.
@@ -573,11 +579,37 @@ public class Main extends AbstractMain {
         /** method intended for subclassing, to add items to the catalog */
         protected void populateCatalog(BrooklynCatalog catalog) {
             // Force load of catalog (so web console is up to date)
-            catalog.getCatalogItems();
+            confirmCatalog(catalog);
 
             // nothing else added here
         }
 
+        protected void confirmCatalog(BrooklynCatalog catalog) {
+            // Force load of catalog (so web console is up to date)
+            Stopwatch time = Stopwatch.createStarted();
+            Iterable<CatalogItem<Object, Object>> items = 
catalog.getCatalogItems();
+            for (CatalogItem<Object, Object> item: items) {
+                try {
+                    Object spec = catalog.createSpec(item);
+                    if (spec instanceof EntitySpec) {
+                        
BrooklynTypes.getDefinedEntityType(((EntitySpec<?>)spec).getType());
+                    }
+                    log.debug("Catalog loaded spec "+spec+" for item "+item);  
                    
+                } catch (Throwable throwable) {
+                    // swallow errors, apart from interrupted
+                    if (throwable instanceof InterruptedException)
+                        throw new 
RuntimeInterruptedException((InterruptedException) throwable);
+                    if (throwable instanceof RuntimeInterruptedException)
+                        throw (RuntimeInterruptedException) throwable;
+
+                    log.error("Error loading catalog item '"+item+"': 
"+throwable);
+                    log.debug("Trace for error loading catalog item 
'"+item+"': "+throwable, throwable);
+                }
+            }
+            log.debug("Catalog (size "+Iterables.size(items)+") confirmed in 
"+Duration.of(time));                      
+            // nothing else added here
+        }
+        
         /** convenience for subclasses to specify that an app should run,
          * throwing the right (caught) error if another app has already been 
specified */
         protected void setAppToLaunch(String className) {

Reply via email to