You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ke...@apache.org on 2013/04/27 02:47:41 UTC
git commit: updated refs/heads/vmsync to 9786f7b
Updated Branches:
refs/heads/vmsync 7ad0722b8 -> 9786f7b7b
consolidate VM work jobs
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/9786f7b7
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9786f7b7
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9786f7b7
Branch: refs/heads/vmsync
Commit: 9786f7b7bb681ef364e067a912eb0400657055c0
Parents: 7ad0722
Author: Kelven Yang <ke...@gmail.com>
Authored: Fri Apr 26 17:44:28 2013 -0700
Committer: Kelven Yang <ke...@gmail.com>
Committed: Fri Apr 26 17:44:28 2013 -0700
----------------------------------------------------------------------
.../com/cloud/vm/VirtualMachineManagerImpl.java | 2 -
server/src/com/cloud/vm/VmWorkJobDao.java | 28 +++++
server/src/com/cloud/vm/VmWorkJobDaoImpl.java | 79 ++++++++++++++
server/src/com/cloud/vm/VmWorkJobVO.java | 81 +++++++++++++++
server/test/com/cloud/vm/dao/VmDaoTest.java | 28 +++++
.../com/cloud/vm/dao/VmDaoTestConfiguration.java | 7 ++
setup/db/db/schema-410to420.sql | 11 ++
7 files changed, 234 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9786f7b7/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
index a34e02c..eed54af 100755
--- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -39,8 +39,6 @@ import javax.naming.ConfigurationException;
import com.cloud.capacity.CapacityManager;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.framework.messagebus.MessageBus;
-import org.apache.cloudstack.framework.messagebus.MessageDispatcher;
-import org.apache.cloudstack.messagebus.SubjectConstants;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import com.cloud.dc.*;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9786f7b7/server/src/com/cloud/vm/VmWorkJobDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VmWorkJobDao.java b/server/src/com/cloud/vm/VmWorkJobDao.java
new file mode 100644
index 0000000..fa33114
--- /dev/null
+++ b/server/src/com/cloud/vm/VmWorkJobDao.java
@@ -0,0 +1,28 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm;
+
+import java.util.List;
+
+import com.cloud.utils.db.GenericDao;
+import com.cloud.vm.VmWorkJobVO.Step;
+
+public interface VmWorkJobDao extends GenericDao<VmWorkJobVO, Long> {
+ VmWorkJobVO findPendingWorkJob(VirtualMachine.Type type, long instanceId);
+ List<VmWorkJobVO> listPendingWorkJobs(VirtualMachine.Type type, long instanceId);
+ void updateStep(long workJobId, Step step);
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9786f7b7/server/src/com/cloud/vm/VmWorkJobDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VmWorkJobDaoImpl.java b/server/src/com/cloud/vm/VmWorkJobDaoImpl.java
new file mode 100644
index 0000000..f542e69
--- /dev/null
+++ b/server/src/com/cloud/vm/VmWorkJobDaoImpl.java
@@ -0,0 +1,79 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm;
+
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+
+import com.cloud.utils.DateUtil;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.vm.VmWorkJobVO.Step;
+
+public class VmWorkJobDaoImpl extends GenericDaoBase<VmWorkJobVO, Long> implements VmWorkJobDao {
+
+ protected SearchBuilder<VmWorkJobVO> PendingWorkJobSearch;
+
+ public VmWorkJobDaoImpl() {
+ }
+
+ @PostConstruct
+ public void init() {
+ PendingWorkJobSearch = createSearchBuilder();
+ PendingWorkJobSearch.and("vmType", PendingWorkJobSearch.entity().getVmType(), Op.EQ);
+ PendingWorkJobSearch.and("vmInstanceId", PendingWorkJobSearch.entity().getVmInstanceId(), Op.EQ);
+ PendingWorkJobSearch.and("step", PendingWorkJobSearch.entity().getStep(), Op.NEQ);
+ PendingWorkJobSearch.done();
+ }
+
+ public VmWorkJobVO findPendingWorkJob(VirtualMachine.Type type, long instanceId) {
+
+ SearchCriteria<VmWorkJobVO> sc = PendingWorkJobSearch.create();
+ sc.setParameters("vmType", type);
+ sc.setParameters("vmInstanceId", instanceId);
+ sc.setParameters("step", Step.Done);
+
+ Filter filter = new Filter(VmWorkJobVO.class, "created", true, null, null);
+ List<VmWorkJobVO> result = this.listBy(sc, filter);
+ if(result != null && result.size() > 0)
+ return result.get(0);
+
+ return null;
+ }
+
+ public List<VmWorkJobVO> listPendingWorkJobs(VirtualMachine.Type type, long instanceId) {
+
+ SearchCriteria<VmWorkJobVO> sc = PendingWorkJobSearch.create();
+ sc.setParameters("vmType", type);
+ sc.setParameters("vmInstanceId", instanceId);
+ sc.setParameters("step", Step.Done);
+
+ Filter filter = new Filter(VmWorkJobVO.class, "created", true, null, null);
+ return this.listBy(sc, filter);
+ }
+
+ public void updateStep(long workJobId, Step step) {
+ VmWorkJobVO jobVo = findById(workJobId);
+ jobVo.setStep(step);
+ jobVo.setLastUpdated(DateUtil.currentGMTTime());
+ update(workJobId, jobVo);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9786f7b7/server/src/com/cloud/vm/VmWorkJobVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/VmWorkJobVO.java b/server/src/com/cloud/vm/VmWorkJobVO.java
new file mode 100644
index 0000000..5303b87
--- /dev/null
+++ b/server/src/com/cloud/vm/VmWorkJobVO.java
@@ -0,0 +1,81 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.vm;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.Table;
+
+import com.cloud.async.AsyncJobVO;
+
+@Entity
+@Table(name="vm_work_job")
+@DiscriminatorValue(value="VmWork")
+@PrimaryKeyJoinColumn(name="id")
+public class VmWorkJobVO extends AsyncJobVO {
+
+ public enum Step {
+ Prepare,
+ Starting,
+ Started,
+ Release,
+ Done,
+ Migrating,
+ Reconfiguring
+ }
+
+ @Column(name="step")
+ Step step;
+
+ @Column(name="vm_type")
+ @Enumerated(value=EnumType.STRING)
+ VirtualMachine.Type vmType;
+
+ @Column(name="vm_instance_id")
+ long vmInstanceId;
+
+ public VmWorkJobVO() {
+ }
+
+ public Step getStep() {
+ return step;
+ }
+
+ public void setStep(Step step) {
+ this.step = step;
+ }
+
+ public VirtualMachine.Type getVmType() {
+ return vmType;
+ }
+
+ public void setVmType(VirtualMachine.Type vmType) {
+ this.vmType = vmType;
+ }
+
+ public long getVmInstanceId() {
+ return vmInstanceId;
+ }
+
+ public void setVmInstanceid(long vmInstanceId) {
+ this.vmInstanceId = vmInstanceId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9786f7b7/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 83f39f8..75b04ab 100644
--- a/server/test/com/cloud/vm/dao/VmDaoTest.java
+++ b/server/test/com/cloud/vm/dao/VmDaoTest.java
@@ -33,6 +33,8 @@ import com.cloud.utils.db.Transaction;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VmWorkJobDao;
+import com.cloud.vm.VmWorkJobVO;
import junit.framework.Assert;
import junit.framework.TestCase;
@@ -43,6 +45,7 @@ public class VmDaoTest extends TestCase {
@Inject UserVmDao userVmDao;
@Inject VMInstanceDao instanceDao;
+ @Inject VmWorkJobDao workJobDao;
@Before
public void setup() {
@@ -139,4 +142,29 @@ public class VmDaoTest extends TestCase {
userVmDao.expunge(1L);
userVmDao.expunge(2L);
}
+
+ @Test
+ public void testVmWork() {
+ VmWorkJobVO workJob = new VmWorkJobVO();
+ workJob.setAccountId(1);
+ workJob.setCmd("StartVM");
+ workJob.setInitMsid(1L);
+ workJob.setStep(VmWorkJobVO.Step.Prepare);
+ workJob.setVmType(VirtualMachine.Type.ConsoleProxy);
+ workJob.setVmInstanceid(1L);
+
+ workJobDao.persist(workJob);
+
+ VmWorkJobVO pendingWorkJob = workJobDao.findPendingWorkJob(VirtualMachine.Type.ConsoleProxy, 1L);
+ Assert.assertTrue(pendingWorkJob.getCmd().equals("StartVM"));
+ Assert.assertTrue(pendingWorkJob.getInitMsid() == 1);
+ Assert.assertTrue(pendingWorkJob.getAccountId() == 1);
+ Assert.assertTrue(pendingWorkJob.getStep() == VmWorkJobVO.Step.Prepare);
+
+ workJobDao.updateStep(pendingWorkJob.getId(), VmWorkJobVO.Step.Starting);
+ pendingWorkJob = workJobDao.findPendingWorkJob(VirtualMachine.Type.ConsoleProxy, 1L);
+ Assert.assertTrue(pendingWorkJob.getStep() == VmWorkJobVO.Step.Starting);
+
+ workJobDao.expunge(workJob.getId());
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9786f7b7/server/test/com/cloud/vm/dao/VmDaoTestConfiguration.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/dao/VmDaoTestConfiguration.java b/server/test/com/cloud/vm/dao/VmDaoTestConfiguration.java
index 1574c0c..6b0a15a 100644
--- a/server/test/com/cloud/vm/dao/VmDaoTestConfiguration.java
+++ b/server/test/com/cloud/vm/dao/VmDaoTestConfiguration.java
@@ -30,6 +30,8 @@ import com.cloud.host.dao.HostDaoImpl;
import com.cloud.host.dao.HostDetailsDao;
import com.cloud.host.dao.HostTagsDao;
import com.cloud.tags.dao.ResourceTagDao;
+import com.cloud.vm.VmWorkJobDao;
+import com.cloud.vm.VmWorkJobDaoImpl;
@Configuration
public class VmDaoTestConfiguration {
@@ -88,4 +90,9 @@ public class VmDaoTestConfiguration {
public UserVmDetailsDao userVmDetailsDao() {
return Mockito.mock(UserVmDetailsDao.class);
}
+
+ @Bean
+ public VmWorkJobDao vmWorkJobDao() {
+ return new VmWorkJobDaoImpl();
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9786f7b7/setup/db/db/schema-410to420.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql
index a6f2c2b..89cd8f5 100644
--- a/setup/db/db/schema-410to420.sql
+++ b/setup/db/db/schema-410to420.sql
@@ -421,3 +421,14 @@ 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 unsigned;
ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__power_host` FOREIGN KEY (`power_host`) REFERENCES `cloud`.`host`(`id`);
+
+CREATE TABLE `cloud`.`vm_work_job` (
+ `id` bigint unsigned UNIQUE NOT NULL,
+ `step` char(32) NOT NULL COMMENT 'state',
+ `vm_type` char(32) NOT NULL COMMENT 'type of vm',
+ `vm_instance_id` bigint unsigned NOT NULL COMMENT 'vm instance',
+ PRIMARY KEY (`id`),
+ CONSTRAINT `fk_vm_work_job__instance_id` FOREIGN KEY (`vm_instance_id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE,
+ INDEX `i_vm_work_job__vm`(`vm_type`, `vm_instance_id`),
+ INDEX `i_vm_work_job__step`(`step`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;