private void createImageForVmMetaData() {
    VDSReturnValue retVal =
        Backend.getInstance()
            .getResourceManager()
            .RunVdsCommand(
                VDSCommandType.CreateImage,
                new CreateImageVDSCommandParameters(
                    storagePool.getId(),
                    storageDomainId,
                    vmConfImageGroupId,
                    MemoryUtils.META_DATA_SIZE_IN_BYTES,
                    VolumeType.Sparse,
                    VolumeFormat.COW,
                    vmConfVolumeId,
                    ""));

    if (!retVal.getSucceeded()) {
      throw new EngineException(
          EngineError.VolumeCreationError, "Failed to create image for vm configuration!");
    }

    Guid taskId = enclosingCommand.persistAsyncTaskPlaceHolder(CREATE_IMAGE_FOR_VM_TASK_KEY);
    Guid guid =
        enclosingCommand.createTask(
            taskId, retVal.getCreationInfo(), enclosingCommand.getActionType());
    enclosingCommand.getTaskIdList().add(guid);
  }
  private void createImageForMemoryDump() {
    VDSReturnValue retVal =
        Backend.getInstance()
            .getResourceManager()
            .RunVdsCommand(
                VDSCommandType.CreateImage,
                new CreateImageVDSCommandParameters(
                    storagePool.getId(),
                    storageDomainId,
                    memoryDumpImageGroupId,
                    vm.getTotalMemorySizeInBytes(),
                    getVolumeTypeForDomain(),
                    VolumeFormat.RAW,
                    memoryDumpVolumeId,
                    ""));

    if (!retVal.getSucceeded()) {
      throw new EngineException(
          EngineError.VolumeCreationError, "Failed to create image for memory!");
    }

    Guid taskId =
        enclosingCommand.persistAsyncTaskPlaceHolder(CREATE_IMAGE_FOR_MEMORY_DUMP_TASK_KEY);
    Guid guid =
        enclosingCommand.createTask(
            taskId,
            retVal.getCreationInfo(),
            enclosingCommand.getActionType(),
            VdcObjectType.Storage,
            storageDomainId);
    enclosingCommand.getTaskIdList().add(guid);
  }
Esempio n. 3
0
 @Override
 protected void perform() {
   VDSReturnValue returnValue =
       runVdsCommand(VDSCommandType.Thaw, new VdsAndVmIDVDSParametersBase(getVdsId(), getVmId()));
   setActionReturnValue(returnValue.getReturnValue());
   setSucceeded(returnValue.getSucceeded());
 }
  @Override
  protected void executeCommand() {
    List<VM> vms = getVmDao().getAllRunningForVds(getVdsId());
    Collections.sort(vms, Collections.reverseOrder(new VmsComparer()));
    List<Guid> autoStartVmIdsToRerun = new ArrayList<>();
    for (VM vm : vms) {
      if (vm.isAutoStartup()) {
        autoStartVmIdsToRerun.add(vm.getId());
      }
      VDSReturnValue returnValue =
          runVdsCommand(
              VDSCommandType.SetVmStatus,
              new SetVmStatusVDSCommandParameters(vm.getId(), VMStatus.Down, VmExitStatus.Error));
      // Write that this VM was shut down by host reboot or manual fence
      if (returnValue != null && returnValue.getSucceeded()) {
        logSettingVmToDown(getVds().getId(), vm.getId());
      }

      runInternalActionWithTasksContext(
          VdcActionType.ProcessDownVm, new ProcessDownVmParameters(vm.getId(), true));
    }

    runVdsCommand(
        VDSCommandType.UpdateVdsVMsCleared,
        new UpdateVdsVMsClearedVDSCommandParameters(getVdsId()));
    if (!autoStartVmIdsToRerun.isEmpty()) {
      haAutoStartVmsRunner.addVmsToRun(autoStartVmIdsToRerun);
    }
    setSucceeded(true);
  }
