You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@griffin.apache.org by gu...@apache.org on 2017/10/25 03:23:34 UTC

incubator-griffin git commit: Add Monitoring Module

Repository: incubator-griffin
Updated Branches:
  refs/heads/master 97a6805df -> 6ab05fc20


Add Monitoring Module

user: xiaoqiu.duan  xiaoqiu2017wy163.com

Author: xiaoqiu.duan <xi...@163.com>
Author: xiaoqiu.duan <xi...@vipshop.com>

Closes #147 from xiaoqiu-vip/griffin-vip.


Project: http://git-wip-us.apache.org/repos/asf/incubator-griffin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-griffin/commit/6ab05fc2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-griffin/tree/6ab05fc2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-griffin/diff/6ab05fc2

Branch: refs/heads/master
Commit: 6ab05fc208e915d0d3c28f1e11c2909cf2e585ca
Parents: 97a6805
Author: xiaoqiu.duan <xi...@163.com>
Authored: Wed Oct 25 11:23:28 2017 +0800
Committer: Lionel Liu <bh...@163.com>
Committed: Wed Oct 25 11:23:28 2017 +0800

----------------------------------------------------------------------
 measure/pom.xml                                 |   6 +
 measure/src/main/resources/config.json          |   1 -
 measure/src/main/resources/env.json             |  17 +-
 .../measure/config/params/env/EmailParam.scala  |  36 ++++
 .../measure/config/params/env/EnvParam.scala    |  10 +-
 .../measure/config/params/env/SMSParam.scala    |  36 ++++
 .../apache/griffin/measure/util/MailUtil.java   |  72 ++++++++
 .../apache/griffin/measure/util/Md5Util.java    |  56 ++++++
 .../griffin/measure/util/MessageUtil.java       | 178 +++++++++++++++++++
 .../src/main/resources/application.properties   |   2 +-
 service/src/main/resources/sparkJob.properties  |   3 +-
 11 files changed, 408 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/measure/pom.xml
----------------------------------------------------------------------
diff --git a/measure/pom.xml b/measure/pom.xml
index 7be88f5..9b16595 100644
--- a/measure/pom.xml
+++ b/measure/pom.xml
@@ -171,6 +171,12 @@ under the License.
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>com.sun.mail</groupId>
+      <artifactId>javax.mail</artifactId>
+      <version>1.4.4</version>
+    </dependency>
+
   </dependencies>
 
   <build>

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/measure/src/main/resources/config.json
----------------------------------------------------------------------
diff --git a/measure/src/main/resources/config.json b/measure/src/main/resources/config.json
index b6e5af9..1edb299 100644
--- a/measure/src/main/resources/config.json
+++ b/measure/src/main/resources/config.json
@@ -32,7 +32,6 @@
       ]
     }
   ],
-
   "evaluateRule": {
     "rules": [
       {

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/measure/src/main/resources/env.json
----------------------------------------------------------------------
diff --git a/measure/src/main/resources/env.json b/measure/src/main/resources/env.json
index 14e3b75..1081b6a 100644
--- a/measure/src/main/resources/env.json
+++ b/measure/src/main/resources/env.json
@@ -38,7 +38,22 @@
       }
     }
   ],
