diff --git a/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextBuilder.java b/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextBuilder.java index 5c4f8041b2..2034b3e2e0 100644 --- a/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/StandaloneComputeServiceContextBuilder.java @@ -26,6 +26,7 @@ import static org.jclouds.Constants.PROPERTY_IDENTITY; import java.util.List; import java.util.Properties; +import org.jclouds.PropertiesBuilder; import org.jclouds.compute.config.StandaloneComputeServiceClientModule; import com.google.inject.Module; @@ -35,10 +36,14 @@ import com.google.inject.Module; * @author Adrian Cole */ public class StandaloneComputeServiceContextBuilder extends - ComputeServiceContextBuilder { + ComputeServiceContextBuilder { public StandaloneComputeServiceContextBuilder(Properties props) { super(ComputeService.class, ComputeService.class, props); + if (properties.size() == 0) + properties.putAll(new PropertiesBuilder().build()); + if (!properties.containsKey("jclouds.provider")) + properties.setProperty("jclouds.provider", "standalone"); if (!properties.containsKey(PROPERTY_ENDPOINT)) properties.setProperty(PROPERTY_ENDPOINT, "standalone"); if (!properties.containsKey(PROPERTY_API_VERSION)) diff --git a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java index 47bd722d32..71014c4317 100644 --- a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java @@ -204,12 +204,19 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { } + /** + * The default template if none is provided. + */ @Provides @Named("DEFAULT") protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { return template.osFamily(UBUNTU); } + /** + * supplies how the tag is encoded into the name. A string of hex characters is the last argument + * and tag is the first + */ @Provides @Named("NAMING_CONVENTION") @Singleton @@ -243,20 +250,20 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { @Singleton @Memoized protected Supplier> supplyImageCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final Supplier> imageSupplier) { + final Supplier> imageSupplier) { return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, seconds, - new Supplier>() { - @Override - public Set get() { - return imageSupplier.get(); - } - }); + new Supplier>() { + @Override + public Set get() { + return imageSupplier.get(); + } + }); } @Provides @Singleton protected Supplier> provideLocationMap( - @Memoized Supplier> locations) { + @Memoized Supplier> locations) { return Suppliers.compose(new Function, Map>() { @Override @@ -278,14 +285,14 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { @Singleton @Memoized protected Supplier> supplyLocationCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final Supplier> locationSupplier) { + final Supplier> locationSupplier) { return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, seconds, - new Supplier>() { - @Override - public Set get() { - return locationSupplier.get(); - } - }); + new Supplier>() { + @Override + public Set get() { + return locationSupplier.get(); + } + }); } @Provides @@ -312,14 +319,14 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { @Singleton @Memoized protected Supplier> supplySizeCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, - final Supplier> hardwareSupplier) { + final Supplier> hardwareSupplier) { return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, seconds, - new Supplier>() { - @Override - public Set get() { - return hardwareSupplier.get(); - } - }); + new Supplier>() { + @Override + public Set get() { + return hardwareSupplier.get(); + } + }); } @Provides diff --git a/compute/src/main/java/org/jclouds/compute/strategy/AddNodeWithTagStrategy.java b/compute/src/main/java/org/jclouds/compute/strategy/AddNodeWithTagStrategy.java index 106feec7a5..167d7a5192 100644 --- a/compute/src/main/java/org/jclouds/compute/strategy/AddNodeWithTagStrategy.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/AddNodeWithTagStrategy.java @@ -29,6 +29,19 @@ import org.jclouds.compute.domain.Template; */ public interface AddNodeWithTagStrategy { + /** + * create a node given the name and template parameters such as imageid, hardwareid, and + * locationid. + * + * @param tag + * tag supplied by the user + * @param name + * supplied by {@link RunNodesAndAddToSetStrategy } and must have the tag encoded into + * it. + * @param template + * supplied by the user + * @return NodeMetadata from the new object, most likely in some pending state. + */ NodeMetadata execute(String tag, String name, Template template); } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceDependenciesModule.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceDependenciesModule.java index 83770cfad4..3b87d025da 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceDependenciesModule.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceDependenciesModule.java @@ -362,7 +362,7 @@ public class StubComputeServiceDependenciesModule extends AbstractModule { public static class StubHardwareSupplier implements Supplier> { static Hardware stub(String type, int cores, int ram, float disk) { - return new org.jclouds.compute.domain.HardwareBuilder().id(type).providerId(type).name(type).processors( + return new org.jclouds.compute.domain.HardwareBuilder().ids(type).name(type).processors( ImmutableList.of(new Processor(cores, 1.0))).ram(ram).volumes( ImmutableList. of(new VolumeImpl(disk, true, false))).build(); } diff --git a/core/src/main/java/org/jclouds/collect/FindResourceInSet.java b/core/src/main/java/org/jclouds/collect/FindResourceInSet.java new file mode 100644 index 0000000000..bdf0ed154b --- /dev/null +++ b/core/src/main/java/org/jclouds/collect/FindResourceInSet.java @@ -0,0 +1,70 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.collect; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.NoSuchElementException; +import java.util.Set; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.logging.Logger; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Supplier; +import com.google.common.collect.Iterables; + +/** + * @author Adrian Cole + */ +@Singleton +public abstract class FindResourceInSet implements Function { + @Resource + protected Logger logger = Logger.NULL; + + private final Supplier> set; + + @Inject + public FindResourceInSet(@Memoized Supplier> set) { + this.set = checkNotNull(set, "set"); + } + + public abstract boolean matches(F from, T input); + + public T apply(final F from) { + try { + return Iterables.find(set.get(), new Predicate() { + + @Override + public boolean apply(T input) { + return matches(from, input); + } + + }); + } catch (NoSuchElementException e) { + logger.warn("could not find a match in set for %s", from); + } + return null; + } +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/collect/TransformingSetSupplier.java b/core/src/main/java/org/jclouds/collect/TransformingSetSupplier.java new file mode 100644 index 0000000000..e02c6c3a0c --- /dev/null +++ b/core/src/main/java/org/jclouds/collect/TransformingSetSupplier.java @@ -0,0 +1,48 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.collect; + +import static com.google.common.collect.Iterables.transform; +import static com.google.common.collect.Sets.newHashSet; + +import java.util.Set; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; + +/** + * + * @author Adrian Cole + */ + +public abstract class TransformingSetSupplier implements Supplier> { + private final Function converter; + + public TransformingSetSupplier(Function converter) { + this.converter = converter; + } + + @Override + public Set get() { + return newHashSet(transform(supplyFrom(), converter)); + } + + public abstract Iterable supplyFrom(); +} diff --git a/pom.xml b/pom.xml index ca9300914a..6ff8b53bc2 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,7 @@ core compute blobstore + skeletons filesystem extensions tools diff --git a/skeletons/pom.xml b/skeletons/pom.xml new file mode 100644 index 0000000000..ca07ccd404 --- /dev/null +++ b/skeletons/pom.xml @@ -0,0 +1,37 @@ + + + + + + jclouds-project + org.jclouds + 1.0-SNAPSHOT + ../project/pom.xml + + 4.0.0 + jclouds-skeletons-project + pom + jclouds skeletons project + + standalone-compute + + diff --git a/skeletons/standalone-compute/README.txt b/skeletons/standalone-compute/README.txt new file mode 100644 index 0000000000..f8231086df --- /dev/null +++ b/skeletons/standalone-compute/README.txt @@ -0,0 +1,3 @@ +this is a skeleton for a standalone compute provider. + +Essentially, a standalone provider is one that doesn't use jclouds http services. Examples could be native drivers like libvirt or shell-driven ones like virtualbox. diff --git a/skeletons/standalone-compute/pom.xml b/skeletons/standalone-compute/pom.xml new file mode 100644 index 0000000000..3ef57068aa --- /dev/null +++ b/skeletons/standalone-compute/pom.xml @@ -0,0 +1,123 @@ + + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.0-SNAPSHOT + ../../project/pom.xml + + jclouds-examples-standalone-compute + jclouds example components for a standalone compute provider + + + trmkrun-ccc,test.trmk-924 + https://servermanager-compute.com + 1.0 + FIXME + + + + ${project.groupId} + jclouds-core + ${project.version} + test-jar + test + + + ${project.groupId} + jclouds-compute + ${project.version} + + + ${project.groupId} + jclouds-compute + ${project.version} + test-jar + test + + + log4j + log4j + 1.2.14 + test + + + ${project.groupId} + jclouds-log4j + ${project.version} + test + + + ${project.groupId} + jclouds-jsch + ${project.version} + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + + test.servermanager-compute.endpoint + ${test.servermanager-compute.endpoint} + + + test.servermanager-compute.apiversion + ${test.servermanager-compute.apiversion} + + + test.servermanager-compute.identity + ${test.servermanager-compute.identity} + + + jclouds.compute.blacklist.nodes + ${jclouds.compute.blacklist.nodes} + + + + + + + + + + + + diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/Hardware.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/Hardware.java new file mode 100644 index 0000000000..856306a964 --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/Hardware.java @@ -0,0 +1,63 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager; + +import com.google.common.base.Objects; + +/** + * This would be replaced with the real java object related to the underlying hardware + * + * @author Adrian Cole + */ +public class Hardware { + + public int id; + public String name; + public int cores; + public int ram; + public float disk; + + public Hardware(int id, String name, int cores, int ram, float disk) { + this.id = id; + this.name = name; + this.cores = cores; + this.ram = ram; + this.disk = disk; + } + + @Override + public int hashCode() { + return Objects.hashCode(id, name, cores, ram, disk); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + return Objects.equal(this.toString(), that.toString()); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("id", id).add("name", name).add("cores", cores).add("ram", ram) + .add("disk", disk).toString(); + } + +} \ No newline at end of file diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/Image.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/Image.java new file mode 100644 index 0000000000..9939d6ec34 --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/Image.java @@ -0,0 +1,56 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager; + +import com.google.common.base.Objects; + +/** + * This would be replaced with the real java object related to the underlying image + * + * @author Adrian Cole + */ +public class Image { + + public int id; + public String name; + + public Image(int id, String name) { + this.id = id; + this.name = name; + } + + @Override + public int hashCode() { + return Objects.hashCode(id, name); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + return Objects.equal(this.toString(), that.toString()); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("id", id).add("name", name).toString(); + } + +} \ No newline at end of file diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/Server.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/Server.java new file mode 100644 index 0000000000..7369a7679a --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/Server.java @@ -0,0 +1,67 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager; + +import com.google.common.base.Objects; + +/** + * This would be replaced with the real java object related to the underlying server + * + * @author Adrian Cole + */ +public class Server { + public enum Status { + ACTIVE, BUILD, TERMINATED, UNRECOGNIZED + + } + + public int id; + public String name; + public Status status; + public String datacenter; + public int imageId; + public int hardwareId; + public String publicAddress; + public String privateAddress; + public String loginUser; + public String password; + + @Override + public int hashCode() { + return Objects.hashCode(id, name, status, datacenter, imageId, hardwareId, publicAddress, privateAddress, + loginUser); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + return Objects.equal(this.toString(), that.toString()); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("id", id).add("name", name).add("status", status) + .add("datacenter", datacenter).add("imageId", imageId).add("hardwareId", hardwareId) + .add("publicAddress", publicAddress).add("privateAddress", privateAddress).add("loginUser", loginUser) + .toString(); + } + +} \ No newline at end of file diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/ServerManager.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/ServerManager.java new file mode 100644 index 0000000000..0de102cd46 --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/ServerManager.java @@ -0,0 +1,99 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager; + +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.inject.Singleton; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; + +/** + * This would be replaced with the real connection to the service that can + * create/list/reboot/get/destroy things + * + * @author Adrian Cole + */ +@Singleton +public class ServerManager { + + private final static Map servers = Maps.newHashMap(); + private final static Map images = ImmutableMap.of(1, new Image(1, "ubuntu")); + private final static Map hardware = ImmutableMap.of(1, new Hardware(1, "small", 1, 512, 10)); + + private final static AtomicInteger nodeIds = new AtomicInteger(0); + + /** + * simulate creating a server, as this is really going to happen with the api underneath + * + * @param name + * @param name + * @param imageId + * @param hardwareId + * @return new server + */ + public Server createServerInDC(String datacenter, String name, int imageId, int hardwareId) { + Server server = new Server(); + server.id = nodeIds.getAndIncrement(); + server.name = name; + server.datacenter = datacenter; + server.imageId = imageId; + server.hardwareId = hardwareId; + server.publicAddress = "7.1.1." + server.id; + server.privateAddress = "10.1.1." + server.id; + server.loginUser = "root"; + server.password = "password"; + servers.put(server.id, server); + return server; + } + + public Server getServer(int serverId) { + return servers.get(serverId); + } + + public Iterable listServers() { + return servers.values(); + } + + public Image getImage(int imageId) { + return images.get(imageId); + } + + public Iterable listImages() { + return images.values(); + } + + public Hardware getHardware(int hardwareId) { + return hardware.get(hardwareId); + } + + public Iterable listHardware() { + return hardware.values(); + } + + public void destroyServer(int serverId) { + servers.remove(serverId); + } + + public void rebootServer(int serverId) { + } +} \ No newline at end of file diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilder.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilder.java new file mode 100644 index 0000000000..36a1040ff2 --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilder.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute; + +import java.util.List; +import java.util.Properties; + +import org.jclouds.compute.StandaloneComputeServiceContextBuilder; +import org.jclouds.compute.config.StandaloneComputeServiceContextModule; +import org.jclouds.servermanager.compute.strategy.ServerManagerAddNodeWithTagStrategy; +import org.jclouds.servermanager.compute.strategy.ServerManagerDestroyNodeStrategy; +import org.jclouds.servermanager.compute.strategy.ServerManagerGetAndListNodesStrategy; +import org.jclouds.servermanager.compute.strategy.ServerManagerRebootNodeStrategy; +import org.jclouds.servermanager.compute.suppliers.ServerManagerHardwareSupplier; +import org.jclouds.servermanager.compute.suppliers.ServerManagerImageSupplier; +import org.jclouds.servermanager.compute.suppliers.ServerManagerLocationSupplier; + +import com.google.inject.Module; + +/** + * + * @author Adrian Cole + */ +public class ServerManagerComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder { + + public ServerManagerComputeServiceContextBuilder(Properties props) { + super(props); + } + + @Override + protected void addContextModule(List modules) { + modules.add(createContextModule()); + } + + public static StandaloneComputeServiceContextModule createContextModule() { + return StandaloneComputeServiceContextModule.builder() + .defineAddNodeWithTagStrategy(ServerManagerAddNodeWithTagStrategy.class) + .defineDestroyNodeStrategy(ServerManagerDestroyNodeStrategy.class) + .defineGetNodeMetadataStrategy(ServerManagerGetAndListNodesStrategy.class) + .defineListNodesStrategy(ServerManagerGetAndListNodesStrategy.class) + .defineRebootNodeStrategy(ServerManagerRebootNodeStrategy.class) + .defineHardwareSupplier(ServerManagerHardwareSupplier.class) + .defineLocationSupplier(ServerManagerLocationSupplier.class) + .defineImageSupplier(ServerManagerImageSupplier.class).build(); + } + +} diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerManagerHardwareToHardware.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerManagerHardwareToHardware.java new file mode 100644 index 0000000000..0ba6387ce3 --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerManagerHardwareToHardware.java @@ -0,0 +1,50 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute.functions; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Volume; +import org.jclouds.compute.domain.internal.VolumeImpl; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableList; + +/** + * @author Adrian Cole + */ +@Singleton +public class ServerManagerHardwareToHardware implements Function { + + @Override + public Hardware apply(org.jclouds.servermanager.Hardware from) { + HardwareBuilder builder = new HardwareBuilder(); + builder.ids(from.id + ""); + builder.name(from.name); + builder.processors(ImmutableList.of(new Processor(from.cores, 1.0))); + builder.ram(from.ram); + builder.volumes(ImmutableList. of(new VolumeImpl(from.disk, true, false))); + return builder.build(); + } + +} diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerManagerImageToImage.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerManagerImageToImage.java new file mode 100644 index 0000000000..8708ef45ac --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerManagerImageToImage.java @@ -0,0 +1,62 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute.functions; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.OperatingSystemBuilder; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; + +import com.google.common.base.Function; + +/** + * @author Adrian Cole + */ +@Singleton +public class ServerManagerImageToImage implements Function { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + @Override + public Image apply(org.jclouds.servermanager.Image from) { + + ImageBuilder builder = new ImageBuilder(); + builder.ids(from.id + ""); + builder.name(from.name); + builder.description(from.name); + + OsFamily family = null; + try { + family = OsFamily.fromValue(from.name); + builder.operatingSystem(new OperatingSystemBuilder().name(from.name).family(family).build()); + } catch (IllegalArgumentException e) { + logger.debug("<< didn't match os(%s)", from); + } + return builder.build(); + } + +} diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerToNodeMetadata.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerToNodeMetadata.java new file mode 100644 index 0000000000..8d29a0efda --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/functions/ServerToNodeMetadata.java @@ -0,0 +1,135 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName; + +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.FindResourceInSet; +import org.jclouds.collect.Memoized; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.servermanager.Server; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +@Singleton +public class ServerToNodeMetadata implements Function { + + public static final Map serverStatusToNodeState = ImmutableMap + . builder().put(Server.Status.ACTIVE, NodeState.RUNNING)// + .put(Server.Status.BUILD, NodeState.PENDING)// + .put(Server.Status.TERMINATED, NodeState.TERMINATED)// + .put(Server.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED)// + .build(); + + private final FindHardwareForServer findHardwareForServer; + private final FindLocationForServer findLocationForServer; + private final FindImageForServer findImageForServer; + private final Map credentialStore; + + @Inject + ServerToNodeMetadata(Map credentialStore, FindHardwareForServer findHardwareForServer, + FindLocationForServer findLocationForServer, FindImageForServer findImageForServer) { + this.credentialStore = checkNotNull(credentialStore, "credentialStore"); + this.findHardwareForServer = checkNotNull(findHardwareForServer, "findHardwareForServer"); + this.findLocationForServer = checkNotNull(findLocationForServer, "findLocationForServer"); + this.findImageForServer = checkNotNull(findImageForServer, "findImageForServer"); + } + + @Override + public NodeMetadata apply(Server from) { + // convert the result object to a jclouds NodeMetadata + NodeMetadataBuilder builder = new NodeMetadataBuilder(); + builder.ids(from.id + ""); + builder.name(from.name); + builder.location(findLocationForServer.apply(from)); + builder.tag(parseTagFromName(from.name)); + builder.imageId(from.imageId + ""); + Image image = findImageForServer.apply(from); + if (image != null) + builder.operatingSystem(image.getOperatingSystem()); + builder.hardware(findHardwareForServer.apply(from)); + builder.state(serverStatusToNodeState.get(from.status)); + builder.publicAddresses(ImmutableSet. of(from.publicAddress)); + builder.privateAddresses(ImmutableSet. of(from.privateAddress)); + builder.credentials(credentialStore.get(from.id + "")); + return builder.build(); + } + + @Singleton + public static class FindHardwareForServer extends FindResourceInSet { + + @Inject + public FindHardwareForServer(@Memoized Supplier> hardware) { + super(hardware); + } + + @Override + public boolean matches(Server from, Hardware input) { + return input.getProviderId().equals(from.hardwareId + ""); + } + } + + @Singleton + public static class FindImageForServer extends FindResourceInSet { + + @Inject + public FindImageForServer(@Memoized Supplier> hardware) { + super(hardware); + } + + @Override + public boolean matches(Server from, Image input) { + return input.getProviderId().equals(from.imageId + ""); + } + } + + @Singleton + public static class FindLocationForServer extends FindResourceInSet { + + @Inject + public FindLocationForServer(@Memoized Supplier> hardware) { + super(hardware); + } + + @Override + public boolean matches(Server from, Location input) { + return input.getId().equals(from.datacenter + ""); + } + } +} diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerAddNodeWithTagStrategy.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerAddNodeWithTagStrategy.java new file mode 100644 index 0000000000..a934b9afd3 --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerAddNodeWithTagStrategy.java @@ -0,0 +1,89 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import java.util.Map; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.strategy.AddNodeWithTagStrategy; +import org.jclouds.domain.Credentials; +import org.jclouds.logging.Logger; +import org.jclouds.servermanager.Server; +import org.jclouds.servermanager.ServerManager; +import org.jclouds.servermanager.compute.functions.ServerToNodeMetadata; + +/** + * This creates a node in the backend client. You create it with the parameters of the + * {@link Template} object. Then, convert it to a {@link NodeMetadata} object. + * + * @author Adrian Cole + * + */ +@Singleton +public class ServerManagerAddNodeWithTagStrategy implements AddNodeWithTagStrategy { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private final Map credentialStore; + private final ServerManager client; + private final ServerToNodeMetadata serverToNodeMetadata; + + @Inject + public ServerManagerAddNodeWithTagStrategy(Map credentialStore, ServerManager client, + ServerToNodeMetadata serverToNodeMetadata) { + this.credentialStore = checkNotNull(credentialStore, "credentialStore"); + this.client = checkNotNull(client, "client"); + this.serverToNodeMetadata = checkNotNull(serverToNodeMetadata, "serverToNodeMetadata"); + } + + /** + * {@inheritDoc} + */ + @Override + public NodeMetadata execute(String tag, String name, Template template) { + checkState(tag != null, "tag (that which groups identical nodes together) must be specified"); + checkState(name != null && name.indexOf(tag) != -1, "name should have %s encoded into it", tag); + + logger.debug(">> instantiating new server dc(%s) name(%s) image(%s) hardware(%s)", + template.getLocation().getId(), name, template.getImage().getProviderId(), template.getHardware() + .getProviderId()); + + // create the backend object using parameters from the template. + Server from = client.createServerInDC(template.getLocation().getId(), name, + Integer.parseInt(template.getImage().getProviderId()), + Integer.parseInt(template.getHardware().getProviderId())); + // store the credentials so that later functions can use them + credentialStore.put(from.id + "", new Credentials(from.loginUser, from.password)); + logger.debug("<< instantiated server(%s)", from.id); + return serverToNodeMetadata.apply(from); + } + +} \ No newline at end of file diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerDestroyNodeStrategy.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerDestroyNodeStrategy.java new file mode 100644 index 0000000000..50ae2286fb --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerDestroyNodeStrategy.java @@ -0,0 +1,68 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.strategy.DestroyNodeStrategy; +import org.jclouds.compute.strategy.GetNodeMetadataStrategy; +import org.jclouds.logging.Logger; +import org.jclouds.servermanager.ServerManager; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ServerManagerDestroyNodeStrategy implements DestroyNodeStrategy { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private final ServerManager client; + private final GetNodeMetadataStrategy getNodeMetadataStrategy; + + @Inject + protected ServerManagerDestroyNodeStrategy(ServerManager client, GetNodeMetadataStrategy getNodeMetadataStrategy) { + this.client = checkNotNull(client, "client"); + this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, "getNodeMetadataStrategy"); + } + + @Override + public NodeMetadata execute(String id) { + + NodeMetadata node = getNodeMetadataStrategy.execute(id); + if (node == null) + return node; + + logger.debug(">> destroying server(%s)", id); + client.destroyServer(Integer.parseInt(id)); + logger.debug("<< destroyed server(%s)", id); + + return node; + } +} diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerGetAndListNodesStrategy.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerGetAndListNodesStrategy.java new file mode 100644 index 0000000000..e28e578d76 --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerGetAndListNodesStrategy.java @@ -0,0 +1,70 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.predicates.NodePredicates; +import org.jclouds.compute.strategy.GetNodeMetadataStrategy; +import org.jclouds.compute.strategy.ListNodesStrategy; +import org.jclouds.servermanager.Server; +import org.jclouds.servermanager.ServerManager; +import org.jclouds.servermanager.compute.functions.ServerToNodeMetadata; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ServerManagerGetAndListNodesStrategy implements ListNodesStrategy, GetNodeMetadataStrategy { + private final ServerManager client; + private final ServerToNodeMetadata serverToNodeMetadata; + + @Inject + protected ServerManagerGetAndListNodesStrategy(ServerManager client, ServerToNodeMetadata serverToNodeMetadata) { + this.client = checkNotNull(client, "client"); + this.serverToNodeMetadata = checkNotNull(serverToNodeMetadata, "serverToNodeMetadata"); + } + + @Override + public NodeMetadata execute(String id) { + int serverId = Integer.parseInt(id); + Server server = client.getServer(serverId); + return server == null ? null : serverToNodeMetadata.apply(server); + } + + @Override + public Iterable list() { + return listDetailsOnNodesMatching(NodePredicates.all()); + } + + @Override + public Iterable listDetailsOnNodesMatching(Predicate filter) { + return Iterables.filter(Iterables.transform(client.listServers(), serverToNodeMetadata), filter); + } +} \ No newline at end of file diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerRebootNodeStrategy.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerRebootNodeStrategy.java new file mode 100644 index 0000000000..6420a5a222 --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/strategy/ServerManagerRebootNodeStrategy.java @@ -0,0 +1,69 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.strategy.GetNodeMetadataStrategy; +import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.logging.Logger; +import org.jclouds.servermanager.ServerManager; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ServerManagerRebootNodeStrategy implements RebootNodeStrategy { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private final ServerManager client; + private final GetNodeMetadataStrategy getNodeMetadataStrategy; + + @Inject + protected ServerManagerRebootNodeStrategy(ServerManager client, GetNodeMetadataStrategy getNodeMetadataStrategy) { + this.client = checkNotNull(client, "client"); + this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, "getNodeMetadataStrategy"); + } + + @Override + public NodeMetadata execute(String id) { + + NodeMetadata node = getNodeMetadataStrategy.execute(id); + if (node == null || node.getState() == NodeState.TERMINATED) + return node; + + logger.debug(">> rebooting server(%s)", id); + client.rebootServer(Integer.parseInt(id)); + logger.debug("<< rebooted server(%s)", id); + + return node; + } +} diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/suppliers/ServerManagerHardwareSupplier.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/suppliers/ServerManagerHardwareSupplier.java new file mode 100644 index 0000000000..1039c398ac --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/suppliers/ServerManagerHardwareSupplier.java @@ -0,0 +1,49 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute.suppliers; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.TransformingSetSupplier; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.servermanager.ServerManager; +import org.jclouds.servermanager.compute.functions.ServerManagerHardwareToHardware; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ServerManagerHardwareSupplier extends + TransformingSetSupplier { + private final ServerManager client; + + @Inject + protected ServerManagerHardwareSupplier(ServerManager client, + ServerManagerHardwareToHardware serverManagerHardwareToHardware) { + super(serverManagerHardwareToHardware); + this.client = client; + } + + public Iterable supplyFrom() { + return client.listHardware(); + } +} diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/suppliers/ServerManagerImageSupplier.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/suppliers/ServerManagerImageSupplier.java new file mode 100644 index 0000000000..666addfa42 --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/suppliers/ServerManagerImageSupplier.java @@ -0,0 +1,47 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute.suppliers; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.TransformingSetSupplier; +import org.jclouds.compute.domain.Image; +import org.jclouds.servermanager.ServerManager; +import org.jclouds.servermanager.compute.functions.ServerManagerImageToImage; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ServerManagerImageSupplier extends TransformingSetSupplier { + private final ServerManager client; + + @Inject + protected ServerManagerImageSupplier(ServerManager client, ServerManagerImageToImage serverManagerImageToImage) { + super(serverManagerImageToImage); + this.client = client; + } + + public Iterable supplyFrom() { + return client.listImages(); + } +} diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/suppliers/ServerManagerLocationSupplier.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/suppliers/ServerManagerLocationSupplier.java new file mode 100644 index 0000000000..e40109c04a --- /dev/null +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/suppliers/ServerManagerLocationSupplier.java @@ -0,0 +1,54 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.servermanager.compute.suppliers; + +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.internal.LocationImpl; +import org.jclouds.rest.annotations.Provider; + +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class ServerManagerLocationSupplier implements Supplier> { + + private final String providerName; + + @Inject + ServerManagerLocationSupplier(@Provider String providerName) { + this.providerName = providerName; + } + + @Override + public Set get() { + Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); + return ImmutableSet.of(new LocationImpl(LocationScope.ZONE, "1", "SFO", provider)); + } +} \ No newline at end of file diff --git a/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilderTest.java b/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilderTest.java new file mode 100644 index 0000000000..5c45742b6c --- /dev/null +++ b/skeletons/standalone-compute/src/test/java/org/jclouds/servermanager/compute/ServerManagerComputeServiceContextBuilderTest.java @@ -0,0 +1,38 @@ +package org.jclouds.servermanager.compute; + +import static org.testng.Assert.assertNotNull; + +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.ComputeServiceContextFactory; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + * + */ +@Test(groups = "unit") +public class ServerManagerComputeServiceContextBuilderTest { + + @Test + public void testCreateContextModule() { + assertNotNull(ServerManagerComputeServiceContextBuilder.createContextModule()); + } + + @Test + public void testCanBuildDirectly() { + ComputeServiceContext context = new ServerManagerComputeServiceContextBuilder(new Properties()) + .buildComputeServiceContext(); + context.close(); + } + + @Test + public void testCanBuildWithComputeService() { + ComputeServiceContext context = ComputeServiceContextFactory + .createStandaloneContext(ServerManagerComputeServiceContextBuilder.createContextModule()); + context.close(); + + } +} diff --git a/skeletons/standalone-compute/src/test/resources/log4j.xml b/skeletons/standalone-compute/src/test/resources/log4j.xml new file mode 100755 index 0000000000..f7337defb9 --- /dev/null +++ b/skeletons/standalone-compute/src/test/resources/log4j.xml @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file