@@ -13,6 +13,7 @@ class DpCloudServer(Machine):
1313 def __init__ (self , context ):
1414 self .context = context
1515 self .input_data = context .remote_profile ['input_data' ].copy ()
16+ self .api_version = self .input_data .get ('api_version' , 1 )
1617
1718 def gen_script (self , job ):
1819 shell_script = super (DpCloudServer , self ).gen_script (job )
@@ -42,30 +43,53 @@ def do_submit(self, job):
4243 input_data ['job_resources' ] = job_resources
4344 input_data ['command' ] = f"bash { job .script_file_name } "
4445
45-
46- job_id = api .job_create (
47- job_type = input_data ['job_type' ],
48- oss_path = input_data ['job_resources' ],
49- input_data = input_data ,
50- program_id = self .context .remote_profile .get ('program_id' , None )
51- )
52-
53- job .job_id = job_id
46+ job_id = None
47+ if self .api_version == 2 :
48+ job_id , group_id = api .job_create_v2 (
49+ job_type = input_data ['job_type' ],
50+ oss_path = input_data ['job_resources' ],
51+ input_data = input_data ,
52+ program_id = self .context .remote_profile .get ('program_id' , None )
53+ )
54+ self .input_data ['job_group_id' ] = group_id
55+ job .job_id = str (job_id ) + ':job_group_id' + str (group_id )
56+ job_id = job .job_id
57+ else :
58+ job_id = api .job_create (
59+ job_type = input_data ['job_type' ],
60+ oss_path = input_data ['job_resources' ],
61+ input_data = input_data ,
62+ program_id = self .context .remote_profile .get ('program_id' , None )
63+ )
5464 job .job_state = JobStatus .waiting
5565 return job_id
5666
5767 def check_status (self , job ):
5868 if job .job_id == '' :
5969 return JobStatus .unsubmitted
70+ job_id = job .job_id
71+ if type (job .job_id ) is str and ':job_group_id' in job .job_id :
72+ ids = job .job_id .split (":job_group_id" )
73+ job .job_id ,self .input_data ["job_group_id" ] = int (ids [0 ]), int (ids [1 ])
74+ self .api_version = 2
75+ job_id = job .job_id
6076 dlog .debug (f"debug: check_status; job.job_id:{ job .job_id } ; job.job_hash:{ job .job_hash } " )
61-
62- check_return = api .get_tasks (job .job_id )
77+ check_return = None
78+ if self .api_version == 2 :
79+ check_return = api .get_tasks_v2 (job_id ,self .input_data .get ('job_group_id' ))
80+ else :
81+ check_return = api .get_tasks (job_id )
6382 try :
6483 dp_job_status = check_return [0 ]["status" ]
6584 except IndexError as e :
66- dlog .error (f"cannot find job information in check_return. job { job . job_id } . check_return:{ check_return } ; retry one more time after 60 seconds" )
85+ dlog .error (f"cannot find job information in check_return. job { job_id } . check_return:{ check_return } ; retry one more time after 60 seconds" )
6786 time .sleep (60 )
68- retry_return = api .get_tasks (job .job_id )
87+ retry_return = None
88+ retry_return = api .get_tasks (job_id )
89+ if self .api_version == 2 :
90+ retry_return = api .get_tasks_v2 (job_id ,self .input_data .get ('job_group_id' ))
91+ else :
92+ retry_return = api .get_tasks (job_id )
6993 try :
7094 dp_job_status = retry_return [0 ]["status" ]
7195 except IndexError as e :
@@ -91,8 +115,13 @@ def map_dp_job_state(status):
91115 - 1 :JobStatus .terminated ,
92116 0 :JobStatus .waiting ,
93117 1 :JobStatus .running ,
94- 2 :JobStatus .finished
118+ 2 :JobStatus .finished ,
119+ 3 :JobStatus .waiting ,
120+ 4 :JobStatus .running ,
121+ 5 :JobStatus .terminated
95122 }
123+ if status not in map_dict :
124+ return JobStatus .unknown
96125 return map_dict [status ]
97126
98127
0 commit comments