Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5221996
commit 0987632
Showing
23 changed files
with
609 additions
and
55 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
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
52 changes: 52 additions & 0 deletions
52
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewDoc.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,52 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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.view.index; | |||
|
|||
import org.sonar.server.search.BaseDoc; | |||
|
|||
import java.util.List; | |||
import java.util.Map; | |||
|
|||
public class ViewDoc extends BaseDoc { | |||
|
|||
public ViewDoc(Map<String, Object> fields) { | |||
super(fields); | |||
} | |||
|
|||
public String uuid() { | |||
return getField(ViewIndexDefinition.FIELD_UUID); | |||
} | |||
|
|||
public List<String> projects() { | |||
return getField(ViewIndexDefinition.FIELD_PROJECTS); | |||
} | |||
|
|||
public ViewDoc setUuid(String s) { | |||
setField(ViewIndexDefinition.FIELD_UUID, s); | |||
return this; | |||
} | |||
|
|||
public ViewDoc setProjects(List<String> s) { | |||
setField(ViewIndexDefinition.FIELD_PROJECTS, s); | |||
return this; | |||
} | |||
|
|||
} |
66 changes: 66 additions & 0 deletions
66
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexDefinition.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,66 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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.view.index; | |||
|
|||
import com.google.common.collect.ImmutableMap; | |||
import org.elasticsearch.cluster.metadata.IndexMetaData; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.process.ProcessConstants; | |||
import org.sonar.server.es.IndexDefinition; | |||
import org.sonar.server.es.NewIndex; | |||
|
|||
/** | |||
* Definition of ES index "views", including settings and fields. | |||
*/ | |||
public class ViewIndexDefinition implements IndexDefinition { | |||
|
|||
public static final String INDEX = "views"; | |||
|
|||
public static final String TYPE_VIEW = "view"; | |||
|
|||
public static final String FIELD_UUID = "uuid"; | |||
public static final String FIELD_PROJECTS = "projects"; | |||
|
|||
private final Settings settings; | |||
|
|||
public ViewIndexDefinition(Settings settings) { | |||
this.settings = settings; | |||
} | |||
|
|||
@Override | |||
public void define(IndexDefinitionContext context) { | |||
NewIndex index = context.create(INDEX); | |||
|
|||
// shards | |||
boolean clusterMode = settings.getBoolean(ProcessConstants.CLUSTER_ACTIVATE); | |||
if (clusterMode) { | |||
index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4); | |||
index.getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1); | |||
// else keep defaults (one shard) | |||
} | |||
|
|||
// type "view" | |||
NewIndex.NewIndexType mapping = index.createType(TYPE_VIEW); | |||
mapping.setAttribute("_id", ImmutableMap.of("path", FIELD_UUID)); | |||
mapping.stringFieldBuilder(FIELD_UUID).build(); | |||
mapping.stringFieldBuilder(FIELD_PROJECTS).build(); | |||
} | |||
} |
102 changes: 102 additions & 0 deletions
102
server/sonar-server/src/main/java/org/sonar/server/view/index/ViewIndexer.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,102 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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.view.index; | |||
|
|||
import com.google.common.collect.Maps; | |||
import org.elasticsearch.action.update.UpdateRequest; | |||
import org.sonar.core.component.ComponentDto; | |||
import org.sonar.core.persistence.DbSession; | |||
import org.sonar.server.db.DbClient; | |||
import org.sonar.server.es.BaseIndexer; | |||
import org.sonar.server.es.BulkIndexer; | |||
import org.sonar.server.es.EsClient; | |||
|
|||
import java.util.List; | |||
import java.util.Map; | |||
|
|||
import static com.google.common.collect.Maps.newHashMap; | |||
|
|||
public class ViewIndexer extends BaseIndexer { | |||
|
|||
private final DbClient dbClient; | |||
private final EsClient esClient; | |||
|
|||
public ViewIndexer(DbClient dbClient, EsClient esClient) { | |||
super(esClient, 300, ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW); | |||
this.dbClient = dbClient; | |||
this.esClient = esClient; | |||
} | |||
|
|||
@Override | |||
protected long doIndex(long lastUpdatedAt) { | |||
// Index only if index is empty | |||
long count = esClient.prepareCount(ViewIndexDefinition.INDEX).setTypes(ViewIndexDefinition.TYPE_VIEW).get().getCount(); | |||
if (count == 0) { | |||
DbSession dbSession = dbClient.openSession(false); | |||
try { | |||
Map<String, String> viewAndProjectViewUuidMap = newHashMap(); | |||
for (Map<String, String> viewsMap : dbClient.componentDao().selectAllViewsAndSubViews(dbSession)) { | |||
viewAndProjectViewUuidMap.put(viewsMap.get("uuid"), viewsMap.get("projectUuid")); | |||
} | |||
index(dbSession, viewAndProjectViewUuidMap); | |||
} finally { | |||
dbSession.close(); | |||
} | |||
} | |||
return 0L; | |||
} | |||
|
|||
public void index(String rootViewUuid) { | |||
DbSession dbSession = dbClient.openSession(false); | |||
try { | |||
Map<String, String> viewAndProjectViewUuidMap = newHashMap(); | |||
for (ComponentDto viewOrSubView : dbClient.componentDao().selectModulesTree(dbSession, rootViewUuid)) { | |||
viewAndProjectViewUuidMap.put(viewOrSubView.uuid(), viewOrSubView.projectUuid()); | |||
} | |||
index(dbSession, viewAndProjectViewUuidMap); | |||
} finally { | |||
dbSession.close(); | |||
} | |||
} | |||
|
|||
private void index(DbSession dbSession, Map<String, String> viewAndProjectViewUuidMap) { | |||
final BulkIndexer bulk = new BulkIndexer(esClient, ViewIndexDefinition.INDEX); | |||
bulk.start(); | |||
for (Map.Entry<String, String> entry : viewAndProjectViewUuidMap.entrySet()) { | |||
doIndex(dbSession, bulk, entry.getKey(), entry.getValue()); | |||
} | |||
bulk.stop(); | |||
} | |||
|
|||
private void doIndex(DbSession dbSession, BulkIndexer bulk, String uuid, String projectUuid) { | |||
List<String> projects = dbClient.componentDao().selectProjectsFromView(dbSession, projectUuid, uuid); | |||
bulk.add(newUpsertRequest(new ViewDoc(Maps.<String, Object>newHashMap()) | |||
.setUuid(uuid) | |||
.setProjects(projects))); | |||
} | |||
|
|||
private UpdateRequest newUpsertRequest(ViewDoc doc) { | |||
return new UpdateRequest(ViewIndexDefinition.INDEX, ViewIndexDefinition.TYPE_VIEW, doc.uuid()) | |||
.doc(doc.getFields()) | |||
.upsert(doc.getFields()); | |||
} | |||
|
|||
} |
25 changes: 25 additions & 0 deletions
25
server/sonar-server/src/main/java/org/sonar/server/view/index/package-info.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,25 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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. | |||
*/ | |||
|
|||
@ParametersAreNonnullByDefault | |||
package org.sonar.server.view.index; | |||
|
|||
import javax.annotation.ParametersAreNonnullByDefault; | |||
|
Oops, something went wrong.