diff --git a/oap-storage/oap-storage-cloud-aws-s3/src/main/java/oap/storage/cloud/awss3/FileSystemCloudApiS3.java b/oap-storage/oap-storage-cloud-aws-s3/src/main/java/oap/storage/cloud/awss3/FileSystemCloudApiS3.java index c886c82fc..b8b7e3083 100644 --- a/oap-storage/oap-storage-cloud-aws-s3/src/main/java/oap/storage/cloud/awss3/FileSystemCloudApiS3.java +++ b/oap-storage/oap-storage-cloud-aws-s3/src/main/java/oap/storage/cloud/awss3/FileSystemCloudApiS3.java @@ -75,6 +75,7 @@ import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.net.URI; +import java.net.URISyntaxException; import java.nio.ByteBuffer; import java.nio.file.Path; import java.time.Instant; @@ -275,7 +276,11 @@ public String getName() { @Override public URI getUri() { - return s3Client.utilities().parseUri( URI.create( path.toString() ) ).uri(); + try { + return s3Client.utilities().getUrl( builder -> builder.bucket( path.container ).key( path.path ).build() ).toURI(); + } catch( URISyntaxException e ) { + throw new CloudException( e ); + } } @Override 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 ffee9da21..5e3e38785 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 @@ -18,6 +18,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Path; import java.util.Map; @@ -93,7 +95,7 @@ public void testGetOutputStream() throws IOException { } @Test - public void testGetMetadata() { + public void testGetMetadata() throws URISyntaxException { Path path = testDirectoryFixture.testPath( "my-file.txt" ); Files.write( path, "test string", ContentWriter.ofString() ); @@ -103,6 +105,7 @@ public void testGetMetadata() { 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( item.getUri() ).isEqualTo( new URI( "http://localhost:" + s3mockFixture.getHttpPort() + "/test-bucket/logs/file.txt" ) ); assertThat( fileSystem.getMetadata( new CloudURI( "s3", TEST_BUCKET, "/unknown.txt" ) ) ).isNull(); } 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 38148c6d8..9a4723301 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 @@ -24,7 +24,6 @@ import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -117,13 +116,6 @@ public void copy( CloudURI source, CloudURI destination, Map tag } } - private DateTime toDateTime( Date date ) { - if( date == null ) { - return null; - } - return new DateTime( date ); - } - public PageSet list( CloudURI path, ListOptions listOptions ) throws CloudException { return getCloudApi( path ).list( path, listOptions ); }