GS2-Deploy/CDK Reference of GS2-StateMachine

Entities

Namespace

Namespace

Namespace is a mechanism that allows multiple uses of the same service for different purposes within a single project. Basically, GS2 services have a layer called namespace, and different namespaces are treated as completely different data spaces, even for the same service.

Therefore, it is necessary to create a namespace before starting to use each service.

TypeRequireDefaultLimitationDescription
namestring~ 32 charsNamespace name
descriptionstring~ 1024 charsDescription
supportSpeculativeExecutionstring“disable”~ 128 charsWhether to support speculative execution
transactionSettingTransactionSetting{supportSpeculativeExecution} == “enable”Transaction settings
startScriptScriptSettingScript to execute when starting the state machine
passScriptScriptSettingScript to execute when the state machine is successfully completed
errorScriptScriptSettingScript to execute when the state machine fails
lowestStateMachineVersionlongLowest version of the state machine
logSettingLogSettingLog output settings

GetAttr

TypeDescription
ItemNamespaceNamespace created

Implementation Example

Type: GS2::StateMachine::Namespace
Properties:
  Name: namespace1
  Description: null
  SupportSpeculativeExecution: null
  TransactionSetting: null
  StartScript: null
  PassScript: null
  ErrorScript: null
  LowestStateMachineVersion: null
  LogSetting: 
    LoggingNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:log:namespace1
from gs2_cdk import Stack, core, state_machine

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        state_machine.Namespace(
            stack=self,
            name="namespace-0001",
            options=state_machine.NamespaceOptions(
                log_setting=core.LogSetting(
                    logging_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001',
                ),
            ),
        )

