mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
Hook log4j to Spring bootstrapped Javelin server
This commit is contained in:
parent
559933f062
commit
b96bb8feb9
@ -31,7 +31,7 @@ import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
//@Component(value="EngineHostDetailsDao")
|
||||
@Component(value="EngineHostDetailsDao")
|
||||
@Local(value=HostDetailsDao.class)
|
||||
public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements HostDetailsDao {
|
||||
protected final SearchBuilder<DetailVO> HostSearch;
|
||||
|
||||
@ -38,6 +38,8 @@ public interface ManagementServer extends ManagementService {
|
||||
*/
|
||||
long getId();
|
||||
|
||||
void startup();
|
||||
|
||||
/**
|
||||
* Fetches the version of cloud stack
|
||||
*/
|
||||
|
||||
@ -23,6 +23,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.api.commands.GenerateUsageRecordsCmd;
|
||||
import com.cloud.api.commands.GetUsageRecordsCmd;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
@ -39,33 +45,32 @@ import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
public class ManagementServerExtImpl extends ManagementServerImpl implements ManagementServerExt {
|
||||
private final AccountDao _accountDao;
|
||||
private final DomainDao _domainDao;
|
||||
private final UsageDao _usageDao;
|
||||
private final UsageJobDao _usageJobDao;
|
||||
private final TimeZone _usageTimezone;
|
||||
|
||||
protected ManagementServerExtImpl() {
|
||||
super();
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
_accountDao = locator.getDao(AccountDao.class);
|
||||
_domainDao = locator.getDao(DomainDao.class);
|
||||
_usageDao = locator.getDao(UsageDao.class);
|
||||
_usageJobDao = locator.getDao(UsageJobDao.class);
|
||||
@Inject private AccountDao _accountDao;
|
||||
@Inject private DomainDao _domainDao;
|
||||
@Inject private UsageDao _usageDao;
|
||||
@Inject private UsageJobDao _usageJobDao;
|
||||
private TimeZone _usageTimezone;
|
||||
|
||||
public ManagementServerExtImpl() {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
void init() {
|
||||
super.init();
|
||||
|
||||
Map<String, String> configs = getConfigs();
|
||||
String timeZoneStr = configs.get("usage.aggregation.timezone");
|
||||
if (timeZoneStr == null) {
|
||||
timeZoneStr = "GMT";
|
||||
}
|
||||
_usageTimezone = TimeZone.getTimeZone(timeZoneStr);
|
||||
String timeZoneStr = configs.get("usage.aggregation.timezone");
|
||||
if (timeZoneStr == null) {
|
||||
timeZoneStr = "GMT";
|
||||
}
|
||||
_usageTimezone = TimeZone.getTimeZone(timeZoneStr);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -221,10 +221,12 @@ import com.cloud.utils.Ternary;
|
||||
import com.cloud.utils.component.Adapters;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.SystemIntegrityChecker;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.crypt.DBEncryptionUtil;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Filter;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.db.JoinBuilder;
|
||||
import com.cloud.utils.db.JoinBuilder.JoinType;
|
||||
@ -314,11 +316,11 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
@Inject private ConfigurationManager _configMgr;
|
||||
@Inject private ResourceTagDao _resourceTagDao;
|
||||
|
||||
@Inject private ProjectManager _projectMgr;
|
||||
@Inject private ResourceManager _resourceMgr;
|
||||
@Inject private SnapshotManager _snapshotMgr;
|
||||
@Inject private HighAvailabilityManager _haMgr;
|
||||
@Inject private HostTagsDao _hostTagsDao;
|
||||
@Inject ProjectManager _projectMgr;
|
||||
@Inject ResourceManager _resourceMgr;
|
||||
@Inject SnapshotManager _snapshotMgr;
|
||||
@Inject HighAvailabilityManager _haMgr;
|
||||
@Inject HostTagsDao _hostTagsDao;
|
||||
|
||||
@Inject ComponentContext _placeholder;
|
||||
|
||||
@ -357,7 +359,54 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
_availableIdsMap.put(id, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void startup() {
|
||||
s_logger.info("Startup CloudStack management server...");
|
||||
initCloudStackComponents();
|
||||
}
|
||||
|
||||
private void initCloudStackComponents() {
|
||||
runCheckers();
|
||||
startDaos(); // daos should not be using managers and adapters.
|
||||
|
||||
/*
|
||||
configureManagers();
|
||||
configureAdapters();
|
||||
startManagers();
|
||||
startAdapters();
|
||||
*/
|
||||
}
|
||||
|
||||
private void runCheckers() {
|
||||
Map<String, SystemIntegrityChecker> checkers = ComponentContext.getApplicationContext().getBeansOfType(
|
||||
SystemIntegrityChecker.class);
|
||||
|
||||
for(SystemIntegrityChecker checker : checkers.values()) {
|
||||
try {
|
||||
checker.check();
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Problems with running checker:" + checker.getClass().getName(), e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startDaos() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
Map<String, GenericDaoBase> daos = ComponentContext.getApplicationContext().getBeansOfType(
|
||||
GenericDaoBase.class);
|
||||
|
||||
for(GenericDaoBase dao : daos.values()) {
|
||||
try {
|
||||
|
||||
// dao.configure(dao.getClass().getSimpleName(), params);
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Problems with running checker:" + dao.getClass().getName(), e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<String, String> getConfigs() {
|
||||
return _configs;
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
// under the License.
|
||||
package com.cloud.servlet;
|
||||
|
||||
import java.util.Map;
|
||||
import java.io.File;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
@ -24,32 +24,32 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PropertyConfigurator;
|
||||
import org.apache.log4j.xml.DOMConfigurator;
|
||||
|
||||
import com.cloud.api.ApiServer;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.server.ConfigurationServer;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.utils.PropertiesUtil;
|
||||
import com.cloud.utils.SerialVersionUID;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.component.SystemIntegrityChecker;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
||||
public class CloudStartupServlet extends HttpServlet implements ServletContextListener {
|
||||
public static final Logger s_logger = Logger.getLogger(CloudStartupServlet.class.getName());
|
||||
|
||||
static final long serialVersionUID = SerialVersionUID.CloudStartupServlet;
|
||||
|
||||
protected static ComponentLocator s_locator;
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
|
||||
// Save Configuration Values
|
||||
initLog4j();
|
||||
|
||||
// Save Configuration Values
|
||||
ConfigurationServer c = (ConfigurationServer)ComponentContext.getCompanent(ConfigurationServer.class);
|
||||
try {
|
||||
c.persistDefaultValues();
|
||||
ManagementServer ms = (ManagementServer)ComponentContext.getCompanent(ManagementServer.class);
|
||||
ms.startup();
|
||||
ApiServer.initApiServer(ms.getApiConfig());
|
||||
} catch (InvalidParameterValueException ipve) {
|
||||
s_logger.error("Exception starting management server ", ipve);
|
||||
@ -73,50 +73,18 @@ public class CloudStartupServlet extends HttpServlet implements ServletContextLi
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
}
|
||||
|
||||
//
|
||||
// following should be moved to CloudStackServer component later to encapsulate business logic in one place
|
||||
//
|
||||
private void initCloudStackComponents() {
|
||||
runCheckers();
|
||||
startDaos(); // daos should not be using managers and adapters.
|
||||
|
||||
/*
|
||||
configureManagers();
|
||||
configureAdapters();
|
||||
startManagers();
|
||||
startAdapters();
|
||||
*/
|
||||
|
||||
private void initLog4j() {
|
||||
File file = PropertiesUtil.findConfigFile("log4j-cloud.xml");
|
||||
if (file != null) {
|
||||
s_logger.info("log4j configuration found at " + file.getAbsolutePath());
|
||||
DOMConfigurator.configureAndWatch(file.getAbsolutePath());
|
||||
} else {
|
||||
file = PropertiesUtil.findConfigFile("log4j-cloud.properties");
|
||||
if (file != null) {
|
||||
s_logger.info("log4j configuration found at " + file.getAbsolutePath());
|
||||
PropertyConfigurator.configureAndWatch(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void runCheckers() {
|
||||
Map<String, SystemIntegrityChecker> checkers = ComponentContext.getApplicationContext().getBeansOfType(
|
||||
SystemIntegrityChecker.class);
|
||||
|
||||
for(SystemIntegrityChecker checker : checkers.values()) {
|
||||
try {
|
||||
checker.check();
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Problems with running checker:" + checker.getClass().getName(), e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startDaos() {
|
||||
@SuppressWarnings("rawtypes")
|
||||
Map<String, GenericDaoBase> daos = ComponentContext.getApplicationContext().getBeansOfType(
|
||||
GenericDaoBase.class);
|
||||
|
||||
for(GenericDaoBase dao : daos.values()) {
|
||||
try {
|
||||
|
||||
// dao.configure(dao.getClass().getSimpleName(), params);
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Problems with running checker:" + dao.getClass().getName(), e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user