-
Notifications
You must be signed in to change notification settings - Fork 645
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
Add healthy wait condition that waits until a container becomes healthy #719
Changes from all commits
9877a5e
58cfd14
3f27fcb
0ebc408
fb766ca
79cba59
75fa940
b9a5c9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.fabric8.maven.docker.model; | ||
/* | ||
* | ||
* Copyright 2014 Roland Huss | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Interface representing an inspected container | ||
* | ||
* @author daniel | ||
* @since 17/02/15 | ||
*/ | ||
public interface InspectedContainer extends Container { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the benefit to extend Please add also some javadocs to public interface methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, understand. |
||
|
||
/** | ||
* The Health Status of this container (if applicable). | ||
* @return {@code false} if the container has a configured healthcheck and has not the | ||
* Health Status "healthy". Returns {@code true} otherwise. | ||
*/ | ||
boolean isHealthy(); | ||
|
||
/** | ||
* @return the docker healthcheck command that is configured for this container. | ||
*/ | ||
String getHealthcheck(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.fabric8.maven.docker.wait; | ||
|
||
import java.util.List; | ||
|
||
import io.fabric8.maven.docker.access.DockerAccess; | ||
import io.fabric8.maven.docker.access.DockerAccessException; | ||
import io.fabric8.maven.docker.model.InspectedContainer; | ||
import io.fabric8.maven.docker.util.Logger; | ||
|
||
/** | ||
* @author roland | ||
* @since 29/03/2017 | ||
*/ | ||
public class HealthCheckChecker implements WaitChecker { | ||
|
||
private boolean first = true; | ||
|
||
private final List<String> logOut; | ||
|
||
private DockerAccess docker; | ||
private String containerId; | ||
private Logger log; | ||
private final String imageConfigDesc; | ||
|
||
public HealthCheckChecker(DockerAccess docker, String containerId, String imageConfigDesc, List<String> logOut, Logger log) { | ||
this.docker = docker; | ||
this.containerId = containerId; | ||
this.imageConfigDesc = imageConfigDesc; | ||
this.logOut = logOut; | ||
this.log = log; | ||
} | ||
|
||
@Override | ||
public boolean check() { | ||
try { | ||
final InspectedContainer container = docker.getContainer(containerId); | ||
if (container == null) { | ||
log.debug("HealthyWaitChecker: Container %s not found"); | ||
return false; | ||
} | ||
|
||
final String healthcheck = container.getHealthcheck(); | ||
if (first) { | ||
if (healthcheck == null) { | ||
throw new IllegalArgumentException("Can not wait for healthy state of " + imageConfigDesc +". No HEALTHCHECK configured."); | ||
} | ||
log.info("%s: Waiting to become healthy", imageConfigDesc); | ||
log.debug("HealthyWaitChecker: Waiting for healthcheck: '%s'", healthcheck); | ||
logOut.add("on healthcheck '" + healthcheck+ "'"); | ||
first = false; | ||
} else if (log.isDebugEnabled()) { | ||
log.debug("HealthyWaitChecker: Waiting on healthcheck '%s'", healthcheck); | ||
} | ||
|
||
return container.isHealthy(); | ||
} catch(DockerAccessException e) { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public void cleanUp() {} | ||
}; |
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 wonder what
<healthy>false</healthy>
would imply ;-)I know, Maven doesn't allow empty tags, so that's probably fine.
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.
To be honest, I have no clue what particularly maven does to merge those plugin configs into mojo parameters :) I am open to any other suggestion (maybe as attribute on wait?)
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's more a complaint against Maven ;-). No, attributes are not possible at all for Maven configurations, no empty tags, too.
So its fine for me as it is now, except when we would find something 'useful' to put as value (like a timeout, but thats also available otherwise). But no worries here ...