Flaugh24 commented on code in PR #1632:
URL: https://github.com/apache/ignite-3/pull/1632#discussion_r1098370808
##########
modules/runner/src/test/java/org/apache/ignite/internal/component/RestAddressReporterTest.java:
##########
@@ -39,25 +39,53 @@ class RestAddressReporterTest {
private static final String REST_ADDRESS_FILENAME = "rest-address";
@Test
- @DisplayName("REST server network address is reported to file")
- void networkAddressReported(@TempDir Path tmpDir) throws IOException {
+ @DisplayName("REST server network addresses is reported to file")
+ void httpAndHttpsAddressesReported(@TempDir Path tmpDir) throws
IOException {
// Given
RestAddressReporter reporter = new RestAddressReporter(tmpDir);
// When
- reporter.writeReport(new NetworkAddress("localhost", 9999));
+ reporter.writeReport(new NetworkAddress("localhost", 9999), new
NetworkAddress("localhost", 8443));
+
+ // Then there is a report
+ String restAddress =
Files.readString(tmpDir.resolve(REST_ADDRESS_FILENAME));
+ assertThat(restAddress, equalTo("http://localhost:9999,
https://localhost:8443"));
+ }
+
+ @Test
+ @DisplayName("REST server HTTP address is reported to file")
+ void httpAddressReported(@TempDir Path tmpDir) throws IOException {
+ // Given
+ RestAddressReporter reporter = new RestAddressReporter(tmpDir);
+
+ // When
+ reporter.writeReport(new NetworkAddress("localhost", 9999), null);
// Then there is a report
String restAddress =
Files.readString(tmpDir.resolve(REST_ADDRESS_FILENAME));
assertThat(restAddress, equalTo("http://localhost:9999"));
}
+ @Test
+ @DisplayName("REST server HTTPS address is reported to file")
+ void httpsAddressReported(@TempDir Path tmpDir) throws IOException {
+ // Given
+ RestAddressReporter reporter = new RestAddressReporter(tmpDir);
+
+ // When
+ reporter.writeReport(null, new NetworkAddress("localhost", 8443));
Review Comment:
Now it looks like
1. in the case of enabled SSL
Node named defaultNode started successfully. REST addresses are
[http://127.0.0.1:10300, https://127.0.0.1:10400]
2. in case of disabled SSL
Node named defaultNode started successfully. REST addresses are
[http://127.0.0.1:10300]
##########
modules/rest/src/main/java/org/apache/ignite/internal/rest/RestComponent.java:
##########
@@ -99,37 +104,77 @@ public RestComponent(List<RestFactory> restFactories,
RestConfiguration restConf
@Override
public void start() {
RestView restConfigurationView = restConfiguration.value();
+ RestSslView sslConfigurationView = restConfigurationView.ssl();
- int desiredPort = restConfigurationView.port();
+ boolean sslEnabled = sslConfigurationView.enabled();
+ boolean dualProtocol = restConfiguration.dualProtocol().value();
+ int desiredHttpPort = restConfigurationView.port();
int portRange = restConfigurationView.portRange();
+ int desiredHttpsPort = sslConfigurationView.port();
+ int httpsPortRange = sslEnabled ? sslConfigurationView.portRange() : 0;
+ int httpPortCandidate = desiredHttpPort;
+ int httpsPortCandidate = desiredHttpsPort;
- for (int portCandidate = desiredPort; portCandidate <= desiredPort +
portRange; portCandidate++) {
- try {
- port = portCandidate;
- context = buildMicronautContext(portCandidate)
- .deduceEnvironment(false)
- .environments(BARE_METAL)
- .start();
- LOG.info("REST protocol started successfully");
+ while (httpPortCandidate <= desiredHttpPort + portRange
+ && httpsPortCandidate <= desiredHttpsPort + httpsPortRange) {
+ if (startHttpServer(httpPortCandidate, httpsPortCandidate)) {
return;
- } catch (ApplicationStartupException e) {
- BindException bindException = findBindException(e);
- if (bindException != null) {
- LOG.debug("Got exception during node start, going to try
again [port={}]", portCandidate);
- continue;
- }
- throw new RuntimeException(e);
+ }
+
+ LOG.debug("Got exception during node start, going to try again
[httpPort={}, httpsPort={}]",
+ httpPortCandidate,
+ httpsPortCandidate);
+
+ if (sslEnabled && dualProtocol) {
+ httpPortCandidate++;
+ httpsPortCandidate++;
+ } else if (sslEnabled) {
+ httpsPortCandidate++;
+ } else {
+ httpPortCandidate++;
}
}
- LOG.debug("Unable to start REST endpoint. All ports are in use
[ports=[{}, {}]]", desiredPort, (desiredPort + portRange));
+ LOG.debug("Unable to start REST endpoint."
+ + " Couldn't find available port for HTTP or HTTPS"
+ + " [HTTP ports=[{}, {}]],"
+ + " [HTTP ports=[{}, {}]]",
+ desiredHttpPort, (desiredHttpPort + portRange),
+ desiredHttpsPort, (desiredHttpsPort + httpsPortRange));
- String msg = "Cannot start REST endpoint. " + "All ports in range [" +
desiredPort + ", " + (desiredPort + portRange)
- + "] are in use.";
+ String msg = "Cannot start REST endpoint."
+ + " Couldn't find available port for HTTP or HTTPS"
+ + " [HTTP ports=[" + desiredHttpPort + ", " + desiredHttpPort
+ portRange + "]],"
+ + " [HTTPS ports=[" + desiredHttpsPort + ", " +
desiredHttpsPort + httpsPortRange + "]]";
throw new RuntimeException(msg);
}
+ /** Starts Micronaut application using the provided ports.
+ *
+ * @param httpPortCandidate HTTP port candidate.
+ * @param httpsPortCandidate HTTPS port candidate.
+ * @return {@code True} if server was started successfully, {@code False}
if couldn't bind one of the ports.
+ */
+ private boolean startHttpServer(int httpPortCandidate, int
httpsPortCandidate) {
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]