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

pekko support? #1784

Closed
pjfanning opened this issue Jul 29, 2023 · 12 comments
Closed

pekko support? #1784

pjfanning opened this issue Jul 29, 2023 · 12 comments
Labels
enhancement Functionality that has never existed in guardrail scala Broadly concerning Scala code generation or the generated Scala code

Comments

@pjfanning
Copy link

Any interest in supporting pekko-http. This is a FOSS fork of akka-http.
pekko-http 1.0.0 should be released this week. Snapshots are available already.

https://pekko.apache.org/docs/pekko-http

@blast-hardcheese
Copy link
Member

Pardon the delay, I'm on vacation for the next two weeks.

Is the only change the package namespace? If so it may be possible to have a module based on the akka modules that translates the package names in the AST during generation.

I've been pushing for explicit package names to avoid namespace collisions with terms that come from OpenAPI files, so this may be all that's required until the libraries diverge significantly.

@pjfanning
Copy link
Author

pjfanning commented Aug 6, 2023

Thanks @blast-hardcheese for your response.

The Pekko code uses different package names - org.apache.pekko instead of akka. The config names are prefixed with pekko instead of akka.

Pekko HTTP has Scala 3 support so you won't need to use Cross Version support to handle Scala 3.

I've migrated a few libs to use Pekko and it is quite straightforward.

There is no urgency is this issue but it would be nice to get around to it in a few months.

@blast-hardcheese
Copy link
Member

The Pekko code uses different package names - org.apache.pekko instead of akka. The config names are prefixed with pekko instead of akka.

👍

I've migrated a few libs to use Pekko and it is quite straightforward.

👍

There is no urgency is this issue but it would be nice to get around to it in a few months.

indeed. I'm heartened that there's a push in this direction, happy to lend support when I can.

@blast-hardcheese blast-hardcheese added enhancement Functionality that has never existed in guardrail help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought scala Broadly concerning Scala code generation or the generated Scala code labels Oct 22, 2023
@blast-hardcheese
Copy link
Member

OK, I've started on this -- Initial module work is in progress and should be published to maven central in a few days, though the ABI will only be compatible with the most recent SNAPSHOT release.

@blast-hardcheese blast-hardcheese removed the help wanted Easy to moderately difficult issues that don't require deep knowledge or architectural thought label Dec 3, 2023
@blast-hardcheese
Copy link
Member

For those who see this, something that would be very much appreciated is adding your organization name to the Adopters list in README.md.

Additionally, especially if you use guardrail internals, please join the matrix server, there have been some significant structural changes to make it easier to develop new modules.

@blast-hardcheese
Copy link
Member

blast-hardcheese commented Dec 3, 2023

New repo available at guardrail-dev/module-pekko-http, version 0.1.0 published to maven central.

The module is still in very early stages, and due to a lack of foresight on my part, this release jar depends on some SNAPSHOT deps until the next ABI-stable release is cut, but that should be good enough for testing in the interim.

@blast-hardcheese
Copy link
Member

Alright, thank you all for the interest!

Since this has been an ask from a few organizations at this point, feel free to reach out to devon@guardrail.dev or over Matrix if you determine you need more personalized solutions for your environment.

For the DIY-ers, here's what you need to get guardrail generating Apache Pekko:

guardrail-cli usage:

cs launch -r https://s01.oss.sonatype.org/content/repositories/snapshots \
  dev.guardrail::guardrail-cli:0.71.0 dev.guardrail::guardrail-scala-pekko-http:0.1.0 \
  -- --defaults --specPath .../petstore.json --outputPath /tmp/example/src/main/scala --packageName example \
     --module pekko-http --module circe \
     --client --server

sbt-guardrail usage:

diff --git a/build.sbt b/build.sbt
index 213d979..ec765f2 100644
--- a/build.sbt
+++ b/build.sbt
@@ -1,5 +1,5 @@
 Compile / guardrailTasks := List(
-  ScalaServer(file("petstore.yaml"), pkg="foo"),
+  ScalaServer(file("petstore.yaml"), pkg="foo", modules=List("pekko-http", "circe")),
 )

