aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-03-31 12:20:55 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-04-05 09:58:04 +0200
commit975158a5a726aa67c093f85779ac2c97efd03bb8 (patch)
treef2feb4851f4a0e2a6723e20d182413a01aeffade /server/sonar-server
parent87d559b07cdc6727dafe0c9e1286b30c8e7867ea (diff)
downloadsonarqube-975158a5a726aa67c093f85779ac2c97efd03bb8.tar.gz
sonarqube-975158a5a726aa67c093f85779ac2c97efd03bb8.zip
SONAR-7436 replace JMX/RMI by HTTP
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/pom.xml9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/CeModule.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeDatabaseMBean.java (renamed from server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsStateMonitor.java)53
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeDatabaseMBeanImpl.java22
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeTasksMBean.java (renamed from server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeStateMonitor.java)65
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeTasksMBeanImpl.java20
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/BaseMonitorMBean.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeDatabaseMonitor.java65
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeTasksMonitor.java62
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/DatabaseMonitor.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java22
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/JmxConnectionFactoryProvider.java46
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/JvmPropsMonitor.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/Monitor.java8
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/PluginsMonitor.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/ProcessSystemInfoClient.java61
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SystemMonitor.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java45
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/monitoring/CeDatabaseMBeanImplTest.java70
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/monitoring/CeTasksMBeanImplTest.java9
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeDatabaseMonitorTest.java61
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeStateMonitorTest.java61
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeTasksMonitorTest.java61
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/DatabaseMonitorTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java22
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsStateMonitorTest.java60
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/FakeMonitor.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/JmxConnectionFactoryProviderTest.java56
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/JvmPropsMonitorTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/PluginsMonitorTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/ProcessSystemInfoClientTest.java99
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SonarQubeMonitorTest.java17
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SystemMonitorTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java15
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java5
37 files changed, 431 insertions, 644 deletions
diff --git a/server/sonar-server/pom.xml b/server/sonar-server/pom.xml
index 2b1a4860dbb..12253497147 100644
--- a/server/sonar-server/pom.xml
+++ b/server/sonar-server/pom.xml
@@ -160,6 +160,10 @@
<artifactId>elasticsearch</artifactId>
</dependency>
<dependency>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ </dependency>
+ <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sonar-ws</artifactId>
<version>${project.version}</version>
@@ -223,6 +227,11 @@
<artifactId>subethasmtp</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.squareup.okhttp</groupId>
+ <artifactId>mockwebserver</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/CeModule.java b/server/sonar-server/src/main/java/org/sonar/server/computation/CeModule.java
index 4cdf80747d4..2051a4929e2 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/CeModule.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/CeModule.java
@@ -22,6 +22,8 @@ package org.sonar.server.computation;
import org.sonar.ce.log.CeLogging;
import org.sonar.core.platform.Module;
import org.sonar.db.purge.period.DefaultPeriodCleaner;
+import org.sonar.process.systeminfo.ProcessStateSystemInfo;
+import org.sonar.process.systeminfo.SystemInfoHttpServer;
import org.sonar.server.computation.configuration.CeConfigurationImpl;
import org.sonar.server.computation.dbcleaner.IndexPurgeListener;
import org.sonar.server.computation.dbcleaner.ProjectCleaner;
@@ -37,6 +39,8 @@ public class CeModule extends Module {
CeConfigurationImpl.class,
CeLogging.class,
CeDatabaseMBeanImpl.class,
+ SystemInfoHttpServer.class,
+ new ProcessStateSystemInfo("Compute Engine State"),
DefaultPeriodCleaner.class,
ProjectCleaner.class,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsStateMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeDatabaseMBean.java
index 779019be924..6f20edc66c4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsStateMonitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeDatabaseMBean.java
@@ -17,34 +17,27 @@
* 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 com.google.common.base.Optional;
-import java.util.Map;
-import org.sonar.process.ProcessId;
-import org.sonar.process.jmx.JmxConnection;
-import org.sonar.process.jmx.JmxConnectionFactory;
-
-public class EsStateMonitor implements Monitor {
-
- private final JmxConnectionFactory jmxConnectionFactory;
-
- public EsStateMonitor(JmxConnectionFactory jmxConnectionFactory) {
- this.jmxConnectionFactory = jmxConnectionFactory;
- }
-
- @Override
- public String name() {
- return "Elasticsearch State";
- }
-
- @Override
- public Optional<Map<String, Object>> attributes() {
- try (JmxConnection connection = jmxConnectionFactory.create(ProcessId.ELASTICSEARCH)) {
- if (connection == null) {
- return Optional.absent();
- }
- return Optional.of(connection.getSystemState());
- }
- }
+package org.sonar.server.computation.monitoring;
+
+public interface CeDatabaseMBean {
+
+ String OBJECT_NAME = "SonarQube:name=ComputeEngineDatabaseConnection";
+
+ int getPoolActiveConnections();
+
+ int getPoolMaxActiveConnections();
+
+ int getPoolIdleConnections();
+
+ int getPoolMaxIdleConnections();
+
+ int getPoolMinIdleConnections();
+
+ int getPoolInitialSize();
+
+ long getPoolMaxWaitMillis();
+
+ boolean getPoolRemoveAbandoned();
+
+ int getPoolRemoveAbandonedTimeoutSeconds();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeDatabaseMBeanImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeDatabaseMBeanImpl.java
index 4b7e43a3fa5..e0315abcad4 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeDatabaseMBeanImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeDatabaseMBeanImpl.java
@@ -22,10 +22,11 @@ package org.sonar.server.computation.monitoring;
import org.apache.commons.dbcp.BasicDataSource;
import org.picocontainer.Startable;
import org.sonar.db.DbClient;
-import org.sonar.process.jmx.CeDatabaseMBean;
-import org.sonar.process.jmx.Jmx;
+import org.sonar.process.Jmx;
+import org.sonar.process.systeminfo.SystemInfoSection;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
-public class CeDatabaseMBeanImpl implements CeDatabaseMBean, Startable {
+public class CeDatabaseMBeanImpl implements CeDatabaseMBean, Startable, SystemInfoSection {
private final DbClient dbClient;
public CeDatabaseMBeanImpl(DbClient dbClient) {
@@ -94,4 +95,19 @@ public class CeDatabaseMBeanImpl implements CeDatabaseMBean, Startable {
return (BasicDataSource) dbClient.getDatabase().getDataSource();
}
+ @Override
+ public ProtobufSystemInfo.Section toProtobuf() {
+ ProtobufSystemInfo.Section.Builder builder = ProtobufSystemInfo.Section.newBuilder();
+ builder.setName("Compute Engine Database Connection");
+ builder.addAttributesBuilder().setKey("Pool Initial Size").setLongValue(getPoolInitialSize()).build();
+ builder.addAttributesBuilder().setKey("Pool Active Connections").setLongValue(getPoolActiveConnections()).build();
+ builder.addAttributesBuilder().setKey("Pool Idle Connections").setLongValue(getPoolIdleConnections()).build();
+ builder.addAttributesBuilder().setKey("Pool Max Active Connections").setLongValue(getPoolMaxActiveConnections()).build();
+ builder.addAttributesBuilder().setKey("Pool Max Idle Connections").setLongValue(getPoolMaxIdleConnections()).build();
+ builder.addAttributesBuilder().setKey("Pool Min Idle Connections").setLongValue(getPoolMinIdleConnections()).build();
+ builder.addAttributesBuilder().setKey("Pool Max Wait (ms)").setLongValue(getPoolMaxWaitMillis()).build();
+ builder.addAttributesBuilder().setKey("Pool Remove Abandoned").setBooleanValue(getPoolRemoveAbandoned()).build();
+ builder.addAttributesBuilder().setKey("Pool Remove Abandoned Timeout (sec)").setLongValue(getPoolRemoveAbandonedTimeoutSeconds()).build();
+ return builder.build();
+ }
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeStateMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeTasksMBean.java
index d920607edb6..227e9f6be8c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeStateMonitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeTasksMBean.java
@@ -17,34 +17,39 @@
* 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 com.google.common.base.Optional;
-import java.util.Map;
-import org.sonar.process.ProcessId;
-import org.sonar.process.jmx.JmxConnection;
-import org.sonar.process.jmx.JmxConnectionFactory;
-
-public class CeStateMonitor implements Monitor {
-
- private final JmxConnectionFactory jmxConnectionFactory;
-
- public CeStateMonitor(JmxConnectionFactory jmxConnectionFactory) {
- this.jmxConnectionFactory = jmxConnectionFactory;
- }
-
- @Override
- public String name() {
- return "Compute Engine State";
- }
-
- @Override
- public Optional<Map<String, Object>> attributes() {
- try (JmxConnection connection = jmxConnectionFactory.create(ProcessId.COMPUTE_ENGINE)) {
- if (connection == null) {
- return Optional.absent();
- }
- return Optional.of(connection.getSystemState());
- }
- }
+package org.sonar.server.computation.monitoring;
+
+public interface CeTasksMBean {
+
+ String OBJECT_NAME = "SonarQube:name=ComputeEngineTasks";
+
+ /**
+ * Count of batch reports waiting for processing since startup, including reports received before instance startup.
+ */
+ long getPendingCount();
+
+ /**
+ * Count of batch reports under processing.
+ */
+ long getInProgressCount();
+
+ /**
+ * Count of batch reports which processing ended with an error since instance startup.
+ */
+ long getErrorCount();
+
+ /**
+ * Count of batch reports which processing ended successfully since instance startup.
+ */
+ long getSuccessCount();
+
+ /**
+ * Time spent processing reports since startup, in milliseconds.
+ */
+ long getProcessingTime();
+
+ /**
+ * Configured number of Workers.
+ */
+ int getWorkerCount();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeTasksMBeanImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeTasksMBeanImpl.java
index 57b08e356de..df7e68ec989 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeTasksMBeanImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/monitoring/CeTasksMBeanImpl.java
@@ -21,11 +21,12 @@ package org.sonar.server.computation.monitoring;
import org.picocontainer.Startable;
import org.sonar.ce.monitoring.CEQueueStatus;
-import org.sonar.process.jmx.CeTasksMBean;
-import org.sonar.process.jmx.Jmx;
+import org.sonar.process.Jmx;
+import org.sonar.process.systeminfo.SystemInfoSection;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
import org.sonar.server.computation.configuration.CeConfiguration;
-public class CeTasksMBeanImpl implements CeTasksMBean, Startable {
+public class CeTasksMBeanImpl implements CeTasksMBean, Startable, SystemInfoSection {
private final CEQueueStatus queueStatus;
private final CeConfiguration ceConfiguration;
@@ -76,4 +77,17 @@ public class CeTasksMBeanImpl implements CeTasksMBean, Startable {
public int getWorkerCount() {
return ceConfiguration.getWorkerCount();
}
+
+ @Override
+ public ProtobufSystemInfo.Section toProtobuf() {
+ ProtobufSystemInfo.Section.Builder builder = ProtobufSystemInfo.Section.newBuilder();
+ builder.setName("Compute Engine Tasks");
+ builder.addAttributesBuilder().setKey("Pending").setLongValue(getPendingCount()).build();
+ builder.addAttributesBuilder().setKey("In Progress").setLongValue(getInProgressCount()).build();
+ builder.addAttributesBuilder().setKey("Processed With Error").setLongValue(getErrorCount()).build();
+ builder.addAttributesBuilder().setKey("Processed With Success").setLongValue(getSuccessCount()).build();
+ builder.addAttributesBuilder().setKey("Processing Time (ms)").setLongValue(getProcessingTime()).build();
+ builder.addAttributesBuilder().setKey("Worker Count").setLongValue(getWorkerCount()).build();
+ return builder.build();
+ }
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/BaseMonitorMBean.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/BaseMonitorMBean.java
index b56d9a9346e..44f63304eec 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/BaseMonitorMBean.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/BaseMonitorMBean.java
@@ -20,7 +20,7 @@
package org.sonar.server.platform.monitoring;
import org.picocontainer.Startable;
-import org.sonar.process.jmx.Jmx;
+import org.sonar.process.Jmx;
/**
* Base implementation of a {@link org.sonar.server.platform.monitoring.Monitor}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeDatabaseMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeDatabaseMonitor.java
deleted file mode 100644
index 052d3ff5634..00000000000
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeDatabaseMonitor.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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 com.google.common.base.Optional;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.sonar.process.ProcessId;
-import org.sonar.process.jmx.CeDatabaseMBean;
-import org.sonar.process.jmx.JmxConnection;
-import org.sonar.process.jmx.JmxConnectionFactory;
-
-public class CeDatabaseMonitor implements Monitor {
-
- private static final int NUMBER_OF_ATTRIBUTES = 9;
-
- private final JmxConnectionFactory jmxConnectionFactory;
-
- public CeDatabaseMonitor(JmxConnectionFactory jmxConnectionFactory) {
- this.jmxConnectionFactory = jmxConnectionFactory;
- }
-
- @Override
- public String name() {
- return "Compute Engine Database Connection";
- }
-
- @Override
- public Optional<Map<String, Object>> attributes() {
- try (JmxConnection connection = jmxConnectionFactory.create(ProcessId.COMPUTE_ENGINE)) {
- if (connection == null) {
- return Optional.absent();
- }
- Map<String, Object> result = new LinkedHashMap<>(NUMBER_OF_ATTRIBUTES);
- CeDatabaseMBean mbean = connection.getMBean(CeDatabaseMBean.OBJECT_NAME, CeDatabaseMBean.class);
- result.put("Pool Initial Size", mbean.getPoolInitialSize());
- result.put("Pool Active Connections", mbean.getPoolActiveConnections());
- result.put("Pool Idle Connections", mbean.getPoolIdleConnections());
- result.put("Pool Max Active Connections", mbean.getPoolMaxActiveConnections());
- result.put("Pool Max Idle Connections", mbean.getPoolMaxIdleConnections());
- result.put("Pool Min Idle Connections", mbean.getPoolMinIdleConnections());
- result.put("Pool Max Wait (ms)", mbean.getPoolMaxWaitMillis());
- result.put("Pool Remove Abandoned", mbean.getPoolRemoveAbandoned());
- result.put("Pool Remove Abandoned Timeout (sec)", mbean.getPoolRemoveAbandonedTimeoutSeconds());
- return Optional.of(result);
- }
- }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeTasksMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeTasksMonitor.java
deleted file mode 100644
index fbdd08ba5dd..00000000000
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/CeTasksMonitor.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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 com.google.common.base.Optional;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.sonar.process.ProcessId;
-import org.sonar.process.jmx.CeTasksMBean;
-import org.sonar.process.jmx.JmxConnection;
-import org.sonar.process.jmx.JmxConnectionFactory;
-
-public class CeTasksMonitor implements Monitor {
-
- private static final int NUMBER_OF_ATTRIBUTES = 6;
-
- private final JmxConnectionFactory jmxConnectionFactory;
-
- public CeTasksMonitor(JmxConnectionFactory jmxConnectionFactory) {
- this.jmxConnectionFactory = jmxConnectionFactory;
- }
-
- @Override
- public String name() {
- return "Compute Engine Tasks";
- }
-
- @Override
- public Optional<Map<String, Object>> attributes() {
- try (JmxConnection connection = jmxConnectionFactory.create(ProcessId.COMPUTE_ENGINE)) {
- if (connection == null) {
- return Optional.absent();
- }
- Map<String, Object> result = new LinkedHashMap<>(NUMBER_OF_ATTRIBUTES);
- CeTasksMBean ceMBean = connection.getMBean(CeTasksMBean.OBJECT_NAME, CeTasksMBean.class);
- result.put("Pending", ceMBean.getPendingCount());
- result.put("In Progress", ceMBean.getInProgressCount());
- result.put("Processed With Success", ceMBean.getSuccessCount());
- result.put("Processed With Error", ceMBean.getErrorCount());
- result.put("Processing Time (ms)", ceMBean.getProcessingTime());
- result.put("Worker Count", ceMBean.getWorkerCount());
- return Optional.of(result);
- }
- }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/DatabaseMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/DatabaseMonitor.java
index f71f841b6e6..4e957180552 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/DatabaseMonitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/DatabaseMonitor.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.platform.monitoring;
-import com.google.common.base.Optional;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
@@ -101,11 +100,11 @@ public class DatabaseMonitor extends BaseMonitorMBean implements DatabaseMonitor
}
@Override
- public Optional<Map<String, Object>> attributes() {
+ public Map<String, Object> attributes() {
Map<String, Object> attributes = new LinkedHashMap<>();
completeDbAttributes(attributes);
completePoolAttributes(attributes);
- return Optional.of(attributes);
+ return attributes;
}
private void completePoolAttributes(Map<String, Object> attributes) {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java
index 686ae56880a..7f37d2b0f31 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/EsMonitor.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.platform.monitoring;
-import com.google.common.base.Optional;
import java.util.LinkedHashMap;
import java.util.Map;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
@@ -30,21 +29,15 @@ import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.breaker.CircuitBreaker;
-import org.sonar.process.ProcessId;
-import org.sonar.process.jmx.EsSettingsMBean;
-import org.sonar.process.jmx.JmxConnection;
-import org.sonar.process.jmx.JmxConnectionFactory;
import org.sonar.server.es.EsClient;
import static org.apache.commons.io.FileUtils.byteCountToDisplaySize;
public class EsMonitor extends BaseMonitorMBean implements EsMonitorMBean {
- private final JmxConnectionFactory jmxConnectionFactory;
private final EsClient esClient;
- public EsMonitor(JmxConnectionFactory jmxConnectionFactory, EsClient esClient) {
- this.jmxConnectionFactory = jmxConnectionFactory;
+ public EsMonitor(EsClient esClient) {
this.esClient = esClient;
}
@@ -72,22 +65,13 @@ public class EsMonitor extends BaseMonitorMBean implements EsMonitorMBean {
}
@Override
- public Optional<Map<String, Object>> attributes() {
+ public Map<String, Object> attributes() {
Map<String, Object> attributes = new LinkedHashMap<>();
-
- try (JmxConnection connection = jmxConnectionFactory.create(ProcessId.ELASTICSEARCH)) {
- if (connection != null) {
- EsSettingsMBean mbean = connection.getMBean(EsSettingsMBean.OBJECT_NAME, EsSettingsMBean.class);
- attributes.put("Cluster Name", mbean.getClusterName());
- attributes.put("Node Name", mbean.getNodeName());
- attributes.put("HTTP Port", mbean.getHttpPort());
- }
- }
attributes.put("State", getStateAsEnum());
attributes.put("Indices", indexAttributes());
attributes.put("Number of Nodes", getNumberOfNodes());
attributes.put("Nodes", nodeAttributes());
- return Optional.of(attributes);
+ return attributes;
}
private LinkedHashMap<String, LinkedHashMap<String, Object>> indexAttributes() {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/JmxConnectionFactoryProvider.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/JmxConnectionFactoryProvider.java
deleted file mode 100644
index ebc98c1dddf..00000000000
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/JmxConnectionFactoryProvider.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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 java.io.File;
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.config.Settings;
-import org.sonar.process.jmx.JmxConnectionFactory;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH;
-
-public class JmxConnectionFactoryProvider extends ProviderAdapter {
-
- private JmxConnectionFactory singleton = null;
-
- public synchronized JmxConnectionFactory provide(Settings settings) {
- if (singleton == null) {
- singleton = new JmxConnectionFactory(nonNullValueAsFile(settings, PROPERTY_SHARED_PATH));
- }
- return singleton;
- }
-
- private static File nonNullValueAsFile(Settings settings, String key) {
- String s = settings.getString(key);
- checkArgument(s != null, "Property %s is not set", key);
- return new File(s);
- }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/JvmPropsMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/JvmPropsMonitor.java
index 26f642b7e6b..d49a1e172d5 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/JvmPropsMonitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/JvmPropsMonitor.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.platform.monitoring;
-import com.google.common.base.Optional;
import java.util.Map;
import java.util.Objects;
import java.util.TreeMap;
@@ -31,11 +30,11 @@ public class JvmPropsMonitor implements Monitor {
}
@Override
- public Optional<Map<String, Object>> attributes() {
+ public Map<String, Object> attributes() {
Map<String, Object> sortedProps = new TreeMap<>();
for (Map.Entry<Object, Object> systemProp : System.getProperties().entrySet()) {
sortedProps.put(Objects.toString(systemProp.getKey()), Objects.toString(systemProp.getValue()));
}
- return Optional.of(sortedProps);
+ return sortedProps;
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/Monitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/Monitor.java
index d4d6808865a..a268b43e5fe 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/Monitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/Monitor.java
@@ -19,9 +19,7 @@
*/
package org.sonar.server.platform.monitoring;
-import com.google.common.base.Optional;
import java.util.Map;
-import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
import org.sonar.server.platform.ws.InfoAction;
@@ -29,7 +27,6 @@ import org.sonar.server.platform.ws.InfoAction;
* Any component that is involved in the information returned by the web service api/system/info
*/
@ServerSide
-@ComputeEngineSide
public interface Monitor {
/**
* Name of section in System Info page
@@ -39,9 +36,6 @@ public interface Monitor {
/**
* Type of attribute values must be supported by {@link org.sonar.api.utils.text.JsonWriter#valueObject(Object)}
* because of JSON export by {@link InfoAction}.
- *
- * @return map of attributes, or Optional.absent() if the monitored component is not up. In the latter case
- * nothing is returned in the web service api/system/info.
*/
- Optional<Map<String, Object>> attributes();
+ Map<String, Object> attributes();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/PluginsMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/PluginsMonitor.java
index 6edb3cef096..afed7b16f48 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/PluginsMonitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/PluginsMonitor.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.platform.monitoring;
-import com.google.common.base.Optional;
import java.util.LinkedHashMap;
import java.util.Map;
import org.sonar.core.platform.PluginInfo;
@@ -42,7 +41,7 @@ public class PluginsMonitor implements Monitor {
}
@Override
- public Optional<Map<String, Object>> attributes() {
+ public Map<String, Object> attributes() {
Map<String, Object> attributes = new LinkedHashMap<>();
for (PluginInfo plugin : repository.getPluginInfos()) {
LinkedHashMap<String, Object> pluginAttributes = new LinkedHashMap<>();
@@ -53,6 +52,6 @@ public class PluginsMonitor implements Monitor {
}
attributes.put(plugin.getKey(), pluginAttributes);
}
- return Optional.of(attributes);
+ return attributes;
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/ProcessSystemInfoClient.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/ProcessSystemInfoClient.java
new file mode 100644
index 00000000000..3968a2792a0
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/ProcessSystemInfoClient.java
@@ -0,0 +1,61 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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 com.google.common.base.Optional;
+import java.io.File;
+import java.net.URI;
+import org.apache.commons.io.IOUtils;
+import org.sonar.api.config.Settings;
+import org.sonar.process.DefaultProcessCommands;
+import org.sonar.process.ProcessId;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+
+import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH;
+
+/**
+ * Connects to the System Info HTTP server of another JVM process.
+ */
+public class ProcessSystemInfoClient {
+
+ private final File ipcSharedDir;
+
+ public ProcessSystemInfoClient(Settings props) {
+ this.ipcSharedDir = new File(props.getString(PROPERTY_SHARED_PATH));
+ }
+
+ /**
+ * Connects to the specified JVM process and requests system information.
+ * @return the system info, or absent if the process is not up or if its HTTP URL
+ * is not registered into IPC.
+ */
+ public Optional<ProtobufSystemInfo.SystemInfo> connect(ProcessId processId) {
+ try (DefaultProcessCommands commands = DefaultProcessCommands.secondary(ipcSharedDir, processId.getIpcIndex())) {
+ if (commands.isUp()) {
+ String url = commands.getSystemInfoUrl();
+ byte[] protobuf = IOUtils.toByteArray(new URI(url));
+ return Optional.of(ProtobufSystemInfo.SystemInfo.parseFrom(protobuf));
+ }
+ return Optional.absent();
+ } catch (Exception e) {
+ throw new IllegalStateException("Can not get system info of process " + processId, e);
+ }
+ }
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java
index 7d6c3bd00ba..ab513629d81 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SonarQubeMonitor.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.platform.monitoring;
-import com.google.common.base.Optional;
import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -97,7 +96,7 @@ public class SonarQubeMonitor extends BaseMonitorMBean implements SonarQubeMonit
}
@Override
- public Optional<Map<String, Object>> attributes() {
+ public Map<String, Object> attributes() {
Map<String, Object> attributes = new LinkedHashMap<>();
attributes.put("Server ID", getServerId());
attributes.put("Version", getVersion());
@@ -111,7 +110,7 @@ public class SonarQubeMonitor extends BaseMonitorMBean implements SonarQubeMonit
attributes.put("Temp Dir", settings.getString(ProcessProperties.PATH_TEMP));
attributes.put("Logs Dir", settings.getString(ProcessProperties.PATH_LOGS));
attributes.put("Logs Level", getLogLevel());
- return Optional.of(attributes);
+ return attributes;
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SystemMonitor.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SystemMonitor.java
index d7d279d94c9..b5788d847ae 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SystemMonitor.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/SystemMonitor.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.platform.monitoring;
-import com.google.common.base.Optional;
import java.lang.management.ClassLoadingMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
@@ -53,7 +52,7 @@ public class SystemMonitor implements Monitor {
}
@Override
- public Optional<Map<String, Object>> attributes() {
+ public Map<String, Object> attributes() {
Map<String, Object> attributes = new LinkedHashMap<>();
attributes.put("System Date", formatDateTime(new Date(system.now())));
attributes.put("Start Time", formatDateTime(new Date(runtimeMXBean().getStartTime())));
@@ -76,7 +75,7 @@ public class SystemMonitor implements Monitor {
attributes.put("Threads", threadMXBean().getThreadCount());
attributes.put("Threads Peak", threadMXBean().getPeakThreadCount());
attributes.put("Daemon Thread", threadMXBean().getDaemonThreadCount());
- return Optional.of(attributes);
+ return attributes;
}
private static RuntimeMXBean runtimeMXBean() {
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
index 7d4549f10a8..b617008eb74 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
@@ -149,15 +149,11 @@ import org.sonar.server.permission.ws.PermissionsWsModule;
import org.sonar.server.platform.BackendCleanup;
import org.sonar.server.platform.ServerLogging;
import org.sonar.server.platform.SettingsChangeNotifier;
-import org.sonar.server.platform.monitoring.CeDatabaseMonitor;
-import org.sonar.server.platform.monitoring.CeStateMonitor;
-import org.sonar.server.platform.monitoring.CeTasksMonitor;
import org.sonar.server.platform.monitoring.DatabaseMonitor;
import org.sonar.server.platform.monitoring.EsMonitor;
-import org.sonar.server.platform.monitoring.EsStateMonitor;
-import org.sonar.server.platform.monitoring.JmxConnectionFactoryProvider;
import org.sonar.server.platform.monitoring.JvmPropsMonitor;
import org.sonar.server.platform.monitoring.PluginsMonitor;
+import org.sonar.server.platform.monitoring.ProcessSystemInfoClient;
import org.sonar.server.platform.monitoring.SonarQubeMonitor;
import org.sonar.server.platform.monitoring.SystemMonitor;
import org.sonar.server.platform.ws.ChangeLogLevelAction;
@@ -635,7 +631,7 @@ public class PlatformLevel4 extends PlatformLevel {
TypeValidationModule.class,
// System
- new JmxConnectionFactoryProvider(),
+ ProcessSystemInfoClient.class,
ServerLogging.class,
RestartAction.class,
InfoAction.class,
@@ -648,10 +644,6 @@ public class PlatformLevel4 extends PlatformLevel {
PluginsMonitor.class,
JvmPropsMonitor.class,
DatabaseMonitor.class,
- EsStateMonitor.class,
- CeStateMonitor.class,
- CeTasksMonitor.class,
- CeDatabaseMonitor.class,
MigrateDbAction.class,
LogsAction.class,
ChangeLogLevelAction.class,
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java
index 3512a9eb632..7f68912e96d 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/InfoAction.java
@@ -26,7 +26,10 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.core.permission.GlobalPermissions;
+import org.sonar.process.ProcessId;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
import org.sonar.server.platform.monitoring.Monitor;
+import org.sonar.server.platform.monitoring.ProcessSystemInfoClient;
import org.sonar.server.user.UserSession;
/**
@@ -34,11 +37,13 @@ import org.sonar.server.user.UserSession;
*/
public class InfoAction implements SystemWsAction {
- private final Monitor[] monitors;
private final UserSession userSession;
+ private final ProcessSystemInfoClient processSystemInfoClient;
+ private final Monitor[] monitors;
- public InfoAction(UserSession userSession, Monitor... monitors) {
+ public InfoAction(UserSession userSession, ProcessSystemInfoClient processSystemInfoClient, Monitor... monitors) {
this.userSession = userSession;
+ this.processSystemInfoClient = processSystemInfoClient;
this.monitors = monitors;
}
@@ -64,12 +69,38 @@ public class InfoAction implements SystemWsAction {
private void writeJson(JsonWriter json) {
json.beginObject();
for (Monitor monitor : monitors) {
- Optional<Map<String, Object>> attributes = monitor.attributes();
- if (attributes.isPresent()) {
- json.name(monitor.name());
+ Map<String, Object> attributes = monitor.attributes();
+ json.name(monitor.name());
+ json.beginObject();
+ for (Map.Entry<String, Object> attribute : attributes.entrySet()) {
+ json.name(attribute.getKey()).valueObject(attribute.getValue());
+ }
+ json.endObject();
+ }
+ Optional<ProtobufSystemInfo.SystemInfo> ceSysInfo = processSystemInfoClient.connect(ProcessId.COMPUTE_ENGINE);
+ if (ceSysInfo.isPresent()) {
+ for (ProtobufSystemInfo.Section section : ceSysInfo.get().getSectionsList()) {
+ json.name(section.getName());
json.beginObject();
- for (Map.Entry<String, Object> attribute : attributes.get().entrySet()) {
- json.name(attribute.getKey()).valueObject(attribute.getValue());
+ for (ProtobufSystemInfo.Attribute attribute : section.getAttributesList()) {
+ switch (attribute.getValueCase()) {
+ case BOOLEAN_VALUE:
+ json.name(attribute.getKey()).valueObject(attribute.getBooleanValue());
+ break;
+ case LONG_VALUE:
+ json.name(attribute.getKey()).valueObject(attribute.getLongValue());
+ break;
+ case DOUBLE_VALUE:
+ json.name(attribute.getKey()).valueObject(attribute.getDoubleValue());
+ break;
+ case STRING_VALUE:
+ json.name(attribute.getKey()).valueObject(attribute.getStringValue());
+ break;
+ case VALUE_NOT_SET:
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported type: " + attribute.getValueCase());
+ }
}
json.endObject();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/monitoring/CeDatabaseMBeanImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/monitoring/CeDatabaseMBeanImplTest.java
new file mode 100644
index 00000000000..a81a7d8d69e
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/monitoring/CeDatabaseMBeanImplTest.java
@@ -0,0 +1,70 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.computation.monitoring;
+
+import java.lang.management.ManagementFactory;
+import javax.annotation.CheckForNull;
+import javax.management.InstanceNotFoundException;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CeDatabaseMBeanImplTest {
+
+ @Rule
+ public DbTester dbTester = DbTester.create(System2.INSTANCE);
+
+ CeDatabaseMBeanImpl underTest = new CeDatabaseMBeanImpl(dbTester.getDbClient());
+
+ @Test
+ public void register_and_unregister() throws Exception {
+ assertThat(getMBean()).isNull();
+
+ underTest.start();
+ assertThat(getMBean()).isNotNull();
+
+ underTest.stop();
+ assertThat(getMBean()).isNull();
+ }
+
+ @Test
+ public void export_system_info() {
+ ProtobufSystemInfo.Section section = underTest.toProtobuf();
+ assertThat(section.getName()).isEqualTo("Compute Engine Database Connection");
+ assertThat(section.getAttributesCount()).isEqualTo(9);
+ assertThat(section.getAttributes(0).getKey()).isEqualTo("Pool Initial Size");
+ assertThat(section.getAttributes(0).getLongValue()).isGreaterThanOrEqualTo(0);
+ }
+
+ @CheckForNull
+ private ObjectInstance getMBean() throws Exception {
+ try {
+ return ManagementFactory.getPlatformMBeanServer().getObjectInstance(new ObjectName(CeDatabaseMBean.OBJECT_NAME));
+ } catch (InstanceNotFoundException e) {
+ return null;
+ }
+ }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/monitoring/CeTasksMBeanImplTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/monitoring/CeTasksMBeanImplTest.java
index 9b5bc7becc8..a891f1d5569 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/monitoring/CeTasksMBeanImplTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/monitoring/CeTasksMBeanImplTest.java
@@ -26,7 +26,7 @@ import javax.management.ObjectInstance;
import javax.management.ObjectName;
import org.junit.Test;
import org.sonar.ce.monitoring.CEQueueStatus;
-import org.sonar.process.jmx.CeTasksMBean;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
import org.sonar.server.computation.configuration.CeConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
@@ -66,6 +66,13 @@ public class CeTasksMBeanImplTest {
assertThat(underTest.getWorkerCount()).isEqualTo(WORKER_COUNT);
}
+ @Test
+ public void export_system_info() {
+ ProtobufSystemInfo.Section section = underTest.toProtobuf();
+ assertThat(section.getName()).isEqualTo("Compute Engine Tasks");
+ assertThat(section.getAttributesCount()).isEqualTo(6);
+ }
+
/**
* Dumb implementation of CEQueueStatus which returns constant values for get methods and throws UnsupportedOperationException
* for other methods.
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeDatabaseMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeDatabaseMonitorTest.java
deleted file mode 100644
index 9758471ffcb..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeDatabaseMonitorTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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 com.google.common.base.Optional;
-import java.util.Map;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.sonar.process.ProcessId;
-import org.sonar.process.jmx.CeDatabaseMBean;
-import org.sonar.process.jmx.JmxConnectionFactory;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class CeDatabaseMonitorTest {
-
- JmxConnectionFactory jmxConnectionFactory = mock(JmxConnectionFactory.class, Mockito.RETURNS_DEEP_STUBS);
- CeDatabaseMonitor underTest = new CeDatabaseMonitor(jmxConnectionFactory);
-
- @Test
- public void testName() {
- assertThat(underTest.name()).isNotEmpty();
- }
-
- @Test
- public void attributes() {
- CeDatabaseMBean mbean = mock(CeDatabaseMBean.class, Mockito.RETURNS_DEFAULTS);
-
- when(jmxConnectionFactory.create(ProcessId.COMPUTE_ENGINE).getMBean(CeDatabaseMBean.OBJECT_NAME, CeDatabaseMBean.class))
- .thenReturn(mbean);
- Optional<Map<String, Object>> attributes = underTest.attributes();
- assertThat(attributes.get()).containsKeys("Pool Initial Size", "Pool Active Connections");
- assertThat(attributes.get()).hasSize(9);
- }
-
- @Test
- public void absent_attributes_if_CE_is_down() {
- when(jmxConnectionFactory.create(ProcessId.COMPUTE_ENGINE)).thenReturn(null);
- Optional<Map<String, Object>> attributes = underTest.attributes();
- assertThat(attributes.isPresent()).isFalse();
- }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeStateMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeStateMonitorTest.java
deleted file mode 100644
index 1154bcff55c..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeStateMonitorTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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 com.google.common.base.Optional;
-import com.google.common.collect.ImmutableSortedMap;
-import java.util.Map;
-import org.assertj.core.data.MapEntry;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.sonar.process.ProcessId;
-import org.sonar.process.jmx.JmxConnectionFactory;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class CeStateMonitorTest {
-
- JmxConnectionFactory jmxConnectionFactory = mock(JmxConnectionFactory.class, Mockito.RETURNS_DEEP_STUBS);
- CeStateMonitor underTest = new CeStateMonitor(jmxConnectionFactory);
-
- @Test
- public void testName() {
- assertThat(underTest.name()).isNotEmpty();
- }
-
- @Test
- public void testAttributes() {
- when(jmxConnectionFactory.create(ProcessId.COMPUTE_ENGINE).getSystemState()).thenReturn(ImmutableSortedMap.<String, Object>of(
- "foo", "foo_val", "bar", "bar_val"));
- Optional<Map<String, Object>> attributes = underTest.attributes();
- assertThat(attributes.get()).containsExactly(
- MapEntry.entry("bar", "bar_val"),
- MapEntry.entry("foo", "foo_val"));
- }
-
- @Test
- public void absent_attributes_if_CE_is_down() {
- when(jmxConnectionFactory.create(ProcessId.COMPUTE_ENGINE)).thenReturn(null);
- Optional<Map<String, Object>> attributes = underTest.attributes();
- assertThat(attributes.isPresent()).isFalse();
- }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeTasksMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeTasksMonitorTest.java
deleted file mode 100644
index c9d7626aa5a..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/CeTasksMonitorTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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 com.google.common.base.Optional;
-import java.util.Map;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.sonar.process.ProcessId;
-import org.sonar.process.jmx.CeTasksMBean;
-import org.sonar.process.jmx.JmxConnectionFactory;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class CeTasksMonitorTest {
-
- JmxConnectionFactory jmxConnectionFactory = mock(JmxConnectionFactory.class, Mockito.RETURNS_DEEP_STUBS);
- CeTasksMonitor underTest = new CeTasksMonitor(jmxConnectionFactory);
-
- @Test
- public void testName() {
- assertThat(underTest.name()).isNotEmpty();
- }
-
- @Test
- public void testAttributes() {
- CeTasksMBean mbean = mock(CeTasksMBean.class, Mockito.RETURNS_DEFAULTS);
-
- when(jmxConnectionFactory.create(ProcessId.COMPUTE_ENGINE).getMBean(CeTasksMBean.OBJECT_NAME, CeTasksMBean.class))
- .thenReturn(mbean);
- Optional<Map<String, Object>> attributes = underTest.attributes();
- assertThat(attributes.get()).containsKeys("Pending");
- assertThat(attributes.get()).hasSize(6);
- }
-
- @Test
- public void absent_attributes_if_CE_is_down() {
- when(jmxConnectionFactory.create(ProcessId.COMPUTE_ENGINE)).thenReturn(null);
- Optional<Map<String, Object>> attributes = underTest.attributes();
- assertThat(attributes.isPresent()).isFalse();
- }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/DatabaseMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/DatabaseMonitorTest.java
index 5ed384ce7b0..5941af2a2ba 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/DatabaseMonitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/DatabaseMonitorTest.java
@@ -49,7 +49,7 @@ public class DatabaseMonitorTest {
@Test
public void db_info() {
- Map<String, Object> attributes = underTest.attributes().get();
+ Map<String, Object> attributes = underTest.attributes();
assertThat(attributes.get("Database")).isEqualTo("H2");
assertThat(attributes.get("Database Version").toString()).startsWith("1.");
assertThat(attributes.get("Username")).isEqualTo("SONAR");
@@ -58,7 +58,7 @@ public class DatabaseMonitorTest {
@Test
public void pool_info() {
- Map<String, Object> attributes = underTest.attributes().get();
+ Map<String, Object> attributes = underTest.attributes();
assertThat((int) attributes.get("Pool Max Connections")).isGreaterThan(0);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java
index 6379c5d0779..47ec8a30311 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsMonitorTest.java
@@ -21,35 +21,21 @@ package org.sonar.server.platform.monitoring;
import java.util.Map;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
-import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
-import org.mockito.Mockito;
import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessId;
-import org.sonar.process.jmx.EsSettingsMBean;
-import org.sonar.process.jmx.JmxConnectionFactory;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.NewIndex;
import org.sonar.server.issue.index.IssueIndexDefinition;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
public class EsMonitorTest {
@ClassRule
public static EsTester esTester = new EsTester().addDefinitions(new IssueIndexDefinition(new Settings()));
- JmxConnectionFactory jmxConnectionFactory = mock(JmxConnectionFactory.class, Mockito.RETURNS_DEEP_STUBS);
- EsSettingsMBean settingsMBean = mock(EsSettingsMBean.class);
- EsMonitor underTest = new EsMonitor(jmxConnectionFactory, esTester.client());
-
- @Before
- public void setUp() throws Exception {
- when(jmxConnectionFactory.create(ProcessId.ELASTICSEARCH).getMBean(EsSettingsMBean.OBJECT_NAME, EsSettingsMBean.class)).thenReturn(settingsMBean);
- }
+ EsMonitor underTest = new EsMonitor(esTester.client());
@Test
public void name() {
@@ -58,7 +44,7 @@ public class EsMonitorTest {
@Test
public void cluster_attributes() {
- Map<String, Object> attributes = underTest.attributes().get();
+ Map<String, Object> attributes = underTest.attributes();
assertThat(underTest.getState()).isEqualTo(ClusterHealthStatus.GREEN.name());
assertThat(attributes.get("State")).isEqualTo(ClusterHealthStatus.GREEN);
assertThat(attributes.get("Number of Nodes")).isEqualTo(1);
@@ -66,7 +52,7 @@ public class EsMonitorTest {
@Test
public void node_attributes() {
- Map<String, Object> attributes = underTest.attributes().get();
+ Map<String, Object> attributes = underTest.attributes();
Map nodesAttributes = (Map) attributes.get("Nodes");
// one node
@@ -78,7 +64,7 @@ public class EsMonitorTest {
@Test
public void index_attributes() {
- Map<String, Object> attributes = underTest.attributes().get();
+ Map<String, Object> attributes = underTest.attributes();
Map indicesAttributes = (Map) attributes.get("Indices");
// one index "issues"
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsStateMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsStateMonitorTest.java
deleted file mode 100644
index 7618fedfbd8..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/EsStateMonitorTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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 com.google.common.base.Optional;
-import com.google.common.collect.ImmutableSortedMap;
-import java.util.Map;
-import org.assertj.core.data.MapEntry;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.sonar.process.ProcessId;
-import org.sonar.process.jmx.JmxConnectionFactory;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class EsStateMonitorTest {
- JmxConnectionFactory jmxConnectionFactory = mock(JmxConnectionFactory.class, Mockito.RETURNS_DEEP_STUBS);
- EsStateMonitor underTest = new EsStateMonitor(jmxConnectionFactory);
-
- @Test
- public void testName() {
- assertThat(underTest.name()).isNotEmpty();
- }
-
- @Test
- public void testAttributes() {
- when(jmxConnectionFactory.create(ProcessId.ELASTICSEARCH).getSystemState()).thenReturn(ImmutableSortedMap.<String, Object>of(
- "foo", "foo_val", "bar", "bar_val"));
- Optional<Map<String, Object>> attributes = underTest.attributes();
- assertThat(attributes.get()).containsExactly(
- MapEntry.entry("bar", "bar_val"),
- MapEntry.entry("foo", "foo_val"));
- }
-
- @Test
- public void absent_attributes_if_CE_is_down() {
- when(jmxConnectionFactory.create(ProcessId.ELASTICSEARCH)).thenReturn(null);
- Optional<Map<String, Object>> attributes = underTest.attributes();
- assertThat(attributes.isPresent()).isFalse();
- }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/FakeMonitor.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/FakeMonitor.java
index 879b65f8405..7ef3801ee09 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/FakeMonitor.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/FakeMonitor.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.platform.monitoring;
-import com.google.common.base.Optional;
import java.util.Collections;
import java.util.Map;
@@ -36,7 +35,7 @@ public class FakeMonitor extends BaseMonitorMBean implements FakeMonitorMBean {
}
@Override
- public Optional<Map<String, Object>> attributes() {
- return Optional.of(Collections.<String, Object>emptyMap());
+ public Map<String, Object> attributes() {
+ return Collections.emptyMap();
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/JmxConnectionFactoryProviderTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/JmxConnectionFactoryProviderTest.java
deleted file mode 100644
index 03998a76cde..00000000000
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/JmxConnectionFactoryProviderTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact 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.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.sonar.api.config.Settings;
-import org.sonar.process.ProcessEntryPoint;
-import org.sonar.process.jmx.JmxConnectionFactory;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class JmxConnectionFactoryProviderTest {
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- Settings settings = new Settings();
- JmxConnectionFactoryProvider underTest = new JmxConnectionFactoryProvider();
-
- @Test
- public void provide_JmxConnector() {
- settings.setProperty(ProcessEntryPoint.PROPERTY_SHARED_PATH, "path/");
- JmxConnectionFactory connector = underTest.provide(settings);
-
- assertThat(connector).isNotNull();
- // cache
- assertThat(underTest.provide(settings)).isSameAs(connector);
- }
-
- @Test
- public void throw_IAE_if_ipc_shared_path_is_not_set() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Property process.sharedDir is not set");
-
- underTest.provide(settings);
- }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/JvmPropsMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/JvmPropsMonitorTest.java
index 0a534035280..0e8d4090f04 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/JvmPropsMonitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/JvmPropsMonitorTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.platform.monitoring;
-import com.google.common.base.Optional;
import java.util.Map;
import org.junit.Test;
@@ -36,8 +35,8 @@ public class JvmPropsMonitorTest {
@Test
public void attributes() {
- Optional<Map<String, Object>> attributes = underTest.attributes();
+ Map<String, Object> attributes = underTest.attributes();
- assertThat(attributes.get()).containsKeys("java.vm.vendor", "os.name");
+ assertThat(attributes).containsKeys("java.vm.vendor", "os.name");
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/PluginsMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/PluginsMonitorTest.java
index c5c4b1a4f51..e3a5f374163 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/PluginsMonitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/PluginsMonitorTest.java
@@ -52,7 +52,7 @@ public class PluginsMonitorTest {
new PluginInfo("no-version")
.setName("No Version")));
- Map<String, Object> attributes = underTest.attributes().get();
+ Map<String, Object> attributes = underTest.attributes();
assertThat(attributes).containsKeys("key-1", "key-2");
assertThat((Map) attributes.get("key-1"))
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/ProcessSystemInfoClientTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/ProcessSystemInfoClientTest.java
new file mode 100644
index 00000000000..ff3016a7dfc
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/ProcessSystemInfoClientTest.java
@@ -0,0 +1,99 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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 com.google.common.base.Optional;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
+import java.io.File;
+import okio.Buffer;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.config.Settings;
+import org.sonar.process.DefaultProcessCommands;
+import org.sonar.process.ProcessEntryPoint;
+import org.sonar.process.ProcessId;
+import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+
+import static java.lang.String.format;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ProcessSystemInfoClientTest {
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ @Rule
+ public MockWebServer server = new MockWebServer();
+
+ File ipcSharedDir;
+ ProcessSystemInfoClient underTest;
+
+ @Before
+ public void setUp() throws Exception {
+ ipcSharedDir = temp.newFolder();
+ Settings settings = new Settings();
+ settings.setProperty(ProcessEntryPoint.PROPERTY_SHARED_PATH, ipcSharedDir.getAbsolutePath());
+ underTest = new ProcessSystemInfoClient(settings);
+ }
+
+ @Test
+ public void connect_returns_absent_if_process_is_down() throws Exception {
+ Optional<ProtobufSystemInfo.SystemInfo> info = underTest.connect(ProcessId.COMPUTE_ENGINE);
+
+ assertThat(info.isPresent()).isFalse();
+ }
+
+ @Test
+ public void get_information_if_process_is_up() throws Exception {
+ Buffer response = new Buffer();
+ response.read(ProtobufSystemInfo.Section.newBuilder().build().toByteArray());
+ server.enqueue(new MockResponse().setBody(response));
+
+ // initialize registration of process
+ try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(ipcSharedDir, ProcessId.COMPUTE_ENGINE.getIpcIndex())) {
+ processCommands.setUp();
+ processCommands.setSystemInfoUrl(format("http://%s:%d", server.getHostName(), server.getPort()));
+ }
+
+ Optional<ProtobufSystemInfo.SystemInfo> info = underTest.connect(ProcessId.COMPUTE_ENGINE);
+ assertThat(info.get().getSectionsCount()).isEqualTo(0);
+ }
+
+ @Test
+ public void throws_ISE_if_http_error() throws Exception {
+ server.enqueue(new MockResponse().setResponseCode(500));
+
+ // initialize registration of process
+ try (DefaultProcessCommands processCommands = DefaultProcessCommands.secondary(ipcSharedDir, ProcessId.COMPUTE_ENGINE.getIpcIndex())) {
+ processCommands.setUp();
+ processCommands.setSystemInfoUrl(format("http://%s:%d", server.getHostName(), server.getPort()));
+ }
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Can not get system info of process " + ProcessId.COMPUTE_ENGINE);
+ underTest.connect(ProcessId.COMPUTE_ENGINE);
+ }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SonarQubeMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SonarQubeMonitorTest.java
index 70155ae82f9..a522c1df767 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SonarQubeMonitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SonarQubeMonitorTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.platform.monitoring;
-import com.google.common.base.Optional;
import java.io.File;
import java.util.Map;
import org.apache.commons.io.FileUtils;
@@ -62,8 +61,8 @@ public class SonarQubeMonitorTest {
when(server.getStartedAt()).thenReturn(DateUtils.parseDate("2015-01-01"));
SonarQubeMonitor monitor = new SonarQubeMonitor(settings, new SecurityRealmFactory(settings), server, serverLogging);
- Optional<Map<String, Object>> attributes = monitor.attributes();
- assertThat(attributes.get()).containsKeys("Server ID", "Version");
+ Map<String, Object> attributes = monitor.attributes();
+ assertThat(attributes).containsKeys("Server ID", "Version");
}
@Test
@@ -74,8 +73,8 @@ public class SonarQubeMonitorTest {
when(server.getRootDir()).thenReturn(rootDir);
SonarQubeMonitor monitor = new SonarQubeMonitor(settings, new SecurityRealmFactory(settings), server, serverLogging);
- Optional<Map<String, Object>> attributes = monitor.attributes();
- assertThat(attributes.get()).containsEntry("Official Distribution", Boolean.TRUE);
+ Map<String, Object> attributes = monitor.attributes();
+ assertThat(attributes).containsEntry("Official Distribution", Boolean.TRUE);
}
@Test
@@ -85,15 +84,15 @@ public class SonarQubeMonitorTest {
when(server.getRootDir()).thenReturn(rootDir);
SonarQubeMonitor monitor = new SonarQubeMonitor(settings, new SecurityRealmFactory(settings), server, serverLogging);
- Optional<Map<String, Object>> attributes = monitor.attributes();
- assertThat(attributes.get()).containsEntry("Official Distribution", Boolean.FALSE);
+ Map<String, Object> attributes = monitor.attributes();
+ assertThat(attributes).containsEntry("Official Distribution", Boolean.FALSE);
}
@Test
public void get_log_level() throws Exception {
SonarQubeMonitor monitor = new SonarQubeMonitor(settings, new SecurityRealmFactory(settings), server, serverLogging);
- Optional<Map<String, Object>> attributes = monitor.attributes();
- assertThat(attributes.get()).containsEntry("Logs Level", "DEBUG");
+ Map<String, Object> attributes = monitor.attributes();
+ assertThat(attributes).containsEntry("Logs Level", "DEBUG");
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SystemMonitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SystemMonitorTest.java
index 07510691802..e8290638a65 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SystemMonitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/SystemMonitorTest.java
@@ -35,7 +35,7 @@ public class SystemMonitorTest {
@Test
public void system_properties() {
- Map<String, Object> attributes = underTest.attributes().get();
+ Map<String, Object> attributes = underTest.attributes();
assertThat(attributes).containsKeys("System Date", "Processors");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java
index 41a0a6788b9..c4a61be4f80 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/InfoActionTest.java
@@ -19,17 +19,18 @@
*/
package org.sonar.server.platform.ws;
-import com.google.common.base.Optional;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
+import org.mockito.Mockito;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.internal.SimpleGetRequest;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.platform.monitoring.Monitor;
+import org.sonar.server.platform.monitoring.ProcessSystemInfoClient;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.WsTester;
@@ -40,12 +41,12 @@ import static org.mockito.Mockito.when;
public class InfoActionTest {
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone().login("login")
- .setName("name");
+ .setName("name");
Monitor monitor1 = mock(Monitor.class);
Monitor monitor2 = mock(Monitor.class);
- Monitor monitor3 = mock(Monitor.class);
- InfoAction underTest = new InfoAction(userSessionRule, monitor1, monitor2, monitor3);
+ ProcessSystemInfoClient processSystemInfoClient = mock(ProcessSystemInfoClient.class, Mockito.RETURNS_MOCKS);
+ InfoAction underTest = new InfoAction(userSessionRule, processSystemInfoClient, monitor1, monitor2);
@Test(expected = ForbiddenException.class)
public void should_fail_when_does_not_have_admin_right() {
@@ -64,11 +65,9 @@ public class InfoActionTest {
attributes2.put("one", 1);
attributes2.put("two", 2);
when(monitor1.name()).thenReturn("Monitor One");
- when(monitor1.attributes()).thenReturn(Optional.of(attributes1));
+ when(monitor1.attributes()).thenReturn(attributes1);
when(monitor2.name()).thenReturn("Monitor Two");
- when(monitor2.attributes()).thenReturn(Optional.of(attributes2));
- when(monitor3.name()).thenReturn("Monitor Three");
- when(monitor3.attributes()).thenReturn(Optional.<Map<String, Object>>absent());
+ when(monitor2.attributes()).thenReturn(attributes2);
WsTester.TestResponse response = new WsTester.TestResponse();
underTest.handle(new SimpleGetRequest(), response);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java
index 773e6d5b0a5..adda7539e6b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemWsTest.java
@@ -24,6 +24,7 @@ import org.sonar.api.config.Settings;
import org.sonar.api.server.ws.WebService;
import org.sonar.server.app.ProcessCommandWrapper;
import org.sonar.server.platform.Platform;
+import org.sonar.server.platform.monitoring.ProcessSystemInfoClient;
import org.sonar.server.tester.AnonymousMockUserSession;
import org.sonar.server.user.UserSession;
@@ -32,10 +33,12 @@ import static org.mockito.Mockito.mock;
public class SystemWsTest {
+ ProcessSystemInfoClient processSystemInfoClient = mock(ProcessSystemInfoClient.class);
+
@Test
public void define() {
RestartAction action1 = new RestartAction(mock(UserSession.class), mock(Settings.class), mock(Platform.class), mock(ProcessCommandWrapper.class));
- InfoAction action2 = new InfoAction(new AnonymousMockUserSession());
+ InfoAction action2 = new InfoAction(new AnonymousMockUserSession(), processSystemInfoClient);
SystemWs ws = new SystemWs(action1, action2);
WebService.Context context = new WebService.Context();