/** * Synchronizes the specified stream from the specified state spout component id with the provided ISubscribedState object. * * The recommended usage of this method is as follows: * * ```java _myState = context.setSubscribedState(componentId, streamId, new MyState()); ``` * * @param componentId the id of the StateSpout component to subscribe to * @param streamId the stream to subscribe to * @param obj Provided ISubscribedState implementation * @return Returns the ISubscribedState object provided */ public <T extends ISubscribedState> T setSubscribedState(String componentId, String streamId, T obj) { throw new NotImplementedException(); }
@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); }
/** * 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; }
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); }
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; } }
/** * 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 updateState(WindowsState state, List<TridentTuple> tuples, TridentCollector collector) { Long currentTxId = state.getCurrentTxId(); LOG.debug("Removing triggers using WindowStateUpdater, txnId: [{}] ", currentTxId); for (TridentTuple tuple : tuples) { try { Object fieldValue = tuple.getValueByField(WindowTridentProcessor.TRIGGER_FIELD_NAME); if (!(fieldValue instanceof WindowTridentProcessor.TriggerInfo)) { throw new IllegalClassException(WindowTridentProcessor.TriggerInfo.class, fieldValue.getClass()); } WindowTridentProcessor.TriggerInfo triggerInfo = (WindowTridentProcessor.TriggerInfo) fieldValue; String triggerCompletedKey = WindowTridentProcessor.getWindowTriggerInprocessIdPrefix(triggerInfo.windowTaskId) + currentTxId; LOG.debug("Removing trigger key [{}] and trigger completed key [{}] from store: [{}]", triggerInfo, triggerCompletedKey, windowsStore); windowsStore.removeAll(Lists.newArrayList(triggerInfo.generateTriggerKey(), triggerCompletedKey)); } catch (Exception ex) { LOG.warn(ex.getMessage()); collector.reportError(ex); throw new FailedException(ex); } } }
/** * @return Returns this class as byte[] */ public byte[] toByteArray() { return SerializationUtils.serialize(this); }
public static LGPayload deserialize(byte[] serialized) { return (LGPayload) SerializationUtils.deserialize(serialized); }
public void checkCredentialsChanged() { Credentials newCreds = workerState.stormClusterState.credentials(topologyId, null); if (!ObjectUtils.equals(newCreds, credentialsAtom.get())) { // This does not have to be atomic, worst case we update when one is not needed ClientAuthUtils.updateSubject(subject, autoCreds, (null == newCreds) ? null : newCreds.get_creds()); for (IRunningExecutor executor : executorsAtom.get()) { executor.credentialsChanged(newCreds); } credentialsAtom.set(newCreds); } }
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; }
final String principal = StringUtils.isBlank(asUser) ? getPrincipal(subject) : asUser; String serviceName = ClientAuthUtils.get(loginConf, ClientAuthUtils.LOGIN_CONTEXT_CLIENT, "serviceName"); if (serviceName == null) {
/** * All state from all subscribed state spouts streams will be synced with the provided object. * * It is recommended that your ISubscribedState object is kept as an instance variable of this object. The recommended usage of this * method is as follows: * * ```java _myState = context.setAllSubscribedState(new MyState()); ``` * * @param obj Provided ISubscribedState implementation * @return Returns the ISubscribedState object provided */ public <T extends ISubscribedState> T setAllSubscribedState(T obj) { //check that only subscribed to one component/stream for statespout //setsubscribedstate appropriately throw new NotImplementedException(); }
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 byte[] toByteArray() { return SerializationUtils.serialize(this); }
public static LGCommand deserialize(byte[] serialized) { return (LGCommand) SerializationUtils.deserialize(serialized); }
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());
/** * Synchronizes the specified stream from the specified state spout component * id with the provided ISubscribedState object. * * The recommended usage of this method is as follows: * * ```java * _myState = context.setSubscribedState(componentId, streamId, new MyState()); * ``` * * @param componentId the id of the StateSpout component to subscribe to * @param streamId the stream to subscribe to * @param obj Provided ISubscribedState implementation * @return Returns the ISubscribedState object provided */ public <T extends ISubscribedState> T setSubscribedState(String componentId, String streamId, T obj) { throw new NotImplementedException(); }
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); } }