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

[DPP-619][Self-service error codes] Adopt error codes in ApiLedgerIdentityService #11303

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private[daml] object ApiServices {
ApiTransactionService.create(ledgerId, transactionsService, metrics, errorsVersionsSwitcher)

val apiLedgerIdentityService =
ApiLedgerIdentityService.create(() => identityService.getLedgerId())
ApiLedgerIdentityService.create(() => identityService.getLedgerId(), errorsVersionsSwitcher)

val apiVersionService =
ApiVersionService.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

package com.daml.platform.apiserver.services

import com.daml.error.{DamlContextualizedErrorLogger, ContextualizedErrorLogger}
import com.daml.error.{
ContextualizedErrorLogger,
DamlContextualizedErrorLogger,
ErrorCodesVersionSwitcher,
}
import com.daml.ledger.api.domain.LedgerId
import com.daml.ledger.api.v1.ledger_identity_service.LedgerIdentityServiceGrpc.{
LedgerIdentityService => GrpcLedgerIdentityService
Expand All @@ -22,22 +26,25 @@ import scalaz.syntax.tag._
import scala.concurrent.{ExecutionContext, Future}

private[apiserver] final class ApiLedgerIdentityService private (
getLedgerId: () => Future[LedgerId]
getLedgerId: () => Future[LedgerId],
errorCodesVersionSwitcher: ErrorCodesVersionSwitcher,
)(implicit executionContext: ExecutionContext, loggingContext: LoggingContext)
extends GrpcLedgerIdentityService
with GrpcApiService {
private val logger = ContextualizedLogger.get(this.getClass)
private implicit val contextualizedErrorLogger: ContextualizedErrorLogger =
new DamlContextualizedErrorLogger(logger, loggingContext, None)

private val errorFactories = ErrorFactories(errorCodesVersionSwitcher)

@volatile var closed = false

override def getLedgerIdentity(
request: GetLedgerIdentityRequest
): Future[GetLedgerIdentityResponse] = {
logger.info(s"Received request for ledger identity: $request")
if (closed)
Future.failed(ErrorFactories.serviceNotRunning(None))
Future.failed(errorFactories.serviceNotRunning(None))
else
getLedgerId()
.map(ledgerId => GetLedgerIdentityResponse(ledgerId.unwrap))
Expand All @@ -52,11 +59,12 @@ private[apiserver] final class ApiLedgerIdentityService private (

private[apiserver] object ApiLedgerIdentityService {
def create(
getLedgerId: () => Future[LedgerId]
getLedgerId: () => Future[LedgerId],
errorCodesVersionSwitcher: ErrorCodesVersionSwitcher,
)(implicit
executionContext: ExecutionContext,
loggingContext: LoggingContext,
): ApiLedgerIdentityService with BindableService = {
new ApiLedgerIdentityService(getLedgerId)
new ApiLedgerIdentityService(getLedgerId, errorCodesVersionSwitcher)
}
}