Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce actions protocol #5

Merged
merged 22 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
aeb6df3
feat: added external proto to build/lib configuration
raphael-goetz Aug 22, 2024
60d529a
feat: added external proto files
raphael-goetz Aug 22, 2024
a7b81ba
feat: added external proto files
raphael-goetz Aug 22, 2024
e36e386
Merge remote-tracking branch 'origin/feat/external-actions' into feat…
raphael-goetz Aug 22, 2024
cfd3d61
feat: added DataType & removed unneeded types
raphael-goetz Aug 22, 2024
fa0eff5
feat: added identifier field for action transfer request
raphael-goetz Aug 22, 2024
58b3dbd
ref: moved definitions.proto into shared folder
raphael-goetz Aug 23, 2024
b041e2f
feat: adjusted build configuration
raphael-goetz Aug 23, 2024
622b0ae
feat: flows are now updated via stream
raphael-goetz Aug 23, 2024
42f0a38
feat: added shared module
raphael-goetz Aug 23, 2024
f6597b3
fix: removed unneeded message type
raphael-goetz Aug 23, 2024
3c691f1
Merge branch 'main' into feat/external-actions
raphael-goetz Aug 23, 2024
7404d29
feat: started to adjust flows to new database schema
raphael-goetz Aug 23, 2024
d01ac7d
fix: InformationRequest now returns InformationResponse
raphael-goetz Aug 23, 2024
d1b6817
feat: adjusted building configuration to current proto files
raphael-goetz Aug 27, 2024
4d59650
feat: updated proto files to latest communication-planing
raphael-goetz Aug 27, 2024
003ef5d
feat: updated proto files to latest communication-planing
raphael-goetz Aug 27, 2024
63a98ce
Merge remote-tracking branch 'origin/feat/external-actions' into feat…
raphael-goetz Aug 27, 2024
7f0ba1b
fix: removed non-existing proto files for compiling
raphael-goetz Aug 27, 2024
d9a219f
Move proto files
Taucher2003 Aug 29, 2024
3cc0264
Fix ruby build for shared protos
Taucher2003 Aug 29, 2024
e458033
Rename start_node in Flow
Taucher2003 Aug 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build/ruby/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
.rspec_status

