protected void updateReadOnlyChangeability() {
    DiskInterface diskInterface = getDiskInterface().getSelectedItem();

    if (diskInterface == DiskInterface.IDE) {
      getIsReadOnly()
          .setChangeProhibitionReason(constants.cannotEnableIdeInterfaceForReadOnlyDisk());
      getIsReadOnly().setIsChangeable(false);
      getIsReadOnly().setEntity(false);
      return;
    }

    boolean isDirectLUN = getDiskStorageType().getEntity() == DiskStorageType.LUN;
    boolean isScsiPassthrough = getIsScsiPassthrough().getEntity();
    if (diskInterface == DiskInterface.VirtIO_SCSI && isDirectLUN && isScsiPassthrough) {
      getIsReadOnly()
          .setChangeProhibitionReason(constants.cannotEnableReadonlyWhenScsiPassthroughEnabled());
      getIsReadOnly().setIsChangeable(false);
      getIsReadOnly().setEntity(false);
      return;
    }

    if (isVmAttachedToPool() && !getIsNew()) {
      getIsReadOnly().setIsChangeable(false);
    } else {
      getIsReadOnly().setIsChangeable(isEditEnabled());
    }
    getIsReadOnly().setEntity(getIsNew() ? Boolean.FALSE : getDisk().getReadOnly());
  }
Ejemplo n.º 2
0
  private void setRngAvailability() {
    TModel model = getModel();
    Set<VmRngDevice.Source> requiredRngSources = model.getSelectedCluster().getRequiredRngSources();

    boolean requiredRngSourcesEmpty = requiredRngSources.isEmpty();
    boolean randomSourceAvailable = requiredRngSources.contains(VmRngDevice.Source.RANDOM);
    boolean hwrngSourceAvailable = requiredRngSources.contains(VmRngDevice.Source.HWRNG);

    model.getIsRngEnabled().setIsChangable(!requiredRngSourcesEmpty);
    model.getRngPeriod().setIsChangable(!requiredRngSourcesEmpty);
    model.getRngBytes().setIsChangable(!requiredRngSourcesEmpty);

    if (requiredRngSourcesEmpty) {
      model.getIsRngEnabled().setMessage(constants.rngNotSupportedByCluster());
      model.getRngPeriod().setMessage(constants.rngNotSupportedByCluster());
      model.getRngBytes().setMessage(constants.rngNotSupportedByCluster());
    }

    model.getRngSourceRandom().setIsChangable(randomSourceAvailable);
    if (!randomSourceAvailable) {
      model
          .getRngSourceRandom()
          .setChangeProhibitionReason(
              messages.rngSourceNotSupportedByCluster(VmRngDevice.Source.RANDOM.toString()));
    }

    model.getRngSourceHwrng().setIsChangable(hwrngSourceAvailable);
    if (!hwrngSourceAvailable) {
      model
          .getRngSourceHwrng()
          .setChangeProhibitionReason(
              messages.rngSourceNotSupportedByCluster(VmRngDevice.Source.HWRNG.toString()));
    }
  }
Ejemplo n.º 3
0
  /**
   * @param template - the template that the latest template should be based on
   * @return template representing the latest template
   */
  private VmTemplate createLatestTemplate(VmTemplate template) {
    VmTemplate latestTemplate = new VmTemplate(template);
    latestTemplate.setTemplateVersionName(constants.latestTemplateVersionName());
    latestTemplate.setDescription(constants.latestTemplateVersionDescription());

    return latestTemplate;
  }
