Exemplo n.º 1
0
  @Override
  protected void executeVmCommand() {
    VDSReturnValue vdsReturnValue =
        resourceManager.runVdsCommand(VDSCommandType.MigrateBroker, getParameters());
    VM vm = getVmDao().get(getParameters().getVmId());

    if (vdsReturnValue.getSucceeded()) {
      resourceManager.AddAsyncRunningVm(getParameters().getVmId());
      resourceManager.InternalSetVmStatus(vm, VMStatus.MigratingFrom);
      vm.setMigratingToVds(getParameters().getDstVdsId());
      vmManager.update(vm.getDynamicData());
      getVDSReturnValue().setReturnValue(VMStatus.MigratingFrom);
    } else {
      log.error("Failed Vm migration");
      getVDSReturnValue().setSucceeded(false);
      getVDSReturnValue().setReturnValue(vm.getStatus());
      getVDSReturnValue().setVdsError(vdsReturnValue.getVdsError());
      getVDSReturnValue().setExceptionString(vdsReturnValue.getExceptionString());
      getVDSReturnValue().setExceptionObject(vdsReturnValue.getExceptionObject());
    }
  }
  @Override
  protected void executeCommand() {
    VDSReturnValue returnValue =
        runVdsCommand(
            VDSCommandType.ResetGlusterVolumeOptions,
            new ResetGlusterVolumeOptionsVDSParameters(
                upServer.getId(),
                getGlusterVolumeName(),
                getParameters().getVolumeOption(),
                getParameters().isForceAction()));
    setSucceeded(returnValue.getSucceeded());

    if (getSucceeded()) {

      if (getParameters().getVolumeOption() != null
          && !(getParameters().getVolumeOption().getKey().isEmpty())) {
        GlusterVolumeOptionEntity entity =
            getGlusterVolume().getOption(getParameters().getVolumeOption().getKey());
        isResetAllOptions = false;
        if (entity != null) {
          removeOptionInDb(entity);
          String optionValue = entity.getValue();
          getParameters().getVolumeOption().setValue(optionValue != null ? optionValue : "");
          addCustomValue(GlusterConstants.OPTION_KEY, getParameters().getVolumeOption().getKey());
          addCustomValue(
              GlusterConstants.OPTION_VALUE, getParameters().getVolumeOption().getValue());
        }
      } else {
        for (GlusterVolumeOptionEntity option : getGlusterVolume().getOptions()) {
          removeOptionInDb(option);
        }
        isResetAllOptions = true;
      }
    } else {
      handleVdsError(
          AuditLogType.GLUSTER_VOLUME_OPTIONS_RESET_FAILED, returnValue.getVdsError().getMessage());
      return;
    }
  }
Exemplo n.º 3
0
  @Override
  protected void executeCommand() {
    VDSReturnValue returnValue =
        runVdsCommand(
            VDSCommandType.StopGlusterVolumeGeoRepSession,
            new GlusterVolumeGeoRepSessionVDSParameters(
                upServer.getId(),
                getGeoRepSession().getMasterVolumeName(),
                getGeoRepSession().getSlaveHostName(),
                getGeoRepSession().getSlaveVolumeName(),
                getGeoRepSession().getUserName(),
                getParameters().isForce()));

    setSucceeded(returnValue.getSucceeded());
    if (getSucceeded()) {
      getGeoRepSession().setStatus(GeoRepSessionStatus.STOPPED);
      getGlusterGeoRepDao().updateSession(getGeoRepSession());
    } else {
      handleVdsError(
          AuditLogType.GEOREP_SESSION_STOP_FAILED, returnValue.getVdsError().getMessage());
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see org.ovirt.engine.core.bll.CommandBase#executeCommand()
   */
  @Override
  protected void executeCommand() {
    // set the gluster volume name for audit purpose
    setGlusterVolumeName(volume.getName());

    if (volume.getTransportTypes() == null || volume.getTransportTypes().isEmpty()) {
      volume.addTransportType(TransportType.TCP);
    }

    // GLUSTER access protocol is enabled by default
    volume.addAccessProtocol(AccessProtocol.GLUSTER);
    if (!volume.getAccessProtocols().contains(AccessProtocol.NFS)) {
      volume.disableNFS();
    }

    VDSReturnValue returnValue =
        runVdsCommand(
            VDSCommandType.CreateGlusterVolume,
            new CreateGlusterVolumeVDSParameters(upServer.getId(), volume));
    setSucceeded(returnValue.getSucceeded());

    if (!getSucceeded()) {
      handleVdsError(
          AuditLogType.GLUSTER_VOLUME_CREATE_FAILED, returnValue.getVdsError().getMessage());
      return;
    }

    // Volume created successfully. Insert it to database.
    GlusterVolumeEntity createdVolume = (GlusterVolumeEntity) returnValue.getReturnValue();
    setVolumeType(createdVolume);
    setBrickOrder(createdVolume.getBricks());
    addVolumeToDb(createdVolume);

    // set all options of the volume
    setVolumeOptions(createdVolume);

    getReturnValue().setActionReturnValue(createdVolume.getId());
  }
  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);
  }
  @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();
    }
  }