Friday, 8 September 2017

GIT - getting started

Git is a version control system (VCS) for code. It is used to keep track of revisions and allow a development team to work together on a project through branches. This fast guide has the scope of show an overview of git using the command line interface (CLI). 

To begin with a clone a remote repository in your directory:
$ git clone http://<username>@<repository_url>
From your directory you can switch branch with:
$ git checkout <branch_name>
If you want create a new local branch:
$ git checkout -b <branch_name>
To show the current branch:
$ git branch
The command shows the branch list and the current branch is that with *. For the status about the files changed
$ git status
When a file has some changes, you can revert your changes with:
$ git checkout -- <file_with_changes>
or you can add it to commit file list:
$ git add <file_with_changes>
now you can commit the file in your local repository:
$ git commit -m "your comment"
To update the local repository with the remote repository:
$ git pull
For merge from a branch with the current branch:
$ git merge <branch_target>
To update the branch on remote repository
$ git push origin <your_branch>
To create a local tag
$ git tag <tag_name>
To add a local tag in remote repository
$ git push origin <tag_name>

Thursday, 7 September 2017

Microservice Architecture and Service Oriented Architecture (SOA)

Are they the same concept? Let's see the two definitions:

The term "Microservice Architecture" has sprung up over the last few years to describe a particular way of designing software applications as suites of independently deployable services. While there is no precise definition of this architectural style, there are certain common characteristics around organization around business capability, automated deployment, intelligence in the endpoints, and decentralized control of languages and data. (cit Martin Fowler [1]).

Service Oriented Architecture (SOA) is a paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. (Reference Model for Service Oriented Architecture 1.0 [2]).

Comparing the two definitions seems fairly clear that although they have some similar aspects are not the same. A good article, "Microservices is SOA, for those who know what SOA is" [3] of Steve Jones, illustrates a series of points which highlight the differences between the two architectures.

Characteristics of a Microservice Architecture

Let's analyze the characteristics of a microservice architecture.

Componentization via Services

A component is a unit of software that is independently replaceable and upgradeable. Microservice architectures will use libraries, but their primary way of componentizing their own software is by breaking down into services. We define libraries as components that are linked into a program and called using in-memory function calls, while servicesare out-of-process components who communicate with a mechanism such as a web service request, or remote procedure call. One main reason for using services as components is that services are independently deployable. Another consequence of using services as components is a more explicit component interface. 

Organized around Business Capabilities

The microservice approach to division is different, splitting up into services organized around business capability. Such services take a broad-stack implementation of software for that business area, including user-interface, persistant storage, and any external collaborations. Consequently the teams are cross-functional, including the full range of skills required for the development: user-experience, database, and project management.

Products not Projects

On completion the software is handed over to a maintenance organization and the project team that built it is disbanded. Microservice proponents tend to avoid this model, preferring instead the notion that a team should own a product over its full lifetime.

Smart endpoints and dumb pipes

The microservice community favours an alternative approach: smart endpoints and dumb pipes. Applications built from microservices aim to be as decoupled and as cohesive as possible - they own their own domain logic and act more as filters in the classical Unix sense - receiving a request, applying logic as appropriate and producing a response.
The two protocols used most commonly are HTTP request-response with resource API's and lightweight messaging. Microservice teams use the principles and protocols that the world wide web is built on. The second approach in common use is messaging over a lightweight message bus. The infrastructure chosen is typically dumb (dumb as in acts as a message router only) - simple implementations such as RabbitMQ or ZeroMQ don't do much more than provide a reliable asynchronous fabric - the smarts still live in the end points that are producing and consuming messages; in the services. In a monolith, the components are executing in-process and communication between them is via either method invocation or function call. The biggest issue in changing a monolith into microservices lies in changing the communication pattern.

Decentralized Governance

One of the consequences of centralised governance is the tendency to standardise on single technology platforms. Teams building microservices prefer a different approach to standards too. Rather than use a set of defined standards written down somewhere on paper they prefer the idea of producing useful tools that other developers can use to solve similar problems to the ones they are facing.

Decentralized Data Management

