public SettableBlobMeta deepCopy() { return new SettableBlobMeta(this); }
@Override public void run(ClientBlobStore blobStore) throws Exception { Iterator<String> keys; boolean isArgsEmpty = (args == null || args.length == 0); if (isArgsEmpty) { keys = blobStore.listKeys(); } else { keys = Arrays.asList(args).iterator(); } while (keys.hasNext()) { String key = keys.next(); try { ReadableBlobMeta meta = blobStore.getBlobMeta(key); long version = meta.get_version(); List<AccessControl> acl = meta.get_settable().get_acl(); LOG.info("{} {} {}", key, version, generateAccessControlsInfo(acl)); } catch (AuthorizationException ae) { if (!isArgsEmpty) { LOG.error("ACCESS DENIED to key: {}", key); } } catch (KeyNotFoundException knf) { if (!isArgsEmpty) { LOG.error("{} NOT FOUND", key); } } } } });
@Override public void setBlobMeta(String key, SettableBlobMeta meta, Subject who) throws AuthorizationException, KeyNotFoundException { if (meta.get_replication_factor() <= 0) { meta.set_replication_factor((int)conf.get(Config.STORM_BLOBSTORE_REPLICATION_FACTOR)); } who = checkAndGetSubject(who); validateKey(key); aclHandler.normalizeSettableBlobMeta(key, meta, who, ADMIN); BlobStoreAclHandler.validateSettableACLs(key, meta.get_acl()); SettableBlobMeta orig = getStoredBlobMeta(key); aclHandler.hasPermissions(orig.get_acl(), ADMIN, who, key); BlobStoreFileOutputStream mOut = null; writeMetadata(key, meta); }
@Override public int hashCode() { int hashCode = 1; hashCode = hashCode * 8191 + ((is_set_acl()) ? 131071 : 524287); if (is_set_acl()) hashCode = hashCode * 8191 + acl.hashCode(); hashCode = hashCode * 8191 + ((is_set_replication_factor()) ? 131071 : 524287); if (is_set_replication_factor()) hashCode = hashCode * 8191 + replication_factor; return hashCode; }
public java.lang.Object getFieldValue(_Fields field) { switch (field) { case ACL: return get_acl(); case REPLICATION_FACTOR: return get_replication_factor(); } throw new java.lang.IllegalStateException(); }
public void setFieldValue(_Fields field, java.lang.Object value) { switch (field) { case ACL: if (value == null) { unset_acl(); } else { set_acl((java.util.List<AccessControl>)value); } break; case REPLICATION_FACTOR: if (value == null) { unset_replication_factor(); } else { set_replication_factor((java.lang.Integer)value); } break; } }
SettableBlobMeta metadata = new SettableBlobMeta(BlobStoreAclHandler .WORLD_EVERYTHING); try (AtomicOutputStream out = store.createBlob("test", metadata, null)) { assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)")); readAssertEquals(store, "test", 1); metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING); LOG.info("Creating test again"); try (AtomicOutputStream out = store.createBlob("test", metadata, null)) { assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)")); metadata = new SettableBlobMeta(BlobStoreAclHandler.DEFAULT); LOG.info("Creating test for empty acls when security is off"); try (AtomicOutputStream out = store.createBlob("test-empty-acls", metadata, null)) { assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.get_acl().toString().contains("OTHER"));
@Override public void run(ClientBlobStore blobStore) throws Exception { ReadableBlobMeta meta = blobStore.getBlobMeta(key); List<AccessControl> acl = meta.get_settable().get_acl(); List<AccessControl> newAcl; if (setAcl != null && !setAcl.isEmpty()) { newAcl = setAcl; } else { newAcl = acl; } SettableBlobMeta newMeta = new SettableBlobMeta(newAcl); LOG.info("Setting ACL for {} to {}", key, generateAccessControlsInfo(newAcl)); blobStore.setBlobMeta(key, newMeta); } });
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); }
SettableBlobMeta metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING); try (AtomicOutputStream out = store.createBlob("test", metadata, null)) { out.write(1); assertTrue("ACL does not contain WORLD_EVERYTHING", metadata.toString().contains("AccessControl(type:OTHER, access:7)")); readAssertEquals(store, "test", 1); metadata = new SettableBlobMeta(BlobStoreAclHandler.WORLD_EVERYTHING); LOG.info("Creating test again"); try (AtomicOutputStream out = store.createBlob("test", metadata, null)) {
/** * Client facing API to set the metadata for a blob. * * @param key blob key name. * @param meta contains ACL information. * @throws AuthorizationException * @throws KeyNotFoundException */ public final void setBlobMeta(String key, SettableBlobMeta meta) throws AuthorizationException, KeyNotFoundException { if (meta != null && meta.is_set_acl()) { BlobStoreAclHandler.validateSettableACLs(key, meta.get_acl()); } setBlobMetaToExtend(key, meta); }
@Override public int updateBlobReplication(String key, int replication, Subject who) throws AuthorizationException, KeyNotFoundException { who = checkAndGetSubject(who); validateKey(key); SettableBlobMeta meta = getStoredBlobMeta(key); meta.set_replication_factor(replication); aclHandler.hasAnyPermissions(meta.get_acl(), WRITE | ADMIN, who, key); try { writeMetadata(key, meta); return hbs.updateBlobReplication(DATA_PREFIX + key, replication); } catch (IOException exp) { throw new RuntimeException(exp); } }
@Test(expected = AuthorizationException.class) public void testDuplicateACLsForCreate() throws Exception { SettableBlobMeta meta = new SettableBlobMeta(); AccessControl submitterAcl = BlobStoreAclHandler.parseAccessControl("u:tester:rwa"); meta.add_to_acl(submitterAcl); AccessControl duplicateAcl = BlobStoreAclHandler.parseAccessControl("u:tester:r--"); meta.add_to_acl(duplicateAcl); String testKey = "testDuplicateACLsBlobKey"; client.createBlob(testKey, meta); }
@Override public void read(org.apache.storm.thrift.protocol.TProtocol prot, ReadableBlobMeta struct) throws org.apache.storm.thrift.TException { org.apache.storm.thrift.protocol.TTupleProtocol iprot = (org.apache.storm.thrift.protocol.TTupleProtocol) prot; struct.settable = new SettableBlobMeta(); struct.settable.read(iprot); struct.set_settable_isSet(true); struct.version = iprot.readI64(); struct.set_version_isSet(true); } }
public void validate() throws org.apache.storm.thrift.TException { // check for required fields if (!is_set_acl()) { throw new org.apache.storm.thrift.protocol.TProtocolException("Required field 'acl' is unset! Struct:" + toString()); } // check for sub-struct validity }
public void write(org.apache.storm.thrift.protocol.TProtocol oprot, SettableBlobMeta struct) throws org.apache.storm.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); if (struct.acl != null) { oprot.writeFieldBegin(ACL_FIELD_DESC); { oprot.writeListBegin(new org.apache.storm.thrift.protocol.TList(org.apache.storm.thrift.protocol.TType.STRUCT, struct.acl.size())); for (AccessControl _iter609 : struct.acl) { _iter609.write(oprot); } oprot.writeListEnd(); } oprot.writeFieldEnd(); } if (struct.is_set_replication_factor()) { oprot.writeFieldBegin(REPLICATION_FACTOR_FIELD_DESC); oprot.writeI32(struct.replication_factor); oprot.writeFieldEnd(); } oprot.writeFieldStop(); oprot.writeStructEnd(); }
@Override public OutputStream getOutputStream() throws IOException { checkIsNotTmp(); OutputStream out = null; FsPermission fileperms = new FsPermission(BLOBSTORE_FILE_PERMISSION); try { out = _fs.create(_path, (short)this.getMetadata().get_replication_factor()); _fs.setPermission(_path, fileperms); _fs.setReplication(_path, (short)this.getMetadata().get_replication_factor()); } catch (IOException e) { //Try to create the parent directory, may not work FsPermission dirperms = new FsPermission(HdfsBlobStoreImpl.BLOBSTORE_DIR_PERMISSION); if (!_fs.mkdirs(_path.getParent(), dirperms)) { LOG.warn("error creating parent dir: " + _path.getParent()); } out = _fs.create(_path, (short)this.getMetadata().get_replication_factor()); _fs.setPermission(_path, dirperms); _fs.setReplication(_path, (short)this.getMetadata().get_replication_factor()); } if (out == null) { throw new IOException("Error in creating: " + _path); } return out; }
@Override public boolean equals(java.lang.Object that) { if (that == null) return false; if (that instanceof SettableBlobMeta) return this.equals((SettableBlobMeta)that); return false; }
@Override public java.lang.String toString() { java.lang.StringBuilder sb = new java.lang.StringBuilder("SettableBlobMeta("); boolean first = true; sb.append("acl:"); if (this.acl == null) { sb.append("null"); } else { sb.append(this.acl); } first = false; if (is_set_replication_factor()) { if (!first) sb.append(", "); sb.append("replication_factor:"); sb.append(this.replication_factor); first = false; } sb.append(")"); return sb.toString(); }