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();
  }
Beispiel #2
0
  @Override
  public Map<String, String> getJobMessageProperties() {
    if (jobProperties == null) {
      jobProperties = super.getJobMessageProperties();
      VDS vds = getParameters().getvds();

      String vdsName = (vds != null && vds.getName() != null) ? vds.getName() : "";
      jobProperties.put(VdcObjectType.VDS.name().toLowerCase(), vdsName);
    }
    return jobProperties;
  }
Beispiel #3
0
  protected boolean canConnect(VDS vds) {
    // execute the connectivity and id uniqueness validation for VDS type hosts
    if (!getParameters().isPending()
        && !getParameters().isProvisioned()
        && Config.<Boolean>getValue(ConfigValues.InstallVds)) {
      try (final EngineSSHClient sshclient = getSSHClient()) {
        sshclient.connect();
        sshclient.authenticate();

        String hostUUID = getInstalledVdsIdIfExists(sshclient);
        if (hostUUID != null && vdsDao.getAllWithUniqueId(hostUUID).size() != 0) {
          return failValidation(EngineMessage.ACTION_TYPE_FAILED_VDS_WITH_SAME_UUID_EXIST);
        }

        return isValidGlusterPeer(sshclient, vds.getClusterId());
      } catch (AuthenticationException e) {
        log.error(
            "Failed to authenticate session with host '{}': {}", vds.getName(), e.getMessage());
        log.debug("Exception", e);
        return failValidation(EngineMessage.VDS_CANNOT_AUTHENTICATE_TO_SERVER);
      } catch (SecurityException e) {
        log.error(
            "Failed to connect to host '{}', fingerprint '{}': {}",
            vds.getName(),
            vds.getSshKeyFingerprint(),
            e.getMessage());
        log.debug("Exception", e);
        addValidationMessage(EngineMessage.VDS_SECURITY_CONNECTION_ERROR);
        addValidationMessageVariable("ErrorMessage", e.getMessage());
        return failValidation(EngineMessage.VDS_CANNOT_AUTHENTICATE_TO_SERVER);
      } catch (Exception e) {
        log.error("Failed to establish session with host '{}': {}", vds.getName(), e.getMessage());
        log.debug("Exception", e);

        return failValidation(EngineMessage.VDS_CANNOT_CONNECT_TO_SERVER);
      }
    }
    return true;
  }
 private void stopGlusterServices(VDS vds) {
   if (vds.getVdsGroupSupportsGlusterService()) {
     // Stop glusterd service first
     boolean succeeded =
         resourceManagerProvider
             .get()
             .runVdsCommand(
                 VDSCommandType.ManageGlusterService,
                 new GlusterServiceVDSParameters(vds.getId(), Arrays.asList("glusterd"), "stop"))
             .getSucceeded();
     if (succeeded) {
       // Stop other gluster related processes on the node
       succeeded =
           resourceManagerProvider
               .get()
               .runVdsCommand(
                   VDSCommandType.StopGlusterProcesses,
                   new VdsIdVDSCommandParametersBase(vds.getId()))
               .getSucceeded();
       // Mark the bricks as DOWN on this node
       if (succeeded) {
         List<GlusterBrickEntity> bricks =
             glusterBrickDao.getGlusterVolumeBricksByServerId(vds.getId());
         for (GlusterBrickEntity brick : bricks) {
           brick.setStatus(GlusterStatus.DOWN);
         }
         glusterBrickDao.updateBrickStatuses(bricks);
       }
     }
     if (!succeeded) {
       log.error(
           "Failed to stop gluster services while moving the host '{}' to maintenance",
           vds.getName());
     }
   }
 }
 @Override
 public String getEntityOldName() {
   return oldHost.getName();
 }
  private Map<String, Object> generateNetworks() {
    Map<String, Object> networks = new HashMap<String, Object>();
    NetworkQoSDao qosDao = getDbFacade().getQosDao();
    for (Network network : getParameters().getNetworks()) {
      Map<String, Object> opts = new HashMap<String, Object>();
      VdsNetworkInterface iface =
          findNetworkInterface(
              network.getName(), getParameters().getInterfaces(), getParameters().getBonds());
      String ifaceNameWithoutVlan = NetworkUtils.stripVlan(iface);
      Boolean bonded = findInterfaceByName(ifaceNameWithoutVlan).getBonded();
      String type = (bonded != null && bonded) ? "bonding" : "nic";
      opts.put(type, ifaceNameWithoutVlan);
      if (NetworkUtils.isVlan(network)) {
        opts.put("vlan", network.getVlanId().toString());
      }

      if (iface.getBootProtocol() != null) {
        addBootProtocol(opts, iface);
      }

      if (network.getMtu() == 0) {
        opts.put("mtu", NetworkUtils.getDefaultMtu().toString());
      } else {
        opts.put("mtu", String.valueOf(network.getMtu()));
      }

      opts.put("bridged", Boolean.toString(network.isVmNetwork()));
      if (network.isVmNetwork()) {
        opts.put(VdsProperties.STP, network.getStp() ? "yes" : "no");
      }

      VDS host = getDbFacade().getVdsDao().get(getParameters().getVdsId());
      Version version = host.getVdsGroupCompatibilityVersion();
      if (qosConfiguredOnInterface(iface, network) && FeatureSupported.hostNetworkQos(version)) {
        NetworkQosMapper qosMapper =
            new NetworkQosMapper(
                opts, VdsProperties.HOST_QOS_INBOUND, VdsProperties.HOST_QOS_OUTBOUND);
        qosMapper.serialize(
            iface.isQosOverridden() ? iface.getQos() : qosDao.get(network.getQosId()));
      }

      Set<Version> supportedClusterVersionsSet = host.getSupportedClusterVersionsSet();
      if (supportedClusterVersionsSet == null || supportedClusterVersionsSet.isEmpty()) {
        log.warnFormat(
            "Host {0} ({1}) doesn't contain Supported Cluster Versions, therefore 'defaultRoute'"
                + " will not be sent via the SetupNetworks",
            host.getName(), host.getId());
      } else if (FeatureSupported.defaultRoute(Collections.max(supportedClusterVersionsSet))
          && NetworkUtils.isManagementNetwork(network)
          && (iface.getBootProtocol() == NetworkBootProtocol.DHCP
              || (iface.getBootProtocol() == NetworkBootProtocol.STATIC_IP
                  && StringUtils.isNotEmpty(iface.getGateway())))) {
        opts.put(DEFAULT_ROUTE, Boolean.TRUE);
      }

      if (iface.hasCustomProperties()) {
        opts.put(VdsProperties.NETWORK_CUSTOM_PROPERTIES, iface.getCustomProperties());
      }

      networks.put(network.getName(), opts);
    }

    for (String net : getParameters().getRemovedNetworks()) {
      networks.put(net, REMOVE_OBJ);
    }

    return networks;
  }
 /** this property is used for audit log events */
 public final String getDestinationVdsName() {
   VDS destinationVds = getDestinationVds();
   return destinationVds != null ? destinationVds.getName() : null;
 }
  @Override
  protected void executeCommand() {
    if (UpdateStorageDomainsInDb()) {
      // setting storage pool status to maintenance
      StoragePool storagePool = getStoragePool();
      getCompensationContext().snapshotEntity(storagePool);
      TransactionSupport.executeInNewTransaction(
          new TransactionMethod<Object>() {
            @Override
            public Object runInTransaction() {
              getStoragePool().setStatus(StoragePoolStatus.Maintenance);
              getStoragePool().setStoragePoolFormatType(masterStorageDomain.getStorageFormat());
              DbFacade.getInstance().getStoragePoolDao().update(getStoragePool());
              getCompensationContext().stateChanged();
              StoragePoolStatusHandler.poolStatusChanged(
                  getStoragePool().getId(), getStoragePool().getStatus());
              return null;
            }
          });

      // Following code performs only read operations, therefore no need for new transaction
      boolean result = false;
      retVal = null;
      for (VDS vds : getAllRunningVdssInPool()) {
        setVds(vds);
        for (Guid storageDomainId : getParameters().getStorages()) {
          // now the domain should have the mapping
          // with the pool in db
          StorageDomain storageDomain =
              DbFacade.getInstance()
                  .getStorageDomainDao()
                  .getForStoragePool(storageDomainId, getStoragePool().getId());
          StorageHelperDirector.getInstance()
              .getItem(storageDomain.getStorageType())
              .connectStorageToDomainByVdsId(storageDomain, getVds().getId());
        }
        retVal = addStoragePoolInIrs();
        if (!retVal.getSucceeded()
            && retVal.getVdsError().getCode() == VdcBllErrors.StorageDomainAccessError) {
          log.warnFormat("Error creating storage pool on vds {0} - continuing", vds.getName());
          continue;
        } else {
          // storage pool creation succeeded or failed
          // but didn't throw exception
          result = retVal.getSucceeded();
          break;
        }
      }

      setSucceeded(result);
      if (!result) {
        if (retVal != null && retVal.getVdsError().getCode() != null) {
          throw new VdcBLLException(
              retVal.getVdsError().getCode(), retVal.getVdsError().getMessage());
        } else {
          // throw exception to cause rollback and stop the
          // command
          throw new VdcBLLException(VdcBllErrors.ENGINE_ERROR_CREATING_STORAGE_POOL);
        }
      }
    }

    // Create pool phase completed, no rollback is needed here, so compensation information needs to
    // be cleared!
    TransactionSupport.executeInNewTransaction(
        new TransactionMethod<Void>() {
          @Override
          public Void runInTransaction() {
            getCompensationContext().resetCompensation();
            return null;
          }
        });
    freeLock();
    // if create succeeded activate
    if (getSucceeded()) {
      ActivateStorageDomains();
    }
  }