aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-core
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2022-02-10 12:09:48 +0100
committersonartech <sonartech@sonarsource.com>2022-08-29 20:02:52 +0000
commit8961d0c0b80dd23b7ed01ea0f249282956374795 (patch)
treefb1ab3db4f1fdd2c27b6ba1398a06572822a1b25 /server/sonar-webserver-core
parent4d1bd03543c55e564151d55e3a4763b82bc8e512 (diff)
downloadsonarqube-8961d0c0b80dd23b7ed01ea0f249282956374795.tar.gz
sonarqube-8961d0c0b80dd23b7ed01ea0f249282956374795.zip
SONAR-17200 Move to HikariCP from Apache DBCP
Diffstat (limited to 'server/sonar-webserver-core')
-rw-r--r--server/sonar-webserver-core/build.gradle2
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/BaseSectionMBean.java56
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/DbConnectionSection.java63
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/DbConnectionSectionMBean.java28
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/StandaloneSystemSection.java1
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BaseSectionMBeanTest.java2
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/DbConnectionSectionTest.java21
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/FakeSection.java1
8 files changed, 31 insertions, 143 deletions
diff --git a/server/sonar-webserver-core/build.gradle b/server/sonar-webserver-core/build.gradle
index 622bbfb5a95..6443e5c4524 100644
--- a/server/sonar-webserver-core/build.gradle
+++ b/server/sonar-webserver-core/build.gradle
@@ -28,7 +28,7 @@ dependencies {
compile 'org.apache.httpcomponents:httpclient'
compile 'org.apache.logging.log4j:log4j-api'
compile 'org.apache.tomcat.embed:tomcat-embed-core'
- compile 'org.apache.commons:commons-dbcp2'
+ compile 'com.zaxxer:HikariCP'
compile 'org.slf4j:jul-to-slf4j'
compile 'org.slf4j:slf4j-api'
compile 'org.sonarsource.api.plugin:sonar-plugin-api'
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/BaseSectionMBean.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/BaseSectionMBean.java
deleted file mode 100644
index b5afeaff0e2..00000000000
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/BaseSectionMBean.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2022 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.platform.monitoring;
-
-import org.sonar.api.Startable;
-import org.sonar.process.Jmx;
-import org.sonar.process.systeminfo.SystemInfoSection;
-
-/**
- * Base implementation of a {@link SystemInfoSection}
- * that is exported as a JMX bean
- */
-public abstract class BaseSectionMBean implements SystemInfoSection, Startable {
-
- /**
- * Auto-registers to MBean server
- */
- @Override
- public void start() {
- Jmx.register(objectName(), this);
- }
-
- /**
- * Unregister, if needed
- */
- @Override
- public void stop() {
- Jmx.unregister(objectName());
- }
-
- String objectName() {
- return "SonarQube:name=" + name();
- }
-
- /**
- * Name of section in System Info page
- */
- abstract String name();
-}
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/DbConnectionSection.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/DbConnectionSection.java
index 8c59cbc0128..4d55ae46693 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/DbConnectionSection.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/DbConnectionSection.java
@@ -19,9 +19,9 @@
*/
package org.sonar.server.platform.monitoring;
-import org.apache.commons.dbcp2.BasicDataSource;
import org.sonar.api.SonarQubeSide;
import org.sonar.api.SonarRuntime;
+import org.sonar.db.DatabaseMBean;
import org.sonar.db.DbClient;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo.Section;
import org.sonar.server.platform.db.migration.version.DatabaseVersion;
@@ -31,15 +31,14 @@ import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
/**
* Information about database connection pool
*/
-public class DbConnectionSection extends BaseSectionMBean implements DbConnectionSectionMBean {
+public class DbConnectionSection extends DatabaseMBean implements DbConnectionSectionMBean {
private final DatabaseVersion dbVersion;
- private final DbClient dbClient;
private final SonarRuntime runtime;
public DbConnectionSection(DatabaseVersion dbVersion, DbClient dbClient, SonarRuntime runtime) {
+ super(dbClient);
this.dbVersion = dbVersion;
- this.dbClient = dbClient;
this.runtime = runtime;
}
@@ -54,51 +53,6 @@ public class DbConnectionSection extends BaseSectionMBean implements DbConnectio
}
@Override
- public int getPoolActiveConnections() {
- return commonsDbcp().getNumActive();
- }
-
- @Override
- public int getPoolMaxActiveConnections() {
- return commonsDbcp().getMaxTotal();
- }
-
- @Override
- public int getPoolIdleConnections() {
- return commonsDbcp().getNumIdle();
- }
-
- @Override
- public int getPoolMaxIdleConnections() {
- return commonsDbcp().getMaxIdle();
- }
-
- @Override
- public int getPoolMinIdleConnections() {
- return commonsDbcp().getMinIdle();
- }
-
- @Override
- public int getPoolInitialSize() {
- return commonsDbcp().getInitialSize();
- }
-
- @Override
- public long getPoolMaxWaitMillis() {
- return commonsDbcp().getMaxWaitMillis();
- }
-
- @Override
- public boolean getPoolRemoveAbandoned() {
- return commonsDbcp().getRemoveAbandonedOnBorrow();
- }
-
- @Override
- public int getPoolRemoveAbandonedTimeoutSeconds() {
- return commonsDbcp().getRemoveAbandonedTimeout();
- }
-
- @Override
public Section toProtobuf() {
Section.Builder protobuf = Section.newBuilder();
String side = runtime.getSonarQubeSide() == SonarQubeSide.COMPUTE_ENGINE ? "Compute Engine" : "Web";
@@ -108,18 +62,13 @@ public class DbConnectionSection extends BaseSectionMBean implements DbConnectio
}
private void completePoolAttributes(Section.Builder protobuf) {
+ setAttribute(protobuf, "Pool Total Connections", getPoolTotalConnections());
setAttribute(protobuf, "Pool Active Connections", getPoolActiveConnections());
- setAttribute(protobuf, "Pool Max Connections", getPoolMaxActiveConnections());
- setAttribute(protobuf, "Pool Initial Size", getPoolInitialSize());
setAttribute(protobuf, "Pool Idle Connections", getPoolIdleConnections());
+ setAttribute(protobuf, "Pool Max Connections", getPoolMaxConnections());
setAttribute(protobuf, "Pool Min Idle Connections", getPoolMinIdleConnections());
- setAttribute(protobuf, "Pool Max Idle Connections", getPoolMaxIdleConnections());
setAttribute(protobuf, "Pool Max Wait (ms)", getPoolMaxWaitMillis());
- setAttribute(protobuf, "Pool Remove Abandoned", getPoolRemoveAbandoned());
- setAttribute(protobuf, "Pool Remove Abandoned Timeout (seconds)", getPoolRemoveAbandonedTimeoutSeconds());
+ setAttribute(protobuf, "Pool Max Lifetime (ms)", getPoolMaxLifeTimeMillis());
}
- private BasicDataSource commonsDbcp() {
- return (BasicDataSource) dbClient.getDatabase().getDataSource();
- }
}
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/DbConnectionSectionMBean.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/DbConnectionSectionMBean.java
index 59fccd64b46..44144825efc 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/DbConnectionSectionMBean.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/DbConnectionSectionMBean.java
@@ -27,21 +27,24 @@ public interface DbConnectionSectionMBean {
String getMigrationStatus();
/**
- *
+ * Get the number of currently active connections in the pool.
*/
int getPoolActiveConnections();
/**
- * The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.
+ * The maximum number of connections that can be allocated from this pool at the same time, or negative for no limit.
*/
- int getPoolMaxActiveConnections();
+ int getPoolMaxConnections();
- int getPoolIdleConnections();
+ /**
+ * Total number of connections currently in the pool
+ */
+ int getPoolTotalConnections();
/**
- * The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit.
+ * Get the number of currently idle connections in the pool.
*/
- int getPoolMaxIdleConnections();
+ int getPoolIdleConnections();
/**
* The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero to create none.
@@ -49,9 +52,9 @@ public interface DbConnectionSectionMBean {
int getPoolMinIdleConnections();
/**
- * The initial number of connections that are created when the pool is started.
+ * Maximum lifetime of a connection in the pool.
*/
- int getPoolInitialSize();
+ long getPoolMaxLifeTimeMillis();
/**
* The maximum number of milliseconds that the pool will wait
@@ -59,13 +62,4 @@ public interface DbConnectionSectionMBean {
*/
long getPoolMaxWaitMillis();
- /**
- * Flag to remove abandoned connections if they exceed the {@link #getPoolRemoveAbandonedTimeoutSeconds()}.
- */
- boolean getPoolRemoveAbandoned();
-
- /**
- * Timeout in seconds before an abandoned connection can be removed.
- */
- int getPoolRemoveAbandonedTimeoutSeconds();
}
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/StandaloneSystemSection.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/StandaloneSystemSection.java
index 0c728efc507..457b6377951 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/StandaloneSystemSection.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/StandaloneSystemSection.java
@@ -29,6 +29,7 @@ import org.sonar.api.platform.Server;
import org.sonar.api.security.SecurityRealm;
import org.sonar.api.server.authentication.IdentityProvider;
import org.sonar.core.util.stream.MoreCollectors;
+import org.sonar.process.systeminfo.BaseSectionMBean;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
import org.sonar.server.authentication.IdentityProviderRepository;
import org.sonar.server.log.ServerLogging;
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BaseSectionMBeanTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BaseSectionMBeanTest.java
index 556c5a7544f..cb2ed963626 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BaseSectionMBeanTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/BaseSectionMBeanTest.java
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BaseSectionMBeanTest {
- private FakeSection underTest = new FakeSection();
+ private final FakeSection underTest = new FakeSection();
@Test
public void test_registration() throws Exception {
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/DbConnectionSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/DbConnectionSectionTest.java
index 1363e1b15e2..1086c1c1a8e 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/DbConnectionSectionTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/DbConnectionSectionTest.java
@@ -38,9 +38,9 @@ public class DbConnectionSectionTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- private DatabaseVersion databaseVersion = mock(DatabaseVersion.class);
- private SonarRuntime runtime = mock(SonarRuntime.class);
- private DbConnectionSection underTest = new DbConnectionSection(databaseVersion, dbTester.getDbClient(), runtime);
+ private final DatabaseVersion databaseVersion = mock(DatabaseVersion.class);
+ private final SonarRuntime runtime = mock(SonarRuntime.class);
+ private final DbConnectionSection underTest = new DbConnectionSection(databaseVersion, dbTester.getDbClient(), runtime);
@Test
public void jmx_name_is_not_empty() {
@@ -50,13 +50,12 @@ public class DbConnectionSectionTest {
@Test
public void pool_info() {
ProtobufSystemInfo.Section section = underTest.toProtobuf();
- assertThat(attribute(section, "Pool Max Connections").getLongValue()).isGreaterThan(0L);
- assertThat(attribute(section, "Pool Idle Connections").getLongValue()).isGreaterThanOrEqualTo(0L);
- assertThat(attribute(section, "Pool Min Idle Connections").getLongValue()).isGreaterThanOrEqualTo(0L);
- assertThat(attribute(section, "Pool Max Idle Connections").getLongValue()).isGreaterThanOrEqualTo(0L);
- assertThat(attribute(section, "Pool Max Wait (ms)")).isNotNull();
- assertThat(attribute(section, "Pool Remove Abandoned")).isNotNull();
- assertThat(attribute(section, "Pool Remove Abandoned Timeout (seconds)").getLongValue()).isGreaterThanOrEqualTo(0L);
+ assertThat(attribute(section, "Pool Total Connections").getLongValue()).isNotNegative();
+ assertThat(attribute(section, "Pool Active Connections").getLongValue()).isNotNegative();
+ assertThat(attribute(section, "Pool Idle Connections").getLongValue()).isNotNegative();
+ assertThat(attribute(section, "Pool Max Connections").getLongValue()).isNotNegative();
+ assertThat(attribute(section, "Pool Min Idle Connections")).isNotNull();
+ assertThat(attribute(section, "Pool Max Lifetime (ms)")).isNotNull();
}
@Test
@@ -64,7 +63,7 @@ public class DbConnectionSectionTest {
when(runtime.getSonarQubeSide()).thenReturn(SonarQubeSide.COMPUTE_ENGINE);
assertThat(underTest.toProtobuf().getName()).isEqualTo("Compute Engine Database Connection");
- when(runtime.getSonarQubeSide()).thenReturn(SonarQubeSide.SERVER );
+ when(runtime.getSonarQubeSide()).thenReturn(SonarQubeSide.SERVER);
assertThat(underTest.toProtobuf().getName()).isEqualTo("Web Database Connection");
}
}
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/FakeSection.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/FakeSection.java
index efc1955fd27..6374fee3d5a 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/FakeSection.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/FakeSection.java
@@ -19,6 +19,7 @@
*/
package org.sonar.server.platform.monitoring;
+import org.sonar.process.systeminfo.BaseSectionMBean;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
public class FakeSection extends BaseSectionMBean implements FakeSectionMBean {