mirror of https://github.com/apache/jclouds.git
Issue 331: fix bug where not all state mappings are handled
This commit is contained in:
parent
5aeba30d5c
commit
dec277e4d5
|
@ -77,8 +77,8 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
@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()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,10 +113,11 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
}
|
||||
}
|
||||
|
||||
private static final Map<InstanceState, NodeState> instanceToNodeState = ImmutableMap
|
||||
.<InstanceState, NodeState> 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<InstanceState, NodeState> instanceToNodeState = ImmutableMap.<InstanceState, NodeState> 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<RegionAndName, KeyPair> credentialsMap;
|
||||
|
@ -129,7 +130,8 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
@Inject
|
||||
RunningInstanceToNodeMetadata(EC2Client client, Map<RegionAndName, KeyPair> credentialsMap,
|
||||
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
|
||||
Provider<Set<? extends Image>> images, // to facilitate on-demand refresh of image list
|
||||
Provider<Set<? extends Image>> images, // to facilitate on-demand
|
||||
// refresh of image list
|
||||
ConcurrentMap<RegionAndName, Image> imageMap, Set<? extends Location> locations,
|
||||
@Named("volumeMapping") Function<RunningInstance, Map<String, String>> instanceToStorageMapping) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
|
@ -193,7 +195,8 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
} catch (NoSuchElementException e) {
|
||||
logger.debug("no tag parsed from %s's groups: %s", instance.getId(), instance.getGroupIds());
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.debug("too many groups match %s; %s's groups: %s", "jclouds#", instance.getId(), instance.getGroupIds());
|
||||
logger
|
||||
.debug("too many groups match %s; %s's groups: %s", "jclouds#", instance.getId(), instance.getGroupIds());
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,15 @@ import com.google.common.collect.ImmutableSet;
|
|||
*/
|
||||
@Test(groups = "unit", testName = "ec2.RunningInstanceToNodeMetadataTest")
|
||||
public class RunningInstanceToNodeMetadataTest {
|
||||
|
||||
public void testAllStatesCovered() {
|
||||
|
||||
for (InstanceState state : InstanceState.values()) {
|
||||
assert RunningInstanceToNodeMetadata.instanceToNodeState.containsKey(state) : state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class ImageProvider implements Provider<Set<? extends org.jclouds.compute.domain.Image>> {
|
||||
private final Set<? extends org.jclouds.compute.domain.Image> images;
|
||||
|
||||
|
|
|
@ -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<Server>(
|
||||
new ServerLatestJobCompleted(client.getJobServices()),
|
||||
timeouts.nodeRunning * 9l / 10l);
|
||||
this.serverLatestJobCompletedShort = new RetryablePredicate<Server>(
|
||||
new ServerLatestJobCompleted(client.getJobServices()),
|
||||
timeouts.nodeRunning * 1l / 10l);
|
||||
this.serverLatestJobCompleted = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client
|
||||
.getJobServices()), timeouts.nodeRunning * 9l / 10l);
|
||||
this.serverLatestJobCompletedShort = new RetryablePredicate<Server>(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<Server, NodeMetadata> serverToNodeMetadata;
|
||||
|
||||
@Inject
|
||||
protected GoGridListNodesStrategy(GoGridClient client,
|
||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||
protected GoGridListNodesStrategy(GoGridClient client, Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||
this.client = client;
|
||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
||||
}
|
||||
|
@ -191,10 +189,9 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(
|
||||
Predicate<ComputeMetadata> filter) {
|
||||
return Iterables.filter(Iterables.transform(client.getServerServices().getServerList(),
|
||||
serverToNodeMetadata), filter);
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||
return Iterables.filter(Iterables.transform(client.getServerServices().getServerList(), serverToNodeMetadata),
|
||||
filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,8 +201,7 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
|||
private final Function<Server, NodeMetadata> serverToNodeMetadata;
|
||||
|
||||
@Inject
|
||||
protected GoGridGetNodeMetadataStrategy(GoGridClient client,
|
||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||
protected GoGridGetNodeMetadataStrategy(GoGridClient client, Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||
this.client = client;
|
||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
||||
}
|
||||
|
@ -241,21 +237,31 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static final Map<ServerState, NodeState> serverStateToNodeState = ImmutableMap.<ServerState, NodeState> 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<String, NodeState> provideServerToNodeState() {
|
||||
return ImmutableMap.<String, NodeState> 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<ServerState, NodeState> 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
|
||||
*/
|
||||
|
@ -294,14 +300,13 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
Set<? extends Location> getAssignableLocations(@Provider String providerName, GoGridClient sync,
|
||||
LogHolder holder, Function<ComputeMetadata, String> indexer) {
|
||||
Set<? extends Location> getAssignableLocations(@Provider String providerName, GoGridClient sync, LogHolder holder,
|
||||
Function<ComputeMetadata, String> indexer) {
|
||||
final Set<Location> 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<? extends Size> provideSizes(GoGridClient sync, Set<? extends Image> images,
|
||||
LogHolder holder, Function<ComputeMetadata, String> indexer)
|
||||
throws InterruptedException, TimeoutException, ExecutionException {
|
||||
protected Set<? extends Size> provideSizes(GoGridClient sync, Set<? extends Image> images, LogHolder holder,
|
||||
Function<ComputeMetadata, String> indexer) throws InterruptedException, TimeoutException, ExecutionException {
|
||||
final Set<Size> sizes = Sets.newHashSet();
|
||||
holder.logger.debug(">> providing sizes");
|
||||
|
||||
sizes.add(new SizeImpl("1", "1", "1", null, null, ImmutableMap.<String, String> of(), 0.5,
|
||||
512, 30, architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32,
|
||||
Architecture.X86_64))));
|
||||
sizes.add(new SizeImpl("2", "2", "2", null, null, ImmutableMap.<String, String> of(), 1,
|
||||
1024, 60, architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32,
|
||||
Architecture.X86_64))));
|
||||
sizes.add(new SizeImpl("3", "3", "3", null, null, ImmutableMap.<String, String> of(), 2,
|
||||
2048, 120, architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32,
|
||||
Architecture.X86_64))));
|
||||
sizes.add(new SizeImpl("4", "4", "4", null, null, ImmutableMap.<String, String> of(), 4,
|
||||
4096, 240, architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32,
|
||||
Architecture.X86_64))));
|
||||
sizes.add(new SizeImpl("5", "5", "5", null, null, ImmutableMap.<String, String> of(), 8,
|
||||
8192, 480, architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32,
|
||||
Architecture.X86_64))));
|
||||
sizes.add(new SizeImpl("1", "1", "1", null, null, ImmutableMap.<String, String> of(), 0.5, 512, 30,
|
||||
architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))));
|
||||
sizes.add(new SizeImpl("2", "2", "2", null, null, ImmutableMap.<String, String> of(), 1, 1024, 60,
|
||||
architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))));
|
||||
sizes.add(new SizeImpl("3", "3", "3", null, null, ImmutableMap.<String, String> of(), 2, 2048, 120,
|
||||
architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))));
|
||||
sizes.add(new SizeImpl("4", "4", "4", null, null, ImmutableMap.<String, String> of(), 4, 4096, 240,
|
||||
architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))));
|
||||
sizes.add(new SizeImpl("5", "5", "5", null, null, ImmutableMap.<String, String> of(), 8, 8192, 480,
|
||||
architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))));
|
||||
holder.logger.debug("<< sizes(%d)", sizes.size());
|
||||
return sizes;
|
||||
}
|
||||
|
@ -356,31 +355,31 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Set<? extends Image> provideImages(final GoGridClient sync, LogHolder holder,
|
||||
Function<ComputeMetadata, String> indexer, Location location,
|
||||
PopulateDefaultLoginCredentialsForImageStrategy authenticator)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
PopulateDefaultLoginCredentialsForImageStrategy authenticator) throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
final Set<Image> images = Sets.newHashSet();
|
||||
holder.logger.debug(">> providing images");
|
||||
Set<ServerImage> 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.<String, String> of(), from.getDescription(),
|
||||
version, os, osDescription, arch, defaultCredentials));
|
||||
images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), from.getId() + "", location, null,
|
||||
ImmutableMap.<String, String> of(), from.getDescription(), version, os, osDescription, arch,
|
||||
defaultCredentials));
|
||||
}
|
||||
holder.logger.debug("<< images(%d)", images.size());
|
||||
return images;
|
||||
|
|
|
@ -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<Server, NodeMetadata> {
|
|||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private final Map<String, NodeState> serverStateToNodeState;
|
||||
private final Map<ServerState, NodeState> serverStateToNodeState;
|
||||
private final GoGridClient client;
|
||||
private final Set<? extends Image> images;
|
||||
private final Map<String, ? extends Location> locations;
|
||||
|
@ -78,7 +79,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
|||
}
|
||||
|
||||
@Inject
|
||||
ServerToNodeMetadata(Map<String, NodeState> serverStateToNodeState, GoGridClient client,
|
||||
ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState, GoGridClient client,
|
||||
Set<? extends Image> images, Map<String, ? extends Location> locations) {
|
||||
this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
||||
this.client = checkNotNull(client, "client");
|
||||
|
@ -91,7 +92,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
|||
Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName());
|
||||
final String tag = matcher.find() ? matcher.group(1) : null;
|
||||
Set<String> 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<Server, NodeMetadata> {
|
|||
} 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.<String, String> of(),
|
||||
tag, image, state, ipSet, ImmutableList.<String> of(), ImmutableMap
|
||||
.<String, String> of(), creds);
|
||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get(from
|
||||
.getDatacenter().getId()
|
||||
+ ""), null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList.<String> of(),
|
||||
ImmutableMap.<String, String> of(), creds);
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
|
|
|
@ -23,18 +23,18 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.domain;
|
||||
|
||||
|
||||
import com.google.common.primitives.Longs;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class Server implements Comparable<Server> {
|
||||
|
||||
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<Server> {
|
|||
/**
|
||||
* 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<Server> {
|
|||
return description;
|
||||
}
|
||||
|
||||
public Option getState() {
|
||||
public ServerState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -195,8 +195,8 @@ public class Server implements Comparable<Server> {
|
|||
|
||||
@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 + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* 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")));
|
||||
}
|
||||
}
|
|
@ -18,19 +18,43 @@
|
|||
*/
|
||||
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 ServerStateAdapter implements JsonDeserializer<ServerState> {
|
||||
@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 ObjectTypeAdapter implements JsonDeserializer<ObjectType> {
|
||||
@Override
|
||||
public ObjectType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
public ObjectType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return ObjectType.fromValue(name);
|
||||
}
|
||||
|
@ -38,7 +62,8 @@ public class CustomDeserializers {
|
|||
|
||||
public static class LoadBalancerOsAdapter implements JsonDeserializer<LoadBalancerOs> {
|
||||
@Override
|
||||
public LoadBalancerOs deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
public LoadBalancerOs deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return LoadBalancerOs.fromValue(name);
|
||||
}
|
||||
|
@ -46,7 +71,8 @@ public class CustomDeserializers {
|
|||
|
||||
public static class LoadBalancerStateAdapter implements JsonDeserializer<LoadBalancerState> {
|
||||
@Override
|
||||
public LoadBalancerState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
public LoadBalancerState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return LoadBalancerState.fromValue(name);
|
||||
}
|
||||
|
@ -54,7 +80,8 @@ public class CustomDeserializers {
|
|||
|
||||
public static class LoadBalancerPersistenceTypeAdapter implements JsonDeserializer<LoadBalancerPersistenceType> {
|
||||
@Override
|
||||
public LoadBalancerPersistenceType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
public LoadBalancerPersistenceType deserialize(JsonElement jsonElement, Type type,
|
||||
JsonDeserializationContext context) throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return LoadBalancerPersistenceType.fromValue(name);
|
||||
}
|
||||
|
@ -62,7 +89,8 @@ public class CustomDeserializers {
|
|||
|
||||
public static class LoadBalancerTypeAdapter implements JsonDeserializer<LoadBalancerType> {
|
||||
@Override
|
||||
public LoadBalancerType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
public LoadBalancerType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return LoadBalancerType.fromValue(name);
|
||||
}
|
||||
|
@ -70,7 +98,8 @@ public class CustomDeserializers {
|
|||
|
||||
public static class IpStateAdapter implements JsonDeserializer<IpState> {
|
||||
@Override
|
||||
public IpState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
public IpState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return IpState.fromValue(name);
|
||||
}
|
||||
|
@ -78,7 +107,8 @@ public class CustomDeserializers {
|
|||
|
||||
public static class JobStateAdapter implements JsonDeserializer<JobState> {
|
||||
@Override
|
||||
public JobState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
public JobState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return JobState.fromValue(name);
|
||||
}
|
||||
|
@ -86,7 +116,8 @@ public class CustomDeserializers {
|
|||
|
||||
public static class ServerImageStateAdapter implements JsonDeserializer<ServerImageState> {
|
||||
@Override
|
||||
public ServerImageState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
public ServerImageState deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return ServerImageState.fromValue(name);
|
||||
}
|
||||
|
@ -94,7 +125,8 @@ public class CustomDeserializers {
|
|||
|
||||
public static class ServerImageTypeAdapter implements JsonDeserializer<ServerImageType> {
|
||||
@Override
|
||||
public ServerImageType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
|
||||
public ServerImageType deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||
return ServerImageType.fromValue(name);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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<String, NodeState> serverStateToNodeState = createMock(Map.class);
|
||||
Map<ServerState, NodeState> 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<String, ? extends Location> locations = ImmutableMap.<String, Location> 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);
|
||||
|
|
|
@ -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<Type, Object> provideCustomAdapterBindings() {
|
||||
Map<Type, Object> 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;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,10 +217,9 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
|
|||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Map<Instance.Status, NodeState> provideServerToNodeState() {
|
||||
return ImmutableMap.<Instance.Status, NodeState> builder().put(Instance.Status.ACTIVE, NodeState.RUNNING)//
|
||||
@VisibleForTesting
|
||||
static final Map<Instance.Status, NodeState> instanceStatusToNodeState = ImmutableMap
|
||||
.<Instance.Status, NodeState> 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)//
|
||||
|
@ -230,7 +230,13 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
|
|||
.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<Instance.Status, NodeState> provideServerToNodeState() {
|
||||
return instanceStatusToNodeState;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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,10 +239,9 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
|||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Map<ServerStatus, NodeState> provideServerToNodeState() {
|
||||
return ImmutableMap.<ServerStatus, NodeState> builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)//
|
||||
@VisibleForTesting
|
||||
static final Map<ServerStatus, NodeState> serverToNodeState = ImmutableMap.<ServerStatus, NodeState> builder().put(
|
||||
ServerStatus.ACTIVE, NodeState.RUNNING)//
|
||||
.put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)//
|
||||
.put(ServerStatus.DELETED, NodeState.TERMINATED)//
|
||||
.put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)//
|
||||
|
@ -264,6 +264,11 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
|||
.put(ServerStatus.REBOOT, NodeState.PENDING)//
|
||||
.put(ServerStatus.HARD_REBOOT, NodeState.PENDING)//
|
||||
.put(ServerStatus.UNKNOWN, NodeState.UNKNOWN).build();
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Map<ServerStatus, NodeState> provideServerToNodeState() {
|
||||
return serverToNodeState;
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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,9 +105,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
|||
}).to(ServerToNodeMetadata.class);
|
||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||
})
|
||||
.to(
|
||||
new TypeLiteral<ComputeServiceContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
||||
}).to(new TypeLiteral<ComputeServiceContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
||||
}).in(Scopes.SINGLETON);
|
||||
bind(new TypeLiteral<RestContext<RimuHostingClient, RimuHostingAsyncClient>>() {
|
||||
}).to(new TypeLiteral<RestContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
||||
|
@ -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<Server, Iterable<String>> getPublicAddresses,
|
||||
Map<RunningState, NodeState> runningStateToNodeState) {
|
||||
Function<Server, Iterable<String>> getPublicAddresses, Map<RunningState, NodeState> runningStateToNodeState) {
|
||||
this.client = client;
|
||||
this.getPublicAddresses = getPublicAddresses;
|
||||
this.runningStateToNodeState = runningStateToNodeState;
|
||||
|
@ -194,15 +190,13 @@ 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.<String, String> of(),
|
||||
tag, template.getImage(), runningStateToNodeState.get(server.getState()),
|
||||
getPublicAddresses.apply(server), ImmutableList.<String> of(), ImmutableMap
|
||||
.<String, String> of(), new Credentials("root", serverResponse
|
||||
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template
|
||||
.getLocation(), null, ImmutableMap.<String, String> of(), tag, template.getImage(),
|
||||
runningStateToNodeState.get(server.getState()), getPublicAddresses.apply(server), ImmutableList
|
||||
.<String> of(), ImmutableMap.<String, String> of(), new Credentials("root", serverResponse
|
||||
.getNewInstanceRequest().getCreateOptions().getPassword()));
|
||||
return node;
|
||||
}
|
||||
|
@ -227,10 +221,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(
|
||||
Predicate<ComputeMetadata> filter) {
|
||||
return Iterables.filter(Iterables.transform(client.getServerList(), serverToNodeMetadata),
|
||||
filter);
|
||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||
return Iterables.filter(Iterables.transform(client.getServerList(), serverToNodeMetadata), filter);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -256,15 +248,18 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
|||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Map<RunningState, NodeState> provideServerToNodeState() {
|
||||
return ImmutableMap.<RunningState, NodeState> builder().put(RunningState.RUNNING,
|
||||
NodeState.RUNNING)//
|
||||
@VisibleForTesting
|
||||
static final Map<RunningState, NodeState> runningStateToNodeState = ImmutableMap.<RunningState, NodeState> 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<RunningState, NodeState> provideServerToNodeState() {
|
||||
return runningStateToNodeState;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
@ -290,8 +285,8 @@ 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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,8 +296,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
|||
Map<RunningState, NodeState> runningStateToNodeState, Set<? extends Image> images,
|
||||
Set<? extends Location> 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.<String, String> of(), tag, image, state,
|
||||
getPublicAddresses.apply(from), ImmutableList.<String> of(), ImmutableMap
|
||||
.<String, String> of(), creds);
|
||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap
|
||||
.<String, String> of(), tag, image, state, getPublicAddresses.apply(from), ImmutableList.<String> of(),
|
||||
ImmutableMap.<String, String> of(), creds);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -335,9 +327,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
|||
private static class ServerToPublicAddresses implements Function<Server, Iterable<String>> {
|
||||
@Override
|
||||
public Iterable<String> apply(Server server) {
|
||||
return server.getIpAddresses() == null ? ImmutableSet.<String> of() : Iterables.concat(
|
||||
ImmutableList.of(server.getIpAddresses().getPrimaryIp()), server.getIpAddresses()
|
||||
.getSecondaryIps());
|
||||
return server.getIpAddresses() == null ? ImmutableSet.<String> of() : Iterables.concat(ImmutableList.of(server
|
||||
.getIpAddresses().getPrimaryIp()), server.getIpAddresses().getSecondaryIps());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,8 +355,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
|||
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());
|
||||
}
|
||||
|
@ -389,9 +380,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
|||
@Singleton
|
||||
protected Set<? extends Size> provideSizes(RimuHostingClient sync, Set<? extends Image> images,
|
||||
Set<? extends Location> locations, LogHolder holder,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor,
|
||||
Function<ComputeMetadata, String> indexer) throws InterruptedException,
|
||||
TimeoutException, ExecutionException {
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, Function<ComputeMetadata, String> indexer)
|
||||
throws InterruptedException, TimeoutException, ExecutionException {
|
||||
final Set<Size> 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.<String, String> of(), 1, from.getRam(), from.getDiskSize(),
|
||||
ImagePredicates.any()));
|
||||
sizes.add(new SizeImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap
|
||||
.<String, String> 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<? extends Image> provideImages(final RimuHostingClient sync, LogHolder holder,
|
||||
Function<ComputeMetadata, String> indexer) throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
Function<ComputeMetadata, String> indexer) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
final Set<Image> 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.<String, String> of(), from.getDescription(), version, os,
|
||||
osDescription, arch, new Credentials("root", null)));
|
||||
images.add(new ImageImpl(from.getId(), from.getDescription(), from.getId(), null, null, ImmutableMap
|
||||
.<String, String> of(), from.getDescription(), version, os, osDescription, arch, new Credentials("root",
|
||||
null)));
|
||||
}
|
||||
holder.logger.debug("<< images(%d)", images.size());
|
||||
return images;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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 {
|
|||
}
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Map<Slice.Status, NodeState> provideSliceToNodeState() {
|
||||
return ImmutableMap.<Slice.Status, NodeState> builder().put(Slice.Status.ACTIVE, NodeState.RUNNING)//
|
||||
@VisibleForTesting
|
||||
static final Map<Slice.Status, NodeState> sliceStatusToNodeState = ImmutableMap.<Slice.Status, NodeState> 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<Slice.Status, NodeState> provideSliceToNodeState() {
|
||||
return sliceStatusToNodeState;
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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<VAppStatus, NodeState> vAppStatusToNodeState = ImmutableMap.<VAppStatus, NodeState> 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<VAppStatus, NodeState> provideVAppStatusToNodeState() {
|
||||
return ImmutableMap.<VAppStatus, NodeState> 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
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue