/*
* 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.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
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.VmAllocationPolicyBio;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.brite.DijkstraBW;
import org.cloudbus.cloudsim.brite.Graph.Graph;
import org.cloudbus.cloudsim.brite.Graph.Node;
import org.cloudbus.cloudsim.brite.Import.BriteImport;
import org.cloudbus.cloudsim.brite.Model.ModelConstants;
import org.cloudbus.cloudsim.brite.Topology.Topology;
import org.cloudbus.cloudsim.brite.Util.Util;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
/**
* An example showing how to create
* scalable simulations.
*/
public class CS2_RoundRobin {
/** The cloudlet list. */
private static List cloudletList;
/** The vmlist. */
private static List vmlist;
/*public static int numVms=1000;
public static int numDatacenters=50;
public static int numDatacenterHosts=10;
public static int numCloudlets=2000;
*/
public static int numVms=40;
public static int numDatacenters=1;
public static int numDatacenterHosts=4;
public static int numCloudlets=160;
public static int getNumVms(){
return numVms;
}
public int getDatacenters(){
return numDatacenters;
}
public int getDatacenterHosts(){
return numDatacenterHosts;
}
public int getNumCloudlets(){
return numCloudlets;
}
/**
* Creates main() to run this example
*/
public static void main(String[] args) {
//Quando um novo datacenter eh requisitado?
//Resp.: Cada datacenter possui uma politica de alocacao
//Em algum lugar, um novo datacenter eh requisitado
//
//Do jeito que estah, a alocacao ordenada ou nao
//tera o mesmo impacto na rede
//
//A alocacao eh por datacenter, ou seja, enquanto
//existirem cloudlets para serem processados novos
//datacenters sao alocados.
//Quando o atual nao eh mais capaz de prover recursos
//Ou seja, as VMs sao encaminhadas para o datacenter por meio do broker
//cloudlets sao atribuidas s VMS
//Esses valores podem variar
//Preciso encontrar um ganho na distribuicao
/*int numVms=40;
int numDatacenters=2;
int datacenterHosts=9;
int numCloudlets=50;
*/
Log.printLine("Starting CS2...");
//Limpa o arquivo de log
try {
java.io.File arquivo = new java.io.File("realcloudsim.log");
java.io.FileOutputStream fos = new java.io.FileOutputStream(arquivo,false);
String texto="";
fos.write(texto.getBytes());
fos.close();
} catch (Exception e){
System.out.println("Excecao: Erro ao gravar no arquivo. " + e.getMessage());
}//fim catch
try {
// First step: Initialize the CloudSim package. It should be called
// before creating any entities.
int num_user = 1; // number of grid 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 [] datacenter = new Datacenter[numDatacenters];
int i=0;
while (i datacenter[i] = createDatacenter("Datacenter_" + i, numDatacenterHosts,i);
//Proximo datacenter
i=i+1;
}//fim while
//Third step: Create Broker
DatacenterBroker broker = createBroker();
int brokerId = broker.getId();
//Fourth step: Create VMs and Cloudlets and send them to broker
vmlist = createVM(brokerId,numVms);
cloudletList = createCloudlet(brokerId,numCloudlets);
broker.submitVmList(vmlist);
broker.submitCloudletList(cloudletList);
// Fifth step: Starts the simulation
CloudSim.startSimulation();
// Final step: Print results when simulation is over
List newList = broker.getCloudletReceivedList();
CloudSim.stopSimulation();
printCloudletList(newList);
//Print the debt of each user to each datacenter
i=0;
while (i datacenter[i].printDebts();
i=i+1;
}//fim while
Log.printLine("CS2 finished!");
}
catch (Exception e)
{
e.printStackTrace();
Log.printLine("Unwanted errors happen");
}
}
private static Datacenter createDatacenter(String name, int datacenterHosts, int indice){
// Here are the steps needed to create a PowerDatacenter:
// 1. We need to create a list to store one or more
// Machines
List hostList = new ArrayList();
// 2. A Machine contains one or more PEs or CPUs/Cores. Therefore, should
// create a list to store these PEs before creating
// a Machine.
List peList1 = new ArrayList();
int mips = 1000;
// 3. Create PEs and add these into the list.
//for a quad-core machine, a list of 4 PEs is required:
peList1.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
peList1.add(new Pe(1, new PeProvisionerSimple(mips)));
peList1.add(new Pe(2, new PeProvisionerSimple(mips)));
peList1.add(new Pe(3, new PeProvisionerSimple(mips)));
//Another list, for a dual-core machine
List peList2 = new ArrayList();
peList2.add(new Pe(0, new PeProvisionerSimple(mips)));
peList2.add(new Pe(1, new PeProvisionerSimple(mips)));
//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;
//Importante: para a politica de alocacao,
//comeco com o indice 1
int i=1;
while (i<=datacenterHosts){
hostId=i;
//Mapeia o host ao no da topologia Brite
//Faco isso na politica de alocacao
hostList.add(
new Host(
hostId,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList1,
new VmSchedulerTimeShared(peList1)
)
); // This is our machine
i=i+1;
}//fim while
// 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).
//O custo do datacenter esta associado com a topologia
String filePath="topology.brite";
// try {
File f = new File(filePath);
//---De BriteImport.java
//BriteImport closes the file after the reading
BriteImport bi = new BriteImport(f, ModelConstants.AS_FILE);
Graph g = bi.parse();
Topology t = new Topology(g);
//Para o calculo do shortest path com Dijkstra
HashMap d;
Node[] nodes;
//Calcula o Dijkstra para a largura de banda
DijkstraBW dijkstra = new DijkstraBW();
nodes = g.getNodesArray();
Node src = nodes[0];
// d[v] constains shortest distance from source to node v
d = dijkstra.runDijkstra(g, src);
/* for (int j=0; j Util.MSG("Bandwidth cost to reach node[" + j + "] from node [0]: " + d.get(nodes[j]));
}//fim for
//Exibir o custo de bandwidth do datacenter em relacao ao recurso
try {
Thread t1 = new Thread();
t1.sleep(100000);
} catch (Exception e){}
*/
//Custo da localidade (em funcao da bandwidth ate o recurso)
double custoLocalidade = Double.parseDouble(d.get(nodes[indice]).toString());
System.out.println(custoLocalidade);
/* //Exibir o custo de bandwidth do datacenter em relacao ao recurso
try {
Thread t1 = new Thread();
t1.sleep(1000);
} catch (Exception e){}
*/
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 = 0.1; // the cost of using processing in this resource
double costPerMem = 0.05; // the cost of using memory in this resource
double costPerStorage = 0.1 + custoLocalidade; // the cost of using storage in this resource
double costPerBw = 100; // the cost of using bw in this resource
LinkedList storageList = new LinkedList(); //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();
}
// } catch (Exception exc){
// Util.MSG("Excecao: " + exc.getMessage());
// }//fim catch
return datacenter;
}
private static List createVM(int userId, int vms) {
//Creates a container to store VMs. This list is passed to the broker later
LinkedList list = new LinkedList();
//VM Parameters
long size = 10000; //image size (MB)
int ram = 512; //vm memory (MB)
int mips = 250;
long bw = 1000;
int pesNumber = 1; //number of cpus
String vmm = "Xen"; //VMM name
//create VMs
Vm[] vm = new Vm[vms];
for(int i=0;i vm[i] = new Vm(i, userId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
//for creating a VM with a space shared scheduling policy for cloudlets:
//vm[i] = Vm(i, userId, mips, pesNumber, ram, bw, size, priority, vmm, new CloudletSchedulerSpaceShared());
list.add(vm[i]);
}
return list;
}
private static List createCloudlet(int userId, int cloudlets){
// Creates a container to store Cloudlets
LinkedList list = new LinkedList();
//cloudlet parameters
long length = 4000;
long fileSize = 300;
long outputSize = 300;
int pesNumber = 1;
UtilizationModel utilizationModel = new UtilizationModelFull();
Cloudlet[] cloudlet = new Cloudlet[cloudlets];
for(int i=0;i cloudlet[i] = new Cloudlet(i, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
// setting the owner of these Cloudlets
cloudlet[i].setUserId(userId);
list.add(cloudlet[i]);
}
return list;
}
//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 list) {
int size = list.size();
Cloudlet cloudlet;
String result="";
String indent = " ";
Log.printLine();
result += "\n";
Log.printLine("========== OUTPUT ==========");
result += "========== OUTPUT ==========\n";
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
"Data center ID" + indent + "VM ID" + indent + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
result += "Cloudlet ID" + indent + "STATUS" + indent +
"Data center ID" + indent + "VM ID" + indent + indent + "Time" + indent + "Start Time" + indent + "Finish Time\n";
DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent + indent);
result += indent + cloudlet.getCloudletId() + indent + indent;
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
Log.print("SUCCESS");
result += "SUCCESS";
Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
indent + indent + indent + dft.format(cloudlet.getActualCPUTime()) +
indent + indent + dft.format(cloudlet.getExecStartTime())+ indent + indent + indent + dft.format(cloudlet.getFinishTime()));
result += indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
indent + indent + indent + dft.format(cloudlet.getActualCPUTime()) +
indent + indent + dft.format(cloudlet.getExecStartTime())+ indent + indent + indent + dft.format(cloudlet.getFinishTime()) + "\n";
}//fim if
}//fim for
try {
java.io.File arquivo = new java.io.File("/home/lucio/realcloudsim.log");
java.io.FileOutputStream fos = new java.io.FileOutputStream(arquivo,true);
fos.write(result.getBytes());
fos.close();
} catch (Exception e){
System.out.println("Excecao: Erro ao gravar no arquivo. " + e.getMessage());
}//fim catch
}
}
* 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.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
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.VmAllocationPolicyBio;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.brite.DijkstraBW;
import org.cloudbus.cloudsim.brite.Graph.Graph;
import org.cloudbus.cloudsim.brite.Graph.Node;
import org.cloudbus.cloudsim.brite.Import.BriteImport;
import org.cloudbus.cloudsim.brite.Model.ModelConstants;
import org.cloudbus.cloudsim.brite.Topology.Topology;
import org.cloudbus.cloudsim.brite.Util.Util;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
/**
* An example showing how to create
* scalable simulations.
*/
public class CS2_RoundRobin {
/** The cloudlet list. */
private static List
/** The vmlist. */
private static List
/*public static int numVms=1000;
public static int numDatacenters=50;
public static int numDatacenterHosts=10;
public static int numCloudlets=2000;
*/
public static int numVms=40;
public static int numDatacenters=1;
public static int numDatacenterHosts=4;
public static int numCloudlets=160;
public static int getNumVms(){
return numVms;
}
public int getDatacenters(){
return numDatacenters;
}
public int getDatacenterHosts(){
return numDatacenterHosts;
}
public int getNumCloudlets(){
return numCloudlets;
}
/**
* Creates main() to run this example
*/
public static void main(String[] args) {
//Quando um novo datacenter eh requisitado?
//Resp.: Cada datacenter possui uma politica de alocacao
//Em algum lugar, um novo datacenter eh requisitado
//
//Do jeito que estah, a alocacao ordenada ou nao
//tera o mesmo impacto na rede
//
//A alocacao eh por datacenter, ou seja, enquanto
//existirem cloudlets para serem processados novos
//datacenters sao alocados.
//Quando o atual nao eh mais capaz de prover recursos
//Ou seja, as VMs sao encaminhadas para o datacenter por meio do broker
//cloudlets sao atribuidas s VMS
//Esses valores podem variar
//Preciso encontrar um ganho na distribuicao
/*int numVms=40;
int numDatacenters=2;
int datacenterHosts=9;
int numCloudlets=50;
*/
Log.printLine("Starting CS2...");
//Limpa o arquivo de log
try {
java.io.File arquivo = new java.io.File("realcloudsim.log");
java.io.FileOutputStream fos = new java.io.FileOutputStream(arquivo,false);
String texto="";
fos.write(texto.getBytes());
fos.close();
} catch (Exception e){
System.out.println("Excecao: Erro ao gravar no arquivo. " + e.getMessage());
}//fim catch
try {
// First step: Initialize the CloudSim package. It should be called
// before creating any entities.
int num_user = 1; // number of grid 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 [] datacenter = new Datacenter[numDatacenters];
int i=0;
while (i
//Proximo datacenter
i=i+1;
}//fim while
//Third step: Create Broker
DatacenterBroker broker = createBroker();
int brokerId = broker.getId();
//Fourth step: Create VMs and Cloudlets and send them to broker
vmlist = createVM(brokerId,numVms);
cloudletList = createCloudlet(brokerId,numCloudlets);
broker.submitVmList(vmlist);
broker.submitCloudletList(cloudletList);
// Fifth step: Starts the simulation
CloudSim.startSimulation();
// Final step: Print results when simulation is over
List
CloudSim.stopSimulation();
printCloudletList(newList);
//Print the debt of each user to each datacenter
i=0;
while (i
i=i+1;
}//fim while
Log.printLine("CS2 finished!");
}
catch (Exception e)
{
e.printStackTrace();
Log.printLine("Unwanted errors happen");
}
}
private static Datacenter createDatacenter(String name, int datacenterHosts, int indice){
// Here are the steps needed to create a PowerDatacenter:
// 1. We need to create a list to store one or more
// Machines
List
// 2. A Machine contains one or more PEs or CPUs/Cores. Therefore, should
// create a list to store these PEs before creating
// a Machine.
List
int mips = 1000;
// 3. Create PEs and add these into the list.
//for a quad-core machine, a list of 4 PEs is required:
peList1.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
peList1.add(new Pe(1, new PeProvisionerSimple(mips)));
peList1.add(new Pe(2, new PeProvisionerSimple(mips)));
peList1.add(new Pe(3, new PeProvisionerSimple(mips)));
//Another list, for a dual-core machine
List
peList2.add(new Pe(0, new PeProvisionerSimple(mips)));
peList2.add(new Pe(1, new PeProvisionerSimple(mips)));
//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;
//Importante: para a politica de alocacao,
//comeco com o indice 1
int i=1;
while (i<=datacenterHosts){
hostId=i;
//Mapeia o host ao no da topologia Brite
//Faco isso na politica de alocacao
hostList.add(
new Host(
hostId,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList1,
new VmSchedulerTimeShared(peList1)
)
); // This is our machine
i=i+1;
}//fim while
// 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).
//O custo do datacenter esta associado com a topologia
String filePath="topology.brite";
// try {
File f = new File(filePath);
//---De BriteImport.java
//BriteImport closes the file after the reading
BriteImport bi = new BriteImport(f, ModelConstants.AS_FILE);
Graph g = bi.parse();
Topology t = new Topology(g);
//Para o calculo do shortest path com Dijkstra
HashMap d;
Node[] nodes;
//Calcula o Dijkstra para a largura de banda
DijkstraBW dijkstra = new DijkstraBW();
nodes = g.getNodesArray();
Node src = nodes[0];
// d[v] constains shortest distance from source to node v
d = dijkstra.runDijkstra(g, src);
/* for (int j=0; j
}//fim for
//Exibir o custo de bandwidth do datacenter em relacao ao recurso
try {
Thread t1 = new Thread();
t1.sleep(100000);
} catch (Exception e){}
*/
//Custo da localidade (em funcao da bandwidth ate o recurso)
double custoLocalidade = Double.parseDouble(d.get(nodes[indice]).toString());
System.out.println(custoLocalidade);
/* //Exibir o custo de bandwidth do datacenter em relacao ao recurso
try {
Thread t1 = new Thread();
t1.sleep(1000);
} catch (Exception e){}
*/
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 = 0.1; // the cost of using processing in this resource
double costPerMem = 0.05; // the cost of using memory in this resource
double costPerStorage = 0.1 + custoLocalidade; // the cost of using storage in this resource
double costPerBw = 100; // the cost of using bw in this resource
LinkedList
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();
}
// } catch (Exception exc){
// Util.MSG("Excecao: " + exc.getMessage());
// }//fim catch
return datacenter;
}
private static List
//Creates a container to store VMs. This list is passed to the broker later
LinkedList
//VM Parameters
long size = 10000; //image size (MB)
int ram = 512; //vm memory (MB)
int mips = 250;
long bw = 1000;
int pesNumber = 1; //number of cpus
String vmm = "Xen"; //VMM name
//create VMs
Vm[] vm = new Vm[vms];
for(int i=0;i
//for creating a VM with a space shared scheduling policy for cloudlets:
//vm[i] = Vm(i, userId, mips, pesNumber, ram, bw, size, priority, vmm, new CloudletSchedulerSpaceShared());
list.add(vm[i]);
}
return list;
}
private static List
// Creates a container to store Cloudlets
LinkedList
//cloudlet parameters
long length = 4000;
long fileSize = 300;
long outputSize = 300;
int pesNumber = 1;
UtilizationModel utilizationModel = new UtilizationModelFull();
Cloudlet[] cloudlet = new Cloudlet[cloudlets];
for(int i=0;i
// setting the owner of these Cloudlets
cloudlet[i].setUserId(userId);
list.add(cloudlet[i]);
}
return list;
}
//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
int size = list.size();
Cloudlet cloudlet;
String result="";
String indent = " ";
Log.printLine();
result += "\n";
Log.printLine("========== OUTPUT ==========");
result += "========== OUTPUT ==========\n";
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
"Data center ID" + indent + "VM ID" + indent + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
result += "Cloudlet ID" + indent + "STATUS" + indent +
"Data center ID" + indent + "VM ID" + indent + indent + "Time" + indent + "Start Time" + indent + "Finish Time\n";
DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent + indent);
result += indent + cloudlet.getCloudletId() + indent + indent;
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
Log.print("SUCCESS");
result += "SUCCESS";
Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
indent + indent + indent + dft.format(cloudlet.getActualCPUTime()) +
indent + indent + dft.format(cloudlet.getExecStartTime())+ indent + indent + indent + dft.format(cloudlet.getFinishTime()));
result += indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
indent + indent + indent + dft.format(cloudlet.getActualCPUTime()) +
indent + indent + dft.format(cloudlet.getExecStartTime())+ indent + indent + indent + dft.format(cloudlet.getFinishTime()) + "\n";
}//fim if
}//fim for
try {
java.io.File arquivo = new java.io.File("/home/lucio/realcloudsim.log");
java.io.FileOutputStream fos = new java.io.FileOutputStream(arquivo,true);
fos.write(result.getBytes());
fos.close();
} catch (Exception e){
System.out.println("Excecao: Erro ao gravar no arquivo. " + e.getMessage());
}//fim catch
}
}

No comments:
Post a Comment