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 521b284
Date Wed, 30 Jul 2014 22:19:54 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 680d4202d -> 521b2840b


new vmsync for simulator


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

Branch: refs/heads/master
Commit: 521b2840b2aa2dae98e8007344f345d23e055195
Parents: 680d420
Author: Anthony Xu <anthony.xu@citrix.com>
Authored: Wed Jul 30 15:10:51 2014 -0700
Committer: Anthony Xu <anthony.xu@citrix.com>
Committed: Wed Jul 30 15:10:51 2014 -0700

----------------------------------------------------------------------
 .../agent/manager/MockStorageManagerImpl.java   |  6 +--
 .../com/cloud/agent/manager/MockVmManager.java  |  4 +-
 .../cloud/agent/manager/MockVmManagerImpl.java  | 45 +++++---------------
 .../cloud/agent/manager/SimulatorManager.java   |  6 +--
 .../agent/manager/SimulatorManagerImpl.java     |  4 +-
 .../cloud/resource/AgentRoutingResource.java    | 14 +-----
 .../src/com/cloud/simulator/MockVMVO.java       | 19 +++++----
 .../src/com/cloud/simulator/MockVm.java         |  6 +--
 .../com/cloud/simulator/dao/MockVMDaoImpl.java  |  4 +-
 setup/db/create-schema-simulator.sql            |  4 +-
 10 files changed, 37 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/521b2840/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
index 89b7950..205e485 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java
@@ -100,7 +100,6 @@ import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.DiskProfile;
-import com.cloud.vm.VirtualMachine.State;
 
 @Component
 @Local(value = {MockStorageManager.class})
@@ -511,13 +510,10 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa
             if (volume != null) {
                 _mockVolumeDao.remove(volume.getId());
             }
-
             if (cmd.getVmName() != null) {
                 MockVm vm = _mockVMDao.findByVmName(cmd.getVmName());
                 if (vm != null) {
-                    vm.setState(State.Expunging);
-                    MockVMVO vmVo = _mockVMDao.createForUpdate(vm.getId());
-                    _mockVMDao.update(vm.getId(), vmVo);
+                    _mockVMDao.remove(vm.getId());
                 }
             }
             txn.commit();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/521b2840/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java
index 2032c7a..1fb1153 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java
@@ -56,11 +56,11 @@ import com.cloud.agent.api.routing.VmDataCommand;
 import com.cloud.simulator.MockVMVO;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.Manager;
