*/
package org.sonar.server.platform.monitoring;
+import java.util.Collection;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.TreeMap;
+import java.util.stream.Stream;
import org.sonar.api.PropertyType;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
+import org.sonar.process.ProcessProperties.Property;
import org.sonar.process.systeminfo.Global;
import org.sonar.process.systeminfo.SystemInfoSection;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo.Section.Builder;
+import org.sonar.server.platform.NodeInformation;
+import static java.util.stream.Collectors.toUnmodifiableSet;
import static org.apache.commons.lang.StringUtils.abbreviate;
import static org.apache.commons.lang.StringUtils.containsIgnoreCase;
import static org.apache.commons.lang.StringUtils.endsWithIgnoreCase;
import static org.sonar.process.ProcessProperties.Property.AUTH_JWT_SECRET;
+import static org.sonar.process.ProcessProperties.Property.CE_JAVA_ADDITIONAL_OPTS;
+import static org.sonar.process.ProcessProperties.Property.CE_JAVA_OPTS;
+import static org.sonar.process.ProcessProperties.Property.SEARCH_JAVA_ADDITIONAL_OPTS;
+import static org.sonar.process.ProcessProperties.Property.SEARCH_JAVA_OPTS;
+import static org.sonar.process.ProcessProperties.Property.WEB_JAVA_ADDITIONAL_OPTS;
+import static org.sonar.process.ProcessProperties.Property.WEB_JAVA_OPTS;
import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
@ServerSide
public class SettingsSection implements SystemInfoSection, Global {
private static final int MAX_VALUE_LENGTH = 500;
private static final String PASSWORD_VALUE = "xxxxxxxx";
+ private static final Collection<String> IGNORED_SETTINGS_IN_CLUSTER = Stream.of(
+ WEB_JAVA_OPTS,
+ WEB_JAVA_ADDITIONAL_OPTS,
+ CE_JAVA_OPTS,
+ CE_JAVA_ADDITIONAL_OPTS,
+ SEARCH_JAVA_OPTS,
+ SEARCH_JAVA_ADDITIONAL_OPTS)
+ .map(Property::getKey)
+ .collect(toUnmodifiableSet());
private final DbClient dbClient;
private final Settings settings;
+ private final NodeInformation nodeInformation;
- public SettingsSection(DbClient dbClient, Settings settings) {
+ public SettingsSection(DbClient dbClient, Settings settings, NodeInformation nodeInformation) {
this.dbClient = dbClient;
this.settings = settings;
+ this.nodeInformation = nodeInformation;
}
@Override
PropertyDefinitions definitions = settings.getDefinitions();
TreeMap<String, String> orderedProps = new TreeMap<>(settings.getProperties());
- for (Entry<String, String> prop : orderedProps.entrySet()) {
- includeSetting(protobuf, definitions, prop);
- }
+ orderedProps.entrySet()
+ .stream()
+ .filter(prop -> nodeInformation.isStandalone() || !IGNORED_SETTINGS_IN_CLUSTER.contains(prop.getKey()))
+ .forEach(prop -> includeSetting(protobuf, definitions, prop));
addDefaultNewCodeDefinition(protobuf);
return protobuf.build();
}
- private static void includeSetting(Builder protobuf, PropertyDefinitions definitions, Entry<String, String> prop) {
+ private void includeSetting(Builder protobuf, PropertyDefinitions definitions, Entry<String, String> prop) {
String key = prop.getKey();
String value = obfuscateValue(definitions, key, prop.getValue());
setAttribute(protobuf, key, value);
*/
package org.sonar.server.platform.monitoring;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.PropertyType;
import org.sonar.db.DbTester;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
+import org.sonar.server.platform.NodeInformation;
import static org.apache.commons.lang.StringUtils.repeat;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.process.ProcessProperties.Property.CE_JAVA_OPTS;
+import static org.sonar.process.ProcessProperties.Property.SEARCH_JAVA_OPTS;
+import static org.sonar.process.ProcessProperties.Property.WEB_JAVA_OPTS;
import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
+import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeDoesNotExist;
import static org.sonar.server.platform.monitoring.SystemInfoTesting.assertThatAttributeIs;
public class SettingsSectionTest {
private PropertyDefinitions defs = new PropertyDefinitions(System2.INSTANCE, PropertyDefinition.builder(PASSWORD_PROPERTY).type(PropertyType.PASSWORD).build());
private Settings settings = new MapSettings(defs);
- private SettingsSection underTest = new SettingsSection(dbTester.getDbClient(), settings);
+ private NodeInformation nodeInformation = mock(NodeInformation.class);
+ private SettingsSection underTest= new SettingsSection(dbTester.getDbClient(), settings, nodeInformation);
+
+ @Before
+ public void setup(){
+ when(nodeInformation.isStandalone()).thenReturn(true);
+ }
+
+ @Test
+ public void should_show_java_settings_in_standalone(){
+ settings.setProperty(WEB_JAVA_OPTS.getKey(), WEB_JAVA_OPTS.getDefaultValue());
+ settings.setProperty(CE_JAVA_OPTS.getKey(), CE_JAVA_OPTS.getDefaultValue());
+ settings.setProperty(SEARCH_JAVA_OPTS.getKey(), SEARCH_JAVA_OPTS.getDefaultValue());
+
+ ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
+
+ assertThatAttributeIs(protobuf, WEB_JAVA_OPTS.getKey(), WEB_JAVA_OPTS.getDefaultValue());
+ assertThatAttributeIs(protobuf, CE_JAVA_OPTS.getKey(), CE_JAVA_OPTS.getDefaultValue());
+ assertThatAttributeIs(protobuf, SEARCH_JAVA_OPTS.getKey(), SEARCH_JAVA_OPTS.getDefaultValue());
+ }
+ @Test
+ public void should_not_show_java_settings_in_cluster(){
+ when(nodeInformation.isStandalone()).thenReturn(false);
+ settings.setProperty(WEB_JAVA_OPTS.getKey(), WEB_JAVA_OPTS.getDefaultValue());
+ settings.setProperty(CE_JAVA_OPTS.getKey(), CE_JAVA_OPTS.getDefaultValue());
+ settings.setProperty(SEARCH_JAVA_OPTS.getKey(), SEARCH_JAVA_OPTS.getDefaultValue());
+
+ ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
+
+ assertThatAttributeDoesNotExist(protobuf, WEB_JAVA_OPTS.getKey());
+ assertThatAttributeDoesNotExist(protobuf, CE_JAVA_OPTS.getKey());
+ assertThatAttributeDoesNotExist(protobuf, SEARCH_JAVA_OPTS.getKey());
+ }
@Test
public void return_properties_and_sort_by_key() {