You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2016/06/07 16:58:32 UTC

tomee git commit: TOMEE-1835 openshift PropertiesResourceProvider

Repository: tomee
Updated Branches:
  refs/heads/master 3fd96f194 -> 413a484f6


TOMEE-1835 openshift PropertiesResourceProvider


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/413a484f
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/413a484f
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/413a484f

Branch: refs/heads/master
Commit: 413a484f63a2861dfc230bd268049f738e784c3a
Parents: 3fd96f1
Author: Romain manni-Bucau <rm...@gmail.com>
Authored: Tue Jun 7 18:58:14 2016 +0200
Committer: Romain manni-Bucau <rm...@gmail.com>
Committed: Tue Jun 7 18:58:14 2016 +0200

----------------------------------------------------------------------
 .../openejb/config/ConfigurationFactory.java    | 16 ++++++++
 .../OpenshiftMySQLPropertiesProvider.java       | 39 ++++++++++++++++++++
 .../OpenshiftPostgreSQLPropertiesProvider.java  | 39 ++++++++++++++++++++
 ...uDatabasePropertiesProviderResourceTest.java |  2 +-
 4 files changed, 95 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/413a484f/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
index 203d14a..99a91b9 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
@@ -116,6 +116,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -1233,6 +1234,8 @@ public class ConfigurationFactory implements OpenEjbConfigurationFactory {
                 propertiesProvider = SystemInstance.get().getProperty(PropertiesResourceProvider.class.getName());
             }
             if (propertiesProvider != null) {
+                propertiesProvider = unaliasPropertiesProvider(propertiesProvider);
+
                 // don't trim them, user wants to handle it himself, let him do it
                 final ObjectRecipe recipe = new ObjectRecipe(propertiesProvider);
                 recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
@@ -1302,6 +1305,19 @@ public class ConfigurationFactory implements OpenEjbConfigurationFactory {
         }
     }
 
+    private static String unaliasPropertiesProvider(final String propertiesProvider) {
+        switch (propertiesProvider.toLowerCase(Locale.ENGLISH)) {
+            case "heroku":
+                return "org.apache.openejb.resource.heroku.HerokuDatabasePropertiesProvider";
+            case "openshift:mysql":
+                return "org.apache.openejb.resource.openshift.OpenshiftMySQLPropertiesProvider";
+            case "openshift:postgresql":
+                return "org.apache.openejb.resource.openshift.OpenshiftPostgreSQLPropertiesProvider";
+            default:
+                return propertiesProvider;
+        }
+    }
+
     /**
      * Takes a raw unparsed string expected to be in jvm classpath syntax
      * and parses it, producing a collection of URIs representing the absolute

http://git-wip-us.apache.org/repos/asf/tomee/blob/413a484f/container/openejb-core/src/main/java/org/apache/openejb/resource/openshift/OpenshiftMySQLPropertiesProvider.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/openshift/OpenshiftMySQLPropertiesProvider.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/openshift/OpenshiftMySQLPropertiesProvider.java
new file mode 100644
index 0000000..7de9308
--- /dev/null
+++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/openshift/OpenshiftMySQLPropertiesProvider.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.resource.openshift;
+
+import org.apache.openejb.api.resource.PropertiesResourceProvider;
+import org.apache.openejb.testng.PropertiesBuilder;
+
+import java.util.Properties;
+
+public class OpenshiftMySQLPropertiesProvider implements PropertiesResourceProvider {
+    @Override
+    public Properties provides() {
+        return new PropertiesBuilder()
+                .p("JdbcDriver", "com.mysql.jdbc.Driver")
+                .p("JdbcUrl", String.format(
+                        "jdbc:mysql://%s:%s/%s?tcpKeepAlive=true",
+                        System.getenv("OPENSHIFT_MYSQL_DB_HOST"),
+                        System.getenv("OPENSHIFT_MYSQL_DB_PORT"),
+                        System.getenv("OPENSHIFT_APP_NAME")))
+                .p("UserName", System.getenv("OPENSHIFT_MYSQL_DB_USERNAME"))
+                .p("Password", System.getenv("OPENSHIFT_MYSQL_DB_PASSWORD"))
+                .p("ValidationQuery", "SELECT 1")
+                .build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/413a484f/container/openejb-core/src/main/java/org/apache/openejb/resource/openshift/OpenshiftPostgreSQLPropertiesProvider.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/openshift/OpenshiftPostgreSQLPropertiesProvider.java b/container/openejb-core/src/main/java/org/apache/openejb/resource/openshift/OpenshiftPostgreSQLPropertiesProvider.java
new file mode 100644
index 0000000..ae9dcb3
--- /dev/null
+++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/openshift/OpenshiftPostgreSQLPropertiesProvider.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.resource.openshift;
+
+import org.apache.openejb.api.resource.PropertiesResourceProvider;
+import org.apache.openejb.testng.PropertiesBuilder;
+
+import java.util.Properties;
+
+public class OpenshiftPostgreSQLPropertiesProvider implements PropertiesResourceProvider {
+    @Override
+    public Properties provides() {
+        return new PropertiesBuilder()
+                .p("JdbcDriver", "org.postgresql.Driver")
+                .p("JdbcUrl", String.format(
+                        "jdbc:postgresql://%s:%s/%s?tcpKeepAlive=true",
+                        System.getenv("OPENSHIFT_POSTGRESQL_DB_HOST"),
+                        System.getenv("OPENSHIFT_POSTGRESQL_DB_PORT"),
+                        System.getenv("OPENSHIFT_APP_NAME")))
+                .p("UserName", System.getenv("OPENSHIFT_POSTGRESQL_DB_USERNAME"))
+                .p("Password", System.getenv("OPENSHIFT_POSTGRESQL_DB_PASSWORD"))
+                .p("ValidationQuery", "SELECT 1")
+                .build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/413a484f/container/openejb-core/src/test/java/org/apache/openejb/resource/heroku/HerokuDatabasePropertiesProviderResourceTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/resource/heroku/HerokuDatabasePropertiesProviderResourceTest.java b/container/openejb-core/src/test/java/org/apache/openejb/resource/heroku/HerokuDatabasePropertiesProviderResourceTest.java
index dd20c90..d1bc95f 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/resource/heroku/HerokuDatabasePropertiesProviderResourceTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/resource/heroku/HerokuDatabasePropertiesProviderResourceTest.java
@@ -43,7 +43,7 @@ import static org.junit.Assert.assertTrue;
 @Classes
 @ContainerProperties({
         @ContainerProperties.Property(name = "DATABASE_URL", value = "hsql://SA@localhost:${hsqldb}/adb"),
-        @ContainerProperties.Property(name = "db", value = "new://Resource?type=DataSource&properties-provider=org.apache.openejb.resource.heroku.HerokuDatabasePropertiesProvider")
+        @ContainerProperties.Property(name = "db", value = "new://Resource?type=DataSource&properties-provider=heroku")
 })
 @SimpleLog
 public class HerokuDatabasePropertiesProviderResourceTest {