mirror of https://github.com/apache/jclouds.git
Merge pull request #196 from richardcloudsoft/cloudstack-deletetemplate
Cloudstack deleteTemplate call returns an asynchronous job response, not void
This commit is contained in:
commit
2d3b652eb3
|
@ -0,0 +1,73 @@
|
|||
package org.jclouds.cloudstack.domain;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* The result of an operation.
|
||||
*
|
||||
* A handful of Cloudstack API calls return this structure when there is no domain model data to return - for example,
|
||||
* when deleting an object.
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
public class JobResult implements Comparable<JobResult> {
|
||||
|
||||
private boolean success;
|
||||
@SerializedName("displaytext")
|
||||
private String displayText;
|
||||
|
||||
/**
|
||||
* present only for the serializer
|
||||
*/
|
||||
JobResult() {
|
||||
}
|
||||
|
||||
public JobResult(boolean success, String displayText) {
|
||||
this.success = success;
|
||||
this.displayText = displayText;
|
||||
}
|
||||
|
||||
public boolean getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public String getDisplayText() {
|
||||
return displayText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
JobResult that = (JobResult) o;
|
||||
|
||||
if (success != that.success) return false;
|
||||
if (displayText != null ? !displayText.equals(that.displayText) : that.displayText != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (success ? 1 : 0);
|
||||
result = 31 * result + (displayText != null ? displayText.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" +
|
||||
"success=" + success +
|
||||
", displayText=" + (displayText != null ? '\'' + displayText + '\'' : "null") +
|
||||
']';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(JobResult other) {
|
||||
int comparison = Boolean.valueOf(success).compareTo(other.success);
|
||||
if (comparison == 0)
|
||||
comparison = displayText.compareTo(other.displayText);
|
||||
return comparison;
|
||||
}
|
||||
}
|
|
@ -116,8 +116,9 @@ public interface TemplateAsyncClient {
|
|||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "deleteTemplate")
|
||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> deleteTemplate(@QueryParam("id") long id, DeleteTemplateOptions... options);
|
||||
@Unwrap
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
ListenableFuture<AsyncCreateResponse> deleteTemplate(@QueryParam("id") long id, DeleteTemplateOptions... options);
|
||||
|
||||
/**
|
||||
* @see TemplateClient#listTemplates
|
||||
|
|
|
@ -130,7 +130,7 @@ public interface TemplateClient {
|
|||
* @param options
|
||||
* optional arguments
|
||||
*/
|
||||
void deleteTemplate(long id, DeleteTemplateOptions... options);
|
||||
AsyncCreateResponse deleteTemplate(long id, DeleteTemplateOptions... options);
|
||||
|
||||
/**
|
||||
* List all executable templates.
|
||||
|
|
|
@ -170,12 +170,12 @@ public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest<Templ
|
|||
HttpRequest httpRequest = processor.createRequest(method, 17);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=deleteTemplate&id=17 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
@ -185,12 +185,12 @@ public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest<Templ
|
|||
HttpRequest httpRequest = processor.createRequest(method, 17, DeleteTemplateOptions.Builder.zoneId(8));
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=deleteTemplate&id=17&zoneid=8 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
}
|
||||
|
|
|
@ -186,7 +186,8 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
assert virtualMachineDestroyed.apply(vm);
|
||||
}
|
||||
if (template != null) {
|
||||
client.getTemplateClient().deleteTemplate(template.getId());
|
||||
AsyncCreateResponse deleteJob = client.getTemplateClient().deleteTemplate(template.getId());
|
||||
assertTrue(jobComplete.apply(deleteJob.getJobId()));
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.cloudstack.parse;
|
||||
|
||||
import org.jclouds.cloudstack.domain.AsyncJob;
|
||||
import org.jclouds.cloudstack.domain.JobResult;
|
||||
import org.jclouds.json.BaseItemParserTest;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Richard Downer
|
||||
*/
|
||||
@Test(groups = "unit", testName = "DeleteNetworkResponseTest")
|
||||
public class JobResultResponseTest extends BaseItemParserTest<JobResult> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/deletetemplateresponse.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("jobresult")
|
||||
public JobResult expected() {
|
||||
return new JobResult(true, null);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{ "queryasyncjobresultresponse" : {"jobid":118,"jobstatus":1,"jobprocstatus":0,"jobresultcode":0,"jobresulttype":"object","jobresult":{"success":true}} }
|
Loading…
Reference in New Issue