This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a commit to branch staging
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/staging by this push:
     new 2f94413  Adding email notifier
2f94413 is described below

commit 2f94413188479b0621133141ef54d062d821926c
Author: Dimuthu Wannipurage <dimuthu.wannipur...@datasprouts.com>
AuthorDate: Mon Nov 19 02:37:21 2018 -0500

    Adding email notifier
---
 modules/airavata-helix/platform-monitor/pom.xml    |  5 +++
 .../helix/cluster/monitoring/ErrorNotifier.java    | 50 ++++++++++++++++++++++
 .../monitoring/HelixParticipantMonitor.java        |  8 ++--
 .../src/main/resources/airavata-server.properties  | 10 +++--
 .../src/main/resources/logback.xml                 | 43 -------------------
 5 files changed, 66 insertions(+), 50 deletions(-)

diff --git a/modules/airavata-helix/platform-monitor/pom.xml 
b/modules/airavata-helix/platform-monitor/pom.xml
index d8ed166..735f911 100644
--- a/modules/airavata-helix/platform-monitor/pom.xml
+++ b/modules/airavata-helix/platform-monitor/pom.xml
@@ -17,5 +17,10 @@
             <artifactId>helix-spectator</artifactId>
             <version>0.17-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>javax.mail</groupId>
+            <artifactId>mail</artifactId>
+            <version>1.4</version>
+        </dependency>
     </dependencies>
 </project>
\ No newline at end of file
diff --git 
a/modules/airavata-helix/platform-monitor/src/main/java/org/apache/airavata/helix/cluster/monitoring/ErrorNotifier.java
 
b/modules/airavata-helix/platform-monitor/src/main/java/org/apache/airavata/helix/cluster/monitoring/ErrorNotifier.java
index 8f892bf..0293d5b 100644
--- 
a/modules/airavata-helix/platform-monitor/src/main/java/org/apache/airavata/helix/cluster/monitoring/ErrorNotifier.java
+++ 
b/modules/airavata-helix/platform-monitor/src/main/java/org/apache/airavata/helix/cluster/monitoring/ErrorNotifier.java
@@ -1,8 +1,15 @@
 package org.apache.airavata.helix.cluster.monitoring;
 
+import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.commons.lang.exception.ExceptionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.Properties;
+import javax.mail.*;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
 public class ErrorNotifier {
 
     private final static Logger logger = 
LoggerFactory.getLogger(ErrorNotifier.class);
@@ -13,5 +20,48 @@ public class ErrorNotifier {
         } else {
             logger.error("Monitor error " + monitorError.getReason(), 
monitorError.getError());
         }
+        sendEmail(monitorError);
+    }
+
+    private void sendEmail(PlatformMonitorError monitorError) {
+
+        try {
+
+            String username = 
ServerSettings.getSetting("sender.email.account");
+            String password = 
ServerSettings.getSetting("sender.email.password");
+            String targetEmails = 
ServerSettings.getSetting("target.email.accounts");
+
+            Properties props = new Properties();
+            props.put("mail.smtp.auth", "true");
+            props.put("mail.smtp.starttls.enable", "true");
+            props.put("mail.smtp.host", "smtp.gmail.com");
+            props.put("mail.smtp.port", "587");
+
+            String[] targetEmailArr = targetEmails.split(",");
+
+            for (String targetEmail : targetEmailArr) {
+                Session session = Session.getInstance(props,
+                        new javax.mail.Authenticator() {
+                            protected PasswordAuthentication 
getPasswordAuthentication() {
+                                return new PasswordAuthentication(username, 
password);
+                            }
+                        });
+
+                Message message = new MimeMessage(session);
+                message.setFrom(new InternetAddress(username));
+                message.setRecipients(Message.RecipientType.TO,
+                        InternetAddress.parse(targetEmail));
+                message.setSubject("Possible issue in " + 
ServerSettings.getSetting("platform.name"));
+                message.setText(monitorError.getReason() + "\n" + "Error code 
" + monitorError.getErrorCode() + "\n" +
+                        (monitorError.getError() != null ? 
ExceptionUtils.getFullStackTrace(monitorError.getError()) : ""));
+
+                Transport.send(message);
+
+                logger.info("Sent notification email to " + targetEmail);
+            }
+
+        } catch (Exception e) {
+            logger.error("Failed to send email", e);
+        }
     }
 }
diff --git 
a/modules/airavata-helix/platform-monitor/src/main/java/org/apache/airavata/helix/cluster/monitoring/HelixParticipantMonitor.java
 
