@@ -93,14 +93,15 @@ def start(self, deployment_instance, await_status: int) -> bool:
9393 )
9494
9595 if not done :
96- total_steps = (
97- len (self .START_STEPS ) - 1
98- ) + self ._get_min_starting_instances (deployment_instance )
99- pbar = tqdm (total = total_steps )
96+ min_instances = self ._get_min_starting_instances (deployment_instance )
97+ num_steps = (len (self .START_STEPS ) - 1 ) + min_instances
98+ if deployment_instance ._predictor ._state .condition is None :
99+ num_steps = min_instances # backward compatibility
100+ pbar = tqdm (total = num_steps )
100101 pbar .set_description ("Creating deployment" )
101102
102103 # set progress function
103- def update_progress (state , num_instances = 0 ):
104+ def update_progress (state , num_instances ):
104105 (progress , desc ) = self ._get_starting_progress (
105106 pbar .n , state , num_instances
106107 )
@@ -109,7 +110,7 @@ def update_progress(state, num_instances=0):
109110 pbar .set_description (desc )
110111
111112 try :
112- update_progress (state )
113+ update_progress (state , num_instances = 0 )
113114 self ._serving_api .post (
114115 deployment_instance , DEPLOYMENT .ACTION_START
115116 ) # start deployment
@@ -138,19 +139,22 @@ def stop(self, deployment_instance, await_status: int) -> bool:
138139 if deployment_instance .requested_instances >= num_instances
139140 else num_instances
140141 )
142+ if deployment_instance ._predictor ._state .condition is None :
143+ # backward compatibility
144+ num_steps = self ._get_min_starting_instances (deployment_instance )
141145 pbar = tqdm (total = num_steps )
142146 pbar .set_description ("Preparing to stop deployment" )
143147
144148 # set progress function
145- def update_progress (state , num_instances = 0 ):
149+ def update_progress (state , num_instances ):
146150 (progress , desc ) = self ._get_stopping_progress (
147151 pbar .total , pbar .n , state , num_instances
148152 )
149153 pbar .update (progress )
150154 if desc is not None :
151155 pbar .set_description (desc )
152156
153- update_progress (state )
157+ update_progress (state , num_instances )
154158 self ._serving_api .post (
155159 deployment_instance , DEPLOYMENT .ACTION_STOP
156160 ) # stop deployment
@@ -225,17 +229,25 @@ def _check_status(self, deployment_instance, desired_status):
225229 print ("Deployment is already stopping" )
226230 return (True , state )
227231 if state .status == PREDICTOR_STATE .STATUS_STARTING :
228- raise ModelServingException (
229- "Deployment is starting, please wait until it completely starts"
230- )
232+ if state .condition is not None :
233+ raise ModelServingException (
234+ "Deployment is starting, please wait until it completely starts"
235+ )
231236 if state .status == PREDICTOR_STATE .STATUS_UPDATING :
232- raise ModelServingException (
233- "Deployment is updating, please wait until the update completes"
234- )
237+ if state .condition is not None :
238+ raise ModelServingException (
239+ "Deployment is updating, please wait until the update completes"
240+ )
235241
236242 return (False , state )
237243
238244 def _get_starting_progress (self , current_step , state , num_instances ):
245+ if state .condition is None : # backward compatibility
246+ progress = num_instances - current_step
247+ if state .status == PREDICTOR_STATE .STATUS_RUNNING :
248+ return (progress , "Deployment is ready" )
249+ return (progress , None if current_step == 0 else "Deployment is starting" )
250+
239251 step = self .START_STEPS .index (state .condition .type )
240252 if (
241253 state .condition .type == PREDICTOR_STATE .CONDITION_TYPE_STARTED
@@ -253,6 +265,15 @@ def _get_starting_progress(self, current_step, state, num_instances):
253265 return (progress , desc )
254266
255267 def _get_stopping_progress (self , total_steps , current_step , state , num_instances ):
268+ if state .condition is None : # backward compatibility
269+ progress = (total_steps - num_instances ) - current_step
270+ if state .status == PREDICTOR_STATE .STATUS_STOPPED :
271+ return (progress , "Deployment is stopped" )
272+ return (
273+ progress ,
274+ None if total_steps == current_step else "Deployment is stopping" ,
275+ )
276+
256277 step = 0
257278 if state .condition .type == PREDICTOR_STATE .CONDITION_TYPE_SCHEDULED :
258279 step = 1 if state .condition .status is None else 0
0 commit comments