mirror of https://github.com/apache/cloudstack.git
Add FactoryBean for VirtualMachineEntity to help implement dyanmic injection
This commit is contained in:
parent
ddf9c6586d
commit
249dcde364
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue