mirror of https://github.com/apache/jclouds.git
cloudstack: asyncjob
This commit is contained in:
parent
4ce474e43c
commit
5df062ba47
|
@ -40,8 +40,8 @@ public class AsyncJob {
|
||||||
private long instanceId = -1;
|
private long instanceId = -1;
|
||||||
@SerializedName("jobinstancetype")
|
@SerializedName("jobinstancetype")
|
||||||
private String instanceType;
|
private String instanceType;
|
||||||
@SerializedName("jobinstancetype")
|
@SerializedName("jobprocstatus")
|
||||||
private String progress;
|
private int progress = -1;
|
||||||
@SerializedName("jobresult")
|
@SerializedName("jobresult")
|
||||||
private Map<String, Object> result = ImmutableMap.of();
|
private Map<String, Object> result = ImmutableMap.of();
|
||||||
@SerializedName("jobresultcode")
|
@SerializedName("jobresultcode")
|
||||||
|
@ -54,7 +54,7 @@ public class AsyncJob {
|
||||||
private int userId = -1;
|
private int userId = -1;
|
||||||
|
|
||||||
public AsyncJob(int accountId, String cmd, Date created, long id, long instanceId, String instanceType,
|
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.accountId = accountId;
|
||||||
this.cmd = cmd;
|
this.cmd = cmd;
|
||||||
this.created = created;
|
this.created = created;
|
||||||
|
@ -122,7 +122,7 @@ public class AsyncJob {
|
||||||
/**
|
/**
|
||||||
* @return the progress information of the PENDING job
|
* @return the progress information of the PENDING job
|
||||||
*/
|
*/
|
||||||
public String getProgress() {
|
public int getProgress() {
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ public class AsyncJob {
|
||||||
result = prime * result + (int) (id ^ (id >>> 32));
|
result = prime * result + (int) (id ^ (id >>> 32));
|
||||||
result = prime * result + (int) (instanceId ^ (instanceId >>> 32));
|
result = prime * result + (int) (instanceId ^ (instanceId >>> 32));
|
||||||
result = prime * result + ((instanceType == null) ? 0 : instanceType.hashCode());
|
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 + ((this.result == null) ? 0 : this.result.hashCode());
|
||||||
result = prime * result + resultCode;
|
result = prime * result + resultCode;
|
||||||
result = prime * result + ((resultType == null) ? 0 : resultType.hashCode());
|
result = prime * result + ((resultType == null) ? 0 : resultType.hashCode());
|
||||||
|
@ -210,10 +210,7 @@ public class AsyncJob {
|
||||||
return false;
|
return false;
|
||||||
} else if (!instanceType.equals(other.instanceType))
|
} else if (!instanceType.equals(other.instanceType))
|
||||||
return false;
|
return false;
|
||||||
if (progress == null) {
|
if (progress != other.progress)
|
||||||
if (other.progress != null)
|
|
||||||
return false;
|
|
||||||
} else if (!progress.equals(other.progress))
|
|
||||||
return false;
|
return false;
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
if (other.result != null)
|
if (other.result != null)
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.cloudstack.domain.AsyncJob;
|
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.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.Unwrap;
|
import org.jclouds.rest.annotations.Unwrap;
|
||||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||||
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
@ -57,5 +59,15 @@ public interface AsyncJobAsyncClient {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||||
ListenableFuture<Set<AsyncJob>> listAsyncJobs(ListAsyncJobsOptions... options);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,4 +44,13 @@ public interface AsyncJobClient {
|
||||||
* @return asyncJobs matching query, or empty set, if no asyncJobs are found
|
* @return asyncJobs matching query, or empty set, if no asyncJobs are found
|
||||||
*/
|
*/
|
||||||
Set<AsyncJob> listAsyncJobs(ListAsyncJobsOptions... options);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.jclouds.cloudstack.features;
|
package org.jclouds.cloudstack.features;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -40,6 +41,14 @@ public class AsyncJobClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
long asyncJobCount = response.size();
|
long asyncJobCount = response.size();
|
||||||
assertTrue(asyncJobCount >= 0);
|
assertTrue(asyncJobCount >= 0);
|
||||||
for (AsyncJob asyncJob : response) {
|
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.getId() > 0 : asyncJob;
|
||||||
assert asyncJob.getAccountId() >= 0 : asyncJob;
|
assert asyncJob.getAccountId() >= 0 : asyncJob;
|
||||||
assert asyncJob.getCmd() != null : asyncJob;
|
assert asyncJob.getCmd() != null : asyncJob;
|
||||||
|
@ -49,7 +58,7 @@ public class AsyncJobClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
assert asyncJob.getInstanceType() == null : asyncJob;
|
assert asyncJob.getInstanceType() == null : asyncJob;
|
||||||
assert asyncJob.getResultType() == null : asyncJob;
|
assert asyncJob.getResultType() == null : asyncJob;
|
||||||
// end
|
// end
|
||||||
if (asyncJob.getProgress() != null) {
|
if (asyncJob.getProgress() > 0) {
|
||||||
assert asyncJob.getResult() == null : asyncJob;
|
assert asyncJob.getResult() == null : asyncJob;
|
||||||
assert asyncJob.getResultCode() == -1 : asyncJob;
|
assert asyncJob.getResultCode() == -1 : asyncJob;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -43,10 +43,10 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
public void testCreateDestroyVirtualMachine() throws Exception {
|
public void testCreateDestroyVirtualMachine() throws Exception {
|
||||||
VirtualMachine vm = null;
|
VirtualMachine vm = null;
|
||||||
try {
|
try {
|
||||||
long serviceOfferingId = Iterables.get(client.getOfferingClient().listServiceOfferings(), 0).getId();
|
long serviceOfferingId = 1;//Iterables.get(client.getOfferingClient().listServiceOfferings(), 0).getId();
|
||||||
long templateId = Iterables.get(client.getTemplateClient().listTemplates(), 0).getId();
|
long templateId = 2;//Iterables.get(client.getTemplateClient().listTemplates(), 0).getId();
|
||||||
long zoneId = Iterables.get(client.getZoneClient().listZones(), 0).getId();
|
long zoneId = 1;//Iterables.get(client.getZoneClient().listZones(), 0).getId();
|
||||||
long networkId = Iterables.get(client.getNetworkClient().listNetworks(), 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);
|
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));
|
AsyncCreateResponse job = client.getVirtualMachineClient().deployVirtualMachine(serviceOfferingId, templateId, zoneId, DeployVirtualMachineOptions.Builder.networkId(networkId));
|
||||||
System.out.println("job: " + job);
|
System.out.println("job: " + job);
|
||||||
|
|
Loading…
Reference in New Issue