Ejemplo n.º 4
0
 @Before
 public void setUp() throws Exception {
   mockService =
       mock(
           GenericApiGWTServiceAsync.class,
           withSettings().extraInterfaces(ServiceDefTarget.class));
   fakeScheduler = new FakeGWTScheduler();
   CommunicationProvider communicationsProvider =
       new GWTRPCCommunicationProvider(mockService, mockXsrfService, mockXsrfRpcRequestBuilder);
   when(mockXsrfRpcRequestBuilder.getXsrfToken())
       .thenReturn(new XsrfToken("Something")); // $NON-NLS-1$
   OperationProcessor operationProcessor = new OperationProcessor(communicationsProvider);
   operationProcessor.setScheduler(fakeScheduler);
   VdcOperationManager operationsManager = new VdcOperationManager(operationProcessor);
   operationsManager.setLoggedIn(true);
   frontend =
       new Frontend(
           operationsManager,
           mockCanDoActionErrorsTranslator,
           mockVdsmErrorsTranslator,
           mockEventBus);
   frontend.setEventsHandler(mockEventsHandler);
   frontend.setConstants(mockConstants);
   frontend.frontendFailureEvent = mockFrontendFailureEvent;
   frontend.setLoginHandler(mockLoginHandler);
   when(mockAsyncQuery.getDel()).thenReturn(mockAsyncCallback);
   when(mockConstants.noCanDoActionMessage()).thenReturn(NO_MESSAGE);
 }
  protected void updateScsiPassthroguhChangeability() {
    getIsScsiPassthrough().setIsChangeable(!getIsReadOnly().getEntity() && isEditEnabled());
    getIsScsiPassthrough()
        .setChangeProhibitionReason(constants.cannotEnableScsiPassthroughForLunReadOnlyDisk());

    updateSgIoUnfilteredChangeability();
  }
Ejemplo n.º 6
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Run a multiple search query, with only multiple requests, with *win* / *lin* as the
  *       parameter, searching for VMs
  *   <li>Force a failure with an HTTP status code = 404
  *   <li>Check to make sure the appropriate query start and query complete events are fired
  * </ol>
  */
 @Test
 public void testRunMultipleQueries_404_failure() {
   // Don't immediately call process until both queries are in the queue.
   fakeScheduler.setThreshold(2);
   when(mockConstants.requestToServerFailedWithCode())
       .thenReturn("A Request to the Server failed with the following Status Code"); // $NON-NLS-1$
   ArrayList<VdcQueryType> queryTypeList = new ArrayList<VdcQueryType>();
   queryTypeList.add(VdcQueryType.Search);
   queryTypeList.add(VdcQueryType.Search);
   ArrayList<VdcQueryParametersBase> queryParamsList = new ArrayList<VdcQueryParametersBase>();
   queryParamsList.add(new SearchParameters("*win*", SearchType.VM)); // $NON-NLS-1$
   queryParamsList.add(new SearchParameters("*lin*", SearchType.VM)); // $NON-NLS-1$
   frontend.runMultipleQueries(
       queryTypeList, queryParamsList, mockMultipleQueryCallback, "test"); // $NON-NLS-1$
   StatusCodeException exception =
       new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, "404 status code"); // $NON-NLS-1$
   // Repeat 4 times, because of retries.
   for (int i = 1; i < RETRY_COUNT; i++) {
     // Reset the count so we can re-add both entries again.
     fakeScheduler.resetCount();
     verify(mockService, times(i))
         .RunMultipleQueries(
             eq(queryTypeList), eq(queryParamsList), callbackMultipleQueries.capture());
     // Call the failure handler.
     callbackMultipleQueries.getValue().onFailure(exception);
   }
   ArgumentCaptor<FrontendFailureEventArgs> eventArgs =
       ArgumentCaptor.forClass(FrontendFailureEventArgs.class);
   verify(mockFrontendFailureEvent).raise(eq(Frontend.class), eventArgs.capture());
   assertEquals(
       "Message text didn't match", //$NON-NLS-1$
       "A Request to the Server failed with the following Status Code: 404", //$NON-NLS-1$
       eventArgs.getValue().getMessage().getText());
 }
Ejemplo n.º 7
0
 public void updateMigrationAvailability() {
   Boolean haHost = getModel().getIsHighlyAvailable().getEntity();
   if (haHost) {
     getModel().getMigrationMode().setChangeProhibitionReason(constants.hostIsHa());
     getModel().getMigrationMode().setSelectedItem(MigrationSupport.MIGRATABLE);
   }
   getModel().getMigrationMode().setIsChangable(!haHost);
 }
Ejemplo n.º 8
0
 public void updateHaAvailability() {
   boolean automaticMigrationAllowed =
       getModel().getMigrationMode().getSelectedItem() == MigrationSupport.MIGRATABLE;
   if (!automaticMigrationAllowed) {
     getModel().getIsHighlyAvailable().setChangeProhibitionReason(constants.hostNonMigratable());
     getModel().getIsHighlyAvailable().setEntity(false);
   }
   getModel().getIsHighlyAvailable().setIsChangable(automaticMigrationAllowed);
 }
Ejemplo n.º 9
0
 @Override
 public boolean validate() {
   if (isNoSelection()) {
     getInvalidityReasons().add(constants.noDisksSelected());
     setIsValid(false);
     return false;
   }
   return true;
 }
Ejemplo n.º 10
0
 private void updateWarningLabel() {
   getWarningLabel().setIsAvailable(false);
   if (getIsPlugged().getEntity().equals(Boolean.TRUE) && getVm().getStatus() != VMStatus.Down) {
     List<EntityModel<DiskModel>> selectedDisks = getSelectedDisks();
     if (selectedDisks != null && isSelectedDiskInterfaceIDE(selectedDisks)) {
       getWarningLabel().setEntity(constants.ideDisksWillBeAttachedButNotActivated());
       getWarningLabel().setIsAvailable(true);
     }
   }
 }
 private void updateShareable(VolumeType volumeType, StorageType storageType) {
   if (storageType.isBlockDomain() && volumeType == VolumeType.Sparse) {
     getIsShareable()
         .setChangeProhibitionReason(constants.shareableDiskNotSupportedByConfiguration());
     getIsShareable().setIsChangeable(false);
     getIsShareable().setEntity(false);
   } else {
     getIsShareable().setIsChangeable(isEditEnabled());
   }
 }
 protected void updateSgIoUnfilteredChangeability() {
   if (!getIsScsiPassthrough().getEntity()) {
     getIsSgIoUnfiltered()
         .setChangeProhibitionReason(constants.cannotEnableSgioWhenScsiPassthroughDisabled());
     getIsSgIoUnfiltered().setIsChangeable(false);
     getIsSgIoUnfiltered().setEntity(false);
     return;
   }
   getIsSgIoUnfiltered().setIsChangeable(isEditEnabled());
 }
  private void updateShareableDiskEnabled(StoragePool datacenter) {
    boolean isShareableDiskEnabled =
        (Boolean)
            AsyncDataProvider.getInstance()
                .getConfigValuePreConverted(
                    ConfigurationValues.ShareableDiskEnabled,
                    datacenter.getCompatibilityVersion().getValue());

    getIsShareable().setChangeProhibitionReason(constants.shareableDiskNotSupported());
    getIsShareable().setIsChangeable(isShareableDiskEnabled && isEditEnabled());
  }
  protected void forceCreationWarning(ArrayList<String> usedLunsMessages) {
    ConfirmationModel confirmationModel = new ConfirmationModel();
    setConfirmWindow(confirmationModel);

    confirmationModel.setTitle(constants.forceStorageDomainCreation());
    confirmationModel.setMessage(constants.lunsAlreadyPartOfSD());
    confirmationModel.setHelpTag(HelpTag.force_lun_disk_creation);
    confirmationModel.setHashName("force_lun_disk_creation"); // $NON-NLS-1$
    confirmationModel.setItems(usedLunsMessages);

    UICommand forceSaveCommand = new UICommand("OnForceSave", this); // $NON-NLS-1$
    forceSaveCommand.setTitle(constants.ok());
    forceSaveCommand.setIsDefault(true);
    confirmationModel.getCommands().add(forceSaveCommand);

    UICommand cancelconfirmCommand = new UICommand("CancelConfirm", this); // $NON-NLS-1$
    cancelconfirmCommand.setTitle(constants.cancel());
    cancelconfirmCommand.setIsCancel(true);
    confirmationModel.getCommands().add(cancelconfirmCommand);
  }
