Maor Lipchuk has uploaded a new change for review.

Change subject: core: Add a CDA on attach to an uninitialized Data Center
......................................................................

core: Add a CDA on attach to an uninitialized Data Center

Adding a validation message when trying to attach a Storage Domain which
already have a storage pool id initiliazed in its meta data.

Storage Domain which have storage pool id already initialized in its
meta data (For example after disaster), needs to be detached first and
then to be attached to the relevant Data Center, since the detach
operation is an SPM operation, an un-initialized Data Center can't
perform this operation since it does not have an SPM yet.

Change-Id: I13ec66cc7ff4773221cc994cb4f0be1886ed9a6b
Bug-Url: https://bugzilla.redhat.com/1138126
Signed-off-by: Maor Lipchuk <mlipc...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddStoragePoolWithStoragesCommand.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
6 files changed, 44 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/46/36546/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddStoragePoolWithStoragesCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddStoragePoolWithStoragesCommand.java
index 8a4f516..1cfb957 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddStoragePoolWithStoragesCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddStoragePoolWithStoragesCommand.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.bll.storage;
 
 import java.util.Collections;
+import java.util.List;
 import java.util.Map;
 
 import org.ovirt.engine.core.bll.Backend;
@@ -13,20 +14,22 @@
 import org.ovirt.engine.core.common.action.StorageDomainPoolParametersBase;
 import org.ovirt.engine.core.common.action.StoragePoolWithStoragesParameter;
 import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.StorageDomain;
+import org.ovirt.engine.core.common.businessentities.StorageDomainStatic;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
 import org.ovirt.engine.core.common.businessentities.StorageDomainType;
 import org.ovirt.engine.core.common.businessentities.StorageFormatType;
+import org.ovirt.engine.core.common.businessentities.StoragePool;
+import org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap;
 import org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId;
 import org.ovirt.engine.core.common.businessentities.StoragePoolStatus;
 import org.ovirt.engine.core.common.businessentities.VDS;
-import org.ovirt.engine.core.common.businessentities.StorageDomain;
-import org.ovirt.engine.core.common.businessentities.StorageDomainStatic;
-import org.ovirt.engine.core.common.businessentities.StoragePool;
-import org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.errors.VdcBllErrors;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.locks.LockingGroup;
+import 
org.ovirt.engine.core.common.queries.StorageDomainsAndStoragePoolIdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.common.utils.VersionStorageFormatUtil;
 import 
org.ovirt.engine.core.common.vdscommands.CreateStoragePoolVDSCommandParameters;
@@ -297,7 +300,7 @@
     protected boolean canDoAction() {
         boolean returnValue = super.canDoAction() && checkStoragePool()
                 && checkStoragePoolStatus(StoragePoolStatus.Uninitialized) && 
initializeVds()
-                && checkStorageDomainsInPool();
+                && checkStorageDomainsInPool() && 
isDomainAttachedToDifferentStoragePool();
         return returnValue;
     }
 
@@ -306,4 +309,27 @@
         return Collections.singletonMap(getStoragePoolId().toString(),
                 LockMessagesMatchUtil.makeLockingPair(LockingGroup.POOL, 
VdcBllMessages.ACTION_TYPE_FAILED_OBJECT_LOCKED));
     }
+
+    private boolean isDomainAttachedToDifferentStoragePool() {
+        if (getStoragePool().getStatus() == StoragePoolStatus.Uninitialized) {
+            for (Guid storageDomainId : getParameters().getStorages()) {
+                StorageDomain domain = 
getStorageDomainDAO().get(storageDomainId);
+                if (domain.getStorageDomainType().isDataDomain() && 
isStorageDomainAttachedToStoragePool(domain)) {
+                    return 
failCanDoAction(VdcBllMessages.ERROR_CANNOT_ADD_STORAGE_DOMAIN_WITH_ATTACHED_DATA_DOMAIN);
+                }
+            }
+        }
+        return true;
+    }
+
+    private boolean isStorageDomainAttachedToStoragePool(StorageDomain 
storageDomain) {
+        List<StorageDomain> storageDomainList =
+                (List<StorageDomain>) 
getBackend().runInternalQuery(VdcQueryType.GetStorageDomainsWithAttachedStoragePoolGuid,
+                        new 
StorageDomainsAndStoragePoolIdQueryParameters(storageDomain,
+                                getStoragePoolId(),
+                                getVds().getId(),
+                                false))
+                        .getReturnValue();
+        return !storageDomainList.isEmpty();
+    }
 }
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 8b4e79f..9164a49 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
@@ -617,6 +617,7 @@
     
ERROR_CANNOT_DEACTIVATE_MASTER_DOMAIN_WITH_TASKS_ON_POOL(ErrorType.CONFLICT),
     
ERROR_CANNOT_ADD_STORAGE_POOL_WITHOUT_DATA_AND_ISO_DOMAINS(ErrorType.BAD_PARAMETERS),
     ERROR_CANNOT_ADD_STORAGE_POOL_WITHOUT_DATA_DOMAIN(ErrorType.CONFLICT),
