@Test public void testUnkownClusterUrl() throws Exception { final URI uri = server.getURI(); try ( SiteToSiteClient client = getDefaultBuilder() .url("http: .portName("input-running") .build() ) { final Transaction transaction = client.createTransaction(TransferDirection.SEND); assertNull(transaction); } }
@Override public Transaction createTransaction(final TransferDirection direction) throws HandshakeException, PortNotRunningException, ProtocolException, UnknownPortException, IOException { final int timeoutMillis = (int) config.getTimeout(TimeUnit.MILLISECONDS); PeerStatus peerStatus; while ((peerStatus = peerSelector.getNextPeerStatus(direction)) != null) { logger.debug("peerStatus={}", peerStatus); final CommunicationsSession commSession = new HttpCommunicationsSession(); final String nodeApiUrl = resolveNodeApiUrl(peerStatus.getPeerDescription()); final StringBuilder clusterUrls = new StringBuilder(); config.getUrls().forEach(url -> { if (clusterUrls.length() > 0) { clusterUrls.append(","); clusterUrls.append(url); } }); final Peer peer = new Peer(peerStatus.getPeerDescription(), commSession, nodeApiUrl, clusterUrls.toString()); final int penaltyMillis = (int) config.getPenalizationPeriod(TimeUnit.MILLISECONDS); String portId = config.getPortIdentifier(); if (StringUtils.isEmpty(portId)) { portId = siteInfoProvider.getPortIdentifier(config.getPortName(), direction); if (StringUtils.isEmpty(portId)) { peer.close(); throw new IOException("Failed to determine the identifier of port " + config.getPortName()); } } final SiteToSiteRestApiClient apiClient = new SiteToSiteRestApiClient(config.getSslContext(), config.getHttpProxy(), config.getEventReporter()); apiClient.setBaseUrl(peer.getUrl()); apiClient.setConnectTimeoutMillis(timeoutMillis); apiClient.setReadTimeoutMillis(timeoutMillis); apiClient.setCompress(config.isUseCompression()); apiClient.setRequestExpirationMillis(config.getIdleConnectionExpiration(TimeUnit.MILLISECONDS)); apiClient.setBatchCount(config.getPreferredBatchCount()); apiClient.setBatchSize(config.getPreferredBatchSize()); apiClient.setBatchDurationMillis(config.getPreferredBatchDuration(TimeUnit.MILLISECONDS)); final String transactionUrl; try { transactionUrl = apiClient.initiateTransaction(direction, portId); commSession.setUserDn(apiClient.getTrustedPeerDn()); } catch (final Exception e) { apiClient.close(); logger.warn("Penalizing a peer {} due to {}", peer, e.toString()); peerSelector.penalize(peer, penaltyMillis); if (e instanceof UnknownPortException || e instanceof PortNotRunningException || e instanceof HandshakeException) { throw e; } logger.debug("Continue trying other peers..."); continue; } final Integer transactionProtocolVersion = apiClient.getTransactionProtocolVersion(); final HttpClientTransaction transaction = new HttpClientTransaction(transactionProtocolVersion, peer, direction, config.isUseCompression(), portId, penaltyMillis, config.getEventReporter()) { @Override protected void close() throws IOException { try { super.close(); } finally { activeTransactions.remove(this); } } }; try { transaction.initialize(apiClient, transactionUrl); } catch (final Exception e) { transaction.error(); throw e; } activeTransactions.add(transaction); return transaction; } logger.info("Couldn't find a valid peer to communicate with."); return null; }
HttpClient extends AbstractSiteToSiteClient implements PeerStatusProvider { @Override public Transaction createTransaction(final TransferDirection direction) throws HandshakeException, PortNotRunningException, ProtocolException, UnknownPortException, IOException { final int timeoutMillis = (int) config.getTimeout(TimeUnit.MILLISECONDS); PeerStatus peerStatus; while ((peerStatus = peerSelector.getNextPeerStatus(direction)) != null) { logger.debug("peerStatus={}", peerStatus); final CommunicationsSession commSession = new HttpCommunicationsSession(); final String nodeApiUrl = resolveNodeApiUrl(peerStatus.getPeerDescription()); final StringBuilder clusterUrls = new StringBuilder(); config.getUrls().forEach(url -> { if (clusterUrls.length() > 0) { clusterUrls.append(","); clusterUrls.append(url); } }); final Peer peer = new Peer(peerStatus.getPeerDescription(), commSession, nodeApiUrl, clusterUrls.toString()); final int penaltyMillis = (int) config.getPenalizationPeriod(TimeUnit.MILLISECONDS); String portId = config.getPortIdentifier(); if (StringUtils.isEmpty(portId)) { portId = siteInfoProvider.getPortIdentifier(config.getPortName(), direction); if (StringUtils.isEmpty(portId)) { peer.close(); throw new IOException("Failed to determine the identifier of port " + config.getPortName()); } } final SiteToSiteRestApiClient apiClient = new SiteToSiteRestApiClient(config.getSslContext(), config.getHttpProxy(), config.getEventReporter()); apiClient.setBaseUrl(peer.getUrl()); apiClient.setConnectTimeoutMillis(timeoutMillis); apiClient.setReadTimeoutMillis(timeoutMillis); apiClient.setCompress(config.isUseCompression()); apiClient.setRequestExpirationMillis(config.getIdleConnectionExpiration(TimeUnit.MILLISECONDS)); apiClient.setBatchCount(config.getPreferredBatchCount()); apiClient.setBatchSize(config.getPreferredBatchSize()); apiClient.setBatchDurationMillis(config.getPreferredBatchDuration(TimeUnit.MILLISECONDS)); final String transactionUrl; try { transactionUrl = apiClient.initiateTransaction(direction, portId); commSession.setUserDn(apiClient.getTrustedPeerDn()); } catch (final Exception e) { apiClient.close(); logger.warn("Penalizing a peer {} due to {}", peer, e.toString()); peerSelector.penalize(peer, penaltyMillis); if (e instanceof UnknownPortException || e instanceof PortNotRunningException || e instanceof HandshakeException) { throw e; } logger.debug("Continue trying other peers..."); continue; } final Integer transactionProtocolVersion = apiClient.getTransactionProtocolVersion(); final HttpClientTransaction transaction = new HttpClientTransaction(transactionProtocolVersion, peer, direction, config.isUseCompression(), portId, penaltyMillis, config.getEventReporter()) { @Override protected void close() throws IOException { try { super.close(); } finally { activeTransactions.remove(this); } } }; try { transaction.initialize(apiClient, transactionUrl); } catch (final Exception e) { transaction.error(); throw e; } activeTransactions.add(transaction); return transaction; } logger.info("Couldn't find a valid peer to communicate with."); return null; } }
HttpClient extends AbstractSiteToSiteClient implements PeerStatusProvider { @Override public Transaction createTransaction(final TransferDirection direction) throws HandshakeException, PortNotRunningException, ProtocolException, UnknownPortException, IOException { final int timeoutMillis = (int) config.getTimeout(TimeUnit.MILLISECONDS); PeerStatus peerStatus; while ((peerStatus = peerSelector.getNextPeerStatus(direction)) != null) { logger.debug("peerStatus={}", peerStatus); final CommunicationsSession commSession = new HttpCommunicationsSession(); final String nodeApiUrl = resolveNodeApiUrl(peerStatus.getPeerDescription()); final StringBuilder clusterUrls = new StringBuilder(); config.getUrls().forEach(url -> { if (clusterUrls.length() > 0) { clusterUrls.append(","); clusterUrls.append(url); } }); final Peer peer = new Peer(peerStatus.getPeerDescription(), commSession, nodeApiUrl, clusterUrls.toString()); final int penaltyMillis = (int) config.getPenalizationPeriod(TimeUnit.MILLISECONDS); String portId = config.getPortIdentifier(); if (StringUtils.isEmpty(portId)) { portId = siteInfoProvider.getPortIdentifier(config.getPortName(), direction); if (StringUtils.isEmpty(portId)) { peer.close(); throw new IOException("Failed to determine the identifier of port " + config.getPortName()); } } final SiteToSiteRestApiClient apiClient = new SiteToSiteRestApiClient(config.getSslContext(), config.getHttpProxy(), config.getEventReporter()); apiClient.setBaseUrl(peer.getUrl()); apiClient.setConnectTimeoutMillis(timeoutMillis); apiClient.setReadTimeoutMillis(timeoutMillis); apiClient.setCompress(config.isUseCompression()); apiClient.setRequestExpirationMillis(config.getIdleConnectionExpiration(TimeUnit.MILLISECONDS)); apiClient.setBatchCount(config.getPreferredBatchCount()); apiClient.setBatchSize(config.getPreferredBatchSize()); apiClient.setBatchDurationMillis(config.getPreferredBatchDuration(TimeUnit.MILLISECONDS)); final String transactionUrl; try { transactionUrl = apiClient.initiateTransaction(direction, portId); commSession.setUserDn(apiClient.getTrustedPeerDn()); } catch (final Exception e) { apiClient.close(); logger.warn("Penalizing a peer {} due to {}", peer, e.toString()); peerSelector.penalize(peer, penaltyMillis); if (e instanceof UnknownPortException || e instanceof PortNotRunningException || e instanceof HandshakeException) { throw e; } logger.debug("Continue trying other peers..."); continue; } final Integer transactionProtocolVersion = apiClient.getTransactionProtocolVersion(); final HttpClientTransaction transaction = new HttpClientTransaction(transactionProtocolVersion, peer, direction, config.isUseCompression(), portId, penaltyMillis, config.getEventReporter()) { @Override protected void close() throws IOException { try { super.close(); } finally { activeTransactions.remove(this); } } }; try { transaction.initialize(apiClient, transactionUrl); } catch (final Exception e) { transaction.error(); throw e; } activeTransactions.add(transaction); return transaction; } logger.info("Couldn't find a valid peer to communicate with."); return null; } HttpClient(final SiteToSiteClientConfig config); }
HttpClient extends AbstractSiteToSiteClient implements PeerStatusProvider { @Override public Transaction createTransaction(final TransferDirection direction) throws HandshakeException, PortNotRunningException, ProtocolException, UnknownPortException, IOException { final int timeoutMillis = (int) config.getTimeout(TimeUnit.MILLISECONDS); PeerStatus peerStatus; while ((peerStatus = peerSelector.getNextPeerStatus(direction)) != null) { logger.debug("peerStatus={}", peerStatus); final CommunicationsSession commSession = new HttpCommunicationsSession(); final String nodeApiUrl = resolveNodeApiUrl(peerStatus.getPeerDescription()); final StringBuilder clusterUrls = new StringBuilder(); config.getUrls().forEach(url -> { if (clusterUrls.length() > 0) { clusterUrls.append(","); clusterUrls.append(url); } }); final Peer peer = new Peer(peerStatus.getPeerDescription(), commSession, nodeApiUrl, clusterUrls.toString()); final int penaltyMillis = (int) config.getPenalizationPeriod(TimeUnit.MILLISECONDS); String portId = config.getPortIdentifier(); if (StringUtils.isEmpty(portId)) { portId = siteInfoProvider.getPortIdentifier(config.getPortName(), direction); if (StringUtils.isEmpty(portId)) { peer.close(); throw new IOException("Failed to determine the identifier of port " + config.getPortName()); } } final SiteToSiteRestApiClient apiClient = new SiteToSiteRestApiClient(config.getSslContext(), config.getHttpProxy(), config.getEventReporter()); apiClient.setBaseUrl(peer.getUrl()); apiClient.setConnectTimeoutMillis(timeoutMillis); apiClient.setReadTimeoutMillis(timeoutMillis); apiClient.setCompress(config.isUseCompression()); apiClient.setRequestExpirationMillis(config.getIdleConnectionExpiration(TimeUnit.MILLISECONDS)); apiClient.setBatchCount(config.getPreferredBatchCount()); apiClient.setBatchSize(config.getPreferredBatchSize()); apiClient.setBatchDurationMillis(config.getPreferredBatchDuration(TimeUnit.MILLISECONDS)); final String transactionUrl; try { transactionUrl = apiClient.initiateTransaction(direction, portId); commSession.setUserDn(apiClient.getTrustedPeerDn()); } catch (final Exception e) { apiClient.close(); logger.warn("Penalizing a peer {} due to {}", peer, e.toString()); peerSelector.penalize(peer, penaltyMillis); if (e instanceof UnknownPortException || e instanceof PortNotRunningException || e instanceof HandshakeException) { throw e; } logger.debug("Continue trying other peers..."); continue; } final Integer transactionProtocolVersion = apiClient.getTransactionProtocolVersion(); final HttpClientTransaction transaction = new HttpClientTransaction(transactionProtocolVersion, peer, direction, config.isUseCompression(), portId, penaltyMillis, config.getEventReporter()) { @Override protected void close() throws IOException { try { super.close(); } finally { activeTransactions.remove(this); } } }; try { transaction.initialize(apiClient, transactionUrl); } catch (final Exception e) { transaction.error(); throw e; } activeTransactions.add(transaction); return transaction; } logger.info("Couldn't find a valid peer to communicate with."); return null; } HttpClient(final SiteToSiteClientConfig config); @Override PeerDescription getBootstrapPeerDescription(); @Override Set<PeerStatus> fetchRemotePeerStatuses(PeerDescription peerDescription); @Override Transaction createTransaction(final TransferDirection direction); @Override boolean isSecure(); @Override void close(); }
HttpClient extends AbstractSiteToSiteClient implements PeerStatusProvider { @Override public Transaction createTransaction(final TransferDirection direction) throws HandshakeException, PortNotRunningException, ProtocolException, UnknownPortException, IOException { final int timeoutMillis = (int) config.getTimeout(TimeUnit.MILLISECONDS); PeerStatus peerStatus; while ((peerStatus = peerSelector.getNextPeerStatus(direction)) != null) { logger.debug("peerStatus={}", peerStatus); final CommunicationsSession commSession = new HttpCommunicationsSession(); final String nodeApiUrl = resolveNodeApiUrl(peerStatus.getPeerDescription()); final StringBuilder clusterUrls = new StringBuilder(); config.getUrls().forEach(url -> { if (clusterUrls.length() > 0) { clusterUrls.append(","); clusterUrls.append(url); } }); final Peer peer = new Peer(peerStatus.getPeerDescription(), commSession, nodeApiUrl, clusterUrls.toString()); final int penaltyMillis = (int) config.getPenalizationPeriod(TimeUnit.MILLISECONDS); String portId = config.getPortIdentifier(); if (StringUtils.isEmpty(portId)) { portId = siteInfoProvider.getPortIdentifier(config.getPortName(), direction); if (StringUtils.isEmpty(portId)) { peer.close(); throw new IOException("Failed to determine the identifier of port " + config.getPortName()); } } final SiteToSiteRestApiClient apiClient = new SiteToSiteRestApiClient(config.getSslContext(), config.getHttpProxy(), config.getEventReporter()); apiClient.setBaseUrl(peer.getUrl()); apiClient.setConnectTimeoutMillis(timeoutMillis); apiClient.setReadTimeoutMillis(timeoutMillis); apiClient.setCompress(config.isUseCompression()); apiClient.setRequestExpirationMillis(config.getIdleConnectionExpiration(TimeUnit.MILLISECONDS)); apiClient.setBatchCount(config.getPreferredBatchCount()); apiClient.setBatchSize(config.getPreferredBatchSize()); apiClient.setBatchDurationMillis(config.getPreferredBatchDuration(TimeUnit.MILLISECONDS)); final String transactionUrl; try { transactionUrl = apiClient.initiateTransaction(direction, portId); commSession.setUserDn(apiClient.getTrustedPeerDn()); } catch (final Exception e) { apiClient.close(); logger.warn("Penalizing a peer {} due to {}", peer, e.toString()); peerSelector.penalize(peer, penaltyMillis); if (e instanceof UnknownPortException || e instanceof PortNotRunningException || e instanceof HandshakeException) { throw e; } logger.debug("Continue trying other peers..."); continue; } final Integer transactionProtocolVersion = apiClient.getTransactionProtocolVersion(); final HttpClientTransaction transaction = new HttpClientTransaction(transactionProtocolVersion, peer, direction, config.isUseCompression(), portId, penaltyMillis, config.getEventReporter()) { @Override protected void close() throws IOException { try { super.close(); } finally { activeTransactions.remove(this); } } }; try { transaction.initialize(apiClient, transactionUrl); } catch (final Exception e) { transaction.error(); throw e; } activeTransactions.add(transaction); return transaction; } logger.info("Couldn't find a valid peer to communicate with."); return null; } HttpClient(final SiteToSiteClientConfig config); @Override PeerDescription getBootstrapPeerDescription(); @Override Set<PeerStatus> fetchRemotePeerStatuses(PeerDescription peerDescription); @Override Transaction createTransaction(final TransferDirection direction); @Override boolean isSecure(); @Override void close();  }