cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject git commit: updated refs/heads/vmsync to ca3d630
Date Wed, 24 Apr 2013 17:42:06 GMT
Updated Branches:
  refs/heads/vmsync 8b4ec1927 -> ca3d6306f


Add support to track host change


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

Branch: refs/heads/vmsync
Commit: ca3d6306f74655e03c6b903c599bb85062874d53
Parents: 8b4ec19
Author: Kelven Yang <kelveny@gmail.com>
Authored: Wed Apr 24 10:41:47 2013 -0700
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Wed Apr 24 10:41:47 2013 -0700

----------------------------------------------------------------------
 core/src/com/cloud/vm/VMInstanceVO.java            |   41 +++++++++------
 server/src/com/cloud/vm/dao/VMInstanceDao.java     |    4 +-
 server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java |   33 +++++++++++-
 server/test/com/cloud/vm/dao/VmDaoTest.java        |   12 ++--
 setup/db/db/schema-410to420.sql                    |    3 +-
 5 files changed, 67 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca3d6306/core/src/com/cloud/vm/VMInstanceVO.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/vm/VMInstanceVO.java b/core/src/com/cloud/vm/VMInstanceVO.java
index d945e58..28bc5f0 100644
--- a/core/src/com/cloud/vm/VMInstanceVO.java
+++ b/core/src/com/cloud/vm/VMInstanceVO.java
@@ -96,17 +96,6 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State,
Vi
     @Column(name="last_host_id", updatable=true, nullable=true)
     protected Long lastHostId;
 
-    @Enumerated(value=EnumType.STRING)
-    @Column(name="power_state", updatable=true)
-    protected PowerState powerState;
-    
-    @Column(name="power_state_update_time", updatable=true, nullable=false)
-    @Temporal(value=TemporalType.TIMESTAMP)
-    protected Date powerStateUpdateTime;
-    
-    @Column(name="power_state_update_count", updatable=true)
-    protected int powerStateUpdateCount;
-    
     @Column(name="pod_id", updatable=true, nullable=false)
     protected Long podIdToDeployIn;
 
@@ -155,11 +144,6 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State,
Vi
     @Enumerated(value=EnumType.STRING)
     protected HypervisorType hypervisorType;
 
-/*
-    @Column(name="tags")
-    protected String tags;
-*/
-    
     @Transient
     Map<String, String> details;
 
@@ -168,6 +152,23 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State,
Vi
 
     @Column(name="disk_offering_id")
     protected Long diskOfferingId;
