mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 00:35:25 +03:00
[Self-service error codes] Adapt ResetService in Sandbox classic (#11731)
CHANGELOG_BEGIN CHANGELOG_END
This commit is contained in:
parent
eca53e9ede
commit
a05a40aeec
@ -501,6 +501,9 @@ The following gRPC status codes have changed for submission rejections in Sandbo
|
||||
|INVALID_ARGUMENT |NOT_FOUND |PARTY_NOT_KNOWN_ON_LEDGER is now returned on transaction rejections on unallocated parties. |PARTY_NOT_KNOWN_ON_LEDGER |
|
||||
+-----------------------------------+---------------------------------------+--------------------------------------------------------------------------------------------+----------------------------------------+
|
||||
|
||||
**NOTE**: Additionally, UNAVAILABLE is now returned when trying to reset the Sandbox server during an ongoing re-initialization (was FAILED_PRECONDITION).
|
||||
|
||||
|
||||
Daml Sandbox and VMBC
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -266,6 +266,12 @@ object LedgerApiErrors extends LedgerApiErrorGroup {
|
||||
) extends LoggingTransactionErrorImpl(
|
||||
cause = s"$serviceName has been shut down."
|
||||
)
|
||||
|
||||
case class ServiceReset(serviceName: String)(implicit
|
||||
loggingContext: ContextualizedErrorLogger
|
||||
) extends LoggingTransactionErrorImpl(
|
||||
cause = s"$serviceName is currently being reset."
|
||||
)
|
||||
}
|
||||
|
||||
object AuthorizationChecks extends ErrorGroup() {
|
||||
|
@ -511,6 +511,20 @@ class ErrorFactories private (errorCodesVersionSwitcher: ErrorCodesVersionSwitch
|
||||
v2 = LedgerApiErrors.ServiceNotRunning.Reject(serviceName).asGrpcError,
|
||||
)
|
||||
|
||||
def serviceIsBeingReset(legacyStatusCode: Int)(serviceName: String)(implicit
|
||||
contextualizedErrorLogger: ContextualizedErrorLogger
|
||||
): StatusRuntimeException =
|
||||
errorCodesVersionSwitcher.choose(
|
||||
v1 = {
|
||||
val statusBuilder = Status
|
||||
.newBuilder()
|
||||
.setCode(legacyStatusCode)
|
||||
.setMessage(s"$serviceName is currently being reset.")
|
||||
grpcError(statusBuilder.build())
|
||||
},
|
||||
v2 = LedgerApiErrors.ServiceNotRunning.ServiceReset(serviceName).asGrpcError,
|
||||
)
|
||||
|
||||
def trackerFailure(msg: String)(implicit
|
||||
contextualizedErrorLogger: ContextualizedErrorLogger
|
||||
): StatusRuntimeException =
|
||||
|
@ -547,6 +547,25 @@ class ErrorFactoriesSpec
|
||||
}
|
||||
}
|
||||
|
||||
"return a serviceIsBeingReset error" in {
|
||||
val serviceName = "Some API Service"
|
||||
val someLegacyStatusCode = Code.CANCELLED
|
||||
|
||||
assertVersionedError(_.serviceIsBeingReset(someLegacyStatusCode.value())(serviceName))(
|
||||
v1_code = someLegacyStatusCode,
|
||||
v1_message = s"$serviceName is currently being reset.",
|
||||
v1_details = Seq.empty,
|
||||
v2_code = Code.UNAVAILABLE,
|
||||
v2_message =
|
||||
s"SERVICE_NOT_RUNNING(1,$truncatedCorrelationId): $serviceName is currently being reset.",
|
||||
v2_details = Seq[ErrorDetails.ErrorDetail](
|
||||
ErrorDetails.ErrorInfoDetail("SERVICE_NOT_RUNNING"),
|
||||
expectedCorrelationIdRequestInfo,
|
||||
ErrorDetails.RetryInfoDetail(1),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
"return a missingField error" in {
|
||||
val testCases = Table(
|
||||
("definite answer", "expected details"),
|
||||
|
@ -63,3 +63,12 @@ SandboxClassicRejections.#invalidLedgerTime:
|
||||
SandboxClassic.CommandCompletionService:
|
||||
- CompletionStream
|
||||
|
||||
SandboxClassic.resetService:
|
||||
change:
|
||||
- FAILED_PRECONDITION
|
||||
- UNAVAILABLE
|
||||
changeExplanation: "UNAVAILABLE is now returned when trying to reset the Sandbox server during an ongoing re-initialization."
|
||||
selfServiceErrorCodeId: SERVICE_NOT_RUNNING
|
||||
services:
|
||||
SandboxClassic:
|
||||
- Reset
|
||||
|
@ -45,9 +45,8 @@ class SandboxResetService(
|
||||
serverCallHandler: ServerCallHandler[ReqT, RespT],
|
||||
): Listener[ReqT] = {
|
||||
if (resetInitialized.get) {
|
||||
throw new StatusRuntimeException(
|
||||
Status.UNAVAILABLE.withDescription("Sandbox server is currently being reset")
|
||||
)
|
||||
throw errorFactories
|
||||
.serviceIsBeingReset(Status.Code.UNAVAILABLE.value())("Sandbox server")
|
||||
}
|
||||
|
||||
serverCallHandler.startCall(serverCall, metadata)
|
||||
@ -71,10 +70,10 @@ class SandboxResetService(
|
||||
private def actuallyReset() = {
|
||||
logger.info("Initiating server reset.")
|
||||
|
||||
if (!resetInitialized.compareAndSet(false, true))
|
||||
throw new StatusRuntimeException(
|
||||
Status.FAILED_PRECONDITION.withDescription("Sandbox server is currently being reset")
|
||||
)
|
||||
if (!resetInitialized.compareAndSet(false, true)) {
|
||||
throw errorFactories
|
||||
.serviceIsBeingReset(Status.Code.FAILED_PRECONDITION.value())("Sandbox server")
|
||||
}
|
||||
|
||||
logger.info(s"Stopping and starting the server.")
|
||||
resetAndRestartServer()
|
||||
|
Loading…
Reference in New Issue
Block a user