cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [1/2] git commit: updated refs/heads/vmsync to 03a9445
Date Wed, 12 Jun 2013 16:52:20 GMT
Updated Branches:
  refs/heads/vmsync d71e358a9 -> 03a9445fd


Workaroud StartUserVM DeploymentPlan serialization issue to make it across job boundary


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

Branch: refs/heads/vmsync
Commit: 03a9445fda67a0b9be0afd5a0ba0eab50962a1fe
Parents: f271720
Author: Kelven Yang <kelveny@gmail.com>
Authored: Tue Jun 11 19:26:54 2013 -0700
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Wed Jun 12 09:45:06 2013 -0700

----------------------------------------------------------------------
 server/src/com/cloud/vm/VmWorkStart.java | 52 ++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03a9445f/server/src/com/cloud/vm/VmWorkStart.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VmWorkStart.java b/server/src/com/cloud/vm/VmWorkStart.java
index fdc6bfd..fbc0a15 100644
--- a/server/src/com/cloud/vm/VmWorkStart.java
+++ b/server/src/com/cloud/vm/VmWorkStart.java
@@ -17,14 +17,32 @@
 
 package com.cloud.vm;
 
+import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
 
-import com.cloud.api.ApiSerializerHelper;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper;
+import org.apache.log4j.Logger;
+
+import com.cloud.deploy.DataCenterDeployment;
 import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.utils.Journal;
 
 public class VmWorkStart extends VmWork {
-	private DeploymentPlan plan;
+    private static final Logger s_logger = Logger.getLogger(VmWorkStart.class);
+
+	long dcId;
+	Long podId;
+	Long clusterId;
+	Long hostId;
+	Long poolId;
+	ExcludeList avoids;
+	Long physicalNetworkId;
+	
+	String reservationId;
+	String journalName;
 	
 	// use serialization friendly map
 	private Map<String, String> rawParams;
@@ -33,11 +51,34 @@ public class VmWorkStart extends VmWork {
 	}
 
 	public DeploymentPlan getPlan() {
+		// this is ugly, to work with legacy code, we need to re-construct the DeploymentPlan hard-codely
+		// this has to be refactored together with migrating legacy code into the new way
+		
+		ReservationContext context = null;
+		if(reservationId != null) {
+	        Journal journal = new Journal.LogJournal("VmWorkStart", s_logger);
+			context = new ReservationContextImpl(reservationId, journal, CallContext.current().getCallingUser(),
CallContext.current().getCallingAccount());
+		}
+		
+		DeploymentPlan plan = new DataCenterDeployment(
+				dcId, podId, clusterId, hostId, poolId, physicalNetworkId, 
+				context);
 		return plan;
 	}
 
 	public void setPlan(DeploymentPlan plan) {
-		this.plan = plan;
+		if(plan != null) {
+			dcId = plan.getDataCenterId();
+			podId = plan.getPodId();
+			clusterId = plan.getClusterId();
+			hostId = plan.getHostId();
+			poolId = plan.getPoolId();
+			physicalNetworkId = plan.getPhysicalNetworkId();
+			avoids = plan.getAvoids();
+			
+			if(plan.getReservationContext() != null)
+				reservationId = plan.getReservationContext().getReservationId();
+		}
 	}
 
 	public Map<String, String> getRawParams() {
@@ -55,7 +96,7 @@ public class VmWorkStart extends VmWork {
 			// Strong-typing for VirtualMachineProfile.Param is really over-kill, have to deal with
it anyway
 			for(Map.Entry<String, String> entry : rawParams.entrySet()) {
 				VirtualMachineProfile.Param key = new VirtualMachineProfile.Param(entry.getKey());
-				Object val = ApiSerializerHelper.fromSerializedString(entry.getValue());
+				Object val = JobSerializerHelper.fromObjectSerializedString(entry.getValue());
 				map.put(key, val);
 			}
 		}
@@ -67,7 +108,8 @@ public class VmWorkStart extends VmWork {
 		if(params != null) {
 			rawParams = new HashMap<String, String>();
 			for(Map.Entry<VirtualMachineProfile.Param, Object> entry : params.entrySet()) {
-				rawParams.put(entry.getKey().getName(), ApiSerializerHelper.toSerializedString(entry.getValue()));
+				rawParams.put(entry.getKey().getName(), JobSerializerHelper.toObjectSerializedString(
+					entry.getValue() instanceof Serializable ? (Serializable)entry.getValue() : entry.getValue().toString()));
 			}
 		}
 	}


Mime
View raw message