It6713 Grid & Cloud Computing Lab
It6713 Grid & Cloud Computing Lab
LIST OF EXPERIMENTS
Exp.
No.
Date
Page
No.
Sign.
5
6
1
2
3
4
5
8
9
Department of IT
Ex.No: 1.
Date:
IMPLEMENTATION OF CALCULATOR
AIM:
Develop a new Web Service for Calculator
PROCEDURE:
Step 1: Open NetBeans IDE 8.1
Department of IT
Department of IT
Department of IT
6
Step 3: Delete the index.html file in Web pages. Create the new file with .XHTML
Department of IT
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
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
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/webapp_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
</session-timeout>
Department of IT
10
</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 .
OUTPUT:
Department of IT
11
Result
Department of IT
Ex.No: 3.
Date:
12
IMPLEMENTATION OF GRID SERVICE
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.
Department of IT
13
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.
Step 5.In spring suite click windows->preferences->webservices->Axis 2 preferences and check the
location of axis 2 .
Department of IT
14
Step 7: In E:/->grid->grid computing software->axis->copy the include folder and paste it in your
project under web content->WEB-INF.
Department of IT
15
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.AxisServletListener"/>
Save and close
Department of IT
16
Step 11:.Now create new package and give the name as com.web.service and click finish.
Step 12:.Now create a class under the package and type a small code and save it.
Department of IT
17
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
18
Step 14:. Right click on your class name->webservice->create webservice->check publish web
service.
Department of IT
19
Step 15: In the same window click on webservice runtime apache:apache axis 2 and check apache
axis 2 and click finish.
Department of IT
20
Step 17:Click on the operation that you have created.
Output:
Result:
Department of IT
21
Ex.No: 4.
Date:
Department of IT
22
Department of IT
23
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
24
Output
Department of IT
25
Result:
Department of IT
Ex.No: 5.
Date:
26
IMPLEMENTATION OF SECURITY MECHANISM
Department of IT
27
Step 4 : Type the corresponding code for all the classes. And add the required jar files in the web
content->web-inf->lib folder.
Department of IT
28
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;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
Department of IT
29
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();
if(rs != null){
rs.next();
Department of IT
30
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;
import javax.servlet.http.HttpSession;
Department of IT
31
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;
import org.apache.log4j.Logger;
Department of IT
32
Department of IT
33
Department of IT
34
Department of IT
35
}
-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{
// pass the request along the filter chain
chain.doFilter(request, response);
Department of IT
36
}
}
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) {
e.printStackTrace();
} catch (SQLException e) {
Department of IT
37
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 {
private Connection connection;
Department of IT
38
Department of IT
39
Department of IT
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>
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>
Department of IT
41
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
42
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/webapp_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>
<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>
Department of IT
43
<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>
<servlet-class>Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping> -->
</web-app>
Department of IT
44
Department of IT
45
Department of IT
46
Department of IT
47
Department of IT
48
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
49
Department of IT
50
Step12: Now ,Go to sts and run the project as Run on server
OUTPUT:
Department of IT
51
Department of IT
52
Result
Department of IT
Ex.No: 6.
Date:
53
IMPLEMENTATION OF GRID PORTAL
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
54
Department of IT
55
Step 3: Create a new class within the newly created package named PieChartServlet and type its
corresponding code.
Department of IT
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
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
58
Department of IT
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
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/webapp_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
61
Step 6 : Add the jar files in WebContent->WEB-INF->lib
Department of IT
62
Output:
Result:
Department of IT
Ex.No: 1.
Date:
63
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
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
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.
Department of IT
66
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.
To find Password run below command:
$cat ~/.one/one_auth
Department of IT
67
Step 8: GotoOneadminDashboard
check for the status onwait for few minutes , if status err problem is due to services are not started
properly.
Department of IT
68
Step11:In Dash board select Image, + symbol will appear on Image dash board which indicates add
click on it.
* 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
69
Department of IT
70
$ onetemplate create --name "TTYLinux" \
--cpu 1 --vcpu 1 --memory 256 --arch x86_64 \
--disk "TTYLinux" \
--nic "private" \
--vnc --ssh --net_context
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
71
OUTPUT:
Check the Status for Virtual Machine RUNNING
Department of IT
Ex.No: 2.
Date:
Result:
Department of IT
72
73
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
Department of IT
74
Department of IT
75
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
76
Department of IT
Ex.No: 3.
Date:
77
PROCEDURE TO INSTALL C COMPLIER
OUTPUT:
Result:
Department of IT
78
Ex.No: 4.
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
Department of IT
79
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)
Department of IT
80
Department of IT
81
Ex.No: 5.
Date:
OUTPUT:
Check the Virtual Machine which had Migrate(KVM1) Status is now in RUNNING(KVM2) status
Result:
Department of IT
82
Step10:Click on
Department of IT
83
OUTPUT:
Result:
Department of IT
84
Ex.No: 6.
Date:
Department of IT
85
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
86
|. 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
87
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
88
(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
89
Department of IT
90
Ex.No: 7.
Date:
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
91
Department of IT
92
Ex.No: 8.
Date:
Aim: To write a program to use the APIs 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
93
Result:
Department of IT
94
Ex.No: 9.
Date:
Department of IT
95
Department of IT
96
Department of IT
97
Result
Department of IT