github.com/anuvu/nomad@v0.8.7-atom1/command/agent/consul/structs.go (about)

     1  package consul
     2  
     3  import (
     4  	"github.com/hashicorp/nomad/client/driver"
     5  	cstructs "github.com/hashicorp/nomad/client/structs"
     6  	"github.com/hashicorp/nomad/nomad/structs"
     7  )
     8  
     9  type TaskServices struct {
    10  	AllocID string
    11  	// Index of the task
    12  	AllocIndex int
    13  	// Name of the task
    14  	Name string
    15  
    16  	// Canary indicates whether or not the allocation is a canary
    17  	Canary bool
    18  
    19  	// Restarter allows restarting the task depending on the task's
    20  	// check_restart stanzas.
    21  	Restarter TaskRestarter
    22  
    23  	// Services and checks to register for the task.
    24  	Services []*structs.Service
    25  
    26  	// Networks from the task's resources stanza.
    27  	Networks structs.Networks
    28  
    29  	// DriverExec is the script executor for the task's driver.
    30  	DriverExec driver.ScriptExecutor
    31  
    32  	// DriverNetwork is the network specified by the driver and may be nil.
    33  	DriverNetwork *cstructs.DriverNetwork
    34  }
    35  
    36  func NewTaskServices(alloc *structs.Allocation, task *structs.Task, restarter TaskRestarter, exec driver.ScriptExecutor, net *cstructs.DriverNetwork) *TaskServices {
    37  	ts := TaskServices{
    38  		AllocID:       alloc.ID,
    39  		AllocIndex:    int(alloc.Index()),
    40  		Name:          task.Name,
    41  		Restarter:     restarter,
    42  		Services:      task.Services,
    43  		DriverExec:    exec,
    44  		DriverNetwork: net,
    45  	}
    46  
    47  	if task.Resources != nil {
    48  		ts.Networks = task.Resources.Networks
    49  	}
    50  
    51  	if alloc.DeploymentStatus != nil && alloc.DeploymentStatus.Canary {
    52  		ts.Canary = true
    53  	}
    54  
    55  	return &ts
    56  }
    57  
    58  // Copy method for easing tests
    59  func (t *TaskServices) Copy() *TaskServices {
    60  	newTS := new(TaskServices)
    61  	*newTS = *t
    62  
    63  	// Deep copy Services
    64  	newTS.Services = make([]*structs.Service, len(t.Services))
    65  	for i := range t.Services {
    66  		newTS.Services[i] = t.Services[i].Copy()
    67  	}
    68  	return newTS
    69  }