Thursday, 24 June 2021

Hibernate's @FetchProfile

I came across some hibernate annotations in the source code at work, to be more specific "@FetchProfile". I hadn't seen that one before, so I went onto the Internet.

In my case it was used for Batch jobs, in which all associations were always fetched, and needed to be changed to "EAGER", during the session.

@FetchProfile(name = "STUFF", fetchOverrides = {
@FetchProfile.FetchOverride(entity = Orders.class, association = "customer", mode = FetchMode.JOIN),
})
...
Session session = sessionFactory.getCurrentSession();
session.enableFetchProfile("STUFF");
session.setHibernateFlushMode(FlushMode.MANUAL);

References

A Java geek — Hibernate hard facts - Part 6
https://blog.frankel.ch/hibernate-hard-facts/6/
JBoss Docs Hibernate - 20.1.7. Fetch profiles
https://docs.jboss.org/hibernate/core/3.5/reference/en/html/performance.html#performance-fetching-profiles
JBoss Docs Hibernate Annotations - 2.4.12. Fetch profiles
https://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#d0e3524

Wednesday, 16 June 2021

Docker

$ sudo systemctl start docker

Configuration

I am on a low bandwith thing, so needed to add max-concurrent-uploads to the /etc/docket/daemon.json, otherwise I got connection timeouts. (default is 5)

{
  "experimental": false,
  "max-concurrent-uploads": 1,
  "data-root": "/mnt/docker" }

I've since moved the docker data directory ("data-root") to a separate mount ("/mnt/docker"), as it takes up a deal of space.

See reference 1.

Basics

docker pull dockerimageurl
downloads a particular image, probably from Docker Hub
docker images
can show you all the images the docker has at its disposal
docker container create
creates a new container based on an image
docker run --rm -i -t -p portext:portint dockerimageurl
start running a new container (-d is detached, -p is portmap, -i keep STDIN open even if not attached , -t allocates a pseudo-TTY, --rm removes container on exit ), basically does all of the previous steps if necessary

Administration

docker inspect dockerimageurl
shows low level information on the running container
docker exec <container-id> cat /data.txt
run a single command on the container, can be run as long as the master process (pid 1) is running
docker ls [-a]
seems to be exactly the same as ps
docker ps [-a]
list docker containers (-a for aboth started and stopped)
docker attach <the-container-id>
stttach to a running docker container with the ID from docker ps. Convenient if you've run it "detatched".
docker stop <the-container-id>
stop docker container with the ID from docker ps
docker rm <the-container-id>
remove docker container
docker rmi <the-image-id>
removes an image

Examples

Simply running an image can be done with:

docker run --rm -i -t -p 80:8080 -p 443:8181 --name jelasticgraaljdk17 jelastic/javaengine:graalvm-21.0.0.2

"--name" is a nice option to prevent docker from assigning meaningless auto-generated names to your containers.

It will help tremendously if we could look at how an original image was made. This is possible with the history command.

docker history jelastic/javaengine:graalvm-21.0.0.2

Add --no-trunc to show entire command lines.

For example in the example, it will show the following:

IMAGECREATEDCREATED BYSIZE
72627645230f12 days ago24.4MB
<missing> 12 days ago /bin/sh -c #(nop) WORKDIR /etc/init.d 0B
<missing> 12 days ago /bin/sh -c #(nop) LABEL actions=webAccess a… 0B
<missing> 12 days ago /bin/sh -c #(nop) EXPOSE 21 22 25 80 8080 0B

Added 443 8743 to the exposed ports in my new image.

Creating your own image

docker build
build a new container image based on a Dockerfile. (-t is tag)
docker commit c16378f943fe rhel-httpd:latest
docker login -u YOUR-USER-NAME
logging into the Docker hub
docker tag c16378f943fe YOUR-USER-NAME/name
tag your image appropriately before pushing it to the repo
docker push imagename:tag
pushes an image to a remote Docker repository. If you do not provide a tag, it will automatically become "latest".

Examples

cd ../graalvm
docker build -t maartenl22/jelasticgraaljdk11:latest -t maartenl22/jelasticgraaljdk11:v0.1 .
cd ../karchan
docker build -t maartenl22/karchan:latest -t maartenl22/karchan:v2.0.8 .

