mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-24 18:40:38 +00:00
The method connects a socket, grabs in/out streams from it then writes HTTP request and reads+parses the response. For that it uses class variables for socket and streams, but there's no real need for that -- all three actually exists throughput the method "lifetime". To fix it, coroutinizes the method. The same could be achieved my moving the connected socket and streams into do_with() context, but coroutine is better than that. (indentation is left broken) Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
39 lines
1.4 KiB
C++
39 lines
1.4 KiB
C++
/*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Modified by ScyllaDB
|
|
* Copyright (C) 2015-present ScyllaDB
|
|
*/
|
|
#pragma once
|
|
|
|
#include "locator/production_snitch_base.hh"
|
|
#include <seastar/http/response_parser.hh>
|
|
#include <seastar/net/api.hh>
|
|
#include "utils/exponential_backoff_retry.hh"
|
|
|
|
namespace locator {
|
|
class ec2_snitch : public production_snitch_base {
|
|
public:
|
|
static constexpr const char* TOKEN_REQ_ENDPOINT = "/latest/api/token";
|
|
static constexpr const char* ZONE_NAME_QUERY_REQ = "/latest/meta-data/placement/availability-zone";
|
|
static constexpr const char* AWS_QUERY_SERVER_ADDR = "169.254.169.254";
|
|
static constexpr uint16_t AWS_QUERY_SERVER_PORT = 80;
|
|
static constexpr int AWS_API_CALL_RETRIES = 10;
|
|
|
|
ec2_snitch(const snitch_config&);
|
|
virtual future<> start() override;
|
|
virtual sstring get_name() const override {
|
|
return "org.apache.cassandra.locator.Ec2Snitch";
|
|
}
|
|
protected:
|
|
future<> load_config(bool prefer_local);
|
|
future<sstring> aws_api_call(sstring addr, uint16_t port, const sstring cmd, std::optional<sstring> token);
|
|
future<sstring> read_property_file();
|
|
private:
|
|
http_response_parser _parser;
|
|
sstring _req;
|
|
exponential_backoff_retry _ec2_api_retry = exponential_backoff_retry(std::chrono::seconds(5), std::chrono::seconds(2560));
|
|
future<sstring> aws_api_call_once(sstring addr, uint16_t port, const sstring cmd, std::optional<sstring> token);
|
|
};
|
|
} // namespace locator
|