Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iotevents): support actions #18869

Merged
merged 32 commits into from
Mar 4, 2022
Merged

Conversation

yamatatsu
Copy link
Contributor

This PR allow IoT Events detector model to perform actions as this documentation.
This PR is in roadmap of #17711.

スクリーンショット 2022-02-08 22 43 33

With this fix, all the interfaces of the DetectorModel are now implemented! And next works is implementing expressions and actions.

The exapmle in readme became not simple, so also this PR has sorted explanation of readme.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Feb 8, 2022

@github-actions github-actions bot added the @aws-cdk/aws-iotevents Related to AWS IoT Events label Feb 8, 2022
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @yamatatsu, but we need a few more iterations before we can merge this in.

Thanks for the great contribution, as always!

packages/@aws-cdk/aws-iotevents/README.md Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
@mergify mergify bot dismissed skinny85’s stale review February 9, 2022 14:16

Pull request has been modified.

yamatatsu and others added 14 commits February 9, 2022 23:16
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
Co-authored-by: Adam Ruka <adamruka85@gmail.com>
mergify bot pushed a commit that referenced this pull request Feb 17, 2022
This PR creates new module for aws-iotevents. This PR will contain implementations of Detector Model action classes.
About #18869 (comment) .

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
This PR creates new module for aws-iotevents. This PR will contain implementations of Detector Model action classes.
About aws#18869 (comment) .

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@yamatatsu yamatatsu requested a review from skinny85 March 1, 2022 12:50
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @yamatatsu! This is starting to take shape, but I think we need a few more iterations before we nail the final API of this 🙂.

packages/@aws-cdk/aws-iotevents/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/action.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/action.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
@@ -150,6 +214,7 @@ function toTransitionEventsJson(transitionEvents: TransitionEvent[]): CfnDetecto
return transitionEvents.map(transitionEvent => ({
eventName: transitionEvent.eventName,
condition: transitionEvent.condition.evaluate(),
actions: transitionEvent.actions?.map(action => action.renderActionConfig().configuration),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not be calling renderActionConfig() (soon called bind()) more than once, because it can have side effects, like creating Constructs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will call bind() once by actions by calling DetectorModel constructor. But if a action is used in two detector models, bind() of the action will be called twice.
Is it problem?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! That's exactly how it's supposed to work.

Notice that the second detector model will call bind() with different arguments than the first one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, add a unit test for it, and we'll find out 🙂.

Copy link
Contributor Author

@yamatatsu yamatatsu Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the test! Calling bind twice worked without errors.
Ah.. But if an action set twice to an detector model and the action grant the role something, probably same policy will be added to the role. Is it better that we control it? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! Just let IAM de-duplication handle it.

packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
@yamatatsu
Copy link
Contributor Author

I'll address the comments and revert something to keep the difference small... Sorry!

@skinny85
Copy link
Contributor

skinny85 commented Mar 2, 2022

No worries @yamatatsu, thanks for all of your hard work on this!

@mergify mergify bot dismissed skinny85’s stale review March 3, 2022 11:05

Pull request has been modified.

@yamatatsu yamatatsu requested a review from skinny85 March 3, 2022 14:34
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @yamatatsu! 2 minor comments, and we'll get this merged.

scope: Construct,
actionBindOptions: ActionBindOptions,
events: Event[],
): CfnDetectorModel.EventProperty[] | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does this return undefined?

Copy link
Contributor Author

@yamatatsu yamatatsu Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah.. It is a remnant of big refactoring..

});
// 2st => 1st
offlineState.transitionTo(onlineState, {
when: iotevents.Expression.eq(
iotevents.Expression.inputAttribute(input, 'payload.temperature'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just leave this test unchanged? We already have an integ test in the @aws-cdk/aws-iotevents-actions module, I don't think we need this too.

@mergify mergify bot dismissed skinny85’s stale review March 4, 2022 01:10

Pull request has been modified.

@yamatatsu yamatatsu requested a review from skinny85 March 4, 2022 04:11
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yamatatsu!

@mergify
Copy link
Contributor

mergify bot commented Mar 4, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: de801e0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit e01654e into aws:master Mar 4, 2022
@mergify
Copy link
Contributor

mergify bot commented Mar 4, 2022

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@yamatatsu yamatatsu deleted the iotevents-actions branch March 9, 2022 00:49
TheRealAmazonKendra pushed a commit to TheRealAmazonKendra/aws-cdk that referenced this pull request Mar 11, 2022
This PR allow IoT Events detector model to perform actions as [this documentation](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-supported-actions.html).
This PR is in roadmap of aws#17711.

![スクリーンショット 2022-02-08 22 43 33](https://user-images.githubusercontent.com/11013683/152999288-81721f15-fefb-4108-b34b-aab3f88a7ab8.png)

With this fix, all the interfaces of the DetectorModel are now implemented! And next works is implementing expressions and actions.

The exapmle in readme became not simple, so also this PR has sorted explanation of readme.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-iotevents Related to AWS IoT Events
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants