예제 #1
0
파일: logstream.go 프로젝트: bac/juju
func (st logStreamState) getStart(sink string, allModels bool) (time.Time, error) {
	var tracker *state.LastSentLogTracker
	if allModels {
		var err error
		tracker, err = state.NewAllLastSentLogTracker(st, sink)
		if err != nil {
			return time.Time{}, errors.Trace(err)
		}
	} else {
		tracker = state.NewLastSentLogTracker(st, st.ModelUUID(), sink)
	}
	defer tracker.Close()

	// Resume for the sink...
	_, lastSentTimestamp, err := tracker.Get()
	if errors.Cause(err) == state.ErrNeverForwarded {
		// If we've never forwarded a message, we start from
		// position zero.
		lastSentTimestamp = 0
	} else if err != nil {
		return time.Time{}, errors.Trace(err)
	}

	// Using the same timestamp will cause at least 1 duplicate
	// entry, but that is better than dropping records.
	// TODO(ericsnow) Add 1 to start once we track by sequential int ID
	// instead of by timestamp.
	return time.Unix(0, lastSentTimestamp), nil
}
예제 #2
0
파일: logs_test.go 프로젝트: bac/juju
func (s *LogsSuite) TestAllLastSentLogTrackerNotController(c *gc.C) {
	st := s.NewStateForModelNamed(c, "test-model")
	defer st.Close()

	_, err := state.NewAllLastSentLogTracker(st, "test")

	c.Check(err, gc.ErrorMatches, `only the admin model can track all log records`)
}
예제 #3
0
파일: logs_test.go 프로젝트: bac/juju
func (s *LogsSuite) TestAllLastSentLogTrackerSetGet(c *gc.C) {
	tracker, err := state.NewAllLastSentLogTracker(s.State, "test-sink")
	c.Assert(err, jc.ErrorIsNil)
	defer tracker.Close()

	err = tracker.Set(10, 100)
	c.Assert(err, jc.ErrorIsNil)
	id1, ts1, err := tracker.Get()
	c.Assert(err, jc.ErrorIsNil)
	err = tracker.Set(20, 200)
	c.Assert(err, jc.ErrorIsNil)
	id2, ts2, err := tracker.Get()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(id1, gc.Equals, int64(10))
	c.Check(ts1, gc.Equals, int64(100))
	c.Check(id2, gc.Equals, int64(20))
	c.Check(ts2, gc.Equals, int64(200))
}