示例#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();
  }