diff --git a/CMakeLists.txt b/CMakeLists.txt index 42592ab..08ba983 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,8 @@ if(NOT BUILD_BRIDGE_ONLY) find_package(metadata-manager REQUIRED) find_package(message-manager REQUIRED) find_package(Protobuf REQUIRED) +endif() +if(NOT BUILD_STUB_ONLY) find_package(yugawara REQUIRED) find_package(jogasaki-${SHARKSFIN_IMPLEMENTATION} REQUIRED) find_package(tateyama-${SHARKSFIN_IMPLEMENTATION} REQUIRED) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5490d8c..943ff02 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,9 +21,6 @@ register_tests( TARGET stub DEPENDS message-manager-interface - jogasaki-${SHARKSFIN_IMPLEMENTATION}-api - tateyama-${SHARKSFIN_IMPLEMENTATION}-api - sharksfin-api Boost::serialization glog::glog gflags::gflags @@ -34,7 +31,7 @@ register_tests( ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/common/include - ${CMAKE_SOURCE_DIR}/bridge/include + ${CMAKE_SOURCE_DIR}/test/include ${CMAKE_BINARY_DIR}/src ) endif() diff --git a/test/include/tateyama/framework/component.h b/test/include/tateyama/framework/component.h new file mode 100644 index 0000000..625edf7 --- /dev/null +++ b/test/include/tateyama/framework/component.h @@ -0,0 +1,97 @@ +/* + * Copyright 2018-2024 Project Tsurugi. + * + * 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. + */ +#pragma once + +#include +#include +#include +#include + +namespace tateyama::framework { + +class environment; + +/** + * @brief base class for tateyama components whose life-cycle is managed by the framework + */ +class component { +public: + /** + * @brief type to identify components + * @details the id must be unique among each categories of components (e.g. resource, service) + * Users custom module should use one larger than `max_system_reserved_id`. + */ + using id_type = std::uint32_t; + + /** + * @brief maximum id reserved for built-in system resources/services + */ + static constexpr id_type max_system_reserved_id = 255; + + /** + * @brief construct new object + */ + component() = default; + + component(component const& other) = delete; + component& operator=(component const& other) = delete; + component(component&& other) noexcept = delete; + component& operator=(component&& other) noexcept = delete; + + /** + * @brief setup the component (the state will be `ready`) + * @return true when setup completed successfully + * @return false otherwise + */ + virtual bool setup(environment&) = 0; + + /** + * @brief start the component (the state will be `activated`) + * @return true when start completed successfully + * @return false otherwise + */ + virtual bool start(environment&) = 0; + + /** + * @brief shutdown the component (the state will be `deactivated`) + * @return true when shutdown completed successfully, or component is already deactivated + * @return false otherwise + * @note shutdown is an idempotent operation, meaning second call to the already deactivated component should be + * simply ignored and return true. + */ + virtual bool shutdown(environment&) = 0; + + /** + * @brief destruct the object (the state will be `disposed`) + */ + virtual ~component() = default; + + /** + * @brief list the section names in the config. file that this component is affected + * @return the list of section name + */ + // TODO implement to validate config file + //virtual std::vector configuration_sections() = 0; + + /** + * @brief fetch human readable label of this component (not necessarily unique) + * @return the label for this component + */ + [[nodiscard]] virtual std::string_view label() const noexcept = 0; +}; + +} + diff --git a/test/include/tateyama/framework/component_ids.h b/test/include/tateyama/framework/component_ids.h new file mode 100644 index 0000000..be380cf --- /dev/null +++ b/test/include/tateyama/framework/component_ids.h @@ -0,0 +1,45 @@ +/* + * Copyright 2018-2023 Project Tsurugi. + * + * 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. + */ +#pragma once + +#include + +namespace tateyama::framework { + +// resource +constexpr inline component::id_type resource_id_task_scheduler = 0; +constexpr inline component::id_type resource_id_transactional_kvs = 1; +constexpr inline component::id_type resource_id_sql = 2; +constexpr inline component::id_type resource_id_datastore = 3; +constexpr inline component::id_type resource_id_session = 4; +constexpr inline component::id_type resource_id_status = 5; +//constexpr inline component::id_type resource_id_mutex = 6; +constexpr inline component::id_type resource_id_diagnostic = 7; +constexpr inline component::id_type resource_id_remote_kvs = 8; +constexpr inline component::id_type resource_id_metrics = 9; + +// service +constexpr inline component::id_type service_id_routing = 0; +constexpr inline component::id_type service_id_endpoint_broker = 1; +constexpr inline component::id_type service_id_datastore = 2; +constexpr inline component::id_type service_id_sql = 3; +constexpr inline component::id_type service_id_fdw = 4; +constexpr inline component::id_type service_id_remote_kvs = 5; +constexpr inline component::id_type service_id_debug = 6; +constexpr inline component::id_type service_id_session = 7; +constexpr inline component::id_type service_id_metrics = 8; + +} diff --git a/test/ogawayama/stub/endpoint.h b/test/ogawayama/stub/endpoint.h index 53abb22..c22afae 100644 --- a/test/ogawayama/stub/endpoint.h +++ b/test/ogawayama/stub/endpoint.h @@ -27,16 +27,13 @@ #include #include -#include #include -#include -#include #include -#include #include #include #include +#include "tateyama/framework/component_ids.h" #include "server_wires_impl.h" #include "endpoint_proto_utils.h" #include "ogawayama/stub/stubImpl.h" diff --git a/test/ogawayama/stub/endpoint_proto_utils.h b/test/ogawayama/stub/endpoint_proto_utils.h index 947d9b6..0305765 100644 --- a/test/ogawayama/stub/endpoint_proto_utils.h +++ b/test/ogawayama/stub/endpoint_proto_utils.h @@ -17,9 +17,6 @@ #include -#include - -#include "tateyama/framework/component_ids.h" #include #include #include diff --git a/test/ogawayama/stub/server_wires_impl.h b/test/ogawayama/stub/server_wires_impl.h index c051ea4..8bd8fc6 100644 --- a/test/ogawayama/stub/server_wires_impl.h +++ b/test/ogawayama/stub/server_wires_impl.h @@ -23,7 +23,6 @@ #include #include -#include #include "tateyama/transport/wire.h" diff --git a/test/ogawayama/stub/stub_test_root.h b/test/ogawayama/stub/stub_test_root.h index 053e7a7..e6b2bcb 100644 --- a/test/ogawayama/stub/stub_test_root.h +++ b/test/ogawayama/stub/stub_test_root.h @@ -19,13 +19,9 @@ #include #include -#include #include -#include #include -#include -#include #include #include #include