|
26 | 26 | import com.cloud.storage.dao.VolumeDao; |
27 | 27 | import com.cloud.utils.exception.CloudRuntimeException; |
28 | 28 | import feign.FeignException; |
| 29 | +import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; |
29 | 30 | import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; |
30 | 31 | import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; |
31 | | -import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; |
32 | 32 | import org.apache.cloudstack.storage.command.CreateObjectCommand; |
33 | 33 | import org.apache.cloudstack.storage.feign.FeignClientFactory; |
34 | 34 | import org.apache.cloudstack.storage.feign.client.JobFeignClient; |
|
48 | 48 | import org.apache.cloudstack.storage.service.model.CloudStackVolume; |
49 | 49 | import org.apache.cloudstack.storage.utils.Constants; |
50 | 50 | import org.apache.cloudstack.storage.utils.Utility; |
| 51 | +import org.apache.cloudstack.storage.volume.VolumeObject; |
51 | 52 | import org.apache.logging.log4j.LogManager; |
52 | 53 | import org.apache.logging.log4j.Logger; |
53 | 54 |
|
@@ -82,16 +83,21 @@ public void setOntapStorage(OntapStorage ontapStorage) { |
82 | 83 | @Override |
83 | 84 | public CloudStackVolume createCloudStackVolume(CloudStackVolume cloudstackVolume) { |
84 | 85 | s_logger.info("createCloudStackVolume: Create cloudstack volume " + cloudstackVolume); |
85 | | - // Step 1: set cloudstack volume metadata |
86 | | - String volumeUuid = updateCloudStackVolumeMetadata(cloudstackVolume.getDatastoreId(), cloudstackVolume.getVolumeInfo()); |
87 | | - // Step 2: Send command to KVM host to create qcow2 file using qemu-img |
88 | | - Answer answer = createVolumeOnKVMHost(cloudstackVolume.getVolumeInfo()); |
| 86 | + try { |
| 87 | + // Step 1: set cloudstack volume metadata |
| 88 | + String volumeUuid = updateCloudStackVolumeMetadata(cloudstackVolume.getDatastoreId(), cloudstackVolume.getVolumeInfo()); |
| 89 | + // Step 2: Send command to KVM host to create qcow2 file using qemu-img |
| 90 | + Answer answer = createVolumeOnKVMHost(cloudstackVolume.getVolumeInfo()); |
89 | 91 | if (answer == null || !answer.getResult()) { |
90 | 92 | String errMsg = answer != null ? answer.getDetails() : "Failed to create qcow2 on KVM host"; |
91 | 93 | s_logger.error("createCloudStackVolumeForTypeVolume: " + errMsg); |
92 | 94 | throw new CloudRuntimeException(errMsg); |
93 | 95 | } |
94 | 96 | return cloudstackVolume; |
| 97 | + }catch (Exception e) { |
| 98 | + s_logger.error("createCloudStackVolumeForTypeVolume: error occured " + e); |
| 99 | + throw new CloudRuntimeException(e); |
| 100 | + } |
95 | 101 | } |
96 | 102 |
|
97 | 103 | @Override |
@@ -374,18 +380,29 @@ private ExportPolicy createExportPolicyRequest(AccessGroup accessGroup,String sv |
374 | 380 | return exportPolicy; |
375 | 381 | } |
376 | 382 |
|
377 | | - private String updateCloudStackVolumeMetadata(String dataStoreId, VolumeInfo volumeInfo) { |
378 | | - s_logger.info("createManagedNfsVolume called with datastoreID: {} volumeInfo: {} ", dataStoreId, volumeInfo ); |
379 | | - VolumeVO volume = volumeDao.findById(volumeInfo.getId()); |
380 | | - String volumeUuid = volumeInfo.getUuid(); |
381 | | - volume.setPoolType(Storage.StoragePoolType.NetworkFilesystem); |
382 | | - volume.setPoolId(Long.parseLong(dataStoreId)); //need to check if volume0 already has this data filled |
383 | | - volume.setPath(volumeUuid); // Filename for qcow2 file |
384 | | - volumeDao.update(volume.getId(), volume); |
385 | | - return volumeUuid; |
| 383 | + private String updateCloudStackVolumeMetadata(String dataStoreId, DataObject volumeInfo) { |
| 384 | + s_logger.info("updateCloudStackVolumeMetadata called with datastoreID: {} volumeInfo: {} ", dataStoreId, volumeInfo ); |
| 385 | + try { |
| 386 | + VolumeObject volumeObject = (VolumeObject) volumeInfo; |
| 387 | + long volumeId = volumeObject.getId(); |
| 388 | + s_logger.info("VolumeInfo ID from VolumeObject: {}", volumeId); |
| 389 | + VolumeVO volume = volumeDao.findById(volumeId); |
| 390 | + if (volume == null) { |
| 391 | + throw new CloudRuntimeException("Volume not found with id: " + volumeId); |
| 392 | + } |
| 393 | + String volumeUuid = volumeInfo.getUuid(); |
| 394 | + volume.setPoolType(Storage.StoragePoolType.NetworkFilesystem); |
| 395 | + volume.setPoolId(Long.parseLong(dataStoreId)); |
| 396 | + volume.setPath(volumeUuid); // Filename for qcow2 file |
| 397 | + volumeDao.update(volume.getId(), volume); |
| 398 | + return volumeUuid; |
| 399 | + }catch (Exception e){ |
| 400 | + s_logger.error("Exception while updating volumeInfo: {} in volume: {}", dataStoreId, volumeInfo.getUuid(), e); |
| 401 | + throw new CloudRuntimeException("Exception while updating volumeInfo: " + e.getMessage()); |
| 402 | + } |
386 | 403 | } |
387 | 404 |
|
388 | | - private Answer createVolumeOnKVMHost(VolumeInfo volumeInfo) { |
| 405 | + private Answer createVolumeOnKVMHost(DataObject volumeInfo) { |
389 | 406 | s_logger.info("createVolumeOnKVMHost called with volumeInfo: {} ", volumeInfo); |
390 | 407 |
|
391 | 408 | try { |
|
0 commit comments