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


##########
plugins/storage/volume/ontap/src/main/java/org/apache/cloudstack/storage/service/StorageStrategy.java:
##########
@@ -0,0 +1,453 @@
+/*
+ * 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.utils.exception.CloudRuntimeException;
+import feign.FeignException;
+import org.apache.cloudstack.storage.feign.FeignClientFactory;
+import org.apache.cloudstack.storage.feign.client.AggregateFeignClient;
+import org.apache.cloudstack.storage.feign.client.JobFeignClient;
+import org.apache.cloudstack.storage.feign.client.NetworkFeignClient;
+import org.apache.cloudstack.storage.feign.client.SANFeignClient;
+import org.apache.cloudstack.storage.feign.client.SvmFeignClient;
+import org.apache.cloudstack.storage.feign.client.VolumeFeignClient;
+import org.apache.cloudstack.storage.feign.model.Aggregate;
+import org.apache.cloudstack.storage.feign.model.IpInterface;
+import org.apache.cloudstack.storage.feign.model.IscsiService;
+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.service.model.ProtocolType;
+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 java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+public abstract class StorageStrategy {
+    private final FeignClientFactory feignClientFactory;
+    private final AggregateFeignClient aggregateFeignClient;
+    private final VolumeFeignClient volumeFeignClient;
+    private final SvmFeignClient svmFeignClient;
+    private final JobFeignClient jobFeignClient;
+    private final NetworkFeignClient networkFeignClient;
+    private final SANFeignClient sanFeignClient;
+
+    protected OntapStorage storage;
+
+    private List<Aggregate> aggregates;
+
+    private static final Logger s_logger = 
LogManager.getLogger(StorageStrategy.class);
+
+    public StorageStrategy(OntapStorage ontapStorage) {
+        storage = ontapStorage;
+        String baseURL = Constants.HTTPS + storage.getManagementLIF();
+        s_logger.info("Initializing StorageStrategy with base URL: " + 
baseURL);
+        this.feignClientFactory = new FeignClientFactory();
+        this.aggregateFeignClient = 
feignClientFactory.createClient(AggregateFeignClient.class, baseURL);
+        this.volumeFeignClient = 
feignClientFactory.createClient(VolumeFeignClient.class, baseURL);
+        this.svmFeignClient = 
feignClientFactory.createClient(SvmFeignClient.class, baseURL);
+        this.jobFeignClient = 
feignClientFactory.createClient(JobFeignClient.class, baseURL);
+        this.networkFeignClient = 
feignClientFactory.createClient(NetworkFeignClient.class, baseURL);
+        this.sanFeignClient = 
feignClientFactory.createClient(SANFeignClient.class, baseURL);
+    }
+
+    public boolean connect() {
+        s_logger.info("Attempting to connect to ONTAP cluster at " + 
storage.getManagementLIF() + " and validate SVM " +
+                storage.getSvmName() + ", protocol " + storage.getProtocol());
+        String authHeader = Utility.generateAuthHeader(storage.getUsername(), 
storage.getPassword());
+        String svmName = storage.getSvmName();
+        try {
+            Svm svm = new Svm();
+            s_logger.info("Fetching the SVM details...");
+            Map<String, Object> queryParams = Map.of(Constants.NAME, svmName, 
Constants.FIELDS, Constants.AGGREGATES +
+                    Constants.COMMA + Constants.STATE);
+            OntapResponse<Svm> svms = 
svmFeignClient.getSvmResponse(queryParams, authHeader);
+            if (svms != null && svms.getRecords() != null && 
!svms.getRecords().isEmpty()) {
+                svm = svms.getRecords().get(0);
+            } else {
+                s_logger.error("No SVM found on the ONTAP cluster by the name" 
+ svmName + ".");
+                return false;
+            }
+
+            s_logger.info("Validating SVM state and protocol settings...");
+            if (!Objects.equals(svm.getState(), Constants.RUNNING)) {
+                s_logger.error("SVM " + svmName + " is not in running state.");
+                return false;
+            }
+            if (Objects.equals(storage.getProtocol(), Constants.NFS) && 
!svm.getNfsEnabled()) {
+                s_logger.error("NFS protocol is not enabled on SVM " + 
svmName);
+                return false;
+            } else if (Objects.equals(storage.getProtocol(), Constants.ISCSI) 
&& !svm.getIscsiEnabled()) {
+                s_logger.error("iSCSI protocol is not enabled on SVM " + 
svmName);
+                return false;

Review Comment:
   Not applicable



-- 
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