|
19 | 19 |
|
20 | 20 | package org.apache.cloudstack.storage.service; |
21 | 21 |
|
22 | | -import com.cloud.host.HostVO; |
23 | 22 | import com.cloud.utils.exception.CloudRuntimeException; |
24 | 23 | import feign.FeignException; |
25 | 24 | import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; |
@@ -116,27 +115,60 @@ CloudStackVolume getCloudStackVolume(CloudStackVolume cloudstackVolume) { |
116 | 115 | @Override |
117 | 116 | public AccessGroup createAccessGroup(AccessGroup accessGroup) { |
118 | 117 |
|
119 | | -// Map<String, String> details = accessGroup.getPrimaryDataStoreInfo().getDetails(); |
120 | | -// String svmName = details.get(Constants.SVM_NAME); |
121 | | -// String volumeUUID = details.get(Constants.VOLUME_UUID); |
122 | | -// String volumeName = details.get(Constants.VOLUME_NAME); |
123 | | -// |
124 | | -// // Create the export policy |
125 | | -// ExportPolicy policyRequest = createExportPolicyRequest(accessGroup,svmName,volumeName); |
126 | | -// try { |
127 | | -// createExportPolicy(svmName, policyRequest); |
128 | | -// s_logger.info("ExportPolicy created: {}, now attaching this policy to storage pool volume", policyRequest.getName()); |
129 | | -// |
130 | | -// // attach export policy to volume of storage pool |
131 | | -// assignExportPolicyToVolume(volumeUUID,policyRequest.getName()); |
132 | | -// s_logger.info("Successfully assigned exportPolicy {} to volume {}", policyRequest.getName(), volumeName); |
133 | | -// accessGroup.setPolicy(policyRequest); |
134 | | -// return accessGroup; |
135 | | -// }catch(Exception e){ |
136 | | -// s_logger.error("Exception occurred while creating access group: " + e); |
137 | | -// throw new CloudRuntimeException("Failed to create access group: " + e); |
138 | | -// } |
139 | | - return null; |
| 118 | + Map<String, String> storagePooldetails = accessGroup.getStoragePooldetails(); |
| 119 | + String svmName = storagePooldetails.get(Constants.SVM_NAME); |
| 120 | + Map<String, String> volumedetails = accessGroup.getVolumedetails(); |
| 121 | + String volumeUUID = volumedetails.get(Constants.VOLUME_UUID); |
| 122 | + String volumeName = volumedetails.get(Constants.VOLUME_NAME); |
| 123 | + |
| 124 | + // Create the export policy |
| 125 | + ExportPolicy policyRequest = createExportPolicyRequest(accessGroup,svmName,volumeName); |
| 126 | + try { |
| 127 | + createExportPolicy(svmName, policyRequest); |
| 128 | + s_logger.info("ExportPolicy created: {}, now attaching this policy to storage pool volume", policyRequest.getName()); |
| 129 | + String sanitizedName = volumeUUID.replace('-', '_'); |
| 130 | + String ontapVolumeName = "cs_vol_" + sanitizedName; |
| 131 | + // get the volume from ontap using name |
| 132 | + try { |
| 133 | + // Get the AuthHeader |
| 134 | + String authHeader = Utility.generateAuthHeader(storage.getUsername(), storage.getPassword()); |
| 135 | + Map<String, Object> queryParams = Map.of(Constants.NAME, ontapVolumeName); |
| 136 | + s_logger.debug("Fetching volume details for: " + volumeName); |
| 137 | + |
| 138 | + OntapResponse<Volume> ontapVolume = volumeFeignClient.getVolume(authHeader, queryParams); |
| 139 | + s_logger.debug("Feign call completed. Processing response..."); |
| 140 | + |
| 141 | + if (ontapVolume == null) { |
| 142 | + s_logger.error("OntapResponse is null for volume: " + volumeName); |
| 143 | + throw new CloudRuntimeException("Failed to fetch volume " + volumeName + ": Response is null"); |
| 144 | + } |
| 145 | + s_logger.debug("OntapResponse is not null. Checking records field..."); |
| 146 | + |
| 147 | + if (ontapVolume.getRecords() == null) { |
| 148 | + s_logger.error("OntapResponse.records is null for volume: " + volumeName); |
| 149 | + throw new CloudRuntimeException("Failed to fetch volume " + volumeName + ": Records list is null"); |
| 150 | + } |
| 151 | + s_logger.debug("Records field is not null. Size: " + ontapVolume.getRecords().size()); |
| 152 | + |
| 153 | + if (ontapVolume.getRecords().isEmpty()) { |
| 154 | + s_logger.error("OntapResponse.records is empty for volume: " + volumeName); |
| 155 | + throw new CloudRuntimeException("Failed to fetch volume " + volumeName + ": No records found"); |
| 156 | + } |
| 157 | + Volume onpvolume = ontapVolume.getRecords().get(0); |
| 158 | + s_logger.info("Volume retrieved successfully: " + volumeName + ", UUID: " + onpvolume.getUuid()); |
| 159 | + // attach export policy to volume of storage pool |
| 160 | + assignExportPolicyToVolume(onpvolume.getUuid(),policyRequest.getName()); |
| 161 | + s_logger.info("Successfully assigned exportPolicy {} to volume {}", policyRequest.getName(), volumeName); |
| 162 | + accessGroup.setPolicy(policyRequest); |
| 163 | + return accessGroup; |
| 164 | + } catch (Exception e) { |
| 165 | + s_logger.error("Exception while retrieving volume details for: " + volumeName, e); |
| 166 | + throw new CloudRuntimeException("Failed to fetch volume: " + volumeName + ". Error: " + e.getMessage(), e); |
| 167 | + } |
| 168 | + }catch(Exception e){ |
| 169 | + s_logger.error("Exception occurred while creating access group: " + e); |
| 170 | + throw new CloudRuntimeException("Failed to create access group: " + e); |
| 171 | + } |
140 | 172 | } |
141 | 173 |
|
142 | 174 | @Override |
@@ -374,17 +406,21 @@ private ExportPolicy createExportPolicyRequest(AccessGroup accessGroup,String sv |
374 | 406 | ExportRule exportRule = new ExportRule(); |
375 | 407 |
|
376 | 408 | List<ExportRule.ExportClient> exportClients = new ArrayList<>(); |
377 | | - List<HostVO> hosts = accessGroup.getHostsToConnect(); |
378 | | - for (HostVO host : hosts) { |
379 | | - String hostStorageIp = host.getStorageIpAddress(); |
380 | | - String ip = (hostStorageIp != null && !hostStorageIp.isEmpty()) |
381 | | - ? hostStorageIp |
382 | | - : host.getPrivateIpAddress(); |
383 | | - String ipToUse = ip + "/31"; |
384 | | - ExportRule.ExportClient exportClient = new ExportRule.ExportClient(); |
385 | | - exportClient.setMatch(ipToUse); |
386 | | - exportClients.add(exportClient); |
387 | | - } |
| 409 | +// List<HostVO> hosts = accessGroup.getHostsToConnect(); |
| 410 | +// for (HostVO host : hosts) { |
| 411 | +// String hostStorageIp = host.getStorageIpAddress(); |
| 412 | +// String ip = (hostStorageIp != null && !hostStorageIp.isEmpty()) |
| 413 | +// ? hostStorageIp |
| 414 | +// : host.getPrivateIpAddress(); |
| 415 | +// String ipToUse = ip + "/31"; |
| 416 | +// ExportRule.ExportClient exportClient = new ExportRule.ExportClient(); |
| 417 | +// exportClient.setMatch(ipToUse); |
| 418 | +// exportClients.add(exportClient); |
| 419 | +// } |
| 420 | + |
| 421 | + ExportRule.ExportClient exportClient = new ExportRule.ExportClient(); |
| 422 | + String ipToUse = "0.0.0.0/0"; |
| 423 | + exportClient.setMatch(ipToUse); |
388 | 424 | exportRule.setClients(exportClients); |
389 | 425 | exportRule.setProtocols(List.of(ExportRule.ProtocolsEnum.any)); |
390 | 426 | exportRule.setRoRule(List.of("sys")); // Use sys (Unix UID/GID) authentication for NFS |
|
0 commit comments