Merge pull request #1459 from jclouds/trmk-taskslist

corrected map binder for terremark so that it is compatible w/ jclouds 1.6
This commit is contained in:
Adrian Cole 2013-03-25 10:50:28 -07:00
commit db24e1525a
3 changed files with 21 additions and 14 deletions

View File

@ -65,6 +65,7 @@ import org.jclouds.trmk.vcloud_0_8.binders.BindInstantiateVAppTemplateParamsToXm
import org.jclouds.trmk.vcloud_0_8.binders.BindNodeConfigurationToXmlPayload; import org.jclouds.trmk.vcloud_0_8.binders.BindNodeConfigurationToXmlPayload;
import org.jclouds.trmk.vcloud_0_8.binders.BindVAppConfigurationToXmlPayload; import org.jclouds.trmk.vcloud_0_8.binders.BindVAppConfigurationToXmlPayload;
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameAndCatalogNameToEndpoint; import org.jclouds.trmk.vcloud_0_8.binders.OrgNameAndCatalogNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameAndTasksListNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameAndVDCNameToEndpoint; import org.jclouds.trmk.vcloud_0_8.binders.OrgNameAndVDCNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameCatalogNameItemNameToEndpoint; import org.jclouds.trmk.vcloud_0_8.binders.OrgNameCatalogNameItemNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.binders.OrgNameCatalogNameVAppTemplateNameToEndpoint; import org.jclouds.trmk.vcloud_0_8.binders.OrgNameCatalogNameVAppTemplateNameToEndpoint;
@ -86,7 +87,6 @@ import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
import org.jclouds.trmk.vcloud_0_8.domain.VDC; import org.jclouds.trmk.vcloud_0_8.domain.VDC;
import org.jclouds.trmk.vcloud_0_8.endpoints.Org; import org.jclouds.trmk.vcloud_0_8.endpoints.Org;
import org.jclouds.trmk.vcloud_0_8.filters.SetVCloudTokenCookie; import org.jclouds.trmk.vcloud_0_8.filters.SetVCloudTokenCookie;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameAndTasksListNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.OrgNameToEndpoint; import org.jclouds.trmk.vcloud_0_8.functions.OrgNameToEndpoint;
import org.jclouds.trmk.vcloud_0_8.functions.ParseTaskFromLocationHeader; import org.jclouds.trmk.vcloud_0_8.functions.ParseTaskFromLocationHeader;
import org.jclouds.trmk.vcloud_0_8.functions.VDCURIToInternetServicesEndpoint; import org.jclouds.trmk.vcloud_0_8.functions.VDCURIToInternetServicesEndpoint;
@ -162,9 +162,9 @@ public interface TerremarkVCloudAsyncClient {
@XMLResponseParser(TasksListHandler.class) @XMLResponseParser(TasksListHandler.class)
@Fallback(NullOnNotFoundOr404.class) @Fallback(NullOnNotFoundOr404.class)
@Consumes(TASKSLIST_XML) @Consumes(TASKSLIST_XML)
ListenableFuture<? extends TasksList> findTasksListInOrgNamed( @MapBinder(OrgNameAndTasksListNameToEndpoint.class)
@Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String orgName, ListenableFuture<? extends TasksList> findTasksListInOrgNamed(@Nullable @PayloadParam("orgName") String orgName,
@Nullable @EndpointParam(parser = OrgNameAndTasksListNameToEndpoint.class) String tasksListName); @Nullable @PayloadParam("tasksListName") String tasksListName);
/** /**
* @see TerremarkVCloudClient#getTask * @see TerremarkVCloudClient#getTask

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.trmk.vcloud_0_8.functions; package org.jclouds.trmk.vcloud_0_8.binders;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -27,11 +27,12 @@ import java.util.NoSuchElementException;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.trmk.vcloud_0_8.domain.Org; import org.jclouds.trmk.vcloud_0_8.domain.Org;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType; import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.endpoints.TasksList; import org.jclouds.trmk.vcloud_0_8.endpoints.TasksList;
import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -40,7 +41,7 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class OrgNameAndTasksListNameToEndpoint implements Function<Object, URI> { public class OrgNameAndTasksListNameToEndpoint implements MapBinder {
private final Supplier<Map<String, ? extends Org>> orgMap; private final Supplier<Map<String, ? extends Org>> orgMap;
private final Supplier<ReferenceType> defaultOrg; private final Supplier<ReferenceType> defaultOrg;
private final Supplier<ReferenceType> defaultTasksList; private final Supplier<ReferenceType> defaultTasksList;
@ -54,21 +55,26 @@ public class OrgNameAndTasksListNameToEndpoint implements Function<Object, URI>
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public URI apply(Object from) { @Override
Iterable<Object> orgTasksList = (Iterable<Object>) checkNotNull(from, "args"); public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Object org = Iterables.get(orgTasksList, 0); Object org = postParams.get("orgName");
Object tasksList = Iterables.get(orgTasksList, 1); Object tasksList = postParams.get("tasksListName");
if (org == null && tasksList == null) if (org == null && tasksList == null)
return defaultTasksList.get().getHref(); return (R) request.toBuilder().endpoint(defaultTasksList.get().getHref()).build();
else if (org == null) else if (org == null)
org = defaultOrg.get().getName(); org = defaultOrg.get().getName();
try { try {
Map<String, ReferenceType> tasksLists = checkNotNull(orgMap.get().get(org)).getTasksLists(); Map<String, ReferenceType> tasksLists = checkNotNull(orgMap.get().get(org)).getTasksLists();
return tasksList == null ? Iterables.getLast(tasksLists.values()).getHref() : tasksLists.get(tasksList).getHref(); URI endpoint = tasksList == null ? Iterables.getLast(tasksLists.values()).getHref() : tasksLists.get(tasksList).getHref();
return (R) request.toBuilder().endpoint(endpoint).build();
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + tasksList + " not found in " + orgMap.get()); throw new NoSuchElementException(org + "/" + tasksList + " not found in " + orgMap.get());
} }
} }
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
throw new IllegalStateException(getClass() + " needs parameters");
}
} }

View File

@ -28,6 +28,7 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType; import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType;
import org.jclouds.trmk.vcloud_0_8.domain.Status; import org.jclouds.trmk.vcloud_0_8.domain.Status;
import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate; import org.jclouds.trmk.vcloud_0_8.domain.VAppTemplate;
@ -60,7 +61,7 @@ public class ImageForVCloudExpressVAppTemplate implements Function<VAppTemplate,
} }
@Override @Override
public Image apply(VAppTemplate from) { public Image apply(@Nullable VAppTemplate from) {
if (from == null) if (from == null)
return null; return null;
ImageBuilder builder = new ImageBuilder(); ImageBuilder builder = new ImageBuilder();