-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert Key to ResourceName in v2 services (#111)
* Convert Key to ResourceName in v2 services * added ProtocolConfigKey for HeraldTest * fix lint * using failgrpc methods * exception when neither DataProvider nor ModelProvider provided * fix error message * fix error message in test * dropping v2 in variable name * lint fix * fix HeraldTest dependency * making resource keys public for all repos * make exchangestepattemptid equal to attempt number * make exchangestepid equal to step index
- Loading branch information
Showing
23 changed files
with
549 additions
and
144 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
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/org/wfanet/measurement/duchy/service/api/v2alpha/IdVariable.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 2021 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.service.api.v2alpha | ||
|
||
import org.wfanet.measurement.common.ResourceNameParser | ||
|
||
internal enum class IdVariable() { | ||
DATA_PROVIDER, | ||
REQUISITION, | ||
PROTOCOL_CONFIG | ||
} | ||
|
||
internal fun ResourceNameParser.assembleName(idMap: Map<IdVariable, String>): String { | ||
return assembleName(idMap.mapKeys { it.key.name.toLowerCase() }) | ||
} | ||
|
||
internal fun ResourceNameParser.parseIdVars(resourceName: String): Map<IdVariable, String>? { | ||
return parseIdSegments(resourceName)?.mapKeys { IdVariable.valueOf(it.key.toUpperCase()) } | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/org/wfanet/measurement/duchy/service/api/v2alpha/ProtocolConfigKey.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,36 @@ | ||
// Copyright 2021 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.service.api.v2alpha | ||
|
||
import org.wfanet.measurement.common.ResourceNameParser | ||
|
||
private val parser = ResourceNameParser("protocolConfigs/{protocol_config}") | ||
|
||
/** [ResourceKey] of a ProtocolConfig. */ | ||
data class ProtocolConfigKey(val protocolConfigId: String) : ResourceKey { | ||
override fun toName(): String { | ||
return parser.assembleName(mapOf(IdVariable.PROTOCOL_CONFIG to protocolConfigId)) | ||
} | ||
|
||
companion object { | ||
val defaultValue = ProtocolConfigKey("") | ||
|
||
fun fromName(resourceName: String): ProtocolConfigKey? { | ||
return parser.parseIdVars(resourceName)?.let { | ||
ProtocolConfigKey(it.getValue(IdVariable.PROTOCOL_CONFIG)) | ||
} | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/org/wfanet/measurement/duchy/service/api/v2alpha/RequisitionKey.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,38 @@ | ||
// Copyright 2021 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.service.api.v2alpha | ||
|
||
import org.wfanet.measurement.common.ResourceNameParser | ||
|
||
private val parser = ResourceNameParser("dataProviders/{data_provider}/requisitions/{requisition}") | ||
|
||
/** [ResourceKey] of a Requisition. */ | ||
data class RequisitionKey(val dataProviderId: String, val requisitionId: String) : ResourceKey { | ||
override fun toName(): String { | ||
return parser.assembleName( | ||
mapOf(IdVariable.DATA_PROVIDER to dataProviderId, IdVariable.REQUISITION to requisitionId) | ||
) | ||
} | ||
|
||
companion object { | ||
val defaultValue = RequisitionKey("", "") | ||
|
||
fun fromName(resourceName: String): RequisitionKey? { | ||
return parser.parseIdVars(resourceName)?.let { | ||
RequisitionKey(it.getValue(IdVariable.DATA_PROVIDER), it.getValue(IdVariable.REQUISITION)) | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/org/wfanet/measurement/duchy/service/api/v2alpha/ResourceKey.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,20 @@ | ||
// Copyright 2021 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.service.api.v2alpha | ||
|
||
interface ResourceKey { | ||
/** Converts this [ResourceKey] into a resource name. */ | ||
fun toName(): String | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/org/wfanet/measurement/kingdom/service/api/v2alpha/DataProviderKey.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,36 @@ | ||
// Copyright 2021 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.service.api.v2alpha | ||
|
||
import org.wfanet.measurement.common.ResourceNameParser | ||
|
||
private val parser = ResourceNameParser("dataProviders/{data_provider}") | ||
|
||
/** [DataProviderKey] of a Data Provider. */ | ||
data class DataProviderKey(val dataProviderId: String) : ResourceKey { | ||
override fun toName(): String { | ||
return parser.assembleName(mapOf(IdVariable.DATA_PROVIDER to dataProviderId)) | ||
} | ||
|
||
companion object { | ||
val defaultValue = DataProviderKey("") | ||
|
||
fun fromName(resourceName: String): DataProviderKey? { | ||
return parser.parseIdVars(resourceName)?.let { | ||
DataProviderKey(it.getValue(IdVariable.DATA_PROVIDER)) | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/org/wfanet/measurement/kingdom/service/api/v2alpha/ExchangeKey.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,39 @@ | ||
// Copyright 2021 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.service.api.v2alpha | ||
|
||
import org.wfanet.measurement.common.ResourceNameParser | ||
|
||
private val parser = | ||
ResourceNameParser("recurringExchanges/{recurring_exchange}/exchanges/{exchange}") | ||
|
||
/** [ExchangeKey] of an Exchange. */ | ||
data class ExchangeKey(val recurringExchangeId: String, val exchangeId: String) : ResourceKey { | ||
override fun toName(): String { | ||
return parser.assembleName( | ||
mapOf(IdVariable.RECURRING_EXCHANGE to recurringExchangeId, IdVariable.EXCHANGE to exchangeId) | ||
) | ||
} | ||
|
||
companion object { | ||
val defaultValue = ExchangeKey("", "") | ||
|
||
fun fromName(resourceName: String): ExchangeKey? { | ||
return parser.parseIdVars(resourceName)?.let { | ||
ExchangeKey(it.getValue(IdVariable.RECURRING_EXCHANGE), it.getValue(IdVariable.EXCHANGE)) | ||
} | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/org/wfanet/measurement/kingdom/service/api/v2alpha/ExchangeStepAttemptKey.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,57 @@ | ||
// Copyright 2021 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.service.api.v2alpha | ||
|
||
import org.wfanet.measurement.common.ResourceNameParser | ||
|
||
private val parser = | ||
ResourceNameParser( | ||
"recurringExchanges/{recurring_exchange}/exchanges/{exchange}/steps/{exchange_step}/" + | ||
"attempts/{exchange_step_attempt}" | ||
) | ||
|
||
/** [ExchangeStepAttemptKey] of an Exchange Step Attempt. */ | ||
data class ExchangeStepAttemptKey( | ||
val recurringExchangeId: String, | ||
val exchangeId: String, | ||
val exchangeStepId: String, | ||
val exchangeStepAttemptId: String | ||
) : ResourceKey { | ||
override fun toName(): String { | ||
return parser.assembleName( | ||
mapOf( | ||
IdVariable.RECURRING_EXCHANGE to recurringExchangeId, | ||
IdVariable.EXCHANGE to exchangeId, | ||
IdVariable.EXCHANGE_STEP to exchangeStepId, | ||
IdVariable.EXCHANGE_STEP_ATTEMPT to exchangeStepAttemptId | ||
) | ||
) | ||
} | ||
|
||
companion object { | ||
val defaultValue = ExchangeStepAttemptKey("", "", "", "") | ||
|
||
fun fromName(resourceName: String): ExchangeStepAttemptKey? { | ||
return parser.parseIdVars(resourceName)?.let { | ||
ExchangeStepAttemptKey( | ||
it.getValue(IdVariable.RECURRING_EXCHANGE), | ||
it.getValue(IdVariable.EXCHANGE), | ||
it.getValue(IdVariable.EXCHANGE_STEP), | ||
it.getValue(IdVariable.EXCHANGE_STEP_ATTEMPT) | ||
) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.