From 704435b261f20644a6169c607f21ef29a3f43ba1 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Mon, 9 Apr 2018 11:46:36 +0000 Subject: Adjust vespa-set-node-state to require cluster argument if more than one cluster is present in model. --- .../src/perl/lib/Yahoo/Vespa/Bin/SetNodeState.pm | 18 ++++++++++++++++++ .../src/perl/lib/Yahoo/Vespa/ContentNodeSelection.pm | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/vespaclient/src/perl/lib/Yahoo/Vespa/Bin/SetNodeState.pm b/vespaclient/src/perl/lib/Yahoo/Vespa/Bin/SetNodeState.pm index 894ab7feca4..5461c50ee30 100644 --- a/vespaclient/src/perl/lib/Yahoo/Vespa/Bin/SetNodeState.pm +++ b/vespaclient/src/perl/lib/Yahoo/Vespa/Bin/SetNodeState.pm @@ -31,6 +31,7 @@ sub setNodeState { # (Command line arguments) &handleCommandLine($argsref); detectClusterController(); &showSettings(); + &maybeRequireClusterSelection(); &execute(); } @@ -78,6 +79,23 @@ sub showSettings { # () Yahoo::Vespa::ClusterController::showSettings(); } +sub maybeRequireClusterSelection +{ + return if Yahoo::Vespa::ContentNodeSelection::hasClusterSelection(); + my %clusters; + VespaModel::visitServices(sub { + my ($info) = @_; + if ($$info{'type'} =~ /^(?:distributor|storage|storagenode)$/ ) { + $clusters{$$info{'cluster'}} = 1; + } + }); + my $clusterCount = scalar keys %clusters; + if ($clusterCount > 1) { + printWarning "More than one cluster is present but no cluster is selected\n"; + exitApplication(1); + } +} + # Sets the node state sub execute { # () $success = 1; diff --git a/vespaclient/src/perl/lib/Yahoo/Vespa/ContentNodeSelection.pm b/vespaclient/src/perl/lib/Yahoo/Vespa/ContentNodeSelection.pm index d15fd4a75df..d23471c8910 100644 --- a/vespaclient/src/perl/lib/Yahoo/Vespa/ContentNodeSelection.pm +++ b/vespaclient/src/perl/lib/Yahoo/Vespa/ContentNodeSelection.pm @@ -127,6 +127,10 @@ sub validateCommandLineArguments { # (WantedState) return 1; } +sub hasClusterSelection { + return defined $CLUSTER; +} + ############## Utility functions - Not intended for external use ############# sub validType { # (ServiceType) -> Bool -- cgit v1.2.3