protected IAuthorizer mkAuthorizationHandlerImpl(String klassName, Map<String, Object> conf) throws ClassNotFoundException, IllegalAccessException, InstantiationException { IAuthorizer aznHandler = null; if (StringUtils.isNotBlank(klassName)) { Class<?> aznClass = Class.forName(klassName); if (aznClass != null) { aznHandler = (IAuthorizer) aznClass.newInstance(); if (aznHandler != null) { aznHandler.prepare(conf); } LOG.debug("authorization class name:{}, class:{}, handler:{}", klassName, aznClass, aznHandler); } } return aznHandler; } }
static Process processLauncher(Map<String, Object> conf, String user, List<String> commandPrefix, List<String> args, Map<String, String> environment, final String logPreFix, final ExitCodeCallback exitCodeCallback, File dir) throws IOException { if (StringUtils.isBlank(user)) { throw new IllegalArgumentException("User cannot be blank when calling processLauncher."); } String wlinitial = (String) (conf.get(Config.SUPERVISOR_WORKER_LAUNCHER)); String stormHome = ConfigUtils.concatIfNotNull(System.getProperty(ConfigUtils.STORM_HOME)); String wl; if (StringUtils.isNotBlank(wlinitial)) { wl = wlinitial; } else { wl = stormHome + "/bin/worker-launcher"; } List<String> commands = new ArrayList<>(); if (commandPrefix != null) { commands.addAll(commandPrefix); } commands.add(wl); commands.add(user); commands.addAll(args); LOG.info("Running as user: {} command: {}", user, commands); return launchProcess(commands, environment, logPreFix, exitCodeCallback, dir); }
/** * Validates topology name / blob key. * * @param key topology name / Key for the blob. */ public static boolean isValidKey(String key) { if (StringUtils.isEmpty(key) || "..".equals(key) || ".".equals(key) || !TOPOLOGY_KEY_PATTERN.matcher(key).matches()) { LOG.error("'{}' does not appear to be valid. It must match {}. And it can't be \".\", \"..\", null or empty string.", key, TOPOLOGY_KEY_PATTERN); return false; } return true; }
/** * Submits the topology with the name taken from the configuration **/ protected int submit(Config conf, TopologyBuilder builder) { String name = (String) Utils.get(conf, Config.TOPOLOGY_NAME, null); if (StringUtils.isBlank(name)) { throw new RuntimeException( "No value found for " + Config.TOPOLOGY_NAME); } return submit(name, conf, builder); }
public static CuratorFramework newCurator(Map<String, Object> conf, List<String> servers, Object port, String root, ZookeeperAuthInfo auth, final List<ACL> defaultAcl) { List<String> serverPorts = new ArrayList<>(); for (String zkServer : servers) { serverPorts.add(zkServer + ":" + ObjectReader.getInt(port)); } String zkStr = StringUtils.join(serverPorts, ",") + root; CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); setupBuilder(builder, zkStr, conf, auth); if (defaultAcl != null) { builder.aclProvider(new ACLProvider() { @Override public List<ACL> getDefaultAcl() { return defaultAcl; } @Override public List<ACL> getAclForPath(String s) { return null; } }); } return builder.build(); }
@Override public void onProgress(String srcFile, String targetFile, long bytesUploaded, long totalBytes) { int length = 50; int p = (int) ((length * bytesUploaded) / totalBytes); String progress = StringUtils.repeat("=", p); String todo = StringUtils.repeat(" ", length - p); System.out.printf("\r[%s%s] %d / %d", progress, todo, bytesUploaded, totalBytes); }
final String principal = StringUtils.isBlank(asUser) ? getPrincipal(subject) : asUser; String serviceName = ClientAuthUtils.get(loginConf, ClientAuthUtils.LOGIN_CONTEXT_CLIENT, "serviceName"); if (serviceName == null) {
public String addToClasspathImpl(Collection<String> classpaths, Collection<String> paths) { List<String> allPaths = new ArrayList<>(); if(classpaths != null) { allPaths.addAll(classpaths); } if(paths != null) { allPaths.addAll(paths); } return StringUtils.join(allPaths, CLASS_PATH_SEPARATOR); }
@Override public void onProgress(String srcFile, String targetFile, long bytesUploaded, long totalBytes) { int length = 50; int p = (int)((length * bytesUploaded) / totalBytes); String progress = StringUtils.repeat("=", p); String todo = StringUtils.repeat(" ", length - p); System.out.printf("\r[%s%s] %d / %d", progress, todo, bytesUploaded, totalBytes); }
public static int processLauncherAndWait(Map<String, Object> conf, String user, List<String> args, final Map<String, String> environment, final String logPreFix) throws IOException { int ret = 0; Process process = processLauncher(conf, user, null, args, environment, logPreFix, null, null); if (StringUtils.isNotBlank(logPreFix)) { Utils.readAndLogStream(logPreFix, process.getInputStream()); } try { process.waitFor(); } catch (InterruptedException e) { LOG.info("{} interrupted.", logPreFix); } ret = process.exitValue(); return ret; }
static Process processLauncher(Map<String, Object> conf, String user, List<String> commandPrefix, List<String> args, Map<String, String> environment, final String logPreFix, final ExitCodeCallback exitCodeCallback, File dir) throws IOException { if (StringUtils.isBlank(user)) { throw new IllegalArgumentException("User cannot be blank when calling processLauncher."); } String wlinitial = (String) (conf.get(Config.SUPERVISOR_WORKER_LAUNCHER)); String stormHome = ConfigUtils.concatIfNotNull(System.getProperty("storm.home")); String wl; if (StringUtils.isNotBlank(wlinitial)) { wl = wlinitial; } else { wl = stormHome + "/bin/worker-launcher"; } List<String> commands = new ArrayList<>(); if (commandPrefix != null){ commands.addAll(commandPrefix); } commands.add(wl); commands.add(user); commands.addAll(args); LOG.info("Running as user: {} command: {}", user, commands); return SupervisorUtils.launchProcess(commands, environment, logPreFix, exitCodeCallback, dir); }
if (StringUtils.isBlank(newElems.get_name())) { newElems.set_name(stormBase.get_name()); if (StringUtils.isBlank(newElems.get_topology_version()) && stormBase.is_set_topology_version()) { newElems.set_topology_version(stormBase.get_topology_version()); newElems.set_launch_time_secs(stormBase.get_launch_time_secs()); if (StringUtils.isBlank(newElems.get_owner())) { newElems.set_owner(stormBase.get_owner()); if (StringUtils.isBlank(newElems.get_principal()) && stormBase.is_set_principal()) { newElems.set_principal(stormBase.get_principal());
public static String applyUUIDToFileName(String fileName) { String fileNameWithExt = Files.getNameWithoutExtension(fileName); String ext = Files.getFileExtension(fileName); if (StringUtils.isEmpty(ext)) { fileName = fileName + "-" + UUID.randomUUID(); } else { fileName = fileNameWithExt + "-" + UUID.randomUUID() + "." + ext; } return fileName; } }
public String addToClasspathImpl(String classpath, Collection<String> paths) { if (paths == null || paths.isEmpty()) { return classpath; } List<String> l = new LinkedList<>(); l.add(classpath); l.addAll(paths); return StringUtils.join(l, CLASS_PATH_SEPARATOR); }
protected String javaCmd(String cmd) { String ret = null; String javaHome = System.getenv().get("JAVA_HOME"); if (StringUtils.isNotBlank(javaHome)) { ret = javaHome + Utils.FILE_PATH_SEPARATOR + "bin" + Utils.FILE_PATH_SEPARATOR + cmd; } else { ret = cmd; } return ret; }
@Override public List<Integer> chooseTasks(int taskId, List<Object> values) { // optimisation : single target if (targetTask.size() == 1) { return targetTask; } // missing content in tuple // should not happen // return empty task ids if (values.size() < 2) { LOG.error("Found tuple with less than 2 values. {}", values); return ImmutableList.of(); } // the first value is always the URL // and the second the metadata String url = (String) values.get(0); Metadata metadata = (Metadata) values.get(1); String partitionKey = partitioner.getPartition(url, metadata); if (StringUtils.isBlank(partitionKey)) { LOG.error("No partition key for {}", url); return ImmutableList.of(); } // hash on the key int partition = Math.abs(partitionKey.hashCode() % targetTask.size()); return ImmutableList.of(targetTask.get(partition)); }
public static void validateSettableACLs(String key, List<AccessControl> acls) throws AuthorizationException { Set<String> aclUsers = new HashSet<>(); List<String> duplicateUsers = new ArrayList<>(); for (AccessControl acl : acls) { String aclUser = acl.get_name(); if (!StringUtils.isEmpty(aclUser) && !aclUsers.add(aclUser)) { LOG.error("'{}' user can't appear more than once in the ACLs", aclUser); duplicateUsers.add(aclUser); } } if (duplicateUsers.size() > 0) { String errorMessage = "user " + Arrays.toString(duplicateUsers.toArray()) + " can't appear more than once in the ACLs for key [" + key + "]."; throw new WrappedAuthorizationException(errorMessage); } }
/** * Returns the combined string, escaped for posix shell. * @param command the list of strings to be combined * @return the resulting command string */ public static String shellCmd (List<String> command) { List<String> changedCommands = new ArrayList<>(command.size()); for (String str: command) { if (str == null) { continue; } changedCommands.add("'" + str.replaceAll("'", "'\"'\"'") + "'"); } return StringUtils.join(changedCommands, " "); }
private String substituteChildOptsInternal(String string, int memOnheap) { if (StringUtils.isNotBlank(string)) { String p = String.valueOf(_port); string = string.replace("%ID%", p); string = string.replace("%WORKER-ID%", _workerId); string = string.replace("%TOPOLOGY-ID%", _topologyId); string = string.replace("%WORKER-PORT%", p); if (memOnheap > 0) { string = string.replace("%HEAP-MEM%", String.valueOf(memOnheap)); } } return string; }
public static NimbusInfo toNimbusInfo(Participant participant) { String id = participant.getId(); if (StringUtils.isBlank(id)) { throw new RuntimeException("No nimbus leader participant host found, have you started your nimbus hosts?"); } NimbusInfo nimbusInfo = NimbusInfo.parse(id); nimbusInfo.setLeader(participant.isLeader()); return nimbusInfo; }