use of org.apache.storm.generated.ReadableBlobMeta in project storm by apache.
the class DependencyUploaderTest method uploadArtifactsWhichOneOfThemIsFailedToBeUploaded.
@Test
public void uploadArtifactsWhichOneOfThemIsFailedToBeUploaded() throws Exception {
String artifact = "group:artifact:1.0.0";
String expectedBlobKeyForArtifact = "group-artifact-1.0.0.jar";
File mockFile = createTemporaryDummyFile();
String artifact2 = "group:artifact2:2.0.0";
String expectedBlobKeyForArtifact2 = "group-artifact2-2.0.0.jar";
File mockFile2 = mock(File.class);
when(mockFile2.getName()).thenReturn("dummy.jar");
when(mockFile2.isFile()).thenReturn(true);
when(mockFile2.exists()).thenReturn(true);
when(mockFile2.getPath()).thenThrow(new RuntimeException("just for test!"));
when(mockFile2.toPath()).thenThrow(new RuntimeException("just for test!"));
// we skip uploading first one since we don't test upload for now
when(mockBlobStore.getBlobMeta(contains(expectedBlobKeyForArtifact))).thenReturn(new ReadableBlobMeta());
// we try uploading second one and it should be failed throwing RuntimeException
when(mockBlobStore.getBlobMeta(contains(expectedBlobKeyForArtifact2))).thenThrow(new KeyNotFoundException());
Map<String, File> artifacts = new LinkedHashMap<>();
artifacts.put(artifact, mockFile);
artifacts.put(artifact2, mockFile2);
try {
sut.uploadArtifacts(artifacts);
fail("Should pass RuntimeException");
} catch (RuntimeException e) {
// intended behavior
}
verify(mockBlobStore).getBlobMeta(contains(expectedBlobKeyForArtifact));
verify(mockBlobStore).getBlobMeta(contains(expectedBlobKeyForArtifact2));
// never rollback
verify(mockBlobStore, never()).deleteBlob(contains(expectedBlobKeyForArtifact));
verify(mockBlobStore, never()).deleteBlob(contains(expectedBlobKeyForArtifact2));
}
use of org.apache.storm.generated.ReadableBlobMeta in project storm by apache.
the class HdfsBlobStore method getBlobMeta.
@Override
public ReadableBlobMeta getBlobMeta(String key, Subject who) throws AuthorizationException, KeyNotFoundException {
who = checkAndGetSubject(who);
validateKey(key);
SettableBlobMeta meta = getStoredBlobMeta(key);
_aclHandler.validateUserCanReadMeta(meta.get_acl(), who, key);
ReadableBlobMeta rbm = new ReadableBlobMeta();
rbm.set_settable(meta);
try {
BlobStoreFile pf = _hbs.read(DATA_PREFIX + key);
rbm.set_version(pf.getModTime());
} catch (IOException e) {
throw new RuntimeException(e);
}
return rbm;
}
use of org.apache.storm.generated.ReadableBlobMeta in project storm by apache.
the class BlobStoreUtils method downloadMissingBlob.
// Download missing blobs from potential nimbodes
public static boolean downloadMissingBlob(Map<String, Object> conf, BlobStore blobStore, String key, Set<NimbusInfo> nimbusInfos) throws TTransportException {
ReadableBlobMeta rbm;
ClientBlobStore remoteBlobStore;
InputStreamWithMeta in;
boolean isSuccess = false;
LOG.debug("Download blob NimbusInfos {}", nimbusInfos);
for (NimbusInfo nimbusInfo : nimbusInfos) {
if (isSuccess) {
break;
}
LOG.debug("Download blob key: {}, NimbusInfo {}", key, nimbusInfo);
try (NimbusClient client = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort(), null)) {
rbm = client.getClient().getBlobMeta(key);
remoteBlobStore = new NimbusBlobStore();
remoteBlobStore.setClient(conf, client);
in = remoteBlobStore.getBlob(key);
blobStore.createBlob(key, in, rbm.get_settable(), getNimbusSubject());
// if key already exists while creating the blob else update it
Iterator<String> keyIterator = blobStore.listKeys();
while (keyIterator.hasNext()) {
if (keyIterator.next().equals(key)) {
LOG.debug("Success creating key, {}", key);
isSuccess = true;
break;
}
}
} catch (IOException | AuthorizationException exception) {
throw new RuntimeException(exception);
} catch (KeyAlreadyExistsException kae) {
LOG.info("KeyAlreadyExistsException Key: {} {}", key, kae);
} catch (KeyNotFoundException knf) {
// Catching and logging KeyNotFoundException because, if
// there is a subsequent update and delete, the non-leader
// nimbodes might throw an exception.
LOG.info("KeyNotFoundException Key: {} {}", key, knf);
} catch (Exception exp) {
// Logging an exception while client is connecting
LOG.error("Exception {}", exp);
}
}
if (!isSuccess) {
LOG.error("Could not download the blob with key: {}", key);
}
return isSuccess;
}
use of org.apache.storm.generated.ReadableBlobMeta in project storm by apache.
the class Utils method nimbusVersionOfBlob.
public static long nimbusVersionOfBlob(String key, ClientBlobStore cb) throws AuthorizationException, KeyNotFoundException {
long nimbusBlobVersion = 0;
ReadableBlobMeta metadata = cb.getBlobMeta(key);
nimbusBlobVersion = metadata.get_version();
return nimbusBlobVersion;
}
Aggregations