本文整理汇总了Golang中github.com/coreos/rkt/store.Store类的典型用法代码示例。如果您正苦于以下问题:Golang Store类的具体用法?Golang Store怎么用?Golang Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Store类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getReferencedImgs
func getReferencedImgs(s *store.Store) (map[string]struct{}, error) {
imgs := map[string]struct{}{}
walkErrors := []error{}
// Consider pods in preparing, prepared, run, exitedgarbage state
if err := walkPods(includeMostDirs, func(p *pod) {
appImgs, err := p.getAppsHashes()
if err != nil {
// Ignore errors reading/parsing pod file
return
}
for _, appImg := range appImgs {
key, err := s.ResolveKey(appImg.String())
if err != nil && err != store.ErrKeyNotFound {
walkErrors = append(walkErrors, fmt.Errorf("bad imageID %q in pod definition: %v", appImg.String(), err))
return
}
imgs[key] = struct{}{}
}
}); err != nil {
return nil, fmt.Errorf("failed to get pod handles: %v", err)
}
if len(walkErrors) > 0 {
return nil, fmt.Errorf("errors occured walking pods. errors: %v", walkErrors)
}
return imgs, nil
}
示例2: getTmpROC
// getTmpROC returns a removeOnClose instance wrapping a temporary
// file provided by the passed store. The actual file name is based on
// a hash of the passed path.
func getTmpROC(s *store.Store, path string) (*removeOnClose, error) {
h := sha512.New()
h.Write([]byte(path))
pathHash := s.HashToKey(h)
tmp, err := s.TmpNamedFile(pathHash)
if err != nil {
return nil, errwrap.Wrap(errors.New("error setting up temporary file"), err)
}
// let's lock the file to avoid concurrent writes to the temporary file, it
// will go away when removing the temp file
_, err = lock.TryExclusiveLock(tmp.Name(), lock.RegFile)
if err != nil {
if err != lock.ErrLocked {
return nil, errwrap.Wrap(errors.New("failed to lock temporary file"), err)
}
log.Printf("another rkt instance is downloading this file, waiting...")
_, err = lock.ExclusiveLock(tmp.Name(), lock.RegFile)
if err != nil {
return nil, errwrap.Wrap(errors.New("failed to lock temporary file"), err)
}
}
roc := &removeOnClose{File: tmp}
return roc, nil
}
示例3: gcTreeStore
// gcTreeStore removes all treeStoreIDs not referenced by any non garbage
// collected pod from the store.
func gcTreeStore(s *store.Store) error {
// Take an exclusive lock to block other pods being created.
// This is needed to avoid races between the below steps (getting the
// list of referenced treeStoreIDs, getting the list of treeStoreIDs
// from the store, removal of unreferenced treeStoreIDs) and new
// pods/treeStores being created/referenced
keyLock, err := lock.ExclusiveKeyLock(lockDir(), common.PrepareLock)
if err != nil {
return fmt.Errorf("cannot get exclusive prepare lock: %v", err)
}
defer keyLock.Close()
referencedTreeStoreIDs, err := getReferencedTreeStoreIDs()
if err != nil {
return fmt.Errorf("cannot get referenced treestoreIDs: %v", err)
}
treeStoreIDs, err := s.GetTreeStoreIDs()
if err != nil {
return fmt.Errorf("cannot get treestoreIDs from the store: %v", err)
}
for _, treeStoreID := range treeStoreIDs {
if _, ok := referencedTreeStoreIDs[treeStoreID]; !ok {
if err := s.RemoveTreeStore(treeStoreID); err != nil {
stderr("rkt: error removing treestore %q: %v", treeStoreID, err)
} else {
stderr("rkt: removed treestore %q", treeStoreID)
}
}
}
return nil
}
示例4: getTmpROC
// getTmpROC returns a removeOnClose instance wrapping a temporary
// file provided by the passed store. The actual file name is based on
// a hash of the passed path.
func getTmpROC(s *store.Store, path string) (*removeOnClose, error) {
h := sha512.New()
h.Write([]byte(path))
pathHash := s.HashToKey(h)
tmp, err := s.TmpNamedFile(pathHash)
if err != nil {
return nil, errwrap.Wrap(errors.New("error setting up temporary file"), err)
}
roc := &removeOnClose{File: tmp}
return roc, nil
}
示例5: rmImages
func rmImages(s *store.Store, images []string) error {
done := 0
errors := 0
staleErrors := 0
for _, pkey := range images {
errors++
h, err := types.NewHash(pkey)
if err != nil {
stderr("rkt: wrong image ID %q: %v", pkey, err)
continue
}
key, err := s.ResolveKey(h.String())
if err != nil {
stderr("rkt: image ID %q not valid: %v", pkey, err)
continue
}
if key == "" {
stderr("rkt: image ID %q doesn't exist", pkey)
continue
}
if err = s.RemoveACI(key); err != nil {
if serr, ok := err.(*store.StoreRemovalError); ok {
staleErrors++
stderr("rkt: some files cannot be removed for image ID %q: %v", pkey, serr)
} else {
stderr("rkt: error removing aci for image ID %q: %v", pkey, err)
continue
}
}
stdout("rkt: successfully removed aci for image ID: %q", pkey)
errors--
done++
}
if done > 0 {
stderr("rkt: %d image(s) successfully removed", done)
}
// If anything didn't complete, return exit status of 1
if (errors + staleErrors) > 0 {
if staleErrors > 0 {
stderr("rkt: %d image(s) removed but left some stale files", staleErrors)
}
if errors > 0 {
stderr("rkt: %d image(s) cannot be removed", errors)
}
return fmt.Errorf("error(s) found while removing images")
}
return nil
}
示例6: getStoreKeyFromApp
func getStoreKeyFromApp(s *store.Store, img string) (string, error) {
app, err := discovery.NewAppFromString(img)
if err != nil {
return "", fmt.Errorf("cannot parse the image name: %v", err)
}
labels, err := types.LabelsFromMap(app.Labels)
if err != nil {
return "", fmt.Errorf("invalid labels in the name: %v", err)
}
key, err := s.GetACI(app.Name, labels)
if err != nil {
return "", fmt.Errorf("cannot find image: %v", err)
}
return key, nil
}
示例7: getStoreKeyFromAppOrHash
func getStoreKeyFromAppOrHash(s *store.Store, input string) (string, error) {
var key string
if _, err := types.NewHash(input); err == nil {
key, err = s.ResolveKey(input)
if err != nil {
return "", fmt.Errorf("cannot resolve key: %v", err)
}
} else {
key, err = getStoreKeyFromApp(s, input)
if err != nil {
return "", fmt.Errorf("cannot find image: %v", err)
}
}
return key, nil
}
示例8: getStoreKeyFromAppOrHash
func getStoreKeyFromAppOrHash(s *store.Store, input string) (string, error) {
var key string
if _, err := types.NewHash(input); err == nil {
key, err = s.ResolveKey(input)
if err != nil {
return "", errwrap.Wrap(errors.New("cannot resolve image ID"), err)
}
} else {
key, err = getStoreKeyFromApp(s, input)
if err != nil {
return "", errwrap.Wrap(errors.New("cannot find image"), err)
}
}
return key, nil
}
示例9: aciInfoToV1AlphaAPIImage
// aciInfoToV1AlphaAPIImage takes an aciInfo object and construct the v1alpha.Image object.
// It also returns the image manifest of the image.
func aciInfoToV1AlphaAPIImage(store *store.Store, aciInfo *store.ACIInfo) (*v1alpha.Image, *schema.ImageManifest, error) {
manifest, err := store.GetImageManifestJSON(aciInfo.BlobKey)
if err != nil {
log.Printf("Failed to read the image manifest: %v", err)
return nil, nil, err
}
var im schema.ImageManifest
if err = json.Unmarshal(manifest, &im); err != nil {
log.Printf("Failed to unmarshal image manifest: %v", err)
return nil, nil, err
}
version, ok := im.Labels.Get("version")
if !ok {
version = "latest"
}
return &v1alpha.Image{
BaseFormat: &v1alpha.ImageFormat{
// Only support appc image now. If it's a docker image, then it
// will be transformed to appc before storing in the disk store.
Type: v1alpha.ImageType_IMAGE_TYPE_APPC,
Version: schema.AppContainerVersion.String(),
},
Id: aciInfo.BlobKey,
Name: im.Name.String(),
Version: version,
ImportTimestamp: aciInfo.ImportTime.Unix(),
Manifest: manifest,
}, &im, nil
}
示例10: ExtractLayerInfo
// ExtractLayerInfo extracts the image name and ID from a path to an ACI
func ExtractLayerInfo(store *store.Store, in string) (types.Dependency, error) {
im, err := GetManifestFromImage(in)
if err != nil {
return types.Dependency{}, fmt.Errorf("error getting manifest from image (%v): %v", in, err)
}
inFile, err := os.Open(in)
if err != nil {
return types.Dependency{}, fmt.Errorf("error opening ACI: %v", err)
}
defer inFile.Close()
inImageID, err := store.WriteACI(inFile, false)
if err != nil {
return types.Dependency{}, fmt.Errorf("error writing ACI into the tree store: %v", err)
}
hash, err := types.NewHash(inImageID)
if err != nil {
return types.Dependency{}, fmt.Errorf("error creating hash from an image ID (%s): %v", hash, err)
}
return types.Dependency{
ImageName: im.Name,
ImageID: hash,
}, nil
}
示例11: aciInfoToV1AlphaAPIImage
// aciInfoToV1AlphaAPIImage takes an aciInfo object and construct the v1alpha.Image
// object. It will also get and return the image manifest.
// Note that v1alpha.Image.Manifest field is not set by this function.
func aciInfoToV1AlphaAPIImage(store *store.Store, aciInfo *store.ACIInfo) (*v1alpha.Image, *schema.ImageManifest, error) {
imgManifest, err := store.GetImageManifest(aciInfo.BlobKey)
if err != nil {
return nil, nil, err
}
data, err := json.Marshal(imgManifest)
if err != nil {
return nil, nil, err
}
version, ok := imgManifest.Labels.Get("version")
if !ok {
version = "latest"
}
return &v1alpha.Image{
BaseFormat: &v1alpha.ImageFormat{
// Only support appc image now. If it's a docker image, then it
// will be transformed to appc before storing in the disk store.
Type: v1alpha.ImageType_IMAGE_TYPE_APPC,
Version: schema.AppContainerVersion.String(),
},
Id: aciInfo.BlobKey,
Name: imgManifest.Name.String(),
Version: version,
ImportTimestamp: aciInfo.ImportTime.Unix(),
Manifest: data,
}, imgManifest, nil
}
示例12: renderInStore
// renderInStore renders a ACI specified by `filename` in the given tree store,
// and returns the hash (image ID) of the rendered ACI.
func renderInStore(s *store.Store, filename string) (string, error) {
// Put the ACI into the store
f, err := os.Open(filename)
if err != nil {
return "", fmt.Errorf("Could not open ACI image: %s", err)
}
key, err := s.WriteACI(f, false)
if err != nil {
return "", fmt.Errorf("Could not open ACI: %s", key)
}
// Render the ACI
if err := s.RenderTreeStore(key, false); err != nil {
return "", fmt.Errorf("Could not render tree store: %s", err)
}
return key, err
}
示例13: gcStore
func gcStore(s *store.Store, gracePeriod time.Duration) error {
var imagesToRemove []string
aciinfos, err := s.GetAllACIInfos([]string{"lastused"}, true)
if err != nil {
return fmt.Errorf("Failed to get aciinfos: %v", err)
}
for _, ai := range aciinfos {
if time.Now().Sub(ai.LastUsed) <= gracePeriod {
break
}
imagesToRemove = append(imagesToRemove, ai.BlobKey)
}
if err := rmImages(s, imagesToRemove); err != nil {
return err
}
return nil
}
示例14: getImageInfo
// getImageInfo for a given image ID, returns the *v1alpha.Image object.
func getImageInfo(store *store.Store, imageID string) (*v1alpha.Image, error) {
key, err := store.ResolveKey(imageID)
if err != nil {
stderr.PrintE(fmt.Sprintf("failed to resolve the image ID %q", imageID), err)
return nil, err
}
aciInfo, err := store.GetACIInfoWithBlobKey(key)
if err != nil {
stderr.PrintE(fmt.Sprintf("failed to get ACI info for image %q", key), err)
return nil, err
}
image, _, err := aciInfoToV1AlphaAPIImage(store, aciInfo)
if err != nil {
stderr.PrintE(fmt.Sprintf("failed to convert ACI to v1alphaAPIImage for image %q", key), err)
return nil, err
}
return image, nil
}
示例15: getStoreKeyFromApp
func getStoreKeyFromApp(s *store.Store, img string) (string, error) {
app, err := discovery.NewAppFromString(img)
if err != nil {
return "", fmt.Errorf("cannot parse the image name %q: %v", img, err)
}
labels, err := types.LabelsFromMap(app.Labels)
if err != nil {
return "", fmt.Errorf("invalid labels in the image %q: %v", img, err)
}
key, err := s.GetACI(app.Name, labels)
if err != nil {
switch err.(type) {
case store.ACINotFoundError:
return "", err
default:
return "", fmt.Errorf("cannot find image %q: %v", img, err)
}
}
return key, nil
}