Tuesday, 26 December 2017

TechTip - SVN to GIT Migration - Renaming/Refactoring Projects

During SVN to GIT Migration, I have faced one challenge that is renaming/restructuring projects while migration.

Let say, you have following maven project in SVN

old-project
-- src
-- pom.xml

Now you want this project to be renamed while migrating to GIT and it should look like below:

new-project
-- src
-- pom.xml

If you try changing this name while cloning projects from SVN to GIT just like below. You will loose history after migration. But you must think about solution where history remain as it is but your project can be renamed or restructured.

git svn clone --trunk=/trunk --branches=/branches --branches=/bugfixes --tags=/tags --prefix=origin/ --authors-file= svn-committer.txt  svn://xyz.com/SRC/Trunk/old-project new-project

How to do it? 

Actually, there is no rocket science I have applied here. Its pretty simple. You just need to refactor/rename your projects in SVN itself. The good part is, SVN still maintains full history even after renaming the folder names while copying from one place to another. This is really one of the great features in SVN that I will miss in GIT for sure.

First copy your project in SVN itself with required name using below command

svn copy <source-svn-url>   <destination-svn-url> -m "Renamed project name"


Example:

svn copy svn://xyz.com/SRC/Trunk/old-project  svn://xyz.com/SRC/GIT-SRC/new-project -m "Renamed project name from old-project to new-project"

Do whatever refactoring you want to do with your project in SVN itself. Now once you are ready with structure of your  project which must be there in GIT as repository, you can use your refactored location to clone project.

git svn clone --trunk=/trunk --branches=/branches --branches=/bugfixes --tags=/tags --prefix=origin/ --authors-file= svn-committer.txt  svn://xyz.com/SRC/GIT-SRC/new-project new-project

After migration in GIT, you can see full change history of old-project including message 'Renamed project name from old-project to new-project' that you just did while renaming the project in SVN itself from old to new location.

Renaming/Refactoring was a big challenge but with this simple approach I could successfully renamed/refactored projects while SVN to GIT migration.

If you are looking for post about how to migrate from SVN to GIT. You can refer my another post.


TechTip - How to embed html report within the Jenkins email notifications?

If you would like to send html report through Jenkins email notifications and looking for how to embed html report within the Jenkins email notifications, you can follow below steps:

Prerequisite

Ensure that your Jenkins has email-ext-plugin installed. If not, refer this and install it first.

Steps

Follow below steps to embed html file in email content:
  1. Go to your jenkins job and click on Configure.
  2. Go to Post Build Actions and then select Editable Email Notifications
  3. Select Content Type as HTML(text/plain)
  4. In the default content section replace $DEFAULT_CONTENT with following
           ${FILE,path=”relative path to html file”}

Example

For example, below is the absolute path for your html file. So you just need to pick bold marked as relative path and mention in path.

/app/jenkins/jobs/myjob/workspace/my-maven-module/target/site/surefire-report.html


