-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add runner for non-repudiation (#9076)
* Add runner for non-repudiation Closes #8633 changelog_begin changelog_end * Fix existing tests * Add test for non-repudiation-app option parser * Remove unnecessary dependencies from non-repudiation testing * Fix Scala 2.13 build errors * Fix help message for --api-address and --api-port
- Loading branch information
1 parent
4784cfa
commit 0e4af74
Showing
16 changed files
with
454 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
load( | ||
"//bazel_tools:scala.bzl", | ||
"da_scala_binary", | ||
"da_scala_test", | ||
) | ||
|
||
da_scala_binary( | ||
name = "non-repudiation-app", | ||
srcs = glob(["src/main/scala/**/*.scala"]), | ||
main_class = "com.daml.nonrepudiation.app.NonRepudiationApp", | ||
scala_deps = [ | ||
"@maven//:com_github_scopt_scopt", | ||
"@maven//:com_typesafe_akka_akka_actor", | ||
"@maven//:com_typesafe_akka_akka_stream", | ||
"@maven//:org_tpolecat_doobie_core", | ||
"@maven//:org_tpolecat_doobie_hikari", | ||
"@maven//:org_typelevel_cats_effect", | ||
], | ||
runtime_deps = [ | ||
"@maven//:ch_qos_logback_logback_classic", | ||
"@maven//:org_postgresql_postgresql", | ||
], | ||
deps = [ | ||
"//ledger-api/grpc-definitions:ledger_api_proto_scala", | ||
"//libs-scala/doobie-slf4j", | ||
"//libs-scala/resources", | ||
"//libs-scala/resources-akka", | ||
"//runtime-components/non-repudiation", | ||
"//runtime-components/non-repudiation-api", | ||
"//runtime-components/non-repudiation-postgresql", | ||
"@maven//:io_grpc_grpc_api", | ||
"@maven//:io_grpc_grpc_core", | ||
"@maven//:io_grpc_grpc_netty", | ||
"@maven//:org_slf4j_slf4j_api", | ||
], | ||
) | ||
|
||
da_scala_test( | ||
name = "test", | ||
srcs = glob(["src/test/scala/**/*.scala"]), | ||
scala_deps = [ | ||
"@maven//:com_github_scopt_scopt", | ||
], | ||
deps = [ | ||
":non-repudiation-app", | ||
], | ||
) |
44 changes: 44 additions & 0 deletions
44
...onents/non-repudiation-app/src/main/scala/com/daml/nonrepudiation/app/Configuration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.nonrepudiation.app | ||
|
||
import java.net.{InetAddress, InetSocketAddress} | ||
|
||
import scala.concurrent.duration.{DurationInt, FiniteDuration} | ||
|
||
object Configuration { | ||
|
||
private val LocalHost = InetAddress.getLocalHost.getHostAddress | ||
private val LoopbackAddress = InetAddress.getLoopbackAddress.getHostAddress | ||
|
||
private val ApiDefaultPort: Int = 7882 // Non-repudiation -> NR -> N = 78 and R = 82 in ASCII | ||
private val ParticipantDefaultPort: Int = 6865 | ||
private val ProxyDefaultPort: Int = ParticipantDefaultPort | ||
|
||
val Default: Configuration = | ||
Configuration( | ||
participantAddress = new InetSocketAddress(LocalHost, ParticipantDefaultPort), | ||
proxyAddress = new InetSocketAddress(LoopbackAddress, ProxyDefaultPort), | ||
apiAddress = new InetSocketAddress(LoopbackAddress, ApiDefaultPort), | ||
apiShutdownTimeout = 10.seconds, | ||
databaseJdbcUrl = "jdbc:postgresql:/", | ||
databaseJdbcUsername = "nonrepudiation", | ||
databaseJdbcPassword = "nonrepudiation", | ||
databaseMaxPoolSize = 10, | ||
metricsReportingPeriod = 5.seconds, | ||
) | ||
|
||
} | ||
|
||
final case class Configuration private ( | ||
participantAddress: InetSocketAddress, | ||
proxyAddress: InetSocketAddress, | ||
apiAddress: InetSocketAddress, | ||
apiShutdownTimeout: FiniteDuration, | ||
databaseJdbcUrl: String, | ||
databaseJdbcUsername: String, | ||
databaseJdbcPassword: String, | ||
databaseMaxPoolSize: Int, | ||
metricsReportingPeriod: FiniteDuration, | ||
) |
89 changes: 89 additions & 0 deletions
89
...ts/non-repudiation-app/src/main/scala/com/daml/nonrepudiation/app/NonRepudiationApp.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.nonrepudiation.app | ||
|
||
import java.time.Clock | ||
|
||
import akka.actor.ActorSystem | ||
import com.daml.doobie.logging.Slf4jLogHandler | ||
import com.daml.ledger.api.v1.command_service.CommandServiceGrpc.CommandService | ||
import com.daml.ledger.api.v1.command_submission_service.CommandSubmissionServiceGrpc.CommandSubmissionService | ||
import com.daml.nonrepudiation.api.NonRepudiationApi | ||
import com.daml.nonrepudiation.postgresql.{Tables, createTransactor} | ||
import com.daml.nonrepudiation.{MetricsReporterOwner, NonRepudiationProxy} | ||
import com.daml.resources.akka.AkkaResourceOwnerFactories | ||
import com.daml.resources.{ | ||
AbstractResourceOwner, | ||
HasExecutionContext, | ||
ProgramResource, | ||
ResourceOwnerFactories, | ||
} | ||
import io.grpc.Server | ||
import io.grpc.netty.{NettyChannelBuilder, NettyServerBuilder} | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
object NonRepudiationApp { | ||
|
||
private[app] val Name = "non-repudiation-app" | ||
|
||
private val resourceFactory = new ResourceOwnerFactories[ExecutionContext] | ||
with AkkaResourceOwnerFactories[ExecutionContext] { | ||
override protected implicit val hasExecutionContext: HasExecutionContext[ExecutionContext] = | ||
HasExecutionContext.`ExecutionContext has itself` | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
|
||
val configuration: Configuration = | ||
OptionParser.parse(args, Configuration.Default).getOrElse(sys.exit(1)) | ||
|
||
val program = new ProgramResource(appOwner(configuration)) | ||
|
||
program.run(identity) | ||
|
||
} | ||
|
||
def appOwner( | ||
configuration: Configuration | ||
): AbstractResourceOwner[ExecutionContext, Server] = { | ||
|
||
val participantChannel = | ||
NettyChannelBuilder.forAddress(configuration.participantAddress).usePlaintext().build() | ||
|
||
val proxyChannelBuilder = | ||
NettyServerBuilder.forAddress(configuration.proxyAddress) | ||
|
||
for { | ||
actorSystem <- resourceFactory.forActorSystem(() => ActorSystem(Name)) | ||
transactor <- createTransactor( | ||
configuration.databaseJdbcUrl, | ||
configuration.databaseJdbcUsername, | ||
configuration.databaseJdbcPassword, | ||
configuration.databaseMaxPoolSize, | ||
resourceFactory, | ||
) | ||
logHandler = Slf4jLogHandler(getClass) | ||
db = Tables.initialize(transactor)(logHandler) | ||
_ <- MetricsReporterOwner.slf4j(period = configuration.metricsReportingPeriod) | ||
_ <- NonRepudiationApi.owner( | ||
configuration.apiAddress, | ||
configuration.apiShutdownTimeout, | ||
db.certificates, | ||
db.signedPayloads, | ||
actorSystem, | ||
) | ||
proxy <- NonRepudiationProxy.owner( | ||
participantChannel, | ||
proxyChannelBuilder, | ||
db.certificates, | ||
db.signedPayloads, | ||
Clock.systemUTC(), | ||
CommandService.scalaDescriptor.fullName, | ||
CommandSubmissionService.scalaDescriptor.fullName, | ||
) | ||
} yield proxy | ||
} | ||
|
||
} |
Oops, something went wrong.