Arik Hadas has uploaded a new change for review.

Change subject: core: remove read lock of template being exported
......................................................................

core: remove read lock of template being exported

Replace the exclusive lock which was taken for a template that is being
exported and the lock status in the DB, with persistent shared lock for
the template on the data domain plus persistent exclusive lock for the
template on the export domain.

Change-Id: I830cfef82063d2dbac3689a46758090da8b10df3
Bug-Url: https://bugzilla.redhat.com/920150
Signed-off-by: Arik Hadas <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmTemplateCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyTemplateCommand.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/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
7 files changed, 39 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/09/13109/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmTemplateCommand.java
index 8c408fe..98bc400 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmTemplateCommand.java
@@ -17,6 +17,7 @@
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.StorageDomainType;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
+import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.KeyValuePairCompat;
@@ -25,8 +26,10 @@
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
 
 @DisableInPrepareMode
-@LockIdNameAttribute
+@LockIdNameAttribute(isReleaseAtEndOfExecute = false)
 public class ExportVmTemplateCommand<T extends MoveOrCopyParameters> extends 
MoveOrCopyTemplateCommand<T> {
+
+    private String cachedTemplateIsBeingExportedMessage;
 
     public ExportVmTemplateCommand(T parameters) {
         super(parameters);
@@ -78,7 +81,33 @@
 
     @Override
     protected Map<String, Pair<String, String>> getExclusiveLocks() {
-        return Collections.singletonMap(getVmTemplateId().toString(), 
LockMessagesMatchUtil.TEMPLATE);
+        return Collections.singletonMap(getVmTemplateId().toString(),
+                
LockMessagesMatchUtil.makeLockingPair(LockingGroup.REMOTE_TEMPLATE, 
getTemplateIsBeingExportedMessage()));
+    }
+
+    @Override
+    protected Map<String, Pair<String, String>> getSharedLocks() {
+        return Collections.singletonMap(getVmTemplateId().toString(),
+                LockMessagesMatchUtil.makeLockingPair(LockingGroup.TEMPLATE, 
getTemplateIsBeingExportedMessage()));
+    }
+
+    @Override
+    protected void executeCommand() {
+        if (!getTemplateDisks().isEmpty()) {
+            moveOrCopyAllImageGroups();
+        } else {
+            endVmTemplateRelatedOps();
+        }
+        setSucceeded(true);
+    }
+
+    private String getTemplateIsBeingExportedMessage() {
+        if (cachedTemplateIsBeingExportedMessage == null) {
+            cachedTemplateIsBeingExportedMessage = new 
StringBuilder(VdcBllMessages.ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_EXPORTED.name())
+            .append(String.format("$TemplateName %1$s", 
getVmTemplate().getName()))
+            .toString();
+        }
+        return cachedTemplateIsBeingExportedMessage;
     }
 
     @Override
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyTemplateCommand.java
index dcd577c..938989f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyTemplateCommand.java
@@ -150,14 +150,6 @@
 
     @Override
     protected void executeCommand() {
-        VmTemplateHandler.lockVmTemplateInTransaction(getVmTemplateId(), 
getCompensationContext());
-        freeLock();
-        if (!getTemplateDisks().isEmpty()) {
-            moveOrCopyAllImageGroups();
-        } else {
-            endVmTemplateRelatedOps();
-        }
-        setSucceeded(true);
     }
 
     protected void moveOrCopyAllImageGroups() {
@@ -239,7 +231,7 @@
         setSucceeded(true);
     }
 
-    private void endVmTemplateRelatedOps() {
+    protected final void endVmTemplateRelatedOps() {
         if (getVmTemplate() != null) {
             VmDeviceUtils.setVmDevices(getVmTemplate());
             incrementDbGeneration();
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
index bd53bd8..914be75 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java
@@ -526,6 +526,7 @@
     ACTION_TYPE_FAILED_TEMPLATE_IS_USED_FOR_CREATE_VM,
     ACTION_TYPE_FAILED_DISK_IS_USED_FOR_CREATE_VM,
     ACTION_TYPE_FAILED_DISK_IS_BEING_REMOVED,
+    ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_EXPORTED,
     ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_REMOVED,
     VM_OR_TEMPLATE_ILLEGAL_PRIORITY_VALUE,
 
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 11c0477..523019c 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -493,6 +493,7 @@
 ACTION_TYPE_FAILED_TEMPLATE_IS_USED_FOR_CREATE_VM=Cannot ${action} ${type}. 
This template is currently in use to create VM ${VmName}.
 ACTION_TYPE_FAILED_DISK_IS_USED_FOR_CREATE_VM=Cannot ${action} ${type}. This 
disk is currently in use to create VM ${VmName}.
 ACTION_TYPE_FAILED_DISK_IS_BEING_REMOVED=Cannot ${action} ${type}. Disk 
${DiskName} is being removed.
+ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_EXPORTED=Cannot ${action} ${type}. 
Template ${TemplateName} is being exported.
 ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_REMOVED=Cannot ${action} ${type}. 
Template ${TemplateName} is being removed.
 NETWORK_BOND_HAVE_ATTACHED_VLANS=Bond attached to vlan, remove bonds vlan first
 NETWORK_INTERFACE_CONNECT_TO_VLAN=Cannot attach non vlan network to vlan 
interface
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 17f25cf..76849d5 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
@@ -1327,6 +1327,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. Disk ${DiskName} is being 
removed.")
     String ACTION_TYPE_FAILED_DISK_IS_BEING_REMOVED();
 
+    @DefaultStringValue("Cannot ${action} ${type}. Template ${TemplateName} is 
being exported.")
+    String ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_EXPORTED();
+
     @DefaultStringValue("Cannot ${action} ${type}. Template ${TemplateName} is 
being removed.")
     String ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_REMOVED();
 
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 e2bb661..882d106 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
@@ -490,6 +490,7 @@
 ACTION_TYPE_FAILED_TEMPLATE_IS_USED_FOR_CREATE_VM=Cannot ${action} ${type}. 
This template is currently in use to create VM ${VmName}.
 ACTION_TYPE_FAILED_DISK_IS_USED_FOR_CREATE_VM=Cannot ${action} ${type}. This 
disk is currently in use to create VM ${VmName}.
 ACTION_TYPE_FAILED_DISK_IS_BEING_REMOVED=Cannot ${action} ${type}. Disk 
${DiskName} is being removed.
+ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_EXPORTED=Cannot ${action} ${type}. 
Template ${TemplateName} is being exported.
 ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_REMOVED=Cannot ${action} ${type}. 
Template ${TemplateName} is being removed.
 NETWORK_BOND_HAVE_ATTACHED_VLANS=Bond attached to vlan, remove bonds vlan first
 NETWORK_INTERFACE_CONNECT_TO_VLAN=Cannot attach non vlan network to vlan 
interface
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 8721a49..f2a27f8 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
@@ -487,6 +487,7 @@
 ACTION_TYPE_FAILED_TEMPLATE_IS_USED_FOR_CREATE_VM=Cannot ${action} ${type}. 
This template is currently in use to create VM ${VmName}.
 ACTION_TYPE_FAILED_DISK_IS_USED_FOR_CREATE_VM=Cannot ${action} ${type}. This 
disk is currently in use to create VM ${VmName}.
 ACTION_TYPE_FAILED_DISK_IS_BEING_REMOVED=Cannot ${action} ${type}. Disk 
${DiskName} is being removed.
+ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_EXPORTED=Cannot ${action} ${type}. 
Template ${TemplateName} is being exported.
 ACTION_TYPE_FAILED_TEMPLATE_IS_BEING_REMOVED=Cannot ${action} ${type}. 
Template ${TemplateName} is being removed.
 NETWORK_BOND_HAVE_ATTACHED_VLANS=Bond attached to vlan, remove bonds vlan first
 NETWORK_INTERFACE_CONNECT_TO_VLAN=Cannot attach non vlan network to vlan 
interface


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

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

Reply via email to