use of liquibase.lockservice.LockService in project liquibase by liquibase.
the class Liquibase method tag.
/**
* 'Tags' the database for future rollback
*/
public void tag(String tagString) throws LiquibaseException {
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
lockService.waitForLock();
try {
ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).generateDeploymentId();
checkLiquibaseTables(false, null, new Contexts(), new LabelExpression());
getDatabase().tag(tagString);
} finally {
try {
lockService.releaseLock();
} catch (LockException e) {
log.severe("Could not release lock", e);
}
}
}
use of liquibase.lockservice.LockService in project liquibase by liquibase.
the class Liquibase method changeLogSync.
public void changeLogSync(Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
lockService.waitForLock();
try {
DatabaseChangeLog changeLog = getDatabaseChangeLog();
checkLiquibaseTables(true, changeLog, contexts, labelExpression);
ChangeLogHistoryServiceFactory.getInstance().getChangeLogService(database).generateDeploymentId();
changeLog.validate(database, contexts, labelExpression);
ChangeLogIterator logIterator = new ChangeLogIterator(changeLog, new NotRanChangeSetFilter(database.getRanChangeSetList()), new ContextChangeSetFilter(contexts), new LabelChangeSetFilter(labelExpression), new DbmsChangeSetFilter(database));
logIterator.run(new ChangeLogSyncVisitor(database, changeLogSyncListener), new RuntimeEnvironment(database, contexts, labelExpression));
} finally {
try {
lockService.releaseLock();
} catch (LockException e) {
log.severe("Could not release lock", e);
}
resetServices();
}
}
use of liquibase.lockservice.LockService in project liquibase by liquibase.
the class Liquibase method generateDocumentation.
public void generateDocumentation(String outputDirectory, Contexts contexts, LabelExpression labelExpression) throws LiquibaseException {
log.info("Generating Database Documentation");
changeLogParameters.setContexts(contexts);
changeLogParameters.setLabels(labelExpression);
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
lockService.waitForLock();
try {
DatabaseChangeLog changeLog = getDatabaseChangeLog();
checkLiquibaseTables(false, changeLog, new Contexts(), new LabelExpression());
changeLog.validate(database, contexts, labelExpression);
ChangeLogIterator logIterator = new ChangeLogIterator(changeLog, new DbmsChangeSetFilter(database));
DBDocVisitor visitor = new DBDocVisitor(database);
logIterator.run(visitor, new RuntimeEnvironment(database, contexts, labelExpression));
visitor.writeHTML(new File(outputDirectory), resourceAccessor);
} catch (IOException e) {
throw new LiquibaseException(e);
} finally {
try {
lockService.releaseLock();
} catch (LockException e) {
log.severe("Could not release lock", e);
}
}
// try {
// if (!LockService.getExecutor(database).waitForLock()) {
// return;
// }
//
// DBDocChangeLogHandler changeLogHandler = new DBDocChangeLogHandler(outputDirectory, this, changeLogFile,resourceAccessor);
// runChangeLogs(changeLogHandler);
//
// changeLogHandler.writeHTML(this);
// } finally {
// releaseLock();
// }
}
use of liquibase.lockservice.LockService in project xipki by xipki.
the class LiquibaseMain method releaseLocks.
// method init
public void releaseLocks() throws Exception {
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
lockService.forceReleaseLock();
System.out.println("successfully released the database");
}
use of liquibase.lockservice.LockService in project liquibase by liquibase.
the class HubUpdater method register.
/**
* Automatically register the current user with Hub
*
* @param changeLogFile ChangeLog path for this operation
* @throws LiquibaseException Thrown if registration fails
* @throws CommandExecutionException Thrown if registerChangeLog fails
*/
public HubRegisterResponse register(String changeLogFile) throws LiquibaseException {
HubRegisterResponse registerResponse = null;
if (!hubService.isOnline()) {
return null;
}
//
if (!Scope.getCurrentScope().getUI().getAllowPrompt()) {
return null;
}
// 2. We have a changelog and a changeLogId in it already
if (!StringUtil.isEmpty(HubConfiguration.LIQUIBASE_HUB_API_KEY.getCurrentValue()) || (changeLog != null && changeLog.getChangeLogId() != null)) {
return null;
}
if (skipAutoRegistration != null && skipAutoRegistration) {
return null;
}
//
try {
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
lockService.releaseLock();
} catch (LockException e) {
Scope.getCurrentScope().getLog(HubUpdater.class).warning(Liquibase.MSG_COULD_NOT_RELEASE_LOCK);
}
String promptString = "Do you want to see this operation's report in Liquibase Hub, which improves team collaboration? \n" + "If so, enter your email. If not, enter [N] to no longer be prompted, or [S] to skip for now, but ask again next time";
String input = Scope.getCurrentScope().getUI().prompt(promptString, "S", (input1, returnType) -> {
input1 = input1.trim().toLowerCase();
if (!(input1.equals("s") || input1.equals("n") || input1.contains("@"))) {
throw new IllegalArgumentException(String.format("Invalid value: '%s'", input1));
}
return input1;
}, String.class);
//
// Re-lock before proceeding
//
LockService lockService = LockServiceFactory.getInstance().getLockService(database);
lockService.waitForLock();
String defaultsFilePath = Scope.getCurrentScope().get("defaultsFile", String.class);
File defaultsFile = null;
if (defaultsFilePath != null) {
defaultsFile = new File(defaultsFilePath);
}
input = input.toLowerCase();
if (input.equals("n")) {
//
try {
String message = "No operations will be reported. Simply add a liquibase.hub.apiKey setting to generate free deployment reports. Learn more at https://hub.liquibase.com";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(getClass()).info(message);
writeToPropertiesFile(defaultsFile, "\nliquibase.hub.mode=off\n");
message = "* Updated properties file " + defaultsFile + " to set liquibase.hub.mode=off";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(getClass()).info(message);
DeprecatedConfigurationValueProvider.setData(HubConfiguration.LIQUIBASE_HUB_MODE, HubConfiguration.HubMode.OFF);
} catch (IOException ioe) {
String message = "Unable to write hubMode to liquibase.properties: " + ioe.getMessage();
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(getClass()).warning(message);
}
} else if (input.equals("s")) {
String message = "Skipping auto-registration";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(getClass()).warning(message);
skipAutoRegistration = true;
} else {
//
try {
registerResponse = hubService.register(input);
} catch (LiquibaseException lhe) {
String message = "Account creation failed for email address '" + input + "': " + lhe.getMessage() + ".\n" + "No operation report will be generated.";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(HubUpdater.class).warning(message);
return registerResponse;
}
if (registerResponse == null) {
String message = "Account creation failed for email address '" + input + "'.\n" + "No operation report will be generated.";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(HubUpdater.class).warning(message);
return registerResponse;
}
String message;
try {
//
// Update the properties file
//
writeToPropertiesFile(defaultsFile, "\nliquibase.hub.apiKey=" + registerResponse.getApiKey() + "\n");
//
// If there is no liquibase.hub.mode setting then add one with value 'all'
// Do not update liquibase.hub.mode if it is already set
//
ConfiguredValue<HubConfiguration.HubMode> hubModeProperty = HubConfiguration.LIQUIBASE_HUB_MODE.getCurrentConfiguredValue();
if (hubModeProperty.wasDefaultValueUsed()) {
writeToPropertiesFile(defaultsFile, "\nliquibase.hub.mode=all\n");
message = "* Updated properties file " + defaultsFile + " to set liquibase.hub properties";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(getClass()).info(message);
} else {
message = "* Updated the liquibase.hub.apiKey property.";
String message2 = "The liquibase.hub.mode is already set to " + hubModeProperty.getValue() + ". It will not be updated.";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getUI().sendMessage(message2);
Scope.getCurrentScope().getLog(getClass()).warning(message);
Scope.getCurrentScope().getLog(getClass()).warning(message2);
}
// register the changelog if it exist
DeprecatedConfigurationValueProvider.setData(HubConfiguration.LIQUIBASE_HUB_API_KEY, registerResponse.getApiKey());
if (changeLog != null) {
message = "* Registering changelog file " + changeLogFile + " with Hub";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(getClass()).info(message);
// Update the API key in HubConfiguration
registerChangeLog(registerResponse.getProjectId(), changeLog, changeLogFile);
}
message = "Great! Your free operation and deployment reports will be available to you after your local Liquibase commands complete.";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(getClass()).info(message);
} catch (IOException ioe) {
message = "Unable to write information to liquibase.properties: " + ioe.getMessage() + "\n" + "Please check your permissions. No operations will be reported.";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(getClass()).warning(message);
} catch (CommandExecutionException cee) {
message = "Unable to register changelog: " + cee.getMessage() + "\n" + "No operations will be reported.";
Scope.getCurrentScope().getUI().sendMessage(message);
Scope.getCurrentScope().getLog(getClass()).warning(message);
// System.setProperty(HubConfiguration.LIQUIBASE_HUB_API_KEY.getKey(), null);
DeprecatedConfigurationValueProvider.setData(HubConfiguration.LIQUIBASE_HUB_API_KEY, null);
}
}
return registerResponse;
}
Aggregations