Fixes to VO stuff

This commit is contained in:
Prachi Damle 2013-01-22 12:49:37 -08:00
parent 1cb0ce44df
commit 2adce8e712
8 changed files with 88 additions and 48 deletions

View File

@ -16,6 +16,7 @@
// under the License.
package org.apache.cloudstack.engine.cloud.entity.api;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -107,7 +108,7 @@ public class VMEntityManagerImpl implements VMEntityManager {
@Override
public VMEntityVO loadVirtualMachine(String vmId) {
// TODO Auto-generated method stub
return null;
return _vmEntityDao.findByUuid(vmId);
}
@Override
@ -125,7 +126,10 @@ public class VMEntityManagerImpl implements VMEntityManager {
//FIXME: profile should work on VirtualMachineEntity
VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
DeploymentPlan plan = planToDeploy;
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null);
if(planToDeploy != null && planToDeploy.getDataCenterId() != 0){
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());
}
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
if(!vols.isEmpty()){
@ -192,12 +196,13 @@ public class VMEntityManagerImpl implements VMEntityManager {
Long poolId = null;
Map<Long,Long> storage = vmReservation.getVolumeReservation();
if(storage != null){
Long[] array = new Long[storage.keySet().size()];
storage.keySet().toArray(array);
poolId = array[0];
List<Long> poolIdList = new ArrayList<Long>(storage.keySet());
if(poolIdList !=null && !poolIdList.isEmpty()){
poolId = poolIdList.get(0);
}
}
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterIdToDeployIn(), vmReservation.getPodId(), vmReservation.getClusterId(),
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(),
vmReservation.getHostId(), poolId , null);
VMInstanceVO vmDeployed = _itMgr.start(vm, null, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), plan);

View File

