Issue 628: fixed error on vCloud find network

This commit is contained in:
Adrian Cole 2011-07-23 10:17:09 +10:00
parent 6928082674
commit 2ac2524baa
4 changed files with 140 additions and 5 deletions

View File

@ -355,7 +355,7 @@ public class VCloudAsyncClientTest extends BaseVCloudAsyncClientTest<VCloudAsync
String.class);
HttpRequest request = processor.createRequest(method, "org", "vdc", "network");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2 HTTP/1.1");
assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/network/1990 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
assertPayloadEquals(request, null, null, false);

View File

@ -52,7 +52,7 @@ import org.jclouds.vcloud.functions.OrgNameAndVDCNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameToTasksListEndpoint;
import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint;
import org.jclouds.vcloud.functions.OrgNameVDCNameNetworkNameToEndpoint;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.CatalogItemHandler;
import org.jclouds.vcloud.xml.OrgHandler;
@ -141,9 +141,9 @@ public interface CommonVCloudAsyncClient {
@XMLResponseParser(OrgNetworkHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends OrgNetwork> findNetworkInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String networkName);
@Nullable @EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameNetworkNameToEndpoint.class) String networkName);
/**
* @see CommonVCloudClient#getNetwork

View File

@ -0,0 +1,56 @@
/**
*
* Copyright (C) 2011 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.functions;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Supplier;
/**
*
* @author Adrian Cole
*/
@Singleton
public class OrgNameVDCNameNetworkNameToEndpoint extends OrgNameVDCNameResourceNameToEndpoint {
@Inject
public OrgNameVDCNameNetworkNameToEndpoint(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @VDC ReferenceType defaultVDC) {
super(orgVDCMap, defaultOrg, defaultVDC);
}
protected URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource,
org.jclouds.vcloud.domain.VDC vDCObject) {
ReferenceType resourceEntity = vDCObject.getAvailableNetworks().get(resource);
if (resourceEntity == null)
throw new NoSuchElementException("network " + resource + " in vdc " + vDC + ", org " + org + " not found in "
+ vDCObject.getAvailableNetworks().keySet());
return resourceEntity.getHref();
}
}

View File

@ -0,0 +1,79 @@
/**
*
* Copyright (C) 2011 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.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.inject.Inject;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Org;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
public abstract class OrgNameVDCNameResourceNameToEndpoint implements Function<Object, URI>{
protected final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
protected final ReferenceType defaultOrg;
protected final ReferenceType defaultVDC;
@Inject
public OrgNameVDCNameResourceNameToEndpoint(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
@Org ReferenceType defaultOrg, @org.jclouds.vcloud.endpoints.VDC ReferenceType defaultVDC) {
this.orgVDCMap = orgVDCMap;
this.defaultOrg = defaultOrg;
this.defaultVDC = defaultVDC;
}
@SuppressWarnings("unchecked")
public URI apply(Object from) {
Iterable<Object> orgVDC = (Iterable<Object>) checkNotNull(from, "args");
Object org = Iterables.get(orgVDC, 0);
Object vDC = Iterables.get(orgVDC, 1);
Object resource = Iterables.get(orgVDC, 2);
if (org == null)
org = defaultOrg.getName();
if (vDC == null)
vDC = defaultVDC.getName();
Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> orgToVDCs = orgVDCMap.get();
checkState(orgToVDCs != null, "could not get map of org name to vdcs!");
Map<String, ? extends org.jclouds.vcloud.domain.VDC> vDCs = orgToVDCs.get(org);
if (vDCs == null)
throw new NoSuchElementException("org " + org + " not found in " + orgToVDCs.keySet());
org.jclouds.vcloud.domain.VDC vDCObject = vDCs.get(vDC);
if (vDCObject == null)
throw new NoSuchElementException("vdc " + vDC + " in org " + org + " not found in " + vDCs.keySet());
return getEndpointOfResourceInVDC(org, vDC, resource, vDCObject);
}
protected abstract URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource, VDC vDCObject);
}