Line data Source code
1 : // Copyright (C) 2019 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.notedb.Sequences; 20 : import com.google.gerrit.sshd.CommandMetaData; 21 : import com.google.gerrit.sshd.SshCommand; 22 : import com.google.inject.Inject; 23 : import org.kohsuke.args4j.Argument; 24 : 25 : /** Set sequence value. */ 26 : @RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER) 27 : @CommandMetaData(name = "set", description = "Set the sequence value") 28 1 : final class SequenceSetCommand extends SshCommand { 29 : @Argument(index = 0, metaVar = "NAME", required = true, usage = "sequence name") 30 : private String name; 31 : 32 : @Argument(index = 1, metaVar = "VALUE", required = true, usage = "sequence value") 33 : private int value; 34 : 35 : @Inject Sequences sequences; 36 : 37 : @Override 38 : public void run() throws Exception { 39 0 : switch (name) { 40 : case "changes": 41 0 : sequences.setChangeIdValue(value); 42 0 : break; 43 : case "accounts": 44 0 : sequences.setAccountIdValue(value); 45 0 : break; 46 : case "groups": 47 0 : sequences.setGroupIdValue(value); 48 0 : break; 49 : default: 50 0 : throw die("Unknown sequence name: " + name); 51 : } 52 0 : stdout.print("The value for the " + name + " sequence was set to " + value + "."); 53 0 : stdout.print('\n'); 54 0 : stdout.flush(); 55 0 : } 56 : }