require_relative '../../../../../gen/Design.ORiN3.Common/V1/orin3_common_remote_engine_pb' require_relative '../../../../../gen/Message.ORiN3.RemoteEngine/V1/orin3_remote_engine_pb' require_relative '../../../../../gen/Message.ORiN3.RemoteEngine/V1/orin3_remote_engine_services_pb' require_relative '../message_client_error' module O3 include Design::ORiN3::Common::RemoteEngine::V1::AutoGenerated include Message::ORiN3::RemoteEngine::V1::AutoGenerated end module Grpc module Client module ORiN3 class RemoteEngineStatus attr_reader :result_code, :status, :instance_id, :host, :addresses, :version, :os_platform, :os_description, :running_provider_count def initialize(result_code, status, instance_id, host, addresses, version, os_platform, os_description, running_provider_count) @result_code = result_code @status = status @instance_id = instance_id @host = host @addresses = addresses @version = version @os_platform = os_platform @os_description = os_description @running_provider_count = running_provider_count end end class ProviderEndpoint attr_accessor :index, :ip_address, :port, :uri, :protocol_type def initialize(index, ip_address, port, uri, protocol_type) @index = index @ip_address = ip_address @port = port @uri = uri @protocol_type = protocol_type end end class ProviderInformation attr_accessor :endpoints def initialize(endpoints) @endpoints = endpoints end end class WakeupProviderResponse attr_accessor :id, :provider_information def initialize(id, provider_information) @id = id @provider_information = provider_information end end class RemoteEngine def initialize(channel) @channel = channel end def get_status begin service = O3::RemoteEngineService::Stub.new(nil, :this_channel_is_insecure, channel_override: @channel) request = O3::GetRemoteEngineStatusRequest.new(common: O3::CommonRequest.new) response = service.get_remote_engine_status(request) if (response.common.result_code != :SUCCEEDED) raise MessageClientError.new(response.common.result_code, response.common.detail) end return RemoteEngineStatus.new(response.common.result_code, response.status, response.instance_id, response.host, response.addresses, response.version, response.os_platform, response.os_description, response.running_provider_count) rescue MessageClientError raise rescue StandardError => e raise MessageClientError.new(e) end end def wakeup_provider(id, version, host, port) begin service = O3::RemoteEngineService::Stub.new(nil, :this_channel_is_insecure, channel_override: @channel) endpoint_info = create_provider_core_startup_argument_endpoint_info(0, host, port) telemetry_option = create_telemetry_option(true) argument = create_provider_core_startup_argument(false, [endpoint_info], 0, telemetry_option) request = O3::WakeupProviderRequest.new( common: O3::CommonRequest.new(reserved: 0), id: id, version: version, provider_startup_argument: argument) response = service.wakeup_provider(request) if (response.common.result_code != :SUCCEEDED) raise MessageClientError.new(response.common.result_code, response.common.detail) end endpoints = response.provider_information.endpoints.map do |endpoint| ProviderEndpoint.new( endpoint.index, endpoint.ip_address, endpoint.port, endpoint.uri, endpoint.protocol_type ) end return WakeupProviderResponse.new(response.id, ProviderInformation.new(endpoints)) rescue MessageClientError raise rescue StandardError => e raise MessageClientError.new(e) end end def terminate_provider(id) begin service = O3::RemoteEngineService::Stub.new(nil, :this_channel_is_insecure, channel_override: @channel) request = O3::TerminateProviderRequest.new(common: O3::CommonRequest.new, id: id) response = service.terminate_provider(request) if (response.common.result_code != :SUCCEEDED) raise MessageClientError.new(response.common.result_code, response.common.detail) end rescue MessageClientError raise rescue StandardError => e raise MessageClientError.new(e) end end private def create_provider_core_startup_argument(thread_safe_mode, endpoint_infos, log_level, telemetry_option) O3::ProviderCoreStartupArgument.new( thread_safe_mode: thread_safe_mode, provider_core_startup_argument_endpoint_infos: endpoint_infos, log_level: log_level, telemetry_option: telemetry_option, extension: {} ) end def create_telemetry_option(use_remote_engine_telemetry_setting) O3::TelemetryOption.new( attributes: {}, use_remote_engine_telemetry_setting: use_remote_engine_telemetry_setting, telemetry_endpoints: [] ) end def create_provider_core_startup_argument_endpoint_info(protocol_type, host, port) O3::ProviderCoreStartupArgumentEndpointInfo.new( protocol_type: protocol_type, host: host, port: port, reserved: "".b # 空のバイト列 ) end end end end end