Skip to content

Commit

Permalink
chore: removing entities and workflows from proto spec (#87)
Browse files Browse the repository at this point in the history
* chore: removing entities and workflows from proto spec

* bumping runtime
  • Loading branch information
aludwiko authored Dec 13, 2024
1 parent 5894d6b commit 98e726e
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 207 deletions.
2 changes: 1 addition & 1 deletion akka-javasdk-maven/akka-javasdk-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

<!-- These are dependent on runtime environment and cannot be customized by users -->
<maven.compiler.release>21</maven.compiler.release>
<kalix-runtime.version>1.3.0-f5764fe</kalix-runtime.version>
<kalix-runtime.version>1.3.0-03a3a40</kalix-runtime.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skip.docker>false</skip.docker>
Expand Down
60 changes: 5 additions & 55 deletions akka-javasdk/src/main/scala/akka/javasdk/impl/SdkRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ import akka.javasdk.impl.Validations.Validation
import akka.javasdk.impl.client.ComponentClientImpl
import akka.javasdk.impl.consumer.ConsumerImpl
import akka.javasdk.impl.eventsourcedentity.EventSourcedEntityImpl
import akka.javasdk.impl.eventsourcedentity.EventSourcedEntityService
import akka.javasdk.impl.http.HttpClientProviderImpl
import akka.javasdk.impl.http.JwtClaimsImpl
import akka.javasdk.impl.keyvalueentity.KeyValueEntityImpl
import akka.javasdk.impl.keyvalueentity.KeyValueEntityService
import akka.javasdk.impl.reflection.Reflect
import akka.javasdk.impl.reflection.Reflect.Syntax.AnnotatedElementOps
import akka.javasdk.impl.serialization.JsonSerializer
Expand All @@ -60,7 +58,6 @@ import akka.javasdk.impl.timedaction.TimedActionImpl
import akka.javasdk.impl.timer.TimerSchedulerImpl
import akka.javasdk.impl.view.ViewDescriptorFactory
import akka.javasdk.impl.workflow.WorkflowImpl
import akka.javasdk.impl.workflow.WorkflowService
import akka.javasdk.keyvalueentity.KeyValueEntity
import akka.javasdk.keyvalueentity.KeyValueEntityContext
import akka.javasdk.timedaction.TimedAction
Expand Down Expand Up @@ -319,13 +316,13 @@ private final class Sdk(
None
} else if (classOf[EventSourcedEntity[_, _]].isAssignableFrom(clz)) {
logger.debug(s"Registering EventSourcedEntity [${clz.getName}]")
Some(eventSourcedEntityService(clz.asInstanceOf[Class[EventSourcedEntity[Nothing, Nothing]]]))
None
} else if (classOf[Workflow[_]].isAssignableFrom(clz)) {
logger.debug(s"Registering Workflow [${clz.getName}]")
Some(workflowService(clz.asInstanceOf[Class[Workflow[Nothing]]]))
None
} else if (classOf[KeyValueEntity[_]].isAssignableFrom(clz)) {
logger.debug(s"Registering KeyValueEntity [${clz.getName}]")
Some(keyValueEntityService(clz.asInstanceOf[Class[KeyValueEntity[Nothing]]]))
None
} else if (Reflect.isView(clz)) {
logger.debug(s"Registering View [${clz.getName}]")
None // no factory, handled below
Expand Down Expand Up @@ -555,19 +552,8 @@ private final class Sdk(
serviceDescriptor.getFullName -> service
}

services.groupBy(_._2.getClass).foreach {

case (serviceClass, _: Map[String, EventSourcedEntityService[_, _, _]] @unchecked)
if serviceClass == classOf[EventSourcedEntityService[_, _, _]] =>

case (serviceClass, _: Map[String, KeyValueEntityService[_, _]] @unchecked)
if serviceClass == classOf[KeyValueEntityService[_, _]] =>

case (serviceClass, _: Map[String, WorkflowService[_, _]] @unchecked)
if serviceClass == classOf[WorkflowService[_, _]] =>

case (serviceClass, _) =>
sys.error(s"Unknown service type: $serviceClass")
services.groupBy(_._2.getClass).foreach { case (serviceClass, _) =>
sys.error(s"Unknown service type: $serviceClass")
}

val serviceSetup: Option[ServiceSetup] = maybeServiceClass match {
Expand Down Expand Up @@ -644,42 +630,6 @@ private final class Sdk(
}
}

private def workflowService[S, W <: Workflow[S]](clz: Class[W]): WorkflowService[S, W] = {
new WorkflowService[S, W](
clz,
serializer,
{ context =>

val workflow = wiredInstance(clz) {
sideEffectingComponentInjects(None).orElse {
// remember to update component type API doc and docs if changing the set of injectables
case p if p == classOf[WorkflowContext] => context
}
}

// FIXME pull this inline setup stuff out of SdkRunner and into some workflow class
val workflowStateType: Class[S] = Reflect.workflowStateType(workflow)
serializer.registerTypeHints(workflowStateType)

workflow
.definition()
.getSteps
.asScala
.flatMap { case asyncCallStep: Workflow.AsyncCallStep[_, _, _] =>
List(asyncCallStep.callInputClass, asyncCallStep.transitionInputClass)
}
.foreach(serializer.registerTypeHints)

workflow
})
}
private def eventSourcedEntityService[S, E, ES <: EventSourcedEntity[S, E]](
clz: Class[ES]): EventSourcedEntityService[S, E, ES] =
EventSourcedEntityService(clz, serializer)

private def keyValueEntityService[S, VE <: KeyValueEntity[S]](clz: Class[VE]): KeyValueEntityService[S, VE] =
new KeyValueEntityService(clz, serializer)

private def httpEndpointFactory[E](httpEndpointClass: Class[E]): HttpEndpointConstructionContext => E = {
(context: HttpEndpointConstructionContext) =>
lazy val requestContext = new RequestContext {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import akka.javasdk.impl.ActivatableContext
import akka.javasdk.impl.ComponentDescriptor
import akka.javasdk.impl.ErrorHandling.BadRequestException
import akka.javasdk.impl.MetadataImpl
import akka.javasdk.impl.Service
import akka.javasdk.impl.WorkflowExceptions.WorkflowException
import akka.javasdk.impl.serialization.JsonSerializer
import akka.javasdk.impl.telemetry.SpanTracingImpl
Expand Down Expand Up @@ -49,7 +48,6 @@ import akka.runtime.sdk.spi.SpiWorkflow
import akka.runtime.sdk.spi.TimerClient
import io.opentelemetry.api.trace.Span
import io.opentelemetry.api.trace.Tracer
import kalix.protocol.workflow_entity.WorkflowEntities

/**
* INTERNAL API
Expand Down Expand Up @@ -245,21 +243,6 @@ class WorkflowImpl[S, W <: Workflow[S]](

}

/**
* INTERNAL API
*/
@InternalApi
final class WorkflowService[S, W <: Workflow[S]](
workflowClass: Class[_],
serializer: JsonSerializer,
instanceFactory: Function[WorkflowContext, W])
extends Service(workflowClass, WorkflowEntities.name, serializer) {

def createRouter(context: WorkflowContext) =
new ReflectiveWorkflowRouter[S, W](instanceFactory(context), componentDescriptor.commandHandlers, serializer)

}

/**
* INTERNAL API
*/
Expand Down
30 changes: 0 additions & 30 deletions docs/src/modules/java/pages/event-sourced-entities.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -241,33 +241,3 @@ include::example$shopping-cart-quickstart/src/it/java/shoppingcart/IntegrationTe
<6> Assert there should only be one item.

NOTE: The integration tests in samples are under a specific project profile `it` and can be run using `mvn verify -Pit`.

== Exposing entities directly

include::partial$component-endpoint.adoc[]

=== API

The entity is exposed at a fixed path:

[source]
----
/akka/v1.0/entity/<component id>/<entity id>/<method>
----

In our shopping cart example that is:

[source,shell]
----
curl localhost:9000/akka/v1.0/entity/carts/12345/getCart
----

or, to add an item:

[source,shell]
----
curl localhost:9000/akka/v1.0/entity/carts/12345/addItem \
--header "Content-Type: application/json" \
-XPOST \
--data '{"productId":"akka-tshirt","name":"Akka Tshirt","quantity":10}'
----
22 changes: 1 addition & 21 deletions docs/src/modules/java/pages/key-value-entities.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,4 @@ include::example$key-value-counter/src/it/java/com/example/CounterIntegrationTes
<4> Request to increase the value of counter `bar`. Response should have value `1`.
<5> Explicitly request current value of `bar`. It should be `1`.

NOTE: The integration tests in samples are under a specific project profile `it` and can be run using `mvn verify -Pit`.

== Exposing entities directly

include::partial$component-endpoint.adoc[]

=== API

The entity is exposed at a fixed path:

[source]
----
/akka/v1.0/entity/<component id>/<entity id>/<method>
----

In our counter example that is:

[source,shell]
----
curl localhost:9000/akka/v1.0/entity/counter/foo/get
----
NOTE: The integration tests in samples are under a specific project profile `it` and can be run using `mvn verify -Pit`.
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Dependencies {
val ProtocolVersionMinor = 1
val RuntimeImage = "gcr.io/kalix-public/kalix-runtime"
// Remember to bump kalix-runtime.version in akka-javasdk-maven/akka-javasdk-parent if bumping this
val RuntimeVersion = sys.props.getOrElse("kalix-runtime.version", "1.3.0-f5764fe")
val RuntimeVersion = sys.props.getOrElse("kalix-runtime.version", "1.3.0-03a3a40")
}
// NOTE: embedded SDK should have the AkkaVersion aligned, when updating RuntimeVersion, make sure to check
// if AkkaVersion and AkkaHttpVersion are aligned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,4 @@ GET localhost:9000/api/users/002


### get by country
GET localhost:9000/api/users/by-country/Belgium

### doe@acme info - forbiden call (ACL blocks it)
GET localhost:9000/akka/v1.0/entity/unique-address/[email protected]/getState
GET localhost:9000/api/users/by-country/Belgium
34 changes: 0 additions & 34 deletions samples/key-value-customer-registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,40 +153,6 @@ Start this query in one terminal window while triggering updates in another term
changing the name to and from "Jan Janssen" or adding more customers with different ids and the same name, to see the
updates appear.

## Pre-defined paths

Akka runtime provides pre-defined paths based on the component id, entity id and the method name to interact directly
with the entities, those are however locked down from access through default deny-all ACLs. It is possible to explicitly
allow access on an entity using the `akka.javasdk.annotations.Acl` annotation, or by completely disabling the local
"dev mode" ACL checking by running the service with `mvn -Dakka.javasdk.dev-mode.acl.enabled=false compile exec:java`
or changing the default in your `src/main/resources/application.conf`.

For deployed services the ACLs are always enabled.

Zero parameter methods are exposed as HTTP GET:

```shell
curl localhost:9000/akka/v1.0/entity/customer/002/getCustomer
```

Methods with a parameter are instead exposed as HTTP POST:

```shell
curl -i localhost:9000/akka/v1.0/entity/customer/004/create \
--header "Content-Type: application/json" \
-XPOST \
--data '{"email":"[email protected]","name":"Test 4 Testsson","address":{"street":"Teststreet 27","city":"Testcity"}}'
```

The views:

```shell
curl localhost:9000/akka/v1.0/view/customers_by_email/getCustomer \
--header "Content-Type: application/json" \
-XPOST \
--data '{"email":"[email protected]"}'
```

## Deploying

You can use the [Akka Console](https://console.akka.io) to create a project and see the status of your service.
Expand Down

0 comments on commit 98e726e

Please sign in to comment.