Search in sources :

Example 6 with MigrateVolumeCommand

use of com.cloud.agent.api.storage.MigrateVolumeCommand in project cloudstack by apache.

the class XenServer610WrapperTest method testXenServer610MigrateVolumeCommandWrapper.

@Test
public void testXenServer610MigrateVolumeCommandWrapper() {
    final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
    final Connection conn = Mockito.mock(Connection.class);
    final SR destinationPool = Mockito.mock(SR.class);
    final VDI srcVolume = Mockito.mock(VDI.class);
    final Task task = Mockito.mock(Task.class);
    final long volumeId = 1l;
    final String volumePath = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final int timeout = 120;
    final Map<String, String> other = new HashMap<String, String>();
    other.put("live", "true");
    final MigrateVolumeCommand createStorageCommand = new MigrateVolumeCommand(volumeId, volumePath, pool, timeout);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(xenServer610Resource.getConnection()).thenReturn(conn);
    when(pool.getUuid()).thenReturn(uuid);
    when(xenServer610Resource.getStorageRepository(conn, uuid)).thenReturn(destinationPool);
    when(xenServer610Resource.getVDIbyUuid(conn, volumePath)).thenReturn(srcVolume);
    try {
        when(srcVolume.poolMigrateAsync(conn, destinationPool, other)).thenReturn(task);
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    when(xenServer610Resource.getMigrateWait()).thenReturn(120);
    final Answer answer = wrapper.execute(createStorageCommand, xenServer610Resource);
    verify(xenServer610Resource, times(1)).getConnection();
    // try {
    // verify(xenServer610Resource, times(1)).waitForTask(conn, task, 1000, timeout);
    // verify(xenServer610Resource, times(1)).checkForSuccess(conn, task);
    // } catch (final XenAPIException e) {
    // fail(e.getMessage());
    // } catch (final XmlRpcException e) {
    // fail(e.getMessage());
    // } catch (final TimeoutException e) {
    // fail(e.getMessage());
    // }
    assertFalse(answer.getResult());
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) Task(com.xensource.xenapi.Task) StoragePool(com.cloud.storage.StoragePool) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Answer(com.cloud.agent.api.Answer) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR) Test(org.junit.Test)

Example 7 with MigrateVolumeCommand

use of com.cloud.agent.api.storage.MigrateVolumeCommand in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method migrateVolumeForKVM.

private String migrateVolumeForKVM(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, HostVO hostVO, String errMsg) {
    boolean srcVolumeDetached = srcVolumeInfo.getAttachedVM() == null;
    try {
        Map<String, String> srcDetails = getVolumeDetails(srcVolumeInfo);
        Map<String, String> destDetails = getVolumeDetails(destVolumeInfo);
        MigrateVolumeCommand migrateVolumeCommand = new MigrateVolumeCommand(srcVolumeInfo.getTO(), destVolumeInfo.getTO(), srcDetails, destDetails, StorageManager.KvmStorageOfflineMigrationWait.value());
        if (srcVolumeDetached) {
            _volumeService.grantAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore());
        }
        handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
        _volumeService.grantAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore());
        MigrateVolumeAnswer migrateVolumeAnswer = (MigrateVolumeAnswer) agentManager.send(hostVO.getId(), migrateVolumeCommand);
        if (migrateVolumeAnswer == null || !migrateVolumeAnswer.getResult()) {
            if (migrateVolumeAnswer != null && StringUtils.isNotEmpty(migrateVolumeAnswer.getDetails())) {
                throw new CloudRuntimeException(migrateVolumeAnswer.getDetails());
            } else {
                throw new CloudRuntimeException(errMsg);
            }
        }
        if (srcVolumeDetached) {
            _volumeService.revokeAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore());
        }
        try {
            _volumeService.revokeAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore());
        } catch (Exception e) {
            // This volume should be deleted soon, so just log a warning here.
            LOGGER.warn(e.getMessage(), e);
        }
        return migrateVolumeAnswer.getVolumePath();
    } catch (Exception ex) {
        try {
            _volumeService.revokeAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore());
        } catch (Exception e) {
            // This volume should be deleted soon, so just log a warning here.
            LOGGER.warn(e.getMessage(), e);
        }
        if (srcVolumeDetached) {
            _volumeService.revokeAccess(srcVolumeInfo, hostVO, srcVolumeInfo.getDataStore());
        }
        String msg = "Failed to perform volume migration : ";
        LOGGER.warn(msg, ex);
        throw new CloudRuntimeException(msg + ex.getMessage(), ex);
    } finally {
        handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
    }
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 8 with MigrateVolumeCommand

