in GameLiftPlugin/Source/GameLiftCore/Private/AWSScenariosDeployer.cpp [306:430]
bool AWSScenariosDeployer::DeployScenarioImpl(
IAWSAccountInstance* AwsAccountInstance,
AwsScenarios::IAWSScenario* AwsScenario,
AwsScenarios::BaseInstanceTemplateParams& Params,
const FString& OutConfigFilePath
)
{
constexpr auto DeployAbortResult = false;
constexpr auto DeployCompletedResult = true;
AwsDeployerInternal::sLatestDeploymentLogErrorMessage.Clear();
ShouldBeStopped = false;
auto AccountHandle = AwsAccountInstance->GetInstance();
if (AccountHandle == nullptr)
{
AwsDeployerInternal::sLatestDeploymentLogErrorMessage.Set(Deploy::Errors::kAccountIsInvalidText);
LastAwsError = GameLift::GAMELIFT_ERROR_GENERAL;
UE_LOG(GameLiftCoreLog, Error, TEXT("%s"), Deploy::Logs::kAccountInstanceIsNull);
return DeployAbortResult;
}
if (Params.GameNameParameter.size() > Deploy::kMaxGameNameWithPrefixLength)
{
AwsDeployerInternal::sLatestDeploymentLogErrorMessage.Set(Deploy::Errors::kGameNameIsTooLongText);
LastAwsError = GameLift::GAMELIFT_ERROR_GENERAL;
return DeployAbortResult;
}
GameLiftAccountSetGameName(AccountHandle, Params.GameNameParameter.c_str());
auto ScenarioPath = AwsScenario->GetScenarioPath();
auto StdScenarioPath = Convertors::FSToStdS(ScenarioPath);
GameLiftAccountSetPluginRootPath(AccountHandle, StdScenarioPath.c_str());
auto ScenarioInstancePath = AwsScenario->GetScenarioInstancePath();
auto StdScenarioInstancePath = Convertors::FSToStdS(ScenarioInstancePath);
GameLiftAccountSetRootPath(AccountHandle, StdScenarioInstancePath.c_str());
std::string StdAwsAccountId = GameLiftGetAwsAccountIdByAccountInstance(AccountHandle);
if (ShouldBeStopped)
{
LastAwsError = GameLift::GAMELIFT_ERROR_GENERAL;
UE_LOG(GameLiftCoreLog, Error, TEXT("%s"), Deploy::Logs::kDeploymentHasBeenStopped);
return DeployAbortResult;
}
auto ShouldDeployBeAborted = [this](int ErrorCode, auto&& ErrorDebugString)
{
LastAwsError = ErrorCode;
if (LastAwsError != GameLift::GAMELIFT_SUCCESS)
{
UE_LOG(GameLiftCoreLog, Error, TEXT("%s %s"), ErrorDebugString, *GameLiftErrorAsString::Convert(LastAwsError));
return true;
}
if (ShouldBeStopped)
{
LastAwsError = GameLift::GAMELIFT_ERROR_GENERAL;
UE_LOG(GameLiftCoreLog, Error, TEXT("%s"), Deploy::Logs::kDeploymentHasBeenStopped);
return true;
}
return false;
};
if (ShouldDeployBeAborted(GameLiftAccountCreateAndSetFunctionsReplacementId(AccountHandle), Deploy::Logs::kCreateAndSetFunctionsReplacementIdFailed))
{
return DeployAbortResult;
}
if (ShouldDeployBeAborted(GameLiftAccountGetMainFunctionsReplacementId(AccountHandle, this, AwsDeployerInternal::ReceiveReplacementId),
Deploy::Logs::kGetMainFunctionsReplacementIdFailed))
{
return DeployAbortResult;
}
auto StdBootstrapBucketName = Convertors::FSToStdS(AwsAccountInstance->GetBucketName());
if (ShouldDeployBeAborted(AwsScenario->UploadGameServer(AwsAccountInstance, Params.BuildFolderPath.c_str(), Params.ExtraServerResourcesPath.c_str()),
Deploy::Logs::kUploadGameServerFailed))
{
return DeployAbortResult;
}
Params.AccountId = StdAwsAccountId;
Params.ApiGatewayStageNameParameter = AwsAccountInstance->GetBuildConfiguration();
Params.BuildS3BucketParameter = StdBootstrapBucketName;
Params.LambdaZipS3BucketParameter = StdBootstrapBucketName;
Params.LambdaZipS3KeyParameter = AwsScenarios::GetLambdaS3Key(Params.GameNameParameter, MainFunctionsReplacementId);
Params.UnrealEngineVersionParameter = Convertors::FSToStdS(UnrealVersion::GetCurrentEngineVersion());
if (ShouldDeployBeAborted(AwsScenario->SaveFeatureInstanceTemplate(AwsAccountInstance, Params.ToMap()),
Deploy::Logs::kSaveFeatureInstanceTemplatesFailed))
{
return DeployAbortResult;
}
if (ShouldDeployBeAborted(GameLiftAccountUploadFunctions(AccountHandle), Deploy::Logs::kAccountUploadFunctionsFailed))
{
return DeployAbortResult;
}
if (ShouldDeployBeAborted(GameLiftAccountCreateOrUpdateMainStack(AccountHandle), Deploy::Logs::kCreateOrUpdateMainStackFailed))
{
return DeployAbortResult;
}
if (ShouldDeployBeAborted(GameLiftAccountDeployApiGatewayStage(AccountHandle), Deploy::Logs::kDeployApiGatewayStageFailed))
{
return DeployAbortResult;
}
if (ShouldDeployBeAborted(UpdateDeploymentResults(AwsAccountInstance, ScenarioInstancePath, FString(Params.GameNameParameter.c_str()), AwsAccountInstance->GetBucketName(), OutConfigFilePath),
Deploy::Logs::kDeploymentStackStatusFailed))
{
return DeployAbortResult;
}
return DeployCompletedResult;
}