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 00000000000..2e8638eec07 --- /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{ + + @Override + public VirtualMachineEntityImpl getObject() throws Exception { + return new VirtualMachineEntityImpl(); + } + + @Override + public Class getObjectType() { + return VirtualMachineEntityImpl.class; + } + + @Override + public boolean isSingleton() { + return false; + } + +} 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 e059a8e4f16..2b308d1b9f9 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 computeTags, List rootDiskTags, List 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; 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 b6219f5ad1c..efa95fd8ab7 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 networks, List computeTags, Map details, String owner) { // TODO Auto-generated method stub @@ -141,7 +145,15 @@ public class CloudOrchestrator implements OrchestrationService { List rootDiskTags, List 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 computeTags, List rootDiskTags, List 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);