提交 eebab20f 编写于 作者: Y youyong205

modify the history report

上级 efc4651e
......@@ -46,6 +46,7 @@ import com.dianping.cat.report.service.impl.ProblemReportService;
import com.dianping.cat.report.service.impl.RouterConfigService;
import com.dianping.cat.report.service.impl.ServiceReportService;
import com.dianping.cat.report.service.impl.StateReportService;
import com.dianping.cat.report.service.impl.StorageReportService;
import com.dianping.cat.report.service.impl.SystemReportService;
import com.dianping.cat.report.service.impl.TopReportService;
import com.dianping.cat.report.service.impl.TransactionReportService;
......@@ -74,7 +75,7 @@ public class ReportServiceComponentConfigurator extends AbstractResourceConfigur
all.add(C(ReportService.class, StateAnalyzer.ID, StateReportService.class).req(HourlyReportDao.class,
DailyReportDao.class, WeeklyReportDao.class, MonthlyReportDao.class, HourlyReportContentDao.class,
DailyReportContentDao.class, WeeklyReportContentDao.class, MonthlyReportContentDao.class));
all.add(C(ReportService.class, StorageAnalyzer.ID, CrossReportService.class).req(HourlyReportDao.class,
all.add(C(ReportService.class, StorageAnalyzer.ID, StorageReportService.class).req(HourlyReportDao.class,
DailyReportDao.class, WeeklyReportDao.class, MonthlyReportDao.class, HourlyReportContentDao.class,
DailyReportContentDao.class, WeeklyReportContentDao.class, MonthlyReportContentDao.class));
......
......@@ -124,7 +124,6 @@ public class Handler implements PageHandler<Context> {
}
} catch (DalException e) {
setAlertResult(model, 5);
e.printStackTrace();
Cat.logError(e);
}
}
......
package com.dianping.cat.report.service.impl;
import java.util.Date;
import java.util.List;
import org.unidal.dal.jdbc.DalException;
import org.unidal.dal.jdbc.DalNotFoundException;
import com.dianping.cat.Cat;
import com.dianping.cat.Constants;
import com.dianping.cat.consumer.storage.StorageReportMerger;
import com.dianping.cat.consumer.storage.model.entity.StorageReport;
import com.dianping.cat.consumer.storage.model.transform.DefaultNativeParser;
import com.dianping.cat.core.dal.DailyReport;
import com.dianping.cat.core.dal.DailyReportEntity;
import com.dianping.cat.core.dal.HourlyReport;
import com.dianping.cat.core.dal.HourlyReportContent;
import com.dianping.cat.core.dal.HourlyReportContentEntity;
import com.dianping.cat.core.dal.HourlyReportEntity;
import com.dianping.cat.core.dal.MonthlyReport;
import com.dianping.cat.core.dal.MonthlyReportEntity;
import com.dianping.cat.core.dal.WeeklyReport;
import com.dianping.cat.core.dal.WeeklyReportEntity;
import com.dianping.cat.helper.TimeHelper;
import com.dianping.cat.home.dal.report.DailyReportContent;
import com.dianping.cat.home.dal.report.DailyReportContentEntity;
import com.dianping.cat.home.dal.report.MonthlyReportContent;
import com.dianping.cat.home.dal.report.MonthlyReportContentEntity;
import com.dianping.cat.home.dal.report.WeeklyReportContent;
import com.dianping.cat.home.dal.report.WeeklyReportContentEntity;
import com.dianping.cat.report.service.AbstractReportService;
public class StorageReportService extends AbstractReportService<StorageReport> {
......@@ -21,26 +46,135 @@ public class StorageReportService extends AbstractReportService<StorageReport> {
@Override
public StorageReport queryDailyReport(String id, Date start, Date end) {
// TODO Auto-generated method stub
return null;
StorageReportMerger merger = new StorageReportMerger(new StorageReport(id));
long startTime = start.getTime();
long endTime = end.getTime();
String name = Constants.REPORT_HEAVY;
for (; startTime < endTime; startTime = startTime + TimeHelper.ONE_DAY) {
try {
DailyReport report = m_dailyReportDao.findByDomainNamePeriod(id, name, new Date(startTime),
DailyReportEntity.READSET_FULL);
StorageReport reportModel = queryFromDailyBinary(report.getId(), id);
reportModel.accept(merger);
} catch (DalNotFoundException e) {
// ignore
} catch (Exception e) {
Cat.logError(e);
}
}
StorageReport storageReport = merger.getStorageReport();
storageReport.setStartTime(start);
storageReport.setEndTime(end);
return storageReport;
}
private StorageReport queryFromDailyBinary(int id, String domain) throws DalException {
DailyReportContent content = m_dailyReportContentDao.findByPK(id, DailyReportContentEntity.READSET_FULL);
if (content != null) {
return DefaultNativeParser.parse(content.getContent());
} else {
return new StorageReport(domain);
}
}
private StorageReport queryFromHourlyBinary(int id, String reportId) throws DalException {
HourlyReportContent content = m_hourlyReportContentDao.findByPK(id, HourlyReportContentEntity.READSET_FULL);
if (content != null) {
return DefaultNativeParser.parse(content.getContent());
} else {
return new StorageReport(reportId);
}
}
private StorageReport queryFromMonthlyBinary(int id, String reportId) throws DalException {
MonthlyReportContent content = m_monthlyReportContentDao.findByPK(id, MonthlyReportContentEntity.READSET_FULL);
if (content != null) {
return DefaultNativeParser.parse(content.getContent());
} else {
return new StorageReport(reportId);
}
}
private StorageReport queryFromWeeklyBinary(int id, String reportId) throws DalException {
WeeklyReportContent content = m_weeklyReportContentDao.findByPK(id, WeeklyReportContentEntity.READSET_FULL);
if (content != null) {
return DefaultNativeParser.parse(content.getContent());
} else {
return new StorageReport(reportId);
}
}
@Override
public StorageReport queryHourlyReport(String id, Date start, Date end) {
// TODO Auto-generated method stub
return null;
public StorageReport queryHourlyReport(String reportId, Date start, Date end) {
StorageReportMerger merger = new StorageReportMerger(new StorageReport(reportId));
long startTime = start.getTime();
long endTime = end.getTime();
String name = Constants.REPORT_HEAVY;
for (; startTime < endTime; startTime = startTime + TimeHelper.ONE_HOUR) {
List<HourlyReport> reports = null;
try {
reports = m_hourlyReportDao.findAllByDomainNamePeriod(new Date(startTime), reportId, name,
HourlyReportEntity.READSET_FULL);
} catch (DalException e) {
Cat.logError(e);
}
if (reports != null) {
for (HourlyReport report : reports) {
try {
StorageReport reportModel = queryFromHourlyBinary(report.getId(), reportId);
reportModel.accept(merger);
} catch (DalNotFoundException e) {
// ignore
} catch (Exception e) {
Cat.logError(e);
}
}
}
}
StorageReport storageReport = merger.getStorageReport();
storageReport.setStartTime(start);
storageReport.setEndTime(new Date(end.getTime() - 1));
return storageReport;
}
@Override
public StorageReport queryMonthlyReport(String id, Date start) {
// TODO Auto-generated method stub
return null;
public StorageReport queryMonthlyReport(String reportId, Date start) {
try {
MonthlyReport entity = m_monthlyReportDao.findReportByDomainNamePeriod(start, reportId, Constants.REPORT_HEAVY,
MonthlyReportEntity.READSET_FULL);
return queryFromMonthlyBinary(entity.getId(), reportId);
} catch (DalNotFoundException e) {
// ignore
} catch (Exception e) {
Cat.logError(e);
}
return new StorageReport(reportId);
}
@Override
public StorageReport queryWeeklyReport(String id, Date start) {
// TODO Auto-generated method stub
return null;
public StorageReport queryWeeklyReport(String reportId, Date start) {
try {
WeeklyReport entity = m_weeklyReportDao.findReportByDomainNamePeriod(start, reportId, Constants.REPORT_HEAVY,
WeeklyReportEntity.READSET_FULL);
return queryFromWeeklyBinary(entity.getId(), reportId);
} catch (DalNotFoundException e) {
// ignore
} catch (Exception e) {
Cat.logError(e);
}
return new StorageReport(reportId);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册