本文整理汇总了Golang中github.com/juju/names.ReadableString函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadableString函数的具体用法?Golang ReadableString怎么用?Golang ReadableString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadableString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: detachFilesystems
func detachFilesystems(ctx *context, attachments []storage.FilesystemAttachmentParams) error {
paramsBySource, filesystemSources, err := filesystemAttachmentParamsBySource(ctx, attachments)
if err != nil {
return errors.Trace(err)
}
for sourceName, params := range paramsBySource {
logger.Debugf("detaching filesystems: %v", params)
filesystemSource := filesystemSources[sourceName]
results, err := filesystemSource.DetachFilesystems(params)
if err != nil {
return errors.Annotatef(err, "detaching filesystems from source %q", sourceName)
}
for i, err := range results {
if err == nil {
continue
}
return errors.Annotatef(
err, "detaching %s from %s",
names.ReadableString(params[i].Filesystem),
names.ReadableString(params[i].Machine),
)
}
}
return nil
}
示例2: attachVolumes
// attachVolumes creates volume attachments with the specified parameters.
func attachVolumes(ctx *context, ops map[params.MachineStorageId]*attachVolumeOp) error {
volumeAttachmentParams := make([]storage.VolumeAttachmentParams, 0, len(ops))
for _, op := range ops {
volumeAttachmentParams = append(volumeAttachmentParams, op.args)
}
paramsBySource, volumeSources, err := volumeAttachmentParamsBySource(
ctx.environConfig, ctx.config.StorageDir, volumeAttachmentParams,
)
if err != nil {
return errors.Trace(err)
}
var reschedule []scheduleOp
var volumeAttachments []storage.VolumeAttachment
var statuses []params.EntityStatusArgs
for sourceName, volumeAttachmentParams := range paramsBySource {
logger.Debugf("attaching volumes: %+v", volumeAttachmentParams)
volumeSource := volumeSources[sourceName]
results, err := volumeSource.AttachVolumes(volumeAttachmentParams)
if err != nil {
return errors.Annotatef(err, "attaching volumes from source %q", sourceName)
}
for i, result := range results {
p := volumeAttachmentParams[i]
statuses = append(statuses, params.EntityStatusArgs{
Tag: p.Volume.String(),
Status: params.StatusAttached,
})
status := &statuses[len(statuses)-1]
if result.Error != nil {
// Reschedule the volume attachment.
id := params.MachineStorageId{
MachineTag: p.Machine.String(),
AttachmentTag: p.Volume.String(),
}
reschedule = append(reschedule, ops[id])
// Note: we keep the status as "attaching" to
// indicate that we will retry. When we distinguish
// between transient and permanent errors, we will
// set the status to "error" for permanent errors.
status.Status = params.StatusAttaching
status.Info = result.Error.Error()
logger.Debugf(
"failed to attach %s to %s: %v",
names.ReadableString(p.Volume),
names.ReadableString(p.Machine),
result.Error,
)
continue
}
volumeAttachments = append(volumeAttachments, *result.VolumeAttachment)
}
}
scheduleOperations(ctx, reschedule...)
setStatus(ctx, statuses)
if err := setVolumeAttachmentInfo(ctx, volumeAttachments); err != nil {
return errors.Trace(err)
}
return nil
}
示例3: createFilesystemAttachments
// createFilesystemAttachments creates filesystem attachments with the specified parameters.
func createFilesystemAttachments(
ctx *context,
params []storage.FilesystemAttachmentParams,
) ([]storage.FilesystemAttachment, error) {
paramsBySource, filesystemSources, err := filesystemAttachmentParamsBySource(ctx, params)
if err != nil {
return nil, errors.Trace(err)
}
var allFilesystemAttachments []storage.FilesystemAttachment
for sourceName, params := range paramsBySource {
logger.Debugf("attaching filesystems: %v", params)
filesystemSource := filesystemSources[sourceName]
results, err := filesystemSource.AttachFilesystems(params)
if err != nil {
return nil, errors.Annotatef(err, "attaching filesystems from source %q", sourceName)
}
for i, result := range results {
if result.Error != nil {
return nil, errors.Annotatef(
err, "attaching %s to %s",
names.ReadableString(params[i].Filesystem),
names.ReadableString(params[i].Machine),
)
}
allFilesystemAttachments = append(allFilesystemAttachments, *result.FilesystemAttachment)
}
}
return allFilesystemAttachments, nil
}
示例4: setVolumeAttachmentInfo
func setVolumeAttachmentInfo(ctx *context, volumeAttachments []storage.VolumeAttachment) error {
if len(volumeAttachments) == 0 {
return nil
}
// TODO(axw) we need to be able to list volume attachments in the
// provider, by environment, so that we can "harvest" them if they're
// unknown. This will take care of killing volumes that we fail to
// record in state.
errorResults, err := ctx.config.Volumes.SetVolumeAttachmentInfo(
volumeAttachmentsFromStorage(volumeAttachments),
)
if err != nil {
return errors.Annotate(err, "publishing volumes to state")
}
for i, result := range errorResults {
if result.Error != nil {
return errors.Annotatef(
result.Error, "publishing attachment of %s to %s to state",
names.ReadableString(volumeAttachments[i].Volume),
names.ReadableString(volumeAttachments[i].Machine),
)
}
// Record the volume attachment in the context.
id := params.MachineStorageId{
MachineTag: volumeAttachments[i].Machine.String(),
AttachmentTag: volumeAttachments[i].Volume.String(),
}
ctx.volumeAttachments[id] = volumeAttachments[i]
removePendingVolumeAttachment(ctx, id)
}
return nil
}
示例5: setFilesystemAttachmentInfo
func setFilesystemAttachmentInfo(ctx *context, filesystemAttachments []storage.FilesystemAttachment) error {
if len(filesystemAttachments) == 0 {
return nil
}
// TODO(axw) we need to be able to list filesystem attachments in the
// provider, by environment, so that we can "harvest" them if they're
// unknown. This will take care of killing filesystems that we fail to
// record in state.
errorResults, err := ctx.filesystemAccessor.SetFilesystemAttachmentInfo(
filesystemAttachmentsFromStorage(filesystemAttachments),
)
if err != nil {
return errors.Annotate(err, "publishing filesystems to state")
}
for i, result := range errorResults {
if result.Error != nil {
return errors.Annotatef(
result.Error, "publishing attachment of %s to %s to state",
names.ReadableString(filesystemAttachments[i].Filesystem),
names.ReadableString(filesystemAttachments[i].Machine),
)
}
// Record the filesystem attachment in the context.
ctx.filesystemAttachments[params.MachineStorageId{
MachineTag: filesystemAttachments[i].Machine.String(),
AttachmentTag: filesystemAttachments[i].Filesystem.String(),
}] = filesystemAttachments[i]
}
return nil
}
示例6: RetryProvisioning
func (f *fakeRetryProvisioningClient) RetryProvisioning(machines ...names.MachineTag) (
[]params.ErrorResult, error) {
if f.err != nil {
return nil, f.err
}
results := make([]params.ErrorResult, len(machines))
// For each of the machines passed in, verify that we have the
// id and that the info string is "broken".
for i, machine := range machines {
m, ok := f.m[machine.Id()]
if ok {
if m.info == "broken" {
// The real RetryProvisioning command sets the
// status data "transient" : true.
m.data["transient"] = true
} else {
results[i].Error = common.ServerError(
fmt.Errorf("%s is not in an error state",
names.ReadableString(machine)))
}
} else {
results[i].Error = common.ServerError(
errors.NotFoundf("machine %s", machine.Id()))
}
}
return results, nil
}
示例7: storageChanged
// storageChanged responds to unit storage changes.
func (w *RemoteStateWatcher) storageChanged(keys []string) error {
tags := make([]names.StorageTag, len(keys))
for i, key := range keys {
tags[i] = names.NewStorageTag(key)
}
ids := make([]params.StorageAttachmentId, len(keys))
for i, tag := range tags {
ids[i] = params.StorageAttachmentId{
StorageTag: tag.String(),
UnitTag: w.unit.Tag().String(),
}
}
results, err := w.st.StorageAttachmentLife(ids)
if err != nil {
return errors.Trace(err)
}
w.mu.Lock()
defer w.mu.Unlock()
for i, result := range results {
tag := tags[i]
if result.Error == nil {
if storageSnapshot, ok := w.current.Storage[tag]; ok {
// We've previously started a watcher for this storage
// attachment, so all we needed to do was update the
// lifecycle state.
storageSnapshot.Life = result.Life
w.current.Storage[tag] = storageSnapshot
continue
}
// We haven't seen this storage attachment before, so start
// a watcher now; add it to our catacomb in case of mishap;
// and wait for the initial event.
saw, err := w.st.WatchStorageAttachment(tag, w.unit.Tag())
if err != nil {
return errors.Annotate(err, "watching storage attachment")
}
if err := w.catacomb.Add(saw); err != nil {
return errors.Trace(err)
}
if err := w.watchStorageAttachment(tag, result.Life, saw); err != nil {
return errors.Trace(err)
}
} else if params.IsCodeNotFound(result.Error) {
if watcher, ok := w.storageAttachmentWatchers[tag]; ok {
// already under catacomb management, any error tracked already
worker.Stop(watcher)
delete(w.storageAttachmentWatchers, tag)
}
delete(w.current.Storage, tag)
} else {
return errors.Annotatef(
result.Error, "getting life of %s attachment",
names.ReadableString(tag),
)
}
}
return nil
}
示例8: createFilesystems
// createFilesystems creates filesystems with the specified parameters.
func createFilesystems(ctx *context, params []storage.FilesystemParams) ([]storage.Filesystem, error) {
// TODO(axw) later we may have multiple instantiations (sources)
// for a storage provider, e.g. multiple Ceph installations. For
// now we assume a single source for each provider type, with no
// configuration.
// Create filesystem sources.
filesystemSources := make(map[string]storage.FilesystemSource)
for _, params := range params {
sourceName := string(params.Provider)
if _, ok := filesystemSources[sourceName]; ok {
continue
}
if params.Volume != (names.VolumeTag{}) {
filesystemSources[sourceName] = ctx.managedFilesystemSource
continue
}
filesystemSource, err := filesystemSource(
ctx.environConfig, ctx.storageDir, sourceName, params.Provider,
)
if err != nil {
return nil, errors.Annotate(err, "getting filesystem source")
}
filesystemSources[sourceName] = filesystemSource
}
// Validate and gather filesystem parameters.
paramsBySource := make(map[string][]storage.FilesystemParams)
for _, params := range params {
sourceName := string(params.Provider)
filesystemSource := filesystemSources[sourceName]
err := filesystemSource.ValidateFilesystemParams(params)
if err != nil {
// TODO(axw) we should set an error status for params.Tag
// here, and we should retry periodically.
logger.Errorf("ignoring invalid filesystem: %v", err)
continue
}
paramsBySource[sourceName] = append(paramsBySource[sourceName], params)
}
var allFilesystems []storage.Filesystem
for sourceName, params := range paramsBySource {
logger.Debugf("creating filesystems: %v", params)
filesystemSource := filesystemSources[sourceName]
results, err := filesystemSource.CreateFilesystems(params)
if err != nil {
return nil, errors.Annotatef(err, "creating filesystems from source %q", sourceName)
}
for i, result := range results {
if result.Error != nil {
return nil, errors.Annotatef(result.Error, "creating %s", names.ReadableString(params[i].Tag))
}
allFilesystems = append(allFilesystems, *result.Filesystem)
}
}
return allFilesystems, nil
}
示例9: AttachFilesystems
// AttachFilesystems is defined on the FilesystemSource interface.
func (s *rootfsFilesystemSource) AttachFilesystems(args []storage.FilesystemAttachmentParams) ([]storage.FilesystemAttachment, error) {
attachments := make([]storage.FilesystemAttachment, len(args))
for i, arg := range args {
attachment, err := s.attachFilesystem(arg)
if err != nil {
return nil, errors.Annotatef(err, "attaching %s", names.ReadableString(arg.Filesystem))
}
attachments[i] = attachment
}
return attachments, nil
}
示例10: removeEntities
// removeEntities removes each specified Dead entity from state.
func removeEntities(ctx *context, tags []names.Tag) error {
logger.Debugf("removing entities: %v", tags)
errorResults, err := ctx.life.Remove(tags)
if err != nil {
return errors.Annotate(err, "removing storage entities")
}
for i, result := range errorResults {
if result.Error != nil {
return errors.Annotatef(result.Error, "removing %s from state", names.ReadableString(tags[i]))
}
}
return nil
}
示例11: volumeStorageAttachmentInfo
func volumeStorageAttachmentInfo(
st StorageInterface,
storageInstance state.StorageInstance,
machineTag names.MachineTag,
) (*storage.StorageAttachmentInfo, error) {
storageTag := storageInstance.StorageTag()
volume, err := st.StorageInstanceVolume(storageTag)
if err != nil {
return nil, errors.Annotate(err, "getting volume")
}
volumeInfo, err := volume.Info()
if err != nil {
return nil, errors.Annotate(err, "getting volume info")
}
volumeAttachment, err := st.VolumeAttachment(machineTag, volume.VolumeTag())
if err != nil {
return nil, errors.Annotate(err, "getting volume attachment")
}
volumeAttachmentInfo, err := volumeAttachment.Info()
if err != nil {
return nil, errors.Annotate(err, "getting volume attachment info")
}
blockDevices, err := st.BlockDevices(machineTag)
if err != nil {
return nil, errors.Annotate(err, "getting block devices")
}
blockDevice, ok := MatchingBlockDevice(
blockDevices,
volumeInfo,
volumeAttachmentInfo,
)
if !ok {
// We must not say that a block-kind storage attachment is
// provisioned until its block device has shown up on the
// machine, otherwise the charm may attempt to use it and
// fail.
return nil, errors.NotProvisionedf("%v", names.ReadableString(storageTag))
}
devicePath, err := volumeAttachmentDevicePath(
volumeInfo,
volumeAttachmentInfo,
*blockDevice,
)
if err != nil {
return nil, errors.Trace(err)
}
return &storage.StorageAttachmentInfo{
storage.StorageKindBlock,
devicePath,
}, nil
}
示例12: processDeadFilesystems
// processDeadFilesystems processes the FilesystemResults for Dead filesystems,
// deprovisioning filesystems and removing from state as necessary.
func processDeadFilesystems(ctx *context, tags []names.FilesystemTag, filesystemResults []params.FilesystemResult) error {
for _, tag := range tags {
delete(ctx.pendingFilesystems, tag)
}
var destroy []names.FilesystemTag
var remove []names.Tag
for i, result := range filesystemResults {
tag := tags[i]
if result.Error == nil {
logger.Debugf("filesystem %s is provisioned, queuing for deprovisioning", tag.Id())
filesystem, err := filesystemFromParams(result.Result)
if err != nil {
return errors.Annotate(err, "getting filesystem info")
}
ctx.filesystems[tag] = filesystem
destroy = append(destroy, tag)
continue
}
if params.IsCodeNotProvisioned(result.Error) {
logger.Debugf("filesystem %s is not provisioned, queuing for removal", tag.Id())
remove = append(remove, tag)
continue
}
return errors.Annotatef(result.Error, "getting filesystem information for filesystem %s", tag.Id())
}
if len(destroy)+len(remove) == 0 {
return nil
}
if len(destroy) > 0 {
errorResults, err := destroyFilesystems(ctx, destroy)
if err != nil {
return errors.Annotate(err, "destroying filesystems")
}
for i, tag := range destroy {
if err := errorResults[i]; err != nil {
return errors.Annotatef(err, "destroying %s", names.ReadableString(tag))
}
remove = append(remove, tag)
}
}
if err := removeEntities(ctx, remove); err != nil {
return errors.Annotate(err, "removing filesystems from state")
}
return nil
}
示例13: prepareForUpgrade
func (w *upgradesteps) prepareForUpgrade() (*state.UpgradeInfo, error) {
logger.Infof("checking that upgrade can proceed")
if err := w.preUpgradeSteps(w.st, w.agent.CurrentConfig(), w.st != nil, w.isMaster); err != nil {
return nil, errors.Annotatef(err, "%s cannot be upgraded", names.ReadableString(w.tag))
}
if !w.isStateServer {
return nil, nil
}
logger.Infof("signalling that this state server is ready for upgrade")
info, err := w.st.EnsureUpgradeInfo(w.tag.Id(), w.fromVersion, w.toVersion)
if err != nil {
return nil, errors.Trace(err)
}
// State servers need to wait for other state servers to be ready
// to run the upgrade steps.
logger.Infof("waiting for other state servers to be ready for upgrade")
if err := w.waitForOtherStateServers(info); err != nil {
if err == tomb.ErrDying {
logger.Warningf(`stopped waiting for other state servers: %v`, err)
return nil, err
}
logger.Errorf(`aborted wait for other state servers: %v`, err)
// If master, trigger a rollback to the previous agent version.
if w.isMaster {
logger.Errorf("downgrading environment agent version to %v due to aborted upgrade",
w.fromVersion)
if rollbackErr := w.st.SetEnvironAgentVersion(w.fromVersion); rollbackErr != nil {
logger.Errorf("rollback failed: %v", rollbackErr)
return nil, errors.Annotate(rollbackErr, "failed to roll back desired agent version")
}
}
return nil, errors.Annotate(err, "aborted wait for other state servers")
}
if w.isMaster {
logger.Infof("finished waiting - all state servers are ready to run upgrade steps")
} else {
logger.Infof("finished waiting - the master has completed its upgrade steps")
}
return info, nil
}
示例14: TestReadableString
func (*tagSuite) TestReadableString(c *gc.C) {
var readableStringTests = []struct {
tag names.Tag
result string
}{{
tag: nil,
result: "",
}, {
tag: names.NewMachineTag("0"),
result: "machine 0",
}, {
tag: names.NewUnitTag("wordpress/2"),
result: "unit wordpress/2",
}}
for i, test := range readableStringTests {
c.Logf("test %d: expected result %q", i, test.result)
resultStr := names.ReadableString(test.tag)
c.Assert(resultStr, gc.Equals, test.result)
}
}
示例15: createVolumeDetailsList
func createVolumeDetailsList(
st storageAccess,
volumes []state.Volume,
attachments map[names.VolumeTag][]state.VolumeAttachment,
) ([]params.VolumeDetails, error) {
if len(volumes) == 0 {
return nil, nil
}
results := make([]params.VolumeDetails, len(volumes))
for i, v := range volumes {
details, err := createVolumeDetails(st, v, attachments[v.VolumeTag()])
if err != nil {
return nil, errors.Annotatef(
err, "getting details for %s",
names.ReadableString(v.VolumeTag()),
)
}
results[i] = *details
}
return results, nil
}