Skip to content

Commit

Permalink
Issue #65: support mysql on CloudFoundry
Browse files Browse the repository at this point in the history
  • Loading branch information
yankedev committed Dec 20, 2015
1 parent 1df8889 commit afe5467
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
11 changes: 11 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
applications:
- name: alfio
memory: 512M
host: alfio
path: build/libs/alfio-1.7-SNAPSHOT-boot.war
buildpack: git://github.com/cloudfoundry/java-buildpack.git
env:
JAVA_OPTS: -Dspring.profiles.active='dev' -Djava.security.egd='file:///dev/urandom'


21 changes: 10 additions & 11 deletions src/main/java/alfio/config/support/PlatformProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* <p>
* Supported:
* - Openshift : pgsql only
* - Cloud Foundry: pgsql (elephantdb)
* - Cloud Foundry: mysql (injected)
* - Heroku
* - local use with system properties
*/
Expand Down Expand Up @@ -85,26 +85,23 @@ public boolean isHosting(Environment env) {
* Cloud Foundry configuration.
* see https://docs.cloudfoundry.org/buildpacks/java/spring-service-bindings.html
* <p>
* We assume that the "ElephantSQL" has already been bound to the application.
* When we identify running on CF, we set the driver classname and dialect to MYSQL.
* Anyway, since we use Spring, the Cloud Foundry engine should replace the "DataSource" bean with the right one.
*/
CLOUD_FOUNDRY {
MYSQL {
@Override
public String getDriveClassName(Environment env) {
return POSTGRESQL_DRIVER;
return MYSQL_DRIVER;
}

@Override
public String getUrl(Environment env) {
return env.getRequiredProperty("vcap.services.elephantsql.credentials.uri");
}
public String getUrl(Environment env) { return ""; }

@Override
public String getUsername(Environment env) {
return "";
}


@Override
public String getPassword(Environment env) {
return "";
Expand All @@ -117,17 +114,16 @@ public String getValidationQuery(Environment env) {

@Override
public String getDialect(Environment env) {
return PGSQL;
return MYSQL_DIALECT;
}

@Override
public boolean isHosting(Environment env) {
return ofNullable(env.getProperty("VCAP_APPLICATION")).isPresent();
return ofNullable(env.getProperty("VCAP_SERVICES")).isPresent();
}
},

HEROKU {

@Override
public String getDriveClassName(Environment env) {
return POSTGRESQL_DRIVER;
Expand Down Expand Up @@ -219,6 +215,9 @@ public boolean isHosting(Environment env) {
private static final String POSTGRESQL_DRIVER = "org.postgresql.Driver";
public static final String PGSQL = "PGSQL";

private static final String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
public static final String MYSQL_DIALECT = "MYSQL";


public String getDriveClassName(Environment env) {
return env.getRequiredProperty("datasource.driver");
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/alfio/config/DataSourceConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public class DataSourceConfigurationTest {{
expect.that(configuration.getCloudProvider(environment)).isEqualTo(PlatformProvider.OPENSHIFT);
});
it.should("select CLOUD_FOUNDRY environment", expect -> {
when(environment.getProperty("VCAP_APPLICATION")).thenReturn("cloud foundry");
expect.that(configuration.getCloudProvider(environment)).isEqualTo(PlatformProvider.CLOUD_FOUNDRY);
when(environment.getProperty("VCAP_SERVICES")).thenReturn("cloud foundry");
expect.that(configuration.getCloudProvider(environment)).isEqualTo(PlatformProvider.MYSQL);
});
it.should("select HEROKU environment", expect -> {
when(environment.getProperty("DYNO")).thenReturn("heroku");
Expand Down

0 comments on commit afe5467

Please sign in to comment.