Updated Branches:
  refs/heads/master dcbb0ecef -> d13cc7e7e

ApiDiscoveryService: Use only as pluggable service

Remove usage and impl as adapter.
We have duplicate code that generates apiname:cmd class maps which is
unavoidable right now as:

- Plugin should not depend on ApiServer or any other component
- cloud-utils cannot depend on cloud-api for the APICommand annotation
- Use java reflect to create a static method in cloud-utils that does the job
  would be unsafe.

Signed-off-by: Rohit Yadav <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/d13cc7e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/d13cc7e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/d13cc7e7

Branch: refs/heads/master
Commit: d13cc7e7e49a54e2fdd177c4fe4ce45739b4736d
Parents: 657fb6a
Author: Rohit Yadav <[email protected]>
Authored: Wed Jan 9 17:19:49 2013 -0800
Committer: Rohit Yadav <[email protected]>
Committed: Wed Jan 9 17:25:29 2013 -0800

----------------------------------------------------------------------
 .../cloudstack/discovery/ApiDiscoveryService.java  |    6 +--
 client/tomcatconf/components.xml.in                |    3 -
 .../discovery/ApiDiscoveryServiceImpl.java         |   51 ++++-----------
 3 files changed, 14 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d13cc7e7/api/src/org/apache/cloudstack/discovery/ApiDiscoveryService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/discovery/ApiDiscoveryService.java 
b/api/src/org/apache/cloudstack/discovery/ApiDiscoveryService.java
index 1220694..96ea3ee 100644
--- a/api/src/org/apache/cloudstack/discovery/ApiDiscoveryService.java
+++ b/api/src/org/apache/cloudstack/discovery/ApiDiscoveryService.java
@@ -16,14 +16,10 @@
 // under the License.
 package org.apache.cloudstack.discovery;
 
-import com.cloud.utils.component.Adapter;
 import com.cloud.utils.component.PluggableService;
 import org.apache.cloudstack.api.BaseResponse;
 import org.apache.cloudstack.api.response.ListResponse;
 
-import java.util.Map;
-
-public interface ApiDiscoveryService extends Adapter, PluggableService {
+public interface ApiDiscoveryService extends PluggableService {
     ListResponse<? extends BaseResponse> listApis();
-    Map<String, Class<?>> getApiNameCmdClassMapping();
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d13cc7e7/client/tomcatconf/components.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/components.xml.in 
b/client/tomcatconf/components.xml.in
index b9feed1..b779c86 100755
--- a/client/tomcatconf/components.xml.in
+++ b/client/tomcatconf/components.xml.in
@@ -56,9 +56,6 @@ under the License.
         <adapters key="org.apache.cloudstack.acl.APIAccessChecker">
             <adapter name="StaticRoleBasedAPIAccessChecker" 
class="org.apache.cloudstack.acl.StaticRoleBasedAPIAccessChecker"/>
         </adapters>
-        <adapters key="org.apache.cloudstack.discovery.ApiDiscoveryService">
-            <adapter name="ApiDiscoveryService" 
class="org.apache.cloudstack.discovery.ApiDiscoveryServiceImpl"/>
-        </adapters>
         <adapters key="com.cloud.agent.manager.allocator.HostAllocator">
             <adapter name="FirstFitRouting" 
class="com.cloud.agent.manager.allocator.impl.FirstFitRoutingAllocator"/>
             <!--adapter name="FirstFitRouting" 
class="com.cloud.agent.manager.allocator.impl.RecreateHostAllocator"/-->

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d13cc7e7/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java
 
b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java
index 5363e55..ea6b206 100644
--- 
a/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java
+++ 
b/plugins/api/discovery/src/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java
@@ -17,7 +17,6 @@
 package org.apache.cloudstack.discovery;
 
 import com.cloud.utils.ReflectUtil;
-import com.cloud.utils.component.AdapterBase;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.BaseAsyncCmd;
@@ -30,7 +29,6 @@ import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.log4j.Logger;
 
 import javax.ejb.Local;
-import javax.naming.ConfigurationException;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -39,36 +37,28 @@ import java.util.Map;
 import java.util.Set;
 
 @Local(value = ApiDiscoveryService.class)
-public class ApiDiscoveryServiceImpl extends AdapterBase implements 
ApiDiscoveryService {
-
+public class ApiDiscoveryServiceImpl implements ApiDiscoveryService {
     private static final Logger s_logger = 
Logger.getLogger(ApiDiscoveryServiceImpl.class);
-    private Map<String, Class<?>> _apiNameCmdClassMap;
-    private ListResponse<ApiDiscoveryResponse> _discoveryResponse;
+
+    private ListResponse<ApiDiscoveryResponse> _discoveryResponse = new 
ListResponse<ApiDiscoveryResponse>();
+
+    private Map<String, Class<?>> _apiNameCmdClassMap = new HashMap<String, 
Class<?>>();
 
     protected ApiDiscoveryServiceImpl() {
         super();
+        generateApiNameCmdClassMap();
+        cacheListApiResponse();
     }
 
-    private void generateApiNameCmdClassMapping() {
-        _apiNameCmdClassMap = new HashMap<String, Class<?>>();
-        Set<Class<?>> cmdClasses = 
ReflectUtil.getClassesWithAnnotation(APICommand.class, new 
String[]{"org.apache.cloudstack.api", "com.cloud.api"});
+    private void generateApiNameCmdClassMap() {
+        Set<Class<?>> cmdClasses = 
ReflectUtil.getClassesWithAnnotation(APICommand.class,
+                new String[]{"org.apache.cloudstack.api", "com.cloud.api"});
 
-        for(Class<?> cmdClass: cmdClasses) {
-            String apiName = cmdClass.getAnnotation(APICommand.class).name();
-            if (_apiNameCmdClassMap.containsKey(apiName)) {
-                s_logger.error("API Cmd class " + cmdClass.getName() + " has 
non-unique apiname" + apiName);
-                continue;
-            }
-            _apiNameCmdClassMap.put(apiName, cmdClass);
-        }
+        for(Class<?> cmdClass: cmdClasses)
+            
_apiNameCmdClassMap.put(cmdClass.getAnnotation(APICommand.class).name(), 
cmdClass);
     }
 
-    private void precacheListApiResponse() {
-
-        if(_apiNameCmdClassMap == null)
-            return;
-
-        _discoveryResponse = new ListResponse<ApiDiscoveryResponse>();
+    private void cacheListApiResponse() {
 
         List<ApiDiscoveryResponse> apiDiscoveryResponses = new 
ArrayList<ApiDiscoveryResponse>();
 
@@ -118,21 +108,6 @@ public class ApiDiscoveryServiceImpl extends AdapterBase 
implements ApiDiscovery
     }
 
     @Override
-    public boolean configure(String name, Map<String, Object> params)
-            throws ConfigurationException {
-        super.configure(name, params);
-
-        generateApiNameCmdClassMapping();
-        precacheListApiResponse();
-
-        return true;
-    }
-
-    public Map<String, Class<?>> getApiNameCmdClassMapping() {
-        return _apiNameCmdClassMap;
-    }
-
-    @Override
     public ListResponse<? extends BaseResponse> listApis() {
         return _discoveryResponse;
     }

Reply via email to