-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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): allow setting description, evaluation method and key of DetectorModel #18644
Changes from 1 commit
49b3387
3dc2d35
3ee41a6
dba6fd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,22 @@ export interface IDetectorModel extends IResource { | |
readonly detectorModelName: string; | ||
} | ||
|
||
/** | ||
* Information about the order in which events are evaluated and how actions are executed. | ||
*/ | ||
export enum EvaluationMethod { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this name too generic? Should this be Actually, can we even kill the "Method" suffix here? I don't think it adds much, and just makes the name longer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/** | ||
* When setting to SERIAL, variables are updated and event conditions are evaluated in the order | ||
* that the events are defined. | ||
*/ | ||
BATCH = 'BATCH', | ||
yamatatsu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* When setting to BATCH, variables within a state are updated and events within a state are | ||
* performed only after all event conditions are evaluated. | ||
*/ | ||
SERIAL = 'SERIAL', | ||
} | ||
|
||
/** | ||
* Properties for defining an AWS IoT Events detector model | ||
*/ | ||
|
@@ -27,6 +43,38 @@ export interface DetectorModelProps { | |
*/ | ||
readonly detectorModelName?: string; | ||
|
||
/** | ||
* A brief description of the detector model. | ||
* | ||
* @default none | ||
*/ | ||
readonly detectorModelDescription?: string; | ||
yamatatsu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Information about the order in which events are evaluated and how actions are executed. | ||
* | ||
* 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. | ||
* | ||
* @default EvaluationMethod.BATCH | ||
*/ | ||
readonly evaluationMethod?: EvaluationMethod; | ||
|
||
/** | ||
* The value used to identify a detector instance. When a device or system sends input, a new | ||
* detector instance with a unique key value is created. AWS IoT Events can continue to route | ||
* input to its corresponding detector instance based on this identifying information. | ||
* | ||
* This parameter uses a JSON-path expression to select the attribute-value pair in the message | ||
* payload that is used for identification. To route the message to the correct detector instance, | ||
* the device must send a message payload that contains the same attribute-value. | ||
* | ||
* @default - none (single detector instance will be created and all inputs will be routed to it) | ||
*/ | ||
readonly key?: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name, however, is way, way too generic. How about calling it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/** | ||
* The state that is entered at the creation of each detector. | ||
*/ | ||
|
@@ -70,6 +118,9 @@ export class DetectorModel extends Resource implements IDetectorModel { | |
|
||
const resource = new CfnDetectorModel(this, 'Resource', { | ||
detectorModelName: this.physicalName, | ||
detectorModelDescription: props.detectorModelDescription, | ||
evaluationMethod: props.evaluationMethod, | ||
key: props.key, | ||
detectorModelDefinition: { | ||
initialStateName: props.initialState.stateName, | ||
states: [props.initialState._toStateJson()], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,65 @@ test('can set physical name', () => { | |
}); | ||
}); | ||
|
||
test('can set description', () => { | ||
// WHEN | ||
new iotevents.DetectorModel(stack, 'MyDetectorModel', { | ||
detectorModelDescription: 'test-detector-model-description', | ||
initialState: new iotevents.State({ | ||
stateName: 'test-state', | ||
onEnter: [{ | ||
eventName: 'test-eventName', | ||
condition: iotevents.Expression.fromString('test-eventCondition'), | ||
}], | ||
}), | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::IoTEvents::DetectorModel', { | ||
DetectorModelDescription: 'test-detector-model-description', | ||
}); | ||
}); | ||
|
||
test('can set evaluationMethod', () => { | ||
// WHEN | ||
new iotevents.DetectorModel(stack, 'MyDetectorModel', { | ||
detectorModelDescription: 'test-detector-model-description', | ||
evaluationMethod: iotevents.EvaluationMethod.SERIAL, | ||
initialState: new iotevents.State({ | ||
stateName: 'test-state', | ||
onEnter: [{ | ||
eventName: 'test-eventName', | ||
condition: iotevents.Expression.fromString('test-eventCondition'), | ||
}], | ||
}), | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::IoTEvents::DetectorModel', { | ||
EvaluationMethod: 'SERIAL', | ||
}); | ||
}); | ||
|
||
test('can set key', () => { | ||
// WHEN | ||
new iotevents.DetectorModel(stack, 'MyDetectorModel', { | ||
detectorModelDescription: 'test-detector-model-description', | ||
key: 'payload.deviceId', | ||
initialState: new iotevents.State({ | ||
stateName: 'test-state', | ||
onEnter: [{ | ||
eventName: 'test-eventName', | ||
condition: iotevents.Expression.fromString('test-eventCondition'), | ||
}], | ||
}), | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::IoTEvents::DetectorModel', { | ||
Key: 'payload.deviceId', | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's just do all 3 in one test. Spreading them out like that just makes the tests longer, it doesn't really improve coverage in any way. |
||
|
||
test('can set multiple events to State', () => { | ||
// WHEN | ||
new iotevents.DetectorModel(stack, 'MyDetectorModel', { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ class TestStack extends cdk.Stack { | |
|
||
const input = new iotevents.Input(this, 'MyInput', { | ||
inputName: 'test_input', | ||
attributeJsonPaths: ['payload.temperature'], | ||
attributeJsonPaths: ['payload.deviceId', 'payload.temperature'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, why are we changing existing things? |
||
}); | ||
|
||
const onlineState = new iotevents.State({ | ||
|
@@ -27,6 +27,9 @@ class TestStack extends cdk.Stack { | |
|
||
new iotevents.DetectorModel(this, 'MyDetectorModel', { | ||
detectorModelName: 'test-detector-model', | ||
detectorModelDescription: 'test-detector-model-description', | ||
evaluationMethod: iotevents.EvaluationMethod.SERIAL, | ||
key: 'payload.deviceId', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we use |
||
initialState: onlineState, | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change - seems unrelated to the rest of this PR...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified this for the sake of reality.
The path passed in
detectorKey
must be declared in thisattributeJsonPaths
. And the value passed indetectorKey
is often the unique value of the device or device group.This is because IoT Events is often used to monitor devices and device groups.
I modified integ test for the same reason.