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

Deprecate ArmeriaSettings.ip and add ArmeriaSettings.address #4598

Merged
merged 10 commits into from
Jan 12, 2023

Conversation

kojilin
Copy link
Contributor

@kojilin kojilin commented Dec 30, 2022

Motivation:

Spring allows Users to specify a hostname because Spring converts the input to an InetAddress.
So we need to also allow users to specify a hostname.

Modifications:

  • adding ArmeriaSettings.address whose type is InetAddress
  • deprecating ArmeriaSettings.ip

Result:

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks @kojilin for the quick fix! 🙇‍♂️

Comment on lines 146 to 148
public void setAddress(InetAddress address) {
this.address = address;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should return this like other setters?

final Collection<ServerPort> serverPorts = server.activePorts().values();
for (ServerPort sp : serverPorts) {
final InetAddress address = sp.localAddress().getAddress();
Assertions.assertThat(address.isAnyLocalAddress() || address.isLoopbackAddress()).isTrue();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Prefer static import for assertions.

Suggested change
Assertions.assertThat(address.isAnyLocalAddress() || address.isLoopbackAddress()).isTrue();
assertThat(address.isAnyLocalAddress() || address.isLoopbackAddress()).isTrue();

@ikhoon ikhoon added this to the 1.22.0 milestone Dec 30, 2022
Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Looks really nice! Thanks @kojilin ! 🙇 👍 🙇

* Network address to bind to. If not set, will bind to all addresses, e.g. {@code 0.0.0.0}.
*/
@Nullable
private InetAddress address;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit; do you mind also updating the example?

@@ -0,0 +1,8 @@
armeria:
ports:
- ip: 127.0.0.1
Copy link
Contributor

Choose a reason for hiding this comment

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

optional; I'm unsure if this would also work in windows, but I think it would be cool if we can check that non-ip addresses are also accepted

Suggested change
- ip: 127.0.0.1
- address: localhost

@@ -0,0 +1,61 @@
/*
* Copyright 2020 LINE Corporation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Copyright 2020 LINE Corporation
* Copyright 2023 LINE Corporation

Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Thanks a lot for adding the address. 😄

@@ -82,10 +83,18 @@ public class ArmeriaSettings {
public static class Port {
/**
* IP address to bind to. If not set, will bind to all addresses, e.g. {@code 0.0.0.0}.
* @deprecated Use {@link #address} instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a blank line between the doc and @deprecated. 😉

public Port setIp(String ip) {
this.ip = ip;
return this;
}

/**
* Returns the Network address that the {@link Server} uses.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I guess we don't need to capitalize the word

Suggested change
* Returns the Network address that the {@link Server} uses.
* Returns the network address that the {@link Server} uses.

@@ -0,0 +1,61 @@
/*
* Copyright 2023 LINE Corporation
Copy link
Contributor

Choose a reason for hiding this comment

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

Happy new year. 🎉 🎉 🎉

final Collection<ServerPort> serverPorts = server.activePorts().values();
for (ServerPort sp : serverPorts) {
final InetAddress address = sp.localAddress().getAddress();
assertThat(address.isAnyLocalAddress() || address.isLoopbackAddress()).isTrue();
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: are these values different depending on the OS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure, I just put 127.0.0.1 & 0.0.0.0 at yml, so keep test both

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ha, if so how about branching it so that we can be sure what the test actually means?

if ("127.0.0.1".equals(address.getHostAddress())) {
    assertThat(...).isTrue();
} else {
    // 0.0.0.0
    assertThat(...).isTrue();
}

final String ip = p.getIp();
final int port = p.getPort();
if (ip != null && address != null) {
throw new IllegalStateException("A port cannot have both IP and address: " + p);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we override Port.toString() to properly create the message?

Copy link
Contributor

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Just left one question. Thanks a lot, @kojilin! 😄

return "Port{" +
"ip='" + ip + '\'' +
", address=" + address +
", iface='" + iface + '\'' +
Copy link
Contributor

Choose a reason for hiding this comment

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

question: It seems like we add '' to only ip and iface. Is there any specific reason for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used Intellij to generate and looks like it adds ' or not by String or not.
Maybe I should use MoreObjects.toStringHelper like others?

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't know about it. 😄 It looks good now. Thanks!

@minwoox minwoox merged commit 76c50fe into line:master Jan 12, 2023
@minwoox
Copy link
Contributor

minwoox commented Jan 12, 2023

Thanks a lot, @kojilin! 😄

@kojilin kojilin deleted the 4597 branch June 22, 2024 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate ArmeriaSettings.ip and add ArmeriaSettings.address
4 participants