[SPEC-7510] Remove unnecessary static container for AWSCore scriptcanvas nodes

Signed-off-by: onecent1101 <liug@amazon.com>
This commit is contained in:
onecent1101
2021-07-12 14:17:33 -07:00
parent 177f532ffa
commit 6b6bd1149d
11 changed files with 87 additions and 234 deletions
@@ -1,42 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project. For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
namespace AZ
{
class BehaviorContext;
class EditContext;
class SerializeContext;
} // namespace AZ
// this just provides a convenient template to avoid the necessary boilerplate when you derive from AWSScriptBehaviorBase
#define AWS_SCRIPT_BEHAVIOR_DEFINITION(className, guidString) \
AZ_TYPE_INFO(className, guidString) \
AZ_CLASS_ALLOCATOR(className, AZ::SystemAllocator, 0) \
void ReflectSerialization(AZ::SerializeContext* serializeContext) override; \
void ReflectBehaviors(AZ::BehaviorContext* behaviorContext) override; \
void ReflectEditParameters(AZ::EditContext* editContext) override; \
className(); \
namespace AWSCore
{
//! An interface for AWS ScriptCanvas Behaviors to inherit from
class AWSScriptBehaviorBase
{
public:
virtual ~AWSScriptBehaviorBase() = default;
virtual void ReflectSerialization(AZ::SerializeContext* reflectContext) = 0;
virtual void ReflectBehaviors(AZ::BehaviorContext* behaviorContext) = 0;
virtual void ReflectEditParameters(AZ::EditContext* editContext) = 0;
virtual void Init() {}
virtual void Activate() {}
virtual void Deactivate() {}
};
} // namespace AWSCore
@@ -10,8 +10,6 @@
#include <AzCore/EBus/EBus.h>
#include <AzCore/std/string/string.h>
#include <ScriptCanvas/AWSScriptBehaviorBase.h>
namespace AWSCore
{
using DynamoDBAttributeValueMap = AZStd::unordered_map<AZStd::string, AZStd::string>;
@@ -55,10 +53,14 @@ namespace AWSCore
};
class AWSScriptBehaviorDynamoDB
: public AWSScriptBehaviorBase
{
public:
AWS_SCRIPT_BEHAVIOR_DEFINITION(AWSScriptBehaviorDynamoDB, "{569E74F6-1268-4199-9653-A3B603FC9F4F}");
AZ_RTTI(AWSScriptBehaviorDynamoDB, "{569E74F6-1268-4199-9653-A3B603FC9F4F}");
AWSScriptBehaviorDynamoDB() = default;
virtual ~AWSScriptBehaviorDynamoDB() = default;
static void Reflect(AZ::ReflectContext* context);
static void GetItem(const AZStd::string& tableResourceKey, const DynamoDBAttributeValueMap& keyMap);
static void GetItemRaw(const AZStd::string& table, const DynamoDBAttributeValueMap& keyMap, const AZStd::string& region);
@@ -10,8 +10,6 @@
#include <AzCore/EBus/EBus.h>
#include <AzCore/std/string/string.h>
#include <ScriptCanvas/AWSScriptBehaviorBase.h>
namespace AWSCore
{
//! AWS Script Behavior notifications for ScriptCanvas behaviors that interact with AWS Lambda
@@ -53,10 +51,14 @@ namespace AWSCore
};
class AWSScriptBehaviorLambda
: public AWSScriptBehaviorBase
{
public:
AWS_SCRIPT_BEHAVIOR_DEFINITION(AWSScriptBehaviorLambda, "{9E71534D-34B3-4723-B180-2552513DDA3D}");
AZ_RTTI(AWSScriptBehaviorLambda, "{9E71534D-34B3-4723-B180-2552513DDA3D}");
AWSScriptBehaviorLambda() = default;
virtual ~AWSScriptBehaviorLambda() = default;
static void Reflect(AZ::ReflectContext* context);
static void Invoke(const AZStd::string& functionResourceKey, const AZStd::string& payload);
static void InvokeRaw(const AZStd::string& functionName, const AZStd::string& payload, const AZStd::string& region);
@@ -10,8 +10,6 @@
#include <AzCore/EBus/EBus.h>
#include <AzCore/std/string/string.h>
#include <ScriptCanvas/AWSScriptBehaviorBase.h>
namespace AWSCore
{
//! AWS Script Behavior notifications for ScriptCanvas behaviors that interact with AWS S3
@@ -68,7 +66,6 @@ namespace AWSCore
};
class AWSScriptBehaviorS3
: public AWSScriptBehaviorBase
{
static constexpr const char AWSScriptBehaviorS3Name[] = "AWSScriptBehaviorS3";
static constexpr const char OutputFileIsEmptyErrorMessage[] = "Request validation failed, output file is empty.";
@@ -81,7 +78,12 @@ namespace AWSCore
static constexpr const char RegionNameIsEmptyErrorMessage[] = "Request validation failed, region name is empty.";
public:
AWS_SCRIPT_BEHAVIOR_DEFINITION(AWSScriptBehaviorS3, "{7F4E956C-7463-4236-B320-C992D36A9C6E}");
AZ_RTTI(AWSScriptBehaviorS3, "{7F4E956C-7463-4236-B320-C992D36A9C6E}");
AWSScriptBehaviorS3() = default;
virtual ~AWSScriptBehaviorS3() = default;
static void Reflect(AZ::ReflectContext* context);
static void GetObject(const AZStd::string& bucketResourceKey, const AZStd::string& objectKey, const AZStd::string& outFile);
static void GetObjectRaw(const AZStd::string& bucket, const AZStd::string& objectKey, const AZStd::string& region, const AZStd::string& outFile);
@@ -10,7 +10,6 @@
#include <AzCore/Component/Component.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/std/containers/vector.h>
namespace AWSCore
{
@@ -30,23 +29,8 @@ namespace AWSCore
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
static bool AddedBehaviours()
{
return m_alreadyAddedBehaviors;
}
protected:
////////////////////////////////////////////////////////////////////////
// AZ::Component interface implementation
void Init() override;
void Activate() override;
void Deactivate() override;
////////////////////////////////////////////////////////////////////////
static void AddBehaviors(); // Add any behaviors you derived from AWSScriptBehaviorBase to the implementation of this function
static AZStd::vector<AZStd::unique_ptr<AWSScriptBehaviorBase>> m_behaviors;
static bool m_alreadyAddedBehaviors;
};
} // namespace AWSCore
@@ -20,39 +20,30 @@
namespace AWSCore
{
AWSScriptBehaviorDynamoDB::AWSScriptBehaviorDynamoDB()
void AWSScriptBehaviorDynamoDB::Reflect(AZ::ReflectContext* context)
{
}
void AWSScriptBehaviorDynamoDB::ReflectSerialization(AZ::SerializeContext* serializeContext)
{
if (serializeContext)
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<AWSScriptBehaviorDynamoDB>()
->Version(0);
}
}
void AWSScriptBehaviorDynamoDB::ReflectBehaviors(AZ::BehaviorContext* behaviorContext)
{
behaviorContext->Class<AWSScriptBehaviorDynamoDB>("AWSScriptBehaviorDynamoDB")
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Method("GetItem", &AWSScriptBehaviorDynamoDB::GetItem,
{{{"Table Resource KeyName", "The name of the table containing the requested item."},
{"Key Map", "A map of attribute names to AttributeValue objects, representing the primary key of the item to retrieve."}}})
->Method("GetItemRaw", &AWSScriptBehaviorDynamoDB::GetItemRaw,
{{{"Table Name", "The name of the table containing the requested item."},
{"Key Map", "A map of attribute names to AttributeValue objects, representing the primary key of the item to retrieve."},
{"Region Name", "The region of the table located in."}}});
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<AWSScriptBehaviorDynamoDB>("AWSScriptBehaviorDynamoDB")
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Method("GetItem", &AWSScriptBehaviorDynamoDB::GetItem,
{{{"Table Resource KeyName", "The name of the table containing the requested item."},
{"Key Map", "A map of attribute names to AttributeValue objects, representing the primary key of the item to retrieve."}}})
->Method("GetItemRaw", &AWSScriptBehaviorDynamoDB::GetItemRaw,
{{{"Table Name", "The name of the table containing the requested item."},
{"Key Map", "A map of attribute names to AttributeValue objects, representing the primary key of the item to retrieve."},
{"Region Name", "The region of the table located in."}}});
behaviorContext->EBus<AWSScriptBehaviorDynamoDBNotificationBus>("AWSDynamoDBBehaviorNotificationBus")
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Handler<AWSScriptBehaviorDynamoDBNotificationBusHandler>();
}
void AWSScriptBehaviorDynamoDB::ReflectEditParameters(AZ::EditContext* editContext)
{
AZ_UNUSED(editContext);
behaviorContext->EBus<AWSScriptBehaviorDynamoDBNotificationBus>("AWSDynamoDBBehaviorNotificationBus")
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Handler<AWSScriptBehaviorDynamoDBNotificationBusHandler>();
}
}
void AWSScriptBehaviorDynamoDB::GetItem(const AZStd::string& tableResourceKey, const DynamoDBAttributeValueMap& keyMap)
@@ -21,39 +21,30 @@
namespace AWSCore
{
AWSScriptBehaviorLambda::AWSScriptBehaviorLambda()
void AWSScriptBehaviorLambda::Reflect(AZ::ReflectContext* context)
{
}
void AWSScriptBehaviorLambda::ReflectSerialization(AZ::SerializeContext* serializeContext)
{
if (serializeContext)
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<AWSScriptBehaviorLambda>()
->Version(0);
}
}
void AWSScriptBehaviorLambda::ReflectBehaviors(AZ::BehaviorContext* behaviorContext)
{
behaviorContext->Class<AWSScriptBehaviorLambda>("AWSScriptBehaviorLambda")
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Method("Invoke", &AWSScriptBehaviorLambda::Invoke,
{{{"Function Resource KeyName", "The resource key name of the lambda function in resource mapping config file."},
{"Payload", "The JSON that you want to provide to your Lambda function as input."}}})
->Method("InvokeRaw", &AWSScriptBehaviorLambda::InvokeRaw,
{{{"Function Name", "The name of the Lambda function, version, or alias."},
{"Payload", "The JSON that you want to provide to your Lambda function as input."},
{"Region Name", "The region of the lambda function located in."}}});
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<AWSScriptBehaviorLambda>("AWSScriptBehaviorLambda")
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Method("Invoke", &AWSScriptBehaviorLambda::Invoke,
{{{"Function Resource KeyName", "The resource key name of the lambda function in resource mapping config file."},
{"Payload", "The JSON that you want to provide to your Lambda function as input."}}})
->Method("InvokeRaw", &AWSScriptBehaviorLambda::InvokeRaw,
{{{"Function Name", "The name of the Lambda function, version, or alias."},
{"Payload", "The JSON that you want to provide to your Lambda function as input."},
{"Region Name", "The region of the lambda function located in."}}});
behaviorContext->EBus<AWSScriptBehaviorLambdaNotificationBus>("AWSLambdaBehaviorNotificationBus")
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Handler<AWSScriptBehaviorLambdaNotificationBusHandler>();
}
void AWSScriptBehaviorLambda::ReflectEditParameters(AZ::EditContext* editContext)
{
AZ_UNUSED(editContext);
behaviorContext->EBus<AWSScriptBehaviorLambdaNotificationBus>("AWSLambdaBehaviorNotificationBus")
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Handler<AWSScriptBehaviorLambdaNotificationBusHandler>();
}
}
void AWSScriptBehaviorLambda::Invoke(const AZStd::string& functionResourceKey, const AZStd::string& payload)
@@ -24,49 +24,39 @@
namespace AWSCore
{
AWSScriptBehaviorS3::AWSScriptBehaviorS3()
void AWSScriptBehaviorS3::Reflect(AZ::ReflectContext* context)
{
}
void AWSScriptBehaviorS3::ReflectSerialization(AZ::SerializeContext* serializeContext)
{
if (serializeContext)
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<AWSScriptBehaviorS3>()
->Version(0);
}
}
void AWSScriptBehaviorS3::ReflectBehaviors(AZ::BehaviorContext* behaviorContext)
{
behaviorContext->Class<AWSScriptBehaviorS3>(AWSScriptBehaviorS3Name)
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Method("GetObject", &AWSScriptBehaviorS3::GetObject,
{{{"Bucket Resource KeyName", "The resource key name of the bucket in resource mapping config file."},
{"Object KeyName", "The object key."},
{"Outfile Name", "Filename where the content will be saved."}}})
->Method("GetObjectRaw", &AWSScriptBehaviorS3::GetObjectRaw,
{{{"Bucket Name", "The name of the bucket containing the object."},
{"Object KeyName", "The object key."},
{"Region Name", "The region of the bucket located in."},
{"Outfile Name", "Filename where the content will be saved."}}})
->Method("HeadObject", &AWSScriptBehaviorS3::HeadObject,
{{{"Bucket Resource KeyName", "The resource key name of the bucket in resource mapping config file."},
{"Object KeyName", "The object key."}}})
->Method("HeadObjectRaw", &AWSScriptBehaviorS3::HeadObjectRaw,
{{{"Bucket Name", "The name of the bucket containing the object."},
{"Object KeyName", "The object key."},
{"Region Name", "The region of the bucket located in."}}})
;
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
behaviorContext->Class<AWSScriptBehaviorS3>(AWSScriptBehaviorS3Name)
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Method("GetObject", &AWSScriptBehaviorS3::GetObject,
{{{"Bucket Resource KeyName", "The resource key name of the bucket in resource mapping config file."},
{"Object KeyName", "The object key."},
{"Outfile Name", "Filename where the content will be saved."}}})
->Method("GetObjectRaw", &AWSScriptBehaviorS3::GetObjectRaw,
{{{"Bucket Name", "The name of the bucket containing the object."},
{"Object KeyName", "The object key."},
{"Region Name", "The region of the bucket located in."},
{"Outfile Name", "Filename where the content will be saved."}}})
->Method("HeadObject", &AWSScriptBehaviorS3::HeadObject,
{{{"Bucket Resource KeyName", "The resource key name of the bucket in resource mapping config file."},
{"Object KeyName", "The object key."}}})
->Method("HeadObjectRaw", &AWSScriptBehaviorS3::HeadObjectRaw,
{{{"Bucket Name", "The name of the bucket containing the object."},
{"Object KeyName", "The object key."},
{"Region Name", "The region of the bucket located in."}}});
behaviorContext->EBus<AWSScriptBehaviorS3NotificationBus>("AWSS3BehaviorNotificationBus")
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Handler<AWSScriptBehaviorS3NotificationBusHandler>();
}
void AWSScriptBehaviorS3::ReflectEditParameters(AZ::EditContext* editContext)
{
AZ_UNUSED(editContext);
behaviorContext->EBus<AWSScriptBehaviorS3NotificationBus>("AWSS3BehaviorNotificationBus")
->Attribute(AZ::Script::Attributes::Category, "AWSCore")
->Handler<AWSScriptBehaviorS3NotificationBusHandler>();
}
}
void AWSScriptBehaviorS3::GetObject(
@@ -12,35 +12,17 @@
namespace AWSCore
{
AZStd::vector<AZStd::unique_ptr<AWSScriptBehaviorBase>> AWSScriptBehaviorsComponent::m_behaviors;
bool AWSScriptBehaviorsComponent::m_alreadyAddedBehaviors = false;
void AWSScriptBehaviorsComponent::AddBehaviors()
{
if (!m_alreadyAddedBehaviors)
{
// Add new script behaviors here
m_behaviors.push_back(AZStd::make_unique<AWSScriptBehaviorDynamoDB>());
m_behaviors.push_back(AZStd::make_unique<AWSScriptBehaviorLambda>());
m_behaviors.push_back(AZStd::make_unique<AWSScriptBehaviorS3>());
m_alreadyAddedBehaviors = true;
}
}
void AWSScriptBehaviorsComponent::Reflect(AZ::ReflectContext* context)
{
AddBehaviors();
AWSScriptBehaviorDynamoDB::Reflect(context);
AWSScriptBehaviorLambda::Reflect(context);
AWSScriptBehaviorS3::Reflect(context);
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
{
serialize->Class<AWSScriptBehaviorsComponent, AZ::Component>()
->Version(0);
for (auto&& behavior : m_behaviors)
{
behavior->ReflectSerialization(serialize);
}
if (AZ::EditContext* editContext = serialize->GetEditContext())
{
editContext->Class<AWSScriptBehaviorsComponent>("AWSScriptBehaviors", "Provides ScriptCanvas functions for calling AWS")
@@ -49,19 +31,6 @@ namespace AWSCore
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("AWS"))
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
;
for (auto&& behavior : m_behaviors)
{
behavior->ReflectEditParameters(editContext);
}
}
}
if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
{
for (auto&& behavior : m_behaviors)
{
behavior->ReflectBehaviors(behaviorContext);
}
}
}
@@ -86,31 +55,12 @@ namespace AWSCore
AZ_UNUSED(dependent);
}
void AWSScriptBehaviorsComponent::Init()
{
for (auto&& behavior : m_behaviors)
{
behavior->Init();
}
}
void AWSScriptBehaviorsComponent::Activate()
{
for (auto&& behavior : m_behaviors)
{
behavior->Activate();
}
}
void AWSScriptBehaviorsComponent::Deactivate()
{
for (auto&& behavior : m_behaviors)
{
behavior->Deactivate();
}
// this forces the vector to release its capacity, clear/shrink_to_fit is not
m_behaviors.swap(AZStd::vector<AZStd::unique_ptr<AWSScriptBehaviorBase>>());
}
}
@@ -15,18 +15,6 @@
using namespace AWSCore;
class AWSScriptBehaviorsComponentMock
: public AWSScriptBehaviorsComponent
{
public:
AZ_COMPONENT(AWSScriptBehaviorsComponentMock, "{78579706-E1B2-4788-A34D-A58D3F273FF9}");
int GetBehaviorsNum()
{
return m_behaviors.size();
}
};
class AWSScriptBehaviorsComponentTest
: public UnitTest::ScopedAllocatorSetupFixture
{
@@ -38,7 +26,7 @@ public:
m_behaviorContext = AZStd::make_unique<AZ::BehaviorContext>();
m_entity = AZStd::make_unique<AZ::Entity>();
m_scriptBehaviorsComponent.reset(m_entity->CreateComponent<AWSScriptBehaviorsComponentMock>());
m_scriptBehaviorsComponent.reset(m_entity->CreateComponent<AWSScriptBehaviorsComponent>());
}
void TearDown() override
@@ -56,20 +44,16 @@ protected:
AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
AZStd::unique_ptr<AZ::BehaviorContext> m_behaviorContext;
AZStd::unique_ptr<AZ::ComponentDescriptor> m_componentDescriptor;
AZStd::unique_ptr<AWSScriptBehaviorsComponentMock> m_scriptBehaviorsComponent;
AZStd::unique_ptr<AWSScriptBehaviorsComponent> m_scriptBehaviorsComponent;
AZStd::unique_ptr<AZ::Entity> m_entity;
};
TEST_F(AWSScriptBehaviorsComponentTest, InitActivateDeactivate_Call_GetExpectedNumOfAddedBehaviors)
TEST_F(AWSScriptBehaviorsComponentTest, Reflect)
{
m_componentDescriptor.reset(AWSScriptBehaviorsComponentMock::CreateDescriptor());
int oldEBusNum = m_behaviorContext->m_ebuses.size();
m_componentDescriptor.reset(AWSScriptBehaviorsComponent::CreateDescriptor());
m_componentDescriptor->Reflect(m_serializeContext.get());
m_componentDescriptor->Reflect(m_behaviorContext.get());
EXPECT_TRUE(AWSScriptBehaviorsComponentMock::AddedBehaviours());
EXPECT_TRUE(m_scriptBehaviorsComponent->GetBehaviorsNum() == 3);
m_entity->Init();
m_entity->Activate();
m_entity->Deactivate();
EXPECT_TRUE(m_scriptBehaviorsComponent->GetBehaviorsNum() == 0);
EXPECT_TRUE(m_behaviorContext->m_ebuses.size() - oldEBusNum == 3);
}
-1
View File
@@ -32,7 +32,6 @@ set(FILES
Include/Public/Framework/ServiceRequestJobConfig.h
Include/Public/Framework/Util.h
Include/Public/ResourceMapping/AWSResourceMappingBus.h
Include/Public/ScriptCanvas/AWSScriptBehaviorBase.h
Include/Public/ScriptCanvas/AWSScriptBehaviorDynamoDB.h
Include/Public/ScriptCanvas/AWSScriptBehaviorLambda.h
Include/Public/ScriptCanvas/AWSScriptBehaviorS3.h