host

package
v0.0.0-...-366f0b0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxLCTInterval = 5 * time.Minute

	// Potential init systems supported by a Linux host.
	InitSystemSystemd = "systemd"
	InitSystemSysV    = "sysv"
	InitSystemUpstart = "upstart"
)
View Source
const (
	// Collection is the name of the MongoDB collection that stores hosts.
	Collection = "hosts"
)

Variables

View Source
var (
	IdKey                        = bsonutil.MustHaveTag(Host{}, "Id")
	DNSKey                       = bsonutil.MustHaveTag(Host{}, "Host")
	SecretKey                    = bsonutil.MustHaveTag(Host{}, "Secret")
	UserKey                      = bsonutil.MustHaveTag(Host{}, "User")
	TagKey                       = bsonutil.MustHaveTag(Host{}, "Tag")
	DistroKey                    = bsonutil.MustHaveTag(Host{}, "Distro")
	ProviderKey                  = bsonutil.MustHaveTag(Host{}, "Provider")
	IPKey                        = bsonutil.MustHaveTag(Host{}, "IP")
	ProvisionedKey               = bsonutil.MustHaveTag(Host{}, "Provisioned")
	ProvisionTimeKey             = bsonutil.MustHaveTag(Host{}, "ProvisionTime")
	ExtIdKey                     = bsonutil.MustHaveTag(Host{}, "ExternalIdentifier")
	RunningTaskKey               = bsonutil.MustHaveTag(Host{}, "RunningTask")
	RunningTaskGroupKey          = bsonutil.MustHaveTag(Host{}, "RunningTaskGroup")
	RunningTaskBuildVariantKey   = bsonutil.MustHaveTag(Host{}, "RunningTaskBuildVariant")
	RunningTaskVersionKey        = bsonutil.MustHaveTag(Host{}, "RunningTaskVersion")
	RunningTaskProjectKey        = bsonutil.MustHaveTag(Host{}, "RunningTaskProject")
	TaskDispatchTimeKey          = bsonutil.MustHaveTag(Host{}, "TaskDispatchTime")
	CreateTimeKey                = bsonutil.MustHaveTag(Host{}, "CreationTime")
	ExpirationTimeKey            = bsonutil.MustHaveTag(Host{}, "ExpirationTime")
	TerminationTimeKey           = bsonutil.MustHaveTag(Host{}, "TerminationTime")
	LTCTimeKey                   = bsonutil.MustHaveTag(Host{}, "LastTaskCompletedTime")
	LTCTaskKey                   = bsonutil.MustHaveTag(Host{}, "LastTask")
	LTCGroupKey                  = bsonutil.MustHaveTag(Host{}, "LastGroup")
	LTCBVKey                     = bsonutil.MustHaveTag(Host{}, "LastBuildVariant")
	LTCVersionKey                = bsonutil.MustHaveTag(Host{}, "LastVersion")
	LTCProjectKey                = bsonutil.MustHaveTag(Host{}, "LastProject")
	StatusKey                    = bsonutil.MustHaveTag(Host{}, "Status")
	AgentRevisionKey             = bsonutil.MustHaveTag(Host{}, "AgentRevision")
	NeedsNewAgentKey             = bsonutil.MustHaveTag(Host{}, "NeedsNewAgent")
	NeedsNewAgentMonitorKey      = bsonutil.MustHaveTag(Host{}, "NeedsNewAgentMonitor")
	JasperCredentialsIDKey       = bsonutil.MustHaveTag(Host{}, "JasperCredentialsID")
	StartedByKey                 = bsonutil.MustHaveTag(Host{}, "StartedBy")
	InstanceTypeKey              = bsonutil.MustHaveTag(Host{}, "InstanceType")
	VolumeSizeKey                = bsonutil.MustHaveTag(Host{}, "VolumeTotalSize")
	NotificationsKey             = bsonutil.MustHaveTag(Host{}, "Notifications")
	LastCommunicationTimeKey     = bsonutil.MustHaveTag(Host{}, "LastCommunicationTime")
	UserHostKey                  = bsonutil.MustHaveTag(Host{}, "UserHost")
	ZoneKey                      = bsonutil.MustHaveTag(Host{}, "Zone")
	ProjectKey                   = bsonutil.MustHaveTag(Host{}, "Project")
	ProvisionOptionsKey          = bsonutil.MustHaveTag(Host{}, "ProvisionOptions")
	ProvisionAttemptsKey         = bsonutil.MustHaveTag(Host{}, "ProvisionAttempts")
	TaskCountKey                 = bsonutil.MustHaveTag(Host{}, "TaskCount")
	StartTimeKey                 = bsonutil.MustHaveTag(Host{}, "StartTime")
	ComputeCostPerHourKey        = bsonutil.MustHaveTag(Host{}, "ComputeCostPerHour")
	TotalCostKey                 = bsonutil.MustHaveTag(Host{}, "TotalCost")
	TotalIdleTimeKey             = bsonutil.MustHaveTag(Host{}, "TotalIdleTime")
	HasContainersKey             = bsonutil.MustHaveTag(Host{}, "HasContainers")
	ParentIDKey                  = bsonutil.MustHaveTag(Host{}, "ParentID")
	ContainerImagesKey           = bsonutil.MustHaveTag(Host{}, "ContainerImages")
	ContainerBuildAttempt        = bsonutil.MustHaveTag(Host{}, "ContainerBuildAttempt")
	LastContainerFinishTimeKey   = bsonutil.MustHaveTag(Host{}, "LastContainerFinishTime")
	SpawnOptionsKey              = bsonutil.MustHaveTag(Host{}, "SpawnOptions")
	ContainerPoolSettingsKey     = bsonutil.MustHaveTag(Host{}, "ContainerPoolSettings")
	RunningTeardownForTaskKey    = bsonutil.MustHaveTag(Host{}, "RunningTeardownForTask")
	RunningTeardownSinceKey      = bsonutil.MustHaveTag(Host{}, "RunningTeardownSince")
	SpawnOptionsTaskIDKey        = bsonutil.MustHaveTag(SpawnOptions{}, "TaskID")
	SpawnOptionsBuildIDKey       = bsonutil.MustHaveTag(SpawnOptions{}, "BuildID")
	SpawnOptionsTimeoutKey       = bsonutil.MustHaveTag(SpawnOptions{}, "TimeoutTeardown")
	SpawnOptionsSpawnedByTaskKey = bsonutil.MustHaveTag(SpawnOptions{}, "SpawnedByTask")
)
View Source
var (
	HostsByDistroDistroIDKey          = bsonutil.MustHaveTag(IdleHostsByDistroID{}, "DistroID")
	HostsByDistroIdleHostsKey         = bsonutil.MustHaveTag(IdleHostsByDistroID{}, "IdleHosts")
	HostsByDistroRunningHostsCountKey = bsonutil.MustHaveTag(IdleHostsByDistroID{}, "RunningHostsCount")
)
View Source
var All = db.Query(struct{}{})

All is a query that returns all hosts

IsIdle is a query that returns all running Evergreen hosts with no task.

View Source
var IsRunningAndSpawned = db.Query(
	bson.M{
		StartedByKey: bson.M{"$ne": evergreen.User},
		StatusKey:    bson.M{"$ne": evergreen.HostTerminated},
	},
)

IsRunningAndSpawned is a query that returns all running hosts spawned by an Evergreen user.

View Source
var IsRunningTask = db.Query(
	bson.M{
		RunningTaskKey: bson.M{"$exists": true},
		StatusKey: bson.M{
			"$ne": evergreen.HostTerminated,
		},
	},
)

IsRunningTask is a query that returns all running hosts with a running task

View Source
var IsTerminated = db.Query(
	bson.M{
		RunningTaskKey: bson.M{"$exists": false},
		StatusKey:      evergreen.HostTerminated},
)

IsTerminated is a query that returns all hosts that are terminated (and not running a task).

IsUninitialized is a query that returns all unstarted + uninitialized Evergreen hosts.

Functions

func ByDistroId

func ByDistroId(distroId string) db.Q

ByDistroId produces a query that returns all working hosts (not terminated and not quarantined) of the given distro.

func ByDistroIdDoc

func ByDistroIdDoc(distroId string) bson.M

func ByDynamicWithinTime

func ByDynamicWithinTime(startTime, endTime time.Time) db.Q

ByDynamicWithinTime is a query that returns all dynamic hosts running between a certain time and another time.

func ByExpiringBetween

func ByExpiringBetween(lowerBound time.Time, upperBound time.Time) db.Q

ByExpiringBetween produces a query that returns any user-spawned hosts that will expire between the specified times.

func ById

func ById(id string) db.Q

ById produces a query that returns a host with the given id.

func ByIds

func ByIds(ids []string) db.Q

ByIds produces a query that returns all hosts in the given list of ids.

func ByNotMonitoredSince

func ByNotMonitoredSince(threshold time.Time) db.Q

ByNotMonitoredSince produces a query that returns all hosts whose last reachability check was before the specified threshold, filtering out user-spawned hosts and hosts currently running tasks.

func ByRunningTaskId

func ByRunningTaskId(taskId string) db.Q

ByRunningTaskId returns a host running the task with the given id.

func ByUnprovisionedSince

func ByUnprovisionedSince(threshold time.Time) db.Q

ByUnprovisionedSince produces a query that returns all hosts Evergreen never finished setting up that were created before the given time.

func ByUserWithRunningStatus

func ByUserWithRunningStatus(user string) db.Q

ByUserWithRunningStatus produces a query that returns all running hosts for the given user id.

func ByUserWithUnterminatedStatus

func ByUserWithUnterminatedStatus(user string) db.Q

ByUserWithUnterminatedStatus produces a query that returns all running hosts for the given user id.

func ChmodCommandWithSudo

func ChmodCommandWithSudo(ctx context.Context, script string, sudo bool) *exec.Cmd

func Count

func Count(query db.Q) (int, error)

Count returns the number of hosts that satisfy the given query.

func CountRunningHosts

func CountRunningHosts(distroID string) (int, error)

func DecommissionHostsWithDistroId

func DecommissionHostsWithDistroId(distroId string) error

func FindStaleRunningTasks

func FindStaleRunningTasks(cutoff time.Duration) ([]task.Task, error)

StateRunningTasks returns tasks documents that are currently run by a host and stale

func InsertMany

func InsertMany(hosts []Host) error

func IsLive

func IsLive() bson.M

IsLive is a query that returns all working hosts started by Evergreen

func LastCommunicationTimeElapsed

func LastCommunicationTimeElapsed(currentTime time.Time) bson.M

LastCommunicationTimeElapsed returns hosts which have never communicated or have not communicated in too long.

func MarkInactiveStaticHosts

func MarkInactiveStaticHosts(activeStaticHosts []string, distroID string) error

DecommissionInactiveStaticHosts marks static hosts in the database as terminated provided their ids aren't contained in the passed in activeStaticHosts slice. This is called in the scheduler, and marks any static host in the system that was removed from the distro as "terminated".

Previously this oepration marked these hosts as "decommissioned," which is not a state that makes sense for static hosts.

If the distro is the empty string ("") then this operation affects all distros.

func NeedsNewAgentFlagSet

func NeedsNewAgentFlagSet() db.Q

NeedsNewAgentFlagSet returns legacy hosts with NeedsNewAgent set to true.

func NumHostsByTaskSpec

func NumHostsByTaskSpec(group, bv, project, version string) (int, error)

ByTaskSpec returns a query that finds all running hosts that are running a task with the given group, buildvariant, project, and version.

func Provisioning

func Provisioning() db.Q

Provisioning returns a query used by the hostinit process to determine hosts that are started according to the cloud provider, but have not yet been provisioned by Evergreen.

func RemoveStaleInitializing

func RemoveStaleInitializing(distroID string) error

Removes host intents that have been been uninitialized for more than 3 minutes or spawning (but not started) for more than 15 minutes for the specified distro.

If you pass the empty string as a distroID, it will remove stale host intents for *all* distros.

func ShCommandWithSudo

func ShCommandWithSudo(ctx context.Context, script string, sudo bool) *exec.Cmd

func StaleRunningTaskIDs

func StaleRunningTaskIDs(staleness time.Duration) ([]task.Task, error)

StaleRunningTaskIDs finds any running tasks whose last heartbeat was at least the specified threshold ago and whose host thinks it's still running that task. Projects out everything but the ID and execution

func Starting

func Starting() db.Q

Starting returns a query that finds hosts that we do not yet know to be running.

func TearDownCommandOverSSH

func TearDownCommandOverSSH() string

TearDownCommandOverSSH returns a command for running a teardown script on a host. This command runs if there is a problem running host teardown with the agent and is intended only as a backstop if multiple agent deploys interfere with one another (https://jira.mongodb.org/browse/EVG-5972). It likely can be removed after work to improve amboy job locking or the SSH dependency.

func UpdateAll

func UpdateAll(query interface{}, update interface{}) error

UpdateAll updates all hosts.

func UpdateOne

func UpdateOne(query interface{}, update interface{}) error

UpdateOne updates one host.

func UpsertOne

func UpsertOne(query interface{}, update interface{}) (*adb.ChangeInfo, error)

UpsertOne upserts a host.

Types

type ContainersOnParents

type ContainersOnParents struct {
	ParentHost    Host
	NumContainers int
}

func GetNumContainersOnParents

func GetNumContainersOnParents(d distro.Distro) ([]ContainersOnParents, error)

getNumContainersOnParents returns a slice of uphost parents and their respective number of current containers currently running in order of longest expected finish time

type CreateOptions

type CreateOptions struct {
	ProvisionOptions   *ProvisionOptions
	ExpirationDuration *time.Duration
	UserName           string
	UserHost           bool

	HasContainers         bool
	ParentID              string
	ContainerPoolSettings *evergreen.ContainerPool
	SpawnOptions          SpawnOptions
	DockerOptions         DockerOptions
}

CreateOptions is a struct of options that are commonly passed around when creating a new cloud host.

type DistroStats

type DistroStats []StatsByDistro

func GetStatsByDistro

func GetStatsByDistro() (DistroStats, error)

GetStatsByDistro returns counts of up hosts broken down by distro

func (DistroStats) CountMap

func (d DistroStats) CountMap() map[string]int

func (DistroStats) MaxHostsExceeded

func (d DistroStats) MaxHostsExceeded() map[string]int

func (DistroStats) TasksMap

func (d DistroStats) TasksMap() map[string]int

type DockerOptions

type DockerOptions struct {
	// Optional parameters to define a registry name and authentication
	RegistryName     string `mapstructure:"docker_registry_name" bson:"docker_registry_name,omitempty" json:"docker_registry_name,omitempty"`
	RegistryUsername string `mapstructure:"docker_registry_user" bson:"docker_registry_user,omitempty" json:"docker_registry_user,omitempty"`
	RegistryPassword string `mapstructure:"docker_registry_pw" bson:"docker_registry_pw,omitempty" json:"docker_registry_pw,omitempty"`

	// Image is required and specifies the image for the container.
	// This can be a URL or an image base, to be combined with a registry.
	Image string `mapstructure:"image_url" bson:"image_url,omitempty" json:"image_url,omitempty"`
	// Method is either "pull" or "import" and defines how to retrieve the image.
	Method string `mapstructure:"build_type" bson:"build_type,omitempty" json:"build_type,omitempty"`
	// Command is required and is the command to run on the docker.
	Command string `mapstructure:"command" bson:"command,omitempty" json:"command,omitempty"`
	// If the container is created from host create, we want to skip building the image with agent
	SkipImageBuild bool `mapstructure:"skip_build" bson:"skip_build,omitempty" json:"skip_build,omitempty"`
}

DockerOptions contains options for starting a container

type FinishTime

type FinishTime struct {
	Id         string    `bson:"_id"`
	FinishTime time.Time `bson:"finish_time"`
}

FinishTime is a struct for storing pairs of host IDs and last container finish times

func AggregateLastContainerFinishTimes

func AggregateLastContainerFinishTimes() ([]FinishTime, error)

AggregateLastContainerFinishTimes returns the latest finish time for each host with containers

type Host

type Host struct {
	Id       string        `bson:"_id" json:"id"`
	Host     string        `bson:"host_id" json:"host"`
	User     string        `bson:"user" json:"user"`
	Secret   string        `bson:"secret" json:"secret"`
	Tag      string        `bson:"tag" json:"tag"`
	Distro   distro.Distro `bson:"distro" json:"distro"`
	Provider string        `bson:"host_type" json:"host_type"`
	IP       string        `bson:"ip_address" json:"ip_address"`

	// secondary (external) identifier for the host
	ExternalIdentifier string `bson:"ext_identifier" json:"ext_identifier"`

	// physical location of host
	Project string `bson:"project" json:"project"`
	Zone    string `bson:"zone" json:"zone"`

	// true if the host has been set up properly
	Provisioned       bool      `bson:"provisioned" json:"provisioned"`
	ProvisionAttempts int       `bson:"priv_attempts" json:"provision_attempts"`
	ProvisionTime     time.Time `bson:"prov_time,omitempty" json:"prov_time,omitempty"`

	ProvisionOptions *ProvisionOptions `bson:"provision_options,omitempty" json:"provision_options,omitempty"`

	// the task that is currently running on the host
	RunningTask             string `bson:"running_task,omitempty" json:"running_task,omitempty"`
	RunningTaskGroup        string `bson:"running_task_group,omitempty" json:"running_task_group,omitempty"`
	RunningTaskBuildVariant string `bson:"running_task_bv,omitempty" json:"running_task_bv,omitempty"`
	RunningTaskVersion      string `bson:"running_task_version,omitempty" json:"running_task_version,omitempty"`
	RunningTaskProject      string `bson:"running_task_project,omitempty" json:"running_task_project,omitempty"`

	// the task the most recently finished running on the host
	LastTask               string    `bson:"last_task" json:"last_task"`
	LastGroup              string    `bson:"last_group,omitempty" json:"last_group,omitempty"`
	LastBuildVariant       string    `bson:"last_bv,omitempty" json:"last_bv,omitempty"`
	LastVersion            string    `bson:"last_version,omitempty" json:"last_version,omitempty"`
	LastProject            string    `bson:"last_project,omitempty" json:"last_project,omitempty"`
	RunningTeardownForTask string    `bson:"running_teardown,omitempty" json:"running_teardown,omitempty"`
	RunningTeardownSince   time.Time `bson:"running_teardown_since,omitempty" json:"running_teardown_since,omitempty"`

	// the full task struct that is running on the host (only populated by certain aggregations)
	RunningTaskFull *task.Task `bson:"task_full,omitempty" json:"task_full,omitempty"`

	// duplicate of the DispatchTime field in the above task
	TaskDispatchTime time.Time `bson:"task_dispatch_time" json:"task_dispatch_time"`
	ExpirationTime   time.Time `bson:"expiration_time,omitempty" json:"expiration_time"`

	// creation is when the host document was inserted to the DB, start is when it was started on the cloud provider
	CreationTime    time.Time `bson:"creation_time" json:"creation_time"`
	StartTime       time.Time `bson:"start_time" json:"start_time"`
	TerminationTime time.Time `bson:"termination_time" json:"termination_time"`
	TaskCount       int       `bson:"task_count" json:"task_count"`

	LastTaskCompletedTime time.Time `bson:"last_task_completed_time" json:"last_task_completed_time"`
	LastCommunicationTime time.Time `bson:"last_communication" json:"last_communication"`

	Status    string `bson:"status" json:"status"`
	StartedBy string `bson:"started_by" json:"started_by"`
	// True if this host was created manually by a user (i.e. with spawnhost)
	UserHost             bool   `bson:"user_host" json:"user_host"`
	AgentRevision        string `bson:"agent_revision" json:"agent_revision"`
	NeedsNewAgent        bool   `bson:"needs_agent" json:"needs_agent"`
	NeedsNewAgentMonitor bool   `bson:"needs_agent_monitor" json:"needs_agent_monitor"`

	// JasperCredentialsID is used to match hosts to their Jasper credentials
	// for non-legacy hosts.
	JasperCredentialsID string `bson:"jasper_credentials_id" json:"jasper_credentials_id"`

	// for ec2 dynamic hosts, the instance type requested
	InstanceType string `bson:"instance_type" json:"instance_type,omitempty"`
	// for ec2 dynamic hosts, the total size of the volumes requested, in GiB
	VolumeTotalSize int64 `bson:"volume_total_size" json:"volume_total_size,omitempty"`

	// stores information on expiration notifications for spawn hosts
	Notifications map[string]bool `bson:"notifications,omitempty" json:"notifications,omitempty"`

	// ComputeCostPerHour is the compute (not storage) cost of one host for one hour. Cloud
	// managers can but are not required to cache this price.
	ComputeCostPerHour float64 `bson:"compute_cost_per_hour,omitempty" json:"compute_cost_per_hour,omitempty"`

	// incremented by task start and end stats collectors and
	// should reflect hosts total costs. Only populated for build-hosts
	// where host providers report costs.
	TotalCost float64 `bson:"total_cost,omitempty" json:"total_cost,omitempty"`

	// accrues the value of idle time.
	TotalIdleTime time.Duration `bson:"total_idle_time,omitempty" json:"total_idle_time,omitempty" yaml:"total_idle_time,omitempty"`

	// managed containers require different information based on host type
	// True if this host is a parent of containers
	HasContainers bool `bson:"has_containers,omitempty" json:"has_containers,omitempty"`
	// stores URLs of container images already downloaded on a parent
	ContainerImages map[string]bool `bson:"container_images,omitempty" json:"container_images,omitempty"`
	// stores the ID of the host a container is on
	ParentID string `bson:"parent_id,omitempty" json:"parent_id,omitempty"`
	// stores last expected finish time among all containers on the host
	LastContainerFinishTime time.Time `bson:"last_container_finish_time,omitempty" json:"last_container_finish_time,omitempty"`
	// ContainerPoolSettings
	ContainerPoolSettings *evergreen.ContainerPool `bson:"container_pool_settings,omitempty" json:"container_pool_settings,omitempty"`
	ContainerBuildAttempt int                      `bson:"container_build_attempt" json:"container_build_attempt"`

	// SpawnOptions holds data which the monitor uses to determine when to terminate hosts spawned by tasks.
	SpawnOptions SpawnOptions `bson:"spawn_options,omitempty" json:"spawn_options,omitempty"`

	// DockerOptions stores information for creating a container with a specific image and command
	DockerOptions DockerOptions `bson:"docker_options,omitempty" json:"docker_options,omitempty"`
}

func AllHostsSpawnedByTasksToTerminate

func AllHostsSpawnedByTasksToTerminate() ([]Host, error)

AllHostsSpawnedByTasksToTerminate finds all hosts spawned by tasks that should be terminated.

func AllIdleEphemeral

func AllIdleEphemeral() ([]Host, error)

AllIdleEphemeral finds all running ephemeral hosts without containers that have no running tasks.

func Find

func Find(query db.Q) ([]Host, error)

Find gets all Hosts for the given query.

func FindAllHostsSpawnedByTasks

func FindAllHostsSpawnedByTasks() ([]Host, error)

FindAllHostsSpawnedByTasks finds all running hosts spawned by the `createhost` command.

func FindAllRunningContainers

func FindAllRunningContainers() ([]Host, error)

FindAllRunningContainers finds all the containers that are currently running

func FindAllRunningParents

func FindAllRunningParents() ([]Host, error)

FindAllRunningParents finds all running hosts that have child containers

func FindAllRunningParentsByDistro

func FindAllRunningParentsByDistro(distroId string) ([]Host, error)

FindAllRunningParentsOnDistro finds all running hosts of a given distro with child containers

func FindAllRunningParentsOrdered

func FindAllRunningParentsOrdered() ([]Host, error)

FindAllRunningParentsOrdered finds all running hosts with child containers, sorted in order of soonest to latest LastContainerFinishTime

func FindByFirstProvisioningAttempt

func FindByFirstProvisioningAttempt() ([]Host, error)

func FindByNeedsNewAgentMonitor

func FindByNeedsNewAgentMonitor() ([]Host, error)

FindByNeedsNewAgentMonitor returns running hosts that need a new agent monitor.

func FindHostsSpawnedByBuild

func FindHostsSpawnedByBuild(buildID string) ([]Host, error)

FindHostsSpawnedByBuild finds hosts spawned by the `createhost` command scoped to a given build.

func FindHostsSpawnedByTask

func FindHostsSpawnedByTask(taskID string) ([]Host, error)

FindHostsSpawnedByTask finds hosts spawned by the `createhost` command scoped to a given task.

func FindHostsToTerminate

func FindHostsToTerminate() ([]Host, error)

func FindOne

func FindOne(query db.Q) (*Host, error)

FindOne gets one Host for the given query.

func FindOneByIdOrTag

func FindOneByIdOrTag(id string) (*Host, error)

FindOneByIdOrTag finds a host where the given id is stored in either the _id or tag field. (The tag field is used for the id from the host's original intent host.)

func FindOneId

func FindOneId(id string) (*Host, error)

func FindRunningHosts

func FindRunningHosts(includeSpawnHosts bool) ([]Host, error)

FindRunningHosts is the underlying query behind the hosts page's table

func FindTerminatedHostsRunningTasks

func FindTerminatedHostsRunningTasks() ([]Host, error)

func GenerateContainerHostIntents

func GenerateContainerHostIntents(d distro.Distro, newContainersNeeded int, hostOptions CreateOptions) ([]Host, error)

GenerateContainerHostIntents generates container intent documents by going through available parents and packing on the parents with longest expected finish time

func GetHostsByFromIDWithStatus

func GetHostsByFromIDWithStatus(id, status, user string, limit int) ([]Host, error)

func InsertParentIntentsAndGetNumHostsToSpawn

func InsertParentIntentsAndGetNumHostsToSpawn(pool *evergreen.ContainerPool, newHostsNeeded int, ignoreMaxHosts bool) ([]Host, int, error)

func NewIntent

func NewIntent(d distro.Distro, instanceName, provider string, options CreateOptions) *Host

NewIntent creates an IntentHost using the given host settings. An IntentHost is a host that does not exist yet but is intended to be picked up by the hostinit package and started. This function takes distro information, the name of the instance, the provider of the instance and a CreateOptions and returns an IntentHost.

func (*Host) BootstrapScript

func (h *Host) BootstrapScript(config evergreen.HostJasperConfig, creds *rpc.Credentials) (string, error)

BootstrapScript creates the user data script to bootstrap the host.

func (*Host) CacheHostData

func (h *Host) CacheHostData() error

func (*Host) ClearRunningAndSetLastTask

func (h *Host) ClearRunningAndSetLastTask(t *task.Task) error

ClearRunningAndSetLastTask unsets the running task on the host and updates the last task fields.

func (*Host) ClearRunningTask

func (h *Host) ClearRunningTask() error

ClearRunningTask unsets the running task on the host.

func (*Host) ClearRunningTeardownGroup

func (h *Host) ClearRunningTeardownGroup() error

func (*Host) CountContainersRunningAtTime

func (h *Host) CountContainersRunningAtTime(timestamp time.Time) (int, error)

CountContainersRunningAtTime counts how many containers were running on the given parent host at the specified time, using the host StartTime and TerminationTime fields.

func (*Host) CreateSecret

func (h *Host) CreateSecret() error

CreateSecret generates a host secret and updates the host both locally and in the database.

func (*Host) CurlCommand

func (h *Host) CurlCommand(url string) string

func (*Host) DeleteJasperCredentials

func (h *Host) DeleteJasperCredentials(ctx context.Context, env evergreen.Environment) error

DeleteJasperCredentials deletes the Jasper credentials for the host and updates the host both in memory and in the database.

func (*Host) DisablePoisonedHost

func (h *Host) DisablePoisonedHost(logs string) error

func (*Host) EstimateNumContainersForDuration

func (h *Host) EstimateNumContainersForDuration(start, end time.Time) (float64, error)

EstimateNumberContainersForDuration estimates how many containers were running on a given host during the specified time interval by averaging the counts at the start and end. It is more accurate for shorter tasks.

func (*Host) FetchAndReinstallJasperCommand

func (h *Host) FetchAndReinstallJasperCommand(config evergreen.HostJasperConfig) string

FetchAndReinstallJasperCommand returns the command to fetch Jasper and restart the service with the latest version.

func (*Host) FetchJasperCommand

func (h *Host) FetchJasperCommand(config evergreen.HostJasperConfig) string

FetchJasperCommand builds the command to download and extract the Jasper binary into the distro-specific binary directory.

func (*Host) FetchJasperCommandWithPath

func (h *Host) FetchJasperCommandWithPath(config evergreen.HostJasperConfig, path string) string

FetchJasperCommandWithPath is the same as FetchJasperCommand but sets the PATH variable to path for each command.

func (*Host) ForceReinstallJasperCommand

func (h *Host) ForceReinstallJasperCommand(config evergreen.HostJasperConfig) string

ForceReinstallJasperCommand returns the command to stop the Jasper service, delete the current Jasper service configuration (if it exists), install the new configuration, and restart the service.

func (*Host) GenerateJasperCredentials

func (h *Host) GenerateJasperCredentials(ctx context.Context, env evergreen.Environment) (*rpc.Credentials, error)

GenerateJasperCredentials creates the Jasper credentials for the given host without saving them to the database.

func (*Host) GetContainers

func (h *Host) GetContainers() ([]Host, error)

GetContainers finds all the containers belonging to this host errors if this host is not a parent

func (*Host) GetElapsedCommunicationTime

func (h *Host) GetElapsedCommunicationTime() time.Duration

GetElapsedCommunicationTime returns how long since this host has communicated with evergreen or vice versa

func (*Host) GetParent

func (h *Host) GetParent() (*Host, error)

GetParent finds the parent of this container errors if host is not a container or if parent cannot be found

func (*Host) GetSSHInfo

func (h *Host) GetSSHInfo() (*util.StaticHostInfo, error)

func (*Host) GetTaskGroupString

func (h *Host) GetTaskGroupString() string

func (*Host) IdleTime

func (h *Host) IdleTime() time.Duration

IdleTime returns how long has this host been idle

func (*Host) IncContainerBuildAttempt

func (h *Host) IncContainerBuildAttempt() error

func (*Host) IncCost

func (h *Host) IncCost(amt float64) error

func (*Host) IncIdleTime

func (h *Host) IncIdleTime(dur time.Duration) error

func (*Host) IncProvisionAttempts

func (h *Host) IncProvisionAttempts() error

func (*Host) IncTaskCount

func (h *Host) IncTaskCount() error

func (*Host) InitSystem

func (h *Host) InitSystem(ctx context.Context, sshOptions []string) (string, error)

InitSystem determines the current Linux init system used by this host.

func (*Host) Insert

func (h *Host) Insert() error

func (*Host) IsEphemeral

func (h *Host) IsEphemeral() bool

func (*Host) IsIdleParent

func (h *Host) IsIdleParent() (bool, error)

IsIdleParent determines whether a host with containers has exclusively terminated containers

func (*Host) IsWaitingForAgent

func (h *Host) IsWaitingForAgent() bool

IsWaitingForAgent provides a local predicate for the logic in the "NeedsNewAgent" query.

func (*Host) JasperCredentials

func (h *Host) JasperCredentials(ctx context.Context, env evergreen.Environment) (*rpc.Credentials, error)

JasperCredentials gets the Jasper credentials from the database.

func (*Host) LegacyBootstrap

func (h *Host) LegacyBootstrap() bool

LegacyBootstrap returns whether the host was bootstrapped using the legacy method.

func (*Host) LegacyCommunication

func (h *Host) LegacyCommunication() bool

LegacyCommunication returns whether the app server is communicating with this host using the legacy method.

func (*Host) MarkAsProvisioned

func (h *Host) MarkAsProvisioned() error

func (*Host) MarkReachable

func (h *Host) MarkReachable() error

func (*Host) MarshalBSON

func (h *Host) MarshalBSON() ([]byte, error)

func (*Host) Remove

func (h *Host) Remove() error

func (*Host) ResetLastCommunicated

func (h *Host) ResetLastCommunicated() error

ResetLastCommunicated sets the LastCommunicationTime to be zero.

func (*Host) RunSSHCommand

func (h *Host) RunSSHCommand(ctx context.Context, cmd string, sshOptions []string) (string, error)

RunSSHCommand runs an SSH command on a remote host.

func (*Host) RunSSHJasperRequest

func (h *Host) RunSSHJasperRequest(ctx context.Context, env evergreen.Environment, subCmd string, input interface{}, sshOptions []string) (string, error)

RunSSHJasperRequest runs the command to make a request to the host's Jasper service over SSH. It invoking the subcommand subCmd with the given request input.

func (*Host) SaveJasperCredentials

func (h *Host) SaveJasperCredentials(ctx context.Context, env evergreen.Environment, creds *rpc.Credentials) error

SaveJasperCredentials saves the given Jasper credentials in the database for the host.

func (*Host) SetAgentRevision

func (h *Host) SetAgentRevision(agentRevision string) error

SetAgentRevision sets the updated agent revision for the host

func (*Host) SetDNSName

func (h *Host) SetDNSName(dnsName string) error

SetDNSName updates the DNS name for a given host once

func (*Host) SetDecommissioned

func (h *Host) SetDecommissioned(user string, logs string) error

func (*Host) SetExpirationNotification

func (h *Host) SetExpirationNotification(thresholdKey string) error

SetExpirationNotification updates the notification time for a spawn host

func (*Host) SetExpirationTime

func (h *Host) SetExpirationTime(expirationTime time.Time) error

SetExpirationTime updates the expiration time of a spawn host

func (*Host) SetExtId

func (h *Host) SetExtId() error

func (*Host) SetIPv6Address

func (h *Host) SetIPv6Address(ipv6Address string) error

func (*Host) SetNeedsAgentDeploy

func (h *Host) SetNeedsAgentDeploy(needsDeploy bool) error

SetNeedsAgentDeploy indicates that the host's agent needs to be deployed.

func (*Host) SetNeedsNewAgent

func (h *Host) SetNeedsNewAgent(needsAgent bool) error

SetNeedsNewAgent sets the "needs new agent" flag on the host.

func (*Host) SetNeedsNewAgentAtomically

func (h *Host) SetNeedsNewAgentAtomically(needsAgent bool) error

SetNeedsNewAgentAtomically sets the "needs new agent" flag on the host atomically.

func (*Host) SetNeedsNewAgentMonitor

func (h *Host) SetNeedsNewAgentMonitor(needsAgentMonitor bool) error

SetNeedsNewAgentMonitor sets the "needs new agent monitor" flag on the host to indicate that the host needs to have the agent monitor deployed.

func (*Host) SetNeedsNewAgentMonitorAtomically

func (h *Host) SetNeedsNewAgentMonitorAtomically(needsAgentMonitor bool) error

SetNeedsNewAgentMonitorAtomically is the same as SetNeedsNewAgentMonitor but performs an atomic update on the host in the database.

func (*Host) SetProvisioning

func (h *Host) SetProvisioning() error

SetProvisioning marks the host as initializing. Only allow this if the host is uninitialized.

func (*Host) SetQuarantined

func (h *Host) SetQuarantined(user string, logs string) error

func (*Host) SetRunning

func (h *Host) SetRunning(user string) error

func (*Host) SetRunningTeardownGroup

func (h *Host) SetRunningTeardownGroup(taskID string) error

SetRunningTeardownGroup marks the host as running teardown_group for a task group, no-oping if it's already set to the same task

func (*Host) SetStatus

func (h *Host) SetStatus(status, user string, logs string) error

func (*Host) SetTerminated

func (h *Host) SetTerminated(user string) error

func (*Host) SetUnprovisioned

func (h *Host) SetUnprovisioned() error

func (*Host) SetupCommand

func (h *Host) SetupCommand() string

func (*Host) TearDownCommand

func (h *Host) TearDownCommand() string

TearDownCommand returns a command for running a teardown script on a host.

func (*Host) Terminate

func (h *Host) Terminate(user string) error

func (*Host) UnmarshalBSON

func (h *Host) UnmarshalBSON(in []byte) error

func (*Host) UpdateDocumentID

func (h *Host) UpdateDocumentID(newID string) (*Host, error)

UpdateDocumentID updates the host document corresponding to the current host to have a new ID by finding, deleting, and replacing the document with a new one.

func (*Host) UpdateJasperCredentialsID

func (h *Host) UpdateJasperCredentialsID(id string) error

UpdateJasperCredentialsID sets the ID of the host's Jasper credentials.

func (*Host) UpdateLastCommunicated

func (h *Host) UpdateLastCommunicated() error

UpdateLastCommunicated sets the host's last communication time to the current time.

func (*Host) UpdateLastContainerFinishTime

func (h *Host) UpdateLastContainerFinishTime(t time.Time) error

UpdateLastContainerFinishTime updates latest finish time for a host with containers

func (*Host) UpdateRunningTask

func (h *Host) UpdateRunningTask(t *task.Task) (bool, error)

UpdateRunningTask updates the running task in the host document, returns - true, nil on success - false, nil on duplicate key error, task is already assigned to another host - false, error on all other errors

func (*Host) Upsert

func (h *Host) Upsert() (*adb.ChangeInfo, error)

type HostGroup

type HostGroup []Host

func AllRunningHosts

func AllRunningHosts(distroID string) (HostGroup, error)

func (HostGroup) CountContainersOnParents

func (hosts HostGroup) CountContainersOnParents() (int, error)

CountContainersOnParents counts how many containers are children of the given group of hosts

func (HostGroup) FindUphostContainersOnParents

func (hosts HostGroup) FindUphostContainersOnParents() ([]Host, error)

FindUphostContainersOnParents returns the containers that are children of the given hosts

func (HostGroup) GetHostIds

func (hosts HostGroup) GetHostIds() []string

GetHostIds returns a slice of host IDs for the given group of hosts

func (HostGroup) Stats

func (hosts HostGroup) Stats() HostGroupStats

type HostGroupStats

type HostGroupStats struct {
	Quarantined    int `bson:"quarantined" json:"quarantined" yaml:"quarantined"`
	Decommissioned int `bson:"decommissioned" json:"decommissioned" yaml:"decommissioned"`
	Idle           int `bson:"idle" json:"idle" yaml:"idle"`
	Active         int `bson:"active" json:"active" yaml:"active"`
	Provisioning   int `bson:"provisioning" json:"provisioning" yaml:"provisioning"`
	Total          int `bson:"total" json:"total" yaml:"total"`
}

type IdleHostsByDistroID

type IdleHostsByDistroID struct {
	DistroID          string `bson:"distro_id"`
	IdleHosts         []Host `bson:"idle_hosts"`
	RunningHostsCount int    `bson:"running_hosts_count"`
}

func IdleEphemeralGroupedByDistroID

func IdleEphemeralGroupedByDistroID() ([]IdleHostsByDistroID, error)

IdleEphemeralGroupedByDistroId groups and collates the following by distro.Id: - []host.Host of ephemeral hosts without containers which having no running task, ordered by {host.CreationTime: 1} - the total number of ephemeral hosts with status: evergreen.HostRunning

func (*IdleHostsByDistroID) MarshalBSON

func (h *IdleHostsByDistroID) MarshalBSON() ([]byte, error)

func (*IdleHostsByDistroID) UnmarshalBSON

func (h *IdleHostsByDistroID) UnmarshalBSON(in []byte) error

type InactiveHostCounts

type InactiveHostCounts struct {
	HostType string `bson:"_id"`
	Count    int    `bson:"count"`
}

func CountInactiveHostsByProvider

func CountInactiveHostsByProvider() ([]InactiveHostCounts, error)

type ProviderStats

type ProviderStats []StatsByProvider

func GetProviderCounts

func GetProviderCounts() (ProviderStats, error)

GetProvierCounts returns data on the number of hosts by different provider stats.

func (ProviderStats) Map

func (p ProviderStats) Map() map[string]int

type ProvisionOptions

type ProvisionOptions struct {
	// LoadCLI indicates (if set) that while provisioning the host, the CLI binary should
	// be placed onto the host after startup.
	LoadCLI bool `bson:"load_cli" json:"load_cli"`

	// TaskId if non-empty will trigger the CLI tool to fetch source and artifacts for the given task.
	// Ignored if LoadCLI is false.
	TaskId string `bson:"task_id" json:"task_id"`

	// Owner is the user associated with the host used to populate any necessary metadata.
	OwnerId string `bson:"owner_id" json:"owner_id"`
}

ProvisionOptions is struct containing options about how a new host should be set up.

type SpawnOptions

type SpawnOptions struct {
	// TimeoutTeardown is the time that this host should be torn down. In most cases, a host
	// should be torn down due to its task or build. TimeoutTeardown is a backstop to ensure that Evergreen
	// tears down a host if a task hangs or otherwise does not finish within an expected period of time.
	TimeoutTeardown time.Time `bson:"timeout_teardown" json:"timeout_teardown"`

	// TimeoutTeardown is the time after which Evergreen should give up trying to set up this host.
	TimeoutSetup time.Time `bson:"timeout_setup" json:"timeout_setup"`

	// TaskID is the task_id of the task to which this host is pinned. When the task finishes,
	// this host should be torn down. Only one of TaskID or BuildID should be set.
	TaskID string `bson:"task_id,omitempty" json:"task_id,omitempty"`

	// BuildID is the build_id of the build to which this host is pinned. When the build finishes,
	// this host should be torn down. Only one of TaskID or BuildID should be set.
	BuildID string `bson:"build_id,omitempty" json:"build_id,omitempty"`

	// Retries is the number of times Evergreen should try to spawn this host.
	Retries int `bson:"retries,omitempty" json:"retries,omitempty"`

	// SpawnedByTask indicates that this host has been spawned by a task.
	SpawnedByTask bool `bson:"spawned_by_task,omitempty" json:"spawned_by_task,omitempty"`
}

SpawnOptions holds data which the monitor uses to determine when to terminate hosts spawned by tasks.

type StatsByDistro

type StatsByDistro struct {
	// ID of the distro the below stats are for
	Distro string `bson:"distro" json:"distro,omitempty"`
	// Provider is the provider type of the distro
	Provider string `bson:"provider" json:"provider,omitempty"`
	// Host status that the below stats are for
	Status string `bson:"status" json:"status"`
	// Number of hosts in this status
	Count int `bson:"count" json:"count"`
	// Number of tasks running on hosts in the above group (should only be nonzero for running hosts)
	NumTasks int `bson:"num_tasks_running" json:"num_tasks_running"`
	// MaxHosts reports the pool size of the distro.
	MaxHosts int `bson:"max_hosts" json:"max_hosts"`
}

func (*StatsByDistro) MarshalBSON

func (d *StatsByDistro) MarshalBSON() ([]byte, error)

func (*StatsByDistro) UnmarshalBSON

func (d *StatsByDistro) UnmarshalBSON(in []byte) error

type StatsByProvider

type StatsByProvider struct {
	// the name of a host provider
	Provider string `bson:"provider" json:"provider"`
	// Number of hosts with this provider
	Count int `bson:"count" json:"count"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL