cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthon...@apache.org
Subject git commit: updated refs/heads/master to 04b48ae
Date Thu, 05 Dec 2013 09:45:02 GMT
Updated Branches:
  refs/heads/master 22422b9dd -> 04b48ae04


XS VMmetadata platform contains virtual platform related info, CS should save platform info
in DB to migrate the VM to other Cluster


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

Branch: refs/heads/master
Commit: 04b48ae04e4831611c248e380466f1713267c600
Parents: 22422b9
Author: Anthony Xu <anthony.xu@citrix.com>
Authored: Wed Dec 4 23:54:56 2013 -0800
Committer: Anthony Xu <anthony.xu@citrix.com>
Committed: Thu Dec 5 01:41:14 2013 -0800

----------------------------------------------------------------------
 core/src/com/cloud/agent/api/StopAnswer.java    |  25 ++--
 .../com/cloud/vm/VirtualMachineManagerImpl.java |  78 +++++-------
 .../xen/resource/CitrixResourceBase.java        | 123 +++++++++----------
 .../xen/resource/XenServer610Resource.java      |  14 ---
 .../xen/resource/XenServerPoolVms.java          |   6 +-
 .../com/cloud/template/TemplateManagerImpl.java |  29 ++++-
 utils/src/com/cloud/utils/StringUtils.java      |  26 ++++
 7 files changed, 148 insertions(+), 153 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04b48ae0/core/src/com/cloud/agent/api/StopAnswer.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/agent/api/StopAnswer.java b/core/src/com/cloud/agent/api/StopAnswer.java
