use of com.google.cloud.tools.jib.filesystem.LockFile in project jib by google.
the class CacheStorageWriter method writeMetadata.
/**
* Saves image metadata (a manifest list and a list of manifest/container configuration pairs) for
* an image reference.
*
* @param imageReference the image reference to store the metadata for
* @param metadata the image metadata
*/
void writeMetadata(ImageReference imageReference, ImageMetadataTemplate metadata) throws IOException {
verifyImageMetadata(metadata);
Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
Files.createDirectories(imageDirectory);
try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
writeJsonTemplate(metadata, imageDirectory.resolve("manifests_configs.json"));
}
}
use of com.google.cloud.tools.jib.filesystem.LockFile in project jib by google.
the class CacheStorageReader method retrieveMetadata.
/**
* Retrieves the cached image metadata (a manifest list and a list of manifest/container
* configuration pairs) for an image reference.
*
* @param imageReference the image reference
* @return the image metadata for the image reference, if found
* @throws IOException if an I/O exception occurs
* @throws CacheCorruptedException if the cache is corrupted
*/
Optional<ImageMetadataTemplate> retrieveMetadata(ImageReference imageReference) throws IOException, CacheCorruptedException {
Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
Path metadataPath = imageDirectory.resolve("manifests_configs.json");
if (!Files.exists(metadataPath)) {
return Optional.empty();
}
ImageMetadataTemplate metadata;
try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
metadata = JsonTemplateMapper.readJsonFromFile(metadataPath, ImageMetadataTemplate.class);
}
verifyImageMetadata(metadata, imageDirectory);
return Optional.of(metadata);
}
use of com.google.cloud.tools.jib.filesystem.LockFile in project jib by GoogleContainerTools.
the class CacheStorageReader method retrieveMetadata.
/**
* Retrieves the cached image metadata (a manifest list and a list of manifest/container
* configuration pairs) for an image reference.
*
* @param imageReference the image reference
* @return the image metadata for the image reference, if found
* @throws IOException if an I/O exception occurs
* @throws CacheCorruptedException if the cache is corrupted
*/
Optional<ImageMetadataTemplate> retrieveMetadata(ImageReference imageReference) throws IOException, CacheCorruptedException {
Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
Path metadataPath = imageDirectory.resolve("manifests_configs.json");
if (!Files.exists(metadataPath)) {
return Optional.empty();
}
ImageMetadataTemplate metadata;
try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
metadata = JsonTemplateMapper.readJsonFromFile(metadataPath, ImageMetadataTemplate.class);
}
verifyImageMetadata(metadata, imageDirectory);
return Optional.of(metadata);
}
use of com.google.cloud.tools.jib.filesystem.LockFile in project jib by GoogleContainerTools.
the class CacheStorageWriter method writeMetadata.
/**
* Saves image metadata (a manifest list and a list of manifest/container configuration pairs) for
* an image reference.
*
* @param imageReference the image reference to store the metadata for
* @param metadata the image metadata
*/
void writeMetadata(ImageReference imageReference, ImageMetadataTemplate metadata) throws IOException {
verifyImageMetadata(metadata);
Path imageDirectory = cacheStorageFiles.getImageDirectory(imageReference);
Files.createDirectories(imageDirectory);
try (LockFile ignored = LockFile.lock(imageDirectory.resolve("lock"))) {
writeJsonTemplate(metadata, imageDirectory.resolve("manifests_configs.json"));
}
}
Aggregations