/** * Delete a topology when we are done. * @param topoId the id of the topology * @param who who is deleting it * @throws AuthorizationException if who is not allowed to delete the blob * @throws KeyNotFoundException if the blob could not be found */ public void deleteTopology(final String topoId, final Subject who) throws AuthorizationException, KeyNotFoundException { final String key = ConfigUtils.masterStormCodeKey(topoId); store.deleteBlob(key, who); topos.remove(topoId); }
static List<String> getKeyListFromId(Map<String, Object> conf, String id) { List<String> ret = new ArrayList<>(3); ret.add(ConfigUtils.masterStormCodeKey(id)); ret.add(ConfigUtils.masterStormConfKey(id)); if (!ConfigUtils.isLocalMode(conf)) { ret.add(ConfigUtils.masterStormJarKey(id)); } return ret; }
@VisibleForTesting LocallyCachedBlob getTopoCode(final String topologyId, String owner) { return topologyBlobs.computeIfAbsent(ConfigUtils.masterStormCodeKey(topologyId), (tck) -> { try { return new LocallyCachedTopologyBlob(topologyId, isLocalMode, conf, fsOps, LocallyCachedTopologyBlob.TopologyBlobType .TOPO_CODE, owner, metricsRegistry); } catch (IOException e) { throw new RuntimeException(e); } }); }
@Override public void run(String[] args, Map<String, Object> conf, String command) throws Exception { for (String arg: args) { System.out.println(arg + ":"); StormTopology topo; File f = new File(arg); if (f.exists()) { topo = Utils.deserialize(FileUtils.readFileToByteArray(f), StormTopology.class); } else { //assume it is a topology id final String key = ConfigUtils.masterStormCodeKey(arg); try (BlobStore store = ServerUtils.getNimbusBlobStore(conf, NimbusInfo.fromConf(conf), null)) { topo = Utils.deserialize(store.readBlob(key, Nimbus.NIMBUS_SUBJECT), StormTopology.class); } } System.out.println(prettyPrint(topo)); } }
/** * 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)); }
/** * Update an existing topology . * @param topoId the id of the topology * @param who who is doing it * @param topo the new topology to save * @throws AuthorizationException if who is not allowed to update a topology * @throws KeyNotFoundException if the topology is not found in the blob store * @throws IOException on any error interacting with the blob store */ public void updateTopology(final String topoId, final Subject who, final StormTopology topo) throws AuthorizationException, KeyNotFoundException, IOException { final String key = ConfigUtils.masterStormCodeKey(topoId); store.updateBlob(key, Utils.serialize(topo), who); List<AccessControl> acl = BlobStoreAclHandler.DEFAULT; WithAcl<StormTopology> old = topos.get(topoId); if (old != null) { acl = old.acl; } else { acl = store.getBlobMeta(key, who).get_settable().get_acl(); } topos.put(topoId, new WithAcl<>(acl, topo)); }
/** * Read a topology. * @param topoId the id of the topology to read * @param who who to read it as * @return the deserialized topology. * @throws IOException on any error while reading the blob. * @throws AuthorizationException if who is not allowed to read the blob * @throws KeyNotFoundException if the blob could not be found */ public StormTopology readTopology(final String topoId, final Subject who) throws KeyNotFoundException, AuthorizationException, IOException { final String key = ConfigUtils.masterStormCodeKey(topoId); WithAcl<StormTopology> cached = topos.get(topoId); if (cached == null) { //We need to read a new one StormTopology topo = Utils.deserialize(store.readBlob(key, who), StormTopology.class); ReadableBlobMeta meta = store.getBlobMeta(key, who); cached = new WithAcl<>(meta.get_settable().get_acl(), topo); WithAcl<StormTopology> previous = topos.putIfAbsent(topoId, cached); if (previous != null) { cached = previous; } } else { //Check if the user is allowed to read this aclHandler.hasPermissions(cached.acl, READ, who, key); } return cached.data; }
jarCount = getBlobReplicationCount(ConfigUtils.masterStormJarKey(topoId)); int codeCount = getBlobReplicationCount(ConfigUtils.masterStormCodeKey(topoId)); int confCount = getBlobReplicationCount(ConfigUtils.masterStormConfKey(topoId)); long totalWaitTime = 0; jarCount = getBlobReplicationCount(ConfigUtils.masterStormJarKey(topoId)); codeCount = getBlobReplicationCount(ConfigUtils.masterStormCodeKey(topoId)); confCount = getBlobReplicationCount(ConfigUtils.masterStormConfKey(topoId));
String topoCodeKey = ConfigUtils.masterStormCodeKey(topologyId); String topoConfKey = ConfigUtils.masterStormConfKey(topologyId);
topoInfo.set_component_debug(common.base.get_component_debug()); topoInfo.set_replication_count(getBlobReplicationCount(ConfigUtils.masterStormCodeKey(topoId))); return topoInfo; } catch (Exception e) {
summary.set_replication_count(getBlobReplicationCount(ConfigUtils.masterStormCodeKey(topoId))); } catch (KeyNotFoundException e) {
topoPageInfo.set_uptime_secs(Time.deltaSecs(launchTimeSecs)); topoPageInfo.set_topology_conf(JSONValue.toJSONString(topoConf)); topoPageInfo.set_replication_count(getBlobReplicationCount(ConfigUtils.masterStormCodeKey(topoId))); if (base.is_set_component_debug()) { DebugOptions debug = base.get_component_debug().get(topoId);
@Override protected void downloadBaseBlobs(File tmproot) throws Exception { _fsOps.forceMkdir(tmproot); String stormCodeKey = ConfigUtils.masterStormCodeKey(_topologyId); String stormConfKey = ConfigUtils.masterStormConfKey(_topologyId); File codePath = new File(ConfigUtils.supervisorStormCodePath(tmproot.getAbsolutePath()));
protected void downloadBaseBlobs(File tmproot) throws Exception { String stormJarKey = ConfigUtils.masterStormJarKey(_topologyId); String stormCodeKey = ConfigUtils.masterStormCodeKey(_topologyId); String stormConfKey = ConfigUtils.masterStormConfKey(_topologyId); String jarPath = ConfigUtils.supervisorStormJarPath(tmproot.getAbsolutePath()); String codePath = ConfigUtils.supervisorStormCodePath(tmproot.getAbsolutePath()); String confPath = ConfigUtils.supervisorStormConfPath(tmproot.getAbsolutePath()); _fsOps.forceMkdir(tmproot); _fsOps.restrictDirectoryPermissions(tmproot); ClientBlobStore blobStore = Utils.getClientBlobStoreForSupervisor(_conf); try { Utils.downloadResourcesAsSupervisor(stormJarKey, jarPath, blobStore); Utils.downloadResourcesAsSupervisor(stormCodeKey, codePath, blobStore); Utils.downloadResourcesAsSupervisor(stormConfKey, confPath, blobStore); } finally { blobStore.shutdown(); } Utils.extractDirFromJar(jarPath, ConfigUtils.RESOURCES_SUBDIR, tmproot); }