cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [01/13] git commit: updated refs/heads/master to 1e2e1ea
Date Thu, 09 Jan 2014 22:33:49 GMT
Updated Branches:
  refs/heads/master a298f6fce -> 1e2e1ea05


CLOUDSTACK-5672: Fix VM work job serialization issues in Add/Remove nic


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/0965adb0
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/0965adb0
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/0965adb0

Branch: refs/heads/master
Commit: 0965adb003905fa56dd642f48c632acae4b2c4fc
Parents: 87381d4
Author: Kelven Yang <kelveny@gmail.com>
Authored: Fri Jan 3 17:20:09 2014 -0800
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Thu Jan 9 14:29:12 2014 -0800

----------------------------------------------------------------------
 api/src/com/cloud/network/Network.java          |  3 +-
 api/src/com/cloud/vm/NicProfile.java            |  5 +-
 .../com/cloud/vm/VirtualMachineManagerImpl.java | 76 +++++++++-----------
 .../src/com/cloud/vm/VmWorkAddVmToNetwork.java  | 12 ++--
 .../src/com/cloud/vm/VmWorkRemoveNicFromVm.java | 10 +--
 5 files changed, 51 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0965adb0/api/src/com/cloud/network/Network.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java
index d2c8ac0..0b76789 100644
--- a/api/src/com/cloud/network/Network.java
+++ b/api/src/com/cloud/network/Network.java
@@ -16,6 +16,7 @@
 // under the License.
 package com.cloud.network;
 
+import java.io.Serializable;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
@@ -33,7 +34,7 @@ import com.cloud.utils.fsm.StateObject;
 /**
  * owned by an account.
  */
-public interface Network extends ControlledEntity, StateObject<Network.State>, InternalIdentity,
Identity {
+public interface Network extends ControlledEntity, StateObject<Network.State>, InternalIdentity,
Identity, Serializable {
 
     public enum GuestType {
         Shared, Isolated

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0965adb0/api/src/com/cloud/vm/NicProfile.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/NicProfile.java b/api/src/com/cloud/vm/NicProfile.java
index 2058803..4dd7f68 100644
--- a/api/src/com/cloud/vm/NicProfile.java
+++ b/api/src/com/cloud/vm/NicProfile.java
@@ -16,6 +16,7 @@
 // under the License.
 package com.cloud.vm;
 
+import java.io.Serializable;
 import java.net.URI;
 
 import org.apache.cloudstack.api.InternalIdentity;
@@ -27,7 +28,9 @@ import com.cloud.network.Networks.Mode;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.vm.Nic.ReservationStrategy;
 
-public class NicProfile implements InternalIdentity {
+public class NicProfile implements InternalIdentity, Serializable {
+    private static final long serialVersionUID = 4997005771736090304L;
+
     long id;
     long networkId;
     BroadcastDomainType broadcastType;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0965adb0/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index d0adabf..0653747 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -58,7 +58,6 @@ import org.apache.cloudstack.framework.jobs.AsyncJobManager;
 import org.apache.cloudstack.framework.jobs.Outcome;
 import org.apache.cloudstack.framework.jobs.dao.VmWorkJobDao;
 import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
-import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper;
 import org.apache.cloudstack.framework.jobs.impl.OutcomeImpl;
 import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO;
 import org.apache.cloudstack.framework.messagebus.MessageBus;
@@ -3097,25 +3096,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                 throw new RuntimeException("Execution excetion", e);
             }
 
-            AsyncJobVO jobVo = _entityMgr.findById(AsyncJobVO.class, outcome.getJob().getId());
-            if (jobVo.getResultCode() == JobInfo.Status.SUCCEEDED.ordinal()) {
-
-                NicProfile nic = (NicProfile)JobSerializerHelper.fromObjectSerializedString(jobVo.getResult());
-                return nic;
-            } else {
-                Object jobException = _jobMgr.unmarshallResultObject(outcome.getJob());
-                if (jobException != null) {
-                    if (jobException instanceof ResourceUnavailableException)
-                        throw (ResourceUnavailableException)jobException;
-                    else if (jobException instanceof ConcurrentOperationException)
-                        throw (ConcurrentOperationException)jobException;
-                    else if (jobException instanceof InsufficientCapacityException)
-                        throw (InsufficientCapacityException)jobException;
-                    else if (jobException instanceof RuntimeException)
-                        throw (RuntimeException)jobException;
-                }
-                throw new RuntimeException("Job failed with unhandled exception");
+            Object jobException = _jobMgr.unmarshallResultObject(outcome.getJob());
+            if (jobException != null) {
+                if (jobException instanceof ResourceUnavailableException)
+                    throw (ResourceUnavailableException)jobException;
+                else if (jobException instanceof ConcurrentOperationException)
+                    throw (ConcurrentOperationException)jobException;
+                else if (jobException instanceof InsufficientCapacityException)
+                    throw (InsufficientCapacityException)jobException;
+                else if (jobException instanceof RuntimeException)
+                    throw (RuntimeException)jobException;
+                else if (jobException instanceof Long)
+                    return requested;
             }
+
+            throw new RuntimeException("Unexpected job execution result");
         }
     }
 
@@ -3204,24 +3199,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                 throw new RuntimeException("Execution excetion", e);
             }
 
-            AsyncJobVO jobVo = _entityMgr.findById(AsyncJobVO.class, outcome.getJob().getId());
-
-            if (jobVo.getResultCode() == JobInfo.Status.SUCCEEDED.ordinal()) {
-                Boolean result = (Boolean)JobSerializerHelper.fromObjectSerializedString(jobVo.getResult());
-                return result;
-            } else {
-                Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
-                if (jobResult != null) {
-                    if (jobResult instanceof ResourceUnavailableException)
-                        throw (ResourceUnavailableException)jobResult;
-                    else if (jobResult instanceof ConcurrentOperationException)
-                        throw (ConcurrentOperationException)jobResult;
-                    else if (jobResult instanceof RuntimeException)
-                        throw (RuntimeException)jobResult;
-                }
-
-                throw new RuntimeException("Job failed with un-handled exception");
+            Object jobResult = _jobMgr.unmarshallResultObject(outcome.getJob());
+            if (jobResult != null) {
+                if (jobResult instanceof ResourceUnavailableException)
+                    throw (ResourceUnavailableException)jobResult;
+                else if (jobResult instanceof ConcurrentOperationException)
+                    throw (ConcurrentOperationException)jobResult;
+                else if (jobResult instanceof RuntimeException)
+                    throw (RuntimeException)jobResult;
+                else if (jobResult instanceof Boolean)
+                    return (Boolean)jobResult;
             }
+
+            throw new RuntimeException("Job failed with un-handled exception");
         }
     }
 
@@ -4529,7 +4519,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
 
                     // save work context info (there are some duplications)
                     VmWorkAddVmToNetwork workInfo = new VmWorkAddVmToNetwork(user.getId(),
account.getId(), vm.getId(),
-                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, network, requested);
+                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, network.getId(),
requested);
                     workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 
                     _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
@@ -4578,7 +4568,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
 
                     // save work context info (there are some duplications)
                     VmWorkRemoveNicFromVm workInfo = new VmWorkRemoveNicFromVm(user.getId(),
account.getId(), vm.getId(),
-                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, nic);
+                            VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER, nic.getId());
                     workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
 
                     _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
@@ -4768,9 +4758,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             s_logger.info("Unable to find vm " + work.getVmId());
         }
         assert (vm != null);
-        NicProfile nic = orchestrateAddVmToNetwork(vm, work.getNetwork(),
+
+        Network network = _networkDao.findById(work.getNetworkId());
+        NicProfile nic = orchestrateAddVmToNetwork(vm, network,
                 work.getRequestedNicProfile());
-        return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, _jobMgr.marshallResultObject(nic));
+
+        return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, _jobMgr.marshallResultObject(new
Long(nic.getId())));
     }
 
     private Pair<JobInfo.Status, String> orchestrateRemoveNicFromVm(VmWorkRemoveNicFromVm
work) throws Exception {
@@ -4779,7 +4772,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             s_logger.info("Unable to find vm " + work.getVmId());
         }
         assert (vm != null);
-        boolean result = orchestrateRemoveNicFromVm(vm, work.getNic());
+        NicVO nic = _entityMgr.findById(NicVO.class, work.getNicId());
+        boolean result = orchestrateRemoveNicFromVm(vm, nic);
         return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED,
                 _jobMgr.marshallResultObject(new Boolean(result)));
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0965adb0/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java b/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java
index bb3b496..a56259b 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkAddVmToNetwork.java
@@ -16,24 +16,22 @@
 // under the License.
 package com.cloud.vm;
 
-import com.cloud.network.Network;
-
 public class VmWorkAddVmToNetwork extends VmWork {
     private static final long serialVersionUID = 8861516006586736813L;
 
-    Network network;
+    Long networkId;
     NicProfile requstedNicProfile;
 
     public VmWorkAddVmToNetwork(long userId, long accountId, long vmId, String handlerName,
-            Network network, NicProfile requested) {
+            Long networkId, NicProfile requested) {
         super(userId, accountId, vmId, handlerName);
 
-        this.network = network;
+        this.networkId = networkId;
         requstedNicProfile = requested;
     }
 
-    public Network getNetwork() {
-        return network;
+    public Long getNetworkId() {
+        return networkId;
     }
 
     public NicProfile getRequestedNicProfile() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0965adb0/engine/orchestration/src/com/cloud/vm/VmWorkRemoveNicFromVm.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VmWorkRemoveNicFromVm.java b/engine/orchestration/src/com/cloud/vm/VmWorkRemoveNicFromVm.java
index 29264e6..50f158e 100644
--- a/engine/orchestration/src/com/cloud/vm/VmWorkRemoveNicFromVm.java
+++ b/engine/orchestration/src/com/cloud/vm/VmWorkRemoveNicFromVm.java
@@ -19,15 +19,15 @@ package com.cloud.vm;
 public class VmWorkRemoveNicFromVm extends VmWork {
     private static final long serialVersionUID = -4265657031064437923L;
 
-    Nic nic;
+    Long nicId;
 
-    public VmWorkRemoveNicFromVm(long userId, long accountId, long vmId, String handlerName,
Nic nic) {
+    public VmWorkRemoveNicFromVm(long userId, long accountId, long vmId, String handlerName,
Long nicId) {
         super(userId, accountId, vmId, handlerName);
 
-        this.nic = nic;
+        this.nicId = nicId;
     }
 
-    public Nic getNic() {
-        return nic;
+    public Long getNicId() {
+        return nicId;
     }
 }


Mime
View raw message