mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-17 02:53:18 +01:00
Work with Spring proxy-ed object
This commit is contained in:
parent
a4f4c98670
commit
32e67f60d4
@ -113,13 +113,13 @@ public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProvider
|
|||||||
@Override
|
@Override
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean stop() {
|
public boolean stop() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -74,13 +74,13 @@ public class PrimaryDataStoreProviderManagerImpl implements PrimaryDataStoreProv
|
|||||||
@Override
|
@Override
|
||||||
public boolean start() {
|
public boolean start() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean stop() {
|
public boolean stop() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -218,7 +218,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||||||
|
|
||||||
protected int _pingInterval;
|
protected int _pingInterval;
|
||||||
protected long _pingTimeout;
|
protected long _pingTimeout;
|
||||||
@Inject protected AgentMonitor _monitor = null;
|
@Inject protected AgentMonitor _monitor;
|
||||||
|
|
||||||
protected ExecutorService _executor;
|
protected ExecutorService _executor;
|
||||||
|
|
||||||
@ -401,7 +401,6 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendToSSVM(final long dcId, final Command cmd, final Listener listener) throws AgentUnavailableException {
|
private void sendToSSVM(final long dcId, final Command cmd, final Listener listener) throws AgentUnavailableException {
|
||||||
List<HostVO> ssAHosts = _ssvmMgr.listUpAndConnectingSecondaryStorageVmHost(dcId);
|
List<HostVO> ssAHosts = _ssvmMgr.listUpAndConnectingSecondaryStorageVmHost(dcId);
|
||||||
if (ssAHosts == null || ssAHosts.isEmpty() ) {
|
if (ssAHosts == null || ssAHosts.isEmpty() ) {
|
||||||
|
|||||||
@ -60,24 +60,22 @@ public class AgentMonitor extends Thread implements Listener {
|
|||||||
private static Logger s_logger = Logger.getLogger(AgentMonitor.class);
|
private static Logger s_logger = Logger.getLogger(AgentMonitor.class);
|
||||||
private static Logger status_Logger = Logger.getLogger(Status.class);
|
private static Logger status_Logger = Logger.getLogger(Status.class);
|
||||||
private long _pingTimeout;
|
private long _pingTimeout;
|
||||||
private HostDao _hostDao;
|
@Inject private HostDao _hostDao;
|
||||||
private boolean _stop;
|
private boolean _stop;
|
||||||
private AgentManagerImpl _agentMgr;
|
@Inject private AgentManagerImpl _agentMgr;
|
||||||
private VMInstanceDao _vmDao;
|
@Inject private VMInstanceDao _vmDao;
|
||||||
private DataCenterDao _dcDao = null;
|
@Inject private DataCenterDao _dcDao = null;
|
||||||
private HostPodDao _podDao = null;
|
@Inject private HostPodDao _podDao = null;
|
||||||
private AlertManager _alertMgr;
|
@Inject private AlertManager _alertMgr;
|
||||||
private long _msId;
|
private long _msId;
|
||||||
private ConnectionConcierge _concierge;
|
private ConnectionConcierge _concierge;
|
||||||
@Inject
|
@Inject ClusterDao _clusterDao;
|
||||||
ClusterDao _clusterDao;
|
@Inject ResourceManager _resourceMgr;
|
||||||
@Inject
|
|
||||||
ResourceManager _resourceMgr;
|
|
||||||
|
|
||||||
// private ConnectionConcierge _concierge;
|
// private ConnectionConcierge _concierge;
|
||||||
private Map<Long, Long> _pingMap;
|
private Map<Long, Long> _pingMap;
|
||||||
|
|
||||||
protected AgentMonitor() {
|
public AgentMonitor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public AgentMonitor(long msId, HostDao hostDao, VMInstanceDao vmDao, DataCenterDao dcDao, HostPodDao podDao, AgentManagerImpl agentMgr, AlertManager alertMgr, long pingTimeout) {
|
public AgentMonitor(long msId, HostDao hostDao, VMInstanceDao vmDao, DataCenterDao dcDao, HostPodDao podDao, AgentManagerImpl agentMgr, AlertManager alertMgr, long pingTimeout) {
|
||||||
|
|||||||
@ -43,9 +43,14 @@ import javax.annotation.PostConstruct;
|
|||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.management.InstanceAlreadyExistsException;
|
||||||
|
import javax.management.MBeanRegistrationException;
|
||||||
|
import javax.management.MalformedObjectNameException;
|
||||||
|
import javax.management.NotCompliantMBeanException;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import com.cloud.acl.SecurityChecker.AccessType;
|
import com.cloud.acl.SecurityChecker.AccessType;
|
||||||
@ -218,9 +223,11 @@ import com.cloud.utils.NumbersUtil;
|
|||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.PasswordGenerator;
|
import com.cloud.utils.PasswordGenerator;
|
||||||
import com.cloud.utils.Ternary;
|
import com.cloud.utils.Ternary;
|
||||||
|
import com.cloud.utils.component.Adapter;
|
||||||
import com.cloud.utils.component.Adapters;
|
import com.cloud.utils.component.Adapters;
|
||||||
import com.cloud.utils.component.ComponentContext;
|
import com.cloud.utils.component.ComponentContext;
|
||||||
import com.cloud.utils.component.ComponentLocator;
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
|
import com.cloud.utils.component.Manager;
|
||||||
import com.cloud.utils.component.SystemIntegrityChecker;
|
import com.cloud.utils.component.SystemIntegrityChecker;
|
||||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||||
import com.cloud.utils.crypt.DBEncryptionUtil;
|
import com.cloud.utils.crypt.DBEncryptionUtil;
|
||||||
@ -234,6 +241,8 @@ import com.cloud.utils.db.SearchBuilder;
|
|||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
import com.cloud.utils.db.Transaction;
|
import com.cloud.utils.db.Transaction;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
|
import com.cloud.utils.mgmt.JmxUtil;
|
||||||
|
import com.cloud.utils.mgmt.ManagementBean;
|
||||||
import com.cloud.utils.net.MacAddress;
|
import com.cloud.utils.net.MacAddress;
|
||||||
import com.cloud.utils.net.NetUtils;
|
import com.cloud.utils.net.NetUtils;
|
||||||
import com.cloud.utils.ssh.SSHKeysHelper;
|
import com.cloud.utils.ssh.SSHKeysHelper;
|
||||||
@ -368,13 +377,8 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
private void initCloudStackComponents() {
|
private void initCloudStackComponents() {
|
||||||
runCheckers();
|
runCheckers();
|
||||||
startDaos(); // daos should not be using managers and adapters.
|
startDaos(); // daos should not be using managers and adapters.
|
||||||
|
|
||||||
/*
|
|
||||||
configureManagers();
|
|
||||||
configureAdapters();
|
|
||||||
startManagers();
|
startManagers();
|
||||||
startAdapters();
|
startAdapters();
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runCheckers() {
|
private void runCheckers() {
|
||||||
@ -385,7 +389,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
try {
|
try {
|
||||||
checker.check();
|
checker.check();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
s_logger.error("Problems with running checker:" + checker.getClass().getName(), e);
|
s_logger.error("Problems with running checker:" + ComponentContext.getTargetClass(checker).getName(), e);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -398,15 +402,92 @@ public class ManagementServerImpl implements ManagementServer {
|
|||||||
|
|
||||||
for(GenericDaoBase dao : daos.values()) {
|
for(GenericDaoBase dao : daos.values()) {
|
||||||
try {
|
try {
|
||||||
|
s_logger.info("Starting dao " + ComponentContext.getTargetClass(dao).getName());
|
||||||
|
|
||||||
|
// TODO
|
||||||
// dao.configure(dao.getClass().getSimpleName(), params);
|
// dao.configure(dao.getClass().getSimpleName(), params);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
s_logger.error("Problems with running checker:" + dao.getClass().getName(), e);
|
s_logger.error("Problems with running checker:" + ComponentContext.getTargetClass(dao).getName(), e);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startManagers() {
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
Map<String, Manager> managers = ComponentContext.getApplicationContext().getBeansOfType(
|
||||||
|
Manager.class);
|
||||||
|
|
||||||
|
Map<String, Object> params = new HashMap<String, Object>();
|
||||||
|
for(Manager manager : managers.values()) {
|
||||||
|
s_logger.info("Start manager: " + ComponentContext.getTargetClass(manager).getName() + "...");
|
||||||
|
try {
|
||||||
|
if(!ComponentContext.isPrimary(manager, Manager.class)) {
|
||||||
|
s_logger.error("Skip manager:" + ComponentContext.getTargetClass(manager).getName() + " as there are multiple matches");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!manager.configure(manager.getClass().getSimpleName(), params)) {
|
||||||
|
throw new CloudRuntimeException("Failed to start manager: " + ComponentContext.getTargetClass(manager).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!manager.start()) {
|
||||||
|
throw new CloudRuntimeException("Failed to start manager: " + ComponentContext.getTargetClass(manager).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (manager instanceof ManagementBean) {
|
||||||
|
registerMBean((ManagementBean)manager);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
s_logger.error("Problems to start manager:" + ComponentContext.getTargetClass(manager).getName(), e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startAdapters() {
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
Map<String, Adapter> adapters = ComponentContext.getApplicationContext().getBeansOfType(
|
||||||
|
Adapter.class);
|
||||||
|
|
||||||
|
Map<String, Object> params = new HashMap<String, Object>();
|
||||||
|
for(Adapter adapter : adapters.values()) {
|
||||||
|
try {
|
||||||
|
if(!ComponentContext.isPrimary(adapter, Adapter.class))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!adapter.configure(adapter.getClass().getSimpleName(), params)) {
|
||||||
|
throw new CloudRuntimeException("Failed to start adapter: " + ComponentContext.getTargetClass(adapter).getName());
|
||||||
|
}
|
||||||
|
if (!adapter.start()) {
|
||||||
|
throw new CloudRuntimeException("Failed to start adapter: " + ComponentContext.getTargetClass(adapter).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (adapter instanceof ManagementBean) {
|
||||||
|
registerMBean((ManagementBean)adapter);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
s_logger.error("Problems to start manager:" + ComponentContext.getTargetClass(adapter).getName(), e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void registerMBean(ManagementBean mbean) {
|
||||||
|
try {
|
||||||
|
JmxUtil.registerMBean(mbean);
|
||||||
|
} catch (MalformedObjectNameException e) {
|
||||||
|
s_logger.warn("Unable to register MBean: " + mbean.getName(), e);
|
||||||
|
} catch (InstanceAlreadyExistsException e) {
|
||||||
|
s_logger.warn("Unable to register MBean: " + mbean.getName(), e);
|
||||||
|
} catch (MBeanRegistrationException e) {
|
||||||
|
s_logger.warn("Unable to register MBean: " + mbean.getName(), e);
|
||||||
|
} catch (NotCompliantMBeanException e) {
|
||||||
|
s_logger.warn("Unable to register MBean: " + mbean.getName(), e);
|
||||||
|
}
|
||||||
|
s_logger.info("Registered MBean: " + mbean.getName());
|
||||||
|
}
|
||||||
|
|
||||||
protected Map<String, String> getConfigs() {
|
protected Map<String, String> getConfigs() {
|
||||||
return _configs;
|
return _configs;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,7 +21,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.aop.Advisor;
|
import org.springframework.aop.Advisor;
|
||||||
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||||
@ -30,6 +32,7 @@ import org.springframework.context.ApplicationContextAware;
|
|||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.cloud.utils.component.ComponentContext;
|
||||||
import com.cloud.utils.db.TransactionContextBuilder;
|
import com.cloud.utils.db.TransactionContextBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,7 +68,7 @@ public class ComponentContext implements ApplicationContextAware {
|
|||||||
Map<String, T> matchedTypes = getComponentsOfType(beanType);
|
Map<String, T> matchedTypes = getComponentsOfType(beanType);
|
||||||
if(matchedTypes.size() > 0) {
|
if(matchedTypes.size() > 0) {
|
||||||
for(Map.Entry<String, T> entry : matchedTypes.entrySet()) {
|
for(Map.Entry<String, T> entry : matchedTypes.entrySet()) {
|
||||||
Primary primary = entry.getClass().getAnnotation(Primary.class);
|
Primary primary = getTargetClass(entry).getAnnotation(Primary.class);
|
||||||
if(primary != null)
|
if(primary != null)
|
||||||
return entry.getValue();
|
return entry.getValue();
|
||||||
}
|
}
|
||||||
@ -81,6 +84,30 @@ public class ComponentContext implements ApplicationContextAware {
|
|||||||
return s_appContext.getBeansOfType(beanType);
|
return s_appContext.getBeansOfType(beanType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> boolean isPrimary(Object instance, Class<T> beanType) {
|
||||||
|
Map<String, T> matchedTypes = ComponentContext.getComponentsOfType(beanType);
|
||||||
|
if(matchedTypes.size() > 1) {
|
||||||
|
Primary primary = getTargetClass(instance).getAnnotation(Primary.class);
|
||||||
|
if(primary != null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class<?> getTargetClass(Object instance) {
|
||||||
|
if(instance instanceof Advised) {
|
||||||
|
try {
|
||||||
|
return ((Advised)instance).getTargetSource().getTarget().getClass();
|
||||||
|
} catch(Exception e) {
|
||||||
|
return instance.getClass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance.getClass();
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> T inject(Class<T> clz) {
|
public static <T> T inject(Class<T> clz) {
|
||||||
T instance = s_appContext.getAutowireCapableBeanFactory().createBean(clz);
|
T instance = s_appContext.getAutowireCapableBeanFactory().createBean(clz);
|
||||||
return inject(instance);
|
return inject(instance);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user