-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ik <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,088 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Copyright 2024 Huawei Cloud Computing Technologies Co., Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#ifndef OPENGEMINI_POINT_HPP | ||
#define OPENGEMINI_POINT_HPP | ||
|
||
#include <chrono> | ||
#include <map> | ||
#include <string> | ||
#include <variant> | ||
|
||
#include "opengemini/Precision.hpp" | ||
|
||
namespace opengemini { | ||
|
||
/// | ||
/// \~English | ||
/// @brief Holds the point data. | ||
/// | ||
/// \~Chinese | ||
/// @brief 点位数据。 | ||
/// | ||
struct Point { | ||
using Field = std::variant<double, int64_t, uint64_t, std::string, bool>; | ||
using Time = std::chrono::time_point<std::chrono::system_clock, | ||
std::chrono::nanoseconds>; | ||
|
||
std::string measurement; | ||
std::map<std::string, Field> fields; | ||
Time time; | ||
std::map<std::string, std::string> tags; | ||
Precision precision{ Precision::Nanosecond }; | ||
}; | ||
|
||
} // namespace opengemini | ||
|
||
#endif // !OPENGEMINI_POINT_HPP |
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,54 @@ | ||
// | ||
// Copyright 2024 Huawei Cloud Computing Technologies Co., Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
#include "opengemini/impl/cli/Functor.hpp" | ||
|
||
#include <boost/url.hpp> | ||
|
||
#include "opengemini/Exception.hpp" | ||
#include "opengemini/impl/comm/UrlTargets.hpp" | ||
#include "opengemini/impl/enc/LineProtocolEncoder.hpp" | ||
|
||
namespace opengemini::impl { | ||
|
||
template<typename POINT_TYPE> | ||
void ClientImpl::Functor::RunWrite<POINT_TYPE>::operator()( | ||
boost::asio::yield_context yield) const | ||
{ | ||
if (db_.empty()) { | ||
throw Exception(errc::LogicErrors::InvalidArgument, | ||
"Database name cannot be empty"); | ||
} | ||
|
||
auto content = enc::LineProtocolEncoder{}.Encode(point_); | ||
if (content.empty()) { return; } | ||
|
||
boost::url target(url::WRITE); | ||
target.set_query(fmt::format("db={}&rp={}", db_, rp_)); | ||
|
||
auto rsp = impl_->http_->Post(impl_->lb_->PickAvailableServer(), | ||
target.buffer(), | ||
std::move(content), | ||
yield); | ||
if (rsp.result() != http::Status::no_content) { | ||
throw Exception(errc::ServerErrors::UnexpectedStatusCode, | ||
fmt::format("Received code: {}, body:{}", | ||
rsp.result_int(), | ||
rsp.body())); | ||
} | ||
} | ||
|
||
} // namespace opengemini::impl |
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
Oops, something went wrong.