It6713 Grid Cloud Computing Lab

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 96

IT6713- GRID AND CLOUD COMPUTING LAB

IV YEAR/ VII SEMESTER


2013-Regulation

Department of Information Technology

JERUSALEM COLLEGE OF ENGINEERING

Velachery Main Road, Pallikkaranai, Chennai – 600 100

Prepared and Compiled By

Mr George Fernandez.I B.E,M.Tech,(Ph.D)


Asst Prof, Dept of IT.
[email protected]

Mr P.S Tamizharasan B.E,M.Tech,(Ph.D)


Asst Prof, Dept of IT.
[email protected]
2

LIST OF EXPERIMENTS
Exp. Page
Date Name of The Experiments Sign.
No. No.
GRID COMPUTING LAB

1 Develop a new Web Service for Calculator.


2 Develop new OGSA-compliant Web Service.
3 Using Apache Axis develop a Grid Service.
4 Develop applications using Java or C/C++ Grid APIs
Develop secured applications using basic security
5
mechanisms available in Globus Toolkit.
Develop a Grid portal, where user can submit a job
6 and get the result. Implement it with and without
GRAM concept.
CLOUD COMPUTING LAB:
Find procedure to run the virtual machine of different
1
configuration
Find procedure to attach virtual block to the virtual
2 machine and check whether it holds the data even after
the release of the virtual machine.
Install a C compiler in the virtual machine and execute
3
a sample program.
Show the virtual machine migration based on the
4
certain condition from one node to the other.
Find procedure to install storage controller and interact
5
with it.
6 Find procedure to set up the one node Hadoop cluster.
7 Mount the one node Hadoop cluster using FUSE.
Write a program to use the API’s of Hadoop to interact
8
with it.
Write a word count program to demonstrate the use of
9
Map and Reduce tasks.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
3

Ex.No: 1.
IMPLEMENTATION OF CALCULATOR
Date:

AIM: Develop a new Web Service for Calculator

PROCEDURE:
Step 1: Open NetBeans IDE 8.1

Step 2: Go to file menu and Select a new project.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
4

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
5

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
6

Step 3: Delete the index.html file in Web pages. Create the new file with .XHTML

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
7

Step 4: Delete the default content in index.xhtml of webpage and type the following code.

Index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<form action="./cal.jsp">
<center>
<h>Addition Program</h><br/><br/>
Input Text1 : <input type="text" name="t1" /><br/><br/>
Input Text2 : <input type="text" name="t2" /><br/><br/>
<input type="submit" value="+" name="add" /> <input type="submit" value="-"
name="sub"/>
<input type="submit" value="*" name="mul" />

</center>
</form>
</h:body>
</html>

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
8

Step 5: Create a new jsp file and name it cal.jsp and type the following code in it.

cal.jsp
<html>
<head>
<title>Enter two numbers to add up</title>
</head>

<body>

<%= "<h3> Addition:


"+(Integer.parseInt(request.getParameter("t1"))+Integer.parseInt(request.getParameter("t2")))+"</h1>
"%>
<%= "<h3> Subtraction: "+(Integer.parseInt(request.getParameter("t1"))-
Integer.parseInt(request.getParameter("t2")))+"</h1>"%>
<%= "<h3> Multiplication:
"+(Integer.parseInt(request.getParameter("t1"))*Integer.parseInt(request.getParameter("t2")))+"</h1>
"%>
</body>
</html>

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
9

Step 6: Delete the default content in web.xml of WEB-INF and type the following code.
web.xml

<?xml version="1.0" encoding="UTF-8"?>


<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-
app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
10

</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>

Step 7: Deploy and Run the Project by right click on the project name .

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
11

OUTPUT:

Result

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
12

Ex.No: 3.
IMPLEMENTATION OF GRID SERVICE
Date:

AIM: Using Apache Axis develop a Grid Service

PROCEDURE:
Step 1: Open spring tool suite IDE from My Computer->E:/->Grid->grid computing software-
>spring tool suite release->spring source->sts -3.3.0 release->sts.exe

Step 2:Create a new Dynamic web project from File->new->Dynamic web project.
Enter the project name and change dynamic web module version to 2.5

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
13

Step 3: In the same window, click modify button in the configuration select Axis2 web service
and click on ok and then next and finally generate web xml must be checked and click finish.

Step 4:Create a system variable for apache axis by going by :right click on computer and select
properties select advanced system settings and click on environment variable and set the new
variable to the path:

E:\->Grid->grid computing software's->Axis->axis 2-1.7.3 –bin and select ok.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
14

Step 5.In spring suite click windows->preferences->webservices->Axis 2 preferences and check the
location of axis 2 .

Step 6:.Again in windows->preference->web service->server and runtime change webservice runtime


to apache axis 2 and click ok

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
15

Step 7: In E:/->grid->grid computing software->axis->copy the include folder and paste it in your
project under web content->WEB-INF.
Step 8:copy the jstl and xmlschema_core jar files in the same axis folder and paste it inside lib
folder.
Step 9:.Now go to conf->axis2.xml
Type the following code in the document
<transportReceiver name="http" class="org.apache.axis2.transport.http.Axis
ServletListener"/>
Save and close

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
16