# generated ruby files
lib/tucana/actions/*.rb
lib/tucana/internal/*.rb
lib/tucana/shared/*.rb
61 changes: 45 additions & 16 deletions build/ruby/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,77 @@ RSpec::Core::RakeTask.new(:spec)

PROJECT_ROOT = File.expand_path("../..", __dir__)
RUBY_ROOT = "#{PROJECT_ROOT}/build/ruby".freeze
INPUT_INTERNAL_DIR = "#{PROJECT_ROOT}/internal".freeze
PROTO_ROOT = "#{PROJECT_ROOT}/proto".freeze
INPUT_ACTIONS_DIR = "#{PROTO_ROOT}/actions".freeze
INPUT_INTERNAL_DIR = "#{PROTO_ROOT}/internal".freeze
INPUT_SHARED_DIR = "#{PROTO_ROOT}/shared".freeze
OUTPUT_ACTIONS_DIR = "#{RUBY_ROOT}/lib/tucana/actions".freeze
OUTPUT_INTERNAL_DIR = "#{RUBY_ROOT}/lib/tucana/internal".freeze
OUTPUT_SHARED_DIR = "#{RUBY_ROOT}/lib/tucana/shared".freeze

def system!(*args)
system(*args, exception: true)
end

namespace :generate_ruby do
desc "Generate ruby files for the internal protocol"
task :internal do
FileUtils.rm_rf(OUTPUT_INTERNAL_DIR)
FileUtils.mkdir_p(OUTPUT_INTERNAL_DIR)
def compile_protos!(input_dir, output_dir)
FileUtils.rm_rf(output_dir)
FileUtils.mkdir_p(output_dir)
FileUtils.chdir RUBY_ROOT do
Dir["#{INPUT_INTERNAL_DIR}/*.proto"].each do |file|
Dir["#{input_dir}/*.proto"].each do |file|
# rubocop:disable Layout/LineLength
system!("bundle exec grpc_tools_ruby_protoc -I #{INPUT_INTERNAL_DIR} --ruby_out=#{OUTPUT_INTERNAL_DIR} --grpc_out=#{OUTPUT_INTERNAL_DIR} #{file}")
system!("bundle exec grpc_tools_ruby_protoc -I #{input_dir} -I #{INPUT_SHARED_DIR} --ruby_out=#{output_dir} --grpc_out=#{output_dir} #{file}")
# rubocop:enable Layout/LineLength
end
Dir["#{OUTPUT_INTERNAL_DIR}/*_pb.rb"].each do |file|

Dir["#{OUTPUT_SHARED_DIR}/*_pb.rb"].each do |shared_file|
shared_file_name = File.basename(shared_file).delete_suffix('.rb')
Dir["#{output_dir}/*_pb.rb"].each do |file|
code = File.read(file)
code = code.gsub("require '#{shared_file_name}'", "require_relative '../shared/#{shared_file_name}'")
File.write(file, code)
end
end

Dir["#{output_dir}/*_pb.rb"].each do |file|
code = File.read(file)
code = code.gsub(/require '(\S+)_pb'/, "require_relative '\\1_pb'")
File.write(file, code)
File.write(file, code)
end
end
end

desc "Generate ruby files for shared files between protocols"
task :shared do
compile_protos!(INPUT_SHARED_DIR, OUTPUT_SHARED_DIR)
end

desc "Generate ruby files for the internal protocol"
task internal: "generate_ruby:shared" do
compile_protos!(INPUT_INTERNAL_DIR, OUTPUT_INTERNAL_DIR)
end

desc "Generate ruby files for the actions protocol"
task actions: "generate_ruby:shared" do
compile_protos!(INPUT_ACTIONS_DIR, OUTPUT_ACTIONS_DIR)
end

desc "Generate ruby files for all protocols"
task all: ["generate_ruby:internal"]
task all: %w[generate_ruby:internal generate_ruby:actions]
end

namespace :release do
desc "Set the version for the gem"
task :version, [:version] do |_, args|
File.write("#{RUBY_ROOT}/lib/tucana/version.rb", <<~RUBY)
# frozen_string_literal: true
# frozen_string_literal: true

# this file is managed with the "release:version" task.
# to update the version, run "bundle exec rake release:version[NEW_VERSION]".
# this file is managed with the "release:version" task.
# to update the version, run "bundle exec rake release:version[NEW_VERSION]".

module Tucana
VERSION = "#{args[:version]}"
end
module Tucana
VERSION = "#{args[:version]}"
end
RUBY

system!("bundle")
Expand Down
8 changes: 8 additions & 0 deletions build/ruby/spec/tucana_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@
it "has a version number" do
expect(Tucana::VERSION).not_to be_nil
end

it "can load internal protocol" do
expect { Tucana.load_protocol(:internal) }.not_to raise_error
end

it "can load actions protocol" do
expect { Tucana.load_protocol(:actions) }.not_to raise_error
end
end
42 changes: 25 additions & 17 deletions build/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,40 @@ use std::io::Result;

fn main() -> Result<()> {

let path = "src/internal";
let proto = &[
"definitions.proto",
"flow_definition.proto",
"node.proto",
"flow.proto",
"action.proto",
"transfer.proto",
"ping.proto"
];

if !std::path::Path::new(&path).exists() {
create_dir(path)?;
let inclusions = &[
"../../proto/shared",
"../../proto/internal",
"../../proto/actions",
];

let out_path = "src/generated";

if !std::path::Path::new(&out_path).exists() {
create_dir(out_path)?;
}

tonic_build::configure()
.out_dir(path)
.out_dir(out_path)
.build_server(true)
.build_client(true)
.type_attribute("Variable", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("RuleType", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Rule", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Type", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("FlowDefinition", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("RuntimeFunctionDefinition", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("RuntimeParameterDefinition", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Parameter", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Node", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Flow", "#[derive(serde::Serialize, serde::Deserialize)]")
.compile(&[
"variable.proto",
"rule.proto",
"type.proto",
"node.proto",
"flow.proto",
"ping.proto",
], &["../../internal"])
.expect("Cannot compile protos");
.compile(proto, inclusions)
.expect("Cannot compile internal protos");

Ok(())
}
10 changes: 9 additions & 1 deletion build/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
pub mod internal {
include!("internal/internal.rs");
include!("generated/internal.rs");
}

pub mod actions {
include!("generated/actions.rs");
}

pub mod shared {
include!("generated/shared.rs");
}
59 changes: 0 additions & 59 deletions internal/flow.proto

This file was deleted.

24 changes: 0 additions & 24 deletions internal/node.proto

This file was deleted.

16 changes: 0 additions & 16 deletions internal/rule.proto

This file was deleted.

15 changes: 0 additions & 15 deletions internal/type.proto

This file was deleted.

21 changes: 21 additions & 0 deletions proto/actions/transfer.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";

import "definitions.proto";

option ruby_package = "Tucana::Actions";

package actions;

message InformationRequest {
string identifier = 1;
repeated shared.RuntimeFunctionDefinition function_definition = 2;
repeated shared.RuntimeParameterDefinition parameter_definition = 3;
}

message InformationResponse {
bool success = 1;
}

service ActionTransferService {
rpc Transfer (stream InformationRequest) returns (InformationResponse);
}
25 changes: 25 additions & 0 deletions proto/internal/action.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
import "definitions.proto";

option ruby_package = "Tucana::Internal";

package internal;

message ActionLogonRequest {
string identifier = 1;
repeated shared.RuntimeFunctionDefinition function_definition = 2;
repeated shared.RuntimeParameterDefinition parameter_definition = 3;
}

message ActionLogonResponse {}

message ActionLogoffRequest {
string identifier = 1;
}

message ActionLogoffResponse {}

service ActionService {
rpc Logon (ActionLogonRequest) returns (ActionLogonResponse);
rpc Logoff (ActionLogoffRequest) returns (ActionLogoffResponse);
}
Loading