Ejemplo n.º 15
0
  protected void updateCpuPinningVisibility() {
    if (getModel().getSelectedCluster() != null) {
      VDSGroup cluster = getModel().getSelectedCluster();
      String compatibilityVersion = cluster.getcompatibility_version().toString();
      boolean isLocalSD =
          getModel().getSelectedDataCenter() != null
              && getModel().getSelectedDataCenter().isLocal();

      // cpu pinning is available on Local SD with no consideration for auto assign value
      boolean hasCpuPinning =
          Boolean.FALSE.equals(getModel().getIsAutoAssign().getEntity()) || isLocalSD;

      if (Boolean.FALSE.equals(
          AsyncDataProvider.getInstance()
              .getConfigValuePreConverted(
                  ConfigurationValues.CpuPinningEnabled, compatibilityVersion))) {
        hasCpuPinning = false;
      } else if (Boolean.FALSE.equals(
              AsyncDataProvider.getInstance()
                  .getConfigValuePreConverted(
                      ConfigurationValues.CpuPinMigrationEnabled,
                      AsyncDataProvider.getInstance().getDefaultConfigurationVersion()))
          && isVmMigratable()
          && !isLocalSD) {
        hasCpuPinning = false;
      }

      if (!hasCpuPinning) {
        if (isLocalSD) {
          getModel()
              .getCpuPinning()
              .setChangeProhibitionReason(constants.cpuPinningUnavailableLocalStorage());
        } else {
          getModel().getCpuPinning().setChangeProhibitionReason(constants.cpuPinningUnavailable());
        }
        getModel().getCpuPinning().setEntity("");
      }
      getModel().getCpuPinning().setIsChangable(hasCpuPinning);
    }
  }
  private void updatePlugChangeability() {
    if (getVm() == null) { // No point in updating plug to VM if there's no VM
      return;
    }

    DiskInterface diskInterface = getDiskInterface().getSelectedItem();
    boolean isVmRunning = getVm() != null && getVm().getStatus() != VMStatus.Down;

    if (DiskInterface.IDE.equals(diskInterface) && isVmRunning) {
      getIsPlugged().setChangeProhibitionReason(constants.cannotHotPlugDiskWithIdeInterface());
      getIsPlugged().setIsChangeable(false);
      getIsPlugged().setEntity(false);
    } else {
      if (!canDiskBePlugged(getVm())) {
        getIsPlugged().setChangeProhibitionReason(constants.cannotPlugDiskIncorrectVmStatus());
        getIsPlugged().setIsChangeable(false);
        getIsPlugged().setEntity(false);
      } else {
        getIsPlugged().setIsChangeable(isEditEnabled());
        getIsPlugged().setEntity(true);
      }
    }
  }
  private void updateDirectLunDiskEnabled(StoragePool datacenter) {
    if (getDiskStorageType().getEntity() != DiskStorageType.LUN) {
      return;
    }

    boolean isDirectLUNDiskkEnabled =
        (Boolean)
            AsyncDataProvider.getInstance()
                .getConfigValuePreConverted(
                    ConfigurationValues.DirectLUNDiskEnabled,
                    datacenter.getCompatibilityVersion().getValue());

    getIsDirectLunDiskAvaialable().setEntity(isDirectLUNDiskkEnabled);
    setMessage(
        !isDirectLUNDiskkEnabled ? constants.directLUNDiskNotSupported() : ""); // $NON-NLS-1$
  }
  private void commonInitialize() {
    super.initialize();

    // Create and set commands
    UICommand onSaveCommand = new UICommand("OnSave", this); // $NON-NLS-1$
    onSaveCommand.setTitle(constants.ok());
    onSaveCommand.setIsDefault(true);
    getCommands().add(onSaveCommand);
    getCommands().add(getCancelCommand());

    // Update data
    if (getVm() != null) {
      updateBootableDiskAvailable();
      getIsUsingScsiReservation().setIsAvailable(true);
    }
    updateDatacenters();
  }
  public void updateBootableFrom(List<Disk> vmDisks) {
    getIsBootable().setEntity(true);
    getIsBootable().setIsChangeable(true);
    if (getDisk() == null || !getDisk().isDiskSnapshot()) {
      for (Disk disk : vmDisks) {
        if (disk.isBoot() && !disk.equals(getDisk())) {
          getIsBootable().setEntity(false);
          if (!disk.isDiskSnapshot()) {
            getIsBootable().setChangeProhibitionReason(constants.onlyOneBootableDisk());
            getIsBootable().setIsChangeable(false);
            break;
          }
        }
      }
    }

    if (!getIsNew()) {
      getIsBootable().setEntity(getDisk().isBoot());
    }
  }
