You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2020/12/21 08:36:04 UTC

[GitHub] [cloudstack] DaanHoogland commented on a change in pull request #4553: Fix for mapping guest OS type read from OVF to existing guest OS in C…

DaanHoogland commented on a change in pull request #4553:
URL: https://github.com/apache/cloudstack/pull/4553#discussion_r546565799



##########
File path: utils/src/main/java/com/cloud/utils/StringUtils.java
##########
@@ -313,4 +313,42 @@ public static String mapToString(final Map<String, String> map) {
     public static String toCSVList(final List<String> csvList) {
         return join(csvList, ",");
     }
+
+    public static int min(int x, int y, int z)
+    {
+        if (x <= y && x <= z)
+            return x;
+        if (y <= x && y <= z)

Review comment:
       ```suggestion
           if (y <= z)
   ```

##########
File path: engine/storage/src/main/java/org/apache/cloudstack/storage/image/deployasis/DeployAsIsHelperImpl.java
##########
@@ -174,8 +174,26 @@ private void handleGuestOsFromOVFDescriptor(long templateId, String guestOsType,
                 hypervisor.toString(), minimumHypervisorVersion);
 
         if (CollectionUtils.isNotEmpty(guestOsMappings)) {
-            GuestOSHypervisorVO mapping = guestOsMappings.get(0);
-            long guestOsId = mapping.getGuestOsId();
+            Long guestOsId = null;
+            if (guestOsMappings.size() == 1) {
+                GuestOSHypervisorVO mapping = guestOsMappings.get(0);
+                guestOsId = mapping.getGuestOsId();
+            } else {
+                if (!StringUtils.isEmpty(guestOsDescription)) {
+                    int minimumEdits = Integer.MAX_VALUE;
+                    for (GuestOSHypervisorVO guestOSHypervisorVO : guestOsMappings) {

Review comment:
       some small worry here. I'm not sure it applies to guestos names, but linguistically this can yield false positives easily;
   - "van os"
   - "vanos"
   - "fan nos"
   - "vamos"
   - "fam. os"
   with the bare eye the last one is the proper replacement of the first. Would this algorithm yield this?

##########
File path: utils/src/main/java/com/cloud/utils/StringUtils.java
##########
@@ -313,4 +313,42 @@ public static String mapToString(final Map<String, String> map) {
     public static String toCSVList(final List<String> csvList) {
         return join(csvList, ",");
     }
+
+    public static int min(int x, int y, int z)
+    {
+        if (x <= y && x <= z)
+            return x;
+        if (y <= x && y <= z)
+            return y;
+        else
+            return z;
+    }
+
+    /**
+     * Calculates minimum number of edits required to convert from one string to another string.
+     * @param str1
+     *      String that needs editing
+     * @param str2
+     *      Target string that needs after editing
+     * @return minimum number of edits required to convert str1 to str2
+     */
+    public static int minimumEditDistance(String str1, String str2) {

Review comment:
       can we have some unit tests for this, please?
   I think it assumes a definition of what an edit is, that we need to make explicit as well. 

##########
File path: utils/src/main/java/com/cloud/utils/StringUtils.java
##########
@@ -313,4 +313,42 @@ public static String mapToString(final Map<String, String> map) {
     public static String toCSVList(final List<String> csvList) {
         return join(csvList, ",");
     }
+
+    public static int min(int x, int y, int z)
+    {
+        if (x <= y && x <= z)
+            return x;
+        if (y <= x && y <= z)
+            return y;
+        else
+            return z;
+    }
+
+    /**
+     * Calculates minimum number of edits required to convert from one string to another string.
+     * @param str1
+     *      String that needs editing
+     * @param str2
+     *      Target string that needs after editing

Review comment:
       ```suggestion
        * @param str1     String that needs editing
        * @param str2     Target string that is required/expected after editing
   ```




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org