You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whirr.apache.org by as...@apache.org on 2011/03/15 18:19:52 UTC

svn commit: r1081865 - in /incubator/whirr/trunk/core/src: main/java/org/apache/whirr/service/ main/java/org/apache/whirr/service/jclouds/ main/java/org/jclouds/ test/java/org/apache/whirr/service/jclouds/ test/java/org/jclouds/

Author: asavu
Date: Tue Mar 15 17:19:51 2011
New Revision: 1081865

URL: http://svn.apache.org/viewvc?rev=1081865&view=rev
Log:
WHIRR-198. support user-defined images (rewrote to fix classpath ordering issues) (Adrian Cole via asavu)

Added:
    incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/TakeLoginCredentialsFromWhirrProperties.java
    incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/TakeLoginCredentialsFromWhirrPropertiesTest.java
Removed:
    incubator/whirr/trunk/core/src/main/java/org/jclouds/
    incubator/whirr/trunk/core/src/test/java/org/jclouds/
Modified:
    incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ComputeServiceContextBuilder.java

Modified: incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ComputeServiceContextBuilder.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ComputeServiceContextBuilder.java?rev=1081865&r1=1081864&r2=1081865&view=diff
==============================================================================
--- incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ComputeServiceContextBuilder.java (original)
+++ incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/ComputeServiceContextBuilder.java Tue Mar 15 17:19:51 2011
@@ -26,8 +26,10 @@ import java.util.Set;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationConverter;
+import org.apache.whirr.service.jclouds.TakeLoginCredentialsFromWhirrProperties;
 import org.jclouds.compute.ComputeServiceContext;
 import org.jclouds.compute.ComputeServiceContextFactory;
+import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
 import org.jclouds.logging.log4j.config.Log4JLoggingModule;
 import org.jclouds.ssh.jsch.config.JschSshClientModule;
 import org.slf4j.Logger;
@@ -48,7 +50,7 @@ public class ComputeServiceContextBuilde
     Configuration jcloudsConfig =
       spec.getConfigurationForKeysWithPrefix("jclouds");
     Set<AbstractModule> wiring = ImmutableSet.of(new JschSshClientModule(),
-      new Log4JLoggingModule());
+      new Log4JLoggingModule(), new BindLoginCredentialsPatchForEC2());
     if (spec.getProvider().equals("ec2")){
       LOG.warn("please use provider \"aws-ec2\" instead of \"ec2\"");
       spec.setProvider("aws-ec2");
@@ -61,4 +63,14 @@ public class ComputeServiceContextBuilde
       spec.getIdentity(), spec.getCredential(),
       wiring, ConfigurationConverter.getProperties(jcloudsConfig));
   }
+  
+  //patch until jclouds 1.0-beta-10
+  private static class BindLoginCredentialsPatchForEC2 extends AbstractModule {
+
+    @Override
+    protected void configure() {
+      bind(EC2PopulateDefaultLoginCredentialsForImageStrategy.class).to(TakeLoginCredentialsFromWhirrProperties.class);
+    }
+     
+  }
 }

Added: incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/TakeLoginCredentialsFromWhirrProperties.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/TakeLoginCredentialsFromWhirrProperties.java?rev=1081865&view=auto
==============================================================================
--- incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/TakeLoginCredentialsFromWhirrProperties.java (added)
+++ incubator/whirr/trunk/core/src/main/java/org/apache/whirr/service/jclouds/TakeLoginCredentialsFromWhirrProperties.java Tue Mar 15 17:19:51 2011
@@ -0,0 +1,48 @@
+/**
+ * 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.whirr.service.jclouds;
+
+import java.util.List;
+
+import javax.inject.Singleton;
+
+import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
+import org.jclouds.domain.Credentials;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+
+@Singleton
+// patch until jclouds 1.0-beta-10
+public class TakeLoginCredentialsFromWhirrProperties extends
+    EC2PopulateDefaultLoginCredentialsForImageStrategy {
+
+  @Override
+  public Credentials execute(Object resourceToAuthenticate) {
+    if (System.getProperties().containsKey("whirr.login-user") &&
+       !"".equals(System.getProperty("whirr.login-user").trim())) {
+      List<String> creds = Lists.newArrayList(Splitter.on(':').split(System.getProperty("whirr.login-user")));
+      if (creds.size() == 2)
+         return new Credentials(creds.get(0), creds.get(1));
+      return new Credentials(creds.get(0), null);
+    } else {
+       return super.execute(resourceToAuthenticate);
+    }
+  }
+}

Added: incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/TakeLoginCredentialsFromWhirrPropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/TakeLoginCredentialsFromWhirrPropertiesTest.java?rev=1081865&view=auto
==============================================================================
--- incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/TakeLoginCredentialsFromWhirrPropertiesTest.java (added)
+++ incubator/whirr/trunk/core/src/test/java/org/apache/whirr/service/jclouds/TakeLoginCredentialsFromWhirrPropertiesTest.java Tue Mar 15 17:19:51 2011
@@ -0,0 +1,80 @@
+/**
+ * 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.whirr.service.jclouds;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.io.IOException;
+
+import org.apache.whirr.service.jclouds.TakeLoginCredentialsFromWhirrProperties;
+import org.jclouds.domain.Credentials;
+import org.junit.Test;
+
+public class TakeLoginCredentialsFromWhirrPropertiesTest {
+  TakeLoginCredentialsFromWhirrProperties strat = 
+     new TakeLoginCredentialsFromWhirrProperties();
+
+  @Test
+  public synchronized void testNotSetIsDefault() throws IOException {
+    try {
+      assertThat(
+          strat.execute(null),
+          equalTo(new Credentials("root", null)));
+    } finally {
+      System.getProperties().remove("whirr.login-user");
+    }
+  }
+  
+  @Test
+  public synchronized void testSetEmptyIsDefault() throws IOException {
+    try {
+      System.setProperty("whirr.login-user", "");
+      assertThat(
+          strat.execute(null),
+          equalTo(new Credentials("root", null)));
+    } finally {
+      System.getProperties().remove("whirr.login-user");
+    }
+  }
+
+  @Test
+  public synchronized void testSetUsername() throws IOException {
+    try {
+      System.setProperty("whirr.login-user", "ubuntu");
+      assertThat(
+          strat.execute(null),
+          equalTo(new Credentials("ubuntu", null)));
+    } finally {
+      System.getProperties().remove("whirr.login-user");
+    }
+  }
+  
+  @Test
+  public synchronized void testSetUsernamePassword() throws IOException {
+    try {
+      System.setProperty("whirr.login-user", "ubuntu:pass");
+      assertThat(
+          strat.execute(null),
+          equalTo(new Credentials("ubuntu", "pass")));
+    } finally {
+      System.getProperties().remove("whirr.login-user");
+    }
+  }
+}