diff --git a/api/src/com/cloud/vm/VirtualMachine.java b/api/src/com/cloud/vm/VirtualMachine.java index 3a10b033210..83f1612fc55 100755 --- a/api/src/com/cloud/vm/VirtualMachine.java +++ b/api/src/com/cloud/vm/VirtualMachine.java @@ -284,7 +284,7 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, I public long getServiceOfferingId(); - public long getDiskOfferingId(); + public Long getDiskOfferingId(); Type getType(); diff --git a/core/src/com/cloud/vm/UserVmVO.java b/core/src/com/cloud/vm/UserVmVO.java index 05a4bd1a636..a16eaf9dca0 100755 --- a/core/src/com/cloud/vm/UserVmVO.java +++ b/core/src/com/cloud/vm/UserVmVO.java @@ -78,8 +78,8 @@ public class UserVmVO extends VMInstanceVO implements UserVm { long accountId, long serviceOfferingId, String userData, - String name) { - super(id, serviceOfferingId, name, instanceName, Type.User, templateId, hypervisorType, guestOsId, domainId, accountId, haEnabled, limitCpuUse); + String name, Long diskOfferingId) { + super(id, serviceOfferingId, name, instanceName, Type.User, templateId, hypervisorType, guestOsId, domainId, accountId, haEnabled, limitCpuUse, diskOfferingId); this.userData = userData; this.displayName = displayName; this.details = new HashMap(); diff --git a/core/src/com/cloud/vm/VMInstanceVO.java b/core/src/com/cloud/vm/VMInstanceVO.java index 474c78828ed..36c33477f57 100644 --- a/core/src/com/cloud/vm/VMInstanceVO.java +++ b/core/src/com/cloud/vm/VMInstanceVO.java @@ -155,6 +155,9 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject computeTags, @QueryParam("root-disk-tags") List rootDiskTags, - @QueryParam("networks") List networks, + @QueryParam("network-nic-map") Map networkNicMap, @QueryParam("deploymentplan") DeploymentPlan plan ) throws InsufficientCapacityException; @@ -89,7 +91,7 @@ public interface OrchestrationService { @QueryParam("disk-size") Long diskSize, @QueryParam("compute-tags") List computeTags, @QueryParam("root-disk-tags") List rootDiskTags, - @QueryParam("networks") List networks, + @QueryParam("network-nic-map") Map networkNicMap, @QueryParam("deploymentplan") DeploymentPlan plan ) throws InsufficientCapacityException; @@ -107,4 +109,6 @@ public interface OrchestrationService { @POST TemplateEntity registerTemplate(String name, URL path, String os, Hypervisor hypervisor); + + VirtualMachineEntity getVirtualMachine(@QueryParam("id") String id); } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManager.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManager.java index 37545e8f469..8e58e73739a 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManager.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManager.java @@ -18,9 +18,25 @@ package org.apache.cloudstack.engine.cloud.entity.api; import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.deploy.DeploymentPlanner.ExcludeList; +import com.cloud.exception.AgentUnavailableException; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceUnavailableException; + public interface VMEntityManager { VMEntityVO loadVirtualMachine(String vmId); void saveVirtualMachine(VMEntityVO vmInstanceVO); + + String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan plan, ExcludeList exclude) throws InsufficientCapacityException, ResourceUnavailableException; + + void deployVirtualMachine(String reservationId, String caller) throws InsufficientCapacityException, ResourceUnavailableException; + + boolean stopvirtualmachine(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException; + + boolean destroyVirtualMachine(VMEntityVO vmEntityVO, String caller) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException; } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java index 05c39bc0e48..b1db24289b2 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java @@ -16,12 +16,94 @@ // under the License. package org.apache.cloudstack.engine.cloud.entity.api; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.inject.Inject; + import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO; +import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO; +import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMEntityDao; +import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao; import org.springframework.stereotype.Component; +import com.cloud.dc.DataCenter; +import com.cloud.deploy.DataCenterDeployment; +import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.deploy.DeploymentPlanner; +import com.cloud.deploy.DeploymentPlanner.ExcludeList; +import com.cloud.exception.AgentUnavailableException; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InsufficientServerCapacityException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.dao.NetworkDao; +import com.cloud.org.Cluster; +import com.cloud.service.dao.ServiceOfferingDao; +import com.cloud.storage.StoragePoolVO; +import com.cloud.storage.Volume; +import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.DiskOfferingDao; +import com.cloud.storage.dao.StoragePoolDao; +import com.cloud.storage.dao.VMTemplateDao; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.user.Account; +import com.cloud.user.User; +import com.cloud.user.dao.AccountDao; +import com.cloud.user.dao.UserDao; +import com.cloud.utils.component.ComponentContext; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachineManager; +import com.cloud.vm.VirtualMachineProfile; +import com.cloud.vm.VirtualMachineProfileImpl; +import com.cloud.vm.dao.VMInstanceDao; + @Component public class VMEntityManagerImpl implements VMEntityManager { + @Inject + protected VMInstanceDao _vmDao; + @Inject + protected VMTemplateDao _templateDao = null; + + @Inject + protected ServiceOfferingDao _serviceOfferingDao; + + @Inject + protected DiskOfferingDao _diskOfferingDao = null; + + @Inject + protected NetworkDao _networkDao; + + @Inject + protected AccountDao _accountDao = null; + + @Inject + protected UserDao _userDao = null; + + @Inject + protected VMEntityDao _vmEntityDao; + + @Inject + protected VMReservationDao _reservationDao; + + @Inject + protected VirtualMachineManager _itMgr; + + @Inject + protected List _planners; + + @Inject + protected VolumeDao _volsDao; + + @Inject + protected StoragePoolDao _storagePoolDao; + @Override public VMEntityVO loadVirtualMachine(String vmId) { // TODO Auto-generated method stub @@ -29,9 +111,114 @@ public class VMEntityManagerImpl implements VMEntityManager { } @Override - public void saveVirtualMachine(VMEntityVO vmInstanceVO) { - // TODO Auto-generated method stub + public void saveVirtualMachine(VMEntityVO entity) { + _vmEntityDao.persist(entity); } + @Override + public String reserveVirtualMachine(VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude) + throws InsufficientCapacityException, ResourceUnavailableException { + + //call planner and get the deployDestination. + //load vm instance and offerings and call virtualMachineManagerImpl + //FIXME: profile should work on VirtualMachineEntity + VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid()); + VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm); + DeploymentPlan plan = planToDeploy; + + List vols = _volsDao.findReadyRootVolumesByInstance(vm.getId()); + if(!vols.isEmpty()){ + VolumeVO vol = vols.get(0); + StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId()); + if (!pool.isInMaintenance()) { + long rootVolDcId = pool.getDataCenterId(); + Long rootVolPodId = pool.getPodId(); + Long rootVolClusterId = pool.getClusterId(); + if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) { + Long clusterIdSpecified = planToDeploy.getClusterId(); + if (clusterIdSpecified != null && rootVolClusterId != null) { + if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) { + // cannot satisfy the plan passed in to the + // planner + throw new ResourceUnavailableException("Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for " + + vm, Cluster.class, clusterIdSpecified); + } + } + plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), vol.getPoolId(), null, null); + }else{ + plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, null); + + } + } + + } + + DeploymentPlanner planner = ComponentContext.getCompanent(plannerToUse); + DeployDestination dest = null; + + if (planner.canHandle(vmProfile, plan, exclude)) { + dest = planner.plan(vmProfile, plan, exclude); + } + + if (dest != null) { + //save destination with VMEntityVO + VMReservationVO vmReservation = new VMReservationVO(vm.getId(), dest.getDataCenter().getId(), dest.getPod().getId(), dest.getCluster().getId(), dest.getHost().getId()); + Map volumeReservationMap = new HashMap(); + for(Volume vo : dest.getStorageForDisks().keySet()){ + volumeReservationMap.put(vo.getId(), dest.getStorageForDisks().get(vo).getId()); + } + vmReservation.setVolumeReservation(volumeReservationMap); + + vmEntityVO.setVmReservation(vmReservation); + _vmEntityDao.persist(vmEntityVO); + + return vmReservation.getUuid(); + }else{ + throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId()); + } + + } + + @Override + public void deployVirtualMachine(String reservationId, String caller) throws InsufficientCapacityException, ResourceUnavailableException{ + //grab the VM Id and destination using the reservationId. + + VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId); + long vmId = vmReservation.getVmId(); + + VMInstanceVO vm = _vmDao.findById(vmId); + //Pass it down + Long poolId = null; + Map storage = vmReservation.getVolumeReservation(); + if(storage != null){ + Long[] array = new Long[storage.keySet().size()]; + storage.keySet().toArray(array); + poolId = array[0]; + } + + DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterIdToDeployIn(), vmReservation.getPodId(), vmReservation.getClusterId(), + vmReservation.getHostId(), poolId , null); + + VMInstanceVO vmDeployed = _itMgr.start(vm, null, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId()), plan); + + } + + @Override + public boolean stopvirtualmachine(VMEntityVO vmEntityVO, String caller) throws ResourceUnavailableException { + + VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid()); + return _itMgr.stop(vm, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId())); + + } + + @Override + public boolean destroyVirtualMachine(VMEntityVO vmEntityVO, String caller) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException{ + + VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid()); + return _itMgr.destroy(vm, _userDao.findById(new Long(caller)), _accountDao.findById(vm.getAccountId())); + + + } + } 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 2b308d1b9f9..13358d8548d 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 @@ -24,10 +24,17 @@ 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.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; +import com.cloud.exception.AgentUnavailableException; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.OperationTimedoutException; +import com.cloud.exception.ResourceUnavailableException; +@Component public class VirtualMachineEntityImpl implements VirtualMachineEntity { @Inject private VMEntityManager manager; @@ -185,28 +192,25 @@ public class VirtualMachineEntityImpl implements VirtualMachineEntity { } @Override - public String reserve(String plannerToUse, DeployDestination dest, - ExcludeList exclude) { - // TODO Auto-generated method stub - return null; + public String reserve(String plannerToUse, DeploymentPlan plan, + ExcludeList exclude, String caller) throws InsufficientCapacityException, ResourceUnavailableException { + return manager.reserveVirtualMachine(this.vmEntityVO, plannerToUse, plan, exclude); } @Override - public void migrateTo(String reservationId) { + public void migrateTo(String reservationId, String caller) { // TODO Auto-generated method stub } @Override - public void deploy(String reservationId) { - // TODO Auto-generated method stub - + public void deploy(String reservationId, String caller) throws InsufficientCapacityException, ResourceUnavailableException{ + manager.deployVirtualMachine(reservationId, caller); } @Override - public void stop() { - // TODO Auto-generated method stub - + public boolean stop(String caller) throws ResourceUnavailableException{ + return manager.stopvirtualmachine(this.vmEntityVO, caller); } @Override @@ -216,9 +220,8 @@ public class VirtualMachineEntityImpl implements VirtualMachineEntity { } @Override - public void destroy() { - // TODO Auto-generated method stub - + public boolean destroy(String caller) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException { + return manager.destroyVirtualMachine(this.vmEntityVO, caller); } @Override diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMComputeTagVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMComputeTagVO.java new file mode 100644 index 00000000000..b271c8a97b6 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMComputeTagVO.java @@ -0,0 +1,51 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.cloudstack.api.InternalIdentity; + +@Entity +@Table(name = "vm_compute_tags") +public class VMComputeTagVO implements InternalIdentity{ + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "vm_id") + private long vmId; + + @Column(name = "compute_tag") + private String computeTag; + + /** + * There should never be a public constructor for this class. Since it's + * only here to define the table for the DAO class. + */ + protected VMComputeTagVO() { + } + + public VMComputeTagVO(long vmId, String tag) { + this.vmId = vmId; + this.computeTag = tag; + } + + public long getId() { + return id; + } + + public long getVmId() { + return vmId; + } + + public String getComputeTag() { + return computeTag; + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java index 93ac691a4c4..fec1c974359 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java @@ -182,6 +182,12 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject networkIds; + @Column(name="disk_offering_id") + protected Long diskOfferingId; + + @Transient + private VMReservationVO vmReservation; + public VMEntityVO(long id, long serviceOfferingId, @@ -193,7 +199,7 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject poolId + @Transient + Map volumeReservationMap; + + /** + * There should never be a public constructor for this class. Since it's + * only here to define the table for the DAO class. + */ + protected VMReservationVO() { + } + + public VMReservationVO(long vmId, long dataCenterId, long podId, long clusterId, long hostId) { + this.vmId = vmId; + this.dataCenterId = dataCenterId; + this.podId = podId; + this.clusterId = clusterId; + this.hostId = hostId; + this.uuid = UUID.randomUUID().toString(); + } + + + public long getId() { + return id; + } + + public long getVmId() { + return vmId; + } + + @Override + public String getUuid() { + return uuid; + } + + public long getDataCenterId() { + return dataCenterId; + } + + public Long getPodId() { + return podId; + } + + public Long getClusterId() { + return clusterId; + } + + public Long getHostId() { + return hostId; + } + + public Map getVolumeReservation(){ + return volumeReservationMap; + } + + public void setVolumeReservation(Map volumeReservationMap){ + this.volumeReservationMap = volumeReservationMap; + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMRootDiskTagVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMRootDiskTagVO.java new file mode 100644 index 00000000000..92863c7d773 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VMRootDiskTagVO.java @@ -0,0 +1,51 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.apache.cloudstack.api.InternalIdentity; + +@Entity +@Table(name = "vm_root_disk_tags") +public class VMRootDiskTagVO implements InternalIdentity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "vm_id") + private long vmId; + + @Column(name = "compute_tag") + private String rootDiskTag; + + /** + * There should never be a public constructor for this class. Since it's + * only here to define the table for the DAO class. + */ + protected VMRootDiskTagVO() { + } + + public VMRootDiskTagVO(long vmId, String rootDiskTag) { + this.vmId = vmId; + this.rootDiskTag = rootDiskTag; + } + + public long getId() { + return id; + } + + public long getVmId() { + return vmId; + } + + public String getRootDiskTag() { + return rootDiskTag; + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VolumeReservationVO.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VolumeReservationVO.java new file mode 100644 index 00000000000..a746a945581 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VolumeReservationVO.java @@ -0,0 +1,83 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db; + +import java.util.Date; +import java.util.Map; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Transient; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name = "volume_reservation") +public class VolumeReservationVO implements InternalIdentity{ + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "vm_reservation_id") + private long vmReservationId; + + @Column(name = "vm_id") + private long vmId; + + @Column(name="volume_id") + private long volumeId; + + @Column(name="pool_id") + private long poolId; + + // VolumeId -> poolId + @Transient + Map volumeReservationMap; + + /** + * There should never be a public constructor for this class. Since it's + * only here to define the table for the DAO class. + */ + protected VolumeReservationVO() { + } + + public VolumeReservationVO(long vmId, long volumeId, long poolId) { + this.vmId = vmId; + this.volumeId = volumeId; + this.poolId = poolId; + } + + + public long getId() { + return id; + } + + public long getVmId() { + return vmId; + } + + public long geVmReservationId() { + return vmReservationId; + } + + public long getVolumeId() { + return volumeId; + } + + public Long getPoolId() { + return poolId; + } + + + public Map getVolumeReservation(){ + return volumeReservationMap; + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDao.java new file mode 100644 index 00000000000..33ff8368ab0 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDao.java @@ -0,0 +1,15 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db.dao; + +import java.util.List; + +import org.apache.cloudstack.engine.cloud.entity.api.db.VMComputeTagVO; + +import com.cloud.utils.db.GenericDao; + +public interface VMComputeTagDao extends GenericDao{ + + void persist(long vmId, List computeTags); + + List getComputeTags(long vmId); + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDaoImpl.java new file mode 100644 index 00000000000..2fa5a4cbfe5 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMComputeTagDaoImpl.java @@ -0,0 +1,71 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db.dao; + + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.ejb.Local; + + +import org.apache.cloudstack.engine.cloud.entity.api.db.VMComputeTagVO; + +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; + +@Component +@Local(value = { VMComputeTagDao.class }) +public class VMComputeTagDaoImpl extends GenericDaoBase implements VMComputeTagDao { + + protected SearchBuilder VmIdSearch; + + public VMComputeTagDaoImpl() { + } + + @PostConstruct + public void init() { + VmIdSearch = createSearchBuilder(); + VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ); + VmIdSearch.done(); + + } + + @Override + public void persist(long vmId, List computeTags) { + Transaction txn = Transaction.currentTxn(); + + txn.start(); + SearchCriteria sc = VmIdSearch.create(); + sc.setParameters("vmId", vmId); + expunge(sc); + + for (String tag : computeTags) { + tag = tag.trim(); + if(tag.length() > 0) { + VMComputeTagVO vo = new VMComputeTagVO(vmId, tag); + persist(vo); + } + } + txn.commit(); + } + + @Override + public List getComputeTags(long vmId) { + + SearchCriteria sc = VmIdSearch.create(); + sc.setParameters("vmId", vmId); + + List results = search(sc, null); + List computeTags = new ArrayList(results.size()); + for (VMComputeTagVO result : results) { + computeTags.add(result.getComputeTag()); + } + + return computeTags; + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDao.java new file mode 100644 index 00000000000..aa063dc0794 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDao.java @@ -0,0 +1,41 @@ +// 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.db.dao; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO; + +import com.cloud.utils.Pair; +import com.cloud.utils.db.GenericDao; +import com.cloud.utils.fsm.StateDao; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.VirtualMachine.Type; + + +/* + * Data Access Object for vm_instance table + */ +public interface VMEntityDao extends GenericDao { + + void loadVmReservation(VMEntityVO vm); + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDaoImpl.java new file mode 100644 index 00000000000..b97c4227d6b --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMEntityDaoImpl.java @@ -0,0 +1,152 @@ +// 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.db.dao; + + +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.ejb.Local; +import javax.inject.Inject; + +import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO; +import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +import com.cloud.network.NetworkVO; +import com.cloud.network.dao.NetworkDao; +import com.cloud.utils.Pair; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.Transaction; +import com.cloud.vm.NicProfile; + + + +@Component +@Local(value = { VMEntityDao.class }) +public class VMEntityDaoImpl extends GenericDaoBase implements VMEntityDao { + + public static final Logger s_logger = Logger.getLogger(VMEntityDaoImpl.class); + + + @Inject protected VMReservationDaoImpl _vmReservationDao; + + @Inject protected VMComputeTagDaoImpl _vmComputeTagDao; + + @Inject protected VMRootDiskTagDaoImpl _vmRootDiskTagsDao; + + @Inject protected VMNetworkMapDaoImpl _vmNetworkMapDao; + + + @Inject + protected NetworkDao _networkDao; + + public VMEntityDaoImpl() { + } + + @PostConstruct + protected void init() { + + } + + @Override + public void loadVmReservation(VMEntityVO vm) { + VMReservationVO vmReservation = _vmReservationDao.findByVmId(vm.getId()); + vm.setVmReservation(vmReservation); + } + + @Override + @DB + public VMEntityVO persist(VMEntityVO vm) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + + VMEntityVO dbVO = super.persist(vm); + + saveVmNetworks(vm); + loadVmNetworks(dbVO); + saveVmReservation(vm); + loadVmReservation(dbVO); + saveComputeTags(vm.getId(), vm.getComputeTags()); + loadComputeTags(dbVO); + saveRootDiskTags(vm.getId(), vm.getRootDiskTags()); + loadRootDiskTags(dbVO); + + txn.commit(); + + return dbVO; + } + + private void loadVmNetworks(VMEntityVO dbVO) { + List networksIds = _vmNetworkMapDao.getNetworks(dbVO.getId()); + + List networks = new ArrayList(); + for(Long networkId : networksIds){ + NetworkVO network = _networkDao.findById(networkId); + if(network != null){ + networks.add(network.getUuid()); + } + } + + dbVO.setNetworkIds(networks); + + } + + private void saveVmNetworks(VMEntityVO vm) { + List networks = new ArrayList(); + + for(String uuid : vm.getNetworkIds()){ + NetworkVO network = _networkDao.findByUuid(uuid); + if(network != null){ + networks.add(network.getId()); + } + } + _vmNetworkMapDao.persist(vm.getId(), networks); + + } + + private void loadRootDiskTags(VMEntityVO dbVO) { + List rootDiskTags = _vmRootDiskTagsDao.getRootDiskTags(dbVO.getId()); + dbVO.setRootDiskTags(rootDiskTags); + + } + + private void loadComputeTags(VMEntityVO dbVO) { + List computeTags = _vmComputeTagDao.getComputeTags(dbVO.getId()); + dbVO.setComputeTags(computeTags); + + } + + private void saveRootDiskTags(long vmId, List rootDiskTags) { + _vmRootDiskTagsDao.persist(vmId, rootDiskTags); + + } + + private void saveComputeTags(long vmId, List computeTags) { + _vmComputeTagDao.persist(vmId, computeTags); + } + + private void saveVmReservation(VMEntityVO vm) { + _vmReservationDao.persist(vm.getVmReservation()); + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java new file mode 100644 index 00000000000..bb482d3e9f4 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDao.java @@ -0,0 +1,15 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db.dao; + +import java.util.List; + +import org.apache.cloudstack.engine.cloud.entity.api.db.VMNetworkMapVO; + +import com.cloud.utils.db.GenericDao; + +public interface VMNetworkMapDao extends GenericDao{ + + void persist(long vmId, List networks); + + List getNetworks(long vmId); + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java new file mode 100644 index 00000000000..08d2ab26757 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMNetworkMapDaoImpl.java @@ -0,0 +1,69 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db.dao; + + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.PostConstruct; +import javax.ejb.Local; +import javax.inject.Inject; +import org.apache.cloudstack.engine.cloud.entity.api.db.VMNetworkMapVO; +import org.springframework.stereotype.Component; +import com.cloud.network.dao.NetworkDao; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; + +@Component +@Local(value = { VMNetworkMapDao.class }) +public class VMNetworkMapDaoImpl extends GenericDaoBase implements VMNetworkMapDao { + + protected SearchBuilder VmIdSearch; + + @Inject + protected NetworkDao _networkDao; + + public VMNetworkMapDaoImpl() { + } + + @PostConstruct + public void init() { + VmIdSearch = createSearchBuilder(); + VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ); + VmIdSearch.done(); + + } + + @Override + public void persist(long vmId, List networks) { + Transaction txn = Transaction.currentTxn(); + + txn.start(); + SearchCriteria sc = VmIdSearch.create(); + sc.setParameters("vmId", vmId); + expunge(sc); + + for (Long networkId : networks) { + VMNetworkMapVO vo = new VMNetworkMapVO(vmId, networkId); + persist(vo); + } + + txn.commit(); + } + + @Override + public List getNetworks(long vmId) { + + SearchCriteria sc = VmIdSearch.create(); + sc.setParameters("vmId", vmId); + + List results = search(sc, null); + List networks = new ArrayList(results.size()); + for (VMNetworkMapVO result : results) { + networks.add(result.getNetworkId()); + } + + return networks; + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDao.java new file mode 100644 index 00000000000..06f308d18e5 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDao.java @@ -0,0 +1,18 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db.dao; + + +import java.util.Map; + +import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO; + +import com.cloud.utils.db.GenericDao; + +public interface VMReservationDao extends GenericDao{ + + VMReservationVO findByVmId(long vmId); + + void loadVolumeReservation(VMReservationVO reservation); + + VMReservationVO findByReservationId(String reservationId); + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDaoImpl.java new file mode 100644 index 00000000000..10f56101826 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMReservationDaoImpl.java @@ -0,0 +1,93 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db.dao; + + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.ejb.Local; +import javax.inject.Inject; + +import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO; +import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO; +import org.apache.cloudstack.engine.cloud.entity.api.db.VolumeReservationVO; +import org.springframework.stereotype.Component; + +import com.cloud.host.dao.HostTagsDaoImpl; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; + +@Component +@Local(value = { VMReservationDao.class }) +public class VMReservationDaoImpl extends GenericDaoBase implements VMReservationDao { + + protected SearchBuilder VmIdSearch; + + @Inject protected VolumeReservationDaoImpl _volumeReservationDao; + + public VMReservationDaoImpl() { + } + + @PostConstruct + public void init() { + VmIdSearch = createSearchBuilder(); + VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ); + VmIdSearch.done(); + } + + @Override + public VMReservationVO findByVmId(long vmId) { + SearchCriteria sc = VmIdSearch.create("vmId", vmId); + VMReservationVO vmRes = findOneBy(sc); + loadVolumeReservation(vmRes); + return vmRes; + } + + + @Override + public void loadVolumeReservation(VMReservationVO reservation){ + List volumeResList = _volumeReservationDao.listVolumeReservation(reservation.getId()); + Map volumeReservationMap = new HashMap(); + + for(VolumeReservationVO res : volumeResList){ + volumeReservationMap.put(res.getVolumeId(), res.getPoolId()); + } + reservation.setVolumeReservation(volumeReservationMap); + } + + @Override + @DB + public VMReservationVO persist(VMReservationVO reservation) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + + VMReservationVO dbVO = super.persist(reservation); + + saveVolumeReservation(reservation); + loadVolumeReservation(dbVO); + + txn.commit(); + + return dbVO; + } + + 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); + } + + } + + @Override + public VMReservationVO findByReservationId(String reservationId) { + VMReservationVO vmRes = super.findByUuid(reservationId); + loadVolumeReservation(vmRes); + return vmRes; + } +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDao.java new file mode 100644 index 00000000000..87611197def --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDao.java @@ -0,0 +1,15 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db.dao; + +import java.util.List; + +import org.apache.cloudstack.engine.cloud.entity.api.db.VMRootDiskTagVO; + +import com.cloud.utils.db.GenericDao; + +public interface VMRootDiskTagDao extends GenericDao{ + + void persist(long vmId, List diskTags); + + List getRootDiskTags(long vmId); + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDaoImpl.java new file mode 100644 index 00000000000..b65993d73e6 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VMRootDiskTagDaoImpl.java @@ -0,0 +1,70 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db.dao; + + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.ejb.Local; + + +import org.apache.cloudstack.engine.cloud.entity.api.db.VMRootDiskTagVO; + +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; + +@Component +@Local(value = { VMRootDiskTagDao.class }) +public class VMRootDiskTagDaoImpl extends GenericDaoBase implements VMRootDiskTagDao { + + protected SearchBuilder VmIdSearch; + + public VMRootDiskTagDaoImpl() { + } + + @PostConstruct + public void init() { + VmIdSearch = createSearchBuilder(); + VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ); + VmIdSearch.done(); + + } + + @Override + public void persist(long vmId, List rootDiskTags) { + Transaction txn = Transaction.currentTxn(); + + txn.start(); + SearchCriteria sc = VmIdSearch.create(); + sc.setParameters("vmId", vmId); + expunge(sc); + + for (String tag : rootDiskTags) { + tag = tag.trim(); + if(tag.length() > 0) { + VMRootDiskTagVO vo = new VMRootDiskTagVO(vmId, tag); + persist(vo); + } + } + txn.commit(); + } + + + @Override + public List getRootDiskTags(long vmId) { + SearchCriteria sc = VmIdSearch.create(); + sc.setParameters("vmId", vmId); + + List results = search(sc, null); + List computeTags = new ArrayList(results.size()); + for (VMRootDiskTagVO result : results) { + computeTags.add(result.getRootDiskTag()); + } + return computeTags; + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDao.java new file mode 100644 index 00000000000..d4aee472455 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDao.java @@ -0,0 +1,15 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db.dao; + +import java.util.List; + +import org.apache.cloudstack.engine.cloud.entity.api.db.VolumeReservationVO; + +import com.cloud.utils.db.GenericDao; + +public interface VolumeReservationDao extends GenericDao{ + + VolumeReservationVO findByVmId(long vmId); + + List listVolumeReservation(long vmReservationId); + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDaoImpl.java new file mode 100644 index 00000000000..ea96eda9084 --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDaoImpl.java @@ -0,0 +1,52 @@ +package org.apache.cloudstack.engine.cloud.entity.api.db.dao; + + +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.ejb.Local; +import javax.inject.Inject; + +import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO; +import org.apache.cloudstack.engine.cloud.entity.api.db.VolumeReservationVO; +import org.springframework.stereotype.Component; + +import com.cloud.host.dao.HostTagsDaoImpl; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@Component +@Local(value = { VolumeReservationDao.class }) +public class VolumeReservationDaoImpl extends GenericDaoBase implements VolumeReservationDao { + + protected SearchBuilder VmIdSearch; + protected SearchBuilder VmReservationIdSearch; + + public VolumeReservationDaoImpl() { + } + + @PostConstruct + public void init() { + VmIdSearch = createSearchBuilder(); + VmIdSearch.and("vmId", VmIdSearch.entity().getVmId(), SearchCriteria.Op.EQ); + VmIdSearch.done(); + + VmReservationIdSearch = createSearchBuilder(); + VmReservationIdSearch.and("vmReservationId", VmReservationIdSearch.entity().geVmReservationId(), SearchCriteria.Op.EQ); + VmReservationIdSearch.done(); + } + + @Override + public VolumeReservationVO findByVmId(long vmId) { + SearchCriteria sc = VmIdSearch.create("vmId", vmId); + return findOneBy(sc); + } + + @Override + public List listVolumeReservation(long vmReservationId) { + SearchCriteria sc = VmReservationIdSearch.create("vmReservationId", vmReservationId); + return listBy(sc); + } + +} diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java index dc5b57f24bf..a659c5d86ff 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/DataCenterResourceManagerImpl.java @@ -55,7 +55,7 @@ public class DataCenterResourceManagerImpl implements DataCenterResourceManager @Override public DataCenterVO loadDataCenter(String dataCenterId) { - DataCenterVO dataCenterVO = _dataCenterDao.findByUUID(dataCenterId); + DataCenterVO dataCenterVO = _dataCenterDao.findByUuid(dataCenterId); if(dataCenterVO == null){ throw new InvalidParameterValueException("Zone does not exist"); } @@ -86,7 +86,7 @@ public class DataCenterResourceManagerImpl implements DataCenterResourceManager @Override public HostPodVO loadPod(String uuid) { - HostPodVO pod = _podDao.findByUUID(uuid); + HostPodVO pod = _podDao.findByUuid(uuid); if(pod == null){ throw new InvalidParameterValueException("Pod does not exist"); } @@ -95,7 +95,7 @@ public class DataCenterResourceManagerImpl implements DataCenterResourceManager @Override public ClusterVO loadCluster(String uuid) { - ClusterVO cluster = _clusterDao.findByUUID(uuid); + ClusterVO cluster = _clusterDao.findByUuid(uuid); if(cluster == null){ throw new InvalidParameterValueException("Pod does not exist"); } @@ -114,7 +114,7 @@ public class DataCenterResourceManagerImpl implements DataCenterResourceManager @Override public HostVO loadHost(String uuid) { - HostVO host = _hostDao.findByUUID(uuid); + HostVO host = _hostDao.findByUuid(uuid); if(host == null){ throw new InvalidParameterValueException("Host does not exist"); } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java index 771b64d56da..dba4734a142 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDao.java @@ -34,5 +34,4 @@ public interface ClusterDao extends GenericDao, StateDao> getPodClusterIdMap(List clusterIds); List listDisabledClusters(long zoneId, Long podId); List listClustersWithDisabledPods(long zoneId); - ClusterVO findByUUID(String uuid); } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java index f33c6730f1a..3ab6cee2a77 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/ClusterDaoImpl.java @@ -252,20 +252,12 @@ public class ClusterDaoImpl extends GenericDaoBase implements C return result; } - - @Override - public ClusterVO findByUUID(String uuid) { - SearchCriteria sc = UUIDSearch.create(); - sc.setParameters("uuid", uuid); - return findOneBy(sc); - } - - @Override - public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity clusterEntity, Object data) { - - ClusterVO vo = findById(clusterEntity.getId()); - - Date oldUpdatedTime = vo.getLastUpdated(); + @Override + public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity clusterEntity, Object data) { + + ClusterVO vo = findById(clusterEntity.getId()); + + Date oldUpdatedTime = vo.getLastUpdated(); SearchCriteria sc = StateChangeSearch.create(); sc.setParameters("id", vo.getId()); diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDao.java index f34533e7309..ce4ccfc8fc7 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDao.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDao.java @@ -52,5 +52,4 @@ public interface DataCenterDao extends GenericDao, StateDao< List findByKeyword(String keyword); - DataCenterVO findByUUID(String uuid); } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java index 3a0d2c89a0d..832914332cf 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/DataCenterDaoImpl.java @@ -75,13 +75,7 @@ public class DataCenterDaoImpl extends GenericDaoBase implem return findOneBy(sc); } - @Override - public DataCenterVO findByUUID(String uuid) { - SearchCriteria sc = UUIDSearch.create(); - sc.setParameters("uuid", uuid); - return findOneBy(sc); - } - + @Override public DataCenterVO findByToken(String zoneToken){ SearchCriteria sc = TokenSearch.create(); diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDao.java index e3437afbca5..fed7c6e8a2c 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDao.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDao.java @@ -82,6 +82,4 @@ public interface HostDao extends GenericDao, StateDao listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag); - - HostVO findByUUID(String uuid); } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java index f33bc21256e..dbbf342a26d 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostDaoImpl.java @@ -725,94 +725,85 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao return findOneBy(sc); } - @Override - public List findHypervisorHostInCluster(long clusterId) { - SearchCriteria sc = TypeClusterStatusSearch.create(); - sc.setParameters("type", Host.Type.Routing); - sc.setParameters("cluster", clusterId); - sc.setParameters("status", Status.Up); - sc.setParameters("resourceState", ResourceState.Enabled); + @Override + public List findHypervisorHostInCluster(long clusterId) { + SearchCriteria sc = TypeClusterStatusSearch.create(); + sc.setParameters("type", Host.Type.Routing); + sc.setParameters("cluster", clusterId); + sc.setParameters("status", Status.Up); + sc.setParameters("resourceState", ResourceState.Enabled); + + return listBy(sc); + } - return listBy(sc); - } + @Override + public List lockRows( + SearchCriteria sc, + Filter filter, boolean exclusive) { + // TODO Auto-generated method stub + return null; + } - @Override - public List lockRows( - SearchCriteria sc, - Filter filter, boolean exclusive) { - // TODO Auto-generated method stub - return null; - } - - @Override - public org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO lockOneRandomRow( - SearchCriteria sc, - boolean exclusive) { - // TODO Auto-generated method stub - return null; - } + @Override + public org.apache.cloudstack.engine.datacenter.entity.api.db.HostVO lockOneRandomRow( + SearchCriteria sc, + boolean exclusive) { + // TODO Auto-generated method stub + return null; + } - @Override - public List search( - SearchCriteria sc, - Filter filter) { - // TODO Auto-generated method stub - return null; - } + @Override + public List search( + SearchCriteria sc, + Filter filter) { + // TODO Auto-generated method stub + return null; + } - @Override - public List search( - SearchCriteria sc, - Filter filter, boolean enable_query_cache) { - // TODO Auto-generated method stub - return null; - } + @Override + public List search( + SearchCriteria sc, + Filter filter, boolean enable_query_cache) { + // TODO Auto-generated method stub + return null; + } - @Override - public List searchIncludingRemoved( - SearchCriteria sc, - Filter filter, Boolean lock, boolean cache) { - // TODO Auto-generated method stub - return null; - } + @Override + public List searchIncludingRemoved( + SearchCriteria sc, + Filter filter, Boolean lock, boolean cache) { + // TODO Auto-generated method stub + return null; + } - @Override - public List searchIncludingRemoved( - SearchCriteria sc, - Filter filter, Boolean lock, boolean cache, - boolean enable_query_cache) { - // TODO Auto-generated method stub - return null; - } + @Override + public List searchIncludingRemoved( + SearchCriteria sc, + Filter filter, Boolean lock, boolean cache, + boolean enable_query_cache) { + // TODO Auto-generated method stub + return null; + } - @Override - public int remove( - SearchCriteria sc) { - // TODO Auto-generated method stub - return 0; - } + @Override + public int remove( + SearchCriteria sc) { + // TODO Auto-generated method stub + return 0; + } - @Override - public int expunge(SearchCriteria sc) { - // TODO Auto-generated method stub - return 0; - } + @Override + public int expunge(SearchCriteria sc) { + // TODO Auto-generated method stub + return 0; + } - @Override - public HostVO findOneBy(SearchCriteria sc) { - // TODO Auto-generated method stub - return null; - } - - - - @Override - public HostVO findByUUID(String uuid) { - SearchCriteria sc = UUIDSearch.create(); - sc.setParameters("uuid", uuid); - return findOneBy(sc); - } + @Override + public HostVO findOneBy(SearchCriteria sc) { + // TODO Auto-generated method stub + return null; + } } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java index bfdbaaef31b..a5482cad7d8 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDao.java @@ -30,7 +30,4 @@ public interface HostPodDao extends GenericDao, StateDao> getCurrentPodCidrSubnets(long zoneId, long podIdToSkip); public List listDisabledPods(long zoneId); - - public HostPodVO findByUUID(String uuid); - } diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java index b39fdc3810c..0bb270ca7bc 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/HostPodDaoImpl.java @@ -146,13 +146,7 @@ public class HostPodDaoImpl extends GenericDaoBase implements H return customSearch(sc, null); } - @Override - public HostPodVO findByUUID(String uuid) { - SearchCriteria sc = UUIDSearch.create(); - sc.setParameters("uuid", uuid); - return findOneBy(sc); - } - + @Override public boolean updateState(State currentState, Event event, State nextState, DataCenterResourceEntity podEntity, Object data) { 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 efa95fd8ab7..c60ed3416a0 100755 --- a/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java @@ -40,12 +40,16 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.network.NetworkVO; +import com.cloud.network.dao.NetworkDao; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DiskOfferingVO; 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.vm.NicProfile; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.VMInstanceDao; @@ -74,6 +78,13 @@ public class CloudOrchestrator implements OrchestrationService { @Inject protected VirtualMachineEntityFactory _vmEntityFactory; + + @Inject + protected NetworkDao _networkDao; + + @Inject + protected AccountDao _accountDao = null; + 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) { @@ -143,28 +154,36 @@ public class CloudOrchestrator implements OrchestrationService { Long diskSize, List computeTags, List rootDiskTags, - List networks, DeploymentPlan plan) throws InsufficientCapacityException { + Map networkNicMap, DeploymentPlan plan) throws InsufficientCapacityException { // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager); - + + List> networkIpMap = new ArrayList>(); + for (String uuid : networkNicMap.keySet()) { + NetworkVO network = _networkDao.findByUuid(uuid); + if(network != null){ + networkIpMap.add(new Pair(network, networkNicMap.get(uuid))); + } + } + 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); + vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList(networkNicMap.keySet())); + HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor); //load vm instance and offerings and call virtualMachineManagerImpl - VMInstanceVO vm = _vmDao.findByUUID(id); + VMInstanceVO vm = _vmDao.findByUuid(id); - // If the template represents an ISO, a disk offering must be passed in, - // and will be used to create the root disk - // Else, a disk offering is optional, and if present will be used to - // create the data disk - Pair rootDiskOffering = new Pair(null, null); + // If the template represents an ISO, a disk offering must be passed in, and will be used to create the root disk + // Else, a disk offering is optional, and if present will be used to create the data disk + + Pair rootDiskOffering = new Pair(null, null); List> dataDiskOfferings = new ArrayList>(); ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getServiceOfferingId()); @@ -172,8 +191,7 @@ public class CloudOrchestrator implements OrchestrationService { DiskOfferingVO diskOffering = _diskOfferingDao.findById(vm.getDiskOfferingId()); if (diskOffering == null) { - throw new InvalidParameterValueException( - "Unable to find disk offering " + vm.getDiskOfferingId()); + throw new InvalidParameterValueException("Unable to find disk offering " + vm.getDiskOfferingId()); } Long size = null; if (diskOffering.getDiskSize() == 0) { @@ -186,7 +204,8 @@ public class CloudOrchestrator implements OrchestrationService { } dataDiskOfferings.add(new Pair(diskOffering, size)); - if (_itMgr.allocate(vm, _templateDao.findById(new Long(templateId)), offering, rootDiskOffering, dataDiskOfferings, null, null, plan, hypervisorType, null) == null) { + + if (_itMgr.allocate(vm, _templateDao.findById(new Long(templateId)), offering, rootDiskOffering, dataDiskOfferings, networkIpMap, null, plan, hypervisorType, _accountDao.findById(new Long(owner))) == null) { return null; } @@ -195,7 +214,7 @@ public class CloudOrchestrator implements OrchestrationService { @Override 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 { + List computeTags, List rootDiskTags, Map networkNicMap, DeploymentPlan plan) throws InsufficientCapacityException { // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager); VirtualMachineEntityImpl vmEntity = null; @@ -204,10 +223,10 @@ public class CloudOrchestrator implements OrchestrationService { } catch (Exception e) { // add error handling here } - vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks); + vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList(networkNicMap.keySet())); //load vm instance and offerings and call virtualMachineManagerImpl - VMInstanceVO vm = _vmDao.findByUUID(id); + VMInstanceVO vm = _vmDao.findByUuid(id); Pair rootDiskOffering = new Pair(null, null); @@ -251,4 +270,10 @@ public class CloudOrchestrator implements OrchestrationService { return null; } + @Override + public VirtualMachineEntity getVirtualMachine(String id) { + VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, vmEntityManager); + return vmEntity; + } + } diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java index c0b72e772de..787d1c1b623 100755 --- a/server/src/com/cloud/deploy/FirstFitPlanner.java +++ b/server/src/com/cloud/deploy/FirstFitPlanner.java @@ -734,31 +734,35 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner { //If the plan specifies a poolId, it means that this VM's ROOT volume is ready and the pool should be reused. //In this case, also check if rest of the volumes are ready and can be reused. if(plan.getPoolId() != null){ - if (toBeCreated.getState() == Volume.State.Ready && toBeCreated.getPoolId() != null) { - s_logger.debug("Volume is in READY state and has pool already allocated, checking if pool can be reused, poolId: "+toBeCreated.getPoolId()); - List suitablePools = new ArrayList(); - StoragePoolVO pool = _storagePoolDao.findById(toBeCreated.getPoolId()); - if(!pool.isInMaintenance()){ - if(!avoid.shouldAvoid(pool)){ - long exstPoolDcId = pool.getDataCenterId(); + s_logger.debug("Volume has pool already allocated, checking if pool can be reused, poolId: "+toBeCreated.getPoolId()); + List suitablePools = new ArrayList(); + StoragePoolVO pool; + if(toBeCreated.getPoolId() != null){ + pool = _storagePoolDao.findById(toBeCreated.getPoolId()); + }else{ + pool = _storagePoolDao.findById(plan.getPoolId()); + } + + if(!pool.isInMaintenance()){ + if(!avoid.shouldAvoid(pool)){ + long exstPoolDcId = pool.getDataCenterId(); - long exstPoolPodId = pool.getPodId() != null ? pool.getPodId() : -1; - long exstPoolClusterId = pool.getClusterId() != null ? pool.getClusterId() : -1; - if(plan.getDataCenterId() == exstPoolDcId && plan.getPodId() == exstPoolPodId && plan.getClusterId() == exstPoolClusterId){ - s_logger.debug("Planner need not allocate a pool for this volume since its READY"); - suitablePools.add(pool); - suitableVolumeStoragePools.put(toBeCreated, suitablePools); - readyAndReusedVolumes.add(toBeCreated); - continue; - }else{ - s_logger.debug("Pool of the volume does not fit the specified plan, need to reallocate a pool for this volume"); - } + long exstPoolPodId = pool.getPodId() != null ? pool.getPodId() : -1; + long exstPoolClusterId = pool.getClusterId() != null ? pool.getClusterId() : -1; + if(plan.getDataCenterId() == exstPoolDcId && plan.getPodId() == exstPoolPodId && plan.getClusterId() == exstPoolClusterId){ + s_logger.debug("Planner need not allocate a pool for this volume since its READY"); + suitablePools.add(pool); + suitableVolumeStoragePools.put(toBeCreated, suitablePools); + readyAndReusedVolumes.add(toBeCreated); + continue; }else{ - s_logger.debug("Pool of the volume is in avoid set, need to reallocate a pool for this volume"); + s_logger.debug("Pool of the volume does not fit the specified plan, need to reallocate a pool for this volume"); } }else{ - s_logger.debug("Pool of the volume is in maintenance, need to reallocate a pool for this volume"); + s_logger.debug("Pool of the volume is in avoid set, need to reallocate a pool for this volume"); } + }else{ + s_logger.debug("Pool of the volume is in maintenance, need to reallocate a pool for this volume"); } } diff --git a/server/src/com/cloud/network/security/SecurityManagerMBeanImpl.java b/server/src/com/cloud/network/security/SecurityManagerMBeanImpl.java index 9328190f884..90340d77eb6 100644 --- a/server/src/com/cloud/network/security/SecurityManagerMBeanImpl.java +++ b/server/src/com/cloud/network/security/SecurityManagerMBeanImpl.java @@ -141,7 +141,7 @@ public class SecurityManagerMBeanImpl extends StandardMBean implements SecurityG @Override public void simulateVmStart(Long vmId) { //all we need is the vmId - VMInstanceVO vm = new VMInstanceVO(vmId, 5, "foo", "foo", Type.User, null, HypervisorType.Any, 8, 1, 1, false, false); + VMInstanceVO vm = new VMInstanceVO(vmId, 5, "foo", "foo", Type.User, null, HypervisorType.Any, 8, 1, 1, false, false,null); _sgMgr.handleVmStarted(vm); } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index bf3da4cba61..b6042a1045f 100644 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -50,6 +50,7 @@ import org.apache.cloudstack.api.command.user.vmgroup.CreateVMGroupCmd; import org.apache.cloudstack.api.command.user.vmgroup.DeleteVMGroupCmd; import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd; import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd; + import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity; import org.apache.cloudstack.engine.service.api.OrchestrationService; import org.apache.commons.codec.binary.Base64; @@ -97,12 +98,14 @@ import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.event.ActionEvent; import com.cloud.event.EventTypes; import com.cloud.event.UsageEventVO; import com.cloud.event.dao.UsageEventDao; +import com.cloud.exception.CloudException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; @@ -542,10 +545,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager Account account = _accountDao.findById(user.getAccountId()); try { - status = _itMgr.stop(vm, user, account); + VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid()); + status = vmEntity.stop(new Long(userId).toString()); } catch (ResourceUnavailableException e) { s_logger.debug("Unable to stop due to ", e); status = false; + } catch (CloudException e) { + throw new CloudRuntimeException( + "Unable to contact the agent to stop the virtual machine " + + vm, e); } if (status) { @@ -2903,8 +2911,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } List> networks = new ArrayList>(); - - List networkUuidList = new ArrayList(); + + Map networkNicMap = new HashMap(); short defaultNetworkNumber = 0; boolean securityGroupEnabled = false; @@ -2948,7 +2956,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager vpcNetwork = true; } - networkUuidList.add(network.getUuid()); + networkNicMap.put(network.getUuid(), profile); } if (securityGroupIdList != null && !securityGroupIdList.isEmpty() @@ -3030,7 +3038,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager template.getId(), hypervisorType, template.getGuestOSId(), offering.getOfferHA(), offering.getLimitCpuUse(), owner.getDomainId(), owner.getId(), offering.getId(), userData, - hostName); + hostName, diskOfferingId); vm.setUuid(uuidName); if (sshPublicKey != null) { @@ -3063,9 +3071,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager rootDiskTags.add(offering.getTags()); if(isIso){ - VirtualMachineEntity vmEntity = _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(), owner.getAccountName(), vm.getIsoId().toString(), hostName, displayName, hypervisor.name(), guestOSCategory.getName(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkUuidList, plan); + VirtualMachineEntity vmEntity = _orchSrvc.createVirtualMachineFromScratch(vm.getUuid(), new Long(owner.getAccountId()).toString(), vm.getIsoId().toString(), hostName, displayName, hypervisor.name(), guestOSCategory.getName(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, plan); }else { - VirtualMachineEntity vmEntity = _orchSrvc.createVirtualMachine(vm.getUuid(), owner.getAccountName(), new Long(template.getId()).toString(), hostName, displayName, hypervisor.name(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkUuidList, plan); + VirtualMachineEntity vmEntity = _orchSrvc.createVirtualMachine(vm.getUuid(), new Long(owner.getAccountId()).toString(), new Long(template.getId()).toString(), hostName, displayName, hypervisor.name(), offering.getCpu(), offering.getSpeed(), offering.getRamSize(), diskSize, computeTags, rootDiskTags, networkNicMap, plan); } if (s_logger.isDebugEnabled()) { @@ -3377,12 +3385,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager UserVO user = _userDao.findById(userId); try { - _itMgr.advanceStop(vm, forced, user, caller); + VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid()); + vmEntity.stop(new Long(userId).toString()); } catch (ResourceUnavailableException e) { throw new CloudRuntimeException( "Unable to contact the agent to stop the virtual machine " + vm, e); - } catch (OperationTimedoutException e) { + } catch (CloudException e) { throw new CloudRuntimeException( "Unable to contact the agent to stop the virtual machine " + vm, e); @@ -3533,16 +3542,17 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager params.put(VirtualMachineProfile.Param.VmPassword, password); } - vm = _itMgr.start(vm, params, callerUser, callerAccount, plan); + VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid()); + + String reservationId = vmEntity.reserve("FirstFitPlanner", plan, new ExcludeList(), new Long(callerUser.getId()).toString()); + vmEntity.deploy(reservationId, new Long(callerUser.getId()).toString()); - Pair> vmParamPair = new Pair( - vm, params); + Pair> vmParamPair = new Pair(vm, params); if (vm != null && vm.isUpdateParameters()) { // this value is not being sent to the backend; need only for api // display purposes if (template.getEnablePassword()) { - vm.setPassword((String) vmParamPair.second().get( - VirtualMachineProfile.Param.VmPassword)); + vm.setPassword((String) vmParamPair.second().get(VirtualMachineProfile.Param.VmPassword)); vm.setUpdateParameters(false); _vmDao.update(vm.getId(), vm); } @@ -3579,8 +3589,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager State vmState = vm.getState(); try { - status = _itMgr.destroy(vm, userCaller, caller); - } catch (OperationTimedoutException e) { + VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid()); + status = vmEntity.destroy(new Long(userId).toString()); + } catch (CloudException e) { CloudRuntimeException ex = new CloudRuntimeException( "Unable to destroy with specified vmId", e); ex.addProxyObject(vm, vmId, "vmId"); @@ -4503,4 +4514,5 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager @Override public void prepareStop(VirtualMachineProfile profile) { } + } diff --git a/server/src/com/cloud/vm/dao/VMInstanceDao.java b/server/src/com/cloud/vm/dao/VMInstanceDao.java index 3293f61651a..d34b25726dc 100644 --- a/server/src/com/cloud/vm/dao/VMInstanceDao.java +++ b/server/src/com/cloud/vm/dao/VMInstanceDao.java @@ -114,7 +114,5 @@ public interface VMInstanceDao extends GenericDao, StateDao< * @return */ List listDistinctHostNames(long networkId, VirtualMachine.Type... types); - - VMInstanceVO findByUUID(String uuid); } diff --git a/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java b/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java index c85b2f6e148..109c68fd4c3 100644 --- a/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java +++ b/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java @@ -617,9 +617,4 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem return result; } - @Override - public VMInstanceVO findByUUID(String uuid) { - // TODO Auto-generated method stub - return null; - } } diff --git a/setup/db/4.1-new-db-schema.sql b/setup/db/4.1-new-db-schema.sql index 84fbd91979b..f52354fd9c6 100644 --- a/setup/db/4.1-new-db-schema.sql +++ b/setup/db/4.1-new-db-schema.sql @@ -65,3 +65,28 @@ CREATE TABLE `cloud`.`vm_network_map` ( `network_id` bigint unsigned NOT NULL COMMENT 'network id', PRIMARY KEY(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE `cloud`.`vm_reservation` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `uuid` varchar(40) NOT NULL COMMENT 'reservation id', + `vm_id` bigint unsigned NOT NULL COMMENT 'vm id', + `datacenter_id` bigint unsigned NOT NULL COMMENT 'zone id', + `pod_id` bigint unsigned NOT NULL COMMENT 'pod id', + `cluster_id` bigint unsigned NOT NULL COMMENT 'cluster id', + `host_id` bigint unsigned NOT NULL COMMENT 'host id', + `created` datetime COMMENT 'date created', + `removed` datetime COMMENT 'date removed if not null', + CONSTRAINT `uc_vm_reservation__uuid` UNIQUE (`uuid`), + PRIMARY KEY(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`volume_reservation` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `vm_reservation_id` bigint unsigned NOT NULL COMMENT 'id of the vm reservation', + `vm_id` bigint unsigned NOT NULL COMMENT 'vm id', + `volume_id` bigint unsigned NOT NULL COMMENT 'volume id', + `pool_id` bigint unsigned NOT NULL COMMENT 'pool assigned to the volume', + CONSTRAINT `fk_vm_pool_reservation__vm_reservation_id` FOREIGN KEY (`vm_reservation_id`) REFERENCES `vm_reservation`(`id`) ON DELETE CASCADE, + PRIMARY KEY(`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8;