Decentralization of data management presents in a number of different ways. At the most abstract level, it means that the conceptual model of the world will differ between systems. This is a common issue when integrating across a large enterprise, the sales view of a customer will differ from the support view. Some things that are called customers in the sales view may not appear at all in the support view. Those that do may have different attributes and (worse) common attributes with subtly different semantics. The monolithic applications prefer a single logical database for persistant data, enterprises often prefer a single database across a range of applications. Instead microservices prefer letting each service manage its own database, either different instances of the same database technology, or entirely different database systems - an approach called Polyglot Persistence.
Monolithic vs Microservices Architecture
Decentralizing responsibility for data across microservices has implications for managing updates.Using transactions like this helps with consistency, but imposes significant temporal coupling, which is problematic across multiple services. Distributed transactions are notoriously difficult to implement and as a consequence microservice architectures emphasize transactionless coordination between services, with explicit recognition that consistency may only be eventual consistency and problems are dealt with by compensating operations.

Infrastructure Automation

Many of the products or systems being build with microservices are being built by teams with extensive experience of Continuous Delivery and it's precursor, Continuous Integration. Teams building software this way make extensive use of infrastructure automation techniques. The following picture illustrates in the build pipeline shown below.
Another area where we see teams using extensive infrastructure automation is when managing microservices in production. In contrast to our assertion above that as long as deployment is boring there isn't that much difference between monoliths and microservices, the operational landscape for each can be strikingly different.

Design for failure

A consequence of using services as components, is that applications need to be designed so that they can tolerate the failure of services. Any service call could fail due to unavailability of the supplier, the client has to respond to this as gracefully as possible. This is a disadvantage compared to a monolithic design as it introduces additional complexity to handle it. The consequence is that microservice teams constantly reflect on how service failures affect the user experience. Since services can fail at any time, it's important to be able to detect the failures quickly and, if possible, automatically restore service. Microservice applications put a lot of emphasis on real-time monitoring of the application, checking both architectural elements and business relevant metrics. Semantic monitoring can provide an early warning system of something going wrong that triggers development teams to follow up and investigate. This is particularly important to a microservices architecture because the microservice preference towards choreography and event collaboration leads to emergent behavior. 

References 

Monday, 28 August 2017

Getting started with subversion command-line

The following list contains the svn commands most used by a developer:
  • Checkout
  • Update
  • Status
  • Commit
  • Add
  • Revert 
  • Move
  • Delete
The following paragraphs will show examples of these svn commands using the command line interface (CLI).

svn checkout 

Check out a working copy from a repository. Use the following command for the check out of last revision:

 svn co <path_svn>
or
 svn checkout <path_svn>
Examples:
 svn co https://mysvnrep/svn/myproject/trunk
 svn checkout https://mysvnrep/svn/myproject/trunk

It's possible make the check out with the rename of folder name target:

 svn co <path_svn> <folder_name>
Example:
 svn co https://mysvnrep/svn/myproject/trunk myproject

Finally, you can check out of a precision revision

 svn co -r <revision_number> <path_svn>
Example:
 svn co -r 236 https://mysvnrep/svn/myproject/trunk

svn update

Update your working copy with a revision version.
 svn up [-r<revision>]
or
 svn update [-r<revision>]
Note: -r (alias --revision).
If you want update your working copy with the last revision use (without -r option):
 svn update
or
 svn up

svn status

Display the status of working copy files and directories. Diff between your workspace and code repository.
 svn stat <path>
or
 svn st <path>
or
 svn status <path>
<path> is optional parameter, the default value is current folder ( . ). The command output shows the file list with the status for each file. The following status are the most common:

 'A' Item is scheduled for addition.
 'D' Item is scheduled for deletion.
 'M' Item has been modified.
 '?' Item is not under version control.
 '!' Item is missing (e.g., you moved or deleted it without using svn). This also indicates that a directory is incomplete (a checkout or update was interrupted).
 '~' Item is versioned as one kind of object (file, directory, link), but has been replaced by a different kind of object.

svn commit

Send changes from your working copy to the code repository. After the commit from an user X, the changes are available from other users using the svn update command. For commit all files with status changed (M, A, D, etc...) use:
 svn commit -m "<a comment>"
or
  svn ci -m "<a comment>"
If you want commit only a subset of files:
  svn commit -m "<a comment>" file1 file2 ....
Example:
Status before commit
 svn stat
 M Employ.java
 A myPackage/Person.java
Commit only Person.java
 svn commit -m "added Person.java" myPackage/Person.java
Status after commit
 svn stat
 M Employ.java

svn add

Add a new file (or folder) under source control, use the add command:
  svn add <file>
After that use the commit command for send the changes to code repository.
  svn ci -m "a comment" <file>

svn revert

Undo all locat edits. Yuo can revert all files or folders with status A, M and D.
 svn revert <path>
