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

Async liquibase #526

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* ****************************************************************************
* (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Apache License v2.0 which accompany this distribution.
* <p/>
* The Apache License is available at
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* *****************************************************************************
*/
package io.cloudslang.lang.cli.configuration.liquibase;

import liquibase.exception.LiquibaseException;
import liquibase.integration.spring.SpringLiquibase;
import org.apache.log4j.Logger;
import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.env.Environment;
import org.springframework.core.task.TaskExecutor;
import org.springframework.util.StopWatch;

import static org.fusesource.jansi.Ansi.ansi;

/**
* @author Bonczidai Levente
* @since 12/15/2015
*/
public class AsyncSpringLiquibase extends SpringLiquibase {

private final Logger logger = Logger.getLogger(getClass());

@Autowired
@Qualifier("scoreOrchestratorScheduler")
private TaskExecutor taskExecutor;
//
// @Autowired
// private Environment environment;

@Override
public void afterPropertiesSet() throws LiquibaseException {
System.out.println("Test-async");
System.out.println("Thread nr - afterPropertiesSet: " + Thread.currentThread().getId());
// new Thread((new Runnable() {
// @Override
// public void run() {
// try {
// System.out.println("Thread nr - afterPropertiesSet.run: " + Thread.currentThread().getId());
// initDb();
// } catch (LiquibaseException e) {
// e.printStackTrace();
// }
// }
// })).start();
taskExecutor.execute(new Runnable() {
@Override
public void run() {
try {
System.out.println("Thread nr - afterPropertiesSet.run: " + Thread.currentThread().getId());
initDb();
} catch (LiquibaseException e) {
e.printStackTrace();
}
}
});
}

protected void initDb() throws LiquibaseException {
StopWatch watch = new StopWatch();
watch.start();
System.out.println("Thread nr - initDb: " + Thread.currentThread().getId());
super.afterPropertiesSet();
watch.stop();
String msg = "Started Liquibase in " + watch.getTotalTimeMillis() + " ms";
System.out.println(msg);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:score="http://www.cloudslang.io/schema/score"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
Expand All @@ -31,6 +32,17 @@

<bean class="io.cloudslang.lang.api.configuration.SlangSpringConfiguration"/>

<!--<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">-->
<!--<property name="url" value="jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE;LOCK_TIMEOUT=5000"/>-->
<!--<property name="driverClassName" value="org.h2.Driver"/>-->
<!--<property name="username" value="sa"/>-->
<!--<property name="password" value="sa"/>-->
<!--</bean>-->

<!--<bean id="liquibase" class="io.cloudslang.lang.cli.configuration.liquibase.AsyncSpringLiquibase"-->
<!--p:dataSource-ref="dataSource"-->
<!--p:changeLog="classpath:changelog/cli.score.changes.xml"/>-->

<context:property-placeholder location="application.properties"/>

<score:engine />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>

<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<include file="META-INF/database/score.changes.xml"/>
</databaseChangeLog>