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
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
return input.getProviderId().equals(instance.getImageId())
|
return input.getProviderId().equals(instance.getImageId())
|
||||||
&& (input.getLocation() == null || input.getLocation().equals(location) || input.getLocation()
|
&& (input.getLocation() == null || input.getLocation().equals(location) || input.getLocation().equals(
|
||||||
.equals(location.getParent()));
|
location.getParent()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -113,10 +113,11 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<InstanceState, NodeState> instanceToNodeState = ImmutableMap
|
@VisibleForTesting
|
||||||
.<InstanceState, NodeState> builder().put(InstanceState.PENDING, NodeState.PENDING).put(
|
static final Map<InstanceState, NodeState> instanceToNodeState = ImmutableMap.<InstanceState, NodeState> builder()
|
||||||
InstanceState.RUNNING, NodeState.RUNNING).put(InstanceState.SHUTTING_DOWN, NodeState.PENDING).put(
|
.put(InstanceState.PENDING, NodeState.PENDING).put(InstanceState.RUNNING, NodeState.RUNNING).put(
|
||||||
InstanceState.TERMINATED, NodeState.TERMINATED).build();
|
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 EC2Client client;
|
||||||
private final Map<RegionAndName, KeyPair> credentialsMap;
|
private final Map<RegionAndName, KeyPair> credentialsMap;
|
||||||
|
@ -129,7 +130,8 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
||||||
@Inject
|
@Inject
|
||||||
RunningInstanceToNodeMetadata(EC2Client client, Map<RegionAndName, KeyPair> credentialsMap,
|
RunningInstanceToNodeMetadata(EC2Client client, Map<RegionAndName, KeyPair> credentialsMap,
|
||||||
PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
|
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,
|
ConcurrentMap<RegionAndName, Image> imageMap, Set<? extends Location> locations,
|
||||||
@Named("volumeMapping") Function<RunningInstance, Map<String, String>> instanceToStorageMapping) {
|
@Named("volumeMapping") Function<RunningInstance, Map<String, String>> instanceToStorageMapping) {
|
||||||
this.client = checkNotNull(client, "client");
|
this.client = checkNotNull(client, "client");
|
||||||
|
@ -193,7 +195,8 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
logger.debug("no tag parsed from %s's groups: %s", instance.getId(), instance.getGroupIds());
|
logger.debug("no tag parsed from %s's groups: %s", instance.getId(), instance.getGroupIds());
|
||||||
} catch (IllegalArgumentException e) {
|
} 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;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,15 @@ import com.google.common.collect.ImmutableSet;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", testName = "ec2.RunningInstanceToNodeMetadataTest")
|
@Test(groups = "unit", testName = "ec2.RunningInstanceToNodeMetadataTest")
|
||||||
public class 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 static class ImageProvider implements Provider<Set<? extends org.jclouds.compute.domain.Image>> {
|
||||||
private final Set<? extends org.jclouds.compute.domain.Image> images;
|
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.PowerCommand;
|
||||||
import org.jclouds.gogrid.domain.Server;
|
import org.jclouds.gogrid.domain.Server;
|
||||||
import org.jclouds.gogrid.domain.ServerImage;
|
import org.jclouds.gogrid.domain.ServerImage;
|
||||||
|
import org.jclouds.gogrid.domain.ServerState;
|
||||||
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
|
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
|
||||||
import org.jclouds.gogrid.util.GoGridUtils;
|
import org.jclouds.gogrid.util.GoGridUtils;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
@ -78,6 +79,7 @@ import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.annotations.Provider;
|
import org.jclouds.rest.annotations.Provider;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -93,6 +95,7 @@ import com.google.inject.util.Providers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class GoGridComputeServiceContextModule extends AbstractModule {
|
public class GoGridComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
|
@ -149,22 +152,18 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
||||||
private final GetNodeMetadataStrategy getNode;
|
private final GetNodeMetadataStrategy getNode;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected GoGridRebootNodeStrategy(GoGridClient client, GetNodeMetadataStrategy getNode,
|
protected GoGridRebootNodeStrategy(GoGridClient client, GetNodeMetadataStrategy getNode, Timeouts timeouts) {
|
||||||
Timeouts timeouts) {
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.serverLatestJobCompleted = new RetryablePredicate<Server>(
|
this.serverLatestJobCompleted = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client
|
||||||
new ServerLatestJobCompleted(client.getJobServices()),
|
.getJobServices()), timeouts.nodeRunning * 9l / 10l);
|
||||||
timeouts.nodeRunning * 9l / 10l);
|
this.serverLatestJobCompletedShort = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client
|
||||||
this.serverLatestJobCompletedShort = new RetryablePredicate<Server>(
|
.getJobServices()), timeouts.nodeRunning * 1l / 10l);
|
||||||
new ServerLatestJobCompleted(client.getJobServices()),
|
|
||||||
timeouts.nodeRunning * 1l / 10l);
|
|
||||||
this.getNode = getNode;
|
this.getNode = getNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata execute(String id) {
|
public NodeMetadata execute(String id) {
|
||||||
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(
|
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(id)));
|
||||||
new Long(id)));
|
|
||||||
client.getServerServices().power(server.getName(), PowerCommand.RESTART);
|
client.getServerServices().power(server.getName(), PowerCommand.RESTART);
|
||||||
serverLatestJobCompleted.apply(server);
|
serverLatestJobCompleted.apply(server);
|
||||||
client.getServerServices().power(server.getName(), PowerCommand.START);
|
client.getServerServices().power(server.getName(), PowerCommand.START);
|
||||||
|
@ -179,8 +178,7 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
||||||
private final Function<Server, NodeMetadata> serverToNodeMetadata;
|
private final Function<Server, NodeMetadata> serverToNodeMetadata;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected GoGridListNodesStrategy(GoGridClient client,
|
protected GoGridListNodesStrategy(GoGridClient client, Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
this.serverToNodeMetadata = serverToNodeMetadata;
|
||||||
}
|
}
|
||||||
|
@ -191,10 +189,9 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(
|
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||||
Predicate<ComputeMetadata> filter) {
|
return Iterables.filter(Iterables.transform(client.getServerServices().getServerList(), serverToNodeMetadata),
|
||||||
return Iterables.filter(Iterables.transform(client.getServerServices().getServerList(),
|
filter);
|
||||||
serverToNodeMetadata), filter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,8 +201,7 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
||||||
private final Function<Server, NodeMetadata> serverToNodeMetadata;
|
private final Function<Server, NodeMetadata> serverToNodeMetadata;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected GoGridGetNodeMetadataStrategy(GoGridClient client,
|
protected GoGridGetNodeMetadataStrategy(GoGridClient client, Function<Server, NodeMetadata> serverToNodeMetadata) {
|
||||||
Function<Server, NodeMetadata> serverToNodeMetadata) {
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.serverToNodeMetadata = serverToNodeMetadata;
|
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
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
Map<String, NodeState> provideServerToNodeState() {
|
Map<ServerState, NodeState> provideServerToNodeState() {
|
||||||
return ImmutableMap.<String, NodeState> builder().put("On", NodeState.RUNNING).put(
|
return serverStateToNodeState;
|
||||||
"Starting", NodeState.PENDING).put("Off", NodeState.SUSPENDED).put("Saving",
|
|
||||||
NodeState.PENDING).put("Restarting", NodeState.PENDING).put("Stopping",
|
|
||||||
NodeState.PENDING).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds matches to required configurations. GoGrid's documentation only specifies how much RAM
|
* Finds matches to required configurations. GoGrid's documentation only
|
||||||
* one can get with different instance types. The # of cores and disk sizes are purely empyrical
|
* specifies how much RAM one can get with different instance types. The # of
|
||||||
* and aren't guaranteed. However, these are the matches found: Ram: 512MB, CPU: 1 core, HDD: 28
|
* cores and disk sizes are purely empyrical and aren't guaranteed. However,
|
||||||
* GB Ram: 1GB, CPU: 1 core, HDD: 57 GB Ram: 2GB, CPU: 1 core, HDD: 113 GB Ram: 4GB, CPU: 3
|
* these are the matches found: Ram: 512MB, CPU: 1 core, HDD: 28 GB Ram: 1GB,
|
||||||
* cores, HDD: 233 GB Ram: 8GB, CPU: 6 cores, HDD: 462 GB (as of March 2010)
|
* 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
|
* @return matched size
|
||||||
*/
|
*/
|
||||||
|
@ -294,14 +300,13 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
Set<? extends Location> getAssignableLocations(@Provider String providerName, GoGridClient sync,
|
Set<? extends Location> getAssignableLocations(@Provider String providerName, GoGridClient sync, LogHolder holder,
|
||||||
LogHolder holder, Function<ComputeMetadata, String> indexer) {
|
Function<ComputeMetadata, String> indexer) {
|
||||||
final Set<Location> locations = Sets.newHashSet();
|
final Set<Location> locations = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing locations");
|
holder.logger.debug(">> providing locations");
|
||||||
Location parent = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
Location parent = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
||||||
for (Option dc : sync.getServerServices().getDatacenters())
|
for (Option dc : sync.getServerServices().getDatacenters())
|
||||||
locations.add(new LocationImpl(LocationScope.ZONE, dc.getId() + "", dc.getDescription(),
|
locations.add(new LocationImpl(LocationScope.ZONE, dc.getId() + "", dc.getDescription(), parent));
|
||||||
parent));
|
|
||||||
holder.logger.debug("<< locations(%d)", locations.size());
|
holder.logger.debug("<< locations(%d)", locations.size());
|
||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
|
@ -319,27 +324,21 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Set<? extends Size> provideSizes(GoGridClient sync, Set<? extends Image> images,
|
protected Set<? extends Size> provideSizes(GoGridClient sync, Set<? extends Image> images, LogHolder holder,
|
||||||
LogHolder holder, Function<ComputeMetadata, String> indexer)
|
Function<ComputeMetadata, String> indexer) throws InterruptedException, TimeoutException, ExecutionException {
|
||||||
throws InterruptedException, TimeoutException, ExecutionException {
|
|
||||||
final Set<Size> sizes = Sets.newHashSet();
|
final Set<Size> sizes = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing sizes");
|
holder.logger.debug(">> providing sizes");
|
||||||
|
|
||||||
sizes.add(new SizeImpl("1", "1", "1", null, null, ImmutableMap.<String, String> of(), 0.5,
|
sizes.add(new SizeImpl("1", "1", "1", null, null, ImmutableMap.<String, String> of(), 0.5, 512, 30,
|
||||||
512, 30, architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32,
|
architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))));
|
||||||
Architecture.X86_64))));
|
sizes.add(new SizeImpl("2", "2", "2", null, null, ImmutableMap.<String, String> of(), 1, 1024, 60,
|
||||||
sizes.add(new SizeImpl("2", "2", "2", null, null, ImmutableMap.<String, String> of(), 1,
|
architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))));
|
||||||
1024, 60, architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32,
|
sizes.add(new SizeImpl("3", "3", "3", null, null, ImmutableMap.<String, String> of(), 2, 2048, 120,
|
||||||
Architecture.X86_64))));
|
architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))));
|
||||||
sizes.add(new SizeImpl("3", "3", "3", null, null, ImmutableMap.<String, String> of(), 2,
|
sizes.add(new SizeImpl("4", "4", "4", null, null, ImmutableMap.<String, String> of(), 4, 4096, 240,
|
||||||
2048, 120, architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32,
|
architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))));
|
||||||
Architecture.X86_64))));
|
sizes.add(new SizeImpl("5", "5", "5", null, null, ImmutableMap.<String, String> of(), 8, 8192, 480,
|
||||||
sizes.add(new SizeImpl("4", "4", "4", null, null, ImmutableMap.<String, String> of(), 4,
|
architectureIn(ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))));
|
||||||
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());
|
holder.logger.debug("<< sizes(%d)", sizes.size());
|
||||||
return sizes;
|
return sizes;
|
||||||
}
|
}
|
||||||
|
@ -356,31 +355,31 @@ public class GoGridComputeServiceContextModule extends AbstractModule {
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Set<? extends Image> provideImages(final GoGridClient sync, LogHolder holder,
|
protected Set<? extends Image> provideImages(final GoGridClient sync, LogHolder holder,
|
||||||
Function<ComputeMetadata, String> indexer, Location location,
|
Function<ComputeMetadata, String> indexer, Location location,
|
||||||
PopulateDefaultLoginCredentialsForImageStrategy authenticator)
|
PopulateDefaultLoginCredentialsForImageStrategy authenticator) throws InterruptedException,
|
||||||
throws InterruptedException, ExecutionException, TimeoutException {
|
ExecutionException, TimeoutException {
|
||||||
final Set<Image> images = Sets.newHashSet();
|
final Set<Image> images = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing images");
|
holder.logger.debug(">> providing images");
|
||||||
Set<ServerImage> allImages = sync.getImageServices().getImageList();
|
Set<ServerImage> allImages = sync.getImageServices().getImageList();
|
||||||
for (ServerImage from : allImages) {
|
for (ServerImage from : allImages) {
|
||||||
OsFamily os = null;
|
OsFamily os = null;
|
||||||
Architecture arch = (from.getOs().getName().indexOf("64") == -1 && from.getDescription()
|
Architecture arch = (from.getOs().getName().indexOf("64") == -1 && from.getDescription().indexOf("64") == -1) ? Architecture.X86_32
|
||||||
.indexOf("64") == -1) ? Architecture.X86_32 : Architecture.X86_64;
|
: Architecture.X86_64;
|
||||||
String osDescription;
|
String osDescription;
|
||||||
String version = "";
|
String version = "";
|
||||||
|
|
||||||
osDescription = from.getOs().getName();
|
osDescription = from.getOs().getName();
|
||||||
|
|
||||||
String matchedOs = GoGridUtils.parseStringByPatternAndGetNthMatchGroup(from.getOs()
|
String matchedOs = GoGridUtils.parseStringByPatternAndGetNthMatchGroup(from.getOs().getName(),
|
||||||
.getName(), GOGRID_OS_NAME_PATTERN, 1);
|
GOGRID_OS_NAME_PATTERN, 1);
|
||||||
try {
|
try {
|
||||||
os = OsFamily.fromValue(matchedOs.toLowerCase());
|
os = OsFamily.fromValue(matchedOs.toLowerCase());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
holder.logger.debug("<< didn't match os(%s)", matchedOs);
|
holder.logger.debug("<< didn't match os(%s)", matchedOs);
|
||||||
}
|
}
|
||||||
Credentials defaultCredentials = authenticator.execute(from);
|
Credentials defaultCredentials = authenticator.execute(from);
|
||||||
images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), from.getId() + "",
|
images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), from.getId() + "", location, null,
|
||||||
location, null, ImmutableMap.<String, String> of(), from.getDescription(),
|
ImmutableMap.<String, String> of(), from.getDescription(), version, os, osDescription, arch,
|
||||||
version, os, osDescription, arch, defaultCredentials));
|
defaultCredentials));
|
||||||
}
|
}
|
||||||
holder.logger.debug("<< images(%d)", images.size());
|
holder.logger.debug("<< images(%d)", images.size());
|
||||||
return images;
|
return images;
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.gogrid.GoGridClient;
|
import org.jclouds.gogrid.GoGridClient;
|
||||||
import org.jclouds.gogrid.domain.Server;
|
import org.jclouds.gogrid.domain.Server;
|
||||||
|
import org.jclouds.gogrid.domain.ServerState;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -56,7 +57,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
private final Map<String, NodeState> serverStateToNodeState;
|
private final Map<ServerState, NodeState> serverStateToNodeState;
|
||||||
private final GoGridClient client;
|
private final GoGridClient client;
|
||||||
private final Set<? extends Image> images;
|
private final Set<? extends Image> images;
|
||||||
private final Map<String, ? extends Location> locations;
|
private final Map<String, ? extends Location> locations;
|
||||||
|
@ -78,7 +79,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ServerToNodeMetadata(Map<String, NodeState> serverStateToNodeState, GoGridClient client,
|
ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState, GoGridClient client,
|
||||||
Set<? extends Image> images, Map<String, ? extends Location> locations) {
|
Set<? extends Image> images, Map<String, ? extends Location> locations) {
|
||||||
this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
|
||||||
this.client = checkNotNull(client, "client");
|
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());
|
Matcher matcher = ALL_BEFORE_HYPHEN_HEX.matcher(from.getName());
|
||||||
final String tag = matcher.find() ? matcher.group(1) : null;
|
final String tag = matcher.find() ? matcher.group(1) : null;
|
||||||
Set<String> ipSet = ImmutableSet.of(from.getIp().getIp());
|
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());
|
Credentials creds = client.getServerServices().getServerCredentialsList().get(from.getName());
|
||||||
Image image = null;
|
Image image = null;
|
||||||
try {
|
try {
|
||||||
|
@ -99,9 +100,9 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
logger.warn("could not find a matching image for server %s", from);
|
logger.warn("could not find a matching image for server %s", from);
|
||||||
}
|
}
|
||||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations
|
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", locations.get(from
|
||||||
.get(from.getDatacenter().getId() + ""), null, ImmutableMap.<String, String> of(),
|
.getDatacenter().getId()
|
||||||
tag, image, state, ipSet, ImmutableList.<String> of(), ImmutableMap
|
+ ""), null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList.<String> of(),
|
||||||
.<String, String> of(), creds);
|
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.ObjectType;
|
||||||
import org.jclouds.gogrid.domain.ServerImageState;
|
import org.jclouds.gogrid.domain.ServerImageState;
|
||||||
import org.jclouds.gogrid.domain.ServerImageType;
|
import org.jclouds.gogrid.domain.ServerImageType;
|
||||||
|
import org.jclouds.gogrid.domain.ServerState;
|
||||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||||
import org.jclouds.json.config.GsonModule.DateAdapter;
|
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(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter());
|
||||||
bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
|
bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
|
||||||
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
|
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
|
||||||
|
bindings.put(ServerState.class, new CustomDeserializers.ServerStateAdapter());
|
||||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||||
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());
|
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());
|
||||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||||
|
|
|
@ -23,18 +23,18 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.gogrid.domain;
|
package org.jclouds.gogrid.domain;
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.primitives.Longs;
|
import com.google.common.primitives.Longs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
*/
|
*/
|
||||||
public class Server implements Comparable<Server> {
|
public class Server implements Comparable<Server> {
|
||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
private boolean isSandbox;
|
private boolean isSandbox;
|
||||||
private String name;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
private Option state;
|
private ServerState state;
|
||||||
private Option datacenter;
|
private Option datacenter;
|
||||||
|
|
||||||
private Option type;
|
private Option type;
|
||||||
|
@ -47,11 +47,11 @@ public class Server implements Comparable<Server> {
|
||||||
/**
|
/**
|
||||||
* A no-args constructor is required for deserialization
|
* A no-args constructor is required for deserialization
|
||||||
*/
|
*/
|
||||||
public Server() {
|
Server() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Server(long id, Option datacenter, boolean sandbox, String name, String description,
|
public Server(long id, Option datacenter, boolean sandbox, String name, String description, ServerState state,
|
||||||
Option state, Option type, Option ram, Option os, Ip ip, ServerImage image) {
|
Option type, Option ram, Option os, Ip ip, ServerImage image) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.isSandbox = sandbox;
|
this.isSandbox = sandbox;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -85,7 +85,7 @@ public class Server implements Comparable<Server> {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Option getState() {
|
public ServerState getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,8 +195,8 @@ public class Server implements Comparable<Server> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Server [datacenter=" + datacenter + ", description=" + description + ", id=" + id
|
return "Server [datacenter=" + datacenter + ", description=" + description + ", id=" + id + ", image=" + image
|
||||||
+ ", image=" + image + ", ip=" + ip + ", isSandbox=" + isSandbox + ", name=" + name
|
+ ", ip=" + ip + ", isSandbox=" + isSandbox + ", name=" + name + ", os=" + os + ", ram=" + ram + ", state="
|
||||||
+ ", os=" + os + ", ram=" + ram + ", state=" + state + ", type=" + type + "]";
|
+ 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;
|
package org.jclouds.gogrid.functions.internal;
|
||||||
|
|
||||||
import com.google.gson.*;
|
|
||||||
import org.jclouds.gogrid.domain.*;
|
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
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
|
* @author Oleksiy Yarmula
|
||||||
*/
|
*/
|
||||||
public class CustomDeserializers {
|
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> {
|
public static class ObjectTypeAdapter implements JsonDeserializer<ObjectType> {
|
||||||
@Override
|
@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();
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
return ObjectType.fromValue(name);
|
return ObjectType.fromValue(name);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +62,8 @@ public class CustomDeserializers {
|
||||||
|
|
||||||
public static class LoadBalancerOsAdapter implements JsonDeserializer<LoadBalancerOs> {
|
public static class LoadBalancerOsAdapter implements JsonDeserializer<LoadBalancerOs> {
|
||||||
@Override
|
@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();
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
return LoadBalancerOs.fromValue(name);
|
return LoadBalancerOs.fromValue(name);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +71,8 @@ public class CustomDeserializers {
|
||||||
|
|
||||||
public static class LoadBalancerStateAdapter implements JsonDeserializer<LoadBalancerState> {
|
public static class LoadBalancerStateAdapter implements JsonDeserializer<LoadBalancerState> {
|
||||||
@Override
|
@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();
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
return LoadBalancerState.fromValue(name);
|
return LoadBalancerState.fromValue(name);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +80,8 @@ public class CustomDeserializers {
|
||||||
|
|
||||||
public static class LoadBalancerPersistenceTypeAdapter implements JsonDeserializer<LoadBalancerPersistenceType> {
|
public static class LoadBalancerPersistenceTypeAdapter implements JsonDeserializer<LoadBalancerPersistenceType> {
|
||||||
@Override
|
@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();
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
return LoadBalancerPersistenceType.fromValue(name);
|
return LoadBalancerPersistenceType.fromValue(name);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +89,8 @@ public class CustomDeserializers {
|
||||||
|
|
||||||
public static class LoadBalancerTypeAdapter implements JsonDeserializer<LoadBalancerType> {
|
public static class LoadBalancerTypeAdapter implements JsonDeserializer<LoadBalancerType> {
|
||||||
@Override
|
@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();
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
return LoadBalancerType.fromValue(name);
|
return LoadBalancerType.fromValue(name);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +98,8 @@ public class CustomDeserializers {
|
||||||
|
|
||||||
public static class IpStateAdapter implements JsonDeserializer<IpState> {
|
public static class IpStateAdapter implements JsonDeserializer<IpState> {
|
||||||
@Override
|
@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();
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
return IpState.fromValue(name);
|
return IpState.fromValue(name);
|
||||||
}
|
}
|
||||||
|
@ -78,7 +107,8 @@ public class CustomDeserializers {
|
||||||
|
|
||||||
public static class JobStateAdapter implements JsonDeserializer<JobState> {
|
public static class JobStateAdapter implements JsonDeserializer<JobState> {
|
||||||
@Override
|
@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();
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
return JobState.fromValue(name);
|
return JobState.fromValue(name);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +116,8 @@ public class CustomDeserializers {
|
||||||
|
|
||||||
public static class ServerImageStateAdapter implements JsonDeserializer<ServerImageState> {
|
public static class ServerImageStateAdapter implements JsonDeserializer<ServerImageState> {
|
||||||
@Override
|
@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();
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
return ServerImageState.fromValue(name);
|
return ServerImageState.fromValue(name);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +125,8 @@ public class CustomDeserializers {
|
||||||
|
|
||||||
public static class ServerImageTypeAdapter implements JsonDeserializer<ServerImageType> {
|
public static class ServerImageTypeAdapter implements JsonDeserializer<ServerImageType> {
|
||||||
@Override
|
@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();
|
String name = ((JsonObject) jsonElement).get("name").getAsString();
|
||||||
return ServerImageType.fromValue(name);
|
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.Option;
|
||||||
import org.jclouds.gogrid.domain.Server;
|
import org.jclouds.gogrid.domain.Server;
|
||||||
import org.jclouds.gogrid.domain.ServerImage;
|
import org.jclouds.gogrid.domain.ServerImage;
|
||||||
|
import org.jclouds.gogrid.domain.ServerState;
|
||||||
import org.jclouds.gogrid.services.GridServerClient;
|
import org.jclouds.gogrid.services.GridServerClient;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ public class ServerToNodeMetadataTest {
|
||||||
GoGridClient caller = createMock(GoGridClient.class);
|
GoGridClient caller = createMock(GoGridClient.class);
|
||||||
GridServerClient client = createMock(GridServerClient.class);
|
GridServerClient client = createMock(GridServerClient.class);
|
||||||
expect(caller.getServerServices()).andReturn(client).atLeastOnce();
|
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);
|
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");
|
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.getId()).andReturn(1000l).atLeastOnce();
|
||||||
expect(server.getName()).andReturn("tag-ff").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);
|
LocationImpl location = new LocationImpl(LocationScope.ZONE, "1", "US-West-1", null);
|
||||||
Map<String, ? extends Location> locations = ImmutableMap.<String, Location> of("1", location);
|
Map<String, ? extends Location> locations = ImmutableMap.<String, Location> of("1", location);
|
||||||
|
|
||||||
|
@ -75,8 +76,7 @@ public class ServerToNodeMetadataTest {
|
||||||
replay(jcImage);
|
replay(jcImage);
|
||||||
replay(credentialsMap);
|
replay(credentialsMap);
|
||||||
|
|
||||||
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, caller,
|
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, caller, images, locations);
|
||||||
images, locations);
|
|
||||||
|
|
||||||
NodeMetadata metadata = parser.apply(server);
|
NodeMetadata metadata = parser.apply(server);
|
||||||
assertEquals(metadata.getLocation(), location);
|
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.IpState;
|
||||||
import org.jclouds.gogrid.domain.ServerImageState;
|
import org.jclouds.gogrid.domain.ServerImageState;
|
||||||
import org.jclouds.gogrid.domain.ServerImageType;
|
import org.jclouds.gogrid.domain.ServerImageType;
|
||||||
|
import org.jclouds.gogrid.domain.ServerState;
|
||||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
|
@ -52,27 +53,21 @@ public class ParseCredentialsFromJsonResponseTest {
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalStateException.class)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testFailWhenTooManyPasswords() throws UnknownHostException {
|
public void testFailWhenTooManyPasswords() throws UnknownHostException {
|
||||||
InputStream is = getClass().getResourceAsStream(
|
InputStream is = getClass().getResourceAsStream("/test_credentials_list.json");
|
||||||
"/test_credentials_list.json");
|
|
||||||
|
|
||||||
HttpResponse response = new HttpResponse(200, "ok", Payloads
|
HttpResponse response = new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is));
|
||||||
.newInputStreamPayload(is));
|
|
||||||
|
|
||||||
ParseCredentialsFromJsonResponse parser = i
|
ParseCredentialsFromJsonResponse parser = i.getInstance(ParseCredentialsFromJsonResponse.class);
|
||||||
.getInstance(ParseCredentialsFromJsonResponse.class);
|
|
||||||
parser.apply(response);
|
parser.apply(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValid() throws UnknownHostException {
|
public void testValid() throws UnknownHostException {
|
||||||
InputStream is = getClass().getResourceAsStream(
|
InputStream is = getClass().getResourceAsStream("/test_credential.json");
|
||||||
"/test_credential.json");
|
|
||||||
|
|
||||||
HttpResponse response = new HttpResponse(200, "ok", Payloads
|
HttpResponse response = new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is));
|
||||||
.newInputStreamPayload(is));
|
|
||||||
|
|
||||||
ParseCredentialsFromJsonResponse parser = i
|
ParseCredentialsFromJsonResponse parser = i.getInstance(ParseCredentialsFromJsonResponse.class);
|
||||||
.getInstance(ParseCredentialsFromJsonResponse.class);
|
|
||||||
Credentials creds = parser.apply(response);
|
Credentials creds = parser.apply(response);
|
||||||
assertEquals(creds.identity, "root");
|
assertEquals(creds.identity, "root");
|
||||||
assertEquals(creds.credential, "dig44sos");
|
assertEquals(creds.credential, "dig44sos");
|
||||||
|
@ -93,12 +88,9 @@ public class ParseCredentialsFromJsonResponseTest {
|
||||||
public Map<Type, Object> provideCustomAdapterBindings() {
|
public Map<Type, Object> provideCustomAdapterBindings() {
|
||||||
Map<Type, Object> bindings = Maps.newHashMap();
|
Map<Type, Object> bindings = Maps.newHashMap();
|
||||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||||
bindings.put(ServerImageType.class,
|
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||||
new CustomDeserializers.ServerImageTypeAdapter());
|
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||||
bindings.put(ServerImageState.class,
|
bindings.put(ServerState.class, new CustomDeserializers.ServerStateAdapter());
|
||||||
new CustomDeserializers.ServerImageStateAdapter());
|
|
||||||
bindings.put(ServerImageState.class,
|
|
||||||
new CustomDeserializers.ServerImageStateAdapter());
|
|
||||||
return bindings;
|
return bindings;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.gogrid.config.DateSecondsAdapter;
|
||||||
import org.jclouds.gogrid.domain.IpState;
|
import org.jclouds.gogrid.domain.IpState;
|
||||||
import org.jclouds.gogrid.domain.ServerImageState;
|
import org.jclouds.gogrid.domain.ServerImageState;
|
||||||
import org.jclouds.gogrid.domain.ServerImageType;
|
import org.jclouds.gogrid.domain.ServerImageType;
|
||||||
|
import org.jclouds.gogrid.domain.ServerState;
|
||||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
|
@ -77,7 +78,7 @@ public class ParseServerNameToCredentialsMapFromJsonResponseTest {
|
||||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||||
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
bindings.put(ServerState.class, new CustomDeserializers.ServerStateAdapter());
|
||||||
return bindings;
|
return bindings;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,6 +44,7 @@ import org.jclouds.gogrid.domain.Server;
|
||||||
import org.jclouds.gogrid.domain.ServerImage;
|
import org.jclouds.gogrid.domain.ServerImage;
|
||||||
import org.jclouds.gogrid.domain.ServerImageState;
|
import org.jclouds.gogrid.domain.ServerImageState;
|
||||||
import org.jclouds.gogrid.domain.ServerImageType;
|
import org.jclouds.gogrid.domain.ServerImageType;
|
||||||
|
import org.jclouds.gogrid.domain.ServerState;
|
||||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.io.Payloads;
|
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 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");
|
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",
|
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",
|
ServerState.ON, webServer, new Option(1L, "512MB", "Server with 512MB RAM"), centOs, new Ip(1313079L,
|
||||||
"Server with 512MB RAM"), centOs, new Ip(1313079L, "204.51.240.178",
|
"204.51.240.178", "204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc), new ServerImage(
|
||||||
"204.51.240.176/255.255.255.240", true, IpState.ASSIGNED, dc), new ServerImage(1946L,
|
1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "BitNami Gallery 2.3.1-0",
|
||||||
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "BitNami Gallery 2.3.1-0",
|
|
||||||
"http://bitnami.org/stack/gallery", centOs, null, ServerImageType.WEB_APPLICATION_SERVER,
|
"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,
|
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,
|
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.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -74,13 +75,13 @@ import org.jclouds.rest.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import java.util.concurrent.Future;
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
|
@ -216,10 +217,9 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@VisibleForTesting
|
||||||
@Provides
|
static final Map<Instance.Status, NodeState> instanceStatusToNodeState = ImmutableMap
|
||||||
Map<Instance.Status, NodeState> provideServerToNodeState() {
|
.<Instance.Status, NodeState> builder().put(Instance.Status.ACTIVE, NodeState.RUNNING)//
|
||||||
return ImmutableMap.<Instance.Status, NodeState> builder().put(Instance.Status.ACTIVE, NodeState.RUNNING)//
|
|
||||||
.put(Instance.Status.STOPPED, NodeState.SUSPENDED)//
|
.put(Instance.Status.STOPPED, NodeState.SUSPENDED)//
|
||||||
.put(Instance.Status.REMOVED, NodeState.TERMINATED)//
|
.put(Instance.Status.REMOVED, NodeState.TERMINATED)//
|
||||||
.put(Instance.Status.DEPROVISIONING, NodeState.PENDING)//
|
.put(Instance.Status.DEPROVISIONING, NodeState.PENDING)//
|
||||||
|
@ -230,7 +230,13 @@ public class IBMDeveloperCloudComputeServiceContextModule extends AbstractModule
|
||||||
.put(Instance.Status.RESTARTING, NodeState.PENDING)//
|
.put(Instance.Status.RESTARTING, NodeState.PENDING)//
|
||||||
.put(Instance.Status.STARTING, NodeState.PENDING)//
|
.put(Instance.Status.STARTING, NodeState.PENDING)//
|
||||||
.put(Instance.Status.STOPPING, NodeState.PENDING)//
|
.put(Instance.Status.STOPPING, NodeState.PENDING)//
|
||||||
|
.put(Instance.Status.DEPROVISION_PENDING, NodeState.PENDING)//
|
||||||
.put(Instance.Status.UNKNOWN, NodeState.UNKNOWN).build();
|
.put(Instance.Status.UNKNOWN, NodeState.UNKNOWN).build();
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
Map<Instance.Status, NodeState> provideServerToNodeState() {
|
||||||
|
return instanceStatusToNodeState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@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.RestContext;
|
||||||
import org.jclouds.rest.internal.RestContextImpl;
|
import org.jclouds.rest.internal.RestContextImpl;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -238,10 +239,9 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@VisibleForTesting
|
||||||
@Provides
|
static final Map<ServerStatus, NodeState> serverToNodeState = ImmutableMap.<ServerStatus, NodeState> builder().put(
|
||||||
Map<ServerStatus, NodeState> provideServerToNodeState() {
|
ServerStatus.ACTIVE, NodeState.RUNNING)//
|
||||||
return ImmutableMap.<ServerStatus, NodeState> builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)//
|
|
||||||
.put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)//
|
.put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)//
|
||||||
.put(ServerStatus.DELETED, NodeState.TERMINATED)//
|
.put(ServerStatus.DELETED, NodeState.TERMINATED)//
|
||||||
.put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)//
|
.put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)//
|
||||||
|
@ -264,6 +264,11 @@ public class CloudServersComputeServiceContextModule extends AbstractModule {
|
||||||
.put(ServerStatus.REBOOT, NodeState.PENDING)//
|
.put(ServerStatus.REBOOT, NodeState.PENDING)//
|
||||||
.put(ServerStatus.HARD_REBOOT, NodeState.PENDING)//
|
.put(ServerStatus.HARD_REBOOT, NodeState.PENDING)//
|
||||||
.put(ServerStatus.UNKNOWN, NodeState.UNKNOWN).build();
|
.put(ServerStatus.UNKNOWN, NodeState.UNKNOWN).build();
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
Map<ServerStatus, NodeState> provideServerToNodeState() {
|
||||||
|
return serverToNodeState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@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.Server;
|
||||||
import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
|
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.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
@ -104,9 +105,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
}).to(ServerToNodeMetadata.class);
|
}).to(ServerToNodeMetadata.class);
|
||||||
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null));
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
})
|
}).to(new TypeLiteral<ComputeServiceContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
||||||
.to(
|
|
||||||
new TypeLiteral<ComputeServiceContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
|
||||||
}).in(Scopes.SINGLETON);
|
}).in(Scopes.SINGLETON);
|
||||||
bind(new TypeLiteral<RestContext<RimuHostingClient, RimuHostingAsyncClient>>() {
|
bind(new TypeLiteral<RestContext<RimuHostingClient, RimuHostingAsyncClient>>() {
|
||||||
}).to(new TypeLiteral<RestContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
}).to(new TypeLiteral<RestContextImpl<RimuHostingClient, RimuHostingAsyncClient>>() {
|
||||||
|
@ -123,8 +122,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Named("DEFAULT")
|
@Named("DEFAULT")
|
||||||
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
protected TemplateBuilder provideTemplate(TemplateBuilder template) {
|
||||||
return template.sizeId("MIRO1B").osFamily(UBUNTU).architecture(Architecture.X86_32)
|
return template.sizeId("MIRO1B").osFamily(UBUNTU).architecture(Architecture.X86_32).imageNameMatches(
|
||||||
.imageNameMatches(".*10\\.?04.*");
|
".*10\\.?04.*");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -140,8 +139,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
private final GetNodeMetadataStrategy getNode;
|
private final GetNodeMetadataStrategy getNode;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected RimuHostingRebootNodeStrategy(RimuHostingClient client,
|
protected RimuHostingRebootNodeStrategy(RimuHostingClient client, GetNodeMetadataStrategy getNode) {
|
||||||
GetNodeMetadataStrategy getNode) {
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.getNode = getNode;
|
this.getNode = getNode;
|
||||||
}
|
}
|
||||||
|
@ -162,8 +160,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
private final GetNodeMetadataStrategy getNode;
|
private final GetNodeMetadataStrategy getNode;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected RimuHostingDestroyNodeStrategy(RimuHostingClient client,
|
protected RimuHostingDestroyNodeStrategy(RimuHostingClient client, GetNodeMetadataStrategy getNode) {
|
||||||
GetNodeMetadataStrategy getNode) {
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.getNode = getNode;
|
this.getNode = getNode;
|
||||||
}
|
}
|
||||||
|
@ -185,8 +182,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected RimuHostingAddNodeWithTagStrategy(RimuHostingClient client,
|
protected RimuHostingAddNodeWithTagStrategy(RimuHostingClient client,
|
||||||
Function<Server, Iterable<String>> getPublicAddresses,
|
Function<Server, Iterable<String>> getPublicAddresses, Map<RunningState, NodeState> runningStateToNodeState) {
|
||||||
Map<RunningState, NodeState> runningStateToNodeState) {
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.getPublicAddresses = getPublicAddresses;
|
this.getPublicAddresses = getPublicAddresses;
|
||||||
this.runningStateToNodeState = runningStateToNodeState;
|
this.runningStateToNodeState = runningStateToNodeState;
|
||||||
|
@ -194,15 +190,13 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata execute(String tag, String name, Template template) {
|
public NodeMetadata execute(String tag, String name, Template template) {
|
||||||
NewServerResponse serverResponse = client.createServer(name, checkNotNull(template
|
NewServerResponse serverResponse = client.createServer(name, checkNotNull(template.getImage().getProviderId(),
|
||||||
.getImage().getProviderId(), "imageId"), checkNotNull(template.getSize()
|
"imageId"), checkNotNull(template.getSize().getProviderId(), "sizeId"));
|
||||||
.getProviderId(), "sizeId"));
|
|
||||||
Server server = client.getServer(serverResponse.getServer().getId());
|
Server server = client.getServer(serverResponse.getServer().getId());
|
||||||
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId()
|
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template
|
||||||
.toString(), template.getLocation(), null, ImmutableMap.<String, String> of(),
|
.getLocation(), null, ImmutableMap.<String, String> of(), tag, template.getImage(),
|
||||||
tag, template.getImage(), runningStateToNodeState.get(server.getState()),
|
runningStateToNodeState.get(server.getState()), getPublicAddresses.apply(server), ImmutableList
|
||||||
getPublicAddresses.apply(server), ImmutableList.<String> of(), ImmutableMap
|
.<String> of(), ImmutableMap.<String, String> of(), new Credentials("root", serverResponse
|
||||||
.<String, String> of(), new Credentials("root", serverResponse
|
|
||||||
.getNewInstanceRequest().getCreateOptions().getPassword()));
|
.getNewInstanceRequest().getCreateOptions().getPassword()));
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -227,10 +221,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(
|
public Iterable<? extends NodeMetadata> listDetailsOnNodesMatching(Predicate<ComputeMetadata> filter) {
|
||||||
Predicate<ComputeMetadata> filter) {
|
return Iterables.filter(Iterables.transform(client.getServerList(), serverToNodeMetadata), filter);
|
||||||
return Iterables.filter(Iterables.transform(client.getServerList(), serverToNodeMetadata),
|
|
||||||
filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -256,15 +248,18 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@VisibleForTesting
|
||||||
@Provides
|
static final Map<RunningState, NodeState> runningStateToNodeState = ImmutableMap.<RunningState, NodeState> builder()
|
||||||
Map<RunningState, NodeState> provideServerToNodeState() {
|
.put(RunningState.RUNNING, NodeState.RUNNING)//
|
||||||
return ImmutableMap.<RunningState, NodeState> builder().put(RunningState.RUNNING,
|
|
||||||
NodeState.RUNNING)//
|
|
||||||
.put(RunningState.NOTRUNNING, NodeState.SUSPENDED)//
|
.put(RunningState.NOTRUNNING, NodeState.SUSPENDED)//
|
||||||
.put(RunningState.POWERCYCLING, NodeState.PENDING)//
|
.put(RunningState.POWERCYCLING, NodeState.PENDING)//
|
||||||
.put(RunningState.RESTARTING, NodeState.PENDING)//
|
.put(RunningState.RESTARTING, NodeState.PENDING)//
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
Map<RunningState, NodeState> provideServerToNodeState() {
|
||||||
|
return runningStateToNodeState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -290,8 +285,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Image input) {
|
public boolean apply(Image input) {
|
||||||
return input.getProviderId().equals(instance.getImageId())
|
return input.getProviderId().equals(instance.getImageId())
|
||||||
&& (input.getLocation() == null || input.getLocation().equals(location) || input
|
&& (input.getLocation() == null || input.getLocation().equals(location) || input.getLocation()
|
||||||
.getLocation().equals(location.getParent()));
|
.equals(location.getParent()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,8 +296,7 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
Map<RunningState, NodeState> runningStateToNodeState, Set<? extends Image> images,
|
Map<RunningState, NodeState> runningStateToNodeState, Set<? extends Image> images,
|
||||||
Set<? extends Location> locations) {
|
Set<? extends Location> locations) {
|
||||||
this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState");
|
this.getPublicAddresses = checkNotNull(getPublicAddresses, "serverStateToNodeState");
|
||||||
this.runningStateToNodeState = checkNotNull(runningStateToNodeState,
|
this.runningStateToNodeState = checkNotNull(runningStateToNodeState, "serverStateToNodeState");
|
||||||
"serverStateToNodeState");
|
|
||||||
this.images = checkNotNull(images, "images");
|
this.images = checkNotNull(images, "images");
|
||||||
this.locations = checkNotNull(locations, "locations");
|
this.locations = checkNotNull(locations, "locations");
|
||||||
}
|
}
|
||||||
|
@ -310,8 +304,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata apply(Server from) {
|
public NodeMetadata apply(Server from) {
|
||||||
|
|
||||||
Location location = new LocationImpl(LocationScope.ZONE, from.getLocation().getId(), from
|
Location location = new LocationImpl(LocationScope.ZONE, from.getLocation().getId(), from.getLocation()
|
||||||
.getLocation().getName(), null);
|
.getName(), null);
|
||||||
String tag = from.getName().replaceAll("-[0-9]+", "");
|
String tag = from.getName().replaceAll("-[0-9]+", "");
|
||||||
Credentials creds = null;
|
Credentials creds = null;
|
||||||
|
|
||||||
|
@ -319,14 +313,12 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
try {
|
try {
|
||||||
image = Iterables.find(images, new FindImageForServer(location, from));
|
image = Iterables.find(images, new FindImageForServer(location, from));
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
logger.warn("could not find a matching image for server %s in location %s", from,
|
logger.warn("could not find a matching image for server %s in location %s", from, location);
|
||||||
location);
|
|
||||||
}
|
}
|
||||||
NodeState state = runningStateToNodeState.get(from.getState());
|
NodeState state = runningStateToNodeState.get(from.getState());
|
||||||
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "",
|
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, null, ImmutableMap
|
||||||
location, null, ImmutableMap.<String, String> of(), tag, image, state,
|
.<String, String> of(), tag, image, state, getPublicAddresses.apply(from), ImmutableList.<String> of(),
|
||||||
getPublicAddresses.apply(from), ImmutableList.<String> of(), ImmutableMap
|
ImmutableMap.<String, String> of(), creds);
|
||||||
.<String, String> of(), creds);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,9 +327,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
private static class ServerToPublicAddresses implements Function<Server, Iterable<String>> {
|
private static class ServerToPublicAddresses implements Function<Server, Iterable<String>> {
|
||||||
@Override
|
@Override
|
||||||
public Iterable<String> apply(Server server) {
|
public Iterable<String> apply(Server server) {
|
||||||
return server.getIpAddresses() == null ? ImmutableSet.<String> of() : Iterables.concat(
|
return server.getIpAddresses() == null ? ImmutableSet.<String> of() : Iterables.concat(ImmutableList.of(server
|
||||||
ImmutableList.of(server.getIpAddresses().getPrimaryIp()), server.getIpAddresses()
|
.getIpAddresses().getPrimaryIp()), server.getIpAddresses().getSecondaryIps());
|
||||||
.getSecondaryIps());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,8 +355,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
|
||||||
for (final PricingPlan from : sync.getPricingPlanList()) {
|
for (final PricingPlan from : sync.getPricingPlanList()) {
|
||||||
try {
|
try {
|
||||||
locations.add(new LocationImpl(LocationScope.ZONE, from.getDataCenter().getId(), from
|
locations.add(new LocationImpl(LocationScope.ZONE, from.getDataCenter().getId(), from.getDataCenter()
|
||||||
.getDataCenter().getName(), provider));
|
.getName(), provider));
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
holder.logger.warn("datacenter not present in " + from.getId());
|
holder.logger.warn("datacenter not present in " + from.getId());
|
||||||
}
|
}
|
||||||
|
@ -389,9 +380,8 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Set<? extends Size> provideSizes(RimuHostingClient sync, Set<? extends Image> images,
|
protected Set<? extends Size> provideSizes(RimuHostingClient sync, Set<? extends Image> images,
|
||||||
Set<? extends Location> locations, LogHolder holder,
|
Set<? extends Location> locations, LogHolder holder,
|
||||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor,
|
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService userExecutor, Function<ComputeMetadata, String> indexer)
|
||||||
Function<ComputeMetadata, String> indexer) throws InterruptedException,
|
throws InterruptedException, TimeoutException, ExecutionException {
|
||||||
TimeoutException, ExecutionException {
|
|
||||||
final Set<Size> sizes = Sets.newHashSet();
|
final Set<Size> sizes = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing sizes");
|
holder.logger.debug(">> providing sizes");
|
||||||
for (final PricingPlan from : sync.getPricingPlanList()) {
|
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,
|
sizes.add(new SizeImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap
|
||||||
ImmutableMap.<String, String> of(), 1, from.getRam(), from.getDiskSize(),
|
.<String, String> of(), 1, from.getRam(), from.getDiskSize(), ImagePredicates.any()));
|
||||||
ImagePredicates.any()));
|
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
holder.logger.warn("datacenter not present in " + from.getId());
|
holder.logger.warn("datacenter not present in " + from.getId());
|
||||||
}
|
}
|
||||||
|
@ -427,14 +416,12 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
protected Set<? extends Image> provideImages(final RimuHostingClient sync, LogHolder holder,
|
protected Set<? extends Image> provideImages(final RimuHostingClient sync, LogHolder holder,
|
||||||
Function<ComputeMetadata, String> indexer) throws InterruptedException,
|
Function<ComputeMetadata, String> indexer) throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
ExecutionException, TimeoutException {
|
|
||||||
final Set<Image> images = Sets.newHashSet();
|
final Set<Image> images = Sets.newHashSet();
|
||||||
holder.logger.debug(">> providing images");
|
holder.logger.debug(">> providing images");
|
||||||
for (final org.jclouds.rimuhosting.miro.domain.Image from : sync.getImageList()) {
|
for (final org.jclouds.rimuhosting.miro.domain.Image from : sync.getImageList()) {
|
||||||
OsFamily os = null;
|
OsFamily os = null;
|
||||||
Architecture arch = from.getId().indexOf("64") == -1 ? Architecture.X86_32
|
Architecture arch = from.getId().indexOf("64") == -1 ? Architecture.X86_32 : Architecture.X86_64;
|
||||||
: Architecture.X86_64;
|
|
||||||
String osDescription = "";
|
String osDescription = "";
|
||||||
String version = "";
|
String version = "";
|
||||||
|
|
||||||
|
@ -449,9 +436,9 @@ public class RimuHostingComputeServiceContextModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
images.add(new ImageImpl(from.getId(), from.getDescription(), from.getId(), null, null,
|
images.add(new ImageImpl(from.getId(), from.getDescription(), from.getId(), null, null, ImmutableMap
|
||||||
ImmutableMap.<String, String> of(), from.getDescription(), version, os,
|
.<String, String> of(), from.getDescription(), version, os, osDescription, arch, new Credentials("root",
|
||||||
osDescription, arch, new Credentials("root", null)));
|
null)));
|
||||||
}
|
}
|
||||||
holder.logger.debug("<< images(%d)", images.size());
|
holder.logger.debug("<< images(%d)", images.size());
|
||||||
return images;
|
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.Flavor;
|
||||||
import org.jclouds.slicehost.domain.Slice;
|
import org.jclouds.slicehost.domain.Slice;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -244,15 +245,19 @@ public class SlicehostComputeServiceContextModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@VisibleForTesting
|
||||||
@Provides
|
static final Map<Slice.Status, NodeState> sliceStatusToNodeState = ImmutableMap.<Slice.Status, NodeState> builder()
|
||||||
Map<Slice.Status, NodeState> provideSliceToNodeState() {
|
.put(Slice.Status.ACTIVE, NodeState.RUNNING)//
|
||||||
return ImmutableMap.<Slice.Status, NodeState> builder().put(Slice.Status.ACTIVE, NodeState.RUNNING)//
|
|
||||||
.put(Slice.Status.BUILD, NodeState.PENDING)//
|
.put(Slice.Status.BUILD, NodeState.PENDING)//
|
||||||
.put(Slice.Status.REBOOT, NodeState.PENDING)//
|
.put(Slice.Status.REBOOT, NodeState.PENDING)//
|
||||||
.put(Slice.Status.HARD_REBOOT, NodeState.PENDING)//
|
.put(Slice.Status.HARD_REBOOT, NodeState.PENDING)//
|
||||||
.put(Slice.Status.TERMINATED, NodeState.TERMINATED)//
|
.put(Slice.Status.TERMINATED, NodeState.TERMINATED)//
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Provides
|
||||||
|
Map<Slice.Status, NodeState> provideSliceToNodeState() {
|
||||||
|
return sliceStatusToNodeState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@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.compute.strategy.VCloudRebootNodeStrategy;
|
||||||
import org.jclouds.vcloud.domain.VAppStatus;
|
import org.jclouds.vcloud.domain.VAppStatus;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
@ -76,12 +77,16 @@ import com.google.inject.util.Providers;
|
||||||
*/
|
*/
|
||||||
public class VCloudComputeServiceContextModule extends AbstractModule {
|
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
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
Map<VAppStatus, NodeState> provideVAppStatusToNodeState() {
|
Map<VAppStatus, NodeState> provideVAppStatusToNodeState() {
|
||||||
return ImmutableMap.<VAppStatus, NodeState> builder().put(VAppStatus.OFF, NodeState.SUSPENDED).put(VAppStatus.ON,
|
return vAppStatusToNodeState;
|
||||||
NodeState.RUNNING).put(VAppStatus.RESOLVED, NodeState.PENDING).put(VAppStatus.SUSPENDED,
|
|
||||||
NodeState.SUSPENDED).put(VAppStatus.UNRESOLVED, NodeState.PENDING).build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@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