Skip to content

Commit

Permalink
Fixes #629 [Releng] SAP CF - Add Support for Binding of HANA Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ThuF committed Oct 4, 2020
1 parent 3b25a7f commit 51b10ee
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.eclipse.dirigible.cf.utils.CloudFoundryUtils;
import org.eclipse.dirigible.cf.utils.CloudFoundryUtils.HanaDbEnv;
import org.eclipse.dirigible.cf.utils.CloudFoundryUtils.HanaSchemaEnv;
import org.eclipse.dirigible.cf.utils.CloudFoundryUtils.PostgreDbEnv;
import org.eclipse.dirigible.cms.api.ICmsProvider;
import org.eclipse.dirigible.commons.api.module.AbstractDirigibleModule;
Expand Down Expand Up @@ -40,7 +41,8 @@ public int getPriority() {
protected void configure() {
boolean customPostgreDb = bindPostgreDb(CloudFoundryUtils.getPostgreDbEnv());
boolean customHanaDb = bindHanaDb(CloudFoundryUtils.getHanaDbEnv());
if (!customPostgreDb && !customHanaDb) {
boolean customHanaSchema = bindHanaSchema(CloudFoundryUtils.getHanaSchemaEnv());
if (!customPostgreDb && !customHanaDb && !customHanaSchema) {
Configuration.set(IDatabase.DIRIGIBLE_DATABASE_PROVIDER, "local");
}
}
Expand Down Expand Up @@ -80,6 +82,25 @@ private boolean bindHanaDb(HanaDbEnv env) {
return true;
}

private boolean bindHanaSchema(HanaSchemaEnv env) {
if (env == null) {
return false;
}

String name = DATABASE_HANA;
String url = env.getCredentials().getUrl();
String username = env.getCredentials().getUsername();
String password = env.getCredentials().getPassword();
String driver = DATABASE_HANA_DRIVER;

setDatabaseProperties(name, url, driver, username, password);

String maxConnectionsCount = Configuration.get(IDatabase.DIRIGIBLE_DATABASE_DEFAULT_MAX_CONNECTIONS_COUNT, "32");
Configuration.set(IDatabase.DIRIGIBLE_DATABASE_DEFAULT_MAX_CONNECTIONS_COUNT, maxConnectionsCount);
Configuration.set(DIRIGIBLE_MESSAGING_USE_DEFAULT_DATABASE, "false");
return true;
}

private void setDatabaseProperties(String name, String url, String driver) {
setDatabaseProperties(name, url, driver, null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public static HanaDbEnv getHanaDbEnv() {
return vcapServicesEnv.getHanaDbEnv() != null ? vcapServicesEnv.getHanaDbEnv().get(0) : null;
}

public static HanaSchemaEnv getHanaSchemaEnv() {
String envJson = EnvFacade.get(VCAP_SERVICES);
VcapServicesEnv vcapServicesEnv = GsonHelper.GSON.fromJson(envJson, VcapServicesEnv.class);
return vcapServicesEnv.getHanaSchemaEnv() != null ? vcapServicesEnv.getHanaSchemaEnv().get(0) : null;
}

public static class VcapServicesEnv {

private List<XsuaaEnv> xsuaa;
Expand All @@ -82,6 +88,9 @@ public static class VcapServicesEnv {
@SerializedName("hana-db")
private List<HanaDbEnv> hanaDbEnv;

@SerializedName("hana")
private List<HanaSchemaEnv> hanaSchemaEnv;

public List<XsuaaEnv> getXsuaa() {
return xsuaa;
}
Expand All @@ -105,6 +114,14 @@ public List<HanaDbEnv> getHanaDbEnv() {
public void setHanaDbEnv(List<HanaDbEnv> hanaDbEnv) {
this.hanaDbEnv = hanaDbEnv;
}

public List<HanaSchemaEnv> getHanaSchemaEnv() {
return hanaSchemaEnv;
}

public void setHanaSchemaEnv(List<HanaSchemaEnv> hanaSchemaEnv) {
this.hanaSchemaEnv = hanaSchemaEnv;
}
}

public static class XsuaaEnv {
Expand Down Expand Up @@ -315,4 +332,51 @@ public void setUrl(String url) {
}
}
}

public static class HanaSchemaEnv {

private HanaSchemaCredentialsEnv credentials;

public HanaSchemaCredentialsEnv getCredentials() {
return credentials;
}

public void setCredentials(HanaSchemaCredentialsEnv credentials) {
this.credentials = credentials;
}

public static class HanaSchemaCredentialsEnv {

private String url;

@SerializedName("user")
private String username;

private String password;

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}
}
}

0 comments on commit 51b10ee

Please sign in to comment.