@Override public void syncRemoteAssignments(Map<String, byte[]> remote) { Map<String, Assignment> tmp = new ConcurrentHashMap<>(); for (Map.Entry<String, byte[]> entry : remote.entrySet()) { tmp.put(entry.getKey(), ClusterUtils.maybeDeserialize(entry.getValue(), Assignment.class)); } this.idToAssignment = tmp; }
@Override public LogConfig topologyLogConfig(String stormId, Runnable cb) { if (cb != null) { logConfigCallback.put(stormId, cb); } String path = ClusterUtils.logConfigPath(stormId); return ClusterUtils.maybeDeserialize(stateStorage.get_data(path, cb != null), LogConfig.class); }
@Override public StormBase stormBase(String stormId, Runnable callback) { if (callback != null) { stormBaseCallback.put(stormId, callback); } return ClusterUtils.maybeDeserialize(stateStorage.get_data(ClusterUtils.stormPath(stormId), callback != null), StormBase.class); }
@Override public Assignment remoteAssignmentInfo(String stormId, Runnable callback) { if (callback != null) { assignmentInfoCallback.put(stormId, callback); } byte[] serialized = stateStorage.get_data(ClusterUtils.assignmentPath(stormId), callback != null); return ClusterUtils.maybeDeserialize(serialized, Assignment.class); }
@Override public Credentials credentials(String stormId, Runnable callback) { if (callback != null) { credentialsCallback.put(stormId, callback); } String path = ClusterUtils.credentialsPath(stormId); return ClusterUtils.maybeDeserialize(stateStorage.get_data(path, callback != null), Credentials.class); }
@Override public SupervisorInfo supervisorInfo(String supervisorId) { String path = ClusterUtils.supervisorPath(supervisorId); return ClusterUtils.maybeDeserialize(stateStorage.get_data(path, false), SupervisorInfo.class); }
@Override public ClusterWorkerHeartbeat getWorkerHeartbeat(String stormId, String node, Long port) { byte[] bytes = stateStorage.get_worker_hb(ClusterUtils.workerbeatPath(stormId, node, port), false); return ClusterUtils.maybeDeserialize(bytes, ClusterWorkerHeartbeat.class); }
@Override public List<NimbusSummary> nimbuses() { List<NimbusSummary> nimbusSummaries = new ArrayList<>(); List<String> nimbusIds = stateStorage.get_children(ClusterUtils.NIMBUSES_SUBTREE, false); for (String nimbusId : nimbusIds) { byte[] serialized = stateStorage.get_data(ClusterUtils.nimbusPath(nimbusId), false); // check for null which can exist because of a race condition in which nimbus nodes in zk may have been // removed when connections are reconnected after getting children in the above line if (serialized != null) { NimbusSummary nimbusSummary = ClusterUtils.maybeDeserialize(serialized, NimbusSummary.class); nimbusSummaries.add(nimbusSummary); } } return nimbusSummaries; }
@Override public ErrorInfo lastError(String stormId, String componentId) { String path = ClusterUtils.lastErrorPath(stormId, componentId); if (stateStorage.node_exists(path, false)) { ErrorInfo errorInfo = ClusterUtils.maybeDeserialize(stateStorage.get_data(path, false), ErrorInfo.class); return errorInfo; } return null; }
@Override public PrivateWorkerKey getPrivateWorkerKey(WorkerTokenServiceType type, String topologyId, long keyVersion) { String path = ClusterUtils.secretKeysPath(type, topologyId, keyVersion); byte[] data = stateStorage.get_data(path, false); if (data == null) { LOG.debug("Could not find entry at {} will sync to see if that fixes it", path); //We didn't find it, but there are races, so we want to check again after a sync stateStorage.sync_path(path); data = stateStorage.get_data(path, false); } return ClusterUtils.maybeDeserialize(data, PrivateWorkerKey.class); }
@Override public List<ErrorInfo> errors(String stormId, String componentId) { List<ErrorInfo> errorInfos = new ArrayList<>(); String path = ClusterUtils.errorPath(stormId, componentId); if (stateStorage.node_exists(path, false)) { List<String> childrens = stateStorage.get_children(path, false); for (String child : childrens) { String childPath = path + ClusterUtils.ZK_SEPERATOR + child; ErrorInfo errorInfo = ClusterUtils.maybeDeserialize(stateStorage.get_data(childPath, false), ErrorInfo.class); if (errorInfo != null) { errorInfos.add(errorInfo); } } } Collections.sort(errorInfos, new Comparator<ErrorInfo>() { public int compare(ErrorInfo arg0, ErrorInfo arg1) { return Integer.compare(arg1.get_error_time_secs(), arg0.get_error_time_secs()); } }); return errorInfos; }
@Override public List<ProfileRequest> getTopologyProfileRequests(String stormId) { List<ProfileRequest> profileRequests = new ArrayList<>(); String path = ClusterUtils.profilerConfigPath(stormId); if (stateStorage.node_exists(path, false)) { List<String> strs = stateStorage.get_children(path, false); for (String str : strs) { String childPath = path + ClusterUtils.ZK_SEPERATOR + str; byte[] raw = stateStorage.get_data(childPath, false); ProfileRequest request = ClusterUtils.maybeDeserialize(raw, ProfileRequest.class); if (request != null) { profileRequests.add(request); } } } return profileRequests; }
@Override public VersionedData<Assignment> assignmentInfoWithVersion(String stormId, Runnable callback) { if (callback != null) { assignmentInfoWithVersionCallback.put(stormId, callback); } Assignment assignment = null; Integer version = 0; VersionedData<byte[]> dataWithVersion = stateStorage.get_data_with_version(ClusterUtils.assignmentPath(stormId), callback != null); if (dataWithVersion != null) { assignment = ClusterUtils.maybeDeserialize(dataWithVersion.getData(), Assignment.class); version = dataWithVersion.getVersion(); } return new VersionedData<Assignment>(version, assignment); }
@Override public void removeExpiredPrivateWorkerKeys(String topologyId) { for (WorkerTokenServiceType type : WorkerTokenServiceType.values()) { String basePath = ClusterUtils.secretKeysPath(type, topologyId); try { for (String version : stateStorage.get_children(basePath, false)) { String fullPath = basePath + ClusterUtils.ZK_SEPERATOR + version; try { PrivateWorkerKey key = ClusterUtils.maybeDeserialize(stateStorage.get_data(fullPath, false), PrivateWorkerKey.class); if (Time.currentTimeMillis() > key.get_expirationTimeMillis()) { LOG.info("Removing expired worker key {}", fullPath); stateStorage.delete_node(fullPath); } } catch (RuntimeException e) { //This should never happen because only the primary nimbus is active, but just in case // declare the race safe, even if we lose it. if (!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { throw e; } } } } catch (RuntimeException e) { //No node for basePath is OK, nothing to remove if (!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) { throw e; } } } }
@Override public Assignment assignmentInfo(String stormId, Runnable callback) { if (callback != null) { assignmentInfoCallback.put(stormId, callback); } byte[] serialized = stateStorage.get_data(ClusterUtils.assignmentPath(stormId), callback != null); return ClusterUtils.maybeDeserialize(serialized, Assignment.class); }
@Override public StormBase stormBase(String stormId, Runnable callback) { if (callback != null) { stormBaseCallback.put(stormId, callback); } return ClusterUtils.maybeDeserialize(stateStorage.get_data(ClusterUtils.stormPath(stormId), callback != null), StormBase.class); }
@Override public LogConfig topologyLogConfig(String stormId, Runnable cb) { if (cb != null){ logConfigCallback.put(stormId, cb); } String path = ClusterUtils.logConfigPath(stormId); return ClusterUtils.maybeDeserialize(stateStorage.get_data(path, cb != null), LogConfig.class); }
@Override public ClusterWorkerHeartbeat getWorkerHeartbeat(String stormId, String node, Long port) { byte[] bytes = stateStorage.get_worker_hb(ClusterUtils.workerbeatPath(stormId, node, port), false); return ClusterUtils.maybeDeserialize(bytes, ClusterWorkerHeartbeat.class); }
@Override public SupervisorInfo supervisorInfo(String supervisorId) { String path = ClusterUtils.supervisorPath(supervisorId); return ClusterUtils.maybeDeserialize(stateStorage.get_data(path, false), SupervisorInfo.class); }
@Override public ErrorInfo lastError(String stormId, String componentId) { String path = ClusterUtils.lastErrorPath(stormId, componentId); if (stateStorage.node_exists(path, false)) { ErrorInfo errorInfo = ClusterUtils.maybeDeserialize(stateStorage.get_data(path, false), ErrorInfo.class); return errorInfo; } return null; }