From a89aad4d15541e841fba2dde19e4bcd1f720c254 Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Tue, 17 Aug 2010 10:16:16 -0700 Subject: [PATCH] removed override --- api/src/com/cloud/vm/DiskCharacteristics.java | 11 +++- build/build.number | 4 +- build/override/build-cloud.properties | 19 ------ build/override/replace.properties | 7 --- .../src/com/cloud/storage/StorageManager.java | 27 +++++++++ core/src/com/cloud/storage/VolumeVO.java | 15 +++-- .../com/cloud/storage/StorageManagerImpl.java | 52 ++++++++++++---- server/src/com/cloud/user/AccountManager.java | 2 + .../com/cloud/user/AccountManagerImpl.java | 60 +++++++------------ server/src/com/cloud/vm/MauriceMoss.java | 18 +++++- server/src/com/cloud/vm/VmManager.java | 6 +- setup/db/create-schema.sql | 1 + 12 files changed, 131 insertions(+), 91 deletions(-) delete mode 100755 build/override/build-cloud.properties delete mode 100644 build/override/replace.properties diff --git a/api/src/com/cloud/vm/DiskCharacteristics.java b/api/src/com/cloud/vm/DiskCharacteristics.java index b281c661b14..acb30d14bef 100644 --- a/api/src/com/cloud/vm/DiskCharacteristics.java +++ b/api/src/com/cloud/vm/DiskCharacteristics.java @@ -34,11 +34,12 @@ public class DiskCharacteristics { private boolean recreatable; private long diskOfferingId; private Long templateId; + private long volumeId; protected DiskCharacteristics() { } - public DiskCharacteristics(Volume.VolumeType type, String name, long diskOfferingId, long size, String[] tags, boolean useLocalStorage, boolean recreatable, Long templateId) { + public DiskCharacteristics(long volumeId, Volume.VolumeType type, String name, long diskOfferingId, long size, String[] tags, boolean useLocalStorage, boolean recreatable, Long templateId) { this.type = type; this.name = name; this.size = size; @@ -47,6 +48,7 @@ public class DiskCharacteristics { this.recreatable = recreatable; this.diskOfferingId = diskOfferingId; this.templateId = templateId; + this.volumeId = volumeId; } /** @@ -56,6 +58,13 @@ public class DiskCharacteristics { return size; } + /** + * @return id of the volume backing up this disk characteristics + */ + public long getVolumeId() { + return volumeId; + } + /** * @return Unique name for the disk. */ diff --git a/build/build.number b/build/build.number index e130ae9cdbf..6360d93adb4 100644 --- a/build/build.number +++ b/build/build.number @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Mon Aug 16 11:01:21 PDT 2010 -build.number=31 +#Mon Aug 16 18:14:16 PDT 2010 +build.number=32 diff --git a/build/override/build-cloud.properties b/build/override/build-cloud.properties deleted file mode 100755 index fbceda3fcaa..00000000000 --- a/build/override/build-cloud.properties +++ /dev/null @@ -1,19 +0,0 @@ -# This is a template file for defining properties needed by build-vmops.xml. -# If you need to add properties to be used in build-vmops.xml, then you should -# add it in this file. If all you need is to change the default values, -# you should "cp build-vmops.properties.template build-vmops.properties" -# and modify the values within build-vmops.properties. - -debug=true -debuglevel=vars,lines,source -tomcat.home=/home/tomcat/current -debug.jvmarg=-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n -deprecation=off -meld.home=/usr/bin -target.compat.version=1.6 -source.compat.version=1.6 -assertion=-ea -branding.name=default -build.type=developer -premium.name=premium -#manual.build.number=8 diff --git a/build/override/replace.properties b/build/override/replace.properties deleted file mode 100644 index 2e1bbaab5e2..00000000000 --- a/build/override/replace.properties +++ /dev/null @@ -1,7 +0,0 @@ -DBUSER=cloud -DBROOTPW= -DBPW=cloud -MSLOG=.\/dist\/vmops.log -APISERVERLOG=.\/dist\/api.log -DBHOST=localhost - diff --git a/core/src/com/cloud/storage/StorageManager.java b/core/src/com/cloud/storage/StorageManager.java index 77629924d44..3f699149b7c 100644 --- a/core/src/com/cloud/storage/StorageManager.java +++ b/core/src/com/cloud/storage/StorageManager.java @@ -34,12 +34,39 @@ import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.user.Account; +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.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 where the first disk is the root disk. + */ + List 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); + /** * Calls the storage agent and makes the volumes sharable with this host. * diff --git a/core/src/com/cloud/storage/VolumeVO.java b/core/src/com/cloud/storage/VolumeVO.java index fe0c6ce0e02..812b6509687 100755 --- a/core/src/com/cloud/storage/VolumeVO.java +++ b/core/src/com/cloud/storage/VolumeVO.java @@ -27,6 +27,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; +import javax.persistence.TableGenerator; import javax.persistence.Temporal; import javax.persistence.TemporalType; @@ -39,9 +40,10 @@ import com.google.gson.annotations.Expose; @Table(name="volumes") public class VolumeVO implements Volume { @Id - @GeneratedValue(strategy=GenerationType.IDENTITY) + @TableGenerator(name="volume_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="volume_seq", allocationSize=1) + @GeneratedValue(strategy=GenerationType.SEQUENCE) @Column(name="id") - Long id; + long id; @Expose @Column(name="name") @@ -176,7 +178,8 @@ public class VolumeVO implements Volume { } // Real Constructor - public VolumeVO(VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) { + public VolumeVO(long id, VolumeType type, String name, long dcId, long domainId, long accountId, long diskOfferingId, long size) { + this.id = id; this.volumeType = type; this.name = name; this.dataCenterId = dcId; @@ -233,7 +236,7 @@ public class VolumeVO implements Volume { return iscsiName; } - public Long getId() { + public long getId() { return id; } @@ -310,10 +313,6 @@ public class VolumeVO implements Volume { return volumeType; } - public void setId(Long id) { - this.id = id; - } - public void setName(String name) { this.name = name; } diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index f13c6b30699..339ba196377 100644 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -225,11 +225,6 @@ public class StorageManagerImpl implements StorageManager { return true; } - protected void setDeviceId(VolumeVO vol) { - //TODO: Need to figure out what to do here. - vol.setDeviceId(1l); - } - @DB public List allocate(DiskCharacteristics rootDisk, List dataDisks, VMInstanceVO vm, DataCenterVO dc, AccountVO account) { ArrayList vols = new ArrayList(dataDisks.size() + 1); @@ -238,7 +233,7 @@ public class StorageManagerImpl implements StorageManager { long deviceId = 0; Transaction txn = Transaction.currentTxn(); txn.start(); - rootVol = new VolumeVO(VolumeType.ROOT, rootDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), rootDisk.getDiskOfferingId(), rootDisk.getSize()); + rootVol = new VolumeVO(rootDisk.getVolumeId(), VolumeType.ROOT, rootDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), rootDisk.getDiskOfferingId(), rootDisk.getSize()); if (rootDisk.getTemplateId() != null) { rootVol.setTemplateId(rootDisk.getTemplateId()); } @@ -247,10 +242,10 @@ public class StorageManagerImpl implements StorageManager { rootVol = _volsDao.persist(rootVol); vols.add(rootVol); for (DiskCharacteristics dataDisk : dataDisks) { - dataVol = new VolumeVO(VolumeType.DATADISK, dataDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), dataDisk.getDiskOfferingId(), dataDisk.getSize()); + dataVol = new VolumeVO(dataDisk.getVolumeId(), VolumeType.DATADISK, dataDisk.getName(), dc.getId(), account.getDomainId(), account.getId(), dataDisk.getDiskOfferingId(), dataDisk.getSize()); dataVol.setDeviceId(deviceId++); - dataVol = _volsDao.persist(dataVol); dataVol.setInstanceId(vm.getId()); + dataVol = _volsDao.persist(dataVol); vols.add(dataVol); } txn.commit(); @@ -258,6 +253,41 @@ public class StorageManagerImpl implements StorageManager { return vols; } + @Override + public List 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"; + + DiskCharacteristics rootDisk = null; + List dataDisks = new ArrayList(diskOffering != null ? 1 : 0); + + long rootId = _volsDao.getNextInSequence(Long.class, "volume_seq"); + + rootDisk = new DiskCharacteristics(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 DiskCharacteristics(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"; + + long rootId = _volsDao.getNextInSequence(Long.class, "volume_seq"); + DiskCharacteristics rootDisk = new DiskCharacteristics(rootId, VolumeType.ROOT, "ROOT-" + vm.getId() + "-" + rootId, rootOffering.getId(), size != null ? size : rootOffering.getDiskSizeInBytes(), rootOffering.getTagsArray(), rootOffering.getUseLocalStorage(), rootOffering.isRecreatable(), null); + List vols = allocate(rootDisk, null, vm, dc, account); + return vols.get(0); + } + + + @Override + public VolumeVO allocateSystemVm(VMInstanceVO vm, VMTemplateVO template, DiskOfferingVO rootOffering, DataCenterVO dc) { + List vols = allocateTemplatedVm(vm, template, rootOffering, null, null, dc, _accountMgr.getSystemAccount()); + return vols.get(0); + } + public List prepare(VMInstanceVO vm, HostVO host) { List vols = _volsDao.findCreatedByInstance(vm.getId()); List recreateVols = new ArrayList(vols.size()); @@ -427,9 +457,9 @@ public class StorageManagerImpl implements StorageManager { } VMTemplateHostVO ss = sss.get(0); - return new DiskCharacteristics(volume.getVolumeType(), volume.getName(), diskOffering.getId(), ss.getSize(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), Storage.ImageFormat.ISO != template.getFormat() ? template.getId() : null); + return new DiskCharacteristics(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), ss.getSize(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), Storage.ImageFormat.ISO != template.getFormat() ? template.getId() : null); } else { - return new DiskCharacteristics(volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSizeInBytes(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null); + return new DiskCharacteristics(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSizeInBytes(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null); } } @@ -1466,7 +1496,7 @@ public class StorageManagerImpl implements StorageManager { public VolumeVO moveVolume(VolumeVO volume, long destPoolDcId, Long destPoolPodId, Long destPoolClusterId) throws InternalErrorException { // Find a destination storage pool with the specified criteria DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); - DiskCharacteristics dskCh = new DiskCharacteristics(volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSizeInBytes(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null); + DiskCharacteristics dskCh = new DiskCharacteristics(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSizeInBytes(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null); DataCenterVO destPoolDataCenter = _dcDao.findById(destPoolDcId); HostPodVO destPoolPod = _podDao.findById(destPoolPodId); StoragePoolVO destPool = findStoragePool(dskCh, destPoolDataCenter, destPoolPod, destPoolClusterId, null, null, null, new HashSet()); diff --git a/server/src/com/cloud/user/AccountManager.java b/server/src/com/cloud/user/AccountManager.java index a30021935ff..c0392d12aad 100644 --- a/server/src/com/cloud/user/AccountManager.java +++ b/server/src/com/cloud/user/AccountManager.java @@ -100,4 +100,6 @@ public interface AccountManager extends Manager { */ public ResourceLimitVO updateResourceLimit(Long domainId, Long accountId, ResourceType type, Long max) throws InvalidParameterValueException; + AccountVO getSystemAccount(); + } diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java index c1ce0c4897f..c7bab1530fa 100644 --- a/server/src/com/cloud/user/AccountManagerImpl.java +++ b/server/src/com/cloud/user/AccountManagerImpl.java @@ -26,8 +26,8 @@ import javax.naming.ConfigurationException; import org.apache.log4j.Logger; -import com.cloud.configuration.ResourceLimitVO; import com.cloud.configuration.ResourceCount.ResourceType; +import com.cloud.configuration.ResourceLimitVO; import com.cloud.configuration.dao.ResourceCountDao; import com.cloud.configuration.dao.ResourceLimitDao; import com.cloud.domain.DomainVO; @@ -36,7 +36,7 @@ import com.cloud.exception.InvalidParameterValueException; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; -import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.component.Inject; import com.cloud.utils.db.Filter; import com.cloud.utils.db.GlobalLock; import com.cloud.utils.db.SearchCriteria; @@ -46,49 +46,24 @@ public class AccountManagerImpl implements AccountManager { public static final Logger s_logger = Logger.getLogger(AccountManagerImpl.class.getName()); private String _name; - private AccountDao _accountDao; - private DomainDao _domainDao; - private UserDao _userDao; - private VMTemplateDao _templateDao; - private ResourceLimitDao _resourceLimitDao; - private ResourceCountDao _resourceCountDao; - private final GlobalLock m_resourceCountLock = GlobalLock.getInternLock("resource.count"); + @Inject private AccountDao _accountDao; + @Inject private DomainDao _domainDao; + @Inject private UserDao _userDao; + @Inject private VMTemplateDao _templateDao; + @Inject private ResourceLimitDao _resourceLimitDao; + @Inject private ResourceCountDao _resourceCountDao; + @Inject private final GlobalLock m_resourceCountLock = GlobalLock.getInternLock("resource.count"); + + AccountVO _systemAccount; @Override public boolean configure(final String name, final Map params) throws ConfigurationException { _name = name; - final ComponentLocator locator = ComponentLocator.getCurrentLocator(); - - _accountDao = locator.getDao(AccountDao.class); - if (_accountDao == null) { - throw new ConfigurationException("Unable to get the account dao."); - } - - _domainDao = locator.getDao(DomainDao.class); - if (_domainDao == null) { - throw new ConfigurationException("Unable to get the domain dao."); - } - - _userDao = locator.getDao(UserDao.class); - if (_userDao == null) { - throw new ConfigurationException("Unable to get the user dao."); - } - - _templateDao = locator.getDao(VMTemplateDao.class); - if (_templateDao == null) { - throw new ConfigurationException("Unable to get the template dao."); - } - - _resourceLimitDao = locator.getDao(ResourceLimitDao.class); - if (_resourceLimitDao == null) { - throw new ConfigurationException("Unable to get " + ResourceLimitDao.class.getName()); - } - - _resourceCountDao = locator.getDao(ResourceCountDao.class); - if (_resourceCountDao == null) { - throw new ConfigurationException("Unable to get " + ResourceCountDao.class.getName()); - } + _systemAccount = _accountDao.findById(AccountVO.ACCOUNT_ID_SYSTEM); + if (_systemAccount == null) { + throw new ConfigurationException("Unable to find the system account using " + AccountVO.ACCOUNT_ID_SYSTEM); + } return true; } @@ -328,5 +303,10 @@ public class AccountManagerImpl implements AccountManager { return _resourceLimitDao.persist(new ResourceLimitVO(domainId, accountId, type, max)); } } + + @Override + public AccountVO getSystemAccount() { + return _systemAccount; + } } diff --git a/server/src/com/cloud/vm/MauriceMoss.java b/server/src/com/cloud/vm/MauriceMoss.java index c3da57fd10b..eafefe160d7 100644 --- a/server/src/com/cloud/vm/MauriceMoss.java +++ b/server/src/com/cloud/vm/MauriceMoss.java @@ -19,16 +19,28 @@ package com.cloud.vm; import java.util.List; +import javax.ejb.Local; + +import com.cloud.dc.DataCenterVO; +import com.cloud.network.NetworkManager; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; +import com.cloud.storage.StorageManager; +import com.cloud.user.AccountVO; +import com.cloud.utils.component.Inject; +@Local(value=VmManager.class) public class MauriceMoss implements VmManager { + @Inject private StorageManager _storageMgr; + @Inject private NetworkManager _networkMgr; @Override - public VMInstanceVO allocate(VMInstanceVO vm, ServiceOfferingVO serviceOffering, NetworkOfferingVO[] networkOfferings, DiskOfferingVO[] diskOffering) { + public VMInstanceVO allocate(VMInstanceVO vm, ServiceOfferingVO serviceOffering, List networkOfferings, List diskOffering, DataCenterVO dc, AccountVO account) { + _storageMgr.allocateTemplatedVm(vm, template, rootOffering, dataOffering, size, dc, account) return null; } + @Override public void create(VmCharacteristics vm, List disks, List networks) { // TODO Auto-generated method stub @@ -51,5 +63,7 @@ public class MauriceMoss implements VmManager { public void stop() { // TODO Auto-generated method stub } - + + protected MauriceMoss() { + } } diff --git a/server/src/com/cloud/vm/VmManager.java b/server/src/com/cloud/vm/VmManager.java index 2da194a7f7c..59cbbe33ad7 100644 --- a/server/src/com/cloud/vm/VmManager.java +++ b/server/src/com/cloud/vm/VmManager.java @@ -19,9 +19,11 @@ package com.cloud.vm; import java.util.List; +import com.cloud.dc.DataCenterVO; import com.cloud.offerings.NetworkOfferingVO; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.DiskOfferingVO; +import com.cloud.user.AccountVO; /** * Manages allocating resources to vms. @@ -31,7 +33,9 @@ public interface VmManager { VMInstanceVO allocate(VMInstanceVO vm, ServiceOfferingVO serviceOffering, NetworkOfferingVO[] networkOfferings, - DiskOfferingVO[] diskOffering); + DiskOfferingVO[] diskOffering, + DataCenterVO dc, + AccountVO account); void create(VmCharacteristics vm, List disks, List networks); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 2bfe94c29bf..8281af4ca75 100644 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -193,6 +193,7 @@ INSERT INTO `cloud`.`sequence` (name, value) VALUES ('vm_template_seq', 200); INSERT INTO `cloud`.`sequence` (name, value) VALUES ('public_mac_address_seq', 1); INSERT INTO `cloud`.`sequence` (name, value) VALUES ('private_mac_address_seq', 1); INSERT INTO `cloud`.`sequence` (name, value) VALUES ('storage_pool_seq', 200); +INSERT INTO `cloud`.`sequence` (name, value) VALUES ('volume_seq', 1); CREATE TABLE `cloud`.`disk_template_ref` ( `id` bigint unsigned NOT NULL auto_increment,