Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

WIP-CRUD on top of Event Sourcing #220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
6d3b2c1
Issue-197: add npm task for preparing node-support to be able to buil…
ralphlaude Feb 22, 2020
0fbd706
Merge remote-tracking branch 'upstream/master'
ralphlaude Feb 24, 2020
27d22ff
Merge remote-tracking branch 'upstream/master'
ralphlaude Feb 27, 2020
2a32aa1
Merge remote-tracking branch 'upstream/master'
ralphlaude Mar 12, 2020
579d1c4
Merge remote-tracking branch 'upstream/master'
ralphlaude Mar 16, 2020
8014961
Merge remote-tracking branch 'upstream/master'
ralphlaude Mar 23, 2020
91f3333
Merge remote-tracking branch 'upstream/master'
ralphlaude Mar 25, 2020
38327d3
Proposal for CRUD on top of Event Sourcing
ralphlaude Mar 30, 2020
6cc25fe
Proposal for CRUD on top of Event Sourcing; Comment code handling events
ralphlaude Mar 30, 2020
9a7a8bf
rollback changes in the proxy and add proto file for the CRUD domain
ralphlaude Mar 30, 2020
db2e4a8
Add CrudEntity annotation. Add registration for CrudEntity in CloudSt…
ralphlaude Mar 31, 2020
8aa1e97
Merge remote-tracking branch 'upstream/master'
ralphlaude Apr 2, 2020
2374b7b
change CrudEntity annotation. Change registration for CrudEntity in C…
ralphlaude Apr 14, 2020
82c2377
Merge remote-tracking branch 'upstream/master'
ralphlaude Apr 16, 2020
1f741d9
Merge remote-tracking branch 'upstream/master'
ralphlaude Apr 21, 2020
ca6b416
Merge remote-tracking branch 'upstream/master'
ralphlaude Apr 23, 2020
92effcd
Merge remote-tracking branch 'upstream/master'
ralphlaude Apr 24, 2020
473d682
Merge remote-tracking branch 'upstream/master'
ralphlaude Apr 24, 2020
6e23140
Merge remote-tracking branch 'upstream/master'
ralphlaude Apr 26, 2020
3664944
Merge remote-tracking branch 'upstream/master'
ralphlaude Apr 28, 2020
c9cc5f6
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude Apr 28, 2020
cee69f1
Merge remote-tracking branch 'upstream/master'
ralphlaude May 1, 2020
8e951e4
Merge remote-tracking branch 'upstream/master'
ralphlaude May 4, 2020
170bb0c
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude May 4, 2020
78b7840
Initial version for the CRUD protocol and the implementation
ralphlaude May 14, 2020
012c1e3
remove unused import
ralphlaude May 14, 2020
5647e15
Merge remote-tracking branch 'upstream/master'
ralphlaude May 15, 2020
dc810c4
Add comments and change the proto definition
ralphlaude May 15, 2020
078517f
Change the protocol to have one reply type for all operations and imp…
ralphlaude May 18, 2020
5e8ec79
Merge remote-tracking branch 'upstream/master'
ralphlaude May 21, 2020
da4a331
add crud command type as proto field option and extend the user funct…
ralphlaude May 24, 2020
78345f8
add some documentation and do some small refactoring
ralphlaude May 25, 2020
d1bdbb1
add java doc for crud protocol. extend the shopping cart example. ref…
ralphlaude May 26, 2020
d9a5dbd
Merge remote-tracking branch 'upstream/master'
ralphlaude May 27, 2020
ab73109
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude May 27, 2020
e906657
Merge branch 'prototype-crud-on-event-sourcing' into wip-crud-on-top-…
ralphlaude May 27, 2020
344d8d9
Documents the protocol and add new grpc type for command type. implem…
ralphlaude Jun 9, 2020
cda633a
Merge branch 'prototype-crud-on-event-sourcing' into wip-crud-on-top-…
ralphlaude Jun 9, 2020
87d1c4f
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude Jul 14, 2020
d0215aa
Provide a definition of the protocol with snapshotting capabilities a…
ralphlaude Jul 14, 2020
9f72587
wording fixed
ralphlaude Jul 14, 2020
866941d
add sample for crud shopping cart and rollback the sample shopping ca…
ralphlaude Jul 26, 2020
6e997f2
remove old crud shopping cart
ralphlaude Jul 26, 2020
9c9e02b
add StreamFailed in the presstart method
ralphlaude Jul 27, 2020
164a650
add tests for crud entity
ralphlaude Jul 27, 2020
9a3cf53
removed obsolete classes
ralphlaude Jul 27, 2020
c5de37d
add annotations for update and delete handlers
ralphlaude Jul 28, 2020
0979a9e
fixed scala format
ralphlaude Jul 28, 2020
5169003
fixed unit value
ralphlaude Jul 28, 2020
b93a3c0
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude Jul 28, 2020
1321d1e
fixed protobuf attribute index and fixed crud init state handling
ralphlaude Jul 29, 2020
c6e162a
fixed shopping cart entity
ralphlaude Jul 30, 2020
0675b17
call command handler only when the command was successful. Make the C…
ralphlaude Aug 26, 2020
1fd017d
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude Aug 26, 2020
928933c
fixed test
ralphlaude Aug 26, 2020
2310fc9
add native CRUD support with slick and integrate the in memory CRUD s…
ralphlaude Sep 7, 2020
919756d
modified markdown
ralphlaude Sep 7, 2020
dd2e4c8
add generic to command context and entity handler
ralphlaude Sep 7, 2020
bbd5e53
remove the use of sequence number in the GRPC CRUD protocol
ralphlaude Sep 7, 2020
99f8ffc
remove event sourced in memory snapshot store. adapt log for in memor…
ralphlaude Sep 7, 2020
8692f57
first version for checking null on updateEntity
ralphlaude Sep 7, 2020
18ce9c8
add comments
ralphlaude Sep 7, 2020
209648d
add exception handling based on the one in event sourced
ralphlaude Sep 9, 2020
44175e0
add new lines
ralphlaude Sep 9, 2020
b866e71
rewrite crud protocol by using oly command handler and passing the st…
ralphlaude Sep 14, 2020
2731570
change entity initialization
ralphlaude Sep 15, 2020
46b54fc
change entity initialization and adapt annotation based support test
ralphlaude Sep 15, 2020
7ec4ab5
change test name
ralphlaude Sep 15, 2020
d076e86
ignore CRUD entity test
ralphlaude Sep 15, 2020
b05f7aa
remove subsequent invocation checking which is not needed
ralphlaude Sep 16, 2020
11135d7
adapt the init case for the entity
ralphlaude Sep 17, 2020
cb282ad
deal with empty schema in the config
ralphlaude Sep 17, 2020
863dfe3
add comment for already initialized entity
ralphlaude Sep 18, 2020
e511b4b
integrate native crud support in postgres module
ralphlaude Sep 18, 2020
3bc45a0
save CRUD state as byte array
ralphlaude Sep 18, 2020
93a5962
fixed map on slick dbioaction
ralphlaude Sep 18, 2020
dd19ed1
change actor name
ralphlaude Sep 20, 2020
e84d4e6
add infra for CRUD tests in testkit. add exception handling test for …
ralphlaude Sep 22, 2020
6243e4d
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude Sep 22, 2020
624afbf
fixed conflicts and compile errors when merging master
ralphlaude Sep 22, 2020
968c332
fixed format error
ralphlaude Sep 22, 2020
29cdd47
add test for the crud java support
ralphlaude Sep 23, 2020
5cf66b7
remove comments and logs
ralphlaude Sep 23, 2020
bb98d71
changed java 11 for crud sample and fixed conflicting package name
ralphlaude Sep 23, 2020
6a2cd86
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude Sep 25, 2020
8acd3c9
remove concurrency enforcer
ralphlaude Sep 26, 2020
5a97b74
disabled CRUD native support for now
ralphlaude Sep 26, 2020
1b163b3
Add CRUD to expected protocols in TCK
pvlugter Sep 29, 2020
821fd4c
Add default value for cloudstate.proxy.postgres.schema setting
pvlugter Sep 29, 2020
5d9a193
enabled CRUD for the proxy and add readiness-checks
ralphlaude Sep 29, 2020
0248e53
add hikari connection pool properties
ralphlaude Sep 30, 2020
d8f2e9f
fixed protobuf any deserialization
ralphlaude Sep 30, 2020
4c90c02
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude Oct 3, 2020
353b41c
add TCK test for CRUD initial version
ralphlaude Oct 3, 2020
47f7cd3
add TCK test for CRUD and refactoring jdbc store factory
ralphlaude Oct 3, 2020
735257c
Merge remote-tracking branch 'origin/wip-crud-on-top-of-event-sourcin…
ralphlaude Oct 16, 2020
e7ae59c
removed class
ralphlaude Oct 16, 2020
41f189a
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude Oct 16, 2020
3f9789e
add metadata
ralphlaude Oct 16, 2020
eac2e7f
add table creation readiness in native image
ralphlaude Oct 17, 2020
35e0005
rename CRUD to Value Entity
ralphlaude Oct 20, 2020
f820f7f
rename CRUD to Value Entity
ralphlaude Oct 20, 2020
f21b7d0
rename CRUD to Value Entity follow up (crud jdbc configuration to val…
ralphlaude Oct 21, 2020
f65553c
add entity exceptions factory class. extract grpc entity message crea…
ralphlaude Oct 23, 2020
dd30efb
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude Oct 29, 2020
517ee37
integrate tests for entity in circleci
ralphlaude Oct 29, 2020
d4b2493
integrate tests for entity in circleci by building the entity image
ralphlaude Oct 29, 2020
a6bc7d9
integrate tests for entity in circleci by saving the entity image in …
ralphlaude Oct 29, 2020
375f9f9
add jdbc config tests
ralphlaude Oct 29, 2020
a578d6b
Merge branch 'master' into pr/220
pvlugter Nov 1, 2020
87dbd80
Update entity smoke test script
pvlugter Nov 2, 2020
65e5fc8
Fix entity delete in smoke test script
pvlugter Nov 2, 2020
2f6ba27
Add native-image configuration for value entity table
pvlugter Nov 2, 2020
8f1835a
Reduce value entity connection pool size
pvlugter Nov 2, 2020
62f0500
exclude slick dependency from other core persistence module.
ralphlaude Nov 2, 2020
f7e27aa
renaming value entity to entity in the java support, the proxy, the t…
ralphlaude Nov 6, 2020
a2bf57c
fixed native image configuration for value entity
ralphlaude Nov 7, 2020
469edab
write test for properly accessing the state after passivation
ralphlaude Nov 9, 2020
403aed0
fixed grammar
ralphlaude Nov 9, 2020
10c931e
Merge branch 'master' into wip-crud-on-top-of-event-sourcing
ralphlaude Nov 9, 2020
c915048
merge master and refactoring
ralphlaude Nov 9, 2020
5bf6a12
combined readiness checks for eventsourced and value entity
ralphlaude Nov 9, 2020
937084e
fixed readiness check
ralphlaude Nov 9, 2020
5545e6d
removed dedicated readiness check for value entity
ralphlaude Nov 9, 2020
5856394
fixed grammar, remove left crud names and fixed code
ralphlaude Nov 10, 2020
427b538
Merge branch 'master' into pr/220
pvlugter Nov 11, 2020
18cde26
Dynamically create value entity stores
pvlugter Nov 11, 2020
dc786ca
adapt the store-api to able to persist the tpye url of the entity
ralphlaude Nov 11, 2020
340325d
add comment for explaining duplicate shoppingcart.proto
ralphlaude Nov 11, 2020
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
29 changes: 21 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ jobs:
sbt 'dockerBuildCore publishLocal' \
'dockerBuildPostgres publishLocal' \
'dockerBuildCassandra publishLocal' \
java-shopping-cart/docker:publishLocal
java-shopping-cart/docker:publishLocal \
java-eventsourced-shopping-cart/docker:publishLocal
- save_docker_image:
tar_file: cloudstate-sbt-images.tar
docker_image: cloudstateio/cloudstate-proxy-core:latest cloudstateio/cloudstate-proxy-postgres:latest cloudstateio/cloudstate-proxy-cassandra:latest cloudstateio/java-shopping-cart:latest
docker_image: cloudstateio/cloudstate-proxy-core:latest cloudstateio/cloudstate-proxy-postgres:latest cloudstateio/cloudstate-proxy-cassandra:latest cloudstateio/java-shopping-cart:latest cloudstateio/java-eventsourced-shopping-cart:latest
- persist_to_workspace:
root: /tmp/workspace
paths:
Expand Down Expand Up @@ -249,14 +250,20 @@ jobs:
name: Install Cassandra
command: bin/install-cassandra.sh
- run:
name: Run shopping cart test (InMemory)
name: Run value-based shopping cart test (InMemory)
command: bin/run-java-shopping-cart-test.sh InMemory --no-build
- run:
name: Run shopping cart test (Postgres)
name: Run value-based shopping cart test (Postgres)
command: bin/run-java-shopping-cart-test.sh Postgres --no-build
- run:
name: Run shopping cart test (Cassandra)
command: bin/run-java-shopping-cart-test.sh Cassandra --no-build
name: Run eventsourced shopping cart test (InMemory)
command: bin/run-java-eventsourced-shopping-cart-test.sh InMemory --no-build
- run:
name: Run eventsourced shopping cart test (Postgres)
command: bin/run-java-eventsourced-shopping-cart-test.sh Postgres --no-build
- run:
name: Run eventsourced shopping cart test (Cassandra)
command: bin/run-java-eventsourced-shopping-cart-test.sh Cassandra --no-build

native-image-smoke-test:
parameters:
Expand Down Expand Up @@ -300,6 +307,9 @@ jobs:
- run:
name: Load in memory image
command: docker image load < /tmp/workspace/cloudstate-proxy-native-core.tar
- run:
name: Run value-based shopping cart test (InMemory)
command: bin/run-java-shopping-cart-test.sh InMemory --no-build
- when:
condition:
equal: [ Postgres, << parameters.proxy-store >> ]
Expand All @@ -309,6 +319,9 @@ jobs:
command: |
bin/install-postgres.sh
docker image load < /tmp/workspace/cloudstate-proxy-native-postgres.tar
- run:
name: Run value-based shopping cart test (Postgres)
command: bin/run-java-shopping-cart-test.sh Postgres --no-build
- when:
condition:
equal: [ Cassandra, << parameters.proxy-store >> ]
Expand All @@ -319,8 +332,8 @@ jobs:
bin/install-cassandra.sh
docker image load < /tmp/workspace/cloudstate-proxy-native-cassandra.tar
- run:
name: Run shopping cart test (<< parameters.proxy-store >>)
command: bin/run-java-shopping-cart-test.sh << parameters.proxy-store >> --no-build
name: Run eventsourced shopping cart test (<< parameters.proxy-store >>)
command: bin/run-java-eventsourced-shopping-cart-test.sh << parameters.proxy-store >> --no-build

publish-native-images:
machine: true
Expand Down
257 changes: 257 additions & 0 deletions bin/run-java-eventsourced-shopping-cart-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
#!/usr/bin/env bash
#
# Run the Java Event Sourced shopping cart sample as a test, with a given persistence store.
#
# run-java-eventsourced-shopping-cart-test.sh [inmemory|postgres|cassandra]

set -e

echo
echo "=== Running java-eventsourced-shopping-cart test ==="
echo

# process arguments
shopt -s nocasematch
build=true
logs=false
delete=true
declare -a residual
while [[ $# -gt 0 ]] ; do
case "$1" in
--no-build ) build=false; shift ;;
--logs ) logs=true; shift ;;
--no-delete ) delete=false; shift ;;
*) residual=("${residual[@]}" "$1"); shift ;;
esac
done
set -- "${residual[@]}"
store="$1"

