Skip to content

Commit b96bb8f

Browse files
committed
Hook log4j to Spring bootstrapped Javelin server
1 parent 559933f commit b96bb8f

5 files changed

Lines changed: 104 additions & 80 deletions

File tree

engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDetailsDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.cloud.utils.db.SearchCriteria;
3232
import com.cloud.utils.db.Transaction;
3333

34-
//@Component(value="EngineHostDetailsDao")
34+
@Component(value="EngineHostDetailsDao")
3535
@Local(value=HostDetailsDao.class)
3636
public class HostDetailsDaoImpl extends GenericDaoBase<DetailVO, Long> implements HostDetailsDao {
3737
protected final SearchBuilder<DetailVO> HostSearch;

server/src/com/cloud/server/ManagementServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public interface ManagementServer extends ManagementService {
3838
*/
3939
long getId();
4040

41+
void startup();
42+
4143
/**
4244
* Fetches the version of cloud stack
4345
*/

server/src/com/cloud/server/ManagementServerExtImpl.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
import java.util.Map;
2424
import java.util.TimeZone;
2525

26+
import javax.annotation.PostConstruct;
27+
import javax.inject.Inject;
28+
29+
import org.springframework.context.annotation.Primary;
30+
import org.springframework.stereotype.Component;
31+
2632
import com.cloud.api.commands.GenerateUsageRecordsCmd;
2733
import com.cloud.api.commands.GetUsageRecordsCmd;
2834
import com.cloud.domain.dao.DomainDao;
@@ -39,33 +45,32 @@
3945
import com.cloud.user.AccountVO;
4046
import com.cloud.user.UserContext;
4147
import com.cloud.user.dao.AccountDao;
42-
import com.cloud.utils.component.ComponentLocator;
4348
import com.cloud.utils.db.Filter;
4449
import com.cloud.utils.db.SearchCriteria;
4550
import com.cloud.utils.db.Transaction;
4651

52+
@Component
53+
@Primary
4754
public class ManagementServerExtImpl extends ManagementServerImpl implements ManagementServerExt {
48-
private final AccountDao _accountDao;
49-
private final DomainDao _domainDao;
50-
private final UsageDao _usageDao;
51-
private final UsageJobDao _usageJobDao;
52-
private final TimeZone _usageTimezone;
53-
54-
protected ManagementServerExtImpl() {
55-
super();
56-
57-
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
58-
_accountDao = locator.getDao(AccountDao.class);
59-
_domainDao = locator.getDao(DomainDao.class);
60-
_usageDao = locator.getDao(UsageDao.class);
61-
_usageJobDao = locator.getDao(UsageJobDao.class);
55+
@Inject private AccountDao _accountDao;
56+
@Inject private DomainDao _domainDao;
57+
@Inject private UsageDao _usageDao;
58+
@Inject private UsageJobDao _usageJobDao;
59+
private TimeZone _usageTimezone;
6260

61+
public ManagementServerExtImpl() {
62+
}
63+
64+
@PostConstruct
65+
void init() {
66+
super.init();
67+
6368
Map<String, String> configs = getConfigs();
64-
String timeZoneStr = configs.get("usage.aggregation.timezone");
65-
if (timeZoneStr == null) {
66-
timeZoneStr = "GMT";
67-
}
68-
_usageTimezone = TimeZone.getTimeZone(timeZoneStr);
69+
String timeZoneStr = configs.get("usage.aggregation.timezone");
70+
if (timeZoneStr == null) {
71+
timeZoneStr = "GMT";
72+
}
73+
_usageTimezone = TimeZone.getTimeZone(timeZoneStr);
6974
}
7075

7176
@Override

server/src/com/cloud/server/ManagementServerImpl.java

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,12 @@
221221
import com.cloud.utils.component.Adapters;
222222
import com.cloud.utils.component.ComponentContext;
223223
import com.cloud.utils.component.ComponentLocator;
224+
import com.cloud.utils.component.SystemIntegrityChecker;
224225
import com.cloud.utils.concurrency.NamedThreadFactory;
225226
import com.cloud.utils.crypt.DBEncryptionUtil;
226227
import com.cloud.utils.db.DB;
227228
import com.cloud.utils.db.Filter;
229+
import com.cloud.utils.db.GenericDaoBase;
228230
import com.cloud.utils.db.GlobalLock;
229231
import com.cloud.utils.db.JoinBuilder;
230232
import com.cloud.utils.db.JoinBuilder.JoinType;
@@ -314,11 +316,11 @@ public class ManagementServerImpl implements ManagementServer {
314316
@Inject private ConfigurationManager _configMgr;
315317
@Inject private ResourceTagDao _resourceTagDao;
316318

317-
@Inject private ProjectManager _projectMgr;
318-
@Inject private ResourceManager _resourceMgr;
319-
@Inject private SnapshotManager _snapshotMgr;
320-
@Inject private HighAvailabilityManager _haMgr;
321-
@Inject private HostTagsDao _hostTagsDao;
319+
@Inject ProjectManager _projectMgr;
320+
@Inject ResourceManager _resourceMgr;
321+
@Inject SnapshotManager _snapshotMgr;
322+
@Inject HighAvailabilityManager _haMgr;
323+
@Inject HostTagsDao _hostTagsDao;
322324

323325
@Inject ComponentContext _placeholder;
324326

@@ -357,7 +359,54 @@ void init() {
357359
_availableIdsMap.put(id, true);
358360
}
359361
}
360-
362+
363+
public void startup() {
364+
s_logger.info("Startup CloudStack management server...");
365+
initCloudStackComponents();
366+
}
367+
368+
private void initCloudStackComponents() {
369+
runCheckers();
370+
startDaos(); // daos should not be using managers and adapters.
371+
372+
/*
373+
configureManagers();
374+
configureAdapters();
375+
startManagers();
376+
startAdapters();
377+
*/
378+
}
379+
380+
private void runCheckers() {
381+
Map<String, SystemIntegrityChecker> checkers = ComponentContext.getApplicationContext().getBeansOfType(
382+
SystemIntegrityChecker.class);
383+
384+
for(SystemIntegrityChecker checker : checkers.values()) {
385+
try {
386+
checker.check();
387+
} catch (Exception e) {
388+
s_logger.error("Problems with running checker:" + checker.getClass().getName(), e);
389+
System.exit(1);
390+
}
391+
}
392+
}
393+
394+
private void startDaos() {
395+
@SuppressWarnings("rawtypes")
396+
Map<String, GenericDaoBase> daos = ComponentContext.getApplicationContext().getBeansOfType(
397+
GenericDaoBase.class);
398+
399+
for(GenericDaoBase dao : daos.values()) {
400+
try {
401+
402+
// dao.configure(dao.getClass().getSimpleName(), params);
403+
} catch (Exception e) {
404+
s_logger.error("Problems with running checker:" + dao.getClass().getName(), e);
405+
System.exit(1);
406+
}
407+
}
408+
}
409+
361410
protected Map<String, String> getConfigs() {
362411
return _configs;
363412
}

server/src/com/cloud/servlet/CloudStartupServlet.java

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,40 @@
1616
// under the License.
1717
package com.cloud.servlet;
1818

19-
import java.util.Map;
19+
import java.io.File;
2020

2121
import javax.servlet.ServletContextEvent;
2222
import javax.servlet.ServletContextListener;
2323
import javax.servlet.ServletException;
2424
import javax.servlet.http.HttpServlet;
2525

2626
import org.apache.log4j.Logger;
27+
import org.apache.log4j.PropertyConfigurator;
28+
import org.apache.log4j.xml.DOMConfigurator;
2729

2830
import com.cloud.api.ApiServer;
2931
import com.cloud.exception.InvalidParameterValueException;
3032
import com.cloud.server.ConfigurationServer;
3133
import com.cloud.server.ManagementServer;
34+
import com.cloud.utils.PropertiesUtil;
3235
import com.cloud.utils.SerialVersionUID;
3336
import com.cloud.utils.component.ComponentContext;
34-
import com.cloud.utils.component.ComponentLocator;
35-
import com.cloud.utils.component.SystemIntegrityChecker;
36-
import com.cloud.utils.db.GenericDaoBase;
3737

3838
public class CloudStartupServlet extends HttpServlet implements ServletContextListener {
3939
public static final Logger s_logger = Logger.getLogger(CloudStartupServlet.class.getName());
4040

4141
static final long serialVersionUID = SerialVersionUID.CloudStartupServlet;
4242

43-
protected static ComponentLocator s_locator;
44-
4543
@Override
4644
public void init() throws ServletException {
47-
48-
// Save Configuration Values
45+
initLog4j();
46+
47+
// Save Configuration Values
4948
ConfigurationServer c = (ConfigurationServer)ComponentContext.getCompanent(ConfigurationServer.class);
5049
try {
5150
c.persistDefaultValues();
5251
ManagementServer ms = (ManagementServer)ComponentContext.getCompanent(ManagementServer.class);
52+
ms.startup();
5353
ApiServer.initApiServer(ms.getApiConfig());
5454
} catch (InvalidParameterValueException ipve) {
5555
s_logger.error("Exception starting management server ", ipve);
@@ -73,50 +73,18 @@ public void contextInitialized(ServletContextEvent sce) {
7373
@Override
7474
public void contextDestroyed(ServletContextEvent sce) {
7575
}
76-
77-
//
78-
// following should be moved to CloudStackServer component later to encapsulate business logic in one place
79-
//
80-
private void initCloudStackComponents() {
81-
runCheckers();
82-
startDaos(); // daos should not be using managers and adapters.
83-
84-
/*
85-
configureManagers();
86-
configureAdapters();
87-
startManagers();
88-
startAdapters();
89-
*/
90-
}
91-
92-
private void runCheckers() {
93-
Map<String, SystemIntegrityChecker> checkers = ComponentContext.getApplicationContext().getBeansOfType(
94-
SystemIntegrityChecker.class);
95-
96-
for(SystemIntegrityChecker checker : checkers.values()) {
97-
try {
98-
checker.check();
99-
} catch (Exception e) {
100-
s_logger.error("Problems with running checker:" + checker.getClass().getName(), e);
101-
System.exit(1);
102-
}
103-
}
104-
}
105-
106-
private void startDaos() {
107-
@SuppressWarnings("rawtypes")
108-
Map<String, GenericDaoBase> daos = ComponentContext.getApplicationContext().getBeansOfType(
109-
GenericDaoBase.class);
110-
111-
for(GenericDaoBase dao : daos.values()) {
112-
try {
113-
114-
// dao.configure(dao.getClass().getSimpleName(), params);
115-
} catch (Exception e) {
116-
s_logger.error("Problems with running checker:" + dao.getClass().getName(), e);
117-
System.exit(1);
118-
}
119-
}
120-
}
12176

77+
private void initLog4j() {
78+
File file = PropertiesUtil.findConfigFile("log4j-cloud.xml");
79+
if (file != null) {
80+
s_logger.info("log4j configuration found at " + file.getAbsolutePath());
81+
DOMConfigurator.configureAndWatch(file.getAbsolutePath());
82+
} else {
83+
file = PropertiesUtil.findConfigFile("log4j-cloud.properties");
84+
if (file != null) {
85+
s_logger.info("log4j configuration found at " + file.getAbsolutePath());
86+
PropertyConfigurator.configureAndWatch(file.getAbsolutePath());
87+
}
88+
}
89+
}
12290
}

0 commit comments

Comments
 (0)