Thursday, June 23, 2016

What happens when you type "www.google.com" in browser.

1. You enter the URL "www.google.com" in the address bar.

2. Browser tries to resolve the hostname or domain name into IP.

3. First place the computer looks is its local DNS cache, which stores DNS information that the computer has recently retrieved.

4. Ask the recursive DNS server
 - If the records are not present in local DNS cache, your computer queries your ISP's recursive DNS servers.

5. Ask the root DNS server
- If the recursive DNS server does not have record cached, they contact the root name servers.
- The 13 name servers contain pointers for all of the Top-Level Domains (TLDs), such as                        '.com', '.net' and '.org'
- If you enter "www.google.com", the root name servers look at the TLD for the domain -                      www.google.com

6. Ask the TLD DNS servers
- TLD DNS servers look at the next part of the query from right to left - 'www.google.com' -                  then direct the query to the authoritative name servers for 'google.com'.

7. Ask the Authoritative DNS servers
- It will return the IP address of the hostname.

8. The recursive DNS server receives the host record for 'www.google.com' from the authoritative nameservers, and stores the record in its local cache. If anyone else requests the host record for 'www.google.com', the recursive servers will already have the answer, and will not need to go through the lookup process.

Note: If the authoritative name server doesn't recognize the domain, the response indicates failure and the browser generally gives an error like "Can't find the server at www.ppppppp.com

9. After obtaining IP address, web browser opens a TCP connection and then sends the HTTP request, which consist of header and optional content.
- The header includes path requested from server, cache-control etc.

10. HTTP request is sent off to the web server as some number of packets. Each packet has a sequence number that allow them to reassemble together in case packets take different paths.

11. Web server sends the response to the client.

12. Browser checks the response code (200, 201 etc.)

13. If response is cacheable, response is stored in cache.


14. The browser then uses HTML parser to re-create document structure, which is later presented to you on screen. If it finds references to external resources, such as pictures, css files, javascript files, these are is delivered the same way as the HTML document itself.

Friday, October 9, 2015

Build your first HTTP Server using NODE.JS

In this blog, I will be talking about how you can create a HTTP server using Node.js. Later in the blog I will talk about creating "Hello World" app using Express.js

I will start by creating an empty file named Server.js and write the following code in it.


Detailed Explanation of the Above Code


Loading the HTTP module

Node.js has built-in modules to create HTTP server. The first line uses the require function to load a built-in module called http.




Creating the server

We need to create a HTTP Server object to create a server. So, the variable app takes a function that will listen for requests.
The writeHead() is called to write the header of the response. In our case, Http Status is 200 and Content-Type is text/plain.
The end() method sends the response to the client.



Starting the Server

To start a s server we call listen method on the server object.



Run the Server

In the terminal, write the following command:

node FILE-NAME.js

Create a simple application using Express.js


- Express.js is a node.js web application framework.

- Before you start using Express, don't forget to install it.

npm install Express




- We require express and node's http module.
- The express() function is a top level function exported by the express module.
- In the above example we are calling HTTP Get method.

You can use a browser to do a GET request just by entering http://localhost:9090 or you can use Advanced REST client.

After successful execution of the above program, output would look like: 


Now, you have a HTTP server up and running.

Wednesday, May 27, 2015

ESXi and VM Operations using vSphere Java API


In this blog, I will give a detailed description about various VMware technologies such as ESXi, vSphere Client, Hosted Architecture and how to install ESXi, vSphere Client on your machine. 
Also, I will talk about how to use vSphere Java API to perform VM operations.

  • ESXi: It is a Type-1 hypervisor in which the virtualization layer runs directly on hardware.
  • Hosted Architecture: It is a Type-2 hypervisor in which virtualization layer runs on top of a host OS.
    Players: VMware Fusion (Mac), VMware Player (Windows, Linux), VMware Workstation (Windows, Linux), Oracle VirtualBox (Windows, Linux and Mac).
  • vSphere Client: It is an interface for administering ESXi and vCenter Server.
  • vCenter Server: Centralized Management of entire vSphere infrastructure. It has multiple ESXi hosts.

