You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by ahgittin <gi...@git.apache.org> on 2018/09/22 00:46:45 UTC
[GitHub] brooklyn-ui pull request #72: More constraints
GitHub user ahgittin opened a pull request:
https://github.com/apache/brooklyn-ui/pull/72
More constraints
Adds UI support for constraints introduced in https://github.com/apache/brooklyn-server/pull/999
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ahgittin/brooklyn-ui more-constraints
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/brooklyn-ui/pull/72.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #72
----
commit eeb17a0ec2ae622201f97928212cf106b0fd2e4a
Author: Alex Heneveld <al...@...>
Date: 2018-09-21T15:42:52Z
pass the model to config filters
and for "required" include all which have issues recorded against them
commit bd41dce23e38194e6134ae9c5379c513a7e0a25f
Author: Alex Heneveld <al...@...>
Date: 2018-09-22T00:27:36Z
add {forbidden,required}{If,Unless} constraints
also keep constraints as a list, not a map (eg if multiple forbiddenIfs), and update checks to expect json
----
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r220599366
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -275,20 +275,54 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
return $q((resolve) => {
if (entity.miscData.has('config')) {
entity.miscData.get('config')
- .filter(config => config.constraints && Object.keys(config.constraints).length > 0)
+ .filter(config => config.constraints && config.constraints.length > 0)
.forEach(config => {
- for (let [key, constraint] of Object.entries(config.constraints) ) {
+ for (let constraintO of config.constraints) {
let message = null;
+ let key = null, args = null;
+ if (constraintO instanceof String) {
+ key = constraintO;
+ } else if (Object.keys(constraintO).length==1) {
+ key = Object.keys(constraintO)[0];
+ args = constraintO[key];
+ } else {
+ $log.warn("Unknown constraint object", constraintO);
+ key = constraintO;
+ }
+ let val = (k) => entity.config.get(k || config.name);
+ let isSet = (k) => entity.config.has(k || config.name) && angular.isDefined(val(k));
+ let hasDefault = () => angular.isDefined(config.defaultValue);
switch (key) {
case 'Predicates.notNull()':
case 'required':
- if (!angular.isDefined(config.defaultValue) && (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)))) {
+ if (!isSet() && !hasDefault() && val()!='') {
+ // "required" also means that it must not be the empty string
message = `<samp>${config.name}</samp> is required`;
}
break;
case 'regex':
- if (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)) || !(new RegExp(constraint).test(entity.config.get(config.name)))) {
- message = `<samp>${config.name}</samp> does not match the required format: <samp>${config.constraints.regex}</samp>`;
+ if (isSet() && !(new RegExp(args).test(val))) {
--- End diff --
confirmed verbally w aled -- good to merge
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r219831859
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -275,10 +275,20 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
return $q((resolve) => {
if (entity.miscData.has('config')) {
entity.miscData.get('config')
- .filter(config => config.constraints && Object.keys(config.constraints).length > 0)
+ .filter(config => config.constraints && config.constraints.length > 0)
.forEach(config => {
- for (let [key, constraint] of Object.entries(config.constraints) ) {
+ for (let constraintO of config.constraints) {
--- End diff --
`s/contraint0/constraint`
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r219853840
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -275,10 +275,20 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
return $q((resolve) => {
if (entity.miscData.has('config')) {
entity.miscData.get('config')
- .filter(config => config.constraints && Object.keys(config.constraints).length > 0)
+ .filter(config => config.constraints && config.constraints.length > 0)
.forEach(config => {
- for (let [key, constraint] of Object.entries(config.constraints) ) {
+ for (let constraintO of config.constraints) {
--- End diff --
deliberately `constraintO` to indicate `constraint-object`. don't mind if someone wants to use different var names but don't think it's necessary.
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r219855211
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -287,8 +297,28 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
}
break;
case 'regex':
- if (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)) || !(new RegExp(constraint).test(entity.config.get(config.name)))) {
- message = `<samp>${config.name}</samp> does not match the required format: <samp>${config.constraints.regex}</samp>`;
+ if (entity.config.has(config.name) && angular.isDefined(entity.config.get(config.name)) && !(new RegExp(args).test(entity.config.get(config.name)))) {
+ message = `<samp>${config.name}</samp> does not match the required format: <samp>${args}</samp>`;
+ }
+ break;
+ case 'forbiddenIf':
+ if (entity.config.get(config.name) && entity.config.get(args)) {
--- End diff --
yes, these probably should be `isSet(key)` where we introduce `isSet` to mean `config.has(key) && isDefined(config.get(key))` (as used in regex)
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r219920469
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -275,20 +275,54 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
return $q((resolve) => {
if (entity.miscData.has('config')) {
entity.miscData.get('config')
- .filter(config => config.constraints && Object.keys(config.constraints).length > 0)
+ .filter(config => config.constraints && config.constraints.length > 0)
.forEach(config => {
- for (let [key, constraint] of Object.entries(config.constraints) ) {
+ for (let constraintO of config.constraints) {
let message = null;
+ let key = null, args = null;
+ if (constraintO instanceof String) {
+ key = constraintO;
+ } else if (Object.keys(constraintO).length==1) {
+ key = Object.keys(constraintO)[0];
+ args = constraintO[key];
+ } else {
+ $log.warn("Unknown constraint object", constraintO);
+ key = constraintO;
+ }
+ let val = (k) => entity.config.get(k || config.name);
+ let isSet = (k) => entity.config.has(k || config.name) && angular.isDefined(val(k));
+ let hasDefault = () => angular.isDefined(config.defaultValue);
switch (key) {
case 'Predicates.notNull()':
case 'required':
- if (!angular.isDefined(config.defaultValue) && (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)))) {
+ if (!isSet() && !hasDefault() && val()!='') {
+ // "required" also means that it must not be the empty string
message = `<samp>${config.name}</samp> is required`;
}
break;
case 'regex':
- if (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)) || !(new RegExp(constraint).test(entity.config.get(config.name)))) {
- message = `<samp>${config.name}</samp> does not match the required format: <samp>${config.constraints.regex}</samp>`;
+ if (isSet() && !(new RegExp(args).test(val))) {
--- End diff --
Should the regex constraint respect default values? e.g. if a `username` config key has a default of `brooklyn` and a constraint of `regex: [a-z]+`, then I think we should not force the user to override the default. I can imagine other defaults, like a default cidr with a regex enforcing that a user-supplied cidr is in the right format.
---
[GitHub] brooklyn-ui issue #72: More constraints
Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on the issue:
https://github.com/apache/brooklyn-ui/pull/72
NP, will review tomorrow morning @ahgittin
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r220107724
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -275,20 +275,54 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
return $q((resolve) => {
if (entity.miscData.has('config')) {
entity.miscData.get('config')
- .filter(config => config.constraints && Object.keys(config.constraints).length > 0)
+ .filter(config => config.constraints && config.constraints.length > 0)
.forEach(config => {
- for (let [key, constraint] of Object.entries(config.constraints) ) {
+ for (let constraintO of config.constraints) {
let message = null;
+ let key = null, args = null;
+ if (constraintO instanceof String) {
+ key = constraintO;
+ } else if (Object.keys(constraintO).length==1) {
+ key = Object.keys(constraintO)[0];
+ args = constraintO[key];
+ } else {
+ $log.warn("Unknown constraint object", constraintO);
+ key = constraintO;
+ }
+ let val = (k) => entity.config.get(k || config.name);
+ let isSet = (k) => entity.config.has(k || config.name) && angular.isDefined(val(k));
+ let hasDefault = () => angular.isDefined(config.defaultValue);
switch (key) {
case 'Predicates.notNull()':
case 'required':
- if (!angular.isDefined(config.defaultValue) && (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)))) {
+ if (!isSet() && !hasDefault() && val()!='') {
+ // "required" also means that it must not be the empty string
message = `<samp>${config.name}</samp> is required`;
}
break;
case 'regex':
- if (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)) || !(new RegExp(constraint).test(entity.config.get(config.name)))) {
- message = `<samp>${config.name}</samp> does not match the required format: <samp>${config.constraints.regex}</samp>`;
+ if (isSet() && !(new RegExp(args).test(val))) {
--- End diff --
@aledsage you're asking what if the default value is invalid? i think it would be weird to give a user error in that case. it probably is an error, but on the upstream blueprint author's part, not the consumer's part. so i think we shouldn't -- and we don't currently -- test the default value.
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r219833005
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -287,8 +297,28 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
}
break;
case 'regex':
- if (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)) || !(new RegExp(constraint).test(entity.config.get(config.name)))) {
- message = `<samp>${config.name}</samp> does not match the required format: <samp>${config.constraints.regex}</samp>`;
+ if (entity.config.has(config.name) && angular.isDefined(entity.config.get(config.name)) && !(new RegExp(args).test(entity.config.get(config.name)))) {
+ message = `<samp>${config.name}</samp> does not match the required format: <samp>${args}</samp>`;
+ }
+ break;
+ case 'forbiddenIf':
+ if (entity.config.get(config.name) && entity.config.get(args)) {
+ message = `<samp>${config.name}</samp> cannot be set when <samp>${args}</samp> is set`;
+ }
+ break;
+ case 'forbiddenUnless':
+ if (entity.config.get(config.name) && !entity.config.get(args)) {
--- End diff --
Should you check for empty string here?
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/brooklyn-ui/pull/72
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r219833039
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -287,8 +297,28 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
}
break;
case 'regex':
- if (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)) || !(new RegExp(constraint).test(entity.config.get(config.name)))) {
- message = `<samp>${config.name}</samp> does not match the required format: <samp>${config.constraints.regex}</samp>`;
+ if (entity.config.has(config.name) && angular.isDefined(entity.config.get(config.name)) && !(new RegExp(args).test(entity.config.get(config.name)))) {
+ message = `<samp>${config.name}</samp> does not match the required format: <samp>${args}</samp>`;
+ }
+ break;
+ case 'forbiddenIf':
+ if (entity.config.get(config.name) && entity.config.get(args)) {
--- End diff --
Should you check for empty string here?
---
[GitHub] brooklyn-ui issue #72: More constraints
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the issue:
https://github.com/apache/brooklyn-ui/pull/72
@tbouron i think the logic now (after last push) does the best thing for corner cases such as blank string (counts are being set but not acceptable when "required") and false (also counts as being set). also it's a bit simpler.
can you eyeball and merge? i've tested it with the blueprint at https://github.com/apache/brooklyn-server/pull/999#issuecomment-423919250 and it seems to work as expected.
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r219854401
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -287,8 +297,28 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
}
break;
case 'regex':
- if (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)) || !(new RegExp(constraint).test(entity.config.get(config.name)))) {
- message = `<samp>${config.name}</samp> does not match the required format: <samp>${config.constraints.regex}</samp>`;
+ if (entity.config.has(config.name) && angular.isDefined(entity.config.get(config.name)) && !(new RegExp(args).test(entity.config.get(config.name)))) {
--- End diff --
i think the meaning of `regex` should be "_if_ a value is set it must match the regex". that is strictly more usablel (else we cannot express that). can always combine with `required` if you want to make it required _and_ having to match the regex.
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r219832974
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -287,8 +297,28 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
}
break;
case 'regex':
- if (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)) || !(new RegExp(constraint).test(entity.config.get(config.name)))) {
- message = `<samp>${config.name}</samp> does not match the required format: <samp>${config.constraints.regex}</samp>`;
+ if (entity.config.has(config.name) && angular.isDefined(entity.config.get(config.name)) && !(new RegExp(args).test(entity.config.get(config.name)))) {
+ message = `<samp>${config.name}</samp> does not match the required format: <samp>${args}</samp>`;
+ }
+ break;
+ case 'forbiddenIf':
+ if (entity.config.get(config.name) && entity.config.get(args)) {
+ message = `<samp>${config.name}</samp> cannot be set when <samp>${args}</samp> is set`;
+ }
+ break;
+ case 'forbiddenUnless':
+ if (entity.config.get(config.name) && !entity.config.get(args)) {
+ message = `<samp>${config.name}</samp> cannot be set unless <samp>${args}</samp> is set`;
+ }
+ break;
+ case 'requiredIf':
+ if (!entity.config.get(config.name) && entity.config.get(args)) {
--- End diff --
Should you check for empty string here?
---
[GitHub] brooklyn-ui pull request #72: More constraints
Posted by tbouron <gi...@git.apache.org>.
Github user tbouron commented on a diff in the pull request:
https://github.com/apache/brooklyn-ui/pull/72#discussion_r219832729
--- Diff: ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js ---
@@ -287,8 +297,28 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
}
break;
case 'regex':
- if (!entity.config.has(config.name) || !angular.isDefined(entity.config.get(config.name)) || !(new RegExp(constraint).test(entity.config.get(config.name)))) {
- message = `<samp>${config.name}</samp> does not match the required format: <samp>${config.constraints.regex}</samp>`;
+ if (entity.config.has(config.name) && angular.isDefined(entity.config.get(config.name)) && !(new RegExp(args).test(entity.config.get(config.name)))) {
--- End diff --
This is missing the condition where the configuration is not set. In this case, it obviously doesn't match the regex therefore is invalid
---