-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix #1139 : Make it easy to get the URL of a service. #1171
Conversation
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class URLFromServiceImplUtil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will name it URLFromServiceUtil
private static final String PORT_SUFFIX = "_SERVICE_PORT"; | ||
private static final String PROTO_SUFFIX = "_TCP_PROTO"; | ||
|
||
public static String serviceToHostOrBlank(String serviceName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will call it resolveHostFromEnvVarOrSystemProperty
and the same for port, proto, .... because when I read the code that calls this method I was not sure if it were resolving the env varor not.
NodeStatus status = item.getStatus(); | ||
if(!bFound && status != null) { | ||
List<NodeAddress> addresses = status.getAddresses(); | ||
for(NodeAddress address : addresses) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put this second for inside a method? Just do not create two nested for
directly. I usually try to avoid this since for a reader is easier to check what this method exactly do. Since Java does not have multi return like go, this new method could return a simple private class with required arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I wish we had already upgraded this project to Java 8, I could have used javafx.util.Pair
😄
if (!ip.isEmpty()) { | ||
clusterIP = ip; | ||
portNumber = nodePort; | ||
bFound = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following my previous comment bFound
is not required anymore and you can just check for null.
} | ||
|
||
// Sort all loaded implementations according to priority | ||
Collections.sort(servicesList, new ServiceToUrlSortComparator()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add from line 90 to 99 into a method that gets and order services, so the method getURL
looks more compact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, it looks good. The only thing I'd like to change is the priority enum, as I'd like to make room for extension and custom impls. So I'd use just an int. Our impls could use numbers like 10,20,30 or even 100,200,300.
} | ||
|
||
ServiceToUrlImplPriority getPriority(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use an int instead of an enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh true well the enum can still be used but this method should return an int, so we can use our enum internally so calling .getValue()
in implementations but it is true that the return type should be an int.
import io.fabric8.kubernetes.api.model.Service; | ||
|
||
public interface ServiceToURLProvider { | ||
enum ServiceToUrlImplPriority { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that priority is an int
, is this enum really necessary?
@iocanel : Hey, I updated according to your comments. Could you please take a look again whenever you get time :-)? |
@iocanel : polite ping, could you please take a look again? |
[merge] |
retest this please |
c55b81f
to
006d672
Compare
[merge] |
retest this please |
} catch (URISyntaxException exception) { | ||
return false; | ||
} | ||
return url.contains("null") ? false : true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
url may be null at this point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yeah. Thanks for pointing out
+ Implemented getUrl() method for service + Fixed an arquillian dependency error that comes up while running tests in IntelliJ
006d672
to
7d8213d
Compare
[merge] |
#1139
running tests in IntelliJ