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

PAYARA-3988 Dynamic Docker Node Instances #4130

Merged
merged 8 commits into from Aug 21, 2019

Conversation

@Pandrex247
Copy link
Member

commented Aug 6, 2019

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:

  • If the Docker image is not present on the Docker Node machine, Payara Server will now instruct the Docker REST API to pull the image.
  • --autoname can be used with the create-instance command as described in the original Dynamic Instances PR to deal with any name conflicts.
    • If there is a conflict in the Docker container names, the instance will still fail to be created. This is unlikely to happen during normal operation, and should only really occur if the DAS and the Docker Node somehow get out of sync.
  • The stop-instance command will now stop the Docker container
  • The Docker containers are now started, stopped, and deleted based on their ID, rather than their name.
    • This allows Payara Server instances created within Docker Containers spawned manually or via scaling to register themselves with the DAS and retain the ability to be managed by the DAS.
  • If a new container is created and a name conflict is detected with another Payara Server instance, a new instance will be created.
    • This should only happen if you create a container manually, or it is somehow duplicated via scaling.
  • If a new container is created and no instance name is provided to it, a new instance with an auto-generated name will be created.
    • Again, this should only happen in cases where you've created a container manually or it has otherwise been scaled up.

Please 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.

asadmin -a create-instance --node docky1 insty1     >>>     insty1 created in a container named insty1
asadmin -a create-instance --node docky1 insty1     >>>     insty1-BemusedBass created in a container named insty1-BemusedBass
asadmin -a create-instance --node docky1            >>>     Capricious-Carp created in a container named Capricious-Carp

Manual/Scaling Examples

This example demonstrates what would happen if an instance called insty1 already existed on the DAS.

docker container create --network host --mount type=bind,source="/home/anon/passwordfile.txt",target="/opt/payara/passwords/passwordfile.txt",readonly -e PAYARA_DAS_HOST=payaraDas -e PAYARA_DAS_PORT=4848 -e PAYARA_NODE_NAME=docky1 -e PAYARA_INSTANCE_NAME=insty1 payara/server-node:latest     >>>     Instance named insty1-GarishGoldfish created in a container named elastic_ganguly

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:

docker container create --network host --mount type=bind,source="/home/anon/passwordfile.txt",target="/opt/payara/passwords/passwordfile.txt",readonly -e PAYARA_DAS_HOST=payaraDas -e PAYARA_DAS_PORT=4848 -e PAYARA_NODE_NAME=docky1 -e PAYARA_INSTANCE_NAME=insty2 payara/server-node:latest     >>>     Instance named insty2 created in a container named elastic_ganguly

docker container create --network host --mount type=bind,source="/home/anon/passwordfile.txt",target="/opt/payara/passwords/passwordfile.txt",readonly -e PAYARA_DAS_HOST=payaraDas -e PAYARA_DAS_PORT=4848 -e PAYARA_NODE_NAME=docky1 -e PAYARA_INSTANCE_NAME=insty2 payara/server-node:latest     >>>     Instance named insty2-BamboozledBarrcuda created in a container named wonderful_yonath

docker container create --network host --mount type=bind,source="/home/anon/passwordfile.txt",target="/opt/payara/passwords/passwordfile.txt",readonly -e PAYARA_DAS_HOST=payaraDas -e PAYARA_DAS_PORT=4848 -e PAYARA_NODE_NAME=docky1 payara/server-node:latest     >>>     Instance named Magnanimous-Monkfish  created in a container named sleepy_elgamel
Pandrex247 added 5 commits Jul 31, 2019
PAYARA-3988 Pull image if not present, start based on container ID
rather than name, and make sure autonaming works from console
PAYARA-3988 Update Docker image and script to allow dynamic instances.
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.

@Pandrex247 Pandrex247 marked this pull request as ready for review Aug 7, 2019

@Pandrex247

This comment has been minimized.

Copy link
Member Author

commented Aug 7, 2019

Jenkins test please

@rdebusscher rdebusscher self-requested a review Aug 13, 2019

@rdebusscher
Copy link
Contributor

left a comment

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) {

This comment has been minimized.

Copy link
@rdebusscher

rdebusscher Aug 13, 2019

Contributor

adminCommandContext and actionReport unused parameters. Can thus be removed for private method.

This comment has been minimized.

Copy link
@rdebusscher

rdebusscher Aug 13, 2019

Contributor

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())) {

This comment has been minimized.

Copy link
@rdebusscher

rdebusscher Aug 13, 2019

Contributor

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("")) {

This comment has been minimized.

Copy link
@rdebusscher

rdebusscher Aug 13, 2019

Contributor

Maybe use String.isEmpty()? like

!dockerContainerId.trim().isEmpty())

@rdebusscher rdebusscher self-requested a review Aug 13, 2019

@rdebusscher
Copy link
Contributor

left a comment

LGTM

@Pandrex247

This comment has been minimized.

Copy link
Member Author

commented Aug 13, 2019

Jenkins test please

JsonObject jsonResponse = response.readEntity(JsonObject.class);

if (jsonResponse != null) {
String dockerContainerId = jsonResponse.getString("Id");

This comment has been minimized.

Copy link
@jGauravGupta

jGauravGupta Aug 19, 2019

Contributor

Id key defined in lower case on StopDockerContainerCommand @RestParam(name="id") annotation.

This comment has been minimized.

Copy link
@Pandrex247

Pandrex247 Aug 19, 2019

Author Member

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

@AlanRoth
Copy link
Contributor

left a comment

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())) {

This comment has been minimized.

Copy link
@AlanRoth

AlanRoth Aug 19, 2019

Contributor

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);
}

This comment has been minimized.

Copy link
@Pandrex247

Pandrex247 Aug 19, 2019

Author Member

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));

This comment has been minimized.

Copy link
@AlanRoth

AlanRoth Aug 20, 2019

Contributor

That works too, and still somewhat readable :P

@Pandrex247

This comment has been minimized.

Copy link
Member Author

commented Aug 20, 2019

Jenkins test please

@Pandrex247 Pandrex247 merged commit 44ecadc into payara:master Aug 21, 2019

31 of 35 checks passed

security/snyk - appserver/appclient/pom.xml (payara-ci) Test in progress
security/snyk - appserver/batch/pom.xml (payara-ci) Test in progress
security/snyk - appserver/webservices/pom.xml (payara-ci) Test in progress
security/snyk - nucleus/tests/pom.xml (payara-ci) Test in progress
Payara Quick Build and Test Quick build and test passed!
Details
security/snyk - api/payara-api/pom.xml (payara-ci) No new issues
Details
security/snyk - api/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/admingui/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/common/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/connectors/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/deployment/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/distributions/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/ejb/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/extras/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/featuresets/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/grizzly/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/installer/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/jms/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/load-balancer/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/orb/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/osgi-platforms/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/packager/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/registration/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/security/pom.xml (payara-ci) No new issues
Details
security/snyk - appserver/transaction/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/cluster/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/core/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/deployment/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/distributions/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/flashlight/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/grizzly/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/packager/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/resources-l10n/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/resources/pom.xml (payara-ci) No new issues
Details
security/snyk - nucleus/test-utils/pom.xml (payara-ci) No new issues
Details

@Pandrex247 Pandrex247 deleted the Pandrex247:PAYARA-3988-Dynamic-Docker-Nodes branch Aug 21, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.