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 6B08E18829 for ; Wed, 13 May 2015 15:36:58 +0000 (UTC) Received: (qmail 82856 invoked by uid 500); 13 May 2015 15:36:58 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 82833 invoked by uid 500); 13 May 2015 15:36:58 -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 82824 invoked by uid 99); 13 May 2015 15:36:58 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 May 2015 15:36:58 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id B0848C47B2 for ; Wed, 13 May 2015 15:36:57 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.791 X-Spam-Level: * X-Spam-Status: No, score=1.791 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id nrJK8QpA71EB for ; Wed, 13 May 2015 15:36:51 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id CF153230CB for ; Wed, 13 May 2015 15:36:50 +0000 (UTC) Received: (qmail 82793 invoked by uid 99); 13 May 2015 15:36:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 May 2015 15:36:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8FA61E0779; Wed, 13 May 2015 15:36:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: andreaturli@apache.org To: commits@brooklyn.incubator.apache.org Date: Wed, 13 May 2015 15:36:50 -0000 Message-Id: <2c720a9768bf4507ba86273022507f63@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] incubator-brooklyn git commit: Add initial support for PaaS locations by using ReflectiveEntityDriverFactory. Repository: incubator-brooklyn Updated Branches: refs/heads/master 1e04ec160 -> 3fe40c7b5 Add initial support for PaaS locations by using ReflectiveEntityDriverFactory. Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/f32fa3cf Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/f32fa3cf Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/f32fa3cf Branch: refs/heads/master Commit: f32fa3cff2174dae18758533e51bddb482eef2c2 Parents: 78776ca Author: Miguel Barrientos Authored: Tue May 5 21:02:27 2015 +0200 Committer: Miguel Barrientos Committed: Tue May 5 21:02:27 2015 +0200 ---------------------------------------------------------------------- .../drivers/ReflectiveEntityDriverFactory.java | 17 ++++++++ .../brooklyn/location/paas/PaasLocation.java | 30 ++++++++++++++ .../ReflectiveEntityDriverFactoryTest.java | 41 +++++++++++++++++--- .../location/basic/PaasLocationTest.java | 37 ++++++++++++++++++ .../test/location/TestPaasLocation.java | 32 +++++++++++++++ 5 files changed, 151 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f32fa3cf/core/src/main/java/brooklyn/entity/drivers/ReflectiveEntityDriverFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/entity/drivers/ReflectiveEntityDriverFactory.java b/core/src/main/java/brooklyn/entity/drivers/ReflectiveEntityDriverFactory.java index 4a52647..3e0b757 100644 --- a/core/src/main/java/brooklyn/entity/drivers/ReflectiveEntityDriverFactory.java +++ b/core/src/main/java/brooklyn/entity/drivers/ReflectiveEntityDriverFactory.java @@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory; import brooklyn.location.Location; import brooklyn.location.basic.SshMachineLocation; +import brooklyn.location.paas.PaasLocation; import brooklyn.util.collections.MutableList; import brooklyn.util.collections.MutableMap; import brooklyn.util.exceptions.Exceptions; @@ -54,6 +55,7 @@ public class ReflectiveEntityDriverFactory { public ReflectiveEntityDriverFactory() { addRule(DriverInferenceForSshLocation.DEFAULT_IDENTIFIER, new DriverInferenceForSshLocation()); + addRule(DriverInferenceForPaasLocation.DEFAULT_IDENTIFIER, new DriverInferenceForPaasLocation()); } public interface DriverInferenceRule { @@ -165,6 +167,21 @@ public class ReflectiveEntityDriverFactory { } } + public static class DriverInferenceForPaasLocation extends AbstractDriverInferenceRule { + + public static final String DEFAULT_IDENTIFIER = "paas-location-driver-inference-rule"; + + @Override + public String inferDriverClassName(DriverDependentEntity entity, Class driverInterface, Location location) { + String driverInterfaceName = driverInterface.getName(); + if (!(location instanceof PaasLocation)) return null; + if (!driverInterfaceName.endsWith("Driver")) { + throw new IllegalArgumentException(String.format("Driver name [%s] doesn't end with 'Driver'; cannot auto-detect PaasDriver class name", driverInterfaceName)); + } + return Strings.removeFromEnd(driverInterfaceName, "Driver")+ ((PaasLocation) location).getPaasProviderName() + "Driver"; + } + } + /** adds a rule; possibly replacing an old one if one exists with the given identifier. the new rule is added after all previous ones. * @return the replaced rule, or null if there was no old rule */ public DriverInferenceRule addRule(String identifier, DriverInferenceRule rule) { http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f32fa3cf/core/src/main/java/brooklyn/location/paas/PaasLocation.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/location/paas/PaasLocation.java b/core/src/main/java/brooklyn/location/paas/PaasLocation.java new file mode 100644 index 0000000..6165e04 --- /dev/null +++ b/core/src/main/java/brooklyn/location/paas/PaasLocation.java @@ -0,0 +1,30 @@ +/* + * 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 brooklyn.location.paas; + +import brooklyn.location.Location; + +/** + * {@link Location} representing an application container on a PaaS provider. + */ +public interface PaasLocation extends Location { + + String getPaasProviderName(); +} + http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f32fa3cf/core/src/test/java/brooklyn/entity/drivers/ReflectiveEntityDriverFactoryTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/entity/drivers/ReflectiveEntityDriverFactoryTest.java b/core/src/test/java/brooklyn/entity/drivers/ReflectiveEntityDriverFactoryTest.java index a4a80f1..5554259 100644 --- a/core/src/test/java/brooklyn/entity/drivers/ReflectiveEntityDriverFactoryTest.java +++ b/core/src/test/java/brooklyn/entity/drivers/ReflectiveEntityDriverFactoryTest.java @@ -18,23 +18,25 @@ */ package brooklyn.entity.drivers; -import static org.testng.Assert.assertTrue; - -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - import brooklyn.entity.Entity; import brooklyn.entity.basic.AbstractEntity; import brooklyn.entity.basic.EntityLocal; import brooklyn.location.Location; import brooklyn.location.basic.SshMachineLocation; +import brooklyn.location.paas.PaasLocation; +import brooklyn.test.location.TestPaasLocation; import brooklyn.util.collections.MutableMap; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertTrue; public class ReflectiveEntityDriverFactoryTest { private ReflectiveEntityDriverFactory factory; private SshMachineLocation sshLocation; + private PaasLocation paasLocation; private DriverDependentEntity entity; @BeforeMethod @@ -42,6 +44,8 @@ public class ReflectiveEntityDriverFactoryTest { factory = new ReflectiveEntityDriverFactory(); sshLocation = new SshMachineLocation(MutableMap.of("address", "localhost")); entity = new MyDriverDependentEntity(MyDriver.class); + + paasLocation = new TestPaasLocation(); } @AfterMethod @@ -54,12 +58,22 @@ public class ReflectiveEntityDriverFactoryTest { assertTrue(driver.getClass().equals(clazz), "driver="+driver+"; should be "+clazz); } + protected void assertDriverIs(Class clazz, Location location) { + MyDriver driver = factory.build(entity, location); + assertTrue(driver.getClass().equals(clazz), "driver="+driver+"; should be "+clazz); + } + @Test public void testInstantiatesSshDriver() throws Exception { assertDriverIs(MySshDriver.class); } @Test + public void testInstantiatesPaasDriver() throws Exception { + assertDriverIs(MyTestPaasDriver.class, paasLocation); + } + + @Test public void testFullNameMapping() throws Exception { factory.addClassFullNameMapping(MyDriver.class.getName(), MyCustomDriver.class.getName()); assertDriverIs(MyCustomDriver.class); @@ -139,4 +153,19 @@ public class ReflectiveEntityDriverFactoryTest { super(entity, machine); } } + + public static class MyTestPaasDriver implements MyDriver { + public MyTestPaasDriver(Entity entity, PaasLocation location) { + } + + @Override + public Location getLocation() { + throw new UnsupportedOperationException(); + } + + @Override + public EntityLocal getEntity() { + throw new UnsupportedOperationException(); + } + } } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f32fa3cf/core/src/test/java/brooklyn/location/basic/PaasLocationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/location/basic/PaasLocationTest.java b/core/src/test/java/brooklyn/location/basic/PaasLocationTest.java new file mode 100644 index 0000000..0fd2591 --- /dev/null +++ b/core/src/test/java/brooklyn/location/basic/PaasLocationTest.java @@ -0,0 +1,37 @@ +/* + * 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 brooklyn.location.basic; + +import brooklyn.location.paas.PaasLocation; +import brooklyn.management.ManagementContext; +import brooklyn.test.location.TestPaasLocation; +import org.testng.Assert; +import org.testng.annotations.Test; + +public class PaasLocationTest { + + private PaasLocation location; + private ManagementContext mgmt; + + @Test + public void testProviderName(){ + location = new TestPaasLocation(); + Assert.assertEquals(location.getPaasProviderName(), "TestPaas"); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f32fa3cf/core/src/test/java/brooklyn/test/location/TestPaasLocation.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/test/location/TestPaasLocation.java b/core/src/test/java/brooklyn/test/location/TestPaasLocation.java new file mode 100644 index 0000000..be2ba56 --- /dev/null +++ b/core/src/test/java/brooklyn/test/location/TestPaasLocation.java @@ -0,0 +1,32 @@ +/* + * 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 brooklyn.test.location; + +import brooklyn.location.basic.AbstractLocation; +import brooklyn.location.paas.PaasLocation; + +/** + * Mock {@link brooklyn.location.paas.PaasLocation} for test purposes + */ +public class TestPaasLocation extends AbstractLocation implements PaasLocation { + @Override + public String getPaasProviderName() { + return "TestPaas"; + } +} \ No newline at end of file