mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Replace Adapters and PluggableServices, use Spring to load them
This commit is contained in:
parent
453b31f3f4
commit
d79f1f6fdc
@ -63,7 +63,7 @@ import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.component.Adapter;
|
||||
import com.cloud.utils.component.Adapters;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.ComponentLocator.ComponentInfo;
|
||||
import com.cloud.utils.component.LegacyComponentLocator.ComponentInfo;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.OutputInterpreter;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
@ -218,7 +218,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
||||
|
||||
protected int _pingInterval;
|
||||
protected long _pingTimeout;
|
||||
protected AgentMonitor _monitor = null;
|
||||
@Inject protected AgentMonitor _monitor = null;
|
||||
|
||||
protected ExecutorService _executor;
|
||||
|
||||
@ -272,7 +272,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
||||
long lastPing = (System.currentTimeMillis() >> 10) - _pingTimeout;
|
||||
_hostDao.markHostsAsDisconnected(_nodeId, lastPing);
|
||||
|
||||
_monitor = ComponentLocator.inject(AgentMonitor.class, _nodeId, _hostDao, _vmDao, _dcDao, _podDao, this, _alertMgr, _pingTimeout);
|
||||
// _monitor = ComponentLocator.inject(AgentMonitor.class, _nodeId, _hostDao, _vmDao, _dcDao, _podDao, this, _alertMgr, _pingTimeout);
|
||||
registerForHostEvents(_monitor, true, true, false);
|
||||
|
||||
_executor = new ThreadPoolExecutor(threads, threads, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentTaskPool"));
|
||||
|
||||
@ -50,6 +50,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
@ -80,6 +81,7 @@ import org.apache.http.protocol.ResponseContent;
|
||||
import org.apache.http.protocol.ResponseDate;
|
||||
import org.apache.http.protocol.ResponseServer;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.response.ApiResponseSerializer;
|
||||
import com.cloud.api.response.ExceptionResponse;
|
||||
@ -116,6 +118,7 @@ import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CSExceptionErrorCode;
|
||||
import com.cloud.uuididentity.dao.IdentityDao;
|
||||
|
||||
@Component
|
||||
public class ApiServer implements HttpRequestHandler {
|
||||
private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
|
||||
private static final Logger s_accessLogger = Logger.getLogger("apiserver." + ApiServer.class.getName());
|
||||
@ -133,6 +136,8 @@ public class ApiServer implements HttpRequestHandler {
|
||||
private AsyncJobManager _asyncMgr = null;
|
||||
private Account _systemAccount = null;
|
||||
private User _systemUser = null;
|
||||
|
||||
@Inject List<PluggableService> _pluggableServices;
|
||||
|
||||
private static int _workerCount = 0;
|
||||
|
||||
@ -187,9 +192,7 @@ public class ApiServer implements HttpRequestHandler {
|
||||
private String[] getPluggableServicesApiConfigs() {
|
||||
List<String> pluggableServicesApiConfigs = new ArrayList<String>();
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
List<PluggableService> services = locator.getAllPluggableServices();
|
||||
for (PluggableService service : services) {
|
||||
for (PluggableService service : _pluggableServices) {
|
||||
pluggableServicesApiConfigs.add(service.getPropertiesFile());
|
||||
}
|
||||
return pluggableServicesApiConfigs.toArray(new String[0]);
|
||||
|
||||
@ -121,6 +121,9 @@ public class ClusterManagerImpl implements ClusterManager {
|
||||
private final ExecutorService _executor;
|
||||
|
||||
private ClusterServiceAdapter _currentServiceAdapter;
|
||||
|
||||
@Inject
|
||||
private List<ClusterServiceAdapter> _serviceAdapters;
|
||||
|
||||
private ManagementServerHostDao _mshostDao;
|
||||
private ManagementServerHostPeerDao _mshostPeerDao;
|
||||
@ -1306,14 +1309,10 @@ public class ClusterManagerImpl implements ClusterManager {
|
||||
// notification task itself in turn works as a task dispatcher
|
||||
_executor.execute(getClusterPduNotificationTask());
|
||||
|
||||
Adapters<ClusterServiceAdapter> adapters = locator.getAdapters(ClusterServiceAdapter.class);
|
||||
if (adapters == null || !adapters.isSet()) {
|
||||
if (_serviceAdapters == null) {
|
||||
throw new ConfigurationException("Unable to get cluster service adapters");
|
||||
}
|
||||
Enumeration<ClusterServiceAdapter> it = adapters.enumeration();
|
||||
if(it.hasMoreElements()) {
|
||||
_currentServiceAdapter = it.nextElement();
|
||||
}
|
||||
_currentServiceAdapter = _serviceAdapters.get(0);
|
||||
|
||||
if(_currentServiceAdapter == null) {
|
||||
throw new ConfigurationException("Unable to set current cluster service adapter");
|
||||
|
||||
@ -179,7 +179,7 @@ import com.cloud.user.dao.UserStatsLogDaoImpl;
|
||||
import com.cloud.utils.component.Adapter;
|
||||
import com.cloud.utils.component.ComponentLibrary;
|
||||
import com.cloud.utils.component.ComponentLibraryBase;
|
||||
import com.cloud.utils.component.ComponentLocator.ComponentInfo;
|
||||
import com.cloud.utils.component.LegacyComponentLocator.ComponentInfo;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
@ -187,7 +187,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
private int _mgmt_port = 8250;
|
||||
|
||||
private String _name;
|
||||
private Adapters<ConsoleProxyAllocator> _consoleProxyAllocators;
|
||||
@Inject
|
||||
private List<ConsoleProxyAllocator> _consoleProxyAllocators;
|
||||
|
||||
@Inject
|
||||
private ConsoleProxyDao _consoleProxyDao;
|
||||
@ -806,11 +807,10 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
|
||||
private ConsoleProxyAllocator getCurrentAllocator() {
|
||||
// for now, only one adapter is supported
|
||||
Enumeration<ConsoleProxyAllocator> it = _consoleProxyAllocators.enumeration();
|
||||
if (it.hasMoreElements()) {
|
||||
return it.nextElement();
|
||||
}
|
||||
|
||||
for(ConsoleProxyAllocator allocator : _consoleProxyAllocators) {
|
||||
return allocator;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1512,11 +1512,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
value = agentMgrConfigs.get("port");
|
||||
_mgmt_port = NumbersUtil.parseInt(value, 8250);
|
||||
|
||||
_consoleProxyAllocators = locator.getAdapters(ConsoleProxyAllocator.class);
|
||||
if (_consoleProxyAllocators == null || !_consoleProxyAllocators.isSet()) {
|
||||
throw new ConfigurationException("Unable to get proxy allocators");
|
||||
}
|
||||
|
||||
_listener = new ConsoleProxyListener(this);
|
||||
_agentMgr.registerForHostEvents(_listener, true, true, false);
|
||||
|
||||
|
||||
@ -120,10 +120,11 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
|
||||
@Inject
|
||||
ClusterDetailsDao _clusterDetailsDao;
|
||||
long _serverId;
|
||||
@com.cloud.utils.component.Inject(adapter = Investigator.class)
|
||||
Adapters<Investigator> _investigators;
|
||||
@com.cloud.utils.component.Inject(adapter = FenceBuilder.class)
|
||||
Adapters<FenceBuilder> _fenceBuilders;
|
||||
|
||||
@Inject
|
||||
List<Investigator> _investigators;
|
||||
@Inject
|
||||
List<FenceBuilder> _fenceBuilders;
|
||||
@Inject
|
||||
AgentManager _agentMgr;
|
||||
@Inject
|
||||
@ -164,11 +165,8 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
|
||||
return null;
|
||||
}
|
||||
|
||||
final Enumeration<Investigator> en = _investigators.enumeration();
|
||||
Status hostState = null;
|
||||
Investigator investigator = null;
|
||||
while (en.hasMoreElements()) {
|
||||
investigator = en.nextElement();
|
||||
for(Investigator investigator : _investigators) {
|
||||
hostState = investigator.isAgentAlive(host);
|
||||
if (hostState != null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@ -419,22 +417,20 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
|
||||
return null;
|
||||
}
|
||||
|
||||
Enumeration<Investigator> en = _investigators.enumeration();
|
||||
Investigator investigator = null;
|
||||
while (en.hasMoreElements()) {
|
||||
investigator = en.nextElement();
|
||||
for(Investigator it : _investigators) {
|
||||
investigator = it;
|
||||
alive = investigator.isVmAlive(vm, host);
|
||||
s_logger.info(investigator.getName() + " found " + vm + "to be alive? " + alive);
|
||||
if (alive != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean fenced = false;
|
||||
if (alive == null) {
|
||||
s_logger.debug("Fencing off VM that we don't know the state of");
|
||||
Enumeration<FenceBuilder> enfb = _fenceBuilders.enumeration();
|
||||
while (enfb.hasMoreElements()) {
|
||||
FenceBuilder fb = enfb.nextElement();
|
||||
for(FenceBuilder fb : _fenceBuilders) {
|
||||
Boolean result = fb.fenceOff(vm, host);
|
||||
s_logger.info("Fencer " + fb.getName() + " returned " + result);
|
||||
if (result != null && result) {
|
||||
@ -442,6 +438,7 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (!alive) {
|
||||
fenced = true;
|
||||
} else {
|
||||
@ -697,9 +694,6 @@ public class HighAvailabilityManagerImpl implements HighAvailabilityManager, Clu
|
||||
|
||||
_serverId = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getId();
|
||||
|
||||
_investigators = locator.getAdapters(Investigator.class);
|
||||
_fenceBuilders = locator.getAdapters(FenceBuilder.class);
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
final ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
|
||||
if (configDao != null) {
|
||||
|
||||
@ -17,8 +17,10 @@
|
||||
package com.cloud.hypervisor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
@ -42,19 +44,21 @@ public class HypervisorGuruManagerImpl implements HypervisorGuruManager {
|
||||
@Inject HostDao _hostDao;
|
||||
|
||||
String _name;
|
||||
|
||||
@Inject List<HypervisorGuru> _hvGuruList;
|
||||
Map<HypervisorType, HypervisorGuru> _hvGurus = new HashMap<HypervisorType, HypervisorGuru>();
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
_name = name;
|
||||
ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
||||
|
||||
Adapters<HypervisorGuru> hvGurus = locator.getAdapters(HypervisorGuru.class);
|
||||
for (HypervisorGuru guru : hvGurus) {
|
||||
_hvGurus.put(guru.getHypervisorType(), guru);
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
for(HypervisorGuru guru : _hvGuruList) {
|
||||
_hvGurus.put(guru.getHypervisorType(), guru);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -23,6 +23,8 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.xml.DOMConfigurator;
|
||||
|
||||
import com.cloud.configuration.Resource;
|
||||
@ -54,16 +56,17 @@ import com.cloud.vm.dao.InstanceGroupDao;
|
||||
import com.cloud.vm.dao.InstanceGroupVMMapDao;
|
||||
|
||||
public class Db21to22MigrationUtil {
|
||||
private ClusterDao _clusterDao;
|
||||
private HostDao _hostDao;
|
||||
private AccountDao _accountDao;
|
||||
private DomainDao _domainDao;
|
||||
private ResourceCountDao _resourceCountDao;
|
||||
private InstanceGroupDao _vmGroupDao;
|
||||
private InstanceGroupVMMapDao _groupVMMapDao;
|
||||
private ConfigurationDao _configurationDao;
|
||||
private DataCenterDao _zoneDao;
|
||||
private ResourceManager _resourceMgr;
|
||||
|
||||
@Inject private ClusterDao _clusterDao;
|
||||
@Inject private HostDao _hostDao;
|
||||
@Inject private AccountDao _accountDao;
|
||||
@Inject private DomainDao _domainDao;
|
||||
@Inject private ResourceCountDao _resourceCountDao;
|
||||
@Inject private InstanceGroupDao _vmGroupDao;
|
||||
@Inject private InstanceGroupVMMapDao _groupVMMapDao;
|
||||
@Inject private ConfigurationDao _configurationDao;
|
||||
@Inject private DataCenterDao _zoneDao;
|
||||
@Inject private ResourceManager _resourceMgr;
|
||||
|
||||
private void doMigration() {
|
||||
setupComponents();
|
||||
@ -171,16 +174,6 @@ public class Db21to22MigrationUtil {
|
||||
}
|
||||
|
||||
private void setupComponents() {
|
||||
ComponentLocator locator = ComponentLocator.getLocator("migration", "migration-components.xml", "log4j-cloud.xml");
|
||||
|
||||
_accountDao = locator.getDao(AccountDao.class);
|
||||
_domainDao = locator.getDao(DomainDao.class);
|
||||
_resourceCountDao = locator.getDao(ResourceCountDao.class);
|
||||
_vmGroupDao = locator.getDao(InstanceGroupDao.class);
|
||||
_groupVMMapDao = locator.getDao(InstanceGroupVMMapDao.class);
|
||||
_configurationDao = locator.getDao(ConfigurationDao.class);
|
||||
_zoneDao = locator.getDao(DataCenterDao.class);
|
||||
_resourceMgr = locator.getManager(ResourceManager.class);
|
||||
}
|
||||
|
||||
private void setupInstanceGroups() {
|
||||
|
||||
@ -305,7 +305,9 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
private final SSHKeyPairDao _sshKeyPairDao;
|
||||
private final LoadBalancerDao _loadbalancerDao;
|
||||
private final HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
|
||||
private final Adapters<HostAllocator> _hostAllocators;
|
||||
|
||||
@Inject
|
||||
private List<HostAllocator> _hostAllocators;
|
||||
private final ConfigurationManager _configMgr;
|
||||
private final ResourceTagDao _resourceTagDao;
|
||||
|
||||
@ -387,11 +389,6 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
|
||||
_hypervisorCapabilitiesDao = locator.getDao(HypervisorCapabilitiesDao.class);
|
||||
|
||||
_hostAllocators = locator.getAdapters(HostAllocator.class);
|
||||
if (_hostAllocators == null || !_hostAllocators.isSet()) {
|
||||
s_logger.error("Unable to find HostAllocators");
|
||||
}
|
||||
|
||||
String value = _configs.get("event.purge.interval");
|
||||
int cleanup = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 day.
|
||||
|
||||
@ -961,15 +958,14 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
List<Host> suitableHosts = new ArrayList<Host>();
|
||||
Enumeration<HostAllocator> enHost = _hostAllocators.enumeration();
|
||||
|
||||
VirtualMachineProfile<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
|
||||
|
||||
DataCenterDeployment plan = new DataCenterDeployment(srcHost.getDataCenterId(), srcHost.getPodId(), srcHost.getClusterId(), null, null, null);
|
||||
ExcludeList excludes = new ExcludeList();
|
||||
excludes.addHost(srcHostId);
|
||||
while (enHost.hasMoreElements()) {
|
||||
final HostAllocator allocator = enHost.nextElement();
|
||||
|
||||
for(HostAllocator allocator : _hostAllocators) {
|
||||
suitableHosts = allocator.allocateTo(vmProfile, plan, Host.Type.Routing, excludes, HostAllocator.RETURN_UPTO_ALL, false);
|
||||
if (suitableHosts != null && !suitableHosts.isEmpty()) {
|
||||
break;
|
||||
|
||||
@ -222,7 +222,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
@Inject
|
||||
Site2SiteVpnManager _vpnMgr;
|
||||
|
||||
private Adapters<UserAuthenticator> _userAuthenticators;
|
||||
@Inject
|
||||
private List<UserAuthenticator> _userAuthenticators;
|
||||
|
||||
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AccountChecker"));
|
||||
|
||||
@ -230,8 +231,9 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
|
||||
UserVO _systemUser;
|
||||
AccountVO _systemAccount;
|
||||
@com.cloud.utils.component.Inject(adapter = SecurityChecker.class)
|
||||
Adapters<SecurityChecker> _securityCheckers;
|
||||
|
||||
@Inject
|
||||
List<SecurityChecker> _securityCheckers;
|
||||
int _cleanupInterval;
|
||||
|
||||
@Override
|
||||
@ -258,11 +260,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
String value = configs.get(Config.AccountCleanupInterval.key());
|
||||
_cleanupInterval = NumbersUtil.parseInt(value, 60 * 60 * 24); // 1 day.
|
||||
|
||||
_userAuthenticators = locator.getAdapters(UserAuthenticator.class);
|
||||
if (_userAuthenticators == null || !_userAuthenticators.isSet()) {
|
||||
s_logger.error("Unable to find an user authenticator.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1825,8 +1822,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
|
||||
}
|
||||
|
||||
boolean authenticated = false;
|
||||
for (Enumeration<UserAuthenticator> en = _userAuthenticators.enumeration(); en.hasMoreElements();) {
|
||||
UserAuthenticator authenticator = en.nextElement();
|
||||
for(UserAuthenticator authenticator : _userAuthenticators) {
|
||||
if (authenticator.authenticate(username, password, domainId, requestParameters)) {
|
||||
authenticated = true;
|
||||
break;
|
||||
|
||||
@ -19,7 +19,7 @@ package com.cloud.utils.db;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DbAnnotatedBaseDerived {
|
||||
public class DbAnnotatedBaseDerived extends DbAnnotatedBase {
|
||||
|
||||
@DB
|
||||
public void DbAnnotatedMethod() {
|
||||
|
||||
@ -16,6 +16,9 @@
|
||||
// under the License.
|
||||
package com.cloud.utils.db;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.junit.Test;
|
||||
@ -28,12 +31,15 @@ import com.cloud.utils.component.ComponentContext;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="classpath:/com/cloud/utils/db/transactioncontextBuilderTest.xml")
|
||||
public class TransactionContextBuilderTest {
|
||||
|
||||
@Inject
|
||||
DbAnnotatedBaseDerived _derived;
|
||||
|
||||
@Inject
|
||||
DbAnnotatedBase _base;
|
||||
|
||||
@Inject
|
||||
List<DbAnnotatedBase> _list;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
// _derived.DbAnnotatedMethod();
|
||||
@ -42,5 +48,16 @@ public class TransactionContextBuilderTest {
|
||||
// test @DB injection on dynamically constructed objects
|
||||
DbAnnotatedBase base = ComponentContext.inject(new DbAnnotatedBase());
|
||||
base.MethodWithClassDbAnnotated();
|
||||
|
||||
/*
|
||||
Map<String, DbAnnotatedBase> components = ComponentContext.getApplicationContext().getBeansOfType(DbAnnotatedBase.class);
|
||||
for(Map.Entry<String, DbAnnotatedBase> entry : components.entrySet()) {
|
||||
System.out.println(entry.getKey());
|
||||
entry.getValue().MethodWithClassDbAnnotated();
|
||||
}
|
||||
*/
|
||||
for(DbAnnotatedBase entry : _list) {
|
||||
entry.MethodWithClassDbAnnotated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user