Search in sources :

Example 1 with COMMUNITY

use of org.sonar.core.platform.EditionProvider.Edition.COMMUNITY in project sonarqube by SonarSource.

the class TelemetryDataLoaderImpl method load.

@Override
public TelemetryData load() {
    TelemetryData.Builder data = TelemetryData.builder();
    data.setServerId(server.getId());
    data.setVersion(server.getVersion());
    data.setEdition(editionProvider.get().orElse(null));
    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).build();
        data.setNcloc(dbClient.liveMeasureDao().sumNclocOfBiggestBranch(dbSession, query));
        long numberOfUnanalyzedCMeasures = dbClient.liveMeasureDao().countProjectsHavingMeasure(dbSession, UNANALYZED_C_KEY);
        long numberOfUnanalyzedCppMeasures = dbClient.liveMeasureDao().countProjectsHavingMeasure(dbSession, UNANALYZED_CPP_KEY);
        editionProvider.get().filter(edition -> edition.equals(COMMUNITY)).ifPresent(edition -> {
            data.setHasUnanalyzedC(numberOfUnanalyzedCMeasures > 0);
            data.setHasUnanalyzedCpp(numberOfUnanalyzedCppMeasures > 0);
        });
        data.setAlmIntegrationCountByAlm(countAlmUsage(dbSession));
        data.setExternalAuthenticationProviders(dbClient.userDao().selectExternalIdentityProviders(dbSession));
        data.setSonarlintWeeklyUsers(dbClient.userDao().countSonarlintWeeklyUsers(dbSession));
        addScmInformationToTelemetry(dbSession, data);
        addCiInformationToTelemetry(dbSession, data);
    }
    setSecurityCustomConfigIfPresent(data);
    Optional<String> installationDateProperty = internalProperties.read(InternalProperties.INSTALLATION_DATE);
    installationDateProperty.ifPresent(s -> data.setInstallationDate(Long.valueOf(s)));
    Optional<String> installationVersionProperty = internalProperties.read(InternalProperties.INSTALLATION_VERSION);
    data.setInstallationVersion(installationVersionProperty.orElse(null));
    data.setInDocker(dockerSupport.isRunningInDocker());
    return data.build();
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) SumNclocDbQuery(org.sonar.db.measure.SumNclocDbQuery) COMMUNITY(org.sonar.core.platform.EditionProvider.Edition.COMMUNITY) CorePropertyDefinitions(org.sonar.core.config.CorePropertyDefinitions) DatabaseMetaData(java.sql.DatabaseMetaData) Server(org.sonar.api.platform.Server) ProjectMeasuresStatistics(org.sonar.server.measure.index.ProjectMeasuresStatistics) ALM(org.sonar.db.alm.setting.ALM) Function(java.util.function.Function) DbSession(org.sonar.db.DbSession) Inject(javax.inject.Inject) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) SQLException(java.sql.SQLException) PluginInfo(org.sonar.core.platform.PluginInfo) Arrays.asList(java.util.Arrays.asList) ENTERPRISE(org.sonar.core.platform.EditionProvider.Edition.ENTERPRISE) Map(java.util.Map) Configuration(org.sonar.api.config.Configuration) InternalProperties(org.sonar.server.property.InternalProperties) DATACENTER(org.sonar.core.platform.EditionProvider.Edition.DATACENTER) LinkedList(java.util.LinkedList) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Nullable(javax.annotation.Nullable) StringUtils.startsWith(org.apache.commons.lang.StringUtils.startsWith) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) DockerSupport(org.sonar.server.platform.DockerSupport) Optional.ofNullable(java.util.Optional.ofNullable) ProjectCountPerAnalysisPropertyValue(org.sonar.db.component.ProjectCountPerAnalysisPropertyValue) UserIndex(org.sonar.server.user.index.UserIndex) Collectors(java.util.stream.Collectors) PluginRepository(org.sonar.core.platform.PluginRepository) DbClient(org.sonar.db.DbClient) List(java.util.List) SearchOptions(org.sonar.server.es.SearchOptions) ServerSide(org.sonar.api.server.ServerSide) Optional(java.util.Optional) UNANALYZED_CPP_KEY(org.sonar.server.metric.UnanalyzedLanguageMetrics.UNANALYZED_CPP_KEY) UserQuery(org.sonar.server.user.index.UserQuery) CheckForNull(javax.annotation.CheckForNull) Database(org.sonar.server.telemetry.TelemetryData.Database) UNANALYZED_C_KEY(org.sonar.server.metric.UnanalyzedLanguageMetrics.UNANALYZED_C_KEY) SearchOptions(org.sonar.server.es.SearchOptions) SumNclocDbQuery(org.sonar.db.measure.SumNclocDbQuery) ProjectMeasuresStatistics(org.sonar.server.measure.index.ProjectMeasuresStatistics) DbSession(org.sonar.db.DbSession) PluginInfo(org.sonar.core.platform.PluginInfo)

Aggregations

DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 Arrays.asList (java.util.Arrays.asList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 CheckForNull (javax.annotation.CheckForNull)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 StringUtils.startsWith (org.apache.commons.lang.StringUtils.startsWith)1 Configuration (org.sonar.api.config.Configuration)1 Server (org.sonar.api.platform.Server)1 ServerSide (org.sonar.api.server.ServerSide)1 CorePropertyDefinitions (org.sonar.core.config.CorePropertyDefinitions)1 COMMUNITY (org.sonar.core.platform.EditionProvider.Edition.COMMUNITY)1 DATACENTER (org.sonar.core.platform.EditionProvider.Edition.DATACENTER)1