Skip to content

Commit

Permalink
Merge branch 'master' of code.dianpingoa.com:arch/cat
Browse files Browse the repository at this point in the history
  • Loading branch information
jialinsun committed Mar 10, 2015
2 parents d3906d9 + 516da01 commit c8a961e
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@
import com.dianping.cat.report.alert.sender.spliter.WeixinSpliter;
import com.dianping.cat.report.alert.service.AlertEntityService;
import com.dianping.cat.report.alert.storage.StorageDatabaseAlert;
import com.dianping.cat.report.alert.summary.AlertSummaryContentGenerator;
import com.dianping.cat.report.alert.summary.AlertSummaryExecutor;
import com.dianping.cat.report.alert.summary.AlertSummaryGenerator;
import com.dianping.cat.report.alert.summary.AlertSummaryManager;
import com.dianping.cat.report.alert.summary.AlterationSummaryContentGenerator;
import com.dianping.cat.report.alert.summary.FailureSummaryContentGenerator;
import com.dianping.cat.report.alert.summary.SummaryContentGenerator;
import com.dianping.cat.report.alert.summary.AlertSummaryService;
import com.dianping.cat.report.alert.summary.build.AlertInfoBuilder;
import com.dianping.cat.report.alert.summary.build.RelatedSummaryBuilder;
import com.dianping.cat.report.alert.summary.build.AlterationSummaryBuilder;
import com.dianping.cat.report.alert.summary.build.FailureSummaryBuilder;
import com.dianping.cat.report.alert.summary.build.SummaryBuilder;
import com.dianping.cat.report.alert.system.SystemAlert;
import com.dianping.cat.report.alert.thirdParty.HttpConnector;
import com.dianping.cat.report.alert.thirdParty.ThirdPartyAlert;
Expand Down Expand Up @@ -266,25 +266,25 @@ public List<Component> defineComponents() {

all.add(C(AlertEntityService.class).req(AlertDao.class));

all.add(C(AlertSummaryGenerator.class).req(AlertDao.class, TopologyGraphManager.class));
all.add(C(AlertInfoBuilder.class).req(AlertDao.class, TopologyGraphManager.class));

all.add(C(AlertSummaryManager.class).req(AlertSummaryDao.class));
all.add(C(AlertSummaryService.class).req(AlertSummaryDao.class));

all.add(C(SummaryContentGenerator.class, AlertSummaryContentGenerator.ID, AlertSummaryContentGenerator.class)
.req(AlertSummaryGenerator.class, AlertSummaryManager.class));
all.add(C(SummaryBuilder.class, RelatedSummaryBuilder.ID, RelatedSummaryBuilder.class)
.req(AlertInfoBuilder.class, AlertSummaryService.class));

all.add(C(SummaryContentGenerator.class, FailureSummaryContentGenerator.ID, FailureSummaryContentGenerator.class)
all.add(C(SummaryBuilder.class, FailureSummaryBuilder.ID, FailureSummaryBuilder.class)
.req(ModelService.class, ProblemAnalyzer.ID));

all.add(C(SummaryContentGenerator.class, AlterationSummaryContentGenerator.ID,
AlterationSummaryContentGenerator.class).req(AlterationDao.class));
all.add(C(SummaryBuilder.class, AlterationSummaryBuilder.ID,
AlterationSummaryBuilder.class).req(AlterationDao.class));

all.add(C(AlertSummaryExecutor.class)
.req(SenderManager.class)
.req(SummaryContentGenerator.class, AlertSummaryContentGenerator.ID, "m_alertSummaryContentGenerator")
.req(SummaryContentGenerator.class, FailureSummaryContentGenerator.ID, "m_failureSummaryContentGenerator")
.req(SummaryContentGenerator.class, AlterationSummaryContentGenerator.ID,
"m_alterationSummaryContentGenerator"));
.req(SummaryBuilder.class, RelatedSummaryBuilder.ID, "m_relatedBuilder")
.req(SummaryBuilder.class, FailureSummaryBuilder.ID, "m_failureBuilder")
.req(SummaryBuilder.class, AlterationSummaryBuilder.ID,
"m_alterationBuilder"));

return all;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@

import org.unidal.helper.Splitters;
import org.unidal.lookup.annotation.Inject;
import org.unidal.lookup.util.StringUtils;

import com.dianping.cat.Cat;
import com.dianping.cat.helper.TimeHelper;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.report.alert.sender.AlertChannel;
import com.dianping.cat.report.alert.sender.AlertMessageEntity;
import com.dianping.cat.report.alert.sender.sender.SenderManager;
import com.dianping.cat.report.alert.summary.build.RelatedSummaryBuilder;
import com.dianping.cat.report.alert.summary.build.AlterationSummaryBuilder;
import com.dianping.cat.report.alert.summary.build.FailureSummaryBuilder;
import com.dianping.cat.report.alert.summary.build.SummaryBuilder;

public class AlertSummaryExecutor {

@Inject(type = SummaryContentGenerator.class, value = AlertSummaryContentGenerator.ID)
private SummaryContentGenerator m_alertSummaryContentGenerator;
@Inject(type = SummaryBuilder.class, value = RelatedSummaryBuilder.ID)
private SummaryBuilder m_relatedBuilder;

@Inject(type = SummaryContentGenerator.class, value = FailureSummaryContentGenerator.ID)
private SummaryContentGenerator m_failureSummaryContentGenerator;
@Inject(type = SummaryBuilder.class, value = FailureSummaryBuilder.ID)
private SummaryBuilder m_failureBuilder;

@Inject(type = SummaryContentGenerator.class, value = AlterationSummaryContentGenerator.ID)
private SummaryContentGenerator m_alterationSummaryContentGenerator;
@Inject(type = SummaryBuilder.class, value = AlterationSummaryBuilder.ID)
private SummaryBuilder m_alterationBuilder;

@Inject
private SenderManager m_sendManager;
Expand Down Expand Up @@ -55,24 +58,15 @@ private String buildMailTitle(String domain, Date date) {
}

public String execute(String domain, Date date) {
if (StringUtils.isEmpty(domain) || date == null) {
return null;
}
date = normalizeDate(date);

Transaction t = Cat.newTransaction("Summary", domain);

date = normalizeDate(date);
try {
StringBuilder builder = new StringBuilder();

String summaryContent = m_alertSummaryContentGenerator.generateHtml(domain, date);
builder.append(summaryContent);

String failureContext = m_failureSummaryContentGenerator.generateHtml(domain, date);
builder.append(failureContext);

String alterationContext = m_alterationSummaryContentGenerator.generateHtml(domain, date);
builder.append(alterationContext);
builder.append(m_relatedBuilder.generateHtml(domain, date));
builder.append(m_failureBuilder.generateHtml(domain, date));
builder.append(m_alterationBuilder.generateHtml(domain, date));

t.setStatus(Transaction.SUCCESS);
return builder.toString();
Expand All @@ -94,7 +88,9 @@ public String execute(String domain, Date date, String receiverStr) {
List<String> receivers = builderReceivers(receiverStr);
AlertMessageEntity message = new AlertMessageEntity(domain, title, "alertSummary", content, receivers);

m_sendManager.sendAlert(AlertChannel.MAIL, message);
if (receivers.size() > 0) {
m_sendManager.sendAlert(AlertChannel.MAIL, message);
}
}

return content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.dianping.cat.home.dal.report.AlertSummary;
import com.dianping.cat.home.dal.report.AlertSummaryDao;

public class AlertSummaryManager {
public class AlertSummaryService {

@Inject
private AlertSummaryDao m_alertSummaryDao;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dianping.cat.report.alert.summary;
package com.dianping.cat.report.alert.summary.build;

import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -21,8 +21,9 @@
import com.dianping.cat.home.dependency.graph.entity.TopologyGraph;
import com.dianping.cat.report.page.dependency.graph.TopologyGraphManager;
import com.dianping.cat.report.alert.AlertType;
import com.dianping.cat.report.alert.summary.AlertSummaryExecutor;

public class AlertSummaryGenerator {
public class AlertInfoBuilder {

@Inject
private AlertDao m_alertDao;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dianping.cat.report.alert.summary;
package com.dianping.cat.report.alert.summary.build;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -34,26 +34,23 @@ public AlertSummaryVisitor(String domain) {
}

private String convertNameToChinese(String name) {
if (name == null) {
} else {
if (name.equals(AlertType.Network.getName())) {
return "网络告警";
}
if (name.equals(AlertType.Business.getName())) {
return "业务告警";
}
if (name.equals(AlertType.Exception.getName())) {
return "异常告警";
}
if (name.equals(AlertSummaryGenerator.LONG_CALL)) {
return LONG_CALL_NAME;
}
if (name.equals(AlertSummaryGenerator.PREFIX + AlertType.Exception.getName())) {
return "依赖异常告警";
}
if (name.equals(AlertType.System.getName())) {
return "系统告警";
}
if (name.equals(AlertType.Network.getName())) {
return "网络告警";
}
if (name.equals(AlertType.Business.getName())) {
return "业务告警";
}
if (name.equals(AlertType.Exception.getName())) {
return "异常告警";
}
if (name.equals(AlertInfoBuilder.LONG_CALL)) {
return LONG_CALL_NAME;
}
if (name.equals(AlertInfoBuilder.PREFIX + AlertType.Exception.getName())) {
return "依赖异常告警";
}
if (name.equals(AlertType.System.getName())) {
return "系统告警";
}

return "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dianping.cat.report.alert.summary;
package com.dianping.cat.report.alert.summary.build;

import java.util.Date;
import java.util.HashMap;
Expand All @@ -12,8 +12,9 @@
import com.dianping.cat.home.dal.report.Alteration;
import com.dianping.cat.home.dal.report.AlterationDao;
import com.dianping.cat.home.dal.report.AlterationEntity;
import com.dianping.cat.report.alert.summary.AlertSummaryExecutor;

public class AlterationSummaryContentGenerator extends SummaryContentGenerator {
public class AlterationSummaryBuilder extends SummaryBuilder {

@Inject
private AlterationDao m_alterationDao;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dianping.cat.report.alert.summary;
package com.dianping.cat.report.alert.summary.build;

import java.util.Calendar;
import java.util.Date;
Expand All @@ -19,7 +19,7 @@
import com.dianping.cat.service.ModelRequest;
import com.dianping.cat.service.ModelResponse;

public class FailureSummaryContentGenerator extends SummaryContentGenerator {
public class FailureSummaryBuilder extends SummaryBuilder {

public static final String ID = "FailureDecorator";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dianping.cat.report.alert.summary;
package com.dianping.cat.report.alert.summary.build;

import java.util.ArrayList;
import java.util.Date;
Expand All @@ -9,14 +9,15 @@
import org.unidal.lookup.annotation.Inject;

import com.dianping.cat.home.alert.summary.entity.AlertSummary;
import com.dianping.cat.report.alert.summary.AlertSummaryService;

public class AlertSummaryContentGenerator extends SummaryContentGenerator {
public class RelatedSummaryBuilder extends SummaryBuilder {

@Inject
private AlertSummaryGenerator m_alertSummaryGenerator;
private AlertInfoBuilder m_alertSummaryManager;

@Inject
private AlertSummaryManager m_alertSummaryManager;
private AlertSummaryService m_alertSummaryService;

public static final String ID = "AlertSummaryContentGenerator";

Expand All @@ -40,8 +41,8 @@ private Map<Object, Object> gatherDomainsForDependBusiness(Map<Object, Object> m
}

categories.remove(AlertSummaryVisitor.LONG_CALL_NAME);
categories.put(AlertSummaryGenerator.LONG_CALL, longCallMap);
map.put(AlertSummaryGenerator.LONG_CALL + "_length", alerts.size());
categories.put(AlertInfoBuilder.LONG_CALL, longCallMap);
map.put(AlertInfoBuilder.LONG_CALL + "_length", alerts.size());
} catch (Exception ex) {
ex.printStackTrace();
}
Expand All @@ -51,10 +52,9 @@ private Map<Object, Object> gatherDomainsForDependBusiness(Map<Object, Object> m

@Override
public Map<Object, Object> generateModel(String domain, Date date) {
AlertSummary alertSummary = m_alertSummaryGenerator.generateAlertSummary(domain, date);
m_alertSummaryManager.insert(alertSummary);

AlertSummary alertSummary = m_alertSummaryManager.generateAlertSummary(domain, date);
AlertSummaryVisitor visitor = new AlertSummaryVisitor(alertSummary.getDomain());

visitor.visitAlertSummary(alertSummary);

return gatherDomainsForDependBusiness(visitor.getResult());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dianping.cat.report.alert.summary;
package com.dianping.cat.report.alert.summary.build;

import java.io.StringWriter;
import java.util.Date;
Expand All @@ -12,7 +12,7 @@
import freemarker.template.Configuration;
import freemarker.template.Template;

public abstract class SummaryContentGenerator implements Initializable {
public abstract class SummaryBuilder implements Initializable {

public Configuration m_configuration;

Expand All @@ -35,6 +35,7 @@ public String generateHtml(String domain, Date date) {
public void initialize() throws InitializationException {
m_configuration = new Configuration();
m_configuration.setDefaultEncoding("UTF-8");

try {
m_configuration.setClassForTemplateLoading(this.getClass(), "/freemaker");
} catch (Exception e) {
Expand Down
Loading

0 comments on commit c8a961e

Please sign in to comment.