private void OnSave() {
    VmInterfaceModel model = (VmInterfaceModel) getWindow();
    VmNetworkInterface nic =
        model.getIsNew()
            ? new VmNetworkInterface()
            : (VmNetworkInterface) Cloner.clone((VmNetworkInterface) getSelectedItem());

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

    // Save changes.
    nic.setName((String) model.getName().getEntity());
    nic.setNetworkName(((network) model.getNetwork().getSelectedItem()).getname());
    if (model.getNicType().getSelectedItem() == null) {
      nic.setType(null);
    } else {
      nic.setType(((VmInterfaceType) model.getNicType().getSelectedItem()).getValue());
    }
    nic.setMacAddress(
        model.getMAC().getIsChangable()
            ? (model.getMAC().getEntity() == null
                ? null
                : ((String) (model.getMAC().getEntity())).toLowerCase())
            : model.getIsNew() ? "" : nic.getMacAddress());

    if (model.getIsNew()) {
      Frontend.RunMultipleAction(
          VdcActionType.AddVmTemplateInterface,
          new java.util.ArrayList<VdcActionParametersBase>(
              java.util.Arrays.asList(
                  new VdcActionParametersBase[] {
                    new AddVmTemplateInterfaceParameters(getEntityStronglyTyped().getId(), nic)
                  })),
          new IFrontendMultipleActionAsyncCallback() {
            @Override
            public void Executed(FrontendMultipleActionAsyncResult result) {

              Cancel();
            }
          },
          null);
    } else {
      Frontend.RunMultipleAction(
          VdcActionType.UpdateVmTemplateInterface,
          new java.util.ArrayList<VdcActionParametersBase>(
              java.util.Arrays.asList(
                  new VdcActionParametersBase[] {
                    new AddVmTemplateInterfaceParameters(getEntityStronglyTyped().getId(), nic)
                  })),
          new IFrontendMultipleActionAsyncCallback() {
            @Override
            public void Executed(FrontendMultipleActionAsyncResult result) {

              Cancel();
            }
          },
          null);
    }
  }
  public void OnManage() {
    ListModel model = (ListModel) getWindow();

    java.util.ArrayList<EntityModel> items = Linq.<EntityModel>Cast(model.getItems());
    java.util.ArrayList<network> networks = Linq.<network>Cast(getItems());

    if (getEntity() == null) {
      Cancel();
      return;
    }

    java.util.ArrayList<VdcActionParametersBase> prms1 =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (EntityModel a : items) {
      boolean value = false;
      for (network b : networks) {
        if (b.getId().equals(((network) a.getEntity()).getId())) {
          value = true;
          break;
        }
      }
      if (a.getIsSelected() && !value) {
        prms1.add(new AttachNetworkToVdsGroupParameter(getEntity(), (network) a.getEntity()));
      }
    }

    // Call the command only if necessary (i.e. only if there are paramters):
    if (prms1.size() > 0) {
      Frontend.RunMultipleAction(VdcActionType.AttachNetworkToVdsGroup, prms1);
    }

    java.util.ArrayList<VdcActionParametersBase> prms2 =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (EntityModel a : items) {
      boolean value = true;
      for (network b : networks) {
        if (b.getId().equals(((network) a.getEntity()).getId())) {
          value = false;
          break;
        }
      }
      if (!a.getIsSelected() && !value) {
        prms2.add(new AttachNetworkToVdsGroupParameter(getEntity(), (network) a.getEntity()));
      }
    }

    // Call the command only if necessary (i.e. only if there are paramters):
    if (prms2.size() > 0) {
      Frontend.RunMultipleAction(VdcActionType.DetachNetworkToVdsGroup, prms2);
    }

    Cancel();
  }
  private void OnRemove() {
    ConfirmationModel model = (ConfirmationModel) getWindow();

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

    java.util.ArrayList<VdcActionParametersBase> list =
        new java.util.ArrayList<VdcActionParametersBase>();
    for (Object item : getSelectedItems()) {
      VmNetworkInterface a = (VmNetworkInterface) item;
      list.add(
          new RemoveVmTemplateInterfaceParameters(getEntityStronglyTyped().getId(), a.getId()));
    }

    model.StartProgress(null);

    Frontend.RunMultipleAction(
        VdcActionType.RemoveVmTemplateInterface,
        list,
        new IFrontendMultipleActionAsyncCallback() {
          @Override
          public void Executed(FrontendMultipleActionAsyncResult result) {

            ConfirmationModel localModel = (ConfirmationModel) result.getState();
            localModel.StopProgress();
            Cancel();
          }
        },
        model);
  }
  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);
  }
  public void SetAsDisplay() {
    network network = (network) getSelectedItem();

    Frontend.RunAction(
        VdcActionType.UpdateDisplayToVdsGroup,
        new DisplayNetworkToVdsGroupParameters(getEntity(), network, true));
  }
  @Override
  protected void AsyncSearch() {
    super.AsyncSearch();

    setAsyncResult(
        Frontend.RegisterQuery(
            VdcQueryType.GetTemplateInterfacesByTemplateId,
            new GetVmTemplateParameters(getEntityStronglyTyped().getId())));
    setItems(getAsyncResult().getData());
  }
  @Override
  protected void AsyncSearch() {
    super.AsyncSearch();

    setAsyncResult(
        Frontend.RegisterQuery(
            VdcQueryType.GetAllNetworksByClusterId,
            new VdsGroupQueryParamenters(getEntity().getID())));
    setItems(getAsyncResult().getData());
  }
  public void OnAddHost() {
    CancelConfirm();

    HostModel model = (HostModel) getWindow();

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

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

    // Save changes.
    VDS host = new VDS();
    host.setvds_name((String) model.getName().getEntity());
    host.sethost_name((String) model.getHost().getEntity());
    host.setManagmentIp((String) model.getManagementIp().getEntity());
    host.setport((Integer) model.getPort().getEntity());
    host.setvds_group_id(((VDSGroup) model.getCluster().getSelectedItem()).getId());
    host.setpm_enabled((Boolean) model.getIsPm().getEntity());
    host.setpm_user(
        (Boolean) model.getIsPm().getEntity() ? (String) model.getPmUserName().getEntity() : null);
    host.setpm_password(
        (Boolean) model.getIsPm().getEntity() ? (String) model.getPmPassword().getEntity() : null);
    host.setpm_type(
        (Boolean) model.getIsPm().getEntity()
            ? (String) model.getPmType().getSelectedItem()
            : null);
    host.setPmOptionsMap(
        (Boolean) model.getIsPm().getEntity()
            ? new ValueObjectMap(model.getPmOptionsMap(), false)
            : null);

    AddVdsActionParameters vdsActionParams = new AddVdsActionParameters();
    vdsActionParams.setvds(host);
    vdsActionParams.setVdsId(host.getId());
    vdsActionParams.setRootPassword((String) model.getRootPassword().getEntity());

    model.StartProgress(null);

    Frontend.RunAction(
        VdcActionType.AddVds,
        vdsActionParams,
        new IFrontendActionAsyncCallback() {
          @Override
          public void Executed(FrontendActionAsyncResult result) {

            ClusterGuideModel localModel = (ClusterGuideModel) result.getState();
            localModel.PostOnAddHost(result.getReturnValue());
          }
        },
        this);
  }
  private void ChangePassword() {
    VdcReturnValueBase returnValue =
        Frontend.RunAction(
            VdcActionType.ChangeUserPassword,
            new ChangeUserPasswordParameters(
                (String) getUserName().getEntity(),
                (String) getPassword().getEntity(),
                (String) getNewPassword().getEntity(),
                (String) getDomain().getSelectedItem()));

    if (returnValue != null && returnValue.getSucceeded()) {
      // TODO:
    }
  }
  public void OnSave() {
    ClusterNetworkModel model = (ClusterNetworkModel) getWindow();
    network network = new network(null);

    if (getEntity() == null) {
      Cancel();
      return;
    }

    if (!model.Validate() || getEntity().getstorage_pool_id() == null) {
      return;
    }

    network.setstorage_pool_id(getEntity().getstorage_pool_id());
    network.setname((String) model.getName().getEntity());
    network.setstp((Boolean) model.getIsStpEnabled().getEntity());
    network.setdescription((String) model.getDescription().getEntity());
    network.setvlan_id(null);
    if ((Boolean) model.getHasVLanTag().getEntity()) {
      network.setvlan_id(Integer.parseInt(model.getVLanTag().getEntity().toString()));
    }

    Frontend.RunAction(
        VdcActionType.AddNetwork,
        new AddNetworkStoragePoolParameters(network.getstorage_pool_id().getValue(), network),
        new IFrontendActionAsyncCallback() {
          @Override
          public void Executed(FrontendActionAsyncResult result) {

            Object[] data = (Object[]) result.getState();
            ClusterNetworkListModel networkListModel = (ClusterNetworkListModel) data[0];
            VdcReturnValueBase retVal = result.getReturnValue();
            if (retVal != null && retVal.getSucceeded()) {
              network tempVar = new network(null);
              tempVar.setId((Guid) retVal.getActionReturnValue());
              tempVar.setname(((network) data[1]).getname());
              Frontend.RunAction(
                  VdcActionType.AttachNetworkToVdsGroup,
                  new AttachNetworkToVdsGroupParameter(networkListModel.getEntity(), tempVar));
            }
            networkListModel.Cancel();
          }
        },
        new Object[] {this, network});
  }
  @Override
  public void Login() {
    // Completely override the base class functionality.

    if (!Validate()) {
      return;
    }

    // Clear config cache on login (to make sure we don't use old config in a new session)
    DataProvider.ClearConfigCache();

    Frontend.RunAction(
        VdcActionType.LoginUser,
        new LoginUserParameters(
            (String) getUserName().getEntity(),
            (String) getPassword().getEntity(),
            (String) getDomain().getSelectedItem(),
            "",
            "",
            ""),
        new IFrontendActionAsyncCallback() {
          @Override
          public void Executed(FrontendActionAsyncResult result) {

            UserPortalLoginModel model = (UserPortalLoginModel) result.getState();
            VdcReturnValueBase returnValue = result.getReturnValue();
            boolean success = returnValue != null && returnValue.getSucceeded();
            if (success) {
              model.setLoggedUser((VdcUser) returnValue.getActionReturnValue());
              model.getLoggedInEvent().raise(this, EventArgs.Empty);
            } else {
              model.getPassword().setEntity("");
              if (returnValue != null) {
                model.setMessage(Linq.FirstOrDefault(returnValue.getCanDoActionMessages()));
              }
              model.getLoginFailedEvent().raise(this, EventArgs.Empty);
            }
          }
        },
        this);
  }
