Tuesday, 27 August 2013

Jenkins Master/Slave Configuration.


Jenkins Master/Slave Configuration.

Taking our jenkins setup in concern.

We have a Jenkins instance installed on a Ubuntu 10.04 LTS machine. This machine is good enough to build Android projects through Ant build script. But  in order to build iOS Application and Windows application where the build has dependencies with the OS. We cannot build these application on our Linux
i.e we need to have a Mac and Windows machines resp to build their application.

So we would need to have separate slave machines which will help the master machine to build specific tied projects at their end.

To configure the master/slave configuration.

1. Create a new node
Home page->Manage Jenkins->Manage Nodes->New Node
New node configuration:
a. enter name
b. select dump slave and click ok.
c. enter slave name
d. enter number of executors on the slave machine.
e. usage : for ties jobs.
f. Launch method : Java web start.
g. Availibility : online as much as possible.

Now on the home page you will see a new node with the given name at the left side pane with a offline symbol. Now that you have a new node, all you need to do is to connect this new node.

2. Connect the slave machie :
a. Go to the slave machine for example a Mac if you want to make slave machine for building iOS apps.
b. open the jenkins in browser.
c. click on the new node that is showing offline.
d. Click on the "Launch" java web start icon.
NOTE: Initially you would get error as the .jnlp file you have downloaded doesn't contain the correct jenkins server instance path. So you would need to edit it and then again run it by double clicking the file.
e. It will open up a little popup showing "connected" text.
f. After the slave has been connected you could actually see the slave machine online which was showing offline with the defined number of executors you set in its configuration.
g. in windows machine you could also install this java application as a service so that in case of a reboot of windows slave machine the slave can run this application and again connect itself.
h. to install as service just go to the java web application: file->install as service.
and you are done. To double check do to start->services->search "jenkins" -> openup the service and configure it if required.
Double check the connect mode is set to automatic.

3. Jobs Configuration to run on the slave:
As our slave machines are configured to run only tied jobs. Now we need to specifically tie to jobs to always execute on the slave machines. For that.
a. create a new job or go to the configuration page of a existing job
b. Below the description section there is a check box saying "Restrict where this project can be run". So check it and enter the name of the slave machine where the job should run.
c. click save.
From now onwards the job will be executed on the slave machine.


That's it!!

Review board windows client setup

After once we have successfully setup a review board server(which is not part of this post) we need to setup our client machine to be able to create diffs and upload it onto the review board server for review.

Here i am covering how to setup windows client developer machine

1. Install Python2.7.3 : download form here - http://www.python.org/download/releases/2.7.3/

Reviewboard doesn't support 3.x versions of python to work properly.

2. Install python setuptools:
a. goto - https://pypi.python.org/pypi/setuptools/1.1#installation-instructions
b. search for "ez_setup.py"
c. right click and save the file.
d. run this script. It is suppose to download and install the proper version of the setuptools.

Note: You may run in a situation where the script could fail due to lack of administrator permissions.
And you would not get a option to run the script as admin. To enable that you would need to do certain registry tweaks manually. Follow the link - http://www.howtogeek.com/howto/windows-vista/add-run-as-administrator-to-any-file-type-in-windows-vista/

e. after successful installation you could see easy_install.exe under the C:\Python27\Scripts location.
f. add "C:\Python27" and "C:\Python27\Scripts" for easy access.

3. Install RBTools:
a. open command prompt
b. type = easy_install -U RBTools
c. It will install the RBTools for you.

Usage:

a. Checkout the code.
b. create a .reviewboardrc file and add line  - REVIEWBOARD_URL = 'http://reviewboardpath.com' 
c. type post-review - it should create the diff and upload it to the review board server now.

NOTE: If you see a error like "The current directory does not contain a checkout from a supported source code repository". Then in windows one of the most common cause would be that you dont have command line svn installed. It looks like post-review cannot communicate to the svn server through TortoiseSVN.

 

Monday, 19 August 2013

JavaScript Data Types.

Learning JavaScript is not a bad idea as this language is the future or both web and windows applications. Lets start by looking at the data types in a nutshell.

JavaScript has the following data types:

1. Numbers
2. Strings
3. Boolean
4. Arrays
5. Object
6. null
7. undefined

Lets talk about them briefly.

1. Numbers - There is only one number type, i.e there is no separate integer, float etc.
This number is a 64-bit floating point. Which is also called IEEE-754(aka "Double").

There is a special value called NaN(Not a Number)
a. It is a result of undefined or erroneous operation. e.g divide something by zero results in NaN.
b. Toxic: any arithmetic operation with NAN as input will result NaN as output.
c. NaN is not equal to anything including NaN. i.e NaN ==NaN is false NaN is not lesser or greater then NaN :). Even when NaN is not a number but its data type is a Number.

Functions to convert string into numbers.
  •  Number(value):
It converts the value into a number.
It results NaN if it has a problem.
Similar to '+' prefix operator

  • parseInt(value, 10) e.g parseInt("55", 10)
  • + prefix operator. e.g +"55"

