package org.amples;
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
* of Clouds
* Licence: GPL - u/copyleft/gpl.html
*
* Copyright (c) 2009, The University of Melbourne, Australia
*/
【试验一:怎样创建一个含一台主机的数据中心,并在其上运行一个云任务】
DecimalFormat; 【处理huangtu文本、日期、数字和消息的类和接口】【十进制格式】
import java.util.ArrayList; 【Java的实用工具类库java.util包】
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.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
*/ 【主函数运行实例】
public static void main(String[] args) {
Log.printLine(""); 【实验结果输出】
try {
在线金山词霸 // First step: Initialize the CloudSim package. It should be called 【初始化工具包】
// before creating any entities.
int num_ur = 1; // number of cloud urs
Calendar calendar = Instance();
boolean trace_flag = fal; // mean trace events
// Initialize the CloudSim library
CloudSim.init(num_ur, 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 【创建代理】
shrinkage DatacenterBroker broker = createBroker();
int brokerId = Id();垫片英文
// 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
santa is coming to town // 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 【虚拟机列表提交给代理】
give away 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();
【getUtilization()函数 :输入具体时间参数 返回类型是计算资源的利用百分比】
Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
cloudlet.tUrId(brokerId);
cloudlet.tVmId(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();
//a oneFinal step: Print results when simulation is over 【仿真结束 打印结果】
List<Cloudlet> newList = CloudletReceivedList();
printCloudletList(newList);
// Print the debt of each ur to each datacenter 【打印账单】
datacenter0.printDebts();
Log.printLine("CloudSimExample1 finished!");
} catch (Exception e) { 【Java Exception 异常处理机制】
e.printStackTrace();
Log.printLine("Unwanted errors happen");