diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java index 7144b7e450..ef6f75857b 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java @@ -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 credentialsMap; private final Map 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 templateBuilderProvider, Provider 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 credentialsMap, Map 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,69 +127,53 @@ public class EC2ComputeService extends BaseComputeService { Map 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 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 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 ids = new HashSet(); - 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 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); - } - - /** + /** * returns template options, except of type {@link EC2TemplateOptions}. */ @Override public EC2TemplateOptions templateOptions() { return EC2TemplateOptions.class.cast(super.templateOptions()); } + + @Override + public String loadBalanceNodesMatching(Predicate 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 ids = new HashSet(); + 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 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); + } + } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java index 7228605747..c808d29185 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -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>>() { }).annotatedWith(Jsr330.named("volumeMapping")).to(RunningInstanceToStorageMappingUnix.class) .in(Scopes.SINGLETON); @@ -164,7 +165,7 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; - + private final InstanceClient client; private final Map regionMap; private final RunningInstanceToNodeMetadata runningInstanceToNodeMetadata; @@ -214,61 +215,45 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule { } } - @Singleton - public static class GetRegionFromLocation implements Function { - 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 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; } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java index f11b592abb..4c768fdc29 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java @@ -36,9 +36,8 @@ public class EC2Size extends SizeImpl { EC2Size(String instanceType, Double cores, Integer ram, Integer disk, Iterable supportedArchitectures) { - super(instanceType, - instanceType, null, null, - ImmutableMap. of(),cores, ram, disk, supportedArchitectures); + super(instanceType, instanceType, instanceType, null, null, ImmutableMap + . of(), cores, ram, disk, supportedArchitectures); this.instanceType = instanceType; } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java index ad9e8468a0..c7bd858481 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java @@ -140,6 +140,7 @@ public class ImageParser implements Function of("owner", from.getImageOwnerId()), diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java index a0408cc612..6c23ac4c49 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadata.java @@ -170,8 +170,9 @@ public class RunningInstanceToNodeMetadata implements Function instanceStateTerminated; - protected final GetRegionFromLocation getRegionFromLocation; protected final GetNodeMetadataStrategy getNodeMetadataStrategy; @Inject protected EC2DestroyNodeStrategy(EC2Client ec2Client, @Named("TERMINATED") Predicate 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)))); diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/EC2LoadBalancerStrategy.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/EC2LoadBalancerStrategy.java index 7c7871aeac..e9141b5173 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/EC2LoadBalancerStrategy.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/EC2LoadBalancerStrategy.java @@ -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,69 +42,59 @@ import org.jclouds.logging.Logger; * @author Adrian Cole */ @Singleton -public class EC2LoadBalancerStrategy implements LoadBalancerStrategy -{ - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - protected final EC2Client ec2Client; - protected final GetRegionFromLocation getRegionFromLocation; +public class EC2LoadBalancerStrategy implements LoadBalancerStrategy { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + protected final EC2Client ec2Client; + protected final GetRegionFromLocation getRegionFromLocation; - @Inject - protected EC2LoadBalancerStrategy(EC2Client ec2Client, GetRegionFromLocation getRegionFromLocation) - { - this.ec2Client = ec2Client; - this.getRegionFromLocation = getRegionFromLocation; - } + @Inject + 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 instanceIds) - { - String region = getRegionFromLocation.apply(location); - String dnsName = new String(); + @Override + public String execute(Location location, String name, String protocol, int loadBalancerPort, + int instancePort, Set instanceIds) { + String region = getRegionFromLocation.apply(location); + String dnsName = new String(); - // TODO: Fix temp hack - String availabilityZone = new String(); - for (String az : AvailabilityZone.zones) - { - if (az.startsWith(region)) - availabilityZone = az; - } + // TODO: Fix temp hack + String availabilityZone = new String(); + 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 instanceIdlist = new ArrayList(instanceIds); - String[] instanceIdArray = new String[instanceIdlist.size()]; - for(int i=0; i registeredInstanceIds = elbClient - .registerInstancesWithLoadBalancer(region, name, - instanceIdArray); + List instanceIdlist = new ArrayList(instanceIds); + String[] instanceIdArray = new String[instanceIdlist.size()]; + for (int i = 0; i < instanceIdlist.size(); i++) { + instanceIdArray[i] = instanceIdlist.get(i); + } - // deregister instances - boolean changed = registeredInstanceIds.removeAll(instanceIds); - if (changed) - { - List list = new ArrayList(registeredInstanceIds); - instanceIdArray = new String[list.size()]; - for(int i=0; i0) - elbClient.deregisterInstancesWithLoadBalancer(region, name, - instanceIdArray); - } + Set registeredInstanceIds = elbClient.registerInstancesWithLoadBalancerInRegion( + region, name, instanceIdArray); - return dnsName; - } + // deregister instances + boolean changed = registeredInstanceIds.removeAll(instanceIds); + if (changed) { + List list = new ArrayList(registeredInstanceIds); + instanceIdArray = new String[list.size()]; + for (int i = 0; i < list.size(); i++) { + instanceIdArray[i] = list.get(i); + } + if (instanceIdArray.length > 0) + elbClient.deregisterInstancesWithLoadBalancerInRegion(region, name, instanceIdArray); + } + + return dnsName; + } } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/domain/ElasticLoadBalancer.java b/aws/core/src/main/java/org/jclouds/aws/ec2/domain/ElasticLoadBalancer.java index 7001ffc98a..594d326569 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/domain/ElasticLoadBalancer.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/domain/ElasticLoadBalancer.java @@ -1,525 +1,420 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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; +/** + * + * + * @author Lili Nader + */ +public class ElasticLoadBalancer implements Comparable { -public class ElasticLoadBalancer implements Comparable -{ - + private String region; + private String name; + private Set instanceIds; + private Set availabilityZones; + private String dnsName; + private AppCookieStickinessPolicy appCookieStickinessPolicy; + private LBCookieStickinessPolicy lBCookieStickinessPolicy; + private Set loadBalancerListeners; - private String region; - private String name; - private Set instanceIds; - private Set availabilityZones; - private String dnsName; - private AppCookieStickinessPolicy appCookieStickinessPolicy; - private LBCookieStickinessPolicy lBCookieStickinessPolicy; - private Set loadBalancerListeners; + public ElasticLoadBalancer() { + super(); + this.instanceIds = new HashSet(); + this.availabilityZones = new HashSet(); + this.loadBalancerListeners = new HashSet(); + } - public ElasticLoadBalancer() - { - super(); - this.instanceIds = new HashSet(); - this.availabilityZones = new HashSet(); - this.loadBalancerListeners = new HashSet(); - } + public ElasticLoadBalancer(String region, String name, Set instanceIds, + Set availabilityZones, String dnsName) { + super(); + this.region = region; + this.name = name; + this.instanceIds = instanceIds; + this.availabilityZones = availabilityZones; + this.dnsName = dnsName; + this.loadBalancerListeners = new HashSet(); + } - public ElasticLoadBalancer(String region, String name, - Set instanceIds, Set availabilityZones, - String dnsName) - { - super(); - this.region = region; - this.name = name; - this.instanceIds = instanceIds; - this.availabilityZones = availabilityZones; - this.dnsName = dnsName; - this.loadBalancerListeners = new HashSet(); - } + public void setRegion(String region) { + this.region = region; + } + public void setName(String name) { + this.name = name; + } - public void setRegion(String region) - { - this.region = region; - } + public void setInstanceIds(Set instanceIds) { + this.instanceIds = instanceIds; + } - public void setName(String name) - { - this.name = name; - } + public void setAvailabilityZones(Set availabilityZones) { + this.availabilityZones = availabilityZones; + } - public void setInstanceIds(Set instanceIds) - { - this.instanceIds = instanceIds; - } + public void setDnsName(String dnsName) { + this.dnsName = dnsName; + } - public void setAvailabilityZones(Set availabilityZones) - { - this.availabilityZones = availabilityZones; - } + public void setAppCookieStickinessPolicy(AppCookieStickinessPolicy appCookieStickinessPolicy) { + this.appCookieStickinessPolicy = appCookieStickinessPolicy; + } - public void setDnsName(String dnsName) - { - this.dnsName = dnsName; - } + public void setlBCookieStickinessPolicy(LBCookieStickinessPolicy lBCookieStickinessPolicy) { + this.lBCookieStickinessPolicy = lBCookieStickinessPolicy; + } - public void setAppCookieStickinessPolicy( - AppCookieStickinessPolicy appCookieStickinessPolicy) - { - this.appCookieStickinessPolicy = appCookieStickinessPolicy; - } + public void setLoadBalancerListeners(Set loadBalancerListeners) { + this.loadBalancerListeners = loadBalancerListeners; + } - public void setlBCookieStickinessPolicy( - LBCookieStickinessPolicy lBCookieStickinessPolicy) - { - this.lBCookieStickinessPolicy = lBCookieStickinessPolicy; - } + public String getName() { + return name; + } - public void setLoadBalancerListeners( - Set loadBalancerListeners) - { - this.loadBalancerListeners = loadBalancerListeners; - } + public Set getInstanceIds() { + return instanceIds; + } - public String getName() - { - return name; - } + public Set getAvailabilityZones() { + return availabilityZones; + } - public Set getInstanceIds() - { - return instanceIds; - } + public String getDnsName() { + return dnsName; + } - public Set getAvailabilityZones() - { - return availabilityZones; - } + public AppCookieStickinessPolicy getAppCookieStickinessPolicy() { + return appCookieStickinessPolicy; + } - public String getDnsName() - { - return dnsName; - } + public LBCookieStickinessPolicy getlBCookieStickinessPolicy() { + return lBCookieStickinessPolicy; + } - public AppCookieStickinessPolicy getAppCookieStickinessPolicy() - { - return appCookieStickinessPolicy; - } + public Set getLoadBalancerListeners() { + return loadBalancerListeners; + } - public LBCookieStickinessPolicy getlBCookieStickinessPolicy() - { - return lBCookieStickinessPolicy; - } + public String getRegion() { + return region; + } - public Set getLoadBalancerListeners() - { - return loadBalancerListeners; - } + @Override + public int compareTo(ElasticLoadBalancer that) { + return name.compareTo(that.name); + } - public String getRegion() - { - return region; - } + @Override + 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()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((region == null) ? 0 : region.hashCode()); + return result; + } - @Override - public int compareTo(ElasticLoadBalancer that) - { - return name.compareTo(that.name); - } - - @Override - 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()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((region == null) ? 0 : region.hashCode()); - return result; - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ElasticLoadBalancer other = (ElasticLoadBalancer) obj; + if (appCookieStickinessPolicy == null) { + if (other.appCookieStickinessPolicy != null) + return false; + } else if (!appCookieStickinessPolicy.equals(other.appCookieStickinessPolicy)) + return false; + if (availabilityZones == null) { + if (other.availabilityZones != null) + return false; + } else if (!availabilityZones.equals(other.availabilityZones)) + return false; + if (dnsName == null) { + if (other.dnsName != null) + return false; + } else if (!dnsName.equals(other.dnsName)) + return false; + if (instanceIds == null) { + if (other.instanceIds != null) + return false; + } else if (!instanceIds.equals(other.instanceIds)) + return false; + if (lBCookieStickinessPolicy == null) { + if (other.lBCookieStickinessPolicy != null) + return false; + } else if (!lBCookieStickinessPolicy.equals(other.lBCookieStickinessPolicy)) + return false; + if (loadBalancerListeners == null) { + if (other.loadBalancerListeners != null) + return false; + } else if (!loadBalancerListeners.equals(other.loadBalancerListeners)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (region == null) { + if (other.region != null) + return false; + } else if (!region.equals(other.region)) + return false; + return true; + } - @Override - public boolean equals(Object obj) - { - if (this == obj) + public static class AppCookieStickinessPolicy { + private String policyName; + private String cookieName; + + public AppCookieStickinessPolicy() { + super(); + } + + public AppCookieStickinessPolicy(String policyName, String cookieName) { + super(); + this.policyName = policyName; + this.cookieName = cookieName; + } + + public String getPolicyName() { + return policyName; + } + + public String getCookieName() { + return cookieName; + } + + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public void setCookieName(String cookieName) { + this.cookieName = cookieName; + } + + @Override + 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()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; - if (obj == null) + if (obj == null) return false; - if (getClass() != obj.getClass()) + if (getClass() != obj.getClass()) return false; - ElasticLoadBalancer other = (ElasticLoadBalancer) obj; - if (appCookieStickinessPolicy == null) - { - if (other.appCookieStickinessPolicy != null) - return false; - } - else if (!appCookieStickinessPolicy - .equals(other.appCookieStickinessPolicy)) + AppCookieStickinessPolicy other = (AppCookieStickinessPolicy) obj; + if (cookieName == null) { + if (other.cookieName != null) + return false; + } else if (!cookieName.equals(other.cookieName)) return false; - if (availabilityZones == null) - { - if (other.availabilityZones != null) - return false; - } - else if (!availabilityZones.equals(other.availabilityZones)) + if (policyName == null) { + if (other.policyName != null) + return false; + } else if (!policyName.equals(other.policyName)) return false; - if (dnsName == null) - { - if (other.dnsName != null) - return false; - } - else if (!dnsName.equals(other.dnsName)) - return false; - if (instanceIds == null) - { - if (other.instanceIds != null) - return false; - } - else if (!instanceIds.equals(other.instanceIds)) - return false; - if (lBCookieStickinessPolicy == null) - { - if (other.lBCookieStickinessPolicy != null) - return false; - } - else if (!lBCookieStickinessPolicy - .equals(other.lBCookieStickinessPolicy)) - return false; - if (loadBalancerListeners == null) - { - if (other.loadBalancerListeners != null) - return false; - } - else if (!loadBalancerListeners.equals(other.loadBalancerListeners)) - return false; - if (name == null) - { - if (other.name != null) - return false; - } - else if (!name.equals(other.name)) - return false; - if (region == null) - { - if (other.region != null) - return false; - } - else if (!region.equals(other.region)) - return false; - return true; - } + return true; + } + } + public static class LBCookieStickinessPolicy { + private String policyName; + private Integer cookieExpirationPeriod; + public LBCookieStickinessPolicy() { + super(); + } + public LBCookieStickinessPolicy(String policyName, Integer cookieExpirationPeriod) { + super(); + this.policyName = policyName; + this.cookieExpirationPeriod = cookieExpirationPeriod; + } + public String getPolicyName() { + return policyName; + } - public static class AppCookieStickinessPolicy - { - private String policyName; - private String cookieName; + public Integer getCookieExpirationPeriod() { + return cookieExpirationPeriod; + } - - public AppCookieStickinessPolicy() - { - super(); - } + public void setPolicyName(String policyName) { + this.policyName = policyName; + } - public AppCookieStickinessPolicy(String policyName, String cookieName) - { - super(); - this.policyName = policyName; - this.cookieName = cookieName; - } + public void setCookieExpirationPeriod(Integer cookieExpirationPeriod) { + this.cookieExpirationPeriod = cookieExpirationPeriod; + } - public String getPolicyName() - { - return policyName; - } + @Override + 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()); + return result; + } - public String getCookieName() - { - return cookieName; - } - - public void setPolicyName(String policyName) - { - this.policyName = policyName; - } - - public void setCookieName(String cookieName) - { - this.cookieName = cookieName; - } - - @Override - 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()); - return result; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AppCookieStickinessPolicy other = (AppCookieStickinessPolicy) obj; - if (cookieName == null) - { - if (other.cookieName != null) - return false; - } - else if (!cookieName.equals(other.cookieName)) - return false; - if (policyName == null) - { - if (other.policyName != null) - return false; - } - else if (!policyName.equals(other.policyName)) - return false; + @Override + public boolean equals(Object obj) { + if (this == obj) return true; - } - - + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + LBCookieStickinessPolicy other = (LBCookieStickinessPolicy) obj; + if (cookieExpirationPeriod == null) { + if (other.cookieExpirationPeriod != null) + return false; + } else if (!cookieExpirationPeriod.equals(other.cookieExpirationPeriod)) + return false; + if (policyName == null) { + if (other.policyName != null) + return false; + } else if (!policyName.equals(other.policyName)) + return false; + return true; + } - } + } - public static class LBCookieStickinessPolicy - { - private String policyName; - private Integer cookieExpirationPeriod; + public static class LoadBalancerListener { + private Set policyNames; + private Integer instancePort; + private Integer loadBalancerPort; + private String protocol; - public LBCookieStickinessPolicy() - { - super(); - } + public LoadBalancerListener(Set policyNames, Integer instancePort, + Integer loadBalancerPort, String protocol) { + super(); + this.policyNames = policyNames; + this.instancePort = instancePort; + this.loadBalancerPort = loadBalancerPort; + this.protocol = protocol; + } - public LBCookieStickinessPolicy(String policyName, - Integer cookieExpirationPeriod) - { - super(); - this.policyName = policyName; - this.cookieExpirationPeriod = cookieExpirationPeriod; - } + public LoadBalancerListener() { + super(); + } - public String getPolicyName() - { - return policyName; - } + public Set getPolicyNames() { + return policyNames; + } - public Integer getCookieExpirationPeriod() - { - return cookieExpirationPeriod; - } + public Integer getInstancePort() { + return instancePort; + } - public void setPolicyName(String policyName) - { - this.policyName = policyName; - } + public Integer getLoadBalancerPort() { + return loadBalancerPort; + } - public void setCookieExpirationPeriod(Integer cookieExpirationPeriod) - { - this.cookieExpirationPeriod = cookieExpirationPeriod; - } + public String getProtocol() { + return protocol; + } - @Override - 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()); - return result; - } + public void setPolicyNames(Set policyNames) { + this.policyNames = policyNames; + } - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LBCookieStickinessPolicy other = (LBCookieStickinessPolicy) obj; - if (cookieExpirationPeriod == null) - { - if (other.cookieExpirationPeriod != null) - return false; - } - else if (!cookieExpirationPeriod - .equals(other.cookieExpirationPeriod)) - return false; - if (policyName == null) - { - if (other.policyName != null) - return false; - } - else if (!policyName.equals(other.policyName)) - return false; + public void setInstancePort(Integer instancePort) { + this.instancePort = instancePort; + } + + public void setLoadBalancerPort(Integer loadBalancerPort) { + this.loadBalancerPort = loadBalancerPort; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + @Override + 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()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; - } - - + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + LoadBalancerListener other = (LoadBalancerListener) obj; + if (instancePort == null) { + if (other.instancePort != null) + return false; + } else if (!instancePort.equals(other.instancePort)) + return false; + if (loadBalancerPort == null) { + if (other.loadBalancerPort != null) + return false; + } else if (!loadBalancerPort.equals(other.loadBalancerPort)) + return false; + if (policyNames == null) { + if (other.policyNames != null) + return false; + } else if (!policyNames.equals(other.policyNames)) + return false; + if (protocol == null) { + if (other.protocol != null) + return false; + } else if (!protocol.equals(other.protocol)) + return false; + return true; + } - } - - public static class LoadBalancerListener - { - private Set policyNames; - private Integer instancePort; - private Integer loadBalancerPort; - private String protocol; - - public LoadBalancerListener(Set policyNames, - Integer instancePort, Integer loadBalancerPort, String protocol) - { - super(); - this.policyNames = policyNames; - this.instancePort = instancePort; - this.loadBalancerPort = loadBalancerPort; - this.protocol = protocol; - } - - public LoadBalancerListener() - { - super(); - } - - public Set getPolicyNames() - { - return policyNames; - } - - public Integer getInstancePort() - { - return instancePort; - } - - public Integer getLoadBalancerPort() - { - return loadBalancerPort; - } - - public String getProtocol() - { - return protocol; - } - - public void setPolicyNames(Set policyNames) - { - this.policyNames = policyNames; - } - - public void setInstancePort(Integer instancePort) - { - this.instancePort = instancePort; - } - - public void setLoadBalancerPort(Integer loadBalancerPort) - { - this.loadBalancerPort = loadBalancerPort; - } - - public void setProtocol(String protocol) - { - this.protocol = protocol; - } - - @Override - 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()); - return result; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LoadBalancerListener other = (LoadBalancerListener) obj; - if (instancePort == null) - { - if (other.instancePort != null) - return false; - } - else if (!instancePort.equals(other.instancePort)) - return false; - if (loadBalancerPort == null) - { - if (other.loadBalancerPort != null) - return false; - } - else if (!loadBalancerPort.equals(other.loadBalancerPort)) - return false; - if (policyNames == null) - { - if (other.policyNames != null) - return false; - } - else if (!policyNames.equals(other.policyNames)) - return false; - if (protocol == null) - { - if (other.protocol != null) - return false; - } - else if (!protocol.equals(other.protocol)) - return false; - return true; - } - - - - } + } } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerAsyncClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerAsyncClient.java index 2520d7b837..9f28bc817e 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerAsyncClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerAsyncClient.java @@ -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 -{ - /** - * @see ElasticLoadBalancerClient#createLoadBalancer - */ - @POST - @Path("/") - @XMLResponseParser(CreateLoadBalancerResponseHandler.class) - @FormParams(keys = ACTION, values = "CreateLoadBalancer") - ListenableFuture createLoadBalancer( +public interface ElasticLoadBalancerAsyncClient { + /** + * @see ElasticLoadBalancerClient#createLoadBalancerInRegion + */ + @POST + @Path("/") + @XMLResponseParser(CreateLoadBalancerResponseHandler.class) + @FormParams(keys = ACTION, values = "CreateLoadBalancer") + ListenableFuture 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 - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "DeleteLoadBalancer") - ListenableFuture deleteLoadBalancer( + /** + * @see ElasticLoadBalancerClient#deleteLoadBalancerInRegion + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "DeleteLoadBalancer") + ListenableFuture deleteLoadBalancerInRegion( @EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @FormParam("LoadBalancerName") String name); - /** - * @see ElasticLoadBalancerClient#registerInstancesWithLoadBalancer - */ - @POST - @Path("/") - @XMLResponseParser(RegisterInstancesWithLoadBalancerResponseHandler.class) - @FormParams(keys = ACTION, values = "RegisterInstancesWithLoadBalancer") - ListenableFuture> registerInstancesWithLoadBalancer( + /** + * @see ElasticLoadBalancerClient#registerInstancesWithLoadBalancerInRegion + */ + @POST + @Path("/") + @XMLResponseParser(RegisterInstancesWithLoadBalancerResponseHandler.class) + @FormParams(keys = ACTION, values = "RegisterInstancesWithLoadBalancer") + ListenableFuture> registerInstancesWithLoadBalancerInRegion( @EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @FormParam("LoadBalancerName") String name, @BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds); - /** - * @see ElasticLoadBalancerClient#deregisterInstancesWithLoadBalancer - */ - @POST - @Path("/") - @FormParams(keys = ACTION, values = "DeregisterInstancesFromLoadBalancer") - ListenableFuture deregisterInstancesWithLoadBalancer( + /** + * @see ElasticLoadBalancerClient#deregisterInstancesWithLoadBalancerInRegion + */ + @POST + @Path("/") + @FormParams(keys = ACTION, values = "DeregisterInstancesFromLoadBalancer") + ListenableFuture deregisterInstancesWithLoadBalancerInRegion( @EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @FormParam("LoadBalancerName") String name, @BinderParam(BindELBInstanceIdsToIndexedFormParams.class) String... instanceIds); - /** - * @see ElasticLoadBalancerClient#describeLoadBalancers - */ - @POST - @Path("/") - @XMLResponseParser(DescribeLoadBalancersResponseHandler.class) - @FormParams(keys = ACTION, values = "DescribeLoadBalancers") - ListenableFuture> describeLoadBalancers( + /** + * @see ElasticLoadBalancerClient#describeLoadBalancersInRegion + */ + @POST + @Path("/") + @XMLResponseParser(DescribeLoadBalancersResponseHandler.class) + @FormParams(keys = ACTION, values = "DescribeLoadBalancers") + ListenableFuture> describeLoadBalancersInRegion( @EndpointParam(parser = ELBRegionToEndpoint.class) @Nullable String region, @FormParam("LoadBalancerName") @Nullable String name); diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerClient.java b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerClient.java index 0ee2921ac7..e26761cd25 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerClient.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerClient.java @@ -34,48 +34,64 @@ import org.jclouds.concurrent.Timeout; */ @Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) 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 - * @return dns the DNS name for the load balancer - * @see registerInstancesWithLoadBalancerInRegion(@Nullable String region, String name, + String... instanceIds); - /** - * Register instances with an existing 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 registerInstancesWithLoadBalancer(@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 describeLoadBalancers(@Nullable String region, @Nullable String name); + Set describeLoadBalancersInRegion(@Nullable String region, + @Nullable String name); } \ No newline at end of file diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java b/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java index 70a378bce6..26e63b744e 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/util/EC2Utils.java @@ -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 { + 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 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, diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java index d3b4dc1de6..e157b32b35 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java @@ -178,39 +178,37 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { cleanupExtendedStuff(securityGroupClient, keyPairClient, tag); } } - - @Test - public void testLoadBalanceNodesMatching() throws Exception{ - ElasticLoadBalancerClient elbClient = EC2Client.class.cast( - context.getProviderSpecificContext().getApi()) - .getElasticLoadBalancerServices(); + @Test + public void testLoadBalanceNodesMatching() throws Exception { - String tag = "jcloudsElbTest"; - Template template = client.templateBuilder().build(); - Set nodes = client.runNodesWithTag(tag, 2, - template); - Set instanceIds = new HashSet(); - for (NodeMetadata node : nodes) - { + ElasticLoadBalancerClient elbClient = EC2Client.class.cast( + context.getProviderSpecificContext().getApi()).getElasticLoadBalancerServices(); + + String tag = "jcloudsElbTest"; + Template template = client.templateBuilder().build(); + try { + Set nodes = client.runNodesWithTag(tag, 2, template); + Set instanceIds = new HashSet(); + for (NodeMetadata node : nodes) { instanceIds.add(node.getId()); - } + } - // create load balancer - String dnsName = client.loadBalanceNodesMatching(tag, "HTTP", 80, 80, - NodePredicates.withTag(tag)); - assertNotNull(dnsName); - Set elbs = elbClient.describeLoadBalancers( - 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 - client.destroyNodesMatching(NodePredicates.withTag(tag)); - - } + // create load balancer + String dnsName = client.loadBalanceNodesMatching(NodePredicates.withTag(tag), tag, "HTTP", + 80, 80); + assertNotNull(dnsName); + Set elbs = elbClient.describeLoadBalancersInRegion(Region.US_EAST_1, + tag); + assertNotNull(elbs); + ElasticLoadBalancer elb = elbs.iterator().next(); + assertEquals(elb.getInstanceIds(), instanceIds); + } finally { + elbClient.deleteLoadBalancerInRegion(Region.US_EAST_1, tag); + // finaly destroy nodes + client.destroyNodesMatching(NodePredicates.withTag(tag)); + } + } private RunningInstance getInstance(InstanceClient instanceClient, String id) { RunningInstance instance = Iterables.getOnlyElement(Iterables.getOnlyElement(instanceClient diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceTest.java index db009e038e..8a5d83ae47 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceTest.java @@ -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 . newHashMap(), "description", "1.0", null, "ubuntu", Architecture.X86_64, new Credentials("root", null)); replay(optionsProvider); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index 198f9100f7..61b5662a5d 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -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. 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); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImplTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImplTest.java index 3ddccd0629..acf66331f6 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImplTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImplTest.java @@ -91,7 +91,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { Location location = new LocationImpl(LocationScope.REGION, "region", "region", null); Set locations = ImmutableSet. of(location); Set images = ImmutableSet. of(); - Set sizes = ImmutableSet. of(new SizeImpl(null, null, location, null, + Set sizes = ImmutableSet. of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap. of(), 1, 1, 1, EnumSet.allOf(Architecture.class))); Location defaultLocation = createMock(Location.class); Provider optionsProvider = createMock(Provider.class); @@ -127,7 +127,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { Location location = new LocationImpl(LocationScope.REGION, "region", "region", null); Set locations = ImmutableSet. of(location); Set images = ImmutableSet. of(); - Set sizes = ImmutableSet. of(new SizeImpl(null, null, location, null, + Set sizes = ImmutableSet. of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap. of(), 1, 1, 1, EnumSet.allOf(Architecture.class))); Location defaultLocation = createMock(Location.class); Provider optionsProvider = createMock(Provider.class); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerAsyncClientTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerAsyncClientTest.java index a8bef31db4..254a559314 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerAsyncClientTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerAsyncClientTest.java @@ -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 httpMethod = processor.createRequest( method, null, "ReferenceAP1", "i-6055fa09"); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerClientLiveTest.java index d8221566cb..9f3006b880 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/ElasticLoadBalancerClientLiveTest.java @@ -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 allResults = client.describeLoadBalancers(region, name); + Set 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"); } } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/RegisterInstancesWithLoadBalancerResponseHandlerTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/RegisterInstancesWithLoadBalancerResponseHandlerTest.java index adb5c8ac76..9584b294e5 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/xml/RegisterInstancesWithLoadBalancerResponseHandlerTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/xml/RegisterInstancesWithLoadBalancerResponseHandlerTest.java @@ -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,31 +33,26 @@ 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() - { - InputStream is = getClass().getResourceAsStream( - "/ec2/register_instances_with_loadbalancer.xml"); + public void testParse() { + InputStream is = getClass().getResourceAsStream( + "/ec2/register_instances_with_loadbalancer.xml"); - Set instanceIds = Sets.newHashSet(); - instanceIds.add("i-6055fa09"); - instanceIds.add("i-9055fa55"); - + Set instanceIds = Sets.newHashSet(); + instanceIds.add("i-6055fa09"); + instanceIds.add("i-9055fa55"); - Set result = parseXML(is); + Set result = parseXML(is); - assertEquals(result, instanceIds); - } + assertEquals(result, instanceIds); + } - private Set parseXML(InputStream is) - { - RegisterInstancesWithLoadBalancerResponseHandler handler = injector - .getInstance(RegisterInstancesWithLoadBalancerResponseHandler.class); - Set result = factory.create(handler).parse(is); - return result; - } + private Set parseXML(InputStream is) { + RegisterInstancesWithLoadBalancerResponseHandler handler = injector + .getInstance(RegisterInstancesWithLoadBalancerResponseHandler.class); + Set result = factory.create(handler).parse(is); + return result; + } } diff --git a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/ComputeServiceContextToStatusResult.java b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/ComputeServiceContextToStatusResult.java index ac768587ae..2ae83278a7 100644 --- a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/ComputeServiceContextToStatusResult.java +++ b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/ComputeServiceContextToStatusResult.java @@ -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 nodes = context.getComputeService().getNodes(); + Set 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); diff --git a/compute/src/main/clojure/org/jclouds/compute.clj b/compute/src/main/clojure/org/jclouds/compute.clj index d7df1d8a07..a522f4b559 100644 --- a/compute/src/main/clojure/org/jclouds/compute.clj +++ b/compute/src/main/clojure/org/jclouds/compute.clj @@ -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) diff --git a/compute/src/main/java/org/jclouds/compute/ComputeService.java b/compute/src/main/java/org/jclouds/compute/ComputeService.java index 84532c6b70..6ee2f21bc8 100755 --- a/compute/src/main/java/org/jclouds/compute/ComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeService.java @@ -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 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 destroyNodesMatching(Predicate 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 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 @@ -213,33 +214,31 @@ public interface ComputeService { Map runScriptOnNodesMatching( Predicate filter, byte[] runScript, RunScriptOptions options) throws RunScriptOnNodesException; - - /** - * @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 - * 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 - * LoadBalancer. - * @param filter - * Predicate-based filter to define on which nodes the script is - * to be executed - * @return DNS Name of the load balancer - */ - String loadBalanceNodesMatching(String loadBalancerName, String protocol, - Integer loadBalancerPort, Integer instancePort, - Predicate filter); - - void deleteLoadBalancer(String loadBalancerName, Predicate filter); + + /** + * @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 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 LoadBalancer. + * + * @return DNS Name of the load balancer + */ + @Beta + String loadBalanceNodesMatching(Predicate filter, String loadBalancerName, + String protocol, int loadBalancerPort, int instancePort); + + @Beta + void deleteLoadBalancer(String loadBalancerName, Predicate filter); } diff --git a/compute/src/main/java/org/jclouds/compute/domain/ComputeMetadata.java b/compute/src/main/java/org/jclouds/compute/domain/ComputeMetadata.java index 7399847076..f53f1e4f5e 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/ComputeMetadata.java +++ b/compute/src/main/java/org/jclouds/compute/domain/ComputeMetadata.java @@ -50,4 +50,12 @@ public interface ComputeMetadata extends ResourceMetadata { @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(); + } diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/ComputeMetadataImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/ComputeMetadataImpl.java index 298fd2b887..5a658c9f8f 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/ComputeMetadataImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/ComputeMetadataImpl.java @@ -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 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 userMetadata) { + public ComputeMetadataImpl(ComputeType type, String id, String name, String handle, + Location location, URI uri, Map userMetadata) { super(type, id, name, location, uri, userMetadata); + this.handle = checkNotNull(handle, "handle"); + } + + /** + * {@inheritDoc} + */ + @Override + public String getHandle() { + return handle; } } diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java index 5cb3e034af..1bb748ca72 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java @@ -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 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"); @@ -107,14 +106,14 @@ public class ImageImpl extends ComputeMetadataImpl implements Image { } /** - * {@inheritDoc} - */ + * {@inheritDoc} + */ @Override public Credentials getDefaultCredentials() { - return defaultCredentials; + return defaultCredentials; } - @Override + @Override public String toString() { return "[id=" + getId() + ", name=" + getName() + ", locationId=" + getLocation() + ", architecture=" + architecture + ", osDescription=" + osDescription diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java index 795cfe9b94..dec14ca51c 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java @@ -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 userMetadata, @Nullable String tag, @Nullable Image image, NodeState state, Iterable publicAddresses, Iterable privateAddresses, Map 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"); diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java index 8384d4fe1e..f3d532143a 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java @@ -48,10 +48,10 @@ public class SizeImpl extends ComputeMetadataImpl implements Size { private final Set 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 userMetadata, double cores, int ram, int disk, Iterable 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; diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java index 6237f9efbd..8239854944 100755 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -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 templateBuilderProvider; protected final Provider 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 templateBuilderProvider, + Provider templateBuilderProvider, Provider 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 nodes = Sets.newHashSet(); - final Map badNodes = Maps.newLinkedHashMap(); + Set nodes = Sets.newHashSet(); + Map badNodes = Maps.newLinkedHashMap(); Map> responses = runNodesAndAddToSetStrategy.execute(tag, count, template, nodes, badNodes); Map 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() { @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() { @Override public Void call() throws Exception { - rebootNode(node.getLocation(), node.getId()); + rebootNode(node.getHandle()); return null; } }), executor)); @@ -383,12 +377,8 @@ public class BaseComputeService implements ComputeService { return execs; } - - - /** - * {@inheritDoc} - */ - private Iterable verifyParametersAndListNodes( + + private Iterable verifyParametersAndListNodes( Predicate filter, byte[] runScript, final RunScriptOptions options) { checkNotNull(filter, "Filter must be provided"); checkNotNull(runScript, @@ -423,28 +413,6 @@ public class BaseComputeService implements ComputeService { }); } - - /** - * {@inheritDoc} - */ - public String loadBalanceNodesMatching(String loadBalancerName, - String protocol, Integer loadBalancerPort, Integer instancePort, - Predicate filter) - { - return null; - } - - - - /** - * {@inheritDoc} - */ - public void deleteLoadBalancer(String loadBalancerName, - Predicate filter) - { - - } - private Iterable 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 filter) { + throw new UnsupportedOperationException("deleteLoadBalancer not supported in this cloud"); + } + + @Override + public String loadBalanceNodesMatching(Predicate filter, String loadBalancerName, + String protocol, int loadBalancerPort, int instancePort) { + throw new UnsupportedOperationException( + "loadBalanceNodesMatching not supported in this cloud"); + } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/strategy/DestroyNodeStrategy.java b/compute/src/main/java/org/jclouds/compute/strategy/DestroyNodeStrategy.java index 7534dd71a0..6a6e6ad2a1 100644 --- a/compute/src/main/java/org/jclouds/compute/strategy/DestroyNodeStrategy.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/DestroyNodeStrategy.java @@ -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); } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/strategy/GetNodeMetadataStrategy.java b/compute/src/main/java/org/jclouds/compute/strategy/GetNodeMetadataStrategy.java index c65b8a5461..be56098c35 100644 --- a/compute/src/main/java/org/jclouds/compute/strategy/GetNodeMetadataStrategy.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/GetNodeMetadataStrategy.java @@ -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); } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/strategy/LoadBalancerStrategy.java b/compute/src/main/java/org/jclouds/compute/strategy/LoadBalancerStrategy.java index bb98c73894..0a62fd84be 100644 --- a/compute/src/main/java/org/jclouds/compute/strategy/LoadBalancerStrategy.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/LoadBalancerStrategy.java @@ -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 instanceIds); + String execute(Location loaction, String name, String protocol, int loadBalancerPort, + int instancePort, Set instanceIds); } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/strategy/RebootNodeStrategy.java b/compute/src/main/java/org/jclouds/compute/strategy/RebootNodeStrategy.java index ce554caf97..b928f6ce2a 100644 --- a/compute/src/main/java/org/jclouds/compute/strategy/RebootNodeStrategy.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/RebootNodeStrategy.java @@ -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); } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java index d867b88e35..3a1ed6cf96 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java @@ -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); } /** diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index b4b8d76d62..6fc92d1ed0 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -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()); diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java index 92c724fba9..e24399235d 100755 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java @@ -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 sizes = Sets.newHashSet(); holder.logger.debug(">> providing sizes"); - sizes.add(new SizeImpl("1", "1", null, null, ImmutableMap. of(), 0.5, 512, - 30, ImmutableSet. of(Architecture.X86_32, Architecture.X86_64))); - sizes.add(new SizeImpl("2", "2", null, null, ImmutableMap. of(), 1, 1024, 60, - ImmutableSet. of(Architecture.X86_32, Architecture.X86_64))); - sizes.add(new SizeImpl("3", "3", null, null, ImmutableMap. of(), 2, 2048, - 120, ImmutableSet. of(Architecture.X86_32, Architecture.X86_64))); - sizes.add(new SizeImpl("4", "4", null, null, ImmutableMap. of(), 4, 4096, - 240, ImmutableSet. of(Architecture.X86_32, Architecture.X86_64))); - sizes.add(new SizeImpl("5", "5", null, null, ImmutableMap. of(), 8, 8192, - 480, ImmutableSet. of(Architecture.X86_32, Architecture.X86_64))); + sizes.add(new SizeImpl("1", "1", "1", null, null, ImmutableMap. of(), 0.5, + 512, 30, ImmutableSet. of(Architecture.X86_32, Architecture.X86_64))); + sizes.add(new SizeImpl("2", "2", "2", null, null, ImmutableMap. of(), 1, + 1024, 60, ImmutableSet. of(Architecture.X86_32, Architecture.X86_64))); + sizes + .add(new SizeImpl("3", "3", "3", null, null, ImmutableMap. of(), 2, + 2048, 120, ImmutableSet. of(Architecture.X86_32, + Architecture.X86_64))); + sizes + .add(new SizeImpl("4", "4", "4", null, null, ImmutableMap. of(), 4, + 4096, 240, ImmutableSet. of(Architecture.X86_32, + Architecture.X86_64))); + sizes + .add(new SizeImpl("5", "5", "5", null, null, ImmutableMap. of(), 8, + 8192, 480, ImmutableSet. 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. of(), from.getDescription(), version, os, - osDescription, arch, defaultCredentials)); + images.add(new ImageImpl(from.getId() + "", from.getFriendlyName(), from.getId() + "", + location, null, ImmutableMap. of(), from.getDescription(), + version, os, osDescription, arch, defaultCredentials)); } holder.logger.debug("<< images(%d)", images.size()); return images; diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java index 4c3f170672..66b130aeac 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/functions/ServerToNodeMetadata.java @@ -103,8 +103,8 @@ public class ServerToNodeMetadata implements Function { .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 - . of(), tag, image, state, ipSet, ImmutableList. of(), - ImmutableMap. of(), creds); + return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", location, + null, ImmutableMap. of(), tag, image, state, ipSet, ImmutableList + . of(), ImmutableMap. of(), creds); } } \ No newline at end of file diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index 2458775b90..ac0f9d26c2 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -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 - . 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. 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 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 - . of(), from.getDisk() / 10, from.getRam(), from.getDisk(), - ImmutableSet. of(Architecture.X86_32, Architecture.X86_64))); + sizes.add(new SizeImpl(from.getId() + "", from.getName(), from.getId() + "", location, + null, ImmutableMap. of(), from.getDisk() / 10, from.getRam(), + from.getDisk(), ImmutableSet. 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 - . of(), from.getName(), version, os, osDescription, arch, - new Credentials("root", null))); + images.add(new ImageImpl(from.getId() + "", from.getName(), from.getId() + "", location, + null, ImmutableMap. of(), from.getName(), version, os, + osDescription, arch, new Credentials("root", null))); } holder.logger.debug("<< images(%d)", images.size()); return images; diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java index 4e6a9e5692..8e9bfd714b 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/ServerToNodeMetadata.java @@ -98,7 +98,7 @@ public class ServerToNodeMetadata implements Function { .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. of(), null); diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java index 9b3433f397..3a3f09f214 100755 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java @@ -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,12 +196,12 @@ 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. of(), tag, template - .getImage(), runningStateToNodeState.get(server.getState()), getPublicAddresses - .apply(server), ImmutableList. of(), ImmutableMap - . of(), new Credentials("root", serverResponse - .getNewInstanceRequest().getCreateOptions().getPassword())); + NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId() + .toString(), template.getLocation(), null, ImmutableMap. of(), + tag, template.getImage(), runningStateToNodeState.get(server.getState()), + getPublicAddresses.apply(server), ImmutableList. of(), ImmutableMap + . 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. of(), tag, image, state, getPublicAddresses - .apply(from), ImmutableList. of(), ImmutableMap + return new NodeMetadataImpl(from.getId() + "", from.getName(), from.getId() + "", + location, null, ImmutableMap. of(), tag, image, state, + getPublicAddresses.apply(from), ImmutableList. of(), ImmutableMap . of(), creds); } @@ -432,9 +431,9 @@ public class RimuHostingComputeServiceContextModule extends RimuHostingContextMo } }); - sizes.add(new SizeImpl(from.getId(), from.getId(), location, null, ImmutableMap - . of(), 1, from.getRam(), from.getDiskSize(), ImmutableSet - . of(Architecture.X86_32, Architecture.X86_64))); + sizes.add(new SizeImpl(from.getId(), from.getId(), from.getId(), location, null, + ImmutableMap. of(), 1, from.getRam(), from.getDiskSize(), + ImmutableSet. 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 - . of(), from.getDescription(), version, os, osDescription, arch, - new Credentials("root", null))); + images.add(new ImageImpl(from.getId(), from.getDescription(), from.getId(), null, null, + ImmutableMap. of(), from.getDescription(), version, os, + osDescription, arch, new Credentials("root", null))); } holder.logger.debug("<< images(%d)", images.size()); return images; diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java index eb7a2aaa61..77ea0a51bd 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java @@ -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", diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index 6c6bca21b9..9191f0ac63 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -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 metaMap, VApp vApp) { - return new NodeMetadataImpl(vApp.getId(), vApp.getName(), template.getLocation(), vApp - .getLocation(), ImmutableMap. of(), tag, template.getImage(), - vAppStatusToNodeState.get(vApp.getStatus()), computeClient + return new NodeMetadataImpl(vApp.getId(), vApp.getName(), vApp.getId(), template + .getLocation(), vApp.getLocation(), ImmutableMap. of(), tag, + template.getImage(), vAppStatusToNodeState.get(vApp.getStatus()), computeClient .getPublicAddresses(vApp.getId()), computeClient .getPrivateAddresses(vApp.getId()), ImmutableMap. 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. of()); + resource.getId(), location, null, ImmutableMap. 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 - . of(), template.getDescription(), - "", myOs, template.getName(), arch, new Credentials("root", - null))); + resource.getId(), location, template.getLocation(), + ImmutableMap. 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 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. of(), cpus, ram, 10, ImmutableSet - . 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. of(), + cpus, ram, 10, ImmutableSet. of(Architecture.X86_32, + Architecture.X86_64))); + } return sizes; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java index 0a1f6db8db..bba96b8ce9 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/VCloudGetNodeMetadata.java @@ -57,7 +57,7 @@ import com.google.common.collect.Iterables; */ @Singleton public class VCloudGetNodeMetadata { - + @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; @@ -86,15 +86,15 @@ public class VCloudGetNodeMetadata { this.computeClient = checkNotNull(computeClient, "computeClient"); 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. 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. of(), tag, image, + vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(id), + computeClient.getPrivateAddresses(id), getExtra.apply(vApp), null); } } \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java index 03887ea65d..fcc9dab8ba 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeServiceLiveTest.java @@ -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; diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java index bdcf0b8ec1..207da20cfa 100755 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/config/TerremarkVCloudComputeServiceContextModule.java @@ -101,9 +101,9 @@ public class TerremarkVCloudComputeServiceContextModule extends VCloudComputeSer private static class ComputeOptionsToSize implements Function { @Override public Size apply(ComputeOptions from) { - return new SizeImpl(from.toString(), from.toString(), null, null, ImmutableMap - . of(), from.getProcessorCount(), from.getMemory(), 10, - ImmutableSet. of(Architecture.X86_32, Architecture.X86_64)); + return new SizeImpl(from.toString(), from.toString(), from.toString(), null, null, + ImmutableMap. of(), from.getProcessorCount(), from.getMemory(), + 10, ImmutableSet. 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 - . of(), template.getDescription(), - "", myOs, template.getName(), arch, credentialsProvider - .execute(template))); + resource.getId(), location, template.getLocation(), + ImmutableMap. of(), template + .getDescription(), "", myOs, template.getName(), + arch, credentialsProvider.execute(template))); return null; } }), executor));