public SettableBlobMeta deepCopy() { return new SettableBlobMeta(this); }
/** * Performs a deep copy on <i>other</i>. */ public ReadableBlobMeta(ReadableBlobMeta other) { __isset_bitfield = other.__isset_bitfield; if (other.is_set_settable()) { this.settable = new SettableBlobMeta(other.settable); } this.version = other.version; }
private static void createBlobWithContent(String blobKey, ClientBlobStore clientBlobStore, File file) throws AuthorizationException, KeyAlreadyExistsException, IOException, KeyNotFoundException { String stringBlobACL = "o::rwa"; AccessControl blobACL = BlobStoreAclHandler.parseAccessControl(stringBlobACL); List<AccessControl> acls = new LinkedList<AccessControl>(); acls.add(blobACL); // more ACLs can be added here SettableBlobMeta settableBlobMeta = new SettableBlobMeta(acls); AtomicOutputStream blobStream = clientBlobStore.createBlob(blobKey, settableBlobMeta); blobStream.write(readFile(file).toString().getBytes()); blobStream.close(); }
@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 setAclCli(String[] args) throws Exception { Map<String, Object> cl = CLI.opt("s", "set", Collections.emptyList(), new AsAclParser()) .arg("key", CLI.FIRST_WINS) .parse(args); final String key = (String) cl.get("key"); final List<AccessControl> setAcl = (List<AccessControl>) cl.get("s"); ClientBlobStore.withConfiguredClient(new ClientBlobStore.WithBlobstore() { @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); }
@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); } }
private void setupStormCode(Map<String, Object> conf, String topoId, String tmpJarLocation, Map<String, Object> topoConf, StormTopology topology) throws Exception { Subject subject = getSubject(); IStormClusterState clusterState = stormClusterState; BlobStore store = blobStore; String jarKey = ConfigUtils.masterStormJarKey(topoId); if (tmpJarLocation != null) { //in local mode there is no jar try (FileInputStream fin = new FileInputStream(tmpJarLocation)) { store.createBlob(jarKey, fin, new SettableBlobMeta(BlobStoreAclHandler.DEFAULT), subject); } } topoCache.addTopoConf(topoId, subject, topoConf); topoCache.addTopology(topoId, subject, topology); }
/** * Add a new topology. * @param topoId the id of the topology * @param who who is doing it * @param topo the topology itself * @throws AuthorizationException if who is not allowed to add a topology * @throws KeyAlreadyExistsException if the topology already exists * @throws IOException on any error interacting with the blob store */ public void addTopology(final String topoId, final Subject who, final StormTopology topo) throws AuthorizationException, KeyAlreadyExistsException, IOException { final String key = ConfigUtils.masterStormCodeKey(topoId); final List<AccessControl> acl = BlobStoreAclHandler.DEFAULT; SettableBlobMeta meta = new SettableBlobMeta(acl); store.createBlob(key, Utils.serialize(topo), meta, who); topos.put(topoId, new WithAcl<>(meta.get_acl(), topo)); }
/** * Add a new topology config. * @param topoId the id of the topology * @param who who is doing it * @param topoConf the topology conf itself * @throws AuthorizationException if who is not allowed to add a topology conf * @throws KeyAlreadyExistsException if the toplogy conf already exists in the blob store * @throws IOException on any error interacting with the blob store. */ public void addTopoConf(final String topoId, final Subject who, final Map<String, Object> topoConf) throws AuthorizationException, KeyAlreadyExistsException, IOException { final String key = ConfigUtils.masterStormConfKey(topoId); final List<AccessControl> acl = BlobStoreAclHandler.DEFAULT; SettableBlobMeta meta = new SettableBlobMeta(acl); store.createBlob(key, Utils.toCompressedJsonConf(topoConf), meta, who); confs.put(topoId, new WithAcl<>(meta.get_acl(), topoConf)); }
@Test public void testDeleteAfterFailedCreate() throws Exception{ //Check that a blob can be deleted when a temporary file exists in the blob directory LocalFsBlobStore store = initLocalFs(); String key = "test"; SettableBlobMeta metadata = new SettableBlobMeta(BlobStoreAclHandler .WORLD_EVERYTHING); try (AtomicOutputStream out = store.createBlob(key, metadata, null)) { out.write(1); File blobDir = store.getKeyDataDir(key); Files.createFile(blobDir.toPath().resolve("tempFile.tmp")); } store.deleteBlob("test",null); }
@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()); } } }
@Test(expected = AuthorizationException.class) public void testFailAcls() throws Exception { Map<String, Object> conf = new HashMap(); // set clean time really high so doesn't kick in conf.put(DaemonConfig.SUPERVISOR_LOCALIZER_CACHE_CLEANUP_INTERVAL_MS, 60 * 60 * 1000); // enable blobstore acl validation conf.put(Config.STORM_BLOBSTORE_ACL_VALIDATION_ENABLED, true); String topo1 = "topo1"; String key1 = "key1"; TestLocalizer localizer = new TestLocalizer(conf, baseDir.toString()); ReadableBlobMeta rbm = new ReadableBlobMeta(); // set acl so user doesn't have read access AccessControl acl = new AccessControl(AccessControlType.USER, BlobStoreAclHandler.ADMIN); acl.set_name(user1); rbm.set_settable(new SettableBlobMeta(Arrays.asList(acl))); when(mockblobstore.getBlobMeta(anyString())).thenReturn(rbm); when(mockblobstore.getBlob(key1)).thenReturn(new TestInputStreamWithMeta(1)); File user1Dir = localizer.getLocalUserFileCacheDir(user1); assertTrue("failed to create user dir", user1Dir.mkdirs()); LocalAssignment topo1Assignment = new LocalAssignment(topo1, Collections.emptyList()); topo1Assignment.set_owner(user1); PortAndAssignment topo1Pna = new PortAndAssignmentImpl(1, topo1Assignment); // This should throw AuthorizationException because auth failed localizer.getBlob(new LocalResource(key1, false, false), topo1Pna, null); }
@Test public void testCleanup() throws Exception { ClientBlobStore mockBlobstore = mock(ClientBlobStore.class); when(mockBlobstore.getBlobMeta(any())).thenReturn(new ReadableBlobMeta(new SettableBlobMeta(), 1)); PortAndAssignment pna1 = new PortAndAssignmentImpl(1, new LocalAssignment("topo1", Collections.emptyList())); String user = "user";
@Test public void testGoodACLsForCreate() throws Exception { SettableBlobMeta meta = new SettableBlobMeta(); AccessControl submitterAcl = BlobStoreAclHandler.parseAccessControl("u:tester:rwa"); meta.add_to_acl(submitterAcl); String testKey = "testBlobKey"; client.createBlob(testKey, meta); validatedBlobAcls(testKey); }
@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); }
@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); }
@Test public void testGoodACLsForSetBlobMeta() throws Exception { String testKey = "testBlobKey"; SettableBlobMeta meta = new SettableBlobMeta(); createTestBlob(testKey, meta); meta.add_to_acl(BlobStoreAclHandler.parseAccessControl("u:nextuser:r--")); client.setBlobMeta(testKey, meta); validatedBlobAcls(testKey); }
@Test public void testGetFileLength() throws AuthorizationException, KeyNotFoundException, KeyAlreadyExistsException, IOException { LocalFsBlobStore store = initLocalFs(); try (AtomicOutputStream out = store.createBlob("test", new SettableBlobMeta(BlobStoreAclHandler .WORLD_EVERYTHING), null)) { out.write(1); } try (InputStreamWithMeta blobInputStream = store.getBlob("test", null)) { assertEquals(1, blobInputStream.getFileLength()); } } }
case 1: // SETTABLE if (schemeField.type == org.apache.storm.thrift.protocol.TType.STRUCT) { struct.settable = new SettableBlobMeta(); struct.settable.read(iprot); struct.set_settable_isSet(true);