allocation complete. Moving on to actual create and deploy

This commit is contained in:
Alex Huang 2010-09-16 12:01:40 -07:00
parent 54bd0c71a2
commit 131e487c32
14 changed files with 90 additions and 91 deletions

View File

@ -42,6 +42,8 @@ public interface Volume extends PartOf, OwnedBy, BasedOn {
enum SourceType {
Snapshot,DiskOffering,Template,Blank
}
long getId();
/**
* @return the volume name
*/

View File

@ -17,6 +17,7 @@
*/
package com.cloud.vm;
import com.cloud.offering.DiskOffering;
import com.cloud.storage.Volume;
/**
@ -35,6 +36,8 @@ public class DiskProfile {
private long diskOfferingId;
private Long templateId;
private long volumeId;
private Volume vol;
private DiskOffering offering;
protected DiskProfile() {
}
@ -50,7 +53,13 @@ public class DiskProfile {
this.templateId = templateId;
this.volumeId = volumeId;
}
public DiskProfile(Volume vol, DiskOffering offering) {
this(vol.getId(), vol.getVolumeType(), vol.getName(), offering.getId(), vol.getSize(), offering.getTagsArray(), offering.getUseLocalStorage(), offering.getUseLocalStorage(), vol.getSize());
this.vol = vol;
this.offering = offering;
}
/**
* @return size of the disk requested in bytes.
*/

View File

@ -33,7 +33,7 @@ public interface Nic extends Resource {
/**
* @return network profile id that this
*/
long getNetworkProfileId();
long getNetworkConfigurationId();
/**
* @return the vm instance id that this nic belongs to.

View File

@ -39,31 +39,10 @@ import com.cloud.user.AccountVO;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Manager;
import com.cloud.utils.exception.ExecutionException;
import com.cloud.vm.DiskProfile;
import com.cloud.vm.VMInstanceVO;
public interface StorageManager extends Manager {
/**
* Convenience method for creating a VM with a data disk based on a template.
* @param vm VM to create disks for.
* @param template Template to based the root disk on.
* @param rootOffering Disk offering for the root disk.
* @param dataOffering Disk offering for the data disk.
* @param size size of the data disk if the data disk offering has variable size.
* @param dc data center to deploy in.
* @param account owner.
* @return List<VolumeVO> where the first disk is the root disk.
*/
List<VolumeVO> allocateTemplatedVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, DiskOfferingVO dataOffering, Long size, DataCenterVO dc, AccountVO account);
/**
* Convenience method for allocating system VMs in the database.
* @param vm VM to create disks for.
* @param template template the root disk should be based on.
* @param rootOffering Disk offering for the root disk.
* @param dc data center to deploy in.
* @return VolumeVO volume allocated.
*/
VolumeVO allocateSystemVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, DataCenterVO dc);
VolumeVO allocateIsoInstalledVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, Long size, DataCenterVO dc, AccountVO account);
@ -328,7 +307,8 @@ public interface StorageManager extends Manager {
* @param account
* @return VolumeVO a persisted volume.
*/
<T extends VMInstanceVO> VolumeVO allocate(VolumeType type, DiskOfferingVO offering, String name, Long size, VMTemplateVO template, T vm, AccountVO account);
<T extends VMInstanceVO> DiskProfile allocateRawVolume(VolumeType type, String name, DiskOfferingVO offering, Long size, T vm, AccountVO owner);
<T extends VMInstanceVO> DiskProfile allocateTemplatedVolume(VolumeType type, String name, DiskOfferingVO offering, VMTemplateVO template, T vm, AccountVO owner);
<T extends VMInstanceVO> void create(T vm);
Long findHostIdForStoragePool(StoragePoolVO pool);

View File

@ -553,5 +553,5 @@ public class VolumeVO implements Volume {
public void setAttached(Date attached){
this.attached = attached;
}
}

View File

@ -1009,7 +1009,6 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
}
}
@DB
protected Map<String, Object> createProxyInstance2(long dataCenterId) {
long id = _consoleProxyDao.getNextInSequence(Long.class, "id");

View File

@ -2413,6 +2413,8 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
Transaction txn = Transaction.currentTxn();
txn.start();
int deviceId = 0;
for (Pair<NetworkConfigurationVO, NicProfile> network : networks) {
for (NetworkConcierge concierge : _networkConcierges) {
NicProfile profile = concierge.allocate(vm, network.first(), network.second());
@ -2420,7 +2422,8 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
continue;
}
NicVO vo = new NicVO(concierge.getUniqueName(), vm.getId(), network.first().getId());
vo.setDeviceId(deviceId++);
vo.setMode(network.first().getMode());
if (profile.getIp4Address() != null) {
vo.setIp4Address(profile.getIp4Address());
vo.setState(NicVO.State.Reserved);

View File

@ -34,7 +34,7 @@ import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachine;
@Local(value=NetworkProfiler.class)
@Local(value={NetworkProfiler.class, NetworkConcierge.class})
public class ControlNetworkProfiler extends AdapterBase implements NetworkProfiler, NetworkConcierge {
private static final Logger s_logger = Logger.getLogger(ControlNetworkProfiler.class);
@Inject DataCenterDao _dcDao;

View File

@ -31,7 +31,7 @@ import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachine;
@Local(value=NetworkProfiler.class)
@Local(value={NetworkProfiler.class, NetworkConcierge.class})
public class PodBasedNetworkProfiler extends AdapterBase implements NetworkProfiler, NetworkConcierge {
private static final Logger s_logger = Logger.getLogger(PodBasedNetworkProfiler.class);
@Inject DataCenterDao _dcDao;

View File

@ -26,7 +26,7 @@ import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachine;
@Local(value=NetworkProfiler.class)
@Local(value={NetworkProfiler.class, NetworkConcierge.class})
public class PublicNetworkProfiler extends AdapterBase implements NetworkProfiler, NetworkConcierge {
@Override

View File

@ -89,9 +89,9 @@ import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceInUseException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.Host.Type;
import com.cloud.host.dao.DetailsDao;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor;
@ -256,24 +256,6 @@ public class StorageManagerImpl implements StorageManager {
return vols;
}
@Override
public List<VolumeVO> allocateTemplatedVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, DiskOfferingVO diskOffering, Long size, DataCenterVO dc, AccountVO account) {
assert (template.getFormat() != ImageFormat.ISO) : "You can't create user vm based on ISO with this format";
DiskProfile rootDisk = null;
List<DiskProfile> dataDisks = new ArrayList<DiskProfile>(diskOffering != null ? 1 : 0);
long rootId = _volsDao.getNextInSequence(Long.class, "volume_seq");
rootDisk = new DiskProfile(rootId, VolumeType.ROOT, "ROOT-" + vm.getId() + " rootId", rootOffering.getId(), 0, rootOffering.getTagsArray(), rootOffering.getUseLocalStorage(), rootOffering.isRecreatable(), template.getId());
if (diskOffering != null) {
long dataId = _volsDao.getNextInSequence(Long.class, "volume_seq");
dataDisks.add(new DiskProfile(dataId, VolumeType.DATADISK, "DATA-" + vm.getId() + "-" + dataId, diskOffering.getId(), size != null ? size : diskOffering.getDiskSizeInBytes(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null));
}
return allocate(rootDisk, dataDisks, vm, dc, account);
}
@Override
public VolumeVO allocateIsoInstalledVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, Long size, DataCenterVO dc, AccountVO account) {
assert (template.getFormat() == ImageFormat.ISO) : "The template has to be ISO";
@ -285,12 +267,6 @@ public class StorageManagerImpl implements StorageManager {
}
@Override
public VolumeVO allocateSystemVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, DataCenterVO dc) {
List<VolumeVO> vols = allocateTemplatedVm(vm, template, rootOffering, null, null, dc, _accountMgr.getSystemAccount());
return vols.get(0);
}
@Override
public List<VolumeVO> prepare(VMInstanceVO vm, HostVO host) {
List<VolumeVO> vols = _volsDao.findCreatedByInstance(vm.getId());
@ -2292,19 +2268,49 @@ public class StorageManagerImpl implements StorageManager {
}
}
protected DiskProfile toDiskProfile(VolumeVO vol, DiskOfferingVO offering) {
return new DiskProfile(vol.getId(), vol.getVolumeType(), vol.getName(), offering.getId(), vol.getSize(), offering.getTagsArray(), offering.getUseLocalStorage(), offering.isRecreatable(), vol.getTemplateId());
}
@Override
public <T extends VMInstanceVO> VolumeVO allocate(VolumeType type, DiskOfferingVO offering, String name, Long size, VMTemplateVO template, T vm, AccountVO account) {
VolumeVO vol = new VolumeVO(VolumeType.ROOT, name, vm.getDataCenterId(), account.getDomainId(), account.getId(), offering.getId(), size);
public <T extends VMInstanceVO> DiskProfile allocateRawVolume(VolumeType type, String name, DiskOfferingVO offering, Long size, T vm, AccountVO owner) {
if (size == null) {
size = offering.getDiskSizeInBytes();
}
VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), size);
if (vm != null) {
vol.setInstanceId(vm.getId());
}
if (template != null && template.getFormat() != ImageFormat.ISO) {
vol.setTemplateId(template.getId());
}
vol = _volsDao.persist(vol);
return vol;
return toDiskProfile(vol, offering);
}
@Override
public <T extends VMInstanceVO> DiskProfile allocateTemplatedVolume(VolumeType type, String name, DiskOfferingVO offering, VMTemplateVO template, T vm, AccountVO owner) {
assert (template.getFormat() != ImageFormat.ISO) : "ISO is not a template really....";
SearchCriteria<VMTemplateHostVO> sc = HostTemplateStatesSearch.create();
sc.setParameters("id", template.getId());
sc.setParameters("state", com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
sc.setJoinParameters("host", "dcId", vm.getDataCenterId());
List<VMTemplateHostVO> sss = _vmTemplateHostDao.search(sc, null);
if (sss.size() == 0) {
throw new CloudRuntimeException("Template " + template.getName() + " has not been completely downloaded to zone " + vm.getDataCenterId());
}
VMTemplateHostVO ss = sss.get(0);
VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), ss.getSize());
if (vm != null) {
vol.setInstanceId(vm.getId());
}
vol.setTemplateId(template.getId());
vol = _volsDao.persist(vol);
return toDiskProfile(vol, offering);
}
final protected DiskProfile createDiskCharacteristics(VolumeVO volume, DiskOfferingVO offering) {

View File

@ -45,7 +45,6 @@ import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageManager;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Volume.VolumeType;
import com.cloud.storage.VolumeVO;
import com.cloud.user.AccountVO;
import com.cloud.utils.Journal;
import com.cloud.utils.NumbersUtil;
@ -86,19 +85,31 @@ public class MauriceMoss implements VmManager {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Allocating entries for VM: " + vm);
}
VirtualMachineProfile vmProfile = new VirtualMachineProfile(vm, serviceOffering);
VMInstanceVO instance = _vmDao.findById(vm.getId());
VirtualMachineProfile vmProfile = new VirtualMachineProfile(instance, serviceOffering);
Transaction txn = Transaction.currentTxn();
txn.start();
List<NicProfile> nics = _networkMgr.allocate(vm, networks);
instance.setDataCenterId(plan.getDataCenterId());
_vmDao.update(instance.getId(), instance);
List<NicProfile> nics = _networkMgr.allocate(instance, networks);
vmProfile.setNics(nics);
List<DiskProfile> disks = new ArrayList<DiskProfile>(dataDiskOfferings.size() + 1);
VolumeVO volume = _storageMgr.allocate(VolumeType.ROOT, rootDiskOffering.first(), "ROOT-" + vm.getId(), rootDiskOffering.second(), template.getFormat() != ImageFormat.ISO ? template : null, vm, owner);
for (Pair<DiskOfferingVO, Long> offering : dataDiskOfferings) {
volume = _storageMgr.allocate(VolumeType.DATADISK, offering.first(), "DATA-" + vm.getId(), offering.second(), null, vm, owner);
if (dataDiskOfferings == null) {
dataDiskOfferings = new ArrayList<Pair<DiskOfferingVO, Long>>(0);
}
List<DiskProfile> disks = new ArrayList<DiskProfile>(dataDiskOfferings.size() + 1);
if (template.getFormat() == ImageFormat.ISO) {
disks.add(_storageMgr.allocateRawVolume(VolumeType.ROOT, "ROOT-" + vm.getId(), rootDiskOffering.first(), rootDiskOffering.second(), instance, owner));
} else {
disks.add(_storageMgr.allocateTemplatedVolume(VolumeType.ROOT, "ROOT-" + vm.getId(), rootDiskOffering.first(), template, instance, owner));
}
for (Pair<DiskOfferingVO, Long> offering : dataDiskOfferings) {
disks.add(_storageMgr.allocateRawVolume(VolumeType.DATADISK, "DATA-" + vm.getId(), offering.first(), offering.second(), instance, owner));
}
vmProfile.setDisks(disks);
txn.commit();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Allocation completed for VM: " + vm);
@ -118,7 +129,7 @@ public class MauriceMoss implements VmManager {
return vmProfile;
}
@Override
public <T extends VMInstanceVO> VirtualMachineProfile allocate(T vm,
VMTemplateVO template,

View File

@ -29,7 +29,6 @@ import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.network.Network.Mode;
import com.cloud.network.Network.TrafficType;
@Entity
@Table(name="nics")
@ -45,34 +44,24 @@ public class NicVO implements Nic {
@Column(name="instance_id")
long instanceId;
@Column(name="type")
@Enumerated(value=EnumType.STRING)
TrafficType trafficType;
@Column(name="ip4_address")
String ip4Address;
@Column(name="mac_address")
String macAddress;
@Column(name="netmask")
String netMask;
@Column(name="mode")
@Enumerated(value=EnumType.STRING)
Mode mode;
@Column(name="network_profile_id")
long networkProfileId;
@Column(name="String")
String vlan;
@Column(name="network_configuration_id")
long networkConfigurationId;
@Column(name="state")
@Enumerated(value=EnumType.STRING)
State state;
@Column(name="name")
@Column(name="reserver_name")
String reserver;
@Column(name="reservation_id")
@ -84,10 +73,10 @@ public class NicVO implements Nic {
@Column(name="update_time")
Date updateTime;
public NicVO(String reserver, long instanceId, long profileId) {
public NicVO(String reserver, long instanceId, long configurationId) {
this.reserver = reserver;
this.instanceId = instanceId;
this.networkProfileId = profileId;
this.networkConfigurationId = configurationId;
this.state = State.Allocated;
}
@ -129,8 +118,8 @@ public class NicVO implements Nic {
}
@Override
public long getNetworkProfileId() {
return networkProfileId;
public long getNetworkConfigurationId() {
return networkConfigurationId;
}
@Override

View File

@ -116,10 +116,10 @@ CREATE TABLE `cloud`.`nics` (
`instance_id` bigint unsigned NOT NULL COMMENT 'vm instance id',
`ip4_address` varchar(15) COMMENT 'ip4 address',
`mac_address` varchar(17) COMMENT 'mac address',
`network_configuration_id` bigint unsigned NOT NULL COMMENT 'network configuration id',
`vlan` varchar(64) COMMENT 'Virtualized network identifier',
`network_configuration_id` bigint unsigned NOT NULL COMMENT 'network configuration id',
`mode` varchar(32) COMMENT 'mode of getting ip address',
`state` varchar(32) NOT NULL COMMENT 'state of the creation',
`name` varchar(64) COMMENT 'Name of the component that reserved the ip address',
`reserver_name` varchar(255) COMMENT 'Name of the component that reserved the ip address',
`reservation_id` varchar(64) COMMENT 'id for the reservation',
`device_id` int(10) COMMENT 'device id for the network when plugged into the virtual machine',
`update_time` timestamp NOT NULL COMMENT 'time the state was changed',