${FILE,path="my-maven-module/target/site/surefire-report.html”}


This will place the surefire-report.html content in your email body.


Hope this tip is helpful for you.




Monday, 18 December 2017

SVN to GIT Migration

In this post, I will be describing about how to migrate projects from SVN to GIT. You can follow below steps to migrate your projects into GIT from SVN.

Prerequisites 
You need following softwars to be available on your local machine before proceeding further:
  • Java runtime, version 6 or newer
  • Git, with git-svn included, version 1.7.7.5 or newer
  • Subversion, version 1.6.17 or newer.
Instructions 
Step-1: First download svn-migration-scripts.jar from Atlassian’s bitbucket account.

Step-2: You need to verify required software on your local machine. Execute below command to do the same:

java -jar svn-migration-scripts.jar verify

If you are moving your projects from SVN to GIT, you must want to maintain SVN history in GIT too. But it must be possible where committer names in SVN and GIT are different. For this you need to map committer's names with GIT committer email.

Step-3: Extract SVN committer’s names and store in text file. Execute below command to do same: 
java -jar svn-migration-scripts.jar authors <SVN-URL> > svn-committer.txt 
Step-4: Map every SVN committer’s information with their respective mail id's on GIT. 
For example, while extracting we got below file:

NarendraV = NarendraV < NarendraV@mycompany.com>
AbcX = AbcX <AbcX@mycompany.com>


Now change this file like below. Here, we need to ensure that given email id is configured in GIT. 

NarendraV = NarendraV <NarendraV@abc.com>
AbcX = AbcX AbcX@abc.com

Step-5: Execute below command for converting SVN project to GIT in local:

git svn clone --trunk=/trunk --branches=/branches --branches=/bugfixes --tags=/tags --prefix=origin/ --authors-file= svn-committer.txt <svn-repository-url> <git-repository-name>

Ensure to replace <svn-repository-url> with your SVN repository URL and <git-repository-name> with repository name in GIT.

Step-4: Now create remote repository using BitBucket and push your local SVN to GIT converted project (done in step#5). 

First add remote repository to your local:

git remote add <GIT-Repository>

Now push project to remote repository using below command:

git push <remote-name> <remote-branch>

Example: git push origin develop

If you would like to get more detail, you can refer this link.

Challenges Faced
Here I would like to list out some challenges that we faced during SVN to GIT migration.
  • SVN branch did not follow the branch/trunk/tag standard structure
  • Restructuring/Refactoring projects in GIT. Please refer this link to get detail. 
  • Empty sub-folder migration from SVN to GIT
Hope this post helps you in SVN to GIT migration.

TechTip - Oracle SQL query to replace strings in clob column

If you are looking for oracle query to find and replace a string in clob column in bulk. You can find same tip below:

Create table having clob column.

create table MyClobTable ( column1 int, clob_column clob );


Create procedure to perform insertion in table

create or replace procedure MyProc( proc_column1 in int, proc_text in varchar2 )
as
begin
insert into MyClobTable values ( proc_column1, proc_text );
end;


Insert below two records in table.

exec MyProc(1, 'I am Narendra Verma and currently living in Atlanta. I visited a lot of places in Atlanta. Atlanta is a nice city in US.' );

exec MyProc(2, It is a great time to be in the City of Atlanta' );

commit;

Check if rows are inserted.

select * from MyClobTable;


Output:
1
I am Narendra Verma and currently living in Atlanta. I visited a lot of places in Atlanta. Atlanta is a nice city in US.

2
It is a great time to be in the City of Atlanta

Execute below to replace ‘Atlanta’ with 'Alpharetta' in all rows.

MERGE INTO MyClobTable A
     USING (SELECT column1,
                   TO_CLOB (REPLACE (clob_column, 'Atlanta', 'Alpharetta'))
                      AS updated_string
              FROM MyClobTable
             WHERE clob_column LIKE '%Atlanta%'
            )  B
        ON (A.column1 = B.column1)
WHEN MATCHED
THEN
   UPDATE SET A.clob_column = B.updated_string;


Check if 'Atlanta' word is replaced with 'Alpharetta' in all rows.

select * from MyClobTable;


Output:
1
I am Narendra Verma and currently living in Alpharetta. I visited a lot of places in Alpharetta. Alpharetta is a nice city in US.
2
It is a great time to be in the City of Alpharetta

Hope this tech tip helped you.

Monday, 26 June 2017

Generating and Reading QR Code (Two-Dimensional Barcode)

If you are looking for solution to generate and read QR code in your java application, I think you are visiting right post. In this post I am going to demonstrate how to generate and read bar code in Java.

About QR (Quick Response) Code 

QR Code is a two-dimensional barcode that is readable by smartphones. It allows to encode over 4000 characters in a two dimensional barcode. 

From Wikipedia: A QR code (abbreviated from Quick Response code) is a specific matrix barcode (or two-dimensional code) that is readable by dedicated QR barcode readers, camera telephones, and to a less common extent, computers with webcams. The code consists of black modules arranged in a square pattern on a white background. The information encoded may be text, URL, or other data.

QR codes are plastered on advertisements, billboards, business windows, and products. Now a days, these are being so popular and being utilized by different technical solutions. Paytm is one of the great example which has gained tremendous popularity where you can just scan QR code and pay. With the help of  QR code you can reduce typing effort for your app users. 

Open Source Lib for Barcode Image Processing 

ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java. To get more detail refer this

Using ZXing, its very easy to generate/read QR code. If you are interested to generate/read QR code in your java code, you need to add below dependency in your maven java project:


<dependency>
               <groupId>com.google.zxing</groupId>
               <artifactId>javase</artifactId>
               <version>2.0</version>
</dependency>


How to Generate QR Code?
Here you will find the java example where you can generate QR code for your given string. In this example I am using my blog URL 'http://nverma-tech-blog.blogspot.com/' for which I want to generate QR code.

import java.io.File;
import java.io.FileOutputStream;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;

public class QRCodeGenerator {

       public static void main(String[] args) throws Exception {

// this is the text that we want to encode          
String text = "http://nverma-tech-blog.blogspot.com/";
      
int width = 400;
       int height = 300; // change the height and width as per your requirement

       // (ImageIO.getWriterFormatNames() returns a list of supported formats)
// could be "gif", "tiff", "jpeg"
       String imageFormat = "png";

       BitMatrix bitMatrix =
new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, width, height);

MatrixToImageWriter.writeToStream(bitMatrix, imageFormat, new FileOutputStream(new File("MyBlogQRCode.png")));
      
}
}


Once you execute this program, it will generate QR code image named 'MyBlogQRCode.png' at the location where your program is executed. If you open QR code image, it will be like below:

Since I have encoded my blog URL 'http://nverma-tech-blog.blogspot.com/' and generated this QR code, if you scan this QR code from your mobile's camera, my blog URL will be opened on browser. 

During writing this post, I did same on my mobile (Motorola X Play) and sharing same flow with you. Ensure that QR code scanner is enabled on your mobile. 

As you scan above QR code on your mobile camera, you will see red marked icon displayed. 




Now click on this icon, two options will be displayed.


Now if you click on View Website, browser is opened and you will see my blog is accessed as per decoded URL 'http://nverma-tech-blog.blogspot.com/' in QRCode.



Now you can read my blog on your mobile too without typing actual URL on your mobile browser :). 

How to Read QR Code?

Here you will find the java example where you can decode your generated QR code and get the same string back which is encoded in QRCode.

import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.InputStream;
import javax.imageio.ImageIO;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Reader;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;

public class BarCodeReader {
      
       public static void main(String[] args) throws Exception {

InputStream barCodeInputStream = new FileInputStream("MyBlogQRCode.png");
            
BufferedImage barCodeBufferedImage = ImageIO.read(barCodeInputStream);

LuminanceSource source = new BufferedImageLuminanceSource(barCodeBufferedImage);
            
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
            
Reader reader = new MultiFormatReader();
             Result result = reader.decode(bitmap);

             System.out.println("Decoded barcode text is - " + result.getText());
            
       }
}


Output of this program is


Decoded barcode text is - http://nverma-tech-blog.blogspot.com/


Others
You can find other good references below on QR code:

Hope this post help you. If you have any question or feedback do write comment. I will try to assist you.


Sunday, 28 May 2017

Technical Events

GIDS established itself as the gold standard conference and expo for the software practitioner ecosystem. Over 45,000 attendees have benefited from the platform since its founding in 2008. I have got an opportunity to attend world class summit GIDS-2017 first time. I was able to meet lot of enthusiastic developers from different parts of the country. Overall I have experienced great learning, wonderful speakers and cool products showcased in this summit. I would like to share my GIDS learning experience in this blog. Read more... 

GIDS (Great Indian Developer Summit) 2017 - My Experience

GIDS has established itself as the gold standard conference and expo for the software practitioner ecosystem. Over 45,000 attendees have benefited from the platform since its founding in 2008. I have got an opportunity to attend world class summit GIDS-2017 first time. I was able to meet lot of enthusiastic developers from different parts of the country. Overall I have experienced great learning, wonderful speakers and cool products showcased in this summit. I would like to share my GIDS learning experience in this blog.  Also, I am curious to share my photo that I clicked during lunch time in GIDs Bangalore




It was a five day summit and each day has a dedicated stream to be presented like Web & Mobile, Java & Dynamic Lang,  Data & Cloud,  Devops & Architecture. I have attended Devops & Architecture stream where there were around 20-30 presentations based on this stream. Also there were different companies who showcased their products and new ideas. Listing couple of those products and providing references to get more detail.

  • Salesforce Heroku: Heroku is like Platform as a Service where you can deploy and run applications.
  • Salesforce PredictionIO : PredictionIO is a Machine Learning framework that you can run on Heroku and use for tasks like intelligent recommendations based on users’ past actions. 
  • Flock: A faster way for your team to communicate.
  • Zoho Creator: Create custom apps for your unique business needs. 
  • NodeRed: NodeRed is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.
  • MetamindIO: Smarter AI for developers.
  • NVDA: NVDA (NonVisual Desktop Access) is a free “screen reader” which enables blind and vision impaired people to use computers. It reads the text on the screen in a computerised voice. You can control what is read to you by moving the cursor to the relevant area of text with a mouse or the arrows on your keyboard.
  • Chaos Monkey: Open sources cloud-testing tool.
  • CUBA PlatformCUBA Platform is an open source framework for the rapid development of enterprise applications. 
Let me also share some key points that I found great during presentations.

Evolutionary Architecture ( By Neal Ford)
For many years software architecture was described as the 'parts that are hard to change later'. But then microservices showed that if architects build evolvability into the architecture, changes become easier. World is moving towards micro services based architecture and avoiding to have monolithic which becomes Big Ball of Mud later. Common concerns of a product like notifications, events, caching, security should not be directly plugged but its good idea to have all these as services which can be de-plugged or replaced easily. To get more insight about this talk, you can refer this link.

Journey of Enterprise Continuous Delivery - ( By PayPal Developer)
In this presentation, one of the developer from PayPal has demonstrated how PayPal achieved continuous delivery for a scale of 3500 dev, 2K+ applications, 15K deploys a month? And he shared comparison between old vs new deployment life cycle benchmarks which you really find verify impressive.  


2013
Today
Build Time
Hours
Minutes
Release Duration
5-6 Days
< 10 Minutes
Team involves for Release
Release Management
Release Engineering & Dev Teams
Any individual (on a single click)
Feedback time on quality
analysis
Minimum 1 day
< 30 Minutes

Due to limitation in different continuous integration tools like JenkinsGO and Bamboo, PayPal has decided to built its own in-house tool ECD (Enterprise Continuous  Delivery) using Sprint Batch, Jersey and AngularJS with existing capabilities of Jenkins. ECD has got its additional features like automated creation flow, flexibility to extended steps, parallel processing, simple user interface and YAML based definition. PayPal has got continuous and fast delivery processing after adapting Micro Services Architecture, Docker Cloud Platform and ECD (in-house continuous delivery tool). Most of the IT organizations are looking for continuous and fast delivery and thinking to avoid traditional monolithic architecture pattern. 

Designing Systems for the Remaining 15% of Population
According to WHO, there are around 1.2 billion people with disabilities in the world who face various difficulties in working with digital systems. If as IT solution provider, we can remove the barriers in accessing these systems for users with disabilities, we can expand our markets. Such fixes would not only expand markets for users with disabilities, but many of these fixes would improve usability for people without disabilities. 

How as developer we should contribute:
  • Consistent Navigation
  • Simple interface (well spaced UI controls, good gap between UI controls, simple language)
  • Device independent input (key board uses, touch screen etc.)
  • Multi-sensory (text alternative for images, contrast, caption/subtitle/transcript )
  • Problematically access (for web - HTML structure as indented, for desktop - using standard controls etc.) 

From Spaghetti to Microservices Architecture ( By Stefano Tempesta )
This session explores the agility of architecting fine-grained microservice applications that benefit continuous integration and development practices, and accelerated delivery of new functions into production, with the help of Azure Service Fabric. It also presents the Publish-Subscribe design pattern of an enterprise-level service bus built on Azure Service Bus, which guarantees message queueing and delivery, on-premises and in the cloud.


My Takeaways from GIDS
  • Evolutionary architectural practices and key notes by Neal Ford
  • Latest technology trends for continuous delivery 
  • Microservices architecture and it's challenges
  • Considering designing aspects for users who are differently abled
  • Different products/ideas (listed above) which are showcased
  • Sample project creation on Salesforce Heroku platform
  • MEAN vs LAMP architecture
  • Google's AMP (Accelerated Mobile Pages)
  • Basics of lambda architecture, batch/speed/serving layer and VoltDB

 At last I would like to conclude, overall it was enriching experience where I got to know different architectural aspects, latest technology trends and different new products in the market.