Check that this worked by running:

docker run --name graalvm --rm -i -t -p 8080:8080 -p 8743:8743 maartenl22/jelasticgraaljdk11:latest
docker run --name karchan --rm -i -t -p 8080:8080 -p 8743:8743 maartenl22/karchan:latest

Pushing your image to Docker Hub

Examples

docker build -t maartenl22/jelasticgraaljdk11 .
docker build -t maartenl22/karchan .
docker image ls

First do this, just to make sure:

docker logout
docker login
docker push maartenl22/jelasticgraaljdk11
docker push maartenl22/karchan

You should see both jelasticgraaljdk11 and registry-host:5000/maartenl22/jelasticgraaljdk11 listed.

You should see both karchan and registry-host:5000/maartenl22/karchan listed.

docker run --name karchan -cap-add=NET_ADMIN --rm -i -t -p 8080:8080 -p 8743:8743 jelasticgraaljdk11:latest

The -cap-add=NET_ADMIN is necessary to see the iptables configuration.

cd /home/jelastic
java -jar payara-micro-5.2021.1.jar --port 80 --sslport 443 jakartaee-8-project.war

Portainer

Portainer is a docker image containing a simple server that interfaces with the Docker deamon. With it you can get a good view of what Docker is running and what containers and images are available and all that.

Also attaching a terminal via de website is possible. Very nice.

docker volume create portainer_dataa
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_dataa:/data portainer/portainer-ce

When starting it for the first time, and surfing to localhost:9000, you can add an administrator user.

It works great to get a good overview about what's going on.

Hello, world.

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:95ddb6c31407e84e91a986b004aee40975cb0bda14b5949f6faac5d2deadb4b9
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
-d - run the container in detached mode (in the background)
-p 80:80 - map port 80 of the host to port 80 in the container
docker/getting-started - the image to use
$ sudo docker run -d -p 80:80 docker/getting-started
Unable to find image 'docker/getting-started:latest' locally
latest: Pulling from docker/getting-started
aad63a933944: Pull complete
b14da7a62044: Pull complete
343784d40d66: Pull complete
6f617e610986: Pull complete
Digest: sha256:d2c4fb0641519ea208f20ab03dc40ec2a5a53fdfbccca90bef14f870158ed577
Status: Downloaded newer image for docker/getting-started:latest
c7187daf8a7eb2b0570bc865d
$ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7187daf8a7e docker/getting-started "nginx -g 'daemon of…" 5 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp trusting_archimedes

References

[1] GuguWeb - HOW TO MOVE DOCKER DATA DIRECTORY TO ANOTHER LOCATION ON UBUNTU
https://www.guguweb.com/2019/02/07/how-to-move-docker-data-directory-to-another-location-on-ubuntu/
Jelastic - Build software stack container image for private PaaS
https://jelastic.com/blog/build-software-stack-container-image-private-paas/
Jelastic - Building custom containers
https://docs.jelastic.com/building-custom-container/
Docker - Custom container deployment
https://docs.jelastic.com/custom-containers-deployment/
Docker - Installing fedora
https://docs.docker.com/engine/install/fedora/
Docker - Reference manuals
https://docs.docker.com/reference/
Portainer
https://www.portainer.io/
Youtube - Intro to Docker [with Java Examples]
https://youtu.be/FzwIs2jMESM
Dockerhub - my jelastic graal with jdk 11 docker image
https://hub.docker.com/r/maartenl22/jelasticgraaljdk11
Github - Docker file
https://github.com/maartenl/jelasticgraaljdk11

Thursday, 3 June 2021

Aristotle's Wheel Paradox - To Infinity and Beyond

I love Paradoxes, and I recently accidentally stumbled upon a new one (which is actually really old, so, actually only new for me) on the youtubes.

References

Wikipedia - Artistle's wheel paradox
https://en.wikipedia.org/wiki/Aristotle%27s_wheel_paradox
Youtube - Aristotle's Wheel Paradox - To Infinity and Beyond
https://youtu.be/mrVg9GM5h7Q