Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed wait_relationship_propagation from delete scenario endpoint #530

Merged
merged 2 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions doc/Apis/ScenarioApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ null (empty response body)

<a name="deleteScenario"></a>
# **deleteScenario**
> deleteScenario(organization\_id, workspace\_id, scenario\_id, wait\_relationship\_propagation)
> deleteScenario(organization\_id, workspace\_id, scenario\_id)

Delete a scenario

Expand All @@ -179,7 +179,6 @@ Name | Type | Description | Notes
**organization\_id** | **String**| the Organization identifier | [default to null]
**workspace\_id** | **String**| the Workspace identifier | [default to null]
**scenario\_id** | **String**| the Scenario identifier | [default to null]
**wait\_relationship\_propagation** | **Boolean**| whether to wait until child scenarios are effectively updated | [optional] [default to false]

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class ScenarioServiceIntegrationTest : CsmRedisTestBase() {

logger.info("should delete the Scenario and assert there is only one Scenario left")
scenarioApiService.deleteScenario(
organizationSaved.id!!, workspaceSaved.id!!, scenarioSaved2.id!!, false)
organizationSaved.id!!, workspaceSaved.id!!, scenarioSaved2.id!!)
val scenarioListAfterDelete =
scenarioApiService.findAllScenarios(organizationSaved.id!!, workspaceSaved.id!!, null, null)
assertTrue(scenarioListAfterDelete.size == 1)
Expand Down Expand Up @@ -298,8 +298,7 @@ class ScenarioServiceIntegrationTest : CsmRedisTestBase() {
assertEquals(6, scenarios.size)

logger.info("should delete last child (element 5) and assert there are 5 Scenarios left")
scenarioApiService.deleteScenario(
organizationSaved.id!!, workspaceSaved.id!!, idMap[5]!!, false)
scenarioApiService.deleteScenario(organizationSaved.id!!, workspaceSaved.id!!, idMap[5]!!)
scenarios =
scenarioApiService.findAllScenarios(organizationSaved.id!!, workspaceSaved.id!!, null, null)
assertEquals(5, scenarios.size)
Expand All @@ -310,8 +309,7 @@ class ScenarioServiceIntegrationTest : CsmRedisTestBase() {
assertEquals(idMap[3], scenario.parentId)

logger.info("should delete element 3 (in the middle) and assert there are 4 Scenarios left")
scenarioApiService.deleteScenario(
organizationSaved.id!!, workspaceSaved.id!!, idMap[3]!!, false)
scenarioApiService.deleteScenario(organizationSaved.id!!, workspaceSaved.id!!, idMap[3]!!)
scenarios =
scenarioApiService.findAllScenarios(organizationSaved.id!!, workspaceSaved.id!!, null, null)
assertEquals(4, scenarios.size)
Expand All @@ -322,8 +320,7 @@ class ScenarioServiceIntegrationTest : CsmRedisTestBase() {
assertEquals(idMap[2], scenario.parentId)

logger.info("should delete root element (element 1) and assert there are 3 Scenarios left")
scenarioApiService.deleteScenario(
organizationSaved.id!!, workspaceSaved.id!!, idMap[1]!!, false)
scenarioApiService.deleteScenario(organizationSaved.id!!, workspaceSaved.id!!, idMap[1]!!)
scenarios =
scenarioApiService.findAllScenarios(organizationSaved.id!!, workspaceSaved.id!!, null, null)
assertEquals(3, scenarios.size)
Expand Down Expand Up @@ -455,12 +452,12 @@ class ScenarioServiceIntegrationTest : CsmRedisTestBase() {
if (shouldThrow)
assertThrows<Exception> {
scenarioApiService.deleteScenario(
organizationSaved.id!!, workspaceSaved.id!!, scenarioSaved.id!!, true)
organizationSaved.id!!, workspaceSaved.id!!, scenarioSaved.id!!)
}
else
assertDoesNotThrow {
scenarioApiService.deleteScenario(
organizationSaved.id!!, workspaceSaved.id!!, scenarioSaved.id!!, true)
organizationSaved.id!!, workspaceSaved.id!!, scenarioSaved.id!!)
}
}
}
Expand Down Expand Up @@ -608,7 +605,7 @@ class ScenarioServiceIntegrationTest : CsmRedisTestBase() {
rootId = scenarioSaved.id))

scenarioApiService.deleteScenario(
organizationSaved.id!!, workspaceSaved.id!!, scenarioSaved.id!!, true)
organizationSaved.id!!, workspaceSaved.id!!, scenarioSaved.id!!)

firstChildScenario =
scenarioApiService.findScenarioById(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,13 @@ internal class ScenarioServiceImpl(
}
}

