Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3FF5011BA0 for ; Wed, 9 Jul 2014 21:47:00 +0000 (UTC) Received: (qmail 52802 invoked by uid 500); 9 Jul 2014 21:47:00 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 52777 invoked by uid 500); 9 Jul 2014 21:47:00 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 52768 invoked by uid 99); 9 Jul 2014 21:47:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Jul 2014 21:47:00 +0000 X-ASF-Spam-Status: No, hits=-2000.7 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 09 Jul 2014 21:46:48 +0000 Received: (qmail 48921 invoked by uid 99); 9 Jul 2014 21:46:17 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Jul 2014 21:46:17 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 29D37949CDB; Wed, 9 Jul 2014 21:46:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aledsage@apache.org To: commits@brooklyn.incubator.apache.org Date: Wed, 09 Jul 2014 21:46:44 -0000 Message-Id: <2c4602c6a26f47879bf3be282e28cc9b@git.apache.org> In-Reply-To: <5f8a29a5e5cd4cdc9c14e0f864f01308@git.apache.org> References: <5f8a29a5e5cd4cdc9c14e0f864f01308@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [31/50] git commit: Support for referencing Java catalog entities in YAML X-Virus-Checked: Checked by ClamAV on apache.org Support for referencing Java catalog entities 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/6dda7b6b Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/6dda7b6b Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/6dda7b6b Branch: refs/heads/master Commit: 6dda7b6ba9c985d5fa9619672ef0032d8459d244 Parents: c663e1e Author: Svetoslav Neykov Authored: Tue Jul 8 10:27:33 2014 +0300 Committer: Aled Sage Committed: Wed Jul 9 22:34:45 2014 +0100 ---------------------------------------------------------------------- .../BrooklynAssemblyTemplateInstantiator.java | 68 +++++++++++--------- .../rest/resources/ApplicationResourceTest.java | 18 ++++++ 2 files changed, 55 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6dda7b6b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java ---------------------------------------------------------------------- diff --git a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java index 604d8bf..46e50ed 100644 --- a/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java +++ b/usage/camp/src/main/java/io/brooklyn/camp/brooklyn/spi/creation/BrooklynAssemblyTemplateInstantiator.java @@ -360,38 +360,10 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe EntitySpec spec; CatalogItem> item = entityResolver.getCatalogItem(); - if (item != null) { - String yaml = item.getPlanYaml(); - Reader input = new StringReader(yaml); - - AssemblyTemplate at; - BrooklynClassLoadingContext itemLoader = item.newClassLoadingContext(mgmt); - BrooklynLoaderTracker.setLoader(itemLoader); - try { - at = platform.pdp().registerDeploymentPlan(input); - } finally { - BrooklynLoaderTracker.unsetLoader(itemLoader); - } - - // TODO Should we check entitlements, or sufficient to do once for this being called in the first place? - // TODO Is it acceptable to only allow a single top-level entity in a catalog? If not, we need to think - // about what it would mean to subsequently call buildChildrenEntitySpecs on the list of top-level entities! - try { - AssemblyTemplateInstantiator ati = at.getInstantiator().newInstance(); - if (ati instanceof BrooklynAssemblyTemplateInstantiator) { - List> specs = ((BrooklynAssemblyTemplateInstantiator)ati).buildTemplateServicesAsSpecs(itemLoader, at, platform); - if (specs.size() > 1) { - throw new UnsupportedOperationException("Only supporting single service in catalog item currently"); - } - spec = specs.get(0); - } else { - throw new IllegalStateException("Cannot create application with instantiator: " + ati); - } - } catch (Exception e) { - throw Exceptions.propagate(e); - } - } else { + if (item == null || item.getJavaType() != null) { spec = entityResolver.resolveSpec(); + } else { + spec = resolveCatalogYamlReferenceSpec(platform, mgmt, item); } BrooklynClassLoadingContext newLoader = entityResolver.loader; @@ -402,6 +374,40 @@ public class BrooklynAssemblyTemplateInstantiator implements AssemblyTemplateSpe return result; } + private EntitySpec resolveCatalogYamlReferenceSpec(CampPlatform platform, + ManagementContext mgmt, + CatalogItem> item) { + String yaml = item.getPlanYaml(); + Reader input = new StringReader(yaml); + + AssemblyTemplate at; + BrooklynClassLoadingContext itemLoader = item.newClassLoadingContext(mgmt); + BrooklynLoaderTracker.setLoader(itemLoader); + try { + at = platform.pdp().registerDeploymentPlan(input); + } finally { + BrooklynLoaderTracker.unsetLoader(itemLoader); + } + + // TODO Should we check entitlements, or sufficient to do once for this being called in the first place? + // TODO Is it acceptable to only allow a single top-level entity in a catalog? If not, we need to think + // about what it would mean to subsequently call buildChildrenEntitySpecs on the list of top-level entities! + try { + AssemblyTemplateInstantiator ati = at.getInstantiator().newInstance(); + if (ati instanceof BrooklynAssemblyTemplateInstantiator) { + List> specs = ((BrooklynAssemblyTemplateInstantiator)ati).buildTemplateServicesAsSpecs(itemLoader, at, platform); + if (specs.size() > 1) { + throw new UnsupportedOperationException("Only supporting single service in catalog item currently"); + } + return specs.get(0); + } else { + throw new IllegalStateException("Cannot create application with instantiator: " + ati); + } + } catch (Exception e) { + throw Exceptions.propagate(e); + } + } + protected void buildChildrenEntitySpecs(BrooklynClassLoadingContext loader, EntitySpec parent, List> childConfig) { if (childConfig != null) { for (Map childAttrs : childConfig) { http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6dda7b6b/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java ---------------------------------------------------------------------- diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java b/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java index e48ca92..a3c9a8f 100644 --- a/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java +++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java @@ -41,6 +41,7 @@ import org.testng.annotations.Test; import brooklyn.entity.Application; import brooklyn.entity.basic.BasicApplication; +import brooklyn.entity.basic.BasicEntity; import brooklyn.entity.basic.EntityFunctions; import brooklyn.entity.basic.Lifecycle; import brooklyn.location.Location; @@ -219,6 +220,23 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest { } @Test + public void testReferenceCatalogEntity() throws Exception { + getManagementContext().getCatalog().addItem(BasicEntity.class); + + String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType: " + BasicEntity.class.getName() + " } ] }"; + + ClientResponse response = client().resource("/v1/applications") + .entity(yaml, "application/x-yaml") + .post(ClientResponse.class); + assertTrue(response.getStatus()/100 == 2, "response is "+response); + + // Expect app to be running + URI appUri = response.getLocation(); + waitForApplicationToBeRunning(response.getLocation()); + assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-yaml"); + } + + @Test public void testDeployWithInvalidEntityType() { try { clientDeploy(