Пример #1
0
  private java.util.List<SanTargetModel> ToTargetModelList(java.util.List<LunModel> source) {
    ObservableCollection<SanTargetModel> list = new ObservableCollection<SanTargetModel>();

    for (LunModel lun : source) {
      for (SanTargetModel target : lun.getTargets()) {
        SanTargetModel item = Linq.FirstOrDefault(list, new Linq.TargetPredicate(target));
        if (item == null) {
          item = target;
          list.add(item);
        }

        if (Linq.FirstOrDefault(item.getLuns(), new Linq.LunPredicate(lun)) == null) {
          item.getLuns().add(lun);
        }
      }
    }

    // Merge with last discovered targets list.
    for (SanTargetModel target : lastDiscoveredTargets) {
      if (Linq.FirstOrDefault(list, new Linq.TargetPredicate(target)) == null) {
        list.add(target);
      }
    }

    return list;
  }
Пример #2
0
  public java.util.ArrayList<LunModel> getAddedLuns() {
    java.util.ArrayList<LunModel> luns = new java.util.ArrayList<LunModel>();
    if (getIsGrouppedByTarget()) {
      java.util.List<SanTargetModel> items = (java.util.List<SanTargetModel>) getItems();
      for (SanTargetModel item : items) {
        for (LunModel lun : item.getLuns()) {
          if (lun.getIsSelected()
              && !lun.getIsIncluded()
              && Linq.FirstOrDefault(luns, new Linq.LunPredicate(lun)) == null) {
            luns.add(lun);
          }
        }
      }
    } else {
      java.util.List<LunModel> items = (java.util.List<LunModel>) getItems();
      for (LunModel lun : items) {
        if (lun.getIsSelected()
            && !lun.getIsIncluded()
            && Linq.FirstOrDefault(luns, new Linq.LunPredicate(lun)) == null) {
          luns.add(lun);
        }
      }
    }

    return luns;
  }
Пример #3
0
  /**
   * Organizes items according to the current groupping flag. When new items provided takes them in
   * account and add to the Items collection.
   */
  private void InitializeItems(
      java.util.List<LunModel> newLuns, java.util.List<SanTargetModel> newTargets) {
    if (getIsGrouppedByTarget()) {
      if (getItems() == null) {
        setItems(new ObservableCollection<SanTargetModel>());
      } else {
        // Convert to list of another type as neccessary.
        if (TypeUtil.<LunModel>IsListOf(getItems())) {
          setItems(ToTargetModelList((java.util.List<LunModel>) getItems()));
        }
      }

      java.util.List<SanTargetModel> items = (java.util.List<SanTargetModel>) getItems();

      // Add new targets.
      if (newTargets != null) {
        for (SanTargetModel newItem : newTargets) {
          if (Linq.FirstOrDefault(items, new Linq.TargetPredicate(newItem)) == null) {
            items.add(newItem);
          }
        }
      }

      // Merge luns into targets.
      if (newLuns != null) {
        MergeLunsToTargets(newLuns, items);
      }

      UpdateLoginAllAvailability();
    } else {
      if (getItems() == null) {
        setItems(new ObservableCollection<LunModel>());
      } else {
        // Convert to list of another type as neccessary.
        if (TypeUtil.<SanTargetModel>IsListOf(getItems())) {
          setItems(ToLunModelList((java.util.List<SanTargetModel>) getItems()));
        }
      }

      java.util.List<LunModel> items = (java.util.List<LunModel>) getItems();

      // Add new LUNs.
      if (newLuns != null) {
        for (LunModel newItem : newLuns) {
          if (Linq.FirstOrDefault(items, new Linq.LunPredicate(newItem)) == null) {
            items.add(newItem);
          }
        }
      }
    }
  }
Пример #4
0
  private void MergeLunsToTargets(
      java.util.List<LunModel> newLuns, java.util.List<SanTargetModel> targets) {
    for (LunModel lun : newLuns) {
      for (SanTargetModel target : lun.getTargets()) {
        SanTargetModel item = Linq.FirstOrDefault(targets, new Linq.TargetPredicate(target));
        if (item == null) {
          item = target;
          targets.add(item);
        }

        if (Linq.FirstOrDefault(item.getLuns(), new Linq.LunPredicate(lun)) == null) {
          item.getLuns().add(lun);
        }
      }
    }
  }
  public void AddHost() {
    HostModel model = new HostModel();
    setWindow(model);
    model.setTitle("New Host");
    model.setHashName("new_host");
    model.getPort().setEntity(54321);
    model.getOverrideIpTables().setEntity(true);

    model.getCluster().setSelectedItem(getEntity());
    model.getCluster().setIsChangable(false);

    java.util.ArrayList<storage_pool> dataCenters = DataProvider.GetDataCenterList();
    model.getDataCenter().setItems(dataCenters);
    if (getEntity().getstorage_pool_id() != null) {
      model
          .getDataCenter()
          .setSelectedItem(
              Linq.FirstOrDefault(
                  dataCenters,
                  new Linq.DataCenterPredicate((Guid) getEntity().getstorage_pool_id())));
    }
    model.getDataCenter().setIsChangable(false);

    UICommand tempVar = new UICommand("OnConfirmPMHost", this);
    tempVar.setTitle("OK");
    tempVar.setIsDefault(true);
    model.getCommands().add(tempVar);
    UICommand tempVar2 = new UICommand("Cancel", this);
    tempVar2.setTitle("Cancel");
    tempVar2.setIsCancel(true);
    model.getCommands().add(tempVar2);
  }
