-
Notifications
You must be signed in to change notification settings - Fork 304
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
PAYARA-3988 Dynamic Docker Node Instances #4130
PAYARA-3988 Dynamic Docker Node Instances #4130
Conversation
rather than name, and make sure autonaming works from console
Add stop container command so that instances can be started, stopped, and started again without an error. Create commands to get and set container ID of instances.
Jenkins test please |
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.
Some small code improvements and doubt about the correct URL for pull image.
createContainer(adminCommandContext, actionReport, node, server, dasHost, dasPort); | ||
} | ||
|
||
private void pullImage(AdminCommandContext adminCommandContext, ActionReport actionReport, Node node) { |
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.
adminCommandContext and actionReport unused parameters. Can thus be removed for private 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.
Is it correct that pull Image uses the same Docker URL endpoint as createContainer.
Should it not be the images/create URL?
private WebTarget createWebTarget(Node node) { | ||
Client client = ClientBuilder.newClient(); | ||
WebTarget webTarget = null; | ||
if (Boolean.valueOf(node.getUseTls())) { |
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.
Boolean.parseBoolean does not create first a Boolean which needs to 'boxed'
|
||
// Set the Docker container ID either to the ID of the container, or to the instance name if the the | ||
// ID can't be obtained | ||
if (dockerContainerId != null && !dockerContainerId.equals("")) { |
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.
Maybe use String.isEmpty()? like
!dockerContainerId.trim().isEmpty())
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.
LGTM
Jenkins test please |
JsonObject jsonResponse = response.readEntity(JsonObject.class); | ||
|
||
if (jsonResponse != null) { | ||
String dockerContainerId = jsonResponse.getString("Id"); |
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.
Id
key defined in lower case on StopDockerContainerCommand @RestParam(name="id") annotation.
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.
This is referencing the "Id" field from the Docker Rest API, not our own.
The Docker Rest API has the capital :)
https://docs.docker.com/engine/api/v1.39/#operation/ContainerCreate
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.
Apart from Guarav's comment and little bit of pedantry from me, LGTM
private WebTarget createWebTarget(Node node, String endpoint) { | ||
Client client = ClientBuilder.newClient(); | ||
WebTarget webTarget = null; | ||
if (Boolean.parseBoolean(node.getUseTls())) { |
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.
Correct me if I'm wrong but could you do something like this to reduce redundency? just an idea I had, feel free to disregard;
boolean isHttps = Boolean.parseBoolean(node.getUseTls())
if(endpoint.startsWith("/")) {
webTarget = client.target(isHttps ? "https://" : "http://"
+ node.getNodeHost()
+ ":"
+ node.getDockerPort()
+ endpoint);
} else {
webTarget = client.target(isHttps ? "https://" : "http://"
+ node.getNodeHost()
+ ":"
+ node.getDockerPort()
+ "/"
+ endpoint);
}
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'll give it a test - if I'm going with ternary form I might as well go whole hog with something like the following:
WebTarget webTarget = client.target((Boolean.parseBoolean(node.getUseTls()) ? "https://" : "http://")
+ node.getNodeHost()
+ ":"
+ node.getDockerPort()
+ (endpoint.startsWith("/") ? endpoint : "/" + endpoint));
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.
That works too, and still somewhat readable :P
…-3988-Dynamic-Docker-Nodes
Jenkins test please |
Brings the Autonaming functionality introduced recently to Docker Nodes.
The behaviour around the creation and lifecycle of Docker Instances has changed to be as follows:
--autoname
can be used with thecreate-instance
command as described in the original Dynamic Instances PR to deal with any name conflicts.stop-instance
command will now stop the Docker containerPlease Note: If creating containers manually or otherwise scaling them, the instances are still tied to a Docker Node, and so the containers will fail to start if the host name does not match what has been configured on the DAS (or if the node doesn't exist).
Examples
Asadmin Examples
This example shows that no new behaviour should be expected on-top of what is already described in #4090.
Manual/Scaling Examples
This example demonstrates what would happen if an instance called insty1 already existed on the DAS.
This example demonstrates creating new instances and containers on a Docker Node (you must create & configure the Docker Node on the DAS first), the last showing that the PAYARA_INSTANCE_NAME environment variable is now optional: