-
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.
kvutils - Add Writer which can handle deduplication periods as offset…
…s [KVL-1172] (#11900) changelog_begin changelog_end
- Loading branch information
Showing
23 changed files
with
932 additions
and
121 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
47 changes: 47 additions & 0 deletions
47
.../scala/com/digitalasset/platform/server/api/validation/DeduplicationPeriodValidator.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,47 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.platform.server.api.validation | ||
|
||
import java.time.Duration | ||
|
||
import com.daml.error.ContextualizedErrorLogger | ||
import com.daml.ledger.api.DeduplicationPeriod | ||
import io.grpc.StatusRuntimeException | ||
|
||
class DeduplicationPeriodValidator( | ||
errorFactories: ErrorFactories | ||
) { | ||
private val fieldName = "deduplication_period" | ||
|
||
def validate( | ||
deduplicationPeriod: DeduplicationPeriod, | ||
maxDeduplicationDuration: Duration, | ||
)(implicit | ||
contextualizedErrorLogger: ContextualizedErrorLogger | ||
): Either[StatusRuntimeException, DeduplicationPeriod] = { | ||
deduplicationPeriod match { | ||
case DeduplicationPeriod.DeduplicationDuration(duration) => | ||
validateDuration(duration, maxDeduplicationDuration).map(_ => deduplicationPeriod) | ||
case DeduplicationPeriod.DeduplicationOffset(_) => Right(deduplicationPeriod) | ||
} | ||
} | ||
|
||
def validateDuration(duration: Duration, maxDeduplicationDuration: Duration)(implicit | ||
contextualizedErrorLogger: ContextualizedErrorLogger | ||
): Either[StatusRuntimeException, Duration] = if (duration.isNegative) | ||
Left( | ||
errorFactories | ||
.invalidField(fieldName, "Duration must be positive", definiteAnswer = Some(false)) | ||
) | ||
else if (duration.compareTo(maxDeduplicationDuration) > 0) | ||
Left( | ||
errorFactories.invalidDeduplicationDuration( | ||
fieldName, | ||
s"The given deduplication duration of $duration exceeds the maximum deduplication time of $maxDeduplicationDuration", | ||
definiteAnswer = Some(false), | ||
Some(maxDeduplicationDuration), | ||
) | ||
) | ||
else Right(duration) | ||
} |
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
Oops, something went wrong.