use of liquibase.executor.LoggingExecutor in project liquibase by liquibase.
the class Liquibase method changeLogSync.
public void changeLogSync(Contexts contexts, LabelExpression labelExpression, Writer output) throws LiquibaseException {
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
LoggingExecutor outputTemplate = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database);
Executor oldTemplate = ExecutorService.getInstance().getExecutor(database);
ExecutorService.getInstance().setExecutor(database, outputTemplate);
outputHeader("SQL to add all changesets to database history table");
changeLogSync(contexts, labelExpression);
try {
output.flush();
} catch (IOException e) {
throw new LiquibaseException(e);
}
ExecutorService.getInstance().setExecutor(database, oldTemplate);
resetServices();
}
use of liquibase.executor.LoggingExecutor in project liquibase by liquibase.
the class Liquibase method doChangeLogSyncSql.
private void doChangeLogSyncSql(String tag, Contexts contexts, LabelExpression labelExpression, Writer output, Supplier<String> header) throws LiquibaseException {
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
runInScope(() -> {
LoggingExecutor outputTemplate = new LoggingExecutor(Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor(database), output, database);
/* We have no other choice than to save the current Executer here. */
@SuppressWarnings("squid:S1941") Executor oldTemplate = getAndReplaceJdbcExecutor(output);
outputHeader("SQL to add all changesets to database history table");
changeLogSync(tag, contexts, labelExpression);
flushOutputWriter(output);
Scope.getCurrentScope().getSingleton(ExecutorService.class).setExecutor("jdbc", database, oldTemplate);
resetServices();
});
}
use of liquibase.executor.LoggingExecutor in project liquibase by liquibase.
the class Liquibase method getConnection.
/**
* Create or retrieve the Connection object
*
* @param changeLog Database changelog
* @return Connection
* @throws LiquibaseHubException Thrown by HubService
*/
public Connection getConnection(DatabaseChangeLog changeLog) throws LiquibaseHubException {
//
// If our current Executor is a LoggingExecutor then just return since we will not update Hub
//
Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
if (executor instanceof LoggingExecutor) {
return null;
}
String changeLogId = changeLog.getChangeLogId();
HubUpdater hubUpdater = new HubUpdater(new Date(), changeLog, database);
if (hubUpdater.hubIsNotAvailable(changeLogId)) {
if (StringUtil.isNotEmpty(HubConfiguration.LIQUIBASE_HUB_API_KEY.getCurrentValue()) && changeLogId == null) {
String message = "The API key '" + HubConfiguration.LIQUIBASE_HUB_API_KEY.getCurrentValue() + "' was found, but no changelog ID exists.\n" + "No operations will be reported. Register this changelog with Liquibase Hub to generate free deployment reports.\n" + "Learn more at https://hub.liquibase.com.";
Scope.getCurrentScope().getUI().sendMessage("WARNING: " + message);
Scope.getCurrentScope().getLog(getClass()).warning(message);
}
return null;
}
//
if (StringUtil.isEmpty(HubConfiguration.LIQUIBASE_HUB_API_KEY.getCurrentValue()) && changeLogId != null) {
String message = "The changelog ID '" + changeLogId + "' was found, but no API Key exists.\n" + "No operations will be reported. Simply add a liquibase.hub.apiKey setting to generate free deployment reports.\n" + "Learn more at https://hub.liquibase.com.";
Scope.getCurrentScope().getUI().sendMessage("WARNING: " + message);
Scope.getCurrentScope().getLog(getClass()).warning(message);
return null;
}
Connection connection;
final HubService hubService = Scope.getCurrentScope().getSingleton(HubServiceFactory.class).getService();
if (getHubConnectionId() == null) {
HubChangeLog hubChangeLog = hubService.getHubChangeLog(UUID.fromString(changeLogId), "*");
if (hubChangeLog == null) {
Scope.getCurrentScope().getLog(getClass()).warning("Retrieving Hub Change Log failed for Changelog ID: " + changeLogId);
return null;
}
if (hubChangeLog.isDeleted()) {
//
// Complain and stop the operation
//
String message = "\n" + "The operation did not complete and will not be reported to Hub because the\n" + "" + "registered changelog has been deleted by someone in your organization.\n" + "Learn more at http://hub.liquibase.com.";
throw new LiquibaseHubException(message);
}
Connection exampleConnection = new Connection();
exampleConnection.setProject(hubChangeLog.getProject());
exampleConnection.setJdbcUrl(Liquibase.this.database.getConnection().getURL());
connection = hubService.getConnection(exampleConnection, true);
setHubConnectionId(connection.getId());
} else {
connection = hubService.getConnection(new Connection().setId(getHubConnectionId()), true);
}
return connection;
}
use of liquibase.executor.LoggingExecutor in project liquibase by liquibase.
the class HubUpdater method postUpdateHubExceptionHandling.
/**
* Handle Hub exceptions thrown during the operation
*
* @param operation Operation object
* @param bufferLog Log output
* @param originalExceptionMessage Exception thrown by the operation
*/
public void postUpdateHubExceptionHandling(Operation operation, BufferedLogService bufferLog, String originalExceptionMessage) {
try {
//
// If our current Executor is a LoggingExecutor then just return since we will not update Hub
//
Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
if (executor instanceof LoggingExecutor) {
return;
}
//
if (operation == null || hubIsNotAvailable(changeLog.getChangeLogId())) {
return;
}
//
// Capture the current log level to use for filtering
//
Level currentLevel = HubConfiguration.LIQUIBASE_HUB_LOGLEVEL.getCurrentValue();
//
// Check to see if the changelog has been deactivated
//
final HubService hubService = Scope.getCurrentScope().getSingleton(HubServiceFactory.class).getService();
final HubChangeLog hubChangeLog = hubService.getHubChangeLog(UUID.fromString(changeLog.getChangeLogId()));
if (hubChangeLog.isInactive()) {
String message = "\n" + "The command completed and reported to Hub, but changelog '" + hubChangeLog.getName() + "' has been deactivated by someone in your organization.\n" + "To synchronize your changelog, checkout the latest from source control or run \"deactivatechangelog\".\n" + "After that, commands run against this changelog will not be reported to Hub until \"registerchangelog\" is run again.\n" + "Learn more at http://hub.liquibase.com";
Scope.getCurrentScope().getLog(HubUpdater.class).warning(message);
Scope.getCurrentScope().getUI().sendMessage("WARNING: " + message);
}
hubService.sendOperationEvent(operation, new OperationEvent().setEventType("COMPLETE").setStartDate(startTime).setEndDate(new Date()).setOperationEventStatus(new OperationEvent.OperationEventStatus().setOperationEventStatusType("FAIL").setStatusMessage(String.format("%s operation completed with errors", operation.getOperationStatus().getOperationStatusType()))).setOperationEventLog(new OperationEvent.OperationEventLog().setLogMessage(bufferLog.getLogAsString(currentLevel))));
//
if (hubChangeLog.isActive()) {
showOperationReportLink(operation, hubService);
}
} catch (LiquibaseException serviceException) {
Scope.getCurrentScope().getLog(getClass()).warning(originalExceptionMessage, serviceException);
}
}
use of liquibase.executor.LoggingExecutor in project liquibase by liquibase.
the class RollbackVisitor method visit.
@Override
public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
Executor executor = Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database);
if (!(executor instanceof LoggingExecutor)) {
Scope.getCurrentScope().getUI().sendMessage("Rolling Back Changeset: " + changeSet);
}
sendRollbackWillRunEvent(changeSet, databaseChangeLog, database);
try {
changeSet.rollback(this.database, this.execListener);
} catch (Exception e) {
fireRollbackFailed(changeSet, databaseChangeLog, database, e);
throw e;
}
this.database.removeRanStatus(changeSet);
sendRollbackEvent(changeSet, databaseChangeLog, database);
this.database.commit();
checkForEmptyRollbackFile(changeSet);
}
Aggregations