Put command classes under Spring injection framework
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/df684261 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/df684261 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/df684261 Branch: refs/heads/javelin Commit: df684261cf72f08227b01f1d188c1a44412289ce Parents: a2dab60 Author: Kelven Yang <[email protected]> Authored: Tue Jan 15 18:06:25 2013 -0800 Committer: Kelven Yang <[email protected]> Committed: Tue Jan 15 18:07:19 2013 -0800 ---------------------------------------------------------------------- api/src/org/apache/cloudstack/api/BaseCmd.java | 111 +++++---------- api/src/org/apache/cloudstack/api/BaseListCmd.java | 15 ++- core/src/com/cloud/vm/VMInstanceVO.java | 7 - .../storage/snapshot/db/SnapshotDao2Impl.java | 3 + .../datastore/db/PrimaryDataStoreDaoImpl.java | 5 +- server/src/com/cloud/api/ApiResponseHelper.java | 3 + server/src/com/cloud/api/ApiServer.java | 6 +- 7 files changed, 58 insertions(+), 92 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/df684261/api/src/org/apache/cloudstack/api/BaseCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/BaseCmd.java b/api/src/org/apache/cloudstack/api/BaseCmd.java index ba2c4d2..fe97694 100644 --- a/api/src/org/apache/cloudstack/api/BaseCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseCmd.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; +import javax.inject.Inject; + import org.apache.cloudstack.query.QueryService; import org.apache.log4j.Logger; @@ -109,84 +111,43 @@ public abstract class BaseCmd { @Parameter(name = "response", type = CommandType.STRING) private String responseType; - public static ConfigurationService _configService; - public static AccountService _accountService; - public static UserVmService _userVmService; - public static ManagementService _mgr; - public static StorageService _storageService; - public static ResourceService _resourceService; - public static NetworkService _networkService; - public static TemplateService _templateService; - public static SecurityGroupService _securityGroupService; - public static SnapshotService _snapshotService; - public static ConsoleProxyService _consoleProxyService; - public static VpcVirtualNetworkApplianceService _routerService; - public static ResponseGenerator _responseGenerator; - public static EntityManager _entityMgr; - public static RulesService _rulesService; - public static AutoScaleService _autoScaleService; - public static LoadBalancingRulesService _lbService; - public static RemoteAccessVpnService _ravService; - public static BareMetalVmService _bareMetalVmService; - public static ProjectService _projectService; - public static FirewallService _firewallService; - public static DomainService _domainService; - public static ResourceLimitService _resourceLimitService; - public static IdentityService _identityService; - public static StorageNetworkService _storageNetworkService; - public static TaggedResourceService _taggedResourceService; - public static VpcService _vpcService; - public static NetworkACLService _networkACLService; - public static Site2SiteVpnService _s2sVpnService; - - public static QueryService _queryService; - - public static void setComponents(ResponseGenerator generator) { - _mgr = ComponentContext.getComponent(ManagementService.class); - _accountService = ComponentContext.getComponent(AccountService.class); - _configService = ComponentContext.getComponent(ConfigurationService.class); - - _userVmService = ComponentContext.getComponent(UserVmService.class); - - // TODO, ugly and will change soon - // - Map<String, UserVmService> svmServices = ComponentContext.getComponentsOfType(UserVmService.class); - _userVmService = svmServices.get("BareMetalVmManagerImpl"); - - _storageService = ComponentContext.getComponent(StorageService.class); - _resourceService = ComponentContext.getComponent(ResourceService.class); - - _networkService = ComponentContext.getComponent(NetworkService.class); - _templateService = ComponentContext.getComponent(TemplateService.class); - - // TODO, will change to looking for primary component - // ugly binding to a specific implementation - Map<String, SecurityGroupService> _sgServices = ComponentContext.getComponentsOfType(SecurityGroupService.class); - _securityGroupService = _sgServices.get("SecurityGroupManagerImpl2"); - - _snapshotService = ComponentContext.getComponent(SnapshotService.class); - _consoleProxyService = ComponentContext.getComponent(ConsoleProxyService.class); - _routerService = ComponentContext.getComponent(VpcVirtualNetworkApplianceService.class); - _entityMgr = ComponentContext.getComponent(EntityManager.class); - _rulesService = ComponentContext.getComponent(RulesService.class); - _lbService = ComponentContext.getComponent(LoadBalancingRulesService.class); - _ravService = ComponentContext.getComponent(RemoteAccessVpnService.class); - _responseGenerator = generator; - _bareMetalVmService = ComponentContext.getComponent(BareMetalVmService.class); - _projectService = ComponentContext.getComponent(ProjectService.class); - _firewallService = ComponentContext.getComponent(FirewallService.class); - _domainService = ComponentContext.getComponent(DomainService.class); - _resourceLimitService = ComponentContext.getComponent(ResourceLimitService.class); - _identityService = ComponentContext.getComponent(IdentityService.class); - _storageNetworkService = ComponentContext.getComponent(StorageNetworkService.class); - _taggedResourceService = ComponentContext.getComponent(TaggedResourceService.class); - _vpcService = ComponentContext.getComponent(VpcService.class); - _networkACLService = ComponentContext.getComponent(NetworkACLService.class); - _s2sVpnService = ComponentContext.getComponent(Site2SiteVpnService.class); - } + @Inject public ConfigurationService _configService; + @Inject public AccountService _accountService; + @Inject public UserVmService _userVmService; + @Inject public ManagementService _mgr; + @Inject public StorageService _storageService; + @Inject public ResourceService _resourceService; + @Inject public NetworkService _networkService; + @Inject public TemplateService _templateService; + @Inject public SecurityGroupService _securityGroupService; + @Inject public SnapshotService _snapshotService; + @Inject public ConsoleProxyService _consoleProxyService; + @Inject public VpcVirtualNetworkApplianceService _routerService; + @Inject public ResponseGenerator _responseGenerator; + @Inject public EntityManager _entityMgr; + @Inject public RulesService _rulesService; + @Inject public AutoScaleService _autoScaleService; + @Inject public LoadBalancingRulesService _lbService; + @Inject public RemoteAccessVpnService _ravService; + @Inject public BareMetalVmService _bareMetalVmService; + @Inject public ProjectService _projectService; + @Inject public FirewallService _firewallService; + @Inject public DomainService _domainService; + @Inject public ResourceLimitService _resourceLimitService; + @Inject public IdentityService _identityService; + @Inject public StorageNetworkService _storageNetworkService; + @Inject public TaggedResourceService _taggedResourceService; + @Inject public VpcService _vpcService; + @Inject public NetworkACLService _networkACLService; + @Inject public Site2SiteVpnService _s2sVpnService; + + @Inject public QueryService _queryService; public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException; + public void configure() { + } + public String getResponseType() { if (responseType == null) { return RESPONSE_TYPE_XML; http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/df684261/api/src/org/apache/cloudstack/api/BaseListCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/BaseListCmd.java b/api/src/org/apache/cloudstack/api/BaseListCmd.java index 58e83f7..bc0b2b8 100644 --- a/api/src/org/apache/cloudstack/api/BaseListCmd.java +++ b/api/src/org/apache/cloudstack/api/BaseListCmd.java @@ -42,6 +42,9 @@ public abstract class BaseListCmd extends BaseCmd { // ///////////////// Accessors /////////////////////// // /////////////////////////////////////////////////// + public BaseListCmd() { + } + public String getKeyword() { return keyword; } @@ -62,10 +65,14 @@ public abstract class BaseListCmd extends BaseCmd { return pageSize; } - public static void configure() { - if (_configService.getDefaultPageSize().longValue() != PAGESIZE_UNLIMITED) { - MAX_PAGESIZE = _configService.getDefaultPageSize(); - } + public void configure() { + if(MAX_PAGESIZE == null) { + if (_configService.getDefaultPageSize().longValue() != PAGESIZE_UNLIMITED) { + MAX_PAGESIZE = _configService.getDefaultPageSize(); + } else { + MAX_PAGESIZE = PAGESIZE_UNLIMITED; + } + } } @Override http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/df684261/core/src/com/cloud/vm/VMInstanceVO.java ---------------------------------------------------------------------- diff --git a/core/src/com/cloud/vm/VMInstanceVO.java b/core/src/com/cloud/vm/VMInstanceVO.java index c63dd83..33ebed9 100644 --- a/core/src/com/cloud/vm/VMInstanceVO.java +++ b/core/src/com/cloud/vm/VMInstanceVO.java @@ -42,7 +42,6 @@ import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.StateMachine; import com.cloud.utils.fsm.FiniteStateObject; import com.cloud.vm.VirtualMachine.State; -import org.apache.cloudstack.api.InternalIdentity; @Entity @Table(name="vm_instance") @@ -144,12 +143,6 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi @Enumerated(value=EnumType.STRING) protected HypervisorType hypervisorType; - @Column(name="ram") - protected long ram; - - @Column(name="cpu") - protected int cpu; - @Column(name="tags") protected String tags; http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/df684261/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2Impl.java ---------------------------------------------------------------------- diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2Impl.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2Impl.java index 5e36e10..74cec5e 100644 --- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2Impl.java +++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/db/SnapshotDao2Impl.java @@ -18,8 +18,11 @@ */ package org.apache.cloudstack.storage.snapshot.db; +import org.springframework.stereotype.Component; + import com.cloud.utils.db.GenericDaoBase; +@Component public class SnapshotDao2Impl extends GenericDaoBase<SnapshotVO, Long> implements SnapshotDao2 { } http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/df684261/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java index f73d72c..faca54b 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.cloudstack.storage.datastore.DataStoreStatus; @@ -49,7 +50,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<PrimaryDataStoreVO, protected final SearchBuilder<PrimaryDataStoreVO> DeleteLvmSearch; protected final GenericSearchBuilder<PrimaryDataStoreVO, Long> StatusCountSearch; - protected final PrimaryDataStoreDetailsDao _detailsDao = null; + @Inject protected PrimaryDataStoreDetailsDao _detailsDao; private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and ("; private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?"; @@ -95,8 +96,6 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<PrimaryDataStoreVO, StatusCountSearch.and("status", StatusCountSearch.entity().getStatus(), SearchCriteria.Op.IN); StatusCountSearch.select(null, Func.COUNT, null); StatusCountSearch.done(); - - // _detailsDao = ComponentInject.inject(PrimaryDataStoreDetailsDaoImpl.class); } @Override http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/df684261/server/src/com/cloud/api/ApiResponseHelper.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index c346a6b..dfeeb87 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -132,6 +132,8 @@ import org.apache.cloudstack.api.response.VpnUsersResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.api.response.S3Response; +import org.springframework.stereotype.Component; + import com.cloud.async.AsyncJob; import com.cloud.capacity.Capacity; import com.cloud.capacity.CapacityVO; @@ -240,6 +242,7 @@ import com.cloud.vm.NicProfile; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.Type; +@Component public class ApiResponseHelper implements ResponseGenerator { public final Logger s_logger = Logger.getLogger(ApiResponseHelper.class); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/df684261/server/src/com/cloud/api/ApiServer.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java index 8a2c675..9a62524 100755 --- a/server/src/com/cloud/api/ApiServer.java +++ b/server/src/com/cloud/api/ApiServer.java @@ -132,6 +132,7 @@ import com.cloud.utils.Pair; import com.cloud.utils.NumbersUtil; import com.cloud.utils.ReflectUtil; import com.cloud.utils.StringUtils; +import com.cloud.utils.component.ComponentContext; import com.cloud.utils.component.PluggableService; import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.SearchCriteria; @@ -179,9 +180,6 @@ public class ApiServer implements HttpRequestHandler { } public void init() { - BaseCmd.setComponents(new ApiResponseHelper()); - BaseListCmd.configure(); - _systemAccount = _accountMgr.getSystemAccount(); _systemUser = _accountMgr.getSystemUser(); @@ -346,6 +344,8 @@ public class ApiServer implements HttpRequestHandler { Class<?> cmdClass = getCmdClass(command[0]); if (cmdClass != null) { BaseCmd cmdObj = (BaseCmd) cmdClass.newInstance(); + cmdObj = ComponentContext.inject(cmdObj); + cmdObj.configure(); cmdObj.setFullUrlParams(paramMap); cmdObj.setResponseType(responseType); // This is where the command is either serialized, or directly dispatched
