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 : 26 : @RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER) 27 : @CommandMetaData(name = "activate", description = "Activate the latest index version available") 28 0 : public class IndexActivateCommand extends SshCommand { 29 : 30 : @Argument(index = 0, required = true, metaVar = "INDEX", usage = "index name to activate") 31 : private String name; 32 : 33 : @Inject private VersionManager versionManager; 34 : 35 : @Override 36 : protected void run() throws UnloggedFailure { 37 0 : enableGracefulStop(); 38 : try { 39 0 : if (versionManager.isKnownIndex(name)) { 40 0 : if (versionManager.activateLatestIndex(name)) { 41 0 : stdout.println("Activated latest index version"); 42 : } else { 43 0 : stdout.println("Not activating index, already using latest version"); 44 : } 45 : } else { 46 0 : stderr.println(String.format("Cannot activate index %s: unknown", name)); 47 : } 48 0 : } catch (ReindexerAlreadyRunningException e) { 49 0 : throw die("Failed to activate latest index: " + e.getMessage()); 50 0 : } 51 0 : } 52 : }