Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONAR-9082 SONAR-9062 H2 and ES must use the correct network interface #1912

Closed

Conversation

simonbrandhof
Copy link
Contributor

  • SONAR-9082 H2 must bind to localhost interface only

  • SONAR-9062 ES must bind to the interface defined by property "sonar.search.host"
    when "sonar.search.port" has value "0"

@@ -110,7 +111,7 @@ Provider resolveProviderAndEnforceNonnullJdbcUrl(Props props) {
}

private static String buildH2JdbcUrl(int embeddedDatabasePort) {
return "jdbc:h2:tcp://localhost:" + embeddedDatabasePort + "/sonar";
return "jdbc:h2:tcp://" + InetAddress.getLoopbackAddress().getHostAddress() + ":" + embeddedDatabasePort + "/sonar";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small note here, with IPv6 is requiring the host to be separated with bracket (because : is used in IPv6 address)

cf. http://www.ietf.org/rfc/rfc3986.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact no, I won't add a dependency on guava for that. However I will fix the issue.

assertThat(System2.INSTANCE.isOsWindows()).isEqualTo(SystemUtils.IS_OS_WINDOWS);
}

@Test
public void testIsJavaAtLeast17() throws Exception {
public void testIsJavaAtLeast17() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupid question here: since SonarQube is now using Java8 and that classes won't be loaded by Java 7 or Java 6, does this test shouldn't be dropped ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, let's deprecate this method and return always true.

Connector connector = newConnector(props, HTTP_PROTOCOL, "http");
Connector connector = new Connector(HTTP_PROTOCOL);
connector.setURIEncoding("UTF-8");
connector.setProperty("address", props.value("sonar.web.host", "0.0.0.0"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are supposing that we are using IPv4, not a big deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default value, as commented in sonar.properties. Users can use IPv6 host.


import static java.lang.String.format;
import static java.util.Collections.list;
import static org.apache.commons.lang.StringUtils.isBlank;

public final class NetworkUtils {

private static final RandomPortFinder RANDOM_PORT_FINDER = new RandomPortFinder();
private static final Set<Integer> ALREADY_ALLOCATED = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set will fill during all the tests in the same JVM so even if a port is available we won't be able to find an available port if the method is called more than ~64512 not a big deal for the time being.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact. I will complete the javadoc.

@simonbrandhof simonbrandhof force-pushed the feature/sb/address-already-in-used-in-tests branch from 7053ab1 to a6ca4c7 Compare April 11, 2017 16:20
@SonarTech
Copy link
Collaborator

SonarQube analysis reported 1 issue

  • INFO 1 info

Watch the comments in this conversation to review them.

*/
@Deprecated
public boolean isJavaAtLeast17() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO Do not forget to remove this deprecated code someday. rule

because it always returns true. Java 6 is not supported at runtime.
@simonbrandhof simonbrandhof force-pushed the feature/sb/address-already-in-used-in-tests branch from a6ca4c7 to 41ff386 Compare April 11, 2017 16:42
@simonbrandhof simonbrandhof deleted the feature/sb/address-already-in-used-in-tests branch April 11, 2017 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants