-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Make controller send responses for each command received (#1520)
This change makes the controller process respond to each command it receives with a document indicating whether that command was successfully executed or not. This response will be used by the Java side of the connection to determine when it is appropriate to move on to the next phase of the action that the controller command was part of. For example, when starting a process and connecting named pipes to it it is best that the named pipe connections are not attempted until the process is confirmed to be started. Relates elastic/elasticsearch#62823
- Loading branch information
1 parent
5710d8a
commit d90ff2e
Showing
13 changed files
with
412 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
#include "CResponseJsonWriter.h" | ||
|
||
#include <core/CLogger.h> | ||
|
||
#include <ios> | ||
|
||
namespace ml { | ||
namespace controller { | ||
namespace { | ||
|
||
// JSON field names | ||
const std::string ID{"id"}; | ||
const std::string SUCCESS{"success"}; | ||
const std::string REASON{"reason"}; | ||
} | ||
|
||
CResponseJsonWriter::CResponseJsonWriter(std::ostream& responseStream) | ||
: m_WrappedOutputStream(responseStream), m_Writer{m_WrappedOutputStream} { | ||
} | ||
|
||
void CResponseJsonWriter::writeResponse(std::uint32_t id, bool success, const std::string& reason) { | ||
m_Writer.StartObject(); | ||
m_Writer.Key(ID); | ||
m_Writer.Uint(id); | ||
m_Writer.Key(SUCCESS); | ||
m_Writer.Bool(success); | ||
m_Writer.Key(REASON); | ||
m_Writer.String(reason); | ||
m_Writer.EndObject(); | ||
m_Writer.flush(); | ||
LOG_DEBUG(<< "Wrote controller response - id: " << id | ||
<< " success: " << std::boolalpha << success << " reason: " << reason); | ||
} | ||
} | ||
} |
Oops, something went wrong.