Yaniv Bronhaim has uploaded a new change for review.

Change subject: Moving provision call into transaction
......................................................................

Moving provision call into transaction

Change-Id: I635d87d09eec0dd052d86329d2b6b7f0a1658836
Signed-off-by: Yaniv Bronhaim <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java
1 file changed, 35 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/60/34860/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java
index f490fa5..983c119 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java
@@ -115,34 +115,47 @@
                 log.error("Failed to provision: Host group cannot be empty");
                 throw new 
VdcBLLException(VdcBllErrors.PROVIDER_PROVISION_MISSING_HOSTGROUP);
             }
-            HostProviderProxy proxy =
-                    ((HostProviderProxy) 
ProviderProxyFactory.getInstance().create(getHostProvider()));
-            
getParameters().getvds().getStaticData().setHostProviderId(getParameters().getProviderId());
-            proxy.provisionHost(
-                    getParameters().getvds(),
-                    getParameters().getHostGroup(),
-                    getParameters().getComputeResource(),
-                    getParameters().getHostMac(),
-                    getParameters().getDiscoverName(),
-                    getParameters().getPassword()
-            );
+
+            TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
+                @Override
+                public Void runInTransaction() {
+                    // Adding vdsStatic first to have vdsId before calling to 
provision
+                    AddVdsStaticToDb();
+
+                    HostProviderProxy proxy =
+                            ((HostProviderProxy) 
ProviderProxyFactory.getInstance().create(getHostProvider()));
+                    
getParameters().getvds().getStaticData().setHostProviderId(getParameters().getProviderId());
+                    proxy.provisionHost(
+                            getParameters().getvds(),
+                            getParameters().getHostGroup(),
+                            getParameters().getComputeResource(),
+                            getParameters().getHostMac(),
+                            getParameters().getDiscoverName(),
+                            getParameters().getPassword()
+                    );
+                    AddVdsDynamicToDb();
+                    AddVdsStatisticsToDb();
+                    getCompensationContext().stateChanged();
+                    return null;
+                }
+            });
 
             AuditLogableBase logable = new AuditLogableBase();
             logable.setVds(getParameters().getvds());
             logable.addCustomValue("HostGroupName", 
getParameters().getHostGroup().getName());
             AuditLogDirector.log(logable, AuditLogType.VDS_PROVISION);
+        } else {
+            TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
+                @Override
+                public Void runInTransaction() {
+                    AddVdsStaticToDb();
+                    AddVdsDynamicToDb();
+                    AddVdsStatisticsToDb();
+                    getCompensationContext().stateChanged();
+                    return null;
+                }
+            });
         }
-
-        TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
-            @Override
-            public Void runInTransaction() {
-                AddVdsStaticToDb();
-                AddVdsDynamicToDb();
-                AddVdsStatisticsToDb();
-                getCompensationContext().stateChanged();
-                return null;
-            }
-        });
 
         // set vds spm id
         if (getVdsGroup().getStoragePoolId() != null) {


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

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

Reply via email to