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 Feb 16, 2024
1 parent 321b373 commit 266d3e7
Show file tree
Hide file tree
Showing 19 changed files with 497 additions and 200 deletions.
10 changes: 9 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ bazel_dep(
)
bazel_dep(
name = "cross-media-measurement-api",
version = "0.58.0",
repo_name = "wfa_measurement_proto",
)
bazel_dep(
Expand Down Expand Up @@ -306,3 +305,12 @@ single_version_override(
module_name = "boringssl",
version = BORINGSSL_VERSION,
)

# TODO(world-federation-of-advertisers/cross-media-measurement-api#199): Use version.
archive_override(
module_name = "cross-media-measurement-api",
strip_prefix = "cross-media-measurement-api-8a1e491350d89333343dcca9f534cc68fbaf9736",
urls = [
"https://github.com/world-federation-of-advertisers/cross-media-measurement-api/archive/8a1e491350d89333343dcca9f534cc68fbaf9736.tar.gz",
],
)
68 changes: 26 additions & 42 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,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.kingdom.deploy.gcloud.spanner.common.DataProviderNotFoundException
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

// TODO(@marcopremier): Add method to update data provider required duchies list.
class SpannerDataProvidersService(
private val idGenerator: IdGenerator,
private val client: AsyncDatabaseClient,
Expand Down Expand Up @@ -76,4 +77,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
Expand Up @@ -42,6 +42,7 @@ import org.wfanet.measurement.internal.kingdom.batchCreateMeasurementsResponse
import org.wfanet.measurement.internal.kingdom.batchGetMeasurementsResponse
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.common.CertificateIsInvalidException
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.common.CertificateNotFoundException
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.common.DataProviderNotCapableException
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.common.DataProviderNotFoundException
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.common.DuchyCertificateNotFoundException
import org.wfanet.measurement.kingdom.deploy.gcloud.spanner.common.DuchyNotActiveException
Expand Down Expand Up @@ -77,6 +78,8 @@ class SpannerMeasurementsService(
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "MeasurementConsumer not found.")
} catch (e: DataProviderNotFoundException) {
throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "DataProvider not found.")
} catch (e: DataProviderNotCapableException) {
throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION)
} catch (e: DuchyNotFoundException) {
throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.")
} catch (e: CertificateNotFoundException) {
Expand Down Expand Up @@ -259,6 +262,8 @@ class SpannerMeasurementsService(
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "MeasurementConsumer not found.")
} catch (e: DataProviderNotFoundException) {
throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "DataProvider not found.")
} catch (e: DataProviderNotCapableException) {
throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION)
} catch (e: DuchyNotFoundException) {
throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.")
} catch (e: CertificateNotFoundException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,11 @@ class PopulationNotFoundException(
"external_population_id" to externalPopulationId.toString(),
)
}

class DataProviderNotCapableException(
val externalDataProviderId: ExternalId,
message: String = "DataProvider not capable",
) : KingdomInternalException(ErrorCode.DATA_PROVIDER_NOT_CAPABLE, message) {
override val context
get() = mapOf("external_data_provider_id" to externalDataProviderId.value.toString())
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.wfanet.measurement.internal.kingdom.DataProvider
import org.wfanet.measurement.kingdom.deploy.common.DuchyIds

class DataProviderReader : SpannerReader<DataProviderReader.Result>() {
data class Result(val dataProvider: DataProvider, val dataProviderId: Long)
data class Result(val dataProvider: DataProvider, val dataProviderId: InternalId)

override val baseSql: String =
"""
Expand Down Expand Up @@ -59,7 +59,7 @@ class DataProviderReader : SpannerReader<DataProviderReader.Result>() {
.trimIndent()

override suspend fun translate(struct: Struct): Result =
Result(buildDataProvider(struct), struct.getLong("DataProviderId"))
Result(buildDataProvider(struct), struct.getInternalId("DataProviderId"))

suspend fun readByExternalDataProviderId(
readContext: AsyncDatabaseClient.ReadContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MeasurementReader(private val view: Measurement.View) :
listOf(column),
)
?.getProtoEnum(column, Measurement.State::forNumber)
?: throw MeasurementNotFoundException() { "Measurement not found $measurementId" }
?: throw MeasurementNotFoundException { "Measurement not found $measurementId" }
}

/**
Expand Down Expand Up @@ -207,7 +207,7 @@ class MeasurementReader(private val view: Measurement.View) :
val column = "UpdateTime"
val updateTime =
readContext.readRow("Measurements", measurementKey, listOf(column))?.getTimestamp(column)
?: throw MeasurementNotFoundException() { "Measurement not found for $measurementKey" }
?: throw MeasurementNotFoundException { "Measurement not found for $measurementKey" }
return getEtag(updateTime)
}

Expand Down
Loading

0 comments on commit 266d3e7

Please sign in to comment.