aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-webserver-core/src
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2022-11-09 12:19:20 +0100
committersonartech <sonartech@sonarsource.com>2022-11-10 20:02:47 +0000
commit2bf8736eefebd968b1526c7c0eb4f0eff303ffc3 (patch)
tree19aa175dc469822ae4914cfe828e9075d46d694d /server/sonar-webserver-core/src
parenta334500ec0d6f7970fcb3e65ade93469946ebc5a (diff)
downloadsonarqube-2bf8736eefebd968b1526c7c0eb4f0eff303ffc3.tar.gz
sonarqube-2bf8736eefebd968b1526c7c0eb4f0eff303ffc3.zip
SONAR-17580 add edition information to api/system/info response
Diffstat (limited to 'server/sonar-webserver-core/src')
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/StandaloneSystemSection.java7
-rw-r--r--server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSection.java7
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/StandaloneSystemSectionTest.java29
-rw-r--r--server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSectionTest.java18
4 files changed, 57 insertions, 4 deletions
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 457b6377951..643f39eaf48 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
@@ -24,6 +24,7 @@ import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.CoreProperties;
+import org.sonar.api.SonarRuntime;
import org.sonar.api.config.Configuration;
import org.sonar.api.platform.Server;
import org.sonar.api.security.SecurityRealm;
@@ -55,9 +56,11 @@ public class StandaloneSystemSection extends BaseSectionMBean implements SystemS
private final OfficialDistribution officialDistribution;
private final DockerSupport dockerSupport;
+ private final SonarRuntime sonarRuntime;
+
public StandaloneSystemSection(Configuration config, SecurityRealmFactory securityRealmFactory,
IdentityProviderRepository identityProviderRepository, Server server, ServerLogging serverLogging,
- OfficialDistribution officialDistribution, DockerSupport dockerSupport) {
+ OfficialDistribution officialDistribution, DockerSupport dockerSupport, SonarRuntime sonarRuntime) {
this.config = config;
this.securityRealmFactory = securityRealmFactory;
this.identityProviderRepository = identityProviderRepository;
@@ -65,6 +68,7 @@ public class StandaloneSystemSection extends BaseSectionMBean implements SystemS
this.serverLogging = serverLogging;
this.officialDistribution = officialDistribution;
this.dockerSupport = dockerSupport;
+ this.sonarRuntime = sonarRuntime;
}
@Override
@@ -122,6 +126,7 @@ public class StandaloneSystemSection extends BaseSectionMBean implements SystemS
setAttribute(protobuf, "Server ID", server.getId());
setAttribute(protobuf, "Version", getVersion());
+ setAttribute(protobuf, "Edition", sonarRuntime.getEdition().getLabel());
setAttribute(protobuf, "Docker", dockerSupport.isRunningInDocker());
setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication());
addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders());
diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSection.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSection.java
index 9fb9afef322..c9e3386d812 100644
--- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSection.java
+++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSection.java
@@ -24,6 +24,7 @@ import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.CoreProperties;
+import org.sonar.api.SonarRuntime;
import org.sonar.api.config.Configuration;
import org.sonar.api.platform.Server;
import org.sonar.api.security.SecurityRealm;
@@ -50,13 +51,16 @@ public class GlobalSystemSection implements SystemInfoSection, Global {
private final IdentityProviderRepository identityProviderRepository;
private final DockerSupport dockerSupport;
+ private final SonarRuntime sonarRuntime;
+
public GlobalSystemSection(Configuration config, Server server, SecurityRealmFactory securityRealmFactory,
- IdentityProviderRepository identityProviderRepository, DockerSupport dockerSupport) {
+ IdentityProviderRepository identityProviderRepository, DockerSupport dockerSupport, SonarRuntime sonarRuntime) {
this.config = config;
this.server = server;
this.securityRealmFactory = securityRealmFactory;
this.identityProviderRepository = identityProviderRepository;
this.dockerSupport = dockerSupport;
+ this.sonarRuntime = sonarRuntime;
}
@Override
@@ -65,6 +69,7 @@ public class GlobalSystemSection implements SystemInfoSection, Global {
protobuf.setName("System");
setAttribute(protobuf, "Server ID", server.getId());
+ setAttribute(protobuf, "Edition", sonarRuntime.getEdition().getLabel());
setAttribute(protobuf, "Docker", dockerSupport.isRunningInDocker());
setAttribute(protobuf, "High Availability", true);
setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication());
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/StandaloneSystemSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/StandaloneSystemSectionTest.java
index b6157d1e9b3..3b9f38757e1 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/StandaloneSystemSectionTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/StandaloneSystemSectionTest.java
@@ -27,6 +27,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sonar.api.CoreProperties;
+import org.sonar.api.SonarEdition;
+import org.sonar.api.SonarRuntime;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.platform.Server;
import org.sonar.api.security.SecurityRealm;
@@ -42,6 +44,10 @@ import org.sonar.server.user.SecurityRealmFactory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.api.SonarEdition.COMMUNITY;
+import static org.sonar.api.SonarEdition.DATACENTER;
+import static org.sonar.api.SonarEdition.DEVELOPER;
+import static org.sonar.api.SonarEdition.ENTERPRISE;
import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
@@ -58,12 +64,15 @@ public class StandaloneSystemSectionTest {
private OfficialDistribution officialDistribution = mock(OfficialDistribution.class);
private DockerSupport dockerSupport = mock(DockerSupport.class);
+ private SonarRuntime sonarRuntime = mock(SonarRuntime.class);
+
private StandaloneSystemSection underTest = new StandaloneSystemSection(settings.asConfig(), securityRealmFactory, identityProviderRepository, server,
- serverLogging, officialDistribution, dockerSupport);
+ serverLogging, officialDistribution, dockerSupport, sonarRuntime);
@Before
public void setUp() {
when(serverLogging.getRootLoggerLevel()).thenReturn(LoggerLevel.DEBUG);
+ when(sonarRuntime.getEdition()).thenReturn(COMMUNITY);
}
@Test
@@ -179,6 +188,14 @@ public class StandaloneSystemSectionTest {
assertThat(attribute(protobuf, "Docker").getBooleanValue()).isEqualTo(flag);
}
+ @Test
+ @UseDataProvider("editions")
+ public void get_edition(SonarEdition sonarEdition, String editionLabel) {
+ when(sonarRuntime.getEdition()).thenReturn(sonarEdition);
+ ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
+ assertThatAttributeIs(protobuf, "Edition", editionLabel);
+ }
+
@DataProvider
public static Object[][] trueOrFalse() {
return new Object[][] {
@@ -186,4 +203,14 @@ public class StandaloneSystemSectionTest {
{false}
};
}
+
+ @DataProvider
+ public static Object[][] editions() {
+ return new Object[][] {
+ {COMMUNITY, COMMUNITY.getLabel()},
+ {DEVELOPER, DEVELOPER.getLabel()},
+ {ENTERPRISE, ENTERPRISE.getLabel()},
+ {DATACENTER, DATACENTER.getLabel()},
+ };
+ }
}
diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSectionTest.java
index fcc4bdfda26..258c7e0ad9f 100644
--- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSectionTest.java
+++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/GlobalSystemSectionTest.java
@@ -22,10 +22,12 @@ package org.sonar.server.platform.monitoring.cluster;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.sonar.api.CoreProperties;
+import org.sonar.api.SonarRuntime;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.platform.Server;
import org.sonar.api.security.SecurityRealm;
@@ -38,6 +40,7 @@ import org.sonar.server.user.SecurityRealmFactory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.sonar.api.SonarEdition.COMMUNITY;
import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
@@ -52,8 +55,15 @@ public class GlobalSystemSectionTest {
private SecurityRealmFactory securityRealmFactory = mock(SecurityRealmFactory.class);
private DockerSupport dockerSupport = mock(DockerSupport.class);
+
+ private SonarRuntime sonarRuntime = mock(SonarRuntime.class);
private GlobalSystemSection underTest = new GlobalSystemSection(settings.asConfig(),
- server, securityRealmFactory, identityProviderRepository, dockerSupport);
+ server, securityRealmFactory, identityProviderRepository, dockerSupport, sonarRuntime);
+
+ @Before
+ public void setUp() {
+ when(sonarRuntime.getEdition()).thenReturn(COMMUNITY);
+ }
@Test
public void name_is_not_empty() {
@@ -141,6 +151,12 @@ public class GlobalSystemSectionTest {
assertThatAttributeIs(protobuf, "Docker", flag);
}
+ @Test
+ public void get_edition() {
+ ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
+ assertThatAttributeIs(protobuf, "Edition", COMMUNITY.getLabel());
+ }
+
@DataProvider
public static Object[][] trueOrFalse() {
return new Object[][] {