Skip to content

Commit

Permalink
implement tgctl session command
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Apr 16, 2024
1 parent 19396b9 commit dc95a88
Show file tree
Hide file tree
Showing 21 changed files with 1,816 additions and 472 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ set(ProtoFiles
${CMAKE_CURRENT_SOURCE_DIR}/tateyama/proto/kvs/transaction.proto
${CMAKE_CURRENT_SOURCE_DIR}/tateyama/proto/kvs/data.proto
${CMAKE_CURRENT_SOURCE_DIR}/tateyama/proto/diagnostics.proto
${CMAKE_CURRENT_SOURCE_DIR}/tateyama/proto/session/request.proto
${CMAKE_CURRENT_SOURCE_DIR}/tateyama/proto/session/response.proto
${CMAKE_CURRENT_SOURCE_DIR}/tateyama/proto/session/diagnostic.proto
)

# By default, PROTOBUF_GENERATE_CPP generates file path for .pb.cc as if they are in the same directory.
Expand Down
45 changes: 9 additions & 36 deletions src/tateyama/datastore/backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include <gflags/gflags.h>

#include <tateyama/framework/component_ids.h>
#include <tateyama/logging.h>

#include "tateyama/configuration/bootstrap_configuration.h"
Expand Down Expand Up @@ -94,32 +93,6 @@ static bool prompt(std::string_view msg)
return rtnv;
}

static std::string database_name() {
if (auto conf = tateyama::api::configuration::create_configuration(FLAGS_conf, tateyama::configuration::default_property_for_bootstrap()); conf != nullptr) {
auto endpoint_config = conf->get_section("ipc_endpoint");
if (endpoint_config == nullptr) {
std::cerr << "cannot find ipc_endpoint section in the configuration" << std::endl;
exit(tgctl::return_code::err);
}
auto database_name_opt = endpoint_config->get<std::string>("database_name");
if (!database_name_opt) {
std::cerr << "cannot find database_name at the section in the configuration" << std::endl;
exit(tgctl::return_code::err);
}
return database_name_opt.value();
}
std::cerr << "error in create_configuration" << std::endl;
exit(2);
}

static std::string digest() {
auto bst_conf = configuration::bootstrap_configuration::create_bootstrap_configuration(FLAGS_conf);
if (bst_conf.valid()) {
return bst_conf.digest();
}
return {};
}

