mirror of https://github.com/apache/cloudstack.git
Seperate configurable components out and let them be loaded from Spring configuration file
This commit is contained in:
parent
ad2cd775e0
commit
cf5d935d81
|
|
@ -165,6 +165,7 @@ public abstract class BaseCmd {
|
|||
_autoScaleService = locator.getManager(AutoScaleService.class);
|
||||
_ravService = locator.getManager(RemoteAccessVpnService.class);
|
||||
_responseGenerator = generator;
|
||||
<<<<<<< HEAD
|
||||
_bareMetalVmService = locator.getManager(BareMetalVmService.class);
|
||||
_projectService = locator.getManager(ProjectService.class);
|
||||
_firewallService = locator.getManager(FirewallService.class);
|
||||
|
|
@ -177,6 +178,19 @@ public abstract class BaseCmd {
|
|||
_networkACLService = locator.getManager(NetworkACLService.class);
|
||||
_s2sVpnService = locator.getManager(Site2SiteVpnService.class);
|
||||
_queryService = locator.getManager(QueryService.class);
|
||||
=======
|
||||
//_bareMetalVmService = ComponentContext.getCompanent(BareMetalVmService.class);
|
||||
_projectService = ComponentContext.getCompanent(ProjectService.class);
|
||||
_firewallService = ComponentContext.getCompanent(FirewallService.class);
|
||||
_domainService = ComponentContext.getCompanent(DomainService.class);
|
||||
_resourceLimitService = ComponentContext.getCompanent(ResourceLimitService.class);
|
||||
_identityService = ComponentContext.getCompanent(IdentityService.class);
|
||||
_storageNetworkService = ComponentContext.getCompanent(StorageNetworkService.class);
|
||||
_taggedResourceService = ComponentContext.getCompanent(TaggedResourceService.class);
|
||||
_vpcService = ComponentContext.getCompanent(VpcService.class);
|
||||
_networkACLService = ComponentContext.getCompanent(NetworkACLService.class);
|
||||
_s2sVpnService = ComponentContext.getCompanent(Site2SiteVpnService.class);
|
||||
>>>>>>> Seperate configurable components out and let them be loaded from Spring configuration file
|
||||
}
|
||||
|
||||
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,14 @@
|
|||
|
||||
<bean id="eventBus" class = "org.apache.cloudstack.framework.eventbus.EventBusBase" />
|
||||
|
||||
<!--
|
||||
Configurable components
|
||||
-->
|
||||
<bean id="ManagementServerExtImpl" class ="com.cloud.server.ManagementServerExtImpl" />
|
||||
<bean id="userVmManager" class ="com.cloud.vm.UserVmManagerImpl" />
|
||||
|
||||
<bean id="ClusteredAgentManagerImpl" class ="com.cloud.agent.manager.ClusteredAgentManagerImpl" />
|
||||
<bean id="ClusteredVirtualMachineManagerImpl" class ="com.cloud.vm.ClusteredVirtualMachineManagerImpl" />
|
||||
<bean id="NetworkManagerImpl" class ="com.cloud.network.NetworkManagerImpl" />
|
||||
<bean id="SecondaryStorageManagerImpl" class ="com.cloud.storage.secondary.SecondaryStorageManagerImpl" />
|
||||
<bean id="HighAvailabilityManagerExtImpl" class ="com.cloud.ha.HighAvailabilityManagerExtImpl" />
|
||||
</beans>
|
||||
|
|
|
|||
|
|
@ -139,7 +139,6 @@ import edu.emory.mathcs.backport.java.util.Collections;
|
|||
* ping.interval before announcing an agent has timed out | float | 2.0x || || router.stats.interval | interval to
|
||||
* report router statistics | seconds | 300s || * }
|
||||
**/
|
||||
@Component
|
||||
@Local(value = { AgentManager.class })
|
||||
public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
||||
private static final Logger s_logger = Logger.getLogger(AgentManagerImpl.class);
|
||||
|
|
|
|||
|
|
@ -91,8 +91,6 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||
import com.cloud.utils.nio.Link;
|
||||
import com.cloud.utils.nio.Task;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
@Local(value = { AgentManager.class, ClusteredAgentRebalanceService.class })
|
||||
public class ClusteredAgentManagerImpl extends AgentManagerImpl implements ClusterManagerListener, ClusteredAgentRebalanceService {
|
||||
final static Logger s_logger = Logger.getLogger(ClusteredAgentManagerImpl.class);
|
||||
|
|
|
|||
|
|
@ -24,18 +24,11 @@ import javax.ejb.Local;
|
|||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.usage.dao.UsageJobDao;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
@Local(value={HighAvailabilityManager.class})
|
||||
public class HighAvailabilityManagerExtImpl extends HighAvailabilityManagerImpl {
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package com.cloud.ha;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -32,7 +31,6 @@ import javax.naming.ConfigurationException;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.NDC;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.alert.AlertManager;
|
||||
|
|
@ -66,8 +64,6 @@ import com.cloud.storage.dao.GuestOSCategoryDao;
|
|||
import com.cloud.storage.dao.GuestOSDao;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.component.Adapters;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
|
|
@ -99,7 +95,6 @@ import com.cloud.vm.dao.VMInstanceDao;
|
|||
* ha.retry.wait | time to wait before retrying the work item | seconds | 120 || || stop.retry.wait | time to wait
|
||||
* before retrying the stop | seconds | 120 || * }
|
||||
**/
|
||||
@Component
|
||||
@Local(value = { HighAvailabilityManager.class })
|
||||
public class HighAvailabilityManagerImpl implements HighAvailabilityManager, ClusterManagerListener {
|
||||
protected static final Logger s_logger = Logger.getLogger(HighAvailabilityManagerImpl.class);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementors
|
|||
import org.apache.cloudstack.api.command.user.network.CreateNetworkCmd;
|
||||
import org.apache.cloudstack.api.command.user.network.RestartNetworkCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
||||
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
|
||||
|
|
@ -174,7 +173,6 @@ import java.util.*;
|
|||
/**
|
||||
* NetworkManagerImpl implements NetworkManager.
|
||||
*/
|
||||
@Component
|
||||
@Local(value = { NetworkManager.class, NetworkService.class })
|
||||
public class NetworkManagerImpl implements NetworkManager, NetworkService, Manager, Listener {
|
||||
private static final Logger s_logger = Logger.getLogger(NetworkManagerImpl.class);
|
||||
|
|
|
|||
|
|
@ -49,8 +49,6 @@ import com.cloud.vm.SystemVmLoadScanner.AfterScanAction;
|
|||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.dao.SecondaryStorageVmDao;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
@Local(value = { SecondaryStorageVmManager.class })
|
||||
public class PremiumSecondaryStorageManagerImpl extends SecondaryStorageManagerImpl {
|
||||
private static final Logger s_logger = Logger.getLogger(PremiumSecondaryStorageManagerImpl.class);
|
||||
|
|
|
|||
|
|
@ -26,9 +26,6 @@ import java.util.TimeZone;
|
|||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.commands.GenerateUsageRecordsCmd;
|
||||
import com.cloud.api.commands.GetUsageRecordsCmd;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
|
|
@ -49,8 +46,6 @@ import com.cloud.utils.db.Filter;
|
|||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
public class ManagementServerExtImpl extends ManagementServerImpl implements ManagementServerExt {
|
||||
@Inject private AccountDao _accountDao;
|
||||
@Inject private DomainDao _domainDao;
|
||||
|
|
|
|||
|
|
@ -266,7 +266,6 @@ import com.cloud.vm.dao.VMInstanceDao;
|
|||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
import edu.emory.mathcs.backport.java.util.Collections;
|
||||
|
||||
@Component
|
||||
public class ManagementServerImpl implements ManagementServer {
|
||||
public static final Logger s_logger = Logger.getLogger(ManagementServerImpl.class.getName());
|
||||
|
||||
|
|
@ -463,20 +462,15 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}
|
||||
|
||||
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)) {
|
||||
@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(!manager.configure(manager.getClass().getSimpleName(), params)) {
|
||||
throw new CloudRuntimeException("Failed to start manager: " + ComponentContext.getTargetClass(manager).getName());
|
||||
}
|
||||
|
||||
|
|
@ -495,17 +489,18 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}
|
||||
|
||||
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)) {
|
||||
@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 {
|
||||
// we also skip Adapter class that is both a manager class and a adapter class
|
||||
if(Manager.class.isAssignableFrom(ComponentContext.getTargetClass(adapter)))
|
||||
continue;
|
||||
|
||||
if(!adapter.configure(adapter.getClass().getSimpleName(), params)) {
|
||||
throw new CloudRuntimeException("Failed to start adapter: " + ComponentContext.getTargetClass(adapter).getName());
|
||||
}
|
||||
if (!adapter.start()) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import java.net.URISyntaxException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -31,7 +30,6 @@ import javax.inject.Inject;
|
|||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
|
@ -112,8 +110,6 @@ import com.cloud.user.UserContext;
|
|||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Adapters;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
|
|
@ -157,7 +153,6 @@ import com.cloud.vm.dao.VMInstanceDao;
|
|||
// Starting, HA, Migrating, Creating and Running state are all counted as "Open" for available capacity calculation
|
||||
// because sooner or later, it will be driven into Running state
|
||||
//
|
||||
@Component
|
||||
@Local(value = { SecondaryStorageVmManager.class })
|
||||
public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, VirtualMachineGuru<SecondaryStorageVmVO>, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
|
||||
private static final Logger s_logger = Logger.getLogger(SecondaryStorageManagerImpl.class);
|
||||
|
|
|
|||
|
|
@ -22,14 +22,9 @@ import java.util.Map;
|
|||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.cluster.ClusterManagerListener;
|
||||
import com.cloud.cluster.ManagementServerHostVO;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
@Local(value=VirtualMachineManager.class)
|
||||
public class ClusteredVirtualMachineManagerImpl extends VirtualMachineManagerImpl implements ClusterManagerListener {
|
||||
|
||||
|
|
|
|||
|
|
@ -158,7 +158,6 @@ import com.cloud.vm.dao.SecondaryStorageVmDao;
|
|||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
@Component
|
||||
@Local(value = VirtualMachineManager.class)
|
||||
public class VirtualMachineManagerImpl implements VirtualMachineManager, Listener {
|
||||
private static final Logger s_logger = Logger.getLogger(VirtualMachineManagerImpl.class);
|
||||
|
|
|
|||
|
|
@ -67,16 +67,22 @@ public class ComponentContext implements ApplicationContextAware {
|
|||
Map<String, T> matchedTypes = getComponentsOfType(beanType);
|
||||
if(matchedTypes.size() > 0) {
|
||||
for(Map.Entry<String, T> entry : matchedTypes.entrySet()) {
|
||||
Primary primary = getTargetClass(entry).getAnnotation(Primary.class);
|
||||
Primary primary = getTargetClass(entry.getValue()).getAnnotation(Primary.class);
|
||||
if(primary != null)
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
s_logger.warn("Unable to uniquely locate bean type " + beanType.getName());
|
||||
if(matchedTypes.size() > 1) {
|
||||
s_logger.warn("Unable to uniquely locate bean type " + beanType.getName());
|
||||
for(Map.Entry<String, T> entry : matchedTypes.entrySet()) {
|
||||
s_logger.warn("Candidate " + getTargetClass(entry.getValue()).getName());
|
||||
}
|
||||
}
|
||||
|
||||
return (T)matchedTypes.values().toArray()[0];
|
||||
}
|
||||
}
|
||||
throw new NoSuchBeanDefinitionException("Unable to resolve bean type " + beanType.getName());
|
||||
throw new NoSuchBeanDefinitionException(beanType.getName());
|
||||
}
|
||||
|
||||
public static <T> Map<String, T> getComponentsOfType(Class<T> beanType) {
|
||||
|
|
@ -84,13 +90,13 @@ public class ComponentContext implements ApplicationContextAware {
|
|||
}
|
||||
|
||||
public static <T> boolean isPrimary(Object instance, Class<T> beanType) {
|
||||
|
||||
// we assume single line of interface inheritance of beanType
|
||||
Class<?> componentType = beanType;
|
||||
Class<?> targetClass = getTargetClass(instance);
|
||||
|
||||
Class<?> interfaces[] = targetClass.getInterfaces();
|
||||
for(Class<?> intf : interfaces) {
|
||||
if(beanType.isAssignableFrom(intf)) {
|
||||
if(beanType.isAssignableFrom(intf) && intf != beanType) {
|
||||
componentType = intf;
|
||||
break;
|
||||
}
|
||||
|
|
@ -99,9 +105,15 @@ public class ComponentContext implements ApplicationContextAware {
|
|||
Map<String, T> matchedTypes = (Map<String, T>)ComponentContext.getComponentsOfType(componentType);
|
||||
if(matchedTypes.size() > 1) {
|
||||
Primary primary = targetClass.getAnnotation(Primary.class);
|
||||
if(primary != null)
|
||||
if(primary != null) {
|
||||
s_logger.info(targetClass.getName() + " is the primary component of " + componentType.getName());
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
s_logger.warn(targetClass.getName() + " is not the primary component of " + componentType.getName() + ", there are other candidates");
|
||||
for(T candidate : matchedTypes.values()) {
|
||||
s_logger.warn("Candidate " + getTargetClass(candidate).getName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue