You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by rk...@apache.org on 2014/05/28 00:19:03 UTC

[2/3] git commit: OOZIE-1838 jdbc.connections.active sampler does not show up (rkanter)

OOZIE-1838 jdbc.connections.active sampler does not show up (rkanter)


Project: http://git-wip-us.apache.org/repos/asf/oozie/repo
Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/2a85bfe2
Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/2a85bfe2
Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/2a85bfe2

Branch: refs/heads/master
Commit: 2a85bfe253e8f289051797eddf4b52de0b9e475a
Parents: 503134a
Author: Robert Kanter <rk...@cloudera.com>
Authored: Tue May 27 14:06:19 2014 -0700
Committer: Robert Kanter <rk...@cloudera.com>
Committed: Tue May 27 14:06:19 2014 -0700

----------------------------------------------------------------------
 .../org/apache/oozie/service/JPAService.java    | 33 +++++++++++++++
 .../util/db/InstrumentedBasicDataSource.java    | 44 --------------------
 .../src/main/resources/META-INF/persistence.xml | 12 +++---
 release-log.txt                                 |  1 +
 4 files changed, 40 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oozie/blob/2a85bfe2/core/src/main/java/org/apache/oozie/service/JPAService.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/service/JPAService.java b/core/src/main/java/org/apache/oozie/service/JPAService.java
index aba8709..1b8f53e 100644
--- a/core/src/main/java/org/apache/oozie/service/JPAService.java
+++ b/core/src/main/java/org/apache/oozie/service/JPAService.java
@@ -30,6 +30,7 @@ import javax.persistence.Persistence;
 import javax.persistence.PersistenceException;
 import javax.persistence.Query;
 
+import org.apache.commons.dbcp.BasicDataSource;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.oozie.BundleActionBean;
 import org.apache.oozie.BundleJobBean;
@@ -51,6 +52,7 @@ import org.apache.oozie.util.IOUtils;
 import org.apache.oozie.util.Instrumentable;
 import org.apache.oozie.util.Instrumentation;
 import org.apache.oozie.util.XLog;
