PDF of Distributed System and Cloud Computing Lab
PDF of Distributed System and Cloud Computing Lab
Published by
Director
Institute of Distance and Open Learning, University of Mumbai,Vidyanagari, Mumbai - 400 098.
Module I
Module II
Module III
Module IV
Module V
5. Mutual Exclusion 57
Module VI
Module VII
Module VIII
*****
SYLLABUS
1
REMOTE PROCESS COMMUNICATION
Unit Structure
1.0 Aim
1.1 Objective
1.2 Pre-Requiste
1.3 Steps: 1
1.4 Description
1.5 Socket Programming
1.6 Socket creation
1.7 Important methods of socket class
1.8 Buffered Reader class Constructors
1.9 Buffered Reader class methods
1.10 Threads
1.11 Bibliography
1.12 Reference
EXPERIMENT 1
1.0 AIM
Write a program to develop multi-client server application where multiple
clients chat with each other concurrently.
1.1 OBJECTIVE
In this experiment both client and server program runs on two different
command prompt.
1.2 PRE-REQUISTE
1.3 STEPS: 1
To develop this experiment we are using the Thread concepts for
developing a multi chat application using JDK.
1.4 DESCRIPTION
There are two ways to create thread in java.:
a) Extending the Thread Class.
1
Distributed System and b) And by implementing the Runnable interface
Cloud Computing Lab
Multithreading in java is a process where multiple threads are
executed simultaneously.
If you want to connect or communicate with more than one client then
we have to write the code using Multithreaded Socket Programming.
Multithreaded Server Socket Program using java.
Write this code using notepad
import java.net.*;
import java.io.*;
public class MultithreadedSocketServer
{
public static void main(String[] args) throws Exception
{
try
{
ServerSocket server=new ServerSocket(8888);
int counter=0;
System.out.println("Server Started ....");
while(true)
{
counter++;
Socket serverClient=server.accept(); //server accept the client
connection request
System.out.println(" >> " + "Client No:" + counter + " started!");
ServerClientThread sct = new
ServerClientThread(serverClient,counter); //send the request to a separate
thread
sct.start();
22
} Remote Process
Communication
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Comiple:
javac TCPClient .java
Run:
java TCPClient
OUTPUT:
Figure (a)
Figure (b)
Important methods of ServerSocket class are:
Figure(c)
Creating Server:
To create a server we need to create the object that is the instance of a
SeverSocket class.
1. Syntax: ServerSocket ss=new ServerSocket(4444);
2. Socket s=ss.accept();//establishes connection and waits for the clientC
reating Client:
To create a client we need to create the instance of a socket class.
1. Syntax: Socket s=new Socket("localhost",4444);
88
BufferedReader class: Remote Process
Communication
It is a class used to read the text from a input stream which is a
character based.
To read the text line by line we use the method readLine() method.
Syntax:
public class BufferedReader extends Reader
1.10 THREADS
A thread is a smallest unit of a process.
1.11 BIBLIOGRAPGHY
https://www.javatpoint.com/socket-programming
https://www.javatpoint.com/
10
10
1.12 REFERENCE Remote Process
Communication
https://www.javatpoint.com/socket-programming
https://www.javatpoint.com/
*****
11
MODULE II
2
REMOTE PROCEDURE CALL
Unit Structure
2.1 Aim
2.2 Objective
2.3 Theory
2.4 Practical No-1
2.4.1 Software Required
2.4.2 Program
2.4.3 Output
2.5 Practical No-2
2.5.1 Software Required
2.5.2Program
2.5.3 Output
2.6 Questions
2.1 AIM
To implement a server calculator using RPC concept.
2.2 OBJECTIVE
The Objective of this module is to make students understand the concepts
of Remote Object Communication.
2.3 THEORY
A remote procedure call is an interprocess communication technique that
is used for client-server based applications. It is also known as a
subroutine call or a function call. A client has a request message that the
RPC translates and sends to the server. This request may be a procedure or
a function call to a remote server. When the server receives the request, it
sends the required response back to the client. The client is blocked while
the server is processing the call and only resumed execution after the
server is finished.
The sequence of events in a remote procedure call are given as
follows:
The client stub makes a system call to send the message to the server
and puts the parameters in the message.
12
The message is sent from the client to the server by the client’s Remote Procedure Call
operating system.
The parameters are removed from the message by the server stub.
2.4.2 Program:
First, we will execute server-side file.
RPCServer.java
13
Distributed System and import java.util.*;
Cloud Computing Lab
import java.net.*;
class RPCServer
{
DatagramSocket ds;
DatagramPacket dp;
String str,methodName,result;
int val1,val2;
RPCServer()
{
try
{
ds=new DatagramSocket(1200);
byte b[]=new byte[4096];
while(true)
{
dp=new DatagramPacket(b,b.length);
ds.receive(dp);
str=new String(dp.getData(),0,dp.getLength());
if(str.equalsIgnoreCase("q"))
{
System.exit(1);
}
else
{
StringTokenizer st = new StringTokenizer(str," ");
int i=0;
while(st.hasMoreTokens())
{
String token=st.nextToken();
methodName=token;
val1 = Integer.parseInt(st.nextToken());
val2 = Integer.parseInt(st.nextToken());
}
}
14
14
System.out.println(str); Remote Procedure Call
InetAddress ia = InetAddress.getLocalHost();
if(methodName.equalsIgnoreCase("add"))
{
result= "" + add(val1,val2);
}
else if(methodName.equalsIgnoreCase("sub"))
{
result= "" + sub(val1,val2);
}
else if(methodName.equalsIgnoreCase("mul"))
{
result= "" + mul(val1,val2);
}
else if(methodName.equalsIgnoreCase("div"))
{
result= "" + div(val1,val2);
}
byte b1[]=result.getBytes();
DatagramSocket ds1 = new DatagramSocket();
DatagramPacket dp1 = new
DatagramPacket(b1,b1.length,InetAddress.getLocalHost(), 1300);
System.out.println("result : "+result+"\n");
ds1.send(dp1);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public int add(int val1, int val2)
{
return val1+val2;
}
15
Distributed System and public int sub(int val3, int val4)
Cloud Computing Lab
{
return val3-val4;
}
public int mul(int val3, int val4)
{
return val3*val4;
}
public int div(int val3, int val4)
{
return val3/val4;
}
public static void main(String[] args)
{
new RPCServer();
}
}
Client-side java file:
RPCClient.java
import java.io.*;
import java.net.*;
class RPCClient
{
RPCClient()
{
try
{
InetAddress ia = InetAddress.getLocalHost();
DatagramSocket ds = new DatagramSocket();
DatagramSocket ds1 = new DatagramSocket(1300);
System.out.println("\nRPC Client\n");
System.out.println("Enter method name and parameter like add 3
4\n");
while (true)
{
16
16
BufferedReader br = new BufferedReader(new Remote Procedure Call
InputStreamReader(System.in));
String str = br.readLine();
byte b[] = str.getBytes();
DatagramPacket dp = new
DatagramPacket(b,b.length,ia,1200);
ds.send(dp);
dp = new DatagramPacket(b,b.length);
ds1.receive(dp);
String s = new String(dp.getData(),0,dp.getLength());
System.out.println("\nResult = " + s + "\n");
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new RPCClient();
}
}
2.4.3 Output:
17
Distributed System and
Cloud Computing Lab
2.5.2Program:
Server-side program:
import java.net.*;
import java.io.*;
import java.util.*;
class DateServer
{
public static void main(String args[]) throws Exception
{
ServerSocket s=new ServerSocket(5217);
while(true)
{
System.out.println("Waiting For Connection ...");
Socket soc=s.accept();
DataOutputStream out=new
DataOutputStream(soc.getOutputStream());
out.writeBytes("Server Date: " + (new Date()).toString() + "\n");
out.close();
soc.close();
}
}
}
18
18
Client side: Remote Procedure Call
import java.io.*;
import java.net.*;
class DateClient
{
public static void main(String args[]) throws Exception
{
Socket soc=new Socket(InetAddress.getLocalHost(),5217);
BufferedReader in=new BufferedReader(new
InputStreamReader(soc.getInputStream() ));
System.out.println(in.readLine());
}
}
2.5.3 Output:
First compile the client code on console and then compile the server code
on different console.
Run the server code, after that client code. Now the client console shows
the time and date of server machine.
2.6 QUESTIONS
Q.1) What is Remote Procedure call?
Q.2) What is Client Stub in remote procedure call?
Q.3) What is Server Stub in remote procedure call?
Q.4) What is the sequence of events during remote procedure call?
*****
19
MODULE III
3
REMOTE METHOD INVOCATION
Unit Structure
3.0 Aim
3.1 Objective
3.2 Pre-Requisite
EXPERIMENT 1
3.0 AIM
Write a client-server program which displays the server machine's date
and time on the client machine.
3.1 OBJECTIVE
In this example both client and server program run on different command
prompt. The time and date of server machine's is displayed on client
machine.
3.2 PRE-REQUISITE
Make sure that JDK 1.8 is installed on your system for all Experiment.
import java.io.*;
import java.net.*;
class DateClient
{
public static void main(String args[]) throws Exception
{
Socket soc=new Socket(InetAddress.getLocalHost(),5217);
BufferedReader in=new BufferedReader(new
InputStreamReader(soc.getInputStream() ));
System.out.println(in.readLine());
}
}
20
STEPS 2: Create file name DateServer.java Remote Method Invocation
import java.net.*;
import java.io.*;
import java.util.*;
class DateServer
{
public static void main(String args[]) throws Exception
{
ServerSocket s=new ServerSocket(5217);
while(true)
{
System.out.println("Waiting For Connection ...");
Socket soc=s.accept();
DataOutputStream out=new
DataOutputStream(soc.getOutputStream());
out.writeBytes("Server Date: " + (new Date()).toString() + "\n");
out.close();
soc.close();
}
}
}
STEP 3:
Output:
First compile the client code on console and then compile the server code
on different console.
● Run the server code, after that client code. Now the client console
shows the time and date of server machine.
AIM
Demonstrate an sample RMI Java application.
21
Distributed System and
Cloud Computing Lab
OBJECTIVE
In this example demonstrating Remote Method Invocation. It is a
mechanism that allows an object residing in one system (JVM) to
access/invoke an object running on another JVM.
RMI is used to build distributed applications; it provides remote
communication between Java programs. It is provided in the
package java.rmi.
PRE-REQUISITE
Make sure that JDK 1.8 is installed on your system For all Experiment.
DESCRIPTION
To write an RMI Java application, you would have to follow the steps
given below:
● Define the remote interface
● Develop the implementation class (remote object)
● Develop the server program
● Develop the client program
● Compile the application
● Execute the application
registry.bind("Hello", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
24
24
Developing the Client Program: Remote Method Invocation
Write a client program in it, fetch the remote object and invoke the
required method using this object.
To this method, you need to pass a string value representing the bind
name as a parameter. This will return you the remote object.
The lookup() returns an object of type remote, down cast it to the type
Hello.
● Finally invoke the required method using the obtained remote object.
Verification: As soon you start the client, you would see the following
output in the server.
EXPERIMENT 3
AIM
Demonstrate an how a client program can retrieve the records of a table in
MySQL database residing on the server.
27
Distributed System and OBJECTIVE
Cloud Computing Lab
In this example using Remote Method Invocation. How a client program
can retrieve the records of a table in MySQL database residing on the
server.
PRE-REQUISITE
Make sure that JDK 1.8 is installed on your system for all Experiment.
DESCRIPTION
29
Distributed System and Developing the Implementation Class:
Cloud Computing Lab
Create a class and implement the above created interface.
Here we are implementing the getStudents() method of the Remote
interface. When you invoke this method, it retrieves the records of a table
named student_data. Sets these values to the Student class using its setter
methods, adds it to a list object and returns that list.
import java.sql.*;
import java.util.*;
// Database credentials
String USER = "myuser";
String PASS = "password";
//Open a connection
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
30
30
//Execute a query Remote Method Invocation
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "SELECT * FROM student_data";
ResultSet rs = stmt.executeQuery(sql);
Server Program:
An RMI server program should implement the remote interface or extend
the implementation class. Here, we should create a remote object and bind
it to the RMI registry.
31
Distributed System and Following is the server program of this application. Here, we will extend
Cloud Computing Lab the above created class, create a remote object and register it to the RMI
registry with the bind name hello.
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
registry.bind("Hello", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
32
32
Client Program: Remote Method Invocation
// System.out.println("bc "+s.getBranch());
System.out.println("ID: " + s.getId());
System.out.println("name: " + s.getName());
System.out.println("branch: " + s.getBranch());
System.out.println("percent: " + s.getPercent());
System.out.println("email: " + s.getEmail());
}
// System.out.println(list);
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
33
Distributed System and e.printStackTrace();
Cloud Computing Lab
}
}
}
34
34
Step 3: Run the server class file as shown below. Remote Method Invocation
Java Server
EXPERIMENT 4
AIM
Demonstrate an how a client should provide an equation to the server
through an interface. The server will solve the expression given by the
client.
OBJECTIVE
In this example using Remote Method Invocation, how a client should
provide an equation to the server through an interface. The server will
solve the expression given by the client
PRE-REQUISITE
Make sure that JDK 1.8 is installed on your system for all Experiment.
35
Distributed System and
Cloud Computing Lab
DESCRIPTION
In this example, we have followed all the 6 steps to create and run the rmi
application. The client application need only two files, remote interface
and client application. In the rmi application, both client and server
interacts with the remote interface. The client application invokes methods
on the proxy object, RMI sends the request to the remote JVM. The return
value is sent back to the proxy object and then to the client application.
3) create the stub and skeleton objects using the rmic tool:
Next step is to create stub and skeleton objects using the rmi compiler.
The rmic tool invokes the RMI compiler and creates stub and skeleton
objects.
rmic AdderRemote
36
36
4) Start the registry service by the rmiregistry tool: Remote Method Invocation
Now start the registry service by using the rmiregistry tool. If you don't
specify the port number, it uses a default port number. In this example, we
are using the port number 5000.
rmiregistry 5000
*****
38
38
MODULE IV
4
REMOTE OBJECT COMMUNICATION
Unit Structure
4.1 Aim
4.2 Objective
4.3 Theory
4.4 Practical No-1
4.4.1 Software Required
4.4.2 Program
4.4.3 Procedure to execute the program
4.5 Practical No-2
4.5.1 Software Required
4.5.2Program
4.5.3 Procedure to execute the program
4.6 Questions
4.7 Self Learning Topic
4.1 AIM
4.2 OBJECTIVE
The Objective of this module is to make students understand the concepts
of Remote Object Communication.
4.3 THEORY
Remote object communication is possible via RMI (Remote Method
Invocation).
A remote object is an object whose method can be invoked from another
JVM.
The RMI (Remote Method Invocation) is an API that provides a way to
create distributed application in java. The RMI allows an object to call
upon methods on an object running in another JVM.
The RMI provides remote communication between the applications using
two objects stub and skeleton.
39
Distributed System and
Cloud Computing Lab
RMI uses stub and skeleton object for communication with the remote
object.
Stub:
The stub is an object that acts as a gateway at the client side. All the
outgoing requests are passed through it. It resides at the client side and
represents the remote object. When the caller invokes method on the stub
object, it does the following tasks:
a) It starts a connection with remote Virtual Machine (JVM),
b) It writes and transmits (marshals) the parameters to the remote Virtual
Machine (JVM),
c) It waits for the result.
d) After the result is received, it reads (unmarshals) the return value or
exception, and
e) It finally, returns the value to the caller.
Skeleton:
The skeleton is an object that acts as a gateway for the server-side object.
All the incoming requests are passed through it. When the skeleton
receives the incoming request, it does the following tasks:
a) It reads the parameter for the remote method.
b) It invokes the method on the actual remote object, and
c) It writes and transmits (marshals) the result to the caller.
RMI Registry:
RMI registry is a namespace where all server objects are placed. Each
time the server creates an object, it registers this object with the
40
40
RMIregistry using bind () or ebind () methods. These objects are Remote Object
registered using a unique name known as bind name. Communication
4.4 PRACTICAL - NO 1
Using MySQL create Library database. Create table Book (Book_id,
Book_name, Book_author) and retrieve the Book information from
Library database using Remote Object Communication concept.
4.4.2 Program:
41
Distributed System and Library.java
Cloud Computing Lab
public class Library implements java.io.Serializable {
private int BookID;
private String BookName,BookAuthor;
Hello.java
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.*;
42
42
// Creating Remote interface for our application Remote Object
Communication
public interface Hello extends Remote
{
public List<Library> getBookInfo() throws Exception;
}
ImplExample.java
import java.sql. *;
import java.util.*;
// Database credentials
String USER = "root";
String PASS = "system";
//Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "SELECT * FROM Book";
ResultSet rs = stmt.executeQuery(sql);
4) Server Program:
An RMI server program should implement the remote interface or extend
the implementation class. Here, we should create a remote object and bind
it to the RMI registry.
44
44
Following is the server program of this application. Here, we will extend Remote Object
the above created class, create a remote object and register it to the RMI Communication
registry with the bind name bookinfo.
In this program server is using port no:6666,we can use any available port.
Server.java
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
5) Client Program:
Following is the client program of this application. Here, we are fetching
the remote object and invoking the method named getBookInfo(). It
retrieves the records of the table from the list object and displays them. 45
Distributed System and In this program, LocateRegistry.getRegistry() method is taking two
Cloud Computing Lab parameter, first is the ip address of the server and second is the port no on
which server is listening.
Client.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.*;
System.out.println("-----------------------------------------------");
}
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
46
46 }
4.4.3 Procedure to execute the program: Remote Object
Communication
Step1: Open the command prompt and go to the folder where you have
save all the java files and compile all the files by using the following
command:
>javac *.java;
once you execute start rmiregistry command one more command prompt
will be open as shown below:
Step 4: Run the client class file on new command prompt if running client
and server on same machine as shown below.
>java Client
4.5.2 Program:
Before starting with codingin java, create ElectricBill database in
MySql.In ElectricBill Database Create Bill(ConsumerName, BillDuedate,
billamount)table.
48
48
Remote Object
Communication
Note: In this practical we are going to create the following java classes:
1. Electric.java
2. Hello.java (Remote Interface)
3. ImplExample.java (Implementation class)
4. Client.java
5. Server.java
Electric.java
public class Electric implements java.io.Serializable {
private float BillAmount;
private String CustomerName,BillDueDate;
49
Distributed System and public void setBillAmount(float BillAmount) {
Cloud Computing Lab
this.BillAmount =BillAmount;
}
public void setCustomerName(String CustomerName) {
this.CustomerName =CustomerName;
}
public void setBillDueDate(String BillDueDate) {
this.BillDueDate = BillDueDate;
}
Hello.java
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.*;
ImplExample.java
import java.sql. *;
import java.util.*;
50
50
// Implementing the remote interface Remote Object
Communication
public class ImplExample implements Hello {
// Database credentials
String USER = "root";
String PASS = "system";
//Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "SELECT * FROM Bill";
ResultSet rs = stmt.executeQuery(sql);
4) Server Program:
An RMI server program should implement the remote interface or extend
the implementation class. Here, we should create a remote object and bind
it to the RMI registry.
Following is the server program of this application. Here, we will extend
the above created class, create a remote object and register it to the RMI
registry with the bind name billinfo.
In this program server is using port no:6666,we can use any available port.
Server.java
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
5) Client Program:
Following is the client program of this application. Here, we are fetching
the remote object and invoking the method named getBillInfo(). It
retrieves the records of the table from the list object and displays them.
In this program, LocateRegistry.getRegistry() method is taking two
parameter, first is the IP address of the server and second is the port no on
which server is listening.
Client.java
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.*;
public class Client {
private Client() {}
public static void main(String[] args)throws Exception {
try {
// Getting the registry
Registry registry =
LocateRegistry.getRegistry("192.168.0.102",6666);
System.out.println("-----------------------------------------------");
}
// System.out.println(list);
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}
}
}
54
54
Step2: Start the rmi registry using the following command. Remote Object
Communication
>start rmiregistry
once you execute start rmiregistry command one more command prompt
will be open as shown below:
55
Distributed System and Step 4: Run the client class file on new command prompt if running client
Cloud Computing Lab and server on same machine by the following command.
>java Client
4.6 QUESTIONS
1) Explain the difference between RPC and RMI.
2) What is the function of java.net.unknownhostException?
3) What are the different terms that are used in RMI?
4) What are the different types of classes that are used in RMI?
5) What is the process of making a class serializable?
*****
56
56
MODULE V
5
MUTUAL EXCLUSION
Unit Structure
5.0 Objective
5.1 Introduction
5.2 Summary
5.3 References
5.4 Unit End Exercises
5.0 OBJECTIVE
Mutual exclusion ensures that concurrent access of processes to a shared
resource or data is serialized, that is, executed in a mutually exclusive
manner. Mutual exclusion in a distributed system states that only one
process is allowed to execute the critical section (CS) at any given time.
5.1 INTRODUCTION
Mutual exclusion is a concurrency control property which is introduced
to prevent race conditions. It is the requirement that a process can not
enter its critical section while another concurrent process is currently
present or executing in its critical section i.e only one process is allowed to
execute the critical section at any given instance of time.
No Starvation:
Every site who wants to execute critical section should get an opportunity
to execute it in finite time. Any site should not wait indefinitely to execute
critical section while other site are repeatedly executing critical section
Fairness:
Each site should get a fair chance to execute critical section. Any request
to execute critical section must be executed in the order they are made i.e
Critical section execution requests should be executed in the order of their
arrival in the system.
Fault Tolerance:
In case of failure, it should be able to recognize it by itself in order to
continue functioning without any disruption.
Solution to distributed mutual exclusion:
As we know shared variables or a local kernel can not be used to
implement mutual exclusion in distributed systems. Message passing is a
way to implement mutual exclusion. Below are the three approaches based
on message passing to implement mutual exclusion in distributed systems:
58
58
● Each requests for critical section contains a sequence number. This Mutual Exclusion
sequence number is used to distinguish old and current requests.
● This approach insures Mutual exclusion as the token is unique
Example:
Suzuki-Kasami’s Broadcast Algorithm
Example:
Lamport's algorithm, Ricart–Agrawala algorithm
Example:
● Maekawa’s Algorithm
Peterson's Algorithm:
If you don't have a hardware atomic test and set, then enforcing mutual
exclusion on a bare machine that meets all the requirements above takes a
surprising amount of work.
// Thread 0 // Thread 1
claim0 = false; claim1 = false;
while (true) { while (true) {
claim0 = true; claim1 = true;
turn = 1; turn = 0;
while (claim1 && turn != 0) {} while (claim0 && turn != 1) {}
CRITICAL SECTION CRITICAL SECTION
claim0 = false; claim1 = false;
NON_CRITICAL_SECTION NON_CRITICAL_SECTION
} }
Bakery Algorithm:
The bakery algorithm solves the mutual exclusion problem for multiple
threads on a bare machine.
62
62
Scheduler-Assisted Mutual Exclusion: Mutual Exclusion
It's nice if the operating system can provide some way to make a thread go
to sleep (i.e. remove it from the pool of ready threads that get scheduled
on a processor) and wake it up when something happens.
Primitives to make this happen include barriers (like latches, countdowns,
and cyclic barriers), mutexes, semaphores, futexes, and exchangers.
Barriers:
Barriers are simple objects used to allow one or more threads to wait until
other threads have completed some work. They can be used for mutual
exclusion if you like. Java has a few of these in its java.util.concurrent
library.
Semaphores:
Semaphores are pretty much designed to implement mutual exclusion.
They work like this:
Semaphore s = new Semaphore(MAX, true);
.
.
.
s.acquire();
CRITICAL_SECTION
s.release();
.
.
.
The idea is that the thread will block on the semaphore if the maximum
number of threads have already successfully "acquired." When a thread
does a "release" then one of the block threads will wake up (meaning the
acquire call finally returns).
The internal implementation is something like this:
Semaphore(max, fifo)
Creates a new semaphore with the given maximum value and fifo flag. If
fifo is true, threads block in a FIFO queue so a release always wakes the
one blocked the longest; otherwise they block in a set and a release wakes
an arbitrary blocked thread.
s.acquire()
atomically {if (s.value > 0) s.value--; else block on s}
63
Distributed System and s.release()
Cloud Computing Lab
atomically {
if (there are threads blocked on s)
wake one of them
else if (s.value == s.MAX)
fail
else
s.value++
}
A semaphore with a maximum count of 1 is called a binary semaphore or
sometimes just a mutex.
Semaphores are an "unstructured" low-level primitive; you might not use
them directly in high-level applications:
● Responsibility of proper use is distributed among all the threads; one
malicious or buggy thread could:
o "Forget" to call wait before entering its critical section and start
whacking shared data in violation of mutual exclusion
o "Forget" to call signal when done, causing the other threads to
deadlock.
● There is no guarantee that resources are accessed only within critical
sections.
So the modern approach is for resources to protect themselves.
Data-Oriented Synchronization:
A simple way to put the resource itself in charge of the protection (instead
of the threads) is to have a lock associated with every object, like in Java:
public class Account {
private BigDecimal balance = BigDecimal.ZERO;
}
Every object in Java has an associated monitor which a thread can lock
and unlock. Only one thread at a time can hold a monitor's lock. A
synchronized method or synchronized statement does an implicit lock at
the beginning and an unlock at the end. An attempt to lock a monitor that
is already locked causes the thread to wait until the lock is free (unless the
lock owner itself is trying to lock again).
By making the account responsible for managing its own synchronization
we free the gazillions of threads that wish to use accounts from having to
remember to lock and unlock themselves!
Note: You don't have to make the scope of the lock be an entire method:
.
.
.
synchronized (x) {
...
}
.
.
.
Notification:
Simply using the synchronized keyword might not be sufficient. Consider
a message board where threads can post messages and other threads can
take them out. The message buffer has a fixed, bounded size. Adds can
only be done when the buffer isn't full, and removes when not empty.
public class UnsynchronizedBuffer {
private Object[] data;
private int head = 0;
private int tail = 0;
private int count = 0;
public Buffer(int capacity) {
data = new Object[capacity];
}
public boolean add(Object item) {
if (count < data.length) {
data[tail] = item; 65
Distributed System and tail = (tail + 1) % data.length;
Cloud Computing Lab
count++;
return true;
}
return false;
}
public Object remove() {
if (count > 0) {
Object item = data[head];
head = (head + 1) % data.length;
count--;
return item;
}
return null;
}
public int getSize() {
return count;
}
}
Notice the race conditions! The buffer could have room for only one
more item, but two threads both try to add at the same time. They each
execute the size test before either completes the adding of an item. There's
a similar race when multiple threads try to remove from a buffer with only
one message.
Exercise: Explain the race conditions a bit more precisely.
What if we just synchronize add and remove? Yeah, that'll remove the
races, but threads wanting to add (or remove) before proceeding will have
to busy wait! NOOOOOOOO! Can't they just go to sleep until some other
thread makes room (in the wants-to-add case) or puts something in (in the
wants-to-remove case)? Yep. Like this:
public class SynchronizedBuffer {
private Object[] data;
private int head = 0;
private int tail = 0;
private int count = 0;
public Buffer(int capacity) {
66
66 data = new Object[capacity];
} Mutual Exclusion
public synchronized void add(Object item) {
while (count == data.length) {
try {wait();} catch (InterruptedException e) {}
}
data[tail] = item;
tail = (tail + 1) % data.length;
count++;
notifyAll();
}
public synchronized Object remove() {
while (count == 0) {
try {wait();} catch (InterruptedException e) {}
}
Object item = data[head];
head = (head + 1) % data.length;
count--;
notifyAll();
return item;
}
public int getSize() {
return count;
}
}
wait() moves a thread into the buffer's wait set (making them blocked),
and notifyAll removes all the threads in the object's wait set (and makes
them runnable again).
This makes the buffer a blocking queue, which is pretty nice; the API for
it is quite clean. But, doing things this way in Java still leaves room for
improvement: all threads here are waiting on the buffer object only, we're
not distinguishing between threads waiting for "not full" and those waiting
for "not empty".
Exercise: What if we placed two new fields within the
SynchronizedBuffer class
private Object notFull = new Object();
private Object notEmpty = new Object();
67
Distributed System and and then rewrote the body of add like this:
Cloud Computing Lab
synchronized (notFull) {
while (count == data.length) {
try {notFull.wait();} catch (InterruptedException e) {}
}
}
data[tail] = item;
tail = (tail + 1) % data.length;
count++;
synchronized (notEmpty) {notEmpty.notifyAll();}
and made similar changes to remove(). Does this work? If so, is it better
than the previous version? How? If not, how does it fail? (Describe any
race conditions, deadlock or starvation in detail.)
By the way, Java does have its own blocking queue class, but you wanted
to learn about wait and notifyAll, right?
end Buffer;
How it works:
● Entries, procedures and functions by definition provide mutually
exclusive access.
● Entries and procedures can read and write shared data; functions can
only read. Thus, an implementation can optimize by allowing multiple
function calls at the same time.
● Only entries have barriers. There is a queue associated with each
entry "inside" the object.
69
Distributed System and ● When an entry is called the barrier is evaluated. If false, the calling task
Cloud Computing Lab is queued on the entry.
● At the end of a procedure or entry body, barriers are re-evaluated.
● Tasks already queued on entries have priority over tasks trying to get
in. Therefore a caller can not even evaluate a barrier until the protected
object is finished with the current and all queued tasks.
It's the programmer's responsibility to see that all barriers execute quickly
and don't call a potentially blocking operation!
Advantages of protected objects (please read the Ada 95 Rationale section
on protected types):
● Scalability
● Adaptability
● Modularity
● Efficiency
● Expressiveness
● Compatibility
● Great for implementing interrupt handlers
In computer science, mutual exclusion refers to the requirement of
ensuring that no two concurrent processes are in their critical section at the
same time; it is a basic requirement in concurrency control, to prevent race
conditions. Here, a critical section refers to a period when the process
accesses a shared resource, such as shared memory. The requirement of
mutual exclusion was first identified and solved by Edsger W. Dijkstra in
his seminal 1965 paper titled Solution of a problem in concurrent
programming control, and is credited as the first topic in the study of
concurrent algorithms.
Program Code:
#include <pthread.h>
#include <stdio.h>
int count = 0;
pthread_mutex_t thread_lock;
void* run_thread()
{
pthread_mutex_lock(&thread_lock);
pthread_t thread_id = pthread_self();
70
70
printf("Thread %u: Current value of count = %d\n", thread_id, count); Mutual Exclusion
printf("Thread %u incrementing count ...\n");
count++;
sleep(1);
printf("Value of count after incremented by thread %u = %d\n",
thread_id, count);
pthread_mutex_unlock(&thread_lock);
pthread_exit(NULL);
}
int main (int argc, char *argv[])
{
pthread_t thread_array[4];
int i = 0, ret, thread_num = 4;
for (i = 0; i < thread_num; i++) {
if ((ret = pthread_create(&thread_array[i], NULL, run_thread, NULL)==-
1) { printf("Thread
creation failed with return code: %d", ret);
exit(ret);
}
}
pthread_exit(NULL);
}
while(!kbhit())
if(cs!=0)
{
t2 = time(NULL);
if(t2-t1 > run)
{
printf("Process%d ",pro-1);
printf(" exits critical section.\n"); 71
Distributed System and cs=0;
Cloud Computing Lab
}
}
key = getch();
if(key!='q')
{
if(cs!=0)
printf("Error: Another process is currently executing critical
section Please wait till its execution is over.\n");
else
{
printf("Process %d ",pro);
printf(" entered critical section\n"); cs=1;
pro++;
t1 = time(NULL);
}
}
}
}
OUTPUT:
{ while(!kbhit()) if(cs!=0)
{
t2 = time(NULL);
if(t2-t1 > run)
{
printf("Process%d ",pro-1);
printf(" exits critical section.\n");
cs=0;
}
}
key = getch();
if(key!='q')
72
72
{ Mutual Exclusion
if(cs!=0) printf("Error: Another process is currently executing critical
section Please wait till its execution is over.\n");
else
{
printf("Process %d ",pro);
printf(" entered critical section\n");
cs=1;
pro++;
t1 = time(NULL);
}
}
}
}
OUTPUT:
{
while(!kbhit())
if(cs!=0)
{
t2 = time(NULL);
if(t2-t1 > run)
{
printf("Process%d ",pro-1);
printf(" exits critical section.\n");
cs=0;
}
}
key = getch();
if(key!='q')
{
if(cs!=0)
73
Distributed System and printf("Error: Another process is currently executing critical
Cloud Computing Lab
section Please wait till its execution is over.\n");
else
{
printf("Process %d ",pro);
printf(" entered critical section\n"); cs=1;
pro++;
t1 = time(NULL);
}
}
}
}
OUTPUT:
5.2 SUMMARY
A mutual exclusion (mutex) is a program object that prevents
simultaneous access to a shared resource. This concept is used in
concurrent programming with a critical section, a piece of code in which
processes or threads access a shared resource.
5.3 REFERENCES
1) The Basics of Hacking and Penetration Testing
2) Hacking: The Art of Exploitation
3) The Web Application Hacker’s Handbook: Finding and Exploiting
Security Flaws
*****
74
74
MODULE VI
6
IMPLEMENTATION OF CLOUD
COMPUTING SERVICES
Unit Structure
6.0 Objective
6.1 Introduction
6.2 Summary
6.3 References
6.4 Unit End Exercises
6.0 OBJECTIVE
Simply put, cloud computing is the delivery of computing services—
including servers, storage, databases, networking, software, analytics, and
intelligence—over the Internet (“the cloud”) to offer faster innovation,
flexible resources, and economies of scale. You typically pay only for
cloud services you use, helping lower your operating costs, run your
infrastructure more efficiently and scale as your business needs change.
6.1 INTRODUCTION
SaaS:
Software as a Service:
Essentially, any application that runs with its contents from the cloud is
referred to as Software as a Service, As long as you do not own it.
Some examples are Gmail, Netflix, OneDrive etc.
AUDIENCE: End users, everybody
IaaS:
Infrastructure as a Service means that the provider allows a portion of
their computing power to its customers, It is purchased by the potency of
the computing power and they are bundled in Virtual Machines. A
company like Google Cloud platform, AWS, Alibaba Cloud can be
referred to as IaaS providers because they sell processing powers (servers,
storage, networking) to their users in terms of Virtual Machines.
AUDIENCE: IT professionals, System Admins
75
Distributed System and PaaS:
Cloud Computing Lab
Platform as a Service is more like the middle-man between IaaS and
SaaS, Instead of a customer having to deal with the nitty-gritty of servers,
networks and storage, everything is readily available by the PaaS
providers. Essentially a development environment is initialized to make
building applications easier.
Examples would be Heroku, AWS Elastic Beanstalk, Google App Engine
etc
AUDIENCE: Software developers.
There are various cloud services available today, such as Amazon's EC2
and AWS, Apache Hadoop, Microsoft Azure and many others. Which
category does each belong to and why?
AWS Example:
EC2 which has only the hardware and you select the base OS to be
installed. If you want to install Hadoop on that you have to do it yourself,
it's just the base infrastructure AWS has provided.
76
76
PaaS (Platform as a Service): Implementation of Cloud
Computing Services
Provides you the infrastructure with OS and necessary base software. You
will have to run your scripts to get the desired output.
AWS Example:
EMR which has the hardware (EC2) + Base OS + Hadoop software
already installed. You will have to run hive/spark scripts to query tables
and get results. You will need to invoke the instance and wait for 10 min
for the setup to be ready. You have to take care of how many clusters you
need based on the jobs you are running, but not worry about the cluster
configuration.
AWS Example:
Athena, which is just a UI for you to query tables in S3 (with metadata
stored in Glu). Just open the browser login to AWS and start running your
queries, no worry about RAM/Storage/CPU/number of clusters,
everything the cloud takes care of.
77
Distributed System and
Cloud Computing Lab
78
78
2. On the Storage accounts page, select Create. Implementation of Cloud
Computing Services
79
Distributed System and The following image shows a standard configuration of the advanced
Cloud Computing Lab properties for a new storage account.
81
Distributed System and 5. Under Choose an application Framework, select Express.js, and
Cloud Computing Lab then select Next. The application framework, which you chose in a
previous step, dictates the type of Azure service deployment target
that's available here.
6. Select the Windows Web App, and then select Next.
On the App Services page, select the name of your web app.
82
82
The Overview page for your web app, contains options for basic Implementation of Cloud
management like browse, stop, start, restart, and delete. The left menu Computing Services
provides further pages for configuring your app.
6.3 REFERENCES:
1. What is cloud computing? A beginner’s guide | Microsoft Azure
2. Create a resource - Microsoft Azure
*****
83
MODULE VII
7
IMPLEMENTATION OF IDENTITY
MANAGEMENT USING CLOUD
Unit Structure
7.0 Objective
7.1 Introduction
7.2 Summary
7.3 References
7.4 Unit End Exercises
7.0 OBJECTIVE
The main goal of identity management is to ensure only authenticated
users are granted access to the specific applications, systems or IT
environments for which they are authorized.
7.1 INTRODUCTION
Identity management in cloud computing is the subsequent step of identity
and access management (IAM) solutions. However, it is a lot more than
merely a straightforward web app single sign-on (SSO) solution. This next
generation of IAM solution is a holistic move of the identity provider right
to the cloud.
Innovations in the user identity management space have been a trend in
the past couple of years. Most of these developments across business and
technology fronts have been around identity management in cloud
computing, enabling the authentication and authorization processes right
in the cloud.
The primary goal of identity management in cloud computing is dealing
with personal identity information so that a user’s access to data, computer
resources, applications, and services is controlled accurately.
Identity management in cloud computing is the subsequent step of identity
and access management (IAM) solutions. However, it is a lot more than
merely a straightforward web app single sign-on (SSO) solution. This next
generation of IAM solution is a holistic move of the identity provider right
to the cloud.
Known as Directory-as-a-Service (DaaS), this particular service is the
advanced version of the conventional and on-premises solutions, including
Lightweight Directory Access Protocol (LDAP) as well as Microsoft
Active Directory (AD).
84
Features of a Modern Cloud Identity Management Solution: Implementation of Identity
Management Using Cloud
The following are a few advantages of identity management in cloud
computing:
● It offers a consistent access control interface: Applicable for all
cloud platform services; Cloud IAM solutions provide a clean and
single access control interface.
● It offers superior security levels: If needed, we can easily define
increased security levels for crucial applications.
● It lets businesses access resources at diverse levels: Businesses
can define roles and grant permissions to explicit users for accessing
resources at diverse granularity levels.
1. Authentication:
The process by which it can be identified that the user, which wants to
access the network resources, valid or not by asking some credentials
such as username and password. Common methods are to put
authentication on console port, AUX port, or vty lines.
As network administrators, we can control how a user is authenticated if
someone wants to access the network. Some of these methods include
using the local database of that device (router) or sending authentication
requests to an external server like the ACS server. To specify the method
to be used for authentication, a default or customized authentication
method list is used.
2. Authorization:
It provides capabilities to enforce policies on network resources after the
user has gained access to the network resources through authentication.
After the authentication is successful, authorization can be used to
determine what resources is the user allowed to access and the operations
that can be performed.
For example, if a junior network engineer (who should not access all the
resources) wants to access the device then the administrator can create a
view that will allow particular commands only to be executed by the user
(the commands that are allowed in the method list). The administrator can
use the authorization method list to specify how the user is authorized to
network resources i.e through a local database or ACS server.
86
86
3. Accounting: Implementation of Identity
Management Using Cloud
It provides means of monitoring and capturing the events done by the user
while accessing the network resources. It even monitors how long the user
has access to the network. The administrator can create an accounting
method list to specify what should be accounted for and to whom the
accounting records should be sent.
AAA implementation:
AAA can be implemented by using the local database of the device or by
using an external ACS server.
Local database:
If we want to use the local running configuration of the router or switch to
implement AAA, we should create users first for authentication and
provide privilege levels to users for Authorization.
ACS server:
This is the common method used. An external ACS server is used (can be
ACS device or software installed on Vmware) for AAA on which
configuration on both router and ACS is required. The configuration
includes creating a user, separate customized method list for
authentication, Authorization, and Accounting.
The client or Network Access Server (NAS) sends authentication requests
to the ACS server and the server takes the decision to allow the user to
access the network resource or not according to the credentials provided
by the user.
Authorization Techniques:
Role-based access control:
RBAC or Role-based access control technique is given to users as per their
role or profile in the organization. It can be implemented for system-
system or user-to-system.
SAML:
SAML stands for Security Assertion Markup Language. It is an open
standard that provides authorization credentials to service providers. These
credentials are exchanged through digitally signed XML documents.
87
Distributed System and OpenID authorization:
Cloud Computing Lab
It helps the clients to verify the identity of end-users on the basis of
authentication.
OAuth:
OAuth is an authorization protocol, which enables the API to authenticate
and access the requested resources.
Code:
1. import java.util.Scanner;
2. public class User_Authentication
3. {
4. public static void main(String args[])
5. {
6. String username, password;
7. Scanner s = new Scanner(System.in);
8. System.out.print("Enter username:");//username:user
9. username = s.nextLine();
10. System.out.print("Enter password:");//password:user
11. password = s.nextLine();
12. if(username.equals("user") && password.equals("user"))
13. {
14. System.out.println("Authentication Successful");
15. }
16. else
17. {
18. System.out.println("Authentication Failed");
88
88
19. } Implementation of Identity
Management Using Cloud
20. }
21. }
Output:
$ javac User_Authentication.java
$ java User_Authentication
Enter username:user
Enter password:user
Authentication Successful
Enter username:abcd
Enter password:1234
Authentication Failed
Authentication is the process of verifying the identity of users or
information. User authentication is the process of verifying the identity of
the user when that user logs in to a computer system. The main objective
of authentication is to allow authorized users to access the computer and to
deny access to unauthorized users.
Example:
Default Assumption: User name = Sandeep Kamble, Password =
Sandeep Kamble
Input: User name = Sandeep Kamble, Password = Sandeep Kamble
Output: Authentication Successful
Input: User name = Sandeep Kamble, Password = Hello world
Output: User name/ Password not matching
Approach:
1. Take username and password as string input from the user.
2. Check if the username matches the password or not.
3. If it matches then welcome the user.
4. Else display an appropriate message.
Below is the implementation of the above approach
89
Distributed System and Java Code:
Cloud Computing Lab
// Java program to check the authentication of the user
// Importing the modules
import java.util.*;
// Gfg Class
public class Gfg
{
// Main CLass
public static void main(String args[])
{
// Declaring the username and password
String user_name = "Sandeep Kamble";
String password = "Sandeep Kamble";
90
90
Login Form Java: Implementation of Identity
Management Using Cloud
In Java, a form for entering authentication credentials to access the
restricted page is referred to as a Login form. A login form contains only
two fields, i.e., username and password. Each user should have a unique
username that can be an email, phone number, or any custom username.
After submitting the login form, the underlying code of the form checks
whether the credentials are authentic or not to allow the user to access the
restricted page. If the users provide unauthentic credentials, they will not
be able to forward the login form.
LoginFormDemo.java
1. //import required classes and packages
2. import javax.swing.*;
3. import java.awt.*;
4. import java.awt.event.*;
5. import java.lang.Exception;
6.
7. //create CreateLoginForm class to create login form
8. //class extends JFrame to create a window where our component add
9. //class implements ActionListener to perform an action on button clic
k 91
Distributed System and 10. class CreateLoginForm extends JFrame implements ActionListener
Cloud Computing Lab
11. {
12. //initialize button, panel, label, and text field
13. JButton b1;
14. JPanel newPanel;
15. JLabel userLabel, passLabel;
16. final JTextField textField1, textField2;
17.
18. //calling constructor
19. CreateLoginForm()
20. {
21.
22. //create label for username
23. userLabel = new JLabel();
24. userLabel.setText("Username"); //set label value for textField
1
25.
26. //create text field to get username from the user
27. textField1 = new JTextField(15); //set length of the text
28.
29. //create label for password
30. passLabel = new JLabel();
31. passLabel.setText("Password"); //set label value for textField
2
32.
33. //create text field to get password from the user
34. textField2 = new JPasswordField(15); //set length for the pass
word
35.
36. //create submit button
92
92
37. b1 = new JButton("SUBMIT"); //set label to button Implementation of Identity
Management Using Cloud
38.
39. //create panel to put form elements
40. newPanel = new JPanel(new GridLayout(3, 1));
41. newPanel.add(userLabel); //set username label to panel
42. newPanel.add(textField1); //set text field to panel
43. newPanel.add(passLabel); //set password label to panel
44. newPanel.add(textField2); //set text field to panel
45. newPanel.add(b1); //set button to panel
46.
47. //set border to panel
48. add(newPanel, BorderLayout.CENTER);
49.
50. //perform action on button click
51. b1.addActionListener(this); //add action listener to button
52. setTitle("LOGIN FORM"); //set title to the login form
53. }
54.
55. //define abstract method actionPerformed() which will be called on
button click
56. public void actionPerformed(ActionEvent ae) //pass action listen
er as a parameter
57. {
58. String userValue = textField1.getText(); //get user entered us
ername from the textField1
59. String passValue = textField2.getText(); //get user entered p
asword from the textField2
60.
61. //check whether the credentials are authentic or not
62. if (userValue.equals("[email protected]") && passValue.equals(
"test")) { //if authentic, navigate user to a new page
93
Distributed System and 63.
Cloud Computing Lab
64. //create instance of the NewPage
65. NewPage page = new NewPage();
66.
67. //make page visible to the user
68. page.setVisible(true);
69.
70. //create a welcome label and set it to the new page
71. JLabel wel_label = new JLabel("Welcome: "+userValue);
72. page.getContentPane().add(wel_label);
73. }
74. else{
75. //show error message
76. System.out.println("Please enter valid username and password
");
77. }
78. }
79. }
80. //create the main class
81. class LoginFormDemo
82. {
83. //main() method start
84. public static void main(String arg[])
85. {
86. try
87. {
88. //create instance of the CreateLoginForm
89. CreateLoginForm form = new CreateLoginForm();
90. form.setSize(300,100); //set size of the frame
94
94 91. form.setVisible(true); //make form visible to the user
92. } Implementation of Identity
Management Using Cloud
93. catch(Exception e)
94. {
95. //handle exception
96. JOptionPane.showMessageDialog(null, e.getMessage());
97. }
98. }
99. }
NewPage.java:
1. //import required classes and packages
2. import javax.swing.*;
3. import java.awt.*;
4.
5. //create NewPage class to create a new page on which user will naviga
te
6. class NewPage extends JFrame
7. {
8. //constructor
9. NewPage()
10. {
11. setDefaultCloseOperation(javax.swing.
12. WindowConstants.DISPOSE_ON_CLOSE);
13. setTitle("Welcome");
14. setSize(400, 200);
15. }
16. }
Output:
Now, when we run the LoginFormDemo.java class, a panel will be open
having the label, text fields, and button. We enter the credentials and hit
on the submit button. If the credentials are authentic, the login form will
navigate us to the welcome page as described below:
95
Distributed System and
Cloud Computing Lab
7.2 SUMMARY
Identity management in cloud computing is highly critical to your
organization. It can persuade the productivity of your employees and
the security of your organization. It can also have immense control over
what technology solutions you select.
However, IAM solutions have to be supple across identity management
and access control in cloud computing to match the current complexities
of the computing environment. If you are locked into some conventional
platforms or service providers because of your active directory ad service,
explore a vendor-neutral cloud identity management solution.
7.3 REFERENCES
1) The Basics of Hacking and Penetration Testing
2) Hacking: The Art of Exploitation
3) The Web Application Hacker’s Handbook: Finding and Exploiting
Security Flaws
*****
96
96
MODULE VIII
8
APP DEVELOPMENT USING CLOUD
COMPUTING
Unit Structure
8.0 Objective
8.1 Introduction
8.2 Summary
8.3 References
8.4 Unit End Exercises
8.0 OBJECTIVE
Application development is the process of creating a computer program or
a set of programs to perform the different tasks that a business requires.
From calculating monthly expenses to scheduling sales reports,
applications help businesses automate processes and increase efficiency.
Cloud application development is a hot topic of 2020. The cloud approach
gives companies lots of valuable benefits: development cost reduction, (no
need for hardware, servers, or even some software), higher accessibility of
the final product, a new level of standardization, and scaling opportunities
8.1 INTRODUCTION
The world has seen an important increase in the demand for Cloud-based
applications. This has in turn increased the demand for Cloud application
development. As a result, the past few years have had a consolidation of
the Cloud computing market.
Cloud apps and services are used, directly or indirectly, by almost
everyone. Businesses have also increased their use of Cloud-based
applications and services, even if they sometimes don’t know it. If you use
SaaS tools, you are surely using a Cloud app. However, Cloud apps are
more than just that.
For many, Cloud apps are still a mystery — one that we plan to explain
throughout this article. As an app development company, we know it is
important for any business to properly make use of Cloud services. If you
want to understand what Cloud computing and Cloud application
development are, how your company can benefit from them, or even if
you just want examples of Cloud apps, this article is for you.
97
Distributed System and What Is the ‘Cloud’?
Cloud Computing Lab
The ‘Cloud’ refers to HiTech computing services that travel over the
internet to some servers in a different location. This IT infrastructure is
usually managed by a third party who charges a fee in exchange for the
computing power and other cloud-based services. In general, Cloud
services allow companies to hire the computing power they need in a
flexible way and without having to directly own or manage the IT
infrastructure themselves.
This technology and its associated services have been gaining popularity
because of the benefits they bring. Thanks to fast internet connections and
efficient computers, it is now possible to make information move fast
enough to have Cloud-based apps that feel almost as if the computing
action occurred natively in the device. Thanks to 5G connections, Cloud
computing is almost resembling Edge computing, helping develop better
and more powerful IoT systems.
Thanks to reduced latency, it is possible to transfer information fast
enough from one place to another in such a way that no delay is felt by the
user. Latency is the delay that occurs between the action of a user and an
app’s response. A reduced latency allows for more real-time and fast-
response apps, opening up all sorts of possibilities for businesses through
better software.
The Cloud market has become more important for a variety of industries
throughout 2020 due to the increased use of tools like Zoom and Google
Meet, which are used by individuals and remote-ready companies alike,
but also to Software as a Service (SaaS) apps like Netflix and Spotify
which are used by people all over the world.
By avoiding the need to own, manage, and configure their own IT
infrastructure through outsourcing, companies can focus on their core
purpose. This has been a game-changer for many software-based
companies and their IT-dependent business models.
What Is a ‘Cloud-Based Application’?
Cloud-based applications, also known as Cloud apps, seem to be taking
over. In theory, a Cloud app is one that uses Cloud-based services. So,
whether an app is mobile or web, they probably use some sort of Cloud
service. What really differentiates a Cloud app from a native one is the
extent to which they use Cloud services.
Increased dependence on the Cloud’s processing power is the result of
companies building innovative and creative solutions to all sorts of
problems that use technology to do things that were previously impossible.
Thanks to the ability to process large amounts of data (Big Data) through
third party owned IT infrastructure, companies can perform massive
calculations and deliver top services.
98
98
In particular, Cloud services have opened up the possibility for many web- App Development Using
based Cloud applications, also known as web apps. A web app is one Cloud Computing
where most of the computation occurs in the Cloud, not on the device
itself, and usually built with the use of Cloud application development
services. A new form of web app, known as a Progressive Web App
(PWA), is also seeing an increase in popularity.
99
Distributed System and Although some businesses have their own Cloud development teams, most
Cloud Computing Lab will hire an app development company with experience in Cloud services.
A great way to verify an app development company’s experience with the
Cloud is through certifications like AWS. Koombea, for example, is
a certified AWS partner.
100
100
● You can store data locally so an application can work offline. As soon App Development Using
as the device is back online, the app will automatically sync with the Cloud Computing
cloud.
● Customers can use a cloud-based app from any internet-connected
device such as a smartphone, tablet, or laptop. All information is
stored in the cloud, so users can pick up where they left off on any
device.
There are three types of cloud-based apps: SaaS, IaaS, and PaaS. Let’s
figure out what each of them stands for.
Architecture:
It’s a good idea to create an advanced data architecture. Classic solutions
are always reliable. However, for cloud applications, a microservices
architecture is commonly used.
103
Distributed System and Service model:
Cloud Computing Lab
The service model you select — SaaS, PaaS, IaaS — must match the type
of cloud solution you’re developing. For example, when developing an
application like Slack, you need to take a SaaS approach.
Utilities:
● Google Analytics
● Twilio
● Optimizely
● Heap
● Recurly
● Zuora
● Cyfe
● TransmogrifAI
DevOps:
● Jenkins
● Bitbucket
● New Relic
● Datadog
● Puppet Labs
● Cloud9 IDE
● Sauce Labs
104
104
● StillAlive App Development Using
Cloud Computing
Business tools:
● Jira
● G Suite
● InVision
● Salesforce Sales Cloud
● Balsamiq
● DocuSign
● UXPin
106
106 ● Version information
● Pricing information App Development Using
Cloud Computing
For the App Store:
● Title (app name)
● Short description
● Full description
● Screenshots
● High-resolution icon
● Featured graphic
● Promo video (optional)
● Type and category
● Content rating
● Languages and translations (if any)
● Contact details
● Privacy policy
● Compatible devices
● Pricing and distribution
Some of the materials listed will cost you nothing to produce, while others
will be quite expensive. Creating a copyright and privacy policy usually
takes time and expensive legal services. How much does it cost to list an
app on the App Store and Google Play if a development company helps
you? Releasing an application can take different amounts of time
depending on the amount of work the company has to do.
Also, remember that before your app is published on either app store, it
must go through an approval process. This procedure can take some time
and require additional development costs. If your app doesn’t meet
platform rules or requirements, it won’t be accepted.
If your app isn’t accepted, you may need to make a few changes in order
to get it approved. Some mobile app development companies provide their
services until your app gets approved, but others don’t.
Example 1: Dynamically changing the background color of a webpage on
each click
HTML
<!DOCTYPE HTML>
<html>
107
Distributed System and
Cloud Computing Lab
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
</head>
<script>
function changecolor()
{
// Generating random color each time
var color = "#"+(Math.random()*16777215|0).toString(16);
$("body").css("background-color",color);
}
</script>
</body>
</html>
Output:
108
108
8.2 SUMMARY App Development Using
Cloud Computing
Cloud computing is the delivery of computing resources — including
storage, processing power, databases, networking, analytics, artificial
intelligence, and software applications — over the internet (the cloud).
8.3 REFERENCES
*****
109