From 7f02bd8929b2d297cc9fa673dc5a5bf4113066ce Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 16 Oct 2010 23:45:14 -0700 Subject: [PATCH] Issue 381: removed unnecessary VCloudLocation class --- .../vcloud/compute/domain/VCloudLocation.java | 49 ------------------- .../functions/FindLocationForResource.java | 4 +- .../OrgAndVDCToLocationSupplier.java | 7 ++- .../vcloud/functions/OrgsForLocations.java | 3 +- ...remarkVCloudExpressVAppToNodeMetadata.java | 13 +++-- ...agIntoNameRunNodesAndAddToSetStrategy.java | 18 +++---- 6 files changed, 21 insertions(+), 73 deletions(-) delete mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudLocation.java diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudLocation.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudLocation.java deleted file mode 100644 index 1f5f0e31f0..0000000000 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/domain/VCloudLocation.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * - * Copyright (C) 2010 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.vcloud.compute.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationScope; -import org.jclouds.domain.internal.LocationImpl; -import org.jclouds.vcloud.domain.ReferenceType; - -/** - * - * @author Adrian Cole - */ -public class VCloudLocation extends LocationImpl { - - private static final long serialVersionUID = -5052812549904524841L; - - private final ReferenceType resource; - - public VCloudLocation(ReferenceType resource, Location parent) { - super(checkNotNull(resource, "resource").getType().endsWith("org+xml") ? LocationScope.REGION - : LocationScope.ZONE, resource.getHref().toASCIIString(), resource.getName(), parent); - this.resource = resource; - } - - public ReferenceType getResource() { - return resource; - } - -} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/FindLocationForResource.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/FindLocationForResource.java index 8b668688b7..8df6a3d21e 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/FindLocationForResource.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/FindLocationForResource.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.compute.functions; +import java.net.URI; import java.util.NoSuchElementException; import java.util.Set; @@ -28,7 +29,6 @@ import javax.inject.Singleton; import org.jclouds.domain.Location; import org.jclouds.logging.Logger; -import org.jclouds.vcloud.compute.domain.VCloudLocation; import org.jclouds.vcloud.domain.ReferenceType; import com.google.common.base.Supplier; @@ -60,7 +60,7 @@ public class FindLocationForResource { do { // The "name" isn't always present, ex inside a vApp we have a rel // link that only includes href and type. - if (VCloudLocation.class.cast(input).getResource().getHref().equals(resource.getHref())) + if (URI.create(input.getId()).equals(resource.getHref())) return input; input = input.getParent(); } while (input.getParent() != null); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/OrgAndVDCToLocationSupplier.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/OrgAndVDCToLocationSupplier.java index aa841d7da0..f25a87123b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/OrgAndVDCToLocationSupplier.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/OrgAndVDCToLocationSupplier.java @@ -28,9 +28,8 @@ import javax.inject.Singleton; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.internal.LocationImpl; -import org.jclouds.vcloud.compute.domain.VCloudLocation; -import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.ReferenceType; import com.google.common.base.Supplier; import com.google.common.collect.Sets; @@ -59,9 +58,9 @@ public class OrgAndVDCToLocationSupplier implements Supplier locations = Sets.newLinkedHashSet(); for (ReferenceType org : orgNameToResource.get().values()) { - Location orgL = new VCloudLocation(org, provider); + Location orgL = new LocationImpl(LocationScope.REGION, org.getHref().toASCIIString(), org.getName(), provider); for (ReferenceType vdc : orgNameToVDCResource.get().get(org.getName()).getVDCs().values()) { - locations.add(new VCloudLocation(vdc, orgL)); + locations.add(new LocationImpl(LocationScope.ZONE, vdc.getHref().toASCIIString(), vdc.getName(), orgL)); } } return locations; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgsForLocations.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgsForLocations.java index 164f0de1cf..08d38ea7cc 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgsForLocations.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/OrgsForLocations.java @@ -38,7 +38,6 @@ import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.logging.Logger; import org.jclouds.vcloud.CommonVCloudAsyncClient; -import org.jclouds.vcloud.compute.domain.VCloudLocation; import org.jclouds.vcloud.domain.Org; import com.google.common.base.Function; @@ -80,7 +79,7 @@ public class OrgsForLocations implements Function, @Override public URI apply(Location from) { - return VCloudLocation.class.cast(from.getParent()).getResource().getHref(); + return URI.create(from.getParent().getId()); } })), new Function>() { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TerremarkVCloudExpressVAppToNodeMetadata.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TerremarkVCloudExpressVAppToNodeMetadata.java index 2ce137d453..c7aea007c5 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TerremarkVCloudExpressVAppToNodeMetadata.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TerremarkVCloudExpressVAppToNodeMetadata.java @@ -35,7 +35,6 @@ import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.domain.NodeState; import org.jclouds.domain.Credentials; import org.jclouds.vcloud.compute.VCloudExpressComputeClient; -import org.jclouds.vcloud.compute.domain.VCloudLocation; import org.jclouds.vcloud.compute.functions.FindLocationForResource; import org.jclouds.vcloud.compute.functions.HardwareForVCloudExpressVApp; import org.jclouds.vcloud.compute.functions.VCloudExpressVAppToNodeMetadata; @@ -55,12 +54,12 @@ public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppT @Inject public TerremarkVCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient, - Map credentialStore, Map vAppStatusToNodeState, - HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp, - FindLocationForResource findLocationForResourceInVDC, Supplier> images, - ConcurrentMap credentialsMap) { + Map credentialStore, Map vAppStatusToNodeState, + HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp, + FindLocationForResource findLocationForResourceInVDC, Supplier> images, + ConcurrentMap credentialsMap) { super(computeClient, credentialStore, vAppStatusToNodeState, hardwareForVCloudExpressVApp, - findLocationForResourceInVDC, images); + findLocationForResourceInVDC, images); this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap"); ; } @@ -86,7 +85,7 @@ public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppT } OrgAndName getOrgAndNameFromNode(NodeMetadata node) { - URI orgId = VCloudLocation.class.cast(node.getLocation().getParent()).getResource().getHref(); + URI orgId = URI.create(node.getLocation().getParent().getId()); OrgAndName orgAndName = new OrgAndName(orgId, node.getTag()); return orgAndName; } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.java index 23b5996492..239154aabb 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/strategy/TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.terremark.compute.strategy; +import java.net.URI; import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -36,7 +37,6 @@ import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.compute.util.ComputeUtils; import org.jclouds.domain.LocationScope; -import org.jclouds.vcloud.compute.domain.VCloudLocation; import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions; /** @@ -51,21 +51,21 @@ public class TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy extends Encod @Inject protected TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy(AddNodeWithTagStrategy addNodeWithTagStrategy, - ListNodesStrategy listNodesStrategy, @Named("NAMING_CONVENTION") String nodeNamingConvention, - ComputeUtils utils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, - CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) { + ListNodesStrategy listNodesStrategy, @Named("NAMING_CONVENTION") String nodeNamingConvention, + ComputeUtils utils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, + CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) { super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, utils, executor); this.createNewKeyPairUnlessUserSpecifiedOtherwise = createNewKeyPairUnlessUserSpecifiedOtherwise; } @Override public Map> execute(String tag, int count, Template template, Set nodes, - Map badNodes) { + Map badNodes) { assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: " - + template.getLocation(); - createNewKeyPairUnlessUserSpecifiedOtherwise.execute(VCloudLocation.class - .cast(template.getLocation().getParent()).getResource().getHref(), tag, template.getImage() - .getDefaultCredentials().identity, template.getOptions().as(TerremarkVCloudTemplateOptions.class)); + + template.getLocation(); + createNewKeyPairUnlessUserSpecifiedOtherwise.execute(URI.create(template.getLocation().getParent().getId()), tag, + template.getImage().getDefaultCredentials().identity, template.getOptions().as( + TerremarkVCloudTemplateOptions.class)); return super.execute(tag, count, template, nodes, badNodes); } } \ No newline at end of file