Implement the Cloudstack "VM group" API calls

This commit is contained in:
Richard Downer 2011-11-06 11:48:28 +02:00
parent 0f8a2eec17
commit 98c3116edc
11 changed files with 882 additions and 0 deletions

View File

@ -33,6 +33,7 @@ import org.jclouds.cloudstack.features.SSHKeyPairAsyncClient;
import org.jclouds.cloudstack.features.SecurityGroupAsyncClient; import org.jclouds.cloudstack.features.SecurityGroupAsyncClient;
import org.jclouds.cloudstack.features.TemplateAsyncClient; import org.jclouds.cloudstack.features.TemplateAsyncClient;
import org.jclouds.cloudstack.features.VirtualMachineAsyncClient; import org.jclouds.cloudstack.features.VirtualMachineAsyncClient;
import org.jclouds.cloudstack.features.VMGroupAsyncClient;
import org.jclouds.cloudstack.features.ZoneAsyncClient; import org.jclouds.cloudstack.features.ZoneAsyncClient;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
@ -142,4 +143,11 @@ public interface CloudStackAsyncClient {
*/ */
@Delegate @Delegate
SSHKeyPairAsyncClient getSSHKeyPairClient(); SSHKeyPairAsyncClient getSSHKeyPairClient();
/**
* Provides asynchronous access to VM groups
*/
@Delegate
VMGroupAsyncClient getVMGroupClient();
} }

View File

@ -35,6 +35,7 @@ import org.jclouds.cloudstack.features.SSHKeyPairClient;
import org.jclouds.cloudstack.features.SecurityGroupClient; import org.jclouds.cloudstack.features.SecurityGroupClient;
import org.jclouds.cloudstack.features.TemplateClient; import org.jclouds.cloudstack.features.TemplateClient;
import org.jclouds.cloudstack.features.VirtualMachineClient; import org.jclouds.cloudstack.features.VirtualMachineClient;
import org.jclouds.cloudstack.features.VMGroupClient;
import org.jclouds.cloudstack.features.ZoneClient; import org.jclouds.cloudstack.features.ZoneClient;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
@ -146,4 +147,10 @@ public interface CloudStackClient {
@Delegate @Delegate
SSHKeyPairClient getSSHKeyPairClient(); SSHKeyPairClient getSSHKeyPairClient();
/**
* Provides synchronous access to VM groups
*/
@Delegate
VMGroupClient getVMGroupClient();
} }

View File

