Skip to content

Commit 2adce8e

Browse files
author
Prachi Damle
committed
Fixes to VO stuff
1 parent 1cb0ce4 commit 2adce8e

8 files changed

Lines changed: 88 additions & 48 deletions

File tree

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.engine.cloud.entity.api;
1818

19+
import java.util.ArrayList;
1920
import java.util.HashMap;
2021
import java.util.List;
2122
import java.util.Map;
@@ -107,7 +108,7 @@ public class VMEntityManagerImpl implements VMEntityManager {
107108
@Override
108109
public VMEntityVO loadVirtualMachine(String vmId) {
109110
// TODO Auto-generated method stub
110-
return null;
111+
return _vmEntityDao.findByUuid(vmId);
111112
}
112113

113114
@Override
@@ -125,7 +126,10 @@ public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse,
125126
//FIXME: profile should work on VirtualMachineEntity
126127
VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
127128
VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vm);
128-
DeploymentPlan plan = planToDeploy;
129+
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null);
130+
if(planToDeploy != null && planToDeploy.getDataCenterId() != 0){
131+
plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId());
132+
}
129133

130134
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
131135
if(!vols.isEmpty()){
@@ -192,12 +196,13 @@ public void deployVirtualMachine(String reservationId, String caller) throws Ins
192196
Long poolId = null;
193197
Map<Long,Long> storage = vmReservation.getVolumeReservation();
194198
if(storage != null){
195-
Long[] array = new Long[storage.keySet().size()];
196-
storage.keySet().toArray(array);
197-
poolId = array[0];
199+
List<Long> poolIdList = new ArrayList<Long>(storage.keySet());
200+
if(poolIdList !=null && !poolIdList.isEmpty()){
201+
poolId = poolIdList.get(0);
202+
}
198203
}
199204

200-
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterIdToDeployIn(), vmReservation.getPodId(), vmReservation.getClusterId(),
205+
DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(),
201206
vmReservation.getHostId(), poolId , null);
202207

