Ayal Baron has posted comments on this change.

Change subject: core: Change connect/disconnect storage commands to type 
agnostic
......................................................................


Patch Set 2:

(8 comments)

http://gerrit.ovirt.org/#/c/23296/2/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectHostToStoragePooServerCommandBase.java
File 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectHostToStoragePooServerCommandBase.java:

Line 25:         return connectionsTypeMap;
Line 26:     }
Line 27: 
Line 28:     protected void initConnectionList() {
Line 29:         _connections = new ArrayList<StorageServerConnections>(
this should be part of the object creation and thus _connections should never 
be null, then we can avoid all the redundant null checks we have.
Line 30:                 
DbFacade.getInstance().getStorageServerConnectionDao().getAllConnectableStorageSeverConnection(getStoragePool().getId()));
Line 31:         updateConnectionsTypeMap();
Line 32:     }
Line 33: 


Line 33: 
Line 34:     private void updateConnectionsTypeMap() {
Line 35:         connectionsTypeMap = new HashMap<>();
Line 36:         for (StorageServerConnections conn : _connections) {
Line 37:             if 
(!connectionsTypeMap.containsKey(conn.getstorage_type())) {
please add:
connType = conn.getstorage_type()
and then use that for clarity.
Line 38:                 connectionsTypeMap.put(conn.getstorage_type(), new 
ArrayList<StorageServerConnections>());
Line 39:             }
Line 40:             connectionsTypeMap.get(conn.getstorage_type()).add(conn);
Line 41:         }


http://gerrit.ovirt.org/#/c/23296/2/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectHostToStoragePoolServersCommand.java
File 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectHostToStoragePoolServersCommand.java:

Line 42:     }
Line 43: 
Line 44:     private boolean connectStorageServer(Map<StorageType, 
List<StorageServerConnections>> connectionsByType) {
Line 45:         boolean connectSucceeded = true;
Line 46:         if (connectionsByType != null && connectionsByType.size() > 0) 
{
1. I don't see where it would be valid to pass null to this method 
(getConnectionsTypeMap always returns a map) so the null check here is wrong 
imo and would hide bugs in the code
2. if it's not null then it's a map and it should be safe to loop on it even if 
it is a map of size == 0 so that check is redundant imo.
Line 47:             for (Map.Entry<StorageType, 
List<StorageServerConnections>> connectionToType : 
connectionsByType.entrySet()) {
Line 48:                 connectSucceeded = connectSucceeded && 
connectStorageServersByType(connectionToType.getKey(), 
connectionToType.getValue());
Line 49:             }
Line 50: 


Line 43: 
Line 44:     private boolean connectStorageServer(Map<StorageType, 
List<StorageServerConnections>> connectionsByType) {
Line 45:         boolean connectSucceeded = true;
Line 46:         if (connectionsByType != null && connectionsByType.size() > 0) 
{
Line 47:             for (Map.Entry<StorageType, 
List<StorageServerConnections>> connectionToType : 
connectionsByType.entrySet()) {
looping over the entrySet makes the variable names illegible.
please loop over keyset and then it becomes:

for (StorageType connectionType : ...) {
    connections = connectionsByType.get(connectionType)
    connectSucceeded = connectSucceeded && 
connectStorageServerByType(connectionType, connections)
Line 48:                 connectSucceeded = connectSucceeded && 
connectStorageServersByType(connectionToType.getKey(), 
connectionToType.getValue());
Line 49:             }
Line 50: 
Line 51:             log.infoFormat("Host {0} storage connection was {1} ", 
getVds().getName(),


Line 44:     private boolean connectStorageServer(Map<StorageType, 
List<StorageServerConnections>> connectionsByType) {
Line 45:         boolean connectSucceeded = true;
Line 46:         if (connectionsByType != null && connectionsByType.size() > 0) 
{
Line 47:             for (Map.Entry<StorageType, 
List<StorageServerConnections>> connectionToType : 
connectionsByType.entrySet()) {
Line 48:                 connectSucceeded = connectSucceeded && 
connectStorageServersByType(connectionToType.getKey(), 
connectionToType.getValue());
connectSucceeded which returs false if any of the connections failed and true 
if all succeeded is meaningless.
probably not related to this patch, but any reliance on such a value seems 
wrong to me.
Line 49:             }
Line 50: 
Line 51:             log.infoFormat("Host {0} storage connection was {1} ", 
getVds().getName(),
Line 52:                     connectSucceeded ? "succeeded" : "failed");


http://gerrit.ovirt.org/#/c/23296/2/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DisconnectHostFromStoragePoolServersCommand.java
File 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DisconnectHostFromStoragePoolServersCommand.java:

Line 16: 
Line 17: @InternalCommandAttribute
Line 18: @NonTransactiveCommandAttribute
Line 19: public class DisconnectHostFromStoragePoolServersCommand extends
Line 20:         
ConnectHostToStoragePooServerCommandBase<HostStoragePoolParametersBase> {
ConnectHostToStorage Poo?
this doesn't smell good...
Line 21: 
Line 22:     public 
DisconnectHostFromStoragePoolServersCommand(HostStoragePoolParametersBase 
parameters) {
Line 23:         super(parameters);
Line 24:         setStoragePool(parameters.getStoragePool());


Line 27: 
Line 28:     @Override
Line 29:     protected void executeCommand() {
Line 30:         initConnectionList();
Line 31:         // TODO: check if host belong to more than one storage pool
please remove this comment, it's plain wrong
Line 32: 
Line 33:         if (getConnectionsTypeMap() != null && 
getConnectionsTypeMap().size() > 0) {
Line 34:             for (Map.Entry<StorageType, 
List<StorageServerConnections>> connectionToType : 
getConnectionsTypeMap().entrySet()) {
Line 35:                 disconnectStorageByType(connectionToType.getKey(), 
connectionToType.getValue());


Line 29:     protected void executeCommand() {
Line 30:         initConnectionList();
Line 31:         // TODO: check if host belong to more than one storage pool
Line 32: 
Line 33:         if (getConnectionsTypeMap() != null && 
getConnectionsTypeMap().size() > 0) {
1. getConnectionsTypeMap should never be null so check is redundant
2. you can loop over an empty map so size check is redundant as well
Line 34:             for (Map.Entry<StorageType, 
List<StorageServerConnections>> connectionToType : 
getConnectionsTypeMap().entrySet()) {
Line 35:                 disconnectStorageByType(connectionToType.getKey(), 
connectionToType.getValue());
Line 36:             }
Line 37:         }


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I07a7fb8af9ce89a38b51cdb07a43a15f9c13f839
Gerrit-PatchSet: 2
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tal Nisan <[email protected]>
Gerrit-Reviewer: Allon Mureinik <[email protected]>
Gerrit-Reviewer: Ayal Baron <[email protected]>
Gerrit-Reviewer: Daniel Erez <[email protected]>
Gerrit-Reviewer: Federico Simoncelli <[email protected]>
Gerrit-Reviewer: Liron Ar <[email protected]>
Gerrit-Reviewer: Maor Lipchuk <[email protected]>
Gerrit-Reviewer: Sergey Gotliv <[email protected]>
Gerrit-Reviewer: Vered Volansky <[email protected]>
Gerrit-Reviewer: oVirt Jenkins CI Server
Gerrit-HasComments: Yes
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to