Skip to content

Commit 9a2f930

Browse files
committed
multiple DATASETID values workflow code & tests
1 parent b2e43ae commit 9a2f930

File tree

8 files changed

+182
-77
lines changed

8 files changed

+182
-77
lines changed

doc/Models/RunTemplateParameter.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Name | Type | Description | Notes
1111
**maxValue** | **String** | the maximum value for this parameter | [optional] [default to null]
1212
**regexValidation** | **String** | a regex to validate the value | [optional] [default to null]
1313
**options** | **Map** | freeform options | [optional] [default to null]
14-
**isArray** | **Boolean** | whether or not the parameter contains an array of values | [optional] [default to null]
1514

1615
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1716

doc/Models/ScenarioRunTemplateParameterValue.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
66
**parameterId** | **String** | the parameter Id | [default to null]
77
**varType** | **String** | the parameter value type | [optional] [default to null]
8-
**isArray** | **Boolean** | whether or not the parameter contains an array of values | [optional] [default to null]
98
**value** | **String** | the parameter value | [default to null]
109
**isInherited** | **Boolean** | whether or not the value is inherited from parent or has been changed | [optional] [default to null]
1110

openapi/plantuml/schemas.plantuml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ entity RunTemplateParameter {
136136
maxValue: String
137137
regexValidation: String
138138
options: Map
139-
isArray: Boolean
140139
}
141140

