Roy Golan has uploaded a new change for review.

Change subject: core: IrsProxy selection code cleanup
......................................................................

core: IrsProxy selection code cleanup

* break long methods
* remove unused, useless variables

further cleanup should be made to the rest of the classes

Change-Id: Icc94288f209b015c4384630990fe561e43aebbbf
Signed-off-by: Roy Golan <rgo...@redhat.com>
---
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java
1 file changed, 87 insertions(+), 72 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/28/20528/1

diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java
index 264ccd3..2d71a1f 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/irsbroker/IrsBrokerCommand.java
@@ -576,7 +576,6 @@
         }
 
         private String gethostFromVds() {
-            String returnValue = null;
             Guid curVdsId = (mCurrentVdsId != null) ? mCurrentVdsId : 
Guid.Empty;
             StoragePool storagePool = 
DbFacade.getInstance().getStoragePoolDao().get(_storagePoolId);
 
@@ -591,7 +590,19 @@
             // If VDS is in initialize status, wait for it to be up (or until
             // configurable timeout is reached)
             waitForVdsIfIsInitializing(curVdsId);
-            // update pool status to problematic while selecting spm
+
+            setPoolToNonResponsiveWhileSelecting();
+
+            VDS selectedVds = selectVds(curVdsId, prioritizedVdsInPool);
+
+            if (selectedVds != null) {
+                return checkSpmStatus(curVdsId, storagePool, 
prioritizedVdsInPool, storagePool.getStatus(), selectedVds);
+            } else {
+                return null;
+            }
+        }
+
+        private void setPoolToNonResponsiveWhileSelecting() {
             try {
                 ResourceManager
                         .getInstance()
@@ -602,9 +613,10 @@
             } catch (RuntimeException ex) {
                 throw new IRSStoragePoolStatusException(ex);
             }
-            VDS selectedVds = null;
-            SpmStatusResult spmStatus = null;
+        }
 
+        private VDS selectVds(Guid curVdsId, List<VDS> prioritizedVdsInPool) {
+            VDS selectedVds = null;
             if (prioritizedVdsInPool != null && prioritizedVdsInPool.size() > 
0) {
                 selectedVds = prioritizedVdsInPool.get(0);
             } else if (!Guid.Empty.equals(curVdsId) && 
!getTriedVdssList().contains(curVdsId)) {
@@ -614,80 +626,83 @@
                     selectedVds = null;
                 }
             }
+            return selectedVds;
+        }
 
-            if (selectedVds != null) {
-                // Stores origin host id in case and will be needed to 
disconnect from storage pool
-                Guid selectedVdsId = selectedVds.getId();
-                Integer selectedVdsSpmId = selectedVds.getVdsSpmId();
-                mTriedVdssList.add(selectedVdsId);
 
-                VDSReturnValue returnValueFromVds = 
ResourceManager.getInstance().runVdsCommand(
-                        VDSCommandType.SpmStatus,
-                        new SpmStatusVDSCommandParameters(selectedVds.getId(), 
_storagePoolId));
-                spmStatus = (SpmStatusResult) 
returnValueFromVds.getReturnValue();
-                if (spmStatus != null) {
-                    mCurrentVdsId = selectedVds.getId();
-                    boolean performedPoolConnect = false;
-                    log.infoFormat("hostFromVds::selectedVds - {0}, spmStatus 
{1}, storage pool {2}",
-                            selectedVds.getName(), 
spmStatus.getSpmStatus().toString(), storagePool.getName());
-                    if (spmStatus.getSpmStatus() == SpmStatus.Unknown_Pool) {
-                        Guid masterId = 
DbFacade.getInstance().getStorageDomainDao()
-                                
.getMasterStorageDomainIdForPool(_storagePoolId);
-                        VDSReturnValue connectResult = 
ResourceManager.getInstance().runVdsCommand(
-                                VDSCommandType.ConnectStoragePool,
-                                new 
ConnectStoragePoolVDSCommandParameters(selectedVds.getId(), _storagePoolId,
-                                        selectedVds.getVdsSpmId(), masterId, 
storagePool.getmaster_domain_version()));
-                        if (!connectResult.getSucceeded()
-                                && connectResult.getExceptionObject() 
instanceof IRSNoMasterDomainException) {
-                            throw connectResult.getExceptionObject();
-                        } else if (!connectResult.getSucceeded()) {
-                            // if connect to pool fails throw exception for
-                            // failover
-                            throw new IRSNonOperationalException("Could not 
connect host to Data Center(Storage issue)");
-                        }
-                        performedPoolConnect = true;
-                        // refresh spmStatus result
-                        spmStatus = (SpmStatusResult) ResourceManager
-                                .getInstance()
-                                .runVdsCommand(VDSCommandType.SpmStatus,
-                                        new 
SpmStatusVDSCommandParameters(selectedVds.getId(), _storagePoolId))
-                                .getReturnValue();
-                        log.infoFormat(
-                                "hostFromVds::Connected host to pool - 
selectedVds - {0}, spmStatus {1}, storage pool {2}",
-                                selectedVds.getName(),
-                                spmStatus.getSpmStatus().toString(),
-                                storagePool.getName());
-                    }
-                    RefObject<VDS> tempRefObject = new 
RefObject<VDS>(selectedVds);
-                    spmStatus =
-                            handleSpmStatusResult(curVdsId, 
prioritizedVdsInPool, storagePool, tempRefObject, spmStatus);
-                    selectedVds = tempRefObject.argvalue;
+        private String checkSpmStatus(Guid curVdsId, StoragePool storagePool, 
List<VDS> prioritizedVdsInPool, StoragePoolStatus prevStatus, VDS selectedVds) {
+            String returnValue = null;
+            SpmStatusResult spmStatus;// Stores orig in host id in case and 
will be needed to disconnect from storage pool
+            Guid selectedVdsId = selectedVds.getId();
+            Integer selectedVdsSpmId = selectedVds.getVdsSpmId();
+            mTriedVdssList.add(selectedVdsId);
 
-                    if (selectedVds != null) {
-                        RefObject<VDS> tempRefObject2 = new 
RefObject<VDS>(selectedVds);
-                        RefObject<SpmStatusResult> tempRefObject3 = new 
RefObject<SpmStatusResult>(spmStatus);
-                        returnValue = handleSelectedVdsForSPM(storagePool, 
tempRefObject2, tempRefObject3, storagePool.getStatus());
-                        selectedVds = tempRefObject2.argvalue;
-                        spmStatus = tempRefObject3.argvalue;
-                    } else {
-                        mCurrentVdsId = null;
+            VDSReturnValue returnValueFromVds = 
ResourceManager.getInstance().runVdsCommand(
+                    VDSCommandType.SpmStatus,
+                    new SpmStatusVDSCommandParameters(selectedVds.getId(), 
_storagePoolId));
+            spmStatus = (SpmStatusResult) returnValueFromVds.getReturnValue();
+
+            if (spmStatus != null) {
+                mCurrentVdsId = selectedVds.getId();
+                boolean performedPoolConnect = false;
+                log.infoFormat("hostFromVds::selectedVds - {0}, spmStatus {1}, 
storage pool {2}",
+                        selectedVds.getName(), 
spmStatus.getSpmStatus().toString(), storagePool.getName());
+                if (spmStatus.getSpmStatus() == SpmStatus.Unknown_Pool) {
+                    Guid masterId = 
DbFacade.getInstance().getStorageDomainDao()
+                            .getMasterStorageDomainIdForPool(_storagePoolId);
+                    VDSReturnValue connectResult = 
ResourceManager.getInstance().runVdsCommand(
+                            VDSCommandType.ConnectStoragePool,
+                            new 
ConnectStoragePoolVDSCommandParameters(selectedVds.getId(), _storagePoolId,
+                                    selectedVds.getVdsSpmId(), masterId, 
storagePool.getmaster_domain_version()));
+                    if (!connectResult.getSucceeded()
+                            && connectResult.getExceptionObject() instanceof 
IRSNoMasterDomainException) {
+                        throw connectResult.getExceptionObject();
+                    } else if (!connectResult.getSucceeded()) {
+                        // if connect to pool fails throw exception for
+                        // failover
+                        throw new IRSNonOperationalException("Could not 
connect host to Data Center(Storage issue)");
                     }
-                    if (performedPoolConnect && selectedVds == null) {
-                        // if could not start spm on this host and connected to
-                        // pool here
-                        // then disconnect
-                        ResourceManager.getInstance().runVdsCommand(
-                                VDSCommandType.DisconnectStoragePool,
-                                new 
DisconnectStoragePoolVDSCommandParameters(selectedVdsId, _storagePoolId,
-                                        selectedVdsSpmId));
-                    }
+                    performedPoolConnect = true;
+                    // refresh spmStatus result
+                    spmStatus = (SpmStatusResult) ResourceManager
+                            .getInstance()
+                            .runVdsCommand(VDSCommandType.SpmStatus,
+                                    new 
SpmStatusVDSCommandParameters(selectedVds.getId(), _storagePoolId))
+                            .getReturnValue();
+                    log.infoFormat(
+                            "hostFromVds::Connected host to pool - selectedVds 
- {0}, spmStatus {1}, storage pool {2}",
+                            selectedVds.getName(),
+                            spmStatus.getSpmStatus().toString(),
+                            storagePool.getName());
+                }
+                RefObject<VDS> tempRefObject = new RefObject<VDS>(selectedVds);
+                spmStatus =
+                        handleSpmStatusResult(curVdsId, prioritizedVdsInPool, 
storagePool, tempRefObject, spmStatus);
+                selectedVds = tempRefObject.argvalue;
+
+                if (selectedVds != null) {
+                    RefObject<VDS> tempRefObject2 = new 
RefObject<VDS>(selectedVds);
+                    RefObject<SpmStatusResult> tempRefObject3 = new 
RefObject<SpmStatusResult>(spmStatus);
+                    returnValue = handleSelectedVdsForSPM(storagePool, 
tempRefObject2, tempRefObject3, prevStatus);
+                    selectedVds = tempRefObject2.argvalue;
                 } else {
+                    mCurrentVdsId = null;
+                }
+                if (performedPoolConnect && selectedVds == null) {
+                    // if could not start spm on this host and connected to
+                    // pool here
+                    // then disconnect
+                    ResourceManager.getInstance().runVdsCommand(
+                            VDSCommandType.DisconnectStoragePool,
+                            new 
DisconnectStoragePoolVDSCommandParameters(selectedVdsId, _storagePoolId,
+                                    selectedVdsSpmId));
+                }
+            } else {
 
-                    log.infoFormat("hostFromVds::selectedVds - {0}, spmStatus 
returned null!",
-                            selectedVds.getName());
-                    if (returnValueFromVds.getExceptionObject() instanceof 
IRSNoMasterDomainException) {
-                        throw returnValueFromVds.getExceptionObject();
-                    }
+                log.infoFormat("hostFromVds::selectedVds - {0}, spmStatus 
returned null!",
+                        selectedVds.getName());
+                if (returnValueFromVds.getExceptionObject() instanceof 
IRSNoMasterDomainException) {
+                    throw returnValueFromVds.getExceptionObject();
                 }
             }
             return returnValue;


-- 
To view, visit http://gerrit.ovirt.org/20528
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icc94288f209b015c4384630990fe561e43aebbbf
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Roy Golan <rgo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to