Skip to content

Commit

Permalink
Merge pull request #118 from skorzhevsky/update-jobs-for-new-sdk
Browse files Browse the repository at this point in the history
Fix jobs.list_jobs() for new SdkApi. Minor code cleanup.
  • Loading branch information
t1m0thyj authored Aug 26, 2022
2 parents afa9492 + 76330a5 commit 3a58202
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/zos_jobs/zowe/zos_jobs_for_zowe_sdk/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def cancel_job(self, jobname, jobid):
request_url = "{}{}".format(self.request_endpoint, job_url)
custom_args["url"] = request_url
custom_args["json"] = {"request": "cancel"}
response_json = self.request_handler.perform_request("PUT", custom_args, expected_code = [202])
response_json = self.request_handler.perform_request("PUT", custom_args, expected_code=[202])
return response_json

def delete_job(self, jobname, jobid):
Expand All @@ -99,7 +99,7 @@ def delete_job(self, jobname, jobid):
job_url = "{}/{}".format(jobname, jobid)
request_url = "{}{}".format(self.request_endpoint, job_url)
custom_args["url"] = request_url
response_json = self.request_handler.perform_request("DELETE", custom_args, expected_code = [202])
response_json = self.request_handler.perform_request("DELETE", custom_args, expected_code=[202])
return response_json

def list_jobs(self, owner=None, prefix="*", max_jobs=1000, user_correlator=None):
Expand All @@ -123,7 +123,7 @@ def list_jobs(self, owner=None, prefix="*", max_jobs=1000, user_correlator=None
"""
custom_args = self._create_custom_request_arguments()
params = {"prefix": prefix, "max-jobs": max_jobs}
params["owner"] = owner if owner else self.connection.user
params["owner"] = owner if owner else self.session.user
if user_correlator:
params["user-correlator"] = user_correlator
custom_args["params"] = params
Expand Down Expand Up @@ -202,8 +202,7 @@ def submit_plaintext(self, jcl):
)
return response_json


def get_spool_files(self,correlator):
def get_spool_files(self, correlator):
"""Retrieve the spool files for a job identified by the correlator.
Parameters
Expand All @@ -223,7 +222,7 @@ def get_spool_files(self,correlator):
response_json = self.request_handler.perform_request("GET", custom_args)
return response_json

def get_jcl_text(self,correlator):
def get_jcl_text(self, correlator):
"""Retrieve the input JCL text for job with specified correlator
Parameters
----------
Expand All @@ -242,7 +241,7 @@ def get_jcl_text(self,correlator):
response_json = self.request_handler.perform_request("GET", custom_args)
return response_json

def get_spool_file_contents(self,correlator,id):
def get_spool_file_contents(self, correlator, id):
"""Retrieve the contents of a single spool file from a job
Expand All @@ -260,13 +259,13 @@ def get_spool_file_contents(self,correlator,id):
A JSON containing the result of the request execution
"""
custom_args = self._create_custom_request_arguments()
job_url = "{}/files/{}/records".format(correlator,id)
job_url = "{}/files/{}/records".format(correlator, id)
request_url = "{}{}".format(self.request_endpoint, job_url)
custom_args["url"] = request_url
response_json = self.request_handler.perform_request("GET", custom_args)
return response_json

def get_job_output_as_files(self,status,output_dir):
def get_job_output_as_files(self, status, output_dir):
"""This method will get all the spool files as well as the submitted jcl text in separate files in the specified
output directory. The structure will be as follows:
Expand Down Expand Up @@ -302,12 +301,12 @@ def get_job_output_as_files(self,status,output_dir):
_job_id = status['jobid']
_job_correlator = status['job-correlator']

_output_dir = os.path.join(output_dir,_job_name,_job_id)
os.makedirs(_output_dir,exist_ok=True)
_output_file = os.path.join(output_dir,_job_name,_job_id,'jcl.txt')
_output_dir = os.path.join(output_dir, _job_name, _job_id)
os.makedirs(_output_dir, exist_ok=True)
_output_file = os.path.join(output_dir, _job_name, _job_id, 'jcl.txt')
_data_spool_file = self.get_jcl_text(_job_correlator)
_dataset_content = _data_spool_file['response']
_out_file = open(_output_file,'w')
_out_file = open(_output_file, 'w')
_out_file.write(_dataset_content)
_out_file.close()

Expand All @@ -316,13 +315,13 @@ def get_job_output_as_files(self,status,output_dir):
_stepname = _spool_file['stepname']
_ddname = _spool_file['ddname']
_spoolfile_id = _spool_file['id']
_output_dir = os.path.join(output_dir,_job_name,_job_id,_stepname)
os.makedirs(_output_dir,exist_ok=True)
_output_dir = os.path.join(output_dir, _job_name, _job_id, _stepname)
os.makedirs(_output_dir, exist_ok=True)

_output_file = os.path.join(output_dir,_job_name,_job_id,_stepname,_ddname)
_data_spool_file = self.get_spool_file_contents(_job_correlator,_spoolfile_id)
_output_file = os.path.join(output_dir, _job_name, _job_id, _stepname, _ddname)
_data_spool_file = self.get_spool_file_contents(_job_correlator, _spoolfile_id)
_dataset_content = _data_spool_file['response']
_out_file = open(_output_file,'w')
_out_file = open(_output_file, 'w')
_out_file.write(_dataset_content)
_out_file.close()

Expand Down

0 comments on commit 3a58202

Please sign in to comment.