JoaoJandre commented on code in PR #6699:
URL: https://github.com/apache/cloudstack/pull/6699#discussion_r1263948870


##########
server/src/main/java/com/cloud/storage/StorageManagerImpl.java:
##########
@@ -648,6 +651,38 @@ public boolean stop() {
         return true;
     }
 
+    private DataStore createLocalStorage(Map<String, Object> poolInfos) throws 
ConnectionException{
+        Object existingUuid = poolInfos.get("uuid");
+        if( existingUuid == null ){
+            poolInfos.put("uuid", UUID.randomUUID().toString());
+        }
+        String hostAddress = poolInfos.get("host").toString();
+        Host host = _hostDao.findByName(hostAddress);
+
+        if( host == null )
+            host = _hostDao.findByIp(hostAddress);
+
+        if( host == null )
+            host = _hostDao.findByPublicIp(hostAddress);
+
+        if( host == null )
+            throw new InvalidParameterValueException(String.format("host %s 
not found",hostAddress));

Review Comment:
   ```suggestion
           if( host == null ) {
               host = _hostDao.findByIp(hostAddress);
   
               if( host == null ) {
                   host = _hostDao.findByPublicIp(hostAddress);
   
                   if( host == null ) {
                       throw new 
InvalidParameterValueException(String.format("host %s not found",hostAddress));
                   }
                }
            }
   ```
   If the host is not null after `Host host = 
_hostDao.findByName(hostAddress)`, we should not check if it's null three 
times, same thing if it's not null after searching by IP. It is better to nest 
the `if`s to avoid triple/double checking needlessly.



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