andrijapanicsb commented on code in PR #14256:
URL: https://github.com/apache/cloudstack/pull/14256#discussion_r4199057616


##########
plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorImportHelper.java:
##########
@@ -0,0 +1,201 @@
+// 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.datastore.util;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import com.cloud.hypervisor.Hypervisor;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.linbit.linstor.api.ApiException;
+import com.linbit.linstor.api.DevelopersApi;
+import com.linbit.linstor.api.model.Node;
+import com.linbit.linstor.api.model.ResourceDefinition;
+import com.linbit.linstor.api.model.ResourceWithVolumes;
+import com.linbit.linstor.api.model.VolumeDefinition;
+import org.apache.cloudstack.storage.volume.VolumeOnStorageTO;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * Import validation must not change resource placement or live-migration 
properties.
+ * Both single-volume inspection and listing use controller metadata, never 
local DRBD devices.
+ */
+public final class LinstorImportHelper {
+    static final int PAGE_SIZE = 1000;
+
+    private LinstorImportHelper() {
+    }
+
+    private static String resourceName(String path) {
+        // CloudStack volume paths are the resource name without the cs- 
prefix, not device paths.
+        if (StringUtils.isBlank(path) || !path.matches("[a-zA-Z0-9_-]+")) {
+            throw new CloudRuntimeException("Invalid LINSTOR volume path: 
expected a resource name without a device path");
+        }
+        return LinstorUtil.RSC_PREFIX + path;
+    }
+
+    private static void requireGroup(String group) {
+        if (StringUtils.isBlank(group)) {
+            throw new CloudRuntimeException("Cannot validate LINSTOR import: 
the storage pool has no resource group");
+        }
+    }
+
+    private static List<ResourceDefinition> definitions(DevelopersApi api, 
String path) throws ApiException {
+        List<String> names = path == null ? Collections.emptyList() : 
Collections.singletonList(resourceName(path));
+        List<ResourceDefinition> result = new ArrayList<>();
+        for (int offset = 0; ; offset += PAGE_SIZE) {
+            List<ResourceDefinition> page = api.resourceDefinitionList(names, 
true, null, PAGE_SIZE, offset);

Review Comment:
   Thx @rp- fixed all 3 occurrences in ce349d813e



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