From 0cd61bfe7089d2fbc13202fed32bdb05c291d2be Mon Sep 17 00:00:00 2001 From: youyong205 Date: Sat, 3 Jan 2015 00:45:48 +0800 Subject: [PATCH] fix last report null problem --- .../page/dependency/ExternalInfoBuilder.java | 1 + .../page/model/cross/LocalCrossService.java | 2 +- .../dependency/LocalDependencyService.java | 2 +- .../page/model/event/LocalEventService.java | 2 +- .../heartbeat/LocalHeartbeatService.java | 2 +- .../page/model/matrix/LocalMatrixService.java | 2 +- .../page/model/metric/LocalMetricService.java | 2 +- .../model/problem/LocalProblemService.java | 2 +- .../page/model/state/LocalStateService.java | 2 +- .../page/model/top/LocalTopService.java | 4 +- .../transaction/LocalTransactionService.java | 2 +- .../service/DefaultReportServiceManager.java | 663 +++++++++--------- 12 files changed, 345 insertions(+), 341 deletions(-) diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/dependency/ExternalInfoBuilder.java b/cat-home/src/main/java/com/dianping/cat/report/page/dependency/ExternalInfoBuilder.java index 38fa42ece8..0340ac04d0 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/page/dependency/ExternalInfoBuilder.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/dependency/ExternalInfoBuilder.java @@ -127,6 +127,7 @@ private TopReport queryTopReport(Payload payload) { if (m_topService.isEligable(request)) { ModelResponse response = m_topService.invoke(request); TopReport report = response.getModel(); + if (report == null || report.getDomains().size() == 0) { report = m_reportService.queryTopReport(domain, new Date(payload.getDate()), new Date(payload.getDate() + TimeHelper.ONE_HOUR)); diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/model/cross/LocalCrossService.java b/cat-home/src/main/java/com/dianping/cat/report/page/model/cross/LocalCrossService.java index 98370fea98..3c5d72e511 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/page/model/cross/LocalCrossService.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/model/cross/LocalCrossService.java @@ -27,7 +27,7 @@ public LocalCrossService() { protected CrossReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception { CrossReport report = super.getReport(request, period, domain); - if (report == null && period.isLast()) { + if ((report == null || report.getIps().isEmpty()) && period.isLast()) { long startTime = request.getStartTime(); report = getReportFromLocalDisk(startTime, domain); diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/model/dependency/LocalDependencyService.java b/cat-home/src/main/java/com/dianping/cat/report/page/model/dependency/LocalDependencyService.java index e4980926fc..cd864088a1 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/page/model/dependency/LocalDependencyService.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/model/dependency/LocalDependencyService.java @@ -27,7 +27,7 @@ public LocalDependencyService() { protected DependencyReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception { DependencyReport report = super.getReport(request, period, domain); - if (report == null && period.isLast()) { + if ((report == null || report.getDomainNames().isEmpty()) && period.isLast()) { long startTime = request.getStartTime(); report = getReportFromLocalDisk(startTime, domain); } diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/model/event/LocalEventService.java b/cat-home/src/main/java/com/dianping/cat/report/page/model/event/LocalEventService.java index 2aa9cb9c4c..c3253c3d14 100755 --- a/cat-home/src/main/java/com/dianping/cat/report/page/model/event/LocalEventService.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/model/event/LocalEventService.java @@ -27,7 +27,7 @@ public LocalEventService() { protected EventReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception { EventReport report = super.getReport(request, period, domain); - if (report == null && period.isLast()) { + if ((report == null || report.getIps().isEmpty()) && period.isLast()) { long startTime = request.getStartTime(); report = getReportFromLocalDisk(startTime, domain); } diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/model/heartbeat/LocalHeartbeatService.java b/cat-home/src/main/java/com/dianping/cat/report/page/model/heartbeat/LocalHeartbeatService.java index bd3bd09c95..2dd56730f7 100755 --- a/cat-home/src/main/java/com/dianping/cat/report/page/model/heartbeat/LocalHeartbeatService.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/model/heartbeat/LocalHeartbeatService.java @@ -26,7 +26,7 @@ public LocalHeartbeatService() { protected HeartbeatReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception { HeartbeatReport report = super.getReport(request, period, domain); - if (report == null && period.isLast()) { + if ((report == null || report.getIps().isEmpty()) && period.isLast()) { long startTime = request.getStartTime(); report = getReportFromLocalDisk(startTime, domain); } diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/model/matrix/LocalMatrixService.java b/cat-home/src/main/java/com/dianping/cat/report/page/model/matrix/LocalMatrixService.java index dec7db97c2..db50fadbff 100755 --- a/cat-home/src/main/java/com/dianping/cat/report/page/model/matrix/LocalMatrixService.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/model/matrix/LocalMatrixService.java @@ -27,7 +27,7 @@ public LocalMatrixService() { protected MatrixReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception { MatrixReport report = super.getReport(request, period, domain); - if (report == null && period.isLast()) { + if ((report == null || report.getDomainNames().isEmpty()) && period.isLast()) { long startTime = request.getStartTime(); report = getReportFromLocalDisk(startTime, domain); } diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/model/metric/LocalMetricService.java b/cat-home/src/main/java/com/dianping/cat/report/page/model/metric/LocalMetricService.java index 662432620d..1c3203a1c3 100755 --- a/cat-home/src/main/java/com/dianping/cat/report/page/model/metric/LocalMetricService.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/model/metric/LocalMetricService.java @@ -26,7 +26,7 @@ public LocalMetricService() { protected MetricReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception { MetricReport report = super.getReport(request, period, domain); - if (report == null && period.isLast()) { + if ((report == null || report.getMetricItems().isEmpty()) && period.isLast()) { long startTime = request.getStartTime(); report = getReportFromLocalDisk(startTime, domain); diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/model/problem/LocalProblemService.java b/cat-home/src/main/java/com/dianping/cat/report/page/model/problem/LocalProblemService.java index 815cc3c6de..725b5a2b7f 100755 --- a/cat-home/src/main/java/com/dianping/cat/report/page/model/problem/LocalProblemService.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/model/problem/LocalProblemService.java @@ -27,7 +27,7 @@ public LocalProblemService() { protected ProblemReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception { ProblemReport report = super.getReport(request, period, domain); - if (report == null && period.isLast()) { + if ((report == null || report.getIps().isEmpty()) && period.isLast()) { long startTime = request.getStartTime(); report = getReportFromLocalDisk(startTime, domain); } diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/model/state/LocalStateService.java b/cat-home/src/main/java/com/dianping/cat/report/page/model/state/LocalStateService.java index 1c54ac355a..b01694e22e 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/page/model/state/LocalStateService.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/model/state/LocalStateService.java @@ -26,7 +26,7 @@ public LocalStateService() { protected StateReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception { StateReport report = super.getReport(request, period, domain); - if (report == null && period.isLast()) { + if ((report == null || report.getMachines().isEmpty()) && period.isLast()) { long startTime = request.getStartTime(); report = getReportFromLocalDisk(startTime, domain); diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/model/top/LocalTopService.java b/cat-home/src/main/java/com/dianping/cat/report/page/model/top/LocalTopService.java index 6124086c03..3d19e2ff17 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/page/model/top/LocalTopService.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/model/top/LocalTopService.java @@ -26,10 +26,10 @@ public LocalTopService() { protected TopReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception { TopReport report = super.getReport(request, period, domain); - if (report == null && period.isLast()) { + if ((report == null || report.getDomains().isEmpty()) && period.isLast()) { long startTime = request.getStartTime(); report = getReportFromLocalDisk(startTime, domain); - + if (report == null) { report = new TopReport(domain); report.setStartTime(new Date(startTime)); diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/model/transaction/LocalTransactionService.java b/cat-home/src/main/java/com/dianping/cat/report/page/model/transaction/LocalTransactionService.java index 1ab94aaa70..2219919376 100755 --- a/cat-home/src/main/java/com/dianping/cat/report/page/model/transaction/LocalTransactionService.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/model/transaction/LocalTransactionService.java @@ -26,7 +26,7 @@ public LocalTransactionService() { protected TransactionReport getReport(ModelRequest request, ModelPeriod period, String domain) throws Exception { TransactionReport report = super.getReport(request, period, domain); - if (report == null && period.isLast()) { + if ((report == null || report.getIps().isEmpty()) && period.isLast()) { long startTime = request.getStartTime(); report = getReportFromLocalDisk(startTime, domain); } diff --git a/cat-home/src/main/java/com/dianping/cat/report/service/DefaultReportServiceManager.java b/cat-home/src/main/java/com/dianping/cat/report/service/DefaultReportServiceManager.java index 9ad6a07d2f..7da66cb320 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/service/DefaultReportServiceManager.java +++ b/cat-home/src/main/java/com/dianping/cat/report/service/DefaultReportServiceManager.java @@ -1,330 +1,333 @@ -package com.dianping.cat.report.service; - -import java.util.Date; -import java.util.Map; -import java.util.Set; - -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; -import org.unidal.dal.jdbc.DalException; -import org.unidal.lookup.ContainerHolder; -import org.unidal.lookup.annotation.Inject; - -import com.dianping.cat.Cat; -import com.dianping.cat.Constants; -import com.dianping.cat.consumer.cross.CrossAnalyzer; -import com.dianping.cat.consumer.cross.model.entity.CrossReport; -import com.dianping.cat.consumer.dependency.DependencyAnalyzer; -import com.dianping.cat.consumer.dependency.model.entity.DependencyReport; -import com.dianping.cat.consumer.event.EventAnalyzer; -import com.dianping.cat.consumer.event.model.entity.EventReport; -import com.dianping.cat.consumer.heartbeat.HeartbeatAnalyzer; -import com.dianping.cat.consumer.heartbeat.model.entity.HeartbeatReport; -import com.dianping.cat.consumer.matrix.MatrixAnalyzer; -import com.dianping.cat.consumer.matrix.model.entity.MatrixReport; -import com.dianping.cat.consumer.metric.MetricAnalyzer; -import com.dianping.cat.consumer.metric.model.entity.MetricReport; -import com.dianping.cat.consumer.problem.ProblemAnalyzer; -import com.dianping.cat.consumer.problem.model.entity.ProblemReport; -import com.dianping.cat.consumer.state.StateAnalyzer; -import com.dianping.cat.consumer.state.model.entity.StateReport; -import com.dianping.cat.consumer.top.TopAnalyzer; -import com.dianping.cat.consumer.top.model.entity.TopReport; -import com.dianping.cat.consumer.transaction.TransactionAnalyzer; -import com.dianping.cat.consumer.transaction.model.entity.TransactionReport; -import com.dianping.cat.core.dal.DailyReport; -import com.dianping.cat.core.dal.DailyReportDao; -import com.dianping.cat.core.dal.HourlyReport; -import com.dianping.cat.core.dal.HourlyReportContent; -import com.dianping.cat.core.dal.HourlyReportContentDao; -import com.dianping.cat.core.dal.HourlyReportDao; -import com.dianping.cat.core.dal.MonthlyReport; -import com.dianping.cat.core.dal.MonthlyReportDao; -import com.dianping.cat.core.dal.MonthlyReportEntity; -import com.dianping.cat.core.dal.WeeklyReport; -import com.dianping.cat.core.dal.WeeklyReportDao; -import com.dianping.cat.core.dal.WeeklyReportEntity; -import com.dianping.cat.home.alert.report.entity.AlertReport; -import com.dianping.cat.home.bug.entity.BugReport; -import com.dianping.cat.home.dal.report.DailyReportContent; -import com.dianping.cat.home.dal.report.DailyReportContentDao; -import com.dianping.cat.home.dal.report.MonthlyReportContent; -import com.dianping.cat.home.dal.report.MonthlyReportContentDao; -import com.dianping.cat.home.dal.report.WeeklyReportContent; -import com.dianping.cat.home.dal.report.WeeklyReportContentDao; -import com.dianping.cat.home.heavy.entity.HeavyReport; -import com.dianping.cat.home.highload.entity.HighloadReport; -import com.dianping.cat.home.jar.entity.JarReport; -import com.dianping.cat.home.network.entity.NetGraphSet; -import com.dianping.cat.home.router.entity.RouterConfig; -import com.dianping.cat.home.service.entity.ServiceReport; -import com.dianping.cat.home.utilization.entity.UtilizationReport; - -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class DefaultReportServiceManager extends ContainerHolder implements ReportServiceManager, Initializable { - - @Inject - private HourlyReportDao m_hourlyReportDao; - - @Inject - private DailyReportDao m_dailyReportDao; - - @Inject - private WeeklyReportDao m_weeklyReportDao; - - @Inject - private MonthlyReportDao m_monthlyReportDao; - - @Inject - private HourlyReportContentDao m_hourlyReportContentDao; - - @Inject - private DailyReportContentDao m_dailyReportContentDao; - - @Inject - private WeeklyReportContentDao m_weeklyReportContentDao; - - @Inject - private MonthlyReportContentDao m_monthlyReportContentDao; - - private Map m_reportServices; - - @Override - public void initialize() throws InitializationException { - m_reportServices = lookupMap(ReportService.class); - } - - @Override - public boolean insertDailyReport(DailyReport report, byte[] content) { - try { - report.setContent(""); - m_dailyReportDao.insert(report); - - int id = report.getId(); - DailyReportContent proto = m_dailyReportContentDao.createLocal(); - - proto.setReportId(id); - proto.setContent(content); - m_dailyReportContentDao.insert(proto); - return true; - } catch (DalException e) { - Cat.logError(e); - return false; - } - } - - @Override - public boolean insertHourlyReport(HourlyReport report, byte[] content) { - try { - report.setContent(""); - m_hourlyReportDao.insert(report); - - int id = report.getId(); - HourlyReportContent proto = m_hourlyReportContentDao.createLocal(); - - proto.setReportId(id); - proto.setContent(content); - m_hourlyReportContentDao.insert(proto); - return true; - } catch (DalException e) { - Cat.logError(e); - return false; - } - } - - @Override - public boolean insertMonthlyReport(MonthlyReport report, byte[] content) { - try { - MonthlyReport monthReport = m_monthlyReportDao.findReportByDomainNamePeriod(report.getPeriod(), - report.getDomain(), report.getName(), MonthlyReportEntity.READSET_FULL); - - if (monthReport != null) { - MonthlyReportContent reportContent = m_monthlyReportContentDao.createLocal(); - - reportContent.setKeyReportId(monthReport.getId()); - reportContent.setReportId(monthReport.getId()); - m_monthlyReportDao.deleteReportByDomainNamePeriod(report); - m_monthlyReportContentDao.deleteByPK(reportContent); - } - } catch (Exception e) { - Cat.logError(e); - } - - try { - m_monthlyReportDao.insert(report); - - int id = report.getId(); - MonthlyReportContent proto = m_monthlyReportContentDao.createLocal(); - - proto.setReportId(id); - proto.setContent(content); - m_monthlyReportContentDao.insert(proto); - - return true; - } catch (DalException e) { - Cat.logError(e); - return false; - } - } - - @Override - public boolean insertWeeklyReport(WeeklyReport report, byte[] content) { - try { - WeeklyReport weeklyReport = m_weeklyReportDao.findReportByDomainNamePeriod(report.getPeriod(), - report.getDomain(), report.getName(), WeeklyReportEntity.READSET_FULL); - - if (weeklyReport != null) { - WeeklyReportContent reportContent = m_weeklyReportContentDao.createLocal(); - - reportContent.setKeyReportId(weeklyReport.getId()); - reportContent.setReportId(weeklyReport.getId()); - m_weeklyReportContentDao.deleteByPK(reportContent); - m_weeklyReportDao.deleteReportByDomainNamePeriod(report); - } - } catch (Exception e) { - Cat.logError(e); - } - - try { - m_weeklyReportDao.insert(report); - - int id = report.getId(); - WeeklyReportContent proto = m_weeklyReportContentDao.createLocal(); - - proto.setReportId(id); - proto.setContent(content); - m_weeklyReportContentDao.insert(proto); - return true; - } catch (DalException e) { - Cat.logError(e); - return false; - } - } - - @Override - public AlertReport queryAlertReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(Constants.REPORT_ALERT); - - return reportService.queryReport(domain, start, end); - } - - public Set queryAllDomainNames(Date start, Date end, String name) { - ReportService reportService = m_reportServices.get(TransactionAnalyzer.ID); - - return reportService.queryAllDomainNames(start, end, name); - } - - public BugReport queryBugReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(Constants.REPORT_BUG); - - return reportService.queryReport(domain, start, end); - } - - public CrossReport queryCrossReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(CrossAnalyzer.ID); - - return reportService.queryReport(domain, start, end); - } - - public DependencyReport queryDependencyReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(DependencyAnalyzer.ID); - - return reportService.queryReport(domain, start, end); - } - - public EventReport queryEventReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(EventAnalyzer.ID); - - return reportService.queryReport(domain, start, end); - } - - public HeartbeatReport queryHeartbeatReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(HeartbeatAnalyzer.ID); - - return reportService.queryReport(domain, start, end); - } - - public HeavyReport queryHeavyReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(Constants.REPORT_HEAVY); - - return reportService.queryReport(domain, start, end); - } - - @Override - public HighloadReport queryHighloadReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(Constants.HIGH_LOAD_REPORT); - - return reportService.queryReport(domain, start, end); - } - - @Override - public JarReport queryJarReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(Constants.REPORT_JAR); - - return reportService.queryReport(domain, start, end); - } - - public MatrixReport queryMatrixReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(MatrixAnalyzer.ID); - - return reportService.queryReport(domain, start, end); - } - - public MetricReport queryMetricReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(MetricAnalyzer.ID); - - return reportService.queryReport(domain, start, end); - } - - @Override - public NetGraphSet queryNetTopologyReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(Constants.REPORT_NET_TOPOLOGY); - - return reportService.queryReport(domain, start, end); - } - - public ProblemReport queryProblemReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(ProblemAnalyzer.ID); - - return reportService.queryReport(domain, start, end); - } - - @Override - public RouterConfig queryRouterConfigReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(Constants.REPORT_ROUTER); - - return reportService.queryReport(domain, start, end); - } - - public ServiceReport queryServiceReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(Constants.REPORT_SERVICE); - - return reportService.queryReport(domain, start, end); - } - - public StateReport queryStateReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(StateAnalyzer.ID); - - return reportService.queryReport(domain, start, end); - } - - public TopReport queryTopReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(TopAnalyzer.ID); - - return reportService.queryReport(domain, start, end); - } - - public TransactionReport queryTransactionReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(TransactionAnalyzer.ID); - - return reportService.queryReport(domain, start, end); - } - - @Override - public UtilizationReport queryUtilizationReport(String domain, Date start, Date end) { - ReportService reportService = m_reportServices.get(Constants.REPORT_UTILIZATION); - - return reportService.queryReport(domain, start, end); - } - -} +package com.dianping.cat.report.service; + +import java.util.Date; +import java.util.Map; +import java.util.Set; + +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; +import org.unidal.dal.jdbc.DalException; +import org.unidal.dal.jdbc.DalNotFoundException; +import org.unidal.lookup.ContainerHolder; +import org.unidal.lookup.annotation.Inject; + +import com.dianping.cat.Cat; +import com.dianping.cat.Constants; +import com.dianping.cat.consumer.cross.CrossAnalyzer; +import com.dianping.cat.consumer.cross.model.entity.CrossReport; +import com.dianping.cat.consumer.dependency.DependencyAnalyzer; +import com.dianping.cat.consumer.dependency.model.entity.DependencyReport; +import com.dianping.cat.consumer.event.EventAnalyzer; +import com.dianping.cat.consumer.event.model.entity.EventReport; +import com.dianping.cat.consumer.heartbeat.HeartbeatAnalyzer; +import com.dianping.cat.consumer.heartbeat.model.entity.HeartbeatReport; +import com.dianping.cat.consumer.matrix.MatrixAnalyzer; +import com.dianping.cat.consumer.matrix.model.entity.MatrixReport; +import com.dianping.cat.consumer.metric.MetricAnalyzer; +import com.dianping.cat.consumer.metric.model.entity.MetricReport; +import com.dianping.cat.consumer.problem.ProblemAnalyzer; +import com.dianping.cat.consumer.problem.model.entity.ProblemReport; +import com.dianping.cat.consumer.state.StateAnalyzer; +import com.dianping.cat.consumer.state.model.entity.StateReport; +import com.dianping.cat.consumer.top.TopAnalyzer; +import com.dianping.cat.consumer.top.model.entity.TopReport; +import com.dianping.cat.consumer.transaction.TransactionAnalyzer; +import com.dianping.cat.consumer.transaction.model.entity.TransactionReport; +import com.dianping.cat.core.dal.DailyReport; +import com.dianping.cat.core.dal.DailyReportDao; +import com.dianping.cat.core.dal.HourlyReport; +import com.dianping.cat.core.dal.HourlyReportContent; +import com.dianping.cat.core.dal.HourlyReportContentDao; +import com.dianping.cat.core.dal.HourlyReportDao; +import com.dianping.cat.core.dal.MonthlyReport; +import com.dianping.cat.core.dal.MonthlyReportDao; +import com.dianping.cat.core.dal.MonthlyReportEntity; +import com.dianping.cat.core.dal.WeeklyReport; +import com.dianping.cat.core.dal.WeeklyReportDao; +import com.dianping.cat.core.dal.WeeklyReportEntity; +import com.dianping.cat.home.alert.report.entity.AlertReport; +import com.dianping.cat.home.bug.entity.BugReport; +import com.dianping.cat.home.dal.report.DailyReportContent; +import com.dianping.cat.home.dal.report.DailyReportContentDao; +import com.dianping.cat.home.dal.report.MonthlyReportContent; +import com.dianping.cat.home.dal.report.MonthlyReportContentDao; +import com.dianping.cat.home.dal.report.WeeklyReportContent; +import com.dianping.cat.home.dal.report.WeeklyReportContentDao; +import com.dianping.cat.home.heavy.entity.HeavyReport; +import com.dianping.cat.home.highload.entity.HighloadReport; +import com.dianping.cat.home.jar.entity.JarReport; +import com.dianping.cat.home.network.entity.NetGraphSet; +import com.dianping.cat.home.router.entity.RouterConfig; +import com.dianping.cat.home.service.entity.ServiceReport; +import com.dianping.cat.home.utilization.entity.UtilizationReport; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class DefaultReportServiceManager extends ContainerHolder implements ReportServiceManager, Initializable { + + @Inject + private HourlyReportDao m_hourlyReportDao; + + @Inject + private DailyReportDao m_dailyReportDao; + + @Inject + private WeeklyReportDao m_weeklyReportDao; + + @Inject + private MonthlyReportDao m_monthlyReportDao; + + @Inject + private HourlyReportContentDao m_hourlyReportContentDao; + + @Inject + private DailyReportContentDao m_dailyReportContentDao; + + @Inject + private WeeklyReportContentDao m_weeklyReportContentDao; + + @Inject + private MonthlyReportContentDao m_monthlyReportContentDao; + + private Map m_reportServices; + + @Override + public void initialize() throws InitializationException { + m_reportServices = lookupMap(ReportService.class); + } + + @Override + public boolean insertDailyReport(DailyReport report, byte[] content) { + try { + report.setContent(""); + m_dailyReportDao.insert(report); + + int id = report.getId(); + DailyReportContent proto = m_dailyReportContentDao.createLocal(); + + proto.setReportId(id); + proto.setContent(content); + m_dailyReportContentDao.insert(proto); + return true; + } catch (DalException e) { + Cat.logError(e); + return false; + } + } + + @Override + public boolean insertHourlyReport(HourlyReport report, byte[] content) { + try { + report.setContent(""); + m_hourlyReportDao.insert(report); + + int id = report.getId(); + HourlyReportContent proto = m_hourlyReportContentDao.createLocal(); + + proto.setReportId(id); + proto.setContent(content); + m_hourlyReportContentDao.insert(proto); + return true; + } catch (DalException e) { + Cat.logError(e); + return false; + } + } + + @Override + public boolean insertMonthlyReport(MonthlyReport report, byte[] content) { + try { + MonthlyReport monthReport = m_monthlyReportDao.findReportByDomainNamePeriod(report.getPeriod(), + report.getDomain(), report.getName(), MonthlyReportEntity.READSET_FULL); + + if (monthReport != null) { + MonthlyReportContent reportContent = m_monthlyReportContentDao.createLocal(); + + reportContent.setKeyReportId(monthReport.getId()); + reportContent.setReportId(monthReport.getId()); + m_monthlyReportDao.deleteReportByDomainNamePeriod(report); + m_monthlyReportContentDao.deleteByPK(reportContent); + } + } catch (DalNotFoundException e) { + } catch (Exception e) { + Cat.logError(e); + } + + try { + m_monthlyReportDao.insert(report); + + int id = report.getId(); + MonthlyReportContent proto = m_monthlyReportContentDao.createLocal(); + + proto.setReportId(id); + proto.setContent(content); + m_monthlyReportContentDao.insert(proto); + + return true; + } catch (DalException e) { + Cat.logError(e); + return false; + } + } + + @Override + public boolean insertWeeklyReport(WeeklyReport report, byte[] content) { + try { + WeeklyReport weeklyReport = m_weeklyReportDao.findReportByDomainNamePeriod(report.getPeriod(), + report.getDomain(), report.getName(), WeeklyReportEntity.READSET_FULL); + + if (weeklyReport != null) { + WeeklyReportContent reportContent = m_weeklyReportContentDao.createLocal(); + + reportContent.setKeyReportId(weeklyReport.getId()); + reportContent.setReportId(weeklyReport.getId()); + m_weeklyReportContentDao.deleteByPK(reportContent); + m_weeklyReportDao.deleteReportByDomainNamePeriod(report); + } + } catch (DalNotFoundException e) { + } catch (Exception e) { + Cat.logError(e); + } + + try { + m_weeklyReportDao.insert(report); + + int id = report.getId(); + WeeklyReportContent proto = m_weeklyReportContentDao.createLocal(); + + proto.setReportId(id); + proto.setContent(content); + m_weeklyReportContentDao.insert(proto); + return true; + } catch (DalException e) { + Cat.logError(e); + return false; + } + } + + @Override + public AlertReport queryAlertReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(Constants.REPORT_ALERT); + + return reportService.queryReport(domain, start, end); + } + + public Set queryAllDomainNames(Date start, Date end, String name) { + ReportService reportService = m_reportServices.get(TransactionAnalyzer.ID); + + return reportService.queryAllDomainNames(start, end, name); + } + + public BugReport queryBugReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(Constants.REPORT_BUG); + + return reportService.queryReport(domain, start, end); + } + + public CrossReport queryCrossReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(CrossAnalyzer.ID); + + return reportService.queryReport(domain, start, end); + } + + public DependencyReport queryDependencyReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(DependencyAnalyzer.ID); + + return reportService.queryReport(domain, start, end); + } + + public EventReport queryEventReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(EventAnalyzer.ID); + + return reportService.queryReport(domain, start, end); + } + + public HeartbeatReport queryHeartbeatReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(HeartbeatAnalyzer.ID); + + return reportService.queryReport(domain, start, end); + } + + public HeavyReport queryHeavyReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(Constants.REPORT_HEAVY); + + return reportService.queryReport(domain, start, end); + } + + @Override + public HighloadReport queryHighloadReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(Constants.HIGH_LOAD_REPORT); + + return reportService.queryReport(domain, start, end); + } + + @Override + public JarReport queryJarReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(Constants.REPORT_JAR); + + return reportService.queryReport(domain, start, end); + } + + public MatrixReport queryMatrixReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(MatrixAnalyzer.ID); + + return reportService.queryReport(domain, start, end); + } + + public MetricReport queryMetricReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(MetricAnalyzer.ID); + + return reportService.queryReport(domain, start, end); + } + + @Override + public NetGraphSet queryNetTopologyReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(Constants.REPORT_NET_TOPOLOGY); + + return reportService.queryReport(domain, start, end); + } + + public ProblemReport queryProblemReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(ProblemAnalyzer.ID); + + return reportService.queryReport(domain, start, end); + } + + @Override + public RouterConfig queryRouterConfigReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(Constants.REPORT_ROUTER); + + return reportService.queryReport(domain, start, end); + } + + public ServiceReport queryServiceReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(Constants.REPORT_SERVICE); + + return reportService.queryReport(domain, start, end); + } + + public StateReport queryStateReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(StateAnalyzer.ID); + + return reportService.queryReport(domain, start, end); + } + + public TopReport queryTopReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(TopAnalyzer.ID); + + return reportService.queryReport(domain, start, end); + } + + public TransactionReport queryTransactionReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(TransactionAnalyzer.ID); + + return reportService.queryReport(domain, start, end); + } + + @Override + public UtilizationReport queryUtilizationReport(String domain, Date start, Date end) { + ReportService reportService = m_reportServices.get(Constants.REPORT_UTILIZATION); + + return reportService.queryReport(domain, start, end); + } + +}