-import com.cloud.vm.VirtualMachine.State;
+import com.cloud.vm.VirtualMachine.PowerState;
 
 public interface MockVmManager extends Manager {
 
-    Map<String, State> getVmStates(String hostGuid);
+    Map<String, PowerState> getVmStates(String hostGuid);
 
     Map<String, MockVMVO> getVms(String hostGuid);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/521b2840/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
index 7650afa..00cd108 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java
@@ -90,7 +90,6 @@ import com.cloud.utils.Ternary;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.VirtualMachine.PowerState;
 
 @Component
@@ -147,7 +146,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager
{
             vm = new MockVMVO();
             vm.setCpu(cpuHz);
             vm.setMemory(ramSize);
-            vm.setState(State.Running);
+            vm.setPowerState(PowerState.PowerOn);
             vm.setName(vmName);
             vm.setVncPort(vncPort);
             vm.setHostId(host.getId());
@@ -175,8 +174,8 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager
{
                 txn.close();
             }
         } else {
-            if (vm.getState() == State.Stopped) {
-                vm.setState(State.Running);
+            if (vm.getPowerState() == PowerState.PowerOff) {
+                vm.setPowerState(PowerState.PowerOn);
                 txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
                 try {
                     txn.start();
@@ -193,7 +192,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager
{
             }
         }
 
-        if (vm.getState() == State.Running && vmName.startsWith("s-")) {
+        if (vm.getPowerState() == PowerState.PowerOn && vmName.startsWith("s-"))
{
             String prvIp = null;
             String prvMac = null;
             String prvNetMask = null;
@@ -289,18 +288,18 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager
{
     }
 
     @Override
-    public Map<String, State> getVmStates(String hostGuid) {
+    public Map<String, PowerState> getVmStates(String hostGuid) {
         TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
         try {
             txn.start();
-            Map<String, State> states = new HashMap<String, State>();
+            Map<String, PowerState> states = new HashMap<String, PowerState>();
             List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
             if (vms.isEmpty()) {
                 txn.commit();
                 return states;
             }
             for (MockVm vm : vms) {
-                states.put(vm.getName(), vm.getState());
+                states.put(vm.getName(), vm.getPowerState());
             }
             txn.commit();
             return states;
@@ -355,7 +354,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager
{
             }
 
             txn.commit();
-            return new CheckVirtualMachineAnswer(cmd, vm.getState()==State.Running? PowerState.PowerOn:
PowerState.PowerOff, vm.getVncPort());
+            return new CheckVirtualMachineAnswer(cmd, vm.getPowerState(), vm.getVncPort());
         } catch (Exception ex) {
             txn.rollback();
             throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(),
ex);
@@ -392,10 +391,6 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager
{
             MockVMVO vm = _mockVmDao.findByVmNameAndHost(vmName, info.getHostUuid());
             if (vm == null) {
                 return new MigrateAnswer(cmd, false, "can't find vm:" + vmName + " on host:"
+ info.getHostUuid(), null);
-            } else {
-                if (vm.getState() == State.Migrating) {
-                    vm.setState(State.Running);
-                }
             }
 
             MockHost destHost = _mockHostDao.findByGuid(destGuid);
@@ -423,7 +418,6 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager
{
         try {
             txn.start();
             MockVMVO vm = _mockVmDao.findById(vmTo.getId());
-            vm.setState(State.Migrating);
             _mockVmDao.update(vm.getId(), vm);
             txn.commit();
         } catch (Exception ex) {
@@ -505,7 +499,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager
{
             return new RevertToVMSnapshotAnswer(cmd, false, "No VM by name " + cmd.getVmName());
         }
         s_logger.debug("Reverted to snapshot " + snapshot + " of VM " + vm);
-        return new RevertToVMSnapshotAnswer(cmd, cmd.getVolumeTOs(), vmVo.getState()== State.Running?
PowerState.PowerOn: PowerState.PowerOff);
+        return new RevertToVMSnapshotAnswer(cmd, cmd.getVolumeTOs(), vmVo.getPowerState());
     }
 
     @Override
@@ -516,7 +510,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager
{
             String vmName = cmd.getVmName();
             MockVm vm = _mockVmDao.findByVmName(vmName);
             if (vm != null) {
-                vm.setState(State.Stopped);
+                vm.setPowerState(PowerState.PowerOff);
                 _mockVmDao.update(vm.getId(), (MockVMVO)vm);
             }
 
@@ -537,24 +531,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager
{
 
     @Override
     public RebootAnswer rebootVM(RebootCommand cmd) {
-        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
-        try {
-            txn.start();
-            MockVm vm = _mockVmDao.findByVmName(cmd.getVmName());
-            if (vm != null) {
-                vm.setState(State.Running);
-                _mockVmDao.update(vm.getId(), (MockVMVO)vm);
-            }
-            txn.commit();
-            return new RebootAnswer(cmd, "Rebooted " + cmd.getVmName(), true);
-        } catch (Exception ex) {
-            txn.rollback();
-            throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
-        } finally {
-            txn.close();
-            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
-            txn.close();
-        }
+        return new RebootAnswer(cmd, "Rebooted " + cmd.getVmName(), true);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/521b2840/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManager.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManager.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManager.java
index 485693a..97267d8 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManager.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManager.java
@@ -27,7 +27,7 @@ import com.cloud.simulator.MockVMVO;
 import com.cloud.simulator.dao.MockConfigurationDao;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.Manager;
-import com.cloud.vm.VirtualMachine.State;
+import com.cloud.vm.VirtualMachine.PowerState;
 
 public interface SimulatorManager extends Manager {
     public static final String Name = "simulator manager";
@@ -62,7 +62,7 @@ public interface SimulatorManager extends Manager {
 
     public HashMap<String, Pair<Long, Long>> syncNetworkGroups(String hostGuid);
 
-    Map<String, State> getVmStates(String hostGuid);
+    Map<String, PowerState> getVmStates(String hostGuid);
 
     Map<String, MockVMVO> getVms(String hostGuid);
 
@@ -71,4 +71,4 @@ public interface SimulatorManager extends Manager {
     boolean clearSimulatorMock(Long id);
 
     MockConfigurationDao getMockConfigurationDao();
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/521b2840/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
index 6fb5372..0ea6855 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
@@ -128,7 +128,7 @@ import com.cloud.utils.component.PluggableService;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.vm.VirtualMachine.State;
+import com.cloud.vm.VirtualMachine.PowerState;
 import com.google.gson.Gson;
 import com.google.gson.stream.JsonReader;
 
@@ -453,7 +453,7 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
     }
 
     @Override
-    public Map<String, State> getVmStates(String hostGuid) {
+    public Map<String, PowerState> getVmStates(String hostGuid) {
         return _mockVmMgr.getVmStates(hostGuid);
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/521b2840/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
index 2fe938f..c3c5140 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
@@ -59,7 +59,6 @@ import com.cloud.storage.template.TemplateProp;
 import com.cloud.utils.Pair;
 import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.vm.VirtualMachine.PowerState;
-import com.cloud.vm.VirtualMachine.State;
 import com.google.gson.Gson;
 import com.google.gson.stream.JsonReader;
 
@@ -288,18 +287,7 @@ public class AgentRoutingResource extends AgentStorageResource {
     protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport() {
         HashMap<String, HostVmStateReportEntry> report = new HashMap<String, HostVmStateReportEntry>();
 
-        Map<String, State> states = _simMgr.getVmStates(this.hostGuid);
-        for (String vmName : states.keySet()) {
-            State state = states.get(vmName);
-            if (state == State.Running) {
-                report.put(vmName, new HostVmStateReportEntry(PowerState.PowerOn, agentHost.getName()));
-            } else if (state == State.Stopped) {
-                report.put(vmName, new HostVmStateReportEntry(PowerState.PowerOff, agentHost.getName()));
-            } else {
-                report.put(vmName, new HostVmStateReportEntry(PowerState.PowerUnknown, agentHost.getName()));
-            }
-        }
-
+        Map<String, PowerState> states = _simMgr.getVmStates(this.hostGuid);
         return report;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/521b2840/plugins/hypervisors/simulator/src/com/cloud/simulator/MockVMVO.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/simulator/MockVMVO.java b/plugins/hypervisors/simulator/src/com/cloud/simulator/MockVMVO.java
index 04b4e89..cf471a3 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/simulator/MockVMVO.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/simulator/MockVMVO.java
@@ -25,7 +25,7 @@ import javax.persistence.Table;
 
 import org.apache.cloudstack.api.InternalIdentity;
 
-import com.cloud.vm.VirtualMachine.State;
+import com.cloud.vm.VirtualMachine.PowerState;
 
 @Entity
 @Table(name = "mockvm")
@@ -44,8 +44,8 @@ public class MockVMVO implements MockVm, InternalIdentity {
     @Column(name = "type")
     private String vmType;
 
-    @Column(name = "state")
-    private State state;
+    @Column(name = "power_state")
+    protected PowerState powerState;
 
     @Column(name = "vnc_port")
     private int vncPort;
@@ -96,18 +96,19 @@ public class MockVMVO implements MockVm, InternalIdentity {
     }
 
     @Override
-    public State getState() {
-        return this.state;
+    public PowerState getPowerState() {
+        return powerState;
     }
 
     @Override
-    public String getType() {
-        return this.vmType;
+    public void setPowerState(PowerState powerState) {
+        this.powerState = powerState;
     }
 
+
     @Override
-    public void setState(State state) {
-        this.state = state;
+    public String getType() {
+        return this.vmType;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/521b2840/plugins/hypervisors/simulator/src/com/cloud/simulator/MockVm.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/simulator/MockVm.java b/plugins/hypervisors/simulator/src/com/cloud/simulator/MockVm.java
index 3e5fedd..7330039 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/simulator/MockVm.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/simulator/MockVm.java
@@ -16,16 +16,16 @@
 // under the License.
 package com.cloud.simulator;
 
-import com.cloud.vm.VirtualMachine.State;
+import com.cloud.vm.VirtualMachine.PowerState;
 
 // As storage is mapped from storage device, can virtually treat that VM here does
 public interface MockVm {
 
     public String getName();
 
-    public State getState();
+    public PowerState getPowerState();
 
-    public void setState(State state);
+    public void setPowerState(PowerState state);
 
     public void setHostId(long hostId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/521b2840/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
b/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
index d19dba4..4bf2f8e 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/simulator/dao/MockVMDaoImpl.java
@@ -59,7 +59,7 @@ public class MockVMDaoImpl extends GenericDaoBase<MockVMVO, Long>
implements Moc
     public List<MockVMVO> findByHostGuid(String guid) {
         SearchCriteria<MockVMVO> sc = GuidSearch.create();
         sc.setJoinParameters("host", "guid", guid);
-        sc.setParameters("state", VirtualMachine.State.Running);
+        sc.setParameters("power_state", VirtualMachine.PowerState.PowerOn);
         return listBy(sc);
     }
 
@@ -78,7 +78,7 @@ public class MockVMDaoImpl extends GenericDaoBase<MockVMVO, Long>
implements Moc
 
         GuidSearch = createSearchBuilder();
         GuidSearch.join("host", host, host.entity().getId(), GuidSearch.entity().getHostId(),
JoinBuilder.JoinType.INNER);
-        GuidSearch.and("state", GuidSearch.entity().getState(), SearchCriteria.Op.EQ);
+        GuidSearch.and("power_state", GuidSearch.entity().getPowerState(), SearchCriteria.Op.EQ);
         GuidSearch.done();
 
         vmNameSearch = createSearchBuilder();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/521b2840/setup/db/create-schema-simulator.sql
----------------------------------------------------------------------
diff --git a/setup/db/create-schema-simulator.sql b/setup/db/create-schema-simulator.sql
index d33596e..4bab391 100644
--- a/setup/db/create-schema-simulator.sql
+++ b/setup/db/create-schema-simulator.sql
@@ -73,14 +73,14 @@ CREATE TABLE `simulator`.`mockvm` (
   `name` varchar(255),
   `host_id` bigint unsigned,
   `type` varchar(40),
-  `state` varchar(40),
+  `power_state` varchar(40),
   `vnc_port` bigint unsigned,
   `memory` bigint unsigned,
   `cpu` bigint unsigned,
   `bootargs` varchar(255),
   PRIMARY KEY  (`id`),
   INDEX `i_mockvm__host_id`(`host_id`),
-  INDEX `i_mockvm__state`(`state`),
+  INDEX `i_mockvm__power_state`(`power_state`),
   INDEX `i_mockvm__type`(`type`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 


Mime
View raw message