revised load balancer code and implemented Issue 254: compute handle

This commit is contained in:
Adrian Cole 2010-05-20 16:32:31 -07:00
parent 0d1d28a972
commit 467f815c17
43 changed files with 881 additions and 990 deletions

View File

@ -20,6 +20,7 @@ package org.jclouds.aws.ec2.compute;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.aws.ec2.util.EC2Utils.parseHandle;
import static org.jclouds.util.Utils.checkNotEmpty; import static org.jclouds.util.Utils.checkNotEmpty;
import java.util.HashSet; import java.util.HashSet;
@ -35,7 +36,6 @@ import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule.GetRegionFromLocation;
import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionAndName;
import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules; import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules;
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions; import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
@ -68,9 +68,9 @@ import com.google.common.collect.Maps;
@Singleton @Singleton
public class EC2ComputeService extends BaseComputeService { public class EC2ComputeService extends BaseComputeService {
private final EC2Client ec2Client; private final EC2Client ec2Client;
private final GetRegionFromLocation getRegionFromLocation;
private final Map<RegionAndName, KeyPair> credentialsMap; private final Map<RegionAndName, KeyPair> credentialsMap;
private final Map<RegionAndName, String> securityGroupMap; private final Map<RegionAndName, String> securityGroupMap;
private final LoadBalancerStrategy loadBalancerStrategy;
@Inject @Inject
protected EC2ComputeService(ComputeServiceContext context, protected EC2ComputeService(ComputeServiceContext context,
@ -79,17 +79,16 @@ public class EC2ComputeService extends BaseComputeService {
GetNodeMetadataStrategy getNodeMetadataStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
LoadBalancerStrategy loadBalancerStrategy,
Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateBuilder> templateBuilderProvider,
Provider<TemplateOptions> templateOptionsProvider, ComputeUtils utils, Provider<TemplateOptions> templateOptionsProvider, ComputeUtils utils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
GetRegionFromLocation getRegionFromLocation, LoadBalancerStrategy loadBalancerStrategy, EC2Client ec2Client,
Map<RegionAndName, KeyPair> credentialsMap, Map<RegionAndName, String> securityGroupMap) { Map<RegionAndName, KeyPair> credentialsMap, Map<RegionAndName, String> securityGroupMap) {
super(context, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy, super(context, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
loadBalancerStrategy, templateBuilderProvider, templateOptionsProvider, utils, executor); templateBuilderProvider, templateOptionsProvider, utils, executor);
this.loadBalancerStrategy = checkNotNull(loadBalancerStrategy, "loadBalancerStrategy");
this.ec2Client = ec2Client; this.ec2Client = ec2Client;
this.getRegionFromLocation = getRegionFromLocation;
this.credentialsMap = credentialsMap; this.credentialsMap = credentialsMap;
this.securityGroupMap = securityGroupMap; this.securityGroupMap = securityGroupMap;
} }
@ -128,62 +127,13 @@ public class EC2ComputeService extends BaseComputeService {
Map<String, String> regionTags = Maps.newHashMap(); Map<String, String> regionTags = Maps.newHashMap();
for (NodeMetadata nodeMetadata : deadOnes) { for (NodeMetadata nodeMetadata : deadOnes) {
if (nodeMetadata.getTag() != null) if (nodeMetadata.getTag() != null)
regionTags.put(getRegionFromLocation.apply(nodeMetadata.getLocation()), nodeMetadata regionTags.put(parseHandle(nodeMetadata.getHandle())[0], nodeMetadata.getTag());
.getTag());
} }
for (Entry<String, String> regionTag : regionTags.entrySet()) { for (Entry<String, String> regionTag : regionTags.entrySet()) {
deleteKeyPair(regionTag.getKey(), regionTag.getValue()); deleteKeyPair(regionTag.getKey(), regionTag.getValue());
deleteSecurityGroup(regionTag.getKey(), regionTag.getValue()); deleteSecurityGroup(regionTag.getKey(), regionTag.getValue());
} }
return deadOnes; return deadOnes;
}
@Override
public String loadBalanceNodesMatching(String loadBalancerName,
String protocol, Integer loadBalancerPort, Integer instancePort,
Predicate<NodeMetadata> filter)
{
checkNotNull(loadBalancerName, "loadBalancerName");
checkNotNull(protocol, "protocol");
checkArgument(protocol.toUpperCase().equals("HTTP")
|| protocol.toUpperCase().equals("TCP"),
"Acceptable values for protocol are HTTP or TCP");
checkNotNull(loadBalancerPort, "loadBalancerPort");
checkNotNull(instancePort, "instancePort");
Location location = null;
Set<String> ids = new HashSet<String>();
for (final NodeMetadata node : Iterables.filter(super
.listNodesDetailsMatching(NodePredicates.all()), Predicates
.and(filter, Predicates.not(NodePredicates.TERMINATED))))
{
ids.add(node.getId());
location = node.getLocation();
}
logger.debug(">> creating load balancer (%s)", loadBalancerName);
String dnsName = loadBalancerStrategy
.execute(location, loadBalancerName, protocol,
loadBalancerPort, instancePort, ids);
logger.debug("<< created load balancer (%s) DNS (%s)",
loadBalancerName, dnsName);
return dnsName;
}
@Override
public void deleteLoadBalancer(String loadBalancerName,
Predicate<NodeMetadata> filter)
{
Location location = Iterables.filter(
super.listNodesDetailsMatching(NodePredicates.all()),
Predicates.and(filter, Predicates
.not(NodePredicates.TERMINATED))).iterator().next()
.getLocation();
ec2Client.getElasticLoadBalancerServices().deleteLoadBalancer(
getRegionFromLocation.apply(location), loadBalancerName);
} }
/** /**
@ -193,4 +143,37 @@ public class EC2ComputeService extends BaseComputeService {
public EC2TemplateOptions templateOptions() { public EC2TemplateOptions templateOptions() {
return EC2TemplateOptions.class.cast(super.templateOptions()); return EC2TemplateOptions.class.cast(super.templateOptions());
} }
@Override
public String loadBalanceNodesMatching(Predicate<NodeMetadata> filter, String loadBalancerName,
String protocol, int loadBalancerPort, int instancePort) {
checkNotNull(loadBalancerName, "loadBalancerName");
checkNotNull(protocol, "protocol");
checkArgument(protocol.toUpperCase().equals("HTTP") || protocol.toUpperCase().equals("TCP"),
"Acceptable values for protocol are HTTP or TCP");
Location location = null;
Set<String> ids = new HashSet<String>();
for (NodeMetadata node : Iterables.filter(super
.listNodesDetailsMatching(NodePredicates.all()), Predicates.and(filter, Predicates
.not(NodePredicates.TERMINATED)))) {
ids.add(node.getId());
location = node.getLocation();
}
logger.debug(">> creating load balancer (%s)", loadBalancerName);
String dnsName = loadBalancerStrategy.execute(location, loadBalancerName, protocol,
loadBalancerPort, instancePort, ids);
logger.debug("<< created load balancer (%s) DNS (%s)", loadBalancerName, dnsName);
return dnsName;
}
@Override
public void deleteLoadBalancer(String loadBalancerName, Predicate<NodeMetadata> filter) {
String region = parseHandle(Iterables.get(
Iterables.filter(super.listNodesDetailsMatching(NodePredicates.all()), Predicates
.and(filter, Predicates.not(NodePredicates.TERMINATED))), 0).getHandle())[0];
ec2Client.getElasticLoadBalancerServices().deleteLoadBalancerInRegion(region,
loadBalancerName);
}
} }

View File

@ -18,9 +18,10 @@
*/ */
package org.jclouds.aws.ec2.compute.config; package org.jclouds.aws.ec2.compute.config;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.aws.ec2.options.DescribeImagesOptions.Builder.ownedBy; import static org.jclouds.aws.ec2.options.DescribeImagesOptions.Builder.ownedBy;
import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; import static org.jclouds.aws.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
import static org.jclouds.aws.ec2.util.EC2Utils.getAllRunningInstancesInRegion;
import static org.jclouds.aws.ec2.util.EC2Utils.parseHandle;
import static org.jclouds.compute.domain.OsFamily.UBUNTU; import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import static org.jclouds.concurrent.ConcurrentUtils.awaitCompletion; import static org.jclouds.concurrent.ConcurrentUtils.awaitCompletion;
@ -126,12 +127,12 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class); bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
bind(TemplateOptions.class).to(EC2TemplateOptions.class); bind(TemplateOptions.class).to(EC2TemplateOptions.class);
bind(ComputeService.class).to(EC2ComputeService.class); bind(ComputeService.class).to(EC2ComputeService.class);
bind(LoadBalancerStrategy.class).to(EC2LoadBalancerStrategy.class);
bind(RunNodesAndAddToSetStrategy.class).to(EC2RunNodesAndAddToSetStrategy.class); bind(RunNodesAndAddToSetStrategy.class).to(EC2RunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(EC2ListNodesStrategy.class); bind(ListNodesStrategy.class).to(EC2ListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(EC2GetNodeMetadataStrategy.class); bind(GetNodeMetadataStrategy.class).to(EC2GetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class); bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class);
bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class); bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class);
bind(LoadBalancerStrategy.class).to(EC2LoadBalancerStrategy.class);
bind(new TypeLiteral<Function<RunningInstance, Map<String, String>>>() { bind(new TypeLiteral<Function<RunningInstance, Map<String, String>>>() {
}).annotatedWith(Jsr330.named("volumeMapping")).to(RunningInstanceToStorageMappingUnix.class) }).annotatedWith(Jsr330.named("volumeMapping")).to(RunningInstanceToStorageMappingUnix.class)
.in(Scopes.SINGLETON); .in(Scopes.SINGLETON);
@ -214,61 +215,45 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
} }
} }
@Singleton
public static class GetRegionFromLocation implements Function<Location, String> {
public String apply(Location location) {
String region = location.getScope() == LocationScope.REGION ? location.getId() : location
.getParent().getId();
return region;
}
}
@Singleton @Singleton
public static class EC2GetNodeMetadataStrategy implements GetNodeMetadataStrategy { public static class EC2GetNodeMetadataStrategy implements GetNodeMetadataStrategy {
private final InstanceClient client; private final InstanceClient client;
private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata; private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
private final GetRegionFromLocation getRegionFromLocation;
@Inject @Inject
protected EC2GetNodeMetadataStrategy(InstanceClient client, protected EC2GetNodeMetadataStrategy(InstanceClient client,
GetRegionFromLocation getRegionFromLocation,
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) { RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) {
this.client = client; this.client = client;
this.getRegionFromLocation = getRegionFromLocation;
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata; this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
} }
@Override @Override
public NodeMetadata execute(Location location, String id) { public NodeMetadata execute(String handle) {
String region = getRegionFromLocation.apply(checkNotNull(location, "location")); String[] parts = parseHandle(handle);
String region = parts[0];
String id = parts[1];
RunningInstance runningInstance = Iterables.getOnlyElement(getAllRunningInstancesInRegion( RunningInstance runningInstance = Iterables.getOnlyElement(getAllRunningInstancesInRegion(
client, region, checkNotNull(id, "id"))); client, region, id));
return runningInstanceToNodeMetadata.apply(runningInstance); return runningInstanceToNodeMetadata.apply(runningInstance);
} }
} }
public static Iterable<RunningInstance> getAllRunningInstancesInRegion(InstanceClient client,
String region, String id) {
return Iterables.concat(client.describeInstancesInRegion(region, id));
}
@Singleton @Singleton
public static class EC2RebootNodeStrategy implements RebootNodeStrategy { public static class EC2RebootNodeStrategy implements RebootNodeStrategy {
private final InstanceClient client; private final InstanceClient client;
private final GetRegionFromLocation getRegionFromLocation;
@Inject @Inject
protected EC2RebootNodeStrategy(InstanceClient client, protected EC2RebootNodeStrategy(InstanceClient client) {
GetRegionFromLocation getRegionFromLocation) {
this.client = client; this.client = client;
this.getRegionFromLocation = getRegionFromLocation;
} }
@Override @Override
public boolean execute(Location location, String id) { public boolean execute(String handle) {
String region = getRegionFromLocation.apply(location); String[] parts = parseHandle(handle);
String region = parts[0];
String id = parts[1];
client.rebootInstancesInRegion(region, id); client.rebootInstancesInRegion(region, id);
return true; return true;
} }

View File

@ -36,9 +36,8 @@ public class EC2Size extends SizeImpl {
EC2Size(String instanceType, Double cores, Integer ram, Integer disk, EC2Size(String instanceType, Double cores, Integer ram, Integer disk,
Iterable<Architecture> supportedArchitectures) { Iterable<Architecture> supportedArchitectures) {
super(instanceType, super(instanceType, instanceType, instanceType, null, null, ImmutableMap
instanceType, null, null, .<String, String> of(), cores, ram, disk, supportedArchitectures);
ImmutableMap.<String, String> of(),cores, ram, disk, supportedArchitectures);
this.instanceType = instanceType; this.instanceType = instanceType;
} }

View File

@ -140,6 +140,7 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
return new ImageImpl( return new ImageImpl(
from.getId(), from.getId(),
name, name,
from.getRegion() + "/" + from.getId(),
location, location,
null, null,
ImmutableMap.<String, String> of("owner", from.getImageOwnerId()), ImmutableMap.<String, String> of("owner", from.getImageOwnerId()),

View File

@ -170,8 +170,9 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
Image image = resolveImageForInstanceInLocation(instance, location); Image image = resolveImageForInstanceInLocation(instance, location);
return new NodeMetadataImpl(id, name, location, uri, userMetadata, tag, image, state, return new NodeMetadataImpl(id, name, instance.getRegion() + "/" + instance.getId(),
publicAddresses, privateAddresses, extra, credentials); location, uri, userMetadata, tag, image, state, publicAddresses, privateAddresses,
extra, credentials);
} }
private Credentials getCredentialsForInstanceWithTag(final RunningInstance instance, String tag) { private Credentials getCredentialsForInstanceWithTag(final RunningInstance instance, String tag) {

View File

@ -19,18 +19,18 @@
package org.jclouds.aws.ec2.compute.strategy; package org.jclouds.aws.ec2.compute.strategy;
import static org.jclouds.aws.ec2.util.EC2Utils.parseHandle;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule.GetRegionFromLocation;
import org.jclouds.aws.ec2.domain.RunningInstance; import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.domain.Location;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -47,23 +47,22 @@ public class EC2DestroyNodeStrategy implements DestroyNodeStrategy {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final EC2Client ec2Client; protected final EC2Client ec2Client;
protected final Predicate<RunningInstance> instanceStateTerminated; protected final Predicate<RunningInstance> instanceStateTerminated;
protected final GetRegionFromLocation getRegionFromLocation;
protected final GetNodeMetadataStrategy getNodeMetadataStrategy; protected final GetNodeMetadataStrategy getNodeMetadataStrategy;
@Inject @Inject
protected EC2DestroyNodeStrategy(EC2Client ec2Client, protected EC2DestroyNodeStrategy(EC2Client ec2Client,
@Named("TERMINATED") Predicate<RunningInstance> instanceStateTerminated, @Named("TERMINATED") Predicate<RunningInstance> instanceStateTerminated,
GetRegionFromLocation getRegionFromLocation,
GetNodeMetadataStrategy getNodeMetadataStrategy) { GetNodeMetadataStrategy getNodeMetadataStrategy) {
this.ec2Client = ec2Client; this.ec2Client = ec2Client;
this.instanceStateTerminated = instanceStateTerminated; this.instanceStateTerminated = instanceStateTerminated;
this.getRegionFromLocation = getRegionFromLocation;
this.getNodeMetadataStrategy = getNodeMetadataStrategy; this.getNodeMetadataStrategy = getNodeMetadataStrategy;
} }
@Override @Override
public boolean execute(Location location, String id) { public boolean execute(String handle) {
String region = getRegionFromLocation.apply(location); String[] parts = parseHandle(handle);
String region = parts[0];
String id = parts[1];
ec2Client.getInstanceServices().terminateInstancesInRegion(region, id); ec2Client.getInstanceServices().terminateInstancesInRegion(region, id);
return instanceStateTerminated.apply(Iterables.getOnlyElement(Iterables.concat(ec2Client return instanceStateTerminated.apply(Iterables.getOnlyElement(Iterables.concat(ec2Client
.getInstanceServices().describeInstancesInRegion(region, id)))); .getInstanceServices().describeInstancesInRegion(region, id))));

View File

@ -29,9 +29,9 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.config.EC2ComputeServiceContextModule.GetRegionFromLocation;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.services.ElasticLoadBalancerClient; import org.jclouds.aws.ec2.services.ElasticLoadBalancerClient;
import org.jclouds.aws.ec2.util.EC2Utils.GetRegionFromLocation;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.LoadBalancerStrategy; import org.jclouds.compute.strategy.LoadBalancerStrategy;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -42,8 +42,7 @@ import org.jclouds.logging.Logger;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class EC2LoadBalancerStrategy implements LoadBalancerStrategy public class EC2LoadBalancerStrategy implements LoadBalancerStrategy {
{
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -51,58 +50,49 @@ public class EC2LoadBalancerStrategy implements LoadBalancerStrategy
protected final GetRegionFromLocation getRegionFromLocation; protected final GetRegionFromLocation getRegionFromLocation;
@Inject @Inject
protected EC2LoadBalancerStrategy(EC2Client ec2Client, GetRegionFromLocation getRegionFromLocation) protected EC2LoadBalancerStrategy(EC2Client ec2Client,
{ GetRegionFromLocation getRegionFromLocation) {
this.ec2Client = ec2Client; this.ec2Client = ec2Client;
this.getRegionFromLocation = getRegionFromLocation; this.getRegionFromLocation = getRegionFromLocation;
} }
@Override @Override
public String execute(Location location, String name, public String execute(Location location, String name, String protocol, int loadBalancerPort,
String protocol, Integer loadBalancerPort, Integer instancePort, int instancePort, Set<String> instanceIds) {
Set<String> instanceIds)
{
String region = getRegionFromLocation.apply(location); String region = getRegionFromLocation.apply(location);
String dnsName = new String(); String dnsName = new String();
// TODO: Fix temp hack // TODO: Fix temp hack
String availabilityZone = new String(); String availabilityZone = new String();
for (String az : AvailabilityZone.zones) for (String az : AvailabilityZone.zones) {
{
if (az.startsWith(region)) if (az.startsWith(region))
availabilityZone = az; availabilityZone = az;
} }
ElasticLoadBalancerClient elbClient = ec2Client ElasticLoadBalancerClient elbClient = ec2Client.getElasticLoadBalancerServices();
.getElasticLoadBalancerServices();
dnsName = elbClient.createLoadBalancer(region, name, protocol, dnsName = elbClient.createLoadBalancerInRegion(region, name, protocol, loadBalancerPort,
loadBalancerPort, instancePort, availabilityZone); instancePort, availabilityZone);
List<String> instanceIdlist = new ArrayList<String>(instanceIds); List<String> instanceIdlist = new ArrayList<String>(instanceIds);
String[] instanceIdArray = new String[instanceIdlist.size()]; String[] instanceIdArray = new String[instanceIdlist.size()];
for(int i=0; i<instanceIdlist.size(); i++) for (int i = 0; i < instanceIdlist.size(); i++) {
{
instanceIdArray[i] = instanceIdlist.get(i); instanceIdArray[i] = instanceIdlist.get(i);
} }
Set<String> registeredInstanceIds = elbClient Set<String> registeredInstanceIds = elbClient.registerInstancesWithLoadBalancerInRegion(
.registerInstancesWithLoadBalancer(region, name, region, name, instanceIdArray);
instanceIdArray);
// deregister instances // deregister instances
boolean changed = registeredInstanceIds.removeAll(instanceIds); boolean changed = registeredInstanceIds.removeAll(instanceIds);
if (changed) if (changed) {
{
List<String> list = new ArrayList<String>(registeredInstanceIds); List<String> list = new ArrayList<String>(registeredInstanceIds);
instanceIdArray = new String[list.size()]; instanceIdArray = new String[list.size()];
for(int i=0; i<list.size(); i++) for (int i = 0; i < list.size(); i++) {
{
instanceIdArray[i] = list.get(i); instanceIdArray[i] = list.get(i);
} }
if(instanceIdArray.length>0) if (instanceIdArray.length > 0)
elbClient.deregisterInstancesWithLoadBalancer(region, name, elbClient.deregisterInstancesWithLoadBalancerInRegion(region, name, instanceIdArray);
instanceIdArray);
} }
return dnsName; return dnsName;

View File

@ -1,12 +1,33 @@
/**
*
* 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.aws.ec2.domain; package org.jclouds.aws.ec2.domain;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
/**
public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer> *
{ *
* @author Lili Nader
*/
public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer> {
private String region; private String region;
private String name; private String name;
@ -17,18 +38,15 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
private LBCookieStickinessPolicy lBCookieStickinessPolicy; private LBCookieStickinessPolicy lBCookieStickinessPolicy;
private Set<LoadBalancerListener> loadBalancerListeners; private Set<LoadBalancerListener> loadBalancerListeners;
public ElasticLoadBalancer() public ElasticLoadBalancer() {
{
super(); super();
this.instanceIds = new HashSet<String>(); this.instanceIds = new HashSet<String>();
this.availabilityZones = new HashSet<String>(); this.availabilityZones = new HashSet<String>();
this.loadBalancerListeners = new HashSet<LoadBalancerListener>(); this.loadBalancerListeners = new HashSet<LoadBalancerListener>();
} }
public ElasticLoadBalancer(String region, String name, public ElasticLoadBalancer(String region, String name, Set<String> instanceIds,
Set<String> instanceIds, Set<String> availabilityZones, Set<String> availabilityZones, String dnsName) {
String dnsName)
{
super(); super();
this.region = region; this.region = region;
this.name = name; this.name = name;
@ -38,128 +56,95 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
this.loadBalancerListeners = new HashSet<LoadBalancerListener>(); this.loadBalancerListeners = new HashSet<LoadBalancerListener>();
} }
public void setRegion(String region) {
public void setRegion(String region)
{
this.region = region; this.region = region;
} }
public void setName(String name) public void setName(String name) {
{
this.name = name; this.name = name;
} }
public void setInstanceIds(Set<String> instanceIds) public void setInstanceIds(Set<String> instanceIds) {
{
this.instanceIds = instanceIds; this.instanceIds = instanceIds;
} }
public void setAvailabilityZones(Set<String> availabilityZones) public void setAvailabilityZones(Set<String> availabilityZones) {
{
this.availabilityZones = availabilityZones; this.availabilityZones = availabilityZones;
} }
public void setDnsName(String dnsName) public void setDnsName(String dnsName) {
{
this.dnsName = dnsName; this.dnsName = dnsName;
} }
public void setAppCookieStickinessPolicy( public void setAppCookieStickinessPolicy(AppCookieStickinessPolicy appCookieStickinessPolicy) {
AppCookieStickinessPolicy appCookieStickinessPolicy)
{
this.appCookieStickinessPolicy = appCookieStickinessPolicy; this.appCookieStickinessPolicy = appCookieStickinessPolicy;
} }
public void setlBCookieStickinessPolicy( public void setlBCookieStickinessPolicy(LBCookieStickinessPolicy lBCookieStickinessPolicy) {
LBCookieStickinessPolicy lBCookieStickinessPolicy)
{
this.lBCookieStickinessPolicy = lBCookieStickinessPolicy; this.lBCookieStickinessPolicy = lBCookieStickinessPolicy;
} }
public void setLoadBalancerListeners( public void setLoadBalancerListeners(Set<LoadBalancerListener> loadBalancerListeners) {
Set<LoadBalancerListener> loadBalancerListeners)
{
this.loadBalancerListeners = loadBalancerListeners; this.loadBalancerListeners = loadBalancerListeners;
} }
public String getName() public String getName() {
{
return name; return name;
} }
public Set<String> getInstanceIds() public Set<String> getInstanceIds() {
{
return instanceIds; return instanceIds;
} }
public Set<String> getAvailabilityZones() public Set<String> getAvailabilityZones() {
{
return availabilityZones; return availabilityZones;
} }
public String getDnsName() public String getDnsName() {
{
return dnsName; return dnsName;
} }
public AppCookieStickinessPolicy getAppCookieStickinessPolicy() public AppCookieStickinessPolicy getAppCookieStickinessPolicy() {
{
return appCookieStickinessPolicy; return appCookieStickinessPolicy;
} }
public LBCookieStickinessPolicy getlBCookieStickinessPolicy() public LBCookieStickinessPolicy getlBCookieStickinessPolicy() {
{
return lBCookieStickinessPolicy; return lBCookieStickinessPolicy;
} }
public Set<LoadBalancerListener> getLoadBalancerListeners() public Set<LoadBalancerListener> getLoadBalancerListeners() {
{
return loadBalancerListeners; return loadBalancerListeners;
} }
public String getRegion() public String getRegion() {
{
return region; return region;
} }
@Override @Override
public int compareTo(ElasticLoadBalancer that) public int compareTo(ElasticLoadBalancer that) {
{
return name.compareTo(that.name); return name.compareTo(that.name);
} }
@Override @Override
public int hashCode() public int hashCode() {
{
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime
* result
+ ((appCookieStickinessPolicy == null) ? 0
: appCookieStickinessPolicy.hashCode());
result = prime
* result
+ ((availabilityZones == null) ? 0 : availabilityZones
.hashCode());
result = prime * result + ((dnsName == null) ? 0 : dnsName.hashCode());
result = prime * result result = prime * result
+ ((instanceIds == null) ? 0 : instanceIds.hashCode()); + ((appCookieStickinessPolicy == null) ? 0 : appCookieStickinessPolicy.hashCode());
result = prime result = prime * result + ((availabilityZones == null) ? 0 : availabilityZones.hashCode());
* result result = prime * result + ((dnsName == null) ? 0 : dnsName.hashCode());
+ ((lBCookieStickinessPolicy == null) ? 0 result = prime * result + ((instanceIds == null) ? 0 : instanceIds.hashCode());
: lBCookieStickinessPolicy.hashCode()); result = prime * result
result = prime + ((lBCookieStickinessPolicy == null) ? 0 : lBCookieStickinessPolicy.hashCode());
* result result = prime * result
+ ((loadBalancerListeners == null) ? 0 : loadBalancerListeners + ((loadBalancerListeners == null) ? 0 : loadBalancerListeners.hashCode());
.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((region == null) ? 0 : region.hashCode()); result = prime * result + ((region == null) ? 0 : region.hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (obj == null)
@ -167,125 +152,90 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
ElasticLoadBalancer other = (ElasticLoadBalancer) obj; ElasticLoadBalancer other = (ElasticLoadBalancer) obj;
if (appCookieStickinessPolicy == null) if (appCookieStickinessPolicy == null) {
{
if (other.appCookieStickinessPolicy != null) if (other.appCookieStickinessPolicy != null)
return false; return false;
} } else if (!appCookieStickinessPolicy.equals(other.appCookieStickinessPolicy))
else if (!appCookieStickinessPolicy
.equals(other.appCookieStickinessPolicy))
return false; return false;
if (availabilityZones == null) if (availabilityZones == null) {
{
if (other.availabilityZones != null) if (other.availabilityZones != null)
return false; return false;
} } else if (!availabilityZones.equals(other.availabilityZones))
else if (!availabilityZones.equals(other.availabilityZones))
return false; return false;
if (dnsName == null) if (dnsName == null) {
{
if (other.dnsName != null) if (other.dnsName != null)
return false; return false;
} } else if (!dnsName.equals(other.dnsName))
else if (!dnsName.equals(other.dnsName))
return false; return false;
if (instanceIds == null) if (instanceIds == null) {
{
if (other.instanceIds != null) if (other.instanceIds != null)
return false; return false;
} } else if (!instanceIds.equals(other.instanceIds))
else if (!instanceIds.equals(other.instanceIds))
return false; return false;
if (lBCookieStickinessPolicy == null) if (lBCookieStickinessPolicy == null) {
{
if (other.lBCookieStickinessPolicy != null) if (other.lBCookieStickinessPolicy != null)
return false; return false;
} } else if (!lBCookieStickinessPolicy.equals(other.lBCookieStickinessPolicy))
else if (!lBCookieStickinessPolicy
.equals(other.lBCookieStickinessPolicy))
return false; return false;
if (loadBalancerListeners == null) if (loadBalancerListeners == null) {
{
if (other.loadBalancerListeners != null) if (other.loadBalancerListeners != null)
return false; return false;
} } else if (!loadBalancerListeners.equals(other.loadBalancerListeners))
else if (!loadBalancerListeners.equals(other.loadBalancerListeners))
return false; return false;
if (name == null) if (name == null) {
{
if (other.name != null) if (other.name != null)
return false; return false;
} } else if (!name.equals(other.name))
else if (!name.equals(other.name))
return false; return false;
if (region == null) if (region == null) {
{
if (other.region != null) if (other.region != null)
return false; return false;
} } else if (!region.equals(other.region))
else if (!region.equals(other.region))
return false; return false;
return true; return true;
} }
public static class AppCookieStickinessPolicy {
public static class AppCookieStickinessPolicy
{
private String policyName; private String policyName;
private String cookieName; private String cookieName;
public AppCookieStickinessPolicy() {
public AppCookieStickinessPolicy()
{
super(); super();
} }
public AppCookieStickinessPolicy(String policyName, String cookieName) public AppCookieStickinessPolicy(String policyName, String cookieName) {
{
super(); super();
this.policyName = policyName; this.policyName = policyName;
this.cookieName = cookieName; this.cookieName = cookieName;
} }
public String getPolicyName() public String getPolicyName() {
{
return policyName; return policyName;
} }
public String getCookieName() public String getCookieName() {
{
return cookieName; return cookieName;
} }
public void setPolicyName(String policyName) public void setPolicyName(String policyName) {
{
this.policyName = policyName; this.policyName = policyName;
} }
public void setCookieName(String cookieName) public void setCookieName(String cookieName) {
{
this.cookieName = cookieName; this.cookieName = cookieName;
} }
@Override @Override
public int hashCode() public int hashCode() {
{
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result result = prime * result + ((cookieName == null) ? 0 : cookieName.hashCode());
+ ((cookieName == null) ? 0 : cookieName.hashCode()); result = prime * result + ((policyName == null) ? 0 : policyName.hashCode());
result = prime * result
+ ((policyName == null) ? 0 : policyName.hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (obj == null)
@ -293,82 +243,63 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
AppCookieStickinessPolicy other = (AppCookieStickinessPolicy) obj; AppCookieStickinessPolicy other = (AppCookieStickinessPolicy) obj;
if (cookieName == null) if (cookieName == null) {
{
if (other.cookieName != null) if (other.cookieName != null)
return false; return false;
} } else if (!cookieName.equals(other.cookieName))
else if (!cookieName.equals(other.cookieName))
return false; return false;
if (policyName == null) if (policyName == null) {
{
if (other.policyName != null) if (other.policyName != null)
return false; return false;
} } else if (!policyName.equals(other.policyName))
else if (!policyName.equals(other.policyName))
return false; return false;
return true; return true;
} }
} }
public static class LBCookieStickinessPolicy public static class LBCookieStickinessPolicy {
{
private String policyName; private String policyName;
private Integer cookieExpirationPeriod; private Integer cookieExpirationPeriod;
public LBCookieStickinessPolicy() public LBCookieStickinessPolicy() {
{
super(); super();
} }
public LBCookieStickinessPolicy(String policyName, public LBCookieStickinessPolicy(String policyName, Integer cookieExpirationPeriod) {
Integer cookieExpirationPeriod)
{
super(); super();
this.policyName = policyName; this.policyName = policyName;
this.cookieExpirationPeriod = cookieExpirationPeriod; this.cookieExpirationPeriod = cookieExpirationPeriod;
} }
public String getPolicyName() public String getPolicyName() {
{
return policyName; return policyName;
} }
public Integer getCookieExpirationPeriod() public Integer getCookieExpirationPeriod() {
{
return cookieExpirationPeriod; return cookieExpirationPeriod;
} }
public void setPolicyName(String policyName) public void setPolicyName(String policyName) {
{
this.policyName = policyName; this.policyName = policyName;
} }
public void setCookieExpirationPeriod(Integer cookieExpirationPeriod) public void setCookieExpirationPeriod(Integer cookieExpirationPeriod) {
{
this.cookieExpirationPeriod = cookieExpirationPeriod; this.cookieExpirationPeriod = cookieExpirationPeriod;
} }
@Override @Override
public int hashCode() public int hashCode() {
{
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime
* result
+ ((cookieExpirationPeriod == null) ? 0
: cookieExpirationPeriod.hashCode());
result = prime * result result = prime * result
+ ((policyName == null) ? 0 : policyName.hashCode()); + ((cookieExpirationPeriod == null) ? 0 : cookieExpirationPeriod.hashCode());
result = prime * result + ((policyName == null) ? 0 : policyName.hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (obj == null)
@ -376,38 +307,29 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
LBCookieStickinessPolicy other = (LBCookieStickinessPolicy) obj; LBCookieStickinessPolicy other = (LBCookieStickinessPolicy) obj;
if (cookieExpirationPeriod == null) if (cookieExpirationPeriod == null) {
{
if (other.cookieExpirationPeriod != null) if (other.cookieExpirationPeriod != null)
return false; return false;
} } else if (!cookieExpirationPeriod.equals(other.cookieExpirationPeriod))
else if (!cookieExpirationPeriod
.equals(other.cookieExpirationPeriod))
return false; return false;
if (policyName == null) if (policyName == null) {
{
if (other.policyName != null) if (other.policyName != null)
return false; return false;
} } else if (!policyName.equals(other.policyName))
else if (!policyName.equals(other.policyName))
return false; return false;
return true; return true;
} }
} }
public static class LoadBalancerListener public static class LoadBalancerListener {
{
private Set<String> policyNames; private Set<String> policyNames;
private Integer instancePort; private Integer instancePort;
private Integer loadBalancerPort; private Integer loadBalancerPort;
private String protocol; private String protocol;
public LoadBalancerListener(Set<String> policyNames, public LoadBalancerListener(Set<String> policyNames, Integer instancePort,
Integer instancePort, Integer loadBalancerPort, String protocol) Integer loadBalancerPort, String protocol) {
{
super(); super();
this.policyNames = policyNames; this.policyNames = policyNames;
this.instancePort = instancePort; this.instancePort = instancePort;
@ -415,72 +337,55 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
this.protocol = protocol; this.protocol = protocol;
} }
public LoadBalancerListener() public LoadBalancerListener() {
{
super(); super();
} }
public Set<String> getPolicyNames() public Set<String> getPolicyNames() {
{
return policyNames; return policyNames;
} }
public Integer getInstancePort() public Integer getInstancePort() {
{
return instancePort; return instancePort;
} }
public Integer getLoadBalancerPort() public Integer getLoadBalancerPort() {
{
return loadBalancerPort; return loadBalancerPort;
} }
public String getProtocol() public String getProtocol() {
{
return protocol; return protocol;
} }
public void setPolicyNames(Set<String> policyNames) public void setPolicyNames(Set<String> policyNames) {
{
this.policyNames = policyNames; this.policyNames = policyNames;
} }
public void setInstancePort(Integer instancePort) public void setInstancePort(Integer instancePort) {
{
this.instancePort = instancePort; this.instancePort = instancePort;
} }
public void setLoadBalancerPort(Integer loadBalancerPort) public void setLoadBalancerPort(Integer loadBalancerPort) {
{
this.loadBalancerPort = loadBalancerPort; this.loadBalancerPort = loadBalancerPort;
} }
public void setProtocol(String protocol) public void setProtocol(String protocol) {
{
this.protocol = protocol; this.protocol = protocol;
} }
@Override @Override
public int hashCode() public int hashCode() {
{
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result result = prime * result + ((instancePort == null) ? 0 : instancePort.hashCode());
+ ((instancePort == null) ? 0 : instancePort.hashCode()); result = prime * result + ((loadBalancerPort == null) ? 0 : loadBalancerPort.hashCode());
result = prime result = prime * result + ((policyNames == null) ? 0 : policyNames.hashCode());
* result result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
+ ((loadBalancerPort == null) ? 0 : loadBalancerPort
.hashCode());
result = prime * result
+ ((policyNames == null) ? 0 : policyNames.hashCode());
result = prime * result
+ ((protocol == null) ? 0 : protocol.hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj) {
{
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (obj == null)
@ -488,38 +393,28 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
LoadBalancerListener other = (LoadBalancerListener) obj; LoadBalancerListener other = (LoadBalancerListener) obj;
if (instancePort == null) if (instancePort == null) {
{
if (other.instancePort != null) if (other.instancePort != null)
return false; return false;
} } else if (!instancePort.equals(other.instancePort))
else if (!instancePort.equals(other.instancePort))
return false; return false;
if (loadBalancerPort == null) if (loadBalancerPort == null) {
{
if (other.loadBalancerPort != null) if (other.loadBalancerPort != null)
return false; return false;
} } else if (!loadBalancerPort.equals(other.loadBalancerPort))
else if (!loadBalancerPort.equals(other.loadBalancerPort))
return false; return false;
if (policyNames == null) if (policyNames == null) {
{
if (other.policyNames != null) if (other.policyNames != null)
return false; return false;
} } else if (!policyNames.equals(other.policyNames))
else if (!policyNames.equals(other.policyNames))
return false; return false;
if (protocol == null) if (protocol == null) {
{
if (other.protocol != null) if (other.protocol != null)
return false; return false;
} } else if (!protocol.equals(other.protocol))
else if (!protocol.equals(other.protocol))
return false; return false;
return true; return true;
} }
} }
} }

View File

@ -53,64 +53,63 @@ import com.google.common.util.concurrent.ListenableFuture;
@RequestFilters(FormSigner.class) @RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "2009-11-25") @FormParams(keys = VERSION, values = "2009-11-25")
@VirtualHost @VirtualHost
public interface ElasticLoadBalancerAsyncClient public interface ElasticLoadBalancerAsyncClient {
{
/** /**
* @see ElasticLoadBalancerClient#createLoadBalancer * @see ElasticLoadBalancerClient#createLoadBalancerInRegion
*/ */
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(CreateLoadBalancerResponseHandler.class) @XMLResponseParser(CreateLoadBalancerResponseHandler.class)
@FormParams(keys = ACTION, values = "CreateLoadBalancer") @FormParams(keys = ACTION, values = "CreateLoadBalancer")
ListenableFuture<String> createLoadBalancer( ListenableFuture<String> createLoadBalancerInRegion(
@EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name, @FormParam("LoadBalancerName") String name,
@FormParam("Listeners.member.1.Protocol") String protocol, @FormParam("Listeners.member.1.Protocol") String protocol,
@FormParam("Listeners.member.1.LoadBalancerPort") Integer loadBalancerPort, @FormParam("Listeners.member.1.LoadBalancerPort") int loadBalancerPort,
@FormParam("Listeners.member.1.InstancePort") Integer instancePort, @FormParam("Listeners.member.1.InstancePort") int instancePort,
@FormParam("AvailabilityZones.member.1") String availabilityZone); @FormParam("AvailabilityZones.member.1") String availabilityZone);
/** /**
* @see ElasticLoadBalancerClient#deleteLoadBalancer * @see ElasticLoadBalancerClient#deleteLoadBalancerInRegion
*/ */
@POST @POST
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "DeleteLoadBalancer") @FormParams(keys = ACTION, values = "DeleteLoadBalancer")
ListenableFuture<Void> deleteLoadBalancer( ListenableFuture<Void> deleteLoadBalancerInRegion(
@EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name); @FormParam("LoadBalancerName") String name);
/** /**
* @see ElasticLoadBalancerClient#registerInstancesWithLoadBalancer * @see ElasticLoadBalancerClient#registerInstancesWithLoadBalancerInRegion
*/ */
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(RegisterInstancesWithLoadBalancerResponseHandler.class) @XMLResponseParser(RegisterInstancesWithLoadBalancerResponseHandler.class)
@FormParams(keys = ACTION, values = "RegisterInstancesWithLoadBalancer") @FormParams(keys = ACTION, values = "RegisterInstancesWithLoadBalancer")
ListenableFuture<? extends Set<String>> registerInstancesWithLoadBalancer( ListenableFuture<? extends Set<String>> registerInstancesWithLoadBalancerInRegion(
@EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name, @FormParam("LoadBalancerName") String name,
@BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds); @BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds);
/** /**
* @see ElasticLoadBalancerClient#deregisterInstancesWithLoadBalancer * @see ElasticLoadBalancerClient#deregisterInstancesWithLoadBalancerInRegion
*/ */
@POST @POST
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "DeregisterInstancesFromLoadBalancer") @FormParams(keys = ACTION, values = "DeregisterInstancesFromLoadBalancer")
ListenableFuture<Void> deregisterInstancesWithLoadBalancer( ListenableFuture<Void> deregisterInstancesWithLoadBalancerInRegion(
@EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") String name, @FormParam("LoadBalancerName") String name,
@BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds); @BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds);
/** /**
* @see ElasticLoadBalancerClient#describeLoadBalancers * @see ElasticLoadBalancerClient#describeLoadBalancersInRegion
*/ */
@POST @POST
@Path("/") @Path("/")
@XMLResponseParser(DescribeLoadBalancersResponseHandler.class) @XMLResponseParser(DescribeLoadBalancersResponseHandler.class)
@FormParams(keys = ACTION, values = "DescribeLoadBalancers") @FormParams(keys = ACTION, values = "DescribeLoadBalancers")
ListenableFuture<? extends Set<ElasticLoadBalancer>> describeLoadBalancers( ListenableFuture<? extends Set<ElasticLoadBalancer>> describeLoadBalancersInRegion(
@EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region,
@FormParam("LoadBalancerName") @Nullable String name); @FormParam("LoadBalancerName") @Nullable String name);

View File

@ -38,44 +38,60 @@ public interface ElasticLoadBalancerClient {
/** /**
* Creates a load balancer * Creates a load balancer
* *
* @param name Name of the load balancer * @param name
* @param loadBalancerPort Port for the load balancer to listen on * Name of the load balancer
* @param instancePort Port to forward the request to * @param loadBalancerPort
* Port for the load balancer to listen on
* @param instancePort
* Port to forward the request to
* @return dns the DNS name for the load balancer * @return dns the DNS name for the load balancer
* @see <a href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/DeveloperGuide/" * @see <a href="http://docs.amazonwebservices.com/ElasticLoadBalancing/latest/DeveloperGuide/"
*/ */
String createLoadBalancer(@Nullable String region, String name, String protocol, Integer loadBalancerPort, Integer instancePort, String availabilityZone); String createLoadBalancerInRegion(@Nullable String region, String name, String protocol,
int loadBalancerPort, int instancePort, String availabilityZone);
/** /**
* Delete load balancer * Delete load balancer
* *
* @param name Name of the load balancer * @param name
* Name of the load balancer
* @return * @return
* @see <a href="http://docs.amazonwebservices.com/ElasticLoadBalancing/2009-05-15/DeveloperGuide/" * @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/2009-05-15/DeveloperGuide/"
*/ */
void deleteLoadBalancer(@Nullable String region, String name); void deleteLoadBalancerInRegion(@Nullable String region, String name);
/** /**
* Register instances with an existing load balancer * Register instances with an existing load balancer
* @param name Load Balancer name *
* @param instanceIds Set of instance Ids to register with load balancer * @param name
* Load Balancer name
* @param instanceIds
* Set of instance Ids to register with load balancer
* @return instanceIds registered with load balancer * @return instanceIds registered with load balancer
* *
* @see <a href="http://docs.amazonwebservices.com/ElasticLoadBalancing/2009-05-15/DeveloperGuide/" * @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/2009-05-15/DeveloperGuide/"
*/ */
Set<String> registerInstancesWithLoadBalancer(@Nullable String region, String name, String... instanceIds); Set<String> registerInstancesWithLoadBalancerInRegion(@Nullable String region, String name,
String... instanceIds);
/** /**
* Deregister instances with an existing load balancer * Deregister instances with an existing load balancer
* @param name Load Balancer name *
* @param instanceIds Set of instance Ids to deregister with load balancer * @param name
* Load Balancer name
* @param instanceIds
* Set of instance Ids to deregister with load balancer
* @return * @return
* *
* @see <a href="http://docs.amazonwebservices.com/ElasticLoadBalancing/2009-05-15/DeveloperGuide/" * @see <a
* href="http://docs.amazonwebservices.com/ElasticLoadBalancing/2009-05-15/DeveloperGuide/"
*/ */
void deregisterInstancesWithLoadBalancer(@Nullable String region, String name, String... instanceIds); void deregisterInstancesWithLoadBalancerInRegion(@Nullable String region, String name,
String... instanceIds);
Set<ElasticLoadBalancer> describeLoadBalancersInRegion(@Nullable String region,
Set<ElasticLoadBalancer> describeLoadBalancers(@Nullable String region, @Nullable String name); @Nullable String name);
} }

View File

@ -21,15 +21,32 @@ package org.jclouds.aws.ec2.util;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.services.InstanceClient;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class EC2Utils { public class EC2Utils {
@Singleton
public static class GetRegionFromLocation implements Function<Location, String> {
public String apply(Location location) {
String region = location.getScope() == LocationScope.REGION ? location.getId() : location
.getParent().getId();
return region;
}
}
public static void indexStringArrayToFormValuesWithPrefix(GeneratedHttpRequest<?> request, public static void indexStringArrayToFormValuesWithPrefix(GeneratedHttpRequest<?> request,
String prefix, Object input) { String prefix, Object input) {
@ -42,6 +59,17 @@ public class EC2Utils {
} }
} }
public static Iterable<RunningInstance> getAllRunningInstancesInRegion(InstanceClient client,
String region, String id) {
return Iterables.concat(client.describeInstancesInRegion(region, id));
}
public static String[] parseHandle(String handle) {
String[] parts = checkNotNull(handle, "handle").split("/");
checkArgument(parts.length == 2, "handle syntax is region/id");
return parts;
}
public static void indexIterableToFormValuesWithPrefix(GeneratedHttpRequest<?> request, public static void indexIterableToFormValuesWithPrefix(GeneratedHttpRequest<?> request,
String prefix, Object input) { String prefix, Object input) {
checkArgument(checkNotNull(input, "input") instanceof Iterable<?>, checkArgument(checkNotNull(input, "input") instanceof Iterable<?>,

View File

@ -180,36 +180,34 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
} }
@Test @Test
public void testLoadBalanceNodesMatching() throws Exception{ public void testLoadBalanceNodesMatching() throws Exception {
ElasticLoadBalancerClient elbClient = EC2Client.class.cast( ElasticLoadBalancerClient elbClient = EC2Client.class.cast(
context.getProviderSpecificContext().getApi()) context.getProviderSpecificContext().getApi()).getElasticLoadBalancerServices();
.getElasticLoadBalancerServices();
String tag = "jcloudsElbTest"; String tag = "jcloudsElbTest";
Template template = client.templateBuilder().build(); Template template = client.templateBuilder().build();
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 2, try {
template); Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 2, template);
Set<String> instanceIds = new HashSet<String>(); Set<String> instanceIds = new HashSet<String>();
for (NodeMetadata node : nodes) for (NodeMetadata node : nodes) {
{
instanceIds.add(node.getId()); instanceIds.add(node.getId());
} }
// create load balancer // create load balancer
String dnsName = client.loadBalanceNodesMatching(tag, "HTTP", 80, 80, String dnsName = client.loadBalanceNodesMatching(NodePredicates.withTag(tag), tag, "HTTP",
NodePredicates.withTag(tag)); 80, 80);
assertNotNull(dnsName); assertNotNull(dnsName);
Set<ElasticLoadBalancer> elbs = elbClient.describeLoadBalancers( Set<ElasticLoadBalancer> elbs = elbClient.describeLoadBalancersInRegion(Region.US_EAST_1,
Region.US_EAST_1, tag); tag);
assertNotNull(elbs); assertNotNull(elbs);
ElasticLoadBalancer elb = elbs.iterator().next(); ElasticLoadBalancer elb = elbs.iterator().next();
assertEquals(elb.getInstanceIds(), instanceIds); assertEquals(elb.getInstanceIds(), instanceIds);
} finally {
elbClient.deleteLoadBalancer(Region.US_EAST_1, tag); elbClient.deleteLoadBalancerInRegion(Region.US_EAST_1, tag);
//finaly destroy nodes // finaly destroy nodes
client.destroyNodesMatching(NodePredicates.withTag(tag)); client.destroyNodesMatching(NodePredicates.withTag(tag));
}
} }
private RunningInstance getInstance(InstanceClient instanceClient, String id) { private RunningInstance getInstance(InstanceClient instanceClient, String id) {

View File

@ -125,7 +125,7 @@ public class EC2ComputeServiceTest {
expect(optionsProvider.get()).andReturn(defaultOptions); expect(optionsProvider.get()).andReturn(defaultOptions);
Image image = new ImageImpl("ami-image", "image", location, null, Maps Image image = new ImageImpl("ami-image", "image", "us-east-1/ami-image", location, null, Maps
.<String, String> newHashMap(), "description", "1.0", null, "ubuntu", .<String, String> newHashMap(), "description", "1.0", null, "ubuntu",
Architecture.X86_64, new Credentials("root", null)); Architecture.X86_64, new Credentials("root", null));
replay(optionsProvider); replay(optionsProvider);

View File

@ -271,6 +271,7 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
expect(instance.getId()).andReturn("id").atLeastOnce(); expect(instance.getId()).andReturn("id").atLeastOnce();
expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce(); expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
expect(instance.getKeyName()).andReturn(null).atLeastOnce(); expect(instance.getKeyName()).andReturn(null).atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
@ -328,6 +329,7 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance instance = createMock(RunningInstance.class); RunningInstance instance = createMock(RunningInstance.class);
expect(instance.getId()).andReturn("id").atLeastOnce(); expect(instance.getId()).andReturn("id").atLeastOnce();
expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag")).atLeastOnce(); expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag")).atLeastOnce();
expect(instance.getKeyName()).andReturn(null).atLeastOnce(); expect(instance.getKeyName()).andReturn(null).atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);

View File

@ -91,7 +91,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null); Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
Set<Location> locations = ImmutableSet.<Location> of(location); Set<Location> locations = ImmutableSet.<Location> of(location);
Set<Image> images = ImmutableSet.<Image> of(); Set<Image> images = ImmutableSet.<Image> of();
Set<Size> sizes = ImmutableSet.<Size> of(new SizeImpl(null, null, location, null, Set<Size> sizes = ImmutableSet.<Size> of(new SizeImpl("1", "1", "region/1", location, null,
ImmutableMap.<String, String> of(), 1, 1, 1, EnumSet.allOf(Architecture.class))); ImmutableMap.<String, String> of(), 1, 1, 1, EnumSet.allOf(Architecture.class)));
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
@ -127,7 +127,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null); Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
Set<Location> locations = ImmutableSet.<Location> of(location); Set<Location> locations = ImmutableSet.<Location> of(location);
Set<Image> images = ImmutableSet.<Image> of(); Set<Image> images = ImmutableSet.<Image> of();
Set<Size> sizes = ImmutableSet.<Size> of(new SizeImpl(null, null, location, null, Set<Size> sizes = ImmutableSet.<Size> of(new SizeImpl("1", "1", "region/1", location, null,
ImmutableMap.<String, String> of(), 1, 1, 1, EnumSet.allOf(Architecture.class))); ImmutableMap.<String, String> of(), 1, 1, 1, EnumSet.allOf(Architecture.class)));
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);

View File

@ -41,7 +41,7 @@ public class ElasticLoadBalancerAsyncClientTest extends
public void testRegisterInstancesWithLoadBalancer() throws SecurityException, public void testRegisterInstancesWithLoadBalancer() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = ElasticLoadBalancerAsyncClient.class.getMethod( Method method = ElasticLoadBalancerAsyncClient.class.getMethod(
"registerInstancesWithLoadBalancer", String.class, String.class, String[].class); "registerInstancesWithLoadBalancerInRegion", String.class, String.class, String[].class);
GeneratedHttpRequest<ElasticLoadBalancerAsyncClient> httpMethod = processor.createRequest( GeneratedHttpRequest<ElasticLoadBalancerAsyncClient> httpMethod = processor.createRequest(
method, null, "ReferenceAP1", "i-6055fa09"); method, null, "ReferenceAP1", "i-6055fa09");

View File

@ -67,7 +67,7 @@ public class ElasticLoadBalancerClientLiveTest {
AvailabilityZone.US_EAST_1A, Region.US_WEST_1, AvailabilityZone.US_WEST_1A, AvailabilityZone.US_EAST_1A, Region.US_WEST_1, AvailabilityZone.US_WEST_1A,
Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, Region.AP_SOUTHEAST_1, Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, Region.AP_SOUTHEAST_1,
AvailabilityZone.AP_SOUTHEAST_1A).entrySet()) { AvailabilityZone.AP_SOUTHEAST_1A).entrySet()) {
String dnsName = client.createLoadBalancer(regionZone.getKey(), name, "http", 80, 80, String dnsName = client.createLoadBalancerInRegion(regionZone.getKey(), name, "http", 80, 80,
regionZone.getValue()); regionZone.getValue());
assertNotNull(dnsName); assertNotNull(dnsName);
assert (dnsName.startsWith(name)); assert (dnsName.startsWith(name));
@ -79,7 +79,7 @@ public class ElasticLoadBalancerClientLiveTest {
String name = "TestDescribeLoadBalancer"; String name = "TestDescribeLoadBalancer";
for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1,
Region.US_WEST_1, Region.AP_SOUTHEAST_1)) { Region.US_WEST_1, Region.AP_SOUTHEAST_1)) {
Set<ElasticLoadBalancer> allResults = client.describeLoadBalancers(region, name); Set<ElasticLoadBalancer> allResults = client.describeLoadBalancersInRegion(region, name);
assertNotNull(allResults); assertNotNull(allResults);
assert (allResults.size() >= 1); assert (allResults.size() >= 1);
} }
@ -89,7 +89,7 @@ public class ElasticLoadBalancerClientLiveTest {
void testDeleteLoadBalancer() { void testDeleteLoadBalancer() {
for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1, for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_1,
Region.US_WEST_1, Region.AP_SOUTHEAST_1)) { Region.US_WEST_1, Region.AP_SOUTHEAST_1)) {
client.deleteLoadBalancer(region, "TestLoadBalancer"); client.deleteLoadBalancerInRegion(region, "TestLoadBalancer");
} }
} }

View File

@ -18,20 +18,13 @@
*/ */
package org.jclouds.aws.ec2.xml; package org.jclouds.aws.ec2.xml;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.util.Set; import java.util.Set;
import org.jclouds.aws.ec2.domain.ElasticLoadBalancer;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
@ -40,12 +33,9 @@ import com.google.common.collect.Sets;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "ec2.RegisterInstancesWithLoadBalancerResponseHandlerTest") @Test(groups = "unit", testName = "ec2.RegisterInstancesWithLoadBalancerResponseHandlerTest")
public class RegisterInstancesWithLoadBalancerResponseHandlerTest extends public class RegisterInstancesWithLoadBalancerResponseHandlerTest extends BaseEC2HandlerTest {
BaseEC2HandlerTest
{
public void testParse() public void testParse() {
{
InputStream is = getClass().getResourceAsStream( InputStream is = getClass().getResourceAsStream(
"/ec2/register_instances_with_loadbalancer.xml"); "/ec2/register_instances_with_loadbalancer.xml");
@ -53,14 +43,12 @@ public class RegisterInstancesWithLoadBalancerResponseHandlerTest extends
instanceIds.add("i-6055fa09"); instanceIds.add("i-6055fa09");
instanceIds.add("i-9055fa55"); instanceIds.add("i-9055fa55");
Set<String> result = parseXML(is); Set<String> result = parseXML(is);
assertEquals(result, instanceIds); assertEquals(result, instanceIds);
} }
private Set<String> parseXML(InputStream is) private Set<String> parseXML(InputStream is) {
{
RegisterInstancesWithLoadBalancerResponseHandler handler = injector RegisterInstancesWithLoadBalancerResponseHandler handler = injector
.getInstance(RegisterInstancesWithLoadBalancerResponseHandler.class); .getInstance(RegisterInstancesWithLoadBalancerResponseHandler.class);
Set<String> result = factory.create(handler).parse(is); Set<String> result = factory.create(handler).parse(is);

View File

@ -19,6 +19,7 @@
package org.jclouds.samples.googleappengine.functions; package org.jclouds.samples.googleappengine.functions;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -48,9 +49,9 @@ public class ComputeServiceContextToStatusResult implements Function<String, Sta
String name = "not found"; String name = "not found";
try { try {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
Map<String, ? extends ComputeMetadata> nodes = context.getComputeService().getNodes(); Set<? extends ComputeMetadata> nodes = context.getComputeService().listNodes();
if (nodes.size() > 0) if (nodes.size() > 0)
name = Iterables.get(nodes.keySet(), 0); name = Iterables.get(nodes, 0).getId();
status = ((System.currentTimeMillis() - start) + "ms"); status = ((System.currentTimeMillis() - start) + "ms");
} catch (Exception e) { } catch (Exception e) {
logger.error(e, "Error listing service %s", contextName); logger.error(e, "Error listing service %s", contextName);

View File

@ -207,10 +207,10 @@ See http://code.google.com/p/jclouds for details."
(first (run-nodes tag 1 template compute)))) (first (run-nodes tag 1 template compute))))
(defn #^NodeMetadata node-details (defn #^NodeMetadata node-details
"Retrieve the node metadata." "Retrieve the node metadata, given its handle."
([location id] (node-details location id *compute*)) ([handle] (node-details handle *compute*))
([#^Location location id #^ComputeService compute] ([handle #^ComputeService compute]
(.getNodeMetadata compute location id))) (.getNodeMetadata compute handle)))
(defn reboot-nodes-with-tag (defn reboot-nodes-with-tag
"Reboot all the nodes with the given tag." "Reboot all the nodes with the given tag."
@ -219,10 +219,10 @@ See http://code.google.com/p/jclouds for details."
(.rebootNodesMatching compute (NodePredicates/withTag tag)))) (.rebootNodesMatching compute (NodePredicates/withTag tag))))
(defn reboot-node (defn reboot-node
"Reboot a given node." "Reboot a node, given its handle."
([location id] (reboot-node location id *compute*)) ([handle] (reboot-node handle *compute*))
([#^Location location id #^ComputeService compute] ([handle #^ComputeService compute]
(.rebootNode compute location id))) (.rebootNode compute handle)))
(defn destroy-nodes-with-tag (defn destroy-nodes-with-tag
"Destroy all the nodes with the given tag." "Destroy all the nodes with the given tag."
@ -231,10 +231,10 @@ See http://code.google.com/p/jclouds for details."
(.destroyNodesMatching compute (NodePredicates/withTag tag)))) (.destroyNodesMatching compute (NodePredicates/withTag tag))))
(defn destroy-node (defn destroy-node
"Destroy a given node." "Destroy a node, given its handle."
([location id] (destroy-node location id *compute*)) ([handle] (destroy-node handle *compute*))
([#^Location location id #^ComputeService compute] ([handle #^ComputeService compute]
(.destroyNode compute location id))) (.destroyNode compute handle)))
(defmacro state-predicate [node state] (defmacro state-predicate [node state]
`(= (.getState ~node) `(= (.getState ~node)
@ -295,6 +295,11 @@ See http://code.google.com/p/jclouds for details."
[#^ComputeMetadata node] [#^ComputeMetadata node]
(-?> node .getLocation .getId)) (-?> node .getLocation .getId))
(defn handle
"Returns the compute node's handle"
[#^ComputeMetadata node]
(.getHandle node))
(define-accessors Template image size location options) (define-accessors Template image size location options)
(define-accessors Image version os-family os-description architecture) (define-accessors Image version os-family os-description architecture)
(define-accessors Size cores ram disk) (define-accessors Size cores ram disk)

View File

@ -33,6 +33,7 @@ import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
import com.google.common.annotations.Beta;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;
@ -145,10 +146,10 @@ public interface ComputeService {
Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) throws RunNodesException; Set<? extends NodeMetadata> runNodesWithTag(String tag, int count) throws RunNodesException;
/** /**
* destroy the node. If it is the only node in a tag set, the dependent resources will also be * destroy the node, given its handle. If it is the only node in a tag set, the dependent
* destroyed. * resources will also be destroyed.
*/ */
void destroyNode(Location location, String id); void destroyNode(String handle);
/** /**
* nodes matching the filter are treated as a logical set. Using the delete command, you can save * nodes matching the filter are treated as a logical set. Using the delete command, you can save
@ -160,9 +161,9 @@ public interface ComputeService {
Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter); Set<? extends NodeMetadata> destroyNodesMatching(Predicate<NodeMetadata> filter);
/** /**
* reboot the node. * reboot the node, given its handle.
*/ */
void rebootNode(Location location, String id); void rebootNode(String handle);
/** /**
* nodes matching the filter are treated as a logical set. Using this command, you can save time * nodes matching the filter are treated as a logical set. Using this command, you can save time
@ -171,9 +172,9 @@ public interface ComputeService {
void rebootNodesMatching(Predicate<NodeMetadata> filter); void rebootNodesMatching(Predicate<NodeMetadata> filter);
/** /**
* Find a node by its id * Find a node by its handle.
*/ */
NodeMetadata getNodeMetadata(Location location, String id); NodeMetadata getNodeMetadata(String handle);
/** /**
* get all nodes including details such as image and ip addresses even if it incurs extra * get all nodes including details such as image and ip addresses even if it incurs extra
@ -215,31 +216,29 @@ public interface ComputeService {
throws RunScriptOnNodesException; throws RunScriptOnNodesException;
/** /**
* @param filter
* Predicate-based filter to define which nodes to loadbalance
* @param loadBalancerName * @param loadBalancerName
* Load balancer name * Load balancer name
* @param protocol * @param protocol
* LoadBalancer transport protocol to use for routing - TCP or * LoadBalancer transport protocol to use for routing - TCP or HTTP. This property
* HTTP. This property cannot be modified for the life of the
* LoadBalancer.
* @param loadBalancerPort
* The external TCP port of the LoadBalancer. Valid LoadBalancer
* ports are - 80, 443 and 1024 through 65535. This property
* cannot be modified for the life of the LoadBalancer. * cannot be modified for the life of the LoadBalancer.
* @param instancePort * @param loadBalancerPort
* The InstancePort data type is simple type of type: integer. It * The external TCP port of the LoadBalancer. Valid LoadBalancer ports are - 80, 443
* is the TCP port on which the server on the instance is * and 1024 through 65535. This property cannot be modified for the life of the
* listening. Valid instance ports are one (1) through 65535.
* This property cannot be modified for the life of the
* LoadBalancer. * LoadBalancer.
* @param filter * @param instancePort
* Predicate-based filter to define on which nodes the script is * The InstancePort data type is simple type of type: integer. It is the TCP port on
* to be executed * which the server on the instance is listening. Valid instance ports are one (1)
* through 65535. This property cannot be modified for the life of the LoadBalancer.
*
* @return DNS Name of the load balancer * @return DNS Name of the load balancer
*/ */
String loadBalanceNodesMatching(String loadBalancerName, String protocol, @Beta
Integer loadBalancerPort, Integer instancePort, String loadBalanceNodesMatching(Predicate<NodeMetadata> filter, String loadBalancerName,
Predicate<NodeMetadata> filter); String protocol, int loadBalancerPort, int instancePort);
@Beta
void deleteLoadBalancer(String loadBalancerName, Predicate<NodeMetadata> filter); void deleteLoadBalancer(String loadBalancerName, Predicate<NodeMetadata> filter);
} }

View File

@ -50,4 +50,12 @@ public interface ComputeMetadata extends ResourceMetadata<ComputeType> {
@Override @Override
public String getName(); public String getName();
/**
* A means to uniquely address this resource within a provider. For example, if the namespace of
* a node or image is region based, the handle will likely include both the region and the id
* encoded to avoid collisions.
*
*/
public String getHandle();
} }

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.compute.domain.internal; package org.jclouds.compute.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
@ -35,10 +37,20 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> imple
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 7374704415964898694L; private static final long serialVersionUID = 7374704415964898694L;
private final String handle;
public ComputeMetadataImpl(ComputeType type, String id, String name, Location location, URI uri, public ComputeMetadataImpl(ComputeType type, String id, String name, String handle,
Map<String, String> userMetadata) { Location location, URI uri, Map<String, String> userMetadata) {
super(type, id, name, location, uri, userMetadata); super(type, id, name, location, uri, userMetadata);
this.handle = checkNotNull(handle, "handle");
}
/**
* {@inheritDoc}
*/
@Override
public String getHandle() {
return handle;
} }
} }

