@@ -2,7 +2,11 @@ package pl.touk.nussknacker.engine.api.deployment.simple
2
2
3
3
import pl .touk .nussknacker .engine .api .deployment ._
4
4
import pl .touk .nussknacker .engine .api .deployment .StateStatus .StatusName
5
- import pl .touk .nussknacker .engine .api .deployment .simple .SimpleStateStatus .ProblemStateStatus .defaultActions
5
+ import pl .touk .nussknacker .engine .api .deployment .simple .SimpleStateStatus .ProblemStateStatus .{
6
+ GeneralProblemStateStatus ,
7
+ MultipleJobsRunning ,
8
+ ShouldNotBeRunning
9
+ }
6
10
import pl .touk .nussknacker .engine .api .process .VersionId
7
11
import pl .touk .nussknacker .engine .deployment .DeploymentId
8
12
@@ -12,23 +16,56 @@ object SimpleStateStatus {
12
16
13
17
def fromDeploymentStatus (deploymentStatus : DeploymentStatus ): StateStatus = {
14
18
deploymentStatus match {
15
- case noAttributes : NoAttributesDeploymentStatus => NoAttributesStateStatus (noAttributes .name.value)
19
+ case status : NoAttributesDeploymentStatus => NoAttributesStateStatus (status .name.value)
16
20
// We assume that all deployment status have default allowedActions. Non-default allowedActions have only
17
21
// statuses that are not deployment statuses but scenario statuses.
18
- case problem : ProblemDeploymentStatus => ProblemStateStatus (problem.description )
22
+ case status : ProblemDeploymentStatus => GeneralProblemStateStatus (status.problemDescription )
19
23
}
20
24
}
21
25
22
- // Represents general problem.
23
- final case class ProblemStateStatus (
24
- description : String ,
25
- allowedActions : Set [ScenarioActionName ] = defaultActions,
26
- tooltip : Option [String ] = None
27
- ) extends StateStatus {
26
+ sealed trait ProblemStateStatus extends StateStatus {
28
27
override def name : StatusName = ProblemStateStatus .name
28
+
29
+ def description : String
30
+ def allowedActions : Set [ScenarioActionName ]
31
+ def tooltip : Option [String ]
29
32
}
30
33
31
34
object ProblemStateStatus {
35
+
36
+ final case class ShouldNotBeRunning (deployed : Boolean ) extends ProblemStateStatus {
37
+
38
+ override val description : String =
39
+ if (deployed) " Scenario has been canceled but still is running."
40
+ else " Scenario has been never deployed but now is running."
41
+
42
+ override val allowedActions : Set [ScenarioActionName ] = defaultActions
43
+ override val tooltip : Option [String ] = None
44
+ }
45
+
46
+ final case class MultipleJobsRunning (
47
+ firstNonFinalDeployment : (DeploymentId , StateStatus ),
48
+ secondNonFinalDeployment : (DeploymentId , StateStatus ),
49
+ otherNonFinalDeployments : (DeploymentId , StateStatus )*
50
+ ) extends ProblemStateStatus {
51
+
52
+ override val allowedActions : Set [ScenarioActionName ] = Set (ScenarioActionName .Cancel )
53
+ override val description : String = " More than one deployment is running."
54
+
55
+ override val tooltip : Option [StatusName ] = Some {
56
+ (firstNonFinalDeployment :: secondNonFinalDeployment :: otherNonFinalDeployments.toList)
57
+ .map { case (deploymentId, deploymentStatus) => s " $deploymentId - $deploymentStatus" }
58
+ .mkString(" Expected one job, instead: " , " , " , " " )
59
+ }
60
+
61
+ }
62
+
63
+ final case class GeneralProblemStateStatus (
64
+ override val description : String ,
65
+ override val allowedActions : Set [ScenarioActionName ] = defaultActions,
66
+ override val tooltip : Option [String ] = None
67
+ ) extends ProblemStateStatus
68
+
32
69
val name : String = " PROBLEM"
33
70
34
71
def isProblemStatus (status : StateStatus ): Boolean = status.name == name
@@ -40,48 +77,54 @@ object SimpleStateStatus {
40
77
41
78
// Problem factory methods
42
79
43
- val Failed : ProblemStateStatus = ProblemStateStatus (defaultDescription)
80
+ val Failed : ProblemStateStatus = GeneralProblemStateStatus (defaultDescription)
44
81
45
82
val ArchivedShouldBeCanceled : ProblemStateStatus =
46
- ProblemStateStatus (" Archived scenario should be canceled." , Set (ScenarioActionName .Cancel ))
83
+ GeneralProblemStateStatus (" Archived scenario should be canceled." , Set (ScenarioActionName .Cancel ))
47
84
48
85
val FailedToGet : ProblemStateStatus =
49
- ProblemStateStatus (s " Failed to get a state of the scenario. " )
86
+ GeneralProblemStateStatus (s " Failed to get a state of the scenario. " )
50
87
51
88
def shouldBeRunning (deployedVersionId : VersionId , user : String ): ProblemStateStatus =
52
- ProblemStateStatus (s " Scenario deployed in version $deployedVersionId by $user is not running. " )
89
+ GeneralProblemStateStatus (s " Scenario deployed in version $deployedVersionId by $user is not running. " )
53
90
54
91
def mismatchDeployedVersion (
55
92
deployedVersionId : VersionId ,
56
93
exceptedVersionId : VersionId ,
57
94
user : String
58
95
): ProblemStateStatus =
59
- ProblemStateStatus (
96
+ GeneralProblemStateStatus (
60
97
s " Scenario deployed in version $deployedVersionId by $user, expected version $exceptedVersionId. "
61
98
)
62
99
63
- def shouldNotBeRunning (deployed : Boolean ): ProblemStateStatus = {
64
- val shouldNotBeRunningMessage =
65
- if (deployed) " Scenario has been canceled but still is running."
66
- else " Scenario has been never deployed but now is running."
67
- ProblemStateStatus (shouldNotBeRunningMessage)
68
- }
100
+ def shouldNotBeRunning (deployed : Boolean ): ProblemStateStatus =
101
+ ShouldNotBeRunning (deployed)
69
102
70
103
def missingDeployedVersion (exceptedVersionId : VersionId , user : String ): ProblemStateStatus =
71
- ProblemStateStatus (s " Scenario deployed without version by $user, expected version $exceptedVersionId. " )
72
-
73
- def multipleJobsRunning (nonFinalDeploymentIds : List [(DeploymentId , StateStatus )]): ProblemStateStatus =
74
- ProblemStateStatus (
75
- description = " More than one deployment is running." ,
76
- allowedActions = Set (ScenarioActionName .Cancel ),
77
- tooltip = Some (
78
- nonFinalDeploymentIds
79
- .map { case (deploymentId, deploymentStatus) =>
80
- s " $deploymentId - $deploymentStatus"
81
- }
82
- .mkString(" Expected one job, instead: " , " , " , " " )
83
- )
84
- )
104
+ GeneralProblemStateStatus (s " Scenario deployed without version by $user, expected version $exceptedVersionId. " )
105
+
106
+ def multipleJobsRunning (
107
+ first : (DeploymentId , StateStatus ),
108
+ second : (DeploymentId , StateStatus ),
109
+ others : (DeploymentId , StateStatus )*
110
+ ): ProblemStateStatus =
111
+ MultipleJobsRunning (first, second, others : _* )
112
+
113
+ }
114
+
115
+ implicit class CanBeConsideredAsActiveStatus (val status : StateStatus ) extends AnyVal {
116
+
117
+ def isActive : Boolean = {
118
+ status match {
119
+ case problemStatus : ProblemStateStatus =>
120
+ problemStatus match {
121
+ case _ : ShouldNotBeRunning | _ : MultipleJobsRunning => true
122
+ case _ : GeneralProblemStateStatus => false
123
+ }
124
+ case `Restarting` => true
125
+ case status => DefaultFollowingDeployStatuses .contains(status)
126
+ }
127
+ }
85
128
86
129
}
87
130
@@ -119,7 +162,8 @@ object SimpleStateStatus {
119
162
Set (ScenarioActionName .Deploy , ScenarioActionName .Cancel )
120
163
// When Failed - process is in terminal state in Flink and it doesn't require any cleanup in Flink, but in NK it does
121
164
// - that's why Cancel action is available
122
- case SimpleStateStatus .ProblemStateStatus (_, allowedActions, _) => allowedActions
165
+ case s : ShouldNotBeRunning => s.allowedActions
166
+ case GeneralProblemStateStatus (_, allowedActions, _) => allowedActions
123
167
}
124
168
125
169
val definitions : Map [StatusName , StateDefinitionDetails ] = Map (
0 commit comments