index 6ced335..b593174 100755
--- a/core/src/com/cloud/agent/api/StopAnswer.java
+++ b/core/src/com/cloud/agent/api/StopAnswer.java
@@ -18,35 +18,28 @@ package com.cloud.agent.api;
 
 public class StopAnswer extends RebootAnswer {
 
-    private String hypervisortoolsversion;
-    Integer timeOffset;
+    private String platform;
 
     protected StopAnswer() {
     }
 
-    public StopAnswer(StopCommand cmd, String details, String hypervisortoolsversion, Integer
timeOffset, boolean success) {
-        super(cmd, details, success);
-        this.hypervisortoolsversion = hypervisortoolsversion;
-        this.timeOffset = timeOffset;
+    public StopAnswer(StopCommand cmd, String details, String platform, boolean success)
{
+        super(cmd,  details, success);
+        this.platform = platform;
     }
 
     public StopAnswer(StopCommand cmd, String details, boolean success) {
-        super(cmd, details, success);
-        this.hypervisortoolsversion = null;
-        this.timeOffset = null;
+        super(cmd,  details, success);
+        this.platform = null;
     }
 
     public StopAnswer(StopCommand cmd, Exception e) {
         super(cmd, e);
-        this.hypervisortoolsversion = null;
-        this.timeOffset = null;
+        this.platform = null;
     }
 
-    public String getHypervisorToolsVersion() {
-        return hypervisortoolsversion;
+    public String getPlatform() {
+        return platform;
     }
 
-    public Integer getTimeOffset() {
-        return timeOffset;
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04b48ae0/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 cbaddc9..5136130 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -964,15 +964,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                                 s_logger.info("The guru did not like the answers so stopping
" + vm);
                             }
 
-                            StopCommand cmd = new StopCommand(vm, ExecuteInSequence.value());
-                            StopAnswer answer = (StopAnswer)_agentMgr.easySend(destHostId,
cmd);
-                            if (answer != null) {
-                                String hypervisortoolsversion = answer.getHypervisorToolsVersion();
-                                if (hypervisortoolsversion != null) {
-                                    if (vm.getType() == VirtualMachine.Type.User) {
+                            StopCommand cmd = new StopCommand(vm,  ExecuteInSequence.value());
+                            StopAnswer answer = (StopAnswer) _agentMgr.easySend(destHostId,
cmd);
+                            if ( answer != null ) {
+                                if (vm.getType() == VirtualMachine.Type.User) {
+                                    String platform = answer.getPlatform();
+                                    if (platform != null) {
                                         UserVmVO userVm = _userVmDao.findById(vm.getId());
                                         _userVmDao.loadDetails(userVm);
-                                        userVm.setDetail("hypervisortoolsversion", hypervisortoolsversion);
+                                        userVm.setDetail("platform",  platform);
                                         _userVmDao.saveDetails(userVm);
                                     }
                                 }
@@ -1128,14 +1128,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         VirtualMachine vm = profile.getVirtualMachine();
         StopCommand stop = new StopCommand(vm, ExecuteInSequence.value());
         try {
-            StopAnswer answer = (StopAnswer)_agentMgr.send(vm.getHostId(), stop);
-            if (answer != null) {
-                String hypervisortoolsversion = answer.getHypervisorToolsVersion();
-                if (hypervisortoolsversion != null) {
-                    if (vm.getType() == VirtualMachine.Type.User) {
+            StopAnswer answer = (StopAnswer) _agentMgr.send(vm.getHostId(), stop);
+            if ( answer != null ) {
+                if (vm.getType() == VirtualMachine.Type.User) {
+                    String platform = answer.getPlatform();
+                    if (platform != null) {
                         UserVmVO userVm = _userVmDao.findById(vm.getId());
                         _userVmDao.loadDetails(userVm);
-                        userVm.setDetail("hypervisortoolsversion", hypervisortoolsversion);
+                        userVm.setDetail("platform",  platform);
                         _userVmDao.saveDetails(userVm);
                     }
                 }
@@ -1368,14 +1368,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         StopAnswer answer = null;
         try {
             answer = (StopAnswer)_agentMgr.send(vm.getHostId(), stop);
-
-            if (answer != null) {
-                String hypervisortoolsversion = answer.getHypervisorToolsVersion();
-                if (hypervisortoolsversion != null) {
-                    if (vm.getType() == VirtualMachine.Type.User) {
+            if ( answer != null ) {
+                if (vm.getType() == VirtualMachine.Type.User) {
+                    String platform = answer.getPlatform();
+                    if ( platform != null) {
                         UserVmVO userVm = _userVmDao.findById(vm.getId());
                         _userVmDao.loadDetails(userVm);
-                        userVm.setDetail("hypervisortoolsversion", hypervisortoolsversion);
+                        userVm.setDetail("platform",  platform);
                         _userVmDao.saveDetails(userVm);
                     }
                 }
@@ -1383,16 +1382,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
             stopped = answer.getResult();
             if (!stopped) {
                 throw new CloudRuntimeException("Unable to stop the virtual machine due to
" + answer.getDetails());
-            } else {
-                Integer timeoffset = answer.getTimeOffset();
-                if (timeoffset != null) {
-                    if (vm.getType() == VirtualMachine.Type.User) {
-                        UserVmVO userVm = _userVmDao.findById(vm.getId());
-                        _userVmDao.loadDetails(userVm);
-                        userVm.setDetail("timeoffset", timeoffset.toString());
-                        _userVmDao.saveDetails(userVm);
-                    }
-                }
             }
             vmGuru.finalizeStop(profile, answer);
 
@@ -2572,21 +2561,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
                 ") stopped on host " + hostDesc + " due to storage failure", "Virtual Machine
" + vm.getInstanceName() + " (id: " + vm.getId() + ") running on host [" +
                 vm.getHostId() + "] stopped due to storage failure.");
         }
-        // track hypervsion tools version
-        if (info.hvtoolsversion != null && !info.hvtoolsversion.isEmpty()) {
+        // track platform info
+        if( info.platform != null && !info.platform.isEmpty() ) {
             if (vm.getType() == VirtualMachine.Type.User) {
                 UserVmVO userVm = _userVmDao.findById(vm.getId());
                 _userVmDao.loadDetails(userVm);
-                userVm.setDetail("hypervisortoolsversion", info.hvtoolsversion);
-                _userVmDao.saveDetails(userVm);
-            }
-        }
-        // track hypervsion tools version
-        if (info.hvtoolsversion != null && !info.hvtoolsversion.isEmpty()) {
-            if (vm.getType() == VirtualMachine.Type.User) {
-                UserVmVO userVm = _userVmDao.findById(vm.getId());
-                _userVmDao.loadDetails(userVm);
-                userVm.setDetail("hypervisortoolsversion", info.hvtoolsversion);
+                userVm.setDetail("platform",  info.platform);
                 _userVmDao.saveDetails(userVm);
             }
         }
@@ -2974,17 +2954,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         public String name;
         public State state;
         public String hostUuid;
-        public String hvtoolsversion;
         public VMInstanceVO vm;
+        public String platform;
 
         @SuppressWarnings("unchecked")
-        public AgentVmInfo(String name, VMInstanceVO vm, State state, String host, String
hvtoolsversion) {
+        public AgentVmInfo(String name, VMInstanceVO vm, State state, String host, String
platform) {
             this.name = name;
             this.state = state;
             this.vm = vm;
-            hostUuid = host;
-            this.hvtoolsversion = hvtoolsversion;
-
+            this.hostUuid = host;
+            this.platform = platform;
+            
         }
 
         public AgentVmInfo(String name, VMInstanceVO vm, State state, String host) {
@@ -2998,9 +2978,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
         public String getHostUuid() {
             return hostUuid;
         }
-
-        public String getHvtoolsversion() {
-            return hvtoolsversion;
+        
+        public String getPlatform() {
+            return platform;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04b48ae0/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index ec62c25..6bc8326 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -295,6 +295,7 @@ import com.cloud.utils.StringUtils;
 import com.cloud.utils.Ternary;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
+import com.cloud.utils.StringUtils;
 import com.cloud.vm.DiskProfile;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.PowerState;
@@ -1320,23 +1321,6 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
             vmr.VCPUsMax = 32L;
         }
 
-        Map<String, String> details = vmSpec.getDetails();
-        if (details != null) {
-            String timeoffset = details.get("timeoffset");
-            if (timeoffset != null) {
-                Map<String, String> platform = vmr.platform;
-                platform.put("timeoffset", timeoffset);
-                vmr.platform = platform;
-            }
-
-            String coresPerSocket = details.get("cpu.corespersocket");
-            if (coresPerSocket != null) {
-                Map<String, String> platform = vmr.platform;
-                platform.put("cores-per-socket", coresPerSocket);
-                vmr.platform = platform;
-            }
-        }
-
         vmr.VCPUsAtStartup = (long)vmSpec.getCpus();
         vmr.consoles.clear();
 
@@ -1420,6 +1404,36 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
     }
 
     protected void finalizeVmMetaData(VM vm, Connection conn, VirtualMachineTO vmSpec) throws
Exception {
+
+        Map<String, String> details = vmSpec.getDetails();
+        if ( details != null ) {
+            String platformstring = details.get("platform");
+            if (platformstring != null && !platformstring.isEmpty() ) {
+                Map<String, String> platform = StringUtils.stringToMap(platformstring);
+                vm.setPlatform(conn, platform);
+            } else {
+                String timeoffset = details.get("timeoffset");
+                if (timeoffset != null) {
+                    Map<String, String> platform = vm.getPlatform(conn);
+                    platform.put("timeoffset", timeoffset);
+                    vm.setPlatform(conn, platform);
+                }
+                String coresPerSocket = details.get("cpu.corespersocket");
+                if (coresPerSocket != null) {
+                    Map<String, String> platform = vm.getPlatform(conn);
+                    platform.put("cores-per-socket", coresPerSocket);
+                    vm.setPlatform(conn, platform);
+                }
+
+                String xentoolsversion = details.get("hypervisortoolsversion");
+                if ( xentoolsversion == null || !xentoolsversion.equalsIgnoreCase("xenserver61")
) {
+                     Map<String, String> platform = vm.getPlatform(conn);
+                     platform.remove("device_id");
+                     vm.setPlatform(conn, platform);
+                 }
+
+            }
+        }
     }
 
     protected String handleVmStartFailure(Connection conn, String vmName, VM vm, String message,
Throwable th) {
@@ -3085,7 +3099,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 s_logger.trace("VM " + record.nameLabel + ": powerstate = " + ps + "; vm
state=" + state.toString());
             }
             Host host = record.residentOn;
-            String xstoolsversion = getVMXenToolsVersion(record.platform);
+            String platformstring = StringUtils.mapToString(record.platform);
             String host_uuid = null;
             if (!isRefNull(host)) {
                 try {
@@ -3097,7 +3111,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 } catch (XmlRpcException e) {
                     s_logger.error("Failed to get host uuid for host " + host.toWireString(),
e);
                 }
-                vmStates.put(record.nameLabel, new Ternary<String, State, String>(host_uuid,
state, xstoolsversion));
+                vmStates.put(record.nameLabel, new Ternary<String, State, String>(host_uuid,
state, platformstring));
             }
         }
 
@@ -4072,6 +4086,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
     @Override
     public StopAnswer execute(StopCommand cmd) {
         String vmName = cmd.getVmName();
+        String platformstring = null;
         try {
             Connection conn = getConnection();
             Set<VM> vms = VM.getByNameLabel(conn, vmName);
@@ -4101,7 +4116,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
             }
             for (VM vm : vms) {
                 VM.Record vmr = vm.getRecord(conn);
-
+                platformstring = StringUtils.mapToString(vmr.platform);
                 if (vmr.isControlDomain) {
                     String msg = "Tring to Shutdown control domain";
                     s_logger.warn(msg);
@@ -4111,7 +4126,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 if (vmr.powerState == VmPowerState.RUNNING && !isRefNull(vmr.residentOn)
&& !vmr.residentOn.getUuid(conn).equals(_host.uuid)) {
                     String msg = "Stop Vm " + vmName + " failed due to this vm is not running
on this host: " + _host.uuid + " but host:" + vmr.residentOn.getUuid(conn);
                     s_logger.warn(msg);
-                    return new StopAnswer(cmd, msg, false);
+                    return new StopAnswer(cmd, msg, platformstring, false);
                 }
 
                 State state = s_vms.getState(_cluster, vmName);
@@ -4139,24 +4154,13 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 } catch (Exception e) {
                     String msg = "Catch exception " + e.getClass().getName() + " when stop
VM:" + cmd.getVmName() + " due to " + e.toString();
                     s_logger.debug(msg);
-                    return new StopAnswer(cmd, msg, false);
+                    return new StopAnswer(cmd, msg, platformstring, false);
                 } finally {
 
                     try {
                         if (vm.getPowerState(conn) == VmPowerState.HALTED) {
                             disconnectManagedVolumes(conn, vm);
 
-                            Map<String, String> platform = vm.getPlatform(conn);
-                            Integer timeoffset = null;
-                            try {
-                                if (platform.containsKey("timeoffset")) {
-                                    timeoffset = Integer.valueOf(platform.get("timeoffset"));
-                                }
-                            } catch (NumberFormatException e) {
-                                s_logger.error("Error while reading the platform:timeoffset
field of the instance", e);
-                            }
-                            String xentoolsversion = getVMXenToolsVersion(platform);
-
                             Set<VIF> vifs = vm.getVIFs(conn);
                             List<Network> networks = new ArrayList<Network>();
                             for (VIF vif : vifs) {
@@ -4177,11 +4181,8 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                                     // network might be destroyed by other host
                                 }
                             }
-                            return new StopAnswer(cmd, "Stop VM " + vmName + " Succeed",
xentoolsversion, timeoffset, true);
+                            return new StopAnswer(cmd, "Stop VM " + vmName + " Succeed",
platformstring ,true);
                         }
-                    } catch (XenAPIException e) {
-                        String msg = "VM destroy failed in Stop " + vmName + " Command due
to " + e.toString();
-                        s_logger.warn(msg, e);
                     } catch (Exception e) {
                         String msg = "VM destroy failed in Stop " + vmName + " Command due
to " + e.getMessage();
                         s_logger.warn(msg, e);
@@ -4194,19 +4195,12 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 }
             }
 
-        } catch (XenAPIException e) {
+        } catch (Exception e) {
             String msg = "Stop Vm " + vmName + " fail due to " + e.toString();
             s_logger.warn(msg, e);
-            return new StopAnswer(cmd, msg, false);
-        } catch (XmlRpcException e) {
-            String msg = "Stop Vm " + vmName + " fail due to " + e.getMessage();
-            s_logger.warn(msg, e);
-            return new StopAnswer(cmd, msg, false);
-        } catch (Exception e) {
-            s_logger.warn("Unable to stop " + vmName + " due to ", e);
-            return new StopAnswer(cmd, e);
+            return new StopAnswer(cmd, msg, platformstring, false);
         }
-        return new StopAnswer(cmd, "Stop VM failed", false);
+        return new StopAnswer(cmd, "Stop VM failed", platformstring, false);
     }
 
     /*Override by subclass*/
@@ -8224,13 +8218,12 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 String vm_name = record.nameLabel;
                 VmPowerState ps = record.powerState;
                 final State state = convertToState(ps);
-                String xstoolsversion = getVMXenToolsVersion(record.platform);
                 Host host = record.residentOn;
                 String host_uuid = null;
                 if (!isRefNull(host)) {
                     host_uuid = host.getUuid(conn);
                     synchronized (_cluster.intern()) {
-                        s_vms.put(_cluster, host_uuid, vm_name, state, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm_name, state, null);
                     }
                 }
                 if (s_logger.isTraceEnabled()) {
@@ -8259,19 +8252,19 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
 
             for (final Map.Entry<String, Ternary<String, State, String>> entry
: newStates.entrySet()) {
                 final String vm = entry.getKey();
-                String xstoolsversion = entry.getValue().third();
+                String platform = entry.getValue().third();
                 State newState = entry.getValue().second();
                 String host_uuid = entry.getValue().first();
                 final Ternary<String, State, String> oldState = oldStates.remove(vm);
-
-                // check if xstoolsversion changed
-                if (xstoolsversion != null && oldState != null) {
-                    if (xstoolsversion != oldState.third() && newState != State.Stopped
&& newState != State.Stopping) {
-                        s_logger.warn("Detecting a change in xstoolsversion for " + vm);
-                        changes.put(vm, new Ternary<String, State, String>(host_uuid,
newState, xstoolsversion));
+                
+                // check if platform changed
+                if (platform != null && oldState != null){
+                    if (!platform.equals(oldState.third()) && newState != State.Stopped
&& newState != State.Stopping){
+                        s_logger.warn("Detecting a change in platform for " + vm);
+                        changes.put(vm, new Ternary<String, State, String>(host_uuid,
newState, platform));
 
                         s_logger.debug("11. The VM " + vm + " is in " + newState + " state");
-                        s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm, newState, platform);
                         continue;
                     }
                 }
@@ -8279,10 +8272,10 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                 if (host_uuid != null && oldState != null) {
                     if (!host_uuid.equals(oldState.first()) && newState != State.Stopped
&& newState != State.Stopping) {
                         s_logger.warn("Detecting a change in host for " + vm);
-                        changes.put(vm, new Ternary<String, State, String>(host_uuid,
newState, null));
+                        changes.put(vm, new Ternary<String, State, String>(host_uuid,
newState, platform));
 
                         s_logger.debug("11. The VM " + vm + " is in " + newState + " state");
-                        s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm, newState, platform);
                         continue;
                     }
                 }
@@ -8300,31 +8293,31 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
                     continue;
                 }
                 if (oldState == null) {
-                    s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                    s_vms.put(_cluster, host_uuid, vm, newState, platform);
                     s_logger.warn("Detecting a new state but couldn't find a old state so
adding it to the changes: " + vm);
-                    changes.put(vm, new Ternary<String, State, String>(host_uuid, newState,
null));
+                    changes.put(vm, new Ternary<String, State, String>(host_uuid, newState,
platform));
                 } else if (oldState.second() == State.Starting) {
                     if (newState == State.Running) {
                         s_logger.debug("12. The VM " + vm + " is in " + State.Running + "
state");
-                        s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm, newState, platform);
                     } else if (newState == State.Stopped) {
                         s_logger.warn("Ignoring vm " + vm + " because of a lag in starting
the vm.");
                     }
                 } else if (oldState.second() == State.Migrating) {
                     if (newState == State.Running) {
                         s_logger.debug("Detected that an migrating VM is now running: " +
vm);
-                        s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm, newState, platform);
                     }
                 } else if (oldState.second() == State.Stopping) {
                     if (newState == State.Stopped) {
                         s_logger.debug("13. The VM " + vm + " is in " + State.Stopped + "
state");
-                        s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                        s_vms.put(_cluster, host_uuid, vm, newState, platform);
                     } else if (newState == State.Running) {
                         s_logger.warn("Ignoring vm " + vm + " because of a lag in stopping
the vm. ");
                     }
                 } else if (oldState.second() != newState) {
                     s_logger.debug("14. The VM " + vm + " is in " + newState + " state was
" + oldState.second());
-                    s_vms.put(_cluster, host_uuid, vm, newState, xstoolsversion);
+                    s_vms.put(_cluster, host_uuid, vm, newState, platform);
                     if (newState == State.Stopped) {
                         /*
                          * if (s_vmsKilled.remove(vm)) { s_logger.debug("VM " + vm + " has
been killed for storage. ");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04b48ae0/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java
b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java
index 9a0d559..b7199c8 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer610Resource.java
@@ -454,18 +454,4 @@ public class XenServer610Resource extends XenServer56FP1Resource {
         }
         return "xenserver56";
     }
-
-    @Override
-    protected void finalizeVmMetaData(VM vm, Connection conn, VirtualMachineTO vmSpec) throws
Exception {
-        Map<String, String> details = vmSpec.getDetails();
-        if (details != null) {
-            String xentoolsversion = details.get("hypervisortoolsversion");
-            if (xentoolsversion == null || !xentoolsversion.equalsIgnoreCase("xenserver61"))
{
-                Map<String, String> platform = vm.getPlatform(conn);
-                platform.remove("device_id");
-                vm.setPlatform(conn, platform);
-            }
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04b48ae0/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerPoolVms.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerPoolVms.java
b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerPoolVms.java
index 209be87..71c0e39 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerPoolVms.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerPoolVms.java
@@ -51,9 +51,9 @@ public class XenServerPoolVms {
         return pv == null ? State.Stopped : pv.second(); // if a VM is absent on the cluster,
it is effectively in stopped state.
     }
 
-    public void put(String clusterId, String hostUuid, String name, State state, String xstoolsversion)
{
-        HashMap<String, Ternary<String, State, String>> vms = getClusterVmState(clusterId);
-        vms.put(name, new Ternary<String, State, String>(hostUuid, state, xstoolsversion));
+    public void put(String clusterId, String hostUuid, String name, State state, String platform){
+        HashMap<String, Ternary<String, State, String>> vms= getClusterVmState(clusterId);
+        vms.put(name, new Ternary<String, State, String>(hostUuid, state, platform));
     }
 
     public void put(String clusterId, String hostUuid, String name, State state) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04b48ae0/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index f2fdcee..afaa5b0 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.HashMap;
 import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
@@ -185,6 +186,7 @@ import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.dao.UserVmDao;
+import com.cloud.vm.dao.UserVmDetailsDao;
 import com.cloud.vm.dao.VMInstanceDao;
 
 @Local(value = {TemplateManager.class, TemplateApiService.class})
@@ -200,6 +202,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
     @Inject
     VMTemplateZoneDao _tmpltZoneDao;
     @Inject
+    protected UserVmDetailsDao _vmDetailsDao;
+    @Inject
     protected VMTemplateDetailsDao _templateDetailsDao;
     @Inject
     VMInstanceDao _vmInstanceDao;
@@ -1624,13 +1628,26 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         VMTemplateVO template = _tmpltDao.persist(privateTemplate);
         // Increment the number of templates
         if (template != null) {
-            Map<String, String> detailsStr = cmd.getDetails();
-            if (detailsStr != null) {
-                List<VMTemplateDetailVO> details = new ArrayList<VMTemplateDetailVO>();
-                for (String key : detailsStr.keySet()) {
-                    details.add(new VMTemplateDetailVO(template.getId(), key, detailsStr.get(key)));
+            Map<String, String> details = new HashMap<String, String>();
+            if ( volume != null ) {
+                Long vmId = volume.getInstanceId();
+                if ( vmId != null ) {
+	            UserVmVO userVm = _userVmDao.findById(vmId);
+                    if (userVm == null) {
+                        _userVmDao.loadDetails(userVm);
+                        details.putAll(userVm.getDetails());
+                    }
+                }
+            }
+            if(cmd.getDetails() != null) {
+                details.putAll(cmd.getDetails());
+            }
+            if( !details.isEmpty()) {
+                List<VMTemplateDetailVO> tdetails = new ArrayList<VMTemplateDetailVO>();
+                for (String key : details.keySet()) {
+                    tdetails.add(new VMTemplateDetailVO(template.getId(), key, details.get(key)));
                 }
-                _templateDetailsDao.saveDetails(details);
+                this._templateDetailsDao.saveDetails(tdetails);
             }
 
             _resourceLimitMgr.incrementResourceCount(templateOwner.getId(), ResourceType.template);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04b48ae0/utils/src/com/cloud/utils/StringUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/StringUtils.java b/utils/src/com/cloud/utils/StringUtils.java
index ddd09de..6b4c8f8 100644
--- a/utils/src/com/cloud/utils/StringUtils.java
+++ b/utils/src/com/cloud/utils/StringUtils.java
@@ -19,6 +19,9 @@ package com.cloud.utils;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
+
 import java.util.regex.Pattern;
 
 import org.owasp.esapi.StringUtilities;
@@ -185,4 +188,27 @@ public class StringUtils {
         int found = searchable.lastIndexOf(separator);
         return found > 0 ? found : end - start;
     }
+
+
+    public static Map<String, String> stringToMap(String s){
+        Map<String, String> map=new HashMap<String, String>();
+        String[] elements = s.split(";");
+        for (String parts: elements) {
+            String[] keyValue = parts.split(":");
+            map.put(keyValue[0], keyValue[1]);
+        }
+        return map;
+    }
+
+
+    public static String mapToString(Map<String, String> map){
+        String s = "";
+        for (Map.Entry<String, String> entry: map.entrySet()) {
+            s += entry.getKey() + ":" + entry.getValue() +";";
+        }
+        if (s.length() > 0) {
+            s = s.substring(0, s.length()-1);
+        }
+        return s;
+    }
 }


Mime
View raw message