@ -50,6 +50,8 @@ import org.jclouds.cloudstack.features.SecurityGroupAsyncClient;
import org.jclouds.cloudstack.features.SecurityGroupClient; import org.jclouds.cloudstack.features.SecurityGroupClient;
import org.jclouds.cloudstack.features.TemplateAsyncClient; import org.jclouds.cloudstack.features.TemplateAsyncClient;
import org.jclouds.cloudstack.features.TemplateClient; import org.jclouds.cloudstack.features.TemplateClient;
import org.jclouds.cloudstack.features.VMGroupAsyncClient;
import org.jclouds.cloudstack.features.VMGroupClient;
import org.jclouds.cloudstack.features.VirtualMachineAsyncClient; import org.jclouds.cloudstack.features.VirtualMachineAsyncClient;
import org.jclouds.cloudstack.features.VirtualMachineClient; import org.jclouds.cloudstack.features.VirtualMachineClient;
import org.jclouds.cloudstack.features.ZoneAsyncClient; import org.jclouds.cloudstack.features.ZoneAsyncClient;
@ -95,6 +97,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
.put(ConfigurationClient.class, ConfigurationAsyncClient.class)// .put(ConfigurationClient.class, ConfigurationAsyncClient.class)//
.put(AccountClient.class, AccountAsyncClient.class)// .put(AccountClient.class, AccountAsyncClient.class)//
.put(SSHKeyPairClient.class, SSHKeyPairAsyncClient.class)// .put(SSHKeyPairClient.class, SSHKeyPairAsyncClient.class)//
.put(VMGroupClient.class, VMGroupAsyncClient.class)//
.build(); .build();
public CloudStackRestClientModule() { public CloudStackRestClientModule() {

View File

@ -0,0 +1,186 @@
/**
* 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.cloudstack.domain;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
/**
* @author Richard Downer
*/
public class VMGroup implements Comparable<VMGroup> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String account;
private Date created;
private String domain;
private long domainId;
private String name;
public Builder id(long id) {
this.id = id;
return this;
}
public Builder account(String account) {
this.account = account;
return this;
}
public Builder created(Date created) {
this.created = created;
return this;
}
public Builder domain(String domain) {
this.domain = domain;
return this;
}
public Builder domainId(long domainId) {
this.domainId = domainId;
return this;
}
public Builder name(String name) {
this.name = name;
return this;
}
public VMGroup build() {
return new VMGroup(id, account, created, domain, domainId, name);
}
}
private long id;
private String account;
private Date created;
private String domain;
@SerializedName("domainid")
private long domainId;
private String name;
public VMGroup(long id, String account, Date created, String domain, long domainId, String name) {
this.id = id;
this.account = account;
this.created = created;
this.domain = domain;
this.domainId = domainId;
this.name = name;
}
/**
* present only for serializer
*/
VMGroup() {
}
/**
* @return the VMGroup's ID
*/
public long getId() {
return id;
}
/**
* @return the account that owns the VMGroup
*/
public String getAccount() {
return account;
}
/**
* @return the VMGroup's creation timestamp
*/
public Date getCreated() {
return created;
}
/**
* @return the domain that contains the VMGroup
*/
public String getDomain() {
return domain;
}
/**
* @return the ID of the domain that contains the VMGroup
*/
public long getDomainId() {
return domainId;
}
/**
* @return the name of the VMGroup
*/
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VMGroup vmGroup = (VMGroup) o;
if (domainId != vmGroup.domainId) return false;
if (id != vmGroup.id) return false;
if (account != null ? !account.equals(vmGroup.account) : vmGroup.account != null) return false;
if (created != null ? !created.equals(vmGroup.created) : vmGroup.created != null) return false;
if (domain != null ? !domain.equals(vmGroup.domain) : vmGroup.domain != null) return false;
if (name != null ? !name.equals(vmGroup.name) : vmGroup.name != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (account != null ? account.hashCode() : 0);
result = 31 * result + (created != null ? created.hashCode() : 0);
result = 31 * result + (domain != null ? domain.hashCode() : 0);
result = 31 * result + (int) (domainId ^ (domainId >>> 32));
result = 31 * result + (name != null ? name.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "[id=" + id +
", account='" + account + '\'' +
", created=" + created +
", domain='" + domain + '\'' +
", domainId=" + domainId +
", name='" + name + '\'' +
'}';
}
@Override
public int compareTo(VMGroup vmGroup) {
return new Long(id).compareTo(vmGroup.getId());
}
}

View File

@ -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.cloudstack.features;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.cloudstack.domain.VMGroup;
import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.CreateVMGroupOptions;
import org.jclouds.cloudstack.options.ListVMGroupsOptions;
import org.jclouds.cloudstack.options.UpdateVMGroupOptions;
import org.jclouds.rest.annotations.*;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.Set;
/**
* Provides asynchronous access to CloudStack VM group features.
* <p/>
*
* @author Richard Downer
* @see VMGroupClient
* @see <a href="http://download.cloud.com/releases/2.2.0/api/TOC_User.html" />
*/
@RequestFilters(QuerySigner.class)
@QueryParams(keys = "response", values = "json")
public interface VMGroupAsyncClient {
/**
* Lists VM groups
*
* @param options if present, how to constrain the list.
* @return VM groups matching query, or empty set, if no zones are found
*/
@GET
@QueryParams(keys = "command", values = "listInstanceGroups")
@SelectJson("instancegroup")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<VMGroup>> listInstanceGroups(ListVMGroupsOptions... options);
/**
* @see VMGroupClient#getInstanceGroup
*/
@GET
@QueryParams(keys = "command", values = "listInstanceGroups")
@SelectJson("instancegroup")
@OnlyElement
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<VMGroup> getInstanceGroup(@QueryParam("id") long id);
/**
* Creates a VM group
*
* @param name the name of the VM group
* @param options optional parameters
* @return the new VMGroup
*/
@GET
@QueryParams(keys = "command", values = "createInstanceGroup")
@SelectJson("instancegroup")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<VMGroup> createInstanceGroup(@QueryParam("name") String name, CreateVMGroupOptions... options);
/**
* Modify a VM group
*
* @param name the new name of the group
* @return the modified VMGroup
*/
@GET
@QueryParams(keys = "command", values = "updateInstanceGroup")
@SelectJson("instancegroup")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<VMGroup> updateInstanceGroup(@QueryParam("id") long id, UpdateVMGroupOptions... options);
/**
* Delete a VM group
*
* @param id the ID of the VM group
* @return a future with a void data type
*/
@GET
@QueryParams(keys = "command", values = "deleteInstanceGroup")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteInstanceGroup(@QueryParam("id") long id);
}

View File

@ -0,0 +1,79 @@
/**
* 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.cloudstack.features;
import org.jclouds.cloudstack.domain.VMGroup;
import org.jclouds.cloudstack.options.CreateVMGroupOptions;
import org.jclouds.cloudstack.options.ListVMGroupsOptions;
import org.jclouds.cloudstack.options.UpdateVMGroupOptions;
import org.jclouds.concurrent.Timeout;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to CloudStack VM group features.
* <p/>
*
* @author Richard Downer
* @see VMGroupAsyncClient
* @see <a href="http://download.cloud.com/releases/2.2.0/api/TOC_User.html" />
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface VMGroupClient {
/**
* Lists VM groups
*
* @param options if present, how to constrain the list.
* @return VM groups matching query, or empty set, if no groups are found
*/
Set<VMGroup> listInstanceGroups(ListVMGroupsOptions... options);
/**
* Retrieve a VM group by its id
*
* @param id the id of the required VM group.
* @return the VM group with the requested id, or null if not found
*/
VMGroup getInstanceGroup(long id);
/**
* Creates a VM group
*
* @param name the name of the VM group
* @param options optional parameters
* @return the new VMGroup
*/
VMGroup createInstanceGroup(String name, CreateVMGroupOptions... options);
/**
* Modify a VM group
*
* @param name the new name of the group
* @return the modified VMGroup
*/
VMGroup updateInstanceGroup(long id, UpdateVMGroupOptions... options);
/**
* Delete a VM group
*
* @param id the ID of the VM group
*/
void deleteInstanceGroup(long id);
}