+import org.apache.openjpa.lib.jdbc.DecoratingDataSource;
 import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
 
 /**
@@ -94,6 +96,37 @@ public class JPAService implements Service, Instrumentable {
     @Override
     public void instrument(Instrumentation instr) {
         this.instr = instr;
+
+        final BasicDataSource dataSource = getBasicDataSource();
+        if (dataSource != null) {
+            instr.addSampler("jdbc", "connections.active", 60, 1, new Instrumentation.Variable<Long>() {
+                @Override
+                public Long getValue() {
+                    return (long) dataSource.getNumActive();
+                }
+            });
+            instr.addSampler("jdbc", "connections.idle", 60, 1, new Instrumentation.Variable<Long>() {
+                @Override
+                public Long getValue() {
+                    return (long) dataSource.getNumIdle();
+                }
+            });
+        }
+    }
+
+    private BasicDataSource getBasicDataSource() {
+        // Get the BasicDataSource object; it could be wrapped in a DecoratingDataSource
+        // It might also not be a BasicDataSource if the user configured something different
+        BasicDataSource basicDataSource = null;
+        OpenJPAEntityManagerFactorySPI spi = (OpenJPAEntityManagerFactorySPI) factory;
+        Object connectionFactory = spi.getConfiguration().getConnectionFactory();
+        if (connectionFactory instanceof DecoratingDataSource) {
+            DecoratingDataSource decoratingDataSource = (DecoratingDataSource) connectionFactory;
+            basicDataSource = (BasicDataSource) decoratingDataSource.getInnermostDelegate();
+        } else if (connectionFactory instanceof BasicDataSource) {
+            basicDataSource = (BasicDataSource) connectionFactory;
+        }
+        return basicDataSource;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/oozie/blob/2a85bfe2/core/src/main/java/org/apache/oozie/util/db/InstrumentedBasicDataSource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/oozie/util/db/InstrumentedBasicDataSource.java b/core/src/main/java/org/apache/oozie/util/db/InstrumentedBasicDataSource.java
deleted file mode 100644
index 2705704..0000000
--- a/core/src/main/java/org/apache/oozie/util/db/InstrumentedBasicDataSource.java
+++ /dev/null
@@ -1,44 +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
- * 
- *      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.oozie.util.db;
-
-import org.apache.commons.dbcp.BasicDataSource;
-import org.apache.oozie.service.InstrumentationService;
-import org.apache.oozie.service.Services;
-import org.apache.oozie.util.Instrumentation;
-
-public class InstrumentedBasicDataSource extends BasicDataSource {
-    public static final String INSTR_GROUP = "jdbc";
-    public static final String INSTR_NAME = "connections.active";
-
-    /**
-     * The created datasource instruments the active DB connections.
-     */
-    public InstrumentedBasicDataSource() {
-        InstrumentationService instrumentationService = Services.get().get(InstrumentationService.class);
-        if (instrumentationService != null) {
-            Instrumentation instr = instrumentationService.get();
-            instr.addSampler(INSTR_GROUP, INSTR_NAME, 60, 1, new Instrumentation.Variable<Long>() {
-                public Long getValue() {
-                    return (long) getNumActive();
-                }
-            });
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/oozie/blob/2a85bfe2/core/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/persistence.xml b/core/src/main/resources/META-INF/persistence.xml
index a9b79f4..edda2d5 100644
--- a/core/src/main/resources/META-INF/persistence.xml
+++ b/core/src/main/resources/META-INF/persistence.xml
@@ -43,7 +43,7 @@
         <class>org.apache.oozie.util.db.ValidateConnectionBean</class>
 
         <properties>
-            <property name="openjpa.ConnectionDriverName" value="org.apache.oozie.util.db.InstrumentedBasicDataSource"/>
+            <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
 
             <property name="openjpa.ConnectionProperties" value="**INVALID**"/> <!--Set by StoreService at init time -->
 
@@ -102,7 +102,7 @@
         <class>org.apache.oozie.util.db.ValidateConnectionBean</class>
 
         <properties>
-            <property name="openjpa.ConnectionDriverName" value="org.apache.oozie.util.db.InstrumentedBasicDataSource"/>
+            <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
 
             <property name="openjpa.ConnectionProperties" value="**INVALID**"/> <!--Set by StoreService at init time -->
 
@@ -163,7 +163,7 @@
         <class>org.apache.oozie.util.db.ValidateConnectionBean</class>
 
         <properties>
-            <property name="openjpa.ConnectionDriverName" value="org.apache.oozie.util.db.InstrumentedBasicDataSource"/>
+            <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
 
             <property name="openjpa.ConnectionProperties" value="**INVALID**"/> <!--Set by StoreService at init time -->
 
@@ -222,7 +222,7 @@
         <class>org.apache.oozie.util.db.ValidateConnectionBean</class>
 
         <properties>
-            <property name="openjpa.ConnectionDriverName" value="org.apache.oozie.util.db.InstrumentedBasicDataSource"/>
+            <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
 
             <property name="openjpa.ConnectionProperties" value="**INVALID**"/> <!--Set by StoreService at init time -->
 
@@ -282,7 +282,7 @@
         <class>org.apache.oozie.util.db.ValidateConnectionBean</class>
 
         <properties>
-            <property name="openjpa.ConnectionDriverName" value="org.apache.oozie.util.db.InstrumentedBasicDataSource"/>
+            <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
 
             <property name="openjpa.ConnectionProperties" value="**INVALID**"/> <!--Set by StoreService at init time -->
 
@@ -342,7 +342,7 @@
         <class>org.apache.oozie.util.db.ValidateConnectionBean</class>
 
         <properties>
-            <property name="openjpa.ConnectionDriverName" value="org.apache.oozie.util.db.InstrumentedBasicDataSource"/>
+            <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
 
             <property name="openjpa.ConnectionProperties" value="**INVALID**"/> <!--Set by StoreService at init time -->
 

http://git-wip-us.apache.org/repos/asf/oozie/blob/2a85bfe2/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 04cc79a..008c089 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
 -- Oozie 4.1.0 release (trunk - unreleased)
 
+OOZIE-1838 jdbc.connections.active sampler does not show up (rkanter)
 OOZIE-1801 ZKLocksService instrumentation should say how many locks this server has (rkanter)
 OOZIE-1819 Avoid early queueing of CoordActionInputCheckXCommand (shwethags via rohini)
 OOZIE-1783 Sharelib purging only occurs at Oozie startup (rkanter)