use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.
the class HdfsBlobStoreImplTest method testGetFileLength.
@Test
public void testGetFileLength() throws Exception {
Map<String, Object> conf = new HashMap<>();
String validKey = "validkeyBasic";
String testString = "testingblob";
try (TestHdfsBlobStoreImpl hbs = new TestHdfsBlobStoreImpl(blobDir, conf, DFS_CLUSTER_RULE.getHadoopConf())) {
BlobStoreFile pfile = hbs.write(validKey, false);
// Adding metadata to avoid null pointer exception
SettableBlobMeta meta = new SettableBlobMeta();
meta.set_replication_factor(1);
pfile.setMetadata(meta);
try (OutputStream ios = pfile.getOutputStream()) {
ios.write(testString.getBytes(StandardCharsets.UTF_8));
}
assertEquals(testString.getBytes(StandardCharsets.UTF_8).length, pfile.getFileLength());
}
}
use of org.apache.storm.generated.SettableBlobMeta 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);
try (AtomicOutputStream out = store.createBlob("test", metadata, null)) {
out.write(1);
}
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");
try (AtomicOutputStream out = store.createBlob("test", metadata, null)) {
out.write(2);
}
assertStoreHasExactly(store, "test");
readAssertEquals(store, "test", 2);
LOG.info("Updating test");
try (AtomicOutputStream out = store.updateBlob("test", null)) {
out.write(3);
}
assertStoreHasExactly(store, "test");
readAssertEquals(store, "test", 3);
LOG.info("Updating test again");
try (AtomicOutputStream out = store.updateBlob("test", null)) {
out.write(4);
}
LOG.info("SLEEPING");
Thread.sleep(2);
if (store instanceof HdfsBlobStore) {
((HdfsBlobStore) store).fullCleanup(1);
} else {
fail("Error the blobstore is of unknowntype");
}
}
use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.
the class HdfsBlobStore method getBlobMeta.
@Override
public ReadableBlobMeta getBlobMeta(String key, Subject who) throws AuthorizationException, KeyNotFoundException {
who = checkAndGetSubject(who);
validateKey(key);
SettableBlobMeta meta = extractBlobMeta(key);
aclHandler.validateUserCanReadMeta(meta.get_acl(), who, key);
ReadableBlobMeta rbm = new ReadableBlobMeta();
rbm.set_settable(meta);
try {
BlobStoreFile pf = hbs.read(DATA_PREFIX + key);
rbm.set_version(pf.getModTime());
} catch (IOException e) {
throw new RuntimeException(e);
}
return rbm;
}
use of org.apache.storm.generated.SettableBlobMeta 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 WrappedKeyNotFoundException(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;
SettableBlobMeta blobMeta = Utils.thriftDeserialize(SettableBlobMeta.class, out.toByteArray());
return blobMeta;
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// Ignored
}
}
}
}
use of org.apache.storm.generated.SettableBlobMeta in project storm by apache.
the class HdfsBlobStore method extractBlobMeta.
private SettableBlobMeta extractBlobMeta(String key) throws KeyNotFoundException {
if (key == null) {
throw new WrappedKeyNotFoundException("null can not be blob key");
}
SettableBlobMeta meta = cacheMetas.getIfPresent(key);
if (meta == null) {
meta = getStoredBlobMeta(key);
cacheMetas.put(key, meta);
}
return meta;
}
Aggregations