Friday, April 15, 2016

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:
 yum install kvm
 yum install virt-manager libvirt libvirt-python python-virtinst
 su -c "yum install @virtualization"
 yum groupinfo virtualization
 yum install guestfs-browser
 yum install libguestfs-tools
 yum install python-libguestfs
 yum install virt-top
 su -c "systemctl start libvirtd"
 su -c "systemctl enable libvirtd"
 lsmod | grep kvm

Lab teacher to frame suitable assignment to demonstrate the use of following PaaS tools: Cloud Foundry (Hint: Use Spring Framework), GoogleApp Engine, OpenShift

Steps to deploy app on Google App Engine

1) PyDev Google App Engine Project in Eclipse
2) Select 'src' folder and add to python path
3) Browse google app engine folder after unzipping
4) Hello Webapp world
5) Create index.html
6) Run Config -> Pydev Google App Run -> Browse -> app, then in second Browse -> path/to/google_app_engine/dev_appserver.py
7) Arguments -> Program Arguments -> path/to/app/src
8) Run
9) dev_appserver to check updates on startup, type no

File: helloworld.py

import webapp2
import os
from google.appengine.ext import db
from google.appengine.ext.webapp import template

class Comment(db.Model):
    content = db.StringProperty(multiline=True)
    date = db.DateTimeProperty(auto_now_add=True)
   
def comment_key():
    return db.Key.from_path('comments_dir','default_comments_dir')

class MainPage(webapp2.RequestHandler):
    def get(self):
        comments_query = Comment.all().ancestor(comment_key()).order('-date')
        comments = comments_query.fetch(10)
        template_values = {'Comments':comments}
        path = os.path.join(os.path.dirname(__file__),'index.html')
        self.response.out.write(template.render(path, template_values))
       
class AddComment(webapp2.RequestHandler):
    def post(self):
        comment = Comment(parent=comment_key())
        comment.content = self.request.get('content')
        comment.put()
        self.redirect('/')
       
app = webapp2.WSGIApplication([
('/',MainPage),
('/add',AddComment)
], debug=True)
   
if __name__=='__main__':
    app.run()

File: index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Blog</title>
</head>
<body>
<form action="/add" method="post">
<div>
<textarea rows="3" cols="60" name="content" required></textarea>
</div>
<div>
<input type="submit" value="Add Comment">
</div>
</form>
<br>
<br>
<ul>
{% for comment in Comments %}
<li>
<blockquote>{{ comment.content }}</blockquote>
<blockquote>{{ comment.date.date.day }}/{{ comment.date.date.month }}/{{ comment.date.date.year }}</blockquote>
<blockquote>{{ comment.date.time.hour }}:{{ comment.date.time.minute }}:{{ comment.date.time.second }}</blockquote>
</li>
{% endfor %}
</ul>
</body>
</html>

Write a web application using Scala/ Python/ Java /HTML5 to check the plagiarism in the given text paragraph written/ copied in the text box. Give software Modeling, Design, UML and Test cases for the same using Analysis Modeling (Static Modeling, Object Structuring, Dynamic Modeling).

Commands:
1. sudo easy-install pip

2. sudo pip install flask

3. sudo pip install selenium

File: __init__.py

from flask import Flask, render_template, request


app = Flask(__name__)

#all print statements will show the result in terminal

#open home.html when the app starts
@app.route("/")
def home():
return render_template("home.html")


#this function will be executed after clicking submit button on home.html
@app.route("/detect_plagiarism", methods=["POST"])
def detect_plagiarism():
text = request.form.get("text")
print text
result = plagiarism_report_generator(text)
return render_template("result.html", res=result)



def plagiarism_report_generator(text):

#reading files
fd1 = open("static/input1.txt", "r")
fd2 = open("static/input2.txt", "r")

#combining the two files into source
source = fd1.readlines()
source.extend(fd2.readlines())
source = ''.join(source)

#splitting the sentences with .
text = text.split(".")
source = source.split(".")

print "\n\n\nTEXT : ", text
print "\n\n\nSOURCE : ", source

ip_lines = []
src_lines = []

for line in text:
#remove the first space character in the sentence
if line[:1] == " ":
line = line[1:]
#replace /n by null
line = line.replace("\n","")
#if line itself is null then ignore it
if line == "":
pass
#add line into the ip_lines list
else:
ip_lines.append(line)


for line in source:
#remove the first space character in the sentence
if line[:1] == " ":
line = line[1:]
#replace /n by null
line = line.replace("\n","")
#if line itself is null then ignore it
if line == "":
pass
#add line into the ip_lines list
else:
src_lines.append(line)


counter = 0 #will contain the number of repeated lines


print "\n\n\n TEXT : ", ip_lines
print "\n\n\n SOURCE : ", src_lines

#compare every line in source with every line in input text
for src in src_lines :
for line in ip_lines :
if src == line :
counter+=1
print line, " is repeated"

result = (float(counter)/len(ip_lines))*100 #percentage of plagiarism

return result




if __name__ == '__main__':
app.run(debug=True)

File: second.py

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://127.0.0.1:5000/")
elem1 = driver.find_element_by_name("text")
elem1.send_keys("My name  is husen Chawla")
elem2 = driver.find_element_by_name("sub")
elem2.send_keys(Keys.ENTER)
assert "100" in driver.page_source
driver.close()


Folder: static

File: input1.txt
My name is Amol. I study in PICT.

File: input2.txt
I stay in Pune.

Folder: templates

File: home.html
<!DOCTYPE html>

<html>
<title>Plagiarism Detector</title>
<head></head>

<body>
<form action="/detect_plagiarism" method="post">
<textarea name="text" rows="5" cols="40"></textarea>
<br>
<input type="submit" name="sub" value="Submit">
</form>
</body>

</html>

File: result.html
<!DOCTYPE html>

<html>
<title>Plagiarism Detector</title>
<head></head>

<body>
<p> result is {{res}}%</p>
</body>

</html>

8-Queens Matrix is Stored using JSON/XML having first Queen placed, use back-tracking to place remaining Queens to generate final 8-queen's Matrix. Use suitable Software modeling, Design and testing methods. Justify the selection over other methods.

File: b1.py

import json
import unittest

class MyTestCases(unittest.TestCase):
        def test_positive(self):
                self.assertEqual(run("inp2.json"), True)
def test_negative(self):
self.assertEqual(run("inp3.json"), False)

def isattack(board,r,c):
for i in range(r):
if(board[i][c]==1):
return True
i=r-1
j=c-1
while i>=0 and j>=0:
if(board[i][j]==1):
return True
i-=1
j-=1

i=r-1
j=c+1
while i>=0 and j<8:
if(board[i][j]==1):
return True
i-=1
j-=1
return False


def solve(board,row):
i=0
while i<8:
if (not isattack(board,row,i)):
board[row][i]=1
if row==7:
return True
else:
if(solve(board,row+1)):
return True
else:
board[row][i]=0
i=i+1
if i==8:
return False

def run(filename):
board=[[0 for x in range(8)] for x in range(8)]
if __name__=='__main__':
data=[]
with open(filename, 'r') as f:
data=json.load(f)
if data["start"]>7 or data["start"]<0:
print "Invalid input"
return False #exit()
board[0][data["start"]]=1
if solve(board,1):
print "8 Queens solved"
print "Board Configuraion"
for i in range(8):
for j in range(8):
print str(board[i][j])+"  ",
print "\n"
return True
else:
print "8 Queens not solved"

run('inp1.json')
print "---TESTING---"
unittest.main()


File: inp1.json

{"start":2}

File: inp2.json

{"start":5}

File: inp3.json

{"start":9}


Output

Amols-Air:b1 Darwin$ python b1.py
8 Queens solved
Board Configuraion
0   0   1   0   0   0   0   0  