@ -21,7 +21,7 @@ public class VMRootDiskTagVO implements InternalIdentity {
@Column(name = "vm_id")
private long vmId;
@Column(name = "compute_tag")
@Column(name = "root_disk_tag")
private String rootDiskTag;
/**

View File

@ -26,7 +26,7 @@ public class VolumeReservationVO implements InternalIdentity{
private long id;
@Column(name = "vm_reservation_id")
private long vmReservationId;
private Long vmReservationId;
@Column(name = "vm_id")
private long vmId;
@ -48,10 +48,11 @@ public class VolumeReservationVO implements InternalIdentity{
protected VolumeReservationVO() {
}
public VolumeReservationVO(long vmId, long volumeId, long poolId) {
public VolumeReservationVO(long vmId, long volumeId, long poolId, Long vmReservationId) {
this.vmId = vmId;
this.volumeId = volumeId;
this.poolId = poolId;
this.vmReservationId = vmReservationId;
}
@ -63,7 +64,7 @@ public class VolumeReservationVO implements InternalIdentity{
return vmId;
}
public long geVmReservationId() {
public Long geVmReservationId() {
return vmReservationId;
}

View File

@ -44,10 +44,12 @@ public class VMComputeTagDaoImpl extends GenericDaoBase<VMComputeTagVO, Long> im
expunge(sc);
for (String tag : computeTags) {
tag = tag.trim();
if(tag.length() > 0) {
VMComputeTagVO vo = new VMComputeTagVO(vmId, tag);
persist(vo);
if(tag != null){
tag = tag.trim();
if(tag.length() > 0) {
VMComputeTagVO vo = new VMComputeTagVO(vmId, tag);
persist(vo);
}
}
}
txn.commit();

View File

@ -114,7 +114,14 @@ public class VMEntityDaoImpl extends GenericDaoBase<VMEntityVO, Long> implements
private void saveVmNetworks(VMEntityVO vm) {
List<Long> networks = new ArrayList<Long>();
for(String uuid : vm.getNetworkIds()){
List<String> networksIds = vm.getNetworkIds();
if (networksIds == null || (networksIds != null && networksIds.isEmpty())) {
return;
}
for(String uuid : networksIds){
NetworkVO network = _networkDao.findByUuid(uuid);
if(network != null){
networks.add(network.getId());
@ -137,16 +144,25 @@ public class VMEntityDaoImpl extends GenericDaoBase<VMEntityVO, Long> implements
}
private void saveRootDiskTags(long vmId, List<String> rootDiskTags) {
if (rootDiskTags == null || (rootDiskTags != null && rootDiskTags.isEmpty())) {
return;
}
_vmRootDiskTagsDao.persist(vmId, rootDiskTags);
}
private void saveComputeTags(long vmId, List<String> computeTags) {
if (computeTags == null || (computeTags != null && computeTags.isEmpty())) {
return;
}
_vmComputeTagDao.persist(vmId, computeTags);
}
private void saveVmReservation(VMEntityVO vm) {
_vmReservationDao.persist(vm.getVmReservation());
if(vm.getVmReservation() != null){
_vmReservationDao.persist(vm.getVmReservation());
}
}
}

View File

@ -50,13 +50,15 @@ public class VMReservationDaoImpl extends GenericDaoBase<VMReservationVO, Long>
@Override
public void loadVolumeReservation(VMReservationVO reservation){
List<VolumeReservationVO> volumeResList = _volumeReservationDao.listVolumeReservation(reservation.getId());
Map<Long, Long> volumeReservationMap = new HashMap<Long,Long>();
for(VolumeReservationVO res : volumeResList){
volumeReservationMap.put(res.getVolumeId(), res.getPoolId());
if(reservation != null){
List<VolumeReservationVO> volumeResList = _volumeReservationDao.listVolumeReservation(reservation.getId());
Map<Long, Long> volumeReservationMap = new HashMap<Long,Long>();
for(VolumeReservationVO res : volumeResList){
volumeReservationMap.put(res.getVolumeId(), res.getPoolId());
}
reservation.setVolumeReservation(volumeReservationMap);
}
reservation.setVolumeReservation(volumeReservationMap);
}
@Override
@ -76,12 +78,12 @@ public class VMReservationDaoImpl extends GenericDaoBase<VMReservationVO, Long>
}
private void saveVolumeReservation(VMReservationVO reservation) {
for(Long volumeId : reservation.getVolumeReservation().keySet()){
VolumeReservationVO volumeReservation = new VolumeReservationVO(reservation.getVmId(), volumeId, reservation.getVolumeReservation().get(volumeId));
_volumeReservationDao.persist(volumeReservation);
}
if(reservation.getVolumeReservation() != null){
for(Long volumeId : reservation.getVolumeReservation().keySet()){
VolumeReservationVO volumeReservation = new VolumeReservationVO(reservation.getVmId(), volumeId, reservation.getVolumeReservation().get(volumeId), reservation.getId());
_volumeReservationDao.persist(volumeReservation);
}
}
}
@Override

View File

@ -44,10 +44,12 @@ public class VMRootDiskTagDaoImpl extends GenericDaoBase<VMRootDiskTagVO, Long>
expunge(sc);
for (String tag : rootDiskTags) {
tag = tag.trim();
if(tag.length() > 0) {
VMRootDiskTagVO vo = new VMRootDiskTagVO(vmId, tag);
persist(vo);
if(tag != null){
tag = tag.trim();
if(tag.length() > 0) {
VMRootDiskTagVO vo = new VMRootDiskTagVO(vmId, tag);
persist(vo);
}
}
}
txn.commit();

View File

@ -25,6 +25,7 @@ import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.api.BaseCmd;
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;
@ -49,9 +50,12 @@ import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentContext;
import com.cloud.vm.NicProfile;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
@ -70,6 +74,9 @@ public class CloudOrchestrator implements OrchestrationService {
@Inject
protected VMInstanceDao _vmDao;
@Inject
protected UserVmDao _userVmDao = null;
@Inject
protected ServiceOfferingDao _serviceOfferingDao;
@ -168,7 +175,9 @@ public class CloudOrchestrator implements OrchestrationService {
VirtualMachineEntityImpl vmEntity = null;
try {
vmEntity = _vmEntityFactory.getObject();
//vmEntity = _vmEntityFactory.getObject();
vmEntity = VirtualMachineEntityImpl.class.newInstance();
vmEntity = ComponentContext.inject(vmEntity);
} catch (Exception e) {
// add error handling here
}
@ -188,24 +197,27 @@ public class CloudOrchestrator implements OrchestrationService {
ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
rootDiskOffering.first(offering);
DiskOfferingVO diskOffering = _diskOfferingDao.findById(vm.getDiskOfferingId());
if (diskOffering == null) {
throw new InvalidParameterValueException("Unable to find disk offering " + vm.getDiskOfferingId());
if(vm.getDiskOfferingId() != null){
DiskOfferingVO diskOffering = _diskOfferingDao.findById(vm.getDiskOfferingId());
if (diskOffering == null) {
throw new InvalidParameterValueException("Unable to find disk offering " + vm.getDiskOfferingId());
}
Long size = null;
if (diskOffering.getDiskSize() == 0) {
size = diskSize;
if (size == null) {
throw new InvalidParameterValueException(
"Disk offering " + diskOffering
+ " requires size parameter.");
}
}
dataDiskOfferings.add(new Pair<DiskOfferingVO, Long>(diskOffering, size));
}
Long size = null;
if (diskOffering.getDiskSize() == 0) {
size = diskSize;
if (size == null) {
throw new InvalidParameterValueException(
"Disk offering " + diskOffering
+ " requires size parameter.");
}
}
dataDiskOfferings.add(new Pair<DiskOfferingVO, Long>(diskOffering, size));
if (_itMgr.allocate(vm, _templateDao.findById(new Long(templateId)), offering, rootDiskOffering, dataDiskOfferings, networkIpMap, null, plan, hypervisorType, _accountDao.findById(new Long(owner))) == null) {
if (_itMgr.allocate(_userVmDao.findById(vm.getId(), true), _templateDao.findById(new Long(templateId)), offering, rootDiskOffering, dataDiskOfferings, networkIpMap, null, plan, hypervisorType, _accountDao.findById(new Long(owner))) == null) {
return null;
}