@Override public String getHost() { return description.getHostname(); }
@Override public int hashCode() { return 9824372 + description.getHostname().hashCode() + description.getPort() * 41; }
private void addVariables(Map<String, String> map, String prefix, PeerDescription peer) { map.put(format("%s.hostname", prefix), peer.getHostname()); map.put(format("%s.port", prefix), String.valueOf(peer.getPort())); map.put(format("%s.secure", prefix), String.valueOf(peer.isSecure())); }
@Override public String toString() { return "PeerStatus[hostname=" + description.getHostname() + ",port=" + description.getPort() + ",secure=" + description.isSecure() + ",flowFileCount=" + numFlowFiles + "]"; }
private String resolveNodeApiUrl(final PeerDescription description) { return (description.isSecure() ? "https" : "http") + "://" + description.getHostname() + ":" + description.getPort() + "/nifi-api"; }
private void persistPeerStatuses(final Set<PeerStatus> statuses) { if (persistenceFile == null) { return; } try (final OutputStream fos = new FileOutputStream(persistenceFile); final OutputStream out = new BufferedOutputStream(fos)) { for (final PeerStatus status : statuses) { final PeerDescription description = status.getPeerDescription(); final String line = description.getHostname() + ":" + description.getPort() + ":" + description.isSecure() + ":" + status.isQueryForPeers() + "\n"; out.write(line.getBytes(StandardCharsets.UTF_8)); } } catch (final IOException e) { error(logger, eventReporter, "Failed to persist list of Peers due to {}; if restarted and peer's NCM is down," + " may be unable to transfer data until communications with NCM are restored", e.toString()); logger.error("", e); } }
} catch (final Exception e) { logger.warn("Could not communicate with {}:{} to determine which nodes exist in the remote NiFi cluster, due to {}", peerDescription.getHostname(), peerDescription.getPort(), e.toString()); lastFailure = e;
private CommunicationsSession establishSiteToSiteConnection(final PeerStatus peerStatus) throws IOException { final PeerDescription description = peerStatus.getPeerDescription(); return establishSiteToSiteConnection(description.getHostname(), description.getPort()); }
SiteToSiteTransportProtocol.RAW, PeerDescriptionModifier.RequestType.Peers, new HashMap<>()); dos.writeUTF(modifiedTarget.getHostname()); dos.writeInt(modifiedTarget.getPort()); dos.writeBoolean(modifiedTarget.isSecure());
@Override public Set<PeerStatus> fetchRemotePeerStatuses(final PeerDescription peerDescription) throws IOException { final String hostname = peerDescription.getHostname(); final int port = peerDescription.getPort(); final URI clusterUrl = siteInfoProvider.getActiveClusterUrl();
@Override public Set<PeerStatus> fetchRemotePeerStatuses(PeerDescription peerDescription) throws IOException { // Each node should has the same URL structure and network reach-ability with the proxy configuration. try (final SiteToSiteRestApiClient apiClient = new SiteToSiteRestApiClient(config.getSslContext(), config.getHttpProxy(), config.getEventReporter())) { final String scheme = peerDescription.isSecure() ? "https" : "http"; apiClient.setBaseUrl(scheme, peerDescription.getHostname(), peerDescription.getPort()); final int timeoutMillis = (int) config.getTimeout(TimeUnit.MILLISECONDS); apiClient.setConnectTimeoutMillis(timeoutMillis); apiClient.setReadTimeoutMillis(timeoutMillis); apiClient.setCacheExpirationMillis(config.getCacheExpiration(TimeUnit.MILLISECONDS)); apiClient.setLocalAddress(config.getLocalAddress()); final Collection<PeerDTO> peers = apiClient.getPeers(); if(peers == null || peers.size() == 0){ throw new IOException("Couldn't get any peer to communicate with. " + apiClient.getBaseUrl() + " returned zero peers."); } // Convert the PeerDTO's to PeerStatus objects. Use 'true' for the query-peer-for-peers flag because Site-to-Site over HTTP // was added in NiFi 1.0.0, which means that peer-to-peer queries are always allowed. return peers.stream().map(p -> new PeerStatus(new PeerDescription(p.getHostname(), p.getPort(), p.isSecure()), p.getFlowFileCount(), true)) .collect(Collectors.toSet()); } }
peer.setHostname(target.getHostname()); peer.setPort(target.getPort()); peer.setSecure(target.isSecure()); peer.setHostname(target.getHostname()); peer.setPort(target.getPort()); peer.setSecure(target.isSecure());
final String peerUrl = "nifi://" + peerDescription.getHostname() + ":" + peerDescription.getPort(); peer = new Peer(peerDescription, commsSession, peerUrl, clusterUrl.toString());
private void addVariables(Map<String, String> map, String prefix, PeerDescription peer) { map.put(format("%s.hostname", prefix), peer.getHostname()); map.put(format("%s.port", prefix), String.valueOf(peer.getPort())); map.put(format("%s.secure", prefix), String.valueOf(peer.isSecure())); }
SiteToSiteTransportProtocol.RAW, PeerDescriptionModifier.RequestType.Peers, new HashMap<>()); dos.writeUTF(modifiedTarget.getHostname()); dos.writeInt(modifiedTarget.getPort()); dos.writeBoolean(modifiedTarget.isSecure());