Sunday, March 29, 2020

java.util.Optional means getOrElseThrowNoSuchElementException

java.util.Optional 
...means getOrElseThrowNoSuchElementException

An example:

    @Autowired
    private SimulationDao simulationDao;

@GetMapping(value = "/simulation/{id}")
public Simulation getSimulation(@PathVariable("id") Long id) {
        Simulation simulation = null;
        try {
            Optional simulationOptional =
                    Optional.ofNullable(simulationDao.findById(BigInteger.valueOf(id)));
            if (simulationOptional.isPresent()) {
                simulation = simulationOptional.get();
            }
        } catch (Exception ex) {
   (...)

Thursday, March 26, 2020

Health monitoring

Health monitoring in microservices helps to understand the overall performance of the system and detect individual points of failure. For all of the health checks, we measure whether the check is successful and the latency for performing the health check. Up or down?

https://thenewstack.io/the-hows-whys-and-whats-of-monitoring-microservices/

https://en.wikipedia.org/wiki/Vaadin

https://vaadin.com/blog/microservices-health-monitoring

https://dzone.com/articles/monitoring-microservices-with-health-checks

https://medium.com/swlh/how-to-implement-healthcheck-api-in-microservices-architecture-with-net-core-a5882369b016

https://medium.com/ibm-cloud/java-microservices-with-microprofile-health-check-and-metrics-cd70cf529626



Source: Internet



Source: Internet

Migration and mapping approach

Migration and mapping approach...



Source: Internet. Almost exactly :-)




Source: Internet




Source: Internet



Source: Internet



Source: Internet




Sunday, March 22, 2020

404 not found

404 - Your "invisible censor"...

https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

https://en.wikipedia.org/wiki/HTTP_404
404 Error - historical "the invisible censor" (Thailand, Tunisia) or "potentially illegal"

Movies:
https://en.wikipedia.org/wiki/List_of_Mr._Robot_episodes#ep36

There are five classes defined by the standard:

  1. 1xx informational response – the request was received, continuing process
  2. 2xx successful – the request was successfully received, understood, and accepted
  3. 3xx redirection – further action needs to be taken in order to complete the request
  4. 4xx client error – the request contains bad syntax or cannot be fulfilled
  5. 5xx server error – the server failed to fulfil an apparently valid request

Request methods = HTTP VERBS:
  1. CONNECT
  2. DELETE
  3. GET
  4. HEAD
  5. OPTIONS
  6. PATCH
  7. POST
  8. PUT
  9. TRACE
The 404 error message may appear as follows:
  1. "Error 404"
  2. "404 not found"
  3. "The requested URL was not found on the server."
  4. "HTTP Error 404"
  5. "Error 404: page not found"
This message is usually displayed in black on a blank page.

Remember that the 404 error page can be fully customized.


Wednesday, March 18, 2020

Transaction management in Spring

As we can read on DZONE we should be aware of some misunderstanding of the transaction management mechanism in Spring:
https://dzone.com/articles/how-does-spring-transactional

@Transactional(isolation = Isolation.SERIALIZABLE)
How does @Transactional annotation work?
The persistence context proxy that implements EntityManager is not the only component needed for making declarative transaction management work.
3 separate components are needed:
  1. the EntityManager Proxy
  2. the Transactional Aspect
  3. the Transaction Manager

The Spring declarative transaction management mechanism is very powerful, but it can be misused or wrongly configured easily.

Understanding how it works internally is helpful when troubleshooting situations when the mechanism is not at all working or is working in an unexpected way.

Read more, if You need at https://dzone.com/articles/how-does-spring-transactional

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/annotation/Transactional.html

https://www.baeldung.com/transaction-configuration-with-jpa-and-spring  (@EnableTransactionManagement)

https://docs.spring.io/spring-framework/docs/current/javadoc-api/overview-summary.html


ACID in databases

Concurrency control and ACID Properties in databases (DBMS)

In order to maintain consistency in a database, it follows ACID properties:

  1. Atomicity
  2. Consistency
  3. Isolation
  4. Durability


Are you really aware of the dangers and risk of phenomena and anomalies related to the transaction isolation level (if we have 2 transactions T1 and T2)?:

  1. Dirty Read (T1 updates a row and leaves it uncommitted, meanwhile, T2 reads the updated row!)
  2. Non Repeatable read (T1 reads data. Due to concurrency, T2 updates the same data and commit. Now if T1 again reads the same data, it will retrieve a different value.)
  3. Phantom Read (T1 retrieves a set of rows. Now, T2 generates some new rows that match the search criteria for transaction T1. If transaction T1 re-executes the statement that reads the rows, it gets a different set of rows this time.)


A valuable explanations:

https://sqlperformance.com/2015/04/t-sql-queries/the-read-uncommitted-isolation-level

https://www.geeksforgeeks.org/transaction-isolation-levels-dbms/

https://docs.microsoft.com/en-us/sql/t-sql/statements/set-transaction-isolation-level-transact-sql?view=sql-server-ver15


Based on these phenomena, The SQL standard defines 4 isolation levels (from the weakest to the strongest):

Read Uncommitted > Read Committed > Repeatable Read > Serializable(the Highest isolation level)

The higher isolation level we choose, the cost of it is higher...