-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request juju#4539 from ericsnowcurrently/resources-unified…
…-poller Merge the resources polling worker into the charm revision updater. This patch combines the two workers. It cleans up some of the existing code in the process. (Review request: http://reviews.vapour.ws/r/3975/) Conflicts: cmd/juju/charmcmd/store.go cmd/juju/charmcmd/sub.go cmd/jujud/agent/machine.go cmd/jujud/agent/machine_test.go dependencies.tsv resource/resourceadapters/fakes.go
- Loading branch information
Showing
26 changed files
with
902 additions
and
652 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2016 Canonical Ltd. | ||
// Licensed under the AGPLv3, see LICENCE file for details. | ||
|
||
package charmrevisionupdater | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/juju/errors" | ||
"github.com/juju/names" | ||
|
||
"github.com/juju/juju/charmstore" | ||
"github.com/juju/juju/state" | ||
) | ||
|
||
// LatestCharmHandler exposes the functionality needed to deal with | ||
// the latest info (from the store) for a charm. | ||
type LatestCharmHandler interface { | ||
// HandleLatest deals with the given charm info, treating it as the | ||
// most up-to-date information for the charms most recent revision. | ||
HandleLatest(names.ServiceTag, charmstore.CharmInfo) error | ||
} | ||
|
||
type newHandlerFunc func(*state.State) (LatestCharmHandler, error) | ||
|
||
var registeredHandlers = map[string]newHandlerFunc{} | ||
|
||
// RegisterLatestCharmHandler adds the factory func for the identified | ||
// handler to the handler registry. | ||
func RegisterLatestCharmHandler(name string, newHandler newHandlerFunc) error { | ||
if _, ok := registeredHandlers[name]; ok { | ||
msg := fmt.Sprintf(`"latest charm" handler %q already registered`, name) | ||
return errors.NewAlreadyExists(nil, msg) | ||
} | ||
registeredHandlers[name] = newHandler | ||
return nil | ||
} | ||
|
||
func createHandlers(st *state.State) ([]LatestCharmHandler, error) { | ||
var handlers []LatestCharmHandler | ||
for _, newHandler := range registeredHandlers { | ||
handler, err := newHandler(st) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
handlers = append(handlers, handler) | ||
} | ||
return handlers, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.