View File

@ -0,0 +1,70 @@
/**
* 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.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Options used to control options for creating a VM group
*
* @author Richard Downer
* @see <a
* href="http://download.cloud.com/releases/2.2.8/api/user/createInstanceGroup.html"
* />
*/
public class CreateVMGroupOptions extends BaseHttpRequestOptions {
public static final CreateVMGroupOptions NONE = new CreateVMGroupOptions();
/**
* @param account account who owns the VMGroup
*/
public CreateVMGroupOptions account(String account) {
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
return this;
}
/**
* @param domainId domain ID of the account owning the VMGroup
*/
public CreateVMGroupOptions domainId(long domainId) {
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + ""));
return this;
}
public static class Builder {
/**
* @see org.jclouds.cloudstack.options.CreateVMGroupOptions#account
*/
public static CreateVMGroupOptions account(String account) {
CreateVMGroupOptions options = new CreateVMGroupOptions();
return options.account(account);
}
/**
* @see org.jclouds.cloudstack.options.CreateVMGroupOptions#domainId
*/
public static CreateVMGroupOptions domainId(long id) {
CreateVMGroupOptions options = new CreateVMGroupOptions();
return options.domainId(id);
}
}
}

View File

@ -0,0 +1,120 @@
/**
* 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.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.NetworkType;
import org.jclouds.cloudstack.domain.TrafficType;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Options used to control what VMGroups information is returned
*
* @author Richard Downer
* @see <a
* href="http://download.cloud.com/releases/2.2.8/api/user/listInstanceGroups.html"
* />
*/
public class ListVMGroupsOptions extends BaseHttpRequestOptions {
public static final ListVMGroupsOptions NONE = new ListVMGroupsOptions();
/**
* @param id list VMGroups by id
*/
public ListVMGroupsOptions id(long id) {
this.queryParameters.replaceValues("id", ImmutableSet.of(id + ""));
return this;
}
/**
* @param account account who owns the VMGroups
*/
public ListVMGroupsOptions account(String account) {
this.queryParameters.replaceValues("account", ImmutableSet.of(account));
return this;
}
/**
* @param domainId domain ID of the account owning the VMGroups
*/
public ListVMGroupsOptions domainId(long domainId) {
this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + ""));
return this;
}
/**
* @param keyword keyword to search on
*/
public ListVMGroupsOptions keyword(String keyword) {
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword));
return this;
}
/**
* @param name find a VMGroup by its name
*/
public ListVMGroupsOptions name(String name) {
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
return this;
}
public static class Builder {
/**
* @see org.jclouds.cloudstack.options.ListVMGroupsOptions#id
*/
public static ListVMGroupsOptions id(long id) {
ListVMGroupsOptions options = new ListVMGroupsOptions();
return options.id(id);
}
/**
* @see org.jclouds.cloudstack.options.ListVMGroupsOptions#account
*/
public static ListVMGroupsOptions account(String account) {
ListVMGroupsOptions options = new ListVMGroupsOptions();
return options.account(account);
}
/**
* @see org.jclouds.cloudstack.options.ListVMGroupsOptions#domainId
*/
public static ListVMGroupsOptions domainId(long id) {
ListVMGroupsOptions options = new ListVMGroupsOptions();
return options.domainId(id);
}
/**
* @see org.jclouds.cloudstack.options.ListVMGroupsOptions#keyword
*/
public static ListVMGroupsOptions keyword(String keyword) {
ListVMGroupsOptions options = new ListVMGroupsOptions();
return options.keyword(keyword);
}
/**
* @see org.jclouds.cloudstack.options.ListVMGroupsOptions#account
*/
public static ListVMGroupsOptions name(String name) {
ListVMGroupsOptions options = new ListVMGroupsOptions();
return options.name(name);
}
}
}