0   0   0   0   1   0   0   0  

0   0   0   0   0   0   1   0  

1   0   0   0   0   0   0   0  

0   0   0   1   0   0   0   0  

0   1   0   0   0   0   0   0  

0   0   0   0   0   0   0   1  

0   0   0   0   0   1   0   0  

---TESTING---
Invalid input
.8 Queens solved
Board Configuraion
0   0   0   0   0   1   0   0  

0   1   0   0   0   0   0   0  

0   0   0   0   1   0   0   0  

0   0   0   0   0   0   0   1  

0   0   0   1   0   0   0   0  

0   0   0   0   0   0   1   0  

0   0   1   0   0   0   0   0  

1   0   0   0   0   0   0   0  

.
----------------------------------------------------------------------
Ran 2 tests in 0.002s

OK

Install following Cloud Simulators/Tools and frame suitable assignments to demonstarte its use: CloudSim, CloudAnalyst, GreenCloud/Docker, iCanCloud/IBM Smart Cloud, GDCSim/SPECI, MDCSim/ NetworkCloudSim. Assignment : Simulate the following. i) Create and Configure the data center and user base to show response time, request servicing time and data center loading

File: CloudSimExample3.java

/*
 * Title:        CloudSim Toolkit
 * Description:  CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
 *               of Clouds
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * Copyright (c) 2009, The University of Melbourne, Australia
 */

package org.cloudbus.cloudsim.examples;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;


/**
 * A simple example showing how to create
 * a datacenter with two hosts and run two
 * cloudlets on it. The cloudlets run in
 * VMs with different MIPS requirements.
 * The cloudlets will take different time
 * to complete the execution depending on
 * the requested VM performance.
 */
public class CloudSimExample3 {

/** The cloudlet list. */
private static List<Cloudlet> cloudletList;

/** The vmlist. */
private static List<Vm> vmlist;

/**
* Creates main() to run this example
*/
public static void main(String[] args) {

Log.printLine("Starting CloudSimExample3...");

try {
// First step: Initialize the CloudSim package. It should be called
// before creating any entities.
int num_user = 1;   // number of cloud users
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false;  // mean trace events

// Initialize the CloudSim library
CloudSim.init(num_user, calendar, trace_flag);

// Second step: Create Datacenters
//Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
@SuppressWarnings("unused")
Datacenter datacenter0 = createDatacenter("Datacenter_0");

//Third step: Create Broker
DatacenterBroker broker = createBroker();
int brokerId = broker.getId();

//Fourth step: Create one virtual machine
vmlist = new ArrayList<Vm>();

//VM description
int vmid = 0;
int mips = 250;
long size = 10000; //image size (MB)
int ram = 2048; //vm memory (MB)
long bw = 1000;
int pesNumber = 1; //number of cpus
String vmm = "Xen"; //VMM name

//create two VMs
Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());

//the second VM will have twice the priority of VM1 and so will receive twice CPU time
vmid++;
Vm vm2 = new Vm(vmid, brokerId, mips * 2, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());

//add the VMs to the vmList
vmlist.add(vm1);
vmlist.add(vm2);

//submit vm list to the broker
broker.submitVmList(vmlist);


//Fifth step: Create two Cloudlets
cloudletList = new ArrayList<Cloudlet>();

//Cloudlet properties
int id = 0;
long length = 40000;
long fileSize = 300;
long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull();

Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
cloudlet1.setUserId(brokerId);

id++;
Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
cloudlet2.setUserId(brokerId);

//add the cloudlets to the list
cloudletList.add(cloudlet1);
cloudletList.add(cloudlet2);

//submit cloudlet list to the broker
broker.submitCloudletList(cloudletList);


//bind the cloudlets to the vms. This way, the broker
// will submit the bound cloudlets only to the specific VM
broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId());
broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId());

// Sixth step: Starts the simulation
CloudSim.startSimulation();