203208
VMInstanceVO vmDeployed = _itMgr.start(vm, null, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), plan);

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMRootDiskTagVO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class VMRootDiskTagVO implements InternalIdentity {
2121
@Column(name = "vm_id")
2222
private long vmId;
2323

24-
@Column(name = "compute_tag")
24+
@Column(name = "root_disk_tag")
2525
private String rootDiskTag;
2626

2727
/**

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VolumeReservationVO.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class VolumeReservationVO implements InternalIdentity{
2626
private long id;
2727

2828
@Column(name = "vm_reservation_id")
29-
private long vmReservationId;
29+
private Long vmReservationId;
3030

3131
@Column(name = "vm_id")
3232
private long vmId;
@@ -48,10 +48,11 @@ public class VolumeReservationVO implements InternalIdentity{
4848
protected VolumeReservationVO() {
4949
}
5050

51-
public VolumeReservationVO(long vmId, long volumeId, long poolId) {
51+
public VolumeReservationVO(long vmId, long volumeId, long poolId, Long vmReservationId) {
5252
this.vmId = vmId;
5353
this.volumeId = volumeId;
5454
this.poolId = poolId;
55+
this.vmReservationId = vmReservationId;
5556
}
5657

5758

@@ -63,7 +64,7 @@ public long getVmId() {
6364
return vmId;
6465
}
6566

66-
public long geVmReservationId() {
67+
public Long geVmReservationId() {
6768
return vmReservationId;
6869
}
6970

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDaoImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ public void persist(long vmId, List<String> computeTags) {
4444
expunge(sc);
4545

4646
for (String tag : computeTags) {
47-
tag = tag.trim();
48-
if(tag.length() > 0) {
49-
VMComputeTagVO vo = new VMComputeTagVO(vmId, tag);
50-
persist(vo);
47+
if(tag != null){
48+
tag = tag.trim();
49+
if(tag.length() > 0) {
50+
VMComputeTagVO vo = new VMComputeTagVO(vmId, tag);
51+
persist(vo);
52+
}
5153
}
5254
}
5355
txn.commit();

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDaoImpl.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,14 @@ private void loadVmNetworks(VMEntityVO dbVO) {
114114
private void saveVmNetworks(VMEntityVO vm) {
115115
List<Long> networks = new ArrayList<Long>();
116116

117-
for(String uuid : vm.getNetworkIds()){
117+
List<String> networksIds = vm.getNetworkIds();
118+
119+
if (networksIds == null || (networksIds != null && networksIds.isEmpty())) {
120+
return;
121+
}
122+
123+
124+
for(String uuid : networksIds){
118125
NetworkVO network = _networkDao.findByUuid(uuid);
119126
if(network != null){
120127
networks.add(network.getId());
@@ -137,16 +144,25 @@ private void loadComputeTags(VMEntityVO dbVO) {
137144
}
138145

139146
private void saveRootDiskTags(long vmId, List<String> rootDiskTags) {
147+
if (rootDiskTags == null || (rootDiskTags != null && rootDiskTags.isEmpty())) {
148+
return;
149+
}
140150
_vmRootDiskTagsDao.persist(vmId, rootDiskTags);
141151

142152
}
143153

144154
private void saveComputeTags(long vmId, List<String> computeTags) {
155+
if (computeTags == null || (computeTags != null && computeTags.isEmpty())) {
156+
return;
157+
}
158+
145159
_vmComputeTagDao.persist(vmId, computeTags);
146160
}
147161

148162
private void saveVmReservation(VMEntityVO vm) {
149-
_vmReservationDao.persist(vm.getVmReservation());
163+
if(vm.getVmReservation() != null){
164+
_vmReservationDao.persist(vm.getVmReservation());
165+
}
150166
}
151167

152168
}

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDaoImpl.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ public VMReservationVO findByVmId(long vmId) {
5050

5151
@Override
5252
public void loadVolumeReservation(VMReservationVO reservation){
53-
List<VolumeReservationVO> volumeResList = _volumeReservationDao.listVolumeReservation(reservation.getId());
54-
Map<Long, Long> volumeReservationMap = new HashMap<Long,Long>();
55-
56-
for(VolumeReservationVO res : volumeResList){
57-
volumeReservationMap.put(res.getVolumeId(), res.getPoolId());
53+
if(reservation != null){
54+
List<VolumeReservationVO> volumeResList = _volumeReservationDao.listVolumeReservation(reservation.getId());
55+
Map<Long, Long> volumeReservationMap = new HashMap<Long,Long>();
56+
57+
for(VolumeReservationVO res : volumeResList){
58+
volumeReservationMap.put(res.getVolumeId(), res.getPoolId());
59+
}
60+
reservation.setVolumeReservation(volumeReservationMap);
5861
}
59-
reservation.setVolumeReservation(volumeReservationMap);
6062
}
6163

6264
@Override
@@ -76,12 +78,12 @@ public VMReservationVO persist(VMReservationVO reservation) {
7678
}
7779

7880
private void saveVolumeReservation(VMReservationVO reservation) {
79-
80-
for(Long volumeId : reservation.getVolumeReservation().keySet()){
81-
VolumeReservationVO volumeReservation = new VolumeReservationVO(reservation.getVmId(), volumeId, reservation.getVolumeReservation().get(volumeId));
82-
_volumeReservationDao.persist(volumeReservation);
83-
}
84-
81+
if(reservation.getVolumeReservation() != null){
82+
for(Long volumeId : reservation.getVolumeReservation().keySet()){
83+
VolumeReservationVO volumeReservation = new VolumeReservationVO(reservation.getVmId(), volumeId, reservation.getVolumeReservation().get(volumeId), reservation.getId());
84+
_volumeReservationDao.persist(volumeReservation);
85+
}
86+
}
8587
}
8688

8789
@Override

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDaoImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ public void persist(long vmId, List<String> rootDiskTags) {
4444
expunge(sc);
4545

4646
for (String tag : rootDiskTags) {
47-
tag = tag.trim();
48-
if(tag.length() > 0) {
49-
VMRootDiskTagVO vo = new VMRootDiskTagVO(vmId, tag);
50-
persist(vo);
47+
if(tag != null){
48+
tag = tag.trim();
49+
if(tag.length() > 0) {
50+
VMRootDiskTagVO vo = new VMRootDiskTagVO(vmId, tag);
51+
persist(vo);
52+
}
5153
}
5254
}
5355
txn.commit();

engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import javax.inject.Inject;
2727

28+
import org.apache.cloudstack.api.BaseCmd;
2829
import org.apache.cloudstack.engine.cloud.entity.api.NetworkEntity;
2930
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
3031
import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity;
@@ -49,9 +50,12 @@
4950
import com.cloud.storage.dao.VMTemplateDao;
5051
import com.cloud.user.dao.AccountDao;
5152
import com.cloud.utils.Pair;
53+
import com.cloud.utils.component.ComponentContext;
5254
import com.cloud.vm.NicProfile;
55+
import com.cloud.vm.UserVmVO;
5356
import com.cloud.vm.VMInstanceVO;
5457
import com.cloud.vm.VirtualMachineManager;
58+
import com.cloud.vm.dao.UserVmDao;
5559
import com.cloud.vm.dao.VMInstanceDao;
5660

5761

@@ -70,6 +74,9 @@ public class CloudOrchestrator implements OrchestrationService {
7074
@Inject
7175
protected VMInstanceDao _vmDao;
7276

77+
@Inject
78+
protected UserVmDao _userVmDao = null;
79+
7380
@Inject
7481
protected ServiceOfferingDao _serviceOfferingDao;
7582

@@ -168,7 +175,9 @@ public VirtualMachineEntity createVirtualMachine(
168175

169176
VirtualMachineEntityImpl vmEntity = null;
170177
try {
171-
vmEntity = _vmEntityFactory.getObject();
178+
//vmEntity = _vmEntityFactory.getObject();
179+
vmEntity = VirtualMachineEntityImpl.class.newInstance();
180+
vmEntity = ComponentContext.inject(vmEntity);
172181
} catch (Exception e) {
173182
// add error handling here
174183
}
@@ -188,24 +197,27 @@ public VirtualMachineEntity createVirtualMachine(
188197

189198
ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
190199
rootDiskOffering.first(offering);
191-
192-
DiskOfferingVO diskOffering = _diskOfferingDao.findById(vm.getDiskOfferingId());
193-
if (diskOffering == null) {
194-
throw new InvalidParameterValueException("Unable to find disk offering " + vm.getDiskOfferingId());
195-
}
196-
Long size = null;
197-
if (diskOffering.getDiskSize() == 0) {
198-
size = diskSize;
199-
if (size == null) {
200-
throw new InvalidParameterValueException(
201-
"Disk offering " + diskOffering
202-
+ " requires size parameter.");
203-
}
200+
201+
if(vm.getDiskOfferingId() != null){
202+
DiskOfferingVO diskOffering = _diskOfferingDao.findById(vm.getDiskOfferingId());
203+
if (diskOffering == null) {
204+
throw new InvalidParameterValueException("Unable to find disk offering " + vm.getDiskOfferingId());
205+
}
206+
Long size = null;
207+
if (diskOffering.getDiskSize() == 0) {
208+
size = diskSize;
209+
if (size == null) {
210+
throw new InvalidParameterValueException(
211+
"Disk offering " + diskOffering
212+
+ " requires size parameter.");
213+
}
214+
}
215+
dataDiskOfferings.add(new Pair<DiskOfferingVO, Long>(diskOffering, size));
204216
}
205-
dataDiskOfferings.add(new Pair<DiskOfferingVO, Long>(diskOffering, size));
206217

207218

208-
if (_itMgr.allocate(vm, _templateDao.findById(new Long(templateId)), offering, rootDiskOffering, dataDiskOfferings, networkIpMap, null, plan, hypervisorType, _accountDao.findById(new Long(owner))) == null) {
219+
220+
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) {
209221
return null;
210222
}
211223

0 commit comments

Comments
 (0)