print(SampleStack().yaml())  # Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\StateMachine\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\StateMachine\Model\Options\NamespaceOptions(
                logSetting: new \Gs2Cdk\Core\Model\LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001",
                ),
            ),
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.stateMachine.model.Namespace(
            this,
            "namespace-0001",
            new io.gs2.cdk.stateMachine.model.options.NamespaceOptions() {
                {
                    logSetting = new io.gs2.cdk.core.model.LogSetting(
                        "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                    );
                }
            }
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
import core from "@/gs2cdk/core";
import stateMachine from "@/gs2cdk/stateMachine";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new stateMachine.model.Namespace(
            this,
            "namespace-0001",
            {
                logSetting: new core.LogSetting(
                    "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2StateMachine.Model.Namespace(
            this,
            "namespace-0001",
            new Gs2Cdk.Gs2StateMachine.Model.Options.NamespaceOptions {
                logSetting = new Gs2Cdk.Core.Model.LogSetting(
                    "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                ),
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template

StateMachineMaster

State machine definition

manages state machines written in GSL.

TypeRequireDefaultLimitationDescription
namespaceNamestring~ 32 charsNamespace name
mainStateMachineNamestring~ 128 charsMain state machine name
payloadstring~ 5242880 charsState machine definition

GetAttr

TypeDescription
ItemStateMachineMasterCreated State Machine Master

Implementation Example

Type: GS2::StateMachine::StateMachineMaster
Properties:
  NamespaceName: namespace1
  MainStateMachineName: MainStateMachine
  Payload: \nStateMachine MainStateMachine {\n  EntryPoint Task1;\n\n  Task Task1(int initCounter) {\n    Event Pass();\n    Event Error(string Reason);\n\n    Script grn:gs2:ap-northeast-1:YourOwnerId:script:state-machine-0001:script:Task1\n  }\n\n  PassTask Pass;\n\n  ErrorTask Error(string reason);\n\n  Transition Task1 handling Pass -> Pass;\n  Transition Task1 handling Error -> Error;\n}\n    
from gs2_cdk import Stack, core, state_machine

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        state_machine.StateMachineMaster(
            stack=self,
            namespace_name="namespace-0001",
            main_state_machine_name='MainStateMachine',
            payload='\nStateMachine MainStateMachine {\n  EntryPoint Task1;\n\n  Task Task1(int initCounter) {\n    Event Pass();\n    Event Error(string Reason);\n\n    Script grn:gs2:ap-northeast-1:YourOwnerId:script:state-machine-0001:script:Task1\n  }\n\n  PassTask Pass;\n\n  ErrorTask Error(string reason);\n\n  Transition Task1 handling Pass -> Pass;\n  Transition Task1 handling Error -> Error;\n}\n    ',
        )

print(SampleStack().yaml())  # Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\StateMachine\Model\StateMachineMaster(
            stack: $this,
            namespaceName: "namespace-0001",
            mainStateMachineName: "MainStateMachine",
            payload: "\nStateMachine MainStateMachine {\n  EntryPoint Task1;\n\n  Task Task1(int initCounter) {\n    Event Pass();\n    Event Error(string Reason);\n\n    Script grn:gs2:ap-northeast-1:YourOwnerId:script:state-machine-0001:script:Task1\n  }\n\n  PassTask Pass;\n\n  ErrorTask Error(string reason);\n\n  Transition Task1 handling Pass -> Pass;\n  Transition Task1 handling Error -> Error;\n}\n    ",
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.stateMachine.model.StateMachineMaster(
            this,
            "namespace-0001",
            "MainStateMachine",
            "\nStateMachine MainStateMachine {\n  EntryPoint Task1;\n\n  Task Task1(int initCounter) {\n    Event Pass();\n    Event Error(string Reason);\n\n    Script grn:gs2:ap-northeast-1:YourOwnerId:script:state-machine-0001:script:Task1\n  }\n\n  PassTask Pass;\n\n  ErrorTask Error(string reason);\n\n  Transition Task1 handling Pass -> Pass;\n  Transition Task1 handling Error -> Error;\n}\n    "
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
import core from "@/gs2cdk/core";
import stateMachine from "@/gs2cdk/stateMachine";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new stateMachine.model.StateMachineMaster(
            this,
            "namespace-0001",
            "MainStateMachine",
            "\nStateMachine MainStateMachine {\n  EntryPoint Task1;\n\n  Task Task1(int initCounter) {\n    Event Pass();\n    Event Error(string Reason);\n\n    Script grn:gs2:ap-northeast-1:YourOwnerId:script:state-machine-0001:script:Task1\n  }\n\n  PassTask Pass;\n\n  ErrorTask Error(string reason);\n\n  Transition Task1 handling Pass -> Pass;\n  Transition Task1 handling Error -> Error;\n}\n    "
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2StateMachine.Model.StateMachineMaster(
            this,
            "namespace-0001",
            "MainStateMachine",
            "\nStateMachine MainStateMachine {\n  EntryPoint Task1;\n\n  Task Task1(int initCounter) {\n    Event Pass();\n    Event Error(string Reason);\n\n    Script grn:gs2:ap-northeast-1:YourOwnerId:script:state-machine-0001:script:Task1\n  }\n\n  PassTask Pass;\n\n  ErrorTask Error(string reason);\n\n  Transition Task1 handling Pass -> Pass;\n  Transition Task1 handling Error -> Error;\n}\n    "
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template

StackEntry

Stack

TypeRequireDefaultLimitationDescription
stateMachineNamestring~ 128 charsName of the state machine
taskNamestring~ 128 charsTask name

Variable

State variables per state machine

TypeRequireDefaultLimitationDescription
stateMachineNamestring~ 128 charsName of the state machine
valuestring~ 1048576 charsValue

TransactionSetting

Transaction settings

TypeRequireDefaultLimitationDescription
enableAutoRunboolfalseAutomatically run issued stamp sheets on the server side, or
distributorNamespaceIdstring“grn:gs2:{region}:{ownerId}:distributor:default”~ 1024 charsGS2-Distributor namespace used for stamp sheet execution
keyIdstring!{enableAutoRun}“grn:gs2:{region}:{ownerId}:key:default:key:default”~ 1024 charsGS2-Key encryption key used to sign the stamp sheet
queueNamespaceIdstring“grn:gs2:{region}:{ownerId}:queue:default”~ 1024 charsNamespace in GS2-JobQueue used to run the stamp sheet

Event

Event

TypeRequireDefaultLimitationDescription
eventTypeenum [
“change_state”,
“emit”
]
~ 128 charsEvent type
changeStateEventChangeStateEvent{eventType} == “change_state”Change state
emitEventEmitEvent{eventType} == “emit”Send a message

ChangeStateEvent

Change state event

TypeRequireDefaultLimitationDescription
taskNamestring~ 128 charsTask name
hashstring~ 64 charsHash
timestamplongTimestamp

EmitEvent

Send a message event

TypeRequireDefaultLimitationDescription
eventstring~ 128 charsEvent name
parametersstring~ 1024 charsParameters
timestamplongTimestamp

RandomStatus

Random number status

TypeRequireDefaultLimitationDescription
seedlong~ 4294967294Random seed
usedList<RandomUsed>~ 1000 itemsList of used random number

RandomUsed

Used random number

TypeRequireDefaultLimitationDescription
categorylong~ 4294967294Category
usedlong~ 4294967294Used random number

LogSetting

Log setting

This type manages log output settings. This type holds the identifier of the log namespace used to output log data. The log namespace ID specifies the GS2-Log namespace to aggregate and store the log data. Through this setting, API request and response log data under this namespace will be output to the target GS2-Log. GS2-Log provides logs in real time, which can be used for system monitoring, analysis, debugging, etc.

TypeRequireDefaultLimitationDescription
loggingNamespaceIdstring~ 1024 charsNamespace GRN

ScriptSetting

Script settings

In GS2, you can associate custom scripts with microservice events and execute them. This model holds the settings for triggering script execution.

There are two main ways to execute a script: synchronous execution and asynchronous execution. Synchronous execution blocks processing until the script has finished executing. Instead, you can use the script execution result to stop the execution of the API or to tamper with the result of the API.

On the other hand, asynchronous execution does not block processing until the script has finished executing. Instead, you can use the script execution result to stop the execution of the API or to tamper with the result of the API. However, asynchronous execution does not block processing until the script has finished executing, so it is generally recommended to use asynchronous execution.

There are two types of asynchronous execution methods: GS2-Script and Amazon EventBridge. By using Amazon EventBridge, you can write processing in languages other than Lua.

TypeRequireDefaultLimitationDescription
triggerScriptIdstring~ 1024 charsScript GRN
doneTriggerTargetTypeenum [
“none”,
“gs2_script”,
“aws”
]
“none”~ 128 charsNotification of Completion
doneTriggerScriptIdstring{doneTriggerTargetType} == “gs2_script”~ 1024 charsScript GRN
doneTriggerQueueNamespaceIdstring{doneTriggerTargetType} == “gs2_script”~ 1024 charsNamespace GRN

GS2 States Language Definition Extension

extension syntax for defining GS2 States Language in CDK