32 #ifndef AUTOMATION__HPP
33 #define AUTOMATION__HPP
55 return "eInvalidInput";
57 return "eCommandProcessingError";
72 input(message.Iterate()),
90 template <
typename TValue>
103 template <
typename TInt = Int8>
125 auto found = [&](
const CArgument& arg) {
return name == arg.
Name(); };
126 const auto result = find_if(begin(), end(), found);
187 template <
class TDerived>
190 template <
class TDerived>
193 template <
class TClass,
void(TClass::*Method)(const TArguments&, SInputOutput& io)>
300 new_object->SetID(new_object_id);
302 return new_object_id;
305 template <
class TDerived>
317 auto object_id =
input.GetNode().AsInteger();
318 auto& object_ref = that->ObjectIdToRef(object_id);
320 if (name != object_ref->GetType())
return nullptr;
323 return object_ref.GetPointer();
326 template <
class TDerived>
332 auto& reply = io.
reply;
337 new_object.
Reset(TDerived::Create(args, that));
344 auto id = that->AddObject(new_object);
345 reply.AppendInteger(
id);
348 template <
class TClass,
void(TClass::*Method)(const TArguments&, SInputOutput& io)>
353 auto that =
static_cast<TClass*
>(
data);
354 (that->*Method)(args, io);
Iterator for JSON arrays and objects.
Int8 AsInteger() const
Provided that this is a numeric node (that is, either an integer or a floating point node),...
const string AsString() const
Provided that this is a string node, return the string value of this node.
bool AsBoolean() const
Provided that this is a boolean node, return the boolean value of this node.
double AsDouble() const
Provided that this is a numeric node (that is, either a floating point or an integer node),...
CNetServiceIterator Iterate(EIterationMode mode=eSortByLoad)
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
This class is for use by the grid_cli utility only.
CJsonNode m_TypeOrDefaultValue
void Exec(const string &name, CJsonIterator &input)
CArgument(string name, CJsonNode::ENodeType type)
CArgument(string name, const TValue &value)
CArgument(CJsonIterator &input)
@ eCommandProcessingError
NCBI_EXCEPTION_DEFAULT(CAutomationException, CException)
virtual const char * GetErrCodeString(void) const override
Get error code interpreted as text.
static void ExecNew(const TArguments &args, SInputOutput &io, void *data)
void SetID(TObjectID object_id)
static void ExecMethod(const TArguments &args, SInputOutput &io, void *data)
CAutomationObject(CAutomationProc *automation_proc)
virtual const string & GetType() const =0
static void * CheckCall(const string &name, SInputOutput &io, void *data)
CAutomationProc * m_AutomationProc
static TCommands Commands()
static void ExecVersion(const TArguments &args, SInputOutput &io, void *data)
static void ExecDel(const TArguments &args, SInputOutput &io, void *data)
vector< TAutomationObjectRef > m_ObjectByIndex
static TCommands NewCommands()
static void ExecEcho(const TArguments &args, SInputOutput &io, void *data)
TObjectID AddObject(TAutomationObjectRef new_object)
static void ExecSleep(const TArguments &args, SInputOutput &io, void *data)
static TCommands CallCommands()
void SendWarning(const string &warn_msg, TAutomationObjectRef source)
TAutomationObjectRef ReturnNetScheduleServerObject(CNetScheduleAPI::TInstance ns_api, CNetServer::TInstance server)
bool Process(const CJsonNode &message)
void SendError(const CTempString &error_message)
static void ExecExit(const TArguments &args, SInputOutput &io, void *data)
static void ExecWhatIs(const TArguments &args, SInputOutput &io, void *data)
TAutomationObjectRef ReturnNetStorageServerObject(CNetStorageAdmin::TInstance nst_api, CNetServer::TInstance server)
TAutomationObjectRef & ObjectIdToRef(TObjectID object_id)
TAutomationObjectRef ReturnNetCacheServerObject(CNetICacheClient::TInstance ic_api, CNetServer::TInstance server)
static void ExecAllowXSite(const TArguments &args, SInputOutput &io, void *data)
CJsonNode ProcessMessage(const CJsonNode &message)
IMessageSender * m_MessageSender
CAutomationProc(IMessageSender *message_sender)
static void ExecSetContext(const TArguments &args, SInputOutput &io, void *data)
void * Check(SInputOutput &io, void *data)
shared_ptr< SCommandImpl > m_Impl
bool Exec(SInputOutput &io, void *data)
CJsonNode Help(CJsonIterator &input)
CCommand(string name, TCommandExecutor exec, TArgsInit args=TArgsInit())
virtual void OutputMessage(const CJsonNode &)=0
virtual ~IMessageSender()
virtual void InputMessage(const CJsonNode &)
TErrCode GetErrCode(void) const
Get error code.
const string & GetMsg(void) const
Get message string.
EErrCode
Error types that an application can generate.
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
void Reset(void)
Reset reference object.
int64_t Int8
8-byte (64-bit) signed integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
pair< TCommands, TCommandChecker > TCommandGroup
initializer_list< CArgument > TArgsInit
CRef< CAutomationObject > TAutomationObjectRef
vector< CCommand > TCommands
function< void(const TArguments &, SInputOutput &, void *)> TCommandExecutor
function< void *(const string &, SInputOutput &, void *)> TCommandChecker
const GenericPointer< typename T::ValueType > T2 value
const CharType(& source)[N]
void ExecGetName(const TArguments &args, SInputOutput &io)
void ExecGetAddress(const TArguments &args, SInputOutput &io)
virtual CNetService GetService()=0
SNetServiceBase(CAutomationProc *automation_proc)
static TCommands CallCommands()
SNetService(CAutomationProc *automation_proc)
void ExecExec(const TArguments &args, SInputOutput &io)
static TCommands CallCommands()
void ExecServerInfo(const TArguments &args, SInputOutput &io)
SServerAddressToJson(int which_part)
virtual CJsonNode ExecOn(CNetServer server)
const CArgument & operator[](const char *name) const
TArguments(TArgsInit args)