# Build the java eventsourced shopping cart
if [ "$build" == true ] ; then
echo
echo "Building java-eventsourced-shopping-cart ..."
[ -f docker-env.sh ] && source docker-env.sh
sbt -Ddocker.username=cloudstatedev -Ddocker.tag=dev java-eventsourced-shopping-cart/docker:publishLocal
fi

statefulstore="inmemory"
statefulservice="shopping-cart-$statefulstore"

case "$store" in

postgres ) # deploy the eventsourced shopping-cart with postgres store

statefulstore="postgres"
statefulservice="shopping-cart-$statefulstore"

kubectl apply -f - <<YAML
apiVersion: cloudstate.io/v1alpha1
kind: StatefulStore
metadata:
name: $statefulstore
spec:
postgres:
host: postgres-postgresql.default.svc.cluster.local
credentials:
secret:
name: postgres-credentials
---
apiVersion: cloudstate.io/v1alpha1
kind: StatefulService
metadata:
name: $statefulservice
spec:
storeConfig:
statefulStore:
name: $statefulstore
containers:
- image: cloudstateio/java-eventsourced-shopping-cart:latest
imagePullPolicy: Never
name: user-function
YAML
;;

cassandra ) # deploy the eventsourced shopping-cart with cassandra store

statefulstore="cassandra"
statefulservice="shopping-cart-$statefulstore"

