Updated Branches: refs/heads/javelin ddf9c6586 -> 249dcde36
Add FactoryBean for VirtualMachineEntity to help implement dyanmic injection Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/249dcde3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/249dcde3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/249dcde3 Branch: refs/heads/javelin Commit: 249dcde364190c3c957bc351cf3505ebb5ed6d66 Parents: ddf9c65 Author: Kelven Yang <kelv...@gmail.com> Authored: Thu Jan 17 21:06:17 2013 -0800 Committer: Kelven Yang <kelv...@gmail.com> Committed: Thu Jan 17 21:06:45 2013 -0800 ---------------------------------------------------------------------- .../entity/api/VirtualMachineEntityFactory.java | 40 +++++++++++++++ .../cloud/entity/api/VirtualMachineEntityImpl.java | 24 +++++++-- .../platform/orchestration/CloudOrchestrator.java | 23 ++++++++- 3 files changed, 81 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/249dcde3/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityFactory.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityFactory.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityFactory.java new file mode 100644 index 0000000..2e8638e --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityFactory.java @@ -0,0 +1,40 @@ +// 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 org.apache.cloudstack.engine.cloud.entity.api; + +import org.springframework.beans.factory.FactoryBean; +import org.springframework.stereotype.Component; + +@Component +public class VirtualMachineEntityFactory implements FactoryBean<VirtualMachineEntityImpl>{ + + @Override + public VirtualMachineEntityImpl getObject() throws Exception { + return new VirtualMachineEntityImpl(); + } + + @Override + public Class<?> getObjectType() { + return VirtualMachineEntityImpl.class; + } + + @Override + public boolean isSingleton() { + return false; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/249dcde3/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java index e059a8e..2b308d1 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VirtualMachineEntityImpl.java @@ -23,20 +23,36 @@ import java.util.Map; import javax.inject.Inject; - - import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO; -import org.springframework.stereotype.Component; import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlanner.ExcludeList; -@Component public class VirtualMachineEntityImpl implements VirtualMachineEntity { @Inject private VMEntityManager manager; private VMEntityVO vmEntityVO; + + public VirtualMachineEntityImpl() { + } + + public void init(String vmId) { + this.vmEntityVO = this.manager.loadVirtualMachine(vmId); + } + + public void init(String vmId, String owner, String hostName, String displayName, int cpu, int speed, long memory, List<String> computeTags, List<String> rootDiskTags, List<String> networks) { + init(vmId); + this.vmEntityVO.setOwner(owner); + this.vmEntityVO.setHostname(hostName); + this.vmEntityVO.setDisplayname(displayName); + this.vmEntityVO.setSpeed(speed); + this.vmEntityVO.setComputeTags(computeTags); + this.vmEntityVO.setRootDiskTags(rootDiskTags); + this.vmEntityVO.setNetworkIds(networks); + + manager.saveVirtualMachine(vmEntityVO); + } public VirtualMachineEntityImpl(String vmId, VMEntityManager manager) { this.manager = manager; http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/249dcde3/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java ---------------------------------------------------------------------- diff --git a/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java index b6219f5..efa95fd 100755 --- a/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java @@ -28,6 +28,7 @@ import javax.inject.Inject; import org.apache.cloudstack.engine.cloud.entity.api.NetworkEntity; import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity; import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity; +import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityFactory; import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl; import org.apache.cloudstack.engine.cloud.entity.api.VMEntityManager; import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; @@ -71,6 +72,9 @@ public class CloudOrchestrator implements OrchestrationService { @Inject protected DiskOfferingDao _diskOfferingDao = null; + @Inject + protected VirtualMachineEntityFactory _vmEntityFactory; + public VirtualMachineEntity createFromScratch(String uuid, String iso, String os, String hypervisor, String hostName, int cpu, int speed, long memory, List<String> networks, List<String> computeTags, Map<String, String> details, String owner) { // TODO Auto-generated method stub @@ -141,7 +145,15 @@ public class CloudOrchestrator implements OrchestrationService { List<String> rootDiskTags, List<String> networks, DeploymentPlan plan) throws InsufficientCapacityException { - VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager); + // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager); + + VirtualMachineEntityImpl vmEntity = null; + try { + vmEntity = _vmEntityFactory.getObject(); + } catch (Exception e) { + // add error handling here + } + vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks); HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor); @@ -185,7 +197,14 @@ public class CloudOrchestrator implements OrchestrationService { public VirtualMachineEntity createVirtualMachineFromScratch(String id, String owner, String isoId, String hostName, String displayName, String hypervisor, String os, int cpu, int speed, long memory,Long diskSize, List<String> computeTags, List<String> rootDiskTags, List<String> networks, DeploymentPlan plan) throws InsufficientCapacityException { - VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager); + // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager); + VirtualMachineEntityImpl vmEntity = null; + try { + vmEntity = _vmEntityFactory.getObject(); + } catch (Exception e) { + // add error handling here + } + vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks); //load vm instance and offerings and call virtualMachineManagerImpl VMInstanceVO vm = _vmDao.findByUUID(id);