Search in sources :

Example 1 with MigrateVmToPoolAnswer

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

the class VirtualMachineManagerImpl method markVolumesInPool.

private void markVolumesInPool(VMInstanceVO vm, Answer[] hypervisorMigrationResults) {
    MigrateVmToPoolAnswer relevantAnswer = null;
    if (hypervisorMigrationResults.length == 1 && !hypervisorMigrationResults[0].getResult()) {
        throw new CloudRuntimeException(String.format("VM ID: %s migration failed. %s", vm.getUuid(), hypervisorMigrationResults[0].getDetails()));
    }
    for (Answer answer : hypervisorMigrationResults) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(String.format("Received an %s: %s", answer.getClass().getSimpleName(), answer));
        }
        if (answer instanceof MigrateVmToPoolAnswer) {
            relevantAnswer = (MigrateVmToPoolAnswer) answer;
        }
    }
    if (relevantAnswer == null) {
        throw new CloudRuntimeException("No relevant migration results found");
    }
    List<VolumeObjectTO> results = relevantAnswer.getVolumeTos();
    if (results == null) {
        results = new ArrayList<>();
    }
    List<VolumeVO> volumes = _volsDao.findUsableVolumesForInstance(vm.getId());
    if (s_logger.isDebugEnabled()) {
        String msg = String.format("Found %d volumes for VM %s(uuid:%s, id:%d)", results.size(), vm.getInstanceName(), vm.getUuid(), vm.getId());
        s_logger.debug(msg);
    }
    for (VolumeObjectTO result : results) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(String.format("Updating volume (%d) with path '%s' on pool '%s'", result.getId(), result.getPath(), result.getDataStoreUuid()));
        }
        VolumeVO volume = _volsDao.findById(result.getId());
        StoragePool pool = _storagePoolDao.findPoolByUUID(result.getDataStoreUuid());
        if (volume == null || pool == null) {
            continue;
        }
        volume.setPath(result.getPath());
        volume.setPoolId(pool.getId());
        if (result.getChainInfo() != null) {
            volume.setChainInfo(result.getChainInfo());
        }
        _volsDao.update(volume.getId(), volume);
    }
}
Also used : MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) ReplugNicAnswer(com.cloud.agent.api.ReplugNicAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.agent.api.ClusterVMMetaDataSyncAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateVmToPoolAnswer(com.cloud.agent.api.MigrateVmToPoolAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO)

Example 2 with MigrateVmToPoolAnswer

use of com.cloud.agent.api.MigrateVmToPoolAnswer 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)

Aggregations

Answer (com.cloud.agent.api.Answer)2 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)2 MigrateVmToPoolAnswer (com.cloud.agent.api.MigrateVmToPoolAnswer)2 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)2 PrepareForMigrationAnswer (com.cloud.agent.api.PrepareForMigrationAnswer)2 RebootAnswer (com.cloud.agent.api.RebootAnswer)2 ReplugNicAnswer (com.cloud.agent.api.ReplugNicAnswer)2 StartAnswer (com.cloud.agent.api.StartAnswer)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 AttachIsoAnswer (com.cloud.agent.api.AttachIsoAnswer)1 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)1 CheckOnHostAnswer (com.cloud.agent.api.CheckOnHostAnswer)1 ClusterVMMetaDataSyncAnswer (com.cloud.agent.api.ClusterVMMetaDataSyncAnswer)1 CreateVMSnapshotAnswer (com.cloud.agent.api.CreateVMSnapshotAnswer)1 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)1 DeleteVMSnapshotAnswer (com.cloud.agent.api.DeleteVMSnapshotAnswer)1 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)1 GetStoragePoolCapabilitiesAnswer (com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer)1