Skip to content

Commit

Permalink
feat: new codegen annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
octonato committed Jan 4, 2022
1 parent 621ffe7 commit 380335f
Show file tree
Hide file tree
Showing 52 changed files with 2,314 additions and 277 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ case class PackageNaming(
) {
lazy val javaPackage: String = javaPackageOption.getOrElse(pkg)
lazy val javaOuterClassname: String = javaOuterClassnameOption.getOrElse(name)

/**
* This changes both the proto package and the javaPackage (if defined) This is useful when we derived a component
* descriptor from a Service descriptor. In such a case, after we resolve the package where the component should live,
* we need to modify it in order to have the file generated in the right package.
*/
def changePackages(newPackage: String): PackageNaming = {
val adaptedPackage = javaPackageOption.map(_ => newPackage)
copy(javaPackageOption = adaptedPackage, pkg = newPackage)
}
}

object PackageNaming {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# Re-generates sample proto file descriptors from the source
# Requires https://github.com/lightbend/akkaserverless-java-sdk to be cloned locally, and its path provided
# Usage: ./generate-from-samples.sh /path/to/akkaserverless-framework /path/to/akkaserverless-java-sdk

if [ $# -lt 1 ]; then
echo "Required arguments not supplied"
echo "Usage: ./generate-from-samples.sh /path/to/akkaserverless-framework"
exit 1
fi

if [ ! -d "$1" ]; then
echo "$1 does not exist or is not a directory"
exit 1
fi


protoc --include_imports \
--proto_path="$1/protocols/sdk/src/main/protobuf" \
--proto_path="protos/event-sourced-entity-unnamed" \
--descriptor_set_out=descriptor-sets/event-sourced-shoppingcart-unnamed.desc \
"protos/event-sourced-entity-unnamed/com/example/shoppingcart/domain/shoppingcart_domain.proto" \
"protos/event-sourced-entity-unnamed/com/example/shoppingcart/shoppingcart_api.proto"

echo "Generated event-sourced-shoppingcart-unnamed.desc"

protoc --include_imports \
--proto_path="$1/protocols/sdk/src/main/protobuf" \
--proto_path="protos/event-sourced-entity" \
--descriptor_set_out=descriptor-sets/event-sourced-shoppingcart.desc \
"protos/event-sourced-entity/com/example/shoppingcart/domain/shoppingcart_domain.proto" \
"protos/event-sourced-entity/com/example/shoppingcart/shoppingcart_api.proto"

echo "Generated event-sourced-shoppingcart.desc"


protoc --include_imports \
--proto_path="$1/protocols/sdk/src/main/protobuf" \
--proto_path="protos/view" \
--descriptor_set_out=descriptor-sets/view-shoppingcart.desc \
"protos/view/com/example/shoppingcart/view/shopping_cart_view_model.proto"

echo "Generated view-shoppingcart.desc"

protoc --include_imports \
--proto_path="$1/protocols/sdk/src/main/protobuf" \
--proto_path="protos/view-named" \
--descriptor_set_out=descriptor-sets/view-shoppingcart-named.desc \
"protos/view-named/com/example/shoppingcart/view/shopping_cart_view_model.proto"

echo "Generated view-shoppingcart-named.desc"

protoc --include_imports \
--proto_path="$1/protocols/sdk/src/main/protobuf" \
--proto_path="protos/value-entity-unnamed" \
--descriptor_set_out=descriptor-sets/value-shoppingcart-unnamed.desc \
"protos/value-entity-unnamed/com/example/shoppingcart/domain/shoppingcart_domain.proto" \
"protos/value-entity-unnamed/com/example/shoppingcart/shoppingcart_api.proto"

echo "Generated value-shoppingcart-unnamed.desc"

protoc --include_imports \
--proto_path="$1/protocols/sdk/src/main/protobuf" \
--proto_path="protos/value-entity" \
--descriptor_set_out=descriptor-sets/value-shoppingcart.desc \
"protos/value-entity/com/example/shoppingcart/domain/shoppingcart_domain.proto" \
"protos/value-entity/com/example/shoppingcart/shoppingcart_api.proto"

echo "Generated value-shoppingcart.desc"


protoc --include_imports \
--proto_path="$1/protocols/sdk/src/main/protobuf" \
--proto_path="protos/action" \
--descriptor_set_out=descriptor-sets/action-shoppingcart.desc \
"protos/action/com/example/shoppingcart/shoppingcart_controller_api.proto"

echo "Generated action-shoppingcart.desc"

protoc --include_imports \
--proto_path="$1/protocols/sdk/src/main/protobuf" \
--proto_path="protos/action-named" \
--descriptor_set_out=descriptor-sets/action-shoppingcart-named.desc \
"protos/action-named/com/example/shoppingcart/shoppingcart_controller_api.proto"

echo "Generated action-shoppingcart.desc"

protoc --include_imports \
--proto_path="$1/protocols/sdk/src/main/protobuf" \
--proto_path="protos/replicated-entity-unnamed" \
--descriptor_set_out=descriptor-sets/replicated-shoppingcart-unnamed.desc \
"protos/replicated-entity-unnamed/com/example/shoppingcart/domain/shoppingcart_domain.proto" \
"protos/replicated-entity-unnamed/com/example/shoppingcart/shoppingcart_api.proto"

echo "Generated replicated-shoppingcart-unnamed.desc"

protoc --include_imports \
--proto_path="$1/protocols/sdk/src/main/protobuf" \
--proto_path="protos/replicated-entity" \
--descriptor_set_out=descriptor-sets/replicated-shoppingcart.desc \
"protos/replicated-entity/com/example/shoppingcart/domain/shoppingcart_domain.proto" \
"protos/replicated-entity/com/example/shoppingcart/shoppingcart_api.proto"

echo "Generated replicated-shoppingcart.desc"
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2021 Lightbend Inc.
//
// 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.

syntax = "proto3";

package com.example.shoppingcart;

option java_outer_classname = "ShoppingCartController";
import "akkaserverless/annotations.proto";

message NewCart {
}

message NewCartCreated {
string cart_id = 1;
}

service ShoppingCartAction {
option (akkaserverless.codegen) = {
action: {
name: ".controllers.ShoppingCartController"
}
};

rpc InitializeCart(NewCart) returns (NewCartCreated);
rpc CreatePrePopulated(NewCart) returns (NewCartCreated);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2021 Lightbend Inc.
//
// 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.

syntax = "proto3";

package com.example.shoppingcart;

option java_outer_classname = "ShoppingCartController";
import "akkaserverless/annotations.proto";

message NewCart {
}

message NewCartCreated {
string cart_id = 1;
}

service ShoppingCartAction {
option (akkaserverless.codegen) = {
action: { }
};

rpc InitializeCart(NewCart) returns (NewCartCreated);
rpc CreatePrePopulated(NewCart) returns (NewCartCreated);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021 Lightbend Inc.
//
// 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.

syntax = "proto3";

package com.example.shoppingcart.domain;
option java_outer_classname = "ShoppingCartDomain";

message LineItem {
string productId = 1;
string name = 2;
int32 quantity = 3;
}

// The item added event.
message ItemAdded {
LineItem item = 1;
}

// The item removed event.
message ItemRemoved {
string productId = 1;
}

// The checked out event.
message CheckedOut {
int64 checked_out_timestamp = 1;
}

// The shopping cart state.
message Cart {
repeated LineItem items = 1;
}
// end::domain[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2021 Lightbend Inc.
//
// 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.

syntax = "proto3";

package com.example.shoppingcart;

import "akkaserverless/annotations.proto";
import "google/protobuf/empty.proto";

option java_outer_classname = "ShoppingCartApi";

message AddLineItem {
string cart_id = 1 [(akkaserverless.field).entity_key = true];
string product_id = 2;
string name = 3;
int32 quantity = 4;
}

message RemoveLineItem {
string cart_id = 1 [(akkaserverless.field).entity_key = true];
string product_id = 2;
}

message GetShoppingCart {
string cart_id = 1 [(akkaserverless.field).entity_key = true];
}

message LineItem {
string product_id = 1;
string name = 2;
int32 quantity = 3;
}

message Cart {
repeated LineItem items = 1;
}

service ShoppingCartService {
option (akkaserverless.codegen) = {
event_sourced_entity: {
entity_type: "shopping-cart"
state: ".domain.Cart"
events: [
".domain.ItemAdded",
".domain.ItemRemoved" ]
}
};

rpc AddItem (AddLineItem) returns (google.protobuf.Empty);

rpc RemoveItem (RemoveLineItem) returns (google.protobuf.Empty);

rpc GetCart (GetShoppingCart) returns (Cart);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021 Lightbend Inc.
//
// 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.

syntax = "proto3";

package com.example.shoppingcart.domain;
option java_outer_classname = "ShoppingCartDomain";

message LineItem {
string productId = 1;
string name = 2;
int32 quantity = 3;
}

// The item added event.
message ItemAdded {
LineItem item = 1;
}

// The item removed event.
message ItemRemoved {
string productId = 1;
}

// The checked out event.
message CheckedOut {
int64 checked_out_timestamp = 1;
}

// The shopping cart state.
message Cart {
repeated LineItem items = 1;
}
// end::domain[]
Loading

0 comments on commit 380335f

Please sign in to comment.