alan-turing-institute / simulate

A web framework for research simulations.
http://simulate.readthedocs.io
MIT License
4 stars 1 forks source link

Manager status API cannot handle "RUNNING" patch #70

Closed masonlr closed 6 years ago

masonlr commented 6 years ago

In the current JobStatusApi(), the response object r is not defined for job_status.upper() = "RUNNING"

class JobStatusApi(Resource):
    """
    Endpoint to update the status of a job  when it starts running etc.
    """

    @use_kwargs(job_status_args, locations=('json',))
    def patch(self, job_id, job_status):
        """
        update the status of this job - do a PATCH request to middleware api.
        If the status is COMPLETED, send the middleware the output URI.
        If the status is FINALIZING, send the backend the info it needs to
        upload the job output to azure.
        """
        middleware_url = current_app.config["MIDDLEWARE_API_BASE"]
        status_dict = {"status": job_status}
        outputs = []
        if job_status.upper() == "COMPLETED":
            ### right now we only have one output, which is a zip file
            job_outputs = job_output.get_outputs(job_id, with_sas=False)
            for output_type, uri in job_outputs.items():
                outputs.append({"job_id": job_id,
                                "output_type": output_type,
                                "destination_path": uri})
            ### call the middleware's status api to update the status to "COMPLETED"
            r = requests.put('{}/job/{}/status'.format(middleware_url,str(job_id)),
                             json=status_dict)
            if r.status_code != 200:
                return {
                    "status": r.status_code,
                    "message": "Error setting COMPLETED status."
                }
            ### now call the middleware's output api to add the output.
            for output in outputs:
                r = requests.post('{}/job/{}/output'.format(middleware_url,str(job_id)),
                                  json=output)
                if r.status_code != 200:
                    return {
                        "status": r.status_code,
                        "message": "Error setting output."
                    }
            ### posted all outputs to middleware
            return {
                "status": 200,
                "message": "successfully added outputs"
            }
        elif job_status.upper() == 'FINALIZING':
            acc, con, tok, blob = job_output.prepare_output_storage()
            blob_name = '{}/{}'.format(job_id,blob)
            return {"status": 200,
                    "data": {"token": tok,
                             "container": con,
                             "account": acc,
                             "blob": blob_name
                             }
                    }
        else:
            return {"status": r.status_code,
                    "data": r.content.decode("utf-8")
            }
masonlr commented 6 years ago

The consequence of this bug is that the frontend is not displaying the RUNNING status.

masonlr commented 6 years ago

Manager currently accepts a "job_status" field in the JSON, whereas middleware accepts a "status" field. Propose that we make these consistent.

masonlr commented 6 years ago

Addressed by alan-turing-institute/gateway-job-manager-openfoam#10