func (s *StateStore) updateDeploymentStatusImpl(index uint64, u *structs.DeploymentStatusUpdate, txn *memdb.Txn) error {
	// Retrieve deployment
	ws := memdb.NewWatchSet()
	deployment, err := s.deploymentByIDImpl(ws, u.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", u.DeploymentID)
	} else if !deployment.Active() {
		return fmt.Errorf("Deployment %q has terminal status %q:", deployment.ID, deployment.Status)
	}

	// Apply the new status
	copy := deployment.Copy()
	copy.Status = u.Status
	copy.StatusDescription = u.StatusDescription
	copy.ModifyIndex = index

	// Insert the deployment
	if err := txn.Insert("deployment", copy); err != nil {
		return err
	}

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

	// If the deployment is being marked as complete, set the job to stable.
	if copy.Status == structs.DeploymentStatusSuccessful {
		if err := s.updateJobStabilityImpl(index, copy.JobID, copy.JobVersion, true, txn); err != nil {
			return fmt.Errorf("failed to update job stability: %v", err)
		}
	}

	return nil
}
// updateDeploymentStatusImpl is used to make deployment status updates
updateDeploymentStatusImpl is used to make deployment status updates
// updateDeploymentStatusImpl is used to make deployment status updates
func (s *StateStore) updateDeploymentStatusImpl(index uint64, u *structs.DeploymentStatusUpdate, txn *memdb.Txn) error {
	ws := memdb.NewWatchSet()
	deployment, err := s.deploymentByIDImpl(ws, u.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", u.DeploymentID)
	} else if !deployment.Active() {
		return fmt.Errorf("Deployment %q has terminal status %q:", deployment.ID, deployment.Status)
	}
	copy := deployment.Copy()
	copy.Status = u.Status
	copy.StatusDescription = u.StatusDescription
	copy.ModifyIndex = index
	if err := txn.Insert("deployment", copy); err != nil {
		return err
	}
	if err := txn.Insert("index", &IndexEntry{"deployment", index}); err != nil {
		return fmt.Errorf("index update failed: %v", err)
	}
	if copy.Status == structs.DeploymentStatusSuccessful {
		if err := s.updateJobStabilityImpl(index, copy.JobID, copy.JobVersion, true, txn); err != nil {
			return fmt.Errorf("failed to update job stability: %v", err)
		}
	}
	return nil
}
func ( s * StateStore ) updateDeploymentStatusImpl ( index uint64 , u * structs . DeploymentStatusUpdate , txn * memdb . Txn ) error { ws := memdb . NewWatchSet ( ) deployment , err := s . deploymentByIDImpl ( ws , u . DeploymentID , txn ) if err != nil { return err } else if deployment == nil { return fmt . Errorf ( " " , u . DeploymentID ) } else if ! deployment . Active ( ) { return fmt . Errorf ( " " , deployment . ID , deployment . Status ) } copy := deployment . Copy ( ) copy . Status = u . Status copy . StatusDescription = u . StatusDescription copy . ModifyIndex = index if err := txn . Insert ( " " , copy ) ; err != nil { return err } if err := txn . Insert ( " " , & IndexEntry { " " , index } ) ; err != nil { return fmt . Errorf ( " " , err ) } if copy . Status == structs . DeploymentStatusSuccessful { if err := s . updateJobStabilityImpl ( index , copy . JobID , copy . JobVersion , true , txn ) ; err != nil { return fmt . Errorf ( " " , err ) } } return nil }
updateDeploymentStatusImpl is used to make deployment status updates
updateDeploymentStatusImpl is used to make deployment status updates
// Retrieve deployment // Apply the new status // Insert the deployment // Update the index // If the deployment is being marked as complete, set the job to stable.