NCBI C++ ToolKit
netcache_api_admin.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: netcache_api_admin.cpp 79549 2017-09-19 15:47:16Z sadyrovr $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Maxim Didenko, Anatoliy Kuznetsov
27  *
28  * File Description:
29  * Implementation of net cache client.
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 
35 #include "netcache_api_impl.hpp"
36 
39 
41 
43 {
46 }
47 
48 void SNetCacheAdminImpl::PrintCmdOutput(string cmd, CNcbiOstream& output_stream, bool multiline_output)
49 {
52  m_API->m_Service.PrintCmdOutput(cmd, output_stream, style);
53 }
54 
56 {
57  string cmd("SHUTDOWN");
58 
60  m_Impl->m_API->AppendClientIPSessionID(&cmd, req);
61 
62  if (shutdown_option == eDrain)
63  cmd += " drain=1";
64 
65  m_Impl->m_API->AppendHitID(&cmd, req);
66  m_Impl->m_API->m_Service.ExecOnAllServers(cmd);
67 }
68 
70 {
71  string cmd("RECONF");
72 
73  if (reload_option == eMirrorReload) {
74  cmd += " section=mirror";
75  }
76 
77  m_Impl->ExecOnAllServers(cmd);
78 }
79 
80 void CNetCacheAdmin::Purge(const string& cache_name)
81 {
82  string cmd("PURGE \"" + NStr::PrintableString(cache_name));
83  cmd += '"';
84  m_Impl->ExecOnAllServers(cmd);
85 }
86 
88 {
89  m_Impl->PrintCmdOutput("GETCONF", output_stream);
90 }
91 
93  const string& aggregation_period,
94  CNetCacheAdmin::EStatPeriodCompleteness period_completeness)
95 {
96  string cmd("GETSTAT");
97 
98  if (period_completeness != eReturnCurrentPeriod) {
99  cmd += " prev=1 type=\"";
100  if (!aggregation_period.empty())
101  cmd += NStr::PrintableString(aggregation_period);
102  cmd += '"';
103  } else if (!aggregation_period.empty()) {
104  cmd += " prev=0 type=\"";
105  cmd += NStr::PrintableString(aggregation_period);
106  cmd += '"';
107  }
108 
109  m_Impl->PrintCmdOutput(cmd, output_stream);
110 }
111 
113 {
114  m_Impl->PrintCmdOutput("HEALTH", output_stream);
115 }
116 
118 {
119  m_Impl->PrintCmdOutput("VERSION", output_stream, false);
120 }
121 
122 
void PrintCmdOutput(const string &cmd, CNcbiOstream &output_stream, ECmdOutputStyle output_style, CNetService::EIterationMode=CNetService::eSortByLoad)
@ eMultilineOutput_NetCacheStyle
void ExecOnAllServers(const string &cmd)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static CRequestContext & GetRequestContext(void)
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext()
Definition: ncbidiag.cpp:1901
CNetRef< SNetCacheAdminImpl > m_Impl
EStatPeriodCompleteness
Enumeration for use with PrintStat().
void PrintStat(CNcbiOstream &output_stream, const string &aggregation_period=kEmptyStr, EStatPeriodCompleteness period_completeness=eReturnCurrentPeriod)
Print server statistics.
EShutdownOption
Shutdown options.
void PrintHealth(CNcbiOstream &output_stream)
void GetServerVersion(CNcbiOstream &output_stream)
void ReloadServerConfig(EReloadConfigOption reload_option=eCompleteReload)
Reload configuration parameters from the same source.
EReloadConfigOption
Reload configuration options.
void PrintConfig(CNcbiOstream &output_stream)
Print contents of the configuration file.
void ShutdownServer(EShutdownOption shutdown_option=eNormalShutdown)
Shutdown the server daemon.
void Purge(const string &cache_name)
Remove all blobs from an ICache database.
@ eDrain
Wait for all blobs to expire.
@ eMirrorReload
Parameters related to mirroring will only be reloaded.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
static string PrintableString(const CTempString str, TPrintableMode mode=fNewLine_Quote|fNonAscii_Passthru)
Get a printable version of the specified string.
Definition: ncbistr.cpp:3953
Administrative API for NetCache.
NetCache API exception declarations.
void AppendClientIPSessionIDHitID(string *cmd)
void ExecOnAllServers(string cmd)
void PrintCmdOutput(string cmd, CNcbiOstream &output_stream, bool multiline_output=true)
Modified on Sat Jun 15 11:53:56 2024 by modify_doxy.py rev. 669887