kubectl apply -f - <<YAML
apiVersion: cloudstate.io/v1alpha1
kind: StatefulStore
metadata:
name: $statefulstore
spec:
cassandra:
host: cassandra.default.svc.cluster.local
credentials:
secret:
name: cassandra-credentials
---
apiVersion: cloudstate.io/v1alpha1
kind: StatefulService
metadata:
name: $statefulservice
spec:
storeConfig:
statefulStore:
name: $statefulstore
database: shoppingcart
containers:
- image: cloudstateio/java-eventsourced-shopping-cart:latest
imagePullPolicy: Never
name: user-function
YAML
;;

inmemory | * ) # deploy the eventsourced shopping-cart with in-memory store

statefulstore="inmemory"
statefulservice="shopping-cart-$statefulstore"

kubectl apply -f - <<YAML
apiVersion: cloudstate.io/v1alpha1
kind: StatefulStore
metadata:
name: $statefulstore
spec:
inMemory: true
---
apiVersion: cloudstate.io/v1alpha1
kind: StatefulService
metadata:
name: $statefulservice
spec:
storeConfig:
statefulStore:
name: $statefulstore
containers:
- image: cloudstateio/java-eventsourced-shopping-cart:latest
imagePullPolicy: Never
name: user-function
YAML
;;

