@Override
 public storage_domains getStorageDomain() {
   storage_domains sd = new storage_domains();
   sd.setstatus(StorageDomainStatus.Active);
   sd.setavailable_disk_size(10);
   return sd;
 }
Exemplo n.º 2
0
  public static boolean IsActiveStorageDomain(storage_domains storageDomain) {
    boolean isActive =
        storageDomain.getstatus() != null
            && storageDomain.getstatus() == StorageDomainStatus.Active;

    return isActive;
  }
 @Override
 public StorageDomainDAO getStorageDomainDAO() {
   final storage_domains sd = new storage_domains();
   sd.setstorage_domain_type(StorageDomainType.ImportExport);
   final StorageDomainDAO d = mock(StorageDomainDAO.class);
   when(d.getForStoragePool(any(Guid.class), any(Guid.class))).thenReturn(sd);
   return d;
 }
Exemplo n.º 4
0
 /**
  * Check if storage_domains item with specified Guid exist in List
  *
  * @param items
  * @param id
  * @return
  */
 public static boolean IsSDItemExistInList(ArrayList<storage_domains> items, Guid id) {
   for (storage_domains b : items) {
     if (b.getId().equals(id)) {
       return true;
     }
   }
   return false;
 }
 private static boolean isBelowSpaceThreshold(final storage_domains domain) {
   Integer availableDiskSize =
       domain.getavailable_disk_size() == null ? 0 : domain.getavailable_disk_size();
   Integer usedDiskSize = domain.getused_disk_size() == null ? 0 : domain.getused_disk_size();
   double totalSize = availableDiskSize + usedDiskSize;
   return totalSize != 0
       && (availableDiskSize / totalSize) * (double) 100 > getLowDiskPercentThreshold();
 }
Exemplo n.º 6
0
 public static storage_domains getStorageById(
     Guid storageId, ArrayList<storage_domains> storageDomains) {
   for (storage_domains storage : storageDomains) {
     if (storage.getId().equals(storageId)) {
       return storage;
     }
   }
   return null;
 }
Exemplo n.º 7
0
  public static boolean IsDataActiveStorageDomain(storage_domains storageDomain) {
    boolean isData =
        storageDomain.getstorage_domain_type() == StorageDomainType.Data
            || storageDomain.getstorage_domain_type() == StorageDomainType.Master;

    boolean isActive = IsActiveStorageDomain(storageDomain);

    return isData && isActive;
  }
Exemplo n.º 8
0
 public static ArrayList<storage_domains> FindAllStorageDomainsBySharedStatus(
     ArrayList<storage_domains> items, StorageDomainSharedStatus status) {
   ArrayList<storage_domains> ret = new ArrayList<storage_domains>();
   for (storage_domains i : items) {
     if (i.getstorage_domain_shared_status() == status) {
       ret.add(i);
     }
   }
   return ret;
 }
Exemplo n.º 9
0
 /**
  * Checks if Any StorageDomain Is Matser And Active
  *
  * @param sdl
  * @return
  */
 public static boolean IsAnyStorageDomainIsMatserAndActive(List<storage_domains> sdl) {
   for (storage_domains a : sdl) {
     if (a.getstorage_domain_type() == StorageDomainType.Master
         && a.getstatus() != null
         && a.getstatus() == StorageDomainStatus.Active) {
       return true;
     }
   }
   return false;
 }
 private static boolean hasSpacePct(
     final storage_domains storageDomain, final long requestedSize) {
   Integer availableDiskSize =
       storageDomain.getavailable_disk_size() == null ? 0 : storageDomain.getavailable_disk_size();
   Integer usedDiskSize =
       storageDomain.getused_disk_size() == null ? 0 : storageDomain.getused_disk_size();
   double totalSize = availableDiskSize + usedDiskSize;
   return totalSize != 0
       && ((availableDiskSize - requestedSize) / totalSize) * 100 > getLowDiskPercentThreshold();
 }