Ejemplo n.º 20
0
  public void updateUseHostCpuAvailability() {

    boolean clusterSupportsHostCpu =
        getClusterCompatibilityVersion() != null
            && (getClusterCompatibilityVersion().compareTo(Version.v3_2) >= 0);
    boolean nonMigratable =
        MigrationSupport.PINNED_TO_HOST == getModel().getMigrationMode().getSelectedItem();
    boolean manuallyMigratableAndAnyHostInCluster =
        MigrationSupport.IMPLICITLY_NON_MIGRATABLE
                == getModel().getMigrationMode().getSelectedItem()
            && Boolean.TRUE.equals(getModel().getIsAutoAssign().getEntity());

    if (clusterSupportsHostCpu && (nonMigratable || manuallyMigratableAndAnyHostInCluster)) {
      getModel().getHostCpu().setIsChangable(true);
    } else {
      getModel().getHostCpu().setEntity(false);
      getModel().getHostCpu().setChangeProhibitionReason(constants.hosCPUUnavailable());
      getModel().getHostCpu().setIsChangable(false);
    }
  }
Ejemplo n.º 21
0
  public void dataCenterWithClusterSelectedItemChanged() {
    DataCenterWithCluster dataCenterWithCluster =
        getModel().getDataCenterWithClustersList().getSelectedItem();
    if (dataCenterWithCluster == null) {
      return;
    }
    StoragePool dataCenter = dataCenterWithCluster.getDataCenter();
    if (dataCenter == null) {
      return;
    }

    if (dataCenter.getQuotaEnforcementType() != QuotaEnforcementTypeEnum.DISABLED) {
      getModel().getQuota().setIsAvailable(true);
    } else {
      getModel().getQuota().setIsAvailable(false);
    }

    getModel().getIsRngEnabled().setIsChangable(isRngDeviceSupported(getModel()));

    getModel().getIsRngEnabled().setMessage(constants.rngNotSupportedByCluster());
    setRngAvailability();

    postDataCenterWithClusterSelectedItemChanged();
  }
