@Override public RequestType getRequestType(final Peer peer) throws IOException { if (!handshakeCompleted) { throw new IllegalStateException("Handshake has not been completed"); } if (shutdown) { throw new IllegalStateException("Protocol is shutdown"); } logger.debug("{} Reading Request Type from {} using {}", new Object[]{this, peer, peer.getCommunicationsSession()}); final RequestType requestType = RequestType.readRequestType(new DataInputStream(peer.getCommunicationsSession().getInput().getInputStream())); logger.debug("{} Got Request Type {} from {}", new Object[]{this, requestType, peer}); return requestType; }
final String clusterUrl = "nifi://localhost:" + req.getLocalPort(); return new Peer(peerDescription, commSession, peerUrl, clusterUrl);
final CommunicationsSession commsSession = peer.getCommunicationsSession(); final DataOutputStream dos = new DataOutputStream(commsSession.getOutput().getOutputStream()); final PeerDescription modifiedTarget = peerDescriptionModifier.modify(peer.getDescription(), target, SiteToSiteTransportProtocol.RAW, PeerDescriptionModifier.RequestType.Peers, new HashMap<>());
final CommunicationsSession commsSession = peer.getCommunicationsSession(); commsSession.setTimeout(timeoutMillis); final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream()); dos.writeUTF(peer.getUrl()); transitUriPrefix = peer.getUrl(); logger.error("{} received unexpected response {} from {} when negotiating Codec", new Object[]{ this, handshakeResponse, peer}); peer.close(); throw new HandshakeException("Received unexpected response " + handshakeResponse);
if (connection != null && connection.getPeer().isPenalized(portId)) { peer = new Peer(peerDescription, commsSession, peerUrl, clusterUrl.toString()); peer.close(); } catch (final IOException ioe) { peerSelector.penalize(peer, penalizationMillis); cleanup(protocol, peer); throw new PortNotRunningException(peer.toString() + " indicates that port " + portId + " is not running"); } else if (protocol.isPortUnknown()) { peerSelector.penalize(peer, penalizationMillis); cleanup(protocol, peer); throw new UnknownPortException(peer.toString() + " indicates that port " + portId + " is not known"); codec = connection.getCodec(); peer = connection.getPeer(); commsSession = peer.getCommunicationsSession(); protocol = connection.getSocketClientProtocol();
CommunicationsSession commsSession = peer.getCommunicationsSession(); final Response transactionConfirmationResponse = readTransactionResponse(true, commsSession); if (transactionConfirmationResponse.getCode() == ResponseCode.CONFIRM_TRANSACTION) { peer.penalize(port.getIdentifier(), port.getYieldPeriod(TimeUnit.MILLISECONDS)); } else if (transactionResponse.getCode() != ResponseCode.TRANSACTION_FINISHED) { throw new ProtocolException("After sending data, expected TRANSACTION_FINISHED response but got " + transactionResponse);
final CommunicationsSession commsSession = peer.getCommunicationsSession(); final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream()); String remoteDn = commsSession.getUserDn(); final String sourceSystemFlowFileUuid = dataPacket.getAttributes().get(CoreAttributes.UUID.key()); final String host = StringUtils.isEmpty(peer.getHost()) ? "unknown" : peer.getHost(); final String port = peer.getPort() <= 0 ? "unknown" : String.valueOf(peer.getPort()); ? null : "urn:nifi:" + sourceSystemFlowFileUuid, "Remote Host=" + peer.getHost() + ", Remote DN=" + remoteDn, transferMillis); session.transfer(flowFile, Relationship.ANONYMOUS); flowFilesReceived.add(flowFile);
final CommunicationsSession commsSession = peer.getCommunicationsSession(); String remoteDn = commsSession.getUserDn(); if (remoteDn == null) { session.getProvenanceReporter().send(flowFile, transitUri, "Remote Host=" + peer.getHost() + ", Remote DN=" + remoteDn, transmissionMillis, false); session.remove(flowFile);
final Peer peer = new Peer(peerStatus.getPeerDescription(), commSession, nodeApiUrl, clusterUrls.toString()); portId = siteInfoProvider.getPortIdentifier(config.getPortName(), direction); if (StringUtils.isEmpty(portId)) { peer.close(); throw new IOException("Failed to determine the identifier of port " + config.getPortName()); apiClient.setBaseUrl(peer.getUrl()); apiClient.setConnectTimeoutMillis(timeoutMillis); apiClient.setReadTimeoutMillis(timeoutMillis);
final CommunicationsSession commsSession = establishSiteToSiteConnection(hostname, port); final Peer peer = new Peer(clusterPeerDescription, commsSession, "nifi://" + hostname + ":" + port, clusterUrl.toString()); final SocketClientProtocol clientProtocol = new SocketClientProtocol(); final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream()); peer.close(); throw new IOException("Failed to determine the identifier of port " + remoteDestination.getName()); peer.close(); } catch (final IOException e) { final String message = String.format("%s Failed to close resources when updating list of peers due to %s", this, e.toString());
@Override public final String toString() { return getClass().getSimpleName() + "[Url=" + peer.getUrl() + ", TransferDirection=" + direction + ", State=" + state + "]"; }
/** * Updates internal state map to penalize a PeerStatus that points to the * specified peer * * @param peer the peer * @param penalizationMillis period of time to penalize a given peer */ public void penalize(final Peer peer, final long penalizationMillis) { penalize(peer.getDescription(), penalizationMillis); }
peer.penalize(destinationId, penaltyMillis); backoff = true; } else if (transactionResponse.getCode() != ResponseCode.TRANSACTION_FINISHED) {
protected String createTransitUri(Peer peer, String sourceFlowFileIdentifier) { return peer.createTransitUri(sourceFlowFileIdentifier); }
private void cleanup(final SocketClientProtocol protocol, final Peer peer) { if (protocol != null && peer != null) { try { protocol.shutdown(peer); } catch (final TransmissionDisabledException e) { // User disabled transmission.... do nothing. logger.debug(this + " Transmission Disabled by User"); } catch (IOException e1) { } } if (peer != null) { try { peer.close(); } catch (final TransmissionDisabledException e) { // User disabled transmission.... do nothing. logger.debug(this + " Transmission Disabled by User"); } catch (IOException e1) { } } }
CommunicationsSession commsSession = peer.getCommunicationsSession(); final Response transactionConfirmationResponse = readTransactionResponse(true, commsSession); if (transactionConfirmationResponse.getCode() == ResponseCode.CONFIRM_TRANSACTION) { peer.penalize(port.getIdentifier(), port.getYieldPeriod(TimeUnit.MILLISECONDS)); } else if (transactionResponse.getCode() != ResponseCode.TRANSACTION_FINISHED) { throw new ProtocolException("After sending data, expected TRANSACTION_FINISHED response but got " + transactionResponse);
final CommunicationsSession commsSession = peer.getCommunicationsSession(); final DataInputStream dis = new DataInputStream(commsSession.getInput().getInputStream()); String remoteDn = commsSession.getUserDn(); final String sourceSystemFlowFileUuid = dataPacket.getAttributes().get(CoreAttributes.UUID.key()); final String host = StringUtils.isEmpty(peer.getHost()) ? "unknown" : peer.getHost(); final String port = peer.getPort() <= 0 ? "unknown" : String.valueOf(peer.getPort()); ? null : "urn:nifi:" + sourceSystemFlowFileUuid, "Remote Host=" + peer.getHost() + ", Remote DN=" + remoteDn, transferMillis); session.transfer(flowFile, Relationship.ANONYMOUS); flowFilesReceived.add(flowFile);
final CommunicationsSession commsSession = peer.getCommunicationsSession(); String remoteDn = commsSession.getUserDn(); if (remoteDn == null) { session.getProvenanceReporter().send(flowFile, transitUri, "Remote Host=" + peer.getHost() + ", Remote DN=" + remoteDn, transmissionMillis, false); session.remove(flowFile);
@Override protected String createTransitUri(Peer peer, String sourceFlowFileIdentifier) { String transitUriPrefix = handshakeProperties.getTransitUriPrefix(); return (transitUriPrefix == null) ? peer.getUrl() : transitUriPrefix + sourceFlowFileIdentifier; } }
public boolean offer(final EndpointConnection endpointConnection) { final Peer peer = endpointConnection.getPeer(); if (peer == null) { return false; } final BlockingQueue<EndpointConnection> connectionQueue = connectionQueueMap.get(peer.getDescription()); if (connectionQueue == null) { return false; } activeConnections.remove(endpointConnection); if (shutdown) { terminate(endpointConnection); return false; } else { endpointConnection.setLastTimeUsed(); return connectionQueue.offer(endpointConnection); } }