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

OZ-532: Force release liquibase lock before EIP client startup #34

Closed
wants to merge 7 commits into from

Conversation

VaishSiddharth
Copy link
Contributor

@VaishSiddharth VaishSiddharth commented May 9, 2024

JIRA: https://mekomsolutions.atlassian.net/browse/OZ-532

Added liquibase dependency & code to force release lock when DB url is set (check is required because eip-demo doesn't depend on liquibase)

@mks-d mks-d changed the title OZ-532 | Force release liquibase lock before eip client startup OZ-532: Force release liquibase lock before EIP client startup May 13, 2024
@@ -26,6 +26,7 @@
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<start-class>com.ozonehis.eip.Application</start-class>
<liquibaseVersion>4.24.0</liquibaseVersion>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use the latest? v4.27.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@corneliouzbett corneliouzbett left a comment

Choose a reason for hiding this comment

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

Good work @VaishSiddharth!
I have provided you with some suggestions

Comment on lines 26 to 33
@Value("${spring.mngt-datasource.jdbcUrl:#{null}}")
private String url;

@Value("${spring.mngt-datasource.username:#{null}}")
private String username;

@Value("${spring.mngt-datasource.password:#{null}}")
private String password;
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to do this since we already have the management datasource class here

Comment on lines 42 to 62
if (url == null || username == null || password == null) {
log.info("Skipping liquibase step: forceReleaseLock");
return;
}
Connection connection = null;
try {
connection = DriverManager.getConnection(url, username, password);
Database database =
DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
LockServiceFactory.getInstance().getLockService(database).forceReleaseLock();
} catch (Exception e) {
log.error("Error occurred while releasing lock from Liquibase: {}", e.getMessage(), e);
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
log.error("Error occurred while closing connection: {}", e.getMessage(), e);
}
}
}
Copy link
Contributor

@corneliouzbett corneliouzbett May 13, 2024

Choose a reason for hiding this comment

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

Let's use the 'mngtDataSource' already configured in the context. The simplified code would look like and of course handle the exceptions well.

// Add the applicationContext

if (applicationContext.containsBean("mngtDataSource")) {
  DataSource mgtDatasource = applicationContext.getBean("mngtDataSource", DataSource.class);
  try {
    Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(mgtDatasource.getConnection()));
    LockServiceFactory.getInstance().getLockService(database).forceReleaseLock();
  } catch (DatabaseException | SQLException | LockException e) {
    throw new RuntimeException(e);
    }
}

Copy link
Contributor Author

@VaishSiddharth VaishSiddharth May 13, 2024

Choose a reason for hiding this comment

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

Should we add logic to close connection after lock is released?

finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                    log.error("Error occurred while closing connection: {}", e.getMessage(), e);
                }
            }

Comment on lines +26 to +27
# ---- Liquibase Configuration -----------------------------------------------------------------------------------------
spring.liquibase.enabled=${ENABLE_LIQUIBASE}
Copy link
Contributor

Choose a reason for hiding this comment

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

How are you utilizing this property in your code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is required to prevent liquibase from searching changelog.xml files and returning error for eip-demo service

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can do away with this property since it's already been set here.

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 is required otherwise the eip-demo service fails to start
Screenshot 2024-05-13 at 6 37 32 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants