Beispiel #1
0
  /**
   * The scenario in which a host is already exists when adding new host after the validate is when
   * the existed host type is oVirt and its status is 'Pending Approval'. In this case the old entry
   * is removed from the DB, since the oVirt node was added again, where the new host properties
   * might be updated (e.g. cluster adjustment, data center, host name, host address) and a new
   * entry with updated properties is added.
   *
   * @param oVirtId the deprecated host entry to remove
   */
  private boolean removeDeprecatedOvirtEntry(final Guid oVirtId) {

    final VDS vds = vdsDao.get(oVirtId);
    if (vds == null || !VdsHandler.isPendingOvirt(vds)) {
      return false;
    }

    String vdsName = getParameters().getVdsStaticData().getName();
    log.info(
        "Host '{}', id '{}' of type '{}' is being re-registered as Host '{}'",
        vds.getName(),
        vds.getId(),
        vds.getVdsType().name(),
        vdsName);
    VdcReturnValueBase result =
        TransactionSupport.executeInNewTransaction(
            () -> runInternalAction(VdcActionType.RemoveVds, new RemoveVdsParameters(oVirtId)));

    if (!result.getSucceeded()) {
      String errors =
          result.isValid()
              ? result.getFault().getError().name()
              : StringUtils.join(result.getValidationMessages(), ",");
      log.warn(
          "Failed to remove Host '{}', id '{}', re-registering it as Host '{}' fails with errors {}",
          vds.getName(),
          vds.getId(),
          vdsName,
          errors);
    } else {
      log.info("Host '{}' is now known as Host '{}'", vds.getName(), vdsName);
    }

    return result.getSucceeded();
  }
  private static VDSReturnValue runVdsCommand(
      VDSCommandType vdsCommandType,
      VdsIdVDSCommandParametersBase params,
      Guid storagePoolId,
      CommandBase<?> cmd,
      boolean performFailover) {
    Set<Guid> executedHosts = new HashSet<>();
    VDSReturnValue returnValue = null;
    if (params.getVdsId() == null) {
      chooseHostForExecution(params, storagePoolId, cmd, Collections.emptyList());
      if (params.getVdsId() == null) {
        throw new EngineException(
            EngineError.RESOURCE_MANAGER_VDS_NOT_FOUND,
            "No host was found to perform the operation");
      }
    }

    int attempts = 0;
    while (attempts <= Config.<Integer>getValue(ConfigValues.HsmCommandFailOverRetries)) {
      try {
        attempts++;
        returnValue = getBackend().getResourceManager().runVdsCommand(vdsCommandType, params);
        if (returnValue != null && returnValue.getSucceeded()) {
          return returnValue;
        }
      } catch (EngineException e) {
        returnValue = e.getVdsReturnValue();
      }

      executedHosts.add(params.getVdsId());

      if (!performFailover || (returnValue != null && !returnValue.isCanTryOnDifferentVds())) {
        break;
      }

      chooseHostForExecution(params, storagePoolId, cmd, executedHosts);

      if (params.getVdsId() == null) {
        break;
      }
    }

    return VdsHandler.handleVdsResult(returnValue);
  }
 private boolean NeedToUpdateVdsBroker() {
   return VdsHandler.isFieldsUpdated(
       getParameters().getVdsStaticData(), oldHost.getStaticData(), UPDATE_FIELDS_VDS_BROKER);
 }