Compile complete

This commit is contained in:
Alex Huang 2013-08-29 09:48:05 -07:00
parent 6e8ca99466
commit b8e79c30a8
34 changed files with 457 additions and 496 deletions

View File

@ -41,6 +41,11 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-config</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@ -109,5 +109,6 @@ public class SpringUtils {
return processor; return processor;
} }
} }
} }

View File

@ -81,7 +81,7 @@
</bean> </bean>
<bean id="messageBus" class = "org.apache.cloudstack.framework.messagebus.MessageBusBase" /> <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 DAO with customized configuration
@ -718,6 +718,7 @@
<bean id="storageManagerImpl" class="com.cloud.storage.StorageManagerImpl"/> <bean id="storageManagerImpl" class="com.cloud.storage.StorageManagerImpl"/>
<bean id="volumeOrchestrator" class="org.apache.cloudstack.engine.orchestration.VolumeOrchestrator"> <bean id="volumeOrchestrator" class="org.apache.cloudstack.engine.orchestration.VolumeOrchestrator">
<property name="PodAllocators" value="#{podAllocators.Adapters}" />
<property name="StoragePoolAllocators" value="#{storagePoolAllocators.Adapters}" /> <property name="StoragePoolAllocators" value="#{storagePoolAllocators.Adapters}" />
</bean> </bean>
@ -726,7 +727,6 @@
</bean> </bean>
<bean id="resourceManagerImpl" class="com.cloud.resource.ResourceManagerImpl" > <bean id="resourceManagerImpl" class="com.cloud.resource.ResourceManagerImpl" >
<property name="PodAllocators" value="#{podAllocators.Adapters}" />
<property name="Discoverers" value="#{resourceDiscoverers.Adapters}" /> <property name="Discoverers" value="#{resourceDiscoverers.Adapters}" />
</bean> </bean>
@ -739,7 +739,7 @@
<property name="HostAllocators" value="#{hostAllocators.Adapters}" /> <property name="HostAllocators" value="#{hostAllocators.Adapters}" />
</bean> </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="NetworkGurus" value="#{networkGurus.Adapters}" />
<property name="NetworkElements" value="#{networkElements.Adapters}" /> <property name="NetworkElements" value="#{networkElements.Adapters}" />
<property name="IpDeployers" value="#{ipDeployers.Adapters}" /> <property name="IpDeployers" value="#{ipDeployers.Adapters}" />

View File

