JCLOUDS-381. Allow explicit naming of nodes, decouple group identity from instance name.

This commit is contained in:
Andrew Bayer 2013-11-18 10:02:37 -08:00
parent c0ccb55d8c
commit aca161fd96
4 changed files with 21 additions and 8 deletions

View File

@ -17,6 +17,7 @@
package org.jclouds.googlecomputeengine.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.groupFromMapOrName;
import java.net.URI;
import java.util.Map;
@ -77,7 +78,9 @@ public class InstanceInZoneToNodeMetadata implements Function<InstanceInZone, No
Image image = checkNotNull(imagesMap.get(checkNotNull(input.getImage(), "image")),
"no image for %s. images: %s", input.getImage(), imagesMap.values());
String group = nodeNamingConvention.groupInUniqueNameOrNull(input.getName());
String group = groupFromMapOrName(input.getMetadata().getItems(),
input.getName(), nodeNamingConvention);
FluentIterable<String> tags = FluentIterable.from(input.getTags().getItems())
.filter(Predicates.not(firewallTagNamingConvention.get(group).isFirewallTag()));

View File

@ -232,6 +232,14 @@ public class GoogleComputeEngineTemplateOptions extends TemplateOptions {
return GoogleComputeEngineTemplateOptions.class.cast(super.userMetadata(key, value));
}
/**
* {@inheritDoc}
*/
@Override
public GoogleComputeEngineTemplateOptions nodeNames(Iterable<String> nodeNames) {
return GoogleComputeEngineTemplateOptions.class.cast(super.nodeNames(nodeNames));
}
/**
* {@inheritDoc}
*/

View File

@ -31,12 +31,12 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Inject;
import javax.inject.Named;
import com.google.common.collect.Sets;
import org.jclouds.Constants;
import org.jclouds.compute.config.CustomizationResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy;
@ -47,16 +47,16 @@ import org.jclouds.googlecomputeengine.config.UserProject;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.Network;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.features.FirewallApi;
import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
import org.jclouds.googlecomputeengine.features.FirewallApi;
import org.jclouds.googlecomputeengine.options.FirewallOptions;
import org.jclouds.net.domain.IpProtocol;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
@ -124,6 +124,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
Network network = getOrCreateNetwork(templateOptions, sharedResourceName);
getOrCreateFirewalls(templateOptions, network, firewallTagNamingConvention.get(group));
templateOptions.network(network.getSelfLink());
templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group);
return super.execute(group, count, mutableTemplate, goodNodes, badNodes, customizationResponses);
}

View File

@ -19,7 +19,6 @@ package org.jclouds.googlecomputeengine.compute;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.jclouds.googlecomputeengine.features.FirewallApiExpectTest.GET_FIREWALL_REQUEST;
import static org.jclouds.googlecomputeengine.features.GlobalOperationApiExpectTest.GET_GLOBAL_OPERATION_REQUEST;
import static org.jclouds.googlecomputeengine.features.GlobalOperationApiExpectTest.GET_GLOBAL_OPERATION_RESPONSE;
import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_GOOGLE_IMAGES_REQUEST;
@ -162,7 +161,8 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
}
}
private HttpRequest createInstanceRequestForInstance(String instanceName, String networkName, String publicKey) {
private HttpRequest createInstanceRequestForInstance(String instanceName, String groupName,
String networkName, String publicKey) {
return HttpRequest
.builder()
.method("POST")
@ -180,7 +180,8 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
"\"accessConfigs\":[{\"type\":\"ONE_TO_ONE_NAT\"}]}]," +
"\"metadata\":{\"kind\":\"compute#metadata\",\"items\":[{\"key\":\"sshKeys\"," +
"\"value\":\"jclouds:" +
publicKey + " jclouds@localhost\"}]}}",
publicKey + " jclouds@localhost\"},{\"key\":\"jclouds-group\"," +
"\"value\":\"" + groupName + "\"}]}}",
MediaType.APPLICATION_JSON)).build();
}
@ -440,7 +441,7 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
.add(LIST_PROJECT_IMAGES_REQUEST)
.add(LIST_GOOGLE_IMAGES_REQUEST)
.add(LIST_MACHINE_TYPES_REQUEST)
.add(createInstanceRequestForInstance("test-1", "jclouds-test", openSshKey))
.add(createInstanceRequestForInstance("test-1", "test", "jclouds-test", openSshKey))
.add(GET_ZONE_OPERATION_REQUEST)
.add(getInstanceRequestForInstance("test-1"))
.add(SET_TAGS_REQUEST)