func (s *StateStore) UpsertPlanResults(index uint64, results *structs.ApplyPlanResultsRequest) error {
	txn := s.db.Txn(true)
	defer txn.Abort()

	// Upsert the newly created or updated deployment
	if results.Deployment != nil {
		if err := s.upsertDeploymentImpl(index, results.Deployment, txn); err != nil {
			return err
		}
	}

	// Update the status of deployments effected by the plan.
	if len(results.DeploymentUpdates) != 0 {
		s.upsertDeploymentUpdates(index, results.DeploymentUpdates, txn)
	}

	// Attach the job to all the allocations. It is pulled out in the payload to
	// avoid the redundancy of encoding, but should be denormalized prior to
	// being inserted into MemDB.
	structs.DenormalizeAllocationJobs(results.Job, results.Alloc)

	// Calculate the total resources of allocations. It is pulled out in the
	// payload to avoid encoding something that can be computed, but should be
	// denormalized prior to being inserted into MemDB.
	for _, alloc := range results.Alloc {
		if alloc.Resources != nil {
			continue
		}

		alloc.Resources = new(structs.Resources)
		for _, task := range alloc.TaskResources {
			alloc.Resources.Add(task)
		}

		// Add the shared resources
		alloc.Resources.Add(alloc.SharedResources)
	}

	// Upsert the allocations
	if err := s.upsertAllocsImpl(index, results.Alloc, txn); err != nil {
		return err
	}

	txn.Commit()
	return nil
}
// UpsertPlanResults is used to upsert the results of a plan.
UpsertPlanResults is used to upsert the results of a plan.
// UpsertPlanResults is used to upsert the results of a plan .
func (s *StateStore) UpsertPlanResults(index uint64, results *structs.ApplyPlanResultsRequest) error {
	txn := s.db.Txn(true)
	defer txn.Abort()
	if results.Deployment != nil {
		if err := s.upsertDeploymentImpl(index, results.Deployment, txn); err != nil {
			return err
		}
	}
	if len(results.DeploymentUpdates) != 0 {
		s.upsertDeploymentUpdates(index, results.DeploymentUpdates, txn)
	}
	structs.DenormalizeAllocationJobs(results.Job, results.Alloc)
	for _, alloc := range results.Alloc {
		if alloc.Resources != nil {
			continue
		}
		alloc.Resources = new(structs.Resources)
		for _, task := range alloc.TaskResources {
			alloc.Resources.Add(task)
		}
		alloc.Resources.Add(alloc.SharedResources)
	}
	if err := s.upsertAllocsImpl(index, results.Alloc, txn); err != nil {
		return err
	}
	txn.Commit()
	return nil
}
func ( s * StateStore ) UpsertPlanResults ( index uint64 , results * structs . ApplyPlanResultsRequest ) error { txn := s . db . Txn ( true ) defer txn . Abort ( ) if results . Deployment != nil { if err := s . upsertDeploymentImpl ( index , results . Deployment , txn ) ; err != nil { return err } } if len ( results . DeploymentUpdates ) != 0 { s . upsertDeploymentUpdates ( index , results . DeploymentUpdates , txn ) } structs . DenormalizeAllocationJobs ( results . Job , results . Alloc ) for _ , alloc := range results . Alloc { if alloc . Resources != nil { continue } alloc . Resources = new ( structs . Resources ) for _ , task := range alloc . TaskResources { alloc . Resources . Add ( task ) } alloc . Resources . Add ( alloc . SharedResources ) } if err := s . upsertAllocsImpl ( index , results . Alloc , txn ) ; err != nil { return err } txn . Commit ( ) return nil }
UpsertPlanResults is used to upsert the results of a plan.
UpsertPlanResults is used to upsert the results of a plan .
// Upsert the newly created or updated deployment // Update the status of deployments effected by the plan. // Attach the job to all the allocations. It is pulled out in the payload to // avoid the redundancy of encoding, but should be denormalized prior to // being inserted into MemDB. // Calculate the total resources of allocations. It is pulled out in the // payload to avoid encoding something that can be computed, but should be // denormalized prior to being inserted into MemDB. // Add the shared resources // Upsert the allocations