From d0f8a708e0f6194bc348a3d96a926766754f7a5f Mon Sep 17 00:00:00 2001 From: "igor.petrenko" Date: Tue, 10 Sep 2024 17:53:20 +0300 Subject: [PATCH] OAP-204 oap-cloud: FileSystem#getMetadata --- .../src/test/java/oap/storage/cloud/FileSystemTest.java | 3 ++- .../src/main/java/oap/storage/cloud/FileSystem.java | 8 +++++++- pom.xml | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/oap-storage/oap-storage-cloud-test/src/test/java/oap/storage/cloud/FileSystemTest.java b/oap-storage/oap-storage-cloud-test/src/test/java/oap/storage/cloud/FileSystemTest.java index 4a2e09613..c75dbc47c 100644 --- a/oap-storage/oap-storage-cloud-test/src/test/java/oap/storage/cloud/FileSystemTest.java +++ b/oap-storage/oap-storage-cloud-test/src/test/java/oap/storage/cloud/FileSystemTest.java @@ -82,9 +82,10 @@ public void testGetMetadata() { s3mockFixture.uploadFile( TEST_BUCKET, "logs/file.txt", path, Map.of( "test-tag", "tag-val" ) ); FileSystem.StorageItem item = fileSystem.getMetadata( new CloudURI( "s3", TEST_BUCKET, "/logs/file.txt" ) ); - assertThat( item.getLastModified() ).isLessThanOrEqualTo( new DateTime( DateTimeZone.UTC ) ); assertThat( item.getSize() ).isEqualTo( 11L ); + + assertThat( fileSystem.getMetadata( new CloudURI( "s3", TEST_BUCKET, "/unknown.txt" ) ) ).isNull(); } @Test diff --git a/oap-storage/oap-storage-cloud/src/main/java/oap/storage/cloud/FileSystem.java b/oap-storage/oap-storage-cloud/src/main/java/oap/storage/cloud/FileSystem.java index fea7cfcee..4f717949a 100644 --- a/oap-storage/oap-storage-cloud/src/main/java/oap/storage/cloud/FileSystem.java +++ b/oap-storage/oap-storage-cloud/src/main/java/oap/storage/cloud/FileSystem.java @@ -23,6 +23,7 @@ import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.joda.time.DateTime; +import javax.annotation.Nullable; import java.io.File; import java.io.InputStream; import java.io.Serial; @@ -352,12 +353,17 @@ public PageSet list( String path, ListContainerOptions op return list( pathURI, options ); } + @Nullable public StorageItem getMetadata( CloudURI path ) { log.debug( "getMetadata {}", path ); try( BlobStoreContext context = getContext( path ) ) { BlobStore blobStore = context.getBlobStore(); - return wrapToStorageItem( blobStore.getBlob( path.container, path.path ).getMetadata() ); + Blob blob = blobStore.getBlob( path.container, path.path ); + if( blob == null ) { + return null; + } + return wrapToStorageItem( blob.getMetadata() ); } catch( Exception e ) { throw new CloudException( e ); } diff --git a/pom.xml b/pom.xml index ead018296..4e73bdd82 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ - 22.4.17 + 22.4.18 21.0.0 21.0.1