host

package
v0.0.0-...-1d50e38 Latest Latest
Warning

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

Go to latest
Published: May 30, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Collection is the name of the MongoDB collection that stores hosts.
	Collection = "hosts"
)
View Source
const (
	MaxLCTInterval = time.Minute * 10
)

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")
	ProvisionedKey           = bsonutil.MustHaveTag(Host{}, "Provisioned")
	RunningTaskKey           = bsonutil.MustHaveTag(Host{}, "RunningTask")
	PidKey                   = bsonutil.MustHaveTag(Host{}, "Pid")
	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")
	LTCKey                   = bsonutil.MustHaveTag(Host{}, "LastTaskCompleted")
	StatusKey                = bsonutil.MustHaveTag(Host{}, "Status")
	AgentRevisionKey         = bsonutil.MustHaveTag(Host{}, "AgentRevision")
	StartedByKey             = bsonutil.MustHaveTag(Host{}, "StartedBy")
	InstanceTypeKey          = bsonutil.MustHaveTag(Host{}, "InstanceType")
	NotificationsKey         = bsonutil.MustHaveTag(Host{}, "Notifications")
	UserDataKey              = bsonutil.MustHaveTag(Host{}, "UserData")
	LastReachabilityCheckKey = bsonutil.MustHaveTag(Host{}, "LastReachabilityCheck")
	LastCommunicationTimeKey = bsonutil.MustHaveTag(Host{}, "LastCommunicationTime")
	UnreachableSinceKey      = bsonutil.MustHaveTag(Host{}, "UnreachableSince")
)
View Source
var All = db.Query(nil)

All is a query that returns all hosts

IsActive is a query that returns all Evergreen hosts that are working or capable of being assigned work to do.

View Source
var IsAvailableAndFree = db.Query(
	bson.M{
		RunningTaskKey: bson.M{"$exists": false},
		StatusKey:      evergreen.HostRunning,
		StartedByKey:   evergreen.User,
	},
).Sort([]string{"-" + LTCTimeKey})

IsAvailableAndFree is a query that returns all running Evergreen hosts without an assigned task.

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

IsDecommissioned is a query that returns all hosts without a running task that are marked for decommissioning.

IsFree is a query that returns all running Evergreen hosts without an assigned task.

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

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

View Source
var IsProvisioningFailure = db.Query(bson.D{{StatusKey, evergreen.HostProvisionFailed}})

IsProvisioningFailure is a query that returns all hosts that failed to provision.

IsRunning is a query that returns all hosts that are running (i.e. status != terminated).

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},
	},
)

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

IsUninitialized is a query that returns all uninitialized Evergreen hosts.

Functions

func ByAvailableForDistro

func ByAvailableForDistro(d string) db.Q

ByAvailableForDistro returns all running Evergreen hosts with no running task of a certain distro Id.

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 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 ByExpiredSince

func ByExpiredSince(time time.Time) db.Q

ByExpiredSicne produces a query that returns any user-spawned hosts that will expired after the given 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 ByRunningWithTimedOutLCT

func ByRunningWithTimedOutLCT(currentTime time.Time) db.Q

ByRunningWithTimedOutLCT returns hosts that are running and either have no Last Commmunication Time or have one that exists that is greater than the MaxLTCInterval duration away from the current time.

func ByUnproductiveSince

func ByUnproductiveSince(threshold time.Time) db.Q

ByUnproductiveSince produces a query that returns all hosts that are not doing work and were created before the given time.

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 ByUnreachableBefore

func ByUnreachableBefore(threshold time.Time) db.Q

ByUnreachableBefore produces a query that returns a list of all hosts that are still unreachable, and have been in that state since before the given time threshold.

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 Count

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

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

func DecommissionHostsWithDistroId

func DecommissionHostsWithDistroId(distroId string) error

func DecommissionInactiveStaticHosts

func DecommissionInactiveStaticHosts(activeStaticHosts []string) error

