Skip to content

Commit 50b2c26

Browse files
Alena ProkharchykAlena Prokharchyk
authored andcommitted
Fixed XML api writer
Reviewed-by: Alena
1 parent 2f69ec3 commit 50b2c26

1 file changed

Lines changed: 60 additions & 18 deletions

File tree

server/src/com/cloud/api/doc/ApiXmlDocWriter.java

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,19 @@
4747
import com.cloud.api.BaseCmd;
4848
import com.cloud.api.Implementation;
4949
import com.cloud.api.Parameter;
50+
import com.cloud.api.response.AsyncJobResponse;
5051
import com.cloud.api.response.BaseResponse;
52+
import com.cloud.api.response.HostResponse;
53+
import com.cloud.api.response.IPAddressResponse;
54+
import com.cloud.api.response.LoadBalancerResponse;
55+
import com.cloud.api.response.SecurityGroupResponse;
56+
import com.cloud.api.response.SnapshotResponse;
57+
import com.cloud.api.response.StoragePoolResponse;
58+
import com.cloud.api.response.TemplateResponse;
59+
import com.cloud.api.response.UserVmResponse;
60+
import com.cloud.api.response.VolumeResponse;
5161
import com.cloud.serializer.Param;
62+
import com.cloud.server.api.response.ExternalLoadBalancerResponse;
5263
import com.google.gson.annotations.SerializedName;
5364
import com.thoughtworks.xstream.XStream;
5465

@@ -64,6 +75,23 @@ public class ApiXmlDocWriter {
6475
private static TreeMap<Object, String> domain_admin_api_commands_sorted = new TreeMap<Object, String>();
6576
private static TreeMap<Object, String> regular_user_api_commands_sorted = new TreeMap<Object, String>();
6677
private static String dirName = "";
78+
private static final List<String> _asyncResponses = setAsyncResponses();
79+
80+
private static List<String> setAsyncResponses() {
81+
List<String> asyncResponses = new ArrayList<String>();
82+
asyncResponses.add(TemplateResponse.class.getName());
83+
asyncResponses.add(VolumeResponse.class.getName());
84+
//asyncResponses.add(LoadBalancerResponse.class.getName());
85+
asyncResponses.add(HostResponse.class.getName());
86+
asyncResponses.add(IPAddressResponse.class.getName());
87+
asyncResponses.add(StoragePoolResponse.class.getName());
88+
asyncResponses.add(UserVmResponse.class.getName());
89+
asyncResponses.add(SecurityGroupResponse.class.getName());
90+
//asyncResponses.add(ExternalLoadBalancerResponse.class.getName());
91+
asyncResponses.add(SnapshotResponse.class.getName());
92+
93+
return asyncResponses;
94+
}
6795

6896
public static void main(String[] args) {
6997
LinkedProperties preProcessedCommands = new LinkedProperties();
@@ -312,30 +340,33 @@ private static void writeCommand(ObjectOutputStream out, String command) throws
312340

313341
// Get fields from superclass
314342
Class<?> superClass = clas.getSuperclass();
315-
String superName = superClass.getName();
316-
if (!superName.equals(BaseCmd.class.getName()) && !superName.equals(BaseAsyncCmd.class.getName()) && !superName.equals(BaseAsyncCreateCmd.class.getName())) {
317-
Field[] superClassFields = superClass.getDeclaredFields();
318-
if (superClassFields != null) {
319-
Field[] tmpFields = new Field[fields.length + superClassFields.length];
320-
System.arraycopy(fields, 0, tmpFields, 0, fields.length);
321-
System.arraycopy(superClassFields, 0, tmpFields, fields.length, superClassFields.length);
322-
fields = tmpFields;
343+
boolean isAsync = false;
344+
while (superClass != null && superClass != Object.class) {
345+
String superName = superClass.getName();
346+
if (!superName.equals(BaseCmd.class.getName()) && !superName.equals(BaseAsyncCmd.class.getName()) && !superName.equals(BaseAsyncCreateCmd.class.getName())) {
347+
Field[] superClassFields = superClass.getDeclaredFields();
348+
if (superClassFields != null) {
349+
Field[] tmpFields = new Field[fields.length + superClassFields.length];
350+
System.arraycopy(fields, 0, tmpFields, 0, fields.length);
351+
System.arraycopy(superClassFields, 0, tmpFields, fields.length, superClassFields.length);
352+
fields = tmpFields;
353+
}
323354
}
324355
superClass = superClass.getSuperclass();
356+
// Set Async information for the command
357+
if (superName.equals(BaseAsyncCmd.class.getName()) || superName.equals(BaseAsyncCreateCmd.class.getName())) {
358+
isAsync = true;
359+
}
325360
}
361+
362+
apiCommand.setAsync(isAsync);
363+
326364
request = setRequestFields(fields);
327365

328-
// Set Async information for the command
329-
if (superName.equals(BaseAsyncCmd.class.getName()) || superName.equals(BaseAsyncCreateCmd.class.getName())) {
330-
apiCommand.setAsync(true);
331-
} else {
332-
apiCommand.setAsync(false);
333-
}
334-
335366
// Get response parameters
336367
Class<?> responseClas = impl.responseObject();
337368
Field[] responseFields = responseClas.getDeclaredFields();
338-
response = setResponseFields(responseFields);
369+
response = setResponseFields(responseFields, responseClas);
339370

340371
apiCommand.setRequest(request);
341372
apiCommand.setResponse(response);
@@ -447,7 +478,7 @@ private static ArrayList<Argument> setRequestFields(Field[] fields) {
447478
return arguments;
448479
}
449480

450-
private static ArrayList<Argument> setResponseFields(Field[] responseFields) {
481+
private static ArrayList<Argument> setResponseFields(Field[] responseFields, Class<?> responseClas) {
451482
ArrayList<Argument> arguments = new ArrayList<Argument>();
452483
ArrayList<Argument> sortedChildlessArguments = new ArrayList<Argument>();
453484
ArrayList<Argument> sortedArguments = new ArrayList<Argument>();
@@ -475,7 +506,7 @@ private static ArrayList<Argument> setResponseFields(Field[] responseFields) {
475506
if (superName.equals(BaseResponse.class.getName())) {
476507
ArrayList<Argument> fieldArguments = new ArrayList<Argument>();
477508
Field[] fields = fieldClass.getDeclaredFields();
478-
fieldArguments = setResponseFields(fields);
509+
fieldArguments = setResponseFields(fields, fieldClass);
479510
respArg.setArguments(fieldArguments);
480511
hasChildren = true;
481512
}
@@ -506,6 +537,17 @@ private static ArrayList<Argument> setResponseFields(Field[] responseFields) {
506537
}
507538
arguments.addAll(sortedChildlessArguments);
508539
arguments.addAll(sortedArguments);
540+
541+
if (responseClas.getName().equalsIgnoreCase(AsyncJobResponse.class.getName())) {
542+
Argument jobIdArg = new Argument("jobid", "the ID of the async job");
543+
arguments.add(jobIdArg);
544+
} else if (_asyncResponses.contains(responseClas.getName())) {
545+
Argument jobIdArg = new Argument("jobid", "the ID of the latest async job acting on this object");
546+
Argument jobStatusArg = new Argument("jobstatus", "the current status of the latest async job acting on this object");
547+
arguments.add(jobIdArg);
548+
arguments.add(jobStatusArg);
549+
}
550+
509551
return arguments;
510552
}
511553

0 commit comments

Comments
 (0)