Commit 293f5514 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Added support for 'info' and 'results' commands for 'vos_job'.

parent 522cb584
Loading
Loading
Loading
Loading
+45 −17
Original line number Diff line number Diff line
#!/usr/bin/env python

import os
import json
import sys

from amqp_client import AMQPClient
@@ -34,13 +34,49 @@ class VOSJob(AMQPClient):
            if jobList:
                print("\n" + tabulate(jobResponse["jobList"], headers = "keys", tablefmt = "pretty") + "\n")
            else:
                sys.exit("\nNo active job found.\n")                
                sys.exit("\nNo active jobs found.\n")                
        elif jobResponse["responseType"] == "LST_BY_PHASE_DONE":
            jobList = jobResponse["jobList"]
            if jobList:
                print("\n" + tabulate(jobResponse["jobList"], headers = "keys", tablefmt = "pretty") + "\n")
            else:
                sys.exit(f"\nNo {jobPhase} job found.\n")
                sys.exit(f"\nNo {jobPhase} jobs found.\n")
        elif jobResponse["responseType"] == "ERROR":
            errorCode = jobResponse["errorCode"]
            errorMsg = jobResponse["errorMsg"]
            sys.exit(f"\nError code: {errorCode}\nError message: {errorMsg}\n")
        else:
            sys.exit("\nFATAL: Unknown response type.\n")

    def info(self, jobId):
        jobRequest = { "requestType": "JOB_INFO", "jobId": jobId }
        jobResponse = self.call(jobRequest)
        if "responseType" not in jobResponse:
            sys.exit("FATAL: Malformed response.\n")
        elif jobResponse["responseType"] == "LST_INFO_DONE":
            jobInfo = jobResponse["jobInfo"]
            if jobInfo:
                print("\n" + json.dumps(jobInfo, indent = 4, sort_keys = True) + "\n")
            else:
                sys.exit(f"\nThere is no job with ID {jobId}\n")                
        elif jobResponse["responseType"] == "ERROR":
            errorCode = jobResponse["errorCode"]
            errorMsg = jobResponse["errorMsg"]
            sys.exit(f"\nError code: {errorCode}\nError message: {errorMsg}\n")
        else:
            sys.exit("\nFATAL: Unknown response type.\n")

    def results(self, jobId):
        jobRequest = { "requestType": "JOB_RESULTS", "jobId": jobId }
        jobResponse = self.call(jobRequest)
        if "responseType" not in jobResponse:
            sys.exit("FATAL: Malformed response.\n")
        elif jobResponse["responseType"] == "LST_RESULTS_DONE":
            jobResults = jobResponse["jobResults"]
            if jobResults:
                print("\n" + json.dumps(jobResults, indent = 4, sort_keys = True) + "\n")
            else:
                sys.exit(f"\nThere may be no job with ID {jobId} or it may still be active.\n")                
        elif jobResponse["responseType"] == "ERROR":
            errorCode = jobResponse["errorCode"]
            errorMsg = jobResponse["errorMsg"]
@@ -62,10 +98,8 @@ DESCRIPTION
    The client accepts the following commands:
    
    list 
        if launched without any argument it will
        display all the currently active jobs.
        The command can also be used with one
        argument, the job phase. The following 
        if launched without any argument it will display all the currently active jobs.
        The command can also be used with one argument, the job phase. The following 
        values are allowed:
        - pending
        - queued
@@ -74,13 +108,11 @@ DESCRIPTION
        - error
        
    info
        prints a JSON object containing the job 
        info according to the UWS specification.
        prints a JSON object containing the job info according to the UWS specification.
        A job id is required as argument.
        
    results
        prints a JSON object containing the job 
        results according to the UWS specification.
        prints a JSON object containing the job results according to the UWS specification.
        A job id is required as argument.
        """)

@@ -102,13 +134,9 @@ elif len(sys.argv) == 3:
        else:
            vosJobCli.help()
    elif cmd == "info":
        #TODO
        #vosJobCli.info()
        pass
        vosJobCli.info(arg)
    elif cmd == "results":
        #TODO
        #vosJobCli.results()
        pass
        vosJobCli.results(arg)
    else:
        vosJobCli.help()
else:
+11 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ class JobAMQPServer(AMQPServer):
                                  self.params["host"],
                                  self.params.getint("port"),
                                  self.params["db"])
        self.jobId = None
        self.jobPhase = None
        super(JobAMQPServer, self).__init__(host, port, queue)

@@ -37,9 +38,17 @@ class JobAMQPServer(AMQPServer):
            self.dbConn.disconnect()
            response = { "responseType": "LST_BY_PHASE_DONE", "jobList": result }
        elif requestBody["requestType"] == "JOB_INFO":
            pass
            self.jobId = requestBody["jobId"]
            self.dbConn.connect()
            result = self.dbConn.getJobInfo(self.jobId)
            self.dbConn.disconnect()
            response = { "responseType": "LST_INFO_DONE", "jobInfo": result }
        elif requestBody["requestType"] == "JOB_RESULTS":
            pass                
            self.jobId = requestBody["jobId"]
            self.dbConn.connect()
            result = self.dbConn.getJobResults(self.jobId)
            self.dbConn.disconnect()
            response = { "responseType": "LST_RESULTS_DONE", "jobResults": result }
        else:
            response = { "responseType": "ERROR",
                         "errorCode": 2,