Microservice & Container

Microservices is the one of main architecture to building could-based solution. Here, it consists of combination of small distributed applications to build entire system. The application is a component which is isolated and well-developed. All dependencies of relevant application should be in independent from other component and belongs to particular component. The component and its dependencies are packaged in single container. Finally the container is deployed on platform infrastructure.

Scaling is the important factor on cloud based solution. The container can do major role for scaling as per resource demand. It is very difficult and complex operation to managing containers manually. But it is very important to manage financial cost less. There are some tools such docker swarm, mesophere and kunernetes for automate container orchestration. These tools can manage resources at scaling as per given configuration.

Continue reading


Yarn upgrade to the latest

Yarn is a package manager for JavaScript created by Facebook. 

Find current version

$ yarn –version

Current version on my machine is 0.27

I followed below steps to complete upgrade process.

Remove yarn setup
$ sudo apt autoremove yarn

Add repository with latest version
$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Install yarn
$ sudo apt-get update
$ sudo apt-get install yarn

Continue reading

Spring JPA – Saving list items in entity

Spring JPA provides easy way to saving entity in database than traditional SQL operation. Here, developer can populate entity object and trigger save function in relevant repository. In entity population, developer must be aware on list operation.


public class HotelInfoEntity {

 private Long id;
 private String name;
 private String address;
 @JoinColumn(name = "countryid")
 private CountryEntity country;
 @OneToMany(mappedBy = "hotelInfo", cascade = CascadeType.ALL, orphanRemoval=true)
 private List rooms = new ArrayList<>();

 public List getRooms() {
  return rooms;

 public void setRooms(List rooms) {
  this.rooms = rooms;

 ... getter and setter methods of rest 

Incorrect implementation:

Most of developer do mistake when set list parameters ( Eg: setRooms(List rooms) ). They create the array and call to setter function to set list attribute to object.

It is wrong. It could cause to following error, specially in update operation.


This object keeps the reference to room list. When developer crates new array and assigned using setter method, reference to room list in hotel entity might be lost. Hence following error could happen.

2017-11-08 10:38:37.557 ERROR 3756 --- [nio-8080-exec-7] r.r.h.p.setup.service.PromotionService : IN SAVE 
org.springframework.orm.jpa.JpaSystemException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: com.example.samplespringboot.entity.RoomEntity; nested exception is org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: com.example.samplespringboot.entity.RoomEntity
 at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:333)
 at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244)
 at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:521)
 at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)


To add list items

Stop creating new array and assigned to list directly.
Do add element to list.


To clear list

Clear list


Java 8 – Lambda – List Operatoins

Java 8 feature, Lambda, provides features to process List easily.

Model class:

public class User {
 private Long id;
 private String firstName;
 private String lastName;
 private int age;
 private String city;
 private LocalDate dateOfBirth;

 // Getter and setter methods

List to Map

Key: id of user object
Value: user obeject

Option 1

Map<Long, User> userIdMap = userList.stream().collect(Collectors.toMap(User::getId, x -> x));

Option 2

Map<Long, User> userIdMap = userList.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));

List to Map (Object parameters)

Key: id of user object
Value: first name of user object

Option 1

Map<Long, String> userIdMap = userList.stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getFirstName()));

Option 2

Map<Long, String> userIdMap = userList.stream().collect(Collectors.toMap(User::getId, User::getFirstName));

Key: id of user object
Value: name concatenating first and and last names

Map<Long, String> userFullNameMap = userList.stream().collect(Collectors.toMap(x -> x.getId(), x -> (x.getFirstName() + " " + x.getLastName()) ));


Filter user object by age

 List<User> result = userList.stream()
                          .filter(x -> x.getAge() > 29)

Filtered output as List

 List<User> result = userList.stream()
                          .filter(x -> x.getAge() > 29)

Filtered output as Set

 Set<User> result = userList.stream()
                          .filter(x -> x.getAge() > 29)



Jcloud NoSuchMethodError in Rackspace Cloud File implementation

Rackspace cloud file feature was implemented with out project. In the deployment, it gave the no such method. error as following.

java.util.ServiceConfigurationError: org.jclouds.providers.ProviderMetadata: Provider org.jclouds.rackspace.cloudfiles.uk.CloudFilesUKProviderMetadata could not be instantiated: java.lang.NoSuchMethodError: com.google.common.base.Objects.firstNonNull(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
 at java.util.ServiceLoader.fail(ServiceLoader.java:207)
 at java.util.ServiceLoader.access$100(ServiceLoader.java:164)
 at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:353)

Then I went through all the required libraries and configuration but could not find any missing items. Then I searched on Internet but given suggestion are not helpful. Finally, the decision was to check every libraries in deployment environment which causes to conflicted.

Affected libraries:

After struggling with all libraries on entire project in many hours, two libraries were found affecting to be conflicted. We removed those jar files since they are no longer required for deployment. Then cloud file feature works successfully.

Then we found out how these libraries affected to be conflicted. These libraries has used class files which were available in google-collect.jar. Later it was renamed with guava and it is developed. Rackspace cloud files uses guava-17.0.jar. It works properly with Rackspace cloud files integration.

Database Transaction not worked in MySQL

I work on java project. It accesses MySQL database and is deployed in Jboss 7. I need to implement the database transaction inside the project. Event though I modified java code, it was not worked. I looked into Jboss 7 changes, related to database transaction and could not find the any changes.

Then I developed a sample java project that accesses the MySQL database. It is deployed in Jboss 7. Database was created, using XAMPP. By default, it set InnoDB as database engine. It worked properly. Whilst testing on that project, I changed the database engine to MyISAM. Here, I could notice, database transaction did not work.

With that perception, I searched on database engines in MySQL. It gives the better conclusion. MySQL uses two major database engines. Those are InnoDB and MyISAM. They have considerable major changes. One of them is based on database transaction. InnoDB supports transaction and MyISAM does not.

Again, I back to the real project. Its database used two types of engines. Initial database is built with InnoDB. Later, one of team member of made some changes for few tables. Those engine has been set MyISAM. Therefore, the real project does not perform the database transactions. These modifications has been made on the  earlier version of MySQL. Therefore it set the MyISAM for engine.

By default, the newer version of MySQL sets InnoDB as the database engine. Earlier versions sets MyISAM database.