-
Notifications
You must be signed in to change notification settings - Fork 1.3k
upgrade/systemvm: add template zone entries #5642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| // under the License. | ||
| package com.cloud.upgrade; | ||
|
|
||
| import com.cloud.dc.DataCenterVO; | ||
| import com.cloud.dc.dao.ClusterDao; | ||
| import com.cloud.dc.dao.ClusterDaoImpl; | ||
| import com.cloud.dc.dao.DataCenterDao; | ||
|
|
@@ -26,14 +27,18 @@ | |
| import com.cloud.storage.Storage.ImageFormat; | ||
| import com.cloud.storage.VMTemplateStorageResourceAssoc; | ||
| import com.cloud.storage.VMTemplateVO; | ||
| import com.cloud.storage.VMTemplateZoneVO; | ||
| import com.cloud.storage.dao.VMTemplateDao; | ||
| import com.cloud.storage.dao.VMTemplateDaoImpl; | ||
| import com.cloud.storage.dao.VMTemplateZoneDao; | ||
| import com.cloud.storage.dao.VMTemplateZoneDaoImpl; | ||
| import com.cloud.template.VirtualMachineTemplate; | ||
| import com.cloud.upgrade.dao.BasicTemplateDataStoreDaoImpl; | ||
| import com.cloud.user.Account; | ||
| import com.cloud.utils.DateUtil; | ||
| import com.cloud.utils.Pair; | ||
| import com.cloud.utils.UriUtils; | ||
| import com.cloud.utils.db.GenericDaoBase; | ||
| import com.cloud.utils.db.GlobalLock; | ||
| import com.cloud.utils.db.Transaction; | ||
| import com.cloud.utils.db.TransactionCallbackNoReturn; | ||
|
|
@@ -104,6 +109,8 @@ public class SystemVmTemplateRegistration { | |
| @Inject | ||
| VMTemplateDao vmTemplateDao; | ||
| @Inject | ||
| VMTemplateZoneDao vmTemplateZoneDao; | ||
| @Inject | ||
| TemplateDataStoreDao templateDataStoreDao; | ||
| @Inject | ||
| VMInstanceDao vmInstanceDao; | ||
|
|
@@ -117,6 +124,7 @@ public class SystemVmTemplateRegistration { | |
| public SystemVmTemplateRegistration() { | ||
| dataCenterDao = new DataCenterDaoImpl(); | ||
| vmTemplateDao = new VMTemplateDaoImpl(); | ||
| vmTemplateZoneDao = new VMTemplateZoneDaoImpl(); | ||
| templateDataStoreDao = new BasicTemplateDataStoreDaoImpl(); | ||
| vmInstanceDao = new VMInstanceDaoImpl(); | ||
| imageStoreDao = new ImageStoreDaoImpl(); | ||
|
|
@@ -435,7 +443,7 @@ private List<String> fetchAllHypervisors(Long zoneId) { | |
| return hypervisorList; | ||
| } | ||
|
|
||
| private Long createTemplateObjectInDB(SystemVMTemplateDetails details) { | ||
| private VMTemplateVO createTemplateObjectInDB(SystemVMTemplateDetails details) { | ||
| Long templateId = vmTemplateDao.getNextInSequence(Long.class, "id"); | ||
| VMTemplateVO template = new VMTemplateVO(); | ||
| template.setUuid(details.getUuid()); | ||
|
|
@@ -458,10 +466,31 @@ private Long createTemplateObjectInDB(SystemVMTemplateDetails details) { | |
| template.setState(VirtualMachineTemplate.State.Inactive); | ||
| template.setDeployAsIs(Hypervisor.HypervisorType.VMware.equals(details.getHypervisorType())); | ||
| template = vmTemplateDao.persist(template); | ||
| if (template == null) { | ||
| return null; | ||
| return template; | ||
| } | ||
|
|
||
| private VMTemplateZoneVO createOrUpdateTemplateZoneEntry(long zoneId, long templateId) { | ||
| VMTemplateZoneVO templateZoneVO = vmTemplateZoneDao.findByZoneTemplate(zoneId, templateId); | ||
| if (templateZoneVO == null) { | ||
| templateZoneVO = new VMTemplateZoneVO(zoneId, templateId, new java.util.Date()); | ||
| templateZoneVO = vmTemplateZoneDao.persist(templateZoneVO); | ||
| } else { | ||
| templateZoneVO.setLastUpdated(new java.util.Date()); | ||
| if (vmTemplateZoneDao.update(templateZoneVO.getId(), templateZoneVO)) { | ||
| templateZoneVO = null; | ||
| } | ||
| } | ||
| return templateZoneVO; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this returned templateZoneVO is unused, and only being validated for null. I think, it is better through the exception when the update fails.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think it affects functionality
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
correct, doesn't affect functionality. it's about the implementation. returning VMTemplateZoneVO is not required in this method. |
||
| } | ||
|
|
||
| private void createCrossZonesTemplateZoneRefEntries(VMTemplateVO template) { | ||
| List<DataCenterVO> dcs = dataCenterDao.listAll(); | ||
sureshanaparti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for (DataCenterVO dc : dcs) { | ||
| VMTemplateZoneVO templateZoneVO = createOrUpdateTemplateZoneEntry(dc.getId(), template.getId()); | ||
| if (templateZoneVO == null) { | ||
| throw new CloudRuntimeException(String.format("Failed to create template_zone_ref record for the systemVM template for hypervisor: %s and zone: %s", template.getHypervisorType().name(), dc)); | ||
| } | ||
| } | ||
| return template.getId(); | ||
| } | ||
|
|
||
| private void createTemplateStoreRefEntry(SystemVMTemplateDetails details) { | ||
|
|
@@ -585,10 +614,12 @@ private Long performTemplateRegistrationOperations(Pair<Hypervisor.HypervisorTyp | |
| SystemVMTemplateDetails details = new SystemVMTemplateDetails(templateName, hypervisorAndTemplateName.second(), created, | ||
| url, checksum, format, (int) guestOsId, hypervisor, storeId); | ||
| if (templateId == null) { | ||
| templateId = createTemplateObjectInDB(details); | ||
| } | ||
| if (templateId == null) { | ||
| throw new CloudRuntimeException(String.format("Failed to register template for hypervisor: %s", hypervisor.name())); | ||
| VMTemplateVO template = createTemplateObjectInDB(details); | ||
| if (template == null) { | ||
| throw new CloudRuntimeException(String.format("Failed to register template for hypervisor: %s", hypervisor.name())); | ||
| } | ||
| templateId = template.getId(); | ||
| createCrossZonesTemplateZoneRefEntries(template); | ||
| } | ||
| details.setId(templateId); | ||
| String destTempFolderName = String.valueOf(templateId); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.