GS2 States Language 정의 확장
GS2 States Language를 CDK로 정의하기 위한 확장 구문에 대하여
Deploy 처리에서 조작 대상이 되는 리소스
네임스페이스
네임스페이스는 하나의 프로젝트 내에서 동일한 서비스를 서로 다른 용도로 여러 개 이용하기 위한 엔티티입니다.
GS2의 각 서비스는 네임스페이스 단위로 관리됩니다. 네임스페이스가 다르면 동일한 서비스라도 완전히 독립된 데이터 공간으로 취급됩니다.
따라서 각 서비스의 이용을 시작하려면 먼저 네임스페이스를 생성해야 합니다.
리소스 생성·갱신 요청
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| name | string | ✓ | ~ 128자 | 네임스페이스 이름 네임스페이스 고유의 이름입니다. 영숫자 및 -(하이픈) _(언더스코어) .(마침표)로 지정합니다. | ||||||||
| description | string | ~ 1024자 | 설명문 | |||||||||
| supportSpeculativeExecution | 문자열 열거형 enum { “enable”, “disable” } | “disable” | 투기적 실행을 지원할지 여부 활성화하면 스테이트 머신 정의와 난수 상태가 Status 엔티티에 포함되어, 클라이언트가 서버 확인 전에 로컬에서 상태 전이를 시뮬레이션할 수 있게 됩니다. transactionSetting 설정이 필요합니다.
| |||||||||
| transactionSetting | TransactionSetting | {supportSpeculativeExecution} == “enable” | 트랜잭션 설정 스테이트 머신의 emit 액션 실행 시 트랜잭션 처리 방식을 제어하는 설정입니다. 투기적 실행을 활성화하는 경우 필요합니다. ※ supportSpeculativeExecution이(가) “enable” 이면 활성화 | |||||||||
| startScript | ScriptSetting | 스테이트 머신을 시작했을 때 실행할 스크립트 설정 Script 트리거 레퍼런스 - start | ||||||||||
| passScript | ScriptSetting | 스테이트 머신이 정상 종료되었을 때 실행할 스크립트 설정 Script 트리거 레퍼런스 - pass | ||||||||||
| errorScript | ScriptSetting | 스테이트 머신이 이상 종료되었을 때 실행할 스크립트 설정 Script 트리거 레퍼런스 - error | ||||||||||
| lowestStateMachineVersion | long | 스테이트 머신의 최저 버전 실행 가능한 스테이트 머신의 최저 버전입니다. 이 값보다 오래된 버전의 스테이트 머신으로 생성된 Status 인스턴스는 거부되며, 모든 실행 중인 인스턴스가 최신 정의를 사용하도록 보장됩니다. | ||||||||||
| logSetting | LogSetting | 로그 출력 설정 스테이트 머신의 실행, 상태 전이, emit 이벤트에 관한 API 요청·응답 로그를 출력할 GS2-Log의 네임스페이스를 지정합니다. |
!GetAttr 태그로 취득 가능한 리소스 생성 결과
| 타입 | 설명 | |
|---|---|---|
| Item | Namespace | 생성한 네임스페이스 |
Type: GS2::StateMachine::Namespace
Properties:
Name: namespace-0001
Description: null
SupportSpeculativeExecution: null
TransactionSetting: null
StartScript: null
PassScript: null
ErrorScript: null
LowestStateMachineVersion: null
LogSetting:
LoggingNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001import (
"github.com/gs2io/gs2-golang-cdk/core"
"github.com/gs2io/gs2-golang-cdk/stateMachine"
)
SampleStack := core.NewStack()
stateMachine.NewNamespace(
&SampleStack,
"namespace-0001",
stateMachine.NamespaceOptions{
LogSetting: &core.LogSetting{
LoggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001",
},
},
)
println(SampleStack.Yaml()) // Generate Templateclass 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()
.withLogSetting(new io.gs2.cdk.core.model.LogSetting(
"grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
))
);
}
}
System.out.println(new SampleStack().yaml()); // Generate Templatepublic class SampleStack : Gs2Cdk.Core.Model.Stack
{
public SampleStack() {
new Gs2Cdk.Gs2StateMachine.Model.Namespace(
stack: this,
name: "namespace-0001",
options: new Gs2Cdk.Gs2StateMachine.Model.Options.NamespaceOptions
{
logSetting = new Gs2Cdk.Core.Model.LogSetting(
loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
)
}
);
}
}
Debug.Log(new SampleStack().Yaml()); // Generate Templateimport 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
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트랜잭션 설정
트랜잭션 설정은 트랜잭션의 실행 방식, 정합성, 비동기 처리, 충돌 회피 메커니즘을 제어하는 설정입니다.
자동 실행(AutoRun), 원자적 실행(AtomicCommit), GS2-Distributor를 이용한 비동기 실행, 스크립트 결과의 일괄 적용, GS2-JobQueue를 통한 입수 액션의 비동기화 등을 조합하여 게임 로직에 맞는 견고한 트랜잭션 관리를 가능하게 합니다.
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |
|---|---|---|---|---|---|---|
| enableAutoRun | bool | false | 발행한 트랜잭션을 서버 사이드에서 자동으로 실행할지 여부 | |||
| enableAtomicCommit | bool | {enableAutoRun} == true | false | 트랜잭션의 실행을 원자적으로 커밋할지 여부 ※ enableAutoRun이(가) true 이면 활성화 | ||
| transactionUseDistributor | bool | {enableAtomicCommit} == true | false | 트랜잭션을 비동기 처리로 실행할지 여부 ※ enableAtomicCommit이(가) true 이면 활성화 | ||
| commitScriptResultInUseDistributor | bool | {transactionUseDistributor} == true | false | 스크립트의 결과 커밋 처리를 비동기 처리로 실행할지 여부 ※ transactionUseDistributor이(가) true 이면 활성화 | ||
| acquireActionUseJobQueue | bool | {enableAtomicCommit} == true | false | 입수 액션을 실행할 때 GS2-JobQueue를 사용할지 여부 ※ enableAtomicCommit이(가) true 이면 활성화 | ||
| distributorNamespaceId | string | “grn:gs2:{region}:{ownerId}:distributor:default” | ~ 1024자 | 트랜잭션 실행에 사용하는 GS2-Distributor 네임스페이스 GRN | ||
| queueNamespaceId | string | “grn:gs2:{region}:{ownerId}:queue:default” | ~ 1024자 | 트랜잭션 실행에 사용하는 GS2-JobQueue의 네임스페이스 GRN |
스크립트 설정
GS2에서는 마이크로서비스의 이벤트에 연결하여 커스텀 스크립트를 실행할 수 있습니다.
이 모델은 스크립트 실행을 트리거하기 위한 설정을 보유합니다.
스크립트 실행 방식은 크게 두 가지로, 바로 “동기 실행"과 “비동기 실행"입니다.
동기 실행은 스크립트 실행이 완료될 때까지 처리가 블록됩니다.
대신 스크립트 실행 결과를 이용하여 API 실행을 중단시키거나 API 응답 내용을 제어할 수 있습니다.
한편, 비동기 실행에서는 스크립트 완료를 기다리기 위해 처리가 블록되는 일이 없습니다.
다만 스크립트 실행 결과를 이용하여 API 실행을 중단하거나 API 응답 내용을 변경할 수는 없습니다.
비동기 실행은 API의 응답 흐름에 영향을 주지 않으므로 원칙적으로 비동기 실행을 권장합니다.
비동기 실행에는 실행 방식이 두 가지 있으며, GS2-Script와 Amazon EventBridge가 있습니다.
Amazon EventBridge를 사용함으로써 Lua 이외의 언어로 처리를 작성할 수 있습니다.
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| triggerScriptId | string | ~ 1024자 | API 실행 시 동기적으로 실행되는 GS2-Script의 스크립트
GRN
“grn:gs2:“로 시작하는 GRN 형식의 ID로 지정해야 합니다. | |||||||||||
| doneTriggerTargetType | 문자열 열거형 enum { “none”, “gs2_script”, “aws” } | “none” | 비동기 스크립트의 실행 방법 비동기 실행에서 사용할 스크립트의 종류를 지정합니다. “비동기 실행의 스크립트를 사용하지 않음(none)”, “GS2-Script를 사용함(gs2_script)”, “Amazon EventBridge를 사용함(aws)” 중에서 선택할 수 있습니다.
| |||||||||||
| doneTriggerScriptId | string | {doneTriggerTargetType} == “gs2_script” | ~ 1024자 | 완료 시 실행할 스크립트 GRN
“grn:gs2:“로 시작하는 GRN 형식의 ID로 지정해야 합니다. ※ doneTriggerTargetType이(가) “gs2_script” 이면 활성화 | ||||||||||
| doneTriggerQueueNamespaceId | string | {doneTriggerTargetType} == “gs2_script” | ~ 1024자 | 완료 시 스크립트를 실행할 GS2-JobQueue 네임스페이스 GRN
완료 스크립트의 완료 여부를 알고 싶을 때 사용합니다. ※ doneTriggerTargetType이(가) “gs2_script” 이면 활성화 |
로그 출력 설정
로그 데이터의 출력 설정을 관리합니다. 이 타입은 로그 데이터를 출력하기 위해 사용되는 GS2-Log 네임스페이스의 식별자(Namespace ID)를 보관합니다.
로그 네임스페이스ID(loggingNamespaceId)에는 로그 데이터를 수집하여 저장하는 GS2-Log의 네임스페이스를 GRN 형식으로 지정합니다.
이 설정을 하면 설정된 네임스페이스 내에서 발생한 API 요청·응답 로그 데이터가 대상 GS2-Log 네임스페이스 쪽으로 출력됩니다.
GS2-Log에서는 실시간으로 로그가 제공되어 시스템 모니터링, 분석, 디버깅 등에 활용할 수 있습니다.
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |
|---|---|---|---|---|---|---|
| loggingNamespaceId | string | ✓ | ~ 1024자 | 로그를 출력할 GS2-Log의 네임스페이스
GRN
“grn:gs2:“로 시작하는 GRN 형식의 ID로 지정해야 합니다. |
스테이트 머신 정의
GSL로 작성된 스테이트 머신을 관리합니다.
리소스 생성·갱신 요청
| 타입 | 활성화 조건 | 필수 | 기본값 | 값 제한 | 설명 | |
|---|---|---|---|---|---|---|
| namespaceName | string | ✓ | ~ 128자 | 네임스페이스 이름 네임스페이스 고유의 이름입니다. 영숫자 및 -(하이픈) _(언더스코어) .(마침표)로 지정합니다. | ||
| mainStateMachineName | string | ✓ | ~ 128자 | 메인 스테이트 머신 이름 GSL 정의 내에서 진입점이 되는 스테이트 머신의 이름입니다. 이 스테이트 머신부터 실행이 시작되며, 스택 메커니즘을 통해 서브 스테이트 머신을 호출할 수 있습니다. | ||
| payload | string | ✓ | ~ 5242880자 | 스테이트 머신 정의 스테이트 머신의 상태, 전이, 액션을 정의하는 GSL(GS2 State Language) 소스 코드입니다. 효율적인 취득을 위해 메타데이터와는 별도로 저장됩니다. |
!GetAttr 태그로 취득 가능한 리소스 생성 결과
| 타입 | 설명 | |
|---|---|---|
| Item | StateMachineMaster | 작성한 스테이트 머신 마스터 |
Type: GS2::StateMachine::StateMachineMaster
Properties:
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}\nimport (
"github.com/gs2io/gs2-golang-cdk/core"
"github.com/gs2io/gs2-golang-cdk/stateMachine"
)
SampleStack := core.NewStack()
stateMachine.NewStateMachineMaster(
&SampleStack,
"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 ",
stateMachine.StateMachineMasterOptions{},
)
println(SampleStack.Yaml()) // Generate Templateclass 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 Templatepublic class SampleStack : Gs2Cdk.Core.Model.Stack
{
public SampleStack() {
new Gs2Cdk.Gs2StateMachine.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 "
);
}
}
Debug.Log(new SampleStack().Yaml()); // Generate Templateimport 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
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 TemplateGS2 States Language를 CDK로 정의하기 위한 확장 구문에 대하여