Posts

Call Sequence of Spring Boot when API call is invoked.

 Please note that this is incomplete and not accurate, and I'm merely jotting down anything that I've found out, as I'm short on time while writing this. When the API is called, the call sequence within the spring boot library is shown below: In the org.springframework:spring.webmvc library, specifically in the RequestMappingHandlerAdapter class, the call sequence:  1) handleInternal method, it will check session.  2) invokeHandlerMethod that I think it will handle the passing of parameter. (Note that this is just an assumption)  3) getDataBinderFactory method, which i think will handle the binding of the value from the parameter into the endpoints parameter request.  4)  createInitBinderMethod method, which i think will make the parameter discoverable.  5) getModelFactory method, which I think will get the list of endpoints registered 6) getSessionAttributesHandler, which handles the cases when session is found or not 7) createInvocable...

Failed to apply plugin Intellij Gradle

Image
 Failed to apply plugin in Intellij Gradle is caused by wrong Java version being used in Gradle. To fix it, go to Settings -> Build, Execution, Deployment  -> Build Tools -> Gradle , find Gradle section, and select the correct Gradle JVM version. The version of JVM used should be compatible with the version of Gradle you are using.  If all still can't work, try the following: - Invalidate cache (Go to File -> Invalidate Cache ) - Delete the global .gradle folder (Located in your Users folder), as well as your project .gradle folder, and run ./gradlew.bat --refresh-dependencies - Ensure the JAVA_HOME and PATH is pointing to the right JDK version. For my case, my project is using Java 11, so the values should reflect.  JAVA_HOME = C:\Program Files\Java\jdk-11.0.8 PATH=C:\Program Files\Java\jdk-11.0.8\bin Note: Also, please make sure that the \ bin is added at the back of the path. If you have multiple Java version installed, please make sure the path...

Running cassandra on docker

1) https://cassandra.apache.org/doc/latest/cassandra/getting-started/cassandra-quickstart.html#step-1-get-cassandra-using-docker 2) Run this ` docker pull cassandra:latest` 3) Then, run this,       ` docker network create cassandra   docker run --rm -d --name cassandra --hostname cassandra --network cassandra cassandra` This creates a container called 'cassandra' within the 'cassandra' network   4) Then, run this docker run -it --name cql-client --network cassandra -v "C:/Users/nic35/a.cql:/scripts/data.cql" -e CQLSH_HOST=cassandra -e CQLSH_PORT=9042 -e CQLVERSION=3.4.7 nuvo/docker-cqlsh bash This creates a container called 'cql-client' basing on 'nuvo/docker-cqlsh' image, within the 'cassandra' network, and passing in a few other environment variables. 5) Then, run cqlsh in the bash prompt. Note: If you ever want to run the bash prompt again, do `docker exec -it cql-client bash`

The arrangement of flags in your docker command matters!

In the official document of docker, commands are presented in the format of: docker container run [OPTIONS] IMAGE [COMMAND] [ARG...] And the arrangement stated above must be followed, or else many kind of weird errors will occur. Let's say you are trying to run a docker container interactively: docker run {image} -it --entrypoint=sh -d Guess what happens? Instead of running the image, it will instead show the following error: getopt: invalid option -- 'i' getopt: invalid option -- 't' getopt: unrecognized option '--entrypoint=sh' getopt: invalid option -- 'd' This is because in the docker documentation, it specifically says to put the [options] - the flags such as -i, -t, or -d, right before IMAGE. Therefore, if we were to switch the position, we will be able to get the result we need. For example: docker run  -it --entrypoint=sh -d  {image} This should run the docker container in the background, while enable interactivity to our container.

Mounting files from your local PC to your docker container using -v

Mounting files from your local PC to your docker container using -v There are times when you need to mount files to your docker container in order for some files to have their changes persisted. For example, in Cassandra, if you were to edit your cassandra.yaml file, the file changes will not persist if you restart your docker container. But if you don't restart, the changes would not apply. In this guide, I will show you how to mount files from your local PC to your docker container using the flag -v How to mount files from your local PC to your docker container? To do this, simply run the following command. docker run -v `{directory_of_local_pc}:{directory_of_docker_container}` {image_name} directory_of_local_pc is the absolute path of your file that you want to mount. For example, if you want to mount a file, let's call it, cassandra.yaml. So your absolute path would be `D:\docker_stuff\cassandra.yaml`. directory_of_docker_container is the absolute path of your file that you...

Running CQL scripts in Cassandra

How to run CQL scripts in Cassandra  There are 2 ways to run a CQL script, the first way would be running the following command: - cqlsh -f {directory} The second way would be using the command within the CQLSH terminal: - source '{directory}' Where does the {directory} points to? The directory points to the root of your server. For example, if you are on linux, the root would be `/`. Therefore, if you placed your scripts under the folder `scripts`, your directory would look like this `/scripts/{cql_script_name}.cql`.  I've been running the command, but it keeps saying `No such file or directory`? If you met this error, please make sure that:      - The file actually exist in the directory. You can check if by typing `ls -l {directory}`. If it doesn't exist, it will show the same error. If you are on docker, and you are unsure of how to mount your CQL file into your container, you can check out this guide.      - The CQL file has the correct exten...

NoHostAvailableError: All host(s) tried for query failed. First host tried, 127.0.0.1:9042: Error: connect ECONNREFUSED 127.0.0.1:9042

NoHostAvailableError: All host(s) tried for query failed. First host tried, 127.0.0.1:9042: Error: connect ECONNREFUSED 127.0.0.1:9042 Why `All host(s) tried for query failed`? All host(s) tried for query failed occured, because the app could you find any Cassandra node to connect to. What is the fix? In order to fix this, we need to configure the cassandra.yaml file. You can find the file in /etc/cassandra/cassandra.yaml. Once you've located your cassandra.yaml, we need to find the `rpc_address` located in the cassandra.yaml file. What `rpc_address` do is, it defines from which client should the Cassandra node listens to. So if you are creating a Node JS server with an IP address of, let's say, 192.168.1.1, the `rpc_address` should match that. By default, the `rpc_address` is set to 0.0.0.0. In order to fix it, find out what IP address your server is using, and set it to the `rpc_address`.  Note that localhost, nor the default IP would work if you run your Cassandra node in Do...