Issue 221: made sure default template always works on all cloud providers

This commit is contained in:
Adrian Cole 2010-04-04 22:57:03 -07:00
parent 4ee4bb8764
commit 190c768d02
22 changed files with 387 additions and 119 deletions

View File

@ -20,6 +20,7 @@ package org.jclouds.aws.ec2.compute.config;
import static org.jclouds.aws.ec2.options.DescribeImagesOptions.Builder.ownedBy;
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import java.net.URI;
import java.util.Map;
@ -58,7 +59,9 @@ import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.compute.predicates.RunScriptRunning;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.DestroyNodeStrategy;
@ -102,6 +105,13 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class);
}
@Provides
TemplateBuilder provideTemplate(Map<String, ? extends Location> locations,
Map<String, ? extends Image> images, Map<String, ? extends Size> sizes,
Location defaultLocation) {
return new TemplateBuilderImpl(locations, images, sizes, defaultLocation).osFamily(UBUNTU);
}
@Singleton
public static class EC2ListNodesStrategy implements ListNodesStrategy {
private final InstanceClient client;

View File

@ -18,12 +18,12 @@
*/
package org.jclouds.aws.ec2.compute;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.domain.Architecture;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -40,13 +40,18 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
service = "ec2";
}
protected Template buildTemplate(TemplateBuilder templateBuilder) {
return templateBuilder.osFamily(UBUNTU).smallest().architecture(Architecture.X86_32).build();
@Test
public void testTemplateBuilderCanUseImageId() {
client.templateBuilder().imageId("ami-d57f93bc").build();
}
@Test
public void testTemplateBuilder() {
client.templateBuilder().imageId("ami-d57f93bc").build();
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_32);
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}
@Override

View File

