Make some quality of life improvements to set_num_instances command

Allows correct service names (i.e. lowercased, as they appear in App Engine
configuration files and the GCP console), and adds single letter parameters for
common flags.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=229194479
This commit is contained in:
mcilwain 2019-01-14 09:16:11 -08:00 committed by Ben McIlwain
parent 8ac8ecf8f6
commit 6082addb86
2 changed files with 20 additions and 5 deletions

View file

@ -35,6 +35,7 @@ import google.registry.tools.AppEngineConnection.Service;
import google.registry.util.AppEngineServiceUtils; import google.registry.util.AppEngineServiceUtils;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Set; import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
@ -57,21 +58,21 @@ final class SetNumInstancesCommand implements CommandWithRemoteApi {
// TODO(b/119629679): Use List<Service> after upgrading jcommander to latest version. // TODO(b/119629679): Use List<Service> after upgrading jcommander to latest version.
@Parameter( @Parameter(
names = "--services", names = {"-s", "--services"},
description = description =
"Comma-delimited list of App Engine services to set. " "Comma-delimited list of App Engine services to set. "
+ "Allowed values: [DEFAULT, TOOLS, BACKEND, PUBAPI]") + "Allowed values: [DEFAULT, TOOLS, BACKEND, PUBAPI]")
private List<String> serviceNames = ImmutableList.of(); private List<String> serviceNames = ImmutableList.of();
@Parameter( @Parameter(
names = "--versions", names = {"-v", "--versions"},
description = description =
"Comma-delimited list of App Engine versions to set, e.g., canary. " "Comma-delimited list of App Engine versions to set, e.g., canary. "
+ "Cannot be set if --non_live_versions is set.") + "Cannot be set if --non_live_versions is set.")
private List<String> versions = ImmutableList.of(); private List<String> versions = ImmutableList.of();
@Parameter( @Parameter(
names = "--num_instances", names = {"-n", "--num_instances"},
description = description =
"The new number of instances for the given versions " "The new number of instances for the given versions "
+ "or for all non-live versions if --non_live_versions is set.", + "or for all non-live versions if --non_live_versions is set.",
@ -92,10 +93,11 @@ final class SetNumInstancesCommand implements CommandWithRemoteApi {
String projectId; String projectId;
@Override @Override
public void run() throws Exception { public void run() {
ImmutableSet<Service> services = ImmutableSet<Service> services =
serviceNames.stream() serviceNames.stream()
.map(s -> s.toUpperCase(Locale.US))
.map( .map(
name -> name ->
checkArgumentPresent( checkArgumentPresent(

View file

@ -99,7 +99,7 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
ParameterException.class, () -> runCommand("--services=DEFAULT", "--versions=version")); ParameterException.class, () -> runCommand("--services=DEFAULT", "--versions=version"));
assertThat(thrown) assertThat(thrown)
.hasMessageThat() .hasMessageThat()
.contains("The following option is required: --num_instances"); .contains("The following option is required: -n, --num_instances");
} }
@Test @Test
@ -156,6 +156,19 @@ public class SetNumInstancesCommandTest extends CommandTestCase<SetNumInstancesC
verify(appEngineServiceUtils, times(1)).setNumInstances("default", "version", 10L); verify(appEngineServiceUtils, times(1)).setNumInstances("default", "version", 10L);
} }
@Test
public void test_validShortParametersAndLowercaseService_succeeds() throws Exception {
command.appengine =
new AppEngineAdminApiHelper.Builder()
.setAppId(projectId)
.setManualScalingVersionsMap(ImmutableMultimap.of("default", "version"))
.build()
.getAppengine();
runCommand("-s default", "-v version", "-n 10");
verify(appEngineServiceUtils, times(1)).setNumInstances("default", "version", 10L);
}
@Test @Test
public void test_settingMultipleServicesAndVersions_succeeds() throws Exception { public void test_settingMultipleServicesAndVersions_succeeds() throws Exception {
command.appengine = command.appengine =