override fun deleteScenario(
organizationId: String,
workspaceId: String,
scenarioId: String,
waitRelationshipPropagation: Boolean
) {
override fun deleteScenario(organizationId: String, workspaceId: String, scenarioId: String) {
val scenario = this.findScenarioById(organizationId, workspaceId, scenarioId)
csmRbac.verify(scenario.getRbac(), PERMISSION_DELETE, scenarioPermissions)

scenarioRepository.delete(scenario)

this.handleScenarioDeletion(organizationId, workspaceId, scenario, waitRelationshipPropagation)
this.handleScenarioDeletion(organizationId, workspaceId, scenario)
val workspace = workspaceService.findWorkspaceById(organizationId, workspaceId)
deleteScenarioMetadata(organizationId, workspace.key, scenarioId)

Expand Down Expand Up @@ -305,7 +300,6 @@ internal class ScenarioServiceImpl(
organizationId: String,
workspaceId: String,
deletedScenario: Scenario,
waitRelationshipPropagation: Boolean = true
) {
val rootId = deletedScenario.rootId
val children = this.findScenarioChildrenById(organizationId, workspaceId, deletedScenario.id!!)
Expand All @@ -322,18 +316,10 @@ internal class ScenarioServiceImpl(
}
}
runBlocking { childrenUpdatesCoroutines.joinAll() }
if (rootId == null)
children.forEach {
updateRootId(organizationId, workspaceId, it, waitRelationshipPropagation)
}
if (rootId == null) children.forEach { updateRootId(organizationId, workspaceId, it) }
}

private fun updateRootId(
organizationId: String,
workspaceId: String,
scenario: Scenario,
waitRelationshipPropagation: Boolean
) {
private fun updateRootId(organizationId: String, workspaceId: String, scenario: Scenario) {
val rootId = if (scenario.rootId == null) scenario.id else scenario.rootId
val children = this.findScenarioChildrenById(organizationId, workspaceId, scenario.id!!)
val childrenUpdatesCoroutines =
Expand All @@ -345,7 +331,7 @@ internal class ScenarioServiceImpl(
}
}
runBlocking { childrenUpdatesCoroutines.joinAll() }
children.forEach { updateRootId(organizationId, workspaceId, it, waitRelationshipPropagation) }
children.forEach { updateRootId(organizationId, workspaceId, it) }
}

override fun findAllScenarios(
Expand Down
8 changes: 0 additions & 8 deletions scenario/src/main/openapi/scenario.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,6 @@ paths:
description: the Scenario specified is unknown or you don't have access to it
delete:
operationId: deleteScenario
parameters:
- name: wait_relationship_propagation
in: query
description: whether to wait until child scenarios are effectively updated
required: false
schema:
type: boolean
default: false
tags:
- scenario
summary: Delete a scenario
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ class ScenarioServiceImplTests {
every { workspace.sendScenarioMetadataToEventHub } returns false
every { csmPlatformProperties.twincache.scenario.defaultPageSize } returns 5

this.scenarioServiceImpl.deleteScenario(ORGANIZATION_ID, WORKSPACE_ID, c111.id!!, false)
this.scenarioServiceImpl.deleteScenario(ORGANIZATION_ID, WORKSPACE_ID, c111.id!!)

assertNull(m1.parentId)
assertNotNull(m1.id)
Expand Down Expand Up @@ -594,7 +594,7 @@ class ScenarioServiceImplTests {
every { csmPlatformProperties.twincache.scenario.defaultPageSize } returns 100
every { scenarioServiceImpl.isRbacEnabled(ORGANIZATION_ID, WORKSPACE_ID) } returns false

this.scenarioServiceImpl.deleteScenario(ORGANIZATION_ID, WORKSPACE_ID, m1.id!!, true)
this.scenarioServiceImpl.deleteScenario(ORGANIZATION_ID, WORKSPACE_ID, m1.id!!)

assertNull(p11.parentId)
assertNull(p12.parentId)
Expand Down Expand Up @@ -655,7 +655,7 @@ class ScenarioServiceImplTests {
every { csmPlatformProperties.twincache.scenario.defaultPageSize } returns 100
every { scenarioServiceImpl.isRbacEnabled(ORGANIZATION_ID, WORKSPACE_ID) } returns false

this.scenarioServiceImpl.deleteScenario(ORGANIZATION_ID, WORKSPACE_ID, p11.id!!, false)
this.scenarioServiceImpl.deleteScenario(ORGANIZATION_ID, WORKSPACE_ID, p11.id!!)

sequenceOf(c111, c112).forEach {
verify(exactly = 1) { scenarioServiceImpl.upsertScenarioData(it) }
Expand Down Expand Up @@ -1070,7 +1070,7 @@ class ScenarioServiceImplTests {
every { scenarioServiceImpl.findScenarioChildrenById(any(), any(), any()) } returns
emptyList()
scenarioServiceImpl.deleteScenario(
it.organization.id!!, it.workspace.id!!, it.scenario.id!!, false)
it.organization.id!!, it.workspace.id!!, it.scenario.id!!)
}
}

Expand Down
Loading