# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package Yahoo::Vespa::Bin::GetNodeState; use strict; use warnings; use Yahoo::Vespa::ArgParser; use Yahoo::Vespa::ClusterController; use Yahoo::Vespa::ConsoleOutput; use Yahoo::Vespa::ContentNodeSelection; use Yahoo::Vespa::Utils; BEGIN { use base 'Exporter'; our @EXPORT = qw( getNodeState ); } our $resultdesc; our %cluster_states; return 1; # Run the get node state tool sub getNodeState { # (Command line arguments) my ($argsref) = @_; &handleCommandLine($argsref); detectClusterController(); &showSettings(); &showNodeStates(); } # Parse command line arguments sub handleCommandLine { # (Command line arguments) my ($args) = @_; $resultdesc = <$type->{$index}; } # Print all states for a given node sub showNodeStateForNode { # (Service, Index, NodeState, Model, ClusterName) my ($info) = @_; my ($cluster, $type, $index) = ( $$info{'cluster'}, $$info{'type'}, $$info{'index'}); printResult "\n$cluster/$type.$index:\n"; my $nodestate = &getStateForNode($type, $index, $cluster); printState('Unit', $nodestate->unit); printState('Generated', $nodestate->generated); printState('User', $nodestate->user); } # Print the value of a single state type for a node sub printState { # (State name, State) my ($name, $state) = @_; if (!defined $state) { printResult $name . ": UNKNOWN\n"; } else { my $msg = $name . ": "; if ($state->state ne 'up') { $msg .= COLOR_ERR; } $msg .= $state->state; if ($state->state ne 'up') { $msg .= COLOR_RESET; } $msg .= ": " . $state->reason . "\n"; printResult $msg; } }