/**
   * 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;
  }
  /**
   * Creates instances of CloudSim's SanStorage class from a list of SAN registers
   *
   * @param sanList a list of SAN registers.
   * @return a list of SanStorage instances.
   * @since 1.0
   */
  static LinkedList<Storage> createStorageList(List<SanStorageRegistry> sanList) {
    LinkedList<Storage> list = new LinkedList<Storage>();

    for (SanStorageRegistry sr : sanList) {
      try {
        list.add(
            new SanStorage(
                sr.getName(), sr.getCapacity(), sr.getBandwidth(), sr.getNetworkLatency()));
      } catch (ParameterException e) {
        LOG.error("Error on crearing the SanStorage; Error message [{}]", e.getMessage(), e);
      }
    }

    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;
  }