-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Prevent downloading templates to secondary storages that are in read-only
#13023
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
base: 4.20
Are you sure you want to change the base?
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,7 @@ | |||||||||||||||||
| import org.apache.cloudstack.storage.command.DeleteCommand; | ||||||||||||||||||
| import org.apache.cloudstack.storage.datastore.DataObjectManager; | ||||||||||||||||||
| import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager; | ||||||||||||||||||
| import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; | ||||||||||||||||||
| import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; | ||||||||||||||||||
| import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; | ||||||||||||||||||
| import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; | ||||||||||||||||||
|
|
@@ -163,6 +164,8 @@ public class TemplateServiceImpl implements TemplateService { | |||||||||||||||||
| TemplateDataFactory imageFactory; | ||||||||||||||||||
| @Inject | ||||||||||||||||||
| StorageOrchestrationService storageOrchestrator; | ||||||||||||||||||
| @Inject | ||||||||||||||||||
| ImageStoreDao dataStoreDao; | ||||||||||||||||||
|
|
||||||||||||||||||
| class TemplateOpContext<T> extends AsyncRpcContext<T> { | ||||||||||||||||||
| final TemplateObject template; | ||||||||||||||||||
|
|
@@ -295,10 +298,16 @@ public void handleSysTemplateDownload(HypervisorType hostHyper, Long dcId) { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| protected boolean shouldDownloadTemplateToStore(VMTemplateVO template, DataStore store) { | ||||||||||||||||||
| if (dataStoreDao.findById(store.getId()).isReadonly()) { | ||||||||||||||||||
|
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.
Suggested change
npe for removed image store, can check store exists before isReadonly() |
||||||||||||||||||
| logger.debug("Template [{}] will not be downloaded to image store [{}] because this store is marked as read-only.", template.getUniqueName(), | ||||||||||||||||||
| store.getName()); | ||||||||||||||||||
| return false; | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
300
to
+305
|
||||||||||||||||||
|
|
||||||||||||||||||
| Long zoneId = store.getScope().getScopeId(); | ||||||||||||||||||
| DataStore directedStore = _tmpltMgr.verifyHeuristicRulesForZone(template, zoneId); | ||||||||||||||||||
| if (directedStore != null && store.getId() != directedStore.getId()) { | ||||||||||||||||||
| logger.info("Template [{}] will not be download to image store [{}], as a heuristic rule is directing it to another store.", | ||||||||||||||||||
| logger.info("Template [{}] will not be downloaded to image store [{}], as a heuristic rule is directing it to another store.", | ||||||||||||||||||
| template.getUniqueName(), store.getName()); | ||||||||||||||||||
| return false; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |||||
| import org.apache.cloudstack.storage.command.CommandResult; | ||||||
| import org.apache.cloudstack.storage.command.CopyCommand; | ||||||
| import org.apache.cloudstack.storage.command.DeleteCommand; | ||||||
| import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; | ||||||
| import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; | ||||||
| import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; | ||||||
| import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; | ||||||
|
|
@@ -126,6 +127,8 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { | |||||
| AgentManager agentMgr; | ||||||
| @Inject | ||||||
| DataStoreManager dataStoreManager; | ||||||
| @Inject | ||||||
| ImageStoreDao dataStoreDao; | ||||||
|
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.
Suggested change
|
||||||
|
|
||||||
| protected String _proxy = null; | ||||||
|
|
||||||
|
|
@@ -175,10 +178,13 @@ public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCal | |||||
| AsyncCallbackDispatcher<BaseImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher.create(this); | ||||||
| caller.setContext(context); | ||||||
| if (data.getType() == DataObjectType.TEMPLATE) { | ||||||
| caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null)); | ||||||
| if (logger.isDebugEnabled()) { | ||||||
| logger.debug("Downloading template to data store {}", dataStore); | ||||||
| if (dataStoreDao.findById(dataStore.getId()).isReadonly()) { | ||||||
| logger.debug("Template [{}] will not be downloaded to image store [{}] because this store is marked as read-only.", data.getName(), | ||||||
| dataStore.getName()); | ||||||
| return; | ||||||
|
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. same here can have a common method to check image store exists or not and then isReadonly() ? |
||||||
| } | ||||||
|
Comment on lines
+181
to
185
|
||||||
| caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null)); | ||||||
| logger.debug("Downloading template [{}] to data store [{}].", data.getName(), dataStore.getName()); | ||||||
| _downloadMonitor.downloadTemplateToStorage(data, caller); | ||||||
| } else if (data.getType() == DataObjectType.VOLUME) { | ||||||
| caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null)); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -338,6 +338,11 @@ protected boolean isZoneAndImageStoreAvailable(DataStore imageStore, Long zoneId | |
| return false; | ||
| } | ||
|
|
||
| if (_imgStoreDao.findById(imageStore.getId()).isReadonly()) { | ||
|
|
||
| logger.info("Image store [{}] is marked as read-only. Skip downloading template to this image store.", imageStore); | ||
| return false; | ||
| } | ||
|
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. use common method if possible
Comment on lines
+341
to
+344
|
||
|
|
||
| if (!_statsCollector.imageStoreHasEnoughCapacity(imageStore)) { | ||
| logger.info("Image store doesn't have enough capacity. Skip downloading template to this image store [{}].", imageStore); | ||
| return false; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.