View File

@ -0,0 +1,54 @@
/**
* 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.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Options used to control updates to VMGroups
*
* @author Richard Downer
* @see <a
* href="http://download.cloud.com/releases/2.2.0/api/user/updateInstanceGroup.html"
* />
*/
public class UpdateVMGroupOptions extends BaseHttpRequestOptions {
public static final UpdateVMGroupOptions NONE = new UpdateVMGroupOptions();
/**
* @param name new name of the VMGroup
*/
public UpdateVMGroupOptions name(String name) {
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
return this;
}
public static class Builder {
/**
* @see org.jclouds.cloudstack.options.UpdateVMGroupOptions#name
*/
public static UpdateVMGroupOptions name(String name) {
UpdateVMGroupOptions options = new UpdateVMGroupOptions();
return options.name(name);
}
}
}

View File

@ -0,0 +1,177 @@
/**
* 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.cloudstack.features;
import com.google.common.base.Functions;
import com.google.inject.TypeLiteral;
import org.jclouds.cloudstack.options.CreateVMGroupOptions;
import org.jclouds.cloudstack.options.ListVMGroupsOptions;
import org.jclouds.cloudstack.options.UpdateVMGroupOptions;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import java.io.IOException;
import java.lang.reflect.Method;
/**
* Tests behavior of {@code VMGroupAsyncClient}
*
* @author Richard Downer
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "VMGroupAsyncClientTest")
public class VMGroupAsyncClientTest extends BaseCloudStackAsyncClientTest<VMGroupAsyncClient> {
public void testListVMGroups() throws SecurityException, NoSuchMethodException, IOException {
Method method = VMGroupAsyncClient.class.getMethod("listInstanceGroups", ListVMGroupsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listInstanceGroups HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testListVMGroupsOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VMGroupAsyncClient.class.getMethod("listInstanceGroups", ListVMGroupsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, ListVMGroupsOptions.Builder.account("fred")
.domainId(5).id(6));
assertRequestLineEquals(
httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listInstanceGroups&account=fred&domainid=5&id=6 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetVMGroup() throws SecurityException, NoSuchMethodException, IOException {
Method method = VMGroupAsyncClient.class.getMethod("getInstanceGroup", long.class);
HttpRequest httpRequest = processor.createRequest(method, 5);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listInstanceGroups&id=5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest,
Functions.compose(IdentityFunction.INSTANCE, IdentityFunction.INSTANCE).getClass());
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testCreateVMGroup() throws SecurityException, NoSuchMethodException, IOException {
Method method = VMGroupAsyncClient.class.getMethod("createInstanceGroup", String.class, CreateVMGroupOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, "goo");
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=createInstanceGroup&name=goo HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testCreateVMGroupOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VMGroupAsyncClient.class.getMethod("createInstanceGroup", String.class, CreateVMGroupOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, "goo", CreateVMGroupOptions.Builder.account("foo").domainId(42));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=createInstanceGroup&name=goo&account=foo&domainid=42 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testUpdateVMGroup() throws SecurityException, NoSuchMethodException, IOException {
Method method = VMGroupAsyncClient.class.getMethod("updateInstanceGroup", long.class, UpdateVMGroupOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 5, UpdateVMGroupOptions.Builder.name("fred"));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=updateInstanceGroup&id=5&name=fred HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testDeleteVMGroup() throws SecurityException, NoSuchMethodException, IOException {
Method method = VMGroupAsyncClient.class.getMethod("deleteInstanceGroup", long.class);
HttpRequest httpRequest = processor.createRequest(method, 5);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=deleteInstanceGroup&id=5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<VMGroupAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<VMGroupAsyncClient>>() {
};
}
}

View File

@ -0,0 +1,70 @@
/**
* 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.cloudstack.features;
import com.google.common.collect.Iterables;
import org.jclouds.cloudstack.domain.VMGroup;
import org.jclouds.cloudstack.options.ListVMGroupsOptions;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test;
import java.util.Random;
import java.util.Set;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code VMGroupClient}
*
* @author Richard Downer
*/
@Test(groups = "live", singleThreaded = true, testName = "VMGroupClientLiveTest")
public class VMGroupClientLiveTest extends BaseCloudStackClientLiveTest {
private VMGroup groupCreated;
public VMGroupClientLiveTest() {
prefix += "2";
}
@Test
public void testCreateListDestroyVMGroup() {
VMGroupClient vmGroupClient = client.getVMGroupClient();
String name = "jclouds-test-" + (Integer.toHexString(new Random().nextInt()));
groupCreated = vmGroupClient.createInstanceGroup(name);
assertEquals(groupCreated.getName(), name);
Set<VMGroup> search = vmGroupClient.listInstanceGroups(ListVMGroupsOptions.Builder.name(name));
assertEquals(1, search.size());
VMGroup groupFound = Iterables.getOnlyElement(search);
assertEquals(groupFound, groupCreated);
vmGroupClient.deleteInstanceGroup(groupCreated.getId());
groupCreated = null;
}
@AfterGroups(groups = "live")
protected void tearDown() {
if (groupCreated != null) {
client.getVMGroupClient().deleteInstanceGroup(groupCreated.getId());
}
super.tearDown();
}
}