예제 #12
0
  @Override
  protected void UpdateInternal() {
    super.UpdateInternal();

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

    VDS host = (VDS) getContainer().getHost().getSelectedItem();
    if (host == null) {
      ProposeDiscover();
      return;
    }

    ClearItems();
    InitializeItems(null, null);

    getContainer().StartProgress(null);

    Frontend.RunQuery(
        VdcQueryType.GetDeviceList,
        new GetDeviceListQueryParameters(host.getvds_id(), getType()),
        new AsyncQuery(
            this,
            new INewAsyncCallback() {
              @Override
              public void OnSuccess(Object target, Object returnValue) {

                SanStorageModel model = (SanStorageModel) target;
                VdcQueryReturnValue response = (VdcQueryReturnValue) returnValue;
                if (response.getSucceeded()) {
                  model.ApplyData((java.util.ArrayList<LUNs>) response.getReturnValue(), false);
                } else {
                  model.setGetLUNsFailure("Could not retrieve LUNs, please check your storage.");
                }
                model.getContainer().StopProgress();
              }
            },
            true));
  }
  @Override
  protected void SyncSearch() {
    if (getEntity() == null) {
      return;
    }

    super.SyncSearch();

    AsyncQuery _asyncQuery = new AsyncQuery();
    _asyncQuery.setModel(this);
    _asyncQuery.asyncCallback =
        new INewAsyncCallback() {
          public void OnSuccess(Object model, Object ReturnValue) {
            SearchableListModel searchableListModel = (SearchableListModel) model;
            searchableListModel.setItems(
                (java.util.ArrayList<network>)
                    ((VdcQueryReturnValue) ReturnValue).getReturnValue());
          }
        };

    VdsGroupQueryParamenters tempVar = new VdsGroupQueryParamenters(getEntity().getID());
    tempVar.setRefresh(getIsQueryFirstTime());
    Frontend.RunQuery(VdcQueryType.GetAllNetworksByClusterId, tempVar, _asyncQuery);
  }
  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));
  }