Examples:
Revert a folder edited
 svn revert myfolder
 Reverted myfolder
Revert a file added
 svn add myfile.txt
 A myfile.txt
 svn revert myfile.txt
 Reverted myfile.txt
 svn status
 ? myfile.txt
If you want to revert a whole directory of files, use the "--depth=infinity" option:
 svn revert --depth=infinity .
 Reverted myfolder
 Reverted myfile.txt

svn move

Move a file or directory.
 svn move <src> <dst>
or
 svn mv <src> <dst>
The <src> and <dst> can be local path or url.
Examples:
Use move command in your working copy
 svn move myfile.txt myfile2.txt
  A myfile2.txt
  D myfile.txt
Use the commit command to update the svn repository
 svn ci -m "move example"
 Committed revision 1233
Use move command with url
 svn move -m "move example 2" https://mysvnrepo/svn/trunk/myfile.txt https://mysvnrepo/svn/trunk/myfile2.txt
 Committed revision 1234

svn delete

Delete an item from a working copy or the repository.
 svn delete <url or path file>
or
 svn del <url or path file>
or
 svn remove <url or path file>
or
 svn rm <url or path file>
Example: to delete a file or a directory from your working copy use the following command:
 svn delete MyFile.txt 
After that, you can see the local status
 svn stat
 D MyFile.txt
If you want delete the file in repository then you must execute the commit
 svn ci -m "Delete MyFile"

Friday, 25 August 2017

Java - Object creation and Data encapsulation

Object creation

A java class is the definition of a data structure plus actions that operate on them which typically corresponds to a real world object or concept. Constructors are used to initialize the member variables of a class. When an object is created, memory is allocated for the object and the constructor for the class is executed. Constructors are used to initialize an object. Whenever an object is created, a constructor executes. A default constructor is the one that has no arguments and is provided automatically for all classes. This constructor will initialize all instance variables to default values.
Example: the following class use two constructors, the first (line 8) has no parameters while the second (line 13) one has one so you can set the value of name during the object creation.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.blogspot.informationtechnologyarchive;

public class Employee {

 private String name;
 
 // Constructor 1 without parameters
 public Employee() {
  this.name = "Jack";
 }
 
 // Constructor 2 with a parameter
 public Employee(String name){
  this.name = name;
 }
 
 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }

}
Objects are created using the new keyword. The keyword is used in conjunction with a classname and results in memory being allocated from the heap for the object.
Continuing the previous example, we creating two employee objects with both constructors:
1
2
3
4
5
6
 public static void main(String[] args) {
  Employee employee1 = new Employee();
  Employee employee2 = new Employee("Bob");
  System.out.println("Employee 1: " + employee1.getName());
  System.out.println("Employee 2: " + employee2.getName());
 }
The output will be:
Employee 1: Jack
Employee 2: Bob

Data encapsulation

Data encapsulation is concerned with hiding irrelevant information from the programmer and exposing the relevant information. Hiding the implementation details allow changes without affecting other parts of the program.
As example, consider the implementation of the Employee class, the instance variable was declared as private (line 5) and the methods getName and setName were declared as public so you can read and write the name fied but if the metod setName was declared as private then you can only read the name.

Default constructors

A default constructor is normally present for a class. If a class does not have any constructors explicitly declared, it automatically has a default constructor. A default constructor is a constructor that has no arguments.
As example we change Employee class using a default constructor:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
package com.blogspot.informationtechnologyarchive;

public class Employee {

 private String name;
 
 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }

}

Referencing instance variables

A reference variable holds a reference, or pointer, to an object. A field or variable of the object is accessed by following the object reference variable name with a period and then the field or method name. The following code snippet illustrates possible references using the Employee class based upon the declaration of Employee found in the previous section:

1
2
Employee employee = new Employee();
String name = employee.getName();

Thursday, 24 August 2017

How to compress and decompress files in bash

There are available more commands to compress and decompress file in bash. Some of them are: 
  • tar 
  • zip / unzip
  • rar / unrar
  • gzip
  • bzip2

Tar and untar 

To create a tar.gz from bash shell you can use the following command:
$ tar -zcvf myarchive.tar.gz mydirectory
Instead to extract the files from an archive:
$ tar -xvf myarchive.tar.gz

Zip and unzip 

