Issue 327: introduced VCloudLocation which hides the Resource corresponding to the org or vdc

This commit is contained in:
Adrian Cole 2010-08-09 09:54:41 -07:00
parent d8a8c38e4f
commit 3289871c14
5 changed files with 59 additions and 8 deletions

View File

@ -28,6 +28,7 @@ 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.NamedResource;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VDC;
@ -59,10 +60,9 @@ public class OrgAndVDCToLocationProvider implements Provider<Set<? extends Locat
Set<Location> locations = Sets.newLinkedHashSet();
for (NamedResource org : orgNameToResource.get().values()) {
Location orgL = new LocationImpl(LocationScope.REGION, org.getName(), org.getLocation().toASCIIString(),
provider);
Location orgL = new VCloudLocation(org, provider);
for (NamedResource vdc : orgNameToVDCResource.get().get(org.getName()).values()) {
locations.add(new LocationImpl(LocationScope.ZONE, vdc.getName(), vdc.getLocation().toASCIIString(), orgL));
locations.add(new VCloudLocation(vdc, orgL));
}
}
return locations;

View File

@ -0,0 +1,51 @@
/**
*
* 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.NamedResource;
/**
*
* @author Adrian Cole
*/
public class VCloudLocation extends LocationImpl {
private final NamedResource resource;
public NamedResource getResource() {
return resource;
}
public VCloudLocation(NamedResource resource, Location parent) {
super(checkNotNull(resource, "resource").getType().endsWith("org+xml") ? LocationScope.REGION
: LocationScope.ZONE, resource.getName(), resource.getName(), parent);
this.resource = resource;
}
/**
*
*/
private static final long serialVersionUID = -5052812549904524841L;
}

View File

@ -28,6 +28,7 @@ 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.NamedResource;
/**
@ -59,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 (input.getDescription().equals(resource.getLocation().toASCIIString()))
if (VCloudLocation.class.cast(input).getResource().getLocation().equals(resource.getLocation()))
return input;
input = input.getParent();
} while (input.getParent() != null);

View File

@ -31,14 +31,13 @@ import org.jclouds.vcloud.compute.functions.VCloudGetNodeMetadata;
* @author Adrian Cole
*/
@Singleton
public class VCloudGetNodeMetadataStrategy implements
GetNodeMetadataStrategy {
public class VCloudGetNodeMetadataStrategy implements GetNodeMetadataStrategy {
protected final VCloudGetNodeMetadata getNodeMetadata;
@Inject
protected VCloudGetNodeMetadataStrategy(VCloudGetNodeMetadata getNodeMetadata) {
this.getNodeMetadata=getNodeMetadata;
this.getNodeMetadata = getNodeMetadata;
}
@Override

View File

@ -58,7 +58,7 @@ public class TerremarkVCloudComputeServiceLiveTest extends VCloudComputeServiceL
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getArchitecture(), Architecture.X86_64);
assertEquals(defaultTemplate.getImage().getOsFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "32");
assertEquals(defaultTemplate.getLocation().getId(), "Miami Environment 1");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d);
}