Step 10:.under services->web.xml,select the last <servlet>to </servletmapping> and comment it by


clicking on ctrl+shift+C save and close.

Step 11:.Now create new package and give the name as “com.web.service” and click finish.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
17

Step 12:.Now create a class under the package and type a small code and save it.

Step 13:. Type a small code by right click on AddOperationService.java and save it.
AddOperationService.java

package com.cloudnloud.service;
public class AddOpetationService {
public int sumValue(int a,int b)
{
return a+b;
}

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
18

Step 14:. Right click on your class name->webservice->create webservice->check publish web
service.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
19

Step 15: In the same window click on webservice runtime apache:apache axis 2 and check apache
axis 2 and click finish.

Step 16:. Now open chrome->type “localhost:9090/(project name)”

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
20

Step 17:Click on the operation that you have created.

Output:

Result:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
21

Ex.No: 4.
IMPLEMENTATION OF GRID API
Date:

AIM: : Develop applications using Java or C/C++ Grid APIs

PROCEDURE:
Step 1: Create a new java application

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
22

Step 2: Create a new class

Step 3: Type the convertion.java code in the newly created class


convertion.java

import java.util.Scanner;
public class TempConverter{
public static void main(String [] args)
{
float f, c;
f = c = 0;
int a;
Scanner scan = new Scanner (System.in);
System.out.println("Press 1 for C->F or 2 for F->C");
a = scan.nextInt();
if (a == 1)
convertCtoFAndPrint();
else
convertFtoCAndPrint();
}

public static void convertFtoCAndPrint()


{
int c;
int f = c = 0;
Scanner scan = new Scanner (System.in);
System.out.println("Please enter degrees F");

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
23

f = (int) scan.nextFloat();
System.out.println("enter degrees F"+f);
c = (f-32) * 5/9;
System.out.println(f + " degrees F is " + c + " degrees C.");
}

public static void convertCtoFAndPrint()


{
Scanner scan = new Scanner (System.in);
System.out.println("Please enter degrees C");
float c = scan.nextFloat();
float f = (c*9/5)+32;
System.out.println(c + " degrees C is " + f + " degrees F.");
}

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
24

Step 4 : Run the java application

Step 5:In the console:

Press 1 for C->F or 2 for F->C.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
25

Output

Result:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
26

Ex.No: 5.
IMPLEMENTATION OF SECURITY MECHANISM
Date:

AIM: Develop secured applications using basic security mechanisms

PROCEDURE:

Step1 : Open spring tool suite and create a Dynamic web project

Step 2: Create a new package named com.security.servlet

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
27

Step 3: Create 3 classes named LoginServletLogOutServlet and RegisterServlet.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
28

Step 4 : Type the corresponding code for all the classes. And add the required jar files in the web
content->web-inf->lib folder.

Step 5 : similarly create the following packages and class files as in the given order below
1.com.security.servlet
-LoginServlet.java
-LogoutServlet.java
-RegisterServlet.java
1.a.com.security.servlet.errohandlers
-AppErrorHandler.java
1.b.com.security.servlet.filters
-AuthenticationFilter.java
1.c.AppContextListener.java
-AppContextListener.java
2.com.security.util
-DBConnectionManager.java
-User.java

LoginServlet.java
package com.journaldev.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
29

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.journaldev.util.User;

@WebServlet(name = "Login", urlPatterns = { "/Login" })


public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

static Logger logger = Logger.getLogger(LoginServlet.class);

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {
String email = request.getParameter("email");
String password = request.getParameter("password");
String errorMsg = null;
if(email == null || email.equals("")){
errorMsg ="User Email can't be null or empty";
}
if(password == null || password.equals("")){
errorMsg = "Password can't be null or empty";
}

if(errorMsg != null){
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/login.html");
PrintWriter out= response.getWriter();
out.println("<font color=red>"+errorMsg+"</font>");
rd.include(request, response);
}else{

Connection con = (Connection) getServletContext().getAttribute("DBConnection");


PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = con.prepareStatement("select id, name, email,country from Users where
email=? and password=? limit 1");
ps.setString(1, email);
ps.setString(2, password);
rs = ps.executeQuery();

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
30

if(rs != null){
rs.next();
User user = new User(rs.getString("name"), rs.getString("email"),
rs.getString("country"), rs.getInt("id"));
logger.info("User found with details="+user);
HttpSession session = request.getSession();
session.setAttribute("User", user);
response.sendRedirect("home.jsp");;
}else{
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/login.html");
PrintWriter out= response.getWriter();
logger.error("User not found with email="+email);
out.println("<font color=red>No user found with given email id, please
register first.</font>");
rd.include(request, response);
}
} catch (SQLException e) {
e.printStackTrace();
logger.error("Database connection problem");
throw new ServletException("DB Connection problem.");
}finally{
try {
if(rs!=null)rs.close();
if(ps!=null)ps.close();
} catch (SQLException e) {
logger.error("SQLException in closing PreparedStatement or
ResultSet");;
}

}
}
}

}
LogoutServlet.java
package com.journaldev.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
31

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

@WebServlet(name = "Logout", urlPatterns = { "/Logout" })


public class LogoutServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
static Logger logger = Logger.getLogger(LogoutServlet.class);

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {
response.setContentType("text/html");
Cookie[] cookies = request.getCookies();
if(cookies != null){
for(Cookie cookie : cookies){
if(cookie.getName().equals("JSESSIONID")){
logger.info("JSESSIONID="+cookie.getValue());
break;
}
}
}
//invalidate the session if exists
HttpSession session = request.getSession(false);
logger.info("User="+session.getAttribute("User"));
if(session != null){
session.invalidate();
}
response.sendRedirect("login.html");
}

}
RegisterServlet.java
package com.journaldev.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
32

import org.apache.log4j.Logger;

@WebServlet(name = "Register", urlPatterns = { "/Register" })


public class RegisterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

static Logger logger = Logger.getLogger(RegisterServlet.class);

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {
String email = request.getParameter("email");
String password = request.getParameter("password");
String name = request.getParameter("name");
String country = request.getParameter("country");
String errorMsg = null;
if(email == null || email.equals("")){
errorMsg = "Email ID can't be null or empty.";
}
if(password == null || password.equals("")){
errorMsg = "Password can't be null or empty.";
}
if(name == null || name.equals("")){
errorMsg = "Name can't be null or empty.";
}
if(country == null || country.equals("")){
errorMsg = "Country can't be null or empty.";
}

if(errorMsg != null){
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/register.html");
PrintWriter out= response.getWriter();
out.println("<font color=red>"+errorMsg+"</font>");
rd.include(request, response);
}else{

Connection con = (Connection) getServletContext().getAttribute("DBConnection");


PreparedStatement ps = null;
try {
ps = con.prepareStatement("insert into Users(name,email,country, password)
values (?,?,?,?)");
ps.setString(1, name);
ps.setString(2, email);
ps.setString(3, country);
ps.setString(4, password);

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
33

ps.execute();

logger.info("User registered with email="+email);

//forward to login page to login


RequestDispatcher rd =
getServletContext().getRequestDispatcher("/login.html");
PrintWriter out= response.getWriter();
out.println("<font color=green>Registration successful, please login
below.</font>");
rd.include(request, response);
} catch (SQLException e) {
e.printStackTrace();
logger.error("Database connection problem");
throw new ServletException("DB Connection problem.");
}finally{
try {
ps.close();
} catch (SQLException e) {
logger.error("SQLException in closing PreparedStatement");
}
}
}

}
-AppErrorHandler.java
package com.journaldev.servlet.errorhandler;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/AppErrorHandler")
public class AppErrorHandler extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
34

processError(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {
processError(request, response);
}

private void processError(HttpServletRequest request,


HttpServletResponse response) throws IOException {
// Analyze the servlet exception
Throwable throwable = (Throwable) request
.getAttribute("javax.servlet.error.exception");
Integer statusCode = (Integer) request
.getAttribute("javax.servlet.error.status_code");
String servletName = (String) request
.getAttribute("javax.servlet.error.servlet_name");
if (servletName == null) {
servletName = "Unknown";
}
String requestUri = (String) request
.getAttribute("javax.servlet.error.request_uri");
if (requestUri == null) {
requestUri = "Unknown";
}

// Set response content type


response.setContentType("text/html");

PrintWriter out = response.getWriter();


out.write("<html><head><title>Exception/Error Details</title></head><body>");
if(statusCode != 500){
out.write("<h3>Error Details</h3>");
out.write("<strong>Status Code</strong>:"+statusCode+"<br>");
out.write("<strong>Requested URI</strong>:"+requestUri);
}else{
out.write("<h3>Exception Details</h3>");
out.write("<ul><li>Servlet Name:"+servletName+"</li>");
out.write("<li>Exception Name:"+throwable.getClass().getName()+"</li>");
out.write("<li>Requested URI:"+requestUri+"</li>");
out.write("<li>Exception Message:"+throwable.getMessage()+"</li>");
out.write("</ul>");
}

out.write("<br><br>");
out.write("<a href=\"login.html\">Login Page</a>");

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
35

out.write("</body></html>");
}
}
-AuthenticationFilter.java
package com.journaldev.servlet.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

@WebFilter("/AuthenticationFilter")
public class AuthenticationFilter implements Filter {

private Logger logger = Logger.getLogger(AuthenticationFilter.class);

public void init(FilterConfig fConfig) throws ServletException {


logger.info("AuthenticationFilter initialized");
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)


throws IOException, ServletException {

HttpServletRequest req = (HttpServletRequest) request;


HttpServletResponse res = (HttpServletResponse) response;

String uri = req.getRequestURI();


logger.info("Requested Resource::"+uri);

HttpSession session = req.getSession(false);

if(session == null && !(uri.endsWith("html") || uri.endsWith("Login") ||


uri.endsWith("Register"))){
logger.error("Unauthorized access request");
res.sendRedirect("login.html");
}else{

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
36

// pass the request along the filter chain


chain.doFilter(request, response);
}

public void destroy() {


//close any resources here
}

}
-AppContextListener.java
package com.journaldev.servlet.listeners;

import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.xml.DOMConfigurator;

import com.journaldev.util.DBConnectionManager;

@WebListener
public class AppContextListener implements ServletContextListener {

public void contextInitialized(ServletContextEvent servletContextEvent) {


ServletContext ctx = servletContextEvent.getServletContext();

//initialize DB Connection
String dbURL = ctx.getInitParameter("dbURL");
String user = ctx.getInitParameter("dbUser");
String pwd = ctx.getInitParameter("dbPassword");

try {
DBConnectionManager connectionManager = new
DBConnectionManager(dbURL, user, pwd);
ctx.setAttribute("DBConnection", connectionManager.getConnection());
System.out.println("DB Connection initialized successfully.");
} catch (ClassNotFoundException e) {

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
37

e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}

//initialize log4j
String log4jConfig = ctx.getInitParameter("log4j-config");
if(log4jConfig == null){
System.err.println("No log4j-config init param, initializing log4j with
BasicConfigurator");
BasicConfigurator.configure();
}else {
String webAppPath = ctx.getRealPath("/");
String log4jProp = webAppPath + log4jConfig;
File log4jConfigFile = new File(log4jProp);
if (log4jConfigFile.exists()) {
System.out.println("Initializing log4j with: " + log4jProp);
DOMConfigurator.configure(log4jProp);
} else {
System.err.println(log4jProp + " file not found, initializing log4j with
BasicConfigurator");
BasicConfigurator.configure();
}
}
System.out.println("log4j configured properly");
}

public void contextDestroyed(ServletContextEvent servletContextEvent) {


Connection con = (Connection)
servletContextEvent.getServletContext().getAttribute("DBConnection");
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

}
-DBConnectionManager.java
package com.journaldev.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnectionManager {

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
38

private Connection connection;

public DBConnectionManager(String dbURL, String user, String pwd) throws


ClassNotFoundException, SQLException{
Class.forName("com.mysql.jdbc.Driver");
this.connection = DriverManager.getConnection(dbURL, user, pwd);
}

public Connection getConnection(){


return this.connection;
}
}
-User.java
package com.journaldev.util;

import java.io.Serializable;

public class User implements Serializable{

private static final long serialVersionUID = 6297385302078200511L;

private String name;


private String email;
private int id;
private String country;

public User(String nm, String em, String country, int i){


this.name=nm;
this.id=i;
this.country=country;
this.email=em;
}

public void setName(String name) {


this.name = name;
}

public void setEmail(String email) {


this.email = email;
}

public void setId(int id) {


this.id = id;

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
39

public void setCountry(String country) {


this.country = country;
}

public String getName() {


return name;
}

public String getEmail() {


return email;
}

public int getId() {


return id;
}

public String getCountry() {


return country;
}

@Override
public String toString(){
return "Name="+this.name+", Email="+this.email+", Country="+this.country;
}
}

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
40

Step 6: Type the code for home.jsp, login.html and register.html in WEB-CONTENT.

home.jsp
<%@page import="com.journaldev.util.User"%>
<%@ page language="java" contentType="text/html; charset=US-ASCII"
pageEncoding="US-ASCII"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Home Page</title>
</head>
<body>
<%User user = (User) session.getAttribute("User"); %>
<h3>Hi <%=user.getName() %></h3>
<strong>Your Email</strong>: <%=user.getEmail() %><br>
<strong>Your Country</strong>: <%=user.getCountry() %><br>
<br>
<form action="Logout" method="post">
<input type="submit" value="Logout" >
</form>
</body>
</html>

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
41

login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="US-ASCII">
<title>Login Page</title>
</head>
<body>
<h3>Login with email and password</h3>
<form action="Login" method="post">
<strong>User Email</strong>:<input type="text" name="email"><br>
<strong>Password</strong>:<input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
<br>
If you are new user, please <a href="register.html">register</a>.
</body>
</html>

register.html

<!DOCTYPE html>
<html>
<head>
<meta charset="US-ASCII">
<title>Register Page</title>
</head>
<body>
<h3>Provide all the fields for registration.</h3>
<form action="Register" method="post">
<strong>Email ID</strong>:<input type="text" name="email"><br>
<strong>Password</strong>:<input type="password" name="password"><br>
<strong>Name</strong>:<input type="text" name="name"><br>
<strong>Country</strong>:<input type="text" name="country"><br>
<input type="submit" value="Register">
</form>
<br>
If you are registered user, please <a href="login.html">login</a>.
</body>
</html>

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
42

Step 7: Open web.xml in web content and modify it.


web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-
app_2_4.xsd">
<display-name>
loginpage</display-name>

<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>dbUser</param-name>
<param-value>root</param-value>
</context-param>
<context-param>
<param-name>dbPassword</param-name>
<param-value>redhat</param-value>
</context-param>
<context-param>
<param-name>dbURL</param-name>
<param-value>jdbc:mysql://localhost:3306/UserDB</param-value>
</context-param>

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
43

<context-param>
<param-name>log4j-config</param-name>
<param-value>WEB-INF/log4j.xml</param-value>
</context-param>

<error-page>
<error-code>404</error-code>
<location>/AppErrorHandler</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/AppErrorHandler</location>
</error-page>

<filter>
<filter-name>AuthenticationFilter</filter-name>
<filter-class>com.journaldev.servlet.filters.AuthenticationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>AuthenticationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!--
<servlet>
<servlet-name>Register</servlet-name>
<servlet-class>Register</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Register</servlet-name>
<url-pattern>/Register</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>Logout</servlet-name>
<servlet-class>Logout</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Logout</servlet-name>
<url-pattern>/Logout</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>Login</servlet-name>

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
44

<servlet-class>Login</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping> -->
</web-app>

Step8:Creating a database to store the user details


8a.Setup mysql server by giving password = redhat or if u want to give a new password ,
8b Open Mysql command-line client.
8cCreate a new database user

Query : create database UserDB;


Select the newly created database

Query to create a database: create database UserDB;


Query to change database : use UserDB;

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
45

Step 9: Open MySql workbench.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
46

Step 10: Create a new connection from the database menu

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
47

Click store in value

Enter password : redhat

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
48

A new database connection is created.

Step 11: Create a new table named users having the fields : id, name,email,country,password.
Query :
CREATE TABLE `Users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL DEFAULT '',
`email` varchar(20) NOT NULL DEFAULT '',
`country` varchar(20) DEFAULT 'USA',
`password` varchar(20) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
49

To run the query click on the Run option

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
50

Step12: Now ,Go to sts and run the project as Run on server

OUTPUT:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
51

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
52

Result

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
53

Ex.No: 6.
IMPLEMENTATION OF GRID PORTAL
Date:

AIM: Develop a Grid portal, where user can submit a job and get the result

PROCEDRE:

Step 1 :Create a Dynamic Web project in spring tool suite.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
54

Step 2: In Java resource Create a new package.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
55

Step 3: Create a new class within the newly created package named PieChartServlet and type its
corresponding code.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
56

Step 4: In Web content Create a new HTML file and name it chart.html and write its corresponding
code
PieChartServlet.java
package com.cloudnloud.servlet;

import java.awt.Color;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
/* Code for the HTTP Servlet that will return the Pie Chart as a PNG image
back to the browser after generating it using JFreeChart API */
@WebServlet(name = "PieChartServlet", urlPatterns = { "/PieChartServlet" })
public class PieChartServlet extends HttpServlet {
public PieChartServlet() {
/* No code in the constructor for this demonstration */
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
OutputStream out = response.getOutputStream(); /* Get the output stream from the
response object */
try {
DefaultPieDataset myServletPieChart = new DefaultPieDataset();
/* We will now get the values posted to us from the HTML form, to generate a
dynamic pie chart */
/* to get the form values we use request.getParameter method. We have to convert
this to Double format to
pass this as an input to our pie chart*/
/* The NAME used in HTML form will serve as input to getParameter */

myServletPieChart.setValue("Servers",Double.parseDouble(request.getParameter("Servers")));
myServletPieChart.setValue("Monitor",
Double.parseDouble(request.getParameter("Monitor")));

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
57

myServletPieChart.setValue("CPU",
Double.parseDouble(request.getParameter("CPU")));
myServletPieChart.setValue("Keyboards",
Double.parseDouble(request.getParameter("Keyboards")));

myServletPieChart.setValue("Processor",Double.parseDouble(request.getParameter("Processor")));
JFreeChart mychart = ChartFactory.createPieChart("Dynamic Pie Chart
Example",myServletPieChart,true,true,false);
/* We use the configurator to define labels for the chart, which can be shown on
image also */
PiePlot ColorConfigurator = (PiePlot) mychart.getPlot();
ColorConfigurator.setLabelGenerator(new
StandardPieSectionLabelGenerator("{0}:{1}"));
ColorConfigurator.setLabelBackgroundPaint(new Color(220, 220, 220));
response.setContentType("image/png"); /* Set the HTTP Response Type */
/* Send a big chart back to the browser */
ChartUtilities.writeChartAsPNG(out, mychart, 640, 480);/* Write the data to the
output stream */
}
catch (Exception e) {
e.printStackTrace();
System.err.println(e.toString()); /* Throw exceptions to log files */
}
finally {
out.close();/* Close the output stream */
}
}
/* We write a doPost method which will be invoked when you post data to the servlet */
/* Inside doPost we invoke doGet to return a chart back to us depending on the input
parameters*/
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

doGet(request, response);
}

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
58

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
59

chart.html .
<html>
<head>
<Title>Generate Dynamic Pie Chart </Title>
</head>
<body BGCOLOR="white">
<H2>Enter your no. to get a Pie Chart </H2>
<!-- We create a simple form to accept user inputs -->
<!-- The action for this form points to the servlet URL created in earlier posts -->
<FORM ACTION="PieChartServlet" METHOD="POST">
Servers:<INPUT TYPE="TEXT" NAME="Servers"><BR>
Monitor:<INPUT TYPE="TEXT" NAME="Monitor"><BR>
CPU:<INPUT TYPE="TEXT" NAME="CPU"><BR>
Keyboards:<INPUT TYPE="TEXT" NAME="Keyboards"><BR>
Processor:<INPUT TYPE="TEXT" NAME="Processor"><BR>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</body>
</html>

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
60

Step 5: Open web.xml in WEB-INF and type code .


web.xml

<?xml version="1.0" encoding="UTF-8"?>


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-
app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>chart</display-name>
<welcome-file-list>
<welcome-file>chart.html</welcome-file>
<!-- <welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file> -->
</welcome-file-list>
<!-- <servlet> add a line for the PieChartServlet, similar to HellWorld example
<servlet-name>PieChartServlet</servlet-name>
<servlet-class>PieChartServlet</servlet-class>
</servlet>
<servlet-mapping>Create a URL pattern for the new pie chart servlet
<servlet-name>PieChartServlet</servlet-name>
<url-pattern>/servlets/servlet/PieChartServlet</url-pattern>
</servlet-mapping> -->
</web-app>

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
61

Step 6 : Add the jar files in WebContent->WEB-INF->lib

Step 7: Run the project on server.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
62

Output:

Result:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
63

Ex.No: 1. CLOUD COMPUTING LAB: PROCEDURE FOR VIRTUAL MACHINE


Date: OF DIFFERENT CONFIGURATION

AIM: Find procedure to run the virtual machine of different configuration. Check how many
virtual machines can be utilized at particular time.

Throughout the installation there are two separate roles: Frontend and Nodes.
The Frontend Server will execute the OpenNebula services, and the Nodes(KVM1)will be used to
execute virtual machines.

PROCEDURE:

Step 1:Open VMware Workstation.

Step 2: Power on Front end ,open the terminal type ip a and obtain the IPAdress: For
eg:192.168.159.131.Paste the IP Address in Putty Configuration and load frontend.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
64

Step3:Login as root, type password as redhat, start the services of frontend as mentioned below

# systemctl enable opennebula


# systemctl start opennebula
# systemctl enable opennebula-sunstone
# systemctl start opennebula-sunstone

Refresh the NFS exports by doing:

# systemctl restart nfs.service

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
65

Step 4::Power on Kvm1 ,open the terminal type ip a and obtain the IP A dress: For
eg:192.168.159.132.Paste the IP Address in Putty Configuration and load kvm1.

Step5:Login as root, type password as redhat, start the services of Kvm1 as mentioned below
Start the required services:

# systemctl start messagebus.service


# systemctl enable libvirtd.service
# systemctl start libvirtd.service
# systemctl start nfs.service

Step6:On front end copy the key into the browser password field

The default password for the oneadmin user can be found in ~/.one/one_auth which is randomly
generated on every installation.
To interact with OpenNebula, you have to do it from the oneadmin account in the frontend. We will
assume all the following commands are performed from that account. To login
as oneadmin execute su - oneadmin.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
66

To find Password run below command:

$cat ~/.one/one_auth

--* on frontend all the activities to be performed as oneadmin*---

Step7: Adding a Host


To start running VMs, you should first register a worker node for OpenNebula.
Issue this command for each one of your nodes. Replace localhost with your node’s hostname.

$ onehost create kvm1.jce.com -ikvm -v kvm -n dummy

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
67

Step 8: GotoOneadminDashboard

Step 9: Check to see the Datanode is added

[oneadmin@frontend ~]$ onehost list

check for the status onwait for few minutes , if status err problem is due to services are not started
properly.

Step 10:Create the virtual network

[oneadmin@frontend ~]$ onevnet list

Step11:In Dash board select Image, + symbol will appear on Image dash board which indicates add
click on it.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
68

* Now new Create Image will pop out to enter the details for Image, fill the details for
nameTTYLinux.-> Choose image location: Upload ->Choose file:browse for the ttylinux.img
which is stored in particular driver.
*Once image is uploaded click on create

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
69

On Dashboard check for the status Ready

[oneadmin@frontend ~]$ oneimage list


Step12:Create the template (need to refer the image created in previous step)

$ onetemplate create --name "TTYLinux" \


--cpu 1 --vcpu 1 --memory 256 --arch x86_64 \
--disk "TTYLinux" \
--nic "private" \
--vnc --ssh --net_context

Check to see if the template has been created


[oneadmin@frontend ~]$ onetemplate list

Instantiate the template , Click Virtual Machine in Virtual Resources Menu and do the
following steps

Goto Virtual Machines click on+to add the virtual machine

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
70

Select the VMName-TTYlinux,click on create

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
71

OUTPUT:
Check the Status for Virtual Machine RUNNING

Result:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
72

Ex.No: 2. PROCEDURE FOR VIRTUAL MACHINE TO HOLD AND RELEASE


Date: DATA

AIM: Find procedure to attach virtual block to the virtual machine and check whether it holds
the data even after the release of the virtual machine

PROCEDURE:

Note: Repeat The Step1 to Step 8 of 1st Program(Cloud Computing Lab)

Step9:Go to Virtual Resource select Virtual Machine ->Select the VM which is Running

Step10:Select all the permission

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
73

Step11:GotoStorage ,Click on Attach Disk

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
74

Step12:Select on option Volatile Disk->Size 10 MB(Do not Select GB)->Type Default FS-
>Format-SD, click on Attach

Note: When you click refresh the newly attach hdc disappears. Hence we reboot and restart the
services.

Step13:Goto drop down select the Reboot hard

Step14:Restart the services of Frontend and KVM1and go to Virtual Machine Select the Storage
click on Attach Disk and follow the Step11.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
75

Step15:Select the option Recover

Step16:Select Success and click ok.

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
76

OUTPUT:

Result:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
77

Ex.No: 3.
PROCEDURE TO INSTALL C COMPLIER
Date:

AIM: Install a C compiler in the virtual machine and execute a sample Program.

PROCEDURE:
Step1:Log on Putty for KVM1.Once KVM1 on

[root@kvm1 ~]# gccadd.c -o add

[root@kvm1 ~]# ./add

[root@kvm1 ~]# enter two numbers

[root@kvm1 ~]# 2 4

OUTPUT:

[root@kvm1 ~]#Sum of 2no:6

Result:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
78

Ex.No: 4.
PROCEDURE TO MIGRATION VIRTUAL MACHINE
Date:

AIM: Show the virtual machine migration based on the certain condition from one node to the other

PROCEDURE:

Step1:Repeat the Step as shown in of 1st Program(Cloud Computing Lab)

Step2:Power on KVM1,KVM2 as shown below

Step3: Create the 2 hosts(KVM1,KVM2) for migration

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
79

Step4:Once login gotoVirtual Machine select the VM to Migrate-live

Step5:Goto Infrastructure select Host which to Migrated,click on Migrate

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
80

Step 6:Check the status MIGRATE of Virtual Machine

OUTPUT:

Check the Virtual Machine which had Migrate(KVM1) Status is now in RUNNING(KVM2) status

Result:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
81

Ex.No: 5.
PROCEDURE TO INSTALL CONTROLLER
Date:

AIM: Find procedure to install storage controller and interact with it

PROCEDURE:

Note: Repeat The Step1 to Step 8 of 1st Program(Cloud Computing Lab)

Step9:GotoInfrastructure Select DataStores

Step10:Click on + to Create Datastoregive the Name and click on Create

Step11:TheDatastore is created,click on Refresh

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
82

OUTPUT:

Result:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
83

Ex.No: 6.
PROCEDURE TO SET UP ONE NODE HADOOP CLUSTER
Date:

Aim: To set up one node Hadoop Cluster.

Procedure:
Step 1: System Set up and Java Installation
Login in PUTTY
login as: root
[email protected]'s password:redhat
[root@localhost ~]# hostnamehadp

login as: root


[email protected]'s password:redhat
Last login: Mon Jul 11 20:11:53 2016 from 192.168.52.1

(To disable firewall)


[root@hadp ~]# systemctl disable firewalld

[root@hadp ~]# systemctl stop firewalld


[root@hadp ~]# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled)
Active: inactive (dead)
[root@hadp ~]# setenforce 0
[root@hadp ~]# getenforce
Permissive
[root@hadp ~]# yum erase java*

Step 2: Creating Hadoop User


[root@hadp ~]#useraddhadoop
[root@hadp ~]#passwdhadoop
Changing password for user hadoop.
New password:redhat
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:redhat
passwd: all authentication tokens updated successfully.
[root@hadp ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):(press enter)
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):(press enter)
Enter same passphrase again:(press enter)

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
84

Your identification has been saved in /root/.ssh/id_rsa.


Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
73:7c:a3:9c:33:14:a8:fe:35:87:7b:2d:42:33:f6:f5 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| |
| . |
| .. |
| ... |
| .S+o |
| . === .. |
| . oX+.o . |
| . ..*+ . E|
| . .o . |
+-----------------+
[root@hadp ~]# ssh-copy-id hadoop@hadp
Are you sure you want to continue connecting (yes/no)?yes
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to
install the new keys
hadoop@hadp'spassword:redhat

[root@hadp ~]# yum install epel-release


[root@hadp ~]# sshhadoop@hadp
[hadoop@hadp ~]$ exit
logout
Connection to hadp closed.
[root@hadp ~]# yum install java-1.8.0*
COMPLETE!
[root@hadp ~]# su - hadoop
[hadoop@hadp ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa):(press enter)
Enter passphrase (empty for no passphrase):(press enter)
Enter same passphrase again:(press enter)
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
5a:ce:68:95:78:6e:9a:b0:ac:44:04:00:0b:47:5b:5b [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|B.o . E |
|.+ o o |
|. o . |
|. .. |
| . .S |

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
85

|. X |
| ..+= |
|..++ |
| ..oo |
+-----------------+
[hadoop@hadp ~]$ ssh-copy-idroot@hadp
The authenticity of host 'hadp (192.168.52.128)' can't be established.
ECDSA key fingerprint is 14:22:1a:ff:0d:dd:ec:48:fe:6d:f7:7b:bf:c8:09:df.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already
installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the
new keys
root@hadp'spassword:redhat

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'root@hadp'"


and check to make sure that only the key(s) you wanted were added.

[hadoop@hadp ~]$ sshroot@hadp


Last login: Mon Jul 11 20:36:54 2016 from 192.168.52.1
[root@hadp ~]# exit
logout
Connection to hadp closed.

Step 3: Downloading Hadoop 2.6.0

(Download hadoop. Skip this step, if the file is in local repository)


[hadoop@hadp~]$ wgethttp://apache.claz.org/hadoop/common/hadoop-2.6.0/hadoop-2.6.0.tar.gz

[hadoop@hadp ~]$ tar xzf hadoop-2.6.0.tar.gz


[hadoop@hadp ~]$ mv hadoop-2.6.0 hadoop

Step 4: Configuring Hadoop


4.1.:Setup Environment Variables
[hadoop@hadp ~]$ nano ~/.bashrc
(Include the following in .bashrc file.)
(pressctrl+x to exit the nano editor.)
export HADOOP_HOME=/home/hadoop/hadoop
export HADOOP_INSTALL=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR= $HADOOP_HOME/lib/native

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
86

export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin

(Now apply the changes in current


running environment)
[hadoop@hadp ~]$ source ~/.bashrc
[hadoop@hadp ~]$ vi $HADOOP_HOME/etc/hadoop/hadoop-env.sh
JAVA_HOME=/opt/jdk1.8.0_66/
4.2 Edit Configuration Files
[hadoop@hadp ~]$ cd $HADOOP_HOME/etc/hadoop
[hadoop@hadphadoop]$ nano core-site.xml
(Include the following within <configuration>tags )

<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>

[hadoop@hadphadoop]$ nano hdfs-site.xml


(Include the following within <configuration> tags)

<property>
<name>dfs.replication</name>
<value>1</value>
</property>

<property>
<name>dfs.name.dir</name>
<value>file:///home/hadoop/hadoopdata/hdfs/namenode</value>
</property>

<property>
<name>dfs.data.dir</name>
<value>file:///home/hadoop/hadoopdata/hdfs/datanode</value>
</property>

[hadoop@hadphadoop]$ nanomapred-site.xml.template

(Include the following within <configuration> tags)

<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>

[hadoop@hadphadoop]$ nano yarn-site.xml

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
87

(Include the following within <configuration> tags)

<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
4.3 Format Namenode
[hadoop@hadphadoop]$ hdfsnamenode -format
16/07/11 23:13:07 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = hadp.cnl.com/192.168.52.128
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 2.6.0
STARTUP_MSG: classpath =
.
.
.
16/07/11 23:13:09 INFO common.Storage: Storage directory
/home/hadoop/hadoopdata/hdfs/namenodehas been successfully formatted.
16/07/11 23:13:09 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with
txid>= 0
16/07/11 23:13:09 INFO util.ExitUtil: Exiting with status 0
16/07/11 23:13:09 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at hadp.cnl.com/192.168.52.128
************************************************************/
Step 5:Start Hadoop Cluster
[hadoop@hadphadoop]$ cd $HADOOP_HOME/sbin/
[hadoop@hadpsbin]$ start-dfs.sh
Are you sure you want to continue connecting (yes/no)? yes
localhost: Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
hadoop@localhost'spassword:redhat
[hadoop@hadpsbin]$ start-yarn.sh

Step 6: Access HadoopServies in Browser

Access Hadoop Services on port 50070 with the IP_Address on web browser.

http://IP_Address:50070

Output:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
88

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
89

Ex.No: 7. PROCEDURE TOMOUNT THE ONE NODE HADOOP CLUSTER


Date: USING FUSE

Aim:
To mount one node Hadoop cluster using FUSE.

Procedure:

Step 1: Create an input directory using the following command


[hadoop@hadp hadoop]$bin/hdfs dfs -mkdir /user001
[hadoop@hadp hadoop]$bin/hdfs dfs -mkdir /user001/hadoop

Step 2: Copy the input file in the input directory using the following command
[hadoop@hadp hadoop]$bin/hdfs dfs –put /home/hadoop/hadoop/file1.txt /user001/hadoop

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
90

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
91

Ex.No: 8. PROGRAM TO USE THE API’S OF HADOOP TO INTERACT WITH


Date: IT

Aim: To write a program to use the API’s of Hadoop to interact with it.

Program:

URLExpSimple.java:
importjava.io.InputStreamReader;
import java.net.URL;
importjava.net.URLConnection;
importjava.util.Scanner;
public class URLExpSimple {
public static void main(String[] args) {
try {
URL mySite = new URL("http://192.168.35.150:50070");
URLConnectionyc = mySite.openConnection();
Scanner in = new Scanner(new InputStreamReader(yc.getInputStream()));
int count = 0;
while (in.hasNext()) {
System.out.println(in.next());
count++;
}
System.out.println("Number of tokens: " + count);
in.close();
} catch (Exception e) {
e.printStackTrace();
}}}
Now compile and run the program
$javac URLExpSimple.java:
$java URLExpSimple

Output:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
92

Result:

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
93

Ex.No: 9. PROGRAM TO DEMONSTRATE THE USE OF MAP AND REDUCE


Date: TASKS

Aim: To demonstrate the use of Map and Reduce tasks.

Procedure:

Step 1: Create an input directory using the following command


[hadoop@hadp hadoop]$bin/hdfs dfs -mkdir /user001/hadoop

Step 2: Copy the input file in the input directory using the following command
[hadoop@hadp hadoop]$bin/hdfs dfs –put /home/hadoop/hadoop/file1.txt /user001/hadoop

Step 3: Run the application by taking the input files from the input directory using the following
command.
[hadoop@hadphadoop]$bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-
2.7.0.jar grep /user001/hadoop/file1.txt /output001 ‘(IT)’

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
94

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
95

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering
96

Result

Department of IT IT6713 – Grid & Cloud Computing Lab Jerusalem College of Engineering

You might also like