-
Notifications
You must be signed in to change notification settings - Fork 53
Adds constraint (required|forbidden)unlessAnyOf #1008
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
Adds constraint (required|forbidden)unlessAnyOf #1008
Conversation
kemitix
left a comment
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.
The tests aren't 'readable'. The calls to assertKeyBehaviour() method seem somewhat cryptic. As a niave reader of the tests, I've no idea what is being checked unless I also know the internals of the method being called.
|
retest this please Changed test config, to enable |
|
@kemitix I completely agree about the tests being cryptic. Passing four booleans in a row in a method signature is an anti-pattern: it is hard to read and very error-prone. These tests were originally written by Alex - I did some minor improvements to their readability (see d19d207). I decided it was hard to make it much more readable without significantly increasing the amount of code required. On balance, because it is a test class and because the methods are private, it seemed ok to leave the methods as cryptic - unpleasant for code reviewers looking at a diff, but if you open up the class it's liveable with. |
geomacy
left a comment
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.
LGTM.
I tested this with a catalog
brooklyn.catalog:
bundle: my-test
version: 0.0.1-SNAPSHOT
id: my-test
name: TTest
items:
- id: TypeA
itemType: entity
item:
type: org.apache.brooklyn.entity.stock.BasicEntity
brooklyn.parameters:
- name: red
type: string
- name: green
type: string
- name: blue
type: string
constraints:
- requiredUnlessAnyOf:
- red
- green
- id: TypeB
itemType: entity
item:
type: org.apache.brooklyn.entity.stock.BasicEntity
brooklyn.parameters:
- name: red
type: string
- name: green
type: string
- name: blue
type: string
constraints:
- forbiddenUnlessAnyOf:
- red
- greenand deployed assorted test applications as below with the results indicated:
name: test1
location: localhost
services:
- type: TypeAError deploying:
Application deployment failed
Error launching blueprint: Error configuring Basic Entity: [blue:requiredUnlessAnyOf("red", "green")]: ConstraintViolationException: Error configuring Basic Entity: [blue:requiredUnlessAnyOf("red", "green")]
= SUCCESS
name: test2
location: localhost
services:
- type: TypeA
brooklyn.config:
red: yesDeployed OK = SUCCESS
name: test2b
location: localhost
services:
- type: TypeA
brooklyn.config:
green: yesDeployed OK = SUCCESS
name: test3
location: localhost
services:
- type: TypeA
brooklyn.config:
blue: yesDeployed OK = SUCCESS!
name: test4
location: localhost
services:
- type: TypeBDeployed OK = SUCCESS!
name: test5
location: localhost
services:
- type: TypeB
brooklyn.config:
blue: yesError deploying:
Application deployment failed
Error launching blueprint: Invalid value for blue[ConfigKey:java.lang.String] on BasicEntityImpl{id=frgzvs3cd4} (yes); it should satisfy forbiddenUnlessAnyOf("red", "green"): ConstraintViolationException: Invalid value for blue[ConfigKey:java.lang.String] on BasicEntityImpl{id=frgzvs3cd4} (yes); it should satisfy forbiddenUnlessAnyOf("red", "green")
= SUCCESS
name: test6
location: localhost
services:
- type: TypeB
brooklyn.config:
red: yes
blue: yesDeployed OK = success
name: test6b
location: localhost
services:
- type: TypeB
brooklyn.config:
green: yes
blue: yesDeployed OK = SUCCESS
name: test7
location: localhost
services:
- type: TypeB
brooklyn.config:
someOtherArbitraryKey: yes
blue: yesDeployment failed:
Application deployment failed
Error launching blueprint: Invalid value for blue[ConfigKey:java.lang.String] on BasicEntityImpl{id=pr5xdyhrzw} (yes); it should satisfy forbiddenUnlessAnyOf("red", "green"): ConstraintViolationException: Invalid value for blue[ConfigKey:java.lang.String] on BasicEntityImpl{id=pr5xdyhrzw} (yes); it should satisfy forbiddenUnlessAnyOf("red", "green")
= SUCCESS
I'd say it's worth checking the above but I think the new constraints are working as advertised.
I agree with @kemitix that the tests are a bit cryptic, but on the other hand lots of the tests in Brooklyn are pretty cryptic so I wouldn't let that hold this PR up. I would merge this PR myself, but, @aledsage, it might at least be worth the addition of a TODO comment to recommend making these a little clearer to read. I leave it up to you, I'm happy for this to be merged either way.
|
Oh by the way I had to jump through a hoop or two to get Brooklyn built with this - I was initially getting build errors from oddly when I did it worked, and then when I went back to the top and resumed the original build, that finally passed. What's that all about? |
|
Will merge this |
No description provided.