@ -122,9 +122,6 @@ public interface AgentManager {
Answer sendTo(Long dcId, HypervisorType type, Command cmd); 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 AgentAttache handleDirectConnectAgent(HostVO host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException;
public boolean agentStatusTransitTo(HostVO host, Status.Event e, long msId); public boolean agentStatusTransitTo(HostVO host, Status.Event e, long msId);
@ -138,4 +135,6 @@ public interface AgentManager {
public void pullAgentOutMaintenance(long hostId); public void pullAgentOutMaintenance(long hostId);
boolean reconnect(long hostId); boolean reconnect(long hostId);
void rescan();
} }

View File

@ -654,6 +654,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
return resource; return resource;
} }
@Override
public void rescan() {
}
protected boolean loadDirectlyConnectedHost(HostVO host, boolean forRebalance) { protected boolean loadDirectlyConnectedHost(HostVO host, boolean forRebalance) {
boolean initialized = false; boolean initialized = false;
@ -683,7 +686,10 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
} }
if (forRebalance) { if (forRebalance) {
tapLoadingAgents(host.getId(), TapAgentsAction.Add);
Host h = _resourceMgr.createHostAndAgent(host.getId(), resource, host.getDetails(), false, null, true); Host h = _resourceMgr.createHostAndAgent(host.getId(), resource, host.getDetails(), false, null, true);
tapLoadingAgents(host.getId(), TapAgentsAction.Del);
return (h == null ? false : true); return (h == null ? false : true);
} else { } else {
_executor.execute(new SimulateStartTask(host.getId(), resource, host.getDetails())); _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); s_logger.debug("Simulating start for resource " + resource.getName() + " id " + id);
} }
tapLoadingAgents(id, TapAgentsAction.Add);
_resourceMgr.createHostAndAgent(id, resource, details, false, null, false); _resourceMgr.createHostAndAgent(id, resource, details, false, null, false);
tapLoadingAgents(id, TapAgentsAction.Del);
} catch (Exception e) { } catch (Exception e) {
s_logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e); s_logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e);
} finally { } finally {
@ -1302,7 +1310,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
protected AgentManagerImpl() { protected AgentManagerImpl() {
} }
@Override
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) { public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
synchronized (_loadingAgents) { synchronized (_loadingAgents) {
if (action == TapAgentsAction.Add) { if (action == TapAgentsAction.Add) {

View File

@ -1404,6 +1404,19 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust
profilerAgentLB.stop(); 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 @Override
public ConfigKey<?>[] getConfigKeys() { public ConfigKey<?>[] getConfigKeys() {
ConfigKey<?>[] keys = super.getConfigKeys(); ConfigKey<?>[] keys = super.getConfigKeys();

View File

@ -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.DataStoreProvider;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; 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.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.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;

View File

@ -38,14 +38,11 @@ import com.cloud.agent.StartupCommandProcessor;
import com.cloud.agent.api.Answer; import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command; import com.cloud.agent.api.Command;
import com.cloud.agent.api.SetupCommand; 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.agent.manager.Commands;
import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.ClusterVO; import com.cloud.dc.ClusterVO;
import com.cloud.dc.dao.ClusterDao; import com.cloud.dc.dao.ClusterDao;
import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConnectionException;
import com.cloud.exception.DiscoveryException; import com.cloud.exception.DiscoveryException;
import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.HostEnvironment; import com.cloud.host.HostEnvironment;
@ -79,6 +76,10 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
return false; return false;
} }
@Override
public void rescan() {
}
@Override @Override
public boolean start() { public boolean start() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -235,19 +236,6 @@ public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentMa
return null; 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 @Override
public boolean agentStatusTransitTo(HostVO host, Event e, long msId) { public boolean agentStatusTransitTo(HostVO host, Event e, long msId) {
try { try {

View File

@ -29,17 +29,5 @@
<artifactId>cloud-framework-db</artifactId> <artifactId>cloud-framework-db</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </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> </dependencies>
</project> </project>

View File

@ -18,30 +18,28 @@ package org.apache.cloudstack.framework.config;
import java.sql.Date; 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; import com.cloud.utils.exception.CloudRuntimeException;
/** /**
* This is a match set to ConfigKey. * 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> { public class ConfigValue<T> {
ConfigKey<T> _config; ConfigKey<T> _config;
EntityManager _entityMgr; ConfigurationDao _dao;
T _value; T _value;
ScopedConfigStorage _storage; ScopedConfigStorage _storage;
public ConfigValue(EntityManager entityMgr, ConfigKey<T> config) { public ConfigValue(ConfigurationDao entityMgr, ConfigKey<T> config) {
_entityMgr = entityMgr; _dao = entityMgr;
_config = config; _config = config;
} }
protected ConfigValue(EntityManager entityMgr, ConfigKey<T> key, ScopedConfigStorage storage) { public ConfigValue(ConfigurationDao entityMgr, ConfigKey<T> key, ScopedConfigStorage storage) {
this(entityMgr, key); this(entityMgr, key);
_storage = storage; _storage = storage;
} }
@ -52,7 +50,7 @@ public class ConfigValue<T> {
public T value() { public T value() {
if (_value == null || _config.isDynamic()) { 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()); _value = valueOf(vo != null ? vo.getValue() : _config.defaultValue());
} }
@ -70,21 +68,25 @@ public class ConfigValue<T> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected T valueOf(String value) { protected T valueOf(String value) {
Number multiplier = 1;
if (_config.multiplier() != null) {
multiplier = (Number)_config.multiplier();
}
Class<T> type = _config.type(); Class<T> type = _config.type();
if (type.isAssignableFrom(Boolean.class)) { if (type.isAssignableFrom(Boolean.class)) {
return (T)Boolean.valueOf(value); return (T)Boolean.valueOf(value);
} else if (type.isAssignableFrom(Integer.class)) { } 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)) { } 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)) { } else if (type.isAssignableFrom(Short.class)) {
return (T)new Short(Short.parseShort(value)); return (T)new Short(Short.parseShort(value));
} else if (type.isAssignableFrom(String.class)) { } else if (type.isAssignableFrom(String.class)) {
return (T)value; return (T)value;
} else if (type.isAssignableFrom(Float.class)) { } 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)) { } 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)) { } else if (type.isAssignableFrom(String.class)) {
return (T)value; return (T)value;
} else if (type.isAssignableFrom(Date.class)) { } else if (type.isAssignableFrom(Date.class)) {

View File

@ -19,7 +19,7 @@ package org.apache.cloudstack.framework.config.dao;
import java.util.Map; import java.util.Map;
import java.util.List; 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; import com.cloud.utils.db.GenericDao;

View File

@ -17,19 +17,16 @@
package org.apache.cloudstack.framework.config.dao; package org.apache.cloudstack.framework.config.dao;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.Local; import javax.ejb.Local;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import org.apache.log4j.Logger; 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.component.ComponentLifecycle;
import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.crypt.DBEncryptionUtil;
@ -40,7 +37,6 @@ 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;
@Component
@Local(value = {ConfigurationDao.class}) @Local(value = {ConfigurationDao.class})
public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String> implements ConfigurationDao { public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String> implements ConfigurationDao {
private static final Logger s_logger = Logger.getLogger(ConfigurationDaoImpl.class); private static final Logger s_logger = Logger.getLogger(ConfigurationDaoImpl.class);
@ -132,7 +128,8 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
} }
//Use update method with category instead //Use update method with category instead
@Override @Deprecated @Override
@Deprecated
public boolean update(String name, String value) { public boolean update(String name, String value) {
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
try { try {

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package org.apache.cloudstack.framework.config; package org.apache.cloudstack.framework.config.impl;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
@ -24,12 +24,20 @@ import java.util.List;
import javax.inject.Inject; 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.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 org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ConfigInjector; import com.cloud.utils.component.ConfigInjector;
import com.cloud.utils.component.SystemIntegrityChecker; import com.cloud.utils.component.SystemIntegrityChecker;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
/** /**
@ -52,9 +60,8 @@ import com.cloud.utils.exception.CloudRuntimeException;
* - Figure out the correct categories. * - Figure out the correct categories.
* *
*/ */
class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityChecker, ConfigInjector { public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityChecker, ConfigInjector {
@Inject private final static Logger s_logger = Logger.getLogger(ConfigDepotImpl.class);
EntityManager _entityMgr;
@Inject @Inject
ConfigurationDao _configDao; ConfigurationDao _configDao;
@Inject @Inject
@ -62,7 +69,7 @@ class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityC
@Inject @Inject
List<ScopedConfigStorage> _scopedStorage; 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() { public ConfigDepotImpl() {
} }
@ -70,11 +77,11 @@ class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityC
@Override @Override
public <T> ConfigValue<T> get(ConfigKey<T> config) { public <T> ConfigValue<T> get(ConfigKey<T> config) {
if (config.scope() == Scope.Global) { if (config.scope() == Scope.Global) {
return new ConfigValue<T>(_entityMgr, config); return new ConfigValue<T>(_configDao, config);
} else { } else {
for (ScopedConfigStorage storage : _scopedStorage) { for (ScopedConfigStorage storage : _scopedStorage) {
if (storage.getScope() == config.scope()) { 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()); throw new CloudRuntimeException("Unable to find config storage for this scope: " + config.scope());
@ -116,20 +123,23 @@ class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityC
@Override @Override
public void check() { public void check() {
for (Configurable configurable : _configurables) { for (Configurable configurable : _configurables) {
s_logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName());
for (ConfigKey<?> key : configurable.getConfigKeys()) { for (ConfigKey<?> key : configurable.getConfigKeys()) {
if (_allKeys.containsKey(key.key())) { Pair<String, ConfigKey<?>> previous = _allKeys.get(key.key());
throw new CloudRuntimeException("Configurable " + configurable.getConfigComponentName() + " is adding a key that has been added before: " + key.toString()); 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 @Override
public void inject(Field field, Object obj, String key) { public void inject(Field field, Object obj, String key) {
ConfigKey<?> configKey = _allKeys.get(key); Pair<String, ConfigKey<?>> configKey = _allKeys.get(key);
try { try {
field.set(obj, get(configKey)); field.set(obj, get(configKey.second()));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new CloudRuntimeException("Unable to inject configuration due to ", e); throw new CloudRuntimeException("Unable to inject configuration due to ", e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
@ -139,10 +149,10 @@ class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin, SystemIntegrityC
@Override @Override
public ConfigValue<?> get(String name) { public ConfigValue<?> get(String name) {
ConfigKey<?> configKey = _allKeys.get(name); Pair<String, ConfigKey<?>> configKey = _allKeys.get(name);
if (configKey == null) { if (configKey == null) {
throw new CloudRuntimeException("Unable to find a registered config key for " + name); throw new CloudRuntimeException("Unable to find a registered config key for " + name);
} }
return get(configKey); return get(configKey.second());
} }
} }

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package org.apache.cloudstack.framework.config; package org.apache.cloudstack.framework.config.impl;
import java.util.Date; import java.util.Date;
@ -26,6 +26,7 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import org.apache.cloudstack.config.Configuration; import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.framework.config.ConfigKey;
import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.crypt.DBEncryptionUtil;

View File

@ -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);
}
}
}
}

View File

@ -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));
}
}

View File

@ -183,6 +183,7 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected GenericDaoBase() { protected GenericDaoBase() {
super();
Type t = getClass().getGenericSuperclass(); Type t = getClass().getGenericSuperclass();
if (t instanceof ParameterizedType) { if (t instanceof ParameterizedType) {
_entityBeanType = (Class<T>)((ParameterizedType)t).getActualTypeArguments()[0]; _entityBeanType = (Class<T>)((ParameterizedType)t).getActualTypeArguments()[0];

View File

@ -114,8 +114,8 @@ import org.apache.cloudstack.api.response.CreateCmdResponse;
import org.apache.cloudstack.api.response.ExceptionResponse; import org.apache.cloudstack.api.response.ExceptionResponse;
import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.context.CallContext; 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.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.apache.cloudstack.framework.jobs.AsyncJob; import org.apache.cloudstack.framework.jobs.AsyncJob;
import org.apache.cloudstack.framework.jobs.AsyncJobManager; import org.apache.cloudstack.framework.jobs.AsyncJobManager;
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO; import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;

View File

@ -24,17 +24,34 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.lang.reflect.Field; 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.ZipEntry;
import java.util.zip.ZipOutputStream; 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 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.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.AsyncJobResponse;
import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.api.response.HostResponse;
import org.apache.cloudstack.api.response.IPAddressResponse; 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.TemplateResponse;
import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.VolumeResponse;
import com.cloud.alert.AlertManager;
import com.cloud.serializer.Param; import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName; import com.cloud.utils.IteratorUtil;
import com.thoughtworks.xstream.XStream; import com.cloud.utils.ReflectUtil;
import org.reflections.Reflections;
public class ApiXmlDocWriter { public class ApiXmlDocWriter {
public static final Logger s_logger = Logger.getLogger(ApiXmlDocWriter.class.getName()); public static final Logger s_logger = Logger.getLogger(ApiXmlDocWriter.class.getName());
@ -588,10 +606,12 @@ public class ApiXmlDocWriter {
try { try {
ObjectOutputStream out = xs.createObjectOutputStream(new FileWriter(dirName + "/alert_types.xml"), "alerts"); ObjectOutputStream out = xs.createObjectOutputStream(new FileWriter(dirName + "/alert_types.xml"), "alerts");
for (Field f : AlertManager.class.getFields()) { for (Field f : AlertManager.class.getFields()) {
if (f.getClass().isAssignableFrom(Number.class)) {
String name = f.getName().substring(11); String name = f.getName().substring(11);
Alert alert = new Alert(name, f.getInt(null)); Alert alert = new Alert(name, f.getInt(null));
out.writeObject(alert); out.writeObject(alert);
} }
}
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {
s_logger.error("Failed to create output stream to write an alert types ", e); s_logger.error("Failed to create output stream to write an alert types ", e);

View File

@ -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.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ConfigValue; 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.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.apache.cloudstack.region.PortableIp; import org.apache.cloudstack.region.PortableIp;
import org.apache.cloudstack.region.PortableIpDao; import org.apache.cloudstack.region.PortableIpDao;
import org.apache.cloudstack.region.PortableIpRange; import org.apache.cloudstack.region.PortableIpRange;

View File

@ -30,10 +30,11 @@ import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import com.google.gson.Gson;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.google.gson.Gson;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd; import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd; 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 org.apache.cloudstack.utils.identity.ManagementServerNode;
import com.cloud.agent.AgentManager; import com.cloud.agent.AgentManager;
import com.cloud.agent.AgentManager.TapAgentsAction;
import com.cloud.agent.api.Answer; import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command; import com.cloud.agent.api.Command;
import com.cloud.agent.api.GetHostStatsAnswer; 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.StartupRoutingCommand;
import com.cloud.agent.api.UnsupportedAnswer; import com.cloud.agent.api.UnsupportedAnswer;
import com.cloud.agent.api.UpdateHostPasswordCommand; 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.agent.transport.Request;
import com.cloud.api.ApiDBUtils; import com.cloud.api.ApiDBUtils;
import com.cloud.capacity.Capacity; 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) { private Host createHostAndAgent(ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags, boolean forRebalance) {
HostVO host = null; HostVO host = null;
AgentAttache attache = null;
StartupCommand[] cmds = null; StartupCommand[] cmds = null;
boolean hostExists = false; 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); host = createHostVO(cmds, resource, details, hostTags, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT);
if (host != null) { if (host != null) {
attache = _agentMgr.handleDirectConnectAgent(host, cmds, resource, forRebalance);
/* reload myself from database */ /* reload myself from database */
host = _hostDao.findById(host.getId()); host = _hostDao.findById(host.getId());
} }
@ -1764,13 +1760,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
if (cmds != null) { if (cmds != null) {
resource.disconnected(); 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, private Host createHostAndAgentDeferred(ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags,
boolean forRebalance) { boolean forRebalance) {
HostVO host = null; HostVO host = null;
AgentAttache attache = null;
StartupCommand[] cmds = null; StartupCommand[] cmds = null;
boolean hostExists = false; boolean hostExists = false;
boolean deferAgentCreation = true; boolean deferAgentCreation = true;
@ -1826,30 +1814,13 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
host = null; host = null;
GlobalLock addHostLock = GlobalLock.getInternLock("AddHostLock"); GlobalLock addHostLock = GlobalLock.getInternLock("AddHostLock");
try { try {
if (addHostLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) { // to if (addHostLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
// safely // to safely determine first host in cluster in multi-MS scenario
// determine
// first
// host
// in
// cluster
// in
// multi-MS
// scenario
try { try {
host = createHostVO(cmds, resource, details, hostTags, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT); host = createHostVO(cmds, resource, details, hostTags, ResourceStateAdapter.Event.CREATE_HOST_VO_FOR_DIRECT_CONNECT);
if (host != null) { if (host != null) {
deferAgentCreation = !isFirstHostInCluster(host); // if // if first host in cluster no need to defer agent creation
// first deferAgentCreation = !isFirstHostInCluster(host);
// host
// in
// cluster
// no
// need
// to
// defer
// agent
// creation
} }
} finally { } finally {
addHostLock.unlock(); addHostLock.unlock();
@ -1861,9 +1832,6 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
if (host != null) { if (host != null) {
if (!deferAgentCreation) { // if first host in cluster then 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 host = _hostDao.findById(host.getId()); // reload
} else { } else {
host = _hostDao.findById(host.getId()); // reload 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 host.setLastPinged(0); // so that scan task can pick it up
_hostDao.update(host.getId(), host); _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) { } catch (Exception e) {
@ -1899,7 +1853,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
resource.disconnected(); resource.disconnected();
} }
} else { } else {
if (!deferAgentCreation && attache == null) { if (!deferAgentCreation) {
if (cmds != null) { if (cmds != null) {
resource.disconnected(); resource.disconnected();
} }
@ -1914,9 +1868,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
@Override @Override
public Host createHostAndAgent(Long hostId, ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags, public Host createHostAndAgent(Long hostId, ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags,
boolean forRebalance) { boolean forRebalance) {
_agentMgr.tapLoadingAgents(hostId, TapAgentsAction.Add);
Host host = createHostAndAgent(resource, details, old, hostTags, forRebalance); Host host = createHostAndAgent(resource, details, old, hostTags, forRebalance);
_agentMgr.tapLoadingAgents(hostId, TapAgentsAction.Del);
return host; return host;
} }

View File

@ -18,7 +18,7 @@ package com.cloud.server;
import java.util.List; import java.util.List;
import org.apache.cloudstack.framework.config.ConfigurationVO; import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import com.cloud.exception.InternalErrorException; import com.cloud.exception.InternalErrorException;

View File

@ -48,8 +48,8 @@ import org.apache.log4j.Logger;
import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigDepot;
import org.apache.cloudstack.framework.config.ConfigDepotAdmin; 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.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import com.cloud.configuration.Config; import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.ConfigurationManager;

View File

@ -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.engine.subsystem.api.storage.VolumeDataFactory;
import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ConfigValue; 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.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.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO; import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;

View File

@ -4887,14 +4887,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
@Override @Override
public String getConfigComponentName() { public String getConfigComponentName() {
// TODO Auto-generated method stub return UserVmManager.class.getSimpleName();
return null;
} }
@Override @Override
public ConfigKey<?>[] getConfigKeys() { public ConfigKey<?>[] getConfigKeys() {
// TODO Auto-generated method stub return new ConfigKey<?>[] {EnableDynamicallyScaleVm};
return null;
} }
} }

View File

@ -48,6 +48,7 @@ public class AlertControlsUnitTest extends TestCase {
@Mock AlertDao _alertDao; @Mock AlertDao _alertDao;
@Override @Override
@Before @Before
@SuppressWarnings("unchecked")
protected void setUp() { protected void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
_mgmtServer._alertDao = _alertDao; _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); when(_alertDao.deleteAlert(anyList(), anyString(), any(Date.class), any(Date.class), anyLong())).thenReturn(true);
} }
@Override
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
} }

View File

@ -21,8 +21,8 @@ import java.util.Map;
import javax.ejb.Local; 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.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericDaoBase;

View File

@ -35,8 +35,8 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.apache.cloudstack.context.CallContext; 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.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.ConfigurationManager;
import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.InvalidParameterValueException;

View File

@ -16,10 +16,9 @@
// under the License. // under the License.
package com.cloud.utils; package com.cloud.utils;
import com.cloud.utils.exception.CloudRuntimeException; import static java.beans.Introspector.getBeanInfo;
import com.google.common.collect.ImmutableSet; import static java.util.Collections.emptyList;
import org.apache.log4j.Logger; import static java.util.Collections.unmodifiableList;
import org.reflections.Reflections;
import java.beans.BeanInfo; import java.beans.BeanInfo;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
@ -34,9 +33,12 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static java.beans.Introspector.getBeanInfo; import org.apache.log4j.Logger;
import static java.util.Collections.emptyList; import org.reflections.Reflections;
import static java.util.Collections.unmodifiableList;
import com.google.common.collect.ImmutableSet;
import com.cloud.utils.exception.CloudRuntimeException;
public class ReflectUtil { public class ReflectUtil {
@ -109,7 +111,7 @@ public class ReflectUtil {
List<Field> fields = new ArrayList<Field>(); List<Field> fields = new ArrayList<Field>();
Collections.addAll(fields, cmdClass.getDeclaredFields()); Collections.addAll(fields, cmdClass.getDeclaredFields());
Class<?> superClass = cmdClass.getSuperclass(); Class<?> superClass = cmdClass.getSuperclass();
while (baseClass.isAssignableFrom(superClass)) { while (baseClass.isAssignableFrom(superClass) && baseClass != superClass) {
Field[] superClassFields = superClass.getDeclaredFields(); Field[] superClassFields = superClass.getDeclaredFields();
if (superClassFields != null) if (superClassFields != null)
Collections.addAll(fields, superClassFields); Collections.addAll(fields, superClassFields);

View File

@ -22,6 +22,7 @@ import java.util.List;
public class AdapterBase extends ComponentLifecycleBase implements Adapter, ComponentMethodInterceptable { public class AdapterBase extends ComponentLifecycleBase implements Adapter, ComponentMethodInterceptable {
public AdapterBase() { public AdapterBase() {
super();
// set default run level for adapter components // set default run level for adapter components
setRunLevel(ComponentLifecycle.RUN_LEVEL_COMPONENT); setRunLevel(ComponentLifecycle.RUN_LEVEL_COMPONENT);
} }

View File

@ -34,7 +34,6 @@ import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import com.cloud.utils.mgmt.JmxUtil; import com.cloud.utils.mgmt.JmxUtil;
import com.cloud.utils.mgmt.ManagementBean; 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 * are not recommended to be used outside, they exist to help wire Spring Framework
* *
*/ */
@Component @SuppressWarnings("unchecked")
public class ComponentContext implements ApplicationContextAware { public class ComponentContext implements ApplicationContextAware {
private static final Logger s_logger = Logger.getLogger(ComponentContext.class); private static final Logger s_logger = Logger.getLogger(ComponentContext.class);
@ -64,8 +63,7 @@ public class ComponentContext implements ApplicationContextAware {
public static void initComponentsLifeCycle() { public static void initComponentsLifeCycle() {
AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory(); AutowireCapableBeanFactory beanFactory = s_appContext.getAutowireCapableBeanFactory();
Map<String, ComponentMethodInterceptable> interceptableComponents = getApplicationContext().getBeansOfType( Map<String, ComponentMethodInterceptable> interceptableComponents = getApplicationContext().getBeansOfType(ComponentMethodInterceptable.class);
ComponentMethodInterceptable.class);
for (Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) { for (Map.Entry<String, ComponentMethodInterceptable> entry : interceptableComponents.entrySet()) {
Object bean = getTargetObject(entry.getValue()); Object bean = getTargetObject(entry.getValue());
beanFactory.configureBean(bean, entry.getKey()); beanFactory.configureBean(bean, entry.getKey());
@ -73,7 +71,7 @@ public class ComponentContext implements ApplicationContextAware {
Map<String, ComponentLifecycle> lifecycleComponents = getApplicationContext().getBeansOfType(ComponentLifecycle.class); Map<String, ComponentLifecycle> lifecycleComponents = getApplicationContext().getBeansOfType(ComponentLifecycle.class);
Map[] classifiedComponents = new Map[ComponentLifecycle.MAX_RUN_LEVELS]; Map<String, ComponentLifecycle>[] classifiedComponents = new Map[ComponentLifecycle.MAX_RUN_LEVELS];
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) { for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
classifiedComponents[i] = new HashMap<String, ComponentLifecycle>(); classifiedComponents[i] = new HashMap<String, ComponentLifecycle>();
} }
@ -97,7 +95,7 @@ public class ComponentContext implements ApplicationContextAware {
// configuration phase // configuration phase
Map<String, String> avoidMap = new HashMap<String, String>(); Map<String, String> avoidMap = new HashMap<String, String>();
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) { for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
for(Map.Entry<String, ComponentLifecycle> entry : ((Map<String, ComponentLifecycle>)classifiedComponents[i]).entrySet()) { for (Map.Entry<String, ComponentLifecycle> entry : classifiedComponents[i].entrySet()) {
ComponentLifecycle component = entry.getValue(); ComponentLifecycle component = entry.getValue();
String implClassName = ComponentContext.getTargetClass(component).getName(); String implClassName = ComponentContext.getTargetClass(component).getName();
s_logger.info("Configuring " + implClassName); s_logger.info("Configuring " + implClassName);
@ -121,7 +119,7 @@ public class ComponentContext implements ApplicationContextAware {
// starting phase // starting phase
avoidMap.clear(); avoidMap.clear();
for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) { for (int i = 0; i < ComponentLifecycle.MAX_RUN_LEVELS; i++) {
for(Map.Entry<String, ComponentLifecycle> entry : ((Map<String, ComponentLifecycle>)classifiedComponents[i]).entrySet()) { for (Map.Entry<String, ComponentLifecycle> entry : classifiedComponents[i].entrySet()) {
ComponentLifecycle component = entry.getValue(); ComponentLifecycle component = entry.getValue();
String implClassName = ComponentContext.getTargetClass(component).getName(); String implClassName = ComponentContext.getTargetClass(component).getName();
s_logger.info("Starting " + implClassName); s_logger.info("Starting " + implClassName);

View File

@ -20,6 +20,7 @@ import java.lang.reflect.Field;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.annotation.PostConstruct;
import javax.inject.Inject; import javax.inject.Inject;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
@ -36,7 +37,11 @@ public class ComponentLifecycleBase implements ComponentLifecycle {
public ComponentLifecycleBase() { public ComponentLifecycleBase() {
_name = this.getClass().getSimpleName(); _name = this.getClass().getSimpleName();
_runLevel = RUN_LEVEL_COMPONENT; _runLevel = RUN_LEVEL_COMPONENT;
}
@PostConstruct
protected void injectConfigs() {
if (_configInjector != null) {
for (Field field : ReflectUtil.getAllFieldsForClass(this.getClass(), Object.class)) { for (Field field : ReflectUtil.getAllFieldsForClass(this.getClass(), Object.class)) {
InjectConfig config = field.getAnnotation(InjectConfig.class); InjectConfig config = field.getAnnotation(InjectConfig.class);
if (config != null) { if (config != null) {
@ -45,6 +50,7 @@ public class ComponentLifecycleBase implements ComponentLifecycle {
} }
} }
} }
}
@Override @Override
public String getName() { public String getName() {
@ -77,8 +83,7 @@ public class ComponentLifecycleBase implements ComponentLifecycle {
} }
@Override @Override
public boolean configure(String name, Map<String, Object> params) public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
throws ConfigurationException {
_name = name; _name = name;
_configParams = params; _configParams = params;
return true; return true;

View File

@ -18,6 +18,7 @@ package com.cloud.utils.component;
public class ManagerBase extends ComponentLifecycleBase implements ComponentMethodInterceptable { public class ManagerBase extends ComponentLifecycleBase implements ComponentMethodInterceptable {
public ManagerBase() { public ManagerBase() {
super();
// set default run level for manager components // set default run level for manager components
setRunLevel(ComponentLifecycle.RUN_LEVEL_COMPONENT_BOOTSTRAP); setRunLevel(ComponentLifecycle.RUN_LEVEL_COMPONENT_BOOTSTRAP);
} }