diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java index 54a7429302..6def69c6cf 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java @@ -77,8 +77,8 @@ public class RunningInstanceToNodeMetadata implements Function instanceToNodeState = ImmutableMap - . builder().put(InstanceState.PENDING, NodeState.PENDING).put( - InstanceState.RUNNING, NodeState.RUNNING).put(InstanceState.SHUTTING_DOWN, NodeState.PENDING).put( - InstanceState.TERMINATED, NodeState.TERMINATED).build(); + @VisibleForTesting + static final Map instanceToNodeState = ImmutableMap. builder() + .put(InstanceState.PENDING, NodeState.PENDING).put(InstanceState.RUNNING, NodeState.RUNNING).put( + InstanceState.SHUTTING_DOWN, NodeState.PENDING).put(InstanceState.TERMINATED, NodeState.TERMINATED).put( + InstanceState.STOPPING, NodeState.PENDING).put(InstanceState.STOPPED, NodeState.SUSPENDED).build(); private final EC2Client client; private final Map credentialsMap; @@ -128,10 +129,11 @@ public class RunningInstanceToNodeMetadata implements Function credentialsMap, - PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, - Provider> images, // to facilitate on-demand refresh of image list - ConcurrentMap imageMap, Set locations, - @Named("volumeMapping") Function> instanceToStorageMapping) { + PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, + Provider> images, // to facilitate on-demand + // refresh of image list + ConcurrentMap imageMap, Set locations, + @Named("volumeMapping") Function> instanceToStorageMapping) { this.client = checkNotNull(client, "client"); this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap"); this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider"); @@ -166,7 +168,7 @@ public class RunningInstanceToNodeMetadata implements Function> { private final Set images; @@ -117,8 +126,8 @@ public class RunningInstanceToNodeMetadataTest { replay(instance); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, - credentialProvider, new ImageProvider(jcImage), imageMap, locations, - new RunningInstanceToStorageMappingUnix()); + credentialProvider, new ImageProvider(jcImage), imageMap, locations, + new RunningInstanceToStorageMappingUnix()); NodeMetadata metadata = parser.apply(instance); assertEquals(metadata.getLocation(), locations.iterator().next()); @@ -168,7 +177,7 @@ public class RunningInstanceToNodeMetadataTest { expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce(); expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andThrow(new NullPointerException()) - .atLeastOnce(); + .atLeastOnce(); expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); @@ -181,8 +190,8 @@ public class RunningInstanceToNodeMetadataTest { replay(instance); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, - credentialProvider, new ImageProvider(jcImage), imageMap, locations, - new RunningInstanceToStorageMappingUnix()); + credentialProvider, new ImageProvider(jcImage), imageMap, locations, + new RunningInstanceToStorageMappingUnix()); NodeMetadata metadata = parser.apply(instance); assertEquals(metadata.getLocation(), locations.iterator().next()); @@ -247,8 +256,8 @@ public class RunningInstanceToNodeMetadataTest { replay(instance); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, - credentialProvider, new ImageProvider(jcImage), imageMap, locations, - new RunningInstanceToStorageMappingUnix()); + credentialProvider, new ImageProvider(jcImage), imageMap, locations, + new RunningInstanceToStorageMappingUnix()); NodeMetadata metadata = parser.apply(instance); assertEquals(metadata.getLocation(), locations.iterator().next()); @@ -310,8 +319,8 @@ public class RunningInstanceToNodeMetadataTest { replay(instance); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, - credentialProvider, new ImageProvider(jcImage), imageMap, locations, - new RunningInstanceToStorageMappingUnix()); + credentialProvider, new ImageProvider(jcImage), imageMap, locations, + new RunningInstanceToStorageMappingUnix()); NodeMetadata metadata = parser.apply(instance); assertEquals(metadata.getLocation(), locations.iterator().next()); @@ -371,8 +380,8 @@ public class RunningInstanceToNodeMetadataTest { replay(instance); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, - credentialProvider, new ImageProvider(jcImage), imageMap, locations, - new RunningInstanceToStorageMappingUnix()); + credentialProvider, new ImageProvider(jcImage), imageMap, locations, + new RunningInstanceToStorageMappingUnix()); NodeMetadata metadata = parser.apply(instance); assertEquals(metadata.getLocation(), locations.iterator().next()); @@ -424,12 +433,12 @@ public class RunningInstanceToNodeMetadataTest { expect(jcImage.getLocation()).andReturn(location).atLeastOnce(); expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn( - (Set) ImmutableSet. of(image)); + (Set) ImmutableSet. of(image)); expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn( - new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass")); + new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass")); expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); @@ -444,8 +453,8 @@ public class RunningInstanceToNodeMetadataTest { replay(jcImage); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, - credentialProvider, new ImageProvider(jcImage), imageMap, locations, - new RunningInstanceToStorageMappingUnix()); + credentialProvider, new ImageProvider(jcImage), imageMap, locations, + new RunningInstanceToStorageMappingUnix()); NodeMetadata metadata = parser.apply(instance); assertEquals(metadata.getTag(), "tag"); @@ -499,12 +508,12 @@ public class RunningInstanceToNodeMetadataTest { expect(jcImage.getLocation()).andReturn(location).atLeastOnce(); expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn( - (Set) ImmutableSet. of(image)); + (Set) ImmutableSet. of(image)); expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn( - new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass")); + new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass")); expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); @@ -519,8 +528,8 @@ public class RunningInstanceToNodeMetadataTest { replay(jcImage); RunningInstanceToNodeMetadata parser = new RunningInstanceToNodeMetadata(client, credentialsMap, - credentialProvider, new ImageProvider(jcImage), imageMap, locations, - new RunningInstanceToStorageMappingUnix()); + credentialProvider, new ImageProvider(jcImage), imageMap, locations, + new RunningInstanceToStorageMappingUnix()); NodeMetadata metadata = parser.apply(instance); diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java index 320e0c7b67..b938a39bf6 100755 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java @@ -70,6 +70,7 @@ import org.jclouds.gogrid.domain.Option; import org.jclouds.gogrid.domain.PowerCommand; import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.ServerImage; +import org.jclouds.gogrid.domain.ServerState; import org.jclouds.gogrid.predicates.ServerLatestJobCompleted; import org.jclouds.gogrid.util.GoGridUtils; import org.jclouds.logging.Logger; @@ -78,6 +79,7 @@ import org.jclouds.rest.RestContext; import org.jclouds.rest.annotations.Provider; import org.jclouds.rest.internal.RestContextImpl; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; @@ -93,6 +95,7 @@ import com.google.inject.util.Providers; /** * @author Oleksiy Yarmula + * @author Adrian Cole */ public class GoGridComputeServiceContextModule extends AbstractModule { @@ -149,22 +152,18 @@ public class GoGridComputeServiceContextModule extends AbstractModule { private final GetNodeMetadataStrategy getNode; @Inject - protected GoGridRebootNodeStrategy(GoGridClient client, GetNodeMetadataStrategy getNode, - Timeouts timeouts) { + protected GoGridRebootNodeStrategy(GoGridClient client, GetNodeMetadataStrategy getNode, Timeouts timeouts) { this.client = client; - this.serverLatestJobCompleted = new RetryablePredicate( - new ServerLatestJobCompleted(client.getJobServices()), - timeouts.nodeRunning * 9l / 10l); - this.serverLatestJobCompletedShort = new RetryablePredicate( - new ServerLatestJobCompleted(client.getJobServices()), - timeouts.nodeRunning * 1l / 10l); + this.serverLatestJobCompleted = new RetryablePredicate(new ServerLatestJobCompleted(client + .getJobServices()), timeouts.nodeRunning * 9l / 10l); + this.serverLatestJobCompletedShort = new RetryablePredicate(new ServerLatestJobCompleted(client + .getJobServices()), timeouts.nodeRunning * 1l / 10l); this.getNode = getNode; } @Override public NodeMetadata execute(String id) { - Server server = Iterables.getOnlyElement(client.getServerServices().getServersById( - new Long(id))); + Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(id))); client.getServerServices().power(server.getName(), PowerCommand.RESTART); serverLatestJobCompleted.apply(server); client.getServerServices().power(server.getName(), PowerCommand.START); @@ -179,8 +178,7 @@ public class GoGridComputeServiceContextModule extends AbstractModule { private final Function serverToNodeMetadata; @Inject - protected GoGridListNodesStrategy(GoGridClient client, - Function serverToNodeMetadata) { + protected GoGridListNodesStrategy(GoGridClient client, Function serverToNodeMetadata) { this.client = client; this.serverToNodeMetadata = serverToNodeMetadata; } @@ -191,10 +189,9 @@ public class GoGridComputeServiceContextModule extends AbstractModule { } @Override - public Iterable listDetailsOnNodesMatching( - Predicate filter) { - return Iterables.filter(Iterables.transform(client.getServerServices().getServerList(), - serverToNodeMetadata), filter); + public Iterable listDetailsOnNodesMatching(Predicate filter) { + return Iterables.filter(Iterables.transform(client.getServerServices().getServerList(), serverToNodeMetadata), + filter); } } @@ -204,8 +201,7 @@ public class GoGridComputeServiceContextModule extends AbstractModule { private final Function serverToNodeMetadata; @Inject - protected GoGridGetNodeMetadataStrategy(GoGridClient client, - Function serverToNodeMetadata) { + protected GoGridGetNodeMetadataStrategy(GoGridClient client, Function serverToNodeMetadata) { this.client = client; this.serverToNodeMetadata = serverToNodeMetadata; } @@ -214,7 +210,7 @@ public class GoGridComputeServiceContextModule extends AbstractModule { public NodeMetadata execute(String id) { try { Server server = Iterables.getOnlyElement(client.getServerServices().getServersById( - new Long(checkNotNull(id, "id")))); + new Long(checkNotNull(id, "id")))); return server == null ? null : serverToNodeMetadata.apply(server); } catch (NoSuchElementException e) { return null; @@ -241,21 +237,31 @@ public class GoGridComputeServiceContextModule extends AbstractModule { } + @VisibleForTesting + static final Map serverStateToNodeState = ImmutableMap. builder() + .put(ServerState.ON, NodeState.RUNNING)// + .put(ServerState.STARTING, NodeState.PENDING)// + .put(ServerState.OFF, NodeState.SUSPENDED)// + .put(ServerState.STOPPING, NodeState.PENDING)// + .put(ServerState.RESTARTING, NodeState.PENDING)// + .put(ServerState.SAVING, NodeState.PENDING)// + .put(ServerState.RESTORING, NodeState.PENDING)// + .put(ServerState.UPDATING, NodeState.PENDING).build(); + @Singleton @Provides - Map provideServerToNodeState() { - return ImmutableMap. builder().put("On", NodeState.RUNNING).put( - "Starting", NodeState.PENDING).put("Off", NodeState.SUSPENDED).put("Saving", - NodeState.PENDING).put("Restarting", NodeState.PENDING).put("Stopping", - NodeState.PENDING).build(); + Map provideServerToNodeState() { + return serverStateToNodeState; } /** - * Finds matches to required configurations. GoGrid's documentation only specifies how much RAM - * one can get with different instance types. The # of cores and disk sizes are purely empyrical - * and aren't guaranteed. However, these are the matches found: Ram: 512MB, CPU: 1 core, HDD: 28 - * GB Ram: 1GB, CPU: 1 core, HDD: 57 GB Ram: 2GB, CPU: 1 core, HDD: 113 GB Ram: 4GB, CPU: 3 - * cores, HDD: 233 GB Ram: 8GB, CPU: 6 cores, HDD: 462 GB (as of March 2010) + * Finds matches to required configurations. GoGrid's documentation only + * specifies how much RAM one can get with different instance types. The # of + * cores and disk sizes are purely empyrical and aren't guaranteed. However, + * these are the matches found: Ram: 512MB, CPU: 1 core, HDD: 28 GB Ram: 1GB, + * CPU: 1 core, HDD: 57 GB Ram: 2GB, CPU: 1 core, HDD: 113 GB Ram: 4GB, CPU: + * 3 cores, HDD: 233 GB Ram: 8GB, CPU: 6 cores, HDD: 462 GB (as of March + * 2010) * * @return matched size */ @@ -281,7 +287,7 @@ public class GoGridComputeServiceContextModule extends AbstractModule { @Provides @Singleton Location getDefaultLocation(@Named(PROPERTY_GOGRID_DEFAULT_DC) final String defaultDC, - Set locations) { + Set locations) { return Iterables.find(locations, new Predicate() { @Override @@ -294,14 +300,13 @@ public class GoGridComputeServiceContextModule extends AbstractModule { @Provides @Singleton - Set getAssignableLocations(@Provider String providerName, GoGridClient sync, - LogHolder holder, Function indexer) { + Set getAssignableLocations(@Provider String providerName, GoGridClient sync, LogHolder holder, + Function indexer) { final Set locations = Sets.newHashSet(); holder.logger.debug(">> providing locations"); Location parent = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); for (Option dc : sync.getServerServices().getDatacenters()) - locations.add(new LocationImpl(LocationScope.ZONE, dc.getId() + "", dc.getDescription(), - parent)); + locations.add(new LocationImpl(LocationScope.ZONE, dc.getId() + "", dc.getDescription(), parent)); holder.logger.debug("<< locations(%d)", locations.size()); return locations; } @@ -319,27 +324,21 @@ public class GoGridComputeServiceContextModule extends AbstractModule { @Provides @Singleton - protected Set provideSizes(GoGridClient sync, Set images, - LogHolder holder, Function indexer) - throws InterruptedException, TimeoutException, ExecutionException { + protected Set provideSizes(GoGridClient sync, Set images, LogHolder holder, + Function indexer) throws InterruptedException, TimeoutException, ExecutionException { final Set sizes = Sets.newHashSet(); holder.logger.debug(">> providing sizes"); - sizes.add(new SizeImpl("1", "1", "1", null, null, ImmutableMap. of(), 0.5, - 512, 30, architectureIn(ImmutableSet. of(Architecture.X86_32, - Architecture.X86_64)))); - sizes.add(new SizeImpl("2", "2", "2", null, null, ImmutableMap. of(), 1, - 1024, 60, architectureIn(ImmutableSet. of(Architecture.X86_32, - Architecture.X86_64)))); - sizes.add(new SizeImpl("3", "3", "3", null, null, ImmutableMap. of(), 2, - 2048, 120, architectureIn(ImmutableSet. of(Architecture.X86_32, - Architecture.X86_64)))); - sizes.add(new SizeImpl("4", "4", "4", null, null, ImmutableMap. of(), 4, - 4096, 240, architectureIn(ImmutableSet. of(Architecture.X86_32, - Architecture.X86_64)))); - sizes.add(new SizeImpl("5", "5", "5", null, null, ImmutableMap. of(), 8, - 8192, 480, architectureIn(ImmutableSet. of(Architecture.X86_32, - Architecture.X86_64)))); + sizes.add(new SizeImpl("1", "1", "1", null, null, ImmutableMap. of(), 0.5, 512, 30, + architectureIn(ImmutableSet. of(Architecture.X86_32, Architecture.X86_64)))); + sizes.add(new SizeImpl("2", "2", "2", null, null, ImmutableMap. of(), 1, 1024, 60, + architectureIn(ImmutableSet. of(Architecture.X86_32, Architecture.X86_64)))); + sizes.add(new SizeImpl("3", "3", "3", null, null, ImmutableMap. of(), 2, 2048, 120, + architectureIn(ImmutableSet. of(Architecture.X86_32, Architecture.X86_64)))); + sizes.add(new SizeImpl("4", "4", "4", null, null, ImmutableMap. of(), 4, 4096, 240, + architectureIn(ImmutableSet. of(Architecture.X86_32, Architecture.X86_64)))); + sizes.add(new SizeImpl("5", "5", "5", null, null, ImmutableMap. of(), 8, 8192, 480, + architectureIn(ImmutableSet. of(Architecture.X86_32, Architecture.X86_64)))); holder.logger.debug("<< sizes(%d)", sizes.size()); return sizes; } @@ -355,32 +354,32 @@ public class GoGridComputeServiceContextModule extends AbstractModule { @Provides @Singleton protected Set provideImages(final GoGridClient sync, LogHolder holder, - Function indexer, Location location, - PopulateDefaultLoginCredentialsForImageStrategy authenticator) - throws InterruptedException, ExecutionException, TimeoutException { + Function indexer, Location location, + PopulateDefaultLoginCredentialsForImageStrategy authenticator) throws InterruptedException, + ExecutionException, TimeoutException { final Set images = Sets.newHashSet(); holder.logger.debug(">> providing images"); Set allImages = sync.getImageServices().getImageList(); for (ServerImage from : allImages) { OsFamily os = null; - Architecture arch = (from.getOs().getName().indexOf("64") == -1 && from.getDescription() - .indexOf("64") == -1) ? Architecture.X86_32 : Architecture.X86_64; + Architecture arch = (from.getOs().getName().indexOf("64") == -1 && from.getDescription().indexOf("64") == -1) ? Architecture.X86_32 + : Architecture.X86_64; String osDescription; String version = ""; osDescription = from.getOs().getName(); - String matchedOs = GoGridUtils.parseStringByPatternAndGetNthMatchGroup(from.getOs() - .getName(), GOGRID_OS_NAME_PATTERN, 1); + String matchedOs = GoGridUtils.parseStringByPatternAndGetNthMatchGroup(from.getOs().getName(), + GOGRID_OS_NAME_PATTERN, 1); try { os = OsFamily.fromValue(matchedOs.toLowerCase()); } catch (IllegalArgumentException e) { holder.logger.debug("<< didn't match os(%s)", matchedOs); } Credentials defaultCredentials = authenticator.execute(from); - images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), from.getId() + "", - location, null, ImmutableMap. of(), from.getDescription(), - version, os, osDescription, arch, defaultCredentials)); + images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), from.getId() + "", location, null, + ImmutableMap. of(), from.getDescription(), version, os, osDescription, arch, + defaultCredentials)); } holder.logger.debug("<< images(%d)", images.size()); return images; diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java index 854265c342..95c140a14b 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java @@ -38,6 +38,7 @@ import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.gogrid.GoGridClient; import org.jclouds.gogrid.domain.Server; +import org.jclouds.gogrid.domain.ServerState; import org.jclouds.logging.Logger; import com.google.common.base.Function; @@ -56,7 +57,7 @@ public class ServerToNodeMetadata implements Function { @Resource protected Logger logger = Logger.NULL; - private final Map serverStateToNodeState; + private final Map serverStateToNodeState; private final GoGridClient client; private final Set images; private final Map locations; @@ -72,14 +73,14 @@ public class ServerToNodeMetadata implements Function { @Override public boolean apply(Image input) { return input.getProviderId().equals(instance.getImage().getId() + "") - && (input.getLocation() == null || input.getLocation().getId().equals( - instance.getDatacenter().getId() + "")); + && (input.getLocation() == null || input.getLocation().getId().equals( + instance.getDatacenter().getId() + "")); } } @Inject - ServerToNodeMetadata(Map serverStateToNodeState, GoGridClient client, - Set images, Map locations) { + ServerToNodeMetadata(Map serverStateToNodeState, GoGridClient client, + Set images, Map locations) { this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState"); this.client = checkNotNull(client, "client"); this.images = checkNotNull(images, "images"); @@ -91,7 +92,7 @@ public class ServerToNodeMetadata implements Function { Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName()); final String tag = matcher.find() ? matcher.group(1) : null; Set ipSet = ImmutableSet.of(from.getIp().getIp()); - NodeState state = serverStateToNodeState.get(from.getState().getName()); + NodeState state = serverStateToNodeState.get(from.getState()); Credentials creds = client.getServerServices().getServerCredentialsList().get(from.getName()); Image image = null; try { @@ -99,9 +100,9 @@ public class ServerToNodeMetadata implements Function { } catch (NoSuchElementException e) { logger.warn("could not find a matching image for server %s", from); } - return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations - .get(from.getDatacenter().getId() + ""), null, ImmutableMap. of(), - tag, image, state, ipSet, ImmutableList. of(), ImmutableMap - . of(), creds); + return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get(from + .getDatacenter().getId() + + ""), null, ImmutableMap. of(), tag, image, state, ipSet, ImmutableList. of(), + ImmutableMap. of(), creds); } } \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridParserModule.java b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridParserModule.java index 12ae9b8212..33b8183bc9 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridParserModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridParserModule.java @@ -34,6 +34,7 @@ import org.jclouds.gogrid.domain.LoadBalancerType; import org.jclouds.gogrid.domain.ObjectType; import org.jclouds.gogrid.domain.ServerImageState; import org.jclouds.gogrid.domain.ServerImageType; +import org.jclouds.gogrid.domain.ServerState; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.json.config.GsonModule.DateAdapter; @@ -60,6 +61,7 @@ public class GoGridParserModule extends AbstractModule { bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter()); bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter()); bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter()); + bindings.put(ServerState.class, new CustomDeserializers.ServerStateAdapter()); bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter()); bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/Server.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/Server.java index 9e39d2bc4f..e1715ff035 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/domain/Server.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/Server.java @@ -23,18 +23,18 @@ */ package org.jclouds.gogrid.domain; + import com.google.common.primitives.Longs; /** * @author Oleksiy Yarmula */ public class Server implements Comparable { - private long id; private boolean isSandbox; private String name; private String description; - private Option state; + private ServerState state; private Option datacenter; private Option type; @@ -47,11 +47,11 @@ public class Server implements Comparable { /** * A no-args constructor is required for deserialization */ - public Server() { + Server() { } - public Server(long id, Option datacenter, boolean sandbox, String name, String description, - Option state, Option type, Option ram, Option os, Ip ip, ServerImage image) { + public Server(long id, Option datacenter, boolean sandbox, String name, String description, ServerState state, + Option type, Option ram, Option os, Ip ip, ServerImage image) { this.id = id; this.isSandbox = sandbox; this.name = name; @@ -85,7 +85,7 @@ public class Server implements Comparable { return description; } - public Option getState() { + public ServerState getState() { return state; } @@ -195,8 +195,8 @@ public class Server implements Comparable { @Override public String toString() { - return "Server [datacenter=" + datacenter + ", description=" + description + ", id=" + id - + ", image=" + image + ", ip=" + ip + ", isSandbox=" + isSandbox + ", name=" + name - + ", os=" + os + ", ram=" + ram + ", state=" + state + ", type=" + type + "]"; + return "Server [datacenter=" + datacenter + ", description=" + description + ", id=" + id + ", image=" + image + + ", ip=" + ip + ", isSandbox=" + isSandbox + ", name=" + name + ", os=" + os + ", ram=" + ram + ", state=" + + state + ", type=" + type + "]"; } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/ServerState.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/ServerState.java new file mode 100644 index 0000000000..21edd4b3b7 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/ServerState.java @@ -0,0 +1,49 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.gogrid.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.base.CaseFormat; + +/** + * @author Adrian Cole + */ +public enum ServerState { + + ON, STARTING, OFF, STOPPING, RESTARTING, SAVING, RESTORING, UPDATING; + + public String value() { + return (CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name())); + } + + @Override + public String toString() { + return value(); + } + + public static ServerState fromValue(String state) { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state"))); + } +} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/gogrid/functions/internal/CustomDeserializers.java b/gogrid/src/main/java/org/jclouds/gogrid/functions/internal/CustomDeserializers.java index 9634e5d502..f6724b8a47 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/functions/internal/CustomDeserializers.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/functions/internal/CustomDeserializers.java @@ -18,86 +18,118 @@ */ package org.jclouds.gogrid.functions.internal; -import com.google.gson.*; -import org.jclouds.gogrid.domain.*; - import java.lang.reflect.Type; +import org.jclouds.gogrid.domain.IpState; +import org.jclouds.gogrid.domain.JobState; +import org.jclouds.gogrid.domain.LoadBalancerOs; +import org.jclouds.gogrid.domain.LoadBalancerPersistenceType; +import org.jclouds.gogrid.domain.LoadBalancerState; +import org.jclouds.gogrid.domain.LoadBalancerType; +import org.jclouds.gogrid.domain.ObjectType; +import org.jclouds.gogrid.domain.ServerImageState; +import org.jclouds.gogrid.domain.ServerImageType; +import org.jclouds.gogrid.domain.ServerState; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + /** * @author Oleksiy Yarmula */ public class CustomDeserializers { - public static class ObjectTypeAdapter implements JsonDeserializer { - @Override - public ObjectType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { - String name = ((JsonObject) jsonElement).get("name").getAsString(); - return ObjectType.fromValue(name); - } - } + public static class ServerStateAdapter implements JsonDeserializer { + @Override + public ServerState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + String name = ((JsonObject) jsonElement).get("name").getAsString(); + return ServerState.fromValue(name); + } + } - public static class LoadBalancerOsAdapter implements JsonDeserializer { - @Override - public LoadBalancerOs deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { - String name = ((JsonObject) jsonElement).get("name").getAsString(); - return LoadBalancerOs.fromValue(name); - } - } + public static class ObjectTypeAdapter implements JsonDeserializer { + @Override + public ObjectType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + String name = ((JsonObject) jsonElement).get("name").getAsString(); + return ObjectType.fromValue(name); + } + } - public static class LoadBalancerStateAdapter implements JsonDeserializer { - @Override - public LoadBalancerState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { - String name = ((JsonObject) jsonElement).get("name").getAsString(); - return LoadBalancerState.fromValue(name); - } - } + public static class LoadBalancerOsAdapter implements JsonDeserializer { + @Override + public LoadBalancerOs deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + String name = ((JsonObject) jsonElement).get("name").getAsString(); + return LoadBalancerOs.fromValue(name); + } + } - public static class LoadBalancerPersistenceTypeAdapter implements JsonDeserializer { - @Override - public LoadBalancerPersistenceType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { - String name = ((JsonObject) jsonElement).get("name").getAsString(); - return LoadBalancerPersistenceType.fromValue(name); - } - } + public static class LoadBalancerStateAdapter implements JsonDeserializer { + @Override + public LoadBalancerState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + String name = ((JsonObject) jsonElement).get("name").getAsString(); + return LoadBalancerState.fromValue(name); + } + } - public static class LoadBalancerTypeAdapter implements JsonDeserializer { - @Override - public LoadBalancerType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { - String name = ((JsonObject) jsonElement).get("name").getAsString(); - return LoadBalancerType.fromValue(name); - } - } + public static class LoadBalancerPersistenceTypeAdapter implements JsonDeserializer { + @Override + public LoadBalancerPersistenceType deserialize(JsonElement jsonElement, Type type, + JsonDeserializationContext context) throws JsonParseException { + String name = ((JsonObject) jsonElement).get("name").getAsString(); + return LoadBalancerPersistenceType.fromValue(name); + } + } - public static class IpStateAdapter implements JsonDeserializer { - @Override - public IpState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { - String name = ((JsonObject) jsonElement).get("name").getAsString(); - return IpState.fromValue(name); - } - } + public static class LoadBalancerTypeAdapter implements JsonDeserializer { + @Override + public LoadBalancerType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + String name = ((JsonObject) jsonElement).get("name").getAsString(); + return LoadBalancerType.fromValue(name); + } + } - public static class JobStateAdapter implements JsonDeserializer { - @Override - public JobState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { - String name = ((JsonObject) jsonElement).get("name").getAsString(); - return JobState.fromValue(name); - } - } + public static class IpStateAdapter implements JsonDeserializer { + @Override + public IpState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + String name = ((JsonObject) jsonElement).get("name").getAsString(); + return IpState.fromValue(name); + } + } - public static class ServerImageStateAdapter implements JsonDeserializer { - @Override - public ServerImageState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { - String name = ((JsonObject) jsonElement).get("name").getAsString(); - return ServerImageState.fromValue(name); - } - } + public static class JobStateAdapter implements JsonDeserializer { + @Override + public JobState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + String name = ((JsonObject) jsonElement).get("name").getAsString(); + return JobState.fromValue(name); + } + } - public static class ServerImageTypeAdapter implements JsonDeserializer { - @Override - public ServerImageType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { - String name = ((JsonObject) jsonElement).get("name").getAsString(); - return ServerImageType.fromValue(name); - } - } + public static class ServerImageStateAdapter implements JsonDeserializer { + @Override + public ServerImageState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + String name = ((JsonObject) jsonElement).get("name").getAsString(); + return ServerImageState.fromValue(name); + } + } + + public static class ServerImageTypeAdapter implements JsonDeserializer { + @Override + public ServerImageType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + String name = ((JsonObject) jsonElement).get("name").getAsString(); + return ServerImageType.fromValue(name); + } + } } diff --git a/gogrid/src/test/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModuleTest.java b/gogrid/src/test/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModuleTest.java new file mode 100644 index 0000000000..9484718e75 --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModuleTest.java @@ -0,0 +1,37 @@ +/** + * + * 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.gogrid.compute.config; + +import org.jclouds.gogrid.domain.ServerState; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "gogrid.GoGridComputeServiceContextModuleTest") +public class GoGridComputeServiceContextModuleTest { + + public void testAllStatusCovered() { + + for (ServerState state : ServerState.values()) { + assert GoGridComputeServiceContextModule.serverStateToNodeState.containsKey(state) : state; + } + + } +} diff --git a/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java b/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java index ef1db42ca0..9ee69069e1 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadataTest.java @@ -21,6 +21,7 @@ import org.jclouds.gogrid.domain.Ip; import org.jclouds.gogrid.domain.Option; import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.ServerImage; +import org.jclouds.gogrid.domain.ServerState; import org.jclouds.gogrid.services.GridServerClient; import org.testng.annotations.Test; @@ -39,7 +40,7 @@ public class ServerToNodeMetadataTest { GoGridClient caller = createMock(GoGridClient.class); GridServerClient client = createMock(GridServerClient.class); expect(caller.getServerServices()).andReturn(client).atLeastOnce(); - Map serverStateToNodeState = createMock(Map.class); + Map serverStateToNodeState = createMock(Map.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); Option dc = new Option(1l, "US-West-1", "US West 1 Datacenter"); @@ -48,9 +49,9 @@ public class ServerToNodeMetadataTest { expect(server.getId()).andReturn(1000l).atLeastOnce(); expect(server.getName()).andReturn("tag-ff").atLeastOnce(); - expect(server.getState()).andReturn(new Option("NODE_RUNNING")).atLeastOnce(); + expect(server.getState()).andReturn(ServerState.ON).atLeastOnce(); - expect(serverStateToNodeState.get("NODE_RUNNING")).andReturn(NodeState.RUNNING); + expect(serverStateToNodeState.get(ServerState.ON)).andReturn(NodeState.RUNNING); LocationImpl location = new LocationImpl(LocationScope.ZONE, "1", "US-West-1", null); Map locations = ImmutableMap. of("1", location); @@ -75,8 +76,7 @@ public class ServerToNodeMetadataTest { replay(jcImage); replay(credentialsMap); - ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, caller, - images, locations); + ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, caller, images, locations); NodeMetadata metadata = parser.apply(server); assertEquals(metadata.getLocation(), location); diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseCredentialsFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseCredentialsFromJsonResponseTest.java index fb4be4b20a..275c394603 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseCredentialsFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseCredentialsFromJsonResponseTest.java @@ -33,6 +33,7 @@ import org.jclouds.gogrid.config.DateSecondsAdapter; import org.jclouds.gogrid.domain.IpState; import org.jclouds.gogrid.domain.ServerImageState; import org.jclouds.gogrid.domain.ServerImageType; +import org.jclouds.gogrid.domain.ServerState; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; @@ -52,27 +53,21 @@ public class ParseCredentialsFromJsonResponseTest { @Test(expectedExceptions = IllegalStateException.class) public void testFailWhenTooManyPasswords() throws UnknownHostException { - InputStream is = getClass().getResourceAsStream( - "/test_credentials_list.json"); + InputStream is = getClass().getResourceAsStream("/test_credentials_list.json"); - HttpResponse response = new HttpResponse(200, "ok", Payloads - .newInputStreamPayload(is)); + HttpResponse response = new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)); - ParseCredentialsFromJsonResponse parser = i - .getInstance(ParseCredentialsFromJsonResponse.class); + ParseCredentialsFromJsonResponse parser = i.getInstance(ParseCredentialsFromJsonResponse.class); parser.apply(response); } @Test public void testValid() throws UnknownHostException { - InputStream is = getClass().getResourceAsStream( - "/test_credential.json"); + InputStream is = getClass().getResourceAsStream("/test_credential.json"); - HttpResponse response = new HttpResponse(200, "ok", Payloads - .newInputStreamPayload(is)); + HttpResponse response = new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)); - ParseCredentialsFromJsonResponse parser = i - .getInstance(ParseCredentialsFromJsonResponse.class); + ParseCredentialsFromJsonResponse parser = i.getInstance(ParseCredentialsFromJsonResponse.class); Credentials creds = parser.apply(response); assertEquals(creds.identity, "root"); assertEquals(creds.credential, "dig44sos"); @@ -93,12 +88,9 @@ public class ParseCredentialsFromJsonResponseTest { public Map provideCustomAdapterBindings() { Map bindings = Maps.newHashMap(); bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); - bindings.put(ServerImageType.class, - new CustomDeserializers.ServerImageTypeAdapter()); - bindings.put(ServerImageState.class, - new CustomDeserializers.ServerImageStateAdapter()); - bindings.put(ServerImageState.class, - new CustomDeserializers.ServerImageStateAdapter()); + bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter()); + bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); + bindings.put(ServerState.class, new CustomDeserializers.ServerStateAdapter()); return bindings; } }); diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java index a44080af46..2e79c5bc4a 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServerNameToCredentialsMapFromJsonResponseTest.java @@ -33,6 +33,7 @@ import org.jclouds.gogrid.config.DateSecondsAdapter; import org.jclouds.gogrid.domain.IpState; import org.jclouds.gogrid.domain.ServerImageState; import org.jclouds.gogrid.domain.ServerImageType; +import org.jclouds.gogrid.domain.ServerState; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; @@ -77,7 +78,7 @@ public class ParseServerNameToCredentialsMapFromJsonResponseTest { bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter()); bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter()); bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); - bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter()); + bindings.put(ServerState.class, new CustomDeserializers.ServerStateAdapter()); return bindings; } }); diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java index 8d127cceaa..780fae4aa4 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseServersFromJsonResponseTest.java @@ -44,6 +44,7 @@ import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.ServerImage; import org.jclouds.gogrid.domain.ServerImageState; import org.jclouds.gogrid.domain.ServerImageType; +import org.jclouds.gogrid.domain.ServerState; import org.jclouds.gogrid.functions.internal.CustomDeserializers; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payloads; @@ -76,10 +77,9 @@ public class ParseServersFromJsonResponseTest { Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)"); Option webServer = new Option(1L, "Web Server", "Web or Application Server"); Server server = new Server(75245L, dc, false, "PowerServer", "server to test the api. created by Alex", - new Option(1L, "On", "Server is in active state."), webServer, new Option(1L, "512MB", - "Server with 512MB RAM"), centOs, new Ip(1313079L, "204.51.240.178", - "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc), new ServerImage(1946L, - "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "BitNami Gallery 2.3.1-0", + ServerState.ON, webServer, new Option(1L, "512MB", "Server with 512MB RAM"), centOs, new Ip(1313079L, + "204.51.240.178", "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc), new ServerImage( + 1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery", centOs, null, ServerImageType.WEB_APPLICATION_SERVER, ServerImageState.AVAILABLE, 0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true, new Date(1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of(new BillingToken(38L, diff --git a/ibmdev/src/main/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModule.java b/ibmdev/src/main/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModule.java index b3091269c6..662f630fe3 100644 --- a/ibmdev/src/main/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModule.java +++ b/ibmdev/src/main/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModule.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; import javax.annotation.Resource; import javax.inject.Inject; @@ -74,13 +75,13 @@ import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.util.Utils; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import java.util.concurrent.Future; import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.Scopes; @@ -216,21 +217,26 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule } } + @VisibleForTesting + static final Map instanceStatusToNodeState = ImmutableMap + . builder().put(Instance.Status.ACTIVE, NodeState.RUNNING)// + .put(Instance.Status.STOPPED, NodeState.SUSPENDED)// + .put(Instance.Status.REMOVED, NodeState.TERMINATED)// + .put(Instance.Status.DEPROVISIONING, NodeState.PENDING)// + .put(Instance.Status.FAILED, NodeState.ERROR)// + .put(Instance.Status.NEW, NodeState.PENDING)// + .put(Instance.Status.PROVISIONING, NodeState.PENDING)// + .put(Instance.Status.REJECTED, NodeState.ERROR)// + .put(Instance.Status.RESTARTING, NodeState.PENDING)// + .put(Instance.Status.STARTING, NodeState.PENDING)// + .put(Instance.Status.STOPPING, NodeState.PENDING)// + .put(Instance.Status.DEPROVISION_PENDING, NodeState.PENDING)// + .put(Instance.Status.UNKNOWN, NodeState.UNKNOWN).build(); + @Singleton @Provides Map provideServerToNodeState() { - return ImmutableMap. builder().put(Instance.Status.ACTIVE, NodeState.RUNNING)// - .put(Instance.Status.STOPPED, NodeState.SUSPENDED)// - .put(Instance.Status.REMOVED, NodeState.TERMINATED)// - .put(Instance.Status.DEPROVISIONING, NodeState.PENDING)// - .put(Instance.Status.FAILED, NodeState.ERROR)// - .put(Instance.Status.NEW, NodeState.PENDING)// - .put(Instance.Status.PROVISIONING, NodeState.PENDING)// - .put(Instance.Status.REJECTED, NodeState.ERROR)// - .put(Instance.Status.RESTARTING, NodeState.PENDING)// - .put(Instance.Status.STARTING, NodeState.PENDING)// - .put(Instance.Status.STOPPING, NodeState.PENDING)// - .put(Instance.Status.UNKNOWN, NodeState.UNKNOWN).build(); + return instanceStatusToNodeState; } @Singleton diff --git a/ibmdev/src/test/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModuleTest.java b/ibmdev/src/test/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModuleTest.java new file mode 100644 index 0000000000..4b76940fd2 --- /dev/null +++ b/ibmdev/src/test/java/org/jclouds/ibmdev/compute/config/IBMDeveloperCloudComputeServiceContextModuleTest.java @@ -0,0 +1,37 @@ +/** + * + * Copyright (C) 2009 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.ibmdev.compute.config; + +import org.jclouds.ibmdev.domain.Instance; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "ibmdev.IBMDeveloperCloudComputeServiceContextModuleTest") +public class IBMDeveloperCloudComputeServiceContextModuleTest { + + public void testAllStatusCovered() { + + for (Instance.Status state : Instance.Status.values()) { + assert IBMDeveloperCloudComputeServiceContextModule.instanceStatusToNodeState.containsKey(state) : state; + } + + } +} diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index 82fa795206..2c67ab1b67 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -77,6 +77,7 @@ import org.jclouds.rackspace.config.RackspaceLocationsModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; @@ -238,32 +239,36 @@ public class CloudServersComputeServiceContextModule extends AbstractModule { } } + @VisibleForTesting + static final Map serverToNodeState = ImmutableMap. builder().put( + ServerStatus.ACTIVE, NodeState.RUNNING)// + .put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)// + .put(ServerStatus.DELETED, NodeState.TERMINATED)// + .put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)// + .put(ServerStatus.PREP_RESIZE, NodeState.PENDING)// + .put(ServerStatus.RESIZE, NodeState.PENDING)// + .put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)// + .put(ServerStatus.QUEUE_MOVE, NodeState.PENDING)// + .put(ServerStatus.PREP_MOVE, NodeState.PENDING)// + .put(ServerStatus.MOVE, NodeState.PENDING)// + .put(ServerStatus.VERIFY_MOVE, NodeState.PENDING)// + .put(ServerStatus.RESCUE, NodeState.PENDING)// + .put(ServerStatus.ERROR, NodeState.ERROR)// + .put(ServerStatus.BUILD, NodeState.PENDING)// + .put(ServerStatus.RESTORING, NodeState.PENDING)// + .put(ServerStatus.PASSWORD, NodeState.PENDING)// + .put(ServerStatus.REBUILD, NodeState.PENDING)// + .put(ServerStatus.DELETE_IP, NodeState.PENDING)// + .put(ServerStatus.SHARE_IP_NO_CONFIG, NodeState.PENDING)// + .put(ServerStatus.SHARE_IP, NodeState.PENDING)// + .put(ServerStatus.REBOOT, NodeState.PENDING)// + .put(ServerStatus.HARD_REBOOT, NodeState.PENDING)// + .put(ServerStatus.UNKNOWN, NodeState.UNKNOWN).build(); + @Singleton @Provides Map provideServerToNodeState() { - return ImmutableMap. builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)// - .put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)// - .put(ServerStatus.DELETED, NodeState.TERMINATED)// - .put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)// - .put(ServerStatus.PREP_RESIZE, NodeState.PENDING)// - .put(ServerStatus.RESIZE, NodeState.PENDING)// - .put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)// - .put(ServerStatus.QUEUE_MOVE, NodeState.PENDING)// - .put(ServerStatus.PREP_MOVE, NodeState.PENDING)// - .put(ServerStatus.MOVE, NodeState.PENDING)// - .put(ServerStatus.VERIFY_MOVE, NodeState.PENDING)// - .put(ServerStatus.RESCUE, NodeState.PENDING)// - .put(ServerStatus.ERROR, NodeState.ERROR)// - .put(ServerStatus.BUILD, NodeState.PENDING)// - .put(ServerStatus.RESTORING, NodeState.PENDING)// - .put(ServerStatus.PASSWORD, NodeState.PENDING)// - .put(ServerStatus.REBUILD, NodeState.PENDING)// - .put(ServerStatus.DELETE_IP, NodeState.PENDING)// - .put(ServerStatus.SHARE_IP_NO_CONFIG, NodeState.PENDING)// - .put(ServerStatus.SHARE_IP, NodeState.PENDING)// - .put(ServerStatus.REBOOT, NodeState.PENDING)// - .put(ServerStatus.HARD_REBOOT, NodeState.PENDING)// - .put(ServerStatus.UNKNOWN, NodeState.UNKNOWN).build(); + return serverToNodeState; } @Provides diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModuleTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModuleTest.java new file mode 100644 index 0000000000..763e101c54 --- /dev/null +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModuleTest.java @@ -0,0 +1,38 @@ +/** + * + * 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.rackspace.cloudservers.compute.config; + +import org.jclouds.rackspace.cloudservers.domain.ServerStatus; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "cloudservers.CloudServersComputeServiceContextModuleTest") +public class CloudServersComputeServiceContextModuleTest { + + public void testAllStatusCovered() { + + for (ServerStatus state : ServerStatus.values()) { + assert CloudServersComputeServiceContextModule.serverToNodeState.containsKey(state) : state; + } + + } +} diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java index 17e4ee51d0..cdc1f42c46 100755 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java @@ -76,6 +76,7 @@ import org.jclouds.rimuhosting.miro.domain.PricingPlan; import org.jclouds.rimuhosting.miro.domain.Server; import org.jclouds.rimuhosting.miro.domain.internal.RunningState; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; @@ -104,10 +105,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { }).to(ServerToNodeMetadata.class); bind(LoadBalancerService.class).toProvider(Providers. of(null)); bind(new TypeLiteral() { - }) - .to( - new TypeLiteral>() { - }).in(Scopes.SINGLETON); + }).to(new TypeLiteral>() { + }).in(Scopes.SINGLETON); bind(new TypeLiteral>() { }).to(new TypeLiteral>() { }).in(Scopes.SINGLETON); @@ -123,8 +122,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { @Provides @Named("DEFAULT") protected TemplateBuilder provideTemplate(TemplateBuilder template) { - return template.sizeId("MIRO1B").osFamily(UBUNTU).architecture(Architecture.X86_32) - .imageNameMatches(".*10\\.?04.*"); + return template.sizeId("MIRO1B").osFamily(UBUNTU).architecture(Architecture.X86_32).imageNameMatches( + ".*10\\.?04.*"); } @Provides @@ -140,8 +139,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { private final GetNodeMetadataStrategy getNode; @Inject - protected RimuHostingRebootNodeStrategy(RimuHostingClient client, - GetNodeMetadataStrategy getNode) { + protected RimuHostingRebootNodeStrategy(RimuHostingClient client, GetNodeMetadataStrategy getNode) { this.client = client; this.getNode = getNode; } @@ -162,8 +160,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { private final GetNodeMetadataStrategy getNode; @Inject - protected RimuHostingDestroyNodeStrategy(RimuHostingClient client, - GetNodeMetadataStrategy getNode) { + protected RimuHostingDestroyNodeStrategy(RimuHostingClient client, GetNodeMetadataStrategy getNode) { this.client = client; this.getNode = getNode; } @@ -185,8 +182,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { @Inject protected RimuHostingAddNodeWithTagStrategy(RimuHostingClient client, - Function> getPublicAddresses, - Map runningStateToNodeState) { + Function> getPublicAddresses, Map runningStateToNodeState) { this.client = client; this.getPublicAddresses = getPublicAddresses; this.runningStateToNodeState = runningStateToNodeState; @@ -194,16 +190,14 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { @Override public NodeMetadata execute(String tag, String name, Template template) { - NewServerResponse serverResponse = client.createServer(name, checkNotNull(template - .getImage().getProviderId(), "imageId"), checkNotNull(template.getSize() - .getProviderId(), "sizeId")); + NewServerResponse serverResponse = client.createServer(name, checkNotNull(template.getImage().getProviderId(), + "imageId"), checkNotNull(template.getSize().getProviderId(), "sizeId")); Server server = client.getServer(serverResponse.getServer().getId()); - NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId() - .toString(), template.getLocation(), null, ImmutableMap. of(), - tag, template.getImage(), runningStateToNodeState.get(server.getState()), - getPublicAddresses.apply(server), ImmutableList. of(), ImmutableMap - . of(), new Credentials("root", serverResponse - .getNewInstanceRequest().getCreateOptions().getPassword())); + NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template + .getLocation(), null, ImmutableMap. of(), tag, template.getImage(), + runningStateToNodeState.get(server.getState()), getPublicAddresses.apply(server), ImmutableList + . of(), ImmutableMap. of(), new Credentials("root", serverResponse + .getNewInstanceRequest().getCreateOptions().getPassword())); return node; } @@ -216,7 +210,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { @Inject protected RimuHostingListNodesStrategy(RimuHostingClient client, - Function serverToNodeMetadata) { + Function serverToNodeMetadata) { this.client = client; this.serverToNodeMetadata = serverToNodeMetadata; } @@ -227,10 +221,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { } @Override - public Iterable listDetailsOnNodesMatching( - Predicate filter) { - return Iterables.filter(Iterables.transform(client.getServerList(), serverToNodeMetadata), - filter); + public Iterable listDetailsOnNodesMatching(Predicate filter) { + return Iterables.filter(Iterables.transform(client.getServerList(), serverToNodeMetadata), filter); } } @@ -243,7 +235,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { @Inject protected RimuHostingGetNodeMetadataStrategy(RimuHostingClient client, - Function serverToNodeMetadata) { + Function serverToNodeMetadata) { this.client = client; this.serverToNodeMetadata = serverToNodeMetadata; } @@ -256,15 +248,18 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { } } + @VisibleForTesting + static final Map runningStateToNodeState = ImmutableMap. builder() + .put(RunningState.RUNNING, NodeState.RUNNING)// + .put(RunningState.NOTRUNNING, NodeState.SUSPENDED)// + .put(RunningState.POWERCYCLING, NodeState.PENDING)// + .put(RunningState.RESTARTING, NodeState.PENDING)// + .build(); + @Singleton @Provides Map provideServerToNodeState() { - return ImmutableMap. builder().put(RunningState.RUNNING, - NodeState.RUNNING)// - .put(RunningState.NOTRUNNING, NodeState.SUSPENDED)// - .put(RunningState.POWERCYCLING, NodeState.PENDING)// - .put(RunningState.RESTARTING, NodeState.PENDING)// - .build(); + return runningStateToNodeState; } @Singleton @@ -290,19 +285,18 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { @Override public boolean apply(Image input) { return input.getProviderId().equals(instance.getImageId()) - && (input.getLocation() == null || input.getLocation().equals(location) || input - .getLocation().equals(location.getParent())); + && (input.getLocation() == null || input.getLocation().equals(location) || input.getLocation() + .equals(location.getParent())); } } @SuppressWarnings("unused") @Inject ServerToNodeMetadata(Function> getPublicAddresses, - Map runningStateToNodeState, Set images, - Set locations) { + Map runningStateToNodeState, Set images, + Set locations) { this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState"); - this.runningStateToNodeState = checkNotNull(runningStateToNodeState, - "serverStateToNodeState"); + this.runningStateToNodeState = checkNotNull(runningStateToNodeState, "serverStateToNodeState"); this.images = checkNotNull(images, "images"); this.locations = checkNotNull(locations, "locations"); } @@ -310,8 +304,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { @Override public NodeMetadata apply(Server from) { - Location location = new LocationImpl(LocationScope.ZONE, from.getLocation().getId(), from - .getLocation().getName(), null); + Location location = new LocationImpl(LocationScope.ZONE, from.getLocation().getId(), from.getLocation() + .getName(), null); String tag = from.getName().replaceAll("-[0-9]+", ""); Credentials creds = null; @@ -319,14 +313,12 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { try { image = Iterables.find(images, new FindImageForServer(location, from)); } catch (NoSuchElementException e) { - logger.warn("could not find a matching image for server %s in location %s", from, - location); + logger.warn("could not find a matching image for server %s in location %s", from, location); } NodeState state = runningStateToNodeState.get(from.getState()); - return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", - location, null, ImmutableMap. of(), tag, image, state, - getPublicAddresses.apply(from), ImmutableList. of(), ImmutableMap - . of(), creds); + return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap + . of(), tag, image, state, getPublicAddresses.apply(from), ImmutableList. of(), + ImmutableMap. of(), creds); } } @@ -335,16 +327,15 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { private static class ServerToPublicAddresses implements Function> { @Override public Iterable apply(Server server) { - return server.getIpAddresses() == null ? ImmutableSet. of() : Iterables.concat( - ImmutableList.of(server.getIpAddresses().getPrimaryIp()), server.getIpAddresses() - .getSecondaryIps()); + return server.getIpAddresses() == null ? ImmutableSet. of() : Iterables.concat(ImmutableList.of(server + .getIpAddresses().getPrimaryIp()), server.getIpAddresses().getSecondaryIps()); } } @Provides @Singleton Location getDefaultLocation(@Named(PROPERTY_RIMUHOSTING_DEFAULT_DC) final String defaultDC, - Set locations) { + Set locations) { return Iterables.find(locations, new Predicate() { @Override @@ -358,14 +349,14 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { @Provides @Singleton Set getDefaultLocations(RimuHostingClient sync, LogHolder holder, - Function indexer, @Provider String providerName) { + Function indexer, @Provider String providerName) { final Set locations = Sets.newHashSet(); holder.logger.debug(">> providing locations"); Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); for (final PricingPlan from : sync.getPricingPlanList()) { try { - locations.add(new LocationImpl(LocationScope.ZONE, from.getDataCenter().getId(), from - .getDataCenter().getName(), provider)); + locations.add(new LocationImpl(LocationScope.ZONE, from.getDataCenter().getId(), from.getDataCenter() + .getName(), provider)); } catch (NullPointerException e) { holder.logger.warn("datacenter not present in " + from.getId()); } @@ -388,10 +379,9 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { @Provides @Singleton protected Set provideSizes(RimuHostingClient sync, Set images, - Set locations, LogHolder holder, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, - Function indexer) throws InterruptedException, - TimeoutException, ExecutionException { + Set locations, LogHolder holder, + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, Function indexer) + throws InterruptedException, TimeoutException, ExecutionException { final Set sizes = Sets.newHashSet(); holder.logger.debug(">> providing sizes"); for (final PricingPlan from : sync.getPricingPlanList()) { @@ -405,9 +395,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { } }); - sizes.add(new SizeImpl(from.getId(), from.getId(), from.getId(), location, null, - ImmutableMap. of(), 1, from.getRam(), from.getDiskSize(), - ImagePredicates.any())); + sizes.add(new SizeImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap + . of(), 1, from.getRam(), from.getDiskSize(), ImagePredicates.any())); } catch (NullPointerException e) { holder.logger.warn("datacenter not present in " + from.getId()); } @@ -427,14 +416,12 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { @Provides @Singleton protected Set provideImages(final RimuHostingClient sync, LogHolder holder, - Function indexer) throws InterruptedException, - ExecutionException, TimeoutException { + Function indexer) throws InterruptedException, ExecutionException, TimeoutException { final Set images = Sets.newHashSet(); holder.logger.debug(">> providing images"); for (final org.jclouds.rimuhosting.miro.domain.Image from : sync.getImageList()) { OsFamily os = null; - Architecture arch = from.getId().indexOf("64") == -1 ? Architecture.X86_32 - : Architecture.X86_64; + Architecture arch = from.getId().indexOf("64") == -1 ? Architecture.X86_32 : Architecture.X86_64; String osDescription = ""; String version = ""; @@ -449,9 +436,9 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule { } } - images.add(new ImageImpl(from.getId(), from.getDescription(), from.getId(), null, null, - ImmutableMap. of(), from.getDescription(), version, os, - osDescription, arch, new Credentials("root", null))); + images.add(new ImageImpl(from.getId(), from.getDescription(), from.getId(), null, null, ImmutableMap + . of(), from.getDescription(), version, os, osDescription, arch, new Credentials("root", + null))); } holder.logger.debug("<< images(%d)", images.size()); return images; diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModuleTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModuleTest.java new file mode 100644 index 0000000000..eb76cdeff2 --- /dev/null +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModuleTest.java @@ -0,0 +1,37 @@ +/** + * + * 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.rimuhosting.miro.compute.config; + +import org.jclouds.rimuhosting.miro.domain.internal.RunningState; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "rimuhosting.RimuHostingComputeServiceContextModuleTest") +public class RimuHostingComputeServiceContextModuleTest { + + public void testAllStatusCovered() { + + for (RunningState state : RunningState.values()) { + assert RimuHostingComputeServiceContextModule.runningStateToNodeState.containsKey(state) : state; + } + + } +} diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java index cb8b259576..421ba90906 100644 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java +++ b/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java @@ -74,6 +74,7 @@ import org.jclouds.slicehost.compute.functions.SliceToNodeMetadata; import org.jclouds.slicehost.domain.Flavor; import org.jclouds.slicehost.domain.Slice; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; @@ -244,15 +245,19 @@ public class SlicehostComputeServiceContextModule extends AbstractModule { } } + @VisibleForTesting + static final Map sliceStatusToNodeState = ImmutableMap. builder() + .put(Slice.Status.ACTIVE, NodeState.RUNNING)// + .put(Slice.Status.BUILD, NodeState.PENDING)// + .put(Slice.Status.REBOOT, NodeState.PENDING)// + .put(Slice.Status.HARD_REBOOT, NodeState.PENDING)// + .put(Slice.Status.TERMINATED, NodeState.TERMINATED)// + .build(); + @Singleton @Provides Map provideSliceToNodeState() { - return ImmutableMap. builder().put(Slice.Status.ACTIVE, NodeState.RUNNING)// - .put(Slice.Status.BUILD, NodeState.PENDING)// - .put(Slice.Status.REBOOT, NodeState.PENDING)// - .put(Slice.Status.HARD_REBOOT, NodeState.PENDING)// - .put(Slice.Status.TERMINATED, NodeState.TERMINATED)// - .build(); + return sliceStatusToNodeState; } @Provides diff --git a/slicehost/src/test/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModuleTest.java b/slicehost/src/test/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModuleTest.java new file mode 100644 index 0000000000..8870b8dad1 --- /dev/null +++ b/slicehost/src/test/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModuleTest.java @@ -0,0 +1,37 @@ +/** + * + * 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.slicehost.compute.config; + +import org.jclouds.slicehost.domain.Slice; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "slicehost.SlicehostComputeServiceContextModuleTest") +public class SlicehostComputeServiceContextModuleTest { + + public void testAllStatusCovered() { + + for (Slice.Status state : Slice.Status.values()) { + assert SlicehostComputeServiceContextModule.sliceStatusToNodeState.containsKey(state) : state; + } + + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index 53dade856b..2df61fb2ee 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -58,6 +58,7 @@ import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy; import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy; import org.jclouds.vcloud.domain.VAppStatus; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; @@ -76,12 +77,16 @@ import com.google.inject.util.Providers; */ public class VCloudComputeServiceContextModule extends AbstractModule { + @VisibleForTesting + static final Map vAppStatusToNodeState = ImmutableMap. builder().put( + VAppStatus.OFF, NodeState.SUSPENDED).put(VAppStatus.ON, NodeState.RUNNING).put(VAppStatus.RESOLVED, + NodeState.PENDING).put(VAppStatus.SUSPENDED, NodeState.SUSPENDED) + .put(VAppStatus.UNRESOLVED, NodeState.PENDING).build(); + @Singleton @Provides Map provideVAppStatusToNodeState() { - return ImmutableMap. builder().put(VAppStatus.OFF, NodeState.SUSPENDED).put(VAppStatus.ON, - NodeState.RUNNING).put(VAppStatus.RESOLVED, NodeState.PENDING).put(VAppStatus.SUSPENDED, - NodeState.SUSPENDED).put(VAppStatus.UNRESOLVED, NodeState.PENDING).build(); + return vAppStatusToNodeState; } @Provides diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModuleTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModuleTest.java new file mode 100644 index 0000000000..0d08146cb9 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModuleTest.java @@ -0,0 +1,37 @@ +/** + * + * 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.vcloud.compute.config; + +import org.jclouds.vcloud.domain.VAppStatus; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.VCloudComputeServiceContextModuleTest") +public class VCloudComputeServiceContextModuleTest { + + public void testAllStatusCovered() { + + for (VAppStatus state : VAppStatus.values()) { + assert VCloudComputeServiceContextModule.vAppStatusToNodeState.containsKey(state) : state; + } + + } +}