Exemplo n.º 11
0
  private void mockStorageDomains() {
    // Set list of storages domain to have sum of available disk size enough for the quota
    // limitations.
    List<storage_domains> storageDomains = new ArrayList<storage_domains>();
    firstStorageDomains.setused_disk_size(100);
    firstStorageDomains.setavailable_disk_size(50);
    secondStorageDomains.setused_disk_size(100);
    secondStorageDomains.setavailable_disk_size(50);
    storageDomains.add(firstStorageDomains);
    storageDomains.add(secondStorageDomains);

    when(storageDomainDAO.getAllForStoragePool(storagePoolUUID)).thenReturn(storageDomains);
  }
 private static boolean isBelowPctThreshold(final storage_domains domain) {
   storage_domain_dynamic dynamic = domain.getStorageDynamicData();
   return (dynamic != null
       && dynamic.getfreeDiskInGB()
           > Config.<Integer>GetValue(ConfigValues.FreeSpaceCriticalLowInGB)
       && dynamic.getfreeDiskPercent() > Config.<Integer>GetValue(ConfigValues.FreeSpaceLow));
 }
Exemplo n.º 13
0
  @Test
  public void testValidSpecificStorageLimitation() throws Exception {
    List<String> messages = new ArrayList<String>();
    firstStorageDomains.setused_disk_size(0);
    firstStorageDomains.setavailable_disk_size(100);
    Quota quota = mockGeneralStorageQuota();
    quota.setIsDefaultQuota(false);
    when(storageDomainDAO.getForStoragePool(firstStorageDomainUUID, storagePoolUUID))
        .thenReturn(firstStorageDomains);

    boolean isQuotaValid = quotaHelper.checkQuotaValidationForAdd(quota, messages);
    assertTrue(isQuotaValid);

    isQuotaValid = quotaHelper.checkQuotaValidationForEdit(quota, messages);
    assertTrue(isQuotaValid);
  }
  @Override
  protected boolean canDoAction() {
    boolean returnValue = super.canDoAction() && CheckStoragePool();
    getReturnValue()
        .getCanDoActionMessages()
        .remove(VdcBllMessages.VAR__ACTION__RECONSTRUCT_MASTER.toString());

    addCanDoActionMessage(VdcBllMessages.VAR__ACTION__RECOVER_POOL);
    addCanDoActionMessage(VdcBllMessages.VAR__TYPE__STORAGE__DOMAIN);
    if (returnValue) {
      if (getStoragePool().getstatus() == StoragePoolStatus.Uninitialized) {
        addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_STORAGE_POOL_STATUS_ILLEGAL);
        return false;
      } else if (getStorageDomain() != null
          && getStorageDomain().getstatus() != null
          && getStorageDomain().getstatus() == StorageDomainStatus.Active) {
        getReturnValue()
            .getCanDoActionMessages()
            .add(VdcBllMessages.ACTION_TYPE_FAILED_STORAGE_DOMAIN_STATUS_ILLEGAL2.toString());
        returnValue = false;
      } else if (electNewMaster() != null) {
        getReturnValue()
            .getCanDoActionMessages()
            .add(
                VdcBllMessages.STORAGE_POOL_REINITIALIZE_WITH_MORE_THAN_ONE_DATA_DOMAIN.toString());
        returnValue = false;
      } else {
        storage_domains domain =
            DbFacade.getInstance().getStorageDomainDAO().get(_newMasterStorageDomainId);
        if (domain.getstorage_domain_shared_status() != StorageDomainSharedStatus.Unattached) {
          addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_STORAGE_DOMAIN_STATUS_ILLEGAL);
          returnValue = false;
        } else if (domain.getstorage_type() != getStoragePool().getstorage_pool_type()) {
          addCanDoActionMessage(
              VdcBllMessages.ERROR_CANNOT_RECOVERY_STORAGE_POOL_STORAGE_TYPE_MISSMATCH);
          returnValue = false;
        }
      }
    }
    return returnValue;
  }
 protected IStorageHelper setUpStorageHelper(
     storage_domains dom, StorageType storageType, boolean connect, boolean failure) {
   StorageHelperDirector director = mock(StorageHelperDirector.class);
   when(StorageHelperDirector.getInstance()).thenReturn(director);
   IStorageHelper helper = mock(IStorageHelper.class);
   if (connect) {
     when(helper.ConnectStorageToDomainByVdsId(dom, VDS_ID)).thenReturn(true);
     when(helper.DisconnectStorageFromDomainByVdsId(dom, VDS_ID)).thenReturn(true);
   }
   if (!failure) {
     when(helper.StorageDomainRemoved(dom.getStorageStaticData())).thenReturn(true);
   }
   when(director.getItem(storageType)).thenReturn(helper);
   return helper;
 }
 protected storage_domains getStorageDomain(
     Guid id, Guid poolId, StorageDomainType type, StorageType storageType) {
   storage_domains dom = new storage_domains();
   dom.setid(id);
   dom.setstorage_pool_id(poolId);
   dom.setstorage_domain_type(type);
   dom.setstorage_type(storageType);
   dom.setstorage_domain_shared_status(StorageDomainSharedStatus.Unattached);
   return dom;
 }
 /**
  * The new master must be a data domain which is in Active status and not reported by any vdsm as
  * problematic. In case that all domains reported as problematic a first Active data domain will
  * be returned
  *
  * @return an elected master domain or null
  */
 protected storage_domains electNewMaster(boolean duringReconstruct) {
   storage_domains newMaster = null;
   if (getStoragePool() != null) {
     List<storage_domains> storageDomains =
         getStorageDomainDAO().getAllForStoragePool(getStoragePool().getId());
     Collections.sort(storageDomains, new LastTimeUsedAsMasterComp());
     if (storageDomains.size() > 0) {
       storage_domains storageDomain = getStorageDomain();
       for (storage_domains dbStorageDomain : storageDomains) {
         if ((storageDomain == null
                 || (duringReconstruct || !dbStorageDomain.getId().equals(storageDomain.getId())))
             && (dbStorageDomain.getstatus() == StorageDomainStatus.Active
                 || dbStorageDomain.getstatus() == StorageDomainStatus.Unknown)
             && dbStorageDomain.getstorage_domain_type() == StorageDomainType.Data) {
           newMaster = dbStorageDomain;
           break;
         }
       }
     }
   }
   return newMaster;
 }
 @Override
 public int compare(storage_domains o1, storage_domains o2) {
   return Long.compare(o1.getLastTimeUsedAsMaster(), o2.getLastTimeUsedAsMaster());
 }
 protected IStorageHelper getStorageHelper(storage_domains storageDomain) {
   return StorageHelperDirector.getInstance().getItem(storageDomain.getstorage_type());
 }
  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));
  }
 private static boolean hasSpace(final storage_domains storageDomain, final long requestedSize) {
   return storageDomain.getavailable_disk_size() != null
       && storageDomain.getavailable_disk_size() - requestedSize >= getLowDiskSpaceThreshold();
 }
Exemplo n.º 22
0
 @Override
 public boolean Match(storage_domains source) {
   return id.equals(source.getId());
 }
Exemplo n.º 23
0
 @Override
 public boolean Match(storage_domains source) {
   return name.equals(source.getstorage_name());
 }
Exemplo n.º 24
0
 @Override
 public int compare(storage_domains x, storage_domains y) {
   return x.getstorage_name().compareTo(y.getstorage_name());
 }
Exemplo n.º 25
0
 private void mockSecondStorageDomain() {
   secondStorageDomains = new storage_domains();
   secondStorageDomains.setstorage_name(secondStorageDomainName);
   secondStorageDomains.setId(secondStorageDomainUUID);
 }
Exemplo n.º 26
0
 private void mockFirstStorageDomain() {
   firstStorageDomains = new storage_domains();
   firstStorageDomains.setstorage_name(firstStorageDomainName);
   firstStorageDomains.setId(firstStorageDomainUUID);
 }
 private void setStorageDomainStatus(StorageDomainStatus status) {
   storage_domains domain = new storage_domains();
   domain.setstatus(status);
   when(cmd.getStorageDomain()).thenReturn(domain);
 }