*/
package org.sonar.process.systeminfo;
+import java.util.Collection;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
}
}
+ public static void setAttribute(ProtobufSystemInfo.Section.Builder section, String key, @Nullable Collection<String> values) {
+ if (values != null) {
+ section.addAttributesBuilder()
+ .setKey(key)
+ .addAllStringValues(values)
+ .build();
+ }
+ }
+
public static void setAttribute(ProtobufSystemInfo.Section.Builder section, String key, boolean value) {
section.addAttributesBuilder()
.setKey(key)
double double_value = 4;
string string_value = 5;
}
+ repeated string string_values = 6;
}
import org.sonar.process.ProcessProperties;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
import org.sonar.server.authentication.IdentityProviderRepository;
+import org.sonar.server.health.Health;
+import org.sonar.server.health.HealthChecker;
import org.sonar.server.platform.ServerIdLoader;
import org.sonar.server.platform.ServerLogging;
import org.sonar.server.user.SecurityRealmFactory;
private final Server server;
private final ServerLogging serverLogging;
private final ServerIdLoader serverIdLoader;
+ private final HealthChecker healthChecker;
public SonarQubeSection(Configuration config, SecurityRealmFactory securityRealmFactory,
IdentityProviderRepository identityProviderRepository, Server server, ServerLogging serverLogging,
- ServerIdLoader serverIdLoader) {
+ ServerIdLoader serverIdLoader, HealthChecker healthChecker) {
this.config = config;
this.securityRealmFactory = securityRealmFactory;
this.identityProviderRepository = identityProviderRepository;
this.server = server;
this.serverLogging = serverLogging;
this.serverIdLoader = serverIdLoader;
+ this.healthChecker = healthChecker;
}
@Override
setAttribute(protobuf, "Server ID", serverId.getId());
setAttribute(protobuf, "Server ID validated", serverId.isValid());
});
+ Health health = healthChecker.checkNode();
+ setAttribute(protobuf, "Health", health.getStatus().name());
+ setAttribute(protobuf, "Health Causes", health.getCauses());
setAttribute(protobuf, "Version", getVersion());
setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication());
addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders());
json.prop(attribute.getKey(), attribute.getStringValue());
break;
case VALUE_NOT_SET:
+ json.name(attribute.getKey()).beginArray().values(attribute.getStringValuesList()).endArray();
break;
default:
throw new IllegalArgumentException("Unsupported type: " + attribute.getValueCase());
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.health;
+
+public class TestStandaloneHealthChecker implements HealthChecker {
+
+ private Health health = Health.newHealthCheckBuilder().setStatus(Health.Status.GREEN).build();
+
+ public void setHealth(Health h) {
+ this.health = h;
+ }
+
+ @Override
+ public Health checkNode() {
+ return health;
+ }
+
+ @Override
+ public ClusterHealth checkCluster() {
+ throw new IllegalStateException();
+ }
+}
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
import org.sonar.server.authentication.IdentityProviderRepositoryRule;
import org.sonar.server.authentication.TestIdentityProvider;
+import org.sonar.server.health.Health;
+import org.sonar.server.health.TestStandaloneHealthChecker;
import org.sonar.server.platform.ServerId;
import org.sonar.server.platform.ServerIdLoader;
import org.sonar.server.platform.ServerLogging;
import org.sonar.server.user.SecurityRealmFactory;
+import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
private ServerIdLoader serverIdLoader = mock(ServerIdLoader.class);
private ServerLogging serverLogging = mock(ServerLogging.class);
private SecurityRealmFactory securityRealmFactory = mock(SecurityRealmFactory.class);
+ private TestStandaloneHealthChecker healthChecker = new TestStandaloneHealthChecker();
private SonarQubeSection underTest = new SonarQubeSection(settings.asConfig(), securityRealmFactory, identityProviderRepository, server,
- serverLogging, serverIdLoader);
+ serverLogging, serverIdLoader, healthChecker);
@Before
public void setUp() throws Exception {
ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
assertThatAttributeIs(protobuf, "External identity providers whose users are allowed to sign themselves up", "GitHub");
}
+
+ @Test
+ public void return_health() {
+ healthChecker.setHealth(Health.newHealthCheckBuilder()
+ .setStatus(Health.Status.YELLOW)
+ .addCause("foo")
+ .addCause("bar")
+ .build());
+
+ ProtobufSystemInfo.Section protobuf = underTest.toProtobuf();
+ assertThatAttributeIs(protobuf, "Health", "YELLOW");
+ SystemInfoTesting.assertThatAttributeHasOnlyValues(protobuf, "Health Causes", asList("foo", "bar"));
+ }
}
*/
package org.sonar.server.platform.monitoring;
+import java.util.Collection;
import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
-import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.process.systeminfo.SystemInfoUtils.attribute;
public class SystemInfoTesting {
assertThat(value).as(key).isNotNull();
assertThat(value.getBooleanValue()).isEqualTo(expectedValue);
}
+
+ public static void assertThatAttributeHasOnlyValues(ProtobufSystemInfo.Section section, String key, Collection<String> expectedValues) {
+ ProtobufSystemInfo.Attribute value = attribute(section, key);
+ assertThat(value).as(key).isNotNull();
+ assertThat((Collection<String>)value.getStringValuesList()).containsExactlyInAnyOrder(expectedValues.toArray(new String[expectedValues.size()]));
+ }
}