+    
ERROR_CANNOT_ADD_STORAGE_DOMAIN_WITH_ATTACHED_DATA_DOMAIN(ErrorType.CONFLICT),
     
ERROR_CANNOT_ADD_STORAGE_POOL_WITH_DIFFERENT_STORAGE_FORMAT(ErrorType.CONFLICT),
     ERROR_CANNOT_CREATE_STORAGE_DOMAIN_WITHOUT_VG_LV(ErrorType.BAD_PARAMETERS),
     ERROR_CANNOT_REMOVE_POOL_WITH_NETWORKS(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 48f0525..e8c0b3c 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -534,6 +534,9 @@
 NETWORK_VLAN_OUT_OF_RANGE=VLAN ID must be a number between 0 and 4094.
 ERROR_CANNOT_ADD_STORAGE_POOL_WITHOUT_DATA_DOMAIN=Cannot attach Storage 
Domain.\n\
        -Please attach Data Domain to the Data Center first.
+ERROR_CANNOT_ADD_STORAGE_DOMAIN_WITH_ATTACHED_DATA_DOMAIN=Cannot ${action} 
${type}.\n\
+ The Storage Domain is already attached to a different Data Center and cannot 
be attcahed to an uninitialized Data Center.\n\
+ -Please attach a differenet Data Domain to the Data Center first.
 ERROR_CANNOT_REMOVE_POOL_WITH_ACTIVE_DOMAINS=Cannot remove Data Center which 
contains active/locked Storage Domains.\n\
        -Please deactivate all domains and wait for tasks to finish before 
removing the Data Center.
 VDS_GROUP_CANNOT_CHANGE_STORAGE_POOL=Cannot change Data Center association 
when editing a Cluster.
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 11330d2..c5c8bf7 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
@@ -1480,6 +1480,9 @@
     @DefaultStringValue("Cannot attach Storage Domain.\n-Please attach Data 
Domain to the Data Center first.")
     String ERROR_CANNOT_ADD_STORAGE_POOL_WITHOUT_DATA_DOMAIN();
 
+    @DefaultStringValue("Cannot ${action} ${type}.\n The Storage Domain is 
already attached to a different Data Center and cannot be attcahed to an 
uninitialized Data Center.\n -Please attach a differenet Data Domain to the 
Data Center first.")
+    String ERROR_CANNOT_ADD_STORAGE_DOMAIN_WITH_ATTACHED_DATA_DOMAIN();
+
     @DefaultStringValue("Cannot remove Data Center which contains 
active/locked Storage Domains.\n-Please deactivate all domains and wait for 
tasks to finish before removing the Data Center.")
     String ERROR_CANNOT_REMOVE_POOL_WITH_ACTIVE_DOMAINS();
 
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 6f779e0..8791a57 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
@@ -505,6 +505,9 @@
 NETWORK_VLAN_OUT_OF_RANGE=VLAN ID must be a number between 0 and 4094.
 ERROR_CANNOT_ADD_STORAGE_POOL_WITHOUT_DATA_DOMAIN=Cannot attach Storage 
Domain.\n\
        -Please attach Data Domain to the Data Center first.
+ERROR_CANNOT_ADD_STORAGE_DOMAIN_WITH_ATTACHED_DATA_DOMAIN=Cannot ${action} 
${type}.\n\
+ The Storage Domain is already attached to a different Data Center and cannot 
be attcahed to an uninitialized Data Center.\n\
+ -Please attach a differenet Data Domain to the Data Center first.
 ERROR_CANNOT_REMOVE_POOL_WITH_ACTIVE_DOMAINS=Cannot remove Data Center which 
contains active/locked Storage Domains.\n\
        -Please deactivate all domains and wait for tasks to finish before 
removing the Data Center.
 VDS_GROUP_CANNOT_CHANGE_STORAGE_POOL=Cannot change Data Center association 
when editing a Cluster.
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 600a16e..f1279c1 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
@@ -539,6 +539,9 @@
 NETWORK_VLAN_OUT_OF_RANGE=VLAN ID must be a number between 0 and 4094.
 ERROR_CANNOT_ADD_STORAGE_POOL_WITHOUT_DATA_DOMAIN=Cannot attach Storage 
Domain.\n\
        -Please attach Data Domain to the Data Center first.
+ERROR_CANNOT_ADD_STORAGE_DOMAIN_WITH_ATTACHED_DATA_DOMAIN=Cannot ${action} 
${type}.\n\
+ The Storage Domain is already attached to a different Data Center and cannot 
be attcahed to an uninitialized Data Center.\n\
+ -Please attach a differenet Data Domain to the Data Center first.
 ERROR_CANNOT_REMOVE_POOL_WITH_ACTIVE_DOMAINS=Cannot remove Data Center which 
contains active/locked Storage Domains.\n\
        -Please deactivate all domains and wait for tasks to finish before 
removing the Data Center.
 VDS_GROUP_CANNOT_CHANGE_STORAGE_POOL=Cannot change Data Center association 
when editing a Cluster.


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I13ec66cc7ff4773221cc994cb4f0be1886ed9a6b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Maor Lipchuk <mlipc...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to