Skip to content

Commit

Permalink
Update cross-media-measurement-api dep for DataProvider capabilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjayVas committed Mar 18, 2024
1 parent ad99520 commit 7c0a233
Show file tree
Hide file tree
Showing 13 changed files with 614 additions and 1,022 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ bazel_dep(
)
bazel_dep(
name = "cross-media-measurement-api",
version = "0.60.0",
version = "0.61.0",
repo_name = "wfa_measurement_proto",
)
bazel_dep(
Expand Down
890 changes: 13 additions & 877 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import org.wfanet.measurement.internal.kingdom.DataProvider
import org.wfanet.measurement.internal.kingdom.DataProvidersGrpcKt.DataProvidersCoroutineImplBase
import org.wfanet.measurement.internal.kingdom.GetDataProviderRequest
import org.wfanet.measurement.internal.kingdom.ReplaceDataAvailabilityIntervalRequest
import org.wfanet.measurement.internal.kingdom.ReplaceDataProviderCapabilitiesRequest
import org.wfanet.measurement.internal.kingdom.ReplaceDataProviderRequiredDuchiesRequest
import org.wfanet.measurement.internal.kingdom.batchGetDataProvidersResponse
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.common.DataProviderNotFoundException
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.common.KingdomInternalException
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.readers.DataProviderReader
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.writers.CreateDataProvider
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.writers.ReplaceDataAvailabilityInterval
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.writers.ReplaceDataProviderCapabilities
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.writers.ReplaceDataProviderRequiredDuchies

class SpannerDataProvidersService(
Expand Down Expand Up @@ -99,4 +101,16 @@ class SpannerDataProvidersService(
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "DataProvider not found.")
}
}

