-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Allow copy of templates from secondary storages of other zone when adding a new secondary storage #12296
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
Open
harikrishna-patnala
wants to merge
9
commits into
apache:4.20
Choose a base branch
from
shapeblue:improve_template_copy_btw_secondary_storages
base: 4.20
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+437
−23
Open
Allow copy of templates from secondary storages of other zone when adding a new secondary storage #12296
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1c448d3
Allow copy of templates from secondary storages of other zone when ad…
harikrishna-patnala a6d8bf6
Add API param and UI changes on add secondary storage page
harikrishna-patnala b3232a4
Make copy template across zones non blocking
harikrishna-patnala 7a2a9d5
Code fixes
harikrishna-patnala 1797f46
unused imports
harikrishna-patnala 3556d74
Add copy template flag in zone wizard and remove NFS checks
harikrishna-patnala b3916fa
Fix UI
harikrishna-patnala fbbbbd0
Label fixes
harikrishna-patnala d277218
code optimizations
harikrishna-patnala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,15 @@ | |
| import javax.inject.Inject; | ||
| import javax.naming.ConfigurationException; | ||
|
|
||
| import com.cloud.dc.DataCenterVO; | ||
| import com.cloud.dc.dao.DataCenterDao; | ||
| import com.cloud.exception.ResourceAllocationException; | ||
| import com.cloud.exception.StorageUnavailableException; | ||
| import com.cloud.storage.VMTemplateVO; | ||
| import com.cloud.storage.dao.VMTemplateDao; | ||
| import com.cloud.template.TemplateManager; | ||
| import org.apache.cloudstack.api.response.MigrationResponse; | ||
| import org.apache.cloudstack.context.CallContext; | ||
| import org.apache.cloudstack.engine.orchestration.service.StorageOrchestrationService; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||
|
|
@@ -103,6 +111,13 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra | |
| VolumeDataStoreDao volumeDataStoreDao; | ||
| @Inject | ||
| DataMigrationUtility migrationHelper; | ||
| @Inject | ||
| TemplateManager templateManager; | ||
| @Inject | ||
| VMTemplateDao templateDao; | ||
| @Inject | ||
| DataCenterDao dcDao; | ||
|
|
||
|
|
||
| ConfigKey<Double> ImageStoreImbalanceThreshold = new ConfigKey<>("Advanced", Double.class, | ||
| "image.store.imbalance.threshold", | ||
|
|
@@ -308,6 +323,14 @@ public Future<TemplateApiResult> orchestrateTemplateCopyToImageStore(TemplateInf | |
| return submit(destStore.getScope().getScopeId(), new CopyTemplateTask(source, destStore)); | ||
| } | ||
|
|
||
| @Override | ||
| public Future<TemplateApiResult> orchestrateTemplateCopyAcrossZones(TemplateInfo templateInfo, DataStore destStore) { | ||
| Long dstZoneId = destStore.getScope().getScopeId(); | ||
| DataCenterVO dstZone = dcDao.findById(dstZoneId); | ||
| long userId = CallContext.current().getCallingUserId(); | ||
| return submit(dstZoneId, new CrossZoneCopyTemplateTask(userId, templateInfo, dstZone)); | ||
| } | ||
|
|
||
| protected Pair<String, Boolean> migrateCompleted(Long destDatastoreId, DataStore srcDatastore, List<DataObject> files, MigrationPolicy migrationPolicy, int skipped) { | ||
| String message = ""; | ||
| boolean success = true; | ||
|
|
@@ -653,4 +676,47 @@ public TemplateApiResult call() { | |
| return result; | ||
| } | ||
| } | ||
|
|
||
| private class CrossZoneCopyTemplateTask implements Callable<TemplateApiResult> { | ||
| private final long userId; | ||
| private final TemplateInfo sourceTmpl; | ||
| private final DataCenterVO dstZone; | ||
| private final String logid; | ||
|
|
||
| CrossZoneCopyTemplateTask(long userId, TemplateInfo sourceTmpl, DataCenterVO dstZone) { | ||
| this.userId = userId; | ||
| this.sourceTmpl = sourceTmpl; | ||
| this.dstZone = dstZone; | ||
| this.logid = ThreadContext.get(LOGCONTEXTID); | ||
| } | ||
|
|
||
| @Override | ||
| public TemplateApiResult call() { | ||
| ThreadContext.put(LOGCONTEXTID, logid); | ||
| TemplateApiResult result; | ||
| VMTemplateVO template = templateDao.findById(sourceTmpl.getId()); | ||
| try { | ||
| DataStore sourceStore = sourceTmpl.getDataStore(); | ||
| boolean success = templateManager.copy(userId, template, sourceStore, dstZone); | ||
|
|
||
| result = new TemplateApiResult(sourceTmpl); | ||
| if (!success) { | ||
| result.setResult("Cross-zone template copy failed"); | ||
| } | ||
| } catch (StorageUnavailableException | ResourceAllocationException e) { | ||
| logger.error("Exception while copying template [{}] from zone [{}] to zone [{}]", | ||
| template, | ||
| sourceTmpl.getDataStore().getScope().getScopeId(), | ||
| dstZone.getId(), | ||
| e); | ||
| result = new TemplateApiResult(sourceTmpl); | ||
| result.setResult(e.getMessage()); | ||
| } finally { | ||
| tryCleaningUpExecutor(dstZone.getId()); | ||
| ThreadContext.clearAll(); | ||
| } | ||
|
Comment on lines
+714
to
+717
Member
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. I would place these 2 lines outside the finally so that there's less idented code
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. I kept it finally to handle any runtime exceptions as well. |
||
|
|
||
| return result; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I usually prefer having parameters instead of passing things as a detail, so that it is automatically added to the API's documentation, but I'm ok if you keep it like this seeing that there's already documentation and a UI change for it
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.
yes we do have both doc and UI changes for this. The reason I didnt keep it as parameter is, even though it is not passed, the config value will be used.