cloudstack: asyncjob

This commit is contained in:
Adrian Cole 2011-02-13 16:31:35 +01:00
parent 4ce474e43c
commit 5df062ba47
5 changed files with 41 additions and 14 deletions

View File

@ -40,8 +40,8 @@ public class AsyncJob {
private long instanceId = -1;
@SerializedName("jobinstancetype")
private String instanceType;
@SerializedName("jobinstancetype")
private String progress;
@SerializedName("jobprocstatus")
private int progress = -1;
@SerializedName("jobresult")
private Map<String, Object> result = ImmutableMap.of();
@SerializedName("jobresultcode")
@ -54,7 +54,7 @@ public class AsyncJob {
private int userId = -1;
public AsyncJob(int accountId, String cmd, Date created, long id, long instanceId, String instanceType,
String progress, Map<String, Object> result, int resultCode, String resultType, int status, int userId) {
int progress, Map<String, Object> result, int resultCode, String resultType, int status, int userId) {
this.accountId = accountId;
this.cmd = cmd;
this.created = created;
@ -122,7 +122,7 @@ public class AsyncJob {
/**
* @return the progress information of the PENDING job
*/
public String getProgress() {
public int getProgress() {
return progress;
}
@ -171,7 +171,7 @@ public class AsyncJob {
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 + progress;
result = prime * result + ((this.result == null) ? 0 : this.result.hashCode());
result = prime * result + resultCode;
result = prime * result + ((resultType == null) ? 0 : resultType.hashCode());
@ -210,10 +210,7 @@ public class AsyncJob {
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))
if (progress != other.progress)
return false;
if (result == null) {
if (other.result != null)

View File

@ -23,6 +23,7 @@ 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.AsyncJob;
@ -33,6 +34,7 @@ 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 com.google.common.util.concurrent.ListenableFuture;
@ -58,4 +60,14 @@ public interface AsyncJobAsyncClient {
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<AsyncJob>> listAsyncJobs(ListAsyncJobsOptions... options);
/**
* @see AsyncJobClient#getAsyncJob
*/
@GET
@QueryParams(keys = "command", values = "queryAsyncJobResult")
@Unwrap
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<AsyncJob> getAsyncJob(@QueryParam("jobid") long id);
}

View File

@ -44,4 +44,13 @@ public interface AsyncJobClient {
* @return asyncJobs matching query, or empty set, if no asyncJobs are found
*/
Set<AsyncJob> listAsyncJobs(ListAsyncJobsOptions... options);
/**
* get a specific asyncJob by id
*
* @param id
* asyncJob to get
* @return asyncJob or null if not found
*/
AsyncJob getAsyncJob(long id);
}

View File

@ -19,6 +19,7 @@
package org.jclouds.cloudstack.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.util.Set;
@ -40,6 +41,14 @@ public class AsyncJobClientLiveTest extends BaseCloudStackClientLiveTest {
long asyncJobCount = response.size();
assertTrue(asyncJobCount >= 0);
for (AsyncJob asyncJob : response) {
AsyncJob query = client.getAsyncJobClient().getAsyncJob(asyncJob.getId());
assertEquals(query.getId(), asyncJob.getId());
assert query.getStatus() >= 0 : query;
assert query.getResultCode() >= 0 : query;
assert query.getResultType() != null : query;
assert query.getProgress() >= 0 : query;
assert query.getResult() != null : query;
assert asyncJob.getId() > 0 : asyncJob;
assert asyncJob.getAccountId() >= 0 : asyncJob;
assert asyncJob.getCmd() != null : asyncJob;
@ -49,7 +58,7 @@ public class AsyncJobClientLiveTest extends BaseCloudStackClientLiveTest {
assert asyncJob.getInstanceType() == null : asyncJob;
assert asyncJob.getResultType() == null : asyncJob;
// end
if (asyncJob.getProgress() != null) {
if (asyncJob.getProgress() > 0) {
assert asyncJob.getResult() == null : asyncJob;
assert asyncJob.getResultCode() == -1 : asyncJob;
} else {

View File

@ -43,10 +43,10 @@ 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();
long serviceOfferingId = 1;//Iterables.get(client.getOfferingClient().listServiceOfferings(), 0).getId();
long templateId = 2;//Iterables.get(client.getTemplateClient().listTemplates(), 0).getId();
long zoneId = 1;//Iterables.get(client.getZoneClient().listZones(), 0).getId();
long networkId = 204;//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);