public void OnSelectHost() {
    MoveHost model = (MoveHost) getWindow();

    if (model.getProgress() != null) {
      return;
    }

    if (!model.Validate()) {
      return;
    }

    model.setSelectedHosts(new java.util.ArrayList<VDS>());
    for (EntityModel a : Linq.<EntityModel>Cast(model.getItems())) {
      if (a.getIsSelected()) {
        model.getSelectedHosts().add((VDS) a.getEntity());
      }
    }

    VDSGroup cluster = (VDSGroup) model.getCluster().getSelectedItem();

    java.util.ArrayList<VdcActionParametersBase> paramerterList =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (VDS host : model.getSelectedHosts()) {
      // Try to change host's cluster as neccessary.
      if (host.getvds_group_id() != null && !host.getvds_group_id().equals(cluster.getId())) {
        paramerterList.add(new ChangeVDSClusterParameters(cluster.getId(), host.getId()));
      }
    }
    model.StartProgress(null);
    Frontend.RunMultipleAction(
        VdcActionType.ChangeVDSCluster,
        paramerterList,
        new IFrontendMultipleActionAsyncCallback() {
          @Override
          public void Executed(FrontendMultipleActionAsyncResult result) {

            ClusterGuideModel clusterGuideModel = (ClusterGuideModel) result.getState();
            java.util.ArrayList<VDS> hosts =
                ((MoveHost) clusterGuideModel.getWindow()).getSelectedHosts();
            java.util.ArrayList<VdcReturnValueBase> retVals =
                (java.util.ArrayList<VdcReturnValueBase>) result.getReturnValue();
            if (retVals != null && hosts.size() == retVals.size()) {
              int i = 0;
              for (VDS selectedHost : hosts) {
                if (selectedHost.getstatus() == VDSStatus.PendingApproval
                    && retVals.get(i) != null
                    && retVals.get(i).getSucceeded()) {
                  Frontend.RunAction(
                      VdcActionType.ApproveVds, new ApproveVdsParameters(selectedHost.getId()));
                }
              }
              i++;
            }
            clusterGuideModel.getWindow().StopProgress();
            clusterGuideModel.Cancel();
            clusterGuideModel.PostAction();
          }
        },
        this);
  }
 // TODO asynch event handler - design infra code to allow async events in segregated thread
 public void onMomPolicyChange(@Observes @MomPolicyUpdate final VDSGroup cluster) {
   if (cluster == null || cluster.getCompatibilityVersion().compareTo(Version.v3_4) < 0) return;
   List<VDS> activeHostsInCluster =
       vdsDao.getAllForVdsGroupWithStatus(cluster.getId(), VDSStatus.Up);
   // collect all Active hosts into a callable list
   List<Callable<Object>> callables = new LinkedList<>();
   for (final VDS vds : activeHostsInCluster) {
     callables.add(
         new Callable<Object>() {
           @Override
           public Object call() {
             try {
               resourceManagerProvider
                   .get()
                   .runVdsCommand(
                       VDSCommandType.SetMOMPolicyParameters,
                       new MomPolicyVDSParameters(
                           vds,
                           cluster.isEnableBallooning(),
                           cluster.isEnableKsm(),
                           cluster.isKsmMergeAcrossNumaNodes()));
             } catch (EngineException e) {
               log.error("Could not update MoM policy on host '{}'", vds.getName());
             }
             return null;
           }
         });
   }
   // run all VDSCommands concurrently with executor
   if (callables.size() > 0) ThreadPoolUtil.invokeAll(callables);
 }
Example #3
0
 /**
  * Check if VDSGroup item with specified id exist in List
  *
  * @param items
  * @param id
  * @return
  */
 public static boolean IsClusterItemExistInList(List<VDSGroup> items, Guid id) {
   for (VDSGroup a : items) {
     if (id.equals(a.getId())) {
       return true;
     }
   }
   return false;
 }
Example #4
0
  public static boolean IsHostBelongsToAnyOfClusters(ArrayList<VDSGroup> clusters, VDS host) {
    for (VDSGroup cluster : clusters) {
      if (cluster.getId().equals(host.getvds_group_id())) {
        return true;
      }
    }

    return false;
  }
  protected void updateQuotaByCluster(final Guid defaultQuota, final String quotaName) {
    if (getModel().getQuota().getIsAvailable()) {
      VDSGroup cluster = getModel().getSelectedCluster();
      if (cluster == null) {
        return;
      }
      Frontend.getInstance()
          .runQuery(
              VdcQueryType.GetAllRelevantQuotasForVdsGroup,
              new IdQueryParameters(cluster.getId()),
              new AsyncQuery(
                  getModel(),
                  new INewAsyncCallback() {

                    @Override
                    public void onSuccess(Object model, Object returnValue) {
                      UnitVmModel vmModel = (UnitVmModel) model;
                      ArrayList<Quota> quotaList =
                          ((VdcQueryReturnValue) returnValue).getReturnValue();
                      if (quotaList != null && !quotaList.isEmpty()) {
                        vmModel.getQuota().setItems(quotaList);
                      }
                      if (quotaList != null
                          && defaultQuota != null
                          && !Guid.Empty.equals(defaultQuota)) {
                        boolean hasQuotaInList = false;
                        for (Quota quota : quotaList) {
                          if (quota.getId().equals(defaultQuota)) {
                            vmModel.getQuota().setSelectedItem(quota);
                            hasQuotaInList = true;
                            break;
                          }
                        }
                        // Add the quota to the list only in edit mode
                        if (!hasQuotaInList && !getModel().getIsNew()) {
                          Quota quota = new Quota();
                          quota.setId(defaultQuota);
                          quota.setQuotaName(quotaName);
                          quotaList.add(quota);
                          vmModel.getQuota().setItems(quotaList);
                          vmModel.getQuota().setSelectedItem(quota);
                        }
                      }
                    }
                  }));
    }
  }
Example #6
0
 @Override
 public boolean Match(VDSGroup source) {
   return id.equals(source.getId());
 }