fixed credential persistence in gogrid

This commit is contained in:
Adrian Cole 2011-07-07 01:06:01 -07:00
parent 48fa7a6d2c
commit 17545cca29
3 changed files with 21 additions and 25 deletions

View File

@ -35,8 +35,8 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.domain.ServerState;
import org.jclouds.logging.Logger;
@ -56,10 +56,10 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
@Resource
protected Logger logger = Logger.NULL;
private final Map<ServerState, NodeState> serverStateToNodeState;
private final GoGridClient client;
private final Supplier<Set<? extends Image>> images;
private final Supplier<Set<? extends Hardware>> hardwares;
private final Supplier<Map<String, ? extends Location>> locations;
private final Map<String, Credentials> credentialStore;
static class FindImageForServer implements Predicate<Image> {
private final Server instance;
@ -92,11 +92,11 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
}
@Inject
ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState, GoGridClient client,
ServerToNodeMetadata(Map<ServerState, NodeState> serverStateToNodeState, Map<String, Credentials> credentialStore,
@Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
Supplier<Map<String, ? extends Location>> locations) {
this.serverStateToNodeState = checkNotNull(serverStateToNodeState, "serverStateToNodeState");
this.client = checkNotNull(client, "client");
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
this.images = checkNotNull(images, "images");
this.hardwares = checkNotNull(hardwares, "hardwares");
this.locations = checkNotNull(locations, "locations");
@ -118,7 +118,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
builder.state(serverStateToNodeState.get(from.getState()));
builder.publicAddresses(ImmutableSet.of(from.getIp().getIp()));
builder.credentials(client.getServerServices().getServerCredentialsList().get(from.getName()));
builder.credentials(credentialStore.get("node#" + from.getId()));
return builder.build();
}

View File

@ -21,6 +21,7 @@ package org.jclouds.gogrid.compute.strategy;
import static com.google.common.base.Preconditions.*;
import java.security.SecureRandom;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
@ -31,6 +32,7 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.domain.Credentials;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.domain.Ip;
import org.jclouds.gogrid.domain.IpType;
@ -52,16 +54,19 @@ public class FindIpThenCreateNodeInGroup implements CreateNodeWithGroupEncodedIn
private final GoGridClient client;
private final Function<Hardware, String> sizeToRam;
private final Function<Server, NodeMetadata> serverToNodeMetadata;
private RetryablePredicate<Server> serverLatestJobCompleted;
private RetryablePredicate<Server> serverLatestJobCompletedShort;
private final RetryablePredicate<Server> serverLatestJobCompleted;
private final RetryablePredicate<Server> serverLatestJobCompletedShort;
private final Map<String, Credentials> credentialStore;
@Inject
protected FindIpThenCreateNodeInGroup(GoGridClient client,
protected FindIpThenCreateNodeInGroup(GoGridClient client, Map<String, Credentials> credentialStore,
Function<Server, NodeMetadata> serverToNodeMetadata, Function<Hardware, String> sizeToRam,
Timeouts timeouts) {
this.client = client;
this.serverToNodeMetadata = serverToNodeMetadata;
this.sizeToRam = sizeToRam;
this.client = checkNotNull(client, "client");
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
this.serverToNodeMetadata = checkNotNull(serverToNodeMetadata, "serverToNodeMetadata");
this.sizeToRam = checkNotNull(sizeToRam, "sizeToRam");
this.serverLatestJobCompleted = new RetryablePredicate<Server>(
new ServerLatestJobCompleted(client.getJobServices()),
timeouts.nodeRunning * 9l / 10l);
@ -103,12 +108,12 @@ public class FindIpThenCreateNodeInGroup implements CreateNodeWithGroupEncodedIn
addedServer = Iterables.getOnlyElement(client.getServerServices().getServersByName(
addedServer.getName()));
}
credentialStore.put("node#" + addedServer.getId(),client.getServerServices().getServerCredentialsList().get(addedServer.getName()));
return serverToNodeMetadata.apply(addedServer);
}
private Server addServer(String name, Template template, Ip availableIp) {
Server addedServer;
addedServer = client.getServerServices().addServer(name,
Server addedServer = client.getServerServices().addServer(name,
checkNotNull(template.getImage().getProviderId()),
sizeToRam.apply(template.getHardware()), availableIp.getIp());
return addedServer;

View File

@ -37,14 +37,12 @@ import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.compute.suppliers.GoGridHardwareSupplier;
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;
import com.google.common.base.Suppliers;
@ -61,9 +59,7 @@ public class ServerToNodeMetadataTest {
@SuppressWarnings("unchecked")
@Test
public void testApplySetsTagFromNameAndCredentialsFromName() throws UnknownHostException {
GoGridClient caller = createMock(GoGridClient.class);
GridServerClient client = createMock(GridServerClient.class);
expect(caller.getServerServices()).andReturn(client).atLeastOnce();
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");
@ -82,8 +78,7 @@ public class ServerToNodeMetadataTest {
Map<String, ? extends Location> locations = ImmutableMap.<String, Location> of("1", location);
Map<String, Credentials> credentialsMap = createMock(Map.class);
expect(client.getServerCredentialsList()).andReturn(credentialsMap);
expect(credentialsMap.get("group-ff")).andReturn(new Credentials("user", "pass"));
expect(credentialsMap.get("node#1000")).andReturn(new Credentials("user", "pass"));
expect(server.getIp()).andReturn(new Ip("127.0.0.1"));
@ -96,15 +91,13 @@ public class ServerToNodeMetadataTest {
expect(jcImage.getLocation()).andReturn(location).atLeastOnce();
expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
replay(caller);
replay(client);
replay(serverStateToNodeState);
replay(server);
replay(image);
replay(jcImage);
replay(credentialsMap);
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, caller, Suppliers
ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeState, credentialsMap, Suppliers
.<Set<? extends Image>> ofInstance(images), Suppliers
.<Set<? extends Hardware>> ofInstance(GoGridHardwareSupplier.H_ALL), Suppliers
.<Map<String, ? extends Location>> ofInstance(locations));
@ -115,8 +108,6 @@ public class ServerToNodeMetadataTest {
assertEquals(metadata.getGroup(), "group");
assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
verify(caller);
verify(client);
verify(serverStateToNodeState);
verify(image);
verify(credentialsMap);