use of org.apache.storm.generated.KeyNotFoundException in project storm by apache.
the class Nimbus method getResourcesForTopology.
private TopologyResources getResourcesForTopology(String topoId, StormBase base) throws NotAliveException, AuthorizationException, InvalidTopologyException, IOException {
TopologyResources ret = idToResources.get().get(topoId);
if (ret == null) {
try {
IStormClusterState state = stormClusterState;
TopologyDetails details = readTopologyDetails(topoId, base);
double sumOnHeap = 0.0;
double sumOffHeap = 0.0;
double sumCPU = 0.0;
Assignment assignment = state.assignmentInfo(topoId, null);
if (assignment != null) {
if (assignment.is_set_worker_resources()) {
for (WorkerResources wr : assignment.get_worker_resources().values()) {
if (wr.is_set_cpu()) {
sumCPU += wr.get_cpu();
}
if (wr.is_set_mem_off_heap()) {
sumOffHeap += wr.get_mem_off_heap();
}
if (wr.is_set_mem_on_heap()) {
sumOnHeap += wr.get_mem_on_heap();
}
}
}
}
ret = new TopologyResources(details.getTotalRequestedMemOnHeap(), details.getTotalRequestedMemOffHeap(), details.getTotalRequestedCpu(), sumOnHeap, sumOffHeap, sumCPU);
} catch (KeyNotFoundException e) {
//This can happen when a topology is first coming up
// It's thrown by the blobstore code
LOG.error("Failed to get topology details", e);
ret = new TopologyResources(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
}
}
return ret;
}
use of org.apache.storm.generated.KeyNotFoundException in project storm by apache.
the class DependencyUploaderTest method uploadFiles.
@Test
public void uploadFiles() throws Exception {
AtomicOutputStream mockOutputStream = mock(AtomicOutputStream.class);
doNothing().when(mockOutputStream).cancel();
final AtomicInteger counter = new AtomicInteger();
final Answer incrementCounter = new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
counter.addAndGet(1);
return null;
}
};
doAnswer(incrementCounter).when(mockOutputStream).write(anyInt());
doAnswer(incrementCounter).when(mockOutputStream).write(any(byte[].class));
doAnswer(incrementCounter).when(mockOutputStream).write(any(byte[].class), anyInt(), anyInt());
doNothing().when(mockOutputStream).close();
when(mockBlobStore.getBlobMeta(anyString())).thenThrow(new KeyNotFoundException());
when(mockBlobStore.createBlob(anyString(), any(SettableBlobMeta.class))).thenReturn(mockOutputStream);
File mockFile = createTemporaryDummyFile();
String mockFileFileNameWithoutExtension = Files.getNameWithoutExtension(mockFile.getName());
List<String> keys = sut.uploadFiles(Lists.newArrayList(mockFile), false);
assertEquals(1, keys.size());
assertTrue(keys.get(0).contains(mockFileFileNameWithoutExtension));
assertTrue(counter.get() > 0);
verify(mockOutputStream).close();
}
use of org.apache.storm.generated.KeyNotFoundException 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.KeyNotFoundException in project storm by apache.
the class DependencyUploaderTest method uploadArtifacts.
@Test
public void uploadArtifacts() throws Exception {
AtomicOutputStream mockOutputStream = mock(AtomicOutputStream.class);
doNothing().when(mockOutputStream).cancel();
final AtomicInteger counter = new AtomicInteger();
final Answer incrementCounter = new Answer() {
public Object answer(InvocationOnMock invocation) throws Throwable {
counter.addAndGet(1);
return null;
}
};
doAnswer(incrementCounter).when(mockOutputStream).write(anyInt());
doAnswer(incrementCounter).when(mockOutputStream).write(any(byte[].class));
doAnswer(incrementCounter).when(mockOutputStream).write(any(byte[].class), anyInt(), anyInt());
doNothing().when(mockOutputStream).close();
when(mockBlobStore.getBlobMeta(anyString())).thenThrow(new KeyNotFoundException());
when(mockBlobStore.createBlob(anyString(), any(SettableBlobMeta.class))).thenReturn(mockOutputStream);
String artifact = "group:artifact:1.0.0";
String expectedBlobKeyForArtifact = "group-artifact-1.0.0.jar";
File mockFile = createTemporaryDummyFile();
Map<String, File> artifacts = new LinkedHashMap<>();
artifacts.put(artifact, mockFile);
List<String> keys = sut.uploadArtifacts(artifacts);
assertEquals(1, keys.size());
assertTrue(keys.get(0).contains(expectedBlobKeyForArtifact));
assertTrue(counter.get() > 0);
verify(mockOutputStream).close();
}
use of org.apache.storm.generated.KeyNotFoundException in project storm by apache.
the class HdfsBlobStore method getStoredBlobMeta.
private SettableBlobMeta getStoredBlobMeta(String key) throws KeyNotFoundException {
InputStream in = null;
try {
BlobStoreFile pf = _hbs.read(META_PREFIX + key);
try {
in = pf.getInputStream();
} catch (FileNotFoundException fnf) {
throw new KeyNotFoundException(key);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[2048];
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
in.close();
in = null;
return Utils.thriftDeserialize(SettableBlobMeta.class, out.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
//Ignored
}
}
}
}
Aggregations