Search in sources :

Example 1 with MigrateWithStorageAcrossClustersCommand

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

the class KVMStorageMotionStrategy method migrateVmWithVolumesAcrossCluster.

@Override
protected Answer migrateVmWithVolumesAcrossCluster(final VMInstanceVO instanceTo, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost, final Map<VolumeInfo, DataStore> volumeToPoolMap) throws AgentUnavailableException {
    try {
        final List<Pair<VolumeTO, StorageFilerTO>> volumeMapping = buildVolumeMapping(volumeToPoolMap);
        final MigrateWithStorageAcrossClustersCommand command = new MigrateWithStorageAcrossClustersCommand(vmTo, volumeMapping, destHost.getPrivateIpAddress());
        final MigrateWithStorageAcrossClustersAnswer answer = (MigrateWithStorageAcrossClustersAnswer) agentMgr.send(srcHost.getId(), command);
        if (answer == null) {
            final String errorMessage = String.format("Error when trying to migrate VM %s (with storage) to host %s", instanceTo, destHost);
            s_logger.error(errorMessage);
            throw new CloudRuntimeException(errorMessage);
        } else if (!answer.getResult()) {
            final String errorMessage = String.format("Error when trying to migrate VM %s (with storage) to host %s => Details: %s", instanceTo, destHost, answer.getDetails());
            s_logger.error(errorMessage);
            throw new CloudRuntimeException(errorMessage);
        } else {
            // Update the volume details after migration.
            updateVolumePathsAfterMigration(volumeToPoolMap, answer.getVolumes());
        }
        return answer;
    } catch (final OperationTimedoutException e) {
        final String errorMessage = String.format("Operation timed out when attempting to migrate VM %s to host %s", instanceTo, destHost);
        s_logger.error(errorMessage, e);
        throw new AgentUnavailableException(errorMessage, srcHost.getId());
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) MigrateWithStorageAcrossClustersAnswer(com.cloud.agent.api.MigrateWithStorageAcrossClustersAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) MigrateWithStorageAcrossClustersCommand(com.cloud.agent.api.MigrateWithStorageAcrossClustersCommand) Pair(com.cloud.utils.Pair)

Aggregations

MigrateWithStorageAcrossClustersAnswer (com.cloud.agent.api.MigrateWithStorageAcrossClustersAnswer)1 MigrateWithStorageAcrossClustersCommand (com.cloud.agent.api.MigrateWithStorageAcrossClustersCommand)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)1 Pair (com.cloud.utils.Pair)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1