mirror of https://github.com/apache/druid.git
Correct the API used to fetch the version for a GCS object (#16097)
Current API used to fetch the version for a GCS object is incorrect. This PR fixes that API.
This commit is contained in:
parent
c7f1872bd1
commit
2dd8b16467
|
@ -198,13 +198,22 @@ public class GoogleStorage
|
|||
return blob.getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the etag for an object. This is a value that changes whenever the object's data or metadata changes and is
|
||||
* typically but not always the MD5 hash of the object. Ref:
|
||||
* <a href="https://cloud.google.com/storage/docs/hashes-etags#etags">ETags</a>
|
||||
* @param bucket
|
||||
* @param path
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public String version(final String bucket, final String path) throws IOException
|
||||
{
|
||||
Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.GENERATION));
|
||||
Blob blob = storage.get().get(bucket, path, Storage.BlobGetOption.fields(Storage.BlobField.ETAG));
|
||||
if (blob == null) {
|
||||
throw new IOE("Failed to fetch google cloud storage object from bucket [%s] and path [%s].", bucket, path);
|
||||
}
|
||||
return blob.getGeneratedId();
|
||||
return blob.getEtag();
|
||||
}
|
||||
|
||||
/***
|
||||
|
|
|
@ -76,7 +76,7 @@ public class GoogleTimestampVersionedDataFinder extends GoogleDataSegmentPuller
|
|||
return latest;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,18 +203,18 @@ public class GoogleStorageTest
|
|||
@Test
|
||||
public void testVersion() throws IOException
|
||||
{
|
||||
final String version = "7";
|
||||
final String etag = "abcd";
|
||||
EasyMock.expect(mockStorage.get(
|
||||
EasyMock.eq(BUCKET),
|
||||
EasyMock.eq(PATH),
|
||||
EasyMock.anyObject(Storage.BlobGetOption.class)
|
||||
)).andReturn(blob);
|
||||
|
||||
EasyMock.expect(blob.getGeneratedId()).andReturn(version);
|
||||
EasyMock.expect(blob.getEtag()).andReturn(etag);
|
||||
|
||||
EasyMock.replay(mockStorage, blob);
|
||||
|
||||
assertEquals(version, googleStorage.version(BUCKET, PATH));
|
||||
assertEquals(etag, googleStorage.version(BUCKET, PATH));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue