Alissa Bonas has uploaded a new change for review.

Change subject: core: not allow detach last storage connection
......................................................................

core: not allow detach last storage connection

Prevent detaching last storage connection from domain.

Change-Id: Iaf67c945381e8d0d47e5f6b2878f3bd2a571b5b6
Signed-off-by: Alissa Bonas <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DetachStorageConnectionFromStorageDomainCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/StorageConnectionValidator.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/StorageConnectionValidatorTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
8 files changed, 50 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/14/18314/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DetachStorageConnectionFromStorageDomainCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DetachStorageConnectionFromStorageDomainCommand.java
index 24de7a4..788f109 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DetachStorageConnectionFromStorageDomainCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/DetachStorageConnectionFromStorageDomainCommand.java
@@ -33,6 +33,9 @@
         
if(!storageConnectionValidator.isConnectionForISCSIDomainAttached(getStorageDomain()))
 {
             return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_STORAGE_CONNECTION_FOR_DOMAIN_NOT_EXIST);
         }
+        if 
(storageConnectionValidator.isLastConnectionForDomain(getStorageDomain())) {
+            return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_STORAGE_CONNECTION_CANNOT_DETACH_LAST);
+        }
         return true;
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/StorageConnectionValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/StorageConnectionValidator.java
index cae532c..b20e315 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/StorageConnectionValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/StorageConnectionValidator.java
@@ -72,7 +72,19 @@
 
     public boolean isConnectionForISCSIDomainAttached(StorageDomain 
storageDomain) {
         List<StorageServerConnections> connectionsForDomain = 
getAllConnectionsForDomain(storageDomain.getId());
-        for (StorageServerConnections connectionForDomain : 
connectionsForDomain) {
+        return isConnectionAttachedToDomain(connectionsForDomain);
+    }
+
+    public boolean isLastConnectionForDomain(StorageDomain storageDomain) {
+        List<StorageServerConnections> connectionsForDomain = 
getAllConnectionsForDomain(storageDomain.getId());
+        if (connectionsForDomain.size() == 1 && 
isConnectionAttachedToDomain(connectionsForDomain)) {
+            return true;
+        }
+        return false;
+    }
+
+    private boolean isConnectionAttachedToDomain( 
List<StorageServerConnections> connectionsForDomain ) {
+         for (StorageServerConnections connectionForDomain : 
connectionsForDomain) {
             if (connectionForDomain.getid().equals(connection.getid())) {
                 return true;
             }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/StorageConnectionValidatorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/StorageConnectionValidatorTest.java
index 0131f04..9375e92 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/StorageConnectionValidatorTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/StorageConnectionValidatorTest.java
@@ -115,6 +115,33 @@
         assertTrue(validator.isConnectionForISCSIDomainAttached(domain));
     }
 
+    @Test
+    public void isLastConnectionForDomainPositive() {
+        StorageServerConnections connection = new StorageServerConnections();
+        connection.setid("0cc146e8-e5ed-482c-8814-270bc48c297e");
+        List<StorageServerConnections> connections = new ArrayList<>();
+        connections.add(connection);
+        
doReturn(connections).when(validator).getAllConnectionsForDomain(domain.getId());
+        assertTrue(validator.isLastConnectionForDomain(domain));
+    }
+
+    @Test
+    public void isLastConnectionForDomainNegative() {
+        StorageServerConnections connection = new StorageServerConnections();
+        connection.setid("0cc146e8-e5ed-482c-8814-270bc48c297e");
+        List<StorageServerConnections> connections = getConnections();
+        connections.add(connection);
+        
doReturn(connections).when(validator).getAllConnectionsForDomain(domain.getId());
+        assertFalse(validator.isLastConnectionForDomain(domain));
+    }
+
+    @Test
+    public void isLastConnectionForDomainNegative2() {
+        List<StorageServerConnections> connections = getConnections();
+        
doReturn(connections).when(validator).getAllConnectionsForDomain(domain.getId());
+        assertFalse(validator.isLastConnectionForDomain(domain));
+    }
+
     private List<StorageServerConnections> getConnections() {
          List<StorageServerConnections> connectionsList = new ArrayList<>();
          StorageServerConnections connection1 = new StorageServerConnections();
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 535b6e0..f89fbbc 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -467,6 +467,7 @@
     
ACTION_TYPE_FAILED_STORAGE_CONNECTION_BELONGS_TO_SEVERAL_STORAGE_DOMAINS(ErrorType.CONFLICT),
     
ACTION_TYPE_FAILED_STORAGE_CONNECTION_BELONGS_TO_SEVERAL_DISKS(ErrorType.CONFLICT),
     
ACTION_TYPE_FAILED_STORAGE_CONNECTION_BELONGS_TO_SEVERAL_STORAGE_DOMAINS_AND_DISKS(ErrorType.CONFLICT),
+    
ACTION_TYPE_FAILED_STORAGE_CONNECTION_CANNOT_DETACH_LAST(ErrorType.BAD_PARAMETERS),
     
ACTION_TYPE_FAILED_STORAGE_CONNECTION_UNSUPPORTED_CHANGE_STORAGE_TYPE(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_STORAGE_DOMAIN_STATUS_ILLEGAL(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_STORAGE_DOMAIN_STATUS_ILLEGAL2(ErrorType.CONFLICT),
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index ff5ec5f..47bd715 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -371,6 +371,7 @@
 ACTION_TYPE_FAILED_URL_INVALID=Cannot ${action} ${type}. The URL is not valid, 
please enter a valid URL and try again.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_NOT_EXIST=Cannot ${action} ${type}. 
Storage connection doesn't exist.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_FOR_DOMAIN_NOT_EXIST=Cannot ${action} 
${type}. Storage connection is not attached to the specified domain.
+ACTION_TYPE_FAILED_STORAGE_CONNECTION_CANNOT_DETACH_LAST=Cannot ${action} 
${type}. This is the last storage connection attached to the specified domain.
 ACTION_TYPE_FAILED_ACTION_IS_SUPPORTED_ONLY_FOR_ISCSI_DOMAINS=Cannot ${action} 
${type}. Action is supported only for iSCSI storage domains.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_ID_EMPTY=Cannot ${action} ${type}. 
Storage connection id is empty.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_ID_NOT_EMPTY=Cannot ${action} ${type}. 
Storage connection id is not empty.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index 4a1f56a..ff57efd 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -1027,6 +1027,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. Storage connection is not 
attached to the specified domain.")
     String ACTION_TYPE_FAILED_STORAGE_CONNECTION_FOR_DOMAIN_NOT_EXIST();
 
+    @DefaultStringValue("Cannot ${action} ${type}. This is the last storage 
connection attached to the specified domain.")
+    String ACTION_TYPE_FAILED_STORAGE_CONNECTION_CANNOT_DETACH_LAST();
+
     @DefaultStringValue("Cannot ${action} ${type}. No active data Storage 
Domain with enough storage was found in the Data Center.")
     String ACTION_TYPE_FAILED_NO_SUITABLE_DOMAIN_FOUND();
 
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index e3459f3..4b03ea1 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -351,6 +351,7 @@
 ACTION_TYPE_FAILED_URL_INVALID=Cannot ${action} ${type}. The URL is not valid, 
please enter a valid URL and try again.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_NOT_EXIST=Cannot ${action} ${type}. 
Storage connection doesn't exist.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_FOR_DOMAIN_NOT_EXIST=Cannot ${action} 
${type}. Storage connection is not attached to the specified domain.
+ACTION_TYPE_FAILED_STORAGE_CONNECTION_CANNOT_DETACH_LAST=Cannot ${action} 
${type}. This is the last storage connection attached to the specified domain.
 ACTION_TYPE_FAILED_ACTION_IS_SUPPORTED_ONLY_FOR_ISCSI_DOMAINS=Cannot ${action} 
${type}. Action is supported only for iSCSI storage domains.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_ID_EMPTY=Cannot ${action} ${type}. 
Storage connection id is empty.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_ID_NOT_EMPTY=Cannot ${action} ${type}. 
Storage connection id is not empty.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 757e57c..54cf2ca 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -375,6 +375,7 @@
 ACTION_TYPE_FAILED_URL_INVALID=Cannot ${action} ${type}. The URL is not valid, 
please enter a valid URL and try again.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_NOT_EXIST=Cannot ${action} ${type}. 
Storage connection doesn't exist.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_FOR_DOMAIN_NOT_EXIST=Cannot ${action} 
${type}. Storage connection is not attached to the specified domain.
+ACTION_TYPE_FAILED_STORAGE_CONNECTION_CANNOT_DETACH_LAST=Cannot ${action} 
${type}. This is the last storage connection attached to the specified domain.
 ACTION_TYPE_FAILED_ACTION_IS_SUPPORTED_ONLY_FOR_ISCSI_DOMAINS=Cannot ${action} 
${type}. Action is supported only for iSCSI storage domains.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_ID_EMPTY=Cannot ${action} ${type}. 
Storage connection id is empty.
 ACTION_TYPE_FAILED_STORAGE_CONNECTION_ID_NOT_EMPTY=Cannot ${action} ${type}. 
Storage connection id is not empty.


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaf67c945381e8d0d47e5f6b2878f3bd2a571b5b6
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alissa Bonas <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to