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);
}
}
Aggregations