Use a detected struct to hold deployment status for an allocation

This commit is contained in:
Alex Dadgar 2017-05-11 11:03:15 -07:00
parent 71788faacd
commit 9a576bafd1
2 changed files with 34 additions and 8 deletions

View file

@ -2199,17 +2199,19 @@ func (s *StateStore) updateDeploymentWithAlloc(index uint64, alloc, existing *st
// If there was no existing allocation, this is a placement and we increment
// the placement
existingHealthSet := existing.DeploymentStatus != nil && existing.DeploymentStatus.Healthy != nil
allocHealthSet := alloc.DeploymentStatus != nil && alloc.DeploymentStatus.Healthy != nil
if existing == nil {
placed++
} else if existing.DeploymentHealth == nil && alloc.DeploymentHealth != nil {
if *alloc.DeploymentHealth {
} else if !existingHealthSet && allocHealthSet {
if *alloc.DeploymentStatus.Healthy {
healthy++
} else {
unhealthy++
}
} else if existing.DeploymentHealth != nil && alloc.DeploymentHealth != nil {
} else if existingHealthSet && allocHealthSet {
// See if it has gone from healthy to unhealthy
if *existing.DeploymentHealth && !*alloc.DeploymentHealth {
if *existing.DeploymentStatus.Healthy && !*alloc.DeploymentStatus.Healthy {
healthy--
unhealthy++
}

View file

@ -3642,10 +3642,9 @@ type Allocation struct {
// particular deployment
DeploymentID string
// DeploymentHealth marks whether the allocation has been marked healthy or
// unhealthy as part of a deployment. It can be unset if it has neither been
// marked healthy or unhealthy.
DeploymentHealth *bool
// DeploymentStatus captures the status of the allocation as part of the
// given deployment
DeploymentStatus *AllocDeploymentStatus
// Canary marks this allocation as being a canary
Canary bool
@ -3683,6 +3682,7 @@ func (a *Allocation) Copy() *Allocation {
}
na.Metrics = na.Metrics.Copy()
na.DeploymentStatus = na.DeploymentStatus.Copy()
if a.TaskStates != nil {
ts := make(map[string]*TaskState, len(na.TaskStates))
@ -3925,6 +3925,30 @@ func (a *AllocMetric) ScoreNode(node *Node, name string, score float64) {
a.Scores[key] = score
}
// AllocDeploymentStatus captures the status of the allocation as part of the
// deployment. This can include things like if the allocation has been marked as
// heatlhy.
type AllocDeploymentStatus struct {
// Healthy marks whether the allocation has been marked healthy or unhealthy
// as part of a deployment. It can be unset if it has neither been marked
// healthy or unhealthy.
Healthy *bool
}
func (a *AllocDeploymentStatus) Copy() *AllocDeploymentStatus {
if a == nil {
return nil
}
c := new(AllocDeploymentStatus)
if a.Healthy != nil {
c.Healthy = helper.BoolToPtr(*a.Healthy)
}
return c
}
const (
EvalStatusBlocked = "blocked"
EvalStatusPending = "pending"