Step 1: Download and install ESXi.
  • Register yourself at my.vmware.com
  • You can download ESXi from: http://www.vmwarearena.com/2013/10/vsphere-55-download-free-esxi-55.html
  • For installing ESXi, you have to first install any one of the above mentioned hosted architecture's players. Since, I am a Mac user I would suggest you to download VMware Fusion and for windows I would suggest Oracle VirtualBox.
  • Once VMware fusion is successfully downloaded and installed, we will then setup ESXi.

    Install ESXi
  • In VMware fusion create a virtual machine
  • If your machine only has 4GB RAM, use ESXi 5.1 instead of using  ESXi 5.5
  • VMware Fusion Settings:
    Select 2 cores, for ESXi 5.5: 4GB RAM; ESXi 5.1: 2.5GB RAM, Disk: Thin Provisioned, Network Adapter: Bridged, Guest OS: VMware ESXi 5.
    Note: Change the network type to bridge to connect vSphere client to ESXi.






Step 2: Download and install vSphere Client.

Mac users cannot directly install vSphere Client on Mac OS. First install Windows 7 in VMware Fusion and then install vSphere Client on Windows 7.

  • You can download vSphere Client from:
http://vsphereclient.vmware.com/vsphereclient/1/9/9/3/0/7/2/VMware-viclient-all-5.5.0-1993072.exehttp://vsphereclient.vmware.com/vsphereclient/1/2/3/5/2/3/3/VMware-viclient-all-5.1.0-1235233.exe


  • Once vSphere Client is downloaded, install it on Windows and invoke it.



Use IP address, User name and Password of ESXi to access ESXi from vSphere Client.


Step 3: Creating VM on ESXi from vSphere Client.

  • Upload ISO files of different OS to ESXi before creating VM. You can select any of the below options to upload ISO file.

                 – Putty
                 – VI client: datastore browser.
                 – VI client: mount external ISO file.
  • Create new VM and Resource Pool.

  • List of VMs within ESXi
  1. VM1: xphome-656-1
  2. VM2: ubuntu1410-656-2 

    Step 4: Perform VM operations using vSphere Java API (vijava)

    In this blog, I will explain only 2 VM operations i.e Power On  and Power Off VM. There are many other VM operations such as snapshot, clone, migrate which I will be talking about in my next blog.

    Power On and Power Off operations can be performed using vSphere Client. But in this blog I will show how to perform these operations using Java code.

    In Eclipse IDE, add the following external JARs to perform VM operations using java code:
    • dom4j-1.6.1.jar
    • vijava55b20130927.jar


     Step 5: Code Snippet

    I will only give code snippets which will help you in understanding how to connect to ESXi by writing java code and perform different VM operations.
    • Connect to ESXi
      ServiceInstance si = new ServiceInstance(new URL("https://IP OF ESXi/sdk"), "username", "password", true);
    • Power On VM
                    if(vm1.getRuntime().getPowerState() == VirtualMachinePowerState.poweredOff)
    {

                     Task task = vm1.powerOnVM_Task(null);
    task.waitForTask();
    System.out.println("Power On VM: status = " + task.getTaskInfo().state);
                   }
    • Power Off VM
                if(vm1.getRuntime().getPowerState() == VirtualMachinePowerState.poweredOn)
                { 
                         Task task = vm1.powerOffVM_Task(); 
                         task.waitForTask(); 
                        System.out.println("Power off VM: status = " + task.getTaskInfo().state);
                }


    Here is the console output and vSphere Client recent task output to show that Power On and Power Off VM operations are successfully performed.





    In the above displayed output, I have also extracted Host and VM information using vijava.

    Please explore vijava api more so that you can get crystal clear understanding of how host and vm information can be extracted.

    --------------------------------------------------------------------------------------------------------------------------

    So, we have seen how to use vSphere Java API to perform VM operations.