
* stable-2.15:
Skip migrating inline comments on missing patch set parents
Temporarily increase heap size of NoteDb migration tests
Log the reason why a project cannot be found
Change kind cache: short-circuit on root commits
Document that gitweb.type must be set
Tidy up config-gitweb
Change kind cache: short-circuit on root commits
Do not abort indexing if < 50% projects failed
Improve documentation of `index.maxLimit` for Elasticsearch
InitIndex: Set Elasticsearch index config under elasticsearch section
Link to hashtag intro docs from more places
user-upload.txt: Document setting hashtags on push
intro-user.txt: Document hashtags
user-search.txt: Document hashtag operator
intro-user.txt: Mention that topics may affect submission
Add NoteDb migration test for change with no patch set refs
NoteDbMigrator: Totally skip changes with no patch sets
Add more tests for rebuilding changes missing some entities
Fix Change-Id in revert email
Widen set of My Drafts menus that are automatically removed
Migrate old My Drafts menus in refs/users/default
This partially reverts commit e518d9dacc
because Schema_159_to_160_Test references PREFERENCES which was made
private, and uses the forDefault method which was removed. This commit
makes PREFERENCES package visible and re-adds the forDefault method as
a package visible method.
Change-Id: Ifba662a47197b3a5f17988fc69896cdca1ff853b
102 lines
3.5 KiB
Java
102 lines
3.5 KiB
Java
// Copyright (C) 2013 The Android Open Source Project
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package com.google.gerrit.pgm.init;
|
|
|
|
import com.google.common.collect.Iterables;
|
|
import com.google.common.collect.Sets;
|
|
import com.google.gerrit.index.SchemaDefinitions;
|
|
import com.google.gerrit.pgm.init.api.ConsoleUI;
|
|
import com.google.gerrit.pgm.init.api.InitFlags;
|
|
import com.google.gerrit.pgm.init.api.InitStep;
|
|
import com.google.gerrit.pgm.init.api.Section;
|
|
import com.google.gerrit.server.config.SitePaths;
|
|
import com.google.gerrit.server.index.IndexModule;
|
|
import com.google.gerrit.server.index.IndexModule.IndexType;
|
|
import com.google.gerrit.server.index.IndexUtils;
|
|
import com.google.inject.Inject;
|
|
import com.google.inject.Singleton;
|
|
import java.io.IOException;
|
|
import java.nio.file.DirectoryStream;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
|
|
/** Initialize the {@code index} configuration section. */
|
|
@Singleton
|
|
class InitIndex implements InitStep {
|
|
private final ConsoleUI ui;
|
|
private final Section index;
|
|
private final SitePaths site;
|
|
private final InitFlags initFlags;
|
|
private final Section gerrit;
|
|
private final Section.Factory sections;
|
|
|
|
@Inject
|
|
InitIndex(ConsoleUI ui, Section.Factory sections, SitePaths site, InitFlags initFlags) {
|
|
this.ui = ui;
|
|
this.index = sections.get("index", null);
|
|
this.gerrit = sections.get("gerrit", null);
|
|
this.site = site;
|
|
this.initFlags = initFlags;
|
|
this.sections = sections;
|
|
}
|
|
|
|
@Override
|
|
public void run() throws IOException {
|
|
IndexType type = IndexType.LUCENE;
|
|
if (IndexType.values().length > 1) {
|
|
ui.header("Index");
|
|
type = index.select("Type", "type", type);
|
|
}
|
|
|
|
if (type == IndexType.ELASTICSEARCH) {
|
|
Section elasticsearch = sections.get("elasticsearch", null);
|
|
elasticsearch.string("Index Prefix", "prefix", "gerrit");
|
|
String name = ui.readString("default", "Server Name");
|
|
|
|
Section defaultServer = sections.get("elasticsearch", name);
|
|
defaultServer.select(
|
|
"Transport protocol", "protocol", "http", Sets.newHashSet("http", "https"));
|
|
defaultServer.string("Hostname", "hostname", "localhost");
|
|
defaultServer.string("Port", "port", "9200");
|
|
}
|
|
|
|
if ((site.isNew || isEmptySite()) && type == IndexType.LUCENE) {
|
|
for (SchemaDefinitions<?> def : IndexModule.ALL_SCHEMA_DEFS) {
|
|
IndexUtils.setReady(site, def.getName(), def.getLatest().getVersion(), true);
|
|
}
|
|
} else {
|
|
if (IndexType.values().length <= 1) {
|
|
ui.header("Index");
|
|
}
|
|
String message =
|
|
String.format(
|
|
"\nThe index must be %sbuilt before starting Gerrit:\n"
|
|
+ " java -jar gerrit.war reindex -d site_path\n",
|
|
site.isNew ? "" : "re");
|
|
ui.message(message);
|
|
initFlags.autoStart = false;
|
|
}
|
|
}
|
|
|
|
private boolean isEmptySite() {
|
|
try (DirectoryStream<Path> files =
|
|
Files.newDirectoryStream(site.resolve(gerrit.get("basePath")))) {
|
|
return Iterables.isEmpty(files);
|
|
} catch (IOException e) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|