cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] rafaelweingartner commented on a change in pull request #2315: A comprehensive solution for #CLOUDSTACK-9025.
Date Thu, 01 Jan 1970 00:00:00 GMT
rafaelweingartner commented on a change in pull request #2315: A comprehensive solution for
#CLOUDSTACK-9025.
URL: https://github.com/apache/cloudstack/pull/2315#discussion_r150219895
 
 

 ##########
 File path: plugins/hypervisors/xenserver/src/com/cloud/hypervisor/XenServerGuru.java
 ##########
 @@ -167,35 +170,61 @@ public boolean trackVmHostChange() {
 
     @Override
     public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
-        LOGGER.debug("getCommandHostDelegation: " + cmd.getClass());
         if (cmd instanceof StorageSubSystemCommand) {
             StorageSubSystemCommand c = (StorageSubSystemCommand)cmd;
             c.setExecuteInSequence(true);
         }
-        if (cmd instanceof CopyCommand) {
-            CopyCommand cpyCommand = (CopyCommand)cmd;
-            DataTO srcData = cpyCommand.getSrcTO();
-            DataTO destData = cpyCommand.getDestTO();
-
-            if (srcData.getHypervisorType() == HypervisorType.XenServer && srcData.getObjectType()
== DataObjectType.SNAPSHOT &&
-                    destData.getObjectType() == DataObjectType.TEMPLATE) {
-                DataStoreTO srcStore = srcData.getDataStore();
-                DataStoreTO destStore = destData.getDataStore();
-                if (srcStore instanceof NfsTO && destStore instanceof NfsTO) {
-                    HostVO host = hostDao.findById(hostId);
-                    hostDao.loadDetails(host);
-                    String hypervisorVersion = host.getHypervisorVersion();
-                    String snapshotHotFixVersion = host.getDetail(XenserverConfigs.XS620HotFix);
-                    if (hypervisorVersion != null && !hypervisorVersion.equalsIgnoreCase("6.1.0"))
{
-                        if (!(hypervisorVersion.equalsIgnoreCase("6.2.0") &&
-                                !(snapshotHotFixVersion != null && snapshotHotFixVersion.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004))))
{
-                            return new Pair<Boolean, Long>(Boolean.TRUE, new Long(host.getId()));
-                        }
-                    }
-                }
-            }
+        boolean isCopyCommand = cmd instanceof CopyCommand;
+        Pair<Boolean, Long> defaultHostToExecuteCommands = super.getCommandHostDelegation(hostId,
cmd);
+        if (!isCopyCommand) {
+            logger.debug("We are returning the default host to execute commands because the
command is not of Copy type.");
+            return defaultHostToExecuteCommands;
+        }
+        CopyCommand copyCommand = (CopyCommand)cmd;
+        DataTO srcData = copyCommand.getSrcTO();
+        DataTO destData = copyCommand.getDestTO();
+
+        boolean isSourceDataHypervisorXenServer = srcData.getHypervisorType() == HypervisorType.XenServer;
+        if (!isSourceDataHypervisorXenServer) {
+            logger.debug("We are returning the default host to execute commands because the
target hypervisor of the source data is not XenServer.");
+            return defaultHostToExecuteCommands;
+        }
+        DataStoreTO srcStore = srcData.getDataStore();
+        DataStoreTO destStore = destData.getDataStore();
+        boolean isSourceAndDestinationNfsObjects = srcStore instanceof NfsTO && destStore
instanceof NfsTO;
+        if (!isSourceAndDestinationNfsObjects) {
+            logger.debug("We are returning the default host to execute commands because the
source and destination objects are not NFS type.");
+            return defaultHostToExecuteCommands;
+        }
+        boolean isSourceObjectSnapshotTypeAndDestinationObjectTemplateType = srcData.getObjectType()
== DataObjectType.SNAPSHOT
+                && destData.getObjectType() == DataObjectType.TEMPLATE;
+        if (!isSourceObjectSnapshotTypeAndDestinationObjectTemplateType) {
+            logger.debug("We are returning the default host to execute commands because the
source and destination objects are not snapshot and template respectively.");
+            return defaultHostToExecuteCommands;
+        }
+        long snapshotId = srcData.getId();
+        HostVO hostCandidateToExecutedCommand = hostDao.findHostConnectedToSnapshotStoragePoolToExecuteCommand(snapshotId);
+        hostDao.loadDetails(hostCandidateToExecutedCommand);
+        String hypervisorVersion = hostCandidateToExecutedCommand.getHypervisorVersion();
+        if (StringUtils.isBlank(hypervisorVersion)) {
+            logger.debug("We are returning the default host to execute commands because the
hypervisor version is blank.");
+            return defaultHostToExecuteCommands;
+        }
+        boolean isXenServer610 = StringUtils.equals(hypervisorVersion, "6.1.0");
+        if (isXenServer610) {
+            logger.debug("We are returning the default host to execute commands because the
hypervisor version is 6.1.0.");
+            return defaultHostToExecuteCommands;
+        }
+        String snapshotHotFixVersion = hostCandidateToExecutedCommand.getDetail(XenserverConfigs.XS620HotFix);
+        boolean isXenServer620 = StringUtils.equals(hypervisorVersion, "6.2.0");
+        if (isXenServer620 && !StringUtils.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004,
snapshotHotFixVersion)) {
 
 Review comment:
   I have no idea :)
   I only re-worked the code, the logic here is the same. I made sure everything was kept
the same with test cases.
   The result of this code is the same as the replace one. The difference is that I am not
using those if/if/if/if/if.....

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services

Mime
View raw message