+
+    //
+    // Power state for VM state sync
+    //
+    @Enumerated(value=EnumType.STRING)
+    @Column(name="power_state", updatable=true)
+    protected PowerState powerState;
+    
+    @Column(name="power_state_update_time", updatable=true, nullable=false)
+    @Temporal(value=TemporalType.TIMESTAMP)
+    protected Date powerStateUpdateTime;
+    
+    @Column(name="power_state_update_count", updatable=true)
+    protected int powerStateUpdateCount;
+ 
+    @Column(name="power_host", updatable=true)
+    protected Long powerHostId;
     
     public VMInstanceVO(long id,
             long serviceOfferingId,
@@ -519,4 +520,12 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State,
Vi
 	public void setPowerStateUpdateCount(int count) {
 		this.powerStateUpdateCount = count;
 	}
+	
+	public Long getPowerHostId() {
+		return this.powerHostId;
+	}
+	
+	public void setPowerHostId(Long hostId) {
+		this.powerHostId = hostId;
+	}
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca3d6306/server/src/com/cloud/vm/dao/VMInstanceDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/dao/VMInstanceDao.java b/server/src/com/cloud/vm/dao/VMInstanceDao.java
index 1b47826..2a24126 100644
--- a/server/src/com/cloud/vm/dao/VMInstanceDao.java
+++ b/server/src/com/cloud/vm/dao/VMInstanceDao.java
@@ -116,5 +116,7 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>,
StateDao<
      */
     List<String> listDistinctHostNames(long networkId, VirtualMachine.Type... types);
 
-    void updatePowerState(long instanceId, VirtualMachine.PowerState powerState);
+    void updatePowerState(long instanceId, long powerHostId, VirtualMachine.PowerState powerState);
+    void resetVmPowerStateTracking(long instanceId);
+    void resetHostPowerStateTracking(long hostId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca3d6306/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java b/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
index 064ef1c..a3846ca 100644
--- a/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
+++ b/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
@@ -29,6 +29,7 @@ import java.util.Map;
 import javax.annotation.PostConstruct;
 import javax.ejb.Local;
 import javax.inject.Inject;
+import javax.persistence.Entity;
 
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
@@ -629,14 +630,16 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO,
Long> implem
     }
     
     @Override @DB
-    public void updatePowerState(long instanceId, VirtualMachine.PowerState powerState) {
+    public void updatePowerState(long instanceId, long powerHostId, VirtualMachine.PowerState
powerState) {
         Transaction txn = Transaction.currentTxn();
         txn.start();
         
         VMInstanceVO instance = findById(instanceId);
         if(instance != null) {
-        	if(instance.getPowerState() != powerState) {
+        	Long savedPowerHostId = instance.getPowerHostId();
+        	if(instance.getPowerState() != powerState || savedPowerHostId == null || savedPowerHostId.longValue()
!= powerHostId) {
         		instance.setPowerState(powerState);
+        		instance.setPowerHostId(powerHostId);
         		instance.setPowerStateUpdateCount(1);
         		instance.setPowerStateUpdateTime(DateUtil.currentGMTTime());
         		
@@ -654,4 +657,30 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO,
Long> implem
         
         txn.commit();
     }
+    
+    @Override @DB
+    public void resetVmPowerStateTracking(long instanceId) {
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
+        VMInstanceVO instance = findById(instanceId);
+        if(instance != null) {
+        	instance.setPowerStateUpdateCount(0);
+        	instance.setPowerStateUpdateTime(DateUtil.currentGMTTime());
+        	update(instanceId, instance);
+        }
+        
+        txn.commit();
+    }
+    
+    @Override @DB
+    public void resetHostPowerStateTracking(long hostId) {
+    	SearchCriteria<VMInstanceVO> sc = this.createSearchCriteria();
+    	sc.addAnd("powerHostId", SearchCriteria.Op.EQ, hostId);
+    	
+    	VMInstanceVO instance = this.createForUpdate();
+    	instance.setPowerStateUpdateCount(0);
+    	instance.setPowerStateUpdateTime(DateUtil.currentGMTTime());
+    	
+    	this.update(instance, sc);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca3d6306/server/test/com/cloud/vm/dao/VmDaoTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/dao/VmDaoTest.java b/server/test/com/cloud/vm/dao/VmDaoTest.java
index 546bba3..f5694a4 100644
--- a/server/test/com/cloud/vm/dao/VmDaoTest.java
+++ b/server/test/com/cloud/vm/dao/VmDaoTest.java
@@ -79,29 +79,29 @@ public class VmDaoTest extends TestCase {
 		VMInstanceVO instance = instanceDao.findById(1L);
 		Assert.assertTrue(instance.getInstanceName().equals("Dummy"));
 		
-		instanceDao.updatePowerState(1L, VirtualMachine.PowerState.PowerOn);
+		instanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOn);
 		instance = instanceDao.findById(1L);
 		Assert.assertTrue(instance.getPowerState() == VirtualMachine.PowerState.PowerOn);
 		Assert.assertTrue(instance.getPowerStateUpdateCount() == 1);
 		
-		instanceDao.updatePowerState(1L, VirtualMachine.PowerState.PowerOn);
+		instanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOn);
 		instance = instanceDao.findById(1L);
 		Assert.assertTrue(instance.getPowerState() == VirtualMachine.PowerState.PowerOn);
 		Assert.assertTrue(instance.getPowerStateUpdateCount() == 2);
 		
-		instanceDao.updatePowerState(1L, VirtualMachine.PowerState.PowerOn);
+		instanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOn);
 		instance = instanceDao.findById(1L);
 		Assert.assertTrue(instance.getPowerState() == VirtualMachine.PowerState.PowerOn);
 		Assert.assertTrue(instance.getPowerStateUpdateCount() == 3);
 
 		// after 3 times, the update count should stay at 3
-		instanceDao.updatePowerState(1L, VirtualMachine.PowerState.PowerOn);
+		instanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOn);
 		instance = instanceDao.findById(1L);
 		Assert.assertTrue(instance.getPowerState() == VirtualMachine.PowerState.PowerOn);
 		Assert.assertTrue(instance.getPowerStateUpdateCount() == 3);
 		
-		// after 3 times, the update count should stay at 3
-		instanceDao.updatePowerState(1L, VirtualMachine.PowerState.PowerOff);
+		// if power state is changed, the update count will be reset
+		instanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOff);
 		instance = instanceDao.findById(1L);
 		Assert.assertTrue(instance.getPowerState() == VirtualMachine.PowerState.PowerOff);
 		Assert.assertTrue(instance.getPowerStateUpdateCount() == 1);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ca3d6306/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index 14583b0..5b03148 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -419,4 +419,5 @@ ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_executing_msid` bigint;
 ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state` VARCHAR(74) DEFAULT 'PowerUnknown';
 ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state_update_time` DATETIME;
 ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state_update_count` INT DEFAULT 0;
-
+ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_host` BIGINT;
+ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__power_host` FOREIGN KEY
(`power_host`) REFERENCES `cloud`.`host`(`id`);


Mime
View raw message