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);
}
}
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);
}
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.
}
}
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)));
}
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);
}
Aggregations