use of com.cloud.agent.api.storage.MigrateVolumeCommand in project cloudstack by apache.

the class VmwareStorageMotionStrategy method copyAsync.

/**
 * the Vmware storageMotion strategy allows to copy to a destination pool but not to a destination host
 *
 * @param srcData  volume to move
 * @param destData volume description as intended after the move
 * @param destHost null or else
 * @param callback where to report completion or failure to
 */
@Override
public void copyAsync(DataObject srcData, DataObject destData, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback) {
    if (destHost != null) {
        String format = "%s cannot target a host in moving an object from {%s}\n to {%s}";
        String msg = String.format(format, this.getClass().getName(), srcData.toString(), destData.toString());
        s_logger.error(msg);
        throw new CloudRuntimeException(msg);
    }
    // OfflineVmwareMigration: extract the destination pool from destData and construct a migrateVolume command
    if (!isOnPrimary(srcData, destData)) {
        // OfflineVmwareMigration: we shouldn't be here as we would have refused in the canHandle call
        throw new UnsupportedOperationException();
    }
    VirtualMachine vm = getVolumeVm(srcData);
    StoragePool sourcePool = (StoragePool) srcData.getDataStore();
    StoragePool targetPool = (StoragePool) destData.getDataStore();
    Pair<Long, String> hostIdForVmAndHostGuidInTargetCluster = getHostIdForVmAndHostGuidInTargetCluster(vm, srcData, sourcePool, destData, targetPool);
    Long hostId = hostIdForVmAndHostGuidInTargetCluster.first();
    MigrateVolumeCommand cmd = new MigrateVolumeCommand(srcData.getId(), srcData.getTO().getPath(), vm != null ? vm.getInstanceName() : null, sourcePool, targetPool, hostIdForVmAndHostGuidInTargetCluster.second(), ((VolumeObjectTO) srcData.getTO()).getChainInfo());
    if (sourcePool.getParent() != 0) {
        cmd.setContextParam(DiskTO.PROTOCOL_TYPE, Storage.StoragePoolType.DatastoreCluster.toString());
    }
    Answer answer;
    if (hostId != null) {
        answer = agentMgr.easySend(hostId, cmd);
    } else {
        answer = agentMgr.sendTo(sourcePool.getDataCenterId(), HypervisorType.VMware, cmd);
    }
    updateVolumeAfterMigration(answer, srcData, destData);
    CopyCommandResult result = new CopyCommandResult(null, answer);
    callback.complete(result);
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Answer(com.cloud.agent.api.Answer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) StoragePool(com.cloud.storage.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 9 with MigrateVolumeCommand

use of com.cloud.agent.api.storage.MigrateVolumeCommand in project cosmic by MissionCriticalCloud.

the class AncientDataMotionStrategy method migrateVolumeToPool.

protected Answer migrateVolumeToPool(final DataObject srcData, final DataObject destData) {
    final String value = configDao.getValue(Config.MigrateWait.key());
    final int waitInterval = NumbersUtil.parseInt(value, Integer.parseInt(Config.MigrateWait.getDefaultValue()));
    final VolumeInfo volume = (VolumeInfo) srcData;
    final StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destData.getDataStore().getId(), DataStoreRole.Primary);
    final MigrateVolumeCommand command = new MigrateVolumeCommand(volume.getId(), volume.getPath(), destPool, volume.getAttachedVmName(), volume.getVolumeType(), waitInterval);
    final EndPoint ep = selector.select(srcData, StorageAction.MIGRATEVOLUME);
    Answer answer = null;
    if (ep == null) {
        final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
        s_logger.error(errMsg);
        answer = new Answer(command, false, errMsg);
    } else {
        answer = ep.sendMessage(command);
    }
    if (answer == null || !answer.getResult()) {
        throw new CloudRuntimeException("Failed to migrate volume " + volume + " to storage pool " + destPool);
    } else {
        // Update the volume details after migration.
        final VolumeVO volumeVo = volDao.findById(volume.getId());
        final Long oldPoolId = volume.getPoolId();
        volumeVo.setPath(((MigrateVolumeAnswer) answer).getVolumePath());
        final String chainInfo = ((MigrateVolumeAnswer) answer).getVolumeChainInfo();
        if (chainInfo != null) {
            volumeVo.setChainInfo(chainInfo);
        }
        volumeVo.setPodId(destPool.getPodId());
        volumeVo.setPoolId(destPool.getId());
        volumeVo.setLastPoolId(oldPoolId);
        // For SMB, pool credentials are also stored in the uri query string.  We trim the query string
        // part  here to make sure the credentials do not get stored in the db unencrypted.
        String folder = destPool.getPath();
        if (destPool.getPoolType() == StoragePoolType.SMB && folder != null && folder.contains("?")) {
            folder = folder.substring(0, folder.indexOf("?"));
        }
        volumeVo.setFolder(folder);
        volDao.update(volume.getId(), volumeVo);
    }
    return answer;
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint)

Example 10 with MigrateVolumeCommand

use of com.cloud.agent.api.storage.MigrateVolumeCommand in project cosmic by MissionCriticalCloud.

the class XenServer610WrapperTest method testXenServer610MigrateVolumeCommandWrapper.

@Test
public void testXenServer610MigrateVolumeCommandWrapper() {
    final String uuid = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
    final Connection conn = Mockito.mock(Connection.class);
    final SR destinationPool = Mockito.mock(SR.class);
    final VDI srcVolume = Mockito.mock(VDI.class);
    final Task task = Mockito.mock(Task.class);
    final long volumeId = 1l;
    final String volumePath = "206b21a7-c6ec-40e2-b5e2-f861b9612f04";
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final int timeout = 120;
    final Map<String, String> other = new HashMap<>();
    other.put("live", "true");
    final MigrateVolumeCommand createStorageCommand = new MigrateVolumeCommand(volumeId, volumePath, pool, timeout);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(xenServer610Resource.getConnection()).thenReturn(conn);
    when(pool.getUuid()).thenReturn(uuid);
    when(xenServer610Resource.getStorageRepository(conn, uuid)).thenReturn(destinationPool);
    when(xenServer610Resource.getVDIbyUuid(conn, volumePath)).thenReturn(srcVolume);
    try {
        when(srcVolume.poolMigrateAsync(conn, destinationPool, other)).thenReturn(task);
    } catch (final BadServerResponse e) {
        fail(e.getMessage());
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    when(xenServer610Resource.getMigrateWait()).thenReturn(120);
    final Answer answer = wrapper.execute(createStorageCommand, xenServer610Resource);
    verify(xenServer610Resource, times(1)).getConnection();
    // try {
    // verify(xenServer610Resource, times(1)).waitForTask(conn, task, 1000, timeout);
    // verify(xenServer610Resource, times(1)).checkForSuccess(conn, task);
    // } catch (final XenAPIException e) {
    // fail(e.getMessage());
    // } catch (final XmlRpcException e) {
    // fail(e.getMessage());
    // } catch (final TimeoutException e) {
    // fail(e.getMessage());
    // }
    assertFalse(answer.getResult());
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) Task(com.xensource.xenapi.Task) StoragePool(com.cloud.storage.StoragePool) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) HashMap(java.util.HashMap) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Answer(com.cloud.agent.api.Answer) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR) Test(org.junit.Test)

Aggregations

MigrateVolumeCommand (com.cloud.agent.api.storage.MigrateVolumeCommand)10 Answer (com.cloud.agent.api.Answer)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)7 StoragePool (com.cloud.storage.StoragePool)6 HashMap (java.util.HashMap)4 MigrateAnswer (com.cloud.agent.api.MigrateAnswer)3 MigrateVmToPoolCommand (com.cloud.agent.api.MigrateVmToPoolCommand)3 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)3 ModifyTargetsAnswer (com.cloud.agent.api.ModifyTargetsAnswer)3 AttachIsoAnswer (com.cloud.agent.api.AttachIsoAnswer)2 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)2 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)2 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)2 CheckOnHostAnswer (com.cloud.agent.api.CheckOnHostAnswer)2 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)2 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)2 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)2 DeleteVMSnapshotAnswer (com.cloud.agent.api.DeleteVMSnapshotAnswer)2 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)2