// Final step: Print results when simulation is over
List<Cloudlet> newList = broker.getCloudletReceivedList();

CloudSim.stopSimulation();

        printCloudletList(newList);

Log.printLine("CloudSimExample3 finished!");
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("The simulation has been terminated due to an unexpected error");
}
}

private static Datacenter createDatacenter(String name){

// Here are the steps needed to create a PowerDatacenter:
// 1. We need to create a list to store
//    our machine
List<Host> hostList = new ArrayList<Host>();

// 2. A Machine contains one or more PEs or CPUs/Cores.
// In this example, it will have only one core.
List<Pe> peList = new ArrayList<Pe>();

int mips = 1000;

// 3. Create PEs and add these into a list.
peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating

//4. Create Hosts with its id and list of PEs and add them to the list of machines
int hostId=0;
int ram = 2048; //host memory (MB)
long storage = 1000000; //host storage
int bw = 10000;

hostList.add(
    new Host(
    hostId,
    new RamProvisionerSimple(ram),
    new BwProvisionerSimple(bw),
    storage,
    peList,
    new VmSchedulerTimeShared(peList)
    )
    ); // This is our first machine

//create another machine in the Data center
List<Pe> peList2 = new ArrayList<Pe>();

peList2.add(new Pe(0, new PeProvisionerSimple(mips)));

hostId++;

hostList.add(
    new Host(
    hostId,
    new RamProvisionerSimple(ram),
    new BwProvisionerSimple(bw),
    storage,
    peList2,
    new VmSchedulerTimeShared(peList2)
    )
    ); // This is our second machine



// 5. Create a DatacenterCharacteristics object that stores the
//    properties of a data center: architecture, OS, list of
//    Machines, allocation policy: time- or space-shared, time zone
//    and its price (G$/Pe time unit).
String arch = "x86";      // system architecture
String os = "Linux";          // operating system
String vmm = "Xen";
double time_zone = 10.0;         // time zone this resource located
double cost = 3.0;              // the cost of using processing in this resource
double costPerMem = 0.05; // the cost of using memory in this resource
double costPerStorage = 0.001; // the cost of using storage in this resource
double costPerBw = 0.0; // the cost of using bw in this resource
LinkedList<Storage> storageList = new LinkedList<Storage>(); //we are not adding SAN devices by now

        DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
                arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);

// 6. Finally, we need to create a PowerDatacenter object.
Datacenter datacenter = null;
try {
datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
} catch (Exception e) {
e.printStackTrace();
}

return datacenter;
}

//We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
//to the specific rules of the simulated scenario
private static DatacenterBroker createBroker(){

DatacenterBroker broker = null;
try {
broker = new DatacenterBroker("Broker");
} catch (Exception e) {
e.printStackTrace();
return null;
}
return broker;
}

/**
* Prints the Cloudlet objects
* @param list  list of Cloudlets
*/
private static void printCloudletList(List<Cloudlet> list) {
int size = list.size();
Cloudlet cloudlet;

String indent = "    ";
Log.printLine();
Log.printLine("========== OUTPUT ==========");
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
"Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");

DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent + indent);

if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
Log.print("SUCCESS");

Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
indent + indent + dft.format(cloudlet.getFinishTime()));
}
}

}
}

Output:

[amodi@localhost CL3codes]$ cd cloudsim-3.0.3/jars
[amodi@localhost jars]$ java -classpath cloudsim-3.0.3.jar:cloudsim-examples-3.0.3.jar org.cloudbus.cloudsim.examples.CloudSimExample3
Starting CloudSimExample3...
Initialising...
Starting CloudSim version 3.0
Datacenter_0 is starting...
Broker is starting...
Entities started.
0.0: Broker: Cloud Resource List received with 1 resource(s)
0.0: Broker: Trying to Create VM #0 in Datacenter_0
0.0: Broker: Trying to Create VM #1 in Datacenter_0
0.1: Broker: VM #0 has been created in Datacenter #2, Host #0
0.1: Broker: VM #1 has been created in Datacenter #2, Host #1
0.1: Broker: Sending cloudlet 0 to VM #0
0.1: Broker: Sending cloudlet 1 to VM #1
80.1: Broker: Cloudlet 1 received
160.1: Broker: Cloudlet 0 received
160.1: Broker: All Cloudlets executed. Finishing...
160.1: Broker: Destroying VM #0
160.1: Broker: Destroying VM #1
Broker is shutting down...
Simulation: No more future events
CloudInformationService: Notify all CloudSim entities for shutting down.
Datacenter_0 is shutting down...
Broker is shutting down...
Simulation completed.
Simulation completed.

