Jave-Chen 5 years ago committed by qiaozhanwei
parent
commit
dad75727ff
  1. 9
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java
  2. 15
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java

9
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/AlertServer.java

@ -39,20 +39,16 @@ public class AlertServer {
private AlertSender alertSender; private AlertSender alertSender;
private static volatile AlertServer instance; private static AlertServer instance;
public AlertServer() { public AlertServer() {
} }
public static AlertServer getInstance(){ public synchronized static AlertServer getInstance(){
if (null == instance) { if (null == instance) {
synchronized (AlertServer.class) {
if(null == instance) {
instance = new AlertServer(); instance = new AlertServer();
} }
}
}
return instance; return instance;
} }
@ -63,6 +59,7 @@ public class AlertServer {
Thread.sleep(Constants.ALERT_SCAN_INTERVEL); Thread.sleep(Constants.ALERT_SCAN_INTERVEL);
} catch (InterruptedException e) { } catch (InterruptedException e) {
logger.error(e.getMessage(),e); logger.error(e.getMessage(),e);
Thread.currentThread().interrupt();
} }
List<Alert> alerts = alertDao.listWaitExecutionAlert(); List<Alert> alerts = alertDao.listWaitExecutionAlert();
alertSender = new AlertSender(alerts, alertDao); alertSender = new AlertSender(alerts, alertDao);

15
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java

@ -86,6 +86,7 @@ public class EnterpriseWeChatUtils {
String resp; String resp;
CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpGet httpGet = new HttpGet(enterpriseWeChatTokenUrlReplace); HttpGet httpGet = new HttpGet(enterpriseWeChatTokenUrlReplace);
CloseableHttpResponse response = httpClient.execute(httpGet); CloseableHttpResponse response = httpClient.execute(httpGet);
try { try {
@ -100,6 +101,9 @@ public class EnterpriseWeChatUtils {
new TypeToken<Map<String, Object>>() { new TypeToken<Map<String, Object>>() {
}.getType()); }.getType());
return map.get("access_token").toString(); return map.get("access_token").toString();
} finally {
httpClient.close();
}
} }
/** /**
@ -167,10 +171,11 @@ public class EnterpriseWeChatUtils {
public static String sendEnterpriseWeChat(String charset, String data, String token) throws IOException { public static String sendEnterpriseWeChat(String charset, String data, String token) throws IOException {
String enterpriseWeChatPushUrlReplace = enterpriseWeChatPushUrl.replaceAll("\\$token", token); String enterpriseWeChatPushUrlReplace = enterpriseWeChatPushUrl.replaceAll("\\$token", token);
CloseableHttpClient httpclient = HttpClients.createDefault(); CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpPost httpPost = new HttpPost(enterpriseWeChatPushUrlReplace); HttpPost httpPost = new HttpPost(enterpriseWeChatPushUrlReplace);
httpPost.setEntity(new StringEntity(data, charset)); httpPost.setEntity(new StringEntity(data, charset));
CloseableHttpResponse response = httpclient.execute(httpPost); CloseableHttpResponse response = httpClient.execute(httpPost);
String resp; String resp;
try { try {
HttpEntity entity = response.getEntity(); HttpEntity entity = response.getEntity();
@ -179,8 +184,12 @@ public class EnterpriseWeChatUtils {
} finally { } finally {
response.close(); response.close();
} }
logger.info("Enterprise WeChat send [{}], param:{}, resp:{}", enterpriseWeChatPushUrl, data, resp); logger.info("Enterprise WeChat send [{}], param:{}, resp:{}",
enterpriseWeChatPushUrl, data, resp);
return resp; return resp;
} finally {
httpClient.close();
}
} }
/** /**

Loading…
Cancel
Save