-
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.
Add step function sync execution (#66)
Co-authored-by: Sameer Ahmad <mohammadsameer.ahmad@capitalone.com>
- Loading branch information
1 parent
2308bc7
commit aeb817a
Showing
4 changed files
with
124 additions
and
1 deletion.
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
67 changes: 67 additions & 0 deletions
67
src/main/scala/dev/joss/gatling/sfn/action/StartSyncExecutionAction.scala
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,67 @@ | ||
package uk.co.capitalone.services.decision.processor.utils | ||
|
||
import dev.joss.gatling.sfn.action.SfnActionBase | ||
import dev.joss.gatling.sfn.request.attributes.SfnExecuteAttributes | ||
import io.gatling.commons.util.Clock | ||
import io.gatling.core.CoreComponents | ||
import io.gatling.core.action.Action | ||
import io.gatling.core.session._ | ||
import io.gatling.core.stats.StatsEngine | ||
import software.amazon.awssdk.services.sfn.SfnClient | ||
import software.amazon.awssdk.services.sfn.model.StartSyncExecutionRequest | ||
|
||
case class StartSyncExecutionAction( | ||
sfnClient: SfnClient, | ||
coreComponents: CoreComponents, | ||
next: Action, | ||
id: String, | ||
attributes: SfnExecuteAttributes | ||
) extends SfnActionBase { | ||
override def statsEngine: StatsEngine = coreComponents.statsEngine | ||
override def clock: Clock = coreComponents.clock | ||
override def name: String = "Step Function Sync Execution" | ||
override def execute(session: Session): Unit = { | ||
startSyncExecution(session) | ||
} | ||
|
||
private def startSyncExecution( | ||
session: Session | ||
): Unit = { | ||
val request = StartSyncExecutionRequest.builder() | ||
|
||
var stateMachineArn = "" | ||
attributes.stateMachineArn(session).map { arn => | ||
request.stateMachineArn(arn) | ||
stateMachineArn = arn | ||
} | ||
|
||
attributes.input(session).map { arn => | ||
request.input(arn) | ||
} | ||
|
||
val tryStartExecutionResponse = | ||
trySfnRequest(() => sfnClient.startSyncExecution(request.build())) | ||
|
||
val startTime = tryStartExecutionResponse.get.startDate().toEpochMilli | ||
val endTime = tryStartExecutionResponse.get.stopDate().toEpochMilli | ||
if (tryStartExecutionResponse.get.status().toString.equals("SUCCEEDED")) { | ||
logSuccess( | ||
name, | ||
session, | ||
startTime, | ||
endTime, | ||
"The step function successfully completed!" | ||
) | ||
} else { | ||
val failedMessage: String = | ||
tryStartExecutionResponse.failed.get.getMessage | ||
logFailure( | ||
name, | ||
session, | ||
startTime, | ||
endTime, | ||
s"Could not execute step function with ARN: $stateMachineArn. Reason: $failedMessage" | ||
) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/scala/dev/joss/gatling/sfn/action/StartSyncExecutionActionBuilder.scala
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,24 @@ | ||
package uk.co.capitalone.services.decision.processor.utils | ||
|
||
import dev.joss.gatling.sfn.action.SfnActionBuilderBase | ||
import dev.joss.gatling.sfn.request.attributes.SfnExecuteAttributes | ||
import io.gatling.core.action.Action | ||
import io.gatling.core.structure.ScenarioContext | ||
import io.gatling.core.util.NameGen | ||
|
||
case class StartSyncExecutionActionBuilder(attributes: SfnExecuteAttributes) | ||
extends SfnActionBuilderBase | ||
with NameGen { | ||
override def build(ctx: ScenarioContext, next: Action): Action = { | ||
val protocol = getProtocol(ctx) | ||
val client = protocol.sfnClient | ||
StartSyncExecutionAction( | ||
client, | ||
ctx.coreComponents, | ||
next, | ||
genName(""), | ||
attributes | ||
) | ||
} | ||
|
||
} |
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