OrchestrationService: some changes for DeployVM

This commit is contained in:
Prachi Damle 2013-01-08 11:53:41 -08:00
parent 992fa473be
commit a4f4c98670
14 changed files with 5412 additions and 3594 deletions

View File

@ -286,6 +286,8 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, Identity, S
public Date getCreated(); public Date getCreated();
public long getServiceOfferingId(); public long getServiceOfferingId();
public long getDiskOfferingId();
Type getType(); Type getType();

View File

@ -475,4 +475,10 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject<State, Vi
this.serviceOfferingId = serviceOfferingId; this.serviceOfferingId = serviceOfferingId;
} }
@Override
public long getDiskOfferingId() {
// TODO Auto-generated method stub
return 0;
}
} }

View File

@ -40,7 +40,7 @@ import com.cloud.vm.VirtualMachine;
@Path("vm/{id}") @Path("vm/{id}")
@Produces({"application/json", "application/xml"}) @Produces({"application/json", "application/xml"})
@XmlRootElement(name="vm") @XmlRootElement(name="vm")
public interface VirtualMachineEntity extends VirtualMachine, CloudStackEntity { public interface VirtualMachineEntity extends CloudStackEntity {
/** /**
* @return List of uuids for volumes attached to this virtual machine. * @return List of uuids for volumes attached to this virtual machine.

View File

@ -32,6 +32,8 @@ import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity; import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor;
@Path("orchestration") @Path("orchestration")
@ -61,13 +63,16 @@ public interface OrchestrationService {
@QueryParam("template-id") String templateId, @QueryParam("template-id") String templateId,
@QueryParam("host-name") String hostName, @QueryParam("host-name") String hostName,
@QueryParam("display-name") String displayName, @QueryParam("display-name") String displayName,
@QueryParam("hypervisor") String hypervisor,
@QueryParam("cpu") int cpu, @QueryParam("cpu") int cpu,
@QueryParam("speed") int speed, @QueryParam("speed") int speed,
@QueryParam("ram") long memory, @QueryParam("ram") long memory,
@QueryParam("disk-size") Long diskSize,
@QueryParam("compute-tags") List<String> computeTags, @QueryParam("compute-tags") List<String> computeTags,
@QueryParam("root-disk-tags") List<String> rootDiskTags, @QueryParam("root-disk-tags") List<String> rootDiskTags,
@QueryParam("networks") List<String> networks @QueryParam("networks") List<String> networks,
); @QueryParam("deploymentplan") DeploymentPlan plan
) throws InsufficientCapacityException;
@POST @POST
VirtualMachineEntity createVirtualMachineFromScratch( VirtualMachineEntity createVirtualMachineFromScratch(
@ -81,9 +86,12 @@ public interface OrchestrationService {
@QueryParam("cpu") int cpu, @QueryParam("cpu") int cpu,
@QueryParam("speed") int speed, @QueryParam("speed") int speed,
@QueryParam("ram") long memory, @QueryParam("ram") long memory,
@QueryParam("disk-size") Long diskSize,
@QueryParam("compute-tags") List<String> computeTags, @QueryParam("compute-tags") List<String> computeTags,
@QueryParam("root-disk-tags") List<String> rootDiskTags, @QueryParam("root-disk-tags") List<String> rootDiskTags,
@QueryParam("networks") List<String> networks); @QueryParam("networks") List<String> networks,
@QueryParam("deploymentplan") DeploymentPlan plan
) throws InsufficientCapacityException;
@POST @POST
NetworkEntity createNetwork(String id, String name, String domainName, String cidr, String gateway); NetworkEntity createNetwork(String id, String name, String domainName, String cidr, String gateway);

View File

@ -48,6 +48,11 @@
<artifactId>cloud-utils</artifactId> <artifactId>cloud-utils</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-all</artifactId>

View File

@ -0,0 +1,10 @@
package org.apache.cloudstack.engine.cloud.entity.api;
import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
public interface VMEntityManager {
VMEntityVO loadVirtualMachine(String vmId);
void saveVirtualMachine(VMEntityVO vmInstanceVO);
}

View File

@ -0,0 +1,223 @@
package org.apache.cloudstack.engine.cloud.entity.api;
import java.lang.reflect.Method;
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.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
public class VirtualMachineEntityImpl implements VirtualMachineEntity {
private VMEntityManager manager;
private VMEntityVO vmEntityVO;
public VirtualMachineEntityImpl(String vmId, VMEntityManager manager) {
this.manager = manager;
this.vmEntityVO = this.manager.loadVirtualMachine(vmId);
}
public VirtualMachineEntityImpl(String vmId, String owner, String hostName, String displayName, int cpu, int speed, long memory, List<String> computeTags, List<String> rootDiskTags, List<String> networks, VMEntityManager manager) {
this(vmId, manager);
this.vmEntityVO.setOwner(owner);
this.vmEntityVO.setHostname(hostName);
this.vmEntityVO.setDisplayname(displayName);
this.vmEntityVO.setSpeed(speed);
this.vmEntityVO.setComputeTags(computeTags);
this.vmEntityVO.setRootDiskTags(rootDiskTags);
this.vmEntityVO.setNetworkIds(networks);
manager.saveVirtualMachine(vmEntityVO);
}
@Override
public String getUuid() {
return vmEntityVO.getUuid();
}
@Override
public long getId() {
return vmEntityVO.getId();
}
@Override
public String getCurrentState() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getDesiredState() {
// TODO Auto-generated method stub
return null;
}
@Override
public Date getCreatedTime() {
return vmEntityVO.getCreated();
}
@Override
public Date getLastUpdatedTime() {
return vmEntityVO.getUpdateTime();
}
@Override
public String getOwner() {
// TODO Auto-generated method stub
return null;
}
@Override
public Map<String, String> getDetails() {
return vmEntityVO.getDetails();
}
@Override
public void addDetail(String name, String value) {
vmEntityVO.setDetail(name, value);
}
@Override
public void delDetail(String name, String value) {
// TODO Auto-generated method stub
}
@Override
public void updateDetail(String name, String value) {
// TODO Auto-generated method stub
}
@Override
public List<Method> getApplicableActions() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<String> listVolumeIds() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<VolumeEntity> listVolumes() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<String> listNicUuids() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<NicEntity> listNics() {
// TODO Auto-generated method stub
return null;
}
@Override
public TemplateEntity getTemplate() {
// TODO Auto-generated method stub
return null;
}
@Override
public List<String> listTags() {
// TODO Auto-generated method stub
return null;
}
@Override
public void addTag() {
// TODO Auto-generated method stub
}
@Override
public void delTag() {
// TODO Auto-generated method stub
}
@Override
public String reserve(String plannerToUse, DeployDestination dest,
ExcludeList exclude) {
// TODO Auto-generated method stub
return null;
}
@Override
public void migrateTo(String reservationId) {
// TODO Auto-generated method stub
}
@Override
public void deploy(String reservationId) {
// TODO Auto-generated method stub
}
@Override
public void stop() {
// TODO Auto-generated method stub
}
@Override
public void cleanup() {
// TODO Auto-generated method stub
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public VirtualMachineEntity duplicate(String externalId) {
// TODO Auto-generated method stub
return null;
}
@Override
public SnapshotEntity takeSnapshotOf() {
// TODO Auto-generated method stub
return null;
}
@Override
public void attach(VolumeEntity volume, short deviceId) {
// TODO Auto-generated method stub
}
@Override
public void detach(VolumeEntity volume) {
// TODO Auto-generated method stub
}
@Override
public void connectTo(NetworkEntity network, short nicId) {
// TODO Auto-generated method stub
}
@Override
public void disconnectFrom(NetworkEntity netowrk, short nicId) {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,560 @@
// 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;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.db.Encrypt;
import com.cloud.utils.db.GenericDao;
import com.cloud.utils.db.StateMachine;
import com.cloud.utils.fsm.FiniteStateObject;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
@Entity
@Table(name="vm_instance")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.STRING, length=32)
public class VMEntityVO implements VirtualMachine, FiniteStateObject<State, VirtualMachine.Event> {
@Id
@TableGenerator(name="vm_instance_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="vm_instance_seq", allocationSize=1)
@Column(name="id", updatable=false, nullable = false)
protected long id;
@Column(name="name", updatable=false, nullable=false, length=255)
protected String hostName = null;
@Encrypt
@Column(name="vnc_password", updatable=true, nullable=false, length=255)
protected String vncPassword;
@Column(name="proxy_id", updatable=true, nullable=true)
protected Long proxyId;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="proxy_assign_time", updatable=true, nullable=true)
protected Date proxyAssignTime;
/**
* Note that state is intentionally missing the setter. Any updates to
* the state machine needs to go through the DAO object because someone
* else could be updating it as well.
*/
@Enumerated(value=EnumType.STRING)
@StateMachine(state=State.class, event=Event.class)
@Column(name="state", updatable=true, nullable=false, length=32)
protected State state = null;
@Column(name="private_ip_address", updatable=true)
protected String privateIpAddress;
@Column(name="instance_name", updatable=true, nullable=false)
protected String instanceName;
@Column(name="vm_template_id", updatable=true, nullable=true, length=17)
protected Long templateId = new Long(-1);
@Column(name="guest_os_id", nullable=false, length=17)
protected long guestOSId;
@Column(name="host_id", updatable=true, nullable=true)
protected Long hostId;
@Column(name="last_host_id", updatable=true, nullable=true)
protected Long lastHostId;
@Column(name="pod_id", updatable=true, nullable=false)
protected Long podIdToDeployIn;
@Column(name="private_mac_address", updatable=true, nullable=true)
protected String privateMacAddress;
@Column(name="data_center_id", updatable=true, nullable=false)
protected long dataCenterIdToDeployIn;
@Column(name="vm_type", updatable=false, nullable=false, length=32)
@Enumerated(value=EnumType.STRING)
protected Type type;
@Column(name="ha_enabled", updatable=true, nullable=true)
protected boolean haEnabled;
@Column(name="limit_cpu_use", updatable=true, nullable=true)
private boolean limitCpuUse;
@Column(name="update_count", updatable = true, nullable=false)
protected long updated; // This field should be updated everytime the state is updated. There's no set method in the vo object because it is done with in the dao code.
@Column(name=GenericDao.CREATED_COLUMN)
protected Date created;
@Column(name=GenericDao.REMOVED_COLUMN)
protected Date removed;
@Column(name="update_time", updatable=true)
@Temporal(value=TemporalType.TIMESTAMP)
protected Date updateTime;
@Column(name="domain_id")
protected long domainId;
@Column(name="account_id")
protected long accountId;
@Column(name="service_offering_id")
protected long serviceOfferingId;
@Column(name="reservation_id")
protected String reservationId;
@Column(name="hypervisor_type")
@Enumerated(value=EnumType.STRING)
protected HypervisorType hypervisorType;
@Column(name="ram")
protected long ram;
@Column(name="cpu")
protected int cpu;
@Column(name="tags")
protected String tags;
@Transient
Map<String, String> details;
@Column(name="uuid")
protected String uuid = UUID.randomUUID().toString();
//orchestration columns
@Column(name="owner")
private String owner = null;
@Column(name="speed")
private int speed;
@Transient
List<String> computeTags;
@Transient
List<String> rootDiskTags;
@Column(name="hostname")
private String hostname = null;
@Column(name="displayname")
private String displayname = null;
@Transient
List<String> networkIds;
public VMEntityVO(long id,
long serviceOfferingId,
String name,
String instanceName,
Type type,
Long vmTemplateId,
HypervisorType hypervisorType,
long guestOSId,
long domainId,
long accountId,
boolean haEnabled) {
this.id = id;
this.hostName = name != null ? name : this.uuid;
if (vmTemplateId != null) {
this.templateId = vmTemplateId;
}
this.instanceName = instanceName;
this.type = type;
this.guestOSId = guestOSId;
this.haEnabled = haEnabled;
this.vncPassword = Long.toHexString(new Random().nextLong());
this.state = State.Stopped;
this.accountId = accountId;
this.domainId = domainId;
this.serviceOfferingId = serviceOfferingId;
this.hypervisorType = hypervisorType;
this.limitCpuUse = false;
}
public VMEntityVO(long id,
long serviceOfferingId,
String name,
String instanceName,
Type type,
Long vmTemplateId,
HypervisorType hypervisorType,
long guestOSId,
long domainId,
long accountId,
boolean haEnabled,
boolean limitResourceUse) {
this(id, serviceOfferingId, name, instanceName, type, vmTemplateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
this.limitCpuUse = limitResourceUse;
}
protected VMEntityVO() {
}
public Date getRemoved() {
return removed;
}
@Override
public long getDomainId() {
return domainId;
}
@Override
public long getAccountId() {
return accountId;
}
@Override
public Type getType() {
return type;
}
public long getUpdated() {
return updated;
}
@Override
public long getId() {
return id;
}
@Override
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
@Override
public HypervisorType getHypervisorType() {
return hypervisorType;
}
@Override
public Date getCreated() {
return created;
}
public Date getUpdateTime() {
return updateTime;
}
@Override
public long getDataCenterIdToDeployIn() {
return dataCenterIdToDeployIn;
}
@Override
public String getHostName() {
return hostName;
}
@Override
public String getInstanceName() {
return instanceName;
}
@Override
public State getState() {
return state;
}
// don't use this directly, use VM state machine instead, this method is added for migration tool only
@Override
public void setState(State state) {
this.state = state;
}
@Override
public String getPrivateIpAddress() {
return privateIpAddress;
}
public void setPrivateIpAddress(String address) {
privateIpAddress = address;
}
public void setVncPassword(String vncPassword) {
this.vncPassword = vncPassword;
}
@Override
public String getVncPassword() {
return vncPassword;
}
@Override
public long getServiceOfferingId() {
return serviceOfferingId;
}
public Long getProxyId() {
return proxyId;
}
public void setProxyId(Long proxyId) {
this.proxyId = proxyId;
}
public Date getProxyAssignTime() {
return this.proxyAssignTime;
}
public void setProxyAssignTime(Date time) {
this.proxyAssignTime = time;
}
@Override
public long getTemplateId() {
if (templateId == null) {
return -1;
} else {
return templateId;
}
}
public void setTemplateId(Long templateId) {
this.templateId = templateId;
}
@Override
public long getGuestOSId() {
return guestOSId;
}
public void setGuestOSId(long guestOSId) {
this.guestOSId = guestOSId;
}
public void incrUpdated() {
updated++;
}
public void decrUpdated() {
updated--;
}
@Override
public Long getHostId() {
return hostId;
}
@Override
public Long getLastHostId() {
return lastHostId;
}
public void setLastHostId(Long lastHostId) {
this.lastHostId = lastHostId;
}
public void setHostId(Long hostId) {
this.hostId = hostId;
}
@Override
public boolean isHaEnabled() {
return haEnabled;
}
@Override
public boolean limitCpuUse() {
return limitCpuUse;
}
public void setLimitCpuUse(boolean value) {
limitCpuUse = value;
}
@Override
public String getPrivateMacAddress() {
return privateMacAddress;
}
@Override
public Long getPodIdToDeployIn() {
return podIdToDeployIn;
}
public void setPodId(long podId) {
this.podIdToDeployIn = podId;
}
public void setPrivateMacAddress(String privateMacAddress) {
this.privateMacAddress = privateMacAddress;
}
public void setDataCenterId(long dataCenterId) {
this.dataCenterIdToDeployIn = dataCenterId;
}
public boolean isRemoved() {
return removed != null;
}
public void setHaEnabled(boolean value) {
haEnabled = value;
}
public void setReservationId(String reservationId) {
this.reservationId = reservationId;
}
public String getReservationId() {
return this.reservationId;
}
@Override
public Map<String, String> getDetails() {
return details;
}
public void setDetail(String name, String value) {
assert (details != null) : "Did you forget to load the details?";
details.put(name, value);
}
public void setDetails(Map<String, String> details) {
this.details = details;
}
transient String toString;
@Override
public String toString() {
if (toString == null) {
toString = new StringBuilder("VM[").append(type.toString()).append("|").append(hostName).append("]").toString();
}
return toString;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VMEntityVO other = (VMEntityVO) obj;
if (id != other.id)
return false;
return true;
}
public void setServiceOfferingId(long serviceOfferingId) {
this.serviceOfferingId = serviceOfferingId;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public List<String> getComputeTags() {
return computeTags;
}
public void setComputeTags(List<String> computeTags) {
this.computeTags = computeTags;
}
public List<String> getRootDiskTags() {
return rootDiskTags;
}
public void setRootDiskTags(List<String> rootDiskTags) {
this.rootDiskTags = rootDiskTags;
}
public String getHostname() {
return hostname;
}
public void setHostname(String hostname) {
this.hostname = hostname;
}
public String getDisplayname() {
return displayname;
}
public void setDisplayname(String displayname) {
this.displayname = displayname;
}
public List<String> getNetworkIds() {
return networkIds;
}
public void setNetworkIds(List<String> networkIds) {
this.networkIds = networkIds;
}
}

View File

@ -19,23 +19,57 @@
package org.apache.cloudstack.platform.orchestration; package org.apache.cloudstack.platform.orchestration;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.inject.Inject;
import org.apache.cloudstack.engine.cloud.entity.api.NetworkEntity; 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.TemplateEntity;
import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity; import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity;
import org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl;
import org.apache.cloudstack.engine.cloud.entity.api.VMEntityManager;
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
import org.apache.cloudstack.engine.service.api.OrchestrationService; import org.apache.cloudstack.engine.service.api.OrchestrationService;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
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.utils.Pair;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.VMInstanceDao;
public class CloudOrchestrator implements OrchestrationService { public class CloudOrchestrator implements OrchestrationService {
@Inject
private VMEntityManager vmEntityManager;
@Inject
private VirtualMachineManager _itMgr;
@Inject
protected VMTemplateDao _templateDao = null;
@Inject
protected VMInstanceDao _vmDao;
@Inject
protected ServiceOfferingDao _serviceOfferingDao;
@Inject
protected DiskOfferingDao _diskOfferingDao = null;
public VirtualMachineEntity createFromScratch(String uuid, String iso, String os, String hypervisor, String hostName, int cpu, int speed, long memory, List<String> networks, List<String> computeTags, public VirtualMachineEntity createFromScratch(String uuid, String iso, String os, String hypervisor, String hostName, int cpu, int speed, long memory, List<String> networks, List<String> computeTags,
Map<String, String> details, String owner) { Map<String, String> details, String owner) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -96,21 +130,99 @@ public class CloudOrchestrator implements OrchestrationService {
String owner, String owner,
String templateId, String templateId,
String hostName, String hostName,
String displayName, String displayName,
String hypervisor,
int cpu, int cpu,
int speed, int speed,
long memory, long memory,
Long diskSize,
List<String> computeTags, List<String> computeTags,
List<String> rootDiskTags, List<String> rootDiskTags,
List<String> networks) { List<String> networks, DeploymentPlan plan) throws InsufficientCapacityException {
return null;
VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager);
HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
//load vm instance and offerings and call virtualMachineManagerImpl
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<DiskOfferingVO, Long> rootDiskOffering = new Pair<DiskOfferingVO, Long>(null, null);
List<Pair<DiskOfferingVO, Long>> dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO, Long>>();
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());
}
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, null, null, plan, hypervisorType, null) == null) {
return null;
}
return vmEntity;
} }
@Override @Override
public VirtualMachineEntity createVirtualMachineFromScratch(String id, String owner, String isoId, String hostName, String displayName, String hypervisor, String os, int cpu, int speed, long memory, public VirtualMachineEntity createVirtualMachineFromScratch(String id, String owner, String isoId, String hostName, String displayName, String hypervisor, String os, int cpu, int speed, long memory,Long diskSize,
List<String> computeTags, List<String> rootDiskTags, List<String> networks) { List<String> computeTags, List<String> rootDiskTags, List<String> networks, DeploymentPlan plan) throws InsufficientCapacityException {
// TODO Auto-generated method stub
return null; VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager);
//load vm instance and offerings and call virtualMachineManagerImpl
VMInstanceVO vm = _vmDao.findByUUID(id);
Pair<DiskOfferingVO, Long> rootDiskOffering = new Pair<DiskOfferingVO, Long>(null, null);
ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
rootDiskOffering.first(offering);
List<Pair<DiskOfferingVO, Long>> dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO, Long>>();
Long diskOfferingId = vm.getDiskOfferingId();
if (diskOfferingId == null) {
throw new InvalidParameterValueException(
"Installing from ISO requires a disk offering to be specified for the root disk.");
}
DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
if (diskOffering == null) {
throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
}
Long size = null;
if (diskOffering.getDiskSize() == 0) {
size = diskSize;
if (size == null) {
throw new InvalidParameterValueException("Disk offering "
+ diskOffering + " requires size parameter.");
}
}
rootDiskOffering.first(diskOffering);
rootDiskOffering.second(size);
HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
if (_itMgr.allocate(vm, _templateDao.findById(new Long(isoId)), offering, rootDiskOffering, dataDiskOfferings, null, null, plan, hypervisorType, null) == null) {
return null;
}
return vmEntity;
} }
@Override @Override

