Ejemplo n.º 1
0
// NewMachine initializes a new Machine struct with any internal vars created.
func NewMachine(meta MachineMeta, log logging.Logger, t Transport) (*Machine, error) {
	log = MachineLogger(meta, log)

	// Create our Pingers, to be used in the PingTrackers
	kitePinger := kitepinger.NewKitePinger(t)
	httpPinger, err := kitepinger.NewKiteHTTPPinger(meta.URL)
	if err != nil {
		log.Error(
			"Unable to create HTTPPinger from meta.URL. url:%s, err:%s", meta.URL, err,
		)
		return nil, err
	}

	m := &Machine{
		MachineMeta: meta,
		Log:         log,
		KiteTracker: kitepinger.NewPingTracker(kitePinger),
		HTTPTracker: kitepinger.NewPingTracker(httpPinger),
		Transport:   t,
		discover:    discover.NewClient(),
		mountLocker: util.NewMutexWithState(),
	}

	m.discover.Log = m.Log.New("discover")

	// Start our http pinger, to give online/offline statuses for all machines.
	m.HTTPTracker.Start()

	return m, nil
}
Ejemplo n.º 2
0
// InitHTTPTracker creates the HTTPTracker for this Machine, if it is
// currently nil.
//
// This allows a caller to simply call this method beforehand on any machine,
// valid or not, and access the online/offline status of the remote kite.
func (m *Machine) InitHTTPTracker() error {
	if m.HasHTTPTracker() {
		return nil
	}

	// If the URL is empty, don't bother - nothing we can do.
	if m.URL == "" {
		return errors.New("Unable to Init HTTPTracker, Machine.URL is empty.")
	}

	httpPinger, err := kitepinger.NewKiteHTTPPinger(m.URL)
	if err != nil {
		return err
	}

	m.HTTPTracker = kitepinger.NewPingTracker(httpPinger)

	return nil
}