Esempio n. 5
0
 private void disconnectStorageByType(
     StorageType storageType, List<StorageServerConnections> connections) {
   StorageHelperDirector.getInstance()
       .getItem(storageType)
       .prepareDisconnectHostFromStoragePoolServers(getParameters(), connections);
   VDSReturnValue vdsReturnValue =
       runVdsCommand(
           VDSCommandType.DisconnectStorageServer,
           new StorageServerConnectionManagementVDSParameters(
               getVds().getId(), getStoragePool().getId(), storageType, connections));
   setSucceeded(vdsReturnValue.getSucceeded());
   if (!vdsReturnValue.getSucceeded()) {
     StorageHelperDirector.getInstance()
         .getItem(storageType)
         .isConnectSucceeded(
             (HashMap<String, String>) vdsReturnValue.getReturnValue(), connections);
   }
 }
  /** Execution shall perform a call to VDSM to set the SLA parameters. */
  @Override
  protected void executeCommand() {
    VDSReturnValue vdsReturnValue =
        runVdsCommand(
            VDSCommandType.UpdateVmPolicy,
            new UpdateVmPolicyVDSParams(
                getVm().getRunOnVds(), getVmId(), getParameters().getCpuLimit()));

    setSucceeded(vdsReturnValue.getSucceeded());
  }
 @Override
 protected void executeQueryCommand() {
   ArrayList<StorageDomain> returnValue = new ArrayList<>();
   VDSReturnValue vdsReturnValue =
       runVdsCommand(
           VDSCommandType.HSMGetStorageDomainsList,
           new HSMGetStorageDomainsListVDSCommandParameters(
               getParameters().getId(),
               Guid.Empty,
               null,
               getParameters().getStorageDomainType(),
               getParameters().getPath()));
   if (vdsReturnValue.getSucceeded()) {
     ArrayList<Guid> guidsFromIrs = (ArrayList<Guid>) vdsReturnValue.getReturnValue();
     HashSet<Guid> guidsFromDb = new HashSet<>();
     if (guidsFromIrs.size() > 0) {
       List<StorageDomain> domainsInDb = storageDomainDao.getAll();
       for (StorageDomain domain : domainsInDb) {
         guidsFromDb.add(domain.getId());
       }
       for (Guid domainId : guidsFromIrs) {
         if (!guidsFromDb.contains(domainId)) {
           Pair<StorageDomainStatic, Guid> domainFromIrs =
               (Pair<StorageDomainStatic, Guid>)
                   runVdsCommand(
                           VDSCommandType.HSMGetStorageDomainInfo,
                           new HSMGetStorageDomainInfoVDSCommandParameters(
                               getParameters().getId(), domainId))
                       .getReturnValue();
           StorageDomain domain = new StorageDomain();
           domain.setStorageStaticData(domainFromIrs.getFirst());
           domain.setStoragePoolId(domainFromIrs.getSecond());
           if (getParameters().getStorageFormatType() == null
               || getParameters().getStorageFormatType() == domain.getStorageFormat()) {
             if (getParameters().getStorageType() != null
                 && domain.getStorageType().getValue()
                     != getParameters().getStorageType().getValue()) {
               log.warn(
                   "The storage type of domain {} has been changed from {} to {}",
                   domain.getStorageName(),
                   domain.getStorageType().toString(),
                   getParameters().getStorageType().toString());
               domain.setStorageType(getParameters().getStorageType());
             }
             returnValue.add(domain);
           }
         }
       }
     }
     getQueryReturnValue().setReturnValue(returnValue);
   }
 }
Esempio n. 8
0
 /**
  * gets VM full information for the given list of VMs
  *
  * @param vmsToUpdate
  * @return
  */
 protected Map[] getVmInfo(List<String> vmsToUpdate) {
   // TODO refactor commands to use vdsId only - the whole vds object here is useless
   VDS vds = new VDS();
   vds.setId(vdsManager.getVdsId());
   Map[] result = {};
   VDSReturnValue vdsReturnValue =
       getResourceManager()
           .runVdsCommand(
               VDSCommandType.FullList, new FullListVDSCommandParameters(vds, vmsToUpdate));
   if (vdsReturnValue.getSucceeded()) {
     result = (Map[]) (vdsReturnValue.getReturnValue());
   }
   return result;
 }
Esempio n. 9
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);
  }
  /*
   * (non-Javadoc)
   * @see org.ovirt.engine.core.bll.CommandBase#executeCommand()
   */
  @Override
  protected void executeCommand() {
    VDSReturnValue returnValue =
        Backend.getInstance()
            .getResourceManager()
            .RunVdsCommand(
                VDSCommandType.ListGlusterVolumes,
                new GlusterBaseVDSCommandParameters(getVdsGroup().getstorage_pool_id().getValue()));

    // Get the return value from VDS command and put it into the return value of the BLL command
    ArrayList<GlusterVolumeEntity> list = new ArrayList<GlusterVolumeEntity>();
    for (GlusterVolumeEntity glusterVolumeEntity :
        (GlusterVolumeEntity[]) returnValue.getReturnValue()) {
      list.add(glusterVolumeEntity);
    }
    getReturnValue().setActionReturnValue(list);

    setSucceeded(returnValue.getSucceeded());
  }
