/** * Creates instances of CloudSim's PowerDatacenter class from a list of datacenter registries. * * @param dcrList a list of datacenter registries. * @return a map containing names of datacenters as keys and PowerDatacenter instances as values. * @since 1.0 */ static HashMap<String, PowerDatacenter> createDatacenters() { List<DatacenterRegistry> dcrList = DatacenterRegistryBusiness.getListOfDatacenters(); HashMap<String, PowerDatacenter> map = new HashMap<String, PowerDatacenter>(); for (DatacenterRegistry dcr : dcrList) { List<PowerHost> hostList = createHosts(dcr.getHostList()); if (hostList == null) { return null; } DatacenterCharacteristics chars = new DatacenterCharacteristics( dcr.getArchitecture(), dcr.getOs(), dcr.getVmm(), hostList, dcr.getTimeZone(), dcr.getCostPerSec(), dcr.getCostPerMem(), dcr.getCostPerStorage(), dcr.getCostPerBw()); LinkedList<Storage> storageList = createStorageList(dcr.getSanList()); try { Optional<VmAllocationPolicy> allocationPolicy = VM_ALLOCATION_POLICY.getExtensionInstanceByName( dcr.getAllocationPolicyAlias(), hostList, dcr); if (!allocationPolicy.isPresent()) { Dialog.showErrorMessage( null, format( "Error on loading the allocation policy [%s]", dcr.getAllocationPolicyAlias())); return null; } PowerDatacenter newDC = new PowerDatacenter( dcr.getName(), chars, allocationPolicy.get(), storageList, dcr.getSchedulingInterval(), dcr.getMonitoringInterval()); newDC.setDisableMigrations(!dcr.isVmMigration()); map.put(dcr.getName(), newDC); } catch (Exception ex) { LOG.error("Error on creating data centers. Error message: [{}]", ex.getMessage(), ex); } } return map; }
/** * Sets up all the network links to be simulated, * * @param datacenters the datacenters being simulated. * @param brokers the brokers being simulated. * @since 1.0 */ static void setUpNetworkLinks( HashMap<String, PowerDatacenter> datacenters, HashMap<String, DatacenterBroker> brokers) { NetworkMapEntryDAO neDAO = new NetworkMapEntryDAO(); /* * Establish all links whose source is a datacenter */ DatacenterRegistryDAO drDAO = new DatacenterRegistryDAO(); String[] datacenterNames = drDAO.getAllDatacentersNames(); for (String source : datacenterNames) { PowerDatacenter src = datacenters.get(source); List<NetworkMapEntry> destinationList = neDAO.getListOfDestinations(source); for (NetworkMapEntry entry : destinationList) { String destinationName = entry.getDestination(); if (drDAO.getDatacenterRegistry(destinationName) != null) { // destination is a datacenter PowerDatacenter dest = datacenters.get(destinationName); NetworkTopology.addLink( src.getId(), dest.getId(), entry.getBandwidth(), entry.getLatency()); } else { // destination is a customer DatacenterBroker dest = brokers.get(destinationName); NetworkTopology.addLink( src.getId(), dest.getId(), entry.getBandwidth(), entry.getLatency()); } } } /* * Establish all links whose source is a customer */ CustomerRegistryDAO crDAO = new CustomerRegistryDAO(); String[] customerNames = crDAO.getCustomersNames(); for (String source : customerNames) { DatacenterBroker src = brokers.get(source); List<NetworkMapEntry> destinationList = neDAO.getListOfDestinations(source); for (NetworkMapEntry entry : destinationList) { String destinationName = entry.getDestination(); if (drDAO.getDatacenterRegistry(destinationName) != null) { // destination is a datacenter PowerDatacenter dest = datacenters.get(destinationName); NetworkTopology.addLink( src.getId(), dest.getId(), entry.getBandwidth(), entry.getLatency()); } else { // destination is a customer DatacenterBroker dest = brokers.get(destinationName); NetworkTopology.addLink( src.getId(), dest.getId(), entry.getBandwidth(), entry.getLatency()); } } } }