aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2018-04-18 21:28:49 +0200
committerSonarTech <sonartech@sonarsource.com>2018-05-10 20:20:53 +0200
commita5b9a87ed5e97a553d6f6bde845be749497ab5ad (patch)
tree3e0af1430be8b83b57ee44853e1bc17e7f653da8 /server
parent42c098776214ff3d6b94b273197a0a6e493043ea (diff)
downloadsonarqube-a5b9a87ed5e97a553d6f6bde845be749497ab5ad.tar.gz
sonarqube-a5b9a87ed5e97a553d6f6bde845be749497ab5ad.zip
SONAR-10592 display workers pause in System Info page
Diffstat (limited to 'server')
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatus.java5
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatusImpl.java10
-rw-r--r--server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CeTasksMBeanImpl.java1
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplTest.java17
-rw-r--r--server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CeTasksMBeanImplTest.java9
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSection.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSectionTest.java29
7 files changed, 63 insertions, 10 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatus.java b/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatus.java
index 3127d3fef32..c8e4fc45edd 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatus.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatus.java
@@ -19,6 +19,9 @@
*/
package org.sonar.ce.monitoring;
+import org.sonar.api.ce.ComputeEngineSide;
+
+@ComputeEngineSide
public interface CEQueueStatus {
/**
@@ -85,4 +88,6 @@ public interface CEQueueStatus {
* Time spent processing batch reports since startup, in milliseconds.
*/
long getProcessingTime();
+
+ boolean areWorkersPaused();
}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatusImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatusImpl.java
index e9ac48c4727..e1e9c679c0b 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatusImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CEQueueStatusImpl.java
@@ -19,10 +19,12 @@
*/
package org.sonar.ce.monitoring;
+import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.ce.CeQueueDto;
+import org.sonar.server.property.InternalProperties;
import static com.google.common.base.Preconditions.checkArgument;
@@ -70,6 +72,14 @@ public class CEQueueStatusImpl implements CEQueueStatus {
}
@Override
+ public boolean areWorkersPaused() {
+ try (DbSession dbSession = dbClient.openSession(false)) {
+ Optional<String> val = dbClient.internalPropertiesDao().selectByKey(dbSession, InternalProperties.COMPUTE_ENGINE_PAUSE);
+ return "true".equals(val.orElse(null));
+ }
+ }
+
+ @Override
public long getInProgressCount() {
return inProgress.get();
}
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CeTasksMBeanImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CeTasksMBeanImpl.java
index 421dbd5d885..ed62ab4bb21 100644
--- a/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CeTasksMBeanImpl.java
+++ b/server/sonar-ce/src/main/java/org/sonar/ce/monitoring/CeTasksMBeanImpl.java
@@ -93,6 +93,7 @@ public class CeTasksMBeanImpl implements CeTasksMBean, Startable, SystemInfoSect
builder.addAttributesBuilder().setKey("Processing Time (ms)").setLongValue(getProcessingTime()).build();
builder.addAttributesBuilder().setKey("Worker Count").setLongValue(getWorkerCount()).build();
builder.addAttributesBuilder().setKey("Max Worker Count").setLongValue(getWorkerMaxCount()).build();
+ builder.addAttributesBuilder().setKey("Workers Paused").setBooleanValue(queueStatus.areWorkersPaused()).build();
return builder.build();
}
}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplTest.java
index b860b9042f8..285c86ee4b0 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CEQueueStatusImplTest.java
@@ -19,14 +19,15 @@
*/
package org.sonar.ce.monitoring;
+import java.util.Optional;
import java.util.Random;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.ce.CeQueueDto;
+import org.sonar.server.property.InternalProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -135,8 +136,20 @@ public class CEQueueStatusImplTest {
@Test
public void count_Pending_from_database() {
- when(dbClient.ceQueueDao().countByStatus(any(DbSession.class), eq(CeQueueDto.Status.PENDING))).thenReturn(42);
+ when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.PENDING))).thenReturn(42);
assertThat(underTest.getPendingCount()).isEqualTo(42);
}
+
+ @Test
+ public void workers_pause_is_loaded_from_db() {
+ when(dbClient.internalPropertiesDao().selectByKey(any(), eq(InternalProperties.COMPUTE_ENGINE_PAUSE))).thenReturn(Optional.of("true"));
+
+ assertThat(underTest.areWorkersPaused()).isTrue();
+ }
+
+ @Test
+ public void workers_pause_is_false_by_default() {
+ assertThat(underTest.areWorkersPaused()).isFalse();
+ }
}
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CeTasksMBeanImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CeTasksMBeanImplTest.java
index 8fae1b5b811..33e3416e8a6 100644
--- a/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CeTasksMBeanImplTest.java
+++ b/server/sonar-ce/src/test/java/org/sonar/ce/monitoring/CeTasksMBeanImplTest.java
@@ -88,11 +88,10 @@ public class CeTasksMBeanImplTest {
public void export_system_info() {
ProtobufSystemInfo.Section section = underTest.toProtobuf();
assertThat(section.getName()).isEqualTo("Compute Engine Tasks");
- assertThat(section.getAttributesCount()).isEqualTo(7);
+ assertThat(section.getAttributesCount()).isEqualTo(8);
}
private static class DumbCEQueueStatus implements CEQueueStatus {
-
@Override
public long getPendingCount() {
return PENDING_COUNT;
@@ -132,6 +131,12 @@ public class CeTasksMBeanImplTest {
public long getProcessingTime() {
return PROCESSING_TIME;
}
+
+ @Override
+ public boolean areWorkersPaused() {
+ return false;
+ }
+
private long methodNotImplemented() {
throw new UnsupportedOperationException("Not Implemented");
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSection.java b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSection.java
index 381bcfa7cc1..244d2462e53 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSection.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSection.java
@@ -28,6 +28,7 @@ import org.sonar.db.ce.CeQueueDto;
import org.sonar.process.systeminfo.Global;
import org.sonar.process.systeminfo.SystemInfoSection;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import org.sonar.server.property.InternalProperties;
import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
@@ -57,6 +58,7 @@ public class CeQueueGlobalSection implements SystemInfoSection, Global {
setAttribute(protobuf, "Total Pending", dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.PENDING));
setAttribute(protobuf, "Total In Progress", dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.IN_PROGRESS));
setAttribute(protobuf, "Max Workers per Node", workerCountProvider == null ? DEFAULT_NB_OF_WORKERS : workerCountProvider.get());
+ setAttribute(protobuf, "Workers Paused", "true".equals(dbClient.internalPropertiesDao().selectByKey(dbSession, InternalProperties.COMPUTE_ENGINE_PAUSE).orElse(null)));
}
return protobuf.build();
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSectionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSectionTest.java
index 0f375ac4a19..00437ec5f2f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSectionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/monitoring/cluster/CeQueueGlobalSectionTest.java
@@ -19,13 +19,14 @@
*/
package org.sonar.server.platform.monitoring.cluster;
+import java.util.Optional;
import org.junit.Test;
import org.mockito.Mockito;
import org.sonar.ce.configuration.WorkerCountProvider;
import org.sonar.db.DbClient;
-import org.sonar.db.DbSession;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import org.sonar.server.property.InternalProperties;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
@@ -36,11 +37,12 @@ import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatA
public class CeQueueGlobalSectionTest {
private DbClient dbClient = mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS);
+ private WorkerCountProvider workerCountProvider = mock(WorkerCountProvider.class);
@Test
public void test_queue_state_with_default_settings() {
- when(dbClient.ceQueueDao().countByStatus(any(DbSession.class), eq(CeQueueDto.Status.PENDING))).thenReturn(10);
- when(dbClient.ceQueueDao().countByStatus(any(DbSession.class), eq(CeQueueDto.Status.IN_PROGRESS))).thenReturn(1);
+ when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.PENDING))).thenReturn(10);
+ when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.IN_PROGRESS))).thenReturn(1);
CeQueueGlobalSection underTest = new CeQueueGlobalSection(dbClient);
ProtobufSystemInfo.Section section = underTest.toProtobuf();
@@ -52,9 +54,8 @@ public class CeQueueGlobalSectionTest {
@Test
public void test_queue_state_with_overridden_settings() {
- when(dbClient.ceQueueDao().countByStatus(any(DbSession.class), eq(CeQueueDto.Status.PENDING))).thenReturn(10);
- when(dbClient.ceQueueDao().countByStatus(any(DbSession.class), eq(CeQueueDto.Status.IN_PROGRESS))).thenReturn(2);
- WorkerCountProvider workerCountProvider = mock(WorkerCountProvider.class);
+ when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.PENDING))).thenReturn(10);
+ when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.IN_PROGRESS))).thenReturn(2);
when(workerCountProvider.get()).thenReturn(5);
CeQueueGlobalSection underTest = new CeQueueGlobalSection(dbClient, workerCountProvider);
@@ -65,5 +66,21 @@ public class CeQueueGlobalSectionTest {
assertThatAttributeIs(section, "Max Workers per Node", 5);
}
+ @Test
+ public void test_workers_not_paused() {
+ CeQueueGlobalSection underTest = new CeQueueGlobalSection(dbClient, workerCountProvider);
+ ProtobufSystemInfo.Section section = underTest.toProtobuf();
+ assertThatAttributeIs(section, "Workers Paused", false);
+ }
+
+ @Test
+ public void test_workers_paused() {
+ when(dbClient.internalPropertiesDao().selectByKey(any(), eq(InternalProperties.COMPUTE_ENGINE_PAUSE))).thenReturn(Optional.of("true"));
+
+ CeQueueGlobalSection underTest = new CeQueueGlobalSection(dbClient, workerCountProvider);
+ ProtobufSystemInfo.Section section = underTest.toProtobuf();
+
+ assertThatAttributeIs(section, "Workers Paused", true);
+ }
}