@Override public String getServerId() { return server.getId(); }
String loadServerId() { return server.getId(); }
@Override public void start() { Loggers.get(getClass()).info("Server ID: " + server.getId()); }
@Override public void handle(Request request, Response response) throws Exception { System.StatusResponse.Builder protobuf = System.StatusResponse.newBuilder(); ofNullable(server.getId()).ifPresent(protobuf::setId); ofNullable(server.getVersion()).ifPresent(protobuf::setVersion); protobuf.setStatus(computeStatus()); WsUtils.writeProtobuf(protobuf.build(), request, response); }
@Test public void test_getServerId() { when(server.getId()).thenReturn("ABC"); assertThat(underTest.getServerId()).isEqualTo("ABC"); }
@Test public void log_server_id_at_startup() { Server server = mock(Server.class); when(server.getId()).thenReturn("foo"); LogServerId underTest = new LogServerId(server); underTest.start(); assertThat(logTester.logs(LoggerLevel.INFO)).contains("Server ID: foo"); // do not fail underTest.stop(); } }
@Override public void handle(Request request, Response response) { userSession .checkLoggedIn() .checkIsSystemAdministrator(); Navigation.MarketplaceResponse responsePayload = Navigation.MarketplaceResponse.newBuilder() .setNcloc(computeNcloc()) .setServerId(server.getId()) .build(); writeProtobuf(responsePayload, request, response); }
@Test public void returns_server_id_and_nloc() { userSessionRule.logIn().setSystemAdministrator(); when(server.getId()).thenReturn("myserver"); long ncloc = 256L; setNcloc(ncloc); Navigation.MarketplaceResponse expectedResponse = Navigation.MarketplaceResponse.newBuilder() .setServerId("myserver") .setNcloc(ncloc) .build(); Navigation.MarketplaceResponse result = ws.newRequest().executeProtobuf(Navigation.MarketplaceResponse.class); assertThat(result).isEqualTo(expectedResponse); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Server ID", server.getId()); setAttribute(protobuf, "Version", getVersion()); setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication()); addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders()); addIfNotEmpty(protobuf, "External identity providers whose users are allowed to sign themselves up", getAllowsToSignUpEnabledIdentityProviders()); setAttribute(protobuf, "High Availability", false); setAttribute(protobuf, "Official Distribution", officialDistribution.check()); setAttribute(protobuf, "Force authentication", getForceAuthentication()); setAttribute(protobuf, "Home Dir", config.get(PATH_HOME.getKey()).orElse(null)); setAttribute(protobuf, "Data Dir", config.get(PATH_DATA.getKey()).orElse(null)); setAttribute(protobuf, "Temp Dir", config.get(PATH_TEMP.getKey()).orElse(null)); setAttribute(protobuf, "Processors", Runtime.getRuntime().availableProcessors()); return protobuf.build(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Server ID", server.getId()); setAttribute(protobuf, "High Availability", true); setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication()); addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders()); addIfNotEmpty(protobuf, "External identity providers whose users are allowed to sign themselves up", getAllowsToSignUpEnabledIdentityProviders()); setAttribute(protobuf, "Force authentication", getForceAuthentication()); return protobuf.build(); }
@Test public void json_example() { userSessionRule.logIn().setSystemAdministrator(); when(server.getId()).thenReturn("AU-Tpxb--iU5OvuD2FLy"); setNcloc(12345L); String result = ws.newRequest().execute().getInput(); assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString()); }
public TelemetryData load() { TelemetryData.Builder data = TelemetryData.builder(); data.setServerId(server.getId()); data.setVersion(server.getVersion()); data.setEdition(editionProvider.get()); ofNullable(licenseReader) .flatMap(reader -> licenseReader.read()) .ifPresent(license -> data.setLicenseType(license.getType())); Function<PluginInfo, String> getVersion = plugin -> plugin.getVersion() == null ? "undefined" : plugin.getVersion().getName(); Map<String, String> plugins = pluginRepository.getPluginInfos().stream().collect(MoreCollectors.uniqueIndex(PluginInfo::getKey, getVersion)); data.setPlugins(plugins); long userCount = userIndex.search(UserQuery.builder().build(), new SearchOptions().setLimit(1)).getTotal(); data.setUserCount(userCount); ProjectMeasuresStatistics projectMeasuresStatistics = projectMeasuresIndex.searchTelemetryStatistics(); data.setProjectMeasuresStatistics(projectMeasuresStatistics); try (DbSession dbSession = dbClient.openSession(false)) { data.setDatabase(loadDatabaseMetadata(dbSession)); data.setUsingBranches(dbClient.branchDao().hasNonMainBranches(dbSession)); SumNclocDbQuery query = SumNclocDbQuery.builder() .setOnlyPrivateProjects(false) .setOrganizationUuid(defaultOrganizationProvider.get().getUuid()) .build(); data.setNcloc(dbClient.liveMeasureDao().sumNclocOfBiggestLongLivingBranch(dbSession, query)); } return data.build(); }
@Override public String getServerId() { return server.getId(); }
String loadServerId() { return server.getId(); }
@Override public void start() { Loggers.get(getClass()).info("Server ID: " + server.getId()); }
@Override public void handle(Request request, Response response) { userSession .checkLoggedIn() .checkIsSystemAdministrator(); Navigation.MarketplaceResponse responsePayload = Navigation.MarketplaceResponse.newBuilder() .setNcloc(computeNcloc()) .setServerId(server.getId()) .build(); writeProtobuf(responsePayload, request, response); }
@Override public void handle(Request request, Response response) throws Exception { System.StatusResponse.Builder protobuf = System.StatusResponse.newBuilder(); Protobuf.setNullable(server.getId(), protobuf::setId); Protobuf.setNullable(server.getVersion(), protobuf::setVersion); protobuf.setStatus(computeStatus()); WsUtils.writeProtobuf(protobuf.build(), request, response); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Server ID", server.getId()); setAttribute(protobuf, "Version", getVersion()); setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication()); addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders()); addIfNotEmpty(protobuf, "External identity providers whose users are allowed to sign themselves up", getAllowsToSignUpEnabledIdentityProviders()); setAttribute(protobuf, "High Availability", false); setAttribute(protobuf, "Official Distribution", officialDistribution.check()); setAttribute(protobuf, "Force authentication", getForceAuthentication()); setAttribute(protobuf, "Home Dir", config.get(PATH_HOME.getKey()).orElse(null)); setAttribute(protobuf, "Data Dir", config.get(PATH_DATA.getKey()).orElse(null)); setAttribute(protobuf, "Temp Dir", config.get(PATH_TEMP.getKey()).orElse(null)); setAttribute(protobuf, "Processors", Runtime.getRuntime().availableProcessors()); return protobuf.build(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Server ID", server.getId()); setAttribute(protobuf, "High Availability", true); setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication()); addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders()); addIfNotEmpty(protobuf, "External identity providers whose users are allowed to sign themselves up", getAllowsToSignUpEnabledIdentityProviders()); setAttribute(protobuf, "Force authentication", getForceAuthentication()); return protobuf.build(); }
public TelemetryData load() { TelemetryData.Builder data = TelemetryData.builder(); data.setServerId(server.getId()); data.setVersion(server.getVersion()); data.setEdition(editionProvider.get()); Function<PluginInfo, String> getVersion = plugin -> plugin.getVersion() == null ? "undefined" : plugin.getVersion().getName(); Map<String, String> plugins = pluginRepository.getPluginInfos().stream().collect(MoreCollectors.uniqueIndex(PluginInfo::getKey, getVersion)); data.setPlugins(plugins); long userCount = userIndex.search(UserQuery.builder().build(), new SearchOptions().setLimit(1)).getTotal(); data.setUserCount(userCount); ProjectMeasuresStatistics projectMeasuresStatistics = projectMeasuresIndex.searchTelemetryStatistics(); data.setProjectMeasuresStatistics(projectMeasuresStatistics); try (DbSession dbSession = dbClient.openSession(false)) { data.setDatabase(loadDatabaseMetadata(dbSession)); data.setUsingBranches(dbClient.branchDao().hasNonMainBranches(dbSession)); data.setNcloc(dbClient.liveMeasureDao().sumNclocOfBiggestLongLivingBranch(dbSession)); } return data.build(); }