override suspend fun replaceDataProviderCapabilities(
request: ReplaceDataProviderCapabilitiesRequest
): DataProvider {
grpcRequire(request.externalDataProviderId != 0L) { "external_data_provider_id is missing." }

try {
return ReplaceDataProviderCapabilities(request).execute(client, idGenerator)
} catch (e: DataProviderNotFoundException) {
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "DataProvider not found.")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.kingdom.deploy.gcloud.spanner.writers

import org.wfanet.measurement.common.identity.ExternalId
import org.wfanet.measurement.gcloud.spanner.bufferUpdateMutation
import org.wfanet.measurement.gcloud.spanner.set
import org.wfanet.measurement.gcloud.spanner.setJson
import org.wfanet.measurement.internal.kingdom.DataProvider
import org.wfanet.measurement.internal.kingdom.ReplaceDataProviderCapabilitiesRequest
import org.wfanet.measurement.internal.kingdom.copy
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.common.DataProviderNotFoundException
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.readers.DataProviderReader

class ReplaceDataProviderCapabilities(private val request: ReplaceDataProviderCapabilitiesRequest) :
SpannerWriter<DataProvider, DataProvider>() {
override suspend fun TransactionScope.runTransaction(): DataProvider {
val externalDataProviderId = ExternalId(request.externalDataProviderId)
val dataProviderResult: DataProviderReader.Result =
DataProviderReader().readByExternalDataProviderId(transactionContext, externalDataProviderId)
?: throw DataProviderNotFoundException(externalDataProviderId)

val updatedDetails: DataProvider.Details =
dataProviderResult.dataProvider.details.copy { capabilities = request.capabilities }

transactionContext.bufferUpdateMutation("DataProviders") {
set("DataProviderId" to dataProviderResult.dataProviderId)
set("DataProviderDetails" to updatedDetails)
setJson("DataProviderDetailsJson" to updatedDetails)
}

return dataProviderResult.dataProvider.copy { details = updatedDetails }
}

override fun ResultScope<DataProvider>.buildResult(): DataProvider {
return checkNotNull(transactionResult)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,17 @@ kt_jvm_library(
"//src/main/kotlin/org/wfanet/measurement/api:public_api_version",
"//src/main/kotlin/org/wfanet/measurement/api/v2alpha:principal_server_interceptor",
"//src/main/kotlin/org/wfanet/measurement/api/v2alpha:resource_key",
"//src/main/kotlin/org/wfanet/measurement/kingdom/deploy/common:hmss_protocol_config",
"//src/main/kotlin/org/wfanet/measurement/kingdom/deploy/common:llv2_protocol_config",
"//src/main/kotlin/org/wfanet/measurement/kingdom/deploy/common:ro_llv2_protocol_config",
"//src/main/proto/wfa/measurement/api/v2alpha:crypto_kt_jvm_proto",
"//src/main/proto/wfa/measurement/api/v2alpha:differential_privacy_kt_jvm_proto",
"//src/main/proto/wfa/measurement/api/v2alpha:measurement_kt_jvm_proto",
"//src/main/proto/wfa/measurement/api/v2alpha:measurement_spec_kt_jvm_proto",
"//src/main/proto/wfa/measurement/api/v2alpha:measurements_service_kt_jvm_grpc_proto",
"//src/main/proto/wfa/measurement/api/v2alpha:page_token_kt_jvm_proto",
"//src/main/proto/wfa/measurement/api/v2alpha:protocol_config_kt_jvm_proto",
"//src/main/proto/wfa/measurement/internal/kingdom:data_providers_service_kt_jvm_grpc_proto",
"//src/main/proto/wfa/measurement/internal/kingdom:measurement_kt_jvm_proto",
"//src/main/proto/wfa/measurement/internal/kingdom:measurements_service_kt_jvm_grpc_proto",
"@wfa_common_jvm//imports/kotlin/kotlinx/coroutines:core",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.wfanet.measurement.api.Version
import org.wfanet.measurement.api.v2alpha.DataProvider
import org.wfanet.measurement.api.v2alpha.DataProviderCertificateKey
import org.wfanet.measurement.api.v2alpha.DataProviderKey
import org.wfanet.measurement.api.v2alpha.DataProviderKt
import org.wfanet.measurement.api.v2alpha.DataProviderPrincipal
import org.wfanet.measurement.api.v2alpha.DataProvidersGrpcKt.DataProvidersCoroutineImplBase as DataProvidersCoroutineService
import org.wfanet.measurement.api.v2alpha.DuchyKey
Expand All @@ -31,6 +32,7 @@ import org.wfanet.measurement.api.v2alpha.MeasurementConsumerPrincipal
import org.wfanet.measurement.api.v2alpha.MeasurementPrincipal
import org.wfanet.measurement.api.v2alpha.ModelProviderPrincipal
import org.wfanet.measurement.api.v2alpha.ReplaceDataAvailabilityIntervalRequest
import org.wfanet.measurement.api.v2alpha.ReplaceDataProviderCapabilitiesRequest
import org.wfanet.measurement.api.v2alpha.ReplaceDataProviderRequiredDuchiesRequest
import org.wfanet.measurement.api.v2alpha.dataProvider
import org.wfanet.measurement.api.v2alpha.principalFromCurrentContext
Expand All @@ -40,12 +42,15 @@ import org.wfanet.measurement.common.ProtoReflection
import org.wfanet.measurement.common.grpc.failGrpc
import org.wfanet.measurement.common.grpc.grpcRequire
import org.wfanet.measurement.common.grpc.grpcRequireNotNull
import org.wfanet.measurement.common.identity.ApiId
import org.wfanet.measurement.common.identity.apiIdToExternalId
import org.wfanet.measurement.common.identity.externalIdToApiId
import org.wfanet.measurement.internal.kingdom.DataProvider as InternalDataProvider
import org.wfanet.measurement.internal.kingdom.DataProviderKt as InternalDataProviderKt
import org.wfanet.measurement.internal.kingdom.DataProvidersGrpcKt.DataProvidersCoroutineStub
import org.wfanet.measurement.internal.kingdom.getDataProviderRequest
import org.wfanet.measurement.internal.kingdom.replaceDataAvailabilityIntervalRequest
import org.wfanet.measurement.internal.kingdom.replaceDataProviderCapabilitiesRequest
import org.wfanet.measurement.internal.kingdom.replaceDataProviderRequiredDuchiesRequest

class DataProvidersService(private val internalClient: DataProvidersCoroutineStub) :
Expand Down Expand Up @@ -177,6 +182,42 @@ class DataProvidersService(private val internalClient: DataProvidersCoroutineStu
}
return internalDataProvider.toDataProvider()
}

override suspend fun replaceDataProviderCapabilities(
request: ReplaceDataProviderCapabilitiesRequest
): DataProvider {
val key: DataProviderKey =
grpcRequireNotNull(DataProviderKey.fromName(request.name)) {
"Resource name unspecified or invalid"
}

val principal: MeasurementPrincipal = principalFromCurrentContext
if (principal.resourceKey != key) {
failGrpc(Status.PERMISSION_DENIED) {
"Permission for method replaceDataProviderCapabilities denied on resource $request.name"
}
}

val response: InternalDataProvider =
try {
internalClient.replaceDataProviderCapabilities(
replaceDataProviderCapabilitiesRequest {
externalDataProviderId = ApiId(key.dataProviderId).externalId.value
capabilities = request.capabilities.toInternal()
}
)
} catch (e: StatusException) {
throw when (e.status.code) {
Status.Code.DEADLINE_EXCEEDED -> Status.DEADLINE_EXCEEDED
Status.Code.CANCELLED -> Status.CANCELLED
Status.Code.NOT_FOUND -> Status.NOT_FOUND.withDescription("DataProvider not found")
else -> Status.UNKNOWN
}
.withCause(e)
.asRuntimeException()
}
return response.toDataProvider()
}
}

private fun InternalDataProvider.toDataProvider(): DataProvider {
Expand Down Expand Up @@ -204,5 +245,20 @@ private fun InternalDataProvider.toDataProvider(): DataProvider {
}
requiredDuchies += source.requiredExternalDuchyIdsList.map { DuchyKey(it).toName() }
dataAvailabilityInterval = source.details.dataAvailabilityInterval
capabilities = source.details.capabilities.toCapabilities()
}
}

private fun InternalDataProvider.Capabilities.toCapabilities(): DataProvider.Capabilities {
val source = this
return DataProviderKt.capabilities {
honestMajorityShareShuffleSupported = source.honestMajorityShareShuffleSupported
}
}

private fun DataProvider.Capabilities.toInternal(): InternalDataProvider.Capabilities {
val source = this
return InternalDataProviderKt.capabilities {
honestMajorityShareShuffleSupported = source.honestMajorityShareShuffleSupported
}
}
Loading

0 comments on commit 7c0a233

Please sign in to comment.