mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Compile complete
This commit is contained in:
parent
6e8ca99466
commit
b8e79c30a8
@ -41,6 +41,11 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-framework-config</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@ -109,5 +109,6 @@ public class SpringUtils {
|
||||
|
||||
return processor;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="messageBus" class = "org.apache.cloudstack.framework.messagebus.MessageBusBase" />
|
||||
<bean id="configDepot" class = "org.apache.cloudstack.framework.config.ConfigDepotImpl" />
|
||||
<bean id="configDepot" class = "org.apache.cloudstack.framework.config.impl.ConfigDepotImpl" />
|
||||
|
||||
<!--
|
||||
DAO with customized configuration
|
||||
@ -718,6 +718,7 @@
|
||||
<bean id="storageManagerImpl" class="com.cloud.storage.StorageManagerImpl"/>
|
||||
|
||||
<bean id="volumeOrchestrator" class="org.apache.cloudstack.engine.orchestration.VolumeOrchestrator">
|
||||
<property name="PodAllocators" value="#{podAllocators.Adapters}" />
|
||||
<property name="StoragePoolAllocators" value="#{storagePoolAllocators.Adapters}" />
|
||||
</bean>
|
||||
|
||||
@ -726,7 +727,6 @@
|
||||
</bean>
|
||||
|
||||
<bean id="resourceManagerImpl" class="com.cloud.resource.ResourceManagerImpl" >
|
||||
<property name="PodAllocators" value="#{podAllocators.Adapters}" />
|
||||
<property name="Discoverers" value="#{resourceDiscoverers.Adapters}" />
|
||||
</bean>
|
||||
|
||||
@ -739,7 +739,7 @@
|
||||
<property name="HostAllocators" value="#{hostAllocators.Adapters}" />
|
||||
</bean>
|
||||
|
||||
<bean id="networkManagerImpl" class="com.cloud.network.NetworkManagerImpl" >
|
||||
<bean id="networkOrchestrator" class="org.apache.cloudstack.engine.orchestration.NetworkOrchestrator" >
|
||||
<property name="NetworkGurus" value="#{networkGurus.Adapters}" />
|
||||
<property name="NetworkElements" value="#{networkElements.Adapters}" />
|
||||
<property name="IpDeployers" value="#{ipDeployers.Adapters}" />
|
||||
|
||||
@ -122,9 +122,6 @@ public interface AgentManager {
|
||||
|
||||
Answer sendTo(Long dcId, HypervisorType type, Command cmd);
|
||||
|
||||
/* working as a lock while agent is being loaded */
|
||||
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action);
|
||||
|
||||
// public AgentAttache handleDirectConnectAgent(HostVO host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException;
|
||||
|
||||
public boolean agentStatusTransitTo(HostVO host, Status.Event e, long msId);
|
||||
@ -138,4 +135,6 @@ public interface AgentManager {
|
||||
public void pullAgentOutMaintenance(long hostId);
|
||||
|
||||
boolean reconnect(long hostId);
|
||||
|
||||
void rescan();
|
||||
}
|
||||
|
||||
@ -654,6 +654,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rescan() {
|
||||
}
|
||||
|
||||
protected boolean loadDirectlyConnectedHost(HostVO host, boolean forRebalance) {
|
||||
boolean initialized = false;
|
||||
@ -683,7 +686,10 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
}
|
||||
|
||||
if (forRebalance) {
|
||||
tapLoadingAgents(host.getId(), TapAgentsAction.Add);
|
||||
Host h = _resourceMgr.createHostAndAgent(host.getId(), resource, host.getDetails(), false, null, true);
|
||||
tapLoadingAgents(host.getId(), TapAgentsAction.Del);
|
||||
|
||||
return (h == null ? false : true);
|
||||
} else {
|
||||
_executor.execute(new SimulateStartTask(host.getId(), resource, host.getDetails()));
|
||||
@ -1054,7 +1060,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
s_logger.debug("Simulating start for resource " + resource.getName() + " id " + id);
|
||||
}
|
||||
|
||||
tapLoadingAgents(id, TapAgentsAction.Add);
|
||||
_resourceMgr.createHostAndAgent(id, resource, details, false, null, false);
|
||||
tapLoadingAgents(id, TapAgentsAction.Del);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e);
|
||||
} finally {
|
||||
@ -1302,7 +1310,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
protected AgentManagerImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
|
||||
synchronized (_loadingAgents) {
|
||||
if (action == TapAgentsAction.Add) {
|
||||
|
||||
@ -1404,6 +1404,19 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
|
||||
profilerAgentLB.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rescan() {
|
||||
// schedule a scan task immediately
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Scheduling a host scan task");
|
||||
}
|
||||
// schedule host scan task on current MS
|
||||
scheduleHostScanTask();
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Notifying all peer MS to schedule host scan task");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigKey<?>[] getConfigKeys() {
|
||||
ConfigKey<?>[] keys = super.getConfigKeys();
|
||||
|
||||
@ -35,8 +35,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
|
||||
import org.apache.cloudstack.framework.config.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
|
||||
|
||||
@ -38,14 +38,11 @@ import com.cloud.agent.StartupCommandProcessor;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.SetupCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.manager.AgentAttache;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.ConnectionException;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.host.HostEnvironment;
|
||||
@ -79,6 +76,10 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rescan() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
// TODO Auto-generated method stub
|
||||
@ -235,19 +236,6 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentAttache handleDirectConnectAgent(HostVO host, StartupCommand[] cmds, ServerResource resource,
|
||||
boolean forRebalance) throws ConnectionException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean agentStatusTransitTo(HostVO host, Event e, long msId) {
|
||||
try {
|
||||
|
||||
@ -29,17 +29,5 @@
|
||||
<artifactId>cloud-framework-db</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -18,30 +18,28 @@ package org.apache.cloudstack.framework.config;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import org.apache.cloudstack.config.Configuration;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
/**
|
||||
* This is a match set to ConfigKey.
|
||||
*
|
||||
* TODO: When we create a framework project for configuration, this should be
|
||||
* moved there.
|
||||
*/
|
||||
public class ConfigValue<T> {
|
||||
|
||||
ConfigKey<T> _config;
|
||||
EntityManager _entityMgr;
|
||||
ConfigurationDao _dao;
|
||||
T _value;
|
||||
ScopedConfigStorage _storage;
|
||||
|
||||
public ConfigValue(EntityManager entityMgr, ConfigKey<T> config) {
|
||||
_entityMgr = entityMgr;
|
||||
public ConfigValue(ConfigurationDao entityMgr, ConfigKey<T> config) {
|
||||
_dao = entityMgr;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
protected ConfigValue(EntityManager entityMgr, ConfigKey<T> key, ScopedConfigStorage storage) {
|
||||
public ConfigValue(ConfigurationDao entityMgr, ConfigKey<T> key, ScopedConfigStorage storage) {
|
||||
this(entityMgr, key);
|
||||
_storage = storage;
|
||||
}
|
||||
@ -52,7 +50,7 @@ public class ConfigValue<T> {
|
||||
|
||||
public T value() {
|
||||
if (_value == null || _config.isDynamic()) {
|
||||
Configuration vo = _entityMgr.findById(Configuration.class, _config.key());
|
||||
ConfigurationVO vo = _dao.findById(_config.key());
|
||||
_value = valueOf(vo != null ? vo.getValue() : _config.defaultValue());
|
||||
}
|
||||
|
||||
@ -70,21 +68,25 @@ public class ConfigValue<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T valueOf(String value) {
|
||||
Number multiplier = 1;
|
||||
if (_config.multiplier() != null) {
|
||||
multiplier = (Number)_config.multiplier();
|
||||
}
|
||||
Class<T> type = _config.type();
|
||||
if (type.isAssignableFrom(Boolean.class)) {
|
||||
return (T)Boolean.valueOf(value);
|
||||
} else if (type.isAssignableFrom(Integer.class)) {
|
||||
return (T)new Integer((Integer.parseInt(value) * ((Number)_config.multiplier()).intValue()));
|
||||
return (T)new Integer(Integer.parseInt(value) * multiplier.intValue());
|
||||
} else if (type.isAssignableFrom(Long.class)) {
|
||||
return (T)new Long(Long.parseLong(value) * ((Number)_config.multiplier()).longValue());
|
||||
return (T)new Long(Long.parseLong(value) * multiplier.longValue());
|
||||
} else if (type.isAssignableFrom(Short.class)) {
|
||||
return (T)new Short(Short.parseShort(value));
|
||||
} else if (type.isAssignableFrom(String.class)) {
|
||||
return (T)value;
|
||||
} else if (type.isAssignableFrom(Float.class)) {
|
||||
return (T)new Float(Float.parseFloat(value) * ((Number)_config.multiplier()).floatValue());
|
||||
return (T)new Float(Float.parseFloat(value) * multiplier.floatValue());
|
||||
} else if (type.isAssignableFrom(Double.class)) {
|
||||
return (T)new Double(Double.parseDouble(value));
|
||||
return (T)new Double(Double.parseDouble(value) * multiplier.doubleValue());
|
||||
} else if (type.isAssignableFrom(String.class)) {
|
||||
return (T)value;
|
||||
} else if (type.isAssignableFrom(Date.class)) {
|
||||
|
||||
@ -19,7 +19,7 @@ package org.apache.cloudstack.framework.config.dao;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
|
||||
@ -17,19 +17,16 @@
|
||||
package org.apache.cloudstack.framework.config.dao;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
|
||||
import com.cloud.utils.component.ComponentLifecycle;
|
||||
import com.cloud.utils.crypt.DBEncryptionUtil;
|
||||
@ -40,8 +37,7 @@ import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
@Local(value={ConfigurationDao.class})
|
||||
@Local(value = {ConfigurationDao.class})
|
||||
public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String> implements ConfigurationDao {
|
||||
private static final Logger s_logger = Logger.getLogger(ConfigurationDaoImpl.class);
|
||||
private Map<String, String> _configs = null;
|
||||
@ -49,13 +45,13 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
|
||||
|
||||
final SearchBuilder<ConfigurationVO> InstanceSearch;
|
||||
final SearchBuilder<ConfigurationVO> NameSearch;
|
||||
|
||||
|
||||
public static final String UPDATE_CONFIGURATION_SQL = "UPDATE configuration SET value = ? WHERE name = ?";
|
||||
|
||||
public ConfigurationDaoImpl () {
|
||||
public ConfigurationDaoImpl() {
|
||||
InstanceSearch = createSearchBuilder();
|
||||
InstanceSearch.and("instance", InstanceSearch.entity().getInstance(), SearchCriteria.Op.EQ);
|
||||
|
||||
|
||||
NameSearch = createSearchBuilder();
|
||||
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
|
||||
setRunLevel(ComponentLifecycle.RUN_LEVEL_SYSTEM_BOOTSTRAP);
|
||||
@ -65,10 +61,10 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
|
||||
public boolean isPremium() {
|
||||
return _premium;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void invalidateCache() {
|
||||
_configs = null;
|
||||
_configs = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -82,21 +78,21 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
|
||||
List<ConfigurationVO> configurations = listIncludingRemovedBy(sc);
|
||||
|
||||
for (ConfigurationVO config : configurations) {
|
||||
if (config.getValue() != null)
|
||||
_configs.put(config.getName(), config.getValue());
|
||||
if (config.getValue() != null)
|
||||
_configs.put(config.getName(), config.getValue());
|
||||
}
|
||||
|
||||
if(!"DEFAULT".equals(instance)){
|
||||
//Default instance params are already added, need not add again
|
||||
sc = InstanceSearch.create();
|
||||
sc.setParameters("instance", instance);
|
||||
if (!"DEFAULT".equals(instance)) {
|
||||
//Default instance params are already added, need not add again
|
||||
sc = InstanceSearch.create();
|
||||
sc.setParameters("instance", instance);
|
||||
|
||||
configurations = listIncludingRemovedBy(sc);
|
||||
configurations = listIncludingRemovedBy(sc);
|
||||
|
||||
for (ConfigurationVO config : configurations) {
|
||||
if (config.getValue() != null)
|
||||
_configs.put(config.getName(), config.getValue());
|
||||
}
|
||||
for (ConfigurationVO config : configurations) {
|
||||
if (config.getValue() != null)
|
||||
_configs.put(config.getName(), config.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -109,12 +105,12 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
|
||||
public Map<String, String> getConfiguration(Map<String, ? extends Object> params) {
|
||||
return getConfiguration("DEFAULT", params);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, String> getConfiguration() {
|
||||
return getConfiguration("DEFAULT", new HashMap<String, Object>());
|
||||
}
|
||||
|
||||
|
||||
protected void mergeConfigs(Map<String, String> dbParams, Map<String, ? extends Object> xmlParams) {
|
||||
for (Map.Entry<String, ? extends Object> param : xmlParams.entrySet()) {
|
||||
dbParams.put(param.getKey(), (String)param.getValue());
|
||||
@ -122,53 +118,54 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
|
||||
Object premium = params.get("premium");
|
||||
_premium = (premium != null) && ((String) premium).equals("true");
|
||||
Object premium = params.get("premium");
|
||||
_premium = (premium != null) && ((String)premium).equals("true");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//Use update method with category instead
|
||||
@Override @Deprecated
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean update(String name, String value) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
|
||||
stmt.setString(1, value);
|
||||
stmt.setString(2, name);
|
||||
stmt.executeUpdate();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to update Configuration Value", e);
|
||||
}
|
||||
return false;
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
|
||||
stmt.setString(1, value);
|
||||
stmt.setString(2, name);
|
||||
stmt.executeUpdate();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to update Configuration Value", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(String name, String category, String value) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
value = ("Hidden".equals(category) || "Secure".equals(category)) ? DBEncryptionUtil.encrypt(value) : value;
|
||||
PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
|
||||
stmt.setString(1, value);
|
||||
stmt.setString(2, name);
|
||||
stmt.executeUpdate();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to update Configuration Value", e);
|
||||
}
|
||||
return false;
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
value = ("Hidden".equals(category) || "Secure".equals(category)) ? DBEncryptionUtil.encrypt(value) : value;
|
||||
PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
|
||||
stmt.setString(1, value);
|
||||
stmt.setString(2, name);
|
||||
stmt.executeUpdate();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to update Configuration Value", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getValue(String name) {
|
||||
ConfigurationVO config = findByName(name);
|
||||
ConfigurationVO config = findByName(name);
|
||||
return (config == null) ? null : config.getValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public String getValueAndInitIfNotExist(String name, String category, String initValue) {
|
||||
@ -195,12 +192,12 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigurationVO findByName(String name) {
|
||||
SearchCriteria<ConfigurationVO> sc = NameSearch.create();
|
||||
sc.setParameters("name", name);
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.framework.config;
|
||||
package org.apache.cloudstack.framework.config.impl;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@ -24,12 +24,20 @@ import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigDepot;
|
||||
import org.apache.cloudstack.framework.config.ConfigDepotAdmin;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
|
||||
import org.apache.cloudstack.framework.config.ConfigValue;
|
||||
import org.apache.cloudstack.framework.config.Configurable;
|
||||
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.ConfigInjector;
|
||||
import com.cloud.utils.component.SystemIntegrityChecker;
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
/**
|
||||
@ -52,9 +60,8 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
* - Figure out the correct categories.
|
||||
*
|
||||
*/
|
||||
class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityChecker, ConfigInjector {
|
||||
@Inject
|
||||
EntityManager _entityMgr;
|
||||
public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityChecker, ConfigInjector {
|
||||
private final static Logger s_logger = Logger.getLogger(ConfigDepotImpl.class);
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
@Inject
|
||||
@ -62,7 +69,7 @@ class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityC
|
||||
@Inject
|
||||
List<ScopedConfigStorage> _scopedStorage;
|
||||
|
||||
HashMap<String, ConfigKey<?>> _allKeys = new HashMap<String, ConfigKey<?>>(1007);
|
||||
HashMap<String, Pair<String, ConfigKey<?>>> _allKeys = new HashMap<String, Pair<String, ConfigKey<?>>>(1007);
|
||||
|
||||
public ConfigDepotImpl() {
|
||||
}
|
||||
@ -70,11 +77,11 @@ class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityC
|
||||
@Override
|
||||
public <T> ConfigValue<T> get(ConfigKey<T> config) {
|
||||
if (config.scope() == Scope.Global) {
|
||||
return new ConfigValue<T>(_entityMgr, config);
|
||||
return new ConfigValue<T>(_configDao, config);
|
||||
} else {
|
||||
for (ScopedConfigStorage storage : _scopedStorage) {
|
||||
if (storage.getScope() == config.scope()) {
|
||||
return new ConfigValue<T>(_entityMgr, config, storage);
|
||||
return new ConfigValue<T>(_configDao, config, storage);
|
||||
}
|
||||
}
|
||||
throw new CloudRuntimeException("Unable to find config storage for this scope: " + config.scope());
|
||||
@ -116,20 +123,23 @@ class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityC
|
||||
@Override
|
||||
public void check() {
|
||||
for (Configurable configurable : _configurables) {
|
||||
s_logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName());
|
||||
for (ConfigKey<?> key : configurable.getConfigKeys()) {
|
||||
if (_allKeys.containsKey(key.key())) {
|
||||
throw new CloudRuntimeException("Configurable " + configurable.getConfigComponentName() + " is adding a key that has been added before: " + key.toString());
|
||||
Pair<String, ConfigKey<?>> previous = _allKeys.get(key.key());
|
||||
if (previous != null && !previous.first().equals(configurable.getConfigComponentName())) {
|
||||
throw new CloudRuntimeException("Configurable " + configurable.getConfigComponentName() + " is adding a key that has been added before by " + previous.first() +
|
||||
": " + key.toString());
|
||||
}
|
||||
_allKeys.put(key.key(), key);
|
||||
_allKeys.put(key.key(), new Pair<String, ConfigKey<?>>(configurable.getConfigComponentName(), key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inject(Field field, Object obj, String key) {
|
||||
ConfigKey<?> configKey = _allKeys.get(key);
|
||||
Pair<String, ConfigKey<?>> configKey = _allKeys.get(key);
|
||||
try {
|
||||
field.set(obj, get(configKey));
|
||||
field.set(obj, get(configKey.second()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new CloudRuntimeException("Unable to inject configuration due to ", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
@ -139,10 +149,10 @@ class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityC
|
||||
|
||||
@Override
|
||||
public ConfigValue<?> get(String name) {
|
||||
ConfigKey<?> configKey = _allKeys.get(name);
|
||||
Pair<String, ConfigKey<?>> configKey = _allKeys.get(name);
|
||||
if (configKey == null) {
|
||||
throw new CloudRuntimeException("Unable to find a registered config key for " + name);
|
||||
}
|
||||
return get(configKey);
|
||||
return get(configKey.second());
|
||||
}
|
||||
}
|
||||
@ -14,7 +14,7 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.framework.config;
|
||||
package org.apache.cloudstack.framework.config.impl;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -26,6 +26,7 @@ import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.apache.cloudstack.config.Configuration;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
|
||||
import com.cloud.utils.crypt.DBEncryptionUtil;
|
||||
|
||||
@ -1,131 +0,0 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.framework.config;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.test.utils.SpringUtils;
|
||||
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
|
||||
public class ConfigDepotAdminTest {
|
||||
private final ConfigKey<Integer> DynamicIntCK = new ConfigKey<Integer>(Integer.class, "dynIntKey", "Advance", "10", "Test Key", true);
|
||||
private final ConfigKey<Integer> StaticIntCK = new ConfigKey<Integer>(Integer.class, "statIntKey", "Advance", "10", "Test Key", false);
|
||||
|
||||
@Inject
|
||||
Configurable configurable;
|
||||
|
||||
@Inject
|
||||
ConfigDepot _configDepot;
|
||||
|
||||
@Inject
|
||||
ConfigDepotAdmin _depotAdmin;
|
||||
|
||||
@Inject
|
||||
EntityManager _entityMgr;
|
||||
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
ComponentContext.initComponentsLifeCycle(); // NOTE #3
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoPopulation() {
|
||||
ConfigurationVO dynamicIntCV = new ConfigurationVO("UnitTestComponent", DynamicIntCK);
|
||||
dynamicIntCV.setValue("100");
|
||||
ConfigurationVO staticIntCV = new ConfigurationVO("UnitTestComponent", StaticIntCK);
|
||||
dynamicIntCV.setValue("200");
|
||||
|
||||
when(configurable.getConfigComponentName()).thenReturn("UnitTestComponent");
|
||||
when(configurable.getConfigKeys()).thenReturn(new ConfigKey<?>[] {DynamicIntCK, StaticIntCK});
|
||||
when(_entityMgr.findById(org.apache.cloudstack.config.Configuration.class, DynamicIntCK.key())).thenReturn(dynamicIntCV);
|
||||
when(_entityMgr.findById(org.apache.cloudstack.config.Configuration.class, StaticIntCK.key())).thenReturn(staticIntCV);
|
||||
when(_configDao.findById(StaticIntCK.key())).thenReturn(null);
|
||||
when(_configDao.findById(DynamicIntCK.key())).thenReturn(dynamicIntCV);
|
||||
when(_configDao.persist(any(ConfigurationVO.class))).thenReturn(dynamicIntCV);
|
||||
|
||||
_depotAdmin.populateConfigurations();
|
||||
|
||||
// This is once because DynamicIntCK is returned.
|
||||
verify(_configDao, times(1)).persist(any(ConfigurationVO.class));
|
||||
|
||||
when(_configDao.findById(DynamicIntCK.key())).thenReturn(dynamicIntCV);
|
||||
_depotAdmin.populateConfigurations();
|
||||
// This is two because DynamicIntCK also returns null.
|
||||
verify(_configDao, times(2)).persist(any(ConfigurationVO.class));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackageClasses = {ConfigDepotImpl.class}, includeFilters = {@Filter(value = TestConfiguration.Library.class, type = FilterType.CUSTOM)}, useDefaultFilters = false)
|
||||
static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration {
|
||||
@Bean
|
||||
public Configurable configurable() {
|
||||
return mock(Configurable.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EntityManager entityMgr() {
|
||||
return mock(EntityManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConfigurationDao configurationDao() {
|
||||
return mock(ConfigurationDao.class);
|
||||
}
|
||||
|
||||
public static class Library implements TypeFilter {
|
||||
@Override
|
||||
public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
|
||||
ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class);
|
||||
return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.framework.config.impl;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigDepot;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.Configurable;
|
||||
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigDepotImpl;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
|
||||
import com.cloud.utils.db.EntityManager;
|
||||
|
||||
public class ConfigDepotAdminTest extends TestCase {
|
||||
private final ConfigKey<Integer> DynamicIntCK = new ConfigKey<Integer>(Integer.class, "dynIntKey", "Advance", "10", "Test Key", true);
|
||||
private final ConfigKey<Integer> StaticIntCK = new ConfigKey<Integer>(Integer.class, "statIntKey", "Advance", "10", "Test Key", false);
|
||||
|
||||
@Mock
|
||||
Configurable _configurable;
|
||||
|
||||
@Mock
|
||||
ConfigDepot _configDepot;
|
||||
|
||||
ConfigDepotImpl _depotAdmin;
|
||||
|
||||
@Mock
|
||||
EntityManager _entityMgr;
|
||||
|
||||
@Mock
|
||||
ConfigurationDao _configDao;
|
||||
|
||||
@Mock
|
||||
ScopedConfigStorage _scopedStorage;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
_depotAdmin = new ConfigDepotImpl();
|
||||
_depotAdmin._configDao = _configDao;
|
||||
_depotAdmin._configurables = new ArrayList<Configurable>();
|
||||
_depotAdmin._configurables.add(_configurable);
|
||||
_depotAdmin._scopedStorage = new ArrayList<ScopedConfigStorage>();
|
||||
_depotAdmin._scopedStorage.add(_scopedStorage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoPopulation() {
|
||||
ConfigurationVO dynamicIntCV = new ConfigurationVO("UnitTestComponent", DynamicIntCK);
|
||||
dynamicIntCV.setValue("100");
|
||||
ConfigurationVO staticIntCV = new ConfigurationVO("UnitTestComponent", StaticIntCK);
|
||||
dynamicIntCV.setValue("200");
|
||||
|
||||
when(_configurable.getConfigComponentName()).thenReturn("UnitTestComponent");
|
||||
when(_configurable.getConfigKeys()).thenReturn(new ConfigKey<?>[] {DynamicIntCK, StaticIntCK});
|
||||
when(_configDao.findById(StaticIntCK.key())).thenReturn(null);
|
||||
when(_configDao.findById(DynamicIntCK.key())).thenReturn(dynamicIntCV);
|
||||
when(_configDao.persist(any(ConfigurationVO.class))).thenReturn(dynamicIntCV);
|
||||
|
||||
_depotAdmin.populateConfigurations();
|
||||
|
||||
// This is once because DynamicIntCK is returned.
|
||||
verify(_configDao, times(1)).persist(any(ConfigurationVO.class));
|
||||
|
||||
when(_configDao.findById(DynamicIntCK.key())).thenReturn(dynamicIntCV);
|
||||
_depotAdmin.populateConfigurations();
|
||||
// This is two because DynamicIntCK also returns null.
|
||||
verify(_configDao, times(2)).persist(any(ConfigurationVO.class));
|
||||
}
|
||||
}
|
||||
@ -183,6 +183,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected GenericDaoBase() {
|
||||
super();
|
||||
Type t = getClass().getGenericSuperclass();
|
||||
if (t instanceof ParameterizedType) {
|
||||
_entityBeanType = (Class<T>)((ParameterizedType)t).getActualTypeArguments()[0];
|
||||
|
||||
@ -114,8 +114,8 @@ import org.apache.cloudstack.api.response.CreateCmdResponse;
|
||||
import org.apache.cloudstack.api.response.ExceptionResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.config.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.jobs.AsyncJob;
|
||||
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
|
||||
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
|
||||
|
||||
@ -24,17 +24,34 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import com.cloud.utils.IteratorUtil;
|
||||
import com.cloud.utils.ReflectUtil;
|
||||
import org.apache.cloudstack.api.*;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.BaseAsyncCmd;
|
||||
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.BaseResponse;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.AsyncJobResponse;
|
||||
import org.apache.cloudstack.api.response.HostResponse;
|
||||
import org.apache.cloudstack.api.response.IPAddressResponse;
|
||||
@ -44,10 +61,11 @@ import org.apache.cloudstack.api.response.StoragePoolResponse;
|
||||
import org.apache.cloudstack.api.response.TemplateResponse;
|
||||
import org.apache.cloudstack.api.response.UserVmResponse;
|
||||
import org.apache.cloudstack.api.response.VolumeResponse;
|
||||
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import org.reflections.Reflections;
|
||||
import com.cloud.utils.IteratorUtil;
|
||||
import com.cloud.utils.ReflectUtil;
|
||||
|
||||
public class ApiXmlDocWriter {
|
||||
public static final Logger s_logger = Logger.getLogger(ApiXmlDocWriter.class.getName());
|
||||
@ -322,7 +340,7 @@ public class ApiXmlDocWriter {
|
||||
}
|
||||
|
||||
if (impl == null) {
|
||||
throw new IllegalStateException(String.format("An %1$s annotation is required for class %2$s.",
|
||||
throw new IllegalStateException(String.format("An %1$s annotation is required for class %2$s.",
|
||||
APICommand.class.getCanonicalName(), clas.getCanonicalName()));
|
||||
}
|
||||
|
||||
@ -588,9 +606,11 @@ public class ApiXmlDocWriter {
|
||||
try {
|
||||
ObjectOutputStream out = xs.createObjectOutputStream(new FileWriter(dirName + "/alert_types.xml"), "alerts");
|
||||
for (Field f : AlertManager.class.getFields()) {
|
||||
String name = f.getName().substring(11);
|
||||
Alert alert = new Alert(name, f.getInt(null));
|
||||
out.writeObject(alert);
|
||||
if (f.getClass().isAssignableFrom(Number.class)) {
|
||||
String name = f.getName().substring(11);
|
||||
Alert alert = new Alert(name, f.getInt(null));
|
||||
out.writeObject(alert);
|
||||
}
|
||||
}
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
@ -73,8 +73,8 @@ import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationSe
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.ConfigValue;
|
||||
import org.apache.cloudstack.framework.config.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
import org.apache.cloudstack.region.PortableIp;
|
||||
import org.apache.cloudstack.region.PortableIpDao;
|
||||
import org.apache.cloudstack.region.PortableIpRange;
|
||||
|
||||
@ -30,10 +30,11 @@ import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
|
||||
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
|
||||
@ -53,7 +54,6 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||
import org.apache.cloudstack.utils.identity.ManagementServerNode;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.AgentManager.TapAgentsAction;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.GetHostStatsAnswer;
|
||||
@ -65,8 +65,6 @@ import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.agent.api.StartupRoutingCommand;
|
||||
import com.cloud.agent.api.UnsupportedAnswer;
|
||||
import com.cloud.agent.api.UpdateHostPasswordCommand;
|
||||
import com.cloud.agent.manager.AgentAttache;
|
||||
import com.cloud.agent.manager.ClusteredAgentManagerImpl;
|
||||
import com.cloud.agent.transport.Request;
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.capacity.Capacity;
|
||||
@ -1709,7 +1707,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
||||
|
||||
private Host createHostAndAgent(ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags, boolean forRebalance) {
|
||||
HostVO host = null;
|
||||
AgentAttache attache = null;
|
||||
StartupCommand[] cmds = null;
|
||||
boolean hostExists = false;
|
||||
|
||||
@ -1753,7 +1750,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
||||
|
||||
host = createHostVO(cmds, resource, details, hostTags, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT);
|
||||
if (host != null) {
|
||||
attache = _agentMgr.handleDirectConnectAgent(host, cmds, resource, forRebalance);
|
||||
/* reload myself from database */
|
||||
host = _hostDao.findById(host.getId());
|
||||
}
|
||||
@ -1764,13 +1760,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
||||
if (cmds != null) {
|
||||
resource.disconnected();
|
||||
}
|
||||
} else {
|
||||
if (attache == null) {
|
||||
if (cmds != null) {
|
||||
resource.disconnected();
|
||||
}
|
||||
markHostAsDisconnected(host, cmds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1780,7 +1769,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
||||
private Host createHostAndAgentDeferred(ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags,
|
||||
boolean forRebalance) {
|
||||
HostVO host = null;
|
||||
AgentAttache attache = null;
|
||||
StartupCommand[] cmds = null;
|
||||
boolean hostExists = false;
|
||||
boolean deferAgentCreation = true;
|
||||
@ -1826,30 +1814,13 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
||||
host = null;
|
||||
GlobalLock addHostLock = GlobalLock.getInternLock("AddHostLock");
|
||||
try {
|
||||
if (addHostLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) { // to
|
||||
// safely
|
||||
// determine
|
||||
// first
|
||||
// host
|
||||
// in
|
||||
// cluster
|
||||
// in
|
||||
// multi-MS
|
||||
// scenario
|
||||
if (addHostLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
|
||||
// to safely determine first host in cluster in multi-MS scenario
|
||||
try {
|
||||
host = createHostVO(cmds, resource, details, hostTags, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT);
|
||||
if (host != null) {
|
||||
deferAgentCreation = !isFirstHostInCluster(host); // if
|
||||
// first
|
||||
// host
|
||||
// in
|
||||
// cluster
|
||||
// no
|
||||
// need
|
||||
// to
|
||||
// defer
|
||||
// agent
|
||||
// creation
|
||||
// if first host in cluster no need to defer agent creation
|
||||
deferAgentCreation = !isFirstHostInCluster(host);
|
||||
}
|
||||
} finally {
|
||||
addHostLock.unlock();
|
||||
@ -1861,9 +1832,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
||||
|
||||
if (host != null) {
|
||||
if (!deferAgentCreation) { // if first host in cluster then
|
||||
// create agent otherwise defer it to
|
||||
// scan task
|
||||
attache = _agentMgr.handleDirectConnectAgent(host, cmds, resource, forRebalance);
|
||||
host = _hostDao.findById(host.getId()); // reload
|
||||
} else {
|
||||
host = _hostDao.findById(host.getId()); // reload
|
||||
@ -1875,20 +1843,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
||||
host.setLastPinged(0); // so that scan task can pick it up
|
||||
_hostDao.update(host.getId(), host);
|
||||
|
||||
// schedule a scan task immediately
|
||||
if (_agentMgr instanceof ClusteredAgentManagerImpl) {
|
||||
ClusteredAgentManagerImpl clusteredAgentMgr = (ClusteredAgentManagerImpl) _agentMgr;
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Scheduling a host scan task");
|
||||
}
|
||||
// schedule host scan task on current MS
|
||||
clusteredAgentMgr.scheduleHostScanTask();
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Notifying all peer MS to schedule host scan task");
|
||||
}
|
||||
// notify peers to schedule a host scan task as well
|
||||
clusteredAgentMgr.notifyNodesInClusterToScheduleHostScanTask();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@ -1899,7 +1853,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
||||
resource.disconnected();
|
||||
}
|
||||
} else {
|
||||
if (!deferAgentCreation && attache == null) {
|
||||
if (!deferAgentCreation) {
|
||||
if (cmds != null) {
|
||||
resource.disconnected();
|
||||
}
|
||||
@ -1914,9 +1868,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
|
||||
@Override
|
||||
public Host createHostAndAgent(Long hostId, ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags,
|
||||
boolean forRebalance) {
|
||||
_agentMgr.tapLoadingAgents(hostId, TapAgentsAction.Add);
|
||||
Host host = createHostAndAgent(resource, details, old, hostTags, forRebalance);
|
||||
_agentMgr.tapLoadingAgents(hostId, TapAgentsAction.Del);
|
||||
return host;
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ package com.cloud.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
|
||||
|
||||
@ -48,8 +48,8 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigDepot;
|
||||
import org.apache.cloudstack.framework.config.ConfigDepotAdmin;
|
||||
import org.apache.cloudstack.framework.config.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
|
||||
@ -431,8 +431,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.config.ConfigValue;
|
||||
import org.apache.cloudstack.framework.config.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
|
||||
@ -4887,14 +4887,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
|
||||
@Override
|
||||
public String getConfigComponentName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return UserVmManager.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigKey<?>[] getConfigKeys() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return new ConfigKey<?>[] {EnableDynamicallyScaleVm};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -48,6 +48,7 @@ public class AlertControlsUnitTest extends TestCase {
|
||||
@Mock AlertDao _alertDao;
|
||||
@Override
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
_mgmtServer._alertDao = _alertDao;
|
||||
@ -57,6 +58,7 @@ public class AlertControlsUnitTest extends TestCase {
|
||||
when(_alertDao.deleteAlert(anyList(), anyString(), any(Date.class), any(Date.class), anyLong())).thenReturn(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@ -21,8 +21,8 @@ import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
||||
|
||||
@ -35,8 +35,8 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
import org.apache.cloudstack.framework.config.ConfigurationVO;
|
||||
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
|
||||
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
|
||||
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
|
||||
@ -16,10 +16,9 @@
|
||||
// under the License.
|
||||
package com.cloud.utils;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.reflections.Reflections;
|
||||
import static java.beans.Introspector.getBeanInfo;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
@ -34,9 +33,12 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.beans.Introspector.getBeanInfo;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class ReflectUtil {
|
||||
|
||||
@ -109,7 +111,7 @@ public class ReflectUtil {
|
||||
List<Field> fields = new ArrayList<Field>();
|
||||
Collections.addAll(fields, cmdClass.getDeclaredFields());
|
||||
Class<?> superClass = cmdClass.getSuperclass();
|
||||
while (baseClass.isAssignableFrom(superClass)) {
|
||||
while (baseClass.isAssignableFrom(superClass) && baseClass != superClass) {
|
||||
Field[] superClassFields = superClass.getDeclaredFields();
|
||||
if (superClassFields != null)
|
||||
Collections.addAll(fields, superClassFields);
|
||||
|
||||
@ -21,16 +21,17 @@ import java.util.List;
|
||||
// Typical Adapter implementation.
|
||||
public class AdapterBase extends ComponentLifecycleBase implements Adapter, ComponentMethodInterceptable {
|
||||
|
||||
public AdapterBase() {
|
||||
public AdapterBase() {
|
||||
super();
|
||||
// set default run level for adapter components
|
||||
setRunLevel(ComponentLifecycle.RUN_LEVEL_COMPONENT);
|
||||
}
|
||||
|
||||
public static <T extends Adapter> T getAdapterByName(List<T> adapters, String name) {
|
||||
for(T adapter : adapters) {
|
||||
if(adapter.getName() != null && adapter.getName().equalsIgnoreCase(name))
|
||||
return adapter;
|
||||
}
|
||||
return null;
|
||||
public static <T extends Adapter> T getAdapterByName(List<T> adapters, String name) {
|
||||
for (T adapter : adapters) {
|
||||
if (adapter.getName() != null && adapter.getName().equalsIgnoreCase(name))
|
||||
return adapter;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,7 +34,6 @@ import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.mgmt.JmxUtil;
|
||||
import com.cloud.utils.mgmt.ManagementBean;
|
||||
@ -45,7 +44,7 @@ import com.cloud.utils.mgmt.ManagementBean;
|
||||
* are not recommended to be used outside, they exist to help wire Spring Framework
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ComponentContext implements ApplicationContextAware {
|
||||
private static final Logger s_logger = Logger.getLogger(ComponentContext.class);
|
||||
|
||||
@ -53,99 +52,98 @@ public class ComponentContext implements ApplicationContextAware {
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
s_logger.info("Setup Spring Application context");
|
||||
s_logger.info("Setup Spring Application context");
|
||||
s_appContext = applicationContext;
|
||||
}
|
||||
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
return s_appContext;
|
||||
}
|
||||
|
||||
public static void initComponentsLifeCycle() {
|
||||
AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory();
|
||||
|
||||
Map<String, ComponentMethodInterceptable> interceptableComponents = getApplicationContext().getBeansOfType(
|
||||
ComponentMethodInterceptable.class);
|
||||
for(Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) {
|
||||
Object bean = getTargetObject(entry.getValue());
|
||||
beanFactory.configureBean(bean, entry.getKey());
|
||||
}
|
||||
|
||||
Map<String, ComponentLifecycle> lifecycleComponents = getApplicationContext().getBeansOfType(ComponentLifecycle.class);
|
||||
|
||||
Map[] classifiedComponents = new Map[ComponentLifecycle.MAX_RUN_LEVELS];
|
||||
for(int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
|
||||
classifiedComponents[i] = new HashMap<String, ComponentLifecycle>();
|
||||
}
|
||||
|
||||
for(Map.Entry<String, ComponentLifecycle> entry : lifecycleComponents.entrySet()) {
|
||||
classifiedComponents[entry.getValue().getRunLevel()].put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
public static void initComponentsLifeCycle() {
|
||||
AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory();
|
||||
|
||||
Map<String, ComponentMethodInterceptable> interceptableComponents = getApplicationContext().getBeansOfType(ComponentMethodInterceptable.class);
|
||||
for (Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) {
|
||||
Object bean = getTargetObject(entry.getValue());
|
||||
beanFactory.configureBean(bean, entry.getKey());
|
||||
}
|
||||
|
||||
Map<String, ComponentLifecycle> lifecycleComponents = getApplicationContext().getBeansOfType(ComponentLifecycle.class);
|
||||
|
||||
Map<String, ComponentLifecycle>[] classifiedComponents = new Map[ComponentLifecycle.MAX_RUN_LEVELS];
|
||||
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
|
||||
classifiedComponents[i] = new HashMap<String, ComponentLifecycle>();
|
||||
}
|
||||
|
||||
for (Map.Entry<String, ComponentLifecycle> entry : lifecycleComponents.entrySet()) {
|
||||
classifiedComponents[entry.getValue().getRunLevel()].put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
// Run the SystemIntegrityCheckers first
|
||||
Map<String, SystemIntegrityChecker> integrityCheckers = getApplicationContext().getBeansOfType(SystemIntegrityChecker.class);
|
||||
for (Entry<String,SystemIntegrityChecker> entry : integrityCheckers.entrySet() ){
|
||||
s_logger.info ("Running SystemIntegrityChecker " + entry.getKey());
|
||||
for (Entry<String, SystemIntegrityChecker> entry : integrityCheckers.entrySet()) {
|
||||
s_logger.info("Running SystemIntegrityChecker " + entry.getKey());
|
||||
try {
|
||||
entry.getValue().check();
|
||||
} catch(Throwable e) {
|
||||
entry.getValue().check();
|
||||
} catch (Throwable e) {
|
||||
s_logger.error("System integrity check failed. Refuse to startup", e);
|
||||
System.exit(1);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// configuration phase
|
||||
|
||||
// configuration phase
|
||||
Map<String, String> avoidMap = new HashMap<String, String>();
|
||||
for(int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
|
||||
for(Map.Entry<String, ComponentLifecycle> entry : ((Map<String, ComponentLifecycle>)classifiedComponents[i]).entrySet()) {
|
||||
ComponentLifecycle component = entry.getValue();
|
||||
String implClassName = ComponentContext.getTargetClass(component).getName();
|
||||
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
|
||||
for (Map.Entry<String, ComponentLifecycle> entry : classifiedComponents[i].entrySet()) {
|
||||
ComponentLifecycle component = entry.getValue();
|
||||
String implClassName = ComponentContext.getTargetClass(component).getName();
|
||||
s_logger.info("Configuring " + implClassName);
|
||||
|
||||
if(avoidMap.containsKey(implClassName)) {
|
||||
|
||||
if (avoidMap.containsKey(implClassName)) {
|
||||
s_logger.info("Skip configuration of " + implClassName + " as it is already configured");
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
component.configure(component.getName(), component.getConfigParams());
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.error("Unhandled exception", e);
|
||||
throw new RuntimeException("Unable to configure " + implClassName, e);
|
||||
}
|
||||
|
||||
component.configure(component.getName(), component.getConfigParams());
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.error("Unhandled exception", e);
|
||||
throw new RuntimeException("Unable to configure " + implClassName, e);
|
||||
}
|
||||
|
||||
avoidMap.put(implClassName, implClassName);
|
||||
}
|
||||
}
|
||||
|
||||
// starting phase
|
||||
avoidMap.clear();
|
||||
for(int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
|
||||
for(Map.Entry<String, ComponentLifecycle> entry : ((Map<String, ComponentLifecycle>)classifiedComponents[i]).entrySet()) {
|
||||
ComponentLifecycle component = entry.getValue();
|
||||
String implClassName = ComponentContext.getTargetClass(component).getName();
|
||||
}
|
||||
}
|
||||
|
||||
// starting phase
|
||||
avoidMap.clear();
|
||||
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
|
||||
for (Map.Entry<String, ComponentLifecycle> entry : classifiedComponents[i].entrySet()) {
|
||||
ComponentLifecycle component = entry.getValue();
|
||||
String implClassName = ComponentContext.getTargetClass(component).getName();
|
||||
s_logger.info("Starting " + implClassName);
|
||||
|
||||
if(avoidMap.containsKey(implClassName)) {
|
||||
|
||||
if (avoidMap.containsKey(implClassName)) {
|
||||
s_logger.info("Skip configuration of " + implClassName + " as it is already configured");
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
component.start();
|
||||
|
||||
if(getTargetObject(component) instanceof ManagementBean)
|
||||
registerMBean((ManagementBean)getTargetObject(component));
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Unhandled exception", e);
|
||||
throw new RuntimeException("Unable to start " + implClassName, e);
|
||||
}
|
||||
|
||||
component.start();
|
||||
|
||||
if (getTargetObject(component) instanceof ManagementBean)
|
||||
registerMBean((ManagementBean)getTargetObject(component));
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Unhandled exception", e);
|
||||
throw new RuntimeException("Unable to start " + implClassName, e);
|
||||
}
|
||||
|
||||
avoidMap.put(implClassName, implClassName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void registerMBean(ManagementBean mbean) {
|
||||
try {
|
||||
JmxUtil.registerMBean(mbean);
|
||||
@ -160,32 +158,32 @@ public class ComponentContext implements ApplicationContextAware {
|
||||
}
|
||||
s_logger.info("Registered MBean: " + mbean.getName());
|
||||
}
|
||||
|
||||
|
||||
public static <T> T getComponent(String name) {
|
||||
assert(s_appContext != null);
|
||||
assert (s_appContext != null);
|
||||
return (T)s_appContext.getBean(name);
|
||||
}
|
||||
|
||||
public static <T> T getComponent(Class<T> beanType) {
|
||||
assert(s_appContext != null);
|
||||
assert (s_appContext != null);
|
||||
Map<String, T> matchedTypes = getComponentsOfType(beanType);
|
||||
if(matchedTypes.size() > 0) {
|
||||
for(Map.Entry<String, T> entry : matchedTypes.entrySet()) {
|
||||
if (matchedTypes.size() > 0) {
|
||||
for (Map.Entry<String, T> entry : matchedTypes.entrySet()) {
|
||||
Primary primary = getTargetClass(entry.getValue()).getAnnotation(Primary.class);
|
||||
if(primary != null)
|
||||
if (primary != null)
|
||||
return entry.getValue();
|
||||
}
|
||||
|
||||
if(matchedTypes.size() > 1) {
|
||||
if (matchedTypes.size() > 1) {
|
||||
s_logger.warn("Unable to uniquely locate bean type " + beanType.getName());
|
||||
for(Map.Entry<String, T> entry : matchedTypes.entrySet()) {
|
||||
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(beanType.getName());
|
||||
}
|
||||
|
||||
@ -194,10 +192,10 @@ public class ComponentContext implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
public static Class<?> getTargetClass(Object instance) {
|
||||
while(instance instanceof Advised) {
|
||||
while (instance instanceof Advised) {
|
||||
try {
|
||||
instance = ((Advised)instance).getTargetSource().getTarget();
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
return instance.getClass();
|
||||
}
|
||||
}
|
||||
@ -205,7 +203,7 @@ public class ComponentContext implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
public static <T> T getTargetObject(Object instance) {
|
||||
while(instance instanceof Advised) {
|
||||
while (instance instanceof Advised) {
|
||||
try {
|
||||
instance = ((Advised)instance).getTargetSource().getTarget();
|
||||
} catch (Exception e) {
|
||||
@ -215,24 +213,24 @@ public class ComponentContext implements ApplicationContextAware {
|
||||
|
||||
return (T)instance;
|
||||
}
|
||||
|
||||
|
||||
public static <T> T inject(Class<T> clz) {
|
||||
T instance;
|
||||
try {
|
||||
instance = clz.newInstance();
|
||||
return inject(instance);
|
||||
} catch (InstantiationException e) {
|
||||
s_logger.error("Unhandled InstantiationException", e);
|
||||
throw new RuntimeException("Unable to instantiate object of class " + clz.getName() + ", make sure it has public constructor");
|
||||
} catch (IllegalAccessException e) {
|
||||
s_logger.error("Unhandled IllegalAccessException", e);
|
||||
throw new RuntimeException("Unable to instantiate object of class " + clz.getName() + ", make sure it has public constructor");
|
||||
}
|
||||
try {
|
||||
instance = clz.newInstance();
|
||||
return inject(instance);
|
||||
} catch (InstantiationException e) {
|
||||
s_logger.error("Unhandled InstantiationException", e);
|
||||
throw new RuntimeException("Unable to instantiate object of class " + clz.getName() + ", make sure it has public constructor");
|
||||
} catch (IllegalAccessException e) {
|
||||
s_logger.error("Unhandled IllegalAccessException", e);
|
||||
throw new RuntimeException("Unable to instantiate object of class " + clz.getName() + ", make sure it has public constructor");
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T inject(Object instance) {
|
||||
// autowire dynamically loaded object
|
||||
AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory();
|
||||
AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory();
|
||||
beanFactory.autowireBean(instance);
|
||||
return (T)instance;
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
@ -27,70 +28,74 @@ import com.cloud.utils.ReflectUtil;
|
||||
|
||||
public class ComponentLifecycleBase implements ComponentLifecycle {
|
||||
|
||||
protected String _name;
|
||||
protected int _runLevel;
|
||||
protected String _name;
|
||||
protected int _runLevel;
|
||||
protected Map<String, Object> _configParams = new HashMap<String, Object>();
|
||||
@Inject
|
||||
protected ConfigInjector _configInjector;
|
||||
|
||||
public ComponentLifecycleBase() {
|
||||
_name = this.getClass().getSimpleName();
|
||||
_runLevel = RUN_LEVEL_COMPONENT;
|
||||
|
||||
for (Field field : ReflectUtil.getAllFieldsForClass(this.getClass(), Object.class)) {
|
||||
InjectConfig config = field.getAnnotation(InjectConfig.class);
|
||||
if (config != null) {
|
||||
field.setAccessible(true);
|
||||
_configInjector.inject(field, this, config.key());
|
||||
public ComponentLifecycleBase() {
|
||||
_name = this.getClass().getSimpleName();
|
||||
_runLevel = RUN_LEVEL_COMPONENT;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
protected void injectConfigs() {
|
||||
if (_configInjector != null) {
|
||||
for (Field field : ReflectUtil.getAllFieldsForClass(this.getClass(), Object.class)) {
|
||||
InjectConfig config = field.getAnnotation(InjectConfig.class);
|
||||
if (config != null) {
|
||||
field.setAccessible(true);
|
||||
_configInjector.inject(field, this, config.key());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
_name = name;
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigParams(Map<String, Object> params) {
|
||||
_configParams = params;
|
||||
}
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
_name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getConfigParams() {
|
||||
return _configParams;
|
||||
}
|
||||
@Override
|
||||
public void setConfigParams(Map<String, Object> params) {
|
||||
_configParams = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRunLevel() {
|
||||
return _runLevel;
|
||||
}
|
||||
@Override
|
||||
public Map<String, Object> getConfigParams() {
|
||||
return _configParams;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRunLevel(int level) {
|
||||
_runLevel = level;
|
||||
}
|
||||
@Override
|
||||
public int getRunLevel() {
|
||||
return _runLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
@Override
|
||||
public void setRunLevel(int level) {
|
||||
_runLevel = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
_name = name;
|
||||
_configParams = params;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,8 +17,9 @@
|
||||
package com.cloud.utils.component;
|
||||
|
||||
public class ManagerBase extends ComponentLifecycleBase implements ComponentMethodInterceptable {
|
||||
public ManagerBase() {
|
||||
// set default run level for manager components
|
||||
setRunLevel(ComponentLifecycle.RUN_LEVEL_COMPONENT_BOOTSTRAP);
|
||||
}
|
||||
public ManagerBase() {
|
||||
super();
|
||||
// set default run level for manager components
|
||||
setRunLevel(ComponentLifecycle.RUN_LEVEL_COMPONENT_BOOTSTRAP);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user