Beispiel #1
0
func (s *Stack) checkTunnel(c *kite.Client) error {
	resp, err := c.TellWithTimeout("tunnel.info", 2*time.Minute)
	if err != nil {
		return err
	}

	var info tunnel.InfoResponse
	if err := resp.Unmarshal(&info); err != nil {
		return err
	}

	s.Log.Debug("received tunnel.info response: %+v", &info)

	if info.State != tunnel.StateConnected {
		// We do not fail here, as the tunnel can be recovering
		// and we might hit the window when it's not yet done.
		// However we log, to show kloud observed problems with
		// connection.
		s.Log.Warning("%s: want tunnel to be %q, was %q instead", c.ID, tunnel.StateConnected, info.State)

		return nil
	}

	if _, ok := info.Ports["kite"]; !ok {
		// Every klient has its connection to kontrol tunneled, thus
		// tunnel.info should report ports for kite. Warn if there're
		// none to show kloud observed unexpected behavior.
		// However it is not critical though, as we were able to
		// kite.ping the klient, it means the klient may have some
		// other problems (connection with host kite etc.).
		s.Log.Warning("%s: no ports for kite", c.ID)
	}

	return nil
}
Beispiel #2
0
// watch watches the events of the specified event type.
func watch(k *kite.Client, eventType string, eventId string, interval time.Duration) error {
	eventArgs := stack.EventArgs([]stack.EventArg{
		{
			Type:    eventType,
			EventId: eventId,
		},
	})

	for {
		resp, err := k.TellWithTimeout("event", defaultTellTimeout, eventArgs)
		if err != nil {
			return err
		}

		var events []stack.EventResponse
		if err := resp.Unmarshal(&events); err != nil {
			return err
		}

		if len(events) == 0 {
			return errors.New("incoming event response is not an array")
		}

		if events[0].Error != nil {
			return events[0].Error
		}

		DefaultUi.Info(fmt.Sprintf("%s ==> %s [Status: %s Percentage: %d]",
			fmt.Sprint(time.Now())[:19],
			events[0].Event.Message,
			events[0].Event.Status,
			events[0].Event.Percentage,
		))

		if events[0].Event.Error != "" {
			err := errors.New(events[0].Event.Error)
			DefaultUi.Error(err.Error())
			return err
		}

		if events[0].Event.Percentage == 100 {
			return nil
		}

		time.Sleep(interval)
	}
}