From 4ce474e43cef86fbcac68fa8b30b6513cc44b8fc Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 13 Feb 2011 14:03:58 +0100 Subject: [PATCH] cloudstack: added virtualmachine and asyncjob features --- .../internal/RestAnnotationProcessorTest.java | 23 +- .../cloudstack/CloudStackAsyncClient.java | 16 +- .../jclouds/cloudstack/CloudStackClient.java | 14 + .../config/CloudStackRestClientModule.java | 16 +- .../domain/AsyncCreateResponse.java | 55 ++++ .../jclouds/cloudstack/domain/AsyncJob.java | 245 ++++++++++++++ .../cloudstack/domain/IngressRule.java | 192 +++++++++++ .../cloudstack/domain/SecurityGroup.java | 181 +++++++++++ .../cloudstack/domain/VirtualMachine.java | 31 +- .../features/AsyncJobAsyncClient.java | 61 ++++ .../cloudstack/features/AsyncJobClient.java | 47 +++ .../features/SecurityGroupAsyncClient.java | 91 ++++++ .../features/SecurityGroupClient.java | 73 +++++ .../features/VirtualMachineAsyncClient.java | 23 ++ .../features/VirtualMachineClient.java | 26 ++ .../options/DeployVirtualMachineOptions.java | 299 ++++++++++++++++++ .../options/ListAsyncJobsOptions.java | 102 ++++++ .../options/ListSecurityGroupsOptions.java | 126 ++++++++ .../options/ListTemplatesOptions.java | 4 +- .../options/ListVirtualMachinesOptions.java | 6 +- .../features/AsyncJobAsyncClientTest.java | 82 +++++ .../features/AsyncJobClientLiveTest.java | 64 ++++ .../BaseCloudStackClientLiveTest.java | 9 +- .../SecurityGroupAsyncClientTest.java | 140 ++++++++ .../features/SecurityGroupClientLiveTest.java | 80 +++++ .../features/TemplateAsyncClientTest.java | 9 +- .../VirtualMachineAsyncClientTest.java | 43 ++- .../VirtualMachineClientLiveTest.java | 102 ++++-- .../options/ListAsyncJobsOptionsTest.java | 72 +++++ .../ListSecurityGroupsOptionsTest.java | 90 ++++++ .../options/ListTemplatesOptionsTest.java | 8 +- .../options/ListVirtualMachesOptionsTest.java | 8 +- 32 files changed, 2257 insertions(+), 81 deletions(-) create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncCreateResponse.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJob.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AsyncJobAsyncClient.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AsyncJobClient.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupClient.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListAsyncJobsOptions.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListSecurityGroupsOptions.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobAsyncClientTest.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobClientLiveTest.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClientTest.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListAsyncJobsOptionsTest.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListSecurityGroupsOptionsTest.java diff --git a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java index 6f788c2de8..a6efd925a0 100755 --- a/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java +++ b/core/src/test/java/org/jclouds/rest/internal/RestAnnotationProcessorTest.java @@ -772,6 +772,12 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { @Consumes(MediaType.APPLICATION_JSON) ListenableFuture> testUnwrapDepth2(); + @GET + @Path("/") + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture testUnwrapDepth2Long(); + @GET @Path("/") @Unwrap(depth = 3, edgeCollection = Set.class) @@ -960,11 +966,26 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest { assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{\"runit\":[\"0.7.0\",\"0.7.1\"]}}"))), ImmutableSet.of("0.7.0", "0.7.1")); - + assertEquals(parser.apply(new HttpResponse(200, "ok", newStringPayload("{\"runit\":{}}"))), ImmutableSet. of()); } + @SuppressWarnings("unchecked") + public void testUnwrapDepth2Long() throws SecurityException, NoSuchMethodException, IOException { + Method method = TestPut.class.getMethod("testUnwrapDepth2Long"); + HttpRequest request = factory(TestPut.class).createRequest(method); + + assertResponseParserClassEquals(method, request, UnwrapOnlyNestedJsonValue.class); + // now test that it works! + + Function> parser = (Function>) RestAnnotationProcessor + .createResponseParser(parserFactory, injector, method, request); + + assertEquals(parser.apply(new HttpResponse(200, "ok", + newStringPayload("{ \"destroyvirtualmachineresponse\" : {\"jobid\":4} }"))), new Long(4)); + } + @SuppressWarnings("unchecked") public void testUnwrapDepth3() throws SecurityException, NoSuchMethodException, IOException { Method method = TestPut.class.getMethod("testUnwrapDepth3"); diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java index 39e25d6be9..58d9667b3a 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java @@ -19,8 +19,10 @@ package org.jclouds.cloudstack; +import org.jclouds.cloudstack.features.AsyncJobAsyncClient; import org.jclouds.cloudstack.features.NetworkAsyncClient; import org.jclouds.cloudstack.features.OfferingAsyncClient; +import org.jclouds.cloudstack.features.SecurityGroupAsyncClient; import org.jclouds.cloudstack.features.TemplateAsyncClient; import org.jclouds.cloudstack.features.VirtualMachineAsyncClient; import org.jclouds.cloudstack.features.ZoneAsyncClient; @@ -59,10 +61,22 @@ public interface CloudStackAsyncClient { */ @Delegate NetworkAsyncClient getNetworkClient(); - + /** * Provides asynchronous access to VirtualMachine features. */ @Delegate VirtualMachineAsyncClient getVirtualMachineClient(); + + /** + * Provides asynchronous access to SecurityGroup features. + */ + @Delegate + SecurityGroupAsyncClient getSecurityGroupClient(); + + /** + * Provides asynchronous access to AsyncJob features. + */ + @Delegate + AsyncJobAsyncClient getAsyncJobClient(); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java index f459d9f689..140241d4a9 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java @@ -21,8 +21,10 @@ package org.jclouds.cloudstack; import java.util.concurrent.TimeUnit; +import org.jclouds.cloudstack.features.AsyncJobClient; import org.jclouds.cloudstack.features.NetworkClient; import org.jclouds.cloudstack.features.OfferingClient; +import org.jclouds.cloudstack.features.SecurityGroupClient; import org.jclouds.cloudstack.features.TemplateClient; import org.jclouds.cloudstack.features.VirtualMachineClient; import org.jclouds.cloudstack.features.ZoneClient; @@ -68,4 +70,16 @@ public interface CloudStackClient { */ @Delegate VirtualMachineClient getVirtualMachineClient(); + + /** + * Provides synchronous access to SecurityGroup features. + */ + @Delegate + SecurityGroupClient getSecurityGroupClient(); + + /** + * Provides synchronous access to AsyncJob features. + */ + @Delegate + AsyncJobClient getAsyncJobClient(); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java index 734ec7fbae..1dfda6af99 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java @@ -23,10 +23,14 @@ import java.util.Map; import org.jclouds.cloudstack.CloudStackAsyncClient; import org.jclouds.cloudstack.CloudStackClient; +import org.jclouds.cloudstack.features.AsyncJobAsyncClient; +import org.jclouds.cloudstack.features.AsyncJobClient; import org.jclouds.cloudstack.features.NetworkAsyncClient; import org.jclouds.cloudstack.features.NetworkClient; import org.jclouds.cloudstack.features.OfferingAsyncClient; import org.jclouds.cloudstack.features.OfferingClient; +import org.jclouds.cloudstack.features.SecurityGroupAsyncClient; +import org.jclouds.cloudstack.features.SecurityGroupClient; import org.jclouds.cloudstack.features.TemplateAsyncClient; import org.jclouds.cloudstack.features.TemplateClient; import org.jclouds.cloudstack.features.VirtualMachineAsyncClient; @@ -56,12 +60,14 @@ import com.google.common.collect.ImmutableMap; public class CloudStackRestClientModule extends RestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder()// - .put(ZoneClient.class, ZoneAsyncClient.class)// - .put(TemplateClient.class, TemplateAsyncClient.class)// - .put(OfferingClient.class, OfferingAsyncClient.class)// - .put(NetworkClient.class, NetworkAsyncClient.class)// + .put(ZoneClient.class, ZoneAsyncClient.class)// + .put(TemplateClient.class, TemplateAsyncClient.class)// + .put(OfferingClient.class, OfferingAsyncClient.class)// + .put(NetworkClient.class, NetworkAsyncClient.class)// .put(VirtualMachineClient.class, VirtualMachineAsyncClient.class)// - .build(); + .put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)// + .put(AsyncJobClient.class, AsyncJobAsyncClient.class)// + .build(); public CloudStackRestClientModule() { super(CloudStackClient.class, CloudStackAsyncClient.class, DELEGATE_MAP); diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncCreateResponse.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncCreateResponse.java new file mode 100644 index 0000000000..b89b447204 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncCreateResponse.java @@ -0,0 +1,55 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.domain; + +import com.google.gson.annotations.SerializedName; + +/** + * + * @author Adrian Cole + */ +public class AsyncCreateResponse { + private long id; + @SerializedName("jobid") + private long jobId; + + /** + * present only for serializer + * + */ + AsyncCreateResponse() { + + } + + /** + * @return id of the resource being created + */ + public long getId() { + return id; + } + + /** + * @return id of the job in progress + */ + public long getJobId() { + return jobId; + } + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJob.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJob.java new file mode 100644 index 0000000000..94bd5de0c6 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/AsyncJob.java @@ -0,0 +1,245 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.domain; + +import java.util.Date; +import java.util.Map; + +import com.google.common.collect.ImmutableMap; +import com.google.gson.annotations.SerializedName; + +/** + * + * @author Adrian Cole + */ +public class AsyncJob { + @SerializedName("accountid") + private long accountId = -1; + private String cmd; + private Date created; + @SerializedName("jobid") + private long id = -1; + @SerializedName("jobinstanceid") + private long instanceId = -1; + @SerializedName("jobinstancetype") + private String instanceType; + @SerializedName("jobinstancetype") + private String progress; + @SerializedName("jobresult") + private Map result = ImmutableMap.of(); + @SerializedName("jobresultcode") + private int resultCode = -1; + @SerializedName("jobresulttype") + private String resultType; + @SerializedName("jobstatus") + private int status = -1; + @SerializedName("userid") + private int userId = -1; + + public AsyncJob(int accountId, String cmd, Date created, long id, long instanceId, String instanceType, + String progress, Map result, int resultCode, String resultType, int status, int userId) { + this.accountId = accountId; + this.cmd = cmd; + this.created = created; + this.id = id; + this.instanceId = instanceId; + this.instanceType = instanceType; + this.progress = progress; + this.result = result; + this.resultCode = resultCode; + this.resultType = resultType; + this.status = status; + this.userId = userId; + } + + /** + * present only for serializer + * + */ + AsyncJob() { + + } + + /** + * @return the account that executed the async command + */ + public long getAccountId() { + return accountId; + } + + /** + * @return the async command executed + */ + public String getCmd() { + return cmd; + } + + /** + * @return the created date of the job + */ + public Date getCreated() { + return created; + } + + /** + * @return async job ID + */ + public long getId() { + return id; + } + + /** + * @return the unique ID of the instance/entity object related to the job + */ + public long getInstanceId() { + return instanceId; + } + + /** + * @return the instance/entity object related to the job + */ + public String getInstanceType() { + return instanceType; + } + + /** + * @return the progress information of the PENDING job + */ + public String getProgress() { + return progress; + } + + /** + * @return the result reason + */ + public Map getResult() { + return result; + } + + /** + * @return the result code for the job + */ + public int getResultCode() { + return resultCode; + } + + /** + * @return the result type + */ + public String getResultType() { + return resultType; + } + + /** + * @return the current job status-should be 0 for PENDING + */ + public int getStatus() { + return status; + } + + /** + * @return the user that executed the async command + */ + public int getUserId() { + return userId; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (accountId ^ (accountId >>> 32)); + result = prime * result + ((cmd == null) ? 0 : cmd.hashCode()); + result = prime * result + ((created == null) ? 0 : created.hashCode()); + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + (int) (instanceId ^ (instanceId >>> 32)); + result = prime * result + ((instanceType == null) ? 0 : instanceType.hashCode()); + result = prime * result + ((progress == null) ? 0 : progress.hashCode()); + result = prime * result + ((this.result == null) ? 0 : this.result.hashCode()); + result = prime * result + resultCode; + result = prime * result + ((resultType == null) ? 0 : resultType.hashCode()); + result = prime * result + status; + result = prime * result + userId; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AsyncJob other = (AsyncJob) obj; + if (accountId != other.accountId) + return false; + if (cmd == null) { + if (other.cmd != null) + return false; + } else if (!cmd.equals(other.cmd)) + return false; + if (created == null) { + if (other.created != null) + return false; + } else if (!created.equals(other.created)) + return false; + if (id != other.id) + return false; + if (instanceId != other.instanceId) + return false; + if (instanceType == null) { + if (other.instanceType != null) + return false; + } else if (!instanceType.equals(other.instanceType)) + return false; + if (progress == null) { + if (other.progress != null) + return false; + } else if (!progress.equals(other.progress)) + return false; + if (result == null) { + if (other.result != null) + return false; + } else if (!result.equals(other.result)) + return false; + if (resultCode != other.resultCode) + return false; + if (resultType == null) { + if (other.resultType != null) + return false; + } else if (!resultType.equals(other.resultType)) + return false; + if (status != other.status) + return false; + if (userId != other.userId) + return false; + return true; + } + + @Override + public String toString() { + return "[accountId=" + accountId + ", cmd=" + cmd + ", created=" + created + ", id=" + id + ", instanceId=" + + instanceId + ", instanceType=" + instanceType + ", progress=" + progress + ", result=" + result + + ", resultCode=" + resultCode + ", resultType=" + resultType + ", status=" + status + ", userId=" + userId + + "]"; + } + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java new file mode 100644 index 0000000000..7782a3e931 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/IngressRule.java @@ -0,0 +1,192 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.domain; + +import com.google.gson.annotations.SerializedName; + +/** + * + * @author Adrian Cole + */ +public class IngressRule { + private String account; + @SerializedName("cidr") + private String CIDR; + @SerializedName("endport") + private int endPort; + @SerializedName("icmpcode") + private int ICMPCode; + @SerializedName("icmptype") + private int ICMPType; + private String protocol; + @SerializedName("ruleid") + private long id; + @SerializedName("securitygroupname") + private String securityGroupName; + @SerializedName("startport") + private int startPort; + + // for serialization + IngressRule() { + + } + + public IngressRule(String account, String cIDR, int endPort, int iCMPCode, int iCMPType, String protocol, long id, + String securityGroupName, int startPort) { + this.account = account; + this.CIDR = cIDR; + this.endPort = endPort; + this.ICMPCode = iCMPCode; + this.ICMPType = iCMPType; + this.protocol = protocol; + this.id = id; + this.securityGroupName = securityGroupName; + this.startPort = startPort; + } + + /** + * @return account owning the ingress rule + */ + public String getAccount() { + return account; + } + + /** + * @return the CIDR notation for the base IP address of the ingress rule + */ + public String getCIDR() { + return CIDR; + } + + /** + * @return the ending IP of the ingress rule + */ + public int getEndPort() { + return endPort; + } + + /** + * @return the code for the ICMP message response + */ + public int getICMPCode() { + return ICMPCode; + } + + /** + * @return the type of the ICMP message response + */ + public int getICMPType() { + return ICMPType; + } + + /** + * @return the protocol of the ingress rule + */ + public String getProtocol() { + return protocol; + } + + /** + * @return the id of the ingress rule + */ + public long getId() { + return id; + } + + /** + * @return security group name + */ + public String getSecurityGroupName() { + return securityGroupName; + } + + /** + * @return the starting IP of the ingress rule + */ + public int getStartPort() { + return startPort; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((CIDR == null) ? 0 : CIDR.hashCode()); + result = prime * result + ICMPCode; + result = prime * result + ICMPType; + result = prime * result + ((account == null) ? 0 : account.hashCode()); + result = prime * result + endPort; + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ((protocol == null) ? 0 : protocol.hashCode()); + result = prime * result + ((securityGroupName == null) ? 0 : securityGroupName.hashCode()); + result = prime * result + startPort; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + IngressRule other = (IngressRule) obj; + if (CIDR == null) { + if (other.CIDR != null) + return false; + } else if (!CIDR.equals(other.CIDR)) + return false; + if (ICMPCode != other.ICMPCode) + return false; + if (ICMPType != other.ICMPType) + return false; + if (account == null) { + if (other.account != null) + return false; + } else if (!account.equals(other.account)) + return false; + if (endPort != other.endPort) + return false; + if (id != other.id) + return false; + if (protocol == null) { + if (other.protocol != null) + return false; + } else if (!protocol.equals(other.protocol)) + return false; + if (securityGroupName == null) { + if (other.securityGroupName != null) + return false; + } else if (!securityGroupName.equals(other.securityGroupName)) + return false; + if (startPort != other.startPort) + return false; + return true; + } + + @Override + public String toString() { + return "[id=" + id + ", securityGroupName=" + securityGroupName + ", account=" + account + ", startPort=" + + startPort + ", endPort=" + endPort + ", protocol=" + protocol + ", CIDR=" + CIDR + ", ICMPCode=" + + ICMPCode + ", ICMPType=" + ICMPType + "]"; + } + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java new file mode 100644 index 0000000000..2883998d33 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/SecurityGroup.java @@ -0,0 +1,181 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import com.google.common.collect.ImmutableSet; +import com.google.gson.annotations.SerializedName; + +/** + * + * @author Adrian Cole + */ +public class SecurityGroup { + private long id; + private String account; + private String name; + private String description; + private String domain; + @SerializedName("domainid") + private long domainId; + @SerializedName("ingressrule") + private Set ingressRules = ImmutableSet.of(); + + public SecurityGroup(long id, String account, String name, String description, String domain, long domainId, + Set ingressRules) { + this.id = id; + this.account = account; + this.name = name; + this.description = description; + this.domain = domain; + this.domainId = domainId; + this.ingressRules = ImmutableSet.copyOf(checkNotNull(ingressRules, "ingressRules")); + } + + /** + * present only for serializer + * + */ + SecurityGroup() { + + } + + /** + * + * @return the id of the security group + */ + public long getId() { + return id; + } + + /** + * + * @return the name of the security group + */ + + public String getName() { + return name; + } + + /** + * + * @return an alternate display text of the security group. + */ + public String getDescription() { + return description; + } + + /** + * + * @return Domain name for the security group + */ + public String getDomain() { + return domain; + } + + /** + * + * @return the domain id of the security group + */ + public long getDomainId() { + return domainId; + } + + /** + * + * @return the account owning the security group + */ + public String getAccount() { + return account; + } + + /** + * + * @return the list of ingress rules associated with the security group + */ + public Set getIngressRules() { + return ingressRules; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((account == null) ? 0 : account.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((domain == null) ? 0 : domain.hashCode()); + result = prime * result + (int) (domainId ^ (domainId >>> 32)); + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ((ingressRules == null) ? 0 : ingressRules.hashCode()); + result = prime * result + ((name == null) ? 0 : name.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; + SecurityGroup other = (SecurityGroup) obj; + if (account == null) { + if (other.account != null) + return false; + } else if (!account.equals(other.account)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (domain == null) { + if (other.domain != null) + return false; + } else if (!domain.equals(other.domain)) + return false; + if (domainId != other.domainId) + return false; + if (id != other.id) + return false; + if (ingressRules == null) { + if (other.ingressRules != null) + return false; + } else if (!ingressRules.equals(other.ingressRules)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + return "[id=" + id + ", account=" + account + ", name=" + name + ", description=" + description + ", domain=" + + domain + ", domainId=" + domainId + ", ingressRules=" + ingressRules + "]"; + } + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java index 816f0725f6..a7ca285e32 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java @@ -27,8 +27,6 @@ import java.util.Set; import javax.annotation.Nullable; import com.google.common.base.CaseFormat; -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; import com.google.gson.annotations.SerializedName; @@ -108,8 +106,6 @@ public class VirtualMachine { private long rootDeviceId; @SerializedName("rootdevicetype") private String rootDeviceType; - @SerializedName("securitygrouplist") - private String securityGroupList; @SerializedName("serviceofferingid") private long serviceOfferingId; @SerializedName("serviceofferingname") @@ -126,17 +122,19 @@ public class VirtualMachine { @SerializedName("zonename") private String zoneName; @SerializedName("nic") - private Set nics = ImmutableSet. of(); + private Set nics = ImmutableSet. of(); private String hypervisor; + @SerializedName("securitygroup") + private Set securityGroups = ImmutableSet. of(); public VirtualMachine(long id, String account, long cpuCount, long cpuSpeed, long cpuUsed, String displayName, Date created, String domain, long domainId, boolean usesVirtualNetwork, String group, long groupId, long guestOSId, boolean hAEnabled, long hostId, String hostname, String iPAddress, String iSODisplayText, long iSOId, String iSOName, Long jobId, String jobStatus, long memory, String name, Long networkKbsRead, Long networkKbsWrite, String password, boolean passwordEnabled, long rootDeviceId, String rootDeviceType, - Set securityGroupList, long serviceOfferingId, String serviceOfferingName, State state, + Set securityGroups, long serviceOfferingId, String serviceOfferingName, State state, String templateDisplayText, long templateId, String templateName, long zoneId, String zoneName, - Set nics, String hypervisor) { + Set nics, String hypervisor) { this.id = id; this.account = account; this.cpuCount = cpuCount; @@ -167,7 +165,7 @@ public class VirtualMachine { this.passwordEnabled = passwordEnabled; this.rootDeviceId = rootDeviceId; this.rootDeviceType = rootDeviceType; - this.securityGroupList = Joiner.on(',').join(checkNotNull(securityGroupList, "securityGroupList")); + this.securityGroups =ImmutableSet.copyOf(checkNotNull(securityGroups, "securityGroups")); this.serviceOfferingId = serviceOfferingId; this.serviceOfferingName = serviceOfferingName; this.state = state; @@ -405,9 +403,8 @@ public class VirtualMachine { /** * @return list of security groups associated with the virtual machine */ - public Set getSecurityGroupList() { - return securityGroupList == null ? ImmutableSet. of() : ImmutableSet.copyOf(Splitter.on(',').split( - securityGroupList)); + public Set getSecurityGroups() { + return securityGroups; } /** @@ -470,7 +467,7 @@ public class VirtualMachine { /** * @return the list of nics associated with vm */ - public Set getNICs() { + public Set getNICs() { return nics; } @@ -516,7 +513,7 @@ public class VirtualMachine { result = prime * result + (passwordEnabled ? 1231 : 1237); result = prime * result + (int) (rootDeviceId ^ (rootDeviceId >>> 32)); result = prime * result + ((rootDeviceType == null) ? 0 : rootDeviceType.hashCode()); - result = prime * result + ((securityGroupList == null) ? 0 : securityGroupList.hashCode()); + result = prime * result + ((securityGroups == null) ? 0 : securityGroups.hashCode()); result = prime * result + (int) (serviceOfferingId ^ (serviceOfferingId >>> 32)); result = prime * result + ((serviceOfferingName == null) ? 0 : serviceOfferingName.hashCode()); result = prime * result + ((state == null) ? 0 : state.hashCode()); @@ -657,10 +654,10 @@ public class VirtualMachine { return false; } else if (!rootDeviceType.equals(other.rootDeviceType)) return false; - if (securityGroupList == null) { - if (other.securityGroupList != null) + if (securityGroups == null) { + if (other.securityGroups != null) return false; - } else if (!securityGroupList.equals(other.securityGroupList)) + } else if (!securityGroups.equals(other.securityGroups)) return false; if (serviceOfferingId != other.serviceOfferingId) return false; @@ -705,7 +702,7 @@ public class VirtualMachine { + ISOName + ", jobId=" + jobId + ", jobStatus=" + jobStatus + ", memory=" + memory + ", name=" + name + ", networkKbsRead=" + networkKbsRead + ", networkKbsWrite=" + networkKbsWrite + ", password=" + password + ", passwordEnabled=" + passwordEnabled + ", rootDeviceId=" + rootDeviceId + ", rootDeviceType=" - + rootDeviceType + ", securityGroupList=" + securityGroupList + ", serviceOfferingId=" + serviceOfferingId + + rootDeviceType + ", securityGroups=" + securityGroups + ", serviceOfferingId=" + serviceOfferingId + ", serviceOfferingName=" + serviceOfferingName + ", state=" + state + ", templateDisplayText=" + templateDisplayText + ", templateId=" + templateId + ", templateName=" + templateName + ", zoneId=" + zoneId + ", zoneName=" + zoneName + ", nics=" + nics + ", hypervisor=" + hypervisor + "]"; diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AsyncJobAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AsyncJobAsyncClient.java new file mode 100644 index 0000000000..c76b4812b2 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AsyncJobAsyncClient.java @@ -0,0 +1,61 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.features; + +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.core.MediaType; + +import org.jclouds.cloudstack.domain.AsyncJob; +import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.options.ListAsyncJobsOptions; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.Unwrap; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to cloudstack via their REST API. + *

+ * + * @see AsyncJobClient + * @see + * @author Adrian Cole + */ +@RequestFilters(QuerySigner.class) +@QueryParams(keys = "response", values = "json") +public interface AsyncJobAsyncClient { + + /** + * @see AsyncJobClient#listAsyncJobs + */ + @GET + @QueryParams(keys = "command", values = "listAsyncJobs") + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listAsyncJobs(ListAsyncJobsOptions... options); + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AsyncJobClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AsyncJobClient.java new file mode 100644 index 0000000000..415a6504ae --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/AsyncJobClient.java @@ -0,0 +1,47 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.features; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.cloudstack.domain.AsyncJob; +import org.jclouds.cloudstack.options.ListAsyncJobsOptions; +import org.jclouds.concurrent.Timeout; + +/** + * Provides synchronous access to CloudStack asyncJob features. + *

+ * + * @see AsyncJobAsyncClient + * @see + * @author Adrian Cole + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface AsyncJobClient { + /** + * Lists asyncJobs + * + * @param options + * if present, how to constrain the list. + * @return asyncJobs matching query, or empty set, if no asyncJobs are found + */ + Set listAsyncJobs(ListAsyncJobsOptions... options); +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java new file mode 100644 index 0000000000..8765558ba5 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClient.java @@ -0,0 +1,91 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.features; + +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.cloudstack.domain.SecurityGroup; +import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.options.ListSecurityGroupsOptions; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.Unwrap; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides asynchronous access to cloudstack via their REST API. + *

+ * + * @see OfferingClient + * @see + * @author Adrian Cole + */ +@RequestFilters(QuerySigner.class) +@QueryParams(keys = "response", values = "json") +public interface SecurityGroupAsyncClient { + + /** + * @see SecurityGroupClient#listSecurityGroups + */ + @GET + @QueryParams(keys = "command", values = "listSecurityGroups") + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listSecurityGroups(ListSecurityGroupsOptions... options); + + /** + * @see SecurityGroupClient#getSecurityGroup + */ + @GET + @QueryParams(keys = "command", values = "listSecurityGroups") + @Unwrap(depth = 3, edgeCollection = Set.class) + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getSecurityGroup(@QueryParam("id") long id); + + /** + * @see SecurityGroupClient#createSecurityGroup + */ + @GET + @QueryParams(keys = "command", values = "createSecurityGroup") + @Unwrap(depth = 3, edgeCollection = Set.class) + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture createSecurityGroup(@QueryParam("name") String name); + + /** + * @see SecurityGroupClient#deleteSecurityGroup + */ + @GET + @QueryParams(keys = "command", values = "deleteSecurityGroup") + @ExceptionParser(ReturnVoidOnNotFoundOr404.class) + ListenableFuture deleteSecurityGroup(@QueryParam("id") long id); + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupClient.java new file mode 100644 index 0000000000..3fe5a89490 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/SecurityGroupClient.java @@ -0,0 +1,73 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.features; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.jclouds.cloudstack.domain.SecurityGroup; +import org.jclouds.cloudstack.options.ListSecurityGroupsOptions; +import org.jclouds.concurrent.Timeout; + +/** + * Provides synchronous access to CloudStack security group features. + *

+ * + * @see SecurityGroupAsyncClient + * @see + * @author Adrian Cole + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface SecurityGroupClient { + /** + * Lists security groups + * + * @param options + * if present, how to constrain the list. + * @return security groups matching query, or empty set, if no security groups are found + */ + Set listSecurityGroups(ListSecurityGroupsOptions... options); + + /** + * get a specific security group by id + * + * @param id + * group to get + * @return security group or null if not found + */ + SecurityGroup getSecurityGroup(long id); + + /** + * Creates a security group + * + * @param name + * name of the security group + * @return security group + */ + SecurityGroup createSecurityGroup(String name); + + /** + * delete a specific security group by id + * + * @param id + * group to delete + */ + void deleteSecurityGroup(long id); +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java index f6f7d8adcf..ed89d325d0 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java @@ -26,8 +26,10 @@ import javax.ws.rs.GET; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.options.DeployVirtualMachineOptions; import org.jclouds.cloudstack.options.ListVirtualMachinesOptions; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.QueryParams; @@ -70,4 +72,25 @@ public interface VirtualMachineAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getVirtualMachine(@QueryParam("id") long id); + /** + * @see VirtualMachineClient#deployVirtualMachine + */ + @GET + @QueryParams(keys = "command", values = "deployVirtualMachine") + @Unwrap + @Consumes(MediaType.APPLICATION_JSON) + ListenableFuture deployVirtualMachine(@QueryParam("serviceofferingid") long serviceOfferingId, + @QueryParam("templateid") long templateId, @QueryParam("zoneid") long zoneId, + DeployVirtualMachineOptions... options); + + /** + * @see VirtualMachineClient#destroyVirtualMachine + */ + @GET + @QueryParams(keys = "command", values = "destroyVirtualMachine") + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture destroyVirtualMachine(@QueryParam("id") long id); + } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java index c0d5264ea6..17b6b61399 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java @@ -22,7 +22,9 @@ package org.jclouds.cloudstack.features; import java.util.Set; import java.util.concurrent.TimeUnit; +import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.VirtualMachine; +import org.jclouds.cloudstack.options.DeployVirtualMachineOptions; import org.jclouds.cloudstack.options.ListVirtualMachinesOptions; import org.jclouds.concurrent.Timeout; @@ -53,4 +55,28 @@ public interface VirtualMachineClient { * @return VirtualMachine or null if not found */ VirtualMachine getVirtualMachine(long id); + + /** + * Creates and automatically starts a virtual machine based on a service offering, disk offering, + * and template. + * + * @param serviceOfferingId + * the ID of the service offering for the virtual machine + * @param templateId + * the ID of the template for the virtual machine + * @param zoneId + * availability zone for the virtual machine + * @return virtual machine + */ + AsyncCreateResponse deployVirtualMachine(long serviceOfferingId, long templateId, long zoneId, + DeployVirtualMachineOptions... options); + + /** + * Destroys a virtual machine. Once destroyed, only the administrator can recover it. + * + * @param id + * vm to destroy + * @return job id related to destroying the VM, or null if resource was not found + */ + Long destroyVirtualMachine(long id); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java new file mode 100644 index 0000000000..4e12ce4c22 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/DeployVirtualMachineOptions.java @@ -0,0 +1,299 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.options; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.encryption.internal.Base64; +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; + +/** + * Options used to control what disk offerings are returned + * + * @see + * @author Adrian Cole + */ +public class DeployVirtualMachineOptions extends BaseHttpRequestOptions { + + public static final DeployVirtualMachineOptions NONE = new DeployVirtualMachineOptions(); + + /** + * + * @param account + * an optional account for the virtual machine + * @param domain + * domain id + */ + public DeployVirtualMachineOptions accountInDomain(String account, long domain) { + this.queryParameters.replaceValues("account", ImmutableSet.of(account + "")); + return domainId(domain); + } + + /** + * the ID of the disk offering for the virtual machine. If the template is of ISO format, the + * diskOfferingId is for the root disk volume. Otherwise this parameter is used to dinidcate the + * offering for the data disk volume. If the templateId parameter passed is from a Template + * object, the diskOfferingId refers to a DATA Disk Volume created. If the templateId parameter + * passed is from an ISO object, the diskOfferingId refers to a ROOT Disk Volume created. + * + * @param id + * the ID of the disk offering + */ + public DeployVirtualMachineOptions diskOfferingId(long diskofferingid) { + checkArgument(!queryParameters.containsKey("size"), "Mutually exclusive with size"); + this.queryParameters.replaceValues("diskofferingid", ImmutableSet.of(diskofferingid + "")); + return this; + } + + /** + * @param displayName + * an optional user generated name for the virtual machine + */ + public DeployVirtualMachineOptions displayName(String displayName) { + this.queryParameters.replaceValues("displayname", ImmutableSet.of(displayName)); + return this; + } + + /** + * @param domainId + * an optional domainId for the virtual machine + */ + public DeployVirtualMachineOptions domainId(long domainId) { + this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + "")); + return this; + } + + /** + * @param group + * an optional group for the virtual machine + */ + public DeployVirtualMachineOptions group(String group) { + this.queryParameters.replaceValues("group", ImmutableSet.of(group)); + return this; + } + + /** + * @param hypervisor + * the hypervisor on which to deploy the virtual machine + */ + public DeployVirtualMachineOptions hypervisor(String hypervisor) { + this.queryParameters.replaceValues("hypervisor", ImmutableSet.of(hypervisor)); + return this; + } + + /** + * @param keyPair + * name of the ssh key pair used to login to the virtual machine + */ + public DeployVirtualMachineOptions keyPair(String keyPair) { + this.queryParameters.replaceValues("keypair", ImmutableSet.of(keyPair)); + return this; + } + + /** + * @param name + * host name for the virtual machine + */ + public DeployVirtualMachineOptions name(String name) { + this.queryParameters.replaceValues("name", ImmutableSet.of(name)); + return this; + } + + /** + * @param networkId + * network id used by virtual machine + */ + public DeployVirtualMachineOptions networkId(long networkId) { + this.queryParameters.replaceValues("networkids", ImmutableSet.of(networkId + "")); + return this; + } + + /** + * @param networkIds + * network ids used by virtual machine + */ + public DeployVirtualMachineOptions networkIds(Iterable networkIds) { + this.queryParameters.replaceValues("networkids", ImmutableSet.of(Joiner.on(',').join(networkIds))); + return this; + } + + /** + * @param securityGroupId + * security group applied to the virtual machine. Should be passed only when vm is + * created from a zone with Basic Network support + */ + public DeployVirtualMachineOptions securityGroupId(long securityGroupId) { + this.queryParameters.replaceValues("securitygroupids", ImmutableSet.of(securityGroupId + "")); + return this; + } + + /** + * @param securityGroupIds + * security groups applied to the virtual machine. Should be passed only when vm is + * created from a zone with Basic Network support + */ + public DeployVirtualMachineOptions securityGroupIds(Iterable securityGroupIds) { + this.queryParameters.replaceValues("securitygroupids", ImmutableSet.of(Joiner.on(',').join(securityGroupIds))); + return this; + } + + /** + * @param dataDiskSize + * the arbitrary size for the DATADISK volume. Mutually exclusive with diskOfferingId + */ + public DeployVirtualMachineOptions dataDiskSize(long dataDiskSize) { + checkArgument(!queryParameters.containsKey("diskofferingid"), "Mutually exclusive with diskOfferingId"); + this.queryParameters.replaceValues("size", ImmutableSet.of(dataDiskSize + "")); + return this; + } + + /** + * @param unencodedData + * an optional binary data that can be sent to the virtual machine upon a successful + * deployment. This binary data must be base64 encoded before adding it to the request. + * Currently only HTTP GET is supported. Using HTTP GET (via querystring), you can send + * up to 2KB of data after base64 encoding. + */ + public DeployVirtualMachineOptions userData(byte[] unencodedData) { + int length = checkNotNull(unencodedData, "unencodedData").length; + checkArgument(length > 0, "userData cannot be empty"); + checkArgument(length <= 2 * 1024, "userData cannot be larger than 2kb"); + this.queryParameters.replaceValues("userdata", ImmutableSet.of(Base64.encodeBytes(unencodedData))); + return this; + } + + public static class Builder { + /** + * @see DeployVirtualMachineOptions#accountInDomain + */ + public static DeployVirtualMachineOptions accountInDomain(String account, long domain) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.accountInDomain(account, domain); + } + + /** + * @see DeployVirtualMachineOptions#diskOfferingId + */ + public static DeployVirtualMachineOptions diskOfferingId(long diskOfferingId) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.diskOfferingId(diskOfferingId); + } + + /** + * @see DeployVirtualMachineOptions#displayName + */ + public static DeployVirtualMachineOptions displayName(String displayName) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.displayName(displayName); + } + + /** + * @see DeployVirtualMachineOptions#domainId + */ + public static DeployVirtualMachineOptions domainId(long id) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.domainId(id); + } + + /** + * @see DeployVirtualMachineOptions#group + */ + public static DeployVirtualMachineOptions group(String group) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.group(group); + } + + /** + * @see DeployVirtualMachineOptions#hypervisor + */ + public static DeployVirtualMachineOptions hypervisor(String hypervisor) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.hypervisor(hypervisor); + } + + /** + * @see DeployVirtualMachineOptions#keyPair + */ + public static DeployVirtualMachineOptions keyPair(String keyPair) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.keyPair(keyPair); + } + + /** + * @see DeployVirtualMachineOptions#name + */ + public static DeployVirtualMachineOptions name(String name) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.name(name); + } + + /** + * @see DeployVirtualMachineOptions#networkId + */ + public static DeployVirtualMachineOptions networkId(long id) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.networkId(id); + } + + /** + * @see DeployVirtualMachineOptions#networkIds + */ + public static DeployVirtualMachineOptions networkIds(Iterable networkIds) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.networkIds(networkIds); + } + + /** + * @see DeployVirtualMachineOptions#securityGroupId + */ + public static DeployVirtualMachineOptions securityGroupId(long id) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.securityGroupId(id); + } + + /** + * @see DeployVirtualMachineOptions#securityGroupIds + */ + public static DeployVirtualMachineOptions securityGroupIds(Iterable securityGroupIds) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.securityGroupIds(securityGroupIds); + } + + /** + * @see DeployVirtualMachineOptions#dataDiskSize + */ + public static DeployVirtualMachineOptions dataDiskSize(long id) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.dataDiskSize(id); + } + + /** + * @see DeployVirtualMachineOptions#userData + */ + public static DeployVirtualMachineOptions userData(byte[] unencodedData) { + DeployVirtualMachineOptions options = new DeployVirtualMachineOptions(); + return options.userData(unencodedData); + } + } +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListAsyncJobsOptions.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListAsyncJobsOptions.java new file mode 100644 index 0000000000..2fb6237436 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListAsyncJobsOptions.java @@ -0,0 +1,102 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.options; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Date; + +import org.jclouds.date.DateService; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.collect.ImmutableSet; + +/** + * Options used to control what asyncJobs information is returned + * + * @see + * @author Adrian Cole + */ +public class ListAsyncJobsOptions extends BaseHttpRequestOptions { + private final static DateService dateService = new SimpleDateFormatDateService(); + + public static final ListAsyncJobsOptions NONE = new ListAsyncJobsOptions(); + + /** + * + * @param account + * an optional account for the virtual machine + * @param domain + * domain id + */ + public ListAsyncJobsOptions accountInDomain(String account, long domain) { + this.queryParameters.replaceValues("account", ImmutableSet.of(account + "")); + return domainId(domain); + } + + /** + * @param domainId + * the ID of the domain associated with the asyncJob + */ + public ListAsyncJobsOptions domainId(long domainId) { + this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + "")); + return this; + + } + + /** + * @param startDate + * the start date of the async job + */ + public ListAsyncJobsOptions startDate(Date startDate) { + this.queryParameters.replaceValues("startdate", + ImmutableSet.of(dateService.iso8601SecondsDateFormat(checkNotNull(startDate, "startDate")))); + return this; + } + + public static class Builder { + + /** + * @see ListAsyncJobsOptions#startDate + */ + public static ListAsyncJobsOptions startDate(Date startDate) { + ListAsyncJobsOptions options = new ListAsyncJobsOptions(); + return options.startDate(startDate); + } + + /** + * @see ListAsyncJobsOptions#domainId + */ + public static ListAsyncJobsOptions domainId(long id) { + ListAsyncJobsOptions options = new ListAsyncJobsOptions(); + return options.domainId(id); + } + + /** + * @see ListAsyncJobsOptions#accountInDomain + */ + public static ListAsyncJobsOptions accountInDomain(String account, long domain) { + ListAsyncJobsOptions options = new ListAsyncJobsOptions(); + return options.accountInDomain(account, domain); + } + + } +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListSecurityGroupsOptions.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListSecurityGroupsOptions.java new file mode 100644 index 0000000000..c51f90d191 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListSecurityGroupsOptions.java @@ -0,0 +1,126 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.options; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.collect.ImmutableSet; + +/** + * Options used to control what security groups are returned + * + * @see + * @author Adrian Cole + */ +public class ListSecurityGroupsOptions extends BaseHttpRequestOptions { + + public static final ListSecurityGroupsOptions NONE = new ListSecurityGroupsOptions(); + + /** + * @param id + * the ID of the security group + */ + public ListSecurityGroupsOptions id(long id) { + this.queryParameters.replaceValues("id", ImmutableSet.of(id + "")); + return this; + } + + /** + * @param domainId + * the ID of the domain associated with the security group + */ + public ListSecurityGroupsOptions domainId(long domainId) { + this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId + "")); + return this; + + } + + /** + * @param account + * the security group account + */ + public ListSecurityGroupsOptions account(String account) { + this.queryParameters.replaceValues("account", ImmutableSet.of(account)); + return this; + } + + /** + * @param securityGroupName + * lists security groups by name + */ + public ListSecurityGroupsOptions securityGroupName(String securityGroupName) { + this.queryParameters.replaceValues("securitygroupname", ImmutableSet.of(securityGroupName)); + return this; + } + + /** + * @param virtualMachineId + * the ID of the virtual machine. Pass this in if you want to see the available service + * offering that a virtual machine can be changed to. + */ + public ListSecurityGroupsOptions virtualMachineId(long virtualMachineId) { + this.queryParameters.replaceValues("virtualmachineid", ImmutableSet.of(virtualMachineId + "")); + return this; + + } + + public static class Builder { + + /** + * @see ListSecurityGroupsOptions#account + */ + public static ListSecurityGroupsOptions account(String account) { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions(); + return options.account(account); + } + + /** + * @see ListSecurityGroupsOptions#securityGroupName + */ + public static ListSecurityGroupsOptions securityGroupName(String securityGroupName) { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions(); + return options.securityGroupName(securityGroupName); + } + + /** + * @see ListSecurityGroupsOptions#domainId + */ + public static ListSecurityGroupsOptions domainId(long id) { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions(); + return options.domainId(id); + } + + /** + * @see ListSecurityGroupsOptions#id + */ + public static ListSecurityGroupsOptions id(long id) { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions(); + return options.id(id); + } + + /** + * @see ListSecurityGroupsOptions#virtualMachineId + */ + public static ListSecurityGroupsOptions virtualMachineId(long virtualMachineId) { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions(); + return options.virtualMachineId(virtualMachineId); + } + } +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListTemplatesOptions.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListTemplatesOptions.java index ca3217c1f1..4c2d49c158 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListTemplatesOptions.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListTemplatesOptions.java @@ -62,7 +62,7 @@ public class ListTemplatesOptions extends BaseHttpRequestOptions { * @param domain * domain id */ - public ListTemplatesOptions accountInDomain(long account, long domain) { + public ListTemplatesOptions accountInDomain(String account, long domain) { this.queryParameters.replaceValues("account", ImmutableSet.of(account + "")); return domainId(domain); } @@ -127,7 +127,7 @@ public class ListTemplatesOptions extends BaseHttpRequestOptions { /** * @see ListTemplatesOptions#accountInDomain */ - public static ListTemplatesOptions accountInDomain(long account, long domain) { + public static ListTemplatesOptions accountInDomain(String account, long domain) { ListTemplatesOptions options = new ListTemplatesOptions(); return options.accountInDomain(account, domain); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListVirtualMachinesOptions.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListVirtualMachinesOptions.java index f2dde8febb..9e24a9590e 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListVirtualMachinesOptions.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListVirtualMachinesOptions.java @@ -77,8 +77,8 @@ public class ListVirtualMachinesOptions extends BaseHttpRequestOptions { * @param domain * domain id */ - public ListVirtualMachinesOptions accountInDomain(long account, long domain) { - this.queryParameters.replaceValues("account", ImmutableSet.of(account + "")); + public ListVirtualMachinesOptions accountInDomain(String account, long domain) { + this.queryParameters.replaceValues("account", ImmutableSet.of(account)); return domainId(domain); } @@ -147,7 +147,7 @@ public class ListVirtualMachinesOptions extends BaseHttpRequestOptions { /** * @see ListVirtualMachinesOptions#accountInDomain */ - public static ListVirtualMachinesOptions accountInDomain(long account, long domain) { + public static ListVirtualMachinesOptions accountInDomain(String account, long domain) { ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); return options.accountInDomain(account, domain); } diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobAsyncClientTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobAsyncClientTest.java new file mode 100644 index 0000000000..287e70e42e --- /dev/null +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobAsyncClientTest.java @@ -0,0 +1,82 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.features; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.cloudstack.options.ListAsyncJobsOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; +import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code AsyncJobAsyncClient} + * + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "AsyncJobAsyncClientTest") +public class AsyncJobAsyncClientTest extends BaseCloudStackAsyncClientTest { + public void testListAsyncJobs() throws SecurityException, NoSuchMethodException, IOException { + Method method = AsyncJobAsyncClient.class.getMethod("listAsyncJobs", ListAsyncJobsOptions[].class); + HttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listAsyncJobs HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testListAsyncJobsOptions() throws SecurityException, NoSuchMethodException, IOException { + Method method = AsyncJobAsyncClient.class.getMethod("listAsyncJobs", ListAsyncJobsOptions[].class); + HttpRequest httpRequest = processor.createRequest(method, + ListAsyncJobsOptions.Builder.accountInDomain("adrian", 5)); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listAsyncJobs&account=adrian&domainid=5 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } +} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobClientLiveTest.java new file mode 100644 index 0000000000..c28514ce8e --- /dev/null +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/AsyncJobClientLiveTest.java @@ -0,0 +1,64 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.features; + +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.AsyncJob; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code AsyncJobClientLiveTest} + * + * @author Adrian Cole + */ +@Test(groups = "live", sequential = true, testName = "AsyncJobClientLiveTest") +public class AsyncJobClientLiveTest extends BaseCloudStackClientLiveTest { + + public void testListAsyncJobs() throws Exception { + Set response = client.getAsyncJobClient().listAsyncJobs(); + assert null != response; + long asyncJobCount = response.size(); + assertTrue(asyncJobCount >= 0); + for (AsyncJob asyncJob : response) { + assert asyncJob.getId() > 0 : asyncJob; + assert asyncJob.getAccountId() >= 0 : asyncJob; + assert asyncJob.getCmd() != null : asyncJob; + assert asyncJob.getCreated() != null : asyncJob; + // seemingly unused fields + assert asyncJob.getInstanceId() == -1 : asyncJob; + assert asyncJob.getInstanceType() == null : asyncJob; + assert asyncJob.getResultType() == null : asyncJob; + // end + if (asyncJob.getProgress() != null) { + assert asyncJob.getResult() == null : asyncJob; + assert asyncJob.getResultCode() == -1 : asyncJob; + } else { + assert asyncJob.getResult() != null : asyncJob; + assert asyncJob.getResultCode() >= 0 : asyncJob; + } + assert asyncJob.getStatus() >= 0 : asyncJob; + assert asyncJob.getUserId() >= 0 : asyncJob; + } + } + +} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java index 3e67ad7799..b6fe91afb6 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java @@ -45,6 +45,7 @@ import com.google.inject.Module; * @author Adrian Cole */ public class BaseCloudStackClientLiveTest { + protected String prefix = System.getProperty("user.name"); protected CloudStackClient client; protected RestContext context; @@ -57,11 +58,11 @@ public class BaseCloudStackClientLiveTest { protected void setupCredentials() { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider - + ".identity must be set. ex. apiKey"); + + ".identity must be set. ex. apiKey"); credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider - + ".credential must be set. ex. secretKey"); + + ".credential must be set. ex. secretKey"); endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider - + ".endpoint must be set. ex. http://localhost:8080/client/api"); + + ".endpoint must be set. ex. http://localhost:8080/client/api"); apiversion = System.getProperty("test." + provider + ".apiversion"); } @@ -82,7 +83,7 @@ public class BaseCloudStackClientLiveTest { setupCredentials(); Properties overrides = setupProperties(); context = new RestContextFactory().createContext(provider, ImmutableSet. of(new Log4JLoggingModule()), - overrides); + overrides); client = context.getApi(); socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS); diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClientTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClientTest.java new file mode 100644 index 0000000000..704630c59b --- /dev/null +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupAsyncClientTest.java @@ -0,0 +1,140 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.features; + +import java.io.IOException; +import java.lang.reflect.Method; + +import org.jclouds.cloudstack.options.ListSecurityGroupsOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; +import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet; +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 com.google.inject.TypeLiteral; + +/** + * Tests behavior of {@code SecurityGroupAsyncClient} + * + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "SecurityGroupAsyncClientTest") +public class SecurityGroupAsyncClientTest extends BaseCloudStackAsyncClientTest { + + public void testListSecurityGroups() throws SecurityException, NoSuchMethodException, IOException { + Method method = SecurityGroupAsyncClient.class.getMethod("listSecurityGroups", ListSecurityGroupsOptions[].class); + HttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listSecurityGroups HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testListSecurityGroupsOptions() throws SecurityException, NoSuchMethodException, IOException { + Method method = SecurityGroupAsyncClient.class.getMethod("listSecurityGroups", ListSecurityGroupsOptions[].class); + HttpRequest httpRequest = processor.createRequest(method, ListSecurityGroupsOptions.Builder.virtualMachineId(4) + .domainId(5).id(6)); + + assertRequestLineEquals( + httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listSecurityGroups&virtualmachineid=4&domainid=5&id=6 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testGetSecurityGroup() throws SecurityException, NoSuchMethodException, IOException { + Method method = SecurityGroupAsyncClient.class.getMethod("getSecurityGroup", long.class); + HttpRequest httpRequest = processor.createRequest(method, 5); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=listSecurityGroups&id=5 HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + public void testCreateSecurityGroup() throws SecurityException, NoSuchMethodException, IOException { + Method method = SecurityGroupAsyncClient.class.getMethod("createSecurityGroup", String.class); + HttpRequest httpRequest = processor.createRequest(method, "goo"); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=createSecurityGroup&name=goo HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertPayloadEquals(httpRequest, null, null, false); + + assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(httpRequest); + + } + + public void testDeleteSecurityGroup() throws SecurityException, NoSuchMethodException, IOException { + Method method = SecurityGroupAsyncClient.class.getMethod("deleteSecurityGroup", long.class); + HttpRequest httpRequest = processor.createRequest(method, 5); + + assertRequestLineEquals(httpRequest, + "GET http://localhost:8080/client/api?response=json&command=deleteSecurityGroup&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> createTypeLiteral() { + return new TypeLiteral>() { + }; + } +} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java new file mode 100644 index 0000000000..53dcec7de1 --- /dev/null +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java @@ -0,0 +1,80 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import org.jclouds.cloudstack.domain.SecurityGroup; +import org.jclouds.cloudstack.options.ListSecurityGroupsOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; + +/** + * Tests behavior of {@code SecurityGroupClient} + * + * @author Adrian Cole + */ +@Test(groups = "live", sequential = true, testName = "SecurityGroupClientLiveTest") +public class SecurityGroupClientLiveTest extends BaseCloudStackClientLiveTest { + + public void testCreateDestroySecurityGroup() throws Exception { + SecurityGroup group = null; + try { + group = client.getSecurityGroupClient().createSecurityGroup(prefix); + assertEquals(group.getName(), prefix); + checkGroup(group); + } finally { + if (group != null) { + client.getSecurityGroupClient().deleteSecurityGroup(group.getId()); + assertEquals(client.getSecurityGroupClient().getSecurityGroup(group.getId()), null); + } + } + + } + + public void testListSecurityGroups() throws Exception { + Set response = client.getSecurityGroupClient().listSecurityGroups(); + assert null != response; + long groupCount = response.size(); + assertTrue(groupCount >= 0); + for (SecurityGroup group : response) { + SecurityGroup newDetails = Iterables.getOnlyElement(client.getSecurityGroupClient().listSecurityGroups( + ListSecurityGroupsOptions.Builder.id(group.getId()))); + assertEquals(group, newDetails); + checkGroup(group); + } + } + + protected void checkGroup(SecurityGroup group) { + assertEquals(group, client.getSecurityGroupClient().getSecurityGroup(group.getId())); + assert group.getId() > 0 : group; + assert group.getName() != null : group; + assert group.getAccount() != null : group; + assert group.getDescription() != null : group; + assert group.getDomain() != null : group; + assert group.getDomainId() >= 0 : group; + assert group.getIngressRules() != null : group; + } + +} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateAsyncClientTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateAsyncClientTest.java index 9823bcb1da..336c856c5c 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateAsyncClientTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateAsyncClientTest.java @@ -61,12 +61,15 @@ public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest> createTypeLiteral() { return new TypeLiteral>() { diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java index 69f4857995..b8bfa22c75 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java @@ -24,8 +24,10 @@ import static org.testng.Assert.assertTrue; import java.util.Set; +import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.NIC; import org.jclouds.cloudstack.domain.VirtualMachine; +import org.jclouds.cloudstack.options.DeployVirtualMachineOptions; import org.jclouds.cloudstack.options.ListVirtualMachinesOptions; import org.testng.annotations.Test; @@ -38,6 +40,31 @@ import com.google.common.collect.Iterables; */ @Test(groups = "live", sequential = true, testName = "VirtualMachineClientLiveTest") public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest { + public void testCreateDestroyVirtualMachine() throws Exception { + VirtualMachine vm = null; + try { + long serviceOfferingId = Iterables.get(client.getOfferingClient().listServiceOfferings(), 0).getId(); + long templateId = Iterables.get(client.getTemplateClient().listTemplates(), 0).getId(); + long zoneId = Iterables.get(client.getZoneClient().listZones(), 0).getId(); + long networkId = Iterables.get(client.getNetworkClient().listNetworks(), 0).getId(); + System.out.printf("serviceOfferingId %d, templateId %d, zoneId %d, networkId %d%n", serviceOfferingId, templateId, zoneId, networkId); + AsyncCreateResponse job = client.getVirtualMachineClient().deployVirtualMachine(serviceOfferingId, templateId, zoneId, DeployVirtualMachineOptions.Builder.networkId(networkId)); + System.out.println("job: " + job); + vm = client.getVirtualMachineClient().getVirtualMachine(job.getId()); + System.out.println("vm: " + vm); + assertEquals(vm.getServiceOfferingId(), serviceOfferingId); + assertEquals(vm.getTemplateId(), templateId); + assertEquals(vm.getZoneId(), zoneId); + checkVm(vm); + } finally { + if (vm != null) { + Long job = client.getVirtualMachineClient().destroyVirtualMachine(vm.getId()); + assert job != null; + assertEquals(client.getVirtualMachineClient().getVirtualMachine(vm.getId()), null); + } + } + + } public void testListVirtualMachines() throws Exception { Set response = client.getVirtualMachineClient().listVirtualMachines(); @@ -48,41 +75,46 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest { VirtualMachine newDetails = Iterables.getOnlyElement(client.getVirtualMachineClient().listVirtualMachines( ListVirtualMachinesOptions.Builder.id(vm.getId()))); assertEquals(vm, newDetails); - assertEquals(vm, client.getVirtualMachineClient().getVirtualMachine(vm.getId())); - assert vm.getId() > 0 : vm; - assert vm.getName() != null : vm; - assert vm.getDisplayName() != null : vm; - assert vm.getAccount() != null : vm; - assert vm.getDomain() != null : vm; - assert vm.getDomainId() > 0 : vm; - assert vm.getCreated() != null : vm; - assert vm.getState() != null : vm; - assert vm.getZoneId() > 0 : vm; - assert vm.getZoneName() != null : vm; - assert vm.getTemplateId() > 0 : vm; - assert vm.getTemplateName() != null : vm; - assert vm.getTemplateDisplayText() != null : vm; - assert vm.getServiceOfferingId() > 0 : vm; - assert vm.getServiceOfferingName() != null : vm; - assert vm.getCpuCount() > 0 : vm; - assert vm.getCpuSpeed() > 0 : vm; - assert vm.getMemory() > 0 : vm; - assert vm.getGuestOSId() > 0 : vm; - assert vm.getRootDeviceId() >= 0 : vm; - assert vm.getRootDeviceType() != null : vm; - if (vm.getJobId() != null) - assert vm.getJobStatus() != null : vm; - assert vm.getNICs() != null && vm.getNICs().size() > 0 : vm; - for (NIC nic : vm.getNICs()) { - assert nic.getId() > 0 : vm; - assert nic.getNetworkId() > 0 : vm; - assert nic.getNetmask() != null : vm; - assert nic.getGateway() != null : vm; - assert nic.getIPAddress() != null : vm; - assert nic.getTrafficType() != null : vm; - assert nic.getGuestIPType() != null : vm; - } - assert vm.getHypervisor() != null : vm; + checkVm(vm); } } + + protected void checkVm(VirtualMachine vm) { + assertEquals(vm, client.getVirtualMachineClient().getVirtualMachine(vm.getId())); + assert vm.getId() > 0 : vm; + assert vm.getName() != null : vm; + assert vm.getDisplayName() != null : vm; + assert vm.getAccount() != null : vm; + assert vm.getDomain() != null : vm; + assert vm.getDomainId() > 0 : vm; + assert vm.getCreated() != null : vm; + assert vm.getState() != null : vm; + assert vm.getZoneId() > 0 : vm; + assert vm.getZoneName() != null : vm; + assert vm.getTemplateId() > 0 : vm; + assert vm.getTemplateName() != null : vm; + assert vm.getTemplateDisplayText() != null : vm; + assert vm.getServiceOfferingId() > 0 : vm; + assert vm.getServiceOfferingName() != null : vm; + assert vm.getCpuCount() > 0 : vm; + assert vm.getCpuSpeed() > 0 : vm; + assert vm.getMemory() > 0 : vm; + assert vm.getGuestOSId() > 0 : vm; + assert vm.getRootDeviceId() >= 0 : vm; + assert vm.getRootDeviceType() != null : vm; + if (vm.getJobId() != null) + assert vm.getJobStatus() != null : vm; + assert vm.getNICs() != null && vm.getNICs().size() > 0 : vm; + for (NIC nic : vm.getNICs()) { + assert nic.getId() > 0 : vm; + assert nic.getNetworkId() > 0 : vm; + assert nic.getNetmask() != null : vm; + assert nic.getGateway() != null : vm; + assert nic.getIPAddress() != null : vm; + assert nic.getTrafficType() != null : vm; + assert nic.getGuestIPType() != null : vm; + } + assert vm.getSecurityGroups() != null && vm.getSecurityGroups().size() >= 0 : vm; + assert vm.getHypervisor() != null : vm; + } } diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListAsyncJobsOptionsTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListAsyncJobsOptionsTest.java new file mode 100644 index 0000000000..bd409ace7a --- /dev/null +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListAsyncJobsOptionsTest.java @@ -0,0 +1,72 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.options; + +import static org.jclouds.cloudstack.options.ListAsyncJobsOptions.Builder.accountInDomain; +import static org.jclouds.cloudstack.options.ListAsyncJobsOptions.Builder.domainId; +import static org.jclouds.cloudstack.options.ListAsyncJobsOptions.Builder.startDate; +import static org.testng.Assert.assertEquals; + +import java.util.Date; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +/** + * Tests behavior of {@code ListAsyncJobsOptions} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class ListAsyncJobsOptionsTest { + public void testAccountInDomainId() { + ListAsyncJobsOptions options = new ListAsyncJobsOptions().accountInDomain("adrian", 6); + assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account")); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); + } + + public void testAccountInDomainIdStatic() { + ListAsyncJobsOptions options = accountInDomain("adrian", 6); + assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account")); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); + } + + public void testStartDate() { + ListAsyncJobsOptions options = new ListAsyncJobsOptions().startDate(new Date(100000)); + assertEquals(ImmutableList.of("1970-01-01T00:01:40Z"), options.buildQueryParameters().get("startdate")); + } + + public void testDomainId() { + ListAsyncJobsOptions options = new ListAsyncJobsOptions().domainId(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); + } + + + public void testStartDateStatic() { + ListAsyncJobsOptions options = startDate(new Date(100000)); + assertEquals(ImmutableList.of("1970-01-01T00:01:40Z"), options.buildQueryParameters().get("startdate")); + } + + public void testDomainIdStatic() { + ListAsyncJobsOptions options = domainId(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); + } +} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListSecurityGroupsOptionsTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListSecurityGroupsOptionsTest.java new file mode 100644 index 0000000000..5e7407f1a2 --- /dev/null +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListSecurityGroupsOptionsTest.java @@ -0,0 +1,90 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.cloudstack.options; + +import static org.jclouds.cloudstack.options.ListSecurityGroupsOptions.Builder.account; +import static org.jclouds.cloudstack.options.ListSecurityGroupsOptions.Builder.domainId; +import static org.jclouds.cloudstack.options.ListSecurityGroupsOptions.Builder.id; +import static org.jclouds.cloudstack.options.ListSecurityGroupsOptions.Builder.securityGroupName; +import static org.jclouds.cloudstack.options.ListSecurityGroupsOptions.Builder.virtualMachineId; +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +/** + * Tests behavior of {@code ListSecurityGroupsOptions} + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class ListSecurityGroupsOptionsTest { + + public void testId() { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions().id(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id")); + } + + public void testIdStatic() { + ListSecurityGroupsOptions options = id(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id")); + } + + public void testAccount() { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions().account("account"); + assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account")); + } + + public void testAccountStatic() { + ListSecurityGroupsOptions options = account("account"); + assertEquals(ImmutableList.of("account"), options.buildQueryParameters().get("account")); + } + + public void testName() { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions().securityGroupName("securityGroupName"); + assertEquals(ImmutableList.of("securityGroupName"), options.buildQueryParameters().get("securitygroupname")); + } + + public void testNameStatic() { + ListSecurityGroupsOptions options = securityGroupName("securityGroupName"); + assertEquals(ImmutableList.of("securityGroupName"), options.buildQueryParameters().get("securitygroupname")); + } + + public void testDomainId() { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions().domainId(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); + } + + public void testDomainIdStatic() { + ListSecurityGroupsOptions options = domainId(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); + } + + public void testVirtualMachineId() { + ListSecurityGroupsOptions options = new ListSecurityGroupsOptions().virtualMachineId(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("virtualmachineid")); + } + + public void testVirtualMachineIdStatic() { + ListSecurityGroupsOptions options = virtualMachineId(6); + assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("virtualmachineid")); + } +} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListTemplatesOptionsTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListTemplatesOptionsTest.java index dd159aa67a..00694cb911 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListTemplatesOptionsTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListTemplatesOptionsTest.java @@ -61,14 +61,14 @@ public class ListTemplatesOptionsTest { } public void testAccountInDomainId() { - ListTemplatesOptions options = new ListTemplatesOptions().accountInDomain(5, 6); - assertEquals(ImmutableList.of("5"), options.buildQueryParameters().get("account")); + ListTemplatesOptions options = new ListTemplatesOptions().accountInDomain("adrian", 6); + assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account")); assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); } public void testAccountInDomainIdStatic() { - ListTemplatesOptions options = accountInDomain(5, 6); - assertEquals(ImmutableList.of("5"), options.buildQueryParameters().get("account")); + ListTemplatesOptions options = accountInDomain("adrian", 6); + assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account")); assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); } diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListVirtualMachesOptionsTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListVirtualMachesOptionsTest.java index fd89c151f9..9f5142eb09 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListVirtualMachesOptionsTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListVirtualMachesOptionsTest.java @@ -84,14 +84,14 @@ public class ListVirtualMachesOptionsTest { } public void testAccountInDomainId() { - ListVirtualMachinesOptions options = new ListVirtualMachinesOptions().accountInDomain(5, 6); - assertEquals(ImmutableList.of("5"), options.buildQueryParameters().get("account")); + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions().accountInDomain("adrian", 6); + assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account")); assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); } public void testAccountInDomainIdStatic() { - ListVirtualMachinesOptions options = accountInDomain(5, 6); - assertEquals(ImmutableList.of("5"), options.buildQueryParameters().get("account")); + ListVirtualMachinesOptions options = accountInDomain("adrian", 6); + assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account")); assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid")); }