2. Strings: It is a sequence of  0 or more 16-bit characters.
There is no separate Character type. i.e characters are represented as strings with length 1.
Strings are Immutable.
Similar Strings are equal ( == )
String literal can use single or double quotes.
String is a object and it has lot of methods to perform on strings i.e
a. charAt
b. concat
c. match ....etc

3. Boolean:  There are two values true or false.
There is a Boolean function i.e Boolean(value) which returns true if the value is truthy and false if its falsy
It is similar to !! prefix operator.

Falsy values:
  • false
  • null
  • undefined
  • "" (empty string)
  • 0
  • NaN
Truthy Values: All other values including objects are truthy. "0" ,"false" are also truthy. They are strings.

4. null - A value that isn't anything.

5. undefined :
a.  It is the default value for a variable. i.e if you declare a variable but don't initialize it. Then its value will be undefined.

6. Object: 
  1. Its a unification of objects and hash-table.
  2. new object() produces an empty container of  name-value pairs.
  3. A name can be any string, and a value can be any value except undefined
  4. Members can be accessed with dot notation. 
  5. An object is delimited by curly braces. Inside these braces we define the object's properties in the form of key value pairs.
Object is defined like:
var person={firstname:"Jai", lastname:"Pandit", id:5566};
or
var person = new object()
// now add properties to the object.
person.firstname = "Jai"
person.lastname = "Pandit"
person.id = "5566"

7. Arrays :

The following code creates an Array called cars:
var cars=new Array();
cars[0]="Saab";
cars[1]="Volvo";
cars[2]="BMW";
or (condensed array):
var cars=new Array("Saab","Volvo","BMW");

Wednesday, 10 July 2013

Trouble Figuring Android NDK stack trace ?

Have you ever faced a bizarre stack trace  containing only memory locations, and praying god if you could find the code lines around/at crash is happening.

Here is a typical example of a stack trace generated by Android NDK when crash occurs in native code:

Lets try to understand what it is.
The PC stands for the program counter and #0 is the stack pointer where the crash happened.

There are several methods we can un- obfuscate  this stack trace.

1. Addr2line : This tool can be found in toolchains/. In ndkr5
 You can simply provide the addr at which the crash happened and it will generate the corresponding line number.

2 ndk-stack : This tool is available from revision 7 onwards. It takes two arguments

A. The library to look out for reference.
B. The crash dump. A plain txt file which contains the stack trace.

While coping the stack trace you should copy from the starting line which starts from "***** *****" like pattern. Because the current tool looks for this line as starting of the trace. It will be handled in the future versions.

3. Generate a Map file : you can always generate a map file which contains all addresses of classes and methods.



Thats it! Thanks for reading. Comments are solicited.



Autoboxing and Unboxing in Java

Hey all, So today we have a very interesting and quick topic to share about.

Its called Autoboxing and Unboxing in JAVA.

What it is ?

Autoboxing - As the name suggest its some sort of stuff done implicitly i.e automatically by Java compiler. So when write a code line like this:

eg 1: Integer a = 10;

Though our inner soul knows that it will work. but have you ever tried to give a second thought, i.e Why it works ?

Here the Autoboxing comes to play. So what Java does at runtime is it automatically convert the primitive type(int here.) into a object of its wrapper class by invoking  Integer.valueOf(int) method. So after auto conversion at runtime it will become:

runtime : Integer a = Integer.valueOf(10);


Another example where it would play more natural usage:

eg 2: 
 
List<Integer> li = new ArrayList<>();
for (int i = 1; i < 50; i += 2)
    li.add(i);
 
at runtime it become:
 
List<Integer> li = new ArrayList<>();
for (int i = 1; i < 50; i += 2)
    li.add(Integer.valueOf(i));
 

Fact File : If any of you is thinking of why didn't this fellow just do something like List<int> instead of List<Integer>, then lemme tell you primitive types are not allowed in Java Generics.


Now comes the big question, When Java compiler does AutoBoxing ?

There are only two situations:

1. When a primitive type is assigned to its corresponding wrapper class variable.
As we did in first example.

2. When a primitive type is passed to a method which expects a wrapper class object type as a parameter.
As we did in second example


Unboxing - Yeah, you guess it right! its the opposite of boxing. Conversion of Wrapper class to the primitive types is called unboxing.
eg 1: int b = a.intValue();  {a is object of Integer class from the above code}

Another natural example:
 
eg 2:
 
public static int sumEven(List<Integer> li) {
    int sum = 0;
    for (Integer i: li)
        if (i % 2 == 0)
            sum += i;
        return sum;
}

As you know  the % and + operators doesn't operate on objects. So why compiler didn't complained about it at compile time ? Its because at runtime they are automatically unboxed by invoking valueOf() method and are converted to primitive types.

runtime:

public static int sumEven(List<Integer> li) {
    int sum = 0;
    for (Integer i : li)
        if (i.intValue() % 2 == 0)
            sum += i.intValue();
        return sum;
}


Now comes the easiest question of you life, When Java compiler does unboxing ?

There are only two situations:

1. When a wrapper class object is assigned to its corresponding primitive type.
As we did in first example.

2. When the wrapper class object is passed as a parameter to a method that expects a value of the corresponding primitive type.
As we did in second example

Thats all Cheers !! Thanks for reading my first blog.