DecommissionInactiveStaticHosts decommissions static hosts in the database provided their ids aren't contained in the passed in activeStaticHosts slice

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{}) (*mgo.ChangeInfo, error)

UpsertOne upserts a host.

Types

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"`

	// true if the host has been set up properly
	Provisioned bool `bson:"provisioned" json:"provisioned"`

	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"`

	// the pid of the task that is currently running on the host
	Pid string `bson:"pid" json:"pid"`

	// 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"`
	CreationTime     time.Time `bson:"creation_time" json:"creation_time"`
	TerminationTime  time.Time `bson:"termination_time" json:"termination_time"`

	LastTaskCompletedTime time.Time `bson:"last_task_completed_time" json:"last_task_completed_time"`
	LastTaskCompleted     string    `bson:"last_task" json:"last_task"`
	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"`
	// for ec2 dynamic hosts, the instance type requested
	InstanceType string `bson:"instance_type" json:"instance_type,omitempty"`
	// stores information on expiration notifications for spawn hosts
	Notifications map[string]bool `bson:"notifications,omitempty" json:"notifications,omitempty"`

	// stores userdata that was placed on the host at spawn time
	UserData string `bson:"userdata" json:"userdata,omitempty"`

	// the last time that the host's reachability was checked
	LastReachabilityCheck time.Time `bson:"last_reachability_check" json:"last_reachability_check"`

	// if set, the time at which the host first became unreachable
	UnreachableSince time.Time `bson:"unreachable_since,omitempty" json:"unreachable_since"`
}

func Find

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

Find gets all Hosts for the given query.

func FindOne

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

FindOne gets one Host for the given query.

func GetHostsByFromIdWithStatus

func GetHostsByFromIdWithStatus(id, status string, limit, sortDir int) ([]Host, error)

func (*Host) ClearRunningTask

func (host *Host) ClearRunningTask(prevTaskId string, finishTime time.Time) error

ClearRunningTask unsets the running task key on the host and updates the last task completed 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) IdleTime

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

IdleTime returns how long has this host been idle

func (*Host) Insert

func (h *Host) Insert() error

func (*Host) MarkAsProvisioned

func (h *Host) MarkAsProvisioned() 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) 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() 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) SetInitializing

func (h *Host) SetInitializing() error

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

func (*Host) SetQuarantined

func (h *Host) SetQuarantined() error

func (*Host) SetRunning

func (h *Host) SetRunning() error

func (*Host) SetStatus

func (h *Host) SetStatus(status string) error

func (*Host) SetTaskPid

func (h *Host) SetTaskPid(pid string) error

func (*Host) SetTerminated

func (h *Host) SetTerminated() error

func (*Host) SetUninitialized

func (h *Host) SetUninitialized() error

func (*Host) SetUnprovisioned

func (h *Host) SetUnprovisioned() error

func (*Host) SetUnreachable

func (h *Host) SetUnreachable() error

func (*Host) SetUserData

func (h *Host) SetUserData(userData string) error

SetUserData updates the userdata field of a spawn host

func (*Host) Terminate

func (h *Host) Terminate() error

func (*Host) UpdateLastCommunicated

func (h *Host) UpdateLastCommunicated() error

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

func (*Host) UpdateReachability

func (h *Host) UpdateReachability(reachable bool) error

UpdateReachability sets a host as either running or unreachable, and updates the timestamp of the host's last reachability check. If the host is being set to unreachable, the "unreachable since" field is also set to the current time if it is unset.

func (*Host) UpdateRunningTask

func (host *Host) UpdateRunningTask(prevTaskId, newTaskId string,
	finishTime time.Time) (bool, error)

UpdateRunningTask takes two id strings - an old task and a new one - finds the host running the task with Id, 'prevTaskId' and updates its running task to 'newTaskId'; also setting the completion time of 'prevTaskId' Returns true for success and error if it exists

func (*Host) Upsert

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

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.

Jump to

Keyboard shortcuts

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