Search in sources :

Example 1 with MigrateVolumeCommand

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

the class AncientDataMotionStrategy method migrateVolumeToPool.

protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) {
    String value = configDao.getValue(Config.MigrateWait.key());
    int waitInterval = NumbersUtil.parseInt(value, Integer.parseInt(Config.MigrateWait.getDefaultValue()));
    VolumeInfo volume = (VolumeInfo) srcData;
    StoragePool srcPool = (StoragePool) dataStoreMgr.getDataStore(srcData.getDataStore().getId(), DataStoreRole.Primary);
    StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destData.getDataStore().getId(), DataStoreRole.Primary);
    MigrateVolumeCommand command = new MigrateVolumeCommand(volume.getId(), volume.getPath(), destPool, volume.getAttachedVmName(), volume.getVolumeType(), waitInterval, volume.getChainInfo());
    if (srcPool.getParent() != 0) {
        command.setContextParam(DiskTO.PROTOCOL_TYPE, Storage.StoragePoolType.DatastoreCluster.toString());
    }
    EndPoint ep = selector.select(srcData, StorageAction.MIGRATEVOLUME);
    Answer answer = null;
    if (ep == null) {
        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.
        VolumeVO volumeVo = volDao.findById(volume.getId());
        Long oldPoolId = volume.getPoolId();
        volumeVo.setPath(((MigrateVolumeAnswer) answer).getVolumePath());
        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) Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint)

Example 2 with MigrateVolumeCommand

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

the class StorageSystemDataMotionStrategy method handleVolumeMigrationForXenServer.

private void handleVolumeMigrationForXenServer(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) {
    VirtualMachine vm = srcVolumeInfo.getAttachedVM();
    if (vm == null || vm.getState() != VirtualMachine.State.Running) {
        throw new CloudRuntimeException("Currently, a volume to migrate from non-managed storage to managed storage on XenServer must be attached to " + "a VM in the Running state.");
    }
    destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null);
    destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore());
    handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
    HostVO hostVO = _hostDao.findById(vm.getHostId());
    _volumeService.grantAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore());
    String value = _configDao.getValue(Config.MigrateWait.key());
    int waitInterval = NumbersUtil.parseInt(value, Integer.parseInt(Config.MigrateWait.getDefaultValue()));
    StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destVolumeInfo.getDataStore().getId(), DataStoreRole.Primary);
    MigrateVolumeCommand command = new MigrateVolumeCommand(srcVolumeInfo.getId(), srcVolumeInfo.getPath(), destPool, srcVolumeInfo.getAttachedVmName(), srcVolumeInfo.getVolumeType(), waitInterval, null);
    Map<String, String> details = new HashMap<>();
    details.put(DiskTO.MANAGED, Boolean.TRUE.toString());
    details.put(DiskTO.IQN, destVolumeInfo.get_iScsiName());
    details.put(DiskTO.STORAGE_HOST, destPool.getHostAddress());
    details.put(DiskTO.PROTOCOL_TYPE, (destPool.getPoolType() != null) ? destPool.getPoolType().toString() : null);
    command.setDestDetails(details);
    EndPoint ep = selector.select(srcVolumeInfo, StorageAction.MIGRATEVOLUME);
    Answer answer;
    if (ep == null) {
        String errMsg = "No remote endpoint to send command to; check if host or SSVM is down";
        LOGGER.error(errMsg);
        answer = new Answer(command, false, errMsg);
    } else {
        answer = ep.sendMessage(command);
    }
    handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
    if (answer == null || !answer.getResult()) {
        handleFailedVolumeMigration(srcVolumeInfo, destVolumeInfo, hostVO);
        throw new CloudRuntimeException("Failed to migrate volume with ID " + srcVolumeInfo.getId() + " to storage pool with ID " + destPool.getId());
    } else {
        handleSuccessfulVolumeMigration(srcVolumeInfo, destPool, (MigrateVolumeAnswer) answer);
    }
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) Answer(com.cloud.agent.api.Answer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) StoragePool(com.cloud.storage.StoragePool) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) HostVO(com.cloud.host.HostVO) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 3 with MigrateVolumeCommand

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

the class VmwareResource method executeRequest.

