Cloudstack deleteTemplate call returns an asynchronous job response, not void.

This commit is contained in:
Richard Downer 2011-11-30 16:22:55 +02:00
parent 13f1a68b67
commit 1b0b154dfc
7 changed files with 130 additions and 10 deletions

View File

@ -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 OperationResult implements Comparable<OperationResult> {
private boolean success;
@SerializedName("displaytext")
private String displayText;
/**
* present only for the serializer
*/
OperationResult() {
}
public OperationResult(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;
OperationResult that = (OperationResult) 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(OperationResult other) {
int comparison = Boolean.valueOf(success).compareTo(other.success);
if (comparison == 0)
comparison = displayText.compareTo(other.displayText);
return comparison;
}
}

View File

@ -116,8 +116,9 @@ public interface TemplateAsyncClient {
*/ */
@GET @GET
@QueryParams(keys = "command", values = "deleteTemplate") @QueryParams(keys = "command", values = "deleteTemplate")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class) @Unwrap
ListenableFuture<Void> deleteTemplate(@QueryParam("id") long id, DeleteTemplateOptions... options); @Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<AsyncCreateResponse> deleteTemplate(@QueryParam("id") long id, DeleteTemplateOptions... options);
/** /**
* @see TemplateClient#listTemplates * @see TemplateClient#listTemplates

View File

@ -130,7 +130,7 @@ public interface TemplateClient {
* @param options * @param options
* optional arguments * optional arguments
*/ */
void deleteTemplate(long id, DeleteTemplateOptions... options); AsyncCreateResponse deleteTemplate(long id, DeleteTemplateOptions... options);
/** /**
* List all executable templates. * List all executable templates.

View File

@ -170,12 +170,12 @@ public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest<Templ
HttpRequest httpRequest = processor.createRequest(method, 17); HttpRequest httpRequest = processor.createRequest(method, 17);
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=deleteTemplate&id=17 HTTP/1.1"); 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); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest); checkFilters(httpRequest);
} }
@ -185,12 +185,12 @@ public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest<Templ
HttpRequest httpRequest = processor.createRequest(method, 17, DeleteTemplateOptions.Builder.zoneId(8)); 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"); 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); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest); checkFilters(httpRequest);
} }

View File

@ -186,7 +186,8 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
assert virtualMachineDestroyed.apply(vm); assert virtualMachineDestroyed.apply(vm);
} }
if (template != null) { if (template != null) {
client.getTemplateClient().deleteTemplate(template.getId()); AsyncCreateResponse deleteJob = client.getTemplateClient().deleteTemplate(template.getId());
assertTrue(jobComplete.apply(deleteJob.getJobId()));
} }
super.tearDown(); super.tearDown();
} }

View File

@ -0,0 +1,44 @@
/**
* 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.OperationResult;
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 OperationResultResponseTest extends BaseItemParserTest<OperationResult> {
@Override
public String resource() {
return "/deletetemplateresponse.json";
}
@Override
@SelectJson("jobresult")
public OperationResult expected() {
return new OperationResult(true, null);
}
}

View File

@ -0,0 +1 @@
{ "jobresult":{"success":true} }