esac

deployment="$statefulservice"

# Can only kubectl wait when the resource already exists
echo
echo "Waiting for deployment to be created..."
attempts=10
until kubectl get deployment $deployment &> /dev/null || [ $attempts -eq 0 ] ; do
((attempts--))
sleep 1
done
kubectl get deployment $deployment

function fail_with_details {
echo "Failed:" "$@"
echo
echo "=== Operator logs ==="
echo
kubectl logs -l control-plane=controller-manager -n cloudstate-system -c manager --tail=-1
echo
echo "=== Deployment description ==="
echo
kubectl describe deployment/$deployment
echo
echo "=== Pods description ==="
echo
kubectl describe pods
echo
echo "=== Proxy logs ==="
echo
kubectl logs -l cloudstate.io/stateful-service=$statefulservice -c cloudstate-sidecar --tail=-1
echo
echo "=== User function logs ==="
echo
kubectl logs -l cloudstate.io/stateful-service=$statefulservice -c user-function --tail=-1
exit 1
}

# Wait for the deployment to be available
echo
echo "Waiting for deployment to be ready..."
kubectl rollout status --timeout=1m deployment/$deployment || fail_with_details
kubectl get deployment $deployment

# Scale up the deployment, to test with akka clustering
echo
echo "Scaling deployment..."
kubectl scale --replicas=3 statefulservice/$statefulservice
kubectl get deployment $deployment