Esempio n. 11
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());
    }
  }
Esempio n. 12
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());
    }
  }
  @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;
    }
  }
  /*
   * (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());
  }
  @Override
  protected void executeCommand() {
    String address = getParameters().getAddress();
    String subnet =
        StringUtils.isEmpty(getParameters().getSubnet())
            ? getParameters().getNetwork().getSubnet()
            : getParameters().getSubnet();
    String gateway =
        StringUtils.isEmpty(getParameters().getGateway()) ? "" : getParameters().getGateway();
    ArrayList<String> interfaceNames = new ArrayList<>();

    Map<String, VdsNetworkInterface> interfaceByName = Entities.entitiesByName(interfaces);
    for (VdsNetworkInterface i : getParameters().getInterfaces()) {
      VdsNetworkInterface existingIface = interfaceByName.get(i.getName());
      if (Boolean.TRUE.equals(existingIface.getBonded())
          || NetworkUtils.isBondVlan(interfaces, existingIface)) {
        getParameters().setBondName(NetworkUtils.stripVlan(existingIface));
        for (VdsNetworkInterface ix : interfaces) {
          if (NetworkUtils.interfaceBasedOn(existingIface, ix.getBondName())) {
            interfaceNames.add(NetworkUtils.stripVlan(ix));
          }
        }
      } else {
        interfaceNames.add(NetworkUtils.stripVlan(existingIface));
      }
    }

    // updating a vlan over bond if the bond was not provided the bond device should preserve the
    // bonding options
    String bondingOptions = null;
    if (getParameters().getBondingOptions() == null
        && getParameters().getBondName() != null
        && !Entities.entitiesByName(getParameters().getInterfaces())
            .containsKey(getParameters().getBondName())) {
      VdsNetworkInterface bond =
          Entities.entitiesByName(interfaces).get(getParameters().getBondName());
      bondingOptions = bond == null ? null : bond.getBondOptions();
    } else {
      bondingOptions = getParameters().getBondingOptions();
    }

    NetworkVdsmVDSCommandParameters parameters =
        new NetworkVdsmVDSCommandParameters(
            getParameters().getVdsId(),
            getParameters().getNetwork().getName(),
            getParameters().getNetwork().getVlanId(),
            getParameters().getBondName(),
            interfaceNames.toArray(new String[] {}),
            address,
            subnet,
            gateway,
            getParameters().getNetwork().getStp(),
            bondingOptions,
            getParameters().getBootProtocol());
    parameters.setVmNetwork(getParameters().getNetwork().isVmNetwork());
    parameters.setOldNetworkName(getParameters().getOldNetworkName());
    parameters.setConnectionTimeout(
        Config.<Integer>getValue(ConfigValues.NetworkConnectivityCheckTimeoutInSeconds));
    parameters.setCheckConnectivity(getParameters().getCheckConnectivity());

    IPAddress[] adresses = Dns.getHostAddresses(NetworkUtils.OS_REFERENCE_TO_MACHINE_NAME);
    if (adresses != null && adresses.length > 0) {
      parameters.setHostAddr(adresses[0].toString());
    }

    if (getParameters().getCheckConnectivity()) {
      ThreadPoolUtil.execute(new EditNetworkThread(parameters));
      pollVds(getVds());
    } else {
      editNetworkThreadCompat(parameters);
    }

    if (retVal != null && editNetworkDone) {
      // update vds network data
      retVal =
          runVdsCommand(
              VDSCommandType.CollectVdsNetworkData,
              new CollectHostNetworkDataVdsCommandParameters(getVds()));

      if (retVal.getSucceeded()) {
        Guid groupId = getVdsDao().get(getParameters().getVdsId()).getVdsGroupId();
        NetworkClusterHelper.setStatus(groupId, getParameters().getNetwork());
        setSucceeded(true);
      }
    }
  }
  @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();
    }
  }
  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);
  }