Saturday, May 11, 2019

What do I really need? Vm ,Vagrant or Docker



If we are working on windows and our production environment is in Linux machine, then sometimes our code may give problems in the production environment. So, we need to set the development environment as same as production.

In order to do that we can install Virtual box (or any other VMware) in our host PC and install relevant Linux OS and install required software inside the VM and run our application exactly same as the production.

BUT...WE HERE STORIES LIKE...


  • IT works on my machine. But it is not working in other developers’ machine.
  • We have to spend a lot more time to setup the development environment.
  • Sometimes we use LAMP in development machine and production servers use individual installment, may cause issues.
  • Some software version issues or OS update may give issues. Ex: We both using windows 10. When I try to install MYSQL server, it causes errors but other developers machine not giving such bad experience(actually good experience 😊).
  • Since I am a newcomer to this company/team, I need more time to set up production similar environment.

So in order to remove those types of issues, we can use "Vagrant" which is a virtual machine manager. It allows you to script the virtual machine configuration as well as the provisioning.

In the following figure, VirtualBox is used as a platform to create VMs however Vagrant is used to configuring the VM by setting OS version, Network address, Memory allocation, number of CPUs assigned etc.

https://www.softqubes.com/blog/introduction-of-vagrant-development/

Still Not Clear ..How Vagrant apply in our day to day development?

Let's imagine a new developer come to our project. Then he/she needs to set up the development environment similar to our production environment which uses Redhat OS.
But that developer really familiar with Windows environment. So he needs VirtualBox to simulate the production environment while test the code. 

But we have to spend a considerable amount of time to correctly configure the production environment locally. 

WHAT IF FIVE NEW DEVELOPERS HIRED FOR URGENT PROJECT RESOURCE REQUIREMENT THEN WHAT DO YOU THINK ABOUT THIS TIME? 

Each and every developer need to do the same thing in their own machines. Isn't it?

Solution: Keep one scripting file which has same configuration details as production. When new developers hired then they need to execute provisioning script to set up the local development environment.

Practical Usage Of Vagrant
Step 01: Download the provisioning script and execute.
Step 02: Download project, build and test.

Problem: BUT...VIRTUALIZATION  COMES WITH  A COST

Ex: Each VM needs a separate OS.

Solution: Containerization

So, we can use Docker instead of  VM (it depends on situation. Sometimes vagrant is the best for your situation).
In docker, we configure everything to run the code and we create a docker image using those code and data. Then we deploy that container. So, we do not need individual OSs. Docker uses OS kernel so no more cost than VM.

Practical Usage Of Containerization
Step 01: Download project code with docker.
Step 02: Build docker image file
Step 03: Deploy it anywhere where docker container platform installed

How Doker Link With Cloud?

Step 01: Build docker image
Step 02: Upload image to Docker Hub
Step 03: Create containers based on application scalability needs

If you have any question, feel free to comment o it.


Tuesday, March 19, 2019

Why We Need Observer Design Pattern



Observer Design Pattern



This is a one of the famous behavioral design patterns in the object-oriented world.
  • Why we need observer design pattern? 
  • What problem it solves?

      In order to answer those questions, we need to analysis the software design & development practical scenarios.So lets closely looks in to below scenario:
  •       Develop a software by WITHOUT applying observer pattern 
  •       Develop a software by applying observer pattern
     After the analysis, you can answer to above questions by yourself as well as you could get an idea where to apply this pattern in day to day software development projects.

    Let’s continue the Weather Station Story......

      As per the agreement John successfully completed the data feeding application using RMI. But still Volta (weather forecasting company) use paper based reports to presented their analysis reports and those reports print per hourly basis. When weather data interested party (government, media, etc.) wants to know the current weather condition or predictions, they need to contact Volta's telephone operator through telephone. Then telephone operator read data from the printed reports and respond to caller. 
(Image source: Iron Age Tattoo)

      Volta management wanted to optimize this process. So, they decided to mount 2 big displays in the front office to display current weather conditions and foretasted results. Management expected to automatically update displays as soon as automated analysis completed. Then telephone operator can easily present with up to date forecasting results.

      Due to successful of previous project, Volta management decided to give this project to One Soft Solutions. But this time One Soft Solutions senior engineer (John) was getting his annual leave. After a One Soft Solutions management discussion through telephone call John agreed to give some guidelines to his junior developers to continue the project until he come. As promised John, he ask to do this job for one of his junior team member (Devid).

     John prepared a task sheet and share with his Devid to fallow.
  1.       Assign the two front end UI design & development to two separate teams (Team A, Team B)
  2.       Create a new method called “updateDisplay” in “WeatherStation.java class” and write code to update the 2 remote displays which will develop by two UI teams.
  3.       Call updateDisplay method at the end of data analysis code then it will update the displays accordingly.
     Devid discuss with rest of the team and draw a diagram to illustrate what they are going to do.

Figure 1.1 communication workflow 

    Team A – Developed the “CurrentConditionDisplay”

      Team A used RMI to expose their front end object to 'WeatherStation'.Then WeatherStation can remotely invoke the UI object to update the display board (More details of RMI :RMI Post).
      
     They had used "Display" interface.

Figure 1.3 Remote Interface For Current Condition Display


      

      Team B – Developed the “ForecastConditionDisplay”

    They also followed the same process (Team A's).
Figure 1.4 Remote Interface For Forecast Condition Display


You can download the full source code:

     Meanwhile Devid and team had developed the WeatherStation back-end code base.They have retrieved the remote display objects and called the "exposeDataToDisplays" method to update remote objects status.

Figure 1.5 Remote Object Update
 You can download the full source code:

      Seems like everything is ok. All the client expected functions are in there.

     After two weeks....

    John   : Hi Devid ..I reviewed our weather station program
    Devid : Aha..We did that before expected date
    John   : Yes..You guys did it well..But currently display clients are tightly couple to our code.Right....
    Devid : Yeah..
    John   : What is the possibility to add new Display type with minimum changes to existing code.
    Devid : I understood the problem..But I don't have a clear idea how to do that.
    John   : 
  •        You could create common interface ("Display.java") 
  •        Ask all the UI teams to use that interface as their remote interface.
  •       Then you could create list of  display clients.
  •       Add all the remote display client's object to that array list.
  •       Then you can update all the display objects in one-click.
    Devid: What a cool thing..You decided it very well..
    John  : I proposed this solution by keeping "Observer Design Pattern" in mind.You also better to go through that design pattern and try to reduce coupling.I mean 

            "Check weather there is a way to expose weather data as API and clients could subscribe the weather service by themselves