diff --git a/project/guardrail.sbt b/project/guardrail.sbt
index c146a2d..bd14acc 100644
--- a/project/guardrail.sbt
+++ b/project/guardrail.sbt
@@ -1 +1,10 @@
-addSbtPlugin("com.twilio" % "sbt-guardrail" % "0.64.0")
+addSbtPlugin("dev.guardrail" % "sbt-guardrail" % "0.75.2")
+
+libraryDependencies ++= Seq(
+  "dev.guardrail" %% "guardrail-scala-pekko-http" % "0.1.0",
+  "dev.guardrail" %% "guardrail-core" % "0.76.0-SNAPSHOT",
+  "dev.guardrail" %% "guardrail-scala-support" % "0.76.0-SNAPSHOT",
+  "dev.guardrail" %% "guardrail-scala-akka-http" % "0.77.0-SNAPSHOT",
+)
+
+resolvers += "Sonatype OSS Snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots"

Note: For build tooling, you'll have to provide a snapshot release of akka-http as well to avoid ABI classloader exceptions.

Since this appers to work, I'll close this issue. As we continue to build towards the next major release, this module will get updates.

@stanislav-chetvertkov
Copy link
Contributor

@blast-hardcheese Thank you, this is great!
Though I'm experiencing some difficulties due to SPI/loading conflicts, basically what I had previously is a custom pekko module with a dependency on "dev.guardrail" %% "guardrail-scala-akka-http" % "0.75.0", with the replaced imports and some amount of code duplication and custom functionality. Replacing the dependency to "dev.guardrail" %% "guardrail-scala-pekko-http" % "0.1.0", caused messages like Failed to run cli: dev.guardrail.generators.spi.ClientGeneratorLoader: Provider dev.guardrail.generators.scala.pekkoHttp.PekkoHttpClientGeneratorLoader could not be instantiated to appear, I tried experimenting with the content of resources/META-INF/services/dev.guardrail.generators.spi.ClientGeneratorLoader in my repository adding dev.guardrail.generators.scala.pekkoHttp.PekkoHttpClientGeneratorLoader and also changing the CLI arguments adding pekko-http as an additional argument to --module but no effect. I remember SPI loading this was kind of difficult to troubleshoot, I remember that there has to be no ambiguity and maybe I have to do it some other way, I'd appreciate some guidance on this.

@stanislav-chetvertkov
Copy link
Contributor

tried a hack of creating a dummy declaration for dev.guardrail.generators.scala.pekkoHttp.PekkoHttpClientGeneratorLoader so it gets picked up - now I'm getting java.lang.AbstractMethodError: Receiver class dev.guardrail.generators.scala.pekkoHttp.PekkoHttpClientGenerator does not define or inherit an implementation of the resolved method 'abstract cats.Monad MonadF()' of abstract class dev.guardrail.terms.client.ClientTerms. looks like the structure of dev.guardrail.terms.client.ClientTerms has changed between what is in 0.75.3 and in https://github.com/guardrail-dev/guardrail/blob/master/modules/core/src/main/scala/dev/guardrail/terms/client/ClientTerms.scala

@stanislav-chetvertkov
Copy link
Contributor

I've changed guardrail-core and guardrail-scala-support versions to "0.75.3-SNAPSHOT" and will be trying to adjust everything to the changes in the api

@stanislav-chetvertkov
Copy link
Contributor

Just noticed this change 133d58a will try to understand what has changed in https://github.com/guardrail-dev/guardrail/pull/1785/files it looks like a significant rewrite

@blast-hardcheese
Copy link
Member

@stanislav-chetvertkov The changes to the API should be minimal, this time at least.

https://github.com/guardrail-dev/guardrail/blob/master/MIGRATING.md#migrating-to-guardrail-core-0760-snapshot gives some guidance, specifically following the changes laid out in #1785

I debated writing a scalafix rule, since these changes are purely mechanical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Functionality that has never existed in guardrail scala Broadly concerning Scala code generation or the generated Scala code
Projects
None yet
Development

No branches or pull requests

3 participants