sandeeplocharla commented on code in PR #12563:
URL: https://github.com/apache/cloudstack/pull/12563#discussion_r2885632481


##########
plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/UnifiedNASStrategy.java:
##########
@@ -0,0 +1,319 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cloudstack.storage.service;
+
+import com.cloud.host.HostVO;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.utils.exception.CloudRuntimeException;
+import feign.FeignException;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
+import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
+import org.apache.cloudstack.storage.feign.FeignClientFactory;
+import org.apache.cloudstack.storage.feign.client.JobFeignClient;
+import org.apache.cloudstack.storage.feign.client.NASFeignClient;
+import org.apache.cloudstack.storage.feign.client.VolumeFeignClient;
+import org.apache.cloudstack.storage.feign.model.ExportPolicy;
+import org.apache.cloudstack.storage.feign.model.ExportRule;
+import org.apache.cloudstack.storage.feign.model.Job;
+import org.apache.cloudstack.storage.feign.model.Nas;
+import org.apache.cloudstack.storage.feign.model.OntapStorage;
+import org.apache.cloudstack.storage.feign.model.Svm;
+import org.apache.cloudstack.storage.feign.model.Volume;
+import org.apache.cloudstack.storage.feign.model.response.JobResponse;
+import org.apache.cloudstack.storage.feign.model.response.OntapResponse;
+import org.apache.cloudstack.storage.service.model.AccessGroup;
+import org.apache.cloudstack.storage.service.model.CloudStackVolume;
+import org.apache.cloudstack.storage.utils.Constants;
+import org.apache.cloudstack.storage.utils.Utility;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class UnifiedNASStrategy extends NASStrategy {
+
+    private static final Logger s_logger = 
LogManager.getLogger(UnifiedNASStrategy.class);
+    private final FeignClientFactory feignClientFactory;
+    private final NASFeignClient nasFeignClient;
+    private final VolumeFeignClient volumeFeignClient;
+    private final JobFeignClient jobFeignClient;
+    @Inject private VolumeDao volumeDao;
+    @Inject private EndPointSelector epSelector;
+    @Inject private StoragePoolDetailsDao storagePoolDetailsDao;
+
+    public UnifiedNASStrategy(OntapStorage ontapStorage) {
+        super(ontapStorage);
+        String baseURL = Constants.HTTPS + ontapStorage.getManagementLIF();
+        this.feignClientFactory = new FeignClientFactory();
+        this.nasFeignClient = 
feignClientFactory.createClient(NASFeignClient.class, baseURL);
+        this.volumeFeignClient = 
feignClientFactory.createClient(VolumeFeignClient.class,baseURL );
+        this.jobFeignClient = 
feignClientFactory.createClient(JobFeignClient.class, baseURL );
+    }
+
+    public void setOntapStorage(OntapStorage ontapStorage) {
+        this.storage = ontapStorage;
+    }
+
+    @Override
+    public CloudStackVolume createCloudStackVolume(CloudStackVolume 
cloudstackVolume) {
+        return null;
+    }
+
+    @Override
+    CloudStackVolume updateCloudStackVolume(CloudStackVolume cloudstackVolume) 
{
+        return null;
+    }
+
+    @Override
+    public void deleteCloudStackVolume(CloudStackVolume cloudstackVolume) {
+    }
+
+    @Override
+    public void copyCloudStackVolume(CloudStackVolume cloudstackVolume) {
+
+    }
+
+    @Override
+    public CloudStackVolume getCloudStackVolume(Map<String, String> 
cloudStackVolumeMap) {
+        return null;
+    }
+
+    @Override
+    public AccessGroup createAccessGroup(AccessGroup accessGroup) {
+        s_logger.info("createAccessGroup: Create access group {}: " , 
accessGroup);
+        Map<String, String> details = 
accessGroup.getPrimaryDataStoreInfo().getDetails();
+        String svmName = details.get(Constants.SVM_NAME);
+        String volumeUUID = details.get(Constants.VOLUME_UUID);
+        String volumeName = details.get(Constants.VOLUME_NAME);
+
+        ExportPolicy policyRequest = 
createExportPolicyRequest(accessGroup,svmName,volumeName);
+        try {
+            ExportPolicy createdPolicy = createExportPolicy(svmName, 
policyRequest);
+            s_logger.info("ExportPolicy created: {}, now attaching this policy 
to storage pool volume", createdPolicy.getName());
+            assignExportPolicyToVolume(volumeUUID,createdPolicy.getName());
+            
storagePoolDetailsDao.addDetail(accessGroup.getPrimaryDataStoreInfo().getId(), 
Constants.EXPORT_POLICY_ID, String.valueOf(createdPolicy.getId()), true);
+            
storagePoolDetailsDao.addDetail(accessGroup.getPrimaryDataStoreInfo().getId(), 
Constants.EXPORT_POLICY_NAME, createdPolicy.getName(), true);
+            s_logger.info("Successfully assigned exportPolicy {} to volume 
{}", policyRequest.getName(), volumeName);
+            accessGroup.setPolicy(policyRequest);
+            return accessGroup;
+        }catch(Exception e){
+            s_logger.error("Exception occurred while creating access group: " 
+  e);
+            throw new CloudRuntimeException("Failed to create access group: " 
+ e);
+        }
+    }
+
+    @Override
+    public void deleteAccessGroup(AccessGroup accessGroup) {
+        s_logger.info("deleteAccessGroup: Deleting export policy");
+
+        if (accessGroup == null) {
+            throw new CloudRuntimeException("deleteAccessGroup: Invalid 
accessGroup object - accessGroup is null");
+        }
+
+        PrimaryDataStoreInfo primaryDataStoreInfo = 
accessGroup.getPrimaryDataStoreInfo();
+        if (primaryDataStoreInfo == null) {
+            throw new CloudRuntimeException("deleteAccessGroup: 
PrimaryDataStoreInfo is null in accessGroup");
+        }
+        s_logger.info("deleteAccessGroup: Deleting export policy for the 
storage pool {}", primaryDataStoreInfo.getName());
+        try {
+            String authHeader = 
Utility.generateAuthHeader(storage.getUsername(), storage.getPassword());
+            String svmName = storage.getSvmName();
+            String exportPolicyName = 
primaryDataStoreInfo.getDetails().get(Constants.EXPORT_POLICY_NAME);
+            String exportPolicyId = 
primaryDataStoreInfo.getDetails().get(Constants.EXPORT_POLICY_ID);
+
+            try {
+                
nasFeignClient.deleteExportPolicyById(authHeader,exportPolicyId);
+                s_logger.info("deleteAccessGroup: Successfully deleted export 
policy '{}'", exportPolicyName);

Review Comment:
   Addressed it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to