tgctl::return_code tgctl_backup_create(const std::string& path_to_backup) {
std::unique_ptr<monitor::monitor> monitor_output{};

Expand All @@ -131,7 +104,7 @@ tgctl::return_code tgctl_backup_create(const std::string& path_to_backup) {
auto rtnv = tgctl::return_code::ok;
authentication::auth_options();
try {
auto transport = std::make_unique<tateyama::bootstrap::wire::transport>(database_name(), digest(), tateyama::framework::service_id_datastore);
auto transport = std::make_unique<tateyama::bootstrap::wire::transport>(tateyama::framework::service_id_datastore);
::tateyama::proto::datastore::request::Request requestBegin{};
auto backup_begin = requestBegin.mutable_backup_begin();
if (!FLAGS_label.empty()) {
Expand Down Expand Up @@ -240,7 +213,7 @@ tgctl::return_code tgctl_backup_estimate() {
authentication::auth_options();

try {
auto transport = std::make_unique<tateyama::bootstrap::wire::transport>(database_name(), digest(), tateyama::framework::service_id_datastore);
auto transport = std::make_unique<tateyama::bootstrap::wire::transport>(tateyama::framework::service_id_datastore);
::tateyama::proto::datastore::request::Request request{};
request.mutable_backup_estimate();
auto response = transport->send<::tateyama::proto::datastore::response::BackupEstimate>(request);
Expand Down Expand Up @@ -268,7 +241,7 @@ tgctl::return_code tgctl_backup_estimate() {
}
}
} catch (std::runtime_error &e) {
std::cerr << "could not connect to database with name " << database_name() << std::endl;
std::cerr << "could not connect to database with name " << tateyama::bootstrap::wire::transport::database_name() << std::endl;
}
rtnv = tgctl::return_code::err;

Expand Down Expand Up @@ -302,7 +275,7 @@ tgctl::return_code tgctl_restore_backup(const std::string& path_to_backup) {
authentication::auth_options();

try {
auto transport = std::make_unique<tateyama::bootstrap::wire::transport>(database_name(), digest(), tateyama::framework::service_id_datastore);
auto transport = std::make_unique<tateyama::bootstrap::wire::transport>(tateyama::framework::service_id_datastore);
::tateyama::proto::datastore::request::Request request{};
auto restore_begin = request.mutable_restore_begin();
restore_begin->set_backup_directory(path_to_backup);
Expand Down Expand Up @@ -334,7 +307,7 @@ tgctl::return_code tgctl_restore_backup(const std::string& path_to_backup) {
}
}
} catch (std::runtime_error &e) {
std::cerr << "could not connect to database with name " << database_name() << std::endl;
std::cerr << "could not connect to database with name " << tateyama::bootstrap::wire::transport::database_name() << std::endl;
}
rtnv = tgctl::return_code::err;

Expand Down Expand Up @@ -380,7 +353,7 @@ tgctl::return_code tgctl_restore_backup_use_file_list(const std::string& path_to
std::cerr << "option --nokeep_backup is ignored when --use-file-list is specified" << std::endl;
}

auto transport = std::make_unique<tateyama::bootstrap::wire::transport>(database_name(), digest(), tateyama::framework::service_id_datastore);
auto transport = std::make_unique<tateyama::bootstrap::wire::transport>(tateyama::framework::service_id_datastore);
::tateyama::proto::datastore::request::Request request{};
auto restore_begin = request.mutable_restore_begin();
auto entries = restore_begin->mutable_entries();
Expand Down Expand Up @@ -421,7 +394,7 @@ tgctl::return_code tgctl_restore_backup_use_file_list(const std::string& path_to
}
}
} catch (std::runtime_error &e) {
std::cerr << "could not connect to database with name " << database_name() << std::endl;
std::cerr << "could not connect to database with name " << tateyama::bootstrap::wire::transport::database_name() << std::endl;
}
rtnv = tgctl::return_code::err;

Expand All @@ -443,7 +416,7 @@ tgctl::return_code tgctl_restore_tag(const std::string& tag_name) {
authentication::auth_options();

try {
auto transport = std::make_unique<tateyama::bootstrap::wire::transport>(database_name(), digest(), tateyama::framework::service_id_datastore);
auto transport = std::make_unique<tateyama::bootstrap::wire::transport>(tateyama::framework::service_id_datastore);

::tateyama::proto::datastore::request::Request request{};
auto restore_begin = request.mutable_restore_begin();
Expand Down Expand Up @@ -472,7 +445,7 @@ tgctl::return_code tgctl_restore_tag(const std::string& tag_name) {
}
}
} catch (std::runtime_error &e) {
std::cerr << "could not connect to database with name " << database_name() << std::endl;
std::cerr << "could not connect to database with name " << tateyama::bootstrap::wire::transport::database_name() << std::endl;
}
rtnv = tgctl::return_code::err;

Expand Down
3 changes: 3 additions & 0 deletions src/tateyama/proto/diagnostics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ enum Code {

// request header or payload is not valid.
INVALID_REQUEST = 41;

// operation was canceled by user or system.
OPERATION_CANCELED = 42;
}

// diagnostic record.
Expand Down
42 changes: 42 additions & 0 deletions src/tateyama/proto/session/diagnostic.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
syntax = "proto3";

package tateyama.proto.session.diagnostic;

// the error code.
enum ErrorCode {
// the error code is not set.
ERROR_CODE_NOT_SPECIFIED = 0;

// the unknown error was occurred.
UNKNOWN = 1;

// the target session is not found.
SESSION_NOT_FOUND = 2;

// the session label is not unique within the target sessions.
SESSION_AMBIGUOUS = 3;

// the operation was not permitted.
OPERATION_NOT_PERMITTED = 4;

// the target session variable is not declared.
SESSION_VARIABLE_NOT_DECLARED = 5;

// the setting value is invalid for the target variable.
SESSION_VARIABLE_INVALID_VALUE = 6;
}

// the error information of the session control operations.
message Error {
// the error code.
ErrorCode error_code = 1;

// the error message (optional).
string message = 2;

// the error message code (optional).
string message_code = 3;

// the arguments for the message code (optional).
repeated string message_arguments = 4;
}
98 changes: 98 additions & 0 deletions src/tateyama/proto/session/request.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
syntax = "proto3";

package tateyama.proto.session.request;

// the request message to session pseudo service.
message Request {
// service message version (major)
uint64 service_message_version_major = 1;

// service message version (minor)
uint64 service_message_version_minor = 2;

// reserved for system use
reserved 3 to 10;

// the request command.
oneof command {
// obtains session information.
SessionGet session_get = 11;

// obtains list of active sessions.
SessionList session_list = 12;

// request shutdown to the session.
SessionShutdown session_shutdown = 13;

// set session variables.
SessionSetVariable session_set_variable = 14;

// retrieve session variables.
SessionGetVariable session_get_variable= 15;
}
reserved 16 to 99;
}


// obtains session information.
message SessionGet {

// the target session specifier - ID or label.
string session_specifier = 1;
}


// obtains list of active sessions.
message SessionList {
// no special properties.
}


// represents kind of shutdown request.
enum SessionShutdownType {

// the shutdown request type is not set (default behavior).
SESSION_SHUTDOWN_TYPE_NOT_SET = 0;

// denies new requests, and shutdown the session after the all running requests were finished.
GRACEFUL = 1;

// denies new requests, tells cancellation to the running requests,
// and then shutdown the session after the all requests were finished or cancelled.
FORCEFUL = 2;
}

// request shutdown to the session.
message SessionShutdown {

// the target session specifier - ID or label.
string session_specifier = 1;

// the shutdown request type.
SessionShutdownType request_type = 2;
}


// set session variables.
message SessionSetVariable {

// the target session specifier - ID or label.
string session_specifier = 1;

// the target variable name, case insensitive.
string name = 2;

// the text represented value to set.
string value = 3;
}


// retrieve session variables.
message SessionGetVariable {

// the target session specifier - ID or label.
string session_specifier = 1;

// the target variable name, case insensitive.
string name = 2;
}
Loading

0 comments on commit dc95a88

Please sign in to comment.