Пример #6
0
  private java.util.List<LunModel> ToLunModelList(java.util.List<SanTargetModel> source) {
    ObservableCollection<LunModel> list = new ObservableCollection<LunModel>();

    for (SanTargetModel target : source) {
      for (LunModel lun : target.getLuns()) {
        LunModel item = Linq.FirstOrDefault(list, new Linq.LunPredicate(lun));
        if (item == null) {
          item = lun;
          list.add(item);
        }

        if (Linq.FirstOrDefault(item.getTargets(), new Linq.TargetPredicate(target)) == null) {
          item.getTargets().add(target);
        }
      }
    }

    return list;
  }
Пример #7
0
  private void ClearItems() {
    if (getItems() == null) {
      return;
    }

    if (getIsGrouppedByTarget()) {
      java.util.List<SanTargetModel> items = (java.util.List<SanTargetModel>) getItems();

      for (SanTargetModel target : Linq.ToList(items)) {
        boolean found = false;

        // Ensure remove targets that are not in last dicovered targets list.
        if (Linq.FirstOrDefault(lastDiscoveredTargets, new Linq.TargetPredicate(target)) != null) {
          found = true;
        } else {
          // Ensure remove targets that are not contain already included LUNs.
          for (LunModel lun : target.getLuns()) {
            LunModel foundItem = Linq.FirstOrDefault(includedLUNs, new Linq.LunPredicate(lun));
            if (foundItem == null) {
              found = true;
              break;
            }
          }
        }

        if (!found) {
          items.remove(target);
        }
      }
    } else {
      java.util.List<LunModel> items = (java.util.List<LunModel>) getItems();

      // Ensure remove targets that are not contain already included LUNs.
      for (LunModel lun : Linq.ToList(items)) {
        LunModel foundItem = Linq.FirstOrDefault(includedLUNs, new Linq.LunPredicate(lun));
        if (foundItem == null) {
          items.remove(lun);
        }
      }
    }
  }
  public void SelectHost() {
    java.util.ArrayList<VDSGroup> clusters = new java.util.ArrayList<VDSGroup>();
    clusters.add(getEntity());

    MoveHost model = new MoveHost();
    model.setTitle("Select Host");
    model.setHashName("select_host");
    setWindow(model);
    model.getCluster().setItems(clusters);
    model.getCluster().setSelectedItem(Linq.FirstOrDefault(clusters));
    model.getCluster().setIsAvailable(false);

    UICommand tempVar = new UICommand("OnSelectHost", this);
    tempVar.setTitle("OK");
    tempVar.setIsDefault(true);
    model.getCommands().add(tempVar);
    UICommand tempVar2 = new UICommand("Cancel", this);
    tempVar2.setTitle("Cancel");
    tempVar2.setIsCancel(true);
    model.getCommands().add(tempVar2);
  }
  public void SetDefaultNames(VDS host, RefObject<String> message) {
    message.argvalue = null;
    setCommonName(StringFormat.format("%1$s-Local", host.getvds_name().replace('.', '-')));
    storage_pool candidate = null;

    // selecet all possible DCs
    VdcQueryReturnValue returnValue =
        Frontend.RunQuery(
            VdcQueryType.Search,
            new SearchParameters(
                StringFormat.format("DataCenter: name=%1$s", getCommonName() + "*"),
                SearchType.StoragePool));

    java.util.ArrayList<storage_pool> dataCenterList = new java.util.ArrayList<storage_pool>();
    java.util.ArrayList<VDSGroup> clusterList = null;
    if (returnValue != null && returnValue.getSucceeded() && returnValue.getReturnValue() != null) {
      dataCenterList =
          Linq.<storage_pool>Cast(
              (java.util.ArrayList<IVdcQueryable>) returnValue.getReturnValue());
    }
    // check if current settings suitable for local setup (in case just SD creation failed -
    // re-using the same setup)
    boolean useCurrentSettings = false;
    if (host.getstorage_pool_id() != null) {
      storage_pool tempCandidate = DataProvider.GetDataCenterById(host.getstorage_pool_id());
      if (IsLocalDataCenterEmpty(tempCandidate)) {
        candidate = tempCandidate;
        useCurrentSettings = true;
      } else {
        if (tempCandidate != null && tempCandidate.getstorage_pool_type() == StorageType.LOCALFS) {
          message.argvalue =
              "Note: Local Storage is already configured for this Host. The Host belongs to "
                  + host.getstorage_pool_name()
                  + " with local Storage Domain. If OK is clicked - this Host will be moved to a new Data Center, and a new Local Storage Domain will be created. Hit Cancel to abort the operation.";
        }
      }
    }
    // check if there is other DC suitable for re-use
    if (candidate == null) {
      for (storage_pool dataCenter : dataCenterList) {
        // need to check if the new DC is without host.
        if (IsLocalDataCenterEmpty(dataCenter)
            && DataProvider.GetLocalStorageHost(dataCenter.getname()) == null) {
          candidate = dataCenter;
          break;
        }
      }
    }
    java.util.ArrayList<String> listNames = new java.util.ArrayList<String>();
    // in case we found a suitable candidte for re-use:
    if (candidate != null) {
      getDataCenter().setDataCenterId(candidate.getId());
      getDataCenter().getName().setEntity(candidate.getname());
      getDataCenter().getDescription().setEntity(candidate.getdescription());
      Version compVersion = candidate.getcompatibility_version();
      getDataCenter().getVersion().setSelectedItem(compVersion);
      getCluster().getVersion().setSelectedItem(compVersion);
      setDontCreateDataCenter(true);
      // if we use current settings there is no need to create cluster.
      if (useCurrentSettings) {
        getCluster().setClusterId(host.getvds_group_id().getValue());
        getCluster().getName().setEntity(host.getvds_group_name());
        VDSGroup cluster = DataProvider.GetClusterById(host.getvds_group_id().getValue());
        if (cluster != null) {
          getCluster().getDescription().setEntity(cluster.getdescription());
          ServerCpu tempVar = new ServerCpu();
          tempVar.setCpuName(cluster.getcpu_name());
          getCluster().getCPU().setSelectedItem(tempVar);
        }
        setDontCreateCluster(true);
        setDontChangeHostCluster(true);
      }
      // use differnt cluster
      else {
        // check the DC cluster list (for re-use)
        clusterList = DataProvider.GetClusterList(candidate.getId());
        // no clusters avilable - pick up new name.
        if (clusterList.isEmpty()) {
          java.util.ArrayList<VDSGroup> listClusters = DataProvider.GetClusterList();
          listNames = new java.util.ArrayList<String>();
          for (VDSGroup cluster : listClusters) {
            listNames.add(cluster.getname());
          }
          getCluster().getName().setEntity(AvailableName(listNames));
        } else {
          // use the DC cluster.
          getCluster().setClusterId(clusterList.get(0).getId());
          getCluster().getName().setEntity(clusterList.get(0).getname());
          getCluster().getDescription().setEntity(clusterList.get(0).getdescription());
          VDSGroup cluster = DataProvider.GetClusterById(getCluster().getClusterId().getValue());
          if (cluster != null) {
            ServerCpu tempVar2 = new ServerCpu();
            tempVar2.setCpuName(cluster.getcpu_name());
            getCluster().getCPU().setSelectedItem(tempVar2);
          }
          setDontCreateCluster(true);
          if (host.getvds_group_id().getValue().equals(getCluster().getClusterId())) {
            setDontChangeHostCluster(true);
          }
        }
      }
    } else {
      // didn't found DC to re-use, so we select new names:
      listNames = new java.util.ArrayList<String>();
      for (storage_pool storagePool : dataCenterList) {
        listNames.add(storagePool.getname());
      }
      getDataCenter().getName().setEntity(AvailableName(listNames));

      // Choose a Data Center version corresponding to the host.
      if (!StringHelper.isNullOrEmpty(host.getsupported_cluster_levels())) {
        // the supported_cluster_levels are sorted.
        String[] array = host.getsupported_cluster_levels().split("[,]", -1);
        Version maxCombindVersion = null;

        for (int i = 0; i < array.length; i++) {
          Version vdsVersion = new Version(array[i]);
          for (Version version :
              (java.util.List<Version>) getDataCenter().getVersion().getItems()) {
            if (version.equals(vdsVersion) && version.compareTo(maxCombindVersion) > 0) {
              maxCombindVersion = version;
            }
          }
        }
        if (maxCombindVersion != null) {
          getDataCenter().getVersion().setSelectedItem(maxCombindVersion);
          getCluster().getVersion().setSelectedItem(maxCombindVersion);
        }
      }

      listNames = new java.util.ArrayList<String>();
      if (clusterList == null) {
        clusterList = DataProvider.GetClusterList();
      }

      for (VDSGroup cluster : clusterList) {
        listNames.add(cluster.getname());
      }
      getCluster().getName().setEntity(AvailableName(listNames));
    }

    // Choose default CPU name to match host.
    if (host.getCpuName() != null && getCluster().getCPU().getSelectedItem() != null) {
      getCluster()
          .getCPU()
          .setSelectedItem(
              Linq.FirstOrDefault(
                  (java.util.List<ServerCpu>) getCluster().getCPU().getItems(),
                  new Linq.ServerCpuPredicate(host.getCpuName().getCpuName())));
    }
    // always choose a avialable storage name.
    java.util.ArrayList<storage_domains> listStorageDomains = DataProvider.GetStorageDomainList();
    listNames = new java.util.ArrayList<String>();
    for (storage_domains storageDomain : listStorageDomains) {
      listNames.add(storageDomain.getstorage_name());
    }
    getFormattedStorageName().setEntity(AvailableName(listNames));
  }