Ejemplo n.º 22
0
  private void initDataCenter() {
    final UIConstants constants = ConstantsManager.getInstance().getConstants();

    if (getSystemTreeSelectedItem() != null
        && getSystemTreeSelectedItem().getType() != SystemTreeItemType.System) {
      switch (getSystemTreeSelectedItem().getType()) {
        case DataCenter:
        case Cluster:
        case Storages:
        case Storage:
          {
            SystemTreeItemModel dataCenterItem =
                SystemTreeItemModel.findAncestor(
                    SystemTreeItemType.DataCenter, getSystemTreeSelectedItem());
            StoragePool dc = (StoragePool) dataCenterItem.getEntity();

            getDataCenter()
                .setItems(new ArrayList<StoragePool>(Arrays.asList(new StoragePool[] {dc})));
            getDataCenter().setSelectedItem(dc);
            getDataCenter().setIsChangeable(false);
            getDataCenter().setChangeProhibitionReason(constants.cannotChangeDCInTreeContext());
          }
          break;

        case Host:
          {
            VDS host = (VDS) getSystemTreeSelectedItem().getEntity();

            getHost().setIsChangeable(false);
            getHost().setChangeProhibitionReason(constants.cannotChangeHostInTreeContext());
            getHost().setSelectedItem(host);

            SystemTreeItemModel dataCenterItem =
                SystemTreeItemModel.findAncestor(
                    SystemTreeItemType.DataCenter, getSystemTreeSelectedItem());
            StoragePool dc = (StoragePool) dataCenterItem.getEntity();

            getDataCenter()
                .setItems(new ArrayList<StoragePool>(Arrays.asList(new StoragePool[] {dc})));
            getDataCenter().setSelectedItem(dc);
            getDataCenter().setIsChangeable(false);
            getDataCenter().setChangeProhibitionReason(constants.cannotChangeDCInTreeContext());
          }
          break;
      }
    } else {
      if (getStorage() == null
          || getStorage().getStorageDomainSharedStatus() == StorageDomainSharedStatus.Unattached) {
        // We are either adding a new storage or editing an unattached storage
        // -> fill DataCenters drop-down with all possible Data-Centers, choose the empty one:
        // [TODO: In case of an Unattached SD, choose only DCs of the same type]
        AsyncDataProvider.getInstance()
            .getDataCenterList(
                new AsyncQuery(
                    this,
                    new INewAsyncCallback() {
                      @Override
                      public void onSuccess(Object target, Object returnValue) {

                        StorageModel storageModel = (StorageModel) target;
                        StorageModelBehavior storageModelBehavior = behavior;
                        List<StoragePool> dataCenters = (ArrayList<StoragePool>) returnValue;
                        dataCenters = storageModelBehavior.filterDataCenter(dataCenters);
                        StorageModel.addEmptyDataCenterToList(dataCenters);
                        StoragePool oldSelectedItem =
                            storageModel.getDataCenter().getSelectedItem();
                        storageModel.getDataCenter().setItems(dataCenters);
                        if (oldSelectedItem != null) {
                          storageModel
                              .getDataCenter()
                              .setSelectedItem(
                                  Linq.firstOrDefault(
                                      dataCenters,
                                      new Linq.DataCenterPredicate(oldSelectedItem.getId())));
                        } else {
                          storageModel
                              .getDataCenter()
                              .setSelectedItem(
                                  getStorage() == null
                                      ? Linq.firstOrDefault(dataCenters)
                                      : Linq.firstOrDefault(
                                          dataCenters,
                                          new Linq.DataCenterPredicate(UnassignedDataCenterId)));
                        }
                      }
                    }));
      } else { // "Edit Storage" mode:
        AsyncDataProvider.getInstance()
            .getDataCentersByStorageDomain(
                new AsyncQuery(
                    this,
                    new INewAsyncCallback() {
                      @Override
                      public void onSuccess(Object target, Object returnValue) {

                        StorageModel storageModel = (StorageModel) target;
                        List<StoragePool> dataCenters = new ArrayList<StoragePool>();
                        List<StoragePool> dataCentersWithStorage =
                            (ArrayList<StoragePool>) returnValue;
                        if (dataCentersWithStorage.size() < 1
                            || dataCentersWithStorage.get(0) == null) {
                          StorageModel.addEmptyDataCenterToList(dataCenters);
                        } else {
                          dataCenters =
                              new ArrayList<StoragePool>(
                                  Arrays.asList(new StoragePool[] {dataCentersWithStorage.get(0)}));
                        }
                        storageModel.getDataCenter().setItems(dataCenters);
                        storageModel
                            .getDataCenter()
                            .setSelectedItem(Linq.firstOrDefault(dataCenters));
                      }
                    }),
                getStorage().getId());
      }
    }
  }