========== OUTPUT ==========
Cloudlet ID    STATUS    Data center ID    VM ID    Time    Start Time    Finish Time
    1        SUCCESS        2            1        80        0.1        80.1
    0        SUCCESS        2            0        160        0.1        160.1
CloudSimExample3 finished!

Install following Cloud Simulators/Tools and frame suitable assignments to demonstarte its use: CloudSim, CloudAnalyst, GreenCloud/Docker, iCanCloud/IBM Smart Cloud, GDCSim/SPECI, MDCSim/ NetworkCloudSim. Assignment : Simulate the following. i) Create a datacenter with one host and run one cloudlet on it using CloudSim.

File: CloudSimExample1.java

package org.cloudbus.cloudsim.examples;

/*
 * Title:        CloudSim Toolkit
 * Description:  CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
 *               of Clouds
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * Copyright (c) 2009, The University of Melbourne, Australia
 */

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;

import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;

/**
 * A simple example showing how to create a datacenter with one host and run one
 * cloudlet on it.
 */
public class CloudSimExample1 {

/** The cloudlet list. */
private static List<Cloudlet> cloudletList;

/** The vmlist. */
private static List<Vm> vmlist;

/**
* Creates main() to run this example.
*
* @param args the args
*/
@SuppressWarnings("unused")
public static void main(String[] args) {

Log.printLine("Starting CloudSimExample1...");

try {
// First step: Initialize the CloudSim package. It should be called
// before creating any entities.
int num_user = 1; // number of cloud users
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false; // mean trace events

// Initialize the CloudSim library
CloudSim.init(num_user, calendar, trace_flag);

// Second step: Create Datacenters
// Datacenters are the resource providers in CloudSim. We need at
// list one of them to run a CloudSim simulation
Datacenter datacenter0 = createDatacenter("Datacenter_0");

// Third step: Create Broker
DatacenterBroker broker = createBroker();
int brokerId = broker.getId();

// Fourth step: Create one virtual machine
vmlist = new ArrayList<Vm>();

// VM description
int vmid = 0;
int mips = 1000;
long size = 10000; // image size (MB)
int ram = 512; // vm memory (MB)
long bw = 1000;
int pesNumber = 1; // number of cpus
String vmm = "Xen"; // VMM name

// create VM
Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());

// add the VM to the vmList
vmlist.add(vm);

// submit vm list to the broker
broker.submitVmList(vmlist);

// Fifth step: Create one Cloudlet
cloudletList = new ArrayList<Cloudlet>();

// Cloudlet properties
int id = 0;
long length = 400000;
long fileSize = 300;
long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull();

Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
cloudlet.setUserId(brokerId);
cloudlet.setVmId(vmid);

// add the cloudlet to the list
cloudletList.add(cloudlet);

// submit cloudlet list to the broker
broker.submitCloudletList(cloudletList);

// Sixth step: Starts the simulation
CloudSim.startSimulation();

CloudSim.stopSimulation();

//Final step: Print results when simulation is over
List<Cloudlet> newList = broker.getCloudletReceivedList();
printCloudletList(newList);

Log.printLine("CloudSimExample1 finished!");
} catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
}
}

