0% found this document useful (0 votes)
151 views37 pages

Cloud Computing Lab Manual

This document provides instructions for creating an application in Salesforce.com using Apex programming language. It begins with creating a developer edition org and then walks through building a simple warehouse application. It then demonstrates how to add more functionality using Apex triggers to prevent duplicate records by email. Sample test code is also provided to test the trigger functionality.

Uploaded by

Pankz Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
151 views37 pages

Cloud Computing Lab Manual

This document provides instructions for creating an application in Salesforce.com using Apex programming language. It begins with creating a developer edition org and then walks through building a simple warehouse application. It then demonstrates how to add more functionality using Apex triggers to prevent duplicate records by email. Sample test code is also provided to test the trigger functionality.

Uploaded by

Pankz Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Cloud Computing Lab

Manual
1. Introduction to cloud computing.
Cloud computing is a general term for the delivery of hosted services over the internet.
Cloud computing enables companies to consume a compute resource, such as a virtual machine
(VM), storage or an application, as a utility -- just like electricity -- rather than having to build and
maintain computing infrastructures in house.

Cloud computing characteristics and benefits


Cloud computing boasts several attractive benefits for businesses and end users. Five of the main
benefits of cloud computing are:
 Self-service provisioning: End users can spin up compute resources for almost any type of
workload on demand. This eliminates the traditional need for IT administrators to provision
and manage compute resources.
 Elasticity: Companies can scale up as computing needs increase and scale down again as
demands decrease. This eliminates the need for massive investments in local infrastructure,
which may or may not remain active.
 Pay per use: Compute resources are measured at a granular level, enabling users to pay only
for the resources and workloads they use.
 Workload resilience: Cloud service providers often implement redundant resources to
ensure resilient storage and to keep users' important workloads running -- often across
multiple global regions.
 Migration flexibility: Organizations can move certain workloads to or from the cloud -- or
to different cloud platforms -- as desired or automatically for better cost savings or to use
new services as they emerge.

Cloud computing deployment models


Cloud computing services can be private, public or hybrid.
Private cloud services are delivered from a business's data center to internal users. This model
offers the versatility and convenience of the cloud, while preserving the management, control and
security common to local data centers. Internal users may or may not be billed for services
through IT chargeback.
Common private cloud technologies and vendors include VMware and OpenStack.
In the public cloud model, a third-party cloud service provider delivers the cloud service over the
internet. Public cloud services are sold on demand, typically by the minute or hour, though long-
term commitments are available for many services. Customers only pay for
the CPU cycles, storage or bandwidth they consume.
Leading public cloud service providers include Amazon Web Services (AWS),
Microsoft Azure, IBM and Google Cloud Platform.
A hybrid cloud is a combination of public cloud services and an on-premises private cloud, with
orchestration and automation between the two. Companies can run mission-critical workloads or
sensitive applications on the private cloud and use the public cloud to handle workload bursts or
spikes in demand.
The goal of a hybrid cloud is to create a unified, automated, scalable environment that takes
advantage of all that a public cloud infrastructure can provide, while still maintaining control over
mission-critical data.

Types of cloud computing services


Although cloud computing has changed over time, it has been divided into three broad service
categories: infrastructure as a service (IaaS), platform as a service (PaaS) and software as a service
(SaaS).

2.

Creating a Warehouse Application in Sales Force.com

Step 1: Register for a Developer Edition "Org"


If you haven't already done so, start by registering for a free Force.com Developer Edition instance
of Salesforce ("DE org" for short). Use an email address that you can access immediately, submit
the form, and wait for an activation email. Once you receive the activation email, open it, click the
login link, and set your password.
Now you’re in the Force.com's browser-based application development environment and ready to
begin building an app.
Step 2: Create an App
Creating the foundation of a basic cloud app with Force.com requires just a few mouse clicks. In
this tutorial, you use the App Quick Start wizard to create an app that can help you manage
merchandise records in a warehouse.
From the Force.com Home page, click the big Add App button in the Getting Started section. (If
you're starting from somewhere else, click <your_name> | Setup to return to the Force.com Home
page).

