protected IStorageHelper setUpStorageHelper(
     storage_domains dom, StorageType storageType, boolean connect, boolean failure) {
   StorageHelperDirector director = mock(StorageHelperDirector.class);
   when(StorageHelperDirector.getInstance()).thenReturn(director);
   IStorageHelper helper = mock(IStorageHelper.class);
   if (connect) {
     when(helper.ConnectStorageToDomainByVdsId(dom, VDS_ID)).thenReturn(true);
     when(helper.DisconnectStorageFromDomainByVdsId(dom, VDS_ID)).thenReturn(true);
   }
   if (!failure) {
     when(helper.StorageDomainRemoved(dom.getStorageStaticData())).thenReturn(true);
   }
   when(director.getItem(storageType)).thenReturn(helper);
   return helper;
 }
 @Override
 protected void executeCommand() {
   TransactionSupport.executeInNewTransaction(
       new TransactionMethod<Object>() {
         @Override
         public Object runInTransaction() {
           storage_pool_iso_map domainPoolMap =
               new storage_pool_iso_map(
                   getRecoveryStoragePoolParametersData().getNewMasterDomainId(),
                   getRecoveryStoragePoolParametersData().getStoragePoolId(),
                   StorageDomainStatus.Active);
           DbFacade.getInstance().getStoragePoolIsoMapDAO().save(domainPoolMap);
           getCompensationContext().snapshotNewEntity(domainPoolMap);
           getCompensationContext().stateChanged();
           return null;
         }
       });
   getStoragePool().setstatus(StoragePoolStatus.Problematic);
   if (StorageHelperDirector.getInstance()
       .getItem(getStorageDomain().getstorage_type())
       .ConnectStorageToDomainByVdsId(getNewMaster(), getVds().getvds_id())) {
     super.executeCommand();
   } else {
     getReturnValue()
         .setFault(
             new VdcFault(
                 new VdcBLLException(
                     VdcBllErrors.StorageServerConnectionError, "Failed to connect storage"),
                 VdcBllErrors.StorageServerConnectionError));
   }
 }
 protected IStorageHelper getStorageHelper(storage_domains storageDomain) {
   return StorageHelperDirector.getInstance().getItem(storageDomain.getstorage_type());
 }
  @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();
    }
  }