Search in sources :

Example 1 with LayerPropertyNotFoundException

use of com.google.cloud.tools.jib.image.LayerPropertyNotFoundException in project jib by google.

the class CacheMetadataTranslator method fromTemplate.

/**
 * Translates {@link CacheMetadataTemplate} to {@link CacheMetadata}.
 */
static CacheMetadata fromTemplate(CacheMetadataTemplate template, Path cacheDirectory) throws CacheMetadataCorruptedException {
    try {
        CacheMetadata cacheMetadata = new CacheMetadata();
        // Converts each layer object in the template to a cache metadata layer.
        for (CacheMetadataLayerObjectTemplate layerObjectTemplate : template.getLayers()) {
            if (layerObjectTemplate.getDigest() == null || layerObjectTemplate.getDiffId() == null) {
                throw new IllegalStateException("Cannot translate cache metadata layer without a digest or diffId");
            }
            Path layerContentFile = CacheFiles.getLayerFile(cacheDirectory, layerObjectTemplate.getDigest());
            // Gets the properties for a layer. Properties only exist for application layers.
            CacheMetadataLayerPropertiesObjectTemplate propertiesObjectTemplate = layerObjectTemplate.getProperties();
            // Constructs the cache metadata layer from a cached layer and layer metadata.
            LayerMetadata layerMetadata = null;
            if (propertiesObjectTemplate != null) {
                layerMetadata = new LayerMetadata(propertiesObjectTemplate.getSourceFiles(), propertiesObjectTemplate.getLastModifiedTime());
            }
            CachedLayer cachedLayer = new CachedLayer(layerContentFile, new BlobDescriptor(layerObjectTemplate.getSize(), layerObjectTemplate.getDigest()), layerObjectTemplate.getDiffId());
            CachedLayerWithMetadata cachedLayerWithMetadata = new CachedLayerWithMetadata(cachedLayer, layerMetadata);
            cacheMetadata.addLayer(cachedLayerWithMetadata);
        }
        return cacheMetadata;
    } catch (LayerPropertyNotFoundException ex) {
        throw new CacheMetadataCorruptedException(ex);
    }
}
Also used : Path(java.nio.file.Path) BlobDescriptor(com.google.cloud.tools.jib.blob.BlobDescriptor) LayerPropertyNotFoundException(com.google.cloud.tools.jib.image.LayerPropertyNotFoundException) CacheMetadataLayerObjectTemplate(com.google.cloud.tools.jib.cache.json.CacheMetadataLayerObjectTemplate) CacheMetadataLayerPropertiesObjectTemplate(com.google.cloud.tools.jib.cache.json.CacheMetadataLayerPropertiesObjectTemplate)

Aggregations

BlobDescriptor (com.google.cloud.tools.jib.blob.BlobDescriptor)1 CacheMetadataLayerObjectTemplate (com.google.cloud.tools.jib.cache.json.CacheMetadataLayerObjectTemplate)1 CacheMetadataLayerPropertiesObjectTemplate (com.google.cloud.tools.jib.cache.json.CacheMetadataLayerPropertiesObjectTemplate)1 LayerPropertyNotFoundException (com.google.cloud.tools.jib.image.LayerPropertyNotFoundException)1 Path (java.nio.file.Path)1