2018-02-27 19:57:10 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2018-04-16 22:02:00 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/helper"
|
2018-02-27 19:57:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DriverInfo is the current state of a single driver. This is updated
|
|
|
|
// regularly as driver health changes on the node.
|
|
|
|
type DriverInfo struct {
|
|
|
|
Attributes map[string]string
|
|
|
|
Detected bool
|
|
|
|
Healthy bool
|
|
|
|
HealthDescription string
|
|
|
|
UpdateTime time.Time
|
|
|
|
}
|
|
|
|
|
2018-04-16 22:02:00 +00:00
|
|
|
func (di *DriverInfo) Copy() *DriverInfo {
|
|
|
|
if di == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cdi := new(DriverInfo)
|
|
|
|
*cdi = *di
|
|
|
|
cdi.Attributes = helper.CopyMapStringString(di.Attributes)
|
|
|
|
return cdi
|
|
|
|
}
|
|
|
|
|
2018-02-28 19:32:54 +00:00
|
|
|
// MergeHealthCheck merges information from a health check for a drier into a
|
|
|
|
// node's driver info
|
2018-02-27 19:57:10 +00:00
|
|
|
func (di *DriverInfo) MergeHealthCheck(other *DriverInfo) {
|
|
|
|
di.Healthy = other.Healthy
|
|
|
|
di.HealthDescription = other.HealthDescription
|
|
|
|
di.UpdateTime = other.UpdateTime
|
|
|
|
}
|
|
|
|
|
2018-02-28 19:32:54 +00:00
|
|
|
// MergeFingerprint merges information from fingerprinting a node for a driver
|
|
|
|
// into a node's driver info for that driver.
|
2018-02-27 19:57:10 +00:00
|
|
|
func (di *DriverInfo) MergeFingerprintInfo(other *DriverInfo) {
|
|
|
|
di.Detected = other.Detected
|
|
|
|
di.Attributes = other.Attributes
|
|
|
|
}
|
|
|
|
|
|
|
|
// DriverInfo determines if two driver info objects are equal..As this is used
|
|
|
|
// in the process of health checking, we only check the fields that are
|
|
|
|
// computed by the health checker. In the future, this will be merged.
|
|
|
|
func (di *DriverInfo) HealthCheckEquals(other *DriverInfo) bool {
|
2018-03-20 17:25:07 +00:00
|
|
|
if di == nil && other == nil {
|
|
|
|
return true
|
2018-02-27 19:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if di.Healthy != other.Healthy {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-03-14 17:10:41 +00:00
|
|
|
if di.HealthDescription != other.HealthDescription {
|
2018-02-27 19:57:10 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|