Skip to content

Commit 5d17693

Browse files
committed
CLOUDSTACK-1210: Fix pluggable service, apiserver, mgmt server impl, api-discovery
- Mgmt server impl is a pluggable service, fix it's method - Fix getCommands() to return all cmd api classes supported by this mgmt server - For api-discovery, get commands from pluggable services only, don't use reflections - Don't use reflections in ApiServer, iterate pluggableservices - Fix api discovery unit test - The fix was done automatically using following python program along with following step: 1. Get all apis provided by default mgmt server, all of them are in cloud-api now cd api/src/org/apache/cloudstack/api/command find . >> apis 2. For all apis, generate java code that adds the class to the cmdList arraylist: f = open('apis', 'r') data = f.read() f.close() output = "" for a in data.split('\n'): output += "cmdList.add(%s);" % a.split('/')[-1].replace('.java', '.class') # wrote output to a file, copied content to mgmt server impl's getCommands() # similarly, fixed import statements using same code, splitting on / Testing: Ran apiserver, put breakpoints in ApiServer's init() where classes are processed Total cmd classes found by reflections (ReflectUtil) = 354 Total cmd classes found by getCommands for all pluggable services = 354 Next, copied the comma separated values for each set to a string in ipython, a & b set(a).difference(set(b)) returned null. The above test implies both set of cmd classes found by both methods, i.e. using reflections and using getCommands() had same set of apis and all were unique. Conclusion: The changes are idempotent and don't break api server's cmd class api discovery processing. BUG-ID: CLOUDSTACK-1210 Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
1 parent 4a9af12 commit 5d17693

4 files changed

Lines changed: 361 additions & 54 deletions

File tree

‎plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ void init() {
6868
if (s_apiNameDiscoveryResponseMap == null) {
6969
long startTime = System.nanoTime();
7070
s_apiNameDiscoveryResponseMap = new HashMap<String, ApiDiscoveryResponse>();
71-
//TODO: Fix and use PluggableService to get the classes
72-
Set<Class<?>> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class,
73-
new String[]{"org.apache.cloudstack.api", "com.cloud.api"});
71+
Set<Class<?>> cmdClasses = new HashSet<Class<?>>();
7472
for(PluggableService service: _services)
7573
cmdClasses.addAll(service.getCommands());
7674
cacheResponseMap(cmdClasses);

‎plugins/api/discovery/test/org/apache/cloudstack/discovery/ApiDiscoveryTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void verifyListSingleApi() throws Exception {
8383
@Test
8484
public void verifyListApis() throws Exception {
8585
ListResponse<ApiDiscoveryResponse> responses = (ListResponse<ApiDiscoveryResponse>) _discoveryService.listApis(testUser, null);
86-
assertTrue("No. of response items > 1", responses.getCount() > 1);
86+
assertTrue("No. of response items > 1", responses.getCount() == 1);
8787
for (ApiDiscoveryResponse response: responses.getResponses()) {
8888
assertFalse("API name is empty", response.getName().isEmpty());
8989
assertFalse("API description is empty", response.getDescription().isEmpty());

‎server/src/com/cloud/api/ApiServer.java‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,7 @@
2929
import java.text.DateFormat;
3030
import java.text.ParseException;
3131
import java.text.SimpleDateFormat;
32-
import java.util.ArrayList;
33-
import java.util.Collections;
34-
import java.util.Date;
35-
import java.util.HashMap;
36-
import java.util.Iterator;
37-
import java.util.List;
38-
import java.util.Map;
39-
import java.util.Set;
40-
import java.util.TimeZone;
32+
import java.util.*;
4133
import java.util.concurrent.ExecutorService;
4234
import java.util.concurrent.LinkedBlockingQueue;
4335
import java.util.concurrent.ThreadPoolExecutor;
@@ -64,7 +56,6 @@
6456
import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
6557
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
6658
import com.cloud.event.ActionEventUtils;
67-
import com.cloud.utils.ReflectUtil;
6859
import org.apache.cloudstack.acl.APILimitChecker;
6960
import org.apache.cloudstack.api.*;
7061
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
@@ -149,7 +140,6 @@
149140
import com.cloud.utils.db.SearchCriteria;
150141
import com.cloud.utils.db.Transaction;
151142

152-
153143
@Component
154144
public class ApiServer implements HttpRequestHandler {
155145
private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
@@ -165,7 +155,6 @@ public class ApiServer implements HttpRequestHandler {
165155
@Inject private ConfigurationDao _configDao;
166156

167157
@Inject List<PluggableService> _pluggableServices;
168-
169158
@Inject List<APIChecker> _apiAccessCheckers;
170159

171160
private Account _systemAccount = null;
@@ -219,9 +208,7 @@ public void init() {
219208
}
220209
}
221210

222-
Set<Class<?>> cmdClasses = ReflectUtil.getClassesWithAnnotation(APICommand.class,
223-
new String[]{"org.apache.cloudstack.api", "com.cloud.api"});
224-
211+
Set<Class<?>> cmdClasses = new HashSet<Class<?>>();
225212
for(PluggableService pluggableService: _pluggableServices)
226213
cmdClasses.addAll(pluggableService.getCommands());
227214

0 commit comments

Comments
 (0)