我想在Eclipse IDE中创建Cloudsim仿真。我确保没有严重的错误会给程序带来问题。但是当我运行程序时,就会出现此问题。
Exception in thread "main" java.lang.NullPointerException
at org.cloudbus.cloudsim.Host.vmCreate(Host.java:221)
at org.cloudbus.cloudsim.VmAllocationPolicySimple.allocateHostForVm(VmAllocationPolicySimple.java:92)
at org.cloudbus.cloudsim.Datacenter.processVmCreate(Datacenter.java:443)
at org.cloudbus.cloudsim.Datacenter.processEvent(Datacenter.java:216)
at org.cloudbus.cloudsim.core.SimEntity.run(SimEntity.java:426)
at org.cloudbus.cloudsim.core.CloudSim.runClockTick(CloudSim.java:523)
at org.cloudbus.cloudsim.core.CloudSim.run(CloudSim.java:887)
at org.cloudbus.cloudsim.core.CloudSim.startSimulation(CloudSim.java:188)
at cloudsimProject.cloudsimSimulation.main(cloudsimSimulation.java:93)
我不知道应该更改哪个null来解决此问题。这是代码。
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.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerSpaceShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisioner;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
public class cloudsimSimulation {
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
int numUser=1;
Calendar cal;
cal = Calendar.getInstance();
boolean traceFlag=false;
CloudSim.init(numUser, cal, traceFlag);
Datacenter dc = CreateDataCenter();
DatacenterBroker dcb = null;
try
{
dcb = new DatacenterBroker("DatacenterBroker1");
}
catch(Exception e)
{
e.printStackTrace();
}
List<Cloudlet> cloudletList = new ArrayList<Cloudlet>();
long cloudLetLength = 40000;
int pesNumber = 1;
long cloudletFileSize = 300;
long cloudletOutputSize = 400;
UtilizationModelFull fullUtilize = new UtilizationModelFull();
for(int cloudletId=0;cloudletId<40;cloudletId++)
{
Cloudlet newCloudlet = new Cloudlet(cloudletId, cloudLetLength, pesNumber, cloudletFileSize, cloudletOutputSize,
fullUtilize,fullUtilize,fullUtilize);
newCloudlet.setUserId(dcb.getId());
cloudletList.add(newCloudlet);
}
List<Vm> vmList = new ArrayList<Vm>();
long diskSize = 20000;
int ram = 2000;
int mips = 1000;
int bandwidth = 1000;
int vCPU = 1;
String VMM = "XEN";
for(int vmId=0;vmId<40;vmId++)
{
Vm virtualMachine = new Vm(vmId, dcb.getId(), mips, vCPU, ram, bandwidth, diskSize, VMM,
new CloudletSchedulerTimeShared());
vmList.add(virtualMachine);
}
dcb.submitCloudletList(cloudletList);
dcb.submitVmList(vmList);
CloudSim.startSimulation();
List<Cloudlet> finalCloudletExecutionResults = dcb.getCloudletReceivedList();
CloudSim.stopSimulation();
int cloudletNo=0;
for(Cloudlet c : finalCloudletExecutionResults)
{
Log.printLine("Result of cloudlet No " + cloudletNo);
Log.printLine("**********************");
Log.printLine("ID:"+c.getCloudletId()+ "Vm:"+c.getVmId()+ "status:"+c.getStatus()+ ",Execution Time:"+c.getActualCPUTime()+ ",Start:"+c.getExecStartTime()+ ",finish:"+c.getFinishTime() );
Log.printLine("**********************");
cloudletNo++;
}
}
private static Datacenter CreateDataCenter()
{
List<Pe> peList = new ArrayList<Pe>();
PeProvisionerSimple pProvisioner = new PeProvisionerSimple(1000);
Pe core1 = new Pe(0, pProvisioner);
peList.add(core1);
Pe core2 = new Pe(1, pProvisioner);
peList.add(core2);
Pe core3 = new Pe(2, pProvisioner);
peList.add(core3);
Pe core4 = new Pe(3, pProvisioner);
peList.add(core4);
List<Host> hostlist = new ArrayList<Host>();
int ram = 8000;
int bw = 8000;
long storage = 100000;
Host host1 = new Host(0, RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList,
new VmSchedulerSpaceShared(peList));
hostlist.add(host1);
Host host2 = new Host(1, RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList,
new VmSchedulerSpaceShared(peList));
hostlist.add(host2);
Host host3 = new Host(2, RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList,
new VmSchedulerSpaceShared(peList));
hostlist.add(host3);
Host host4 = new Host(3, RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList,
new VmSchedulerSpaceShared(peList));
hostlist.add(host4);
String architecture="x86";
String os = "Linux";
String vmm="XEN";
double timeZone = 5.0;
double ComputecostPerSec = 3.0;
double costPerMem=1.0;
double costPerStorage=0.05;
double costPerBW=0.10;
DatacenterCharacteristics dcCharacteristics=
new DatacenterCharacteristics(architecture, os, vmm, hostlist, timeZone, ComputecostPerSec, costPerMem, costPerStorage, costPerBW);
LinkedList<Storage> SANstroage = new LinkedList<Storage>();
Datacenter dc=null;
try
{
dc = new Datacenter("Datacenter1", dcCharacteristics, new VmAllocationPolicySimple(hostlist), SANstroage, 1);
}
catch(Exception e)
{
e.printStackTrace();
}
return dc;
}
private static RamProvisioner RamProvisionerSimple(int ram)
{
// TODO Auto-generated method stub
return null;
}
}
希望您能帮助我解决此问题。
答案 0 :(得分:1)
方法private static RamProvisioner RamProvisionerSimple(int ram)
返回null,并且在初始化主机时使用了多次