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);
}
}
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);
}
Aggregations