Skip to content

Commit

Permalink
Fix last action data determining (#6134)
Browse files Browse the repository at this point in the history
  • Loading branch information
wrzontek authored Jun 7, 2024
1 parent 13a235d commit 41325b5
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ abstract class DBFetchingProcessRepository[F[_]: Monad](
actionRepository
.getLastActionPerProcess(ProcessActionState.FinishedStates, Some(ScenarioActionName.StateActions))
)
// for last deploy action we are not interested in ExecutionFinished deploys - we don't want to show them in the history
// For last deploy action we are interested in Deploys that are Finished (not ExecutionFinished) and that are not Cancelled
// so that the presence of such an action means that the process is currently deployed
lastDeployedActionPerProcess <- fetchActionsOrEmpty(
actionRepository.getLastActionPerProcess(Set(ProcessActionState.Finished), Some(Set(ScenarioActionName.Deploy)))
)
actionRepository
.getLastActionPerProcess(
ProcessActionState.FinishedStates,
Some(Set(ScenarioActionName.Deploy, ScenarioActionName.Cancel))
)
).map(_.filter { case (_, action) =>
action.actionName == ScenarioActionName.Deploy && action.state == ProcessActionState.Finished
})

latestProcesses <- fetchLatestProcessesQuery(query, lastDeployedActionPerProcess.keySet, isDeployed).result
} yield latestProcesses
.map { case ((_, processVersion), process) =>
Expand Down Expand Up @@ -180,10 +188,13 @@ abstract class DBFetchingProcessRepository[F[_]: Monad](
processVersion = processVersion,
lastActionData = actions.headOption,
lastStateActionData = actions.find(a => ScenarioActionName.StateActions.contains(a.actionName)),
// for last deploy action we are not interested in ExecutionFinished deploys - we don't want to show them in the history
lastDeployedActionData = actions.headOption.filter(a =>
a.actionName == ScenarioActionName.Deploy && a.state == ProcessActionState.Finished
),
// For last deploy action we are interested in Deploys that are Finished (not ExecutionFinished) and that are not Cancelled
// so that the presence of such an action means that the process is currently deployed
lastDeployedActionData = actions
.find(action => Set(ScenarioActionName.Deploy, ScenarioActionName.Cancel).contains(action.actionName))
.filter(action =>
action.actionName == ScenarioActionName.Deploy && action.state == ProcessActionState.Finished
),
isLatestVersion = isLatestVersion,
tags = Some(tags),
history = Some(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ class DbProcessActionRepository(
actionState: Set[ProcessActionState],
actionNamesOpt: Option[Set[ScenarioActionName]]
): DB[Map[ProcessId, ProcessAction]] = {
val query = processActionsTable
val queryWithActionNamesFilter = actionNamesOpt
.map(actionNames => processActionsTable.filter { action => action.actionName.inSet(actionNames) })
.getOrElse(processActionsTable)

val finalQuery = queryWithActionNamesFilter
.filter(_.state.inSet(actionState))
.groupBy(_.processId)
.map { case (processId, group) => (processId, group.map(_.performedAt).max) }
Expand All @@ -318,11 +322,7 @@ class DbProcessActionRepository(
.map { case ((processId, action), comment) => processId -> (action, comment) }

run(
actionNamesOpt
.map(actionNames => query.filter { case (_, (entity, _)) => entity.actionName.inSet(actionNames) })
.getOrElse(query)
.result
.map(_.toMap.mapValuesNow(toFinishedProcessAction))
finalQuery.result.map(_.toMap.mapValuesNow(toFinishedProcessAction))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ trait ProcessDBQueryRepository[F[_]] extends Repository[F] with NuTables {

protected def fetchLatestProcessesQuery(
query: ProcessEntityFactory#ProcessEntity => Rep[Boolean],
lastDeployedActionPerProcess: Set[ProcessId],
deployedProcesses: Set[ProcessId],
isDeployed: Option[Boolean]
)(implicit fetchShape: ScenarioShapeFetchStrategy[_], loggedUser: LoggedUser): Query[
(
Expand All @@ -55,7 +55,7 @@ trait ProcessDBQueryRepository[F[_]] extends Repository[F] with NuTables {
.filter { case ((_, _), process) =>
isDeployed match {
case None => true: Rep[Boolean]
case Some(dep) => process.id.inSet(lastDeployedActionPerProcess) === dep
case Some(dep) => process.id.inSet(deployedProcesses) === dep
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ trait WithAccessControlCheckingConfigScenarioHelper {
rawScenarioHelper.createDeployedCanceledExampleScenario(scenarioName, category.stringify, isFragment = false)
}

def createDeployedWithCustomActionScenario(scenarioName: ProcessName, category: TestCategory): ProcessId = {
rawScenarioHelper.createDeployedWithCustomActionScenario(scenarioName, category.stringify, isFragment = false)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ private[test] class ScenarioHelper(dbRef: DbRef, designerConfig: Config)(implici
} yield id).futureValue
}

def createDeployedWithCustomActionScenario(
scenarioName: ProcessName,
category: String,
isFragment: Boolean
): ProcessId = {
(for {
id <- prepareValidScenario(scenarioName, category, isFragment)
_ <- prepareDeploy(id, processingTypeBy(category))
_ <- prepareCustomAction(id)
} yield id).futureValue
}

def createArchivedExampleScenario(scenarioName: ProcessName, category: String, isFragment: Boolean): ProcessId = {
(for {
id <- prepareValidScenario(scenarioName, category, isFragment)
Expand Down Expand Up @@ -130,6 +142,14 @@ private[test] class ScenarioHelper(dbRef: DbRef, designerConfig: Config)(implici
)
}

private def prepareCustomAction(scenarioId: ProcessId): Future[_] = {
val actionName = ScenarioActionName("Custom")
val comment = DeploymentComment.unsafe(UserComment("Execute custom action")).toComment(actionName)
dbioRunner.run(
actionRepository.addInstantAction(scenarioId, VersionId.initialVersionId, actionName, Some(comment), None)
)
}

private def prepareValidScenario(
scenarioName: ProcessName,
category: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,52 @@ class ProcessesResourcesSpec
}
}

test("should provide the same proper scenario state when fetching all scenarios and one scenario") {
createDeployedWithCustomActionScenario(processName, category = Category1)

Get(s"/api/processes") ~> withReaderUser() ~> applicationRoute ~> check {
status shouldEqual StatusCodes.OK
val loadedProcess = responseAs[List[ScenarioWithDetails]]

loadedProcess.head.lastAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, ScenarioActionName("Custom"), ProcessActionState.Finished, _, _, _, _)
) =>
}
loadedProcess.head.lastStateAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, ScenarioActionName("DEPLOY"), ProcessActionState.Finished, _, _, _, _)
) =>
}
loadedProcess.head.lastDeployedAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, ScenarioActionName("DEPLOY"), ProcessActionState.Finished, _, _, _, _)
) =>
}
}

Get(s"/api/processes/$processName") ~> withReaderUser() ~> applicationRoute ~> check {
status shouldEqual StatusCodes.OK
val loadedProcess = responseAs[ScenarioWithDetails]

loadedProcess.lastAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, ScenarioActionName("Custom"), ProcessActionState.Finished, _, _, _, _)
) =>
}
loadedProcess.lastStateAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, ScenarioActionName("DEPLOY"), ProcessActionState.Finished, _, _, _, _)
) =>
}
loadedProcess.lastDeployedAction should matchPattern {
case Some(
ProcessAction(_, _, _, _, _, _, ScenarioActionName("DEPLOY"), ProcessActionState.Finished, _, _, _, _)
) =>
}
}
}

test("not allow to save process if already exists") {
val processName = ProcessName("p1")
saveProcess(processName, ProcessTestData.sampleScenarioGraph, category = Category1) {
Expand Down
6 changes: 6 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

1.15.2 (7 June 2024)
-------------------------
* [#6134](https://github.com/TouK/nussknacker/pull/6134) Fixes in determining `lastStateActionData` and `lastDeployedActionData` for Scenario.
* Deployed version of scenario is now shown properly even if other actions followed deploy.
* Scenario state is now not impacted by actions that don't actually change it.

1.15.1 (5 June 2024)
-------------------------
* [#6126](https://github.com/TouK/nussknacker/pull/6126) Fix statistics configuration.
Expand Down

0 comments on commit 41325b5

Please sign in to comment.