Search in sources :

Example 1 with MigrateVolumeCommand

use of com.cloud.legacymodel.communication.command.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.legacymodel.communication.command.MigrateVolumeCommand) MigrateVolumeAnswer(com.cloud.legacymodel.communication.answer.MigrateVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) StoragePool(com.cloud.legacymodel.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) MigrateVolumeAnswer(com.cloud.legacymodel.communication.answer.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 2 with MigrateVolumeCommand

use of com.cloud.legacymodel.communication.command.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.legacymodel.communication.command.MigrateVolumeCommand) Task(com.xensource.xenapi.Task) StoragePool(com.cloud.legacymodel.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.legacymodel.communication.answer.Answer) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR) Test(org.junit.Test)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)2 MigrateVolumeCommand (com.cloud.legacymodel.communication.command.MigrateVolumeCommand)2 StoragePool (com.cloud.legacymodel.storage.StoragePool)2 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)1 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)1 MigrateVolumeAnswer (com.cloud.legacymodel.communication.answer.MigrateVolumeAnswer)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 RemoteHostEndPoint (com.cloud.storage.RemoteHostEndPoint)1 VolumeVO (com.cloud.storage.VolumeVO)1 Connection (com.xensource.xenapi.Connection)1 SR (com.xensource.xenapi.SR)1 Task (com.xensource.xenapi.Task)1 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)1 XenAPIException (com.xensource.xenapi.Types.XenAPIException)1 VDI (com.xensource.xenapi.VDI)1 HashMap (java.util.HashMap)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 Test (org.junit.Test)1