-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from wolfboys/master
v1.0.0-beta.2
- Loading branch information
Showing
33 changed files
with
1,017 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 103 additions & 95 deletions
198
streamx-console/streamx-console-service/src/assembly/conf/streamx.sql
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...console-service/src/main/java/com/streamxhub/streamx/console/core/entity/SenderEmail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2019 The StreamX Project | ||
* <p> | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.streamxhub.streamx.console.core.entity; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class SenderEmail { | ||
|
||
private String smtpHost; | ||
private Integer smtpPort; | ||
private String email; | ||
private String password; | ||
private boolean ssl; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...nsole-service/src/main/java/com/streamxhub/streamx/console/core/service/AlertService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2019 The StreamX Project | ||
* <p> | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.streamxhub.streamx.console.core.service; | ||
|
||
import com.streamxhub.streamx.console.core.entity.Application; | ||
import com.streamxhub.streamx.console.core.enums.FlinkAppState; | ||
|
||
/** | ||
* @author benjobs | ||
*/ | ||
public interface AlertService { | ||
|
||
/** | ||
* alert | ||
* | ||
* @param application | ||
*/ | ||
void alert(Application application, FlinkAppState appState); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
...vice/src/main/java/com/streamxhub/streamx/console/core/service/impl/AlertServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright (c) 2019 The StreamX Project | ||
* <p> | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.streamxhub.streamx.console.core.service.impl; | ||
|
||
import com.streamxhub.streamx.common.util.DateUtils; | ||
import com.streamxhub.streamx.common.util.HadoopUtils; | ||
import com.streamxhub.streamx.common.util.Utils; | ||
import com.streamxhub.streamx.console.core.entity.Application; | ||
import com.streamxhub.streamx.console.core.entity.SenderEmail; | ||
import com.streamxhub.streamx.console.core.enums.FlinkAppState; | ||
import com.streamxhub.streamx.console.core.service.AlertService; | ||
import com.streamxhub.streamx.console.core.service.SettingService; | ||
import freemarker.template.Configuration; | ||
import freemarker.template.Template; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.mail.HtmlEmail; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.io.File; | ||
import java.io.StringWriter; | ||
import java.net.URL; | ||
import java.util.Enumeration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.TimeZone; | ||
|
||
/** | ||
* @author benjobs | ||
*/ | ||
@Slf4j | ||
@Service | ||
public class AlertServiceImpl implements AlertService { | ||
|
||
private Template template; | ||
|
||
@Autowired | ||
private SettingService settingService; | ||
|
||
private SenderEmail senderEmail; | ||
|
||
@PostConstruct | ||
public void initConfig() throws Exception { | ||
Configuration configuration = new Configuration(Configuration.VERSION_2_3_28); | ||
String template = "email.html"; | ||
Enumeration<URL> urls = ClassLoader.getSystemResources(template); | ||
if (urls != null) { | ||
if (!urls.hasMoreElements()) { | ||
urls = Thread.currentThread().getContextClassLoader().getResources(template); | ||
} | ||
} | ||
if (urls != null) { | ||
while (urls.hasMoreElements()) { | ||
URL url = urls.nextElement(); | ||
if (url.getPath().contains(".jar")) { | ||
configuration.setClassLoaderForTemplateLoading(Thread.currentThread().getContextClassLoader(), ""); | ||
} else { | ||
File file = new File(url.getPath()); | ||
configuration.setDirectoryForTemplateLoading(file.getParentFile()); | ||
} | ||
configuration.setDefaultEncoding("UTF-8"); | ||
this.template = configuration.getTemplate(template); | ||
break; | ||
} | ||
} else { | ||
log.error("email.html not found!"); | ||
throw new ExceptionInInitializerError("email.html not found!"); | ||
} | ||
} | ||
|
||
@Override | ||
public void alert(Application application, FlinkAppState appState) { | ||
log.info("Email Alert:{} is {}", application.getJobName(), appState.name()); | ||
if (this.senderEmail == null) { | ||
this.senderEmail = settingService.getSenderEmail(); | ||
} | ||
if (this.senderEmail != null) { | ||
//发送邮件 | ||
if (Utils.notEmpty(application.getAlertEmail())) { | ||
try { | ||
HtmlEmail htmlEmail = new HtmlEmail(); | ||
htmlEmail.setCharset("UTF-8"); | ||
htmlEmail.setHostName(this.senderEmail.getSmtpHost()); | ||
htmlEmail.setAuthentication(this.senderEmail.getEmail(), this.senderEmail.getPassword()); | ||
htmlEmail.setFrom(this.senderEmail.getEmail()); | ||
if (this.senderEmail.isSsl()) { | ||
htmlEmail.setSSLOnConnect(true); | ||
htmlEmail.setSslSmtpPort(this.senderEmail.getSmtpPort().toString()); | ||
} | ||
htmlEmail.setSubject("StreamX Alert: [ " + application.getJobName() + " ] is " + appState.name()); | ||
String html = getHtmlMessage(application, appState); | ||
htmlEmail.setHtmlMsg(html); | ||
htmlEmail.addTo(application.getAlertEmail().split(",")); | ||
htmlEmail.send(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private String getHtmlMessage(Application application, FlinkAppState appState) throws Exception { | ||
String content = "Job [" + application.getJobName() + "] is " + appState.name() + "<br>" + | ||
"Start Time: " + DateUtils.format(application.getStartTime(), DateUtils.fullFormat(), TimeZone.getDefault()) + "<br>" + | ||
"End Time: " + DateUtils.format(application.getEndTime(), DateUtils.fullFormat(), TimeZone.getDefault()) + "<br>" + | ||
"Duration: " + DateUtils.toRichTimeDuration(application.getEndTime().getTime() - application.getStartTime().getTime()) + "<br><br>" + | ||
"please check it,Thank you for using StreamX<br><br>" + | ||
"Best Wishes!!"; | ||
|
||
Map<String, String> root = new HashMap<>(); | ||
root.put("title", "Notify :" + application.getJobName().concat(" is ").concat(appState.name())); | ||
root.put("message", content); | ||
String format = "%s/proxy/%s/"; | ||
String url = String.format(format, HadoopUtils.rmHttpAddress(false), application.getAppId()); | ||
root.put("link", url); | ||
|
||
StringWriter writer = new StringWriter(); | ||
template.process(root, writer); | ||
return writer.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.