本文整理汇总了Golang中github.com/juju/juju/api.Client.WatchAll方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.WatchAll方法的具体用法?Golang Client.WatchAll怎么用?Golang Client.WatchAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/api.Client
的用法示例。
在下文中一共展示了Client.WatchAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deployBundle
// deployBundle deploys the given bundle data using the given API client and
// charm store client. The deployment is not transactional, and its progress is
// notified using the given deployment logger.
func deployBundle(data *charm.BundleData, client *api.Client, csclient *csClient, repoPath string, conf *config.Config, log deploymentLogger) error {
if err := data.Verify(func(s string) error {
_, err := constraints.Parse(s)
return err
}); err != nil {
return errors.Annotate(err, "cannot deploy bundle")
}
// Retrieve bundle changes.
changes := bundlechanges.FromData(data)
numChanges := len(changes)
// Initialize the unit status.
status, err := client.Status(nil)
if err != nil {
return errors.Annotate(err, "cannot get environment status")
}
unitStatus := make(map[string]string, numChanges)
for _, serviceData := range status.Services {
for unit, unitData := range serviceData.Units {
unitStatus[unit] = unitData.Machine
}
}
// Instantiate a watcher used to follow the deployment progress.
watcher, err := client.WatchAll()
if err != nil {
return errors.Annotate(err, "cannot watch environment")
}
defer watcher.Stop()
// Instantiate the bundle handler.
h := &bundleHandler{
changes: changes,
results: make(map[string]string, numChanges),
client: client,
csclient: csclient,
repoPath: repoPath,
conf: conf,
log: log,
data: data,
unitStatus: unitStatus,
ignoredMachines: make(map[string]bool, len(data.Services)),
ignoredUnits: make(map[string]bool, len(data.Services)),
watcher: watcher,
}
// Deploy the bundle.
for _, change := range changes {
switch change := change.(type) {
case *bundlechanges.AddCharmChange:
err = h.addCharm(change.Id(), change.Params)
case *bundlechanges.AddMachineChange:
err = h.addMachine(change.Id(), change.Params)
case *bundlechanges.AddRelationChange:
err = h.addRelation(change.Id(), change.Params)
case *bundlechanges.AddServiceChange:
err = h.addService(change.Id(), change.Params)
case *bundlechanges.AddUnitChange:
err = h.addUnit(change.Id(), change.Params)
case *bundlechanges.SetAnnotationsChange:
err = h.setAnnotations(change.Id(), change.Params)
default:
return errors.Errorf("unknown change type: %T", change)
}
if err != nil {
return errors.Annotate(err, "cannot deploy bundle")
}
}
return nil
}