View File

@ -52,12 +52,11 @@ public class ImageImpl extends ComputeMetadataImpl implements Image {
private final Architecture architecture; private final Architecture architecture;
private final Credentials defaultCredentials; private final Credentials defaultCredentials;
public ImageImpl(String id, String name, String handle, Location location, URI uri,
public ImageImpl(String id, String name, Location location, URI uri,
Map<String, String> userMetadata, String description, String version, Map<String, String> userMetadata, String description, String version,
@Nullable OsFamily osFamily, String osDescription, Architecture architecture, @Nullable OsFamily osFamily, String osDescription, Architecture architecture,
Credentials defaultCredentials) { Credentials defaultCredentials) {
super(ComputeType.IMAGE, id, name, location, uri, userMetadata); super(ComputeType.IMAGE, id, name, handle, location, uri, userMetadata);
this.version = checkNotNull(version, "version"); this.version = checkNotNull(version, "version");
this.osFamily = osFamily; this.osFamily = osFamily;
this.description = checkNotNull(description, "description"); this.description = checkNotNull(description, "description");

View File

@ -54,12 +54,12 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
private final String tag; private final String tag;
private final Image image; private final Image image;
public NodeMetadataImpl(String id, String name, Location location, URI uri, public NodeMetadataImpl(String id, String name, String handle, Location location, URI uri,
Map<String, String> userMetadata, @Nullable String tag, @Nullable Image image, Map<String, String> userMetadata, @Nullable String tag, @Nullable Image image,
NodeState state, Iterable<InetAddress> publicAddresses, NodeState state, Iterable<InetAddress> publicAddresses,
Iterable<InetAddress> privateAddresses, Map<String, String> extra, Iterable<InetAddress> privateAddresses, Map<String, String> extra,
@Nullable Credentials credentials) { @Nullable Credentials credentials) {
super(ComputeType.NODE, id, name, location, uri, userMetadata); super(ComputeType.NODE, id, name, handle, location, uri, userMetadata);
this.tag = tag; this.tag = tag;
this.image = image; this.image = image;
this.state = checkNotNull(state, "state"); this.state = checkNotNull(state, "state");

View File

@ -48,10 +48,10 @@ public class SizeImpl extends ComputeMetadataImpl implements Size {
private final Set<Architecture> supportedArchitectures = Sets.newHashSet(); private final Set<Architecture> supportedArchitectures = Sets.newHashSet();
public SizeImpl(String id, String name, @Nullable Location location, URI uri, public SizeImpl(String id, String name, String handle, @Nullable Location location, URI uri,
Map<String, String> userMetadata, double cores, int ram, int disk, Map<String, String> userMetadata, double cores, int ram, int disk,
Iterable<Architecture> supportedArchitectures) { Iterable<Architecture> supportedArchitectures) {
super(ComputeType.SIZE, id, name, location, uri, userMetadata); super(ComputeType.SIZE, id, name, handle, location, uri, userMetadata);
this.cores = cores; this.cores = cores;
this.ram = ram; this.ram = ram;
this.disk = disk; this.disk = disk;

View File

@ -58,7 +58,6 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.LoadBalancerStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.util.ComputeUtils; import org.jclouds.compute.util.ComputeUtils;
@ -96,7 +95,6 @@ public class BaseComputeService implements ComputeService {
protected final RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy; protected final RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy;
protected final RebootNodeStrategy rebootNodeStrategy; protected final RebootNodeStrategy rebootNodeStrategy;
protected final DestroyNodeStrategy destroyNodeStrategy; protected final DestroyNodeStrategy destroyNodeStrategy;
protected final LoadBalancerStrategy loadBalancerStrategy;
protected final Provider<TemplateBuilder> templateBuilderProvider; protected final Provider<TemplateBuilder> templateBuilderProvider;
protected final Provider<TemplateOptions> templateOptionsProvider; protected final Provider<TemplateOptions> templateOptionsProvider;
protected final ComputeUtils utils; protected final ComputeUtils utils;
@ -109,7 +107,7 @@ public class BaseComputeService implements ComputeService {
GetNodeMetadataStrategy getNodeMetadataStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
LoadBalancerStrategy loadBalancerStrategy, Provider<TemplateBuilder> templateBuilderProvider, Provider<TemplateBuilder> templateBuilderProvider,
Provider<TemplateOptions> templateOptionsProvider, ComputeUtils utils, Provider<TemplateOptions> templateOptionsProvider, ComputeUtils utils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
@ -123,7 +121,6 @@ public class BaseComputeService implements ComputeService {
"runNodesAndAddToSetStrategy"); "runNodesAndAddToSetStrategy");
this.rebootNodeStrategy = checkNotNull(rebootNodeStrategy, "rebootNodeStrategy"); this.rebootNodeStrategy = checkNotNull(rebootNodeStrategy, "rebootNodeStrategy");
this.destroyNodeStrategy = checkNotNull(destroyNodeStrategy, "destroyNodeStrategy"); this.destroyNodeStrategy = checkNotNull(destroyNodeStrategy, "destroyNodeStrategy");
this.loadBalancerStrategy = checkNotNull(loadBalancerStrategy, "loadBalancerStrategy");
this.templateBuilderProvider = checkNotNull(templateBuilderProvider, this.templateBuilderProvider = checkNotNull(templateBuilderProvider,
"templateBuilderProvider"); "templateBuilderProvider");
this.templateOptionsProvider = checkNotNull(templateOptionsProvider, this.templateOptionsProvider = checkNotNull(templateOptionsProvider,
@ -151,8 +148,8 @@ public class BaseComputeService implements ComputeService {
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)", logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)",
count, count > 1 ? "s" : "", tag, template.getLocation().getId(), template count, count > 1 ? "s" : "", tag, template.getLocation().getId(), template
.getImage().getId(), template.getSize().getId(), template.getOptions()); .getImage().getId(), template.getSize().getId(), template.getOptions());
final Set<NodeMetadata> nodes = Sets.newHashSet(); Set<NodeMetadata> nodes = Sets.newHashSet();
final Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap(); Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
Map<?, ListenableFuture<Void>> responses = runNodesAndAddToSetStrategy.execute(tag, count, Map<?, ListenableFuture<Void>> responses = runNodesAndAddToSetStrategy.execute(tag, count,
template, nodes, badNodes); template, nodes, badNodes);
Map<?, Exception> executionExceptions = awaitCompletion(responses, executor, null, logger, Map<?, Exception> executionExceptions = awaitCompletion(responses, executor, null, logger,
@ -185,12 +182,11 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void destroyNode(Location location, String id) { public void destroyNode(String handle) {
checkNotNull(location, "location"); checkNotNull(handle, "handle");
checkNotNull(id, "id"); logger.debug(">> destroying node(%s)", handle);
logger.debug(">> destroying node(%s/%s)", location.getId(), id); boolean successful = destroyNodeStrategy.execute(handle);
boolean successful = destroyNodeStrategy.execute(location, id); logger.debug("<< destroyed node(%s) success(%s)", handle, successful);
logger.debug("<< destroyed node(%s/%s) success(%s)", location.getId(), id, successful);
} }
/** /**
@ -205,7 +201,7 @@ public class BaseComputeService implements ComputeService {
responses.put(node, makeListenable(executor.submit(new Callable<Void>() { responses.put(node, makeListenable(executor.submit(new Callable<Void>() {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
destroyNode(node.getLocation(), node.getId()); destroyNode(node.getHandle());
destroyedNodes.add(node); destroyedNodes.add(node);
return null; return null;
} }
@ -282,22 +278,20 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public NodeMetadata getNodeMetadata(Location location, String id) { public NodeMetadata getNodeMetadata(String handle) {
checkNotNull(location, "location"); checkNotNull(handle, "handle");
checkNotNull(id, "id"); return getNodeMetadataStrategy.execute(handle);
return getNodeMetadataStrategy.execute(location, id);
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void rebootNode(Location location, String id) { public void rebootNode(String handle) {
checkNotNull(location, "location"); checkNotNull(handle, "handle");
checkNotNull(id, "id"); logger.debug(">> rebooting node(%s)", handle);
logger.debug(">> rebooting node(%s/%s)", location.getId(), id); boolean successful = rebootNodeStrategy.execute(handle);
boolean successful = rebootNodeStrategy.execute(location, id); logger.debug("<< rebooted node(%s) success(%s)", handle, successful);
logger.debug("<< rebooted node(%s/%s) success(%s)", location.getId(), id, successful);
} }
/** /**
@ -312,7 +306,7 @@ public class BaseComputeService implements ComputeService {
responses.put(node, makeListenable(executor.submit(new Callable<Void>() { responses.put(node, makeListenable(executor.submit(new Callable<Void>() {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
rebootNode(node.getLocation(), node.getId()); rebootNode(node.getHandle());
return null; return null;
} }
}), executor)); }), executor));
@ -384,10 +378,6 @@ public class BaseComputeService implements ComputeService {
} }
/**
* {@inheritDoc}
*/
private Iterable<? extends NodeMetadata> verifyParametersAndListNodes( private Iterable<? extends NodeMetadata> verifyParametersAndListNodes(
Predicate<NodeMetadata> filter, byte[] runScript, final RunScriptOptions options) { Predicate<NodeMetadata> filter, byte[] runScript, final RunScriptOptions options) {
checkNotNull(filter, "Filter must be provided"); checkNotNull(filter, "Filter must be provided");
@ -423,28 +413,6 @@ public class BaseComputeService implements ComputeService {
}); });
} }
/**
* {@inheritDoc}
*/
public String loadBalanceNodesMatching(String loadBalancerName,
String protocol, Integer loadBalancerPort, Integer instancePort,
Predicate<NodeMetadata> filter)
{
return null;
}
/**
* {@inheritDoc}
*/
public void deleteLoadBalancer(String loadBalancerName,
Predicate<NodeMetadata> filter)
{
}
private Iterable<? extends NodeMetadata> detailsOnAllNodes() { private Iterable<? extends NodeMetadata> detailsOnAllNodes() {
return listNodesStrategy.listDetailsOnNodesMatching(NodePredicates.all()); return listNodesStrategy.listDetailsOnNodesMatching(NodePredicates.all());
} }
@ -453,4 +421,16 @@ public class BaseComputeService implements ComputeService {
public TemplateOptions templateOptions() { public TemplateOptions templateOptions() {
return templateOptionsProvider.get(); return templateOptionsProvider.get();
} }
@Override
public void deleteLoadBalancer(String loadBalancerName, Predicate<NodeMetadata> filter) {
throw new UnsupportedOperationException("deleteLoadBalancer not supported in this cloud");
}
@Override
public String loadBalanceNodesMatching(Predicate<NodeMetadata> filter, String loadBalancerName,
String protocol, int loadBalancerPort, int instancePort) {
throw new UnsupportedOperationException(
"loadBalanceNodesMatching not supported in this cloud");
}
} }

View File

@ -19,7 +19,6 @@
package org.jclouds.compute.strategy; package org.jclouds.compute.strategy;
import org.jclouds.domain.Location;
/** /**
* terminates the node and blocks until it is no longer visible or in the state TERMINATED. If this * terminates the node and blocks until it is no longer visible or in the state TERMINATED. If this
@ -29,6 +28,6 @@ import org.jclouds.domain.Location;
*/ */
public interface DestroyNodeStrategy { public interface DestroyNodeStrategy {
boolean execute(Location location, String id); boolean execute(String handle);
} }

View File

@ -20,7 +20,6 @@
package org.jclouds.compute.strategy; package org.jclouds.compute.strategy;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.Location;
/** /**
* returns all details associated to the node below. * returns all details associated to the node below.
@ -29,6 +28,6 @@ import org.jclouds.domain.Location;
*/ */
public interface GetNodeMetadataStrategy { public interface GetNodeMetadataStrategy {
NodeMetadata execute(Location location, String id); NodeMetadata execute(String handle);
} }

View File

@ -28,11 +28,9 @@ import org.jclouds.domain.Location;
* *
* @author Lili Nader * @author Lili Nader
*/ */
public interface LoadBalancerStrategy public interface LoadBalancerStrategy {
{
String execute(Location loaction, String name, String protocol, String execute(Location loaction, String name, String protocol, int loadBalancerPort,
Integer loadBalancerPort, Integer instancePort, int instancePort, Set<String> instanceIds);
Set<String> instanceIds);
} }

View File

@ -19,7 +19,6 @@
package org.jclouds.compute.strategy; package org.jclouds.compute.strategy;
import org.jclouds.domain.Location;
/** /**
* Reboots a node unless it is in the state TERMINATED. * Reboots a node unless it is in the state TERMINATED.
@ -28,6 +27,6 @@ import org.jclouds.domain.Location;
*/ */
public interface RebootNodeStrategy { public interface RebootNodeStrategy {
boolean execute(Location location, String id); boolean execute(String handle);
} }

View File

@ -465,10 +465,10 @@ public class ComputeUtils {
* returns a new instance of {@link NodeMetadata} that has new credentials * returns a new instance of {@link NodeMetadata} that has new credentials
*/ */
public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) { public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) {
return new NodeMetadataImpl(node.getId(), node.getName(), node.getLocation(), node.getUri(), return new NodeMetadataImpl(node.getId(), node.getName(), node.getHandle(), node
node.getUserMetadata(), node.getTag(), node.getImage(), node.getState(), node .getLocation(), node.getUri(), node.getUserMetadata(), node.getTag(), node
.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), .getImage(), node.getState(), node.getPublicAddresses(), node.getPrivateAddresses(),
newCredentials); node.getExtra(), newCredentials);
} }
/** /**

View File

@ -324,7 +324,7 @@ public abstract class BaseComputeServiceLiveTest {
.withTag(tag), Predicates.not(NodePredicates.TERMINATED)))); .withTag(tag), Predicates.not(NodePredicates.TERMINATED))));
for (NodeMetadata node : nodes) { for (NodeMetadata node : nodes) {
metadataSet.remove(node); metadataSet.remove(node);
NodeMetadata metadata = client.getNodeMetadata(node.getLocation(), node.getId()); NodeMetadata metadata = client.getNodeMetadata(node.getHandle());
assertEquals(metadata.getId(), node.getId()); assertEquals(metadata.getId(), node.getId());
assertEquals(metadata.getTag(), node.getTag()); assertEquals(metadata.getTag(), node.getTag());
assertLocationSameOrChild(metadata.getLocation(), template.getLocation()); assertLocationSameOrChild(metadata.getLocation(), template.getLocation());

View File

@ -138,9 +138,9 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
} }
@Override @Override
public boolean execute(Location location, String id) { public boolean execute(String handle) {
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById( Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(
new Long(id))); new Long(handle)));
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);
@ -186,9 +186,9 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
} }
@Override @Override
public NodeMetadata execute(Location location, String id) { public NodeMetadata execute(String handle) {
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById( Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(
new Long(checkNotNull(id, "id")))); new Long(checkNotNull(handle, "handle"))));
return server == null ? null : serverToNodeMetadata.apply(server); return server == null ? null : serverToNodeMetadata.apply(server);
} }
} }
@ -206,9 +206,9 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
} }
@Override @Override
public boolean execute(Location location, String id) { public boolean execute(String handle) {
Server server = Iterables.getOnlyElement(client.getServerServices().getServersById( Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(
new Long(id))); new Long(handle)));
client.getServerServices().deleteByName(server.getName()); client.getServerServices().deleteByName(server.getName());
return serverLatestJobCompleted.apply(server); return serverLatestJobCompleted.apply(server);
} }
@ -329,16 +329,22 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
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", null, null, ImmutableMap.<String, String> of(), 0.5, 512, sizes.add(new SizeImpl("1", "1", "1", null, null, ImmutableMap.<String, String> of(), 0.5,
30, ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))); 512, 30, ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64)));
sizes.add(new SizeImpl("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,
ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))); 1024, 60, ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64)));
sizes.add(new SizeImpl("3", "3", null, null, ImmutableMap.<String, String> of(), 2, 2048, sizes
120, ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))); .add(new SizeImpl("3", "3", "3", null, null, ImmutableMap.<String, String> of(), 2,
sizes.add(new SizeImpl("4", "4", null, null, ImmutableMap.<String, String> of(), 4, 4096, 2048, 120, ImmutableSet.<Architecture> of(Architecture.X86_32,
240, ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))); Architecture.X86_64)));
sizes.add(new SizeImpl("5", "5", null, null, ImmutableMap.<String, String> of(), 8, 8192, sizes
480, ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))); .add(new SizeImpl("4", "4", "4", null, null, ImmutableMap.<String, String> of(), 4,
4096, 240, 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, 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;
} }
@ -377,9 +383,9 @@ public class GoGridComputeServiceContextModule extends GoGridContextModule {
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(), location, null, images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), from.getId() + "",
ImmutableMap.<String, String> of(), from.getDescription(), version, os, location, null, ImmutableMap.<String, String> of(), from.getDescription(),
osDescription, arch, defaultCredentials)); version, os, osDescription, arch, defaultCredentials));
} }
holder.logger.debug("<< images(%d)", images.size()); holder.logger.debug("<< images(%d)", images.size());
return images; return images;

View File

@ -103,8 +103,8 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
.warn("could not find a matching image for server %s in location %s", from, .warn("could not find a matching image for server %s in location %s", from,
location); location);
} }
return new NodeMetadataImpl(from.getId() + "", from.getName(), location, null, ImmutableMap return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location,
.<String, String> of(), tag, image, state, ipSet, ImmutableList.<InetAddress> of(), null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList
ImmutableMap.<String, String> of(), creds); .<InetAddress> of(), ImmutableMap.<String, String> of(), creds);
} }
} }

View File

@ -142,8 +142,8 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
} }
@Override @Override
public boolean execute(Location location, String id) { public boolean execute(String handle) {
int serverId = Integer.parseInt(id); int serverId = Integer.parseInt(handle);
// if false server wasn't around in the first place // if false server wasn't around in the first place
client.rebootServer(serverId, RebootType.HARD); client.rebootServer(serverId, RebootType.HARD);
Server server = client.getServer(serverId); Server server = client.getServer(serverId);
@ -165,8 +165,8 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
} }
@Override @Override
public boolean execute(Location location, String id) { public boolean execute(String handle) {
int serverId = Integer.parseInt(id); int serverId = Integer.parseInt(handle);
// if false server wasn't around in the first place // if false server wasn't around in the first place
if (!client.deleteServer(serverId)) if (!client.deleteServer(serverId))
return false; return false;
@ -193,12 +193,13 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
Server server = client.createServer(name, Integer.parseInt(template.getImage().getId()), Server server = client.createServer(name, Integer.parseInt(template.getImage().getId()),
Integer.parseInt(template.getSize().getId())); Integer.parseInt(template.getSize().getId()));
serverActive.apply(server); serverActive.apply(server);
return new NodeMetadataImpl(server.getId() + "", name, new LocationImpl( return new NodeMetadataImpl(server.getId() + "", name, server.getId() + "",
LocationScope.HOST, server.getHostId(), server.getHostId(), template new LocationImpl(LocationScope.HOST, server.getHostId(), server.getHostId(),
.getLocation()), null, server.getMetadata(), tag, template.getImage(), template.getLocation()), null, server.getMetadata(), tag, template
NodeState.RUNNING, server.getAddresses().getPublicAddresses(), server .getImage(), NodeState.RUNNING, server.getAddresses()
.getAddresses().getPrivateAddresses(), ImmutableMap .getPublicAddresses(), server.getAddresses().getPrivateAddresses(),
.<String, String> of(), new Credentials("root", server.getAdminPass())); ImmutableMap.<String, String> of(),
new Credentials("root", server.getAdminPass()));
} }
} }
@ -242,8 +243,8 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
} }
@Override @Override
public NodeMetadata execute(Location location, String id) { public NodeMetadata execute(String handle) {
int serverId = Integer.parseInt(id); int serverId = Integer.parseInt(handle);
Server server = client.getServer(serverId); Server server = client.getServer(serverId);
return server == null ? null : serverToNodeMetadata.apply(server); return server == null ? null : serverToNodeMetadata.apply(server);
} }
@ -315,9 +316,10 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
final Set<Size> sizes = Sets.newHashSet(); final Set<Size> sizes = Sets.newHashSet();
holder.logger.debug(">> providing sizes"); holder.logger.debug(">> providing sizes");
for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) { for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) {
sizes.add(new SizeImpl(from.getId() + "", from.getName(), location, null, ImmutableMap sizes.add(new SizeImpl(from.getId() + "", from.getName(), from.getId() + "", location,
.<String, String> of(), from.getDisk() / 10, from.getRam(), from.getDisk(), null, ImmutableMap.<String, String> of(), from.getDisk() / 10, from.getRam(),
ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64))); from.getDisk(), 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;
@ -357,9 +359,9 @@ public class CloudServersComputeServiceContextModule extends CloudServersContext
holder.logger.debug("<< didn't match os(%s)", matcher.group(2)); holder.logger.debug("<< didn't match os(%s)", matcher.group(2));
} }
} }
images.add(new ImageImpl(from.getId() + "", from.getName(), location, null, ImmutableMap images.add(new ImageImpl(from.getId() + "", from.getName(), from.getId() + "", location,
.<String, String> of(), from.getName(), version, os, osDescription, arch, null, ImmutableMap.<String, String> of(), from.getName(), version, os,
new Credentials("root", null))); osDescription, arch, new Credentials("root", null)));
} }
holder.logger.debug("<< images(%d)", images.size()); holder.logger.debug("<< images(%d)", images.size());
return images; return images;

View File

@ -98,7 +98,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
.warn("could not find a matching image for server %s in location %s", from, .warn("could not find a matching image for server %s in location %s", from,
location); location);
} }
return new NodeMetadataImpl(from.getId() + "", from.getName(), host, null, return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", host, null,
from.getMetadata(), tag, image, serverToNodeState.get(from.getStatus()), from from.getMetadata(), tag, image, serverToNodeState.get(from.getStatus()), from
.getAddresses().getPublicAddresses(), from.getAddresses() .getAddresses().getPublicAddresses(), from.getAddresses()
.getPrivateAddresses(), ImmutableMap.<String, String> of(), null); .getPrivateAddresses(), ImmutableMap.<String, String> of(), null);

View File

@ -140,8 +140,8 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
} }
@Override @Override
public boolean execute(Location location, String id) { public boolean execute(String handle) {
Long serverId = Long.parseLong(id); Long serverId = Long.parseLong(handle);
// if false server wasn't around in the first place // if false server wasn't around in the first place
return client.restartServer(serverId).getState() == RunningState.RUNNING; return client.restartServer(serverId).getState() == RunningState.RUNNING;
} }
@ -161,8 +161,8 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
} }
@Override @Override
public boolean execute(Location location, String id) { public boolean execute(String handle) {
long serverId = Long.parseLong(id); Long serverId = Long.parseLong(handle);
client.destroyServer(serverId); client.destroyServer(serverId);
return serverDestroyed.apply(client.getServer(serverId)); return serverDestroyed.apply(client.getServer(serverId));
} }
@ -196,10 +196,10 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
Server server = client.getServer(serverResponse.getServer().getId()); Server server = client.getServer(serverResponse.getServer().getId());
// we have to lookup the new details in order to retrieve the currently assigned ip // we have to lookup the new details in order to retrieve the currently assigned ip
// address. // address.
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, template NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId()
.getLocation(), null, ImmutableMap.<String, String> of(), tag, template .toString(), template.getLocation(), null, ImmutableMap.<String, String> of(),
.getImage(), runningStateToNodeState.get(server.getState()), getPublicAddresses tag, template.getImage(), runningStateToNodeState.get(server.getState()),
.apply(server), ImmutableList.<InetAddress> of(), ImmutableMap getPublicAddresses.apply(server), ImmutableList.<InetAddress> 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;
@ -247,9 +247,8 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
} }
@Override @Override
public NodeMetadata execute(Location location, String id) { public NodeMetadata execute(String handle) {
// TODO location long serverId = Long.parseLong(handle);
long serverId = Long.parseLong(id);
Server server = client.getServer(serverId); Server server = client.getServer(serverId);
return server == null ? null : serverToNodeMetadata.apply(server); return server == null ? null : serverToNodeMetadata.apply(server);
} }
@ -322,9 +321,9 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
location); location);
} }
NodeState state = runningStateToNodeState.get(from.getState()); NodeState state = runningStateToNodeState.get(from.getState());
return new NodeMetadataImpl(from.getId() + "", from.getName(), location, null, return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "",
ImmutableMap.<String, String> of(), tag, image, state, getPublicAddresses location, null, ImmutableMap.<String, String> of(), tag, image, state,
.apply(from), ImmutableList.<InetAddress> of(), ImmutableMap getPublicAddresses.apply(from), ImmutableList.<InetAddress> of(), ImmutableMap
.<String, String> of(), creds); .<String, String> of(), creds);
} }
@ -432,9 +431,9 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
} }
}); });
sizes.add(new SizeImpl(from.getId(), from.getId(), location, null, ImmutableMap sizes.add(new SizeImpl(from.getId(), from.getId(), from.getId(), location, null,
.<String, String> of(), 1, from.getRam(), from.getDiskSize(), ImmutableSet ImmutableMap.<String, String> of(), 1, from.getRam(), from.getDiskSize(),
.<Architecture> of(Architecture.X86_32, Architecture.X86_64))); ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64)));
} catch (NullPointerException e) { } catch (NullPointerException e) {
holder.logger.warn("datacenter not present in " + from.getId()); holder.logger.warn("datacenter not present in " + from.getId());
} }
@ -476,9 +475,9 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo
} }
} }
images.add(new ImageImpl(from.getId(), from.getDescription(), null, null, ImmutableMap images.add(new ImageImpl(from.getId(), from.getDescription(), from.getId(), null, null,
.<String, String> of(), from.getDescription(), version, os, osDescription, arch, ImmutableMap.<String, String> of(), from.getDescription(), version, os,
new Credentials("root", null))); osDescription, arch, new Credentials("root", null)));
} }
holder.logger.debug("<< images(%d)", images.size()); holder.logger.debug("<< images(%d)", images.size());
return images; return images;

View File

@ -235,7 +235,7 @@ public class ComputeTask extends Task {
private void logDetails(ComputeService computeService, ComputeMetadata node) { private void logDetails(ComputeService computeService, ComputeMetadata node) {
NodeMetadata metadata = node instanceof NodeMetadata ? NodeMetadata.class.cast(node) NodeMetadata metadata = node instanceof NodeMetadata ? NodeMetadata.class.cast(node)
: computeService.getNodeMetadata(node.getLocation(), node.getId()); : computeService.getNodeMetadata(node.getHandle());
log(String log(String
.format( .format(
" node id=%s, name=%s, tag=%s, location=%s, state=%s, publicIp=%s, privateIp=%s, extra=%s", " node id=%s, name=%s, tag=%s, location=%s, state=%s, publicIp=%s, privateIp=%s, extra=%s",

View File

@ -162,8 +162,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
} }
@Override @Override
public boolean execute(Location location, String id) { public boolean execute(String id) {
Task task = client.resetVApp(id); Task task = client.resetVApp(checkNotNull(id, "node.id"));
return taskTester.apply(task.getId()); return taskTester.apply(task.getId());
} }
@ -179,7 +179,7 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
} }
@Override @Override
public boolean execute(Location location, String id) { public boolean execute(String id) {
computeClient.stop(checkNotNull(id, "node.id")); computeClient.stop(checkNotNull(id, "node.id"));
return true; return true;
} }
@ -214,9 +214,9 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
protected NodeMetadata newCreateNodeResponse(String tag, Template template, protected NodeMetadata newCreateNodeResponse(String tag, Template template,
Map<String, String> metaMap, VApp vApp) { Map<String, String> metaMap, VApp vApp) {
return new NodeMetadataImpl(vApp.getId(), vApp.getName(), template.getLocation(), vApp return new NodeMetadataImpl(vApp.getId(), vApp.getName(), vApp.getId(), template
.getLocation(), ImmutableMap.<String, String> of(), tag, template.getImage(), .getLocation(), vApp.getLocation(), ImmutableMap.<String, String> of(), tag,
vAppStatusToNodeState.get(vApp.getStatus()), computeClient template.getImage(), vAppStatusToNodeState.get(vApp.getStatus()), computeClient
.getPublicAddresses(vApp.getId()), computeClient .getPublicAddresses(vApp.getId()), computeClient
.getPrivateAddresses(vApp.getId()), ImmutableMap.<String, String> of(), .getPrivateAddresses(vApp.getId()), ImmutableMap.<String, String> of(),
new Credentials(metaMap.get("username"), metaMap.get("password"))); new Credentials(metaMap.get("username"), metaMap.get("password")));
@ -255,7 +255,7 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
private ComputeMetadata convertVAppToComputeMetadata(NamedResource vdc, NamedResource resource) { private ComputeMetadata convertVAppToComputeMetadata(NamedResource vdc, NamedResource resource) {
Location location = findLocationForResourceInVDC.apply(resource, vdc.getId()); Location location = findLocationForResourceInVDC.apply(resource, vdc.getId());
return new ComputeMetadataImpl(ComputeType.NODE, resource.getId(), resource.getName(), return new ComputeMetadataImpl(ComputeType.NODE, resource.getId(), resource.getName(),
location, null, ImmutableMap.<String, String> of()); resource.getId(), location, null, ImmutableMap.<String, String> of());
} }
@Override @Override
@ -279,7 +279,7 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
int i = 0; int i = 0;
while (node == null && i++ < 3) { while (node == null && i++ < 3) {
try { try {
node = getNodeMetadataByIdInVDC(vdc.getId(), resource.getId()); node = getNodeMetadataByIdInVDC(resource.getId());
nodes.add(node); nodes.add(node);
} catch (NullPointerException e) { } catch (NullPointerException e) {
logger.warn("vApp %s not yet present in vdc %s", resource.getId(), vdc.getId()); logger.warn("vApp %s not yet present in vdc %s", resource.getId(), vdc.getId());
@ -303,9 +303,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
} }
@Override @Override
public NodeMetadata execute(Location location, String id) { public NodeMetadata execute(String id) {
return getNodeMetadataByIdInVDC(checkNotNull(location, "location").getId(), checkNotNull( return getNodeMetadataByIdInVDC(checkNotNull(id, "node.id"));
id, "node.id"));
} }
} }
@ -366,10 +365,10 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
.getId()); .getId());
images.add(new ImageImpl(resource.getId(), template.getName(), images.add(new ImageImpl(resource.getId(), template.getName(),
location, template.getLocation(), ImmutableMap resource.getId(), location, template.getLocation(),
.<String, String> of(), template.getDescription(), ImmutableMap.<String, String> of(), template
"", myOs, template.getName(), arch, new Credentials("root", .getDescription(), "", myOs, template.getName(),
null))); arch, new Credentials("root", null)));
return null; return null;
} }
}), executor)); }), executor));
@ -431,10 +430,12 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule {
throws InterruptedException, TimeoutException, ExecutionException { throws InterruptedException, TimeoutException, ExecutionException {
Set<Size> sizes = Sets.newHashSet(); Set<Size> sizes = Sets.newHashSet();
for (int cpus : new int[] { 1, 2, 4 }) for (int cpus : new int[] { 1, 2, 4 })
for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) {
sizes.add(new SizeImpl(String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10), null, String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10);
null, null, ImmutableMap.<String, String> of(), cpus, ram, 10, ImmutableSet sizes.add(new SizeImpl(id, null, id, null, null, ImmutableMap.<String, String> of(),
.<Architecture> of(Architecture.X86_32, Architecture.X86_64))); cpus, ram, 10, ImmutableSet.<Architecture> of(Architecture.X86_32,
Architecture.X86_64)));
}
return sizes; return sizes;
} }

View File

@ -87,14 +87,14 @@ public class VCloudGetNodeMetadata {
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState"); this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
} }
protected NodeMetadata getNodeMetadataByIdInVDC(String vDCId, String id) { protected NodeMetadata getNodeMetadataByIdInVDC(String id) {
VApp vApp = client.getVApp(id); VApp vApp = client.getVApp(id);
String tag = null; String tag = null;
Image image = null; Image image = null;
Matcher matcher = TAG_PATTERN_WITH_TEMPLATE.matcher(vApp.getName()); Matcher matcher = TAG_PATTERN_WITH_TEMPLATE.matcher(vApp.getName());
final Location location = findLocationForResourceInVDC.apply(vApp, vDCId); final Location location = findLocationForResourceInVDC.apply(vApp, vApp.getVDC().getId());
if (matcher.find()) { if (matcher.find()) {
tag = matcher.group(1); tag = matcher.group(1);
String templateIdInHexWithoutLeadingZeros = matcher.group(2).replaceAll("^[0]+", ""); String templateIdInHexWithoutLeadingZeros = matcher.group(2).replaceAll("^[0]+", "");
@ -121,9 +121,9 @@ public class VCloudGetNodeMetadata {
tag = "NOTAG-" + vApp.getName(); tag = "NOTAG-" + vApp.getName();
} }
} }
return new NodeMetadataImpl(vApp.getId(), vApp.getName(), location, vApp.getLocation(), return new NodeMetadataImpl(vApp.getId(), vApp.getName(), vApp.getId(), location, vApp
ImmutableMap.<String, String> of(), tag, image, vAppStatusToNodeState.get(vApp .getLocation(), ImmutableMap.<String, String> of(), tag, image,
.getStatus()), computeClient.getPublicAddresses(id), computeClient vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(id),
.getPrivateAddresses(id), getExtra.apply(vApp), null); computeClient.getPrivateAddresses(id), getExtra.apply(vApp), null);
} }
} }

View File

@ -48,7 +48,7 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assert node.getId() != null; assert node.getId() != null;
assert node.getLocation() != null; assert node.getLocation() != null;
assertEquals(node.getType(), ComputeType.NODE); assertEquals(node.getType(), ComputeType.NODE);
NodeMetadata allData = client.getNodeMetadata(node.getLocation(), node.getId()); NodeMetadata allData = client.getNodeMetadata(node.getHandle());
assert allData.getExtra().get("processor/count") != null; assert allData.getExtra().get("processor/count") != null;
assert allData.getExtra().get("disk_drive/1/kb") != null; assert allData.getExtra().get("disk_drive/1/kb") != null;
assert allData.getExtra().get("memory/mb") != null; assert allData.getExtra().get("memory/mb") != null;

View File

@ -101,9 +101,9 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer
private static class ComputeOptionsToSize implements Function<ComputeOptions, Size> { private static class ComputeOptionsToSize implements Function<ComputeOptions, Size> {
@Override @Override
public Size apply(ComputeOptions from) { public Size apply(ComputeOptions from) {
return new SizeImpl(from.toString(), from.toString(), null, null, ImmutableMap return new SizeImpl(from.toString(), from.toString(), from.toString(), null, null,
.<String, String> of(), from.getProcessorCount(), from.getMemory(), 10, ImmutableMap.<String, String> of(), from.getProcessorCount(), from.getMemory(),
ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64)); 10, ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64));
} }
} }
@ -149,10 +149,10 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer
.getId()); .getId());
images.add(new ImageImpl(resource.getId(), template.getName(), images.add(new ImageImpl(resource.getId(), template.getName(),
location, template.getLocation(), ImmutableMap resource.getId(), location, template.getLocation(),
.<String, String> of(), template.getDescription(), ImmutableMap.<String, String> of(), template
"", myOs, template.getName(), arch, credentialsProvider .getDescription(), "", myOs, template.getName(),
.execute(template))); arch, credentialsProvider.execute(template)));
return null; return null;
} }
}), executor)); }), executor));