@@ -293,7 +293,8 @@ def _run_scale_settings(ctx, scale_settings, scalable_entity_properties,
293293 ignore_failure = False ,
294294 ignore_rollback_failure = True ,
295295 instances_remove_ids = None ,
296- node_sequence = None ):
296+ node_sequence = None ,
297+ rollback_on_failure = True ):
297298 modification = ctx .deployment .start_modification (scale_settings )
298299 ctx .refresh_node_instances ()
299300 graph = ctx .graph_mode ()
@@ -355,15 +356,21 @@ def _run_scale_settings(ctx, scale_settings, scalable_entity_properties,
355356 node_instances = added ,
356357 related_nodes = related )
357358 except Exception as ex :
358- ctx .logger .error ('Scale out failed, scaling back in. {}'
359- .format (repr (ex )))
360- _wait_for_sent_tasks (ctx , graph )
361- _uninstall_instances (ctx = ctx ,
362- graph = graph ,
363- removed = added ,
364- related = related ,
365- ignore_failure = ignore_rollback_failure ,
366- node_sequence = node_sequence )
359+ if rollback_on_failure :
360+ ctx .logger .error ('Scale out failed, scaling back in. {}'
361+ .format (repr (ex )))
362+ _wait_for_sent_tasks (ctx , graph )
363+ _uninstall_instances (
364+ ctx = ctx ,
365+ graph = graph ,
366+ removed = added ,
367+ related = related ,
368+ ignore_failure = ignore_rollback_failure ,
369+ node_sequence = node_sequence )
370+ else :
371+ ctx .logger .warn ('Scale out failed, but '
372+ 'rollback_on_failure is disabled. {}'
373+ .format (repr (ex )))
367374 raise ex
368375
369376 if len (set (modification .removed .node_instances )):
@@ -394,11 +401,14 @@ def _run_scale_settings(ctx, scale_settings, scalable_entity_properties,
394401 related = related ,
395402 node_sequence = node_sequence )
396403 except Exception as ex :
397- ctx .logger .warn ('Rolling back deployment modification. '
398- '[modification_id={0}]: {1}'
399- .format (modification .id , repr (ex )))
400- _wait_for_sent_tasks (ctx , graph )
401- modification .rollback ()
404+ if rollback_on_failure :
405+ ctx .logger .warn ('Rolling back deployment modification. '
406+ '[modification_id={0}]: {1}'
407+ .format (modification .id , repr (ex )))
408+ _wait_for_sent_tasks (ctx , graph )
409+ modification .rollback ()
410+ else :
411+ modification .finish ()
402412 raise ex
403413 modification .finish ()
404414
@@ -421,13 +431,12 @@ def _wait_for_sent_tasks(ctx, graph):
421431 cancelled = graph ._is_execution_cancelled ()
422432 if cancelled :
423433 raise api .ExecutionCancelled ()
424- try :
425- finished_tasks = graph ._finished_tasks ()
426- except AttributeError :
427- finished_tasks = graph ._terminated_tasks ()
428- for task in finished_tasks :
434+
435+ finished_tasks = graph ._finished_tasks
436+ while finished_tasks :
437+ task , result = finished_tasks .popitem ()
429438 try :
430- graph ._handle_terminated_task (task )
439+ graph ._handle_terminated_task (result , task )
431440 except RuntimeError :
432441 ctx .logger .error ('Unhandled Failed task: {0}' .format (task ))
433442 if not any (task .get_state () == tasks .TASK_SENT
@@ -488,6 +497,8 @@ def scaledownlist(ctx, scale_compute=False,
488497 scale_node_field_value = u'' ,
489498 all_results = False ,
490499 node_sequence = None ,
500+ force_remove = True ,
501+ rollback_on_failure = True ,
491502 ** _ ):
492503 if not scale_node_field :
493504 raise ValueError ('You should provide `scale_node_field` for correct'
@@ -529,22 +540,25 @@ def scaledownlist(ctx, scale_compute=False,
529540 _run_scale_settings (ctx , scale_settings , {},
530541 instances_remove_ids = instance_ids ,
531542 ignore_failure = ignore_failure ,
532- node_sequence = node_sequence )
543+ node_sequence = node_sequence ,
544+ rollback_on_failure = rollback_on_failure )
533545 except Exception as e :
534546 ctx .logger .info ('Scale down based on transaction failed: {}'
535547 .format (repr (e )))
536- # check list for forced remove
537- removed = []
538- for node in ctx .nodes :
539- for instance in node .instances :
540- if instance .id in instance_ids :
541- removed .append (instance )
542- _uninstall_instances (ctx = ctx ,
543- graph = ctx .graph_mode (),
544- removed = removed ,
545- related = [],
546- ignore_failure = ignore_failure ,
547- node_sequence = node_sequence )
548+
549+ if force_remove :
550+ # check list for forced remove
551+ removed = []
552+ for node in ctx .nodes :
553+ for instance in node .instances :
554+ if instance .id in instance_ids :
555+ removed .append (instance )
556+ _uninstall_instances (ctx = ctx ,
557+ graph = ctx .graph_mode (),
558+ removed = removed ,
559+ related = [],
560+ ignore_failure = ignore_failure ,
561+ node_sequence = node_sequence )
548562
549563 # remove from DB
550564 if force_db_cleanup :
@@ -598,6 +612,7 @@ def scaleuplist(ctx, scalable_entity_properties,
598612 scale_transaction_field = "" ,
599613 scale_transaction_value = "" ,
600614 node_sequence = None ,
615+ rollback_on_failure = True ,
601616 ** kwargs ):
602617
603618 if not scalable_entity_properties :
@@ -612,7 +627,8 @@ def scaleuplist(ctx, scalable_entity_properties,
612627 _run_scale_settings (ctx , scale_settings , scalable_entity_properties ,
613628 scale_transaction_field , scale_transaction_value ,
614629 ignore_failure , ignore_rollback_failure ,
615- node_sequence = node_sequence )
630+ node_sequence = node_sequence ,
631+ rollback_on_failure = rollback_on_failure )
616632
617633
618634def _filter_node_instances (ctx , node_ids , node_instance_ids , type_names ,
0 commit comments