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...