github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7pushaction/sequence.go (about)

     1  package v7pushaction
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     5  )
     6  
     7  func ShouldCreateBitsPackage(plan PushPlan) bool {
     8  	return plan.DropletPath == "" && plan.DockerImageCredentials.Path == ""
     9  }
    10  
    11  func ShouldCreateDockerPackage(plan PushPlan) bool {
    12  	return plan.DropletPath == "" && plan.DockerImageCredentials.Path != ""
    13  }
    14  
    15  func ShouldCreateDroplet(plan PushPlan) bool {
    16  	return plan.DropletPath != ""
    17  }
    18  
    19  func ShouldStagePackage(plan PushPlan) bool {
    20  	return !plan.NoStart && plan.DropletPath == ""
    21  }
    22  
    23  func ShouldCreateDeployment(plan PushPlan) bool {
    24  	return plan.Strategy == constant.DeploymentStrategyRolling
    25  }
    26  
    27  func ShouldStopApplication(plan PushPlan) bool {
    28  	return plan.NoStart && plan.Application.State == constant.ApplicationStarted
    29  }
    30  
    31  func ShouldSetDroplet(plan PushPlan) bool {
    32  	return !plan.NoStart || plan.DropletPath != ""
    33  }
    34  
    35  func ShouldRestart(plan PushPlan) bool {
    36  	return !plan.NoStart
    37  }
    38  
    39  func (actor Actor) GetPrepareApplicationSourceSequence(plan PushPlan) []ChangeApplicationFunc {
    40  	var prepareSourceSequence []ChangeApplicationFunc
    41  	switch {
    42  	case ShouldCreateBitsPackage(plan):
    43  		prepareSourceSequence = append(prepareSourceSequence, actor.CreateBitsPackageForApplication)
    44  	case ShouldCreateDockerPackage(plan):
    45  		prepareSourceSequence = append(prepareSourceSequence, actor.CreateDockerPackageForApplication)
    46  	case ShouldCreateDroplet(plan):
    47  		prepareSourceSequence = append(prepareSourceSequence, actor.CreateDropletForApplication)
    48  	}
    49  	return prepareSourceSequence
    50  }
    51  
    52  func (actor Actor) GetRuntimeSequence(plan PushPlan) []ChangeApplicationFunc {
    53  
    54  	if plan.TaskTypeApplication {
    55  		return actor.getTaskAppRuntimeSequence(plan)
    56  	} else {
    57  		return actor.getDefaultRuntimeSequence(plan)
    58  	}
    59  }
    60  
    61  func (actor Actor) getDefaultRuntimeSequence(plan PushPlan) []ChangeApplicationFunc {
    62  	var runtimeSequence []ChangeApplicationFunc
    63  
    64  	if ShouldStagePackage(plan) {
    65  		runtimeSequence = append(runtimeSequence, actor.StagePackageForApplication)
    66  	}
    67  
    68  	if ShouldCreateDeployment(plan) {
    69  		runtimeSequence = append(runtimeSequence, actor.CreateDeploymentForApplication)
    70  	} else {
    71  		if ShouldStopApplication(plan) {
    72  			runtimeSequence = append(runtimeSequence, actor.StopApplication)
    73  		}
    74  
    75  		if ShouldSetDroplet(plan) {
    76  			runtimeSequence = append(runtimeSequence, actor.SetDropletForApplication)
    77  		}
    78  
    79  		if ShouldRestart(plan) {
    80  			runtimeSequence = append(runtimeSequence, actor.RestartApplication)
    81  		}
    82  	}
    83  
    84  	return runtimeSequence
    85  }
    86  
    87  func (actor Actor) getTaskAppRuntimeSequence(plan PushPlan) []ChangeApplicationFunc {
    88  	var runtimeSequence []ChangeApplicationFunc
    89  
    90  	runtimeSequence = append(runtimeSequence, actor.StagePackageForApplication)
    91  	runtimeSequence = append(runtimeSequence, actor.StopApplication)
    92  	runtimeSequence = append(runtimeSequence, actor.SetDropletForApplication)
    93  
    94  	return runtimeSequence
    95  }