func (s *StateStore) nestedUpdateAllocFromClient(txn *memdb.Txn, index uint64, alloc *structs.Allocation) error {
	// Look for existing alloc
	existing, err := txn.First("allocs", "id", alloc.ID)
	if err != nil {
		return fmt.Errorf("alloc lookup failed: %v", err)
	}

	// Nothing to do if this does not exist
	if existing == nil {
		return nil
	}
	exist := existing.(*structs.Allocation)

	// Copy everything from the existing allocation
	copyAlloc := exist.Copy()

	// Pull in anything the client is the authority on
	copyAlloc.ClientStatus = alloc.ClientStatus
	copyAlloc.ClientDescription = alloc.ClientDescription
	copyAlloc.TaskStates = alloc.TaskStates
	copyAlloc.DeploymentStatus = alloc.DeploymentStatus

	// Update the modify index
	copyAlloc.ModifyIndex = index

	// TODO TEST
	if err := s.updateDeploymentWithAlloc(index, copyAlloc, exist, txn); err != nil {
		return fmt.Errorf("error updating deployment: %v", err)
	}

	if err := s.updateSummaryWithAlloc(index, copyAlloc, exist, txn); err != nil {
		return fmt.Errorf("error updating job summary: %v", err)
	}

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

	// Set the job's status
	forceStatus := ""
	if !copyAlloc.TerminalStatus() {
		forceStatus = structs.JobStatusRunning
	}
	jobs := map[string]string{exist.JobID: forceStatus}
	if err := s.setJobStatuses(index, txn, jobs, false); err != nil {
		return fmt.Errorf("setting job status failed: %v", err)
	}
	return nil
}
// nestedUpdateAllocFromClient is used to nest an update of an allocation with client status
nestedUpdateAllocFromClient is used to nest an update of an allocation with client status
// nestedUpdateAllocFromClient is used to nest an update of an allocation with client status
func (s *StateStore) nestedUpdateAllocFromClient(txn *memdb.Txn, index uint64, alloc *structs.Allocation) error {
	existing, err := txn.First("allocs", "id", alloc.ID)
	if err != nil {
		return fmt.Errorf("alloc lookup failed: %v", err)
	}
	if existing == nil {
		return nil
	}
	exist := existing.(*structs.Allocation)
	copyAlloc := exist.Copy()
	copyAlloc.ClientStatus = alloc.ClientStatus
	copyAlloc.ClientDescription = alloc.ClientDescription
	copyAlloc.TaskStates = alloc.TaskStates
	copyAlloc.DeploymentStatus = alloc.DeploymentStatus
	copyAlloc.ModifyIndex = index
	if err := s.updateDeploymentWithAlloc(index, copyAlloc, exist, txn); err != nil {
		return fmt.Errorf("error updating deployment: %v", err)
	}
	if err := s.updateSummaryWithAlloc(index, copyAlloc, exist, txn); err != nil {
		return fmt.Errorf("error updating job summary: %v", err)
	}
	if err := txn.Insert("allocs", copyAlloc); err != nil {
		return fmt.Errorf("alloc insert failed: %v", err)
	}
	forceStatus := ""
	if !copyAlloc.TerminalStatus() {
		forceStatus = structs.JobStatusRunning
	}
	jobs := map[string]string{exist.JobID: forceStatus}
	if err := s.setJobStatuses(index, txn, jobs, false); err != nil {
		return fmt.Errorf("setting job status failed: %v", err)
	}
	return nil
}
func ( s * StateStore ) nestedUpdateAllocFromClient ( txn * memdb . Txn , index uint64 , alloc * structs . Allocation ) error { existing , err := txn . First ( " " , " " , alloc . ID ) if err != nil { return fmt . Errorf ( " " , err ) } if existing == nil { return nil } exist := existing . ( * structs . Allocation ) copyAlloc := exist . Copy ( ) copyAlloc . ClientStatus = alloc . ClientStatus copyAlloc . ClientDescription = alloc . ClientDescription copyAlloc . TaskStates = alloc . TaskStates copyAlloc . DeploymentStatus = alloc . DeploymentStatus copyAlloc . ModifyIndex = index if err := s . updateDeploymentWithAlloc ( index , copyAlloc , exist , txn ) ; err != nil { return fmt . Errorf ( " " , err ) } if err := s . updateSummaryWithAlloc ( index , copyAlloc , exist , txn ) ; err != nil { return fmt . Errorf ( " " , err ) } if err := txn . Insert ( " " , copyAlloc ) ; err != nil { return fmt . Errorf ( " " , err ) } forceStatus := " " if ! copyAlloc . TerminalStatus ( ) { forceStatus = structs . JobStatusRunning } jobs := map [ string ] string { exist . JobID : forceStatus } if err := s . setJobStatuses ( index , txn , jobs , false ) ; err != nil { return fmt . Errorf ( " " , err ) } return nil }
nestedUpdateAllocFromClient is used to nest an update of an allocation with client status
nestedUpdateAllocFromClient is used to nest an update of an allocation with client status
// Look for existing alloc // Nothing to do if this does not exist // Copy everything from the existing allocation // Pull in anything the client is the authority on // Update the modify index // TODO TEST // Update the allocation // Set the job's status