github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/state/api/logger/logger.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package logger 5 6 import ( 7 "fmt" 8 9 "launchpad.net/juju-core/state/api/base" 10 "launchpad.net/juju-core/state/api/params" 11 "launchpad.net/juju-core/state/api/watcher" 12 ) 13 14 // State provides access to an logger worker's view of the state. 15 type State struct { 16 caller base.Caller 17 } 18 19 // NewState returns a version of the state that provides functionality 20 // required by the logger worker. 21 func NewState(caller base.Caller) *State { 22 return &State{caller} 23 } 24 25 // LoggingConfig returns the loggo configuration string for the agent 26 // specified by agentTag. 27 func (st *State) LoggingConfig(agentTag string) (string, error) { 28 var results params.StringResults 29 args := params.Entities{ 30 Entities: []params.Entity{{Tag: agentTag}}, 31 } 32 err := st.caller.Call("Logger", "", "LoggingConfig", args, &results) 33 if err != nil { 34 // TODO: Not directly tested 35 return "", err 36 } 37 if len(results.Results) != 1 { 38 // TODO: Not directly tested 39 return "", fmt.Errorf("expected one result, got %d", len(results.Results)) 40 } 41 result := results.Results[0] 42 if err := result.Error; err != nil { 43 return "", err 44 } 45 return result.Result, nil 46 } 47 48 // WatchLoggingConfig returns a notify watcher that looks for changes in the 49 // logging-config for the agent specifed by agentTag. 50 func (st *State) WatchLoggingConfig(agentTag string) (watcher.NotifyWatcher, error) { 51 var results params.NotifyWatchResults 52 args := params.Entities{ 53 Entities: []params.Entity{{Tag: agentTag}}, 54 } 55 err := st.caller.Call("Logger", "", "WatchLoggingConfig", args, &results) 56 if err != nil { 57 // TODO: Not directly tested 58 return nil, err 59 } 60 if len(results.Results) != 1 { 61 // TODO: Not directly tested 62 return nil, fmt.Errorf("expected one result, got %d", len(results.Results)) 63 } 64 result := results.Results[0] 65 if result.Error != nil { 66 // TODO: Not directly tested 67 return nil, result.Error 68 } 69 w := watcher.NewNotifyWatcher(st.caller, result) 70 return w, nil 71 }