-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support multi-scope configuration settings #10300
Draft
abh1sar
wants to merge
20
commits into
apache:main
Choose a base branch
from
shapeblue:multi-scope-config
base: main
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.
Draft
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
45ad210
wip: multi-scope config
shwstppr c5da8fa
wip: config-key scope as bitmask
shwstppr 6e7fe6e
Minor service layer changes
abh1sar 24d4cfb
Unit Tests for multi scope config
abh1sar 80f2554
revert changes to marvin/setup.py
abh1sar 3f76576
fixed 41720to41800 upgrade path
abh1sar 1924410
Merge branch 'main' into multi-scope-config
abh1sar 16add72
UT for upgrade path files
abh1sar 3f1c70e
Merge branch 'multi-scope-config' of https://github.com/shapeblue/clo…
abh1sar 17a9e60
fix pre-commit failure
abh1sar d648900
Merge remote-tracking branch 'upstream/main' into multi-scope
abh1sar 82fede2
remove unused imports in CapacityManager
abh1sar 1666aae
Add license to ConfigurationGroupsAggregatorTest.java
abh1sar 673dc56
remove extra logging
abh1sar e9214ca
Move dao code from ConfigurationGroupsAggregator to ConfigurationDaoImpl
abh1sar 2fe63ed
Fix logging message in Upgrade42010to42100
abh1sar 2d25b7b
Merge remote-tracking branch 'upstream/main' into multi-scope
abh1sar 4d24432
fix errors in ConfigurationGroupsAggregatorTest
abh1sar bab660f
fix errors in MockConfigurationDaoImpl
abh1sar e20bc6e
changed logger.debug to logger.warn in DatabaseAccessObject.java
abh1sar 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 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -17,10 +17,16 @@ | |
package com.cloud.upgrade.dao; | ||
|
||
import com.cloud.upgrade.SystemVmTemplateRegistration; | ||
import com.cloud.utils.db.TransactionLegacy; | ||
import com.cloud.utils.exception.CloudRuntimeException; | ||
|
||
import java.io.InputStream; | ||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import org.apache.cloudstack.framework.config.ConfigKey; | ||
|
||
public class Upgrade42010to42100 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { | ||
private SystemVmTemplateRegistration systemVmTemplateRegistration; | ||
|
@@ -53,6 +59,7 @@ | |
|
||
@Override | ||
public void performDataMigration(Connection conn) { | ||
migrateConfigurationScopeToBitmask(conn); | ||
} | ||
|
||
@Override | ||
|
@@ -80,4 +87,35 @@ | |
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)"); | ||
} | ||
} | ||
|
||
protected void migrateConfigurationScopeToBitmask(Connection conn) { | ||
String scopeDataType = DbUpgradeUtils.getTableColumnType(conn, "configuration", "scope"); | ||
logger.info("------------------------{}", scopeDataType); | ||
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 can be removed or rephrased if needed |
||
if (!"varchar(255)".equals(scopeDataType)) { | ||
return; | ||
} | ||
DbUpgradeUtils.addTableColumnIfNotExist(conn, "configuration", "new_scope", "BIGINT DEFAULT 0"); | ||
migrateExistingConfigurationScopeValues(conn); | ||
DbUpgradeUtils.dropTableColumnsIfExist(conn, "configuration", List.of("scope")); | ||
DbUpgradeUtils.changeTableColumnIfNotExist(conn, "configuration", "new_scope", "scope", "BIGINT NOT NULL DEFAULT 0 COMMENT 'Bitmask for scope(s) of this parameter'"); | ||
} | ||
|
||
protected void migrateExistingConfigurationScopeValues(Connection conn) { | ||
StringBuilder sql = new StringBuilder("UPDATE configuration\n" + | ||
"SET new_scope = " + | ||
" CASE "); | ||
for (ConfigKey.Scope scope : ConfigKey.Scope.values()) { | ||
sql.append(" WHEN scope = '").append(scope.name()).append("' THEN ").append(scope.getBitValue()).append(" "); | ||
} | ||
sql.append(" ELSE 0 " + | ||
" END " + | ||
"WHERE scope IS NOT NULL;"); | ||
TransactionLegacy txn = TransactionLegacy.currentTxn(); | ||
try (PreparedStatement pstmt = txn.prepareAutoCloseStatement(sql.toString())) { | ||
pstmt.executeUpdate(); | ||
} catch (SQLException e) { | ||
logger.error("Failed to migrate existing configuration scope values to bitmask", e); | ||
throw new CloudRuntimeException(String.format("Failed to migrate existing configuration scope values to bitmask due to: %s", e.getMessage())); | ||
} | ||
} | ||
} |
This file contains 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 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 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.
this can be removed?