You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2017/06/28 22:01:49 UTC

[1/2] brooklyn-server git commit: BROOKLYN-520: better error if type missing

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 1df0db3c8 -> c2326132d


BROOKLYN-520: better error if type missing


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

Branch: refs/heads/master
Commit: eb03dca56796c72cace595a2b8a86224365da8bd
Parents: 1df0db3
Author: Aled Sage <al...@gmail.com>
Authored: Wed Jun 28 16:04:35 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Jun 28 17:38:09 2017 +0100

----------------------------------------------------------------------
 .../BrooklynComponentTemplateResolver.java      |  12 +-
 .../brooklyn/ValidationMissingTypeYamlTest.java | 222 +++++++++++++++++++
 2 files changed, 232 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/eb03dca5/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
index 7e9b562..e0cbe47 100644
--- a/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
+++ b/camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/BrooklynComponentTemplateResolver.java
@@ -18,6 +18,8 @@
  */
 package org.apache.brooklyn.camp.brooklyn.spi.creation;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedHashSet;
@@ -97,12 +99,12 @@ public class BrooklynComponentTemplateResolver {
     private final EntitySpecResolver serviceSpecResolver;
 
     private BrooklynComponentTemplateResolver(BrooklynClassLoadingContext loader, ConfigBag attrs, AbstractResource optionalTemplate, String type) {
-        this.loader = loader;
+        this.loader = checkNotNull(loader, "loader");
         this.mgmt = loader.getManagementContext();
         this.attrs = ConfigBag.newInstanceCopying(attrs);
         this.template = Maybe.fromNullable(optionalTemplate);
         this.yamlLoader = new BrooklynYamlTypeInstantiator.Factory(loader, this);
-        this.type = type;
+        this.type = checkNotNull(type, "type");
         this.serviceSpecResolver = new CampServiceSpecResolver(mgmt, getServiceTypeResolverOverrides());
     }
 
@@ -130,6 +132,12 @@ public class BrooklynComponentTemplateResolver {
 
         private static BrooklynComponentTemplateResolver newInstance(BrooklynClassLoadingContext context, ConfigBag attrs, AbstractResource optionalTemplate) {
             String type = getDeclaredType(null, optionalTemplate, attrs);
+            if (Strings.isBlank(type)) {
+                String msg = "No type defined " 
+                        + (attrs == null ? ", no attributes supplied" : "in " + "[" + attrs.getAllConfigRaw() + "]")
+                        + (optionalTemplate == null ? "" : ", template " + optionalTemplate);
+                throw new IllegalArgumentException(msg);
+            }
             return new BrooklynComponentTemplateResolver(context, attrs, optionalTemplate, type);
         }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/eb03dca5/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ValidationMissingTypeYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ValidationMissingTypeYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ValidationMissingTypeYamlTest.java
new file mode 100644
index 0000000..d71f381
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ValidationMissingTypeYamlTest.java
@@ -0,0 +1,222 @@
+/*
+ * 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 org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.core.test.entity.TestEntityImpl;
+import org.apache.brooklyn.core.test.policy.TestEnricher;
+import org.apache.brooklyn.core.test.policy.TestPolicy;
+import org.apache.brooklyn.entity.group.DynamicCluster;
+import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.text.Identifiers;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.Test;
+
+@Test
+public class ValidationMissingTypeYamlTest extends AbstractYamlTest {
+    private static final Logger log = LoggerFactory.getLogger(ValidationMissingTypeYamlTest.class);
+
+    
+    @Test
+    public void testNoEntityTypeSpecifiedInTopLevelService() throws Exception {
+        try {
+            createAndStartApplication(
+                    "services:",
+                    "- foo: " + TestEntityImpl.class.getName());
+            Asserts.shouldHaveFailedPreviously();
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "must declare a type");
+        }
+    }
+
+    @Test
+    public void testNoEntityTypeInTopLevelCatalogEntity() throws Exception {
+        try {
+            addCatalogItems(
+                    "brooklyn.catalog:",
+                    "  id: " + Identifiers.makeRandomId(8),
+                    "  version: 1.0.0",
+                    "  itemType: entity",
+                    "  item:",
+                    "    foo: " + TestEntity.class.getName());
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "must declare a type");
+        }
+    }
+
+    @Test
+    public void testNoEntityTypeInTopLevelCatalogApp() throws Exception {
+        try {
+            addCatalogItems(
+                    "brooklyn.catalog:",
+                    "  id: " + Identifiers.makeRandomId(8),
+                    "  version: 1.0.0",
+                    "  itemType: template",
+                    "  item:",
+                    "    services:",
+                    "    - foo: " + TestEntity.class.getName());
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "must declare a type");
+        }
+    }
+
+    @Test
+    public void testNoEntityTypeSpecifiedInChildService() throws Exception {
+        try {
+            createAndStartApplication(
+                    "services:",
+                    "- type: " + TestApplication.class.getName(),
+                    "  brooklyn.children:",
+                    "  - foo: " + TestEntityImpl.class.getName());
+            Asserts.shouldHaveFailedPreviously();
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "No type defined");
+        }
+    }
+    
+    @Test
+    public void testNoEntityTypeInChildCatalogEntity() throws Exception {
+        try {
+            addCatalogItems(
+                    "brooklyn.catalog:",
+                    "  id: " + Identifiers.makeRandomId(8),
+                    "  version: 1.0.0",
+                    "  itemType: entity",
+                    "  item:",
+                    "    type: " + TestApplication.class.getName(),
+                    "    brooklyn.children:",
+                    "    - foo: " + TestEntityImpl.class.getName());
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "No type defined");
+        }
+    }
+
+    @Test
+    public void testNoEntityTypeInChildCatalogApp() throws Exception {
+        try {
+            addCatalogItems(
+                    "brooklyn.catalog:",
+                    "  id: " + Identifiers.makeRandomId(8),
+                    "  version: 1.0.0",
+                    "  itemType: template",
+                    "  item:",
+                    "    services:",
+                    "    - type: " + TestApplication.class.getName(),
+                    "      brooklyn.children:",
+                    "      - foo: " + TestEntityImpl.class.getName());
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "No type defined");
+        }
+    }
+
+    @Test
+    public void testNoEntityTypeSpecifiedInEntitySpec() throws Exception {
+        try {
+            createAndStartApplication(
+                    "services:",
+                    "- type: " + DynamicCluster.class.getName(),
+                    "  brooklyn.config:",
+                    "    initialSize: 0",
+                    "    memberSpec: ",
+                    "      $brooklyn:entitySpec:",
+                    "        foo: " + TestEntityImpl.class.getName());
+            Asserts.shouldHaveFailedPreviously();
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "No type defined");
+        }
+    }
+    
+    @Test
+    public void testNoEntityTypeInEntitySpecInCatalogEntity() throws Exception {
+        try {
+            addCatalogItems(
+                    "brooklyn.catalog:",
+                    "  id: " + Identifiers.makeRandomId(8),
+                    "  version: 1.0.0",
+                    "  itemType: entity",
+                    "  item:",
+                    "    type: " + DynamicCluster.class.getName(),
+                    "    brooklyn.config:",
+                    "      initialSize: 0",
+                    "      memberSpec: ",
+                    "        $brooklyn:entitySpec:",
+                    "          foo: " + TestEntityImpl.class.getName());
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "No type defined");
+        }
+    }
+
+    @Test
+    public void testNoEntityTypeInEntitySpecInCatalogApp() throws Exception {
+        try {
+            addCatalogItems(
+                    "brooklyn.catalog:",
+                    "  id: " + Identifiers.makeRandomId(8),
+                    "  version: 1.0.0",
+                    "  itemType: template",
+                    "  item:",
+                    "    services:",
+                    "    - type: " + DynamicCluster.class.getName(),
+                    "      brooklyn.config:",
+                    "        initialSize: 0",
+                    "        memberSpec: ",
+                    "          $brooklyn:entitySpec:",
+                    "            foo: " + TestEntityImpl.class.getName());
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "No type defined");
+        }
+    }
+
+    // TODO Preferred name should not be 'policy_type'; it should be 'type'!
+    @Test
+    public void testNoPolicyTypeSpecified() throws Exception {
+        try {
+            createAndStartApplication(
+                    "services:",
+                    "- type: " + TestApplication.class.getName(),
+                    "  brooklyn.policies:",
+                    "  - foo: " + TestPolicy.class.getName());
+            Asserts.shouldHaveFailedPreviously();
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "Missing key 'policy_type'");
+        }
+    }
+    
+    // TODO Preferred name should not be 'enricher_type'; it should be 'type'!
+    @Test
+    public void testNoEnricherTypeSpecified() throws Exception {
+        try {
+            createAndStartApplication(
+                    "services:",
+                    "- type: " + TestApplication.class.getName(),
+                    "  brooklyn.enrichers:",
+                    "  - foo: " + TestEnricher.class.getName());
+            Asserts.shouldHaveFailedPreviously();
+        } catch (Exception e) {
+            Asserts.expectedFailureContains(e, "Missing key 'enricher_type'");
+        }
+    }
+    
+    @Override
+    protected Logger getLogger() {
+        return log;
+    }
+}


[2/2] brooklyn-server git commit: This closes #747

Posted by al...@apache.org.
This closes #747


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

Branch: refs/heads/master
Commit: c2326132d82efc0c3bb2bbf93fb5b773962d32e8
Parents: 1df0db3 eb03dca
Author: Aled Sage <al...@gmail.com>
Authored: Wed Jun 28 23:01:18 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Jun 28 23:01:18 2017 +0100

----------------------------------------------------------------------
 .../BrooklynComponentTemplateResolver.java      |  12 +-
 .../brooklyn/ValidationMissingTypeYamlTest.java | 222 +++++++++++++++++++
 2 files changed, 232 insertions(+), 2 deletions(-)
----------------------------------------------------------------------