Beispiel #1
0
// NewRespositoryCache will create a new repoCache or rehydrate
// an existing repoCache from the portlayer k/v store
func NewRepositoryCache(client *client.PortLayer) error {
	defer trace.End(trace.Begin(""))

	rCache.client = client

	val, err := kv.Get(client, repoKey)
	if err != nil && err != kv.ErrKeyNotFound {
		return err
	}
	if val != "" {
		if err = json.Unmarshal([]byte(val), rCache); err != nil {
			return fmt.Errorf("Failed to unmarshal repository cache: %s", err)
		}
		// hydrate refByIDCache
		for _, repository := range rCache.Repositories {
			for refStr, refID := range repository {
				ref, _ := reference.ParseNamed(refStr)
				if rCache.referencesByIDCache[refID] == nil {
					rCache.referencesByIDCache[refID] = make(map[string]reference.Named)
				}
				rCache.referencesByIDCache[refID][refStr] = ref
			}
		}
		// hydrate image -> layer cache
		for image, layer := range rCache.Layers {
			rCache.images[image] = layer
		}

		log.Infof("found %d repositories", len(rCache.Repositories))
		log.Infof("found %d image layers", len(rCache.Layers))
	}
	return nil
}
Beispiel #2
0
// InitializeImageCache will create a new image cache or rehydrate an
// existing image cache from the portlayer k/v store
func InitializeImageCache(client *client.PortLayer) error {
	defer trace.End(trace.Begin(""))

	imageCache.client = client

	log.Debugf("Initializing image cache")

	val, err := kv.Get(client, imageCacheKey)
	if err != nil && err != kv.ErrKeyNotFound {
		return err
	}

	i := struct {
		IDIndex     *truncindex.TruncIndex
		CacheByID   map[string]*metadata.ImageConfig
		CacheByName map[string]*metadata.ImageConfig
	}{}

	if val != "" {

		if err = json.Unmarshal([]byte(val), &i); err != nil {
			return fmt.Errorf("Failed to unmarshal image cache: %s", err)
		}

		// populate the trie with IDs
		for k := range i.CacheByID {
			imageCache.iDIndex.Add(k)
		}

		imageCache.cacheByID = i.CacheByID
		imageCache.cacheByName = i.CacheByName
	}

	return nil
}
Beispiel #3
0
// InitializeLayerCache will create a new layer cache or rehydrate an
// existing layer cache from the portlayer k/v store
func InitializeLayerCache(client *client.PortLayer) error {
	defer trace.End(trace.Begin(""))

	log.Debugf("Initializing layer cache")

	layerCache.client = client

	val, err := kv.Get(client, layerCacheKey)
	if err != nil && err != kv.ErrKeyNotFound {
		return err
	}

	l := struct {
		Layers map[string]*ImageWithMeta
	}{}

	if val != "" {
		if err = json.Unmarshal([]byte(val), &l); err != nil {
			return fmt.Errorf("Failed to unmarshal layer cache: %s", err)
		}

		layerCache.layers = l.Layers
	}

	return nil
}