Create an archive form a text file:
$ zip myarchive.zip myfile.txt
Create an archive form a directory:
$ zip -r myarchive.zip mydirectory
Create an archive with the subdirectories and files into a directory (without it):
$ zip -r -D myarchive.zip mydirectory
Extraction of files and directories from an archive:
$ unzip myarchive.zip
Extraction and overwrite the files and directories from an archive:
$ unzip -o myarchive.zip
Extraction the files and directories from an archive to a target directory
$ unzip myarchive.zip -d mydirectory

Rar and unrar

Create a new rar archive myarchive.rar containing myfile.txt
$ rar a myarchive.rar myfile.txt
Create a new rar archive myarchive.rar containing a directory
$ rar a myarchive.rar mydirectory/
Create a new rar archive that splits the file/files into multiple parts of equal size (10 MB)
$ rar a -v10M -R myarchive.rar mydirectory/
Extraction the files and directories from an archive:
$ unrar e myarchive.rar
List the content of a rar file without uncompressing it
$ unrar l myarchive.rar

Gzip 

The command `gzip' is designed as a complement to `tar', not as a replacement. Instead the command`gunzip' can currently decompress files created by `gzip', `zip', `compress' or `pack'. The detection of the input format is automatic. 
Create an archive form a text file:
$ gzip myfile.txt
Decompress the archive created in previous step:
$ gzip myfile.gz

Bzip2

Bzip2 compresses files using the Burrows-Wheeler block sorting text compression algorithm, and Huffman coding. The command-line options are deliberately very similar to those of GNU gzip, but they are not identical. 
Create an archive form a text file:
$ bzip2 myfile.txt
Decompress the archive created in previous step:
$ bunzip2 myfile.txt.bz2

Wednesday, 23 August 2017

GC log configuration and tools for analyse

Garbage Collection Monitoring 

The Garbage Collection Monitoring refers to the process of figuring out how JVM is running Garbage Collection (GC). The GC log is a highly important tool for revealing potential improvements to the heap and GC configuration or the object allocation pattern of the application. For each GC happening, the GC log provides exact data about its results and duration.

How to enable gc logs in wildfly application server

After this quick overview of GC, let's move on to the practical part about the configuration for wildfly.

Edit the file in $WILDFLY_HOME/bin/standalone.conf and append the following line:
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGC -Xloggc:<your_custom_path>/gc.log -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps"
Where:
  • -XX:+PrintGC activates the “simple” GC logging mode.
  • -Xloggc sets the path and the name of gc log file.
  • -XX:+PrintGCTimeStamps and -XX:+PrintGCDateStamps add time and date.
Similarly, in JBoss AS edit the file $JBOSS_HOME/bin/standalone.conf.

Rolling GC Logs

As of Oracle Java 1.6_34 (or 1.7_2 in the latest minor version or 1.8_x), the GC logs can be automatically rolled at a certain size and retain only a certain number of logs.
Add this second line immediately after the previous one (into standalone.conf file):
JAVA_OPTS="$JAVA_OPTS -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<numberOfFiles> -XX:GCLogFileSize=<size>" 
Where 
  • <numberOfFiles> is just an integer. 
  • <size> is the size of the file (e.g 16K is 16 kilobytes, 128M is 128 megabytes, etc.). Rolled files are appened with .<number>, where earlier numbered files are the older files. 

Example

Set gc log file size to 16 kilobytes and number of file to 3:

JAVA_OPTS="$JAVA_OPTS -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=16K -XX:GCLogFileSize=3" 

[Trabolshouting] GC log rotation data lose on application restart

Issue (JDK-6950794):

After a restart, the first log file gc.log.0 is overwritten and the data of that file is not rolled to gc.log.1 and hence lost. 

Possible solutions:

1) Add the timestamp or date in filename of gc log with following java option:

DATE=`date +%Y-%m-%d-%H-%M`
JAVA_OPTS="$JAVA_OPTS -Xloggc:<your_custom_path>/gc-$DATE.log

 or

JAVA_OPTS="$JAVA_OPTS -Xloggc:<your_custom_path>/gc-%t.log

2) Add pid of wildfly in filename

JAVA_OPTS="$JAVA_OPTS -Xloggc:<your_custom_path>/gc-%p.log

Tools for analyse the gc log files

After the gc log configuration and after and after having collected enough data into gc log during the execution of the application, you are ready to analyse these log files. There are lot a tools for this analysis. Some of these are the following:

GCeasy is an online tool for analyse the gc log, indeed, no need to register, dow
nload & install. Just upload GC log file & review the report instantly. It detects memory leaks, GC pauses, Consecutive Full GCs and several such problems. It provides a tool report very sophisticaed and precise metrics on the G1 GC logs. In addition it parses all formats of Android GC logs including dalvikvm GC Log, Android RunTime (ART) GC Log. For more details about GCeasy see the official web page: http://gceasy.io/

Scalyr is cloud based and it aggregates all of your operational data and provides a ric
h suite of analysis tools to bring that data to life. It analyzies terabytes of data per day and provide instant, real-time parsing to bring structure (and beauty) to otherwise chaotic logs and metrics.
Some her featureas are:
  • Collect everything - Web access logs, system logs, application logs; System, process, and custom server metrics; External probes, server pings, and more - all in one place.
  • Lightning-fast search - Search hundreds of GBs/sec across all your servers. Most searches take less than a second. Learn more about how we search so fast.
  • Manage log volume - Choose which logs are collected; subsample or filter noisy or sensitive logs before they leave your servers. Archive logs to Amazon S3 for long-term storage.
  • Live Tail - Watch new events arrive in near real-time. Apply filters and see only the messages that you care about.
For more details about Scalyr see official web page: https://www.scalyr.com/.

GCViewer is a free open source tool to visualize data produced by the Java VM options -verbose:gc and -Xloggc:<file>. It also calculates garbage collection related performance metrics (throughput, accumulated pauses, longest pause, etc.).
This can be very useful when tuning the garbage collection of a particular application by changing generation sizes or setting the initial heap size.
You can also export the data in CSV (comma separated values) format, which may easily be imported into spreadsheet applications for further processing.
The sources and binaries are available on github in https://github.com/chewiebug/GCViewer. The origial version (http://www.tagtraum.com/gcviewer.html) was used for JDK 1.5, the download link is http://www.tagtraum.com/gcviewer-download.html.

Internal Links

May be of interest to you:

External Links

Monday, 21 August 2017

Bash scripting - examples of constructions (if else, for loop, while loop, until loop)

IF construction

The if construction is one of bash's bases and its syntax is:
 if TEST-COMMANDS; then 
     CONSEQUENT-COMMANDS; 
 else
     CONSEQUENT-ELSE-COMMANDS; 
 fi
else block is optional.

Examples:

Example 1: String comparisons
var="..."
if  [ ${var} = "text" ] 
then
   echo "true";
else
   echo "false";
fi
Example 2: String comparisons with regular expression
var="..."
if  [[ ${var} == tex* ]] 
then
   echo "true";
else
   echo "false";
fi
Example 3: Numeric comparisons
var="..."
if  [ ${var} -gt "10" ] 
then
   echo "....";
fi
Example 4: Checking files
if  [ -f file.txt ]
then
   echo "file.txt exists";
fi

For loop construction

The for loop construction is one of bash's bases and its syntax is:
 for NAME [in LIST ]; do
     COMMANDS; 
 done

Examples:

Example 1: Using command substitution for specifying LIST items:
for i in `cat list.xml`; do 
    cp "$i" "$i".txt ; 
done
Example 2: Using the content of a variable to specify LIST items:
LIST="$(ls *.xml)"
for i in "$LIST"; do
     cp "$i" "$i".txt ; 
done

While loop construction

The while construct allows for repetitive execution of a list of commands, as long as the command controlling the while loop executes successfully (exit status of zero). 
Its syntax is:
 while CONTROL-COMMAND; do
     COMMANDS; 
 done

Examples:

Example 1: Simple example using while.
 while test $index -lt $number; do
     index=$[$index+1];
 done
Example 2: infinite while loop, implement a timer. You can use "CTRL" + "z" to stop the script.
 while true; do
        date +"%T";
        sleep 1;
        clear;
 done

Until loop construction

The until loop is very similar to the while loop, except that the loop executes until the TEST-COMMAND executes successfully. As long as this command fails, the loop continues. The syntax is the same as for the while loop:
 until TEST-COMMAND; do
     COMMANDS; 
 done

Example:

Create a simple script for disk space monitor on your home:
while true; do 
    DISKSPACE=$(df -h $WEBDIR | grep -v File | awk '{print $5 }' | cut -d "%" -f1 -)
    
    until [ $DISKSPACE -ge "90" ]; do 
        alert "disk space 90%";
    done
    
done 

Internal Links

May be of interest to you:

Welcome

Hello everybody, Welcome in my blog called "Information technology archive". Obviously the topics will be related to Informatio...