BryanMLima commented on code in PR #7659:
URL: https://github.com/apache/cloudstack/pull/7659#discussion_r1389664545


##########
server/src/main/java/com/cloud/storage/StorageManagerImpl.java:
##########
@@ -1882,6 +1894,65 @@ public StoragePool syncStoragePool(SyncStoragePoolCmd 
cmd) {
         return (PrimaryDataStoreInfo) _dataStoreMgr.getDataStore(pool.getId(), 
DataStoreRole.Primary);
     }
 
+
+    @Override
+    public Heuristic 
createSecondaryStorageHeuristic(CreateSecondaryStorageSelectorCmd cmd) {
+        String name = cmd.getName();
+        String description = cmd.getDescription();
+        long zoneId = cmd.getZoneId();
+        String heuristicRule = cmd.getHeuristicRule();
+        String purpose = cmd.getPurpose();
+        HeuristicPurpose formattedPurpose = 
EnumUtils.getEnumIgnoreCase(HeuristicPurpose.class, purpose);
+
+        if (formattedPurpose == null) {
+            throw new IllegalArgumentException(String.format("The given 
heuristic purpose [%s] is not valid for creating a new secondary storage 
selector." +
+                    " The valid options are %s.", purpose, 
Arrays.asList(HeuristicPurpose.values())));
+        }
+
+        HeuristicVO heuristic = 
secondaryStorageHeuristicDao.findByZoneIdAndPurpose(zoneId, formattedPurpose);

Review Comment:
   As mentioned, the method `findOneIncludingRemovedBy` only retrieves 
non-removed entries; therefore, this scenario does not occur.



##########
engine/schema/src/main/java/org/apache/cloudstack/secstorage/dao/SecondaryStorageHeuristicDaoImpl.java:
##########
@@ -0,0 +1,50 @@
+// 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.secstorage.dao;
+
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import org.apache.cloudstack.secstorage.HeuristicVO;
+import org.apache.cloudstack.secstorage.heuristics.HeuristicPurpose;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+
+@Component
+public class SecondaryStorageHeuristicDaoImpl extends 
GenericDaoBase<HeuristicVO, Long> implements SecondaryStorageHeuristicDao {
+    private SearchBuilder<HeuristicVO> zoneAndPurposeSearch;
+
+    @PostConstruct
+    public void init() {
+        zoneAndPurposeSearch = createSearchBuilder();
+        zoneAndPurposeSearch.and("zoneId", 
zoneAndPurposeSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
+        zoneAndPurposeSearch.and("purpose", 
zoneAndPurposeSearch.entity().getPurpose(), SearchCriteria.Op.IN);
+        zoneAndPurposeSearch.done();
+    }
+
+    @Override
+    public HeuristicVO findByZoneIdAndPurpose(long zoneId, HeuristicPurpose 
purpose) {
+        SearchCriteria<HeuristicVO> searchCriteria = 
zoneAndPurposeSearch.create();
+        searchCriteria.setParameters("zoneId", zoneId);
+        searchCriteria.setParameters("purpose", purpose.toString());
+        final Filter filter = new Filter(HeuristicVO.class, "created", false);
+
+        return findOneIncludingRemovedBy(searchCriteria, filter);

Review Comment:
   The method name is wrong, its behaviour is as expected, only retrieving 
heuristic rules with removed null.



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