/**
* Creates the datacenter.
*
* @param name the name
*
* @return the datacenter
*/
private static Datacenter createDatacenter(String name) {

// Here are the steps needed to create a PowerDatacenter:
// 1. We need to create a list to store
// our machine
List<Host> hostList = new ArrayList<Host>();

// 2. A Machine contains one or more PEs or CPUs/Cores.
// In this example, it will have only one core.
List<Pe> peList = new ArrayList<Pe>();

int mips = 1000;

// 3. Create PEs and add these into a list.
peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating

// 4. Create Host with its id and list of PEs and add them to the list
// of machines
int hostId = 0;
int ram = 2048; // host memory (MB)
long storage = 1000000; // host storage
int bw = 10000;

hostList.add(
new Host(
hostId,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList,
new VmSchedulerTimeShared(peList)
)
); // This is our machine

// 5. Create a DatacenterCharacteristics object that stores the
// properties of a data center: architecture, OS, list of
// Machines, allocation policy: time- or space-shared, time zone
// and its price (G$/Pe time unit).
String arch = "x86"; // system architecture
String os = "Linux"; // operating system
String vmm = "Xen";
double time_zone = 10.0; // time zone this resource located
double cost = 3.0; // the cost of using processing in this resource
double costPerMem = 0.05; // the cost of using memory in this resource
double costPerStorage = 0.001; // the cost of using storage in this
// resource
double costPerBw = 0.0; // the cost of using bw in this resource
LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are not adding SAN
// devices by now

DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, cost, costPerMem,
costPerStorage, costPerBw);

// 6. Finally, we need to create a PowerDatacenter object.
Datacenter datacenter = null;
try {
datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
} catch (Exception e) {
e.printStackTrace();
}

return datacenter;
}

// We strongly encourage users to develop their own broker policies, to
// submit vms and cloudlets according
// to the specific rules of the simulated scenario
/**
* Creates the broker.
*
* @return the datacenter broker
*/
private static DatacenterBroker createBroker() {
DatacenterBroker broker = null;
try {
broker = new DatacenterBroker("Broker");
} catch (Exception e) {
e.printStackTrace();
return null;
}
return broker;
}

/**
* Prints the Cloudlet objects.
*
* @param list list of Cloudlets
*/
private static void printCloudletList(List<Cloudlet> list) {
int size = list.size();
Cloudlet cloudlet;

String indent = "    ";
Log.printLine();
Log.printLine("========== OUTPUT ==========");
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
+ "Data center ID" + indent + "VM ID" + indent + "Time" + indent
+ "Start Time" + indent + "Finish Time");

DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent + indent);

if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
Log.print("SUCCESS");

Log.printLine(indent + indent + cloudlet.getResourceId()
+ indent + indent + indent + cloudlet.getVmId()
+ indent + indent
+ dft.format(cloudlet.getActualCPUTime()) + indent
+ indent + dft.format(cloudlet.getExecStartTime())
+ indent + indent
+ dft.format(cloudlet.getFinishTime()));
}
}
}

}

Output:

[amodi@localhost CL3codes]$ cd cloudsim-3.0.3/jars
[amodi@localhost jars]$ java -classpath cloudsim-3.0.3.jar:cloudsim-examples-3.0.3.jar org.cloudbus.cloudsim.examples.CloudSimExample1
Starting CloudSimExample1...
Initialising...
Starting CloudSim version 3.0
Datacenter_0 is starting...
Broker is starting...
Entities started.
0.0: Broker: Cloud Resource List received with 1 resource(s)
0.0: Broker: Trying to Create VM #0 in Datacenter_0
0.1: Broker: VM #0 has been created in Datacenter #2, Host #0
0.1: Broker: Sending cloudlet 0 to VM #0
400.1: Broker: Cloudlet 0 received
400.1: Broker: All Cloudlets executed. Finishing...
400.1: Broker: Destroying VM #0
Broker is shutting down...
Simulation: No more future events
CloudInformationService: Notify all CloudSim entities for shutting down.
Datacenter_0 is shutting down...
Broker is shutting down...
Simulation completed.
Simulation completed.

