You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ha...@apache.org on 2016/08/11 13:18:37 UTC
incubator-eagle git commit: [EAGLE-455] Add JDBCMetadataQueryService,
JDBCDataSourceConfig, GuiceJUnitRunner
Repository: incubator-eagle
Updated Branches:
refs/heads/develop d74c186fc -> 43d229eec
[EAGLE-455] Add JDBCMetadataQueryService, JDBCDataSourceConfig, GuiceJUnitRunner
- Enhanced JDBC Metadata Framework by adding JDBCMetadataQueryService, JDBCDataSourceConfig, GuiceJUnitRunner
- Refine `JDBCSecurityMetadataDAO` with `JDBCMetadataQueryService` and add unit test case `JDBCSecurityMetadataDAOTest`
Author: Hao Chen <ha...@apache.org>
Closes #331 from haoch/EAGLE-455.
Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/43d229ee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/43d229ee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/43d229ee
Branch: refs/heads/develop
Commit: 43d229eec09e01dc09f89c04e28b9cbe405032b5
Parents: d74c186
Author: Hao Chen <ha...@apache.org>
Authored: Thu Aug 11 21:18:16 2016 +0800
Committer: Hao Chen <ha...@apache.org>
Committed: Thu Aug 11 21:18:16 2016 +0800
----------------------------------------------------------------------
.gitignore | 1 +
.../apache/eagle/app/test/AppJUnitRunner.java | 2 +-
.../java/org/apache/eagle/app/test/Modules.java | 39 -----
eagle-core/eagle-common/pom.xml | 5 +
.../common/function/ThrowableConsumer.java | 22 +++
.../common/function/ThrowableConsumer2.java | 22 +++
.../common/function/ThrowableFunction.java | 31 ++++
.../common/function/ThrowableSupplier.java | 29 ++++
.../eagle/common/module/GuiceJUnitRunner.java | 80 +++++++++++
.../org/apache/eagle/common/module/Modules.java | 39 +++++
.../eagle/metadata/resource/RESTResponse.java | 12 +-
.../metadata/resource/UncheckedFunction.java | 29 ----
.../metadata/resource/UnhandledConsumer.java | 22 ---
.../metadata/resource/UnhandledSupplier.java | 29 ----
.../eagle-metadata/eagle-metadata-jdbc/pom.xml | 16 +++
.../store/jdbc/JDBCDataSourceConfig.java | 97 +++++++++++++
.../JDBCMetadataMetadataStoreServiceImpl.java | 143 +++++++++++++++++++
.../store/jdbc/JDBCMetadataQueryService.java | 72 ++++++++++
.../metadata/store/jdbc/JDBCMetadataStore.java | 36 +++++
.../jdbc/provider/JDBCDataSourceProvider.java | 58 ++++++++
.../JDBCMetadataStoreConfigProvider.java | 40 ++++++
.../store/mysql/MySQLMetadataStore.java | 29 ----
.../store/jdbc/JDBCDataSourceProviderTest.java | 75 ++++++++++
.../jdbc/JDBCMetadataQueryServiceTest.java | 36 +++++
.../store/jdbc/JDBCMetadataTestBase.java | 52 +++++++
.../src/test/resources/application.conf | 27 ++++
eagle-security/eagle-security-common/pom.xml | 5 +
.../service/JDBCSecurityMetadataDAO.java | 75 ++++------
.../audit/JDBCSecurityMetadataDAOTest.java | 60 ++++++++
.../src/test/resources/application.conf | 77 ++++++++++
.../eagle-security-hbase-auditlog/pom.xml | 5 -
.../hbase/HBaseAuditLogAppProvider.java | 4 +-
.../src/main/resources/application.conf | 7 +-
pom.xml | 3 +-
34 files changed, 1071 insertions(+), 208 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 287626e..f6d9234 100644
--- a/.gitignore
+++ b/.gitignore
@@ -83,3 +83,4 @@ application-local.conf
**/*.pyc
site/
+**/*.db
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/AppJUnitRunner.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/AppJUnitRunner.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/AppJUnitRunner.java
index 7e16bce..572af2c 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/AppJUnitRunner.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/AppJUnitRunner.java
@@ -19,7 +19,7 @@ package org.apache.eagle.app.test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
-import org.apache.eagle.app.module.ApplicationExtensionLoader;
+import org.apache.eagle.common.module.Modules;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/Modules.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/Modules.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/Modules.java
deleted file mode 100644
index 71a6b79..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/Modules.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.app.test;
-
-import com.google.inject.AbstractModule;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Defines the Guice Modules in use in the test class.
- *
- * @version $Id$
- */
-@Inherited
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface Modules {
- /**
- * The Guice Modules classes needed by the class under test.
- */
- Class<? extends AbstractModule>[] value();
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-common/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/pom.xml b/eagle-core/eagle-common/pom.xml
index 4591324..da62897 100644
--- a/eagle-core/eagle-common/pom.xml
+++ b/eagle-core/eagle-common/pom.xml
@@ -81,6 +81,11 @@
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableConsumer.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableConsumer.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableConsumer.java
new file mode 100644
index 0000000..592adab
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableConsumer.java
@@ -0,0 +1,22 @@
+package org.apache.eagle.common.function;
+
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+@FunctionalInterface
+public interface ThrowableConsumer<T, E extends Throwable> {
+ void accept(T o) throws E;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableConsumer2.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableConsumer2.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableConsumer2.java
new file mode 100644
index 0000000..330d48e
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableConsumer2.java
@@ -0,0 +1,22 @@
+package org.apache.eagle.common.function;
+
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+@FunctionalInterface
+public interface ThrowableConsumer2<T1,T2, E extends Throwable> {
+ void accept(T1 o1,T2 o2) throws E;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableFunction.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableFunction.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableFunction.java
new file mode 100644
index 0000000..562abea
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableFunction.java
@@ -0,0 +1,31 @@
+package org.apache.eagle.common.function;
+
+import java.sql.SQLException;
+
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+@FunctionalInterface
+public interface ThrowableFunction<T, R, E extends Throwable> {
+
+ /**
+ * Applies this function to the given argument.
+ *
+ * @param t the function argument
+ * @return the function result
+ */
+ R apply(T t) throws E;
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableSupplier.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableSupplier.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableSupplier.java
new file mode 100644
index 0000000..9e33f67
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/function/ThrowableSupplier.java
@@ -0,0 +1,29 @@
+package org.apache.eagle.common.function;
+
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ *
+ * @see java.util.function.Supplier
+ */
+@FunctionalInterface
+public interface ThrowableSupplier<T, E extends Throwable> {
+ /**
+ * Gets a result.
+ *
+ * @return a result
+ */
+ T get() throws E;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/GuiceJUnitRunner.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/GuiceJUnitRunner.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/GuiceJUnitRunner.java
new file mode 100644
index 0000000..ce04058
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/GuiceJUnitRunner.java
@@ -0,0 +1,80 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.common.module;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.InitializationError;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class GuiceJUnitRunner extends BlockJUnit4ClassRunner {
+ private final Injector injector;
+ public GuiceJUnitRunner(Class<?> klass) throws InitializationError {
+ super(klass);
+ injector = createInjectorFor(getModulesFor(klass));
+ }
+
+ @Override
+ protected Object createTest() throws Exception {
+ final Object obj = super.createTest();
+ injector.injectMembers(this);
+ this.injector.injectMembers(obj);
+ return obj;
+ }
+
+ /**
+ * Create a Guice Injector for the class under test.
+ * @param classes Guice Modules
+ * @return A Guice Injector instance.
+ * @throws InitializationError If couldn't instantiate a module.
+ */
+ private Injector createInjectorFor(final Class<?>[] classes)
+ throws InitializationError {
+ final List<Module> modules = new ArrayList<>();
+ if(classes!= null) {
+ for (final Class<?> module : Arrays.asList(classes)) {
+ try {
+ modules.add((Module) module.newInstance());
+ } catch (final ReflectiveOperationException exception) {
+ throw new InitializationError(exception);
+ }
+ }
+ }
+ return Guice.createInjector(modules);
+ }
+
+ /**
+ * Get the list of Guice Modules request by GuiceModules annotation in the
+ * class under test.
+ * @param klass Class under test.
+ * @return A Class Array of Guice Modules required by this class.
+ * @throws InitializationError If the annotation is not present.
+ */
+ private Class<?>[] getModulesFor(final Class<?> klass)
+ throws InitializationError {
+ final Modules annotation = klass.getAnnotation(Modules.class);
+ if (annotation == null) {
+ return null;
+ }
+ return annotation.value();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/Modules.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/Modules.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/Modules.java
new file mode 100644
index 0000000..8292e08
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/module/Modules.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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.common.module;
+
+import com.google.inject.AbstractModule;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Defines the Guice Modules in use in the test class.
+ *
+ * @version $Id$
+ */
+@Inherited
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Modules {
+ /**
+ * The Guice Modules classes needed by the class under test.
+ */
+ Class<? extends AbstractModule>[] value();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/RESTResponse.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/RESTResponse.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/RESTResponse.java
index af0ae83..ce76a00 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/RESTResponse.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/RESTResponse.java
@@ -18,6 +18,8 @@ package org.apache.eagle.metadata.resource;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.eagle.common.function.ThrowableConsumer;
+import org.apache.eagle.common.function.ThrowableSupplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -87,11 +89,11 @@ public class RESTResponse<T>{
return RESTResponse.<E>builder().of(func);
}
- public static <E> RestResponseBuilder<E> async(UnhandledSupplier<E,Exception> func) {
+ public static <E> RestResponseBuilder<E> async(ThrowableSupplier<E,Exception> func) {
return RESTResponse.<E>builder().async(func);
}
- public static <E> RestResponseBuilder<E> async(UnhandledConsumer<RestResponseBuilder<E>, Exception> func){
+ public static <E> RestResponseBuilder<E> async(ThrowableConsumer<RestResponseBuilder<E>, Exception> func){
return RESTResponse.<E>builder().async(func);
}
@@ -168,7 +170,7 @@ public class RESTResponse<T>{
return this;
}
- public RestResponseBuilder<E> async(UnhandledSupplier<E,Exception> func) {
+ public RestResponseBuilder<E> async(ThrowableSupplier<E,Exception> func) {
CompletableFuture future = CompletableFuture.runAsync(() -> {
try {
this.status(Response.Status.OK).success(true).data(func.get());
@@ -202,7 +204,7 @@ public class RESTResponse<T>{
throw new WebApplicationException(ex,Response.status(this.status).entity(this.current).build());
}
- public RestResponseBuilder<E> async(UnhandledConsumer<RestResponseBuilder<E>, Exception> func){
+ public RestResponseBuilder<E> async(ThrowableConsumer<RestResponseBuilder<E>, Exception> func){
CompletableFuture future = CompletableFuture.runAsync(() -> {
try {
func.accept(this);
@@ -217,7 +219,7 @@ public class RESTResponse<T>{
return this;
}
- public RestResponseBuilder<E> then(UnhandledConsumer<RestResponseBuilder<E>, Exception> func){
+ public RestResponseBuilder<E> then(ThrowableConsumer<RestResponseBuilder<E>, Exception> func){
try {
func.accept(this);
} catch (Throwable ex) {
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UncheckedFunction.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UncheckedFunction.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UncheckedFunction.java
deleted file mode 100644
index ecaba49..0000000
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UncheckedFunction.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.eagle.metadata.resource;
-
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- */
-@FunctionalInterface
-public interface UncheckedFunction<T, R> {
-
- /**
- * Applies this function to the given argument.
- *
- * @param t the function argument
- * @return the function result
- */
- R apply(T t) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UnhandledConsumer.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UnhandledConsumer.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UnhandledConsumer.java
deleted file mode 100644
index a777977..0000000
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UnhandledConsumer.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.apache.eagle.metadata.resource;
-
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- */
-@FunctionalInterface
-public interface UnhandledConsumer<T, E extends Exception> {
- void accept(T o) throws E;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UnhandledSupplier.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UnhandledSupplier.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UnhandledSupplier.java
deleted file mode 100644
index d8e2e88..0000000
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/resource/UnhandledSupplier.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.apache.eagle.metadata.resource;
-
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.
- *
- * @see java.util.function.Supplier
- */
-@FunctionalInterface
-public interface UnhandledSupplier<T, E extends Exception> {
- /**
- * Gets a result.
- *
- * @return a result
- */
- T get() throws E;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/pom.xml b/eagle-core/eagle-metadata/eagle-metadata-jdbc/pom.xml
index 4320520..ab1e0bf 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-jdbc/pom.xml
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/pom.xml
@@ -34,5 +34,21 @@
<artifactId>eagle-metadata-base</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>commons-dbcp</groupId>
+ <artifactId>commons-dbcp</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCDataSourceConfig.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCDataSourceConfig.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCDataSourceConfig.java
new file mode 100644
index 0000000..d40f465
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCDataSourceConfig.java
@@ -0,0 +1,97 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.metadata.store.jdbc;
+
+/**
+ *
+ *
+ * Configuration:
+ *
+ * Prefix: <code>metadata.jdbc.*</code>
+ *
+ * <code>
+ * metadata {
+ * jdbc {
+ * username = ""
+ * password = ""
+ * driverClassName = "org.h2.Driver"
+ * url = "jdbc:h2:./eagle"
+ * connectionProperties = "encoding=UTF8"
+ * }
+ * }
+ * </code>
+ *
+ * https://commons.apache.org/proper/commons-dbcp/configuration.html
+ */
+public class JDBCDataSourceConfig {
+ public final static String CONFIG_PREFIX = "metadata.jdbc";
+ private final static String DEFAULT_DRIVER_CLASS = org.h2.Driver.class.getName();
+ private final static String DEFAULT_CONNECTION_PROPERTIES = "encoding=UTF8";
+ private final static String DEFAULT_URL = "jdbc:h2:./eagle";
+
+ private String username;
+ private String password;
+ private String driverClassName = DEFAULT_DRIVER_CLASS;
+ private String url = DEFAULT_URL;
+ private String connectionProperties = DEFAULT_CONNECTION_PROPERTIES;
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getDriverClassName() {
+ return driverClassName;
+ }
+
+ public void setDriverClassName(String driverClassName) {
+ this.driverClassName = driverClassName;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getConnectionProperties() {
+ return connectionProperties;
+ }
+
+ public void setConnectionProperties(String connectionProperties) {
+ this.connectionProperties = connectionProperties;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s { \n driverClassName=%s \n url=%s \n connectionProperties=%s \n username=%s \n password=*****\n}",
+ CONFIG_PREFIX,driverClassName,url,username,connectionProperties);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataMetadataStoreServiceImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataMetadataStoreServiceImpl.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataMetadataStoreServiceImpl.java
new file mode 100644
index 0000000..442f0be
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataMetadataStoreServiceImpl.java
@@ -0,0 +1,143 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.metadata.store.jdbc;
+
+import com.google.inject.Inject;
+import org.apache.eagle.common.function.ThrowableConsumer2;
+import org.apache.eagle.common.function.ThrowableFunction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sql.DataSource;
+import java.sql.*;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+public class JDBCMetadataMetadataStoreServiceImpl implements JDBCMetadataQueryService {
+ private final static Logger LOGGER = LoggerFactory.getLogger(JDBCMetadataMetadataStoreServiceImpl.class);
+
+ @Inject
+ private DataSource dataSource;
+
+ @Override
+ public boolean execute(String sql) throws SQLException {
+ Connection connection = null;
+ Statement statement = null;
+ try {
+ connection = dataSource.getConnection();
+ statement = connection.createStatement();
+ return statement.execute(sql);
+ } catch (SQLException e) {
+ throw e;
+ } finally {
+ if(statement!=null) try {
+ statement.close();
+ } catch (SQLException e) {
+ LOGGER.error(e.getMessage(),e);
+ }
+ if(connection!=null) try {
+ connection.close();
+ } catch (SQLException e) {
+ LOGGER.error(e.getMessage(),e);
+ }
+ }
+ }
+
+ @Override
+ public boolean dropTable(String tableName) throws SQLException {
+ LOGGER.debug("Dropping table {}",tableName);
+ return execute(String.format("DROP TABLE %s",tableName));
+ }
+
+ @Override
+ public <T, E extends Throwable> int insert(String insertSql, Collection<T> entities, ThrowableConsumer2<PreparedStatement,T, E> mapper) throws E, SQLException {
+ Connection connection = null;
+ PreparedStatement statement = null;
+ try{
+ connection = dataSource.getConnection();
+ statement = connection.prepareStatement(insertSql);
+ connection.setAutoCommit(false);
+ for(T entity : entities){
+ mapper.accept(statement,entity);
+ statement.addBatch();
+ }
+ int[] num = statement.executeBatch();
+ connection.commit();
+ int sum = 0; for(int i:num) sum += i;
+ return sum;
+ } catch(SQLException ex){
+ LOGGER.error("Error to insert batch: {}", insertSql, ex);
+ throw ex;
+ } finally {
+ if(statement!=null) try {
+ statement.close();
+ } catch (SQLException e) {
+ LOGGER.error(e.getMessage(),e);
+ }
+ if(connection!=null) try {
+ connection.close();
+ } catch (SQLException e) {
+ LOGGER.error(e.getMessage(),e);
+ }
+ }
+ }
+
+ @Override
+ public boolean forceDropTable(String tableName) {
+ try {
+ return dropTable(tableName);
+ } catch (SQLException e) {
+ LOGGER.debug(e.getMessage(),e);
+ }
+ return true;
+ }
+
+ @Override
+ public <T,E extends Throwable> List<T> query(String sqlQuery, ThrowableFunction<ResultSet,T,E> mapper) throws SQLException,E {
+ Connection connection = null;
+ PreparedStatement statement = null;
+ ResultSet resultSet = null;
+ try {
+ connection = dataSource.getConnection();
+ statement = connection.prepareStatement(sqlQuery);
+ resultSet = statement.executeQuery();
+ List<T> result = new LinkedList<>();
+ while(resultSet.next()) result.add(mapper.apply(resultSet));
+ return result;
+ } catch (SQLException e) {
+ LOGGER.error("Error to query batch: {}", sqlQuery, e);
+ throw e;
+ } finally {
+ if(resultSet!=null) try{
+ resultSet.close();
+ } catch (SQLException e) {
+ LOGGER.error(e.getMessage(),e);
+ }
+ if(statement!=null) try {
+ statement.close();
+ } catch (SQLException e) {
+ LOGGER.error(e.getMessage(),e);
+ }
+ if(connection!=null) try {
+ connection.close();
+ } catch (SQLException e) {
+ LOGGER.error(e.getMessage(),e);
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataQueryService.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataQueryService.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataQueryService.java
new file mode 100644
index 0000000..82b1b00
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataQueryService.java
@@ -0,0 +1,72 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.metadata.store.jdbc;
+
+import org.apache.eagle.common.function.ThrowableConsumer2;
+import org.apache.eagle.common.function.ThrowableFunction;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.List;
+
+public interface JDBCMetadataQueryService {
+ /**
+ *
+ * @param sql
+ * @return
+ * @throws SQLException
+ */
+ boolean execute(String sql) throws SQLException;
+
+ /**
+ *
+ * @param tableName
+ * @return
+ * @throws SQLException
+ */
+ boolean dropTable(String tableName) throws SQLException;
+
+ /**
+ * @param insertSql
+ * @param entities
+ * @param mapper
+ * @param <T>
+ * @param <E>
+ * @return
+ * @throws E
+ * @throws SQLException
+ */
+ <T, E extends Throwable> int insert(String insertSql, Collection<T> entities, ThrowableConsumer2<PreparedStatement,T,E> mapper) throws E, SQLException;
+
+ /**
+ *
+ * @param tableName
+ * @return
+ * @throws SQLException
+ */
+ boolean forceDropTable(String tableName);
+
+ /**
+ * @param querySql sql query text
+ * @param mapper result set to entity mapper
+ * @param <T>
+ * @return entity list
+ */
+ <T,E extends Throwable> List<T> query(String querySql, ThrowableFunction<ResultSet,T,E> mapper) throws SQLException,E;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataStore.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataStore.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataStore.java
new file mode 100644
index 0000000..239b240
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataStore.java
@@ -0,0 +1,36 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.metadata.store.jdbc;
+
+import com.google.inject.Singleton;
+import org.apache.eagle.alert.metadata.IMetadataDao;
+import org.apache.eagle.alert.metadata.impl.JdbcMetadataDaoImpl;
+import org.apache.eagle.metadata.persistence.MetadataStore;
+import org.apache.eagle.metadata.store.jdbc.provider.JDBCDataSourceProvider;
+import org.apache.eagle.metadata.store.jdbc.provider.JDBCMetadataStoreConfigProvider;
+
+import javax.sql.DataSource;
+
+public class JDBCMetadataStore extends MetadataStore {
+ @Override
+ protected void configure() {
+ bind(IMetadataDao.class).to(JdbcMetadataDaoImpl.class).in(Singleton.class);
+ bind(DataSource.class).toProvider(JDBCDataSourceProvider.class).in(Singleton.class);
+ bind(JDBCDataSourceConfig.class).toProvider(JDBCMetadataStoreConfigProvider.class).in(Singleton.class);
+ bind(JDBCMetadataQueryService.class).to(JDBCMetadataMetadataStoreServiceImpl.class).in(Singleton.class);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCDataSourceProvider.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCDataSourceProvider.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCDataSourceProvider.java
new file mode 100644
index 0000000..52203f3
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCDataSourceProvider.java
@@ -0,0 +1,58 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.metadata.store.jdbc.provider;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.eagle.metadata.store.jdbc.JDBCDataSourceConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+
+public class JDBCDataSourceProvider implements Provider<DataSource> {
+ private final static Logger LOGGER = LoggerFactory.getLogger(JDBCDataSourceProvider.class);
+
+ @Inject
+ private JDBCDataSourceConfig config;
+
+ @Override
+ public DataSource get() {
+ BasicDataSource datasource = new BasicDataSource();
+ datasource.setDriverClassName(config.getDriverClassName());
+ datasource.setUsername(config.getUsername());
+ datasource.setPassword(config.getPassword());
+ datasource.setUrl(config.getUrl());
+ datasource.setConnectionProperties(config.getConnectionProperties());
+ LOGGER.info("Register JDBCDataSourceShutdownHook");
+ Runtime.getRuntime().addShutdownHook(new Thread("JDBCDataSourceShutdownHook"){
+ @Override
+ public void run() {
+ try {
+ LOGGER.info("Shutting down data source");
+ datasource.close();
+ } catch (SQLException e) {
+ LOGGER.error("SQLException: {}",e.getMessage(),e);
+ throw new IllegalStateException("Failed to close datasource",e);
+ }
+ }
+ });
+ return datasource;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCMetadataStoreConfigProvider.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCMetadataStoreConfigProvider.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCMetadataStoreConfigProvider.java
new file mode 100644
index 0000000..fc0d100
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCMetadataStoreConfigProvider.java
@@ -0,0 +1,40 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.metadata.store.jdbc.provider;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.typesafe.config.Config;
+import org.apache.eagle.metadata.store.jdbc.JDBCDataSourceConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JDBCMetadataStoreConfigProvider implements Provider<JDBCDataSourceConfig> {
+ private final static Logger LOGGER = LoggerFactory.getLogger(JDBCMetadataStoreConfigProvider.class);
+
+ @Inject
+ private Config config;
+
+ @Override
+ public JDBCDataSourceConfig get() {
+ JDBCDataSourceConfig dataSourceConfig = new ObjectMapper().convertValue(
+ config.getConfig(JDBCDataSourceConfig.CONFIG_PREFIX).root().unwrapped(),JDBCDataSourceConfig.class);
+ LOGGER.info("JDBC Configuration: {}",dataSourceConfig);
+ return dataSourceConfig;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/mysql/MySQLMetadataStore.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/mysql/MySQLMetadataStore.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/mysql/MySQLMetadataStore.java
deleted file mode 100644
index 1fe2100..0000000
--- a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/mysql/MySQLMetadataStore.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.metadata.store.mysql;
-
-import com.google.inject.Singleton;
-import org.apache.eagle.alert.metadata.IMetadataDao;
-import org.apache.eagle.alert.metadata.impl.JdbcMetadataDaoImpl;
-import org.apache.eagle.metadata.persistence.MetadataStore;
-
-public class MySQLMetadataStore extends MetadataStore{
- @Override
- protected void configure() {
- bind(IMetadataDao.class).to(JdbcMetadataDaoImpl.class).in(Singleton.class);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCDataSourceProviderTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCDataSourceProviderTest.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCDataSourceProviderTest.java
new file mode 100644
index 0000000..9094a57
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCDataSourceProviderTest.java
@@ -0,0 +1,75 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.metadata.store.jdbc;
+
+import com.google.inject.Inject;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+public class JDBCDataSourceProviderTest extends JDBCMetadataTestBase{
+ @Inject
+ private DataSource dataSource;
+ @Inject
+ private JDBCDataSourceConfig dataSourceConfig;
+
+ @Test
+ public void testSingletonDataSource(){
+ DataSource dataSource1 = injector().getInstance(DataSource.class);
+ DataSource dataSource2 = injector().getInstance(DataSource.class);
+ Assert.assertTrue("Should get datasource in singleton pattern",dataSource == dataSource1);
+ Assert.assertTrue("Should get datasource in singleton pattern",dataSource1 == dataSource2);
+ }
+
+ @Test
+ public void testDataSourceConfig(){
+ Assert.assertEquals("jdbc:h2:./eagle4ut",dataSourceConfig.getUrl());
+ Assert.assertEquals(null,dataSourceConfig.getUsername());
+ Assert.assertEquals(null,dataSourceConfig.getPassword());
+ Assert.assertEquals("encoding=UTF8;timeout=60",dataSourceConfig.getConnectionProperties());
+ }
+
+ @Test
+ public void testConnection() throws SQLException {
+ Connection connection = null;
+ Statement statement = null;
+ ResultSet resultSet = null;
+ try {
+ connection = dataSource.getConnection();
+ Assert.assertNotNull(connection);
+ statement = connection.createStatement();
+ resultSet = statement.executeQuery("SELECT 1");
+ Assert.assertTrue(resultSet.next());
+ Assert.assertEquals(1,resultSet.getInt(1));
+ } catch (SQLException e) {
+ Assert.fail(e.getMessage());
+ throw e;
+ } finally {
+ if(resultSet!=null)
+ resultSet.close();
+ if(statement != null)
+ statement.close();
+ if(connection!=null)
+ connection.close();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataQueryServiceTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataQueryServiceTest.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataQueryServiceTest.java
new file mode 100644
index 0000000..0840f76
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataQueryServiceTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.metadata.store.jdbc;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import java.sql.SQLException;
+import java.util.List;
+
+public class JDBCMetadataQueryServiceTest extends JDBCMetadataTestBase{
+ @Inject
+ JDBCMetadataQueryService queryService;
+
+ @Test
+ public void testQuery() throws SQLException {
+ List<Integer> result = queryService.query("SELECT 7",(resultSet) -> resultSet.getInt(1));
+ Assert.assertEquals(1,result.size());
+ Assert.assertEquals(7,result.get(0).intValue());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataTestBase.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataTestBase.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataTestBase.java
new file mode 100644
index 0000000..3e94b8d
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/java/org/apache/eagle/metadata/store/jdbc/JDBCMetadataTestBase.java
@@ -0,0 +1,52 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.metadata.store.jdbc;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.eagle.common.module.CommonGuiceModule;
+import org.junit.After;
+import org.junit.Before;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+
+public class JDBCMetadataTestBase {
+ private Injector injector;
+
+ @Inject
+ private DataSource dataSource;
+
+ @Before
+ public void setUp(){
+ injector = Guice.createInjector(new JDBCMetadataStore(),new CommonGuiceModule());
+ injector.injectMembers(this);
+ }
+
+ @After
+ public void after() throws SQLException {
+ if(dataSource!=null){
+ ((BasicDataSource) dataSource).close();
+ }
+ }
+
+ public Injector injector(){
+ return injector;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/resources/application.conf
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/resources/application.conf b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/resources/application.conf
new file mode 100644
index 0000000..cb2705f
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/test/resources/application.conf
@@ -0,0 +1,27 @@
+# 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.
+
+{
+ metadata {
+ store = "org.apache.eagle.metadata.store.jdbc.JDBCMetadataStore"
+ jdbc {
+ username = null
+ password = null
+ driverClassName = "org.h2.Driver"
+ url = "jdbc:h2:./eagle4ut"
+ connectionProperties = "encoding=UTF8;timeout=60"
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-security/eagle-security-common/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-common/pom.xml b/eagle-security/eagle-security-common/pom.xml
index 18f9bd0..224869a 100644
--- a/eagle-security/eagle-security-common/pom.xml
+++ b/eagle-security/eagle-security-common/pom.xml
@@ -57,6 +57,11 @@
<artifactId>eagle-metadata-base</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.eagle</groupId>
+ <artifactId>eagle-metadata-jdbc</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-security/eagle-security-common/src/main/java/org/apache/eagle/security/service/JDBCSecurityMetadataDAO.java
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-common/src/main/java/org/apache/eagle/security/service/JDBCSecurityMetadataDAO.java b/eagle-security/eagle-security-common/src/main/java/org/apache/eagle/security/service/JDBCSecurityMetadataDAO.java
index 847a598..3dcf50e 100644
--- a/eagle-security/eagle-security-common/src/main/java/org/apache/eagle/security/service/JDBCSecurityMetadataDAO.java
+++ b/eagle-security/eagle-security-common/src/main/java/org/apache/eagle/security/service/JDBCSecurityMetadataDAO.java
@@ -20,13 +20,16 @@
package org.apache.eagle.security.service;
import com.google.inject.Inject;
-import com.typesafe.config.Config;
+import org.apache.eagle.metadata.store.jdbc.JDBCMetadataQueryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.sql.*;
-import java.util.ArrayList;
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
import java.util.Collection;
+import java.util.Collections;
/**
* Since 8/8/16.
@@ -34,51 +37,47 @@ import java.util.Collection;
public class JDBCSecurityMetadataDAO implements ISecurityMetadataDAO {
private static final Logger LOG = LoggerFactory.getLogger(JDBCSecurityMetadataDAO.class);
- private Config config;
/**
* composite primary key: site and hbase_resource
*/
+ private final String TABLE_DDL_STATEMENT = "create table if not exists hbase_sensitivity_entity (site varchar(20), hbase_resource varchar(100), sensitivity_type varchar(20), primary key (site, hbase_resource));";
private final String QUERY_ALL_STATEMENT = "SELECT site, hbase_resource, sensitivity_type FROM hbase_sensitivity_entity";
private final String INSERT_STATEMENT = "INSERT INTO hbase_sensitivity_entity (site, hbase_resource, sensitivity_type) VALUES (?, ?, ?)";
- // get connection url from config
+ private DataSource dataSource;
+ private JDBCMetadataQueryService queryService;
+
+ /**
+ * Inject datasource
+ *
+ * @param dataSource
+ */
@Inject
- public JDBCSecurityMetadataDAO(Config config){
- this.config = config;
+ public JDBCSecurityMetadataDAO(DataSource dataSource, JDBCMetadataQueryService queryService) {
+ this.dataSource = dataSource;
+ this.queryService = queryService;
+ try {
+ queryService.execute(TABLE_DDL_STATEMENT);
+ } catch (SQLException e) {
+ LOG.error("Unable to create table hbase_sensitivity_entity",e);
+ throw new IllegalStateException("Unable to create table hbase_sensitivity_entity",e);
+ }
}
@Override
public Collection<HBaseSensitivityEntity> listHBaseSensitivies() {
- Connection connection = null;
- PreparedStatement statement = null;
- Collection<HBaseSensitivityEntity> ret = new ArrayList<>();
- ResultSet rs = null;
try {
- connection = getJdbcConnection();
- statement = connection.prepareStatement(QUERY_ALL_STATEMENT);
- rs = statement.executeQuery();
- while (rs.next()) {
+ return queryService.query(QUERY_ALL_STATEMENT,(rs -> {
HBaseSensitivityEntity entity = new HBaseSensitivityEntity();
entity.setSite(rs.getString(1));
entity.setHbaseResource(rs.getString(2));
entity.setSensitivityType(rs.getString(3));
- ret.add(entity);
- }
- }catch(Exception e) {
- LOG.error("error in querying hbase_sensitivity_entity table", e);
- }finally{
- try{
- if(rs != null)
- rs.close();
- if(statement != null)
- statement.close();
- if(connection != null)
- connection.close();
- }catch(Exception ex){
- LOG.error("error in closing database resources", ex);
- }
+ return entity;
+ }));
+ } catch (SQLException e) {
+ LOG.error("Error in querying all from hbase_sensitivity_entity table", e);
}
- return ret;
+ return Collections.emptyList();
}
@Override
@@ -86,7 +85,7 @@ public class JDBCSecurityMetadataDAO implements ISecurityMetadataDAO {
Connection connection = null;
PreparedStatement statement = null;
try{
- connection = getJdbcConnection();
+ connection = dataSource.getConnection();
statement = connection.prepareStatement(INSERT_STATEMENT);
connection.setAutoCommit(false);
for(HBaseSensitivityEntity entity : h){
@@ -111,16 +110,4 @@ public class JDBCSecurityMetadataDAO implements ISecurityMetadataDAO {
}
return null;
}
-
- private Connection getJdbcConnection() throws Exception {
- Connection connection = null;
- String conn = config.getString("connection");
- try {
- connection = DriverManager.getConnection(conn, "root", "");
- } catch (Exception e) {
- LOG.error("error get connection for {}", conn, e);
- throw e;
- }
- return connection;
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-security/eagle-security-common/src/test/java/org/apache/eagle/security/crawler/audit/JDBCSecurityMetadataDAOTest.java
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-common/src/test/java/org/apache/eagle/security/crawler/audit/JDBCSecurityMetadataDAOTest.java b/eagle-security/eagle-security-common/src/test/java/org/apache/eagle/security/crawler/audit/JDBCSecurityMetadataDAOTest.java
new file mode 100644
index 0000000..fd86c29
--- /dev/null
+++ b/eagle-security/eagle-security-common/src/test/java/org/apache/eagle/security/crawler/audit/JDBCSecurityMetadataDAOTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.security.crawler.audit;
+
+import com.google.inject.Inject;
+import org.apache.eagle.common.module.CommonGuiceModule;
+import org.apache.eagle.common.module.GuiceJUnitRunner;
+import org.apache.eagle.common.module.Modules;
+import org.apache.eagle.metadata.store.jdbc.JDBCMetadataQueryService;
+import org.apache.eagle.metadata.store.jdbc.JDBCMetadataStore;
+import org.apache.eagle.security.service.HBaseSensitivityEntity;
+import org.apache.eagle.security.service.JDBCSecurityMetadataDAO;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Collections;
+
+@RunWith(GuiceJUnitRunner.class)
+@Modules({JDBCMetadataStore.class, CommonGuiceModule.class})
+public class JDBCSecurityMetadataDAOTest {
+ @Inject
+ private JDBCSecurityMetadataDAO metadataDAO;
+
+ @Inject
+ private JDBCMetadataQueryService queryService;
+
+ @Test
+ public void testJDBCSecurityMetadataDAO(){
+ HBaseSensitivityEntity entity = new HBaseSensitivityEntity();
+ entity.setSite("test_site");
+ entity.setHbaseResource("test_hbaseResource");
+ metadataDAO.addHBaseSensitivity(Collections.singletonList(entity));
+ Collection<HBaseSensitivityEntity> entities = metadataDAO.listHBaseSensitivies();
+ Assert.assertEquals(1,entities.size());
+ Assert.assertEquals("test_site",entities.iterator().next().getSite());
+ }
+
+ @After
+ public void after() throws SQLException {
+ queryService.dropTable("hbase_sensitivity_entity");
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-security/eagle-security-common/src/test/resources/application.conf
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-common/src/test/resources/application.conf b/eagle-security/eagle-security-common/src/test/resources/application.conf
new file mode 100644
index 0000000..2b69406
--- /dev/null
+++ b/eagle-security/eagle-security-common/src/test/resources/application.conf
@@ -0,0 +1,77 @@
+# 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.
+
+{
+ "envContextConfig" : {
+ "env" : "storm",
+ "mode" : "local",
+ "topologyName" : "sandbox-hbaseSecurityLog-topology",
+ "stormConfigFile" : "security-auditlog-storm.yaml",
+ "parallelismConfig" : {
+ "kafkaMsgConsumer" : 1,
+ "hbaseSecurityLogAlertExecutor*" : 1
+ }
+ },
+ "dataSourceConfig": {
+ "topic" : "sandbox_hbase_security_log",
+ "zkConnection" : "sandbox.hortonworks.com:2181",
+ "zkConnectionTimeoutMS" : 15000,
+ "consumerGroupId" : "EagleConsumer",
+ "fetchSize" : 1048586,
+ "deserializerClass" : "org.apache.eagle.security.hbase.HbaseAuditLogKafkaDeserializer",
+ "transactionZKServers" : "sandbox.hortonworks.com",
+ "transactionZKPort" : 2181,
+ "transactionZKRoot" : "/consumers",
+ "consumerGroupId" : "eagle.hbasesecurity.consumer",
+ "transactionStateUpdateMS" : 2000
+ },
+ "alertExecutorConfigs" : {
+ "hbaseSecurityLogAlertExecutor" : {
+ "parallelism" : 1,
+ "partitioner" : "org.apache.eagle.policy.DefaultPolicyPartitioner"
+ "needValidation" : "true"
+ }
+ },
+ "eagleProps" : {
+ "site" : "sandbox",
+ "application": "hbaseSecurityLog",
+ "dataJoinPollIntervalSec" : 30,
+ "mailHost" : "smtp.office365.com",
+ "mailSmtpPort":"587",
+ "mailSmtpAuth" : "true",
+ "mailSmtpUser" : "username",
+ "mailSmtpPassword" : "password",
+ #"mailSmtpSslEnable" : "true",
+ "mailSmtpTlsEnable" : "true",
+ "mailDebug" : "true",
+ "eagleService": {
+ "host": "localhost",
+ "port": 9098
+ "username": "admin",
+ "password": "secret"
+ }
+ },
+ "dynamicConfigSource" : {
+ "enabled" : true,
+ "initDelayMillis" : 0,
+ "delayMillis" : 30000
+ }
+ "metadata":{
+ "jdbc":{
+ "driverClassName":"org.h2.Driver"
+ "url":"jdbc:h2:./eagle-test"
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-security/eagle-security-hbase-auditlog/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-hbase-auditlog/pom.xml b/eagle-security/eagle-security-hbase-auditlog/pom.xml
index 42b9e86..46d67b5 100644
--- a/eagle-security/eagle-security-hbase-auditlog/pom.xml
+++ b/eagle-security/eagle-security-hbase-auditlog/pom.xml
@@ -44,10 +44,5 @@
<artifactId>eagle-app-base</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.eagle</groupId>
- <artifactId>eagle-metadata-jdbc</artifactId>
- <version>${project.version}</version>
- </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-security/eagle-security-hbase-auditlog/src/main/java/org/apache/eagle/security/hbase/HBaseAuditLogAppProvider.java
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-hbase-auditlog/src/main/java/org/apache/eagle/security/hbase/HBaseAuditLogAppProvider.java b/eagle-security/eagle-security-hbase-auditlog/src/main/java/org/apache/eagle/security/hbase/HBaseAuditLogAppProvider.java
index 3da2c98..dd672a5 100644
--- a/eagle-security/eagle-security-hbase-auditlog/src/main/java/org/apache/eagle/security/hbase/HBaseAuditLogAppProvider.java
+++ b/eagle-security/eagle-security-hbase-auditlog/src/main/java/org/apache/eagle/security/hbase/HBaseAuditLogAppProvider.java
@@ -23,7 +23,7 @@ import com.google.inject.AbstractModule;
import org.apache.eagle.app.spi.AbstractApplicationProvider;
import org.apache.eagle.common.module.ModuleRegistry;
import org.apache.eagle.metadata.service.memory.MemoryMetadataStore;
-import org.apache.eagle.metadata.store.mysql.MySQLMetadataStore;
+import org.apache.eagle.metadata.store.jdbc.JDBCMetadataStore;
import org.apache.eagle.security.service.ISecurityMetadataDAO;
import org.apache.eagle.security.service.InMemMetadataDaoImpl;
import org.apache.eagle.security.service.JDBCSecurityMetadataDAO;
@@ -46,7 +46,7 @@ public class HBaseAuditLogAppProvider extends AbstractApplicationProvider<HBaseA
}
});
- registry.register(MySQLMetadataStore.class, new AbstractModule() {
+ registry.register(JDBCMetadataStore.class, new AbstractModule() {
@Override
protected void configure() {
bind(ISecurityMetadataDAO.class).to(JDBCSecurityMetadataDAO.class);
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/eagle-server/src/main/resources/application.conf
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/resources/application.conf b/eagle-server/src/main/resources/application.conf
index ff2d331..111b7ea 100644
--- a/eagle-server/src/main/resources/application.conf
+++ b/eagle-server/src/main/resources/application.conf
@@ -41,8 +41,13 @@
},
"metadata":{
"store": "org.apache.eagle.metadata.service.memory.MemoryMetadataStore"
+ "jdbc":{
+ "username": "root"
+ "password": null
+ "driverClassName":"com.mysql.jdbc.Driver"
+ "url":"jdbc:mysql://server.eagle.apache.org:3306/eagle"
+ }
},
- "connection":"jdbc:mysql://server.eagle.apache.org:3306/eagle",
"application":{
"sink":{
"type": "org.apache.eagle.app.sink.KafkaStreamSink"
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/43d229ee/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c49e64b..100c2f2 100755
--- a/pom.xml
+++ b/pom.xml
@@ -279,7 +279,7 @@
<!-- Testing -->
<junit.version>4.12</junit.version>
<junit-benchmarks.version>0.7.0</junit-benchmarks.version>
- <h2.version>1.3.172</h2.version>
+ <h2.version>1.4.192</h2.version>
<scalatest.version>2.2.4</scalatest.version>
<mockito.version>1.8.1-rc1</mockito.version>
<tomcat.embed.version>7.0.55</tomcat.embed.version>
@@ -727,7 +727,6 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>