mirror of https://github.com/apache/jclouds.git
Issue 112: added tasks list
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2244 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
79280f3484
commit
7f73d1761a
|
@ -24,6 +24,7 @@
|
||||||
package org.jclouds.vcloud;
|
package org.jclouds.vcloud;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
|
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
|
||||||
|
import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
|
||||||
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
||||||
|
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
@ -36,8 +37,10 @@ import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
import org.jclouds.vcloud.domain.Catalog;
|
import org.jclouds.vcloud.domain.Catalog;
|
||||||
import org.jclouds.vcloud.domain.VDC;
|
import org.jclouds.vcloud.domain.VDC;
|
||||||
|
import org.jclouds.vcloud.endpoints.TasksList;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||||
import org.jclouds.vcloud.xml.CatalogHandler;
|
import org.jclouds.vcloud.xml.CatalogHandler;
|
||||||
|
import org.jclouds.vcloud.xml.TasksListHandler;
|
||||||
import org.jclouds.vcloud.xml.VDCHandler;
|
import org.jclouds.vcloud.xml.VDCHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,21 +57,24 @@ public interface VCloudClient {
|
||||||
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
|
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
|
||||||
@Consumes(CATALOG_XML)
|
@Consumes(CATALOG_XML)
|
||||||
@XMLResponseParser(CatalogHandler.class)
|
@XMLResponseParser(CatalogHandler.class)
|
||||||
Future<Catalog> getCatalog();
|
Future<? extends Catalog> getCatalog();
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||||
@XMLResponseParser(VDCHandler.class)
|
@XMLResponseParser(VDCHandler.class)
|
||||||
@Consumes(VDC_XML)
|
@Consumes(VDC_XML)
|
||||||
VDC getDefaultVDC();
|
Future<? extends VDC> getDefaultVDC();
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Endpoint(TasksList.class)
|
||||||
|
@Consumes(TASKSLIST_XML)
|
||||||
|
@XMLResponseParser(TasksListHandler.class)
|
||||||
|
Future<? extends org.jclouds.vcloud.domain.TasksList> getDefaultTasksList();
|
||||||
|
|
||||||
//
|
//
|
||||||
// @GET
|
// @GET
|
||||||
// @Endpoint(vDC.class)
|
// @Endpoint(vDC.class)
|
||||||
// public Set<String> getvDCs();
|
// public Set<String> getvDCs();
|
||||||
//
|
//
|
||||||
// @GET
|
|
||||||
// @Endpoint(TasksList.class)
|
|
||||||
// public Set<String> getTasksLists();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,4 +82,24 @@ public class VCloudMediaType {
|
||||||
public final static MediaType CATALOGITEM_XML_TYPE = new MediaType("application",
|
public final static MediaType CATALOGITEM_XML_TYPE = new MediaType("application",
|
||||||
"vnd.vmware.vcloud.catalogItem+xml");
|
"vnd.vmware.vcloud.catalogItem+xml");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "application/vnd.vmware.vcloud.task+xml"
|
||||||
|
*/
|
||||||
|
public final static String TASK_XML = "application/vnd.vmware.vcloud.task+xml";
|
||||||
|
/**
|
||||||
|
* "application/vnd.vmware.vcloud.task+xml"
|
||||||
|
*/
|
||||||
|
public final static MediaType TASK_XML_TYPE = new MediaType("application",
|
||||||
|
"vnd.vmware.vcloud.task+xml");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "application/vnd.vmware.vcloud.vApp+xml"
|
||||||
|
*/
|
||||||
|
public final static String VAPP_XML = "application/vnd.vmware.vcloud.vApp+xml";
|
||||||
|
/**
|
||||||
|
* "application/vnd.vmware.vcloud.vApp+xml"
|
||||||
|
*/
|
||||||
|
public final static MediaType VAPP_XML_TYPE = new MediaType("application",
|
||||||
|
"vnd.vmware.vcloud.vApp+xml");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ import org.jclouds.rest.RestClientFactory;
|
||||||
import org.jclouds.vcloud.VCloudClient;
|
import org.jclouds.vcloud.VCloudClient;
|
||||||
import org.jclouds.vcloud.VCloudDiscovery;
|
import org.jclouds.vcloud.VCloudDiscovery;
|
||||||
import org.jclouds.vcloud.endpoints.Catalog;
|
import org.jclouds.vcloud.endpoints.Catalog;
|
||||||
|
import org.jclouds.vcloud.endpoints.TasksList;
|
||||||
import org.jclouds.vcloud.endpoints.VDC;
|
import org.jclouds.vcloud.endpoints.VDC;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
|
@ -70,4 +71,11 @@ public class VCloudRestClientModule extends AbstractModule {
|
||||||
protected URI provideDefaultVDC(VCloudDiscovery discovery) {
|
protected URI provideDefaultVDC(VCloudDiscovery discovery) {
|
||||||
return discovery.getOrganization().getVDCs().values().iterator().next().getLocation();
|
return discovery.getOrganization().getVDCs().values().iterator().next().getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@TasksList
|
||||||
|
@Singleton
|
||||||
|
protected URI provideDefaultTasksList(VCloudDiscovery discovery) {
|
||||||
|
return discovery.getOrganization().getTasksLists().values().iterator().next().getLocation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you 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.domain;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.rest.domain.Link;
|
||||||
|
import org.jclouds.vcloud.domain.internal.TaskImpl;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import com.google.inject.ImplementedBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@ImplementedBy(TaskImpl.class)
|
||||||
|
public interface Task extends Comparable<Task> {
|
||||||
|
String getType();
|
||||||
|
|
||||||
|
URI getLocation();
|
||||||
|
|
||||||
|
TaskStatus getStatus();
|
||||||
|
|
||||||
|
DateTime getStartTime();
|
||||||
|
|
||||||
|
DateTime getEndTime();
|
||||||
|
|
||||||
|
Link getOwner();
|
||||||
|
|
||||||
|
Link getResult();
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you 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.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public enum TaskStatus {
|
||||||
|
SUCCESS, FAILED, RUNNING, QUEUED, ERROR, CANCELLED;
|
||||||
|
public String value() {
|
||||||
|
return name().toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TaskStatus fromValue(String status) {
|
||||||
|
return valueOf(checkNotNull(status, "status").toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you 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.domain;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
import org.jclouds.vcloud.domain.internal.TasksListImpl;
|
||||||
|
|
||||||
|
import com.google.inject.ImplementedBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@org.jclouds.vcloud.endpoints.TasksList
|
||||||
|
@ImplementedBy(TasksListImpl.class)
|
||||||
|
public interface TasksList {
|
||||||
|
URI getLocation();
|
||||||
|
|
||||||
|
SortedSet<Task> getTasks();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,154 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you 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.domain.internal;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.rest.domain.Link;
|
||||||
|
import org.jclouds.vcloud.domain.Task;
|
||||||
|
import org.jclouds.vcloud.domain.TaskStatus;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locations of resources in vCloud
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class TaskImpl implements Task {
|
||||||
|
private final String type;
|
||||||
|
private final URI location;
|
||||||
|
private final TaskStatus status;
|
||||||
|
private final DateTime startTime;
|
||||||
|
private final DateTime endTime;
|
||||||
|
private final Link owner;
|
||||||
|
private final Link result;
|
||||||
|
|
||||||
|
public TaskImpl(String type, URI location, TaskStatus status, DateTime startTime,
|
||||||
|
DateTime endTime, Link owner, Link result) {
|
||||||
|
this.type = checkNotNull(type, "type");
|
||||||
|
this.location = checkNotNull(location, "location");
|
||||||
|
this.status = checkNotNull(status, "status");
|
||||||
|
this.startTime = checkNotNull(startTime, "startTime");
|
||||||
|
this.endTime = checkNotNull(endTime, "endTime");
|
||||||
|
this.owner = checkNotNull(owner, "owner");
|
||||||
|
this.result = checkNotNull(result, "result");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTime getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Link getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Link getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTime getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(Task o) {
|
||||||
|
return (this == o) ? 0 : getStartTime().compareTo(o.getStartTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
|
||||||
|
result = prime * result + ((location == null) ? 0 : location.hashCode());
|
||||||
|
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
|
||||||
|
result = prime * result + ((this.result == null) ? 0 : this.result.hashCode());
|
||||||
|
result = prime * result + ((startTime == null) ? 0 : startTime.hashCode());
|
||||||
|
result = prime * result + ((status == null) ? 0 : status.hashCode());
|
||||||
|
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
TaskImpl other = (TaskImpl) obj;
|
||||||
|
if (endTime == null) {
|
||||||
|
if (other.endTime != null)
|
||||||
|
return false;
|
||||||
|
} else if (!endTime.equals(other.endTime))
|
||||||
|
return false;
|
||||||
|
if (location == null) {
|
||||||
|
if (other.location != null)
|
||||||
|
return false;
|
||||||
|
} else if (!location.equals(other.location))
|
||||||
|
return false;
|
||||||
|
if (owner == null) {
|
||||||
|
if (other.owner != null)
|
||||||
|
return false;
|
||||||
|
} else if (!owner.equals(other.owner))
|
||||||
|
return false;
|
||||||
|
if (result == null) {
|
||||||
|
if (other.result != null)
|
||||||
|
return false;
|
||||||
|
} else if (!result.equals(other.result))
|
||||||
|
return false;
|
||||||
|
if (startTime == null) {
|
||||||
|
if (other.startTime != null)
|
||||||
|
return false;
|
||||||
|
} else if (!startTime.equals(other.startTime))
|
||||||
|
return false;
|
||||||
|
if (status == null) {
|
||||||
|
if (other.status != null)
|
||||||
|
return false;
|
||||||
|
} else if (!status.equals(other.status))
|
||||||
|
return false;
|
||||||
|
if (type == null) {
|
||||||
|
if (other.type != null)
|
||||||
|
return false;
|
||||||
|
} else if (!type.equals(other.type))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you 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.domain.internal;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
import org.jclouds.vcloud.domain.Task;
|
||||||
|
import org.jclouds.vcloud.domain.TasksList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locations of resources in vCloud
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class TasksListImpl implements TasksList {
|
||||||
|
|
||||||
|
private final SortedSet<Task> tasks;
|
||||||
|
private final URI location;
|
||||||
|
/** The serialVersionUID */
|
||||||
|
private static final long serialVersionUID = 8464716396538298809L;
|
||||||
|
|
||||||
|
public TasksListImpl(URI location, SortedSet<Task> tasks) {
|
||||||
|
this.location = location;
|
||||||
|
this.tasks = tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet<Task> getTasks() {
|
||||||
|
return tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((location == null) ? 0 : location.hashCode());
|
||||||
|
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
TasksListImpl other = (TasksListImpl) obj;
|
||||||
|
if (location == null) {
|
||||||
|
if (other.location != null)
|
||||||
|
return false;
|
||||||
|
} else if (!location.equals(other.location))
|
||||||
|
return false;
|
||||||
|
if (tasks == null) {
|
||||||
|
if (other.tasks != null)
|
||||||
|
return false;
|
||||||
|
} else if (!tasks.equals(other.tasks))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,7 +37,7 @@ import javax.inject.Qualifier;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
@Retention(value = RetentionPolicy.RUNTIME)
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||||
@Qualifier
|
@Qualifier
|
||||||
public @interface TasksList {
|
public @interface TasksList {
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ package org.jclouds.vcloud.terremark;
|
||||||
|
|
||||||
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
||||||
|
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
|
||||||
|
@ -51,7 +53,7 @@ public interface TerremarkVCloudClient extends VCloudClient {
|
||||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||||
@XMLResponseParser(TerremarkVDCHandler.class)
|
@XMLResponseParser(TerremarkVDCHandler.class)
|
||||||
@Consumes(VDC_XML)
|
@Consumes(VDC_XML)
|
||||||
VDC getDefaultVDC();
|
Future<? extends VDC> getDefaultVDC();
|
||||||
|
|
||||||
//
|
//
|
||||||
// @GET
|
// @GET
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you 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.xml;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.rest.domain.Link;
|
||||||
|
import org.jclouds.rest.util.Utils;
|
||||||
|
import org.jclouds.util.DateService;
|
||||||
|
import org.jclouds.vcloud.domain.Task;
|
||||||
|
import org.jclouds.vcloud.domain.TaskStatus;
|
||||||
|
import org.jclouds.vcloud.domain.TasksList;
|
||||||
|
import org.jclouds.vcloud.domain.internal.TaskImpl;
|
||||||
|
import org.jclouds.vcloud.domain.internal.TasksListImpl;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class TasksListHandler extends ParseSax.HandlerWithResult<TasksList> {
|
||||||
|
|
||||||
|
private SortedSet<Task> tasks = Sets.newTreeSet();
|
||||||
|
protected final DateService dateService;
|
||||||
|
|
||||||
|
private Link taskLink;
|
||||||
|
private Link owner;
|
||||||
|
private Link result;
|
||||||
|
private TaskStatus status;
|
||||||
|
private DateTime startTime;
|
||||||
|
private DateTime endTime;
|
||||||
|
private URI location;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public TasksListHandler(DateService dateService) {
|
||||||
|
this.dateService = dateService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TasksList getResult() {
|
||||||
|
return new TasksListImpl(location, tasks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||||
|
throws SAXException {
|
||||||
|
if (qName.equals("TasksList")) {
|
||||||
|
location = Utils.newLink(attributes).getLocation();
|
||||||
|
} else if (qName.equals("Task")) {
|
||||||
|
taskLink = Utils.newLink(attributes);
|
||||||
|
status = TaskStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
|
||||||
|
startTime = dateService.iso8601DateParse(attributes.getValue(attributes
|
||||||
|
.getIndex("startTime")));
|
||||||
|
endTime = dateService
|
||||||
|
.iso8601DateParse(attributes.getValue(attributes.getIndex("endTime")));
|
||||||
|
} else if (qName.equals("Owner")) {
|
||||||
|
owner = Utils.newLink(attributes);
|
||||||
|
} else if (qName.equals("Result")) {
|
||||||
|
result = Utils.newLink(attributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
if (qName.equals("Task")) {
|
||||||
|
tasks.add(new TaskImpl(taskLink.getType(), taskLink.getLocation(), status, startTime,
|
||||||
|
endTime, owner, result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -59,7 +59,7 @@ public class VCloudClientLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultVDC() throws Exception {
|
public void testDefaultVDC() throws Exception {
|
||||||
VDC response = connection.getDefaultVDC();
|
VDC response = connection.getDefaultVDC().get(10, TimeUnit.SECONDS);
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getName());
|
assertNotNull(response.getName());
|
||||||
assertNotNull(response.getLocation());
|
assertNotNull(response.getLocation());
|
||||||
|
@ -68,6 +68,16 @@ public class VCloudClientLiveTest {
|
||||||
assertNotNull(response.getAvailableNetworks());
|
assertNotNull(response.getAvailableNetworks());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultTasksList() throws Exception {
|
||||||
|
org.jclouds.vcloud.domain.TasksList response = connection.getDefaultTasksList().get(10,
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
assertNotNull(response);
|
||||||
|
assertNotNull(response.getLocation());
|
||||||
|
assertNotNull(response.getTasks());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
@BeforeGroups(groups = { "live" })
|
||||||
public void setupClient() {
|
public void setupClient() {
|
||||||
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
|
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
|
||||||
|
|
|
@ -38,9 +38,11 @@ import org.jclouds.rest.RestClientTest;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.jclouds.vcloud.endpoints.Catalog;
|
import org.jclouds.vcloud.endpoints.Catalog;
|
||||||
|
import org.jclouds.vcloud.endpoints.TasksList;
|
||||||
import org.jclouds.vcloud.endpoints.VDC;
|
import org.jclouds.vcloud.endpoints.VDC;
|
||||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||||
import org.jclouds.vcloud.xml.CatalogHandler;
|
import org.jclouds.vcloud.xml.CatalogHandler;
|
||||||
|
import org.jclouds.vcloud.xml.TasksListHandler;
|
||||||
import org.jclouds.vcloud.xml.VDCHandler;
|
import org.jclouds.vcloud.xml.VDCHandler;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -86,6 +88,22 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
||||||
checkFilters(httpMethod);
|
checkFilters(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGetDefaultTasksList() throws SecurityException, NoSuchMethodException,
|
||||||
|
IOException {
|
||||||
|
Method method = VCloudClient.class.getMethod("getDefaultTasksList");
|
||||||
|
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method);
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpMethod, "GET http://tasksList HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
|
||||||
|
assertEntityEquals(httpMethod, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, TasksListHandler.class);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpMethod);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void checkFilters(GeneratedHttpRequest<VCloudClient> httpMethod) {
|
protected void checkFilters(GeneratedHttpRequest<VCloudClient> httpMethod) {
|
||||||
assertEquals(httpMethod.getFilters().size(), 1);
|
assertEquals(httpMethod.getFilters().size(), 1);
|
||||||
|
@ -105,6 +123,8 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
|
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
|
||||||
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
|
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
|
||||||
|
bind(URI.class).annotatedWith(TasksList.class).toInstance(
|
||||||
|
URI.create("http://tasksList"));
|
||||||
bind(SetVCloudTokenCookie.class).toInstance(
|
bind(SetVCloudTokenCookie.class).toInstance(
|
||||||
new SetVCloudTokenCookie(new Provider<String>() {
|
new SetVCloudTokenCookie(new Provider<String>() {
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ package org.jclouds.vcloud.terremark;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.vcloud.VCloudClientLiveTest;
|
import org.jclouds.vcloud.VCloudClientLiveTest;
|
||||||
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
|
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
|
||||||
|
@ -43,7 +45,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultVDC() throws Exception {
|
public void testDefaultVDC() throws Exception {
|
||||||
super.testDefaultVDC();
|
super.testDefaultVDC();
|
||||||
TerremarkVDC response = (TerremarkVDC) connection.getDefaultVDC();
|
TerremarkVDC response = (TerremarkVDC) connection.getDefaultVDC().get(10, TimeUnit.SECONDS);
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
assertNotNull(response.getCatalog());
|
assertNotNull(response.getCatalog());
|
||||||
assertNotNull(response.getInternetServices());
|
assertNotNull(response.getInternetServices());
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you 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.xml;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
|
import org.jclouds.rest.domain.internal.LinkImpl;
|
||||||
|
import org.jclouds.util.DateService;
|
||||||
|
import org.jclouds.vcloud.VCloudMediaType;
|
||||||
|
import org.jclouds.vcloud.domain.TaskStatus;
|
||||||
|
import org.jclouds.vcloud.domain.TasksList;
|
||||||
|
import org.jclouds.vcloud.domain.internal.TaskImpl;
|
||||||
|
import org.testng.annotations.BeforeTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests behavior of {@code TasksListHandler}
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "vcloud.TasksListHandlerTest")
|
||||||
|
public class TasksListHandlerTest extends BaseHandlerTest {
|
||||||
|
|
||||||
|
private DateService dateService;
|
||||||
|
|
||||||
|
@BeforeTest
|
||||||
|
@Override
|
||||||
|
protected void setUpInjector() {
|
||||||
|
super.setUpInjector();
|
||||||
|
dateService = injector.getInstance(DateService.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testApplyInputStream() {
|
||||||
|
InputStream is = getClass().getResourceAsStream("/taskslist.xml");
|
||||||
|
|
||||||
|
TasksList result = factory.create(injector.getInstance(TasksListHandler.class)).parse(is);
|
||||||
|
assertEquals(result.getLocation(), URI
|
||||||
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/1"));
|
||||||
|
assertEquals(
|
||||||
|
result.getTasks(),
|
||||||
|
ImmutableSortedSet
|
||||||
|
.of(
|
||||||
|
|
||||||
|
new TaskImpl(
|
||||||
|
VCloudMediaType.TASK_XML,
|
||||||
|
URI
|
||||||
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3300"),
|
||||||
|
TaskStatus.SUCCESS,
|
||||||
|
dateService.iso8601DateParse("2009-08-24T21:30:19.587Z"),
|
||||||
|
dateService.iso8601DateParse("2009-08-24T21:30:32.63Z"),
|
||||||
|
new LinkImpl(
|
||||||
|
"VDC Name",
|
||||||
|
VCloudMediaType.VDC_XML,
|
||||||
|
URI
|
||||||
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")),
|
||||||
|
new LinkImpl(
|
||||||
|
"Server1",
|
||||||
|
VCloudMediaType.VAPP_XML,
|
||||||
|
URI
|
||||||
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012"))),
|
||||||
|
|
||||||
|
new TaskImpl(
|
||||||
|
VCloudMediaType.TASK_XML,
|
||||||
|
URI
|
||||||
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"),
|
||||||
|
TaskStatus.SUCCESS,
|
||||||
|
dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"),
|
||||||
|
dateService.iso8601DateParse("2009-08-24T21:29:44.65Z"),
|
||||||
|
new LinkImpl(
|
||||||
|
"VDC Name",
|
||||||
|
VCloudMediaType.VDC_XML,
|
||||||
|
URI
|
||||||
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")),
|
||||||
|
new LinkImpl(
|
||||||
|
"Server1",
|
||||||
|
VCloudMediaType.VAPP_XML,
|
||||||
|
URI
|
||||||
|
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
<TasksList
|
||||||
|
href="https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/1"
|
||||||
|
xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||||
|
<Task
|
||||||
|
href="https://services.vcloudexpress.terremark.com/api/v0.8/task/3300"
|
||||||
|
type="application/vnd.vmware.vcloud.task+xml" status="success"
|
||||||
|
startTime="2009-08-24T21:30:19.587Z" endTime="2009-08-24T21:30:32.63Z">
|
||||||
|
<Owner
|
||||||
|
href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1"
|
||||||
|
type="application/vnd.vmware.vcloud.vdc+xml" name="VDC Name" />
|
||||||
|
<Result
|
||||||
|
href="https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012"
|
||||||
|
type="application/vnd.vmware.vcloud.vApp+xml" name="Server1" />
|
||||||
|
</Task>
|
||||||
|
<Task
|
||||||
|
href="https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"
|
||||||
|
type="application/vnd.vmware.vcloud.task+xml" status="success"
|
||||||
|
startTime="2009-08-24T21:29:32.983Z" endTime="2009-08-24T21:29:44.65Z">
|
||||||
|
<Owner
|
||||||
|
href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1"
|
||||||
|
type="application/vnd.vmware.vcloud.vdc+xml" name="VDC Name" />
|
||||||
|
<Result
|
||||||
|
href="https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012"
|
||||||
|
type="application/vnd.vmware.vcloud.vApp+xml" name="Server1" />
|
||||||
|
</Task>
|
||||||
|
</TasksList>
|
Loading…
Reference in New Issue