Issue 381: removed unnecessary VCloudLocation class

This commit is contained in:
Adrian Cole 2010-10-16 23:45:14 -07:00
parent a9de959146
commit 7f02bd8929
6 changed files with 21 additions and 73 deletions

View File

@ -1,49 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.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;
}
}

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.compute.functions; package org.jclouds.vcloud.compute.functions;
import java.net.URI;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
@ -28,7 +29,6 @@ import javax.inject.Singleton;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -60,7 +60,7 @@ public class FindLocationForResource {
do { do {
// The "name" isn't always present, ex inside a vApp we have a rel // The "name" isn't always present, ex inside a vApp we have a rel
// link that only includes href and type. // 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; return input;
input = input.getParent(); input = input.getParent();
} while (input.getParent() != null); } while (input.getParent() != null);

View File

@ -28,9 +28,8 @@ import javax.inject.Singleton;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; 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.Org;
import org.jclouds.vcloud.domain.ReferenceType;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -59,9 +58,9 @@ public class OrgAndVDCToLocationSupplier implements Supplier<Set<? extends Locat
Set<Location> locations = Sets.newLinkedHashSet(); Set<Location> locations = Sets.newLinkedHashSet();
for (ReferenceType org : orgNameToResource.get().values()) { 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()) { 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; return locations;

View File

@ -38,7 +38,6 @@ import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.CommonVCloudAsyncClient; import org.jclouds.vcloud.CommonVCloudAsyncClient;
import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -80,7 +79,7 @@ public class OrgsForLocations implements Function<Iterable<? extends Location>,
@Override @Override
public URI apply(Location from) { public URI apply(Location from) {
return VCloudLocation.class.cast(from.getParent()).getResource().getHref(); return URI.create(from.getParent().getId());
} }
})), new Function<URI, Future<Org>>() { })), new Function<URI, Future<Org>>() {

View File

@ -35,7 +35,6 @@ import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient; 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.FindLocationForResource;
import org.jclouds.vcloud.compute.functions.HardwareForVCloudExpressVApp; import org.jclouds.vcloud.compute.functions.HardwareForVCloudExpressVApp;
import org.jclouds.vcloud.compute.functions.VCloudExpressVAppToNodeMetadata; import org.jclouds.vcloud.compute.functions.VCloudExpressVAppToNodeMetadata;
@ -55,12 +54,12 @@ public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppT
@Inject @Inject
public TerremarkVCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient, public TerremarkVCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient,
Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp, HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images, FindLocationForResource findLocationForResourceInVDC, Supplier<Set<? extends Image>> images,
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) { ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
super(computeClient, credentialStore, vAppStatusToNodeState, hardwareForVCloudExpressVApp, super(computeClient, credentialStore, vAppStatusToNodeState, hardwareForVCloudExpressVApp,
findLocationForResourceInVDC, images); findLocationForResourceInVDC, images);
this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap"); this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
; ;
} }
@ -86,7 +85,7 @@ public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppT
} }
OrgAndName getOrgAndNameFromNode(NodeMetadata node) { 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()); OrgAndName orgAndName = new OrgAndName(orgId, node.getTag());
return orgAndName; return orgAndName;
} }

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.terremark.compute.strategy; package org.jclouds.vcloud.terremark.compute.strategy;
import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService; 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.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.compute.util.ComputeUtils; import org.jclouds.compute.util.ComputeUtils;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.vcloud.compute.domain.VCloudLocation;
import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions; import org.jclouds.vcloud.terremark.compute.options.TerremarkVCloudTemplateOptions;
/** /**
@ -51,21 +51,21 @@ public class TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy extends Encod
@Inject @Inject
protected TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy(AddNodeWithTagStrategy addNodeWithTagStrategy, protected TerremarkEncodeTagIntoNameRunNodesAndAddToSetStrategy(AddNodeWithTagStrategy addNodeWithTagStrategy,
ListNodesStrategy listNodesStrategy, @Named("NAMING_CONVENTION") String nodeNamingConvention, ListNodesStrategy listNodesStrategy, @Named("NAMING_CONVENTION") String nodeNamingConvention,
ComputeUtils utils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, ComputeUtils utils, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) { CreateNewKeyPairUnlessUserSpecifiedOtherwise createNewKeyPairUnlessUserSpecifiedOtherwise) {
super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, utils, executor); super(addNodeWithTagStrategy, listNodesStrategy, nodeNamingConvention, utils, executor);
this.createNewKeyPairUnlessUserSpecifiedOtherwise = createNewKeyPairUnlessUserSpecifiedOtherwise; this.createNewKeyPairUnlessUserSpecifiedOtherwise = createNewKeyPairUnlessUserSpecifiedOtherwise;
} }
@Override @Override
public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> nodes, public Map<?, Future<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> nodes,
Map<NodeMetadata, Exception> badNodes) { Map<NodeMetadata, Exception> badNodes) {
assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: " assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: "
+ template.getLocation(); + template.getLocation();
createNewKeyPairUnlessUserSpecifiedOtherwise.execute(VCloudLocation.class createNewKeyPairUnlessUserSpecifiedOtherwise.execute(URI.create(template.getLocation().getParent().getId()), tag,
.cast(template.getLocation().getParent()).getResource().getHref(), tag, template.getImage() template.getImage().getDefaultCredentials().identity, template.getOptions().as(
.getDefaultCredentials().identity, template.getOptions().as(TerremarkVCloudTemplateOptions.class)); TerremarkVCloudTemplateOptions.class));
return super.execute(tag, count, template, nodes, badNodes); return super.execute(tag, count, template, nodes, badNodes);
} }
} }