/** * Creates instances of CloudSim's Cloudlet class from a customer's utilization profile. * * @param ugr the utilization profile. * @param brokerId the id of the broker that owns the cloudlets. * @param numOfVms the number of virtual machines. * @return a list of Cloudlet instances. * @since 1.0 */ static List<Cloudlet> createCloudlets(UtilizationProfile ugr, int brokerId, long numOfVms) throws IOException, ServiceDeniedException { List<Cloudlet> list = new ArrayList<Cloudlet>(); for (int i = 0; i < numOfVms; i++) { Optional<UtilizationModel> cpu = UTILIZATION_MODEL.getExtensionInstanceByName(ugr.getUtilizationModelCpuAlias()); if (!cpu.isPresent()) { Dialog.showErrorMessage( null, format( "Error on loading the CPU utilization model [%s]", ugr.getUtilizationModelCpuAlias())); return null; } Optional<UtilizationModel> ram = UTILIZATION_MODEL.getExtensionInstanceByName(ugr.getUtilizationModelRamAlias()); if (!ram.isPresent()) { Dialog.showErrorMessage( null, format( "Error on loading the RAM utilization model [%s]", ugr.getUtilizationModelRamAlias())); return null; } Optional<UtilizationModel> bw = UTILIZATION_MODEL.getExtensionInstanceByName(ugr.getUtilizationModelBwAlias()); if (!bw.isPresent()) { Dialog.showErrorMessage( null, format( "Error on loading the bandwidth utilization model [%s]", ugr.getUtilizationModelBwAlias())); return null; } Cloudlet cloudlet = new Cloudlet( i, (long) ((long) ugr.getLength() * RandomNumberGenerator.getRandomNumbers(1).get(0)), ugr.getCloudletsPesNumber(), ugr.getFileSize(), ugr.getOutputSize(), cpu.get(), ram.get(), bw.get()); cloudlet.setUserId(brokerId); cloudlet.setVmId(i); list.add(cloudlet); } return list; }
/** * Creates instances of CloudSim's DatacenterBroker class from a list of customer registers. * * @param customerList a list of customer instances. * @return a map containing names of customers as keys and DatacenterBroker instances as values. * @since 1.0 */ static HashMap<String, DatacenterBroker> createBrokers() { List<CustomerRegistry> customerList = CustomerRegistryBusiness.getListOfCustomers(); HashMap<String, DatacenterBroker> map = new HashMap<String, DatacenterBroker>(); try { for (CustomerRegistry cr : customerList) { UtilizationProfile up = cr.getUtilizationProfile(); String name = cr.getName(); Optional<DatacenterBroker> broker = DATACENTER_BROKER.getExtensionInstanceByName(up.getBrokerPolicyAlias(), name); if (!broker.isPresent()) { Dialog.showErrorMessage( null, format("Error on loading datacenter broker [%s]", up.getBrokerPolicyAlias())); return null; } int brokerId = broker.get().getId(); List<Vm> vmList = createVms(cr.getVmList(), brokerId); if (vmList == null) { return null; } broker.get().submitVmList(vmList); List<Cloudlet> cloudletList = createCloudlets(up, brokerId, new CustomerRegistryDAO().getNumOfVms(cr.getId())); if (cloudletList == null) { return null; } broker.get().submitCloudletList(cloudletList); map.put(cr.getName(), broker.get()); } } catch (IOException | ServiceDeniedException ex) { LOG.error(ex.getMessage(), ex); } return map; }