Line data Source code
1 : // Copyright (C) 2015 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.sshd.commands; 16 : 17 : import com.google.gerrit.common.data.GlobalCapability; 18 : import com.google.gerrit.extensions.annotations.RequiresCapability; 19 : import com.google.gerrit.server.index.ReindexerAlreadyRunningException; 20 : import com.google.gerrit.server.index.VersionManager; 21 : import com.google.gerrit.sshd.CommandMetaData; 22 : import com.google.gerrit.sshd.SshCommand; 23 : import com.google.inject.Inject; 24 : import org.kohsuke.args4j.Argument; 25 : import org.kohsuke.args4j.Option; 26 : 27 : @RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER) 28 : @CommandMetaData(name = "start", description = "Start the online reindexer") 29 0 : public class IndexStartCommand extends SshCommand { 30 : 31 : @Option(name = "--force", usage = "force a re-index") 32 : private boolean force; 33 : 34 : @Argument(index = 0, required = true, metaVar = "INDEX", usage = "index name to start") 35 : private String name; 36 : 37 : @Inject private VersionManager versionManager; 38 : 39 : @Override 40 : protected void run() throws UnloggedFailure { 41 0 : enableGracefulStop(); 42 : try { 43 0 : if (versionManager.isKnownIndex(name)) { 44 0 : if (versionManager.startReindexer(name, force)) { 45 0 : stdout.println("Reindexer started"); 46 : } else { 47 0 : stdout.println("Nothing to reindex, index is already the latest version"); 48 : } 49 : } else { 50 0 : stderr.println(String.format("Cannot reindex %s: unknown", name)); 51 : } 52 0 : } catch (ReindexerAlreadyRunningException e) { 53 0 : throw die("Failed to start reindexer: " + e.getMessage()); 54 0 : } 55 0 : } 56 : }