Example #1
0
// start is a StartFunc for a Worker manifold.
func (config ManifoldConfig) start(context dependency.Context) (worker.Worker, error) {
	if err := config.validate(); err != nil {
		return nil, errors.Trace(err)
	}
	var apiCaller base.APICaller
	if err := context.Get(config.APICallerName, &apiCaller); err != nil {
		return nil, errors.Trace(err)
	}
	facade, err := config.NewFacade(apiCaller)
	if err != nil {
		return nil, errors.Trace(err)
	}
	modelTag, err := apiCaller.ModelTag()
	if err != nil {
		return nil, errors.Trace(err)
	}
	worker, err := config.NewWorker(Config{
		Facade: facade,
		Model:  modelTag.Id(),
		Check:  config.Check,
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	return worker, nil
}
Example #2
0
// makeWatcherAPICaller creates a watcherAPICall function for a given facade name
// and watcherId.
func makeWatcherAPICaller(caller base.APICaller, facadeName, watcherId string) watcherAPICall {
	bestVersion := caller.BestFacadeVersion(facadeName)
	return func(request string, result interface{}) error {
		return caller.APICall(facadeName, bestVersion,
			watcherId, request, nil, &result)
	}
}
Example #3
0
func (r resources) newUnitFacadeClient(unitName string, caller base.APICaller) (context.APIClient, error) {

	facadeCaller := base.NewFacadeCallerForVersion(caller, context.HookContextFacade, internalserver.FacadeVersion)
	httpClient, err := caller.HTTPClient()
	if err != nil {
		return nil, errors.Trace(err)
	}
	unitHTTPClient := internalclient.NewUnitHTTPClient(httpClient, unitName)

	return internalclient.NewUnitFacadeClient(facadeCaller, unitHTTPClient), nil
}
Example #4
0
// NewClient creates a new client for accessing the undertaker API.
func NewClient(caller base.APICaller, newWatcher NewWatcherFunc) (*Client, error) {
	modelTag, ok := caller.ModelTag()
	if !ok {
		return nil, errors.New("undertaker client is not appropriate for controller-only API")
	}
	return &Client{
		modelTag:   modelTag,
		caller:     base.NewFacadeCaller(caller, "Undertaker"),
		newWatcher: newWatcher,
	}, nil
}
Example #5
0
// NewClient creates a new client for accessing the undertaker API.
func NewClient(caller base.APICaller, newWatcher NewWatcherFunc) (*Client, error) {
	modelTag, err := caller.ModelTag()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return &Client{
		modelTag:   modelTag,
		caller:     base.NewFacadeCaller(caller, "Undertaker"),
		newWatcher: newWatcher,
	}, nil
}
Example #6
0
// NewClient creates a new client for accessing the metricsmanager api
func NewClient(apiCaller base.APICaller) (*Client, error) {
	modelTag, err := apiCaller.ModelTag()
	if err != nil {
		return nil, errors.Trace(err)
	}
	facade := base.NewFacadeCaller(apiCaller, "MetricsManager")
	return &Client{
		modelTag: modelTag,
		facade:   facade,
	}, nil
}
Example #7
0
File: client.go Project: bac/juju
// NewClient creates a new client for accessing the metricsmanager api
func NewClient(apiCaller base.APICaller) (*Client, error) {
	modelTag, ok := apiCaller.ModelTag()
	if !ok {
		return nil, errors.New("metricsmanager client is not appropriate for controller-only API")

	}
	facade := base.NewFacadeCaller(apiCaller, "MetricsManager")
	return &Client{
		modelTag: modelTag,
		facade:   facade,
	}, nil
}
Example #8
0
// NewAPI creates a new client-side machine undertaker facade.
func NewAPI(caller base.APICaller, newWatcher NewWatcherFunc) (*API, error) {
	modelTag, ok := caller.ModelTag()
	if !ok {
		return nil, errors.New("machine undertaker client requires a model API connection")
	}
	api := API{
		facade:     base.NewFacadeCaller(caller, "MachineUndertaker"),
		modelTag:   modelTag,
		newWatcher: newWatcher,
	}
	return &api, nil
}
Example #9
0
File: api.go Project: bac/juju
// NewAPI returns a new API client for the Singular facade. It exposes methods
// for claiming and observing administration responsibility for the apiCaller's
// model, on behalf of the supplied controller machine.
func NewAPI(apiCaller base.APICaller, controllerTag names.MachineTag) (*API, error) {
	controllerId := controllerTag.Id()
	if !names.IsValidMachine(controllerId) {
		return nil, errors.NotValidf("controller tag")
	}
	modelTag, ok := apiCaller.ModelTag()
	if !ok {
		return nil, errors.New("cannot use singular API on controller-only connection")
	}
	facadeCaller := base.NewFacadeCaller(apiCaller, "Singular")
	return &API{
		modelTag:      modelTag,
		controllerTag: controllerTag,
		facadeCaller:  facadeCaller,
	}, nil
}
Example #10
0
File: api.go Project: pmatulis/juju
// NewAPI returns a new API client for the Singular facade. It exposes methods
// for claiming and observing administration responsibility for the apiCaller's
// model, on behalf of the supplied controller machine.
func NewAPI(apiCaller base.APICaller, controllerTag names.MachineTag) (*API, error) {
	controllerId := controllerTag.Id()
	if !names.IsValidMachine(controllerId) {
		return nil, errors.NotValidf("controller tag")
	}
	modelTag, err := apiCaller.ModelTag()
	if err != nil {
		return nil, errors.Trace(err)
	}
	facadeCaller := base.NewFacadeCaller(apiCaller, "Singular")
	return &API{
		modelTag:      modelTag,
		controllerTag: controllerTag,
		facadeCaller:  facadeCaller,
	}, nil
}