mirror of https://github.com/apache/jclouds.git
Merge pull request #146 from jsonking/master
Fleshing out JAXB for Tasks,Actions,Links,VirtualMachine plus update api calls with ecloud
This commit is contained in:
commit
a2f518bb87
|
@ -48,7 +48,7 @@
|
|||
</repositories>
|
||||
|
||||
<properties>
|
||||
<test.trmk-enterprisecloud.endpoint>https://services-beta.enterprisecloud.terremark.com/cloudapi</test.trmk-enterprisecloud.endpoint>
|
||||
<test.trmk-enterprisecloud.endpoint>https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud</test.trmk-enterprisecloud.endpoint>
|
||||
<test.trmk-enterprisecloud.apiversion>2011-07-01</test.trmk-enterprisecloud.apiversion>
|
||||
<test.trmk-enterprisecloud.identity>FIXME</test.trmk-enterprisecloud.identity>
|
||||
<test.trmk-enterprisecloud.credential>FIXME</test.trmk-enterprisecloud.credential>
|
||||
|
|
|
@ -34,7 +34,7 @@ public class TerremarkEnterpriseCloudPropertiesBuilder extends PropertiesBuilder
|
|||
@Override
|
||||
protected Properties defaultProperties() {
|
||||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://services-beta.enterprisecloud.terremark.com/cloudapi");
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud");
|
||||
properties.setProperty(PROPERTY_API_VERSION, "2011-07-01");
|
||||
return properties;
|
||||
}
|
||||
|
|
|
@ -29,18 +29,26 @@ import org.jclouds.javax.annotation.Nullable;
|
|||
import org.jclouds.trmk.enterprisecloud.domain.internal.BaseNamedResource;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.internal.BaseResource;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlEnumValue;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@XmlRootElement(name = "Action")
|
||||
public class Action extends BaseNamedResource<Action> {
|
||||
public static enum ActionDisabled {
|
||||
@XmlEnum
|
||||
public static enum ActionDisabled {
|
||||
/**
|
||||
* The actionDisabled attribute will have a value of noAccess when a user
|
||||
* does not have permission to perform the action. For example, for a user
|
||||
* with read-only access, all actions have actionDisabled="noAccess" set.
|
||||
*/
|
||||
@XmlEnumValue("noAccess")
|
||||
NO_ACCESS,
|
||||
/**
|
||||
* The attribute will have a value of disabled when the action is contrary
|
||||
|
@ -51,6 +59,7 @@ public class Action extends BaseNamedResource<Action> {
|
|||
* conditions apply, actions have actionDisabled="noAccess" set. If
|
||||
* neither condition applies, the attribute will not appear.
|
||||
*/
|
||||
@XmlEnumValue("disabled")
|
||||
DISABLED,
|
||||
/**
|
||||
* ActionDisabled was not parsed by jclouds.
|
||||
|
@ -162,13 +171,17 @@ public class Action extends BaseNamedResource<Action> {
|
|||
|
||||
}
|
||||
|
||||
protected final ActionDisabled actionDisabled;
|
||||
@XmlAttribute
|
||||
protected ActionDisabled actionDisabled;
|
||||
|
||||
public Action(URI href, String type, String name, @Nullable ActionDisabled actionDisabled) {
|
||||
super(href, type, name);
|
||||
this.actionDisabled = actionDisabled;
|
||||
}
|
||||
|
||||
protected Action() {
|
||||
//For JAXB
|
||||
}
|
||||
/**
|
||||
* The attribute actionDisabled appears only when the example has an action
|
||||
* disabled for business rules.
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.trmk.enterprisecloud.domain;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wraps individual Action elements.
|
||||
* Needed because parsing is done with JAXB and it does not handle Generic collections
|
||||
* @author Jason King
|
||||
*/
|
||||
@XmlRootElement(name = "Actions")
|
||||
public class Actions {
|
||||
|
||||
private LinkedHashSet<Action> actions = Sets.newLinkedHashSet();
|
||||
|
||||
@XmlElement(name = "Action")
|
||||
void setAction(Action action) {
|
||||
this.actions.add(action);
|
||||
}
|
||||
|
||||
public Set<Action> getActions() {
|
||||
return Collections.unmodifiableSet(actions);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "["+ actions.toString()+"]";
|
||||
}
|
||||
|
||||
}
|
|
@ -26,41 +26,52 @@ import java.util.Map;
|
|||
import org.jclouds.trmk.enterprisecloud.domain.internal.BaseNamedResource;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.internal.BaseResource;
|
||||
|
||||
import javax.xml.bind.annotation.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@XmlRootElement(name = "Link")
|
||||
public class Link extends BaseNamedResource<Link> {
|
||||
public static enum Relationship {
|
||||
@XmlEnum
|
||||
public static enum Relationship {
|
||||
/**
|
||||
* The entity in the link owns the entity in the response
|
||||
*/
|
||||
@XmlEnumValue("up")
|
||||
UP,
|
||||
/**
|
||||
* The entity in the response owns the entity in the link
|
||||
*/
|
||||
@XmlEnumValue("down")
|
||||
DOWN,
|
||||
/**
|
||||
* The entity in the link is an alternate view of the entity in the
|
||||
* response
|
||||
*/
|
||||
@XmlEnumValue("alternate")
|
||||
ALTERNATE,
|
||||
/**
|
||||
* The link is a path to the first page in the pages of responses
|
||||
*/
|
||||
@XmlEnumValue("first")
|
||||
FIRST,
|
||||
/**
|
||||
* The link is a path to the previous page in the pages of responses
|
||||
*/
|
||||
@XmlEnumValue("previous")
|
||||
PREVIOUS,
|
||||
/**
|
||||
* The link is a path to the next page in the pages of responses
|
||||
*/
|
||||
@XmlEnumValue("next")
|
||||
NEXT,
|
||||
/**
|
||||
* The link is a path to the last page in the pages of responses
|
||||
*/
|
||||
@XmlEnumValue("last")
|
||||
LAST,
|
||||
/**
|
||||
* Relationship was not parsed by jclouds.
|
||||
|
@ -171,13 +182,18 @@ public class Link extends BaseNamedResource<Link> {
|
|||
}
|
||||
}
|
||||
|
||||
protected final Relationship rel;
|
||||
@XmlAttribute
|
||||
protected Relationship rel;
|
||||
|
||||
public Link(URI href, String type, String name, Relationship rel) {
|
||||
super(href, type, name);
|
||||
this.rel = checkNotNull(rel, "rel");
|
||||
}
|
||||
|
||||
protected Link() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.trmk.enterprisecloud.domain;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wraps individual Link elements.
|
||||
* Needed because parsing is done with JAXB and it does not handle Generic collections
|
||||
* @author Jason King
|
||||
*/
|
||||
@XmlRootElement(name = "Links")
|
||||
public class Links {
|
||||
|
||||
private LinkedHashSet<Link> links = Sets.newLinkedHashSet();
|
||||
|
||||
@XmlElement(name = "Link")
|
||||
public void setLink(Link link) {
|
||||
this.links.add(link);
|
||||
}
|
||||
|
||||
public Set<Link> getLinks() {
|
||||
return Collections.unmodifiableSet(links);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "["+ links.toString()+"]";
|
||||
}
|
||||
|
||||
}
|
|
@ -63,6 +63,11 @@ public class Task extends BaseResource<Task> {
|
|||
*/
|
||||
@XmlEnumValue("Success")
|
||||
SUCCESS,
|
||||
/**
|
||||
* the task completed successfully.
|
||||
*/
|
||||
@XmlEnumValue("Complete")
|
||||
COMPLETE,
|
||||
/**
|
||||
* the task failed with an error.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.trmk.enterprisecloud.domain;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wraps individual Task elements.
|
||||
* Needed because parsing is done with JAXB and it does not handle Generic collections
|
||||
* @author Jason King
|
||||
*/
|
||||
@XmlRootElement(name = "Tasks")
|
||||
public class Tasks {
|
||||
|
||||
private LinkedHashSet<Task> tasks = Sets.newLinkedHashSet();
|
||||
|
||||
@XmlElement(name = "Task")
|
||||
public void setTask(Task task) {
|
||||
tasks.add(task);
|
||||
}
|
||||
|
||||
public Set<Task> getTasks() {
|
||||
return Collections.unmodifiableSet(tasks);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "["+tasks.toString()+"]";
|
||||
}
|
||||
}
|
|
@ -21,9 +21,12 @@ package org.jclouds.trmk.enterprisecloud.domain;
|
|||
import org.jclouds.trmk.enterprisecloud.domain.internal.BaseNamedResource;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.internal.BaseResource;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
|
@ -32,6 +35,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
* @author Jason King
|
||||
*
|
||||
*/
|
||||
@XmlRootElement(name = "VirtualMachine")
|
||||
public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -48,32 +52,35 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
}
|
||||
|
||||
public static class Builder extends BaseNamedResource.Builder<VirtualMachine> {
|
||||
private List<Link> links;
|
||||
private List<Action> actions;
|
||||
private List<Task> tasks;
|
||||
private Links links;
|
||||
private Actions actions;
|
||||
private Tasks tasks;
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getLinks
|
||||
*/
|
||||
public Builder links(List<Link> links) {
|
||||
this.links = links;
|
||||
public Builder links(Set<Link> links) {
|
||||
this.links = new Links();
|
||||
for(Link link:links) this.links.setLink(link);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getActions
|
||||
*/
|
||||
public Builder actions(List<Action> actions) {
|
||||
this.actions = actions;
|
||||
public Builder actions(Set<Action> actions) {
|
||||
this.actions = new Actions();
|
||||
for(Action action:actions) this.actions.setAction(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getTasks
|
||||
*/
|
||||
public Builder tasks(List<Task> tasks) {
|
||||
this.tasks = tasks;
|
||||
public Builder tasks(Set<Task> tasks) {
|
||||
this.tasks = new Tasks();
|
||||
for(Task task: tasks) this.tasks.setTask(task);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -150,12 +157,19 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
|
||||
}
|
||||
|
||||
private final List<Link> links;
|
||||
private final List<Task> tasks;
|
||||
private final List<Action> actions;
|
||||
private final String description;
|
||||
@XmlElement(name = "Links", required = true)
|
||||
private Links links;
|
||||
|
||||
public VirtualMachine(URI href, String type, String name, List<Task> tasks, List<Action> actions, List<Link> links, String description) {
|
||||
@XmlElement(name = "Tasks", required = true)
|
||||
private Tasks tasks;
|
||||
|
||||
@XmlElement(name = "Actions", required = true)
|
||||
private Actions actions;
|
||||
|
||||
@XmlElement(name = "Description", required = true)
|
||||
private String description;
|
||||
|
||||
public VirtualMachine(URI href, String type, String name, Tasks tasks, Actions actions, Links links, String description) {
|
||||
super(href, type, name);
|
||||
this.description = checkNotNull(description, "description");
|
||||
this.links = checkNotNull(links, "links");
|
||||
|
@ -163,8 +177,13 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
this.actions = checkNotNull(actions, "actions");
|
||||
}
|
||||
|
||||
public List<Link> getLinks() {
|
||||
return links;
|
||||
protected VirtualMachine() {
|
||||
//For JAXB
|
||||
}
|
||||
|
||||
|
||||
public Set<Link> getLinks() {
|
||||
return Collections.unmodifiableSet(links.getLinks());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,12 +192,12 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
* Use the href to retrieve the complete list of tasks.
|
||||
* @return most recent tasks
|
||||
*/
|
||||
public List<Task> getTasks() {
|
||||
return tasks;
|
||||
public Set<Task> getTasks() {
|
||||
return Collections.unmodifiableSet(tasks.getTasks());
|
||||
}
|
||||
|
||||
public List<Action> getActions() {
|
||||
return actions;
|
||||
public Set<Action> getActions() {
|
||||
return Collections.unmodifiableSet(actions.getActions());
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
|
|
|
@ -103,7 +103,8 @@ public class BaseNamedResource<T extends BaseNamedResource<T>> extends BaseResou
|
|||
|
||||
BaseNamedResource that = (BaseNamedResource) o;
|
||||
|
||||
if (!name.equals(that.name)) return false;
|
||||
if (name != null ? !name.equals(that.name) : that.name != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -111,7 +112,7 @@ public class BaseNamedResource<T extends BaseNamedResource<T>> extends BaseResou
|
|||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + name.hashCode();
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,13 @@ import org.jclouds.rest.annotations.*;
|
|||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Task;
|
||||
import org.jclouds.trmk.enterprisecloud.xml.TasksHandler;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Tasks;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Task via their REST API.
|
||||
|
@ -53,9 +52,9 @@ public interface TaskAsyncClient {
|
|||
@GET
|
||||
@Path("/tasks/environments/{environmentId}")
|
||||
@Consumes("application/vnd.tmrk.cloud.task; type=collection")
|
||||
@XMLResponseParser(TasksHandler.class)
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Task>> getTasksInEnvironment(@PathParam("environmentId") long environmentId);
|
||||
ListenableFuture<Tasks> getTasksInEnvironment(@PathParam("environmentId") long environmentId);
|
||||
|
||||
/**
|
||||
* @see TaskClient#getTask
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.trmk.enterprisecloud.features;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Task;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Tasks;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Task.
|
||||
|
@ -44,7 +44,7 @@ public interface TaskClient {
|
|||
*
|
||||
* @return a history of changes to the environment.
|
||||
*/
|
||||
Set<Task> getTasksInEnvironment(long environmentId);
|
||||
Tasks getTasksInEnvironment(long environmentId);
|
||||
|
||||
/**
|
||||
* The Get Tasks by ID call returns information regarding a specified task in
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.trmk.enterprisecloud.features;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.JAXBResponseParser;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.VirtualMachine;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to VirtualMachine via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see org.jclouds.trmk.enterprisecloud.features.TaskClient
|
||||
* @see <a href=
|
||||
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
|
||||
* />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Headers(keys = "x-trmk-version", values = "{jclouds.api-version}")
|
||||
public interface VirtualMachineAsyncClient {
|
||||
|
||||
/**
|
||||
* @see org.jclouds.trmk.enterprisecloud.features.VirtualMachineClient#getVirtualMachine
|
||||
*/
|
||||
@GET
|
||||
@Path("/virtualMachines/{id}")
|
||||
@Consumes("application/vnd.tmrk.cloud.virtualMachine")
|
||||
@JAXBResponseParser
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<VirtualMachine> getVirtualMachine(@PathParam("id") long id);
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.trmk.enterprisecloud.features;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.VirtualMachine;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to VirtualMachine.
|
||||
* <p/>
|
||||
*
|
||||
* @see org.jclouds.trmk.enterprisecloud.features.VirtualMachineAsyncClient
|
||||
* @see <a href=
|
||||
* "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID="
|
||||
* />
|
||||
* @author Jason King
|
||||
*/
|
||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||
public interface VirtualMachineClient {
|
||||
|
||||
/**
|
||||
* The Get Virtual Machines by ID call returns information regarding a
|
||||
* specified virtual machine defined in an environment.
|
||||
*
|
||||
* @return the virtual Machine or null if not found
|
||||
*/
|
||||
VirtualMachine getVirtualMachine(long id);
|
||||
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.trmk.enterprisecloud.xml;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.util.SaxUtils.currentOrNull;
|
||||
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.NamedResource;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Task;
|
||||
import org.jclouds.util.SaxUtils;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
|
||||
|
||||
protected final DateService dateService;
|
||||
|
||||
protected StringBuilder currentText = new StringBuilder();
|
||||
protected Task.Builder builder = Task.builder();
|
||||
|
||||
@Inject
|
||||
public TaskHandler(DateService dateService) {
|
||||
this.dateService = checkNotNull(dateService, "dateService");
|
||||
}
|
||||
|
||||
public Task getResult() {
|
||||
try {
|
||||
return builder.build();
|
||||
} finally {
|
||||
builder = Task.builder();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||
Map<String, String> attributes = SaxUtils.cleanseAttributes(attrs);
|
||||
if (equalsOrSuffix(qName, "Task")) {
|
||||
builder.fromAttributes(attributes);
|
||||
} else if (equalsOrSuffix(qName, "ImpactedItem")) {
|
||||
builder.impactedItem(NamedResource.builder().fromAttributes(attributes).build());
|
||||
} else if (equalsOrSuffix(qName, "InitiatedBy")) {
|
||||
builder.initiatedBy(NamedResource.builder().fromAttributes(attributes).build());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
if (equalsOrSuffix(qName, "Operation")) {
|
||||
builder.operation(currentOrNull(currentText));
|
||||
} else if (equalsOrSuffix(qName, "Status")) {
|
||||
String status = currentOrNull(currentText);
|
||||
if (status != null)
|
||||
builder.status(Task.Status.fromValue(status));
|
||||
} else if (equalsOrSuffix(qName, "StartTime")) {
|
||||
String date = currentOrNull(currentText);
|
||||
if (date != null)
|
||||
builder.startTime(dateService.iso8601DateParse(date));
|
||||
} else if (equalsOrSuffix(qName, "CompletedTime")) {
|
||||
String date = currentOrNull(currentText);
|
||||
if (date != null)
|
||||
builder.completedTime(dateService.iso8601DateParse(date));
|
||||
} else if (equalsOrSuffix(qName, "Notes")) {
|
||||
builder.notes(currentOrNull(currentText));
|
||||
} else if (equalsOrSuffix(qName, "ErrorMessage")) {
|
||||
builder.errorMessage(currentOrNull(currentText));
|
||||
|
||||
}
|
||||
currentText = new StringBuilder();
|
||||
}
|
||||
|
||||
public void characters(char ch[], int start, int length) {
|
||||
currentText.append(ch, start, length);
|
||||
}
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.trmk.enterprisecloud.xml;
|
||||
|
||||
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Task;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class TasksHandler extends ParseSax.HandlerWithResult<Set<Task>> {
|
||||
public Set<Task> getResult() {
|
||||
try {
|
||||
return builder.build();
|
||||
} finally {
|
||||
builder = ImmutableSet.<Task> builder();
|
||||
}
|
||||
}
|
||||
|
||||
protected final TaskHandler taskHandler;
|
||||
|
||||
protected ImmutableSet.Builder<Task> builder = ImmutableSet.<Task> builder();
|
||||
|
||||
@Inject
|
||||
public TasksHandler(TaskHandler taskHandler) {
|
||||
this.taskHandler = taskHandler;
|
||||
}
|
||||
|
||||
protected boolean inTask;
|
||||
|
||||
protected int depth = 0;
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
||||
depth++;
|
||||
if (depth == 2) {
|
||||
if (equalsOrSuffix(qName, "Task")) {
|
||||
inTask = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (inTask) {
|
||||
taskHandler.startElement(uri, localName, qName, attrs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
depth--;
|
||||
if (depth == 1) {
|
||||
if (equalsOrSuffix(qName, "Task")) {
|
||||
inTask = false;
|
||||
builder.add(taskHandler.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
if (inTask) {
|
||||
taskHandler.endElement(uri, localName, qName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void characters(char ch[], int start, int length) {
|
||||
if (inTask) {
|
||||
taskHandler.characters(ch, start, length);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,12 +20,10 @@ package org.jclouds.trmk.enterprisecloud.features;
|
|||
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.trmk.enterprisecloud.xml.TasksHandler;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -44,13 +42,12 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient
|
|||
Method method = TaskAsyncClient.class.getMethod("getTasksInEnvironment", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1l);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/tasks/environments/1 HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/environments/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/vnd.tmrk.cloud.task; type=collection\nx-trmk-version: 2011-07-01\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TasksHandler.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
@ -59,9 +56,9 @@ public class TaskAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClient
|
|||
|
||||
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TaskAsyncClient.class.getMethod("getTask", URI.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, URI.create("https://services-beta.enterprisecloud.terremark.com/cloudapi/tasks/1"));
|
||||
HttpRequest httpRequest = processor.createRequest(method, URI.create("https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1"));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/tasks/1 HTTP/1.1");
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/tasks/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.task\nx-trmk-version: 2011-07-01\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
|
|
@ -18,15 +18,14 @@
|
|||
*/
|
||||
package org.jclouds.trmk.enterprisecloud.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Task;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Tasks;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TaskClient}
|
||||
*
|
||||
|
@ -47,11 +46,11 @@ public class TaskClientLiveTest extends BaseTerremarkEnterpriseCloudClientLiveTe
|
|||
// TODO: don't hard-code id
|
||||
// TODO: docs say don't parse the href, yet no xml includes "identifier",
|
||||
// I suspect we may need to change to URI args as opposed to long
|
||||
Set<Task> response = client.getTasksInEnvironment(77);
|
||||
Tasks response = client.getTasksInEnvironment(77);
|
||||
assert null != response;
|
||||
|
||||
assertTrue(response.size() >= 0);
|
||||
for (Task task : response) {
|
||||
assertTrue(response.getTasks().size() >= 0);
|
||||
for (Task task : response.getTasks()) {
|
||||
assertEquals(client.getTask(task.getHref()), task);
|
||||
assert task.getStatus() != Task.Status.UNRECOGNIZED : response;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.trmk.enterprisecloud.features;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code TaskAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "VirtualMachineAsyncClientTest")
|
||||
public class VirtualMachineAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClientTest<VirtualMachineAsyncClient> {
|
||||
|
||||
public void testGetVirtualMachine() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachine", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/virtualMachines/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.virtualMachine\nx-trmk-version: 2011-07-01\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<VirtualMachineAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -36,8 +36,10 @@ import org.jclouds.rest.RestContextSpec;
|
|||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.NamedResource;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Task;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Tasks;
|
||||
import org.jclouds.trmk.enterprisecloud.features.TaskAsyncClient;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -50,16 +52,23 @@ import static org.jclouds.io.Payloads.newInputStreamPayload;
|
|||
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
||||
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TaskHandler}
|
||||
* Tests behavior of JAXB parsing for Task/Tasks
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "TaskHandlerTest")
|
||||
public class TaskHandlerTest extends BaseRestClientTest {
|
||||
static SimpleDateFormatDateService dateService = new SimpleDateFormatDateService();
|
||||
static Task expected = Task
|
||||
public class TaskJAXBParsingTest extends BaseRestClientTest {
|
||||
private SimpleDateFormatDateService dateService;
|
||||
private Task expected1;
|
||||
private Task expected2;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
dateService = new SimpleDateFormatDateService();
|
||||
expected1 = Task
|
||||
.builder()
|
||||
.href(URI.create("/livespec/tasks/1002"))
|
||||
.type("application/vnd.tmrk.cloud.task")
|
||||
|
@ -76,6 +85,24 @@ public class TaskHandlerTest extends BaseRestClientTest {
|
|||
NamedResource.builder().href(URI.create("/livespec/admin/users/1")).name("User 1")
|
||||
.type("application/vnd.tmrk.cloud.admin.user").build()).build();
|
||||
|
||||
expected2 = Task
|
||||
.builder()
|
||||
.href(URI.create("/livespec/tasks/1003"))
|
||||
.type("application/vnd.tmrk.cloud.task")
|
||||
.operation("Add Node Service 2")
|
||||
.status(Task.Status.SUCCESS)
|
||||
.impactedItem(
|
||||
NamedResource.builder().href(URI.create("/livespec/nodeservices/2")).name("sample node internet 2")
|
||||
.type("application/vnd.tmrk.cloud.nodeService").build())
|
||||
.startTime(dateService.iso8601DateParse("2011-11-11T11:19:13.38225Z"))
|
||||
.completedTime(dateService.iso8601DateParse("2011-11-11T11:20:13.38225Z"))
|
||||
.notes("Some notes about the operation.")
|
||||
.errorMessage("sample success message 1 here")
|
||||
.initiatedBy(
|
||||
NamedResource.builder().href(URI.create("/livespec/admin/users/3")).name("User 3")
|
||||
.type("application/vnd.tmrk.cloud.admin.user").build()).build();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
|
||||
|
@ -111,6 +138,25 @@ public class TaskHandlerTest extends BaseRestClientTest {
|
|||
|
||||
InputStream is = getClass().getResourceAsStream("/task.xml");
|
||||
Task task = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||
assertEquals(task, expected);
|
||||
assertEquals(task, expected1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseTasksWithJAXB() throws Exception {
|
||||
|
||||
Method method = TaskAsyncClient.class.getMethod("getTasksInEnvironment",long.class);
|
||||
HttpRequest request = factory(TaskAsyncClient.class).createRequest(method,1);
|
||||
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||
|
||||
Function<HttpResponse, Tasks> parser = (Function<HttpResponse, Tasks>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/tasks.xml");
|
||||
Tasks tasksResponse = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||
|
||||
Set<Task> tasks = tasksResponse.getTasks();
|
||||
assertEquals(tasks.size(), 2);
|
||||
assertTrue(tasks.contains(expected1));
|
||||
assertTrue(tasks.contains(expected2));
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.trmk.enterprisecloud.xml;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseSax.Factory;
|
||||
import org.jclouds.http.functions.config.SaxParserModule;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.Task;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TasksHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "TasksHandlerTest")
|
||||
public class TasksHandlerTest {
|
||||
|
||||
public void test() {
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/tasks.xml");
|
||||
Injector injector = Guice.createInjector(new SaxParserModule());
|
||||
Factory factory = injector.getInstance(ParseSax.Factory.class);
|
||||
Set<Task> result = factory.create(injector.getInstance(TasksHandler.class)).parse(is);
|
||||
Set<Task> expected = ImmutableSet.of(TaskHandlerTest.expected);
|
||||
|
||||
assertEquals(result.toString(), expected.toString());
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.trmk.enterprisecloud.xml;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import org.jclouds.crypto.Crypto;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseXMLWithJAXB;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.rest.BaseRestClientTest;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.trmk.enterprisecloud.domain.VirtualMachine;
|
||||
import org.jclouds.trmk.enterprisecloud.features.VirtualMachineAsyncClient;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Named;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.io.Payloads.newInputStreamPayload;
|
||||
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
||||
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of JAXB parsing for VirtualMachines
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "VirtualMachineJAXBParsingTest")
|
||||
public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
|
||||
private SimpleDateFormatDateService dateService;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() {
|
||||
dateService = new SimpleDateFormatDateService();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
void setupFactory() {
|
||||
RestContextSpec<String, Integer> contextSpec = contextSpec("test", "http://localhost:9999", "1", "", "userfoo",
|
||||
"credentialFoo", String.class, Integer.class,
|
||||
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Named("exception")
|
||||
Set<String> exception() {
|
||||
throw new AuthorizationException();
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
injector = createContextBuilder(contextSpec).buildInjector();
|
||||
parserFactory = injector.getInstance(ParseSax.Factory.class);
|
||||
crypto = injector.getInstance(Crypto.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseVirtualMachineWithJAXB() throws Exception {
|
||||
|
||||
Method method = VirtualMachineAsyncClient.class.getMethod("getVirtualMachine", long.class);
|
||||
HttpRequest request = factory(VirtualMachineAsyncClient.class).createRequest(method,1);
|
||||
assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class);
|
||||
|
||||
Function<HttpResponse, VirtualMachine> parser = (Function<HttpResponse, VirtualMachine>) RestAnnotationProcessor
|
||||
.createResponseParser(parserFactory, injector, method, request);
|
||||
|
||||
InputStream is = getClass().getResourceAsStream("/virtualMachine.xml");
|
||||
VirtualMachine virtualMachine = parser.apply(new HttpResponse(200, "ok", newInputStreamPayload(is)));
|
||||
|
||||
assertEquals("My first terremark server",virtualMachine.getDescription());
|
||||
assertEquals(6,virtualMachine.getLinks().size());
|
||||
assertEquals(11,virtualMachine.getActions().size());
|
||||
assertEquals(1,virtualMachine.getTasks().size());
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,12 +1,22 @@
|
|||
<Tasks href="/livespec/tasks/environments/1" type="application/vnd.tmrk.cloud.task; type=collection">
|
||||
<Task href="/livespec/tasks/1002" type="application/vnd.tmrk.cloud.task">
|
||||
<Operation>Add Node Service</Operation>
|
||||
<Status>Error</Status>
|
||||
<ImpactedItem href="/livespec/nodeservices/1" name="sample node internet 1" type="application/vnd.tmrk.cloud.nodeService"/>
|
||||
<StartTime>2011-11-07T11:19:13.38225Z</StartTime>
|
||||
<CompletedTime>2011-11-07T11:20:13.38225Z</CompletedTime>
|
||||
<Notes>Some notes about the operation.</Notes>
|
||||
<ErrorMessage>sample error message 1 here</ErrorMessage>
|
||||
<InitiatedBy href="/livespec/admin/users/1" name="User 1" type="application/vnd.tmrk.cloud.admin.user"/>
|
||||
</Task>
|
||||
<Operation>Add Node Service</Operation>
|
||||
<Status>Error</Status>
|
||||
<ImpactedItem href="/livespec/nodeservices/1" name="sample node internet 1" type="application/vnd.tmrk.cloud.nodeService"/>
|
||||
<StartTime>2011-11-07T11:19:13.38225Z</StartTime>
|
||||
<CompletedTime>2011-11-07T11:20:13.38225Z</CompletedTime>
|
||||
<Notes>Some notes about the operation.</Notes>
|
||||
<ErrorMessage>sample error message 1 here</ErrorMessage>
|
||||
<InitiatedBy href="/livespec/admin/users/1" name="User 1" type="application/vnd.tmrk.cloud.admin.user"/>
|
||||
</Task>
|
||||
<Task href="/livespec/tasks/1003" type="application/vnd.tmrk.cloud.task">
|
||||
<Operation>Add Node Service 2</Operation>
|
||||
<Status>Success</Status>
|
||||
<ImpactedItem href="/livespec/nodeservices/2" name="sample node internet 2" type="application/vnd.tmrk.cloud.nodeService"/>
|
||||
<StartTime>2011-11-11T11:19:13.38225Z</StartTime>
|
||||
<CompletedTime>2011-11-11T11:20:13.38225Z</CompletedTime>
|
||||
<Notes>Some notes about the operation.</Notes>
|
||||
<ErrorMessage>sample success message 1 here</ErrorMessage>
|
||||
<InitiatedBy href="/livespec/admin/users/3" name="User 3" type="application/vnd.tmrk.cloud.admin.user"/>
|
||||
</Task>
|
||||
</Tasks>
|
Loading…
Reference in New Issue