func (s *StateStore) UpdateDeploymentAllocHealth(index uint64, req *structs.ApplyDeploymentAllocHealthRequest) error {
	txn := s.db.Txn(true)
	defer txn.Abort()

	// Retrieve deployment and ensure it is not terminal and is active
	ws := memdb.NewWatchSet()
	deployment, err := s.deploymentByIDImpl(ws, req.DeploymentID, txn)
	if err != nil {
		return err
	} else if deployment == nil {
		return fmt.Errorf("Deployment ID %q couldn't be updated as it does not exist", req.DeploymentID)
	} else if !deployment.Active() {
		return fmt.Errorf("Deployment %q has terminal status %q:", deployment.ID, deployment.Status)
	}

	// Update the health status of each allocation
	if total := len(req.HealthyAllocationIDs) + len(req.UnhealthyAllocationIDs); total != 0 {
		setAllocHealth := func(id string, healthy bool) error {
			existing, err := txn.First("allocs", "id", id)
			if err != nil {
				return fmt.Errorf("alloc %q lookup failed: %v", id, err)
			}
			if existing == nil {
				return fmt.Errorf("unknown alloc %q", id)
			}

			old := existing.(*structs.Allocation)
			if old.DeploymentID != req.DeploymentID {
				return fmt.Errorf("alloc %q is not part of deployment %q", id, req.DeploymentID)
			}

			// Set the health
			copy := old.Copy()
			if copy.DeploymentStatus == nil {
				copy.DeploymentStatus = &structs.AllocDeploymentStatus{}
			}
			copy.DeploymentStatus.Healthy = helper.BoolToPtr(healthy)
			copy.DeploymentStatus.ModifyIndex = index

			if err := s.updateDeploymentWithAlloc(index, copy, old, txn); err != nil {
				return fmt.Errorf("error updating deployment: %v", err)
			}

			if err := txn.Insert("allocs", copy); err != nil {
				return fmt.Errorf("alloc insert failed: %v", err)
			}

			return nil
		}

		for _, id := range req.HealthyAllocationIDs {
			if err := setAllocHealth(id, true); err != nil {
				return err
			}
		}
		for _, id := range req.UnhealthyAllocationIDs {
			if err := setAllocHealth(id, false); err != nil {
				return err
			}
		}

		// Update the indexes
		if err := txn.Insert("index", &IndexEntry{"allocs", index}); err != nil {
			return fmt.Errorf("index update failed: %v", err)
		}
	}

	// Update the deployment status as needed.
	if req.DeploymentUpdate != nil {
		if err := s.updateDeploymentStatusImpl(index, req.DeploymentUpdate, txn); err != nil {
			return err
		}
	}

	// Upsert the job if necessary
	if req.Job != nil {
		if err := s.upsertJobImpl(index, req.Job, false, txn); err != nil {
			return err
		}
	}

	// Upsert the optional eval
	if req.Eval != nil {
		if err := s.nestedUpsertEval(txn, index, req.Eval); err != nil {
			return err
		}
	}

	txn.Commit()
	return nil
}
// UpdateDeploymentAllocHealth is used to update the health of allocations as
// part of the deployment and potentially make a evaluation
UpdateDeploymentAllocHealth is used to update the health of allocations as
part of the deployment and potentially make a evaluation
// UpdateDeploymentAllocHealth is used to update the health of allocations as // part of the deployment and potentially make a evaluation
func (s *StateStore) UpdateDeploymentAllocHealth(index uint64, req *structs.ApplyDeploymentAllocHealthRequest) error {
	txn := s.db.Txn(true)
	defer txn.Abort()
	ws := memdb.NewWatchSet()
	deployment, err := s.deploymentByIDImpl(ws, req.DeploymentID, txn)
	if err != nil {
		return err
	} else if deployment == nil {
		return fmt.Errorf("Deployment ID %q couldn't be updated as it does not exist", req.DeploymentID)
	} else if !deployment.Active() {
		return fmt.Errorf("Deployment %q has terminal status %q:", deployment.ID, deployment.Status)
	}
	if total := len(req.HealthyAllocationIDs) + len(req.UnhealthyAllocationIDs); total != 0 {
		setAllocHealth := func(id string, healthy bool) error {
			existing, err := txn.First("allocs", "id", id)
			if err != nil {
				return fmt.Errorf("alloc %q lookup failed: %v", id, err)
			}
			if existing == nil {
				return fmt.Errorf("unknown alloc %q", id)
			}
			old := existing.(*structs.Allocation)
			if old.DeploymentID != req.DeploymentID {
				return fmt.Errorf("alloc %q is not part of deployment %q", id, req.DeploymentID)
			}
			copy := old.Copy()
			if copy.DeploymentStatus == nil {
				copy.DeploymentStatus = &structs.AllocDeploymentStatus{}
			}
			copy.DeploymentStatus.Healthy = helper.BoolToPtr(healthy)
			copy.DeploymentStatus.ModifyIndex = index
			if err := s.updateDeploymentWithAlloc(index, copy, old, txn); err != nil {
				return fmt.Errorf("error updating deployment: %v", err)
			}
			if err := txn.Insert("allocs", copy); err != nil {
				return fmt.Errorf("alloc insert failed: %v", err)
			}
			return nil
		}
		for _, id := range req.HealthyAllocationIDs {
			if err := setAllocHealth(id, true); err != nil {
				return err
			}
		}
		for _, id := range req.UnhealthyAllocationIDs {
			if err := setAllocHealth(id, false); err != nil {
				return err
			}
		}
		if err := txn.Insert("index", &IndexEntry{"allocs", index}); err != nil {
			return fmt.Errorf("index update failed: %v", err)
		}
	}
	if req.DeploymentUpdate != nil {
		if err := s.updateDeploymentStatusImpl(index, req.DeploymentUpdate, txn); err != nil {
			return err
		}
	}
	if req.Job != nil {
		if err := s.upsertJobImpl(index, req.Job, false, txn); err != nil {
			return err
		}
	}
	if req.Eval != nil {
		if err := s.nestedUpsertEval(txn, index, req.Eval); err != nil {
			return err
		}
	}
	txn.Commit()
	return nil
}
func ( s * StateStore ) UpdateDeploymentAllocHealth ( index uint64 , req * structs . ApplyDeploymentAllocHealthRequest ) error { txn := s . db . Txn ( true ) defer txn . Abort ( ) ws := memdb . NewWatchSet ( ) deployment , err := s . deploymentByIDImpl ( ws , req . DeploymentID , txn ) if err != nil { return err } else if deployment == nil { return fmt . Errorf ( " " , req . DeploymentID ) } else if ! deployment . Active ( ) { return fmt . Errorf ( " " , deployment . ID , deployment . Status ) } if total := len ( req . HealthyAllocationIDs ) + len ( req . UnhealthyAllocationIDs ) ; total != 0 { setAllocHealth := func ( id string , healthy bool ) error { existing , err := txn . First ( " " , " " , id ) if err != nil { return fmt . Errorf ( " " , id , err ) } if existing == nil { return fmt . Errorf ( " " , id ) } old := existing . ( * structs . Allocation ) if old . DeploymentID != req . DeploymentID { return fmt . Errorf ( " " , id , req . DeploymentID ) } copy := old . Copy ( ) if copy . DeploymentStatus == nil { copy . DeploymentStatus = & structs . AllocDeploymentStatus { } } copy . DeploymentStatus . Healthy = helper . BoolToPtr ( healthy ) copy . DeploymentStatus . ModifyIndex = index if err := s . updateDeploymentWithAlloc ( index , copy , old , txn ) ; err != nil { return fmt . Errorf ( " " , err ) } if err := txn . Insert ( " " , copy ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil } for _ , id := range req . HealthyAllocationIDs { if err := setAllocHealth ( id , true ) ; err != nil { return err } } for _ , id := range req . UnhealthyAllocationIDs { if err := setAllocHealth ( id , false ) ; err != nil { return err } } if err := txn . Insert ( " " , & IndexEntry { " " , index } ) ; err != nil { return fmt . Errorf ( " " , err ) } } if req . DeploymentUpdate != nil { if err := s . updateDeploymentStatusImpl ( index , req . DeploymentUpdate , txn ) ; err != nil { return err } } if req . Job != nil { if err := s . upsertJobImpl ( index , req . Job , false , txn ) ; err != nil { return err } } if req . Eval != nil { if err := s . nestedUpsertEval ( txn , index , req . Eval ) ; err != nil { return err } } txn . Commit ( ) return nil }
UpdateDeploymentAllocHealth is used to update the health of allocations as
part of the deployment and potentially make a evaluation
UpdateDeploymentAllocHealth is used to update the health of allocations as part of the deployment and potentially make a evaluation
// Retrieve deployment and ensure it is not terminal and is active // Update the health status of each allocation // Set the health // Update the indexes // Update the deployment status as needed. // Upsert the job if necessary // Upsert the optional eval