コード例 #1
0
 protected void updateTimeZone(final String selectedTimeZone) {
   if (StringHelper.isNullOrEmpty(selectedTimeZone)) {
     updateDefaultTimeZone();
   } else {
     doUpdateTimeZone(selectedTimeZone);
   }
 }
コード例 #2
0
ファイル: StorageModel.java プロジェクト: nirs/ovirt-engine
  private void host_SelectedItemChanged() {
    VDS host = getHost().getSelectedItem();
    if (getCurrentStorageItem() != null) {
      // When changing host clear items for san storage model.
      if (getCurrentStorageItem() instanceof SanStorageModelBase) {
        SanStorageModelBase sanStorageModel = (SanStorageModelBase) getCurrentStorageItem();
        if (getStorage() == null) {
          sanStorageModel.setItems(null);
        }
      }

      if (host != null) {
        getCurrentStorageItem().getUpdateCommand().execute();

        String prefix = host.isOvirtNode() ? localFSPath : ""; // $NON-NLS-1$
        if (!StringHelper.isNullOrEmpty(prefix)) {
          for (Object item : getStorageModels()) {
            if (item instanceof LocalStorageModel) {
              LocalStorageModel model = (LocalStorageModel) item;
              model.getPath().setEntity(prefix);
              model.getPath().setIsChangeable(false);
            }
          }
        }
      }
    }
  }
コード例 #3
0
 private String AvailableName(java.util.ArrayList<String> list) {
   String retVal = getCommonName();
   java.util.ArrayList<Integer> notAvialbleNumberList = new java.util.ArrayList<Integer>();
   String temp;
   for (String str : list) {
     temp = str.replace(getCommonName(), "");
     if (StringHelper.isNullOrEmpty(temp)) {
       temp = "0";
     }
     int tempInt = 0;
     RefObject<Integer> tempRef_tempInt = new RefObject<Integer>(tempInt);
     boolean tempVar = IntegerCompat.TryParse(temp, tempRef_tempInt);
     tempInt = tempRef_tempInt.argvalue;
     if (tempVar) {
       notAvialbleNumberList.add(tempInt);
     }
   }
   Collections.sort(notAvialbleNumberList);
   int i = 0;
   for (i = 0; i < notAvialbleNumberList.size(); i++) {
     if (notAvialbleNumberList.get(i) == i) {
       continue;
     }
     break;
   }
   if (i > 0) {
     retVal = getCommonName() + (new Integer(i)).toString();
   }
   return retVal;
 }
コード例 #4
0
ファイル: Linq.java プロジェクト: derekhiggins/ovirt-engine
 public static NetworkInterface FindInterfaceNetworkNameNotEmpty(
     ArrayList<NetworkInterface> items) {
   for (NetworkInterface i : items) {
     if (!StringHelper.isNullOrEmpty(i.getNetworkName())) {
       return i;
     }
   }
   return null;
 }
コード例 #5
0
ファイル: Linq.java プロジェクト: derekhiggins/ovirt-engine
 public static ArrayList<VdsNetworkInterface> FindAllInterfaceBondNameIsEmpty(
     ArrayList<VdsNetworkInterface> items) {
   ArrayList<VdsNetworkInterface> ret = new ArrayList<VdsNetworkInterface>();
   for (VdsNetworkInterface i : items) {
     if (StringHelper.isNullOrEmpty(i.getBondName())) {
       ret.add(i);
     }
   }
   return ret;
 }
コード例 #6
0
ファイル: Linq.java プロジェクト: derekhiggins/ovirt-engine
 public static ArrayList<NetworkInterface> FindAllInterfaceNetworkNameNotEmpty(
     ArrayList<NetworkInterface> items) {
   ArrayList<NetworkInterface> ret = new ArrayList<NetworkInterface>();
   for (NetworkInterface i : items) {
     if (!StringHelper.isNullOrEmpty(i.getNetworkName())) {
       ret.add(i);
     }
   }
   return ret;
 }
コード例 #7
0
 /**
  * Handle a BackendFailureException or an exception thrown from a backend query/action and
  * re-throw as a WebApplicationException.
  *
  * <p>If the exception indicates that the referenced backend entity does not exist
  * and @notFoundAs404 is true, then throw a WebApplicationException which wraps a 404 HTTP
  * response.
  *
  * @param clz dummy explicit type parameter for use when type inference is not possible
  *     (irrelevant in any case as a value is never returned, rather an exception is always thrown)
  * @param e the exception to handle
  * @param notFoundAs404 whether to return a 404 if appropriate
  * @returns the result of the operation
  */
 protected <T> T handleError(Class<T> clz, Exception e, boolean notFoundAs404) {
   if ((e instanceof EntityNotFoundException) && (notFoundAs404)) {
     throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
   } else if ((e instanceof BackendFailureException)
       && (!StringHelper.isNullOrEmpty(e.getMessage()))) {
     LOG.errorFormat(localize(Messages.BACKEND_FAILED_TEMPLATE), e.getMessage(), null);
     throw new WebFaultException(null, e.getMessage(), Response.Status.BAD_REQUEST);
   } else {
     LOG.errorFormat(localize(Messages.BACKEND_FAILED_TEMPLATE), detail(e), e);
     throw new WebFaultException(e, detail(e), Response.Status.INTERNAL_SERVER_ERROR);
   }
 }
コード例 #8
0
 /**
  * Converts properties from string to map. Method assumes, that properties are syntactically valid
  *
  * @param properties specified properties
  * @return map containing all properties ({@code LinkedHashMap} is used to ensure properties order
  *     is constant)
  */
 public static Map<String, String> convertProperties(String properties) {
   Map<String, String> map = new LinkedHashMap<>();
   if (!StringHelper.isNullOrEmpty(properties)) {
     String[] keyValuePairs = properties.split(PROPERTIES_DELIMETER);
     for (String keyValuePairStr : keyValuePairs) {
       String[] pairParts = keyValuePairStr.split(KEY_VALUE_DELIMETER, 2);
       String key = pairParts[0];
       // property value may be null
       String value = pairParts[1];
       map.put(key, value);
     }
   }
   return map;
 }
コード例 #9
0
  /**
   * Generate a string containing the given VM's configuration.
   *
   * @param vm The VM to generate configuration from.
   * @return A String containing the VM configuration.
   */
  protected String generateVmConfiguration(VM vm) {
    if (vm.getInterfaces() == null || vm.getInterfaces().isEmpty()) {
      vm.setInterfaces(getVmNetworkInterfaceDao().getAllForVm(vm.getId()));
    }

    if (StringHelper.isNullOrEmpty(vm.getvmt_name())) {
      VmTemplate t = getVmTemplateDao().get(vm.getvmt_guid());
      vm.setvmt_name(t.getname());
    }

    RefObject<String> tempRefObject = new RefObject<String>("");
    new OvfManager()
        .ExportVm(
            tempRefObject, vm, new ArrayList<DiskImage>(getDiskImageDao().getAllForVm(vm.getId())));
    return tempRefObject.argvalue;
  }
コード例 #10
0
 protected void updateSelectedCdImage(VmBase vmBase) {
   getModel().getCdImage().setSelectedItem(vmBase.getIsoPath());
   boolean hasCd = !StringHelper.isNullOrEmpty(vmBase.getIsoPath());
   getModel().getCdImage().setIsChangable(hasCd);
   getModel().getCdAttached().setEntity(hasCd);
 }
コード例 #11
0
  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));
  }