本文整理汇总了Golang中github.com/juju/juju/state.State.UpdateUploadedCharm方法的典型用法代码示例。如果您正苦于以下问题:Golang State.UpdateUploadedCharm方法的具体用法?Golang State.UpdateUploadedCharm怎么用?Golang State.UpdateUploadedCharm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/state.State
的用法示例。
在下文中一共展示了State.UpdateUploadedCharm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: StoreCharmArchive
// StoreCharmArchive stores a charm archive in environment storage.
func StoreCharmArchive(st *state.State, curl *charm.URL, ch charm.Charm, r io.Reader, size int64, sha256 string) error {
storage := newStateStorage(st.EnvironUUID(), st.MongoSession())
storagePath, err := charmArchiveStoragePath(curl)
if err != nil {
return errors.Annotate(err, "cannot generate charm archive name")
}
if err := storage.Put(storagePath, r, size); err != nil {
return errors.Annotate(err, "cannot add charm to storage")
}
// Now update the charm data in state and mark it as no longer pending.
_, err = st.UpdateUploadedCharm(ch, curl, storagePath, sha256)
if err != nil {
alreadyUploaded := err == state.ErrCharmRevisionAlreadyModified ||
errors.Cause(err) == state.ErrCharmRevisionAlreadyModified ||
state.IsCharmAlreadyUploadedError(err)
if err := storage.Remove(storagePath); err != nil {
if alreadyUploaded {
logger.Errorf("cannot remove duplicated charm archive from storage: %v", err)
} else {
logger.Errorf("cannot remove unsuccessfully recorded charm archive from storage: %v", err)
}
}
if alreadyUploaded {
// Somebody else managed to upload and update the charm in
// state before us. This is not an error.
return nil
}
}
return nil
}
示例2: StoreCharmArchive
// StoreCharmArchive stores a charm archive in environment storage.
func StoreCharmArchive(st *state.State, archive CharmArchive) error {
storage := newStateStorage(st.ModelUUID(), st.MongoSession())
storagePath, err := charmArchiveStoragePath(archive.ID)
if err != nil {
return errors.Annotate(err, "cannot generate charm archive name")
}
if err := storage.Put(storagePath, archive.Data, archive.Size); err != nil {
return errors.Annotate(err, "cannot add charm to storage")
}
info := state.CharmInfo{
Charm: archive.Charm,
ID: archive.ID,
StoragePath: storagePath,
SHA256: archive.SHA256,
Macaroon: archive.Macaroon,
}
// Now update the charm data in state and mark it as no longer pending.
_, err = st.UpdateUploadedCharm(info)
if err != nil {
alreadyUploaded := err == state.ErrCharmRevisionAlreadyModified ||
errors.Cause(err) == state.ErrCharmRevisionAlreadyModified ||
state.IsCharmAlreadyUploadedError(err)
if err := storage.Remove(storagePath); err != nil {
if alreadyUploaded {
logger.Errorf("cannot remove duplicated charm archive from storage: %v", err)
} else {
logger.Errorf("cannot remove unsuccessfully recorded charm archive from storage: %v", err)
}
}
if alreadyUploaded {
// Somebody else managed to upload and update the charm in
// state before us. This is not an error.
return nil
}
}
return nil
}