Next, fill in the form as follows to match this screen, then click Create:

Once the wizard finishes, click Go To My App, Start Tour, and follow along for a quick overview
of your app's user interface.

Step 3: Try Out the App


To try out your new app, just click New to create a new record of Merchandise.
Then add a new merchandise record for "Laptop" computers.

Tell Me More
The app you just created is very simple -- or is it? Look closely around the screen to see all of the
functionality available by default to your Warehouse app.
 Every object in Force.com automatically has an attached "feed," called Chatter, that lets
authorized app users socialize about and collaborate on the object. Using Chatter, users can
post updates in an object's feed, comment on posts, and follow (subscribe to) the feed to get
pushed updates when they happen. For example, on a Merchandise record, one user might
post a question about the record, to which followers and other users can comment in reply.
 Every DE org has a secure Chat window that lets users interact with one another.
 You can also manage activities related to a record from the Open Activities and Activity
History related lists. Activities include tasks to perform (e.g., making phone calls or sending
email), calendar events, and requested meetings.
 Every app has full-text search functionality for all text fields of an object and Chatter feeds.
 Every DE org has a recycle bin that you can use to view and restore deleted records.
 Every record in Force.com has an "owner," which serves as the basis for a powerful security
system that supports ownership-based record sharing scenarios.
3. Creating an Application in SalesForce.com using Apex programming Language.
Apex Code is designed explicitly for expressing business logic and manipulating data, rather than
generically supporting other programming tasks such as user interfaces and interaction. Apex Code
is therefore conceptually closer to the stored procedure languages common in traditional database
environments, such as PL/SQL and Transact-SQL. But unlike those languages, which due to their
heritage can be terse and difficult to use, Apex Code uses a Java-like syntax, making it
straightforward for most developers to understand. And like Java, Apex Code is strongly typed,
meaning that the code is compiled by the developer before it is executed, and that variables must be
associated with specific object types during this compile process. Control structures are also Java-
like, with for/while loops and iterators borrowing that syntax directly.

