Skip to content
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

Allow a custom executor to be specified through a property on existing Executor implementations DAT-7531 #2374

Merged
merged 10 commits into from Jan 25, 2022
@@ -1,13 +1,11 @@
package liquibase.changelog;

import liquibase.ContextExpression;
import liquibase.Labels;
import liquibase.RuntimeEnvironment;
import liquibase.Scope;
import liquibase.*;
import liquibase.changelog.filter.ChangeSetFilter;
import liquibase.changelog.filter.ChangeSetFilterResult;
import liquibase.changelog.visitor.ChangeSetVisitor;
import liquibase.changelog.visitor.SkippedChangeSetVisitor;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.exception.LiquibaseException;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.exception.ValidationErrors;
Expand Down Expand Up @@ -137,7 +135,8 @@ private void validateChangeSetExecutor(ChangeSet changeSet, RuntimeEnvironment e
if (changeSet.getRunWith() == null) {
return;
}
String executorName = changeSet.getRunWith();
String executorName = ChangeSet.lookupExecutor(changeSet.getRunWith());

Executor executor;
try {
executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor(executorName, env.getTargetDatabase());
Expand Down
18 changes: 17 additions & 1 deletion liquibase-core/src/main/java/liquibase/changelog/ChangeSet.java
Expand Up @@ -8,6 +8,7 @@
import liquibase.change.core.EmptyChange;
import liquibase.change.core.RawSQLChange;
import liquibase.changelog.visitor.ChangeExecListener;
import liquibase.configuration.LiquibaseConfiguration;
import liquibase.database.Database;
import liquibase.database.DatabaseList;
import liquibase.database.ObjectQuotingStrategy;
Expand Down Expand Up @@ -719,7 +720,8 @@ private Executor setupCustomExecutorIfNecessary(Database database) {
if (getRunWith() == null || originalExecutor instanceof LoggingExecutor) {
return originalExecutor;
}
Executor customExecutor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor(getRunWith(), database);
String executorName = ChangeSet.lookupExecutor(getRunWith());
Executor customExecutor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor(executorName, database);
Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor("jdbc", database, customExecutor);
List<Change> changes = getChanges();
for (Change change : changes) {
Expand All @@ -735,6 +737,20 @@ private Executor setupCustomExecutorIfNecessary(Database database) {
return originalExecutor;
}

public static String lookupExecutor(String executorName) {
if (StringUtil.isEmpty(executorName)) {
return null;
}
String key = "liquibase." + executorName + ".executor";
String replacementExecutorName =
(String)Scope.getCurrentScope().getSingleton(LiquibaseConfiguration.class).getCurrentConfiguredValue(null, null, key).getValue();
if (replacementExecutorName != null) {
Scope.getCurrentScope().getLog(ChangeSet.class).info("Mapped '" + executorName + "' to executor '" + replacementExecutorName + "'");
return replacementExecutorName;
}
return executorName;
}

public void rollback(Database database) throws RollbackFailedException {
rollback(database, null);
}
Expand Down
@@ -0,0 +1,55 @@
#### _ _ _ _ _____
## | | (_) (_) | | __ \
## | | _ __ _ _ _ _| |__ __ _ ___ ___ | |__) | __ ___
## | | | |/ _` | | | | | '_ \ / _` / __|/ _ \ | ___/ '__/ _ \
## | |___| | (_| | |_| | | |_) | (_| \__ \ __/ | | | | | (_) |
## \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___| |_| |_| \___/
## | |
## |_|
##
## The liquibase.sqlcmd.conf file stores properties which are used during the
## execution of the Microsoft SQLCMD tool.
## Learn more: https://www.liquibase.org/documentation/config_properties.html
####
####
## Note about relative and absolute paths:
## The liquibase.sqlcmd.path must be a valid path to the SQLCMD executable.
## The liquibase.sqlcmd.timeout value can be one of:
## -1 - disable the timeout
## Any integer value > 0 (measured in seconds)
##
####

# The full path to the SQLCMD executable.
# Sample Linux path
# liquibase.sqlcmd.path=/opt/mssql-tools/bin/sqlcmd
# Sample Windows path
# liquibase.sqlcmd.path="C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\SQLCMD.EXE"

# A valid timeout value for the execution of the SQLCMD tool
liquibase.sqlcmd.timeout=-1

# Flag to indicate whether or not to keep the temporary SQL file after execution of SQLCMD.
# True = keep False = delete (default)
liquibase.sqlcmd.keep.temp=true

# OPTIONAL Flag to designate the location to store temporary SQL file after execution of SQLCMD.
# Liquibase will attempt to use path exactly as entered, so please ensure it complies with your OS requirements.
# liquibase.sqlcmd.keep.temp.path=

# OPTIONAL Flag to designate the name of temporary SQL file after execution of SQLCMD.
# Liquibase will attempt to use the name exactly as entered, so please ensure it complies with your OS requirements.
# liquibase.sqlcmd.keep.temp.name=

# OPTIONAL Args to pass directly to SQLCMD.
# Learn about SQLCMD args at https://<link>
# Note: The delimiter for args is a space eg:" " and not "," or ";" separated.
# liquibase.sqlcmd.args=

# OPTIONAL Path to a log file for the SQLCMD output
# liquibase.sqlcmd.logFile=
#

# OPTIONAL Name of a custom executor to use instead of SQLCMD
# The Executor must be on the Liquibase classpath
# liquibase.sqlcmd.executor=
Expand Up @@ -21,9 +21,9 @@
####

# The full path to the SQLPLUS executable.
# Sample linux path
# Sample Linux path
# liquibase.sqlplus.path=/apps/app/12.2.0.1.0/oracle/product/12.2.0.1.0/client_1/bin/sqlplus
# Sample windows path
# Sample Windows path
# liquibase.sqlplus.path=c:\\oracle\\product\\11.2.0\\client_1\\bin\\sqlplus.exe

# A valid timeout value for the execution of the SQLPLUS tool
Expand All @@ -45,3 +45,7 @@ liquibase.sqlplus.keep.temp=true
# Learn about SQLPLUS args at https://docs.oracle.com/cd/B10501_01/server.920/a90842/ch4.htm
# Note: The delimiter for args is a space eg:" " and not "," or ";" separated.
# liquibase.sqlplus.args=

# OPTIONAL Name of a custom executor to use instead of SQLPLUS
# The Executor must be on the Liquibase classpath
# liquibase.sqlplus.executor=
@@ -0,0 +1,54 @@
#### _ _ _ _ _____
## | | (_) (_) | | __ \
## | | _ __ _ _ _ _| |__ __ _ ___ ___ | |__) | __ ___
## | | | |/ _` | | | | | '_ \ / _` / __|/ _ \ | ___/ '__/ _ \
## | |___| | (_| | |_| | | |_) | (_| \__ \ __/ | | | | | (_) |
## \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___| |_| |_| \___/
## | |
## |_|
##
## The liquibase.sqlcmd.conf file stores properties which are used during the
## execution of the Microsoft SQLCMD tool.
## Learn more: https://www.liquibase.org/documentation/config_properties.html
####
####
## Note about relative and absolute paths:
## The liquibase.sqlcmd.path must be a valid path to the SQLCMD executable.
## The liquibase.sqlcmd.timeout value can be one of:
## -1 - disable the timeout
## Any integer value > 0 (measured in seconds)
##
####

# The full path to the SQLCMD executable.
# Sample Linux path
# liquibase.sqlcmd.path=/opt/mssql-tools/bin/sqlcmd
# Sample Windows path
# liquibase.sqlcmd.path="C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\SQLCMD.EXE"

# A valid timeout value for the execution of the SQLCMD tool
liquibase.sqlcmd.timeout=-1

# Flag to indicate whether or not to keep the temporary SQL file after execution of SQLCMD.
# True = keep False = delete (default)
liquibase.sqlcmd.keep.temp=true

# OPTIONAL Flag to designate the location to store temporary SQL file after execution of SQLCMD.
# Liquibase will attempt to use path exactly as entered, so please ensure it complies with your OS requirements.
# liquibase.sqlcmd.keep.temp.path=

# OPTIONAL Flag to designate the name of temporary SQL file after execution of SQLCMD.
# Liquibase will attempt to use the name exactly as entered, so please ensure it complies with your OS requirements.
# liquibase.sqlcmd.keep.temp.name=

# OPTIONAL Args to pass directly to SQLCMD.
# Learn about SQLCMD args at https://<link>
# Note: The delimiter for args is a space eg:" " and not "," or ";" separated.
# liquibase.sqlcmd.args=

# OPTIONAL Path to a log file for the SQLCMD output
# liquibase.sqlcmd.logFile=

# OPTIONAL Name of a custom executor to use instead of SQLCMD
# The Executor must be on the Liquibase classpath
# liquibase.sqlcmd.executor=
Expand Up @@ -21,9 +21,9 @@
####

# The full path to the SQLPLUS executable.
# Sample linux path
# Sample Linux path
# liquibase.sqlplus.path=/apps/app/12.2.0.1.0/oracle/product/12.2.0.1.0/client_1/bin/sqlplus
# Sample windows path
# Sample Windows path
# liquibase.sqlplus.path=c:\\oracle\\product\\11.2.0\\client_1\\bin\\sqlplus.exe

# A valid timeout value for the execution of the SQLPLUS tool
Expand All @@ -45,3 +45,7 @@ liquibase.sqlplus.keep.temp=true
# Learn about SQLPLUS args at https://docs.oracle.com/cd/B10501_01/server.920/a90842/ch4.htm
# Note: The delimiter for args is a space eg:" " and not "," or ";" separated.
# liquibase.sqlplus.args=

# OPTIONAL Name of a custom executor to use instead of SQLPLUS
# The Executor must be on the Liquibase classpath
# liquibase.sqlplus.executor=
@@ -0,0 +1 @@
liquibase.executor.jvm.ExampleExecutor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this class be committed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be okay. The liquibase-extension-examples are not shipped.