Beispiel #1
0
// 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 (h *Host) UpdateReachability(reachable bool) error {
	status := evergreen.HostRunning
	setUpdate := bson.M{
		StatusKey:                status,
		LastReachabilityCheckKey: time.Now(),
	}

	update := bson.M{}
	if !reachable {
		status = evergreen.HostUnreachable
		setUpdate[StatusKey] = status

		// If the host is being switched to unreachable for the first time, then
		// "unreachable since" will be unset, so we set it to the current time.
		if h.UnreachableSince.Equal(util.ZeroTime) || h.UnreachableSince.Before(util.ZeroTime) {
			now := time.Now()
			setUpdate[UnreachableSinceKey] = now
			h.UnreachableSince = now
		}
	} else {
		// host is reachable, so unset the unreachable_since field
		update["$unset"] = bson.M{UnreachableSinceKey: 1}
		h.UnreachableSince = util.ZeroTime
	}
	update["$set"] = setUpdate

	event.LogHostStatusChanged(h.Id, h.Status, status)

	h.Status = status

	return UpdateOne(bson.M{IdKey: h.Id}, update)
}
Beispiel #2
0
func (self *Host) SetStatus(status string) error {
	if self.Status == evergreen.HostTerminated {
		msg := fmt.Sprintf("Refusing to mark host %v as"+
			" %v because it is already terminated", self.Id, status)
		evergreen.Logger.Logf(slogger.WARN, msg)
		return fmt.Errorf(msg)
	}

	event.LogHostStatusChanged(self.Id, self.Status, status)
	self.Status = status
	return UpdateOne(
		bson.M{
			IdKey: self.Id,
		},
		bson.M{
			"$set": bson.M{
				StatusKey: status,
			},
		},
	)
}
Beispiel #3
0
// UpdateReachability sets a host as either running or unreachable, depending on the bool passed
// in. also update the last reachability check for the host
func (self *Host) UpdateReachability(reachable bool) error {
	status := evergreen.HostRunning
	if !reachable {
		status = evergreen.HostUnreachable
	}

	event.LogHostStatusChanged(self.Id, self.Status, status)
	self.Status = status

	return UpdateOne(
		bson.M{
			IdKey: self.Id,
		},
		bson.M{
			"$set": bson.M{
				StatusKey:                status,
				LastReachabilityCheckKey: time.Now(),
			},
		},
	)
}