/**
   * 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 main() to run this example This example has only one datacenter and one storage */
  protected static ComplexDatacenter createDatacenter(String name) {

    // Here are the steps needed to create a PowerDatacenter:
    // 1. We need to create a list to store one or more
    //    Machines
    List<Host> hostList = new ArrayList<>();

    // 2. A Machine contains one or more PEs or CPUs/Cores. Therefore, should
    //    create a list to store these PEs before creating
    //    a Machine.
    for (int i = 1; i <= 20; i++) {
      List<Pe> peList1 = new ArrayList<>();
      int mips = 32000;
      // 3. Create PEs and add these into the list.
      // for a quad-core machine, a list of 4 PEs is required:
      for (int j = 0; j < 16; j++) {
        peList1.add(new Pe(j, new PeProvisionerSimple(mips)));
      }

      int hostId = 0;
      int ram = 64000; // host memory (MB)
      long storage = 1000000; // host storage
      int bw = 10000;
      hostList.add(
          new Host(
              hostId,
              new RamProvisionerSimple(ram),
              new BwProvisionerSimple(bw),
              storage,
              peList1,
              new VmSchedulerTimeShared(peList1))); // This is our first machine
      // hostId++;
    }

    // 4. Create a DatacenterCharacteristics object that stores the
    //    properties of a data center: architecture, OS, list of
    //    Machines, allocation policy: time- or space-shared, time zone
    //    and its price (G$/Pe time unit).
    String arch = "x86"; // system architecture
    String os = "Linux"; // operating system
    String vmm = "Xen";
    double time_zone = 10.0; // time zone this resource located
    double cost = 3.0; // the cost of using processing in this resource
    double costPerMem = 0.05; // the cost of using memory in this resource
    double costPerStorage = 0.1; // the cost of using storage in this resource
    double costPerBw = 0.1; // the cost of using bw in this resource
    LinkedList<Storage> storageList = new LinkedList<>(); // we are not adding SAN devices by now
    ComplexDatacenter datacenter = null;

    DatacenterCharacteristics characteristics =
        new DatacenterCharacteristics(
            arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);

    // 5. Finally, we need to create a storage object.
    /** The bandwidth within a data center in MB/s. */
    int maxTransferRate = 15; // the number comes from the futuregrid site, you can specify your bw

    try {
      // Here we set the bandwidth to be 15MB/s
      HarddriveStorage s1 = new HarddriveStorage(name, 1e12);
      s1.setMaxTransferRate(maxTransferRate);
      storageList.add(s1);
      datacenter =
          new ComplexDatacenter(
              name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return datacenter;
  }