# Wait for the scaled deployment to be available
echo
echo "Waiting for deployment to be ready..."
kubectl rollout status --timeout=5m deployment/$deployment || fail_with_details
kubectl get deployment $deployment
[ $(kubectl get deployment $deployment -o "jsonpath={.status.availableReplicas}") -eq 3 ] || fail_with_details "Expected 3 available replicas"

# Expose the eventsourced-shopping-cart service
nodeport="$deployment-node-port"
kubectl expose deployment $deployment --name=$nodeport --port=8013 --type=NodePort

# Get the URL for the eventsourced-shopping-cart service
url=$(minikube service $nodeport --url)

# Now we use the REST interface to test it (because it's easier to use curl than a grpc
# command line client)
empty_cart='{"items":[]}'
post='{"productId":"foo","name":"A foo","quantity":10}'
non_empty_cart='{"items":[{"productId":"foo","name":"A foo","quantity":10}]}'

# Iterate over multiple entities to be routed to different nodes
for i in {1..9} ; do
cart_id="test$i"
echo
echo "Testing eventsourced shopping cart $cart_id ..."

initial_cart=''
for attempt in {1..5} ; do
initial_cart=$(curl -s $url/carts/$cart_id || echo '')
[ -n "$initial_cart" ] && break || sleep 1
done

if [[ "$empty_cart" != "$initial_cart" ]]
then
echo "Expected '$empty_cart'"
echo "But got '$initial_cart'"
fail_with_details
else
echo "Initial request for $cart_id succeeded."
fi

curl -s -X POST $url/cart/$cart_id/items/add -H "Content-Type: application/json" -d "$post" > /dev/null

new_cart=$(curl -s $url/carts/$cart_id)
if [[ "$non_empty_cart" != "$new_cart" ]]
then
echo "Expected '$non_empty_cart'"
echo "But got '$new_cart'"
fail_with_details
else
echo "EventSourced Shopping cart update for $cart_id succeeded."
fi
done

# Print proxy logs
if [ "$logs" == true ] ; then
echo
echo "=== Proxy logs ==="
echo
kubectl logs -l cloudstate.io/stateful-service=$statefulservice -c cloudstate-sidecar --tail=-1
fi

# Delete eventsourced shopping-cart
if [ "$delete" == true ] ; then
echo
echo "Deleting $statefulservice ..."
kubectl delete service $deployment
kubectl delete service $nodeport
kubectl delete statefulservice $statefulservice
kubectl delete statefulstore $statefulstore
fi
Loading