b/modules/airavata-helix/platform-monitor/src/main/java/org/apache/airavata/helix/cluster/monitoring/HelixParticipantMonitor.java
index 568db01..97f02df 100644
--- 
a/modules/airavata-helix/platform-monitor/src/main/java/org/apache/airavata/helix/cluster/monitoring/HelixParticipantMonitor.java
+++ 
b/modules/airavata-helix/platform-monitor/src/main/java/org/apache/airavata/helix/cluster/monitoring/HelixParticipantMonitor.java
@@ -57,7 +57,7 @@ public class HelixParticipantMonitor implements 
PlatformMonitor {
                 PlatformMonitorError monitorError = new PlatformMonitorError();
                 monitorError.setReason("Helix participant " + instanceName + " 
is not active");
                 monitorError.setCategory("Participant");
-                monitorError.setCategory("P001");
+                monitorError.setErrorCode("P001");
                 return monitorError;
             }
         } catch (Exception e) {
@@ -65,7 +65,7 @@ public class HelixParticipantMonitor implements 
PlatformMonitor {
             monitorError.setError(e);
             monitorError.setReason("Failed to fetch Helix participant " + 
instanceName + " information");
             monitorError.setCategory("Participant");
-            monitorError.setCategory("P002");
+            monitorError.setErrorCode("P002");
             return monitorError;
         }
         return null;
@@ -83,7 +83,7 @@ public class HelixParticipantMonitor implements 
PlatformMonitor {
                 monitorError.setReason("Mock workflow failed to execute with 
status " + state.name() + ". " +
                         "Check whether Helix cluster is working properly");
                 monitorError.setCategory("Participant");
-                monitorError.setCategory("P003");
+                monitorError.setErrorCode("P003");
                 return monitorError;
             }
         } catch (Exception e) {
@@ -92,7 +92,7 @@ public class HelixParticipantMonitor implements 
PlatformMonitor {
             monitorError.setReason("Failed to launch mock workflow on helix 
cluster  " + helixClusterName + ". " +
                     "Check whether Helix cluster is working properly including 
the availability Controller and Participant");
             monitorError.setCategory("Participant");
-            monitorError.setCategory("P004");
+            monitorError.setErrorCode("P004");
             return monitorError;
         }
         return null;
diff --git 
a/modules/airavata-helix/platform-monitor/src/main/resources/airavata-server.properties
 
b/modules/airavata-helix/platform-monitor/src/main/resources/airavata-server.properties
index 7e4c435..6aecc09 100644
--- 
a/modules/airavata-helix/platform-monitor/src/main/resources/airavata-server.properties
+++ 
b/modules/airavata-helix/platform-monitor/src/main/resources/airavata-server.properties
@@ -1,7 +1,11 @@
-api.server.host=api.staging.scigap.org
+api.server.host=149.165.170.103
 api.server.port=9930
-database.host=db.staging.scigap.org
+database.host=149.165.171.12
 database.port=3306
 helix.cluster.name=AiravataDemoCluster
 helix.participant.name=helixparticipant
-zookeeper.server.connection=api.staging.scigap.org:2181
\ No newline at end of file
+zookeeper.server.connection=149.165.170.103:2181
+sender.email.account=testingjobsairav...@gmail.com
+sender.email.password=XseDe2015
+target.email.accounts=dimuthu.upeks...@gmail.com,dwann...@iu.edu
+platform.name=Testing Environment
\ No newline at end of file
diff --git 
a/modules/airavata-helix/platform-monitor/src/main/resources/logback.xml 
b/modules/airavata-helix/platform-monitor/src/main/resources/logback.xml
index 071bed2..e1a1b2e 100644
--- a/modules/airavata-helix/platform-monitor/src/main/resources/logback.xml
+++ b/modules/airavata-helix/platform-monitor/src/main/resources/logback.xml
@@ -41,55 +41,12 @@
         </rollingPolicy>
     </appender>
 
-    <appender name="KAFKA_FAILED_LOGFILE" 
class="ch.qos.logback.core.rolling.RollingFileAppender">
-        <File>../logs/kafka-failed.log</File>
-        <Append>true</Append>
-        <encoder>
-            <pattern>%d [%t] %-5p %c{30} %X - %m%n</pattern>
-        </encoder>
-        <rollingPolicy 
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-            
<fileNamePattern>../logs/kafka-failed.log.%d{yyyy-MM-dd}</fileNamePattern>
-            <maxHistory>30</maxHistory>
-            <totalSizeCap>1GB</totalSizeCap>
-        </rollingPolicy>
-    </appender>
-
-
-    <appender name="RELAXED-KAFKA-APPENDER" 
class="com.github.danielwegener.logback.kafka.KafkaAppender">
-        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
-            <pattern>%d [%t] %-5p %c{30} %X - %m%n</pattern>
-        </encoder>
-        <topic>airavata-logs</topic>
-        <!-- we don't care how the log messages will be partitioned  -->
-        <keyingStrategy 
class="com.github.danielwegener.logback.kafka.keying.NoKeyKeyingStrategy" />
-
-        <!-- use async delivery. the application threads are not blocked by 
logging -->
-        <deliveryStrategy 
class="com.github.danielwegener.logback.kafka.delivery.AsynchronousDeliveryStrategy"
 />
-
-        <!-- each <producerConfig> translates to regular kafka-client config 
(format: key=value) -->
-        <!-- producer configs are documented here: 
https://kafka.apache.org/documentation.html#newproducerconfigs -->
-        <!-- bootstrap.servers is the only mandatory producerConfig -->
-        <producerConfig>bootstrap.servers=192.168.99.103:9092</producerConfig>
-        <!-- don't wait for a broker to ack the reception of a batch.  -->
-        <producerConfig>acks=0</producerConfig>
-        <!-- wait up to 1000ms and collect log messages before sending them as 
a batch -->
-        <producerConfig>linger.ms=1000</producerConfig>
-        <!-- even if the producer buffer runs full, do not block the 
application but start to drop messages -->
-        <producerConfig>max.block.ms=0</producerConfig>
-        <!-- define a client-id that you use to identify yourself against the 
kafka broker -->
-        
<producerConfig>client.id=${HOSTNAME}-${CONTEXT_NAME}-logback-relaxed</producerConfig>
-
-        <!-- there is no fallback <appender-ref>. If this appender cannot 
deliver, it will drop its messages. -->
-        <appender-ref ref="KAFKA_FAILED_LOGFILE"/>
-    </appender>
-
     <logger name="ch.qos.logback" level="WARN"/>
     <logger name="org.apache.helix" level="WARN"/>
     <logger name="org.apache.zookeeper" level="ERROR"/>
     <logger name="org.apache.airavata" level="INFO"/>
     <logger name="org.hibernate" level="ERROR"/>
     <root level="INFO">
-        <appender-ref ref="RELAXED-KAFKA-APPENDER"/>
         <appender-ref ref="CONSOLE"/>
         <appender-ref ref="LOGFILE"/>
     </root>

Reply via email to