gobblin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject incubator-gobblin git commit: [GOBBLIN-10] Fix_for_#1850_and_#1851
Date Thu, 27 Jul 2017 23:47:13 GMT
Repository: incubator-gobblin
Updated Branches:
  refs/heads/master b12c35385 -> 8d297de3e


[GOBBLIN-10] Fix_for_#1850_and_#1851

DatabaseJobHistoryStore should initialize
Reflections only once.

Fix findbugs error

Closes #1967 from kadaan/Fix_for_#1850


Project: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/commit/8d297de3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/tree/8d297de3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/diff/8d297de3

Branch: refs/heads/master
Commit: 8d297de3e85fa9570ddd60eac38ebf0d08b6e19e
Parents: b12c353
Author: Joel Baranick <joel.baranick@ensighten.com>
Authored: Thu Jul 27 16:47:06 2017 -0700
Committer: Abhishek Tiwari <abhishektiwari.btech@gmail.com>
Committed: Thu Jul 27 16:47:06 2017 -0700

----------------------------------------------------------------------
 .../metastore/DatabaseJobHistoryStore.java      | 28 +++++++++++++++++---
 1 file changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/8d297de3/gobblin-metastore/src/main/java/gobblin/metastore/DatabaseJobHistoryStore.java
----------------------------------------------------------------------
diff --git a/gobblin-metastore/src/main/java/gobblin/metastore/DatabaseJobHistoryStore.java
b/gobblin-metastore/src/main/java/gobblin/metastore/DatabaseJobHistoryStore.java
index 7e841b1..914ab42 100644
--- a/gobblin-metastore/src/main/java/gobblin/metastore/DatabaseJobHistoryStore.java
+++ b/gobblin-metastore/src/main/java/gobblin/metastore/DatabaseJobHistoryStore.java
@@ -17,7 +17,9 @@
 
 package gobblin.metastore;
 
+import javax.annotation.Nullable;
 import javax.sql.DataSource;
+import java.io.File;
 import java.io.IOException;
 import java.net.URL;
 import java.util.Collection;
@@ -27,10 +29,14 @@ import org.flywaydb.core.Flyway;
 import org.flywaydb.core.api.FlywayException;
 import org.flywaydb.core.api.MigrationInfoService;
 import org.flywaydb.core.api.MigrationVersion;
+import org.reflections.Configuration;
 import org.reflections.Reflections;
 import org.reflections.util.ClasspathHelper;
 
+import com.google.common.base.Predicate;
 import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import com.google.inject.Inject;
 
@@ -40,6 +46,7 @@ import gobblin.rest.JobExecutionInfo;
 import gobblin.rest.JobExecutionQuery;
 
 import org.reflections.util.ClasspathHelper;
+import org.reflections.util.ConfigurationBuilder;
 
 
 /**
@@ -52,6 +59,9 @@ import org.reflections.util.ClasspathHelper;
  * @author Yinan Li
  */
 public class DatabaseJobHistoryStore implements JobHistoryStore {
+  // Scan all packages in the classpath with prefix gobblin.metastore.database when
+  // class is loaded. Since scan is expensive we do it only once when class is loaded.
+  private static final Reflections reflections = new Reflections(getConfigurationBuilder());
   private final VersionedDatabaseJobHistoryStore versionedStore;
 
   @Inject
@@ -92,16 +102,26 @@ public class DatabaseJobHistoryStore implements JobHistoryStore {
     return ClasspathHelper.forManifest(ClasspathHelper.forClassLoader(classLoaders));
   }
 
+  private static Configuration getConfigurationBuilder() {
+    ConfigurationBuilder configurationBuilder=  ConfigurationBuilder.build("gobblin.metastore.database",
+        effectiveClassPathUrls(DatabaseJobHistoryStore.class.getClassLoader()));
+    List<URL> filteredUrls = Lists.newArrayList(Iterables.filter(configurationBuilder.getUrls(),
new Predicate<URL>() {
+      @Override
+      public boolean apply(@Nullable URL input) {
+        return input != null && (!input.getProtocol().equals("file") || new File(input.getFile()).exists());
+      }
+    }));
+    configurationBuilder.setUrls(filteredUrls);
+    return configurationBuilder;
+  }
+
   private static VersionedDatabaseJobHistoryStore findVersionedDatabaseJobHistoryStore(MigrationVersion
requiredVersion)
       throws IllegalAccessException, InstantiationException, ClassNotFoundException {
     Class<?> foundClazz = null;
     Class<?> defaultClazz = null;
     MigrationVersion defaultVersion = MigrationVersion.EMPTY;
-    // Scan all packages
-    Reflections reflections = new Reflections("gobblin.metastore.database",
-        effectiveClassPathUrls(DatabaseJobHistoryStore.class.getClassLoader()));
     for (Class<?> clazz : Sets.intersection(reflections.getTypesAnnotatedWith(SupportedDatabaseVersion.class),
-        reflections.getSubTypesOf(VersionedDatabaseJobHistoryStore.class))) {
+            reflections.getSubTypesOf(VersionedDatabaseJobHistoryStore.class))) {
       SupportedDatabaseVersion annotation = clazz.getAnnotation(SupportedDatabaseVersion.class);
       String version = annotation.version();
       MigrationVersion actualVersion = MigrationVersion.fromVersion(Strings.isNullOrEmpty(version)
? null : version);


Mime
View raw message