@@ -123,10 +123,17 @@ def create(self, *args, **kwargs):
123123 config = Config .objects .create (owner = self .owner , app = self )
124124 Release .objects .create (version = 1 , owner = self .owner , app = self , config = config , build = None )
125125
126+ # create required minimum resources in k8s for the application
127+ self ._scheduler .create (self .id )
128+
129+ # Attach the platform specific application sub domain to the k8s service
130+ Domain (owner = self .owner , app = self , domain = self .id ).save ()
131+
126132 def delete (self , * args , ** kwargs ):
127133 """Delete this application including all containers"""
128134 try :
129135 # attempt to remove containers from the scheduler
136+ self ._scheduler .destroy (self .id )
130137 self ._destroy_containers ([c for c in self .container_set .exclude (type = 'run' )])
131138 except RuntimeError :
132139 pass
@@ -323,12 +330,6 @@ def _scale_containers(self, scale_types, to_remove):
323330 command = command ,
324331 ** kwargs
325332 )
326-
327- # Attach the platform specific application sub domain
328- # scheduler.scale creates the required service on apps:create
329- if not Domain .objects .filter (owner = self .owner , app = self , domain = self ).exists ():
330- Domain (owner = self .owner , app = self , domain = str (self )).save ()
331-
332333 except Exception as e :
333334 err = '{} (scale): {}' .format (job_id , e )
334335 log_event (self , err , logging .ERROR )
@@ -375,14 +376,19 @@ def _destroy_containers(self, to_destroy):
375376 """Destroys containers via the scheduler"""
376377 if not to_destroy :
377378 return
378- destroy_threads = [Thread (target = c .destroy ) for c in to_destroy ]
379- [t .start () for t in destroy_threads ]
380- [t .join () for t in destroy_threads ]
381- [c .delete () for c in to_destroy if c .state == 'destroyed' ]
382- if any (c .state != 'destroyed' for c in to_destroy ):
383- err = 'aborting, failed to destroy some containers'
384- log_event (self , err , logging .ERROR )
385- raise RuntimeError (err )
379+
380+ # for mock scheduler
381+ if "scale" not in dir (self ._scheduler ):
382+ destroy_threads = [Thread (target = c .destroy ) for c in to_destroy ]
383+ [t .start () for t in destroy_threads ]
384+ [t .join () for t in destroy_threads ]
385+ [c .delete () for c in to_destroy if c .state == 'destroyed' ]
386+ if any (c .state != 'destroyed' for c in to_destroy ):
387+ err = 'aborting, failed to destroy some containers'
388+ log_event (self , err , logging .ERROR )
389+ raise RuntimeError (err )
390+ else :
391+ [c .delete () for c in to_destroy ]
386392
387393 def deploy (self , user , release ):
388394 """Deploy a new release to this application"""
@@ -418,7 +424,7 @@ def _deploy_app(self, scale_types, release, existing):
418424 'cpu' : release .config .cpu ,
419425 'tags' : release .config .tags ,
420426 'envs' : release .config .values ,
421- 'num' : 0 ,
427+ 'num' : 0 , # Scaling up happens in a separate operation
422428 'version' : version ,
423429 'app_type' : scale_type ,
424430 'build_type' : build_type ,
@@ -458,7 +464,16 @@ def _default_scale(self, user, release):
458464 else :
459465 structure = {'web' : 1 }
460466
461- self .scale (user , structure )
467+ if "scale" in dir (self ._scheduler ):
468+ self ._deploy_app (structure , release , [])
469+ else :
470+ for key , num in structure .items ():
471+ c = Container .objects .create (owner = self .owner ,
472+ app = self ,
473+ release = release ,
474+ type = key ,
475+ num = num )
476+ self ._start_containers ([c ])
462477
463478 def logs (self , log_lines = str (settings .LOG_LINES )):
464479 """Return aggregated log data for this application."""
0 commit comments