142141
entity RunTemplateParameterGroup {
@@ -315,7 +314,6 @@ entity ScenarioRunStatusNode {
315314
entity ScenarioRunTemplateParameterValue {
316315
* parameterId: String
317316
varType: String
318-
isArray: Boolean
319317
* value: String
320318
isInherited: Boolean
321319
}

scenario/src/main/openapi/scenarios.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,6 @@ components:
648648
type: string
649649
readOnly: true
650650
description: the parameter value type
651-
isArray:
652-
type: boolean
653-
readOnly: true
654-
description: whether or not the parameter contains an array of values
655651
value:
656652
type: string
657653
description: the parameter value

scenariorun/src/main/kotlin/com/cosmotech/scenariorun/ContainerFactory.kt

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.cosmotech.scenariorun.container.StartInfo
2121
import com.cosmotech.scenariorun.dataset.PARAMETERS_DATASET_ID
2222
import com.cosmotech.scenariorun.dataset.findDatasetsAndConnectors
2323
import com.cosmotech.scenariorun.dataset.getDatasetEnvVars
24+
import com.cosmotech.scenariorun.dataset.getDatasetIdListFromValue
2425
import com.cosmotech.scenariorun.domain.ScenarioRunContainer
2526
import com.cosmotech.scenariorun.domain.ScenarioRunContainerArtifact
2627
import com.cosmotech.scenariorun.domain.ScenarioRunStartContainers
@@ -750,27 +751,32 @@ internal class ContainerFactory(
750751
?: throw IllegalStateException(
751752
"Parameter ${parameterValue.parameterId} not found in Solution ${solution.id}")
752753
if (parameter.varType == PARAMETERS_DATASET_ID) {
753-
val dataset =
754-
datasets?.find { dataset -> dataset.id == parameterValue.value }
755-
?: throw IllegalStateException(
756-
"Dataset ${parameterValue.value} cannot be found in Datasets")
757-
val connector =
758-
connectors?.find { connector -> connector.id == dataset.connector?.id }
759-
?: throw IllegalStateException(
760-
"Connector id ${dataset.connector?.id} not found in connectors list")
761-
762-
containers.add(
763-
buildFromDataset(
764-
dataset,
765-
connector,
766-
datasetParameterCount,
767-
true,
768-
parameter.id,
769-
organizationId,
770-
workspaceId,
771-
workspaceKey,
772-
csmSimulationId))
773-
datasetParameterCount++
754+
val datasetIdList = getDatasetIdListFromValue(parameterValue.value)
755+
datasetIdList.forEachIndexed { index, datasetId ->
756+
val dataset =
757+
datasets?.find { dataset -> dataset.id == datasetId }
758+
?: throw IllegalStateException(
759+
"Dataset ${datasetId} cannot be found in Datasets")
760+
val connector =
761+
connectors?.find { connector -> connector.id == dataset.connector?.id }
762+
?: throw IllegalStateException(
763+
"Connector id ${dataset.connector?.id} not found in connectors list")
764+
765+
val fetchId =
766+
if (datasetIdList.size == 1) parameter.id else "${parameter.id}-${index.toString()}"
767+
containers.add(
768+
buildFromDataset(
769+
dataset,
770+
connector,
771+
datasetParameterCount,
772+
true,
773+
fetchId,
774+
organizationId,
775+
workspaceId,
776+
workspaceKey,
777+
csmSimulationId))
778+
datasetParameterCount++
779+
}
774780
}
775781
}
776782
}

scenariorun/src/main/kotlin/com/cosmotech/scenariorun/dataset/DatasetUtils.kt

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ internal fun findDatasetsAndConnectors(
4444
?.forEach { parameter ->
4545
val parameterValue = scenario.parametersValues?.find { it.parameterId == parameter.id }
4646
addParameterValue(
47-
parameterValue,
48-
datasetService,
49-
connectorService,
50-
organizationId,
51-
datasets,
52-
connectors,
47+
parameterValue,
48+
datasetService,
49+
connectorService,
50+
organizationId,
51+
datasets,
52+
connectors,
5353
)
5454
}
5555
}
@@ -59,39 +59,36 @@ internal fun findDatasetsAndConnectors(
5959
}
6060

6161
private fun addParameterValue(
62-
parameterValue: ScenarioRunTemplateParameterValue?,
63-
datasetService: DatasetApiService,
64-
connectorService: ConnectorApiService,
65-
organizationId: String,
66-
datasets: MutableMap<String, Dataset>,
67-
connectors: MutableMap<String, Connector>,
68-
) {
69-
if (parameterValue != null && parameterValue.value != "") {
70-
val value = parameterValue.value
71-
if (value.startsWith("[")) {
72-
val datasetIds = value.substring(1, value.length - 1)
73-
val datasetIdList = datasetIds.split(",")
74-
datasetIdList.forEach {
75-
addDatasetAndConnector(
76-
datasetService,
77-
connectorService,
78-
organizationId,
79-
it,
80-
datasets,
81-
connectors,
82-
)
83-
}
84-
} else {
85-
addDatasetAndConnector(
86-
datasetService,
87-
connectorService,
88-
organizationId,
89-
value,
90-
datasets,
91-
connectors,
92-
)
93-
}
62+
parameterValue: ScenarioRunTemplateParameterValue?,
63+
datasetService: DatasetApiService,
64+
connectorService: ConnectorApiService,
65+
organizationId: String,
66+
datasets: MutableMap<String, Dataset>,
67+
connectors: MutableMap<String, Connector>,
68+
) {
69+
if (parameterValue != null && parameterValue.value != "") {
70+
val value = parameterValue.value
71+
val datasetIdList = getDatasetIdListFromValue(value)
72+
datasetIdList.forEach {
73+
addDatasetAndConnector(
74+
datasetService,
75+
connectorService,
76+
organizationId,
77+
it,
78+
datasets,
79+
connectors,
80+
)
9481
}
82+
}
83+
}
84+
85+
internal fun getDatasetIdListFromValue(paramValue: String): List<String> {
86+
if (paramValue.startsWith("[")) {
87+
val datasetIds = paramValue.substring(1, paramValue.length - 1)
88+
return datasetIds.split(",")
89+
} else {
90+
return listOf(paramValue)
91+
}
9592
}
9693

9794
internal fun addDatasetAndConnector(

scenariorun/src/test/kotlin/com/cosmotech/scenariorun/ContainerFactoryTests.kt

Lines changed: 120 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,12 +1377,95 @@ class ContainerFactoryTests {
13771377

13781378
@Test
13791379
fun `Build all containers for a Scenario DATASETID containers env vars`() {
1380-
parametersDatasetEnvTest("1", "param2")
1380+
parametersDatasetEnvTest(getScenarioDatasetIds(), "1", "param2")
13811381
}
13821382

13831383
@Test
13841384
fun `Build all containers for a Scenario DATASETID containers env vars 2`() {
1385-
parametersDatasetEnvTest("2", "param3")
1385+
parametersDatasetEnvTest(getScenarioDatasetIds(), "2", "param3")
1386+
}
1387+
1388+
@Test
1389+
fun `Build all containers for a Scenario Two DATASETID containers name list`() {
1390+
val scenario = getScenarioTwoDatasetIds()
1391+
val datasets = listOf(getDataset(), getDataset2(), getDataset3())
1392+
val connectors = listOf(getConnector(), getConnector2(), getConnector3())
1393+
val workspace = getWorkspace()
1394+
val solution = getSolutionDatasetIds()
1395+
val containers =
1396+
factory.buildContainersPipeline(
1397+
scenario,
1398+
datasets,
1399+
connectors,
1400+
workspace,
1401+
getOrganization(),
1402+
solution,
1403+
CSM_SIMULATION_ID)
1404+
val expected =
1405+
listOf(
1406+
"fetchDatasetContainer-1",
1407+
"fetchScenarioParametersContainer",
1408+
"fetchScenarioDatasetParametersContainer-1",
1409+
"fetchScenarioDatasetParametersContainer-2",
1410+
"fetchScenarioDatasetParametersContainer-3",
1411+
"fetchScenarioDatasetParametersContainer-4",
1412+
"applyParametersContainer",
1413+
"validateDataContainer",
1414+
"sendDataWarehouseContainer",
1415+
"preRunContainer",
1416+
"runContainer",
1417+
"postRunContainer",
1418+
)
1419+
assertEquals(expected, containers.map { container -> container.name })
1420+
}
1421+
1422+
@Test
1423+
fun `Build all containers for a Scenario Two DATASETID containers image list`() {
1424+
val scenario = getScenarioTwoDatasetIds()
1425+
val datasets = listOf(getDataset(), getDataset2(), getDataset3())
1426+
val connectors = listOf(getConnector(), getConnector2(), getConnector3())
1427+
val workspace = getWorkspace()
1428+
val solution = getSolutionDatasetIds()
1429+
val containers =
1430+
factory.buildContainersPipeline(
1431+
scenario,
1432+
datasets,
1433+
connectors,
1434+
workspace,
1435+
getOrganization(),
1436+
solution,
1437+
CSM_SIMULATION_ID)
1438+
val expected =
1439+
listOf(
1440+
"ghcr.io/cosmotech/test_connector:1.0.0",
1441+
"ghcr.io/cosmotech/scenariofetchparameters:1.0.0",
1442+
"ghcr.io/cosmotech/test_connector:1.0.0",
1443+
"ghcr.io/cosmotech/test_connector2:1.0.0",
1444+
"ghcr.io/cosmotech/test_connector2:1.0.0",
1445+
"ghcr.io/cosmotech/test_connector3:1.0.0",
1446+
"twinengines.azurecr.io/cosmotech/testsolution_simulator:1.0.0",
1447+
"twinengines.azurecr.io/cosmotech/testsolution_simulator:1.0.0",
1448+
"ghcr.io/cosmotech/senddatawarehouse:1.0.0",
1449+
"twinengines.azurecr.io/cosmotech/testsolution_simulator:1.0.0",
1450+
"twinengines.azurecr.io/cosmotech/testsolution_simulator:1.0.0",
1451+
"twinengines.azurecr.io/cosmotech/testsolution_simulator:1.0.0",
1452+
)
1453+
assertEquals(expected, containers.map { container -> container.image })
1454+
}
1455+
1456+
@Test
1457+
fun `Build all containers for a Scenario Two DATASETID containers env vars 2-1`() {
1458+
parametersDatasetEnvTest(getScenarioTwoDatasetIds(), "1", "param2-0")
1459+
}
1460+
1461+
@Test
1462+
fun `Build all containers for a Scenario Two DATASETID containers env vars 2-2`() {
1463+
parametersDatasetEnvTest(getScenarioTwoDatasetIds(), "2", "param2-1")
1464+
}
1465+
1466+
@Test
1467+
fun `Build all containers for a Scenario Two DATASETID containers env vars 3`() {
1468+
parametersDatasetEnvTest(getScenarioTwoDatasetIds(), "3", "param3")
13861469
}
13871470

13881471
@Test
@@ -1812,8 +1895,7 @@ class ContainerFactoryTests {
18121895
)
18131896
}
18141897

1815-
private fun parametersDatasetEnvTest(nameId: String, param: String) {
1816-
val scenario = getScenarioDatasetIds()
1898+
private fun parametersDatasetEnvTest(scenario: Scenario, nameId: String, param: String) {
18171899
val datasets = listOf(getDataset(), getDataset2(), getDataset3())
18181900
val connectors = listOf(getConnector(), getConnector2(), getConnector3())
18191901
val workspace = getWorkspace()
@@ -2243,15 +2325,15 @@ class ContainerFactoryTests {
22432325
),
22442326
RunTemplateParameter(
22452327
id = "param2",
2246-
labels = mapOf("en" to "Parameter Dataset 1"),
2328+
labels = mapOf("en" to "Parameter Dataset 2"),
22472329
varType = "%DATASETID%"),
22482330
RunTemplateParameter(
22492331
id = "param3",
2250-
labels = mapOf("en" to "Parameter Dataset 2"),
2332+
labels = mapOf("en" to "Parameter Dataset 3"),
22512333
varType = "%DATASETID%"),
22522334
RunTemplateParameter(
22532335
id = "param4",
2254-
labels = mapOf("en" to "Parameter Dataset 3"),
2336+
labels = mapOf("en" to "Parameter Dataset 4"),
22552337
varType = "%DATASETID%"),
22562338
RunTemplateParameter(
22572339
id = "param5",
@@ -2490,6 +2572,37 @@ class ContainerFactoryTests {
24902572
))
24912573
}
24922574

2575+
private fun getScenarioTwoDatasetIds(): Scenario {
2576+
return Scenario(
2577+
id = "AQWXSZ",
2578+
name = "Test Scenario",
2579+
runTemplateId = "testruntemplate",
2580+
datasetList = listOf("1"),
2581+
parametersValues =
2582+
listOf(
2583+
ScenarioRunTemplateParameterValue(
2584+
parameterId = "param1",
2585+
value = "valParam1",
2586+
),
2587+
ScenarioRunTemplateParameterValue(
2588+
parameterId = "param2",
2589+
value = "[1,2]",
2590+
),
2591+
ScenarioRunTemplateParameterValue(
2592+
parameterId = "param3",
2593+
value = "2",
2594+
),
2595+
ScenarioRunTemplateParameterValue(
2596+
parameterId = "param4",
2597+
value = "3",
2598+
),
2599+
ScenarioRunTemplateParameterValue(
2600+
parameterId = "param5",
2601+
value = "999",
2602+
),
2603+
))
2604+
}
2605+
24932606
private fun getScenarioTwoDatasetsAndDatasetIds(): Scenario {
24942607
return Scenario(
24952608
id = "AQWXSZ",

solution/src/main/openapi/solutions.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,6 @@ components:
682682
type: object
683683
description: freeform options
684684
additionalProperties: true
685-
isArray:
686-
type: boolean
687-
description: whether or not the parameter contains an array of values
688685
required:
689686
- id
690687
- labels

0 commit comments

Comments
 (0)