Commit 561ad088 by lepdou

add cat restapi transaction & fix email windows outlook bug

parent 66c20025
...@@ -76,6 +76,11 @@ public class PortalSettings { ...@@ -76,6 +76,11 @@ public class PortalSettings {
return activeEnvs; return activeEnvs;
} }
public boolean isEnvActive(Env env) {
Boolean mark = envStatusMark.get(env);
return mark == null ? false : mark;
}
private class HealthCheckTask implements Runnable { private class HealthCheckTask implements Runnable {
private static final int ENV_DOWN_THRESHOLD = 2; private static final int ENV_DOWN_THRESHOLD = 2;
......
...@@ -85,6 +85,7 @@ public class RetryableRestTemplate { ...@@ -85,6 +85,7 @@ public class RetryableRestTemplate {
String uri = uriTemplateHandler.expand(path, uriVariables).getPath(); String uri = uriTemplateHandler.expand(path, uriVariables).getPath();
Transaction ct = Tracer.newTransaction("AdminAPI", uri); Transaction ct = Tracer.newTransaction("AdminAPI", uri);
ct.addData("Env", env);
List<ServiceDTO> services = getAdminServices(env, ct); List<ServiceDTO> services = getAdminServices(env, ct);
...@@ -126,6 +127,7 @@ public class RetryableRestTemplate { ...@@ -126,6 +127,7 @@ public class RetryableRestTemplate {
String uri = uriTemplateHandler.expand(path, uriVariables).getPath(); String uri = uriTemplateHandler.expand(path, uriVariables).getPath();
Transaction ct = Tracer.newTransaction("AdminAPI", uri); Transaction ct = Tracer.newTransaction("AdminAPI", uri);
ct.addData("Env", env);
List<ServiceDTO> services = getAdminServices(env, ct); List<ServiceDTO> services = getAdminServices(env, ct);
......
...@@ -101,6 +101,21 @@ public class PortalConfig extends RefreshableConfig { ...@@ -101,6 +101,21 @@ public class PortalConfig extends RefreshableConfig {
/*** /***
* Level: low * Level: low
**/ **/
public Set<Env> publishTipsSupportedEnvs() {
String[] configurations = getArrayProperty("namespace.publish.tips.supported.envs", null);
Set<Env> result = Sets.newHashSet();
if (configurations == null || configurations.length == 0) {
return result;
}
for (String env : configurations) {
result.add(Env.fromString(env));
}
return result;
}
public String consumerTokenSalt() { public String consumerTokenSalt() {
return getValue("consumer.token.salt", "apollo-portal"); return getValue("consumer.token.salt", "apollo-portal");
} }
...@@ -109,12 +124,20 @@ public class PortalConfig extends RefreshableConfig { ...@@ -109,12 +124,20 @@ public class PortalConfig extends RefreshableConfig {
return getValue("email.sender"); return getValue("email.sender");
} }
public String publishEmailBodyTemplate() { public String emailTemplateFramework() {
return getValue("email.template.release.v2", ""); return getValue("email.template.framework", "");
}
public String emailReleaseDiffModuleTemplate() {
return getValue("email.template.release.module.diff", "");
} }
public String rollbackEmailBodyTemplate() { public String emailRollbackDiffModuleTemplate() {
return getValue("email.template.rollback.v2", ""); return getValue("email.template.rollback.module.diff", "");
}
public String emailGrayRulesModuleTemplate() {
return getValue("email.template.release.module.rules", "");
} }
/*** /***
...@@ -139,6 +162,10 @@ public class PortalConfig extends RefreshableConfig { ...@@ -139,6 +162,10 @@ public class PortalConfig extends RefreshableConfig {
return getIntProperty("ctrip.email.survival.duration", 5); return getIntProperty("ctrip.email.survival.duration", 5);
} }
public boolean isSendEmailAsync() {
return getBooleanProperty("email.send.async", true);
}
public String portalServerName() { public String portalServerName() {
return getValue("serverName"); return getValue("serverName");
} }
......
...@@ -31,36 +31,48 @@ public class GrayPublishEmailBuilder extends ConfigPublishEmailBuilder { ...@@ -31,36 +31,48 @@ public class GrayPublishEmailBuilder extends ConfigPublishEmailBuilder {
@Override @Override
public String emailContent(Env env, ReleaseHistoryBO releaseHistory) { public String emailContent(Env env, ReleaseHistoryBO releaseHistory) {
String result = renderEmailCommonContent(getReleaseTemplate(), env, releaseHistory); String result = renderEmailCommonContent(env, releaseHistory);
return renderGrayReleaseRuleContent(result, releaseHistory); return renderGrayReleaseRuleContent(result, releaseHistory);
} }
private String renderGrayReleaseRuleContent(String template, ReleaseHistoryBO releaseHistory) { @Override
String result = template.replaceAll(EMAIL_CONTENT_RULE_SWITCH, ""); protected String getTemplateFramework() {
return portalConfig.emailTemplateFramework();
}
@Override
protected String getDiffModuleTemplate() {
return portalConfig.emailReleaseDiffModuleTemplate();
}
private String renderGrayReleaseRuleContent(String bodyTemplate, ReleaseHistoryBO releaseHistory) {
Map<String, Object> context = releaseHistory.getOperationContext(); Map<String, Object> context = releaseHistory.getOperationContext();
Object rules = context.get("rules"); Object rules = context.get("rules");
List<GrayReleaseRuleItemDTO> List<GrayReleaseRuleItemDTO>
ruleItems = rules == null ? ruleItems = rules == null ?
null : gson.fromJson(rules.toString(), GsonType.RULE_ITEMS); null : gson.fromJson(rules.toString(), GsonType.RULE_ITEMS);
StringBuilder rulesHtmlBuilder = new StringBuilder();
if (CollectionUtils.isEmpty(ruleItems)) { if (CollectionUtils.isEmpty(ruleItems)) {
rulesHtmlBuilder.append("无灰度规则"); return bodyTemplate.replaceAll(EMAIL_CONTENT_GRAY_RULES_MODULE, "<br><h4>无灰度规则</h4>");
} else { } else {
StringBuilder rulesHtmlBuilder = new StringBuilder();
for (GrayReleaseRuleItemDTO ruleItem : ruleItems) { for (GrayReleaseRuleItemDTO ruleItem : ruleItems) {
String clientAppId = ruleItem.getClientAppId(); String clientAppId = ruleItem.getClientAppId();
Set<String> ips = ruleItem.getClientIpList(); Set<String> ips = ruleItem.getClientIpList();
rulesHtmlBuilder.append("<b>AppId:&nbsp;</b>") rulesHtmlBuilder.append("<b>AppId:&nbsp;</b>")
.append(clientAppId) .append(clientAppId)
.append("&nbsp;&nbsp; <b>IP:&nbsp;</b>"); .append("&nbsp;&nbsp; <b>IP:&nbsp;</b>");
IP_JOINER.appendTo(rulesHtmlBuilder, ips); IP_JOINER.appendTo(rulesHtmlBuilder, ips);
} }
} String grayRulesModuleContent = portalConfig.emailGrayRulesModuleTemplate().replaceAll(EMAIL_CONTENT_GRAY_RULES_CONTENT,
Matcher.quoteReplacement(rulesHtmlBuilder.toString()));
return result.replaceAll(EMAIL_CONTENT_FIELD_RULE, Matcher.quoteReplacement(rulesHtmlBuilder.toString())); return bodyTemplate.replaceAll(EMAIL_CONTENT_GRAY_RULES_MODULE, Matcher.quoteReplacement(grayRulesModuleContent));
}
} }
} }
...@@ -20,7 +20,16 @@ public class MergeEmailBuilder extends ConfigPublishEmailBuilder { ...@@ -20,7 +20,16 @@ public class MergeEmailBuilder extends ConfigPublishEmailBuilder {
@Override @Override
protected String emailContent(Env env, ReleaseHistoryBO releaseHistory) { protected String emailContent(Env env, ReleaseHistoryBO releaseHistory) {
String template = getReleaseTemplate(); return renderEmailCommonContent(env, releaseHistory);
return renderEmailCommonContent(template, env, releaseHistory); }
@Override
protected String getTemplateFramework() {
return portalConfig.emailTemplateFramework();
}
@Override
protected String getDiffModuleTemplate() {
return portalConfig.emailReleaseDiffModuleTemplate();
} }
} }
...@@ -20,7 +20,16 @@ public class NormalPublishEmailBuilder extends ConfigPublishEmailBuilder { ...@@ -20,7 +20,16 @@ public class NormalPublishEmailBuilder extends ConfigPublishEmailBuilder {
@Override @Override
protected String emailContent(Env env, ReleaseHistoryBO releaseHistory) { protected String emailContent(Env env, ReleaseHistoryBO releaseHistory) {
String template = getReleaseTemplate(); return renderEmailCommonContent(env, releaseHistory);
return renderEmailCommonContent(template, env, releaseHistory); }
@Override
protected String getTemplateFramework() {
return portalConfig.emailTemplateFramework();
}
@Override
protected String getDiffModuleTemplate() {
return portalConfig.emailReleaseDiffModuleTemplate();
} }
} }
...@@ -20,7 +20,16 @@ public class RollbackEmailBuilder extends ConfigPublishEmailBuilder { ...@@ -20,7 +20,16 @@ public class RollbackEmailBuilder extends ConfigPublishEmailBuilder {
@Override @Override
protected String emailContent(Env env, ReleaseHistoryBO releaseHistory) { protected String emailContent(Env env, ReleaseHistoryBO releaseHistory) {
String template = getRollbackTemplate(); return renderEmailCommonContent(env, releaseHistory);
return renderEmailCommonContent(template, env, releaseHistory); }
@Override
protected String getTemplateFramework() {
return portalConfig.emailTemplateFramework();
}
@Override
protected String getDiffModuleTemplate() {
return portalConfig.emailRollbackDiffModuleTemplate();
} }
} }
package com.ctrip.framework.apollo.portal.service; package com.ctrip.framework.apollo.portal.service;
import com.ctrip.framework.apollo.portal.components.config.PortalConfig;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gson.Gson; import com.google.gson.Gson;
...@@ -30,10 +31,7 @@ import org.springframework.stereotype.Service; ...@@ -30,10 +31,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpClientErrorException;
import java.util.HashMap; import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@Service @Service
public class NamespaceService { public class NamespaceService {
...@@ -42,8 +40,6 @@ public class NamespaceService { ...@@ -42,8 +40,6 @@ public class NamespaceService {
private Gson gson = new Gson(); private Gson gson = new Gson();
@Autowired @Autowired
private PortalSettings portalSettings;
@Autowired
private UserInfoHolder userInfoHolder; private UserInfoHolder userInfoHolder;
@Autowired @Autowired
private ItemService itemService; private ItemService itemService;
...@@ -53,6 +49,10 @@ public class NamespaceService { ...@@ -53,6 +49,10 @@ public class NamespaceService {
private AdminServiceAPI.NamespaceAPI namespaceAPI; private AdminServiceAPI.NamespaceAPI namespaceAPI;
@Autowired @Autowired
private AppNamespaceService appNamespaceService; private AppNamespaceService appNamespaceService;
@Autowired
private PortalConfig portalConfig;
@Autowired
private PortalSettings portalSettings;
public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) { public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) {
...@@ -138,9 +138,11 @@ public class NamespaceService { ...@@ -138,9 +138,11 @@ public class NamespaceService {
public Map<String, Map<String, Boolean>> getNamespacesPublishInfo(String appId) { public Map<String, Map<String, Boolean>> getNamespacesPublishInfo(String appId) {
Map<String, Map<String, Boolean>> result = Maps.newHashMap(); Map<String, Map<String, Boolean>> result = Maps.newHashMap();
List<Env> envs = portalSettings.getActiveEnvs(); Set<Env> envs = portalConfig.publishTipsSupportedEnvs();
for (Env env: envs) { for (Env env: envs) {
result.put(env.toString(), namespaceAPI.getNamespacePublishInfo(env, appId)); if (portalSettings.isEnvActive(env)) {
result.put(env.toString(), namespaceAPI.getNamespacePublishInfo(env, appId));
}
} }
return result; return result;
......
...@@ -66,7 +66,10 @@ public class CtripEmailRequestBuilder { ...@@ -66,7 +66,10 @@ public class CtripEmailRequestBuilder {
setSender.invoke(emailRequest, email.getSenderEmailAddress()); setSender.invoke(emailRequest, email.getSenderEmailAddress());
setSubject.invoke(emailRequest, email.getSubject()); setSubject.invoke(emailRequest, email.getSubject());
setBodyContent.invoke(emailRequest, email.getBody()); String emailBodyBuilder = "<entry><content><![CDATA[<!DOCTYPE html>" +
email.getBody() +
"]]></content></entry>";
setBodyContent.invoke(emailRequest, emailBodyBuilder);
setRecipient.invoke(emailRequest, email.getRecipients()); setRecipient.invoke(emailRequest, email.getRecipients());
return emailRequest; return emailRequest;
......
...@@ -21,6 +21,7 @@ public class CtripEmailService implements EmailService { ...@@ -21,6 +21,7 @@ public class CtripEmailService implements EmailService {
private Object emailServiceClient; private Object emailServiceClient;
private Method sendEmailAsync; private Method sendEmailAsync;
private Method sendEmail;
@Autowired @Autowired
private CtripEmailRequestBuilder emailRequestBuilder; private CtripEmailRequestBuilder emailRequestBuilder;
...@@ -33,13 +34,15 @@ public class CtripEmailService implements EmailService { ...@@ -33,13 +34,15 @@ public class CtripEmailService implements EmailService {
initServiceClientConfig(); initServiceClientConfig();
Class emailServiceClientClazz = Class emailServiceClientClazz =
Class.forName("com.ctrip.framework.apolloctripservice.emailservice.EmailServiceClient"); Class.forName("com.ctrip.framework.apolloctripservice.emailservice.EmailServiceClient");
Method getInstanceMethod = emailServiceClientClazz.getMethod("getInstance"); Method getInstanceMethod = emailServiceClientClazz.getMethod("getInstance");
emailServiceClient = getInstanceMethod.invoke(null); emailServiceClient = getInstanceMethod.invoke(null);
Class sendEmailRequestClazz = Class sendEmailRequestClazz =
Class.forName("com.ctrip.framework.apolloctripservice.emailservice.SendEmailRequest"); Class.forName("com.ctrip.framework.apolloctripservice.emailservice.SendEmailRequest");
sendEmailAsync = emailServiceClientClazz.getMethod("sendEmailAsync", sendEmailRequestClazz); sendEmailAsync = emailServiceClientClazz.getMethod("sendEmailAsync", sendEmailRequestClazz);
sendEmail = emailServiceClientClazz.getMethod("sendEmail", sendEmailRequestClazz);
} catch (Throwable e) { } catch (Throwable e) {
logger.error("init ctrip email service failed", e); logger.error("init ctrip email service failed", e);
Tracer.logError("init ctrip email service failed", e); Tracer.logError("init ctrip email service failed", e);
...@@ -64,9 +67,12 @@ public class CtripEmailService implements EmailService { ...@@ -64,9 +67,12 @@ public class CtripEmailService implements EmailService {
try { try {
Object emailRequest = emailRequestBuilder.buildEmailRequest(email); Object emailRequest = emailRequestBuilder.buildEmailRequest(email);
Object sendResponse = sendEmailAsync.invoke(emailServiceClient, emailRequest);
logger.info("Email sender response:" + sendResponse); Object sendResponse = portalConfig.isSendEmailAsync() ?
sendEmailAsync.invoke(emailServiceClient, emailRequest) :
sendEmail.invoke(emailServiceClient, emailRequest);
logger.info("Email server response: " + sendResponse);
} catch (Throwable e) { } catch (Throwable e) {
logger.error("send email failed", e); logger.error("send email failed", e);
......
package com.ctrip.framework.apollo.portal.spi.ctrip; package com.ctrip.framework.apollo.portal.spi.ctrip;
import com.ctrip.framework.apollo.portal.spi.ctrip.filters.UserAccessFilter;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.ctrip.framework.apollo.portal.components.config.PortalConfig; import com.ctrip.framework.apollo.portal.components.config.PortalConfig;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.ctrip.filters.RecordAccessUserFilter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.FilterRegistrationBean; import org.springframework.boot.context.embedded.FilterRegistrationBean;
...@@ -47,10 +47,10 @@ public class WebContextConfiguration { ...@@ -47,10 +47,10 @@ public class WebContextConfiguration {
} }
@Bean @Bean
public FilterRegistrationBean recordAccessUserFilter() { public FilterRegistrationBean userAccessFilter() {
FilterRegistrationBean filter = new FilterRegistrationBean(); FilterRegistrationBean filter = new FilterRegistrationBean();
filter.setFilter(new RecordAccessUserFilter(userInfoHolder)); filter.setFilter(new UserAccessFilter(userInfoHolder));
filter.addUrlPatterns("/apps"); filter.addUrlPatterns("/*");
return filter; return filter;
} }
......
...@@ -3,23 +3,19 @@ package com.ctrip.framework.apollo.portal.spi.ctrip.filters; ...@@ -3,23 +3,19 @@ package com.ctrip.framework.apollo.portal.spi.ctrip.filters;
import com.ctrip.framework.apollo.portal.constant.CatEventType; import com.ctrip.framework.apollo.portal.constant.CatEventType;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.tracer.Tracer; import com.ctrip.framework.apollo.tracer.Tracer;
import com.google.common.base.Strings;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import javax.servlet.Filter; public class UserAccessFilter implements Filter {
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class RecordAccessUserFilter implements Filter {
private static final String STATIC_RESOURCE_REGEX = ".*\\.(js|html|htm|png|css|woff2)$";
private UserInfoHolder userInfoHolder; private UserInfoHolder userInfoHolder;
public UserAccessFilter(UserInfoHolder userInfoHolder) {
public RecordAccessUserFilter(UserInfoHolder userInfoHolder) {
this.userInfoHolder = userInfoHolder; this.userInfoHolder = userInfoHolder;
} }
...@@ -30,9 +26,13 @@ public class RecordAccessUserFilter implements Filter { ...@@ -30,9 +26,13 @@ public class RecordAccessUserFilter implements Filter {
@Override @Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException { throws IOException, ServletException {
String requestUri = ((HttpServletRequest) request).getRequestURI();
Tracer.logEvent(CatEventType.USER_ACCESS, userInfoHolder.getUser().getUserId()); if (!isStaticResource(requestUri)) {
Tracer.logEvent(CatEventType.USER_ACCESS, userInfoHolder.getUser().getUserId());
}
chain.doFilter(request, response); chain.doFilter(request, response);
} }
...@@ -41,4 +41,9 @@ public class RecordAccessUserFilter implements Filter { ...@@ -41,4 +41,9 @@ public class RecordAccessUserFilter implements Filter {
public void destroy() { public void destroy() {
} }
private boolean isStaticResource(String uri) {
return !Strings.isNullOrEmpty(uri) && uri.matches(STATIC_RESOURCE_REGEX);
}
} }
...@@ -17,12 +17,12 @@ $(document).ready(function () { ...@@ -17,12 +17,12 @@ $(document).ready(function () {
$('[data-tooltip="tooltip"]').tooltip({ $('[data-tooltip="tooltip"]').tooltip({
trigger : 'hover' trigger : 'hover'
}); });
}, 2500);
setTimeout(function () {
$("textarea").niceScroll({cursoropacitymax: 0}); $("textarea").niceScroll({cursoropacitymax: 0});
$("pre").niceScroll({cursoropacitymax: 0}); $("pre").niceScroll({cursoropacitymax: 0});
}, 1000);
setTimeout(function () {
$(".release-history-list").niceScroll({cursoropacitymax: 0}); $(".release-history-list").niceScroll({cursoropacitymax: 0});
}, 2500); }, 2500);
......
...@@ -143,7 +143,7 @@ ...@@ -143,7 +143,7 @@
<dependency> <dependency>
<groupId>com.dianping.cat</groupId> <groupId>com.dianping.cat</groupId>
<artifactId>cat-client</artifactId> <artifactId>cat-client</artifactId>
<version>2.1.2</version> <version>2.2.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.unidal.framework</groupId> <groupId>org.unidal.framework</groupId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment