Search in sources :

Example 6 with AtomicOutputStream

use of org.apache.storm.blobstore.AtomicOutputStream in project storm by apache.

the class Nimbus method cancelBlobUpload.

@SuppressWarnings("deprecation")
@Override
public void cancelBlobUpload(String session) throws AuthorizationException, TException {
    try {
        AtomicOutputStream os = (AtomicOutputStream) blobUploaders.get(session);
        if (os == null) {
            throw new RuntimeException("Blob for session " + session + " does not exist (or timed out)");
        }
        os.cancel();
        LOG.info("Canceled uploading blob for session {}. Closing session.", session);
        blobUploaders.remove(session);
    } catch (Exception e) {
        LOG.warn("finish blob upload exception.", e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) AtomicOutputStream(org.apache.storm.blobstore.AtomicOutputStream) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) InterruptedIOException(java.io.InterruptedIOException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Example 7 with AtomicOutputStream

use of org.apache.storm.blobstore.AtomicOutputStream 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 8 with AtomicOutputStream

use of org.apache.storm.blobstore.AtomicOutputStream 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 9 with AtomicOutputStream

use of org.apache.storm.blobstore.AtomicOutputStream in project storm by apache.

the class BlobStoreTest method testBasic.

public void testBasic(BlobStore store) throws Exception {
    assertStoreHasExactly(store);
    LOG.info("Creating test");
    // Tests for case when subject == null (security turned off) and
    // acls for the blob are set to WORLD_EVERYTHING
    SettableBlobMeta metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
    AtomicOutputStream out = store.createBlob("test", metadata, null);
    out.write(1);
    out.close();
    assertStoreHasExactly(store, "test");
    // Testing whether acls are set to WORLD_EVERYTHING
    assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)"));
    readAssertEquals(store, "test", 1);
    LOG.info("Deleting test");
    store.deleteBlob("test", null);
    assertStoreHasExactly(store);
    // The following tests are run for both hdfs and local store to test the
    // update blob interface
    metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING);
    LOG.info("Creating test again");
    out = store.createBlob("test", metadata, null);
    out.write(2);
    out.close();
    assertStoreHasExactly(store, "test");
    readAssertEquals(store, "test", 2);
    LOG.info("Updating test");
    out = store.updateBlob("test", null);
    out.write(3);
    out.close();
    assertStoreHasExactly(store, "test");
    readAssertEquals(store, "test", 3);
    LOG.info("Updating test again");
    out = store.updateBlob("test", null);
    out.write(4);
    out.flush();
    LOG.info("SLEEPING");
    Thread.sleep(2);
    if (store instanceof HdfsBlobStore) {
        ((HdfsBlobStore) store).fullCleanup(1);
    } else {
        fail("Error the blobstore is of unknowntype");
    }
    try {
        out.close();
    } catch (IOException e) {
    //This is likely to happen when we try to commit something that
    // was cleaned up.  This is expected and acceptable.
    }
}
Also used : AtomicOutputStream(org.apache.storm.blobstore.AtomicOutputStream) IOException(java.io.IOException) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Aggregations

AtomicOutputStream (org.apache.storm.blobstore.AtomicOutputStream)9 SettableBlobMeta (org.apache.storm.generated.SettableBlobMeta)7 IOException (java.io.IOException)4 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)3 File (java.io.File)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Subject (javax.security.auth.Subject)2 AccessControl (org.apache.storm.generated.AccessControl)2 Test (org.junit.Test)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 InterruptedIOException (java.io.InterruptedIOException)1 BindException (java.net.BindException)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)1 AuthorizationException (org.apache.storm.generated.AuthorizationException)1 InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)1