trigger
blockDuplic
ates_tgr on
Lead
bulk(before
insert,
before
update) {
/*
*
begin by
building
a map
which
stores
the
(unique)
list of
leads
*
being
inserted
/updated
, using
email
address
as the
key.
*
/
Ma
p<String
, Lead>
leadMap
= new
Map<Stri
ng,
Lead>();
fo
r (Lead
lead :
System.T
rigger.n
ew)
{

if
(lead.Em
ail !=
null)
{ //
skip
null
emails
/
* for
inserts
OR

*
updates
where
the
email
address
is
changing

* check
to see
if the
email is
a
duplicat
e of
another
in

* this
batch,
if
unique,
add this
lead to
the
leadMap

*/

i
f
( System
.Trigger
.isInser
t ||

(Sys
tem.Trig
ger.isUp
date &&
le
ad.Email
!=
System.T
rigger.o
ldMap.ge
t(lead.I
d).Email
)) {

if
(leadMap
.contain
sKey(lea
d.Email)
) {

lead.Em
ail.addE
rror('An
other
new lead
has the
same
email
address.
');

}
else {

leadMap
.put(lea
d.Email,
lead);

}
}
/*
Using
the lead
map,
make a
single
database
query,
*
find all
the
leads in
the
database
that
have the
same
email
address
as
*
any of
the
leads
being
inserted
/updated
.
*
/
fo
r (Lead
lead :
[select
Email
from Lead
where
Email
IN :leadM
ap.KeySe
t()]) {

Lead
newLead =
leadMap.
get(lead
.Email);

newLe
r('A
lead
with
this
email
address
already
exists.'
);
}
}
In addition, no Apex Code trigger would be complete without test coverage, this is done using a
class with a special testing method, the test code does not commit records to the database and so can
be run over and over without modifying your database. Here is a sample test method to verify the
above code works.

public class testBlockDuplicatesLeadTrigger


{

static testMethod void


testDuplicateTrigger(){

Lead[] l1 =new Lead[]{


new Lead( Email='[email protected]',
LastName='Simpson', Company='fox' )
};
insert l1; // add a known lead

Lead[] l2 =new Lead[]{


new Lead( Email='[email protected]',
LastName='Simpson', Company='fox' )
};
// try to add a matching lead
try { insert l2; } catch
( System.DmlException e) {
system.assert(e.getMessage().co
ntains('first error:
FIELD_CUSTOM_VALIDATION_EXCEPTION, A lead
with this email address already exists'),
e.getMessage());
}

// test duplicates in the same


batch
Lead[] l3 =new Lead[]{
new Lead( Email='[email protected]',
LastName='Simpson', Company='fox' ),
new Lead( Email='[email protected]',
LastName='Simpson', Company='fox' )
};
try { insert l3; } catch
( System.DmlException e) {
system.assert(e.getMessage().co
ntains('first error:
FIELD_CUSTOM_VALIDATION_EXCEPTION, Another
new lead has the same email'),
e.getMessage());

// test update also


Lead[] lup = new Lead[]{
new Lead( Email='[email protected]',
LastName='Simpson', Company='fox' )
};
insert lup;
Lead marge = [ select id,Email from
lead where Email = '[email protected]' limit 1];
system.assert(marge!=null);
marge.Email = '[email protected]';

try { update marge; } catch


( System.DmlException e) {
system.assert(e.getMessage().co
ntains('irst error:
FIELD_CUSTOM_VALIDATION_EXCEPTION, A lead
with this email address already exists'),
e.getMessage());
}
}
}

4. Implementation of SOAP Web services in C#/JAVA Applications.


Creating the ASP.NET Web Service
Launch Visual Studio, and then go to File / New / Web Site...
Choose ASP.NET Web Service as the template and name your project: Server.
Throughout this project, I’ll use C:\Project7 as my default folder.
Go to the Service.cs file and create the four needed methods by replacing:
[WebMethod]
public string HelloWorld() {
return "Hello World";

with:
[[WebMethod]
public int Add(int x, int y)
{
return x + y;
}
[WebMethod]
public int Subtract(int x, int y)
{
return x - y;
}
[WebMethod]
public int Multiply(int x, int y)
{
return x * y;
}
[WebMethod]
public int Division(int x, int y)
{
return x / y;
}
Note that [WebMethod] tag allows the methods to be accessible to external clients. Now replace
the code:
[WebService(Namespace = "http://tempuri.org/")]

with:
[WebService(Namespace="http://tempuri.org/",
Description="A Simple Web Calculator Service",
Name="CalculatorWebService")]

The Description attribute gives external clients a brief description of the service; the Name attribute
lets external clients refer to the service as CalculatorWebService rather than Service.

Installing the Web Service in IIS


This project uses IIS Server 7.0 running on a Windows 7 PC.
Activate IIS server by:
Start Menu / typing IIS in the search bar / Internet Information Services (IIS) Manager
or by: Control Panel / Administrative Tools / Internet Information Services (IIS) Manager
If you couldn’t find IIS, then probably it’s not installed, so consult Appendix A to know how you
can activate this program under Windows 7.

Expand the tree Sites, then right click on Default Web Site, and choose Add Virtual Directory.
Enter WebService in the Alias field, and C:\Project7\Server in the Physical path field.

Click on the WebService folder and then switch IIS to Content View in order to see the
Service.asmx and the web.config files.
Since we’ve manually created the Virtual Directory WebService without the help of Visual Studio
testing mode, you should right click the WebService folder and choose Convert to Application
followed by clicking OK.

Now open your browser and goto http://localhost/WebService/Service.asmx, you should see a
screen similar to this:
Testing the Web Service on the Server Side
On the CalculatorWebService page, you could see four links to the Add, Division, Multiply,
and Subtract methods that we’ve implemented in C#; clicking on any of those links will take
you to a new page where you could test your methods.
Creating the ASP.NET Web Client
Launch Visual Studio, and then go to File / New / Web Site...
Choose ASP.NET Web Site as the template and name your project Client.

Create an interface of your ASP.NET page similar to this:


Now let’s add our web service as a service reference to our project as follows:
Right Click the Project in the solution explorer / choose Add Service Reference / enter
http://localhost/WebService/Service.asmx in the address field /click Go to view the imported
functions / choose ServiceReference as your namespace / click OK.

Edit your Default.aspx.cs source to add the method GetResult that takes as an input two number
strings and an integer function which corresponds to the four basic calculator operations we need.
private string GetResult(string firstNumber, string secondNumber, int function)
{
ServiceReference.CalculatorWebServiceSoapClient client =
new ServiceReference.CalculatorWebServiceSoapClient();
int a, b;
string result = null;

erra.Text = "";
errb.Text = "";
if (!int.TryParse(firstNumber, out a))
{
erra.Text = "Must be a valid 32-bit integer!";
return "";
}

if (!int.TryParse(secondNumber, out b))


{
errb.Text = "Must be a valid 32-bit integer!";
return "";
}

try
{
switch (function)
{
case 0:
result = firstNumber + " + " + secondNumber +
" = " + client.Add(a, b);
break;
case 1:
result = firstNumber + " - " + secondNumber + " = "
+ client.Subtract(a, b);
break;
case 2:
result = firstNumber + " * " + secondNumber + " =
" + client.Multiply(a, b);
break;
case 3:
result = firstNumber + " / " +
secondNumber + " = " + client.Division(a, b);
break;
}
}
catch (Exception e)
{
LabelResult.ForeColor = System.Drawing.Color.Red;
result = "Cannot Divide by Zero!";
}
return result;
}
ServiceReference.CalculatorWebServiceSoapClient client =
new ServiceReference.CalculatorWebServiceSoapClient();

which allows the client object to access the web service methods. ServiceReference is the
namespace of the web service you chose earlier. CalculatorWebServiceSoapClient
establishes the SOAP connection with client (i.e. sends requests and receives responses in the form
of SOAP XML messages between the proxy server and the proxy client).
Finally, add the Submit Button event handler with the following code to access the GetResult
method you created earlier.
protected void btnSubmit_Click(object sender, EventArgs e)
{
LabelResult.ForeColor = System.Drawing.Color.Black;
LabelResult.Text = GetResult(TextBoxFirstNumber.Text,
TextBoxSecondNumber.Text,
DropDownList.SelectedIndex);
}

5. Implementation of Para-Virtualization using VM Ware ̳s Workstation/ Oracle ̳s Virtual


Box and
Guest O.S.
Steps to install and configure VMWare:
#1) Download VMWare workstation trial version setup file from here. Set up is around 307 MB.
Currently, version 12 is available. Please note we have set up screens on version 11.
#2) Install VMWare on your machine. Setup is simple and requires to click Next button couple of
times.
#3) After installation open VMWare workstation by using either start menu or shortcut created on
the desktop.
#4) Click on “Create a New Virtual Machine”.
(Note: Click on the image for enlarged view)
#5) With default “Typical” selected click on Next button.

#6) Specify the path of the operating system set up file.

#7) In the Next step you need to specify a Key or a serial number of operating system. If you are
using trial version then that part can be skipped.
#8) Enter the name for the virtual machine and specify a path to the directory where you want to
create your virtual machine. It is recommended that the drive you’re selecting to install virtual
machine should have sufficient space.
#9) Specify an amount of disk space you want to allocate for a virtual machine. Allocate disk space
according to the size of software you are going to install on the virtual machine.
#10) On the next screen it will show configuration you selected for a virtual machine.

#11) It will allocate Hardware according to the default settings but you can change it by using
Customize Hardware button in the above screen.
You can specify what amount of RAM, a processor has to be allocated for a virtual machine. Do not
allocate complete RAM or complete Processor for a virtual machine. Also, do not allocate very less
RAM or processor. Leave default settings or allocate in such way that your application should be
able to run on the virtual machine. Else it will result in a slow virtual machine.
#12) Click on the Finish button to create the virtual machine at the specified location and with
specified resources.
If you have specified a valid file (.iso, .rar., .nrg) for the operating system it will take standard time
to complete operating system set up on the virtual machine and then it will be ready to use your
regular OS.
Notes:
 If you didn’t specify any operating system while creating the virtual machine, later you can
install it just like we do for your laptop or desktop machines. We can use CD/DVD or USB
devices like Pen Drive or even set up a file on the disk to install the operating system in the
VM.
 If your CD/DVD drive is not working then also it is very simple to install the operating
system. Go to VM -> Settings – > select CD/DVD -> in the right half select radio button for
‘use ISO image from’ and specify the path on your hard disk where the .iso file is placed.
This location will be treated as CD/DVD drive of your machine.
 Make sure correct boot order is specified in BIOS so installation will start while getting VM
power on (in this case guest OS is not installed).

Passing data between host and VM:


Generally, VM is having its own drive and it is not showing drives from host OS in the VM
environment. Also, VM drive cannot be used from host OS.
There are few options using which you can use data from Host OS in VM.
Option #1. Using shared directories: Go to VM -> Settings -> Options -> Shared Folders: add the
path of the required directories which you want to view in the VM.

Option #2. Using USB devices: When USB devices are plugged in those are default available for
host operating system and won’t show in the VM. To make them available in VM do:
VM -> Removable devices -> mouse hover USB device and click Connect (Disconnect from the
host). Now USB device will be available in the Guest OS (VM) but won’t be available in the host
machine. Do reverse action to make it available in the host machine.

6. Installation and Configuration of Hadoop.


Step 1) Add a Hadoop system user using below command
sudo addgroup hadoop_
sudo adduser --ingroup hadoop_ hduser_

Enter your password , name and other details.


Login as a root user

Execute the command


sudo adduser hduser_ sudo

Re-login as hduser_

Step 2) . Configure SSH


In order to manage nodes in a cluster, Hadoop require SSH access
First, switch user, enter following command
su - hduser_

This command will create a new key.


ssh-keygen -t rsa -P ""

Enable SSH access to local machine using this key.


cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys

Now test SSH setup by connecting to locahost as 'hduser' user.


ssh localhost

Purge SSH using,


sudo apt-get purge openssh-server
It is good practice to purge before start of installation

Install SSH using command-


sudo apt-get install openssh-server

Step 3) Next step is to Download Hadoop

Select Stable

Select the tar.gz file ( not the file with src)

Once download is complete, navigate to the directory containing the tar file

Enter , sudo tar xzf hadoop-2.2.0.tar.gz

Now, rename rename hadoop-2.2.0 as hadoop


sudo mv hadoop-2.2.0 hadoop
sudo chown -R hduser_:hadoop_ hadoop

Step 4) Modify ~/.bashrc file


Add following lines to end of file ~/.bashrc
#Set HADOOP_HOME
export HADOOP_HOME=<Installation Directory of Hadoop>
#Set JAVA_HOME
export JAVA_HOME=<Installation Directory of Java>
# Add bin/ directory of Hadoop to PATH
export PATH=$PATH:$HADOOP_HOME/bin

Now, source this environment configuration using below command


. ~/.bashrc

Step 5) Configurations related to HDFS


Set JAVA_HOME inside file $HADOOP_HOME/etc/hadoop/hadoop-env.sh

With

There are two parameters in $HADOOP_HOME/etc/hadoop/core-site.xml which need to be set-


1. 'hadoop.tmp.dir' - Used to specify directory which will be used by Hadoop to store its data files.
2. 'fs.default.name' - This specifies the default file system.
To set these parameters, open core-site.xml
sudo gedit $HADOOP_HOME/etc/hadoop/core-site.xml
Copy below line in between tags <configuration></configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/app/hadoop/tmp</value>
<description>Parent directory for other temporary directories.</description>
</property>
<property>
<name>fs.defaultFS </name>
<value>hdfs://localhost:54310</value>
<description>The name of the default file system. </description>
</property>

Navigate to the directory $HADOOP_HOME/etc/Hadoop

Now, create the directory mentioned in core-site.xml


sudo mkdir -p <Path of Directory used in above setting>

Grant permissions to the directory


sudo chown -R hduser_:Hadoop_ <Path of Directory created in above step>

sudo chmod 750 <Path of Directory created in above step>

Step 6) Map Reduce Configuration


Before you begin with these configurations, lets set HADOOP_HOME path
sudo gedit /etc/profile.d/hadoop.sh
And Enter
export HADOOP_HOME=/home/guru99/Downloads/Hadoop

Next enter
sudo chmod +x /etc/profile.d/hadoop.sh
Exit the Terminal and restart again
Type echo $HADOOP_HOME. To verify the path

Now copy files


sudo cp $HADOOP_HOME/etc/hadoop/mapred-site.xml.template
$HADOOP_HOME/etc/hadoop/mapred-site.xml

Open the mapred-site.xml file


sudo gedit $HADOOP_HOME/etc/hadoop/mapred-site.xml

Add below lines of setting in between tags <configuration> and </configuration>


<property>
<name>mapreduce.jobtracker.address</name>
<value>localhost:54311</value>
<description>MapReduce job tracker runs at this host and port.
</description>
</property>

Open $HADOOP_HOME/etc/hadoop/hdfs-site.xml as below,


sudo gedit $HADOOP_HOME/etc/hadoop/hdfs-site.xml

Add below lines of setting between tags <configuration> and </configuration>


<property>
<name>dfs.replication</name>
<value>1</value>
<description>Default block replication.</description>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/home/hduser_/hdfs</value>
</property>
Create directory specified in above setting-
sudo mkdir -p <Path of Directory used in above setting>
sudo mkdir -p /home/hduser_/hdfs

sudo chown -R hduser_:hadoop_ <Path of Directory created in above step>


sudo chown -R hduser_:hadoop_ /home/hduser_/hdfs

sudo chmod 750 <Path of Directory created in above step>


sudo chmod 750 /home/hduser_/hdfs

Step 7) Before we start Hadoop for the first time, format HDFS using below command
$HADOOP_HOME/bin/hdfs namenode -format

Step 8) Start Hadoop single node cluster using below command


$HADOOP_HOME/sbin/start-dfs.sh
Output of above command

$HADOOP_HOME/sbin/start-yarn.sh

Using 'jps' tool/command, verify whether all the Hadoop related processes are running or not.

If Hadoop has started successfully then output of jps should show NameNode, NodeManager,
ResourceManager, SecondaryNameNode, DataNode.
Step 9) Stopping Hadoop
$HADOOP_HOME/sbin/stop-dfs.sh
$HADOOP_HOME/sbin/stop-yarn.sh

7. Create an application (Ex: Word Count) using Hadoop Map/Reduce.


Workflow of MapReduce consists of 5 steps
1. Splitting – The splitting parameter can be anything, e.g. splitting by space, comma,
semicolon, or even by a new line (‘\n’).
2. Mapping – as explained above
3. Intermediate splitting – the entire process in parallel on different clusters. In order to group
them in “Reduce Phase” the similar KEY data should be on same cluster.
4. Reduce – it is nothing but mostly group by phase
5. Combining – The last phase where all the data (individual result set from each cluster) is
combine together to form a Result
Steps
Step 1. Open Eclipse> File > New > Java Project >( Name it – MRProgramsDemo) > Finish
Step 2. Right Click > New > Package ( Name it - PackageDemo) > Finish
Step 3. Right Click on Package > New > Class (Name it - WordCount)
Step 4. Add Following Reference Libraries –
Right Click on Project > Build Path> Add External Archivals
 /usr/lib/hadoop-0.20/hadoop-core.jar
 Usr/lib/hadoop-0.20/lib/Commons-cli-1.2.jar
Step 5. Type following Program :
package PackageDemo;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
public class WordCount {
public static void main(String [] args) throws Exception
{
Configuration c=new Configuration();
String[] files=new GenericOptionsParser(c,args).getRemainingArgs();
Path input=new Path(files[0]);
Path output=new Path(files[1]);
Job j=new Job(c,"wordcount");
j.setJarByClass(WordCount.class);
j.setMapperClass(MapForWordCount.class);
j.setReducerClass(ReduceForWordCount.class);
j.setOutputKeyClass(Text.class);
j.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(j, input);
FileOutputFormat.setOutputPath(j, output);
System.exit(j.waitForCompletion(true)?0:1);
}
public static class MapForWordCount extends Mapper<LongWritable, Text, Text,
IntWritable>{
public void map(LongWritable key, Text value, Context con) throws
IOException, InterruptedException
{
String line = value.toString();
String[] words=line.split(",");
for(String word: words )
{
Text outputKey = new Text(word.toUpperCase().trim());
IntWritable outputValue = new IntWritable(1);
con.write(outputKey, outputValue);
}
}
}
public static class ReduceForWordCount extends Reducer<Text, IntWritable,
Text, IntWritable>
{
public void reduce(Text word, Iterable<IntWritable> values, Context con)
throws IOException, InterruptedException
{
int sum = 0;
for(IntWritable value : values)
{
sum += value.get();
}
con.write(word, new IntWritable(sum));
}
}
}

Explanation
The program consist of 3 classes:
 Driver class (Public void static main- the entry point)
 Map class which extends public class
Mapper<KEYIN,VALUEIN,KEYOUT,VALUEOUT> and implements the Map function.
 Reduce class which extends public class
Reducer<KEYIN,VALUEIN,KEYOUT,VALUEOUT> and implements the Reduce
function.
Step 6. Make Jar File
Right Click on Project> Export> Select export destination as Jar File > next> Finish

Step 7: Take a text file and move it in HDFS


To Move this into Hadoop directly, open the terminal and enter the following commands:
[training@localhost ~]$ hadoop fs -put wordcountFile wordCountFile
Step 8 . Run Jar file
(hadoop jar jarfilename.jar packageName.ClassName PathToInputTextFile
PathToOutputDirectry)
[training@localhost ~]$ hadoop jar MRProgramsDemo.jar PackageDemo.WordCount
wordCountFile MRDir1
Step 9. Open Result
[training@localhost ~]$ hadoop fs -ls MRDir1
Found 3 items
-rw-r--r-- 1 training supergroup 0 2016-02-23 03:36
/user/training/MRDir1/_SUCCESS
drwxr-xr-x - training supergroup 0 2016-02-23 03:36
/user/training/MRDir1/_logs
-rw-r--r-- 1 training supergroup 20 2016-02-23 03:36
/user/training/MRDir1/part-r-00000
[training@localhost ~]$ hadoop fs -cat MRDir1/part-r-00000
BUS 7
CAR 4
TRAIN 6

8. Case Study: PAAS(Facebook, Google App Engine)


Case Study # 4 – Facebook Ads Success with just $1 per Day
Similar to the Buffer experiment, this case study by Brian Carter, a prominent Facebook
Marketing and Advertising Expert and Bestselling author of the book “ The Like Economy”
showed that even investing a minimum of $1/day on Facebook Ads can give you a significant
reach.
By consistently investing $1/day for 30 days, he was able to reach 120,000 people or 4000 people
every day.
He in an active user of most advertising platforms and this is what he found as the cost to reach
1000 people using popular advertising channels.
Facebook Ads are far cheaper than the legacy advertising solutions (newspaper, tv, etc.), but also
left behind its online competitors (Adwords and LinkedIn).
The objective of this case study or experiment was to show that even if you start with a minimal
budget, Facebook Ads can still prove beneficial.

Most businesses can afford to spend $1/day on Facebook, can’t they?


Lesson Learned # 11 – Budget is or should not be a roadblock for virtually any business. $1/day
or $30/month is not a big deal for most businesses.
Lesson Learned # 12 – Even if you are investing more on other channels for traffic or lead
generation successfully, it doesn’t hurt to spend a small proportion on Facebook Ads. You might
get the same number of traffic, but the overall cost will be much cheaper than all other alternatives.
Check out more details about this case study here.

9. Case Study: Amazon Web Services.

Cloud Computing Case Study of Amazon Web Services for Ecommerce Websites

ECommerce enterprises are the major beneficiaries with the advent of Cloud Computing. These
businesses, mostly attract visitors and sales online. More than 60% of its resources used before
sales are available online. Other aspects of eCommerce is sourcing products from vendors, product
delivery to customers and managing the supply chain is offline. A typical eCommerce business
relies heavily on virtual transactions. These activities prompt the enterprise to build attractive and
heavily featured websites with database, high end applications (both web and mobile), high storage
and computing capacity for fast performance, 24 X 7 availability, accessibility on every mobile
device.

Cloud computing is the advanced form of on premise hosting and are designed to manage the
feature deficient in eCommerce sites. There are typical problem for eCommerce businesses like
website break down during peak hours or surge in traffic, sudden need for space due to increase in
product portfolio and built in apps, ERP (like inventory management or Customer Relationship
Management). Cloud Computing has auto scaling, load balancing features which automatically
adjusts with the sudden need for increased computing and increased storage thereby allowing
smooth functioning of the online resources.
Amazon Web Services is the leading cloud computing company and offer computing services for
eCommerce enterprises. We have discussed one of the cases to understand the benefits of using
Cloud Infrastructure and services.
Ice.com , an eCommerce enterprise into retailing jewelry migrated to Amazon Web Services Cloud.
It is based out of New York, United States. ICE was growing fast with its increasing need for IT
hardware and ,so, hosted on two servers located in Montreal, Canada. They were bearing a monthly
expense of $26,000 for managing the physical servers. Besides, they were running a risk for no
disaster recovery plan for the resources and also had plans to introduce many new web store
application, an enterprise resource planning (ERP), a content management system ( CMS) and a
business intelligence ( BI) platform for the smooth functioning of the business. ICE hired an AWS
partner for system development, remote administration, automation, deployment and scalability of
web applications on AWS Infrastructure.

AWS sets up ICE eCommerce sites, ERP, CMS, BI keeping in compliance with the PCI (Payment
Card Industry) standard and Cloud security best practices. ICE used all Amazon features like
Amazon EC2 (Elastic Cloud Computing), Amazon ELB (Elastic Load Balancing) and Amazon
EBS (Elastic Block Storage). Implemented Amazon VPC (Virtual Private Cloud ) to host the ERP
and BI platforms. Amazon S3 (Simple Storage Service) for storing html and static pages. AWS
IAM (Identity and Access Management) allowing secured authorized access to staffs and availing
instances at multiple zones like East and West US coast with a proper disaster recovery plan.
ICE reaped the benefit in fastest new application migration due to the presence of Cloud
Infrastructure, otherwise, which have not been possible. Overhead staff expense was reduced to half
wherein one database administrator and one IT professional replaced two administrators and three
IT professionals. Moreover, AWS helped ICE to save $250000 annually for migrating to Cloud
Infrastructure.

You might also like