airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [27/45] airavata git commit: adding simple REST service for receiving job statuses
Date Wed, 08 Mar 2017 17:13:07 GMT
adding simple REST service for receiving job statuses


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/e34722a9
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/e34722a9
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/e34722a9

Branch: refs/heads/ansible-testing-0.17
Commit: e34722a98b7634d71e80ccab170bd43197395d12
Parents: 6c367b9
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Thu Mar 2 14:05:48 2017 -0500
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Thu Mar 2 14:05:48 2017 -0500

----------------------------------------------------------------------
 sandbox/job-status-rest-server/README.MD   |  9 +++++
 sandbox/job-status-rest-server/api_test.py |  6 +++
 sandbox/job-status-rest-server/app.py      | 50 +++++++++++++++++++++++++
 3 files changed, 65 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/e34722a9/sandbox/job-status-rest-server/README.MD
----------------------------------------------------------------------
diff --git a/sandbox/job-status-rest-server/README.MD b/sandbox/job-status-rest-server/README.MD
new file mode 100644
index 0000000..104e10a
--- /dev/null
+++ b/sandbox/job-status-rest-server/README.MD
@@ -0,0 +1,9 @@
+Python Flask framework based REST API for sending job statuses from clusters
+============================================================================
+
+Requirement
+* pip install flask
+* pip install flask-restful
+
+Sample CURL Command
+curl -X POST -d "job_id=ABC&job_name=Test&status=0&emails[]=supun.nakandala@gmail.com,eabeysin@iu.edu"
http://localhost:8089/job_status
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/e34722a9/sandbox/job-status-rest-server/api_test.py
----------------------------------------------------------------------
diff --git a/sandbox/job-status-rest-server/api_test.py b/sandbox/job-status-rest-server/api_test.py
new file mode 100644
index 0000000..8ca513d
--- /dev/null
+++ b/sandbox/job-status-rest-server/api_test.py
@@ -0,0 +1,6 @@
+import requests
+
+r = requests.post("http://localhost:8089/job_status", data={
+    'job_id': 12524, 'job_name': 'issue', 'status': '0', 'emails[]': ['supun.nakandala@gmail.com']
+})
+print(r.status_code, r.reason)

http://git-wip-us.apache.org/repos/asf/airavata/blob/e34722a9/sandbox/job-status-rest-server/app.py
----------------------------------------------------------------------
diff --git a/sandbox/job-status-rest-server/app.py b/sandbox/job-status-rest-server/app.py
new file mode 100644
index 0000000..e894650
--- /dev/null
+++ b/sandbox/job-status-rest-server/app.py
@@ -0,0 +1,50 @@
+from flask import Flask, request
+from flask_restful import Resource, Api
+from flask import jsonify
+
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+
+import smtplib
+import sys
+
+app = Flask(__name__)
+
+email_username = 'gw56jobs@scigap.org'
+email_password = 'XseDe2015'
+status_string = "COMPLETED"
+from_address = 'gw56jobs@scigap.org'
+
+
+@app.route('/job_status', methods=['POST'])
+def job_status():
+    name = request.form['job_name']
+    job_id = request.form['job_id']
+    status = request.form['status']
+    emails = request.form.getlist('emails[]')
+    if status == "0":
+        for to_address in emails:
+            msg = MIMEMultipart()
+            msg['From'] = from_address
+            msg['To'] = to_address
+            msg['Subject'] = "Job_id=" + job_id + " Name=" + name + " Status=" + status_string
+
+            server = smtplib.SMTP('smtp.gmail.com:587')
+            server.ehlo()
+            server.starttls()
+            server.login(email_username, email_password)
+            server.sendmail(from_address, to_address, msg.as_string())
+
+            server.quit()
+
+    return jsonify({'result': 200})
+
+
+if __name__ == '__main__':
+    app.config.update(
+        DEBUG=True
+    )
+    app.run(
+        host="localhost",
+        port=int("8089"),
+    )


Mime
View raw message