Skip to content

Commit 31044f6

Browse files
piyush5netappSrivastava, Piyush
authored andcommitted
Delete export policy NFS for the storage pool (#23)
* Delete export policy NFS * Delete export policy NFS review comments * Delete export policy NFS review comments 2 --------- Co-authored-by: Srivastava, Piyush <Piyush.Srivastava@netapp.com>
1 parent 8097526 commit 31044f6

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
3030
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
3131
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
32+
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
3233
import org.apache.cloudstack.storage.command.CreateObjectCommand;
34+
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
3335
import org.apache.cloudstack.storage.feign.FeignClientFactory;
3436
import org.apache.cloudstack.storage.feign.client.JobFeignClient;
3537
import org.apache.cloudstack.storage.feign.client.NASFeignClient;
@@ -66,6 +68,7 @@ public class UnifiedNASStrategy extends NASStrategy {
6668
private final JobFeignClient jobFeignClient;
6769
@Inject private VolumeDao volumeDao;
6870
@Inject private EndPointSelector epSelector;
71+
@Inject private StoragePoolDetailsDao storagePoolDetailsDao;
6972

7073
public UnifiedNASStrategy(OntapStorage ontapStorage) {
7174
super(ontapStorage);
@@ -132,6 +135,9 @@ public AccessGroup createAccessGroup(AccessGroup accessGroup) {
132135
s_logger.info("ExportPolicy created: {}, now attaching this policy to storage pool volume", createdPolicy.getName());
133136
// attach export policy to volume of storage pool
134137
assignExportPolicyToVolume(volumeUUID,createdPolicy.getName());
138+
// save the export policy details in storage pool details
139+
storagePoolDetailsDao.addDetail(accessGroup.getPrimaryDataStoreInfo().getId(), Constants.EXPORT_POLICY_ID, String.valueOf(createdPolicy.getId()), true);
140+
storagePoolDetailsDao.addDetail(accessGroup.getPrimaryDataStoreInfo().getId(), Constants.EXPORT_POLICY_NAME, createdPolicy.getName(), true);
135141
s_logger.info("Successfully assigned exportPolicy {} to volume {}", policyRequest.getName(), volumeName);
136142
accessGroup.setPolicy(policyRequest);
137143
return accessGroup;
@@ -143,7 +149,36 @@ public AccessGroup createAccessGroup(AccessGroup accessGroup) {
143149

144150
@Override
145151
public void deleteAccessGroup(AccessGroup accessGroup) {
146-
//TODO
152+
s_logger.info("deleteAccessGroup: Deleting export policy");
153+
154+
if (accessGroup == null) {
155+
throw new CloudRuntimeException("deleteAccessGroup: Invalid accessGroup object - accessGroup is null");
156+
}
157+
158+
// Get PrimaryDataStoreInfo from accessGroup
159+
PrimaryDataStoreInfo primaryDataStoreInfo = accessGroup.getPrimaryDataStoreInfo();
160+
if (primaryDataStoreInfo == null) {
161+
throw new CloudRuntimeException("deleteAccessGroup: PrimaryDataStoreInfo is null in accessGroup");
162+
}
163+
s_logger.info("deleteAccessGroup: Deleting export policy for the storage pool {}", primaryDataStoreInfo.getName());
164+
try {
165+
String authHeader = Utility.generateAuthHeader(storage.getUsername(), storage.getPassword());
166+
String svmName = storage.getSvmName();
167+
// Determine export policy attached to the storage pool
168+
String exportPolicyName = primaryDataStoreInfo.getDetails().get(Constants.EXPORT_POLICY_NAME);
169+
String exportPolicyId = primaryDataStoreInfo.getDetails().get(Constants.EXPORT_POLICY_ID);
170+
171+
try {
172+
nasFeignClient.deleteExportPolicyById(authHeader,exportPolicyId);
173+
s_logger.info("deleteAccessGroup: Successfully deleted export policy '{}'", exportPolicyName);
174+
} catch (Exception e) {
175+
s_logger.error("deleteAccessGroup: Failed to delete export policy. Exception: {}", e.getMessage(), e);
176+
throw new CloudRuntimeException("Failed to delete export policy: " + e.getMessage(), e);
177+
}
178+
} catch (Exception e) {
179+
s_logger.error("deleteAccessGroup: Failed to delete export policy. Exception: {}", e.getMessage(), e);
180+
throw new CloudRuntimeException("Failed to delete export policy: " + e.getMessage(), e);
181+
}
147182
}
148183

149184
@Override
@@ -340,13 +375,10 @@ private boolean updateFile(String volumeUuid, String filePath, FileInfo fileInfo
340375
}
341376
}
342377

343-
private String generateExportPolicyName(String svmName, String volumeName){
344-
return Constants.EXPORT + Constants.HYPHEN + svmName + Constants.HYPHEN + volumeName;
345-
}
346378

347379
private ExportPolicy createExportPolicyRequest(AccessGroup accessGroup,String svmName , String volumeName){
348380

349-
String exportPolicyName = generateExportPolicyName(svmName,volumeName);
381+
String exportPolicyName = Utility.generateExportPolicyName(svmName,volumeName);
350382
ExportPolicy exportPolicy = new ExportPolicy();
351383

352384
List<ExportRule> rules = new ArrayList<>();

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class Constants {
3333
public static final String MANAGEMENT_LIF = "managementLIF";
3434
public static final String VOLUME_NAME = "volumeName";
3535
public static final String VOLUME_UUID = "volumeUUID";
36+
public static final String EXPORT_POLICY_ID = "exportPolicyId";
37+
public static final String EXPORT_POLICY_NAME = "exportPolicyName";
3638
public static final String IS_DISAGGREGATED = "isDisaggregated";
3739
public static final String RUNNING = "running";
3840
public static final String EXPORT = "export";

plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/utils/Utility.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,8 @@ public static String getIgroupName(String svmName, ScopeType scopeType, Long sco
139139
//Igroup name format: cs_svmName_scopeId
140140
return Constants.CS + Constants.UNDERSCORE + svmName + Constants.UNDERSCORE + scopeType.toString().toLowerCase() + Constants.UNDERSCORE + scopeId;
141141
}
142+
143+
public static String generateExportPolicyName(String svmName, String volumeName){
144+
return Constants.EXPORT + Constants.HYPHEN + svmName + Constants.HYPHEN + volumeName;
145+
}
142146
}

0 commit comments

Comments
 (0)