-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 broken links section in docker-compose recipe #2850
Conversation
Signed-off-by: Mykola Morhun <[email protected]>
Signed-off-by: Mykola Morhun <[email protected]>
@garagatyi @benoitf @l0rd @AndrienkoAleksandr review please |
I'll add tests a bit later, maybe in M7 |
+1 |
Build # 755 - FAILED Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/755/ to view the results. |
What is the reason of names like "...CorrectSource"? |
Agree, I'll change the name. |
Signed-off-by: Mykola Morhun <[email protected]>
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.
For me, the tests should be added before merging as I don't see how we can be sure without testing.
@@ -17,7 +17,7 @@ | |||
|
|||
/** @author andrew00x */ | |||
public class NetworkSettings { | |||
private String ipAddress; | |||
private String iPAddress; |
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 would keep ipAddress as it was as method name is getIpAddress() not getIPAddress()
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.
Yes, ipAddress
is conventional name , but iPAddress
is needed for parsing value from json. Exactly like iPPrefixLen
, iPv6Gateway
in the same class.
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 agree with @benoitf that iPAddress is weird. Wouldn't it possible to use @SerializedName
annotation instead?
*/ | ||
@VisibleForTesting | ||
void replaceServiceToContainerNameInLinks(CheServiceImpl serviceToStart, List<CheServiceImpl> launchedServices) { | ||
final List<String> containerLinks = serviceToStart.getLinks(); |
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.
we couldn't use Java8 stream/filter/collect for the whole method ?
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.
Yes, we can, but I think that it is redundant here.
If we used stream here it would made code more complicated and we would had additional expenses for stream creation/collection here (note, that in many cases list with links contains 0 or 1 element, i.e. how often and how many links you use in docker compose?)
Build # 762 - FAILED Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/762/ to view the results. |
Signed-off-by: Mykola Morhun <[email protected]>
Build # 777 - FAILED Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/777/ to view the results. |
/** | ||
* Replaces linked to this service's name with container name which represents the service in links section. | ||
* The problem is that a user writes names of other services in links section in compose file. | ||
* But actually links are constraints and they values should be names of containers (not services) to be linked. |
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.
and they values => and their values
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.
thx
void replaceServiceToContainerNameInLinks(CheServiceImpl serviceToStart, Map<String, CheServiceImpl> services) { | ||
final List<String> containerLinks = serviceToStart.getLinks(); | ||
for (int i = 0; i < containerLinks.size(); i++) { | ||
String link = containerLinks.get(i); |
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.
Extracting the body of the for loop in a new method would make it more readable
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.
Taking into account, that we have only one loop in the method and this loop actually is method's body and body of this loop cannot be reused somewhere and if so, we should pass iterator and links list into new method as parameters, IMO, there is no point to extract loop body into another method. @garagatyi WDYT?
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.
Since you are going to refactor this code lets figure out what can be cleaned up after that refactoring
@VisibleForTesting | ||
void replaceServiceToContainerNameInLinks(CheServiceImpl serviceToStart, Map<String, CheServiceImpl> services) { | ||
final List<String> containerLinks = serviceToStart.getLinks(); | ||
for (int i = 0; i < containerLinks.size(); i++) { |
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.
You could probably use for each here (for (String link: containersLinks) {
)
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.
No, I cannot. I need to change the list. I can use Iterator
here, but I think that current version is more readable.
int colonIndex = link.indexOf(':'); | ||
if (colonIndex != -1) { | ||
serviceName = link.substring(0, colonIndex); | ||
serviceAlias = link.substring(colonIndex + 1); |
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.
What happen if user provide a (bad) link with an empty alias like: serviceDb:
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.
split()
method is probably more appropriate here instead of manually parsing the links string.
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.
If user provide link with empty alias, like serviceDb:
, than CheEnvironmentValidator
will throw an exception and a user will be notified about syntax error.
|
||
CheServiceImpl serviceLinkedTo = services.get(serviceName); | ||
if (serviceLinkedTo != null) { |
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.
An error should be returned if the user is trying to link a service that does not exist (i.e. serviceLinkedTo == null)
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 think, that error should be reported. Please note, that things like that are validated by CheEnvironmentValidator
.
CheServiceImpl serviceLinkedTo = services.get(serviceName); | ||
if (serviceLinkedTo != null) { | ||
String containerNameLinkedTo = serviceLinkedTo.getContainerName(); | ||
containerLinks.set(i, (serviceAlias == null) ? |
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.
Instead of modifying current containersLinks list you could make this method return a new list
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.
But in case of no links we need additional logic which made code a bit complicated or return new empty list when it can be untouched, which is a bit weird to me.
@@ -895,6 +895,43 @@ public void shouldBeAbleToRemoveSnapshot() throws Exception { | |||
verify(instanceProvider).removeInstanceSnapshot(machineSource); | |||
} | |||
|
|||
@Test | |||
public void shouldReplaceServiceNameWithContainerNameAndAliasInLinks() { |
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.
You are testing 2 things here (links with and without alias). You could probably split this test in 2 separate tests.
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.
ok
Signed-off-by: Mykola Morhun <[email protected]>
void normalizeLinks(CheServiceImpl serviceToNormalizeLinks, Map<String, CheServiceImpl> services) { | ||
final List<String> containerLinks = serviceToNormalizeLinks.getLinks(); | ||
for (int i = 0; i < containerLinks.size(); i++) { | ||
String serviceNameAndAliasToLink[] = containerLinks.get(i).split(":"); // a link has format: 'name:alias' or 'name' |
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.
Pass second argument to split
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.
ok
containerNameLinkTo + ':' + serviceAlias); | ||
} else { | ||
// should never happens. Errors like this should be filtered by CheEnvironmentValidator | ||
LOG.error("Attempt to link non existing service {} to {} service.", serviceName, serviceToNormalizeLinks); |
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.
It is better to throw IllegalArgumentExcption
if (serviceLinkTo != null) { | ||
String containerNameLinkTo = serviceLinkTo.getContainerName(); | ||
containerLinks.set(i, (serviceAlias == null) ? | ||
containerNameLinkTo + ':' + 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.
Is it needed? I suppose it already works in such a way?
@VisibleForTesting | ||
void normalizeLinks(CheServiceImpl serviceToNormalizeLinks, Map<String, CheServiceImpl> services) { | ||
final List<String> containerLinks = serviceToNormalizeLinks.getLinks(); | ||
for (int i = 0; i < containerLinks.size(); i++) { |
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 would suggest to simplify code with stream API - it looks overcomplicated
@@ -667,6 +711,7 @@ private void startEnvironmentQueue(String namespace, | |||
try { | |||
machineProvider.createNetwork(networkId); | |||
|
|||
EnvironmentHolder environmentHolder; |
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.
Is it still used?
@@ -736,7 +781,7 @@ private void startEnvironmentQueue(String namespace, | |||
boolean queuePolled = false; | |||
try (StripedLocks.WriteLock lock = stripedLocks.acquireWriteLock(workspaceId)) { | |||
ensurePreDestroyIsNotExecuted(); | |||
EnvironmentHolder environmentHolder = environments.get(workspaceId); | |||
environmentHolder = environments.get(workspaceId); |
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.
Is it still used?
Build # 802 - FAILED Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/802/ to view the results. |
Signed-off-by: Mykola Morhun <[email protected]>
@@ -895,6 +895,65 @@ public void shouldBeAbleToRemoveSnapshot() throws Exception { | |||
verify(instanceProvider).removeInstanceSnapshot(machineSource); | |||
} | |||
|
|||
@Test | |||
public void shouldReplaceServiceNameWithContainerNameInLinks() { |
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.
Please ensure that code of MachineProviderImpl is also covered
Build # 812 - FAILED Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/812/ to view the results. |
Signed-off-by: Mykola Morhun <[email protected]>
@garagatyi @benoitf @l0rd take a look again please |
Build # 829 - FAILED Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/829/ to view the results. |
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.
Good job!
Nice @mmorhun! LGTM |
Signed-off-by: Mykola Morhun <[email protected]>
Build # 861 - FAILED Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/861/ to view the results. |
What does this PR do?
Fix broken links section in docker-compose recipe.
What issues does this PR fix or reference?
#2687
Previous behavior
If links section is present in recipe than workspace will fail to start.
New behavior
Links and aliases works now.