Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-9721 Extract TelemetryDataLoader from TelemetryDataDaemon
- Loading branch information
Showing
8 changed files
with
229 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,133 @@ | |||
/* | |||
* 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.telemetry; | |||
|
|||
import java.util.Map; | |||
import org.sonar.server.measure.index.ProjectMeasuresStatistics; | |||
|
|||
import static java.util.Objects.requireNonNull; | |||
|
|||
public class TelemetryData { | |||
private final String serverId; | |||
private final String version; | |||
private final Map<String, String> plugins; | |||
private final long lines; | |||
private final long ncloc; | |||
private final long userCount; | |||
private final long projectCount; | |||
private final Map<String, Long> projectCountByLanguage; | |||
private final Map<String, Long> nclocByLanguage; | |||
|
|||
public TelemetryData(Builder builder) { | |||
serverId = builder.serverId; | |||
version = builder.version; | |||
plugins = builder.plugins; | |||
lines = builder.projectMeasuresStatistics.getLines(); | |||
ncloc = builder.projectMeasuresStatistics.getNcloc(); | |||
userCount = builder.userCount; | |||
projectCount = builder.projectMeasuresStatistics.getProjectCount(); | |||
projectCountByLanguage = builder.projectMeasuresStatistics.getProjectCountByLanguage(); | |||
nclocByLanguage = builder.projectMeasuresStatistics.getNclocByLanguage(); | |||
} | |||
|
|||
public String getServerId() { | |||
return serverId; | |||
} | |||
|
|||
public String getVersion() { | |||
return version; | |||
} | |||
|
|||
public Map<String, String> getPlugins() { | |||
return plugins; | |||
} | |||
|
|||
public long getLines() { | |||
return lines; | |||
} | |||
|
|||
public long getNcloc() { | |||
return ncloc; | |||
} | |||
|
|||
public long getUserCount() { | |||
return userCount; | |||
} | |||
|
|||
public long getProjectCount() { | |||
return projectCount; | |||
} | |||
|
|||
public Map<String, Long> getProjectCountByLanguage() { | |||
return projectCountByLanguage; | |||
} | |||
|
|||
public Map<String, Long> getNclocByLanguage() { | |||
return nclocByLanguage; | |||
} | |||
|
|||
static Builder builder() { | |||
return new Builder(); | |||
} | |||
|
|||
static class Builder { | |||
private String serverId; | |||
private String version; | |||
private long userCount; | |||
private Map<String, String> plugins; | |||
private ProjectMeasuresStatistics projectMeasuresStatistics; | |||
|
|||
private Builder() { | |||
// enforce static factory method | |||
} | |||
|
|||
Builder setServerId(String serverId) { | |||
this.serverId = serverId; | |||
return this; | |||
} | |||
|
|||
Builder setVersion(String version) { | |||
this.version = version; | |||
return this; | |||
} | |||
|
|||
void setUserCount(long userCount) { | |||
this.userCount = userCount; | |||
} | |||
|
|||
void setPlugins(Map<String, String> plugins) { | |||
this.plugins = plugins; | |||
} | |||
|
|||
void setProjectMeasuresStatistics(ProjectMeasuresStatistics projectMeasuresStatistics) { | |||
this.projectMeasuresStatistics = projectMeasuresStatistics; | |||
} | |||
|
|||
TelemetryData build() { | |||
requireNonNull(serverId); | |||
requireNonNull(version); | |||
requireNonNull(plugins); | |||
requireNonNull(projectMeasuresStatistics); | |||
|
|||
return new TelemetryData(this); | |||
} | |||
} | |||
} |
69 changes: 69 additions & 0 deletions
69
server/sonar-server/src/main/java/org/sonar/server/telemetry/TelemetryDataLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,69 @@ | |||
/* | |||
* 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.telemetry; | |||
|
|||
import java.util.Map; | |||
import java.util.function.Function; | |||
import org.sonar.api.platform.Server; | |||
import org.sonar.api.server.ServerSide; | |||
import org.sonar.core.platform.PluginInfo; | |||
import org.sonar.core.platform.PluginRepository; | |||
import org.sonar.core.util.stream.MoreCollectors; | |||
import org.sonar.server.es.SearchOptions; | |||
import org.sonar.server.measure.index.ProjectMeasuresIndex; | |||
import org.sonar.server.measure.index.ProjectMeasuresStatistics; | |||
import org.sonar.server.user.index.UserIndex; | |||
import org.sonar.server.user.index.UserQuery; | |||
|
|||
@ServerSide | |||
public class TelemetryDataLoader { | |||
private final Server server; | |||
private final PluginRepository pluginRepository; | |||
private final UserIndex userIndex; | |||
private final ProjectMeasuresIndex projectMeasuresIndex; | |||
|
|||
public TelemetryDataLoader(Server server, PluginRepository pluginRepository, UserIndex userIndex, ProjectMeasuresIndex projectMeasuresIndex) { | |||
this.server = server; | |||
this.pluginRepository = pluginRepository; | |||
this.userIndex = userIndex; | |||
this.projectMeasuresIndex = projectMeasuresIndex; | |||
} | |||
|
|||
public TelemetryData load() { | |||
TelemetryData.Builder data = TelemetryData.builder(); | |||
|
|||
data.setServerId(server.getId()); | |||
data.setVersion(server.getVersion()); | |||
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); | |||
|
|||
return data.build(); | |||
} | |||
|
|||
String loadServerId() { | |||
return server.getId(); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters