Add SetNumInstancesCommand in Nomulus tool to adjust the number of instances

for a given service and version at runtime.

Note that this CL only supports the adjustment for a given service and version. I will add another functionality to let this command be able to detect all non-live versions automatically and apply the adjustment.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=221092001
This commit is contained in:
shicong 2018-11-12 07:59:00 -08:00 committed by jianglai
parent 557984bb75
commit 66d98c8d66
7 changed files with 216 additions and 0 deletions

View file

@ -104,6 +104,7 @@ public final class RegistryTool {
.put("resave_environment_entities", ResaveEnvironmentEntitiesCommand.class)
.put("resave_epp_resource", ResaveEppResourceCommand.class)
.put("send_escrow_report_to_icann", SendEscrowReportToIcannCommand.class)
.put("set_num_instances", SetNumInstancesCommand.class)
.put("setup_ote", SetupOteCommand.class)
.put("uniform_rapid_suspension", UniformRapidSuspensionCommand.class)
.put("unlock_domain", UnlockDomainCommand.class)

View file

@ -98,6 +98,7 @@ interface RegistryToolComponent {
void inject(PendingEscrowCommand command);
void inject(RenewDomainCommand command);
void inject(SendEscrowReportToIcannCommand command);
void inject(SetNumInstancesCommand command);
void inject(SetupOteCommand command);
void inject(UnlockDomainCommand command);
void inject(UpdateCursorsCommand command);

View file

@ -0,0 +1,66 @@
// Copyright 2018 The Nomulus Authors. All Rights Reserved.
//
// 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 google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.flogger.FluentLogger;
import google.registry.util.AppEngineServiceUtils;
import javax.inject.Inject;
/** A command to set the number of instances for an App Engine service. */
@Parameters(
separators = " =",
commandDescription =
"Set the number of instances for a given service and version. "
+ "Note that this command only works for manual scaling service.")
final class SetNumInstancesCommand implements CommandWithRemoteApi {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Parameter(
names = "--service",
description = "Name of the App Engine service, e.g., default.",
required = true)
private String service;
@Parameter(
names = "--version",
description = "Name of the service's version, e.g., canary.",
required = true)
private String version;
@Parameter(
names = "--numInstances",
description = "The new number of instances for the version.",
required = true)
private Long numInstances;
@Inject AppEngineServiceUtils appEngineServiceUtils;
@Override
public void run() throws Exception {
checkArgument(!service.isEmpty(), "Service must be specified");
checkArgument(!version.isEmpty(), "Version must be specified");
checkArgument(numInstances > 0, "Number of instances must be greater than zero");
appEngineServiceUtils.setNumInstances(service, version, numInstances);
logger.atInfo().log(
"Successfully set version %s of service %s to %d instances.",
version, service, numInstances);
}
}

View file

@ -37,4 +37,7 @@ public interface AppEngineServiceUtils {
/** Returns a host name to use for the given service and version. */
String getVersionHostname(String service, String version);
/** Set the number of instances at runtime for a given service and version. */
void setNumInstances(String service, String version, long numInstances);
}

View file

@ -14,6 +14,7 @@
package google.registry.util;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.google.appengine.api.modules.ModulesService;
@ -52,6 +53,14 @@ public class AppEngineServiceUtilsImpl implements AppEngineServiceUtils {
return modulesService.getVersionHostname(service, version);
}
@Override
public void setNumInstances(String service, String version, long numInstances) {
checkArgumentNotNull(service, "Must specify the service");
checkArgumentNotNull(version, "Must specify the version");
checkArgument(numInstances > 0, "Number of instances must be greater than 0");
modulesService.setNumInstances(service, version, numInstances);
}
/** Dagger module for AppEngineServiceUtils. */
@Module
public abstract static class AppEngineServiceUtilsModule {