Skip to content

Commit

Permalink
add endpoint to check if azure copy is working
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoam committed Jul 20, 2021
1 parent 8eacfa4 commit 5f84cfa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions serverpkg/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
def _configure_app():
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
data_path = os.environ['CHECKER_DATA_DIR']

# strip trailing '/' if there is one
if data_path[-1] == '/':
data_path = data_path[0:-1]
app.config['data_dir'] = data_path + '/data'
app.config['matcher_dir'] = data_path + '/matchers'
app.config['runner_dir'] = data_path + '/runners'
Expand Down Expand Up @@ -129,6 +133,13 @@ def get_server_status():
return json.dumps({'num_jobs': _job_status_db.num_running_jobs()})


@app.route('/status/azure', methods=['GET'])
def get_azure_status():
import serverpkg.spark.azure_health as az
import json
return json.dumps({'azcopy upload': 'success' if az.check_azcopy() else 'fail'} )


@app.route('/jobs')
def show_jobs_():
"""
Expand Down
17 changes: 17 additions & 0 deletions serverpkg/spark/azure_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
check Azure related system health
"""

from serverpkg.server import app
from ..logger import Logger
logger = Logger(__name__).logger

def check_azcopy():
""":return True if succeed uploading a file to my subs/container; False otherwise """
import subprocess
completed_proc = subprocess.run( [app.config['runner_dir'] + '/check_azcopy.sh'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)

if completed_proc.returncode != 0:
logger.info("STDERR:\n" + completed_proc.stderr.decode('utf-8'))

return completed_proc.returncode == 0

0 comments on commit 5f84cfa

Please sign in to comment.