@Override
public Answer executeRequest(Command cmd) {
    logCommand(cmd);
    Answer answer = null;
    NDC.push(getCommandLogTitle(cmd));
    try {
        long cmdSequence = _cmdSequence++;
        Date startTime = DateUtil.currentGMTTime();
        PropertyMapDynamicBean mbean = new PropertyMapDynamicBean();
        mbean.addProp("StartTime", DateUtil.getDateDisplayString(TimeZone.getDefault(), startTime));
        mbean.addProp("Command", _gson.toJson(cmd));
        mbean.addProp("Sequence", String.valueOf(cmdSequence));
        mbean.addProp("Name", cmd.getClass().getSimpleName());
        Class<? extends Command> clz = cmd.getClass();
        if (cmd instanceof NetworkElementCommand) {
            return _vrResource.executeRequest((NetworkElementCommand) cmd);
        } else if (clz == ReadyCommand.class) {
            answer = execute((ReadyCommand) cmd);
        } else if (clz == GetHostStatsCommand.class) {
            answer = execute((GetHostStatsCommand) cmd);
        } else if (clz == GetVmStatsCommand.class) {
            answer = execute((GetVmStatsCommand) cmd);
        } else if (clz == GetVmNetworkStatsCommand.class) {
            answer = execute((GetVmNetworkStatsCommand) cmd);
        } else if (clz == GetVmDiskStatsCommand.class) {
            answer = execute((GetVmDiskStatsCommand) cmd);
        } else if (cmd instanceof GetVolumeStatsCommand) {
            return execute((GetVolumeStatsCommand) cmd);
        } else if (clz == CheckHealthCommand.class) {
            answer = execute((CheckHealthCommand) cmd);
        } else if (clz == StopCommand.class) {
            answer = execute((StopCommand) cmd);
        } else if (clz == RebootRouterCommand.class) {
            answer = execute((RebootRouterCommand) cmd);
        } else if (clz == RebootCommand.class) {
            answer = execute((RebootCommand) cmd);
        } else if (clz == CheckVirtualMachineCommand.class) {
            answer = execute((CheckVirtualMachineCommand) cmd);
        } else if (clz == PrepareForMigrationCommand.class) {
            answer = execute((PrepareForMigrationCommand) cmd);
        } else if (clz == MigrateCommand.class) {
            answer = execute((MigrateCommand) cmd);
        } else if (clz == MigrateVmToPoolCommand.class) {
            answer = execute((MigrateVmToPoolCommand) cmd);
        } else if (clz == MigrateWithStorageCommand.class) {
            answer = execute((MigrateWithStorageCommand) cmd);
        } else if (clz == MigrateVolumeCommand.class) {
            answer = execute((MigrateVolumeCommand) cmd);
        } else if (clz == DestroyCommand.class) {
            answer = execute((DestroyCommand) cmd);
        } else if (clz == CreateStoragePoolCommand.class) {
            return execute((CreateStoragePoolCommand) cmd);
        } else if (clz == ModifyTargetsCommand.class) {
            answer = execute((ModifyTargetsCommand) cmd);
        } else if (clz == ModifyStoragePoolCommand.class) {
            answer = execute((ModifyStoragePoolCommand) cmd);
        } else if (clz == GetStoragePoolCapabilitiesCommand.class) {
            answer = execute((GetStoragePoolCapabilitiesCommand) cmd);
        } else if (clz == DeleteStoragePoolCommand.class) {
            answer = execute((DeleteStoragePoolCommand) cmd);
        } else if (clz == CopyVolumeCommand.class) {
            answer = execute((CopyVolumeCommand) cmd);
        } else if (clz == AttachIsoCommand.class) {
            answer = execute((AttachIsoCommand) cmd);
        } else if (clz == ValidateSnapshotCommand.class) {
            answer = execute((ValidateSnapshotCommand) cmd);
        } else if (clz == ManageSnapshotCommand.class) {
            answer = execute((ManageSnapshotCommand) cmd);
        } else if (clz == BackupSnapshotCommand.class) {
            answer = execute((BackupSnapshotCommand) cmd);
        } else if (clz == CreateVolumeFromSnapshotCommand.class) {
            answer = execute((CreateVolumeFromSnapshotCommand) cmd);
        } else if (clz == CreatePrivateTemplateFromVolumeCommand.class) {
            answer = execute((CreatePrivateTemplateFromVolumeCommand) cmd);
        } else if (clz == CreatePrivateTemplateFromSnapshotCommand.class) {
            answer = execute((CreatePrivateTemplateFromSnapshotCommand) cmd);
        } else if (clz == UpgradeSnapshotCommand.class) {
            answer = execute((UpgradeSnapshotCommand) cmd);
        } else if (clz == GetStorageStatsCommand.class) {
            answer = execute((GetStorageStatsCommand) cmd);
        } else if (clz == PrimaryStorageDownloadCommand.class) {
            answer = execute((PrimaryStorageDownloadCommand) cmd);
        } else if (clz == GetVncPortCommand.class) {
            answer = execute((GetVncPortCommand) cmd);
        } else if (clz == SetupCommand.class) {
            answer = execute((SetupCommand) cmd);
        } else if (clz == MaintainCommand.class) {
            answer = execute((MaintainCommand) cmd);
        } else if (clz == PingTestCommand.class) {
            answer = execute((PingTestCommand) cmd);
        } else if (clz == CheckOnHostCommand.class) {
            answer = execute((CheckOnHostCommand) cmd);
        } else if (clz == ModifySshKeysCommand.class) {
            answer = execute((ModifySshKeysCommand) cmd);
        } else if (clz == NetworkUsageCommand.class) {
            answer = execute((NetworkUsageCommand) cmd);
        } else if (clz == StartCommand.class) {
            answer = execute((StartCommand) cmd);
        } else if (clz == CheckSshCommand.class) {
            answer = execute((CheckSshCommand) cmd);
        } else if (clz == CheckNetworkCommand.class) {
            answer = execute((CheckNetworkCommand) cmd);
        } else if (clz == PlugNicCommand.class) {
            answer = execute((PlugNicCommand) cmd);
        } else if (clz == ReplugNicCommand.class) {
            answer = execute((ReplugNicCommand) cmd);
        } else if (clz == UnPlugNicCommand.class) {
            answer = execute((UnPlugNicCommand) cmd);
        } else if (cmd instanceof CreateVMSnapshotCommand) {
            return execute((CreateVMSnapshotCommand) cmd);
        } else if (cmd instanceof DeleteVMSnapshotCommand) {
            return execute((DeleteVMSnapshotCommand) cmd);
        } else if (cmd instanceof RevertToVMSnapshotCommand) {
            return execute((RevertToVMSnapshotCommand) cmd);
        } else if (clz == ResizeVolumeCommand.class) {
            return execute((ResizeVolumeCommand) cmd);
        } else if (clz == UnregisterVMCommand.class) {
            return execute((UnregisterVMCommand) cmd);
        } else if (cmd instanceof StorageSubSystemCommand) {
            checkStorageProcessorAndHandlerNfsVersionAttribute((StorageSubSystemCommand) cmd);
            return storageHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
        } else if (clz == ScaleVmCommand.class) {
            return execute((ScaleVmCommand) cmd);
        } else if (clz == PvlanSetupCommand.class) {
            return execute((PvlanSetupCommand) cmd);
        } else if (clz == GetVmIpAddressCommand.class) {
            return execute((GetVmIpAddressCommand) cmd);
        } else if (clz == UnregisterNicCommand.class) {
            answer = execute((UnregisterNicCommand) cmd);
        } else if (clz == GetUnmanagedInstancesCommand.class) {
            answer = execute((GetUnmanagedInstancesCommand) cmd);
        } else if (clz == PrepareUnmanageVMInstanceCommand.class) {
            answer = execute((PrepareUnmanageVMInstanceCommand) cmd);
        } else if (clz == ValidateVcenterDetailsCommand.class) {
            answer = execute((ValidateVcenterDetailsCommand) cmd);
        } else if (clz == SetupPersistentNetworkCommand.class) {
            answer = execute((SetupPersistentNetworkCommand) cmd);
        } else if (clz == GetVmVncTicketCommand.class) {
            answer = execute((GetVmVncTicketCommand) cmd);
        } else {
            answer = Answer.createUnsupportedCommandAnswer(cmd);
        }
        if (cmd.getContextParam("checkpoint") != null) {
            answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
        }
        Date doneTime = DateUtil.currentGMTTime();
        mbean.addProp("DoneTime", DateUtil.getDateDisplayString(TimeZone.getDefault(), doneTime));
        mbean.addProp("Answer", _gson.toJson(answer));
        synchronized (this) {
            try {
                JmxUtil.registerMBean("VMware " + _morHyperHost.getValue(), "Command " + cmdSequence + "-" + cmd.getClass().getSimpleName(), mbean);
                _cmdMBeans.add(mbean);
                if (_cmdMBeans.size() >= MazCmdMBean) {
                    PropertyMapDynamicBean mbeanToRemove = _cmdMBeans.get(0);
                    _cmdMBeans.remove(0);
                    JmxUtil.unregisterMBean("VMware " + _morHyperHost.getValue(), "Command " + mbeanToRemove.getProp("Sequence") + "-" + mbeanToRemove.getProp("Name"));
                }
            } catch (Exception e) {
                if (s_logger.isTraceEnabled())
                    s_logger.trace("Unable to register JMX monitoring due to exception " + ExceptionUtil.toString(e));
            }
        }
    } finally {
        recycleServiceContext();
        NDC.pop();
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("End executeRequest(), cmd: " + cmd.getClass().getSimpleName());
    return answer;
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) RebootRouterCommand(com.cloud.agent.api.RebootRouterCommand) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) ManageSnapshotCommand(com.cloud.agent.api.ManageSnapshotCommand) GetUnmanagedInstancesCommand(com.cloud.agent.api.GetUnmanagedInstancesCommand) MigrateCommand(com.cloud.agent.api.MigrateCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) GetVmDiskStatsCommand(com.cloud.agent.api.GetVmDiskStatsCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) GetVolumeStatsCommand(com.cloud.agent.api.GetVolumeStatsCommand) PrepareUnmanageVMInstanceCommand(com.cloud.agent.api.PrepareUnmanageVMInstanceCommand) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) ScaleVmCommand(com.cloud.agent.api.ScaleVmCommand) PingTestCommand(com.cloud.agent.api.PingTestCommand) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) GetVmVncTicketCommand(com.cloud.agent.api.GetVmVncTicketCommand) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) UnregisterVMCommand(com.cloud.agent.api.UnregisterVMCommand) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) AttachIsoCommand(com.cloud.agent.api.AttachIsoCommand) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) StopCommand(com.cloud.agent.api.StopCommand) DeleteVMSnapshotCommand(com.cloud.agent.api.DeleteVMSnapshotCommand) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) PrepareForMigrationCommand(com.cloud.agent.api.PrepareForMigrationCommand) ReadyCommand(com.cloud.agent.api.ReadyCommand) GetVmIpAddressCommand(com.cloud.agent.api.GetVmIpAddressCommand) UpgradeSnapshotCommand(com.cloud.agent.api.UpgradeSnapshotCommand) PropertyMapDynamicBean(com.cloud.utils.mgmt.PropertyMapDynamicBean) CheckOnHostCommand(com.cloud.agent.api.CheckOnHostCommand) RebootCommand(com.cloud.agent.api.RebootCommand) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) StartCommand(com.cloud.agent.api.StartCommand) GetStoragePoolCapabilitiesCommand(com.cloud.agent.api.GetStoragePoolCapabilitiesCommand) RevertToVMSnapshotCommand(com.cloud.agent.api.RevertToVMSnapshotCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) ValidateVcenterDetailsCommand(com.cloud.agent.api.ValidateVcenterDetailsCommand) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) CreateVMSnapshotCommand(com.cloud.agent.api.CreateVMSnapshotCommand) GetVmNetworkStatsCommand(com.cloud.agent.api.GetVmNetworkStatsCommand) MigrateVmToPoolCommand(com.cloud.agent.api.MigrateVmToPoolCommand) SetupPersistentNetworkCommand(com.cloud.agent.api.SetupPersistentNetworkCommand) ReplugNicCommand(com.cloud.agent.api.ReplugNicCommand) ModifySshKeysCommand(com.cloud.agent.api.ModifySshKeysCommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) ValidateSnapshotCommand(com.cloud.agent.api.ValidateSnapshotCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) MaintainCommand(com.cloud.agent.api.MaintainCommand) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) SetupCommand(com.cloud.agent.api.SetupCommand) Date(java.util.Date) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) GetStorageStatsCommand(com.cloud.agent.api.GetStorageStatsCommand) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) UnregisterNicCommand(com.cloud.agent.api.UnregisterNicCommand) SetupPersistentNetworkAnswer(com.cloud.agent.api.SetupPersistentNetworkAnswer) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) GetVmVncTicketAnswer(com.cloud.agent.api.GetVmVncTicketAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmNetworkStatsAnswer(com.cloud.agent.api.GetVmNetworkStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) AttachIsoAnswer(com.cloud.agent.api.AttachIsoAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) ReplugNicAnswer(com.cloud.agent.api.ReplugNicAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) GetVncPortCommand(com.cloud.agent.api.GetVncPortCommand) ModifyTargetsCommand(com.cloud.agent.api.ModifyTargetsCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) CheckVirtualMachineCommand(com.cloud.agent.api.CheckVirtualMachineCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand)

Example 4 with MigrateVolumeCommand

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

the class VmwareResource method createAnswerForCmd.

Answer createAnswerForCmd(VirtualMachineMO vmMo, List<VolumeObjectTO> volumeObjectToList, Command cmd, Map<Integer, Long> volumeDeviceKey) throws Exception {
    List<VolumeObjectTO> volumeToList = new ArrayList<>();
    VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo.getDiskInfoBuilder();
    VirtualDisk[] disks = vmMo.getAllDiskDevice();
    Answer answer;
    if (s_logger.isTraceEnabled()) {
        s_logger.trace(String.format("creating answer for %s", cmd.getClass().getSimpleName()));
    }
    if (cmd instanceof MigrateVolumeCommand) {
        if (disks.length == 1) {
            String volumePath = vmMo.getVmdkFileBaseName(disks[0]);
            return new MigrateVolumeAnswer(cmd, true, null, volumePath);
        }
        throw new CloudRuntimeException("not expecting more then  one disk after migrate volume command");
    } else if (cmd instanceof MigrateVmToPoolCommand) {
        volumeToList = volumeObjectToList;
        return new MigrateVmToPoolAnswer((MigrateVmToPoolCommand) cmd, volumeToList);
    }
    return new Answer(cmd, false, null);
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) ArrayList(java.util.ArrayList) VirtualMachineDiskInfoBuilder(com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) VirtualDisk(com.vmware.vim25.VirtualDisk) SetupPersistentNetworkAnswer(com.cloud.agent.api.SetupPersistentNetworkAnswer) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) GetVmVncTicketAnswer(com.cloud.agent.api.GetVmVncTicketAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVmNetworkStatsAnswer(com.cloud.agent.api.GetVmNetworkStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) AttachIsoAnswer(com.cloud.agent.api.AttachIsoAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) ReplugNicAnswer(com.cloud.agent.api.ReplugNicAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) GetUnmanagedInstancesAnswer(com.cloud.agent.api.GetUnmanagedInstancesAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareUnmanageVMInstanceAnswer(com.cloud.agent.api.PrepareUnmanageVMInstanceAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) MigrateVmToPoolCommand(com.cloud.agent.api.MigrateVmToPoolCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Example 5 with MigrateVolumeCommand

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

the class VmwareResource method migrateAndAnswer.

private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHypervisorHost hyperHost, Command cmd) throws Exception {
    String hostNameInTargetCluster = null;
    List<Pair<VolumeTO, StorageFilerTO>> volToFiler = new ArrayList<>();
    if (cmd instanceof MigrateVmToPoolCommand) {
        MigrateVmToPoolCommand mcmd = (MigrateVmToPoolCommand) cmd;
        hostNameInTargetCluster = mcmd.getHostGuidInTargetCluster();
        volToFiler = mcmd.getVolumeToFilerAsList();
    } else if (cmd instanceof MigrateVolumeCommand) {
        hostNameInTargetCluster = ((MigrateVolumeCommand) cmd).getHostGuidInTargetCluster();
    }
    VmwareHypervisorHost hostInTargetCluster = VmwareHelper.getHostMOFromHostName(getServiceContext(), hostNameInTargetCluster);
    try {
        // OfflineVmwareMigration: getVolumesFromCommand(cmd);
        Map<Integer, Long> volumeDeviceKey = new HashMap<>();
        if (cmd instanceof MigrateVolumeCommand) {
            // Else device keys will be found in relocateVirtualMachine
            MigrateVolumeCommand mcmd = (MigrateVolumeCommand) cmd;
            addVolumeDiskmapping(vmMo, volumeDeviceKey, mcmd.getVolumePath(), mcmd.getVolumeId());
            if (s_logger.isTraceEnabled()) {
                for (Integer diskId : volumeDeviceKey.keySet()) {
                    s_logger.trace(String.format("Disk to migrate has disk id %d and volumeId %d", diskId, volumeDeviceKey.get(diskId)));
                }
            }
        }
        List<VolumeObjectTO> volumeToList = relocateVirtualMachine(hyperHost, vmMo.getName(), null, null, hostInTargetCluster, poolUuid, volToFiler);
        return createAnswerForCmd(vmMo, volumeToList, cmd, volumeDeviceKey);
    } catch (Exception e) {
        String msg = "Change data store for VM " + vmMo.getVmName() + " failed";
        s_logger.error(msg + ": " + e.getLocalizedMessage());
        throw new CloudRuntimeException(msg, e);
    }
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) MigrateVmToPoolCommand(com.cloud.agent.api.MigrateVmToPoolCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) Pair(com.cloud.utils.Pair)

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