brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreatu...@apache.org
Subject [1/3] incubator-brooklyn git commit: Add initial support for PaaS locations by using ReflectiveEntityDriverFactory.
Date Wed, 13 May 2015 15:36:50 GMT
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 <mbarrientos@lcc.uma.es>
Authored: Tue May 5 21:02:27 2015 +0200
Committer: Miguel Barrientos <mbarrientos@lcc.uma.es>
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 <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D>
entity, Class<D> 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<MyDriver> entity;
     
     @BeforeMethod
@@ -42,6 +44,8 @@ public class ReflectiveEntityDriverFactoryTest {
         factory = new ReflectiveEntityDriverFactory();
         sshLocation = new SshMachineLocation(MutableMap.of("address", "localhost"));
         entity = new MyDriverDependentEntity<MyDriver>(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


Mime
View raw message