View File

@ -70,6 +70,11 @@
<classifier>tests</classifier> <classifier>tests</classifier>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-engine-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

File diff suppressed because it is too large Load Diff

View File

@ -107,5 +107,7 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
* @return * @return
*/ */
List<String> listDistinctHostNames(long networkId, VirtualMachine.Type... types); List<String> listDistinctHostNames(long networkId, VirtualMachine.Type... types);
VMInstanceVO findByUUID(String uuid);
} }

View File

@ -609,4 +609,10 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
txn.commit(); txn.commit();
return result; return result;
} }
@Override
public VMInstanceVO findByUUID(String uuid) {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -42,3 +42,25 @@ CREATE TABLE `cloud`.`image_data_store` (
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
CONSTRAINT `fk_tags__image_data_store_provider_id` FOREIGN KEY(`image_provider_id`) REFERENCES `image_data_store_provider`(`id`) CONSTRAINT `fk_tags__image_data_store_provider_id` FOREIGN KEY(`image_provider_id`) REFERENCES `image_data_store_provider`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`vm_compute_tags` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`vm_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'vm id',
`compute_tag` varchar(255) NOT NULL COMMENT 'name of tag',
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`vm_root_disk_tags` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`vm_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'vm id',
`root_disk_tag` varchar(255) NOT NULL COMMENT 'name of tag',
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`vm_network_map` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`vm_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'vm id',
`network_id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'network id',
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;