Search in sources :

Example 11 with KeyNotFoundException

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;
}
Also used : Assignment(org.apache.storm.generated.Assignment) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) WorkerResources(org.apache.storm.generated.WorkerResources) IStormClusterState(org.apache.storm.cluster.IStormClusterState) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException)

Example 12 with KeyNotFoundException

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();
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AtomicOutputStream(org.apache.storm.blobstore.AtomicOutputStream) Matchers.anyString(org.mockito.Matchers.anyString) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta) File(java.io.File) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) Test(org.junit.Test)

Example 13 with KeyNotFoundException

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));
}
Also used : ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 14 with KeyNotFoundException

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();
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AtomicOutputStream(org.apache.storm.blobstore.AtomicOutputStream) Matchers.anyString(org.mockito.Matchers.anyString) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta) File(java.io.File) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 15 with KeyNotFoundException

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
            }
        }
    }
}
Also used : BlobStoreFile(org.apache.storm.blobstore.BlobStoreFile) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException)

Aggregations

KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)21 IOException (java.io.IOException)11 AuthorizationException (org.apache.storm.generated.AuthorizationException)10 File (java.io.File)8 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)5 NimbusInfo (org.apache.storm.nimbus.NimbusInfo)5 KeeperException (org.apache.zookeeper.KeeperException)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ClientBlobStore (org.apache.storm.blobstore.ClientBlobStore)3 InputStreamWithMeta (org.apache.storm.blobstore.InputStreamWithMeta)3 ReadableBlobMeta (org.apache.storm.generated.ReadableBlobMeta)3 TTransportException (org.apache.thrift.transport.TTransportException)3 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)3 Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 LinkedHashMap (java.util.LinkedHashMap)2