~nskaggs/+junk/juju-packaging-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/statushistory/pruner.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-27 20:23:11 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161027202311-sux4jk2o73p1d6rg
Re-add src

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2015 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package statushistory
 
5
 
 
6
import (
 
7
        "github.com/juju/juju/apiserver/common"
 
8
        "github.com/juju/juju/apiserver/params"
 
9
        "github.com/juju/juju/state"
 
10
 
 
11
        "github.com/juju/loggo"
 
12
)
 
13
 
 
14
func init() {
 
15
        common.RegisterStandardFacade("StatusHistory", 2, NewAPI)
 
16
}
 
17
 
 
18
var logger = loggo.GetLogger("juju.apiserver.statushistory")
 
19
 
 
20
// API is the concrete implementation of the Pruner endpoint..
 
21
type API struct {
 
22
        st         *state.State
 
23
        authorizer common.Authorizer
 
24
}
 
25
 
 
26
// NewAPI returns an API Instance.
 
27
func NewAPI(st *state.State, _ *common.Resources, auth common.Authorizer) (*API, error) {
 
28
        return &API{
 
29
                st:         st,
 
30
                authorizer: auth,
 
31
        }, nil
 
32
}
 
33
 
 
34
// Prune endpoint removes status history entries until
 
35
// only the N newest records per unit remain.
 
36
func (api *API) Prune(p params.StatusHistoryPruneArgs) error {
 
37
        if !api.authorizer.AuthModelManager() {
 
38
                return common.ErrPerm
 
39
        }
 
40
        return state.PruneStatusHistory(api.st, p.MaxLogsPerEntity)
 
41
}