def delete_job(job_id): # noqa r"""Delete a given job. --- delete: summary: Deletes a given job. description: >- This resource expects the `job_id` of the job to be deleted. operationId: delete_job consumes: - application/json produces: - application/json parameters: - name: job_id in: path description: Required. ID of the job to be deleted. required: true type: string responses: 204: description: >- Request accepted. A request to delete the job has been sent to the computing backend. 404: description: Request failed. The given job ID does not seem to exist. examples: application/json: "message": >- The job cdcf48b1-c2f3-4693-8230-b066e088444c doesn't exist 502: description: >- Request failed. Something went wrong while calling the computing backend. examples: application/json: "message": >- Connection to computing backend failed: [reason] """ if job_exists(job_id): try: backend_job_id = retrieve_backend_job_id(job_id) #KubernetesJobManager.stop(backend_job_id) HTCondorJobManager.stop(backend_job_id) return jsonify(), 204 except ComputingBackendSubmissionError as e: return jsonify({ 'message': 'Connection to computing backend failed:\n{}'.format(e) }), 502 else: return jsonify({'message': 'The job {} doesn\'t exist'.format(job_id)}), 404
def get_job(job_id): # noqa r"""Get a job. --- get: summary: Returns details about a given job. description: >- This resource is expecting the job's UUID as a path parameter. Its information will be served in JSON format. operationId: get_job produces: - application/json parameters: - name: job_id in: path description: Required. ID of the job. required: true type: string responses: 200: description: >- Request succeeded. The response contains details about the given job ID. schema: $ref: '#/definitions/Job' examples: application/json: "job": { "cmd": "date", "cvmfs_mounts": ['atlas.cern.ch', 'atlas-condb.cern.ch'], "docker_img": "busybox", "experiment": "atlas", "job_id": "cdcf48b1-c2f3-4693-8230-b066e088c6ac", "max_restart_count": 3, "restart_count": 0, "status": "started" } 404: description: Request failed. The given job ID does not seem to exist. examples: application/json: "message": >- The job cdcf48b1-c2f3-4693-8230-b066e088444c doesn't exist """ if job_exists(job_id): jobdict = retrieve_job(job_id) return jsonify(jobdict), 200 else: return jsonify({'message': 'The job {} doesn\'t exist' .format(job_id)}), 400
def get_logs(job_id): # noqa r"""Job logs. --- get: summary: Returns the logs for a given job. description: >- This resource is expecting the job's UUID as a path parameter. Its information will be served in JSON format. operationId: get_logs produces: - application/json parameters: - name: job_id in: path description: Required. ID of the job. required: true type: string responses: 200: description: >- Request succeeded. The response contains the logs for the given job. examples: application/json: "log": "Tue May 16 13:52:00 CEST 2017\n" 404: description: Request failed. The given job ID does not seem to exist. examples: application/json: "message": >- The job cdcf48b1-c2f3-4693-8230-b066e088444c doesn't exist """ if job_exists(job_id): return retrieve_job_logs(job_id) else: return jsonify({'message': 'The job {} doesn\'t exist' .format(job_id)}), 404
def delete_job(job_id): # noqa r"""Delete a given job. --- delete: summary: Deletes a given job. description: >- This resource expects the `job_id` of the job to be deleted. operationId: delete_job consumes: - application/json produces: - application/json parameters: - name: job_id in: path description: Required. ID of the job to be deleted. required: true type: string - name: compute_backend in: query description: Job compute backend. required: false type: string responses: 204: description: >- Request accepted. A request to delete the job has been sent to the compute backend. 404: description: Request failed. The given job ID does not seem to exist. examples: application/json: "message": >- The job cdcf48b1-c2f3-4693-8230-b066e088444c doesn't exist 502: description: >- Request failed. Something went wrong while calling the compute backend. examples: application/json: "message": >- Connection to compute backend failed: [reason] """ if job_exists(job_id): try: compute_backend = request.args.get( "compute_backend", current_app.config["DEFAULT_COMPUTE_BACKEND"] ) backend_job_id = retrieve_backend_job_id(job_id) job_manager_cls = current_app.config["COMPUTE_BACKENDS"][compute_backend]() job_manager_cls.stop(backend_job_id) return jsonify(), 204 except ComputingBackendSubmissionError as e: return ( jsonify( {"message": "Connection to compute backend failed:\n{}".format(e)} ), 502, ) else: return jsonify({"message": "The job {} doesn't exist".format(job_id)}), 404