brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [1/2] brooklyn-server git commit: Fix+test rename-jclouds-provider
Date Thu, 12 Jan 2017 16:01:09 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 7d9f5e7a7 -> f89cb0989


Fix+test rename-jclouds-provider

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

Branch: refs/heads/master
Commit: 23628bedfdcc29ddb5d628a7fc12e5b2b79ed77e
Parents: 7d9f5e7
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Jan 12 15:23:31 2017 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Jan 12 15:23:31 2017 +0000

----------------------------------------------------------------------
 ...DeserializingJcloudsRenamesProviderTest.java | 41 +++++++++
 .../jclouds/ComputeServiceRegistryImpl.java     |  5 +-
 .../brooklyn/location/jclouds/JcloudsUtil.java  |  5 +-
 .../jclouds/JcloudsRenamesRebindTest.java       | 90 ++++++++++++++++++++
 4 files changed, 139 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/23628bed/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/DeserializingJcloudsRenamesProviderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/DeserializingJcloudsRenamesProviderTest.java
b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/DeserializingJcloudsRenamesProviderTest.java
new file mode 100644
index 0000000..da45fff
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/persist/DeserializingJcloudsRenamesProviderTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.core.mgmt.persist;
+
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.Test;
+
+public class DeserializingJcloudsRenamesProviderTest {
+
+    @Test
+    public void testRenameNoop() throws Exception {
+        assertEquals(rename("aws-ec2"), "aws-ec2");
+    }
+
+    @Test
+    public void testRenamesDefinedInClasspathFile() throws Exception {
+        assertEquals(rename("openstack-mitaka-nova"), "openstack-nova");
+        assertEquals(rename("openstack-devtest-compute"), "openstack-nova");
+    }
+    
+    protected String rename(String val) throws Exception {
+        return DeserializingJcloudsRenamesProvider.INSTANCE.applyJcloudsRenames(val);
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/23628bed/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/ComputeServiceRegistryImpl.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/ComputeServiceRegistryImpl.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/ComputeServiceRegistryImpl.java
index 9768dba..64d168e 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/ComputeServiceRegistryImpl.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/ComputeServiceRegistryImpl.java
@@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.brooklyn.core.config.Sanitizer;
 import org.apache.brooklyn.core.location.cloud.CloudLocationConfig;
+import org.apache.brooklyn.core.mgmt.persist.DeserializingJcloudsRenamesProvider;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.text.Strings;
@@ -65,7 +66,9 @@ public class ComputeServiceRegistryImpl implements ComputeServiceRegistry,
Jclou
 
     @Override
     public ComputeService findComputeService(ConfigBag conf, boolean allowReuse) {
-        String provider = checkNotNull(conf.get(CLOUD_PROVIDER), "provider must not be null");
+        String rawProvider = checkNotNull(conf.get(CLOUD_PROVIDER), "provider must not be
null");
+        String provider = DeserializingJcloudsRenamesProvider.INSTANCE.applyJcloudsRenames(rawProvider);
+
         String identity = checkNotNull(conf.get(CloudLocationConfig.ACCESS_IDENTITY), "identity
must not be null");
         String credential = checkNotNull(conf.get(CloudLocationConfig.ACCESS_CREDENTIAL),
"credential must not be null");
         

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/23628bed/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsUtil.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsUtil.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsUtil.java
index 7b75bcc..88f4127 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsUtil.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsUtil.java
@@ -38,6 +38,7 @@ import java.util.concurrent.TimeoutException;
 import javax.annotation.Nullable;
 
 import org.apache.brooklyn.core.config.Sanitizer;
+import org.apache.brooklyn.core.mgmt.persist.DeserializingJcloudsRenamesProvider;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.core.config.ConfigBag;
 import org.apache.brooklyn.util.exceptions.Exceptions;
@@ -270,7 +271,9 @@ public class JcloudsUtil implements JcloudsLocationConfig {
      *
      *  @since 0.7.0 */
     @Beta
-    public static BlobStoreContext newBlobstoreContext(String provider, @Nullable String
endpoint, String identity, String credential) {
+    public static BlobStoreContext newBlobstoreContext(String rawProvider, @Nullable String
endpoint, String identity, String credential) {
+        String provider = DeserializingJcloudsRenamesProvider.INSTANCE.applyJcloudsRenames(rawProvider);
+        
         Properties overrides = new Properties();
         // * Java 7,8 bug workaround - sockets closed by GC break the internal bookkeeping
         //   of HttpUrlConnection, leading to invalid handling of the "HTTP/1.1 100 Continue"

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/23628bed/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRenamesRebindTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRenamesRebindTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRenamesRebindTest.java
new file mode 100644
index 0000000..faf3ff9
--- /dev/null
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsRenamesRebindTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.location.jclouds;
+
+import static org.testng.Assert.assertTrue;
+
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.ComputeServiceContext;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Tests rebind (i.e. restarting Brooklyn server) when using the jclouds-provider renames.
+ */
+public class JcloudsRenamesRebindTest extends RebindTestFixtureWithApp {
+
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        super.setUp();
+        
+        // Don't let any defaults from brooklyn.properties (except credentials) interfere
with test
+        AbstractJcloudsLiveTest.stripBrooklynProperties(origManagementContext.getBrooklynProperties());
+    }
+
+    @Test(expectedExceptions=NoSuchElementException.class)
+    public void testProviderDoesNotExist() throws Exception {
+        resolve("wrongprovider");
+    }
+    
+    @Test
+    public void testProviderNotRenamed() throws Exception {
+        JcloudsLocation loc = resolve("aws-ec2:us-east-1", ImmutableMap.of("identity", "dummy",
"credential", "dummy"));
+        assertComputeServiceType(loc, "aws-ec2");
+        
+        rebind();
+        
+        JcloudsLocation newLoc = (JcloudsLocation) mgmt().getLocationManager().getLocation(loc.getId());
+        assertComputeServiceType(newLoc, "aws-ec2");
+    }
+
+    @Test
+    public void testProviderRenamed() throws Exception {
+        JcloudsLocation loc = resolve("openstack-mitaka-nova:http://hostdoesnotexist.com:5000",
ImmutableMap.of("identity", "dummy", "credential", "dummy"));
+        assertComputeServiceType(loc, "openstack-nova");
+        
+        rebind();
+        
+        JcloudsLocation newLoc = (JcloudsLocation) mgmt().getLocationManager().getLocation(loc.getId());
+        assertComputeServiceType(newLoc, "openstack-nova");
+    }
+
+    private JcloudsLocation resolve(String spec) {
+        return resolve(spec, ImmutableMap.of());
+    }
+    
+    private JcloudsLocation resolve(String spec, Map<?,?> flags) {
+        return (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged(spec, flags);
+    }
+    
+    private void assertComputeServiceType(JcloudsLocation loc, String expectedType) {
+        // TODO Would be nice to do this more explicitly, rather than relying on toString.
+        // But this is good enough.
+        ComputeService computeService = loc.getComputeService();
+        ComputeServiceContext context = computeService.getContext();
+        assertTrue(context.toString().contains("id="+expectedType), "computeService="+computeService+";
context="+computeService.getContext());
+    }
+    
+}


Mime
View raw message