-
+  "mail":[
+    {
+      "host":"smtp.163.com",//mail host(163)
+      "mail":"xxx@163.com",//mail
+      "user":"xxx@163.com",//mail user
+      "password":"xxx"//mail password
+    }
+  ],
+  "sms":[
+    {
+      "host":"xxx",//meassage url
+      "id":"xx",
+      "key":"xxx",
+      "UUID":"xxx"
+    }
+  ],
   "cleaner": {
 
   }

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/measure/src/main/scala/org/apache/griffin/measure/config/params/env/EmailParam.scala
----------------------------------------------------------------------
diff --git a/measure/src/main/scala/org/apache/griffin/measure/config/params/env/EmailParam.scala b/measure/src/main/scala/org/apache/griffin/measure/config/params/env/EmailParam.scala
new file mode 100644
index 0000000..f5f8a4c
--- /dev/null
+++ b/measure/src/main/scala/org/apache/griffin/measure/config/params/env/EmailParam.scala
@@ -0,0 +1,36 @@
+/*
+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
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+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 org.apache.griffin.measure.config.params.env
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.annotation.{JsonInclude, JsonProperty}
+import org.apache.griffin.measure.config.params.Param
+
+/**
+  * Created by xiaoqiu.duan on 2017/10/23.
+  */
+@JsonInclude(Include.NON_NULL)
+case class EmailParam(@JsonProperty("host") host: String,
+                       @JsonProperty("mail") mail: String,
+                       @JsonProperty("user") usr: String,
+                       @JsonProperty("password") pwd: String
+                     ) extends Param {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/measure/src/main/scala/org/apache/griffin/measure/config/params/env/EnvParam.scala
----------------------------------------------------------------------
diff --git a/measure/src/main/scala/org/apache/griffin/measure/config/params/env/EnvParam.scala b/measure/src/main/scala/org/apache/griffin/measure/config/params/env/EnvParam.scala
index ad87a5f..629d06a 100644
--- a/measure/src/main/scala/org/apache/griffin/measure/config/params/env/EnvParam.scala
+++ b/measure/src/main/scala/org/apache/griffin/measure/config/params/env/EnvParam.scala
@@ -23,10 +23,12 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include
 import org.apache.griffin.measure.config.params.Param
 
 @JsonInclude(Include.NON_NULL)
-case class EnvParam( @JsonProperty("spark") sparkParam: SparkParam,
-                     @JsonProperty("persist") persistParams: List[PersistParam],
-                     @JsonProperty("info.cache") infoCacheParams: List[InfoCacheParam],
-                     @JsonProperty("cleaner") cleanerParam: CleanerParam
+case class EnvParam(@JsonProperty("spark") sparkParam: SparkParam,
+                    @JsonProperty("persist") persistParams: List[PersistParam],
+                    @JsonProperty("info.cache") infoCacheParams: List[InfoCacheParam],
+                    @JsonProperty("mail") emailParam: EmailParam,
+                    @JsonProperty("sms") smsParam: SMSParam,
+                    @JsonProperty("cleaner") cleanerParam: CleanerParam
                    ) extends Param {
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/measure/src/main/scala/org/apache/griffin/measure/config/params/env/SMSParam.scala
----------------------------------------------------------------------
diff --git a/measure/src/main/scala/org/apache/griffin/measure/config/params/env/SMSParam.scala b/measure/src/main/scala/org/apache/griffin/measure/config/params/env/SMSParam.scala
new file mode 100644
index 0000000..0cc87a7
--- /dev/null
+++ b/measure/src/main/scala/org/apache/griffin/measure/config/params/env/SMSParam.scala
@@ -0,0 +1,36 @@
+/*
+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
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+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 org.apache.griffin.measure.config.params.env
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include
+import com.fasterxml.jackson.annotation.{JsonInclude, JsonProperty}
+import org.apache.griffin.measure.config.params.Param
+
+/**
+  * Created by xiaoqiu.duan on 2017/10/23.
+  */
+@JsonInclude(Include.NON_NULL)
+case class SMSParam(@JsonProperty("host") host: String,
+                    @JsonProperty("id") id: String,
+                    @JsonProperty("key") key: String,
+                    @JsonProperty("UUID") uuid: String
+                     ) extends Param {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/measure/src/main/scala/org/apache/griffin/measure/util/MailUtil.java
----------------------------------------------------------------------
diff --git a/measure/src/main/scala/org/apache/griffin/measure/util/MailUtil.java b/measure/src/main/scala/org/apache/griffin/measure/util/MailUtil.java
new file mode 100644
index 0000000..4bbc581
--- /dev/null
+++ b/measure/src/main/scala/org/apache/griffin/measure/util/MailUtil.java
@@ -0,0 +1,72 @@
+/*
+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
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+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 org.apache.griffin.measure.util;
+
+
+import org.apache.griffin.measure.config.params.env.EmailParam;
+
+import javax.mail.*;
+import javax.mail.internet.*;
+import java.util.Properties;
+
+/**
+ * Created by xiaoqiu.duan on 2017/9/11.
+ */
+public class MailUtil {
+
+    public static void SendMail(String name, String UserArr, String Title, String Info, EmailParam emailParam) throws MessagingException {
+        Properties prop = new Properties();
+        prop.setProperty("mail.transport.protocol", "smtp");
+        prop.setProperty("mail.smtp.host", emailParam.host());
+        prop.setProperty("mail.smtp.auth", "NTLM");
+        prop.setProperty("mail.debug", "true");
+        Session session = Session.getInstance(prop);
+        Message msg = new MimeMessage(session);
+        msg.setFrom(new InternetAddress(emailParam.mail()));
+        //msg.setRecipient(Message.RecipientType.TO, new InternetAddress(UserArr));
+        String[] arr=null;
+        if (UserArr.indexOf(",")==-1) {
+            arr=new String[]{UserArr};
+        }
+        else {
+            arr=UserArr.split(",");
+        }
+        Address[] tos = new InternetAddress[arr.length];
+        for (int i=0; i<arr.length; i++){
+            tos[i] = new InternetAddress(arr[i]);
+        }
+        msg.setRecipients(Message.RecipientType.TO,tos);
+        msg.setSubject(Title);
+        Multipart mainPart = new MimeMultipart();
+        BodyPart html = new MimeBodyPart();
+        html.setContent(Info, "text/html; charset=utf-8");
+        mainPart.addBodyPart(html);
+        msg.setContent(mainPart);
+        msg.addHeader("X-Priority", "3");
+        msg.addHeader("X-MSMail-Priority", "Normal");
+        msg.addHeader("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869");
+        msg.addHeader("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869");
+        msg.addHeader("ReturnReceipt", "1");
+        Transport trans = session.getTransport();
+        trans.connect(emailParam.usr(), emailParam.pwd());
+        trans.sendMessage(msg, msg.getAllRecipients());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/measure/src/main/scala/org/apache/griffin/measure/util/Md5Util.java
----------------------------------------------------------------------
diff --git a/measure/src/main/scala/org/apache/griffin/measure/util/Md5Util.java b/measure/src/main/scala/org/apache/griffin/measure/util/Md5Util.java
new file mode 100644
index 0000000..0782510
--- /dev/null
+++ b/measure/src/main/scala/org/apache/griffin/measure/util/Md5Util.java
@@ -0,0 +1,56 @@
+/*
+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
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+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 org.apache.griffin.measure.util;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class Md5Util {
+
+    private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
+            'e', 'f' };
+
+    private Md5Util() {
+    }
+
+    public static String md5(String s) {
+
+        try {
+            byte[] bytes = s.getBytes();
+
+            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
+            messageDigest.update(bytes);
+            byte[] mdBytes = messageDigest.digest();
+            int j = mdBytes.length;
+            char[] str = new char[j * 2];
+            int k = 0;
+            for (int i = 0; i < j; i++) {
+                byte byte0 = mdBytes[i];
+                str[k++] = HEX_DIGITS[byte0 >>> 4 & 0xf];
+                str[k++] = HEX_DIGITS[byte0 & 0xf];
+            }
+            return new String(str);
+        } catch (NoSuchAlgorithmException ex) {
+
+            return null;
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/measure/src/main/scala/org/apache/griffin/measure/util/MessageUtil.java
----------------------------------------------------------------------
diff --git a/measure/src/main/scala/org/apache/griffin/measure/util/MessageUtil.java b/measure/src/main/scala/org/apache/griffin/measure/util/MessageUtil.java
new file mode 100644
index 0000000..6fba5ff
--- /dev/null
+++ b/measure/src/main/scala/org/apache/griffin/measure/util/MessageUtil.java
@@ -0,0 +1,178 @@
+/*
+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
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+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 org.apache.griffin.measure.util;
+
+import java.io.IOException;
+
+import org.apache.commons.lang.StringUtils;
+import java.util.ArrayList;
+import java.io.*;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.*;
+import java.util.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+import org.apache.griffin.measure.config.params.env.SMSParam;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * Created by xiaoqiu.duan on 2017/9/11.
+ */
+public class MessageUtil {
+
+
+    public static String sendSMSCode(String teamPhone, String content, SMSParam smsParam){
+        String url=smsParam.host();
+        String SYS_ID=smsParam.id();
+        String KEY=smsParam.key();
+        String sendContext="["+smsParam.uuid()+"]: "+content ;
+        System.out.println(" sendContext:  "+sendContext);
+        Long timestamp=new Date().getTime()+20610;
+        System.out.println(" timestamp:  "+timestamp);
+        String[]  tels=teamPhone.split(",") ;
+        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
+        Map<String,Object> param=new HashMap<String, Object>();
+        param.put("apportionment","JR_DATA_ALARM");
+        param.put("event",0);
+        param.put("eventTime",0);
+        param.put("isMasked",false);
+        param.put("originator","ETC");
+        param.put("reqId",uuid);
+        param.put("schemaKey","");
+        param.put("sysId",SYS_ID);
+        param.put("template",sendContext);
+        param.put("templateId","");
+        param.put("timestamp",timestamp);
+        param.put("token",Md5Util.md5(SYS_ID+timestamp+KEY));
+        param.put("typeCode","JR_DATA_ALARM");
+        System.out.println("params:  "+param);
+        List<Map<String, Object>> bodys = new ArrayList<Map<String, Object>>();
+          for (int i=0;i<tels.length;i++) {
+            Map<String, Object> body = new HashMap<String, Object>();
+            body.put("phoneNo", tels[i]);
+            body.put("params", "");
+            body.put("userId", 0);
+            bodys.add(body);
+        }
+        System.out.println("bodys:  "+bodys);
+        JSONObject jsonParam = new JSONObject();
+        try {
+            jsonParam.put("params",param);
+            jsonParam.put("bodys",bodys);
+            System.out.println("jsonParam:  "+jsonParam);
+            System.out.println("jsonParam:  "+jsonParam.toString());
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+        URL u=null;
+        int smsnum=0;
+        HttpURLConnection connection=null;
+        try{
+           String result= postRequestUrl(url, jsonParam.toString(), "utf-8");
+            return "send success";
+        }catch(Exception e){
+            e.printStackTrace();
+            return null;
+        }
+
+    }
+
+
+    public static String postRequestUrl(String url, String param,String encode) {
+        OutputStreamWriter out = null;
+        BufferedReader reader = null;
+        String response="";
+        try {
+            URL httpUrl = null;
+            httpUrl = new URL(url);
+            HttpURLConnection conn = (HttpURLConnection) httpUrl.openConnection();
+            conn.setRequestMethod("POST");
+            conn.setRequestProperty("Content-Type", "application/json");//x-www-form-urlencoded
+            conn.setRequestProperty("connection", "keep-alive");
+            conn.setUseCaches(false);
+            conn.setInstanceFollowRedirects(true);
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            conn.connect();
+            //POST
+            out = new OutputStreamWriter(
+                    conn.getOutputStream());
+            out.write(param);
+
+            out.flush();
+
+            System.out.println("send POST "+conn.getResponseCode());
+            reader = new BufferedReader(new InputStreamReader(
+                    conn.getInputStream()));
+
+            String lines;
+            while ((lines = reader.readLine()) != null) {
+                lines = new String(lines.getBytes(), "utf-8");
+                response+=lines;
+                System.out.println("lines:  "+lines);
+            }
+            reader.close();
+            conn.disconnect();
+
+            //log.info(response.toString());
+        } catch (Exception e) {
+            System.out.println("send POST error!"+e);
+            e.printStackTrace();
+        }
+        finally{
+            try{
+                if(out!=null){
+                    out.close();
+                }
+                if(reader!=null){
+                    reader.close();
+                }
+            }
+            catch(IOException ex){
+                ex.printStackTrace();
+            }
+        }
+
+        return response;
+    }
+
+
+
+    private static String readBufferedContent(BufferedReader bufferedReader) {
+        if (bufferedReader == null)
+            return null;
+        StringBuffer result = new StringBuffer();
+        String line = null;
+        try {
+            while (StringUtils.isNotBlank((line = bufferedReader.readLine()))) {
+                result.append(line+"\r\n");
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+        return result.toString();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/service/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/service/src/main/resources/application.properties b/service/src/main/resources/application.properties
index 2a579e3..15f9db1 100644
--- a/service/src/main/resources/application.properties
+++ b/service/src/main/resources/application.properties
@@ -52,4 +52,4 @@ ldap.url=ldap://<ldap url>
 ldap.domain=<account domain>
 ldap.dc=<domain components config>
 ldap.connect-timeout=<connect timeout config>
-ldap.read-timeout=<read timeout config>
+ldap.read-timeout=<read timeout config>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/6ab05fc2/service/src/main/resources/sparkJob.properties
----------------------------------------------------------------------
diff --git a/service/src/main/resources/sparkJob.properties b/service/src/main/resources/sparkJob.properties
index e01058e..7e0e48c 100644
--- a/service/src/main/resources/sparkJob.properties
+++ b/service/src/main/resources/sparkJob.properties
@@ -48,5 +48,4 @@ livy.uri=http://localhost:8998/batches
 # spark-admin
 # spark.uri=http://10.149.247.156:28088
 # spark.uri=http://10.9.246.187:8088
-spark.uri=http://localhost:8088
-
+spark.uri=http://localhost:8088
\ No newline at end of file