Exemplo n.º 1
0
// Renew is used to renew the TTL on a single session
func (s *Session) Renew(args *structs.SessionSpecificRequest,
	reply *structs.IndexedSessions) error {
	if done, err := s.srv.forward("Session.Renew", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"consul", "session", "renew"}, time.Now())

	// Get the session, from local state
	state := s.srv.fsm.State()
	index, session, err := state.SessionGet(args.Session)
	if err != nil {
		return err
	}

	// Reset the session TTL timer
	reply.Index = index
	if session != nil {
		reply.Sessions = structs.Sessions{session}
		if err := s.srv.resetSessionTimer(args.Session, session); err != nil {
			s.srv.logger.Printf("[ERR] consul.session: Session renew failed: %v", err)
			return err
		}
	}
	return nil
}
Exemplo n.º 2
0
// Get is used to retrieve a single session
func (s *Session) Get(args *structs.SessionSpecificRequest,
	reply *structs.IndexedSessions) error {
	if done, err := s.srv.forward("Session.Get", args, args, reply); done {
		return err
	}

	// Get the local state
	state := s.srv.fsm.State()
	return s.srv.blockingRPC(&args.QueryOptions,
		&reply.QueryMeta,
		state.QueryTables("SessionGet"),
		func() error {
			index, session, err := state.SessionGet(args.Session)
			reply.Index = index
			if session != nil {
				reply.Sessions = structs.Sessions{session}
			} else {
				reply.Sessions = nil
			}
			return err
		})
}