api: Use Identity interface instead of java reflect to getId

- Add new interface method to getId
- Fix method definition in AsyncJob
- Get rid of mechanism to getId using reflect, use Identity interface

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
Rohit Yadav 2012-12-21 19:03:49 -08:00
parent 3209a3a858
commit 024f0d95dd
4 changed files with 5 additions and 16 deletions

View File

@ -50,7 +50,7 @@ public interface AsyncJob extends Identity {
AutoScaleVmGroup
}
Long getId();
long getId();
long getUserId();

View File

@ -18,4 +18,5 @@ package org.apache.cloudstack.api;
public interface Identity {
String getUuid();
long getId();
}

View File

@ -145,7 +145,7 @@ public class AsyncJobVO implements AsyncJob {
@Override
public Long getId() {
public long getId() {
return id;
}

View File

@ -17,8 +17,6 @@
package com.cloud.api;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
@ -48,7 +46,6 @@ import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.utils.IdentityProxy;
import com.cloud.network.dao.NetworkDao;
import com.cloud.server.ManagementServer;
import com.cloud.storage.dao.VMTemplateDao;
@ -635,21 +632,12 @@ public class ApiDispatcher {
if (objVO == null) {
continue;
}
Method method = null;
try {
method = objVO.getClass().getMethod("getId", null);
} catch (NoSuchMethodException e) {
continue;
} catch (SecurityException e) {
continue;
}
// Invoke the getId method, get the internal long ID
// If that fails hide exceptions as the uuid may not exist
try {
id = (Long) method.invoke(objVO);
} catch (InvocationTargetException e) {
id = (Long) ((Identity)objVO).getId();
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (NullPointerException e) {
}
// Return on first non-null Id for the uuid entity
if (id != null)