Skip to content

Commit 8de3bac

Browse files
committed
bug 9026: added ability to turn off apiCommand/commandParameter for docGeneration
status 9026: resolved fixed 1) Don't expose following commands in doc: * registerSSHKeyPair * createSSHKeyPair * deleteSSHKeyPair * listSSHKeyPairs 2) Don't show "sshKeyPairName" parameter for deployVm command
1 parent b3d6130 commit 8de3bac

9 files changed

Lines changed: 54 additions & 46 deletions

File tree

‎api/src/com/cloud/api/Implementation.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
public @interface Implementation {
1212
Class<?> responseObject();
1313
String description() default "";
14+
boolean includeInApiDoc() default true;
1415
}

‎api/src/com/cloud/api/Parameter.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
CommandType type() default CommandType.OBJECT;
3636
CommandType collectionType() default CommandType.OBJECT;
3737
boolean expose() default true;
38+
boolean includeInApiDoc() default true;
3839
}
3940

‎api/src/com/cloud/api/commands/CreateSSHKeyPairCmd.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.cloud.user.SSHKeyPair;
1212
import com.cloud.user.UserContext;
1313

14-
@Implementation(description="Create a new keypair and returns the private key", responseObject=SSHKeyPairResponse.class)
14+
@Implementation(description="Create a new keypair and returns the private key", responseObject=SSHKeyPairResponse.class, includeInApiDoc=false)
1515
public class CreateSSHKeyPairCmd extends BaseCmd {
1616
public static final Logger s_logger = Logger.getLogger(CreateSSHKeyPairCmd.class.getName());
1717
private static final String s_name = "createkeypairresponse";

‎api/src/com/cloud/api/commands/DeleteSSHKeyPairCmd.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.cloud.user.Account;
1111
import com.cloud.user.UserContext;
1212

13-
@Implementation(description="Deletes a keypair by name", responseObject=SuccessResponse.class)
13+
@Implementation(description="Deletes a keypair by name", responseObject=SuccessResponse.class, includeInApiDoc=false)
1414
public class DeleteSSHKeyPairCmd extends BaseCmd {
1515
public static final Logger s_logger = Logger.getLogger(CreateSSHKeyPairCmd.class.getName());
1616
private static final String s_name = "deletekeypairresponse";

‎api/src/com/cloud/api/commands/DeployVMCmd.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
100100
@Parameter(name=ApiConstants.USER_DATA, type=CommandType.STRING, description="an optional binary data that can be sent to the virtual machine upon a successful deployment. This binary data must be base64 encoded before adding it to the request. Currently only HTTP GET is supported. Using HTTP GET (via querystring), you can send up to 2KB of data after base64 encoding.")
101101
private String userData;
102102

103-
@Parameter(name=ApiConstants.SSH_KEYPAIR, type=CommandType.STRING, description="name of the ssh key pair used to login to the virtual machine")
103+
@Parameter(name=ApiConstants.SSH_KEYPAIR, type=CommandType.STRING, description="name of the ssh key pair used to login to the virtual machine", includeInApiDoc=false)
104104
private String sshKeyPairName;
105105

106106
/////////////////////////////////////////////////////

‎api/src/com/cloud/api/commands/GetVMPasswordCmd.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import com.cloud.user.Account;
1313
import com.cloud.uservm.UserVm;
1414

15-
@Implementation(responseObject=GetVMPasswordResponse.class, description="Returns an encrypted password for the VM")
15+
@Implementation(responseObject=GetVMPasswordResponse.class, description="Returns an encrypted password for the VM", includeInApiDoc=false)
1616
public class GetVMPasswordCmd extends BaseCmd {
1717
public static final Logger s_logger = Logger.getLogger(GetVMPasswordCmd.class.getName());
1818
private static final String s_name = "getvmpasswordresponse";

‎api/src/com/cloud/api/commands/ListSSHKeyPairsCmd.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.cloud.api.response.SSHKeyPairResponse;
1414
import com.cloud.user.SSHKeyPair;
1515

16-
@Implementation(description="List registered keypairs", responseObject=SSHKeyPairResponse.class)
16+
@Implementation(description="List registered keypairs", responseObject=SSHKeyPairResponse.class, includeInApiDoc=false)
1717
public class ListSSHKeyPairsCmd extends BaseListCmd {
1818
public static final Logger s_logger = Logger.getLogger(ListSSHKeyPairsCmd.class.getName());
1919
private static final String s_name = "listsshkeypairsresponse";

‎api/src/com/cloud/api/commands/RegisterSSHKeyPairCmd.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.cloud.user.SSHKeyPair;
1212
import com.cloud.user.UserContext;
1313

14-
@Implementation(description="Register a public key in a keypair under a certain name", responseObject=SSHKeyPairResponse.class)
14+
@Implementation(description="Register a public key in a keypair under a certain name", responseObject=SSHKeyPairResponse.class, includeInApiDoc=false)
1515
public class RegisterSSHKeyPairCmd extends BaseCmd {
1616
public static final Logger s_logger = Logger.getLogger(RegisterSSHKeyPairCmd.class.getName());
1717
private static final String s_name = "registerkeypairresponse";

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

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -287,49 +287,55 @@ private static void writeCommand(ObjectOutputStream out, String command) throws
287287
apiCommand.setName(command);
288288

289289
Implementation impl = (Implementation)clas.getAnnotation(Implementation.class);
290-
if (impl == null)
290+
if (impl == null) {
291291
impl = (Implementation)clas.getSuperclass().getAnnotation(Implementation.class);
292-
String commandDescription = impl.description();
293-
if (commandDescription != null)
294-
apiCommand.setDescription(commandDescription);
295-
else
296-
System.out.println("Command " + apiCommand.getName() + " misses description");
297-
298-
//Set request parameters
299-
Field[] fields = clas.getDeclaredFields();
300-
301-
//Get fields from superclass
302-
Class<?> superClass = clas.getSuperclass();
303-
String superName = superClass.getName();
304-
if (!superName.equals(BaseCmd.class.getName()) && !superName.equals(BaseAsyncCmd.class.getName()) && !superName.equals(BaseAsyncCreateCmd.class.getName())) {
305-
Field[] superClassFields = superClass.getDeclaredFields();
306-
if (superClassFields != null && !superClass.getName().equals(BaseListCmd.class.getName())) {
307-
Field[] tmpFields = new Field[fields.length + superClassFields.length];
308-
System.arraycopy(fields, 0, tmpFields, 0, fields.length);
309-
System.arraycopy(superClassFields, 0, tmpFields, fields.length, superClassFields.length);
310-
fields = tmpFields;
311-
}
312-
superClass = superClass.getSuperclass();
313292
}
314-
request = setRequestFields(fields);
315-
316-
317-
//Set Async information for the command
318-
if (superName.equals(BaseAsyncCmd.class.getName()) || superName.equals(BaseAsyncCreateCmd.class.getName())) {
319-
apiCommand.setAsync(true);
293+
294+
if (impl.includeInApiDoc()) {
295+
String commandDescription = impl.description();
296+
if (commandDescription != null)
297+
apiCommand.setDescription(commandDescription);
298+
else
299+
System.out.println("Command " + apiCommand.getName() + " misses description");
300+
301+
//Set request parameters
302+
Field[] fields = clas.getDeclaredFields();
303+
304+
//Get fields from superclass
305+
Class<?> superClass = clas.getSuperclass();
306+
String superName = superClass.getName();
307+
if (!superName.equals(BaseCmd.class.getName()) && !superName.equals(BaseAsyncCmd.class.getName()) && !superName.equals(BaseAsyncCreateCmd.class.getName())) {
308+
Field[] superClassFields = superClass.getDeclaredFields();
309+
if (superClassFields != null && !superClass.getName().equals(BaseListCmd.class.getName())) {
310+
Field[] tmpFields = new Field[fields.length + superClassFields.length];
311+
System.arraycopy(fields, 0, tmpFields, 0, fields.length);
312+
System.arraycopy(superClassFields, 0, tmpFields, fields.length, superClassFields.length);
313+
fields = tmpFields;
314+
}
315+
superClass = superClass.getSuperclass();
316+
}
317+
request = setRequestFields(fields);
318+
319+
320+
//Set Async information for the command
321+
if (superName.equals(BaseAsyncCmd.class.getName()) || superName.equals(BaseAsyncCreateCmd.class.getName())) {
322+
apiCommand.setAsync(true);
323+
} else {
324+
apiCommand.setAsync(false);
325+
}
326+
327+
//Get response parameters
328+
Class<?> responseClas = impl.responseObject();
329+
Field[] responseFields = responseClas.getDeclaredFields();
330+
response = setResponseFields(responseFields);
331+
332+
apiCommand.setRequest(request);
333+
apiCommand.setResponse(response);
334+
335+
out.writeObject(apiCommand);
320336
} else {
321-
apiCommand.setAsync(false);
337+
s_logger.debug("Command " + command + " is not exposed in api doc");
322338
}
323-
324-
//Get response parameters
325-
Class<?> responseClas = impl.responseObject();
326-
Field[] responseFields = responseClas.getDeclaredFields();
327-
response = setResponseFields(responseFields);
328-
329-
apiCommand.setRequest(request);
330-
apiCommand.setResponse(response);
331-
332-
out.writeObject(apiCommand);
333339
}
334340

335341
private static void writeLoginCommand(ObjectOutputStream out) throws ClassNotFoundException, IOException{
@@ -394,7 +400,7 @@ private static ArrayList<Argument> setRequestFields(Field[] fields) {
394400
Argument id = null;
395401
for (Field f : fields) {
396402
Parameter parameterAnnotation = f.getAnnotation(Parameter.class);
397-
if (parameterAnnotation != null && parameterAnnotation.expose()) {
403+
if (parameterAnnotation != null && parameterAnnotation.expose() && parameterAnnotation.includeInApiDoc()) {
398404
Argument reqArg = new Argument(parameterAnnotation.name());
399405
reqArg.setRequired(parameterAnnotation.required());
400406
if (!parameterAnnotation.description().isEmpty()) {

0 commit comments

Comments
 (0)