-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add in process postgres duchy correctness tests (#1152)
This adds in process postgres duchy correctness tests
- Loading branch information
1 parent
53e0bdc
commit 178834b
Showing
25 changed files
with
667 additions
and
164 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
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres/tools/BUILD.bazel
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,20 @@ | ||
load("@rules_java//java:defs.bzl", "java_binary") | ||
load("//src/main/docker:macros.bzl", "java_image") | ||
|
||
java_binary( | ||
name = "UpdateSchema", | ||
args = ["--changelog=duchy/postgres/changelog.yaml"], | ||
main_class = "org.wfanet.measurement.common.db.postgres.tools.UpdateSchema", | ||
resources = ["//src/main/resources/duchy/postgres"], | ||
runtime_deps = [ | ||
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/postgres/tools:update_schema", | ||
], | ||
) | ||
|
||
java_image( | ||
name = "update_schema_image", | ||
args = ["--changelog=duchy/postgres/changelog.yaml"], | ||
binary = ":UpdateSchema", | ||
main_class = "org.wfanet.measurement.common.db.postgres.tools.UpdateSchema", | ||
visibility = ["//src:docker_image_deployment"], | ||
) |
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
81 changes: 81 additions & 0 deletions
81
src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/server/DuchyDataServer.kt
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,81 @@ | ||
// Copyright 2023 The Cross-Media Measurement Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.wfanet.measurement.duchy.deploy.common.server | ||
|
||
import io.grpc.ManagedChannel | ||
import java.time.Duration | ||
import kotlinx.coroutines.runInterruptible | ||
import org.wfanet.measurement.common.crypto.SigningCerts | ||
import org.wfanet.measurement.common.grpc.CommonServer | ||
import org.wfanet.measurement.common.grpc.buildMutualTlsChannel | ||
import org.wfanet.measurement.common.grpc.withShutdownTimeout | ||
import org.wfanet.measurement.common.identity.DuchyInfoFlags | ||
import org.wfanet.measurement.common.identity.withDuchyId | ||
import org.wfanet.measurement.duchy.deploy.common.CommonDuchyFlags | ||
import org.wfanet.measurement.duchy.deploy.common.SystemApiFlags | ||
import org.wfanet.measurement.duchy.deploy.common.service.DuchyDataServices | ||
import org.wfanet.measurement.duchy.deploy.common.service.toList | ||
import org.wfanet.measurement.system.v1alpha.ComputationLogEntriesGrpcKt.ComputationLogEntriesCoroutineStub | ||
import picocli.CommandLine | ||
|
||
abstract class DuchyDataServer : Runnable { | ||
@CommandLine.Mixin | ||
lateinit var serverFlags: CommonServer.Flags | ||
private set | ||
|
||
@CommandLine.Mixin | ||
lateinit var duchyFlags: CommonDuchyFlags | ||
private set | ||
|
||
@CommandLine.Mixin | ||
lateinit var duchyInfoFlags: DuchyInfoFlags | ||
private set | ||
|
||
@CommandLine.Option( | ||
names = ["--channel-shutdown-timeout"], | ||
defaultValue = "3s", | ||
description = ["How long to allow for the gRPC channel to shutdown."], | ||
required = true | ||
) | ||
lateinit var channelShutdownTimeout: Duration | ||
private set | ||
|
||
@CommandLine.Mixin | ||
lateinit var systemApiFlags: SystemApiFlags | ||
private set | ||
|
||
val clientCerts = | ||
SigningCerts.fromPemFiles( | ||
certificateFile = serverFlags.tlsFlags.certFile, | ||
privateKeyFile = serverFlags.tlsFlags.privateKeyFile, | ||
trustedCertCollectionFile = serverFlags.tlsFlags.certCollectionFile | ||
) | ||
val channel: ManagedChannel = | ||
buildMutualTlsChannel(systemApiFlags.target, clientCerts, systemApiFlags.certHost) | ||
.withShutdownTimeout(channelShutdownTimeout) | ||
|
||
val computationLogEntriesClient = | ||
ComputationLogEntriesCoroutineStub(channel).withDuchyId(duchyFlags.duchyName) | ||
|
||
protected suspend fun run(services: DuchyDataServices) { | ||
val server = CommonServer.fromFlags(serverFlags, this::class.simpleName!!, services.toList()) | ||
|
||
runInterruptible { server.start().blockUntilShutdown() } | ||
} | ||
|
||
companion object { | ||
const val SERVICE_NAME = "Computations" | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/service/BUILD.bazel
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,32 @@ | ||
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") | ||
|
||
kt_jvm_library( | ||
name = "duchy_data_services", | ||
srcs = ["DuchyDataServices.kt"], | ||
visibility = [ | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/server:__pkg__", | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/deploy/gcloud/service:__pkg__", | ||
"//src/test/kotlin/org/wfanet/measurement/integration/common/duchy:__pkg__", | ||
], | ||
deps = [ | ||
"//src/main/proto/wfa/measurement/internal/duchy:computation_stats_service_kt_jvm_grpc_proto", | ||
"//src/main/proto/wfa/measurement/internal/duchy:computations_service_kt_jvm_grpc_proto", | ||
"//src/main/proto/wfa/measurement/internal/duchy:continuation_tokens_service_kt_jvm_grpc_proto", | ||
], | ||
) | ||
|
||
kt_jvm_library( | ||
name = "postgres_duchy_data_services", | ||
srcs = ["PostgresDuchyDataServices.kt"], | ||
visibility = [ | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/deploy/gcloud/server:__pkg__", | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/deploy/postgres/server:__pkg__", | ||
"//src/test/kotlin/org/wfanet/measurement/integration/common/duchy:__pkg__", | ||
], | ||
deps = [ | ||
":duchy_data_services", | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/postgres:services", | ||
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc", | ||
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/identity", | ||
], | ||
) |
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/service/DuchyDataServices.kt
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,31 @@ | ||
// Copyright 2023 The Cross-Media Measurement Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.wfanet.measurement.duchy.deploy.common.service | ||
|
||
import io.grpc.BindableService | ||
import kotlin.reflect.full.declaredMemberProperties | ||
import org.wfanet.measurement.internal.duchy.ComputationStatsGrpcKt.ComputationStatsCoroutineImplBase | ||
import org.wfanet.measurement.internal.duchy.ComputationsGrpcKt.ComputationsCoroutineImplBase | ||
import org.wfanet.measurement.internal.duchy.ContinuationTokensGrpcKt.ContinuationTokensCoroutineImplBase | ||
|
||
data class DuchyDataServices( | ||
val computationsService: ComputationsCoroutineImplBase, | ||
val computationStatsService: ComputationStatsCoroutineImplBase, | ||
val continuationTokensService: ContinuationTokensCoroutineImplBase | ||
) | ||
|
||
fun DuchyDataServices.toList(): List<BindableService> { | ||
return DuchyDataServices::class.declaredMemberProperties.map { it.get(this) as BindableService } | ||
} |
74 changes: 74 additions & 0 deletions
74
...in/kotlin/org/wfanet/measurement/duchy/deploy/common/service/PostgresDuchyDataServices.kt
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,74 @@ | ||
// Copyright 2023 The Cross-Media Measurement Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package org.wfanet.measurement.duchy.deploy.common.service | ||
|
||
import java.time.Clock | ||
import org.wfanet.measurement.common.db.r2dbc.DatabaseClient | ||
import org.wfanet.measurement.common.identity.IdGenerator | ||
import org.wfanet.measurement.duchy.db.computation.ComputationProtocolStageDetails | ||
import org.wfanet.measurement.duchy.db.computation.ComputationProtocolStageDetailsHelper | ||
import org.wfanet.measurement.duchy.db.computation.ComputationProtocolStages | ||
import org.wfanet.measurement.duchy.db.computation.ComputationProtocolStagesEnumHelper | ||
import org.wfanet.measurement.duchy.db.computation.ComputationTypeEnumHelper | ||
import org.wfanet.measurement.duchy.db.computation.ComputationTypes | ||
import org.wfanet.measurement.duchy.deploy.common.postgres.PostgresComputationStatsService | ||
import org.wfanet.measurement.duchy.deploy.common.postgres.PostgresComputationsService | ||
import org.wfanet.measurement.duchy.deploy.common.postgres.PostgresContinuationTokensService | ||
import org.wfanet.measurement.duchy.storage.ComputationStore | ||
import org.wfanet.measurement.duchy.storage.RequisitionStore | ||
import org.wfanet.measurement.internal.duchy.ComputationDetails | ||
import org.wfanet.measurement.internal.duchy.ComputationStage | ||
import org.wfanet.measurement.internal.duchy.ComputationStageDetails | ||
import org.wfanet.measurement.internal.duchy.ComputationTypeEnum.ComputationType | ||
import org.wfanet.measurement.storage.StorageClient | ||
import org.wfanet.measurement.system.v1alpha.ComputationLogEntriesGrpcKt.ComputationLogEntriesCoroutineStub | ||
|
||
object PostgresDuchyDataServices { | ||
@JvmStatic | ||
fun create( | ||
storageClient: StorageClient, | ||
computationLogEntriesClient: ComputationLogEntriesCoroutineStub, | ||
duchyName: String, | ||
idGenerator: IdGenerator, | ||
client: DatabaseClient | ||
): DuchyDataServices { | ||
val computationTypeEnumHelper: ComputationTypeEnumHelper<ComputationType> = ComputationTypes | ||
val protocolStagesEnumHelper: | ||
ComputationProtocolStagesEnumHelper<ComputationType, ComputationStage> = | ||
ComputationProtocolStages | ||
val computationProtocolStageDetailsHelper: | ||
ComputationProtocolStageDetailsHelper< | ||
ComputationType, ComputationStage, ComputationStageDetails, ComputationDetails | ||
> = | ||
ComputationProtocolStageDetails | ||
|
||
return DuchyDataServices( | ||
PostgresComputationsService( | ||
computationTypeEnumHelper = computationTypeEnumHelper, | ||
protocolStagesEnumHelper = protocolStagesEnumHelper, | ||
computationProtocolStageDetailsHelper = computationProtocolStageDetailsHelper, | ||
computationStore = ComputationStore(storageClient), | ||
requisitionStore = RequisitionStore(storageClient), | ||
computationLogEntriesClient = computationLogEntriesClient, | ||
duchyName = duchyName, | ||
clock = Clock.systemUTC(), | ||
client = client, | ||
idGenerator = idGenerator, | ||
), | ||
PostgresComputationStatsService(client, idGenerator), | ||
PostgresContinuationTokensService(client, idGenerator) | ||
) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/org/wfanet/measurement/duchy/deploy/gcloud/service/BUILD.bazel
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,18 @@ | ||
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") | ||
|
||
kt_jvm_library( | ||
name = "spanner_duchy_data_services", | ||
srcs = ["SpannerDuchyDataServices.kt"], | ||
visibility = [ | ||
"//src/test/kotlin/org/wfanet/measurement/integration/common/duchy:__pkg__", | ||
], | ||
deps = [ | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/db/computation", | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/deploy/common/service:duchy_data_services", | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/deploy/gcloud/spanner/computation", | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/deploy/gcloud/spanner/continuationtoken:service", | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/service/internal/computations", | ||
"//src/main/kotlin/org/wfanet/measurement/duchy/service/internal/computationstats:service", | ||
"@wfa_common_jvm//src/main/kotlin/org/wfanet/measurement/common/db/r2dbc", | ||
], | ||
) |
Oops, something went wrong.