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.checkNotNull;
import static org.jclouds.aws.ec2.util.EC2Utils.parseHandle;
import static org.jclouds.util.Utils.checkNotEmpty;
import java.util.HashSet;
@ -35,7 +36,6 @@ import javax.inject.Singleton;
import org.jclouds.Constants;
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.RegionNameAndIngressRules;
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
@ -68,9 +68,9 @@ import com.google.common.collect.Maps;
@Singleton
public class EC2ComputeService extends BaseComputeService {
private final EC2Client ec2Client;
private final GetRegionFromLocation getRegionFromLocation;
private final Map<RegionAndName, KeyPair> credentialsMap;
private final Map<RegionAndName, String> securityGroupMap;
private final LoadBalancerStrategy loadBalancerStrategy;
@Inject
protected EC2ComputeService(ComputeServiceContext context,
@ -79,17 +79,16 @@ public class EC2ComputeService extends BaseComputeService {
GetNodeMetadataStrategy getNodeMetadataStrategy,
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
LoadBalancerStrategy loadBalancerStrategy,
Provider<TemplateBuilder> templateBuilderProvider,
Provider<TemplateOptions> templateOptionsProvider, ComputeUtils utils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client,
GetRegionFromLocation getRegionFromLocation,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
LoadBalancerStrategy loadBalancerStrategy, EC2Client ec2Client,
Map<RegionAndName, KeyPair> credentialsMap, Map<RegionAndName, String> securityGroupMap) {
super(context, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy,
loadBalancerStrategy, templateBuilderProvider, templateOptionsProvider, utils, executor);
templateBuilderProvider, templateOptionsProvider, utils, executor);
this.loadBalancerStrategy = checkNotNull(loadBalancerStrategy, "loadBalancerStrategy");
this.ec2Client = ec2Client;
this.getRegionFromLocation = getRegionFromLocation;
this.credentialsMap = credentialsMap;
this.securityGroupMap = securityGroupMap;
}
@ -128,62 +127,13 @@ public class EC2ComputeService extends BaseComputeService {
Map<String, String> regionTags = Maps.newHashMap();
for (NodeMetadata nodeMetadata : deadOnes) {
if (nodeMetadata.getTag() != null)
regionTags.put(getRegionFromLocation.apply(nodeMetadata.getLocation()), nodeMetadata
.getTag());
regionTags.put(parseHandle(nodeMetadata.getHandle())[0], nodeMetadata.getTag());
}
for (Entry<String, String> regionTag : regionTags.entrySet()) {
deleteKeyPair(regionTag.getKey(), regionTag.getValue());
deleteSecurityGroup(regionTag.getKey(), regionTag.getValue());
}
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() {
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;
import static com.google.common.base.Preconditions.checkNotNull;
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.util.EC2Utils.getAllRunningInstancesInRegion;
import static org.jclouds.aws.ec2.util.EC2Utils.parseHandle;
import static org.jclouds.compute.domain.OsFamily.UBUNTU;
import static org.jclouds.concurrent.ConcurrentUtils.awaitCompletion;
@ -126,12 +127,12 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
bind(TemplateOptions.class).to(EC2TemplateOptions.class);
bind(ComputeService.class).to(EC2ComputeService.class);
bind(LoadBalancerStrategy.class).to(EC2LoadBalancerStrategy.class);
bind(RunNodesAndAddToSetStrategy.class).to(EC2RunNodesAndAddToSetStrategy.class);
bind(ListNodesStrategy.class).to(EC2ListNodesStrategy.class);
bind(GetNodeMetadataStrategy.class).to(EC2GetNodeMetadataStrategy.class);
bind(RebootNodeStrategy.class).to(EC2RebootNodeStrategy.class);
bind(DestroyNodeStrategy.class).to(EC2DestroyNodeStrategy.class);
bind(LoadBalancerStrategy.class).to(EC2LoadBalancerStrategy.class);
bind(new TypeLiteral<Function<RunningInstance, Map<String, String>>>() {
}).annotatedWith(Jsr330.named("volumeMapping")).to(RunningInstanceToStorageMappingUnix.class)
.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
public static class EC2GetNodeMetadataStrategy implements GetNodeMetadataStrategy {
private final InstanceClient client;
private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata;
private final GetRegionFromLocation getRegionFromLocation;
@Inject
protected EC2GetNodeMetadataStrategy(InstanceClient client,
GetRegionFromLocation getRegionFromLocation,
RunningInstanceToNodeMetadata runningInstanceToNodeMetadata) {
this.client = client;
this.getRegionFromLocation = getRegionFromLocation;
this.runningInstanceToNodeMetadata = runningInstanceToNodeMetadata;
}
@Override
public NodeMetadata execute(Location location, String id) {
String region = getRegionFromLocation.apply(checkNotNull(location, "location"));
public NodeMetadata execute(String handle) {
String[] parts = parseHandle(handle);
String region = parts[0];
String id = parts[1];
RunningInstance runningInstance = Iterables.getOnlyElement(getAllRunningInstancesInRegion(
client, region, checkNotNull(id, "id")));
client, region, id));
return runningInstanceToNodeMetadata.apply(runningInstance);
}
}
public static Iterable<RunningInstance> getAllRunningInstancesInRegion(InstanceClient client,
String region, String id) {
return Iterables.concat(client.describeInstancesInRegion(region, id));
}
@Singleton
public static class EC2RebootNodeStrategy implements RebootNodeStrategy {
private final InstanceClient client;
private final GetRegionFromLocation getRegionFromLocation;
@Inject
protected EC2RebootNodeStrategy(InstanceClient client,
GetRegionFromLocation getRegionFromLocation) {
protected EC2RebootNodeStrategy(InstanceClient client) {
this.client = client;
this.getRegionFromLocation = getRegionFromLocation;
}
@Override
public boolean execute(Location location, String id) {
String region = getRegionFromLocation.apply(location);
public boolean execute(String handle) {
String[] parts = parseHandle(handle);
String region = parts[0];
String id = parts[1];
client.rebootInstancesInRegion(region, id);
return true;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -29,9 +29,9 @@ import javax.inject.Named;
import javax.inject.Singleton;
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.services.ElasticLoadBalancerClient;
import org.jclouds.aws.ec2.util.EC2Utils.GetRegionFromLocation;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.LoadBalancerStrategy;
import org.jclouds.domain.Location;
@ -42,8 +42,7 @@ import org.jclouds.logging.Logger;
* @author Adrian Cole
*/
@Singleton
public class EC2LoadBalancerStrategy implements LoadBalancerStrategy
{
public class EC2LoadBalancerStrategy implements LoadBalancerStrategy {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
@ -51,58 +50,49 @@ public class EC2LoadBalancerStrategy implements LoadBalancerStrategy
protected final GetRegionFromLocation getRegionFromLocation;
@Inject
protected EC2LoadBalancerStrategy(EC2Client ec2Client, GetRegionFromLocation getRegionFromLocation)
{
protected EC2LoadBalancerStrategy(EC2Client ec2Client,
GetRegionFromLocation getRegionFromLocation) {
this.ec2Client = ec2Client;
this.getRegionFromLocation = getRegionFromLocation;
}
@Override
public String execute(Location location, String name,
String protocol, Integer loadBalancerPort, Integer instancePort,
Set<String> instanceIds)
{
public String execute(Location location, String name, String protocol, int loadBalancerPort,
int instancePort, Set<String> instanceIds) {
String region = getRegionFromLocation.apply(location);
String dnsName = new String();
// TODO: Fix temp hack
String availabilityZone = new String();
for (String az : AvailabilityZone.zones)
{
for (String az : AvailabilityZone.zones) {
if (az.startsWith(region))
availabilityZone = az;
}
ElasticLoadBalancerClient elbClient = ec2Client
.getElasticLoadBalancerServices();
ElasticLoadBalancerClient elbClient = ec2Client.getElasticLoadBalancerServices();
dnsName = elbClient.createLoadBalancer(region, name, protocol,
loadBalancerPort, instancePort, availabilityZone);
dnsName = elbClient.createLoadBalancerInRegion(region, name, protocol, loadBalancerPort,
instancePort, availabilityZone);
List<String> instanceIdlist = new ArrayList<String>(instanceIds);
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);
}
Set<String> registeredInstanceIds = elbClient
.registerInstancesWithLoadBalancer(region, name,
instanceIdArray);
Set<String> registeredInstanceIds = elbClient.registerInstancesWithLoadBalancerInRegion(
region, name, instanceIdArray);
// deregister instances
boolean changed = registeredInstanceIds.removeAll(instanceIds);
if (changed)
{
if (changed) {
List<String> list = new ArrayList<String>(registeredInstanceIds);
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);
}
if(instanceIdArray.length>0)
elbClient.deregisterInstancesWithLoadBalancer(region, name,
instanceIdArray);
if (instanceIdArray.length > 0)
elbClient.deregisterInstancesWithLoadBalancerInRegion(region, name, instanceIdArray);
}
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;
import java.util.HashSet;
import java.util.Set;
public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
{
/**
*
*
* @author Lili Nader
*/
public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer> {
private String region;
private String name;
@ -17,18 +38,15 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
private LBCookieStickinessPolicy lBCookieStickinessPolicy;
private Set<LoadBalancerListener> loadBalancerListeners;
public ElasticLoadBalancer()
{
public ElasticLoadBalancer() {
super();
this.instanceIds = new HashSet<String>();
this.availabilityZones = new HashSet<String>();
this.loadBalancerListeners = new HashSet<LoadBalancerListener>();
}
public ElasticLoadBalancer(String region, String name,
Set<String> instanceIds, Set<String> availabilityZones,
String dnsName)
{
public ElasticLoadBalancer(String region, String name, Set<String> instanceIds,
Set<String> availabilityZones, String dnsName) {
super();
this.region = region;
this.name = name;
@ -38,128 +56,95 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
this.loadBalancerListeners = new HashSet<LoadBalancerListener>();
}
public void setRegion(String region)
{
public void setRegion(String region) {
this.region = region;
}
public void setName(String name)
{
public void setName(String name) {
this.name = name;
}
public void setInstanceIds(Set<String> instanceIds)
{
public void setInstanceIds(Set<String> instanceIds) {
this.instanceIds = instanceIds;
}
public void setAvailabilityZones(Set<String> availabilityZones)
{
public void setAvailabilityZones(Set<String> availabilityZones) {
this.availabilityZones = availabilityZones;
}
public void setDnsName(String dnsName)
{
public void setDnsName(String dnsName) {
this.dnsName = dnsName;
}
public void setAppCookieStickinessPolicy(
AppCookieStickinessPolicy appCookieStickinessPolicy)
{
public void setAppCookieStickinessPolicy(AppCookieStickinessPolicy appCookieStickinessPolicy) {
this.appCookieStickinessPolicy = appCookieStickinessPolicy;
}
public void setlBCookieStickinessPolicy(
LBCookieStickinessPolicy lBCookieStickinessPolicy)
{
public void setlBCookieStickinessPolicy(LBCookieStickinessPolicy lBCookieStickinessPolicy) {
this.lBCookieStickinessPolicy = lBCookieStickinessPolicy;
}
public void setLoadBalancerListeners(
Set<LoadBalancerListener> loadBalancerListeners)
{
public void setLoadBalancerListeners(Set<LoadBalancerListener> loadBalancerListeners) {
this.loadBalancerListeners = loadBalancerListeners;
}
public String getName()
{
public String getName() {
return name;
}
public Set<String> getInstanceIds()
{
public Set<String> getInstanceIds() {
return instanceIds;
}
public Set<String> getAvailabilityZones()
{
public Set<String> getAvailabilityZones() {
return availabilityZones;
}
public String getDnsName()
{
public String getDnsName() {
return dnsName;
}
public AppCookieStickinessPolicy getAppCookieStickinessPolicy()
{
public AppCookieStickinessPolicy getAppCookieStickinessPolicy() {
return appCookieStickinessPolicy;
}
public LBCookieStickinessPolicy getlBCookieStickinessPolicy()
{
public LBCookieStickinessPolicy getlBCookieStickinessPolicy() {
return lBCookieStickinessPolicy;
}
public Set<LoadBalancerListener> getLoadBalancerListeners()
{
public Set<LoadBalancerListener> getLoadBalancerListeners() {
return loadBalancerListeners;
}
public String getRegion()
{
public String getRegion() {
return region;
}
@Override
public int compareTo(ElasticLoadBalancer that)
{
public int compareTo(ElasticLoadBalancer that) {
return name.compareTo(that.name);
}
@Override
public int hashCode()
{
public int hashCode() {
final int prime = 31;
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
+ ((instanceIds == null) ? 0 : instanceIds.hashCode());
result = prime
* result
+ ((lBCookieStickinessPolicy == null) ? 0
: lBCookieStickinessPolicy.hashCode());
result = prime
* result
+ ((loadBalancerListeners == null) ? 0 : loadBalancerListeners
.hashCode());
+ ((appCookieStickinessPolicy == null) ? 0 : appCookieStickinessPolicy.hashCode());
result = prime * result + ((availabilityZones == null) ? 0 : availabilityZones.hashCode());
result = prime * result + ((dnsName == null) ? 0 : dnsName.hashCode());
result = prime * result + ((instanceIds == null) ? 0 : instanceIds.hashCode());
result = prime * result
+ ((lBCookieStickinessPolicy == null) ? 0 : lBCookieStickinessPolicy.hashCode());
result = prime * result
+ ((loadBalancerListeners == null) ? 0 : loadBalancerListeners.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((region == null) ? 0 : region.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
@ -167,125 +152,90 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
if (getClass() != obj.getClass())
return false;
ElasticLoadBalancer other = (ElasticLoadBalancer) obj;
if (appCookieStickinessPolicy == null)
{
if (appCookieStickinessPolicy == null) {
if (other.appCookieStickinessPolicy != null)
return false;
}
else if (!appCookieStickinessPolicy
.equals(other.appCookieStickinessPolicy))
} else if (!appCookieStickinessPolicy.equals(other.appCookieStickinessPolicy))
return false;
if (availabilityZones == null)
{
if (availabilityZones == null) {
if (other.availabilityZones != null)
return false;
}
else if (!availabilityZones.equals(other.availabilityZones))
} else if (!availabilityZones.equals(other.availabilityZones))
return false;
if (dnsName == null)
{
if (dnsName == null) {
if (other.dnsName != null)
return false;
}
else if (!dnsName.equals(other.dnsName))
} else if (!dnsName.equals(other.dnsName))
return false;
if (instanceIds == null)
{
if (instanceIds == null) {
if (other.instanceIds != null)
return false;
}
else if (!instanceIds.equals(other.instanceIds))
} else if (!instanceIds.equals(other.instanceIds))
return false;
if (lBCookieStickinessPolicy == null)
{
if (lBCookieStickinessPolicy == null) {
if (other.lBCookieStickinessPolicy != null)
return false;
}
else if (!lBCookieStickinessPolicy
.equals(other.lBCookieStickinessPolicy))
} else if (!lBCookieStickinessPolicy.equals(other.lBCookieStickinessPolicy))
return false;
if (loadBalancerListeners == null)
{
if (loadBalancerListeners == null) {
if (other.loadBalancerListeners != null)
return false;
}
else if (!loadBalancerListeners.equals(other.loadBalancerListeners))
} else if (!loadBalancerListeners.equals(other.loadBalancerListeners))
return false;
if (name == null)
{
if (name == null) {
if (other.name != null)
return false;
}
else if (!name.equals(other.name))
} else if (!name.equals(other.name))
return false;
if (region == null)
{
if (region == null) {
if (other.region != null)
return false;
}
else if (!region.equals(other.region))
} else if (!region.equals(other.region))
return false;
return true;
}
public static class AppCookieStickinessPolicy
{
public static class AppCookieStickinessPolicy {
private String policyName;
private String cookieName;
public AppCookieStickinessPolicy()
{
public AppCookieStickinessPolicy() {
super();
}
public AppCookieStickinessPolicy(String policyName, String cookieName)
{
public AppCookieStickinessPolicy(String policyName, String cookieName) {
super();
this.policyName = policyName;
this.cookieName = cookieName;
}
public String getPolicyName()
{
public String getPolicyName() {
return policyName;
}
public String getCookieName()
{
public String getCookieName() {
return cookieName;
}
public void setPolicyName(String policyName)
{
public void setPolicyName(String policyName) {
this.policyName = policyName;
}
public void setCookieName(String cookieName)
{
public void setCookieName(String cookieName) {
this.cookieName = cookieName;
}
@Override
public int hashCode()
{
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((cookieName == null) ? 0 : cookieName.hashCode());
result = prime * result
+ ((policyName == null) ? 0 : policyName.hashCode());
result = prime * result + ((cookieName == null) ? 0 : cookieName.hashCode());
result = prime * result + ((policyName == null) ? 0 : policyName.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
@ -293,82 +243,63 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
if (getClass() != obj.getClass())
return false;
AppCookieStickinessPolicy other = (AppCookieStickinessPolicy) obj;
if (cookieName == null)
{
if (cookieName == null) {
if (other.cookieName != null)
return false;
}
else if (!cookieName.equals(other.cookieName))
} else if (!cookieName.equals(other.cookieName))
return false;
if (policyName == null)
{
if (policyName == null) {
if (other.policyName != null)
return false;
}
else if (!policyName.equals(other.policyName))
} else if (!policyName.equals(other.policyName))
return false;
return true;
}
}
public static class LBCookieStickinessPolicy
{
public static class LBCookieStickinessPolicy {
private String policyName;
private Integer cookieExpirationPeriod;
public LBCookieStickinessPolicy()
{
public LBCookieStickinessPolicy() {
super();
}
public LBCookieStickinessPolicy(String policyName,
Integer cookieExpirationPeriod)
{
public LBCookieStickinessPolicy(String policyName, Integer cookieExpirationPeriod) {
super();
this.policyName = policyName;
this.cookieExpirationPeriod = cookieExpirationPeriod;
}
public String getPolicyName()
{
public String getPolicyName() {
return policyName;
}
public Integer getCookieExpirationPeriod()
{
public Integer getCookieExpirationPeriod() {
return cookieExpirationPeriod;
}
public void setPolicyName(String policyName)
{
public void setPolicyName(String policyName) {
this.policyName = policyName;
}
public void setCookieExpirationPeriod(Integer cookieExpirationPeriod)
{
public void setCookieExpirationPeriod(Integer cookieExpirationPeriod) {
this.cookieExpirationPeriod = cookieExpirationPeriod;
}
@Override
public int hashCode()
{
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime
* result
+ ((cookieExpirationPeriod == null) ? 0
: cookieExpirationPeriod.hashCode());
result = prime * result
+ ((policyName == null) ? 0 : policyName.hashCode());
+ ((cookieExpirationPeriod == null) ? 0 : cookieExpirationPeriod.hashCode());
result = prime * result + ((policyName == null) ? 0 : policyName.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
@ -376,38 +307,29 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
if (getClass() != obj.getClass())
return false;
LBCookieStickinessPolicy other = (LBCookieStickinessPolicy) obj;
if (cookieExpirationPeriod == null)
{
if (cookieExpirationPeriod == null) {
if (other.cookieExpirationPeriod != null)
return false;
}
else if (!cookieExpirationPeriod
.equals(other.cookieExpirationPeriod))
} else if (!cookieExpirationPeriod.equals(other.cookieExpirationPeriod))
return false;
if (policyName == null)
{
if (policyName == null) {
if (other.policyName != null)
return false;
}
else if (!policyName.equals(other.policyName))
} else if (!policyName.equals(other.policyName))
return false;
return true;
}
}
public static class LoadBalancerListener
{
public static class LoadBalancerListener {
private Set<String> policyNames;
private Integer instancePort;
private Integer loadBalancerPort;
private String protocol;
public LoadBalancerListener(Set<String> policyNames,
Integer instancePort, Integer loadBalancerPort, String protocol)
{
public LoadBalancerListener(Set<String> policyNames, Integer instancePort,
Integer loadBalancerPort, String protocol) {
super();
this.policyNames = policyNames;
this.instancePort = instancePort;
@ -415,72 +337,55 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
this.protocol = protocol;
}
public LoadBalancerListener()
{
public LoadBalancerListener() {
super();
}
public Set<String> getPolicyNames()
{
public Set<String> getPolicyNames() {
return policyNames;
}
public Integer getInstancePort()
{
public Integer getInstancePort() {
return instancePort;
}
public Integer getLoadBalancerPort()
{
public Integer getLoadBalancerPort() {
return loadBalancerPort;
}
public String getProtocol()
{
public String getProtocol() {
return protocol;
}
public void setPolicyNames(Set<String> policyNames)
{
public void setPolicyNames(Set<String> policyNames) {
this.policyNames = policyNames;
}
public void setInstancePort(Integer instancePort)
{
public void setInstancePort(Integer instancePort) {
this.instancePort = instancePort;
}
public void setLoadBalancerPort(Integer loadBalancerPort)
{
public void setLoadBalancerPort(Integer loadBalancerPort) {
this.loadBalancerPort = loadBalancerPort;
}
public void setProtocol(String protocol)
{
public void setProtocol(String protocol) {
this.protocol = protocol;
}
@Override
public int hashCode()
{
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((instancePort == null) ? 0 : instancePort.hashCode());
result = prime
* result
+ ((loadBalancerPort == null) ? 0 : loadBalancerPort
.hashCode());
result = prime * result
+ ((policyNames == null) ? 0 : policyNames.hashCode());
result = prime * result
+ ((protocol == null) ? 0 : protocol.hashCode());
result = prime * result + ((instancePort == null) ? 0 : instancePort.hashCode());
result = prime * result + ((loadBalancerPort == null) ? 0 : loadBalancerPort.hashCode());
result = prime * result + ((policyNames == null) ? 0 : policyNames.hashCode());
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
return result;
}
@Override
public boolean equals(Object obj)
{
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
@ -488,38 +393,28 @@ public class ElasticLoadBalancer implements Comparable<ElasticLoadBalancer>
if (getClass() != obj.getClass())
return false;
LoadBalancerListener other = (LoadBalancerListener) obj;
if (instancePort == null)
{
if (instancePort == null) {
if (other.instancePort != null)
return false;
}
else if (!instancePort.equals(other.instancePort))
} else if (!instancePort.equals(other.instancePort))
return false;
if (loadBalancerPort == null)
{
if (loadBalancerPort == null) {
if (other.loadBalancerPort != null)
return false;
}
else if (!loadBalancerPort.equals(other.loadBalancerPort))
} else if (!loadBalancerPort.equals(other.loadBalancerPort))
return false;
if (policyNames == null)
{
if (policyNames == null) {
if (other.policyNames != null)
return false;
}
else if (!policyNames.equals(other.policyNames))
} else if (!policyNames.equals(other.policyNames))
return false;
if (protocol == null)
{
if (protocol == null) {
if (other.protocol != null)
return false;
}
else if (!protocol.equals(other.protocol))
} else if (!protocol.equals(other.protocol))
return false;
return true;
}
}
}

View File

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

View File

@ -38,44 +38,60 @@ public interface ElasticLoadBalancerClient {
/**
* Creates a load balancer
*
* @param name Name of the load balancer
* @param loadBalancerPort Port for the load balancer to listen on
* @param instancePort Port to forward the request to
* @param name
* Name of the load balancer
* @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
* @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
*
* @param name Name of the load balancer
* @param name
* Name of the load balancer
* @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
* @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
*
* @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
* @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
*
* @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> describeLoadBalancers(@Nullable String region, @Nullable String name);
Set<ElasticLoadBalancer> describeLoadBalancersInRegion(@Nullable String region,
@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.checkNotNull;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
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 com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
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,
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,
String prefix, Object input) {
checkArgument(checkNotNull(input, "input") instanceof Iterable<?>,

View File

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

View File

@ -125,7 +125,7 @@ public class EC2ComputeServiceTest {
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",
Architecture.X86_64, new Credentials("root", null));
replay(optionsProvider);

View File

@ -271,6 +271,7 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance instance = createMock(RunningInstance.class);
expect(instance.getId()).andReturn("id").atLeastOnce();
expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce();
expect(instance.getGroupIds()).andReturn(ImmutableSet.<String> of()).atLeastOnce();
expect(instance.getKeyName()).andReturn(null).atLeastOnce();
expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
@ -328,6 +329,7 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance instance = createMock(RunningInstance.class);
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.getKeyName()).andReturn(null).atLeastOnce();
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);
Set<Location> locations = ImmutableSet.<Location> of(location);
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)));
Location defaultLocation = createMock(Location.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);
Set<Location> locations = ImmutableSet.<Location> of(location);
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)));
Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class);

View File

@ -41,7 +41,7 @@ public class ElasticLoadBalancerAsyncClientTest extends
public void testRegisterInstancesWithLoadBalancer() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ElasticLoadBalancerAsyncClient.class.getMethod(
"registerInstancesWithLoadBalancer", String.class, String.class, String[].class);
"registerInstancesWithLoadBalancerInRegion", String.class, String.class, String[].class);
GeneratedHttpRequest<ElasticLoadBalancerAsyncClient> httpMethod = processor.createRequest(
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,
Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, Region.AP_SOUTHEAST_1,
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());
assertNotNull(dnsName);
assert (dnsName.startsWith(name));
@ -79,7 +79,7 @@ public class ElasticLoadBalancerClientLiveTest {
String name = "TestDescribeLoadBalancer";
for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_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);
assert (allResults.size() >= 1);
}
@ -89,7 +89,7 @@ public class ElasticLoadBalancerClientLiveTest {
void testDeleteLoadBalancer() {
for (String region : Lists.newArrayList(null, Region.EU_WEST_1, Region.US_EAST_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;
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 java.io.InputStream;
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 com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/**
@ -40,12 +33,9 @@ import com.google.common.collect.Sets;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ec2.RegisterInstancesWithLoadBalancerResponseHandlerTest")
public class RegisterInstancesWithLoadBalancerResponseHandlerTest extends
BaseEC2HandlerTest
{
public class RegisterInstancesWithLoadBalancerResponseHandlerTest extends BaseEC2HandlerTest {
public void testParse()
{
public void testParse() {
InputStream is = getClass().getResourceAsStream(
"/ec2/register_instances_with_loadbalancer.xml");
@ -53,14 +43,12 @@ public class RegisterInstancesWithLoadBalancerResponseHandlerTest extends
instanceIds.add("i-6055fa09");
instanceIds.add("i-9055fa55");
Set<String> result = parseXML(is);
assertEquals(result, instanceIds);
}
private Set<String> parseXML(InputStream is)
{
private Set<String> parseXML(InputStream is) {
RegisterInstancesWithLoadBalancerResponseHandler handler = injector
.getInstance(RegisterInstancesWithLoadBalancerResponseHandler.class);
Set<String> result = factory.create(handler).parse(is);

View File

@ -19,6 +19,7 @@
package org.jclouds.samples.googleappengine.functions;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -48,9 +49,9 @@ public class ComputeServiceContextToStatusResult implements Function<String, Sta
String name = "not found";
try {
long start = System.currentTimeMillis();
Map<String, ? extends ComputeMetadata> nodes = context.getComputeService().getNodes();
Set<? extends ComputeMetadata> nodes = context.getComputeService().listNodes();
if (nodes.size() > 0)
name = Iterables.get(nodes.keySet(), 0);
name = Iterables.get(nodes, 0).getId();
status = ((System.currentTimeMillis() - start) + "ms");
} catch (Exception e) {
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))))
(defn #^NodeMetadata node-details
"Retrieve the node metadata."
([location id] (node-details location id *compute*))
([#^Location location id #^ComputeService compute]
(.getNodeMetadata compute location id)))
"Retrieve the node metadata, given its handle."
([handle] (node-details handle *compute*))
([handle #^ComputeService compute]
(.getNodeMetadata compute handle)))
(defn reboot-nodes-with-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))))
(defn reboot-node
"Reboot a given node."
([location id] (reboot-node location id *compute*))
([#^Location location id #^ComputeService compute]
(.rebootNode compute location id)))
"Reboot a node, given its handle."
([handle] (reboot-node handle *compute*))
([handle #^ComputeService compute]
(.rebootNode compute handle)))
(defn destroy-nodes-with-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))))
(defn destroy-node
"Destroy a given node."
([location id] (destroy-node location id *compute*))
([#^Location location id #^ComputeService compute]
(.destroyNode compute location id)))
"Destroy a node, given its handle."
([handle] (destroy-node handle *compute*))
([handle #^ComputeService compute]
(.destroyNode compute handle)))
(defmacro state-predicate [node state]
`(= (.getState ~node)
@ -295,6 +295,11 @@ See http://code.google.com/p/jclouds for details."
[#^ComputeMetadata node]
(-?> node .getLocation .getId))
(defn handle
"Returns the compute node's handle"
[#^ComputeMetadata node]
(.getHandle node))
(define-accessors Template image size location options)
(define-accessors Image version os-family os-description architecture)
(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.ssh.ExecResponse;
import com.google.common.annotations.Beta;
import com.google.common.base.Predicate;
import com.google.inject.ImplementedBy;
@ -145,10 +146,10 @@ public interface ComputeService {
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
* destroyed.
* destroy the node, given its handle. If it is the only node in a tag set, the dependent
* 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
@ -160,9 +161,9 @@ public interface ComputeService {
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
@ -171,9 +172,9 @@ public interface ComputeService {
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
@ -215,31 +216,29 @@ public interface ComputeService {
throws RunScriptOnNodesException;
/**
* @param filter
* Predicate-based filter to define which nodes to loadbalance
* @param loadBalancerName
* Load balancer name
* @param protocol
* LoadBalancer transport protocol to use for routing - TCP or
* 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
* LoadBalancer transport protocol to use for routing - TCP or HTTP. This property
* cannot be modified for the life of the LoadBalancer.
* @param instancePort
* The InstancePort data type is simple type of type: integer. It
* is the TCP port on 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
* @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.
* @param filter
* Predicate-based filter to define on which nodes the script is
* to be executed
* @param instancePort
* The InstancePort data type is simple type of type: integer. It is the TCP port on
* 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
*/
String loadBalanceNodesMatching(String loadBalancerName, String protocol,
Integer loadBalancerPort, Integer instancePort,
Predicate<NodeMetadata> filter);
@Beta
String loadBalanceNodesMatching(Predicate<NodeMetadata> filter, String loadBalancerName,
String protocol, int loadBalancerPort, int instancePort);
@Beta
void deleteLoadBalancer(String loadBalancerName, Predicate<NodeMetadata> filter);
}

View File

@ -50,4 +50,12 @@ public interface ComputeMetadata extends ResourceMetadata<ComputeType> {
@Override
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;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
@ -35,10 +37,20 @@ public class ComputeMetadataImpl extends ResourceMetadataImpl<ComputeType> imple
/** The serialVersionUID */
private static final long serialVersionUID = 7374704415964898694L;
private final String handle;
public ComputeMetadataImpl(ComputeType type, String id, String name, Location location, URI uri,
Map<String, String> userMetadata) {
public ComputeMetadataImpl(ComputeType type, String id, String name, String handle,
Location location, URI uri, Map<String, String> 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 Credentials defaultCredentials;
public ImageImpl(String id, String name, Location location, URI uri,
public ImageImpl(String id, String name, String handle, Location location, URI uri,
Map<String, String> userMetadata, String description, String version,
@Nullable OsFamily osFamily, String osDescription, Architecture architecture,
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.osFamily = osFamily;
this.description = checkNotNull(description, "description");

View File

@ -54,12 +54,12 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
private final String tag;
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,
NodeState state, Iterable<InetAddress> publicAddresses,
Iterable<InetAddress> privateAddresses, Map<String, String> extra,
@Nullable Credentials credentials) {
super(ComputeType.NODE, id, name, location, uri, userMetadata);
super(ComputeType.NODE, id, name, handle, location, uri, userMetadata);
this.tag = tag;
this.image = image;
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();
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,
Iterable<Architecture> supportedArchitectures) {
super(ComputeType.SIZE, id, name, location, uri, userMetadata);
super(ComputeType.SIZE, id, name, handle, location, uri, userMetadata);
this.cores = cores;
this.ram = ram;
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.GetNodeMetadataStrategy;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.compute.strategy.LoadBalancerStrategy;
import org.jclouds.compute.strategy.RebootNodeStrategy;
import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.util.ComputeUtils;
@ -96,7 +95,6 @@ public class BaseComputeService implements ComputeService {
protected final RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy;
protected final RebootNodeStrategy rebootNodeStrategy;
protected final DestroyNodeStrategy destroyNodeStrategy;
protected final LoadBalancerStrategy loadBalancerStrategy;
protected final Provider<TemplateBuilder> templateBuilderProvider;
protected final Provider<TemplateOptions> templateOptionsProvider;
protected final ComputeUtils utils;
@ -109,7 +107,7 @@ public class BaseComputeService implements ComputeService {
GetNodeMetadataStrategy getNodeMetadataStrategy,
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy,
RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy,
LoadBalancerStrategy loadBalancerStrategy, Provider<TemplateBuilder> templateBuilderProvider,
Provider<TemplateBuilder> templateBuilderProvider,
Provider<TemplateOptions> templateOptionsProvider, ComputeUtils utils,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.context = checkNotNull(context, "context");
@ -123,7 +121,6 @@ public class BaseComputeService implements ComputeService {
"runNodesAndAddToSetStrategy");
this.rebootNodeStrategy = checkNotNull(rebootNodeStrategy, "rebootNodeStrategy");
this.destroyNodeStrategy = checkNotNull(destroyNodeStrategy, "destroyNodeStrategy");
this.loadBalancerStrategy = checkNotNull(loadBalancerStrategy, "loadBalancerStrategy");
this.templateBuilderProvider = checkNotNull(templateBuilderProvider,
"templateBuilderProvider");
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)",
count, count > 1 ? "s" : "", tag, template.getLocation().getId(), template
.getImage().getId(), template.getSize().getId(), template.getOptions());
final Set<NodeMetadata> nodes = Sets.newHashSet();
final Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
Set<NodeMetadata> nodes = Sets.newHashSet();
Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
Map<?, ListenableFuture<Void>> responses = runNodesAndAddToSetStrategy.execute(tag, count,
template, nodes, badNodes);
Map<?, Exception> executionExceptions = awaitCompletion(responses, executor, null, logger,
@ -185,12 +182,11 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc}
*/
@Override
public void destroyNode(Location location, String id) {
checkNotNull(location, "location");
checkNotNull(id, "id");
logger.debug(">> destroying node(%s/%s)", location.getId(), id);
boolean successful = destroyNodeStrategy.execute(location, id);
logger.debug("<< destroyed node(%s/%s) success(%s)", location.getId(), id, successful);
public void destroyNode(String handle) {
checkNotNull(handle, "handle");
logger.debug(">> destroying node(%s)", handle);
boolean successful = destroyNodeStrategy.execute(handle);
logger.debug("<< destroyed node(%s) success(%s)", handle, successful);
}
/**
@ -205,7 +201,7 @@ public class BaseComputeService implements ComputeService {
responses.put(node, makeListenable(executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
destroyNode(node.getLocation(), node.getId());
destroyNode(node.getHandle());
destroyedNodes.add(node);
return null;
}
@ -282,22 +278,20 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc}
*/
@Override
public NodeMetadata getNodeMetadata(Location location, String id) {
checkNotNull(location, "location");
checkNotNull(id, "id");
return getNodeMetadataStrategy.execute(location, id);
public NodeMetadata getNodeMetadata(String handle) {
checkNotNull(handle, "handle");
return getNodeMetadataStrategy.execute(handle);
}
/**
* {@inheritDoc}
*/
@Override
public void rebootNode(Location location, String id) {
checkNotNull(location, "location");
checkNotNull(id, "id");
logger.debug(">> rebooting node(%s/%s)", location.getId(), id);
boolean successful = rebootNodeStrategy.execute(location, id);
logger.debug("<< rebooted node(%s/%s) success(%s)", location.getId(), id, successful);
public void rebootNode(String handle) {
checkNotNull(handle, "handle");
logger.debug(">> rebooting node(%s)", handle);
boolean successful = rebootNodeStrategy.execute(handle);
logger.debug("<< rebooted node(%s) success(%s)", handle, successful);
}
/**
@ -312,7 +306,7 @@ public class BaseComputeService implements ComputeService {
responses.put(node, makeListenable(executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
rebootNode(node.getLocation(), node.getId());
rebootNode(node.getHandle());
return null;
}
}), executor));
@ -384,10 +378,6 @@ public class BaseComputeService implements ComputeService {
}
/**
* {@inheritDoc}
*/
private Iterable<? extends NodeMetadata> verifyParametersAndListNodes(
Predicate<NodeMetadata> filter, byte[] runScript, final RunScriptOptions options) {
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() {
return listNodesStrategy.listDetailsOnNodesMatching(NodePredicates.all());
}
@ -453,4 +421,16 @@ public class BaseComputeService implements ComputeService {
public TemplateOptions templateOptions() {
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;
import org.jclouds.domain.Location;
/**
* 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 {
boolean execute(Location location, String id);
boolean execute(String handle);
}

View File

@ -20,7 +20,6 @@
package org.jclouds.compute.strategy;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.domain.Location;
/**
* returns all details associated to the node below.
@ -29,6 +28,6 @@ import org.jclouds.domain.Location;
*/
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
*/
public interface LoadBalancerStrategy
{
public interface LoadBalancerStrategy {
String execute(Location loaction, String name, String protocol,
Integer loadBalancerPort, Integer instancePort,
Set<String> instanceIds);
String execute(Location loaction, String name, String protocol, int loadBalancerPort,
int instancePort, Set<String> instanceIds);
}

View File

@ -19,7 +19,6 @@
package org.jclouds.compute.strategy;
import org.jclouds.domain.Location;
/**
* Reboots a node unless it is in the state TERMINATED.
@ -28,6 +27,6 @@ import org.jclouds.domain.Location;
*/
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
*/
public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) {
return new NodeMetadataImpl(node.getId(), node.getName(), node.getLocation(), node.getUri(),
node.getUserMetadata(), node.getTag(), node.getImage(), node.getState(), node
.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(),
newCredentials);
return new NodeMetadataImpl(node.getId(), node.getName(), node.getHandle(), node
.getLocation(), node.getUri(), node.getUserMetadata(), node.getTag(), node
.getImage(), node.getState(), node.getPublicAddresses(), node.getPrivateAddresses(),
node.getExtra(), newCredentials);
}
/**

View File

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

View File

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

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,
location);
}
return new NodeMetadataImpl(from.getId() + "", from.getName(), location, null, ImmutableMap
.<String, String> of(), tag, image, state, ipSet, ImmutableList.<InetAddress> of(),
ImmutableMap.<String, String> of(), creds);
return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location,
null, ImmutableMap.<String, String> of(), tag, image, state, ipSet, ImmutableList
.<InetAddress> of(), ImmutableMap.<String, String> of(), creds);
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -48,7 +48,7 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assert node.getId() != null;
assert node.getLocation() != null;
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("disk_drive/1/kb") != 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> {
@Override
public Size apply(ComputeOptions from) {
return new SizeImpl(from.toString(), from.toString(), null, null, ImmutableMap
.<String, String> of(), from.getProcessorCount(), from.getMemory(), 10,
ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64));
return new SizeImpl(from.toString(), from.toString(), from.toString(), null, null,
ImmutableMap.<String, String> of(), from.getProcessorCount(), from.getMemory(),
10, ImmutableSet.<Architecture> of(Architecture.X86_32, Architecture.X86_64));
}
}
@ -149,10 +149,10 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer
.getId());
images.add(new ImageImpl(resource.getId(), template.getName(),
location, template.getLocation(), ImmutableMap
.<String, String> of(), template.getDescription(),
"", myOs, template.getName(), arch, credentialsProvider
.execute(template)));
resource.getId(), location, template.getLocation(),
ImmutableMap.<String, String> of(), template
.getDescription(), "", myOs, template.getName(),
arch, credentialsProvider.execute(template)));
return null;
}
}), executor));