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 transition events #18768

Merged
merged 15 commits into from
Feb 7, 2022

Conversation

yamatatsu
Copy link
Contributor

This PR allow IoT Events detector model to transit to multiple states.
This PR is in roadmap of #17711.

スクリーンショット 2022-02-02 0 38 10

Following image is the graph displayed on AWS console when this integ test deployed. Compared to the previous version, you can see that the state transitions are now represented.

image


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 1, 2022

@github-actions github-actions bot added the @aws-cdk/aws-iotevents Related to AWS IoT Events label Feb 1, 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.

Thanks for the contribution @yamatatsu! This is a very interesting functionality that has some interesting challenges, including some nice programming interview question-level sub-tasks 🙂. I'd like to see a few more iterations on the API itself before we can merge this in.

packages/@aws-cdk/aws-iotevents/lib/event.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/event.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/event.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/event.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts 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 2, 2022 04:53

Pull request has been modified.

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 fantastic @yamatatsu! So much cleaner and easier to read than the initial version 🙂.

I have a few small last comments, but nothing major.

packages/@aws-cdk/aws-iotevents/README.md Outdated Show resolved Hide resolved
/**
* The Boolean expression that, when TRUE, causes the state transition and the actions to be performed.
*/
readonly condition: Expression;
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about calling this property when? This way, the code will read:

someState.transitionTo(otherState, {
  when: iotevents.Expression....,
});

Which I think looks really nice 🙂.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yamatatsu I see you did not address this comment. Any reason? Do you disagree with this name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry! I mistakenly lost this task.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skinny85
I've modified it!

packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts 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 2, 2022 23:53

Pull request has been modified.

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! Last round of minor comments.

onEnter: [{
eventName: 'test-event',
condition: iotevents.Expression.currentInput(input),
when: iotevents.Expression.currentInput(input),
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, is this not a weird condition? What does just currentInput() mean here? Is this true whenever the current input is not empty?

Copy link
Contributor Author

@yamatatsu yamatatsu Feb 5, 2022

Choose a reason for hiding this comment

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

Is this true whenever the current input is not empty?

Yes🙂. In this case, Every messages to this input cause this event and create new detector by the property key.

*
* @default - none (the actions are always executed)
*/
readonly condition?: Expression;
readonly when?: Expression;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, not sure about this change. My comment was only changing this in TransitionOptions, not here (it doesn't read that well here as it does in transitionTo().

I would leave this as-is. If you feel passionate that this is the way to go, fine, but then we need a "Breaking change" note in the PR description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah. I assumed by mistake😅.

* The condition that is used to determine to cause the state transition and the actions.
* When this was evaluated to TRUE, the state transition and the actions are triggered.
*/
readonly when: Expression;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine to leave this name as condition (this is a package-private interface, it doesn't really matter what this name is - we can change it at any time. For that same reason, I'm pretty sure you can remove all of the documentation from this interface if you don't need it).

packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-iotevents/lib/state.ts Outdated Show resolved Hide resolved
@mergify mergify bot dismissed skinny85’s stale review February 5, 2022 07:20

Pull request has been modified.

Comment on lines 23 to 33
/**
* When setting to SERIAL, variables are updated and event conditions are evaluated in the order
* that the events are defined.
* When setting to BATCH, variables within a state are updated and events within a state are
* performed only after all event conditions are evaluated.
*/
BATCH = 'BATCH',

/**
* When setting to BATCH, variables within a state are updated and events within a state are
* performed only after all event conditions are evaluated.
* When setting to SERIAL, variables are updated and event conditions are evaluated in the order
* that the events are defined.
*/
SERIAL = 'SERIAL',
Copy link
Contributor Author

@yamatatsu yamatatsu Feb 6, 2022

Choose a reason for hiding this comment

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

Sorry that my funny mistake😓. Let me include it in this PR.

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!

@mergify
Copy link
Contributor

mergify bot commented Feb 7, 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: beb3341
  • 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 ccc1988 into aws:master Feb 7, 2022
@mergify
Copy link
Contributor

mergify bot commented Feb 7, 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).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
This PR allow IoT Events detector model to transit to multiple states.
This PR is in roadmap of aws#17711.

<img width="561" alt="スクリーンショット 2022-02-02 0 38 10" src="https://user-images.githubusercontent.com/11013683/151999891-45afa8e8-57ed-4264-a323-16b84ed35348.png">

Following image is the graph displayed on AWS console when this integ test deployed. [Compared to the previous version](aws#18049), you can see that the state transitions are now represented.

![image](https://user-images.githubusercontent.com/11013683/151999116-5b3b36b0-d2b9-4e3a-9483-824dc0618f4b.png)


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@yamatatsu yamatatsu deleted the iotevents-dm-transitions branch April 6, 2022 15:17
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.

3 participants