Exemplo n.º 1
0
 @Override
 protected void executeCommand() {
   if (validatePermissions()) {
     if (validateInputs()) {
       try {
         returnValue.setSucceeded(true);
         executeQueryCommand();
       } catch (RuntimeException ex) {
         returnValue.setSucceeded(false);
         Throwable th = ex instanceof EngineException ? ex : ex.getCause();
         if (th instanceof EngineException) {
           EngineException vdcExc = (EngineException) th;
           if (vdcExc.getErrorCode() != null) {
             returnValue.setExceptionString(vdcExc.getErrorCode().toString());
           } else {
             returnValue.setExceptionString(vdcExc.getMessage());
           }
           log.error("Query '{}' failed: {}", getClass().getSimpleName(), vdcExc.getMessage());
           log.error("Exception", vdcExc);
         } else {
           returnValue.setExceptionString(ex.getMessage());
           log.error("Query '{}' failed: {}", getClass().getSimpleName(), ex.getMessage());
           log.error("Exception", ex);
         }
       }
     } else {
       log.error(
           "Query execution failed due to invalid inputs: {}", returnValue.getExceptionString());
     }
   } else {
     String errMessage = "Query execution failed due to insufficient permissions.";
     log.error(errMessage);
     returnValue.setExceptionString(errMessage);
   }
 }
Exemplo n.º 2
0
 /**
  * Log that the migration had failed with the error code that is in the VDS and needs to be
  * retrieved.
  */
 protected void determineMigrationFailureForAuditLog() {
   if (getVm() != null && getVm().getStatus() == VMStatus.Up) {
     try {
       runVdsCommand(
           VDSCommandType.MigrateStatus,
           new MigrateStatusVDSCommandParameters(getVdsId(), getVmId()));
     } catch (EngineException e) {
       migrationErrorCode = e.getErrorCode();
     }
   }
 }
Exemplo n.º 3
0
 protected void getDowntime() {
   if (FeatureSupported.migrateDowntime(getVm().getVdsGroupCompatibilityVersion())) {
     try {
       VDSReturnValue retVal =
           runVdsCommand(
               VDSCommandType.MigrateStatus,
               new MigrateStatusVDSCommandParameters(getDestinationVdsId(), getVmId()));
       if (retVal != null) {
         actualDowntime = (Integer) retVal.getReturnValue();
       }
     } catch (EngineException e) {
       migrationErrorCode = e.getErrorCode();
     }
   }
 }
Exemplo n.º 4
0
  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 void connectAndRefreshAllUpHosts(final boolean commandSucceeded) {
    if (isLastMaster || !commandSucceeded) {
      log.warn(
          "skipping connect and refresh for all hosts, last master '{}', command status '{}'",
          isLastMaster,
          commandSucceeded);
      return;
    }

    List<Callable<Void>> tasks = new ArrayList<>();
    for (final VDS vds : getAllRunningVdssInPool()) {
      tasks.add(
          () -> {
            try {
              if (!connectVdsToNewMaster(vds)) {
                log.warn(
                    "failed to connect vds '{}' to the new master '{}'",
                    vds.getId(),
                    getNewMasterStorageDomainId());
                return null;
              }

              List<StoragePoolIsoMap> storagePoolIsoMap =
                  storagePoolIsoMapDao.getAllForStoragePool(getStoragePool().getId());
              try {
                runVdsCommand(
                    VDSCommandType.ConnectStoragePool,
                    new ConnectStoragePoolVDSCommandParameters(
                        vds,
                        getStoragePool(),
                        getNewMasterStorageDomainId(),
                        storagePoolIsoMap,
                        true));
              } catch (EngineException ex) {
                if (EngineError.StoragePoolUnknown == ex.getVdsError().getCode()) {
                  VDSReturnValue returnVal =
                      runVdsCommand(
                          VDSCommandType.ConnectStoragePool,
                          new ConnectStoragePoolVDSCommandParameters(
                              vds,
                              getStoragePool(),
                              getNewMasterStorageDomainId(),
                              storagePoolIsoMap));
                  if (!returnVal.getSucceeded()) {
                    log.error(
                        "Post reconstruct actions (connectPool) did not complete on host '{}' in the pool. error {}",
                        vds.getId(),
                        returnVal.getVdsError().getMessage());
                  }
                } else {
                  log.error(
                      "Post reconstruct actions (refreshPool)"
                          + " did not complete on host '{}' in the pool. error {}",
                      vds.getId(),
                      ex.getMessage());
                }
              }
            } catch (Exception e) {
              log.error(
                  "Post reconstruct actions (connectPool,refreshPool,disconnect storage)"
                      + " did not complete on host '{}' in the pool: {}",
                  vds.getId(),
                  e.getMessage());
              log.debug("Exception", e);
            }
            return null;
          });
    }
    ThreadPoolUtil.invokeAll(tasks);
  }