Search in sources :

Example 51 with SettableBlobMeta

use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.

the class HdfsBlobStore method updateBlob.

@Override
public AtomicOutputStream updateBlob(String key, Subject who) throws AuthorizationException, KeyNotFoundException {
    who = checkAndGetSubject(who);
    SettableBlobMeta meta = extractBlobMeta(key);
    validateKey(key);
    aclHandler.hasPermissions(meta.get_acl(), WRITE, who, key);
    try {
        BlobStoreFile dataFile = hbs.write(DATA_PREFIX + key, false);
        dataFile.setMetadata(meta);
        return new BlobStoreFileOutputStream(dataFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : BlobStoreFile(org.apache.storm.blobstore.BlobStoreFile) IOException(java.io.IOException) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Example 52 with SettableBlobMeta

use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.

the class Blobstore method createCli.

private static void createCli(String[] args) throws Exception {
    Map<String, Object> cl = CLI.opt("f", "file", null, CLI.AS_STRING).opt("a", "acl", Collections.emptyList(), new AsAclParser()).opt("r", "replication-factor", -1, CLI.AS_INT).arg("key", CLI.FIRST_WINS).parse(args);
    final String key = (String) cl.get("key");
    final String file = (String) cl.get("f");
    final List<AccessControl> acl = (List<AccessControl>) cl.get("a");
    final Integer replicationFactor = (Integer) cl.get("r");
    SettableBlobMeta meta = new SettableBlobMeta(acl);
    meta.set_replication_factor(replicationFactor);
    BlobStore.validateKey(key);
    LOG.info("Creating {} with ACL {}", key, generateAccessControlsInfo(acl));
    if (StringUtils.isNotEmpty(file)) {
        try (BufferedInputStream f = new BufferedInputStream(new FileInputStream(file))) {
            BlobStoreSupport.createBlobFromStream(key, f, meta);
        }
    } else {
        BlobStoreSupport.createBlobFromStream(key, System.in, meta);
    }
    LOG.info("Successfully created {}", key);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ArrayList(java.util.ArrayList) List(java.util.List) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta) AccessControl(org.apache.storm.generated.AccessControl) FileInputStream(java.io.FileInputStream)

Example 53 with SettableBlobMeta

use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.

the class LocalFsBlobStoreTest method testMultiple.

public void testMultiple(BlobStore store) throws Exception {
    assertStoreHasExactly(store);
    LOG.info("Creating test");
    try (AtomicOutputStream out = store.createBlob("test", new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING), null)) {
        out.write(1);
    }
    assertStoreHasExactly(store, "test");
    readAssertEquals(store, "test", 1);
    LOG.info("Creating other");
    try (AtomicOutputStream out = store.createBlob("other", new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING), null)) {
        out.write(2);
    }
    assertStoreHasExactly(store, "test", "other");
    readAssertEquals(store, "test", 1);
    readAssertEquals(store, "other", 2);
    LOG.info("Updating other");
    try (AtomicOutputStream out = store.updateBlob("other", null)) {
        out.write(5);
    }
    assertStoreHasExactly(store, "test", "other");
    readAssertEquals(store, "test", 1);
    readAssertEquals(store, "other", 5);
    LOG.info("Deleting test");
    store.deleteBlob("test", null);
    assertStoreHasExactly(store, "other");
    readAssertEquals(store, "other", 5);
    LOG.info("Creating test again");
    try (AtomicOutputStream out = store.createBlob("test", new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING), null)) {
        out.write(2);
    }
    assertStoreHasExactly(store, "test", "other");
    readAssertEquals(store, "test", 2);
    readAssertEquals(store, "other", 5);
    LOG.info("Updating test");
    try (AtomicOutputStream out = store.updateBlob("test", null)) {
        out.write(3);
    }
    assertStoreHasExactly(store, "test", "other");
    readAssertEquals(store, "test", 3);
    readAssertEquals(store, "other", 5);
    LOG.info("Deleting other");
    store.deleteBlob("other", null);
    assertStoreHasExactly(store, "test");
    readAssertEquals(store, "test", 3);
    LOG.info("Updating test again");
    // intended to not guarding with try-with-resource since otherwise test will fail
    AtomicOutputStream out = store.updateBlob("test", null);
    out.write(4);
    out.flush();
    LOG.info("SLEEPING");
    Thread.sleep(2);
    if (store instanceof LocalFsBlobStore) {
        ((LocalFsBlobStore) store).fullCleanup(1);
    } else {
        fail("Error the blobstore is of unknowntype");
    }
    assertStoreHasExactly(store, "test");
    readAssertEquals(store, "test", 3);
    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 : IOException(java.io.IOException) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Example 54 with SettableBlobMeta

use of org.apache.storm.generated.SettableBlobMeta 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() {

        @Override
        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();
    ArgumentCaptor<SettableBlobMeta> blobMetaArgumentCaptor = ArgumentCaptor.forClass(SettableBlobMeta.class);
    verify(mockBlobStore).createBlob(anyString(), blobMetaArgumentCaptor.capture());
    SettableBlobMeta actualBlobMeta = blobMetaArgumentCaptor.getValue();
    List<AccessControl> actualAcls = actualBlobMeta.get_acl();
    assertTrue(actualAcls.contains(new AccessControl(AccessControlType.USER, BlobStoreAclHandler.READ | BlobStoreAclHandler.WRITE | BlobStoreAclHandler.ADMIN)));
    assertTrue(actualAcls.contains(new AccessControl(AccessControlType.OTHER, BlobStoreAclHandler.READ)));
}
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) AccessControl(org.apache.storm.generated.AccessControl) Test(org.junit.Test)

Example 55 with SettableBlobMeta

use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.

the class ClientBlobStoreTest method testDuplicateACLsForSetBlobMeta.

@Test(expected = AuthorizationException.class)
public void testDuplicateACLsForSetBlobMeta() throws Exception {
    String testKey = "testDuplicateACLsBlobKey";
    SettableBlobMeta meta = new SettableBlobMeta();
    createTestBlob(testKey, meta);
    AccessControl duplicateAcl = BlobStoreAclHandler.parseAccessControl("u:tester:r--");
    meta.add_to_acl(duplicateAcl);
    client.setBlobMeta(testKey, meta);
}
Also used : SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta) AccessControl(org.apache.storm.generated.AccessControl) Test(org.junit.Test)

Aggregations

SettableBlobMeta (org.apache.storm.generated.SettableBlobMeta)61 Test (org.junit.Test)20 ReadableBlobMeta (org.apache.storm.generated.ReadableBlobMeta)18 IOException (java.io.IOException)16 File (java.io.File)14 AccessControl (org.apache.storm.generated.AccessControl)12 AtomicOutputStream (org.apache.storm.blobstore.AtomicOutputStream)10 HashMap (java.util.HashMap)9 Subject (javax.security.auth.Subject)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 LocalAssignment (org.apache.storm.generated.LocalAssignment)7 TmpPath (org.apache.storm.testing.TmpPath)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 BlobStore (org.apache.storm.blobstore.BlobStore)5 BlobStoreFile (org.apache.storm.blobstore.BlobStoreFile)5 FileInputStream (java.io.FileInputStream)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)3