6060import org .apache .cloudstack .api .command .user .vm .ListVMsCmd ;
6161import org .apache .cloudstack .api .command .user .vmgroup .ListVMGroupsCmd ;
6262import org .apache .cloudstack .api .command .user .volume .ListVolumesCmd ;
63- import org .apache .cloudstack .discovery .ApiDiscoveryService ;
6463import org .apache .commons .codec .binary .Base64 ;
6564import org .apache .http .client .utils .URLEncodedUtils ;
6665import org .apache .http .ConnectionClosedException ;
134133import com .cloud .utils .exception .CSExceptionErrorCode ;
135134import com .cloud .uuididentity .dao .IdentityDao ;
136135
137- import org .reflections .Reflections ;
138-
139136public class ApiServer implements HttpRequestHandler {
140137 private static final Logger s_logger = Logger .getLogger (ApiServer .class .getName ());
141138 private static final Logger s_accessLogger = Logger .getLogger ("apiserver." + ApiServer .class .getName ());
@@ -150,15 +147,13 @@ public class ApiServer implements HttpRequestHandler {
150147
151148 @ Inject (adapter = APIAccessChecker .class )
152149 protected Adapters <APIAccessChecker > _apiAccessCheckers ;
153- @ Inject (adapter = ApiDiscoveryService .class )
154- protected Adapters <ApiDiscoveryService > _apiDiscoveryServices ;
155150
156151 private Account _systemAccount = null ;
157152 private User _systemUser = null ;
158153 private static int _workerCount = 0 ;
159154 private static ApiServer s_instance = null ;
160155 private static final DateFormat _dateFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ssZ" );
161- private Map <String , Class <?>> _apiNameCmdClassMap = new HashMap <String , Class <?>>();
156+ private static Map <String , Class <?>> _apiNameCmdClassMap = new HashMap <String , Class <?>>();
162157
163158 private static ExecutorService _executor = new ThreadPoolExecutor (10 , 150 , 60 , TimeUnit .SECONDS , new LinkedBlockingQueue <Runnable >(), new NamedThreadFactory ("ApiServer" ));
164159
@@ -202,13 +197,16 @@ public void init() {
202197 }
203198 }
204199
205- for (ApiDiscoveryService discoveryService : _apiDiscoveryServices ) {
206- _apiNameCmdClassMap .putAll (discoveryService .getApiNameCmdClassMapping ());
207- }
200+ Set <Class <?>> cmdClasses = ReflectUtil .getClassesWithAnnotation (APICommand .class ,
201+ new String []{"org.apache.cloudstack.api" , "com.cloud.api" });
208202
209- if (_apiNameCmdClassMap .size () == 0 ) {
210- s_logger .fatal ("ApiServer failed to generate apiname, cmd class mappings."
211- + "Please check and enable at least one ApiDiscovery adapter." );
203+ for (Class <?> cmdClass : cmdClasses ) {
204+ String apiName = cmdClass .getAnnotation (APICommand .class ).name ();
205+ if (_apiNameCmdClassMap .containsKey (apiName )) {
206+ s_logger .error ("API Cmd class " + cmdClass .getName () + " has non-unique apiname" + apiName );
207+ continue ;
208+ }
209+ _apiNameCmdClassMap .put (apiName , cmdClass );
212210 }
213211
214212 encodeApiResponse = Boolean .valueOf (configDao .getValue (Config .EncodeApiResponse .key ()));
0 commit comments