@ -9,18 +9,28 @@ Here's an example of getting some compute configuration from rackspace:
(use 'org.jclouds.compute)
(use 'clojure.contrib.pprint)
(def provider \"cloudservers\")
(def user \"username\")
(def password \"password\")
(def compute-name \"cloudservers\")
(def compute (compute-context compute-name user password))
; create a compute service
(def compute
(compute-service provider user password))
(with-compute-service [compute]
(pprint (locations))
(pprint (images))
(pprint (nodes))
(pprint (sizes)))
Here's an example of creating and running a small linux node with the tag webserver:
; create a compute service using ssh and log4j extensions
(def compute
(compute-service provider user password :ssh :log4j))
(run-node \"webserver\" compute)
See http://code.google.com/p/jclouds for details."
(:use org.jclouds.core
clojure.contrib.duck-streams
@ -107,8 +117,6 @@ See http://code.google.com/p/jclouds for details."
([] (default-template *compute*))
([#^ComputeService compute]
(.. compute (templateBuilder)
(osFamily OsFamily/UBUNTU)
smallest
(options
(org.jclouds.compute.options.TemplateOptions$Builder/authorizePublicKey
(slurp (str (. System getProperty "user.home") "/.ssh/id_rsa.pub"))))
@ -116,7 +124,26 @@ See http://code.google.com/p/jclouds for details."
(defn run-nodes
"Create the specified number of nodes using the default or specified
template."
template.
; simplest way to add 2 small linux nodes to the group webserver is to run
(run-nodes \"webserver\" 2 compute)
; which is the same as wrapping the run-nodes command with an implicit compute service
; note that this will actually add another 2 nodes to the set called \"webserver\"
(with-compute-service [compute]
(run-nodes \"webserver\" 2 ))
; which is the same as specifying the default template
(with-compute-service [compute]
(run-nodes \"webserver\" 2 (default-template)))
; which, on gogrid, is the same as constructing the smallest centos template that has no layered software
(with-compute-service [compute]
(run-nodes \"webserver\" 2
(build-template service :centos :smallest :image-name-matches \".*w/ None.*\")))
"
([tag count]
(run-nodes tag count (default-template *compute*) *compute*))
([tag count compute-or-template]
@ -129,7 +156,17 @@ See http://code.google.com/p/jclouds for details."
(.runNodesWithTag compute tag count template))))
(defn run-node
"Create a node using the default or specified template."
"Create a node using the default or specified template.
; simplest way to add a small linux node to the group webserver is to run
(run-node \"webserver\" compute)
; which is the same as wrapping the run-node command with an implicit compute service
; note that this will actually add another node to the set called \"webserver\"
(with-compute-service [compute]
(run-node \"webserver\" ))
"
([tag]
(run-nodes tag 1 (default-template *compute*) *compute*))
([tag compute-or-template]
@ -298,7 +335,12 @@ See http://code.google.com/p/jclouds for details."
(f builder value)
(println "Unknown option" option))))
(defn build-template [#^ComputeService compute option & options]
(defn build-template
"Creates a template that can be used to run nodes.
There are many options to use for the default template
"
[#^ComputeService compute option & options]
(let [builder (.. compute (templateBuilder))]
(loop [option option
remaining options]

View File

@ -1,24 +1,19 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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
* Licensed 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
* 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.
* 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.jclouds.compute.domain;

View File

@ -41,6 +41,7 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ComparisonChain;
@ -63,21 +64,35 @@ public class TemplateBuilderImpl implements TemplateBuilder {
private final Map<String, ? extends Image> images;
private final Map<String, ? extends Size> sizes;
private final Map<String, ? extends Location> locations;
private OsFamily os;
private Architecture arch;
private String locationId;
private String imageId;
private String sizeId;
private String osDescription;
private String imageVersion;
private String imageName;
private String imageDescription;
@VisibleForTesting
OsFamily os;
@VisibleForTesting
Architecture arch;
@VisibleForTesting
String locationId;
@VisibleForTesting
String imageId;
@VisibleForTesting
String sizeId;
@VisibleForTesting
String osDescription;
@VisibleForTesting
String imageVersion;
private double minCores;
private int minRam;
@VisibleForTesting
String imageName;
@VisibleForTesting
String imageDescription;
private boolean biggest;
private boolean fastest;
@VisibleForTesting
double minCores;
@VisibleForTesting
int minRam;
@VisibleForTesting
boolean biggest;
@VisibleForTesting
boolean fastest;
private TemplateOptions options = TemplateOptions.NONE;
@ -411,6 +426,12 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Override
public TemplateBuilder imageId(String imageId) {
this.imageId = imageId;
this.imageName = null;
this.imageDescription = null;
this.imageVersion = null;
this.arch = null;
this.os = null;
this.osDescription = null;
return this;
}

View File

@ -39,6 +39,7 @@ import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
@ -139,7 +140,8 @@ public abstract class BaseComputeServiceLiveTest {
template = buildTemplate(client.templateBuilder());
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(
keyPair.get("public")).runScript(buildScript().getBytes());
keyPair.get("public")).runScript(
buildScript(template.getImage().getOsFamily()).getBytes());
nodes = Sets.newTreeSet(client.runNodesWithTag(tag, 2, template).values());
assertEquals(nodes.size(), 2);
checkNodes();
@ -172,19 +174,40 @@ public abstract class BaseComputeServiceLiveTest {
}
}
protected abstract Template buildTemplate(TemplateBuilder templateBuilder);
protected Template buildTemplate(TemplateBuilder templateBuilder) {
return templateBuilder.build();
}
protected String buildScript() {
return new StringBuilder()//
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")//
.append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")//
.append(
"sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list\n")//
.append("apt-get update\n")//
.append("apt-get install -f -y --force-yes openjdk-6-jdk\n")//
.append("wget -qO/usr/bin/runurl run.alestic.com/runurl\n")//
.append("chmod 755 /usr/bin/runurl\n")//
.toString();
protected String buildScript(OsFamily osFamily) {
switch (osFamily) {
case JEOS:
case UBUNTU:
return new StringBuilder()//
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")//
.append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")//
.append(
"sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list\n")//
.append("apt-get update\n")//
.append("apt-get install -f -y --force-yes openjdk-6-jdk\n")//
.append("wget -qO/usr/bin/runurl run.alestic.com/runurl\n")//
.append("chmod 755 /usr/bin/runurl\n")//
.toString();
case CENTOS:
case RHEL:
return new StringBuilder()
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")
.append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("echo \"name=jdkrepository\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append(
"echo \"baseurl=http://ec2-us-east-mirror.rightscale.com/epel/5/i386/\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("yum --nogpgcheck -y install java-1.6.0-openjdk\n")
.append(
"echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n")
.toString();
default:
throw new IllegalArgumentException(osFamily.toString());
}
}
@Test(enabled = true, dependsOnMethods = "testCreate")

View File

@ -0,0 +1,72 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.jclouds.compute.internal;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.domain.Architecture;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Size;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class TemplateBuilderImplTest {
@Test
public void testImageIdNullsEverythingElse() {
TemplateBuilderImpl template = new TemplateBuilderImpl(ImmutableMap.<String, Location> of(),
ImmutableMap.<String, Image> of(), ImmutableMap.<String, Size> of(),
new LocationImpl(LocationScope.REGION, " id", "description", null, true));
template.architecture(Architecture.X86_32);
template.imageDescriptionMatches("imageDescriptionMatches");
template.imageNameMatches("imageNameMatches");
template.imageVersionMatches("imageVersionMatches");
template.osDescriptionMatches("osDescriptionMatches");
template.osFamily(OsFamily.CENTOS);
assertEquals(template.arch, Architecture.X86_32);
assertEquals(template.imageDescription, "imageDescriptionMatches");
assertEquals(template.imageName, "imageNameMatches");
assertEquals(template.imageVersion, "imageVersionMatches");
assertEquals(template.osDescription, "osDescriptionMatches");
assertEquals(template.os, OsFamily.CENTOS);
assertEquals(template.imageId, null);
template.imageId("myid");
assertEquals(template.arch, null);
assertEquals(template.imageDescription, null);
assertEquals(template.imageName, null);
assertEquals(template.imageVersion, null);
assertEquals(template.osDescription, null);
assertEquals(template.os, null);
assertEquals(template.imageId, "myid");
}
}

View File

@ -19,6 +19,7 @@
package org.jclouds.gogrid.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.domain.OsFamily.CENTOS;
import java.net.InetAddress;
import java.net.UnknownHostException;
@ -45,10 +46,12 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.internal.ImageImpl;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.compute.predicates.RunScriptRunning;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
@ -106,6 +109,14 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
bind(DestroyNodeStrategy.class).to(GoGridDestroyNodeStrategy.class);
}
@Provides
TemplateBuilder provideTemplate(Map<String, ? extends Location> locations,
Map<String, ? extends Image> images, Map<String, ? extends Size> sizes,
Location defaultLocation) {
return new TemplateBuilderImpl(locations, images, sizes, defaultLocation).osFamily(CENTOS)
.imageNameMatches(".*w/ None.*");
}
@Provides
@Named("NAMING_CONVENTION")
@Singleton
@ -140,7 +151,7 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
int numOfRetries = 20;
// lock-free consumption of a shared resource: IP address pool
while (notStarted) { // TODO: replace with Predicate-based thread collision avoidance for
// simplicity
// simplicity
Set<Ip> availableIps = client.getIpServices().getIpList(
new GetIpListOptions().onlyUnassigned().onlyWithType(IpType.PUBLIC));
if (availableIps.size() == 0)
@ -316,6 +327,7 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
private final Function<String, InetAddress> stringIpToInetAddress;
private final GoGridClient client;
@SuppressWarnings("unused")
@Inject
ServerToNodeMetadata(Map<String, NodeState> serverStateToNodeState,
Function<String, InetAddress> stringIpToInetAddress, GoGridClient client) {
@ -337,7 +349,6 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
return new NodeMetadataImpl(from.getId() + "", from.getName(), locationId, null,
ImmutableMap.<String, String> of(), tag, state, ipSet, ImmutableList
.<InetAddress> of(), ImmutableMap.<String, String> of(), creds);
}
}
@ -447,8 +458,8 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
holder.logger.debug("<< didn't match os(%s)", matchedOs);
}
images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), location.getId(), null,
ImmutableMap.<String, String> of(), from.getDescription(), version, os,
images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), location.getId(),
null, ImmutableMap.<String, String> of(), from.getDescription(), version, os,
osDescription, arch));
}
holder.logger.debug("<< images(%d)", images.size());

View File

@ -18,7 +18,6 @@
*/
package org.jclouds.gogrid;
import static org.jclouds.compute.domain.OsFamily.CENTOS;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@ -27,11 +26,12 @@ import java.util.Map;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.Architecture;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.rest.RestContext;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.BeforeClass;
@ -52,24 +52,13 @@ public class GoGridComputeServiceLiveTest extends BaseComputeServiceLiveTest {
service = "gogrid";
}
@Override
public String buildScript() {
return new StringBuilder()
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")
.append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("echo \"name=jdkrepository\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append(
"echo \"baseurl=http://ec2-us-east-mirror.rightscale.com/epel/5/i386/\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
.append("yum --nogpgcheck -y install java-1.6.0-openjdk\n")
.append(
"echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n")
.toString();
}
protected Template buildTemplate(TemplateBuilder templateBuilder) {
return templateBuilder.osFamily(CENTOS).imageDescriptionMatches(".*w/ None.*").smallest()
.build();
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_64);
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.CENTOS);
assertEquals(defaultTemplate.getLocation().getId(), "SANFRANCISCO");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}
@Override

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.rackspace.cloudservers.compute.config;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
@ -43,11 +45,13 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.internal.ImageImpl;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.compute.predicates.RunScriptRunning;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
@ -104,6 +108,13 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
bind(DestroyNodeStrategy.class).to(CloudServersDestroyNodeStrategy.class);
}
@Provides
TemplateBuilder provideTemplate(Map<String, ? extends Location> locations,
Map<String, ? extends Image> images, Map<String, ? extends Size> sizes,
Location defaultLocation) {
return new TemplateBuilderImpl(locations, images, sizes, defaultLocation).osFamily(UBUNTU);
}
@Provides
@Named("NAMING_CONVENTION")
@Singleton

View File

@ -19,12 +19,13 @@
package org.jclouds.rackspace.cloudservers.compute;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.Architecture;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient;
import org.jclouds.rackspace.cloudservers.CloudServersClient;
import org.jclouds.rest.RestContext;
@ -47,8 +48,13 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe
service = "cloudservers";
}
protected Template buildTemplate(TemplateBuilder templateBuilder) {
return templateBuilder.osFamily(UBUNTU).osDescriptionMatches(".*9.10.*").smallest().build();
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_64);
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DALLAS");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}
@Override

View File

@ -19,6 +19,7 @@
package org.jclouds.rimuhosting.miro.compute.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import java.net.InetAddress;
import java.net.UnknownHostException;
@ -47,10 +48,12 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.internal.ImageImpl;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.compute.predicates.RunScriptRunning;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
@ -108,6 +111,14 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
bind(DestroyNodeStrategy.class).to(RimuHostingDestroyNodeStrategy.class);
}
@Provides
TemplateBuilder provideTemplate(Map<String, ? extends Location> locations,
Map<String, ? extends Image> images, Map<String, ? extends Size> sizes,
Location defaultLocation) {
return new TemplateBuilderImpl(locations, images, sizes, defaultLocation).sizeId("MIRO1B")
.osFamily(UBUNTU);
}
@Provides
@Named("NAMING_CONVENTION")
@Singleton

View File

@ -28,7 +28,7 @@ import com.google.gson.annotations.SerializedName;
public class Image implements Comparable<Image> {
@SerializedName("distro_code")
private String id;
@SerializedName("distro_desciption")
@SerializedName("distro_description")
private String description;
@Override

View File

@ -18,11 +18,12 @@
*/
package org.jclouds.rimuhosting.miro.compute;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.domain.Architecture;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -39,8 +40,14 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes
tag = "rimuhosting.jclouds";
}
protected Template buildTemplate(TemplateBuilder templateBuilder) {
return templateBuilder.osFamily(UBUNTU).sizeId("MIRO1B").build();
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_64);
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS");
assertEquals(defaultTemplate.getSize().getId(), "MIRO1B");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}
@Override

View File

@ -34,7 +34,6 @@ public class BlueLockVCloudComputeServiceContextModule extends VCloudComputeServ
protected void configure() {
super.configure();
bind(VCloudComputeClient.class).to(BlueLockVCloudComputeClient.class);
}
}

View File

@ -23,7 +23,10 @@ import static org.testng.Assert.assertEquals;
import java.util.Map;
import org.jclouds.compute.domain.Architecture;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.http.HttpResponseException;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudMediaType;
@ -56,24 +59,33 @@ public class BlueLockVCloudComputeServiceLiveTest extends VCloudComputeServiceLi
// TODO verify parsing works
}
// // https://forums.bluelock.com/showthread.php?p=353#post353
// @Override
// @Test(enabled = false)
// public void testCreate() throws Exception {
// super.testCreate();
// }
//
// @Override
// @Test(enabled = false)
// public void testGet() throws Exception {
// super.testGet();
// }
//
// @Override
// @Test(enabled = false)
// public void testReboot() throws Exception {
// super.testReboot();
// }
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_64);
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "133");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}
// // https://forums.bluelock.com/showthread.php?p=353#post353
// @Override
// @Test(enabled = false)
// public void testCreate() throws Exception {
// super.testCreate();
// }
//
// @Override
// @Test(enabled = false)
// public void testGet() throws Exception {
// super.testGet();
// }
//
// @Override
// @Test(enabled = false)
// public void testReboot() throws Exception {
// super.testReboot();
// }
@Test
public void testExample() throws Exception {

View File

@ -20,6 +20,7 @@ package org.jclouds.vcloud.compute.config;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import java.util.Map;
import java.util.Set;
@ -46,10 +47,12 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.internal.ImageImpl;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.compute.predicates.RunScriptRunning;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
@ -110,6 +113,13 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
VAppStatus.UNRESOLVED, NodeState.PENDING).build();
}
@Provides
protected TemplateBuilder provideTemplate(Map<String, ? extends Location> locations,
Map<String, ? extends Image> images, Map<String, ? extends Size> sizes,
Location defaultLocation) {
return new TemplateBuilderImpl(locations, images, sizes, defaultLocation).osFamily(UBUNTU);
}
@Override
protected void configure() {
super.configure();

View File

@ -1,7 +1,6 @@
package org.jclouds.vcloud.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import static org.testng.Assert.assertEquals;
import java.util.Map.Entry;
@ -11,8 +10,6 @@ import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.rest.RestContext;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.VCloudAsyncClient;
@ -36,11 +33,6 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
service = "vcloud";
}
@Override
protected Template buildTemplate(TemplateBuilder templateBuilder) {
return templateBuilder.osFamily(UBUNTU).smallest().build();
}
@Override
protected JschSshClientModule getSshModule() {
return new JschSshClientModule();

View File

@ -18,10 +18,21 @@
*/
package org.jclouds.vcloud.hostingdotcom.compute.config;
import static org.jclouds.compute.domain.OsFamily.CENTOS;
import java.util.Map;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.domain.Location;
import org.jclouds.vcloud.compute.VCloudComputeClient;
import org.jclouds.vcloud.compute.config.VCloudComputeServiceContextModule;
import org.jclouds.vcloud.hostingdotcom.compute.HostingDotComVCloudComputeClient;
import com.google.inject.Provides;
/**
* Configures the {@link HostingDotComVCloudComputeServiceContext}; requires
* {@link HostingDotComVCloudComputeClient} bound.
@ -37,4 +48,12 @@ public class HostingDotComVCloudComputeServiceContextModule extends
bind(VCloudComputeClient.class).to(HostingDotComVCloudComputeClient.class);
}
@Override
@Provides
protected TemplateBuilder provideTemplate(Map<String, ? extends Location> locations,
Map<String, ? extends Image> images, Map<String, ? extends Size> sizes,
Location defaultLocation) {
return new TemplateBuilderImpl(locations, images, sizes, defaultLocation).osFamily(CENTOS);
}
}

View File

@ -19,10 +19,11 @@
package org.jclouds.vcloud.hostingdotcom.compute;
import static org.jclouds.compute.domain.OsFamily.CENTOS;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.domain.Architecture;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.vcloud.compute.VCloudComputeServiceLiveTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -40,9 +41,13 @@ public class HostingDotComVCloudComputeServiceLiveTest extends VCloudComputeServ
service = "hostingdotcom";
}
@Override
protected Template buildTemplate(TemplateBuilder templateBuilder) {
return templateBuilder.osFamily(CENTOS).smallest().build();
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_64);
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.CENTOS);
assertEquals(defaultTemplate.getLocation().getId(), "188849");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}
// Takes too long

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.vcloud.terremark.compute.config;
import static org.jclouds.compute.domain.OsFamily.JEOS;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
@ -34,9 +36,12 @@ import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.internal.ImageImpl;
import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.internal.TemplateBuilderImpl;
import org.jclouds.concurrent.ConcurrentUtils;
import org.jclouds.domain.Location;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.compute.VCloudComputeClient;
@ -57,6 +62,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Provides;
/**
* Configures the {@link TerremarkVCloudComputeServiceContext}; requires
@ -72,6 +78,14 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer
bind(VCloudComputeClient.class).to(TerremarkVCloudComputeClient.class);
}
@Override
@Provides
protected TemplateBuilder provideTemplate(Map<String, ? extends Location> locations,
Map<String, ? extends Image> images, Map<String, ? extends Size> sizes,
Location defaultLocation) {
return new TemplateBuilderImpl(locations, images, sizes, defaultLocation).osFamily(JEOS);
}
private static final ComputeOptionsToSize sizeConverter = new ComputeOptionsToSize();
private static class ComputeOptionsToSize implements Function<ComputeOptions, Size> {

View File

@ -19,7 +19,12 @@
package org.jclouds.vcloud.terremark.compute;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.Architecture;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.rest.RestContext;
import org.jclouds.vcloud.compute.VCloudComputeServiceLiveTest;
import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient;
@ -41,6 +46,15 @@ public class TerremarkVCloudComputeServiceLiveTest extends VCloudComputeServiceL
service = "terremark";
}
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_64);
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.JEOS);
assertEquals(defaultTemplate.getLocation().getId(), "32");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}
public void testAssignability() throws Exception {
@SuppressWarnings("unused")
RestContext<TerremarkVCloudAsyncClient, TerremarkVCloudClient> tmContext = new ComputeServiceContextFactory()