========== OUTPUT ==========
Cloudlet ID    STATUS    Data center ID    VM ID    Time    Start Time    Finish Time
    0        SUCCESS        2            0        400        0.1        400.1
CloudSimExample1 finished!

Design, Implement and Test Mobile Application for Calculator having trigonometry functionality. The data storage uses 1.text files, 2. XML. Use latest open source software modeling, Designing and testing tool/Scrum-it. Implement the design using HTML-5/Scala/ Python/Java/C++/Rubi on Rails. Perform Positive and Negative testing. Use Android toolkit, Celinium, Monkey Talk.

File: MainActivity.java

package com.example.darwin.calculator;

import android.content.Context;
import android.content.DialogInterface;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class MainActivity extends ActionBarActivity implements View.OnClickListener{

    private Button add, sub, mul, div, tan, cos,sin, sqrt, save, recall, clear, file_read;
    private TextView res;
    private EditText num1, num2;
    double saved_value;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();

    }

    public void init(){
        add = (Button) findViewById(R.id.add);
        sub = (Button) findViewById(R.id.sub);
        mul = (Button) findViewById(R.id.mul);
        div = (Button) findViewById(R.id.div);
        sin = (Button) findViewById(R.id.sin);
        cos = (Button) findViewById(R.id.cos);
        tan = (Button) findViewById(R.id.tan);
        sqrt = (Button) findViewById(R.id.sqrt);
        save = (Button) findViewById(R.id.save);
        recall = (Button) findViewById(R.id.recall);
        clear = (Button) findViewById(R.id.clear);
        file_read = (Button) findViewById(R.id.fileread);
        res = (TextView) findViewById(R.id.res);
        num1 = (EditText) findViewById(R.id.num1);
        num2 = (EditText) findViewById(R.id.num2);
        saved_value = 0;
        add.setOnClickListener(this);
        sub.setOnClickListener(this);
        mul.setOnClickListener(this);
        div.setOnClickListener(this);
        sin.setOnClickListener(this);
        cos.setOnClickListener(this);
        tan.setOnClickListener(this);
        sqrt.setOnClickListener(this);
        save.setOnClickListener(this);
        recall.setOnClickListener(this);
        clear.setOnClickListener(this);
        file_read.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {

        String numb1 = num1.getText().toString();
        String numb2 = num2.getText().toString();

        switch(v.getId()){
            case R.id.add:
                double add_ans = Double.parseDouble(numb1) + Double.parseDouble(numb2);
                res.setText(String.valueOf(add_ans));
                break;
            case R.id.sub:
                double sub_ans = Double.parseDouble(numb1) - Double.parseDouble(numb2);
                res.setText(String.valueOf(sub_ans));
                break;
            case R.id.mul:
                double mul_ans = Double.parseDouble(numb1) * Double.parseDouble(numb2);
                res.setText(String.valueOf(mul_ans));
                break;
            case R.id.div:
                try {
                    BigDecimal n1 = new BigDecimal(Double.parseDouble(numb1));
                    BigDecimal n2 = new BigDecimal(Double.parseDouble(numb2));
                    BigDecimal div_ans = n1.divide(n2,5,BigDecimal.ROUND_HALF_UP);
                    res.setText(String.valueOf(div_ans));
                }
                catch(Exception e) {
                    res.setText("cannot divide by 0");
                }
                break;
            case R.id.sin:
                num2.setText(" ");
                double sin_ans = Math.sin(Double.parseDouble(numb1));
                res.setText(String.valueOf(sin_ans));
                break;
            case R.id.cos:
                num2.setText(" ");
                double cos_ans = Math.cos(Double.parseDouble(numb1));
                res.setText(String.valueOf(cos_ans));
                break;
            case R.id.tan:
                num2.setText(" ");
                double tan_ans = Math.tan(Double.parseDouble(numb1));
                res.setText(String.valueOf(tan_ans));
                break;
            case R.id.sqrt:
                num2.setText(" ");
                double sq_ans = Math.sqrt(Double.parseDouble(numb1));
                res.setText(String.valueOf(sq_ans));
                break;
            case R.id.save:
                String value = res.getText().toString();
                saved_value = Double.parseDouble(value);
                num1.setText(" ");
                num2.setText(" ");
                res.setText("Result");
                break;
            case R.id.recall:
                num1.setText(String.valueOf(saved_value));
                break;
            case R.id.clear:
                num1.setText(" ");
                num2.setText(" ");
                res.setText("Result");
                break;
            case R.id.fileread:
                try {
                    Context context=this;
                    AssetManager am =context.getAssets();
                    InputStream is = am.open("file.txt");
                    BufferedReader buf = new BufferedReader(new InputStreamReader(is));
                    String n1=buf.readLine();
                    String n2=buf.readLine();
                    num1.setText(n1);
                    num2.setText(n2);

                } catch(Exception e)
                {
                    e.printStackTrace();
                }
                break;

        }

    }
}

File: activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.darwin.calculator.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enter Numbers"
        android:id="@+id/textView" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/num1"
        android:layout_below="@+id/textView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/num2"
        android:layout_below="@+id/num1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Result"
        android:id="@+id/res"
        android:layout_below="@+id/num2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="63dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ADD"
        android:id="@+id/add"
        android:layout_centerVertical="true"
        android:layout_alignLeft="@+id/mul"
        android:layout_alignStart="@+id/mul" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SUB"
        android:id="@+id/sub"
        android:layout_above="@+id/mul"
        android:layout_alignRight="@+id/num2"
        android:layout_alignEnd="@+id/num2" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="MUL"
        android:id="@+id/mul"
        android:layout_below="@+id/add"
        android:layout_alignLeft="@+id/sin"
        android:layout_alignStart="@+id/sin" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="DIV"
        android:id="@+id/div"
        android:layout_below="@+id/sub"
        android:layout_alignRight="@+id/sub"
        android:layout_alignEnd="@+id/sub" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SIN"
        android:id="@+id/sin"
        android:layout_below="@+id/mul"
        android:layout_alignRight="@+id/textView"
        android:layout_alignEnd="@+id/textView" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="COS"
        android:id="@+id/cos"
        android:layout_above="@+id/tan"
        android:layout_alignLeft="@+id/div"
        android:layout_alignStart="@+id/div" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TAN"
        android:id="@+id/tan"
        android:layout_below="@+id/sin"
        android:layout_alignLeft="@+id/sin"
        android:layout_alignStart="@+id/sin" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SQRT"
        android:id="@+id/sqrt"
        android:layout_below="@+id/cos"
        android:layout_alignLeft="@+id/cos"
        android:layout_alignStart="@+id/cos" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SAVE"
        android:id="@+id/save"
        android:layout_alignBottom="@+id/res"
        android:layout_toRightOf="@+id/sqrt"
        android:layout_toEndOf="@+id/sqrt" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RECALL"
        android:id="@+id/recall"
        android:layout_below="@+id/save"
        android:layout_alignLeft="@+id/save"
        android:layout_alignStart="@+id/save" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CLEAR"
        android:id="@+id/clear"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/recall"
        android:layout_alignEnd="@+id/recall"
        android:layout_toRightOf="@+id/sqrt"
        android:layout_toEndOf="@+id/sqrt" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="READ FILE"
        android:id="@+id/fileread"
        android:layout_above="@+id/clear"
        android:layout_alignRight="@+id/clear"
        android:layout_alignEnd="@+id/clear"
        android:layout_alignLeft="@+id/clear"
        android:layout_alignStart="@+id/clear" />
</RelativeLayout>

File: file.txt
Path: /app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3/assets

4
5

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:  yum install kvm  yum install virt-manager libvirt libvirt-python python-virtinst  su -c "yum install @v...