You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2018/11/30 14:10:23 UTC

[1/3] brooklyn-ui git commit: DSL editor: support referencing `brooklyn.parameters`

Repository: brooklyn-ui
Updated Branches:
  refs/heads/master 84a6f7b36 -> 86c69c20f


DSL editor: support referencing `brooklyn.parameters`

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/dc8ee4e0
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/dc8ee4e0
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/dc8ee4e0

Branch: refs/heads/master
Commit: dc8ee4e019ae581db0fe72a4d09890db566c3045
Parents: bf3477b
Author: Aled Sage <al...@gmail.com>
Authored: Wed Nov 21 16:55:24 2018 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Nov 21 16:55:24 2018 +0000

----------------------------------------------------------------------
 .../app/components/dsl-editor/dsl-editor.js     | 12 ++++
 .../providers/blueprint-service.provider.js     | 16 +++++
 .../app/components/util/model/entity.model.js   | 68 +++++++++++++++++++-
 3 files changed, 94 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/dc8ee4e0/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
----------------------------------------------------------------------
diff --git a/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js b/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
index 707560b..6b52e17 100644
--- a/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
+++ b/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
@@ -287,6 +287,18 @@ export function dslEditorDirective($rootScope, $filter, $log, brUtilsGeneral, bl
             };
         });
 
+        let params = entity.miscData.get('parameters').filter(param => param !== definition).map(param => {
+            return {
+                id: param.name,
+                type: DSL_KINDS.CONFIG,
+                entity: entity,
+                name: param.name,
+                description: param.description
+            };
+        });
+        
+        config = config.concat(params);
+
         config = Object.values(entity.getClusterMemberspecEntities()).reduce((acc, spec) => {
             return acc.concat(getConfigItems(spec, definition));
         }, config);

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/dc8ee4e0/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
----------------------------------------------------------------------
diff --git a/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js b/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
index 69ba3f6..1434f64 100644
--- a/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
+++ b/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
@@ -245,11 +245,13 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
             entity.miscData.set('traits', []);
             deferred.resolve(entity);
             addUnlistedConfigKeysDefinitions(entity);
+            addUnlistedParameterDefinitions(entity);
         } else {
             entity.miscData.set('sensors', []);
             entity.miscData.set('traits', []);
             deferred.resolve(entity);
             addUnlistedConfigKeysDefinitions(entity);
+            addUnlistedParameterDefinitions(entity);
         }
 
         return deferred.promise;
@@ -512,6 +514,16 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
         entity.miscData.set('config', allConfig);
     }
 
+    function addUnlistedParameterDefinitions(entity) {
+        let allParams = entity.miscData.get('parameters') || [];
+        entity.parameters.forEach((param) => {
+            if (!allParams.some((e) => e.name === param.name)) {
+                allParams.push(param);
+            }
+        });
+        entity.miscData.set('parameters', allParams);
+    }
+
     function populateEntityFromApiSuccess(entity, data) {
         entity.clearIssues({group: 'type'});
         entity.type = data.symbolicName;
@@ -523,6 +535,7 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
         });
         entity.miscData.set('typeName', data.displayName || data.symbolicName);
         entity.miscData.set('config', data.config || []);
+        entity.miscData.set('parameters', data.parameters || []);
         entity.miscData.set('sensors', data.sensors || []);
         entity.miscData.set('traits', data.supertypes || []);
         entity.miscData.set('tags', data.tags || []);
@@ -533,6 +546,7 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
         entity.miscData.set('ui-composer-hints', uiHints);
         entity.miscData.set('virtual', data.virtual || null);
         addUnlistedConfigKeysDefinitions(entity);
+        addUnlistedParameterDefinitions(entity);
         return entity;
     }
     function mergeAppendingLists(dst, src) {
@@ -552,11 +566,13 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
         entity.addIssue(Issue.builder().group('type').message($sce.trustAsHtml(`Type <samp>${entity.type + (entity.hasVersion ? ':' + entity.version : '')}</samp> does not exist`)).build());
         entity.miscData.set('typeName', entity.type || '');
         entity.miscData.set('config', []);
+        entity.miscData.set('parameters', []);
         entity.miscData.set('sensors', []);
         entity.miscData.set('traits', []);
         entity.miscData.set('virtual', null);
         entity.icon = typeNotFoundIcon;
         addUnlistedConfigKeysDefinitions(entity);
+        addUnlistedParameterDefinitions(entity);
         return entity;
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/dc8ee4e0/ui-modules/blueprint-composer/app/components/util/model/entity.model.js
----------------------------------------------------------------------
diff --git a/ui-modules/blueprint-composer/app/components/util/model/entity.model.js b/ui-modules/blueprint-composer/app/components/util/model/entity.model.js
index 9643c66..7d04410 100644
--- a/ui-modules/blueprint-composer/app/components/util/model/entity.model.js
+++ b/ui-modules/blueprint-composer/app/components/util/model/entity.model.js
@@ -23,9 +23,9 @@ const MEMBERSPEC_REGEX = /^(\w+\.)*[mM]ember[sS]pec$/;
 const FIRST_MEMBERSPEC_REGEX = /^(\w+\.)*first[mM]ember[sS]pec$/;
 // TODO ideally we'd just look at type EntitySpec, not key name, but for now look at keyname, anything ending memberSpec
 const ANY_MEMBERSPEC_REGEX = /^(\w+\.)*(\w*)[mM]ember[sS]pec$/;
-const RESERVED_KEY_REGEX = /(^children$|^services$|^locations?$|^brooklyn\.config$|^brooklyn\.enrichers$|^brooklyn\.policies$)/;
+const RESERVED_KEY_REGEX = /(^children$|^services$|^locations?$|^brooklyn\.config$|^brooklyn\.parameters$|^brooklyn\.enrichers$|^brooklyn\.policies$)/;
 const FIELD = {
-    SERVICES: 'services', CHILDREN: 'brooklyn.children', CONFIG: 'brooklyn.config', LOCATION: 'location',
+    SERVICES: 'services', CHILDREN: 'brooklyn.children', CONFIG: 'brooklyn.config', PARAMETERS: 'brooklyn.parameters', LOCATION: 'location',
     POLICIES: 'brooklyn.policies', ENRICHERS: 'brooklyn.enrichers', TYPE: 'type', NAME: 'name', ID: 'id',
     // This field is not part of the Brooklyn blueprint spec but used to store information about the composer, e.g. X,Y coordinates, virtual items, etc
     COMPOSER_META: 'brooklyn.composer.metadata'
@@ -50,6 +50,7 @@ const ID = new WeakMap();
 const PARENT = new WeakMap();
 const METADATA = new WeakMap();
 const CONFIG = new WeakMap();
+const PARAMETERS = new WeakMap();
 const CHILDREN = new WeakMap();
 const LOCATIONS = new WeakMap();
 const POLICIES = new WeakMap();
@@ -69,6 +70,7 @@ export class Entity {
     constructor() {
         ID.set(this, Math.random().toString(36).slice(2));
         CONFIG.set(this, new Map());
+        PARAMETERS.set(this, new Map());
         METADATA.set(this, new Map());
         ENRICHERS.set(this, new Map());
         POLICIES.set(this, new Map());
@@ -321,6 +323,10 @@ export class Entity {
         return CONFIG.get(this);
     }
 
+    get parameters() {
+        return PARAMETERS.get(this);
+    }
+
     get metadata() {
         return METADATA.get(this);
     }
@@ -474,6 +480,14 @@ export class Entity {
     }
 
     /**
+     * Has {Entity} got parameters
+     * @returns {boolean}
+     */
+    hasParameters() {
+        return PARAMETERS.get(this).size > 0;
+    }
+
+    /**
      * Has {Entity} got a location
      * @returns {boolean}
      */
@@ -544,6 +558,9 @@ Entity.prototype.setChildrenFromJson = setChildrenFromJson;
 Entity.prototype.getConfigAsJson = getConfigAsJson;
 Entity.prototype.setConfigFromJson = setConfigFromJson;
 
+Entity.prototype.getParametersAsArray = getParametersAsArray;
+Entity.prototype.setParametersFromJson = setParametersFromJson;
+
 Entity.prototype.getMetadataAsJson = getMetadataAsJson;
 Entity.prototype.setMetadataFromJson = setMetadataFromJson;
 
@@ -552,8 +569,10 @@ Entity.prototype.setPoliciesFromJson = setPoliciesFromJson;
 
 Entity.prototype.getData = getData;
 Entity.prototype.addConfig = addConfig;
+Entity.prototype.addParameter = addParameter;
 Entity.prototype.addMetadata = addMetadata;
 Entity.prototype.removeConfig = removeConfig;
+Entity.prototype.removeParameter = removeParameter;
 Entity.prototype.removeMetadata = removeMetadata;
 Entity.prototype.isCluster = isCluster;
 Entity.prototype.isMemberSpec = isMemberSpec;
@@ -596,6 +615,13 @@ function addConfig(key, value) {
     }
 }
 
+function addParameter(param) {
+    let key = param.name;
+    PARAMETERS.get(this).set(key, param);
+    this.touch();
+    return this;
+}
+
 function addMetadata(key, value) {
     if (!RESERVED_KEY_REGEX.test(key)) {
         METADATA.get(this).set(key, value);
@@ -619,6 +645,17 @@ function removeConfig(key) {
 }
 
 /**
+ * Remove an entry from brooklyn.parameters
+ * @param {string} key
+ * @returns {Entity}
+ */
+function removeParameter(key) {
+    PARAMETERS.get(this).delete(key);
+    this.touch();
+    return this;
+}
+
+/**
  * Remove an entry from the entity metadata
  * @param {string} key
  * @returns {Entity}
@@ -734,6 +771,9 @@ function getData(includeChildren = true) {
     if (this.hasConfig()) {
         result[FIELD.CONFIG] = this.getConfigAsJson();
     }
+    if (this.hasParameters()) {
+        result[FIELD.PARAMETERS] = this.getParametersAsArray();
+    }
     if (this.hasLocation()) {
         result.location = LOCATIONS.get(this);
     }
@@ -845,6 +885,7 @@ function resetEntity() {
     ID.set(this, Math.random().toString(36).slice(2));
     this.removeLocation();
     CONFIG.set(this, new Map());
+    PARAMETERS.set(this, new Map());
     METADATA.set(this, new Map());
     ENRICHERS.set(this, new Map());
     POLICIES.set(this, new Map());
@@ -896,6 +937,9 @@ function setEntityFromJson(incomingModel, setChildren = true) {
             case FIELD.CONFIG:
                 self.setConfigFromJson(incomingModel[key]);
                 break;
+            case FIELD.PARAMETERS:
+                self.setParametersFromJson(incomingModel[key]);
+                break;
             case FIELD.ENRICHERS:
                 self.setEnrichersFromJson(incomingModel[key]);
                 break;
@@ -964,6 +1008,22 @@ function setConfigFromJson(incomingModel) {
     this.touch();
 }
 
+/**
+ * Set brooklyn.parameters from JSON {Array}
+ * @param {Array} incomingModel
+ */
+function setParametersFromJson(incomingModel) {
+    if (!Array.isArray(incomingModel)) {
+        throw new Error('Model parse error ... cannot add parameters as it must be an array')
+    }
+    PARAMETERS.get(this).clear();
+    var self = this;
+    incomingModel.map((param)=> {
+        self.addParameter(param);
+    });
+    this.touch();
+}
+
 
 function setMetadataFromJson(incomingModel) {
     METADATA.get(this).clear();
@@ -1022,6 +1082,10 @@ function getConfigAsJson() {
     return cleanForJson(CONFIG.get(this), -1);
 }
 
+function getParametersAsArray() {
+    return Array.from(PARAMETERS.get(this).values());
+}
+
 /* "cleaning" here means:  Dsl objects are toStringed, to the given depth (or infinite if depth<0);
  * and entries in Map that are memberspec are unwrapped.
  * previously we also stringified maps/lists but that seemed pointless, and it was lossy and buggy.


[2/3] brooklyn-ui git commit: This closes #112

Posted by he...@apache.org.
This closes #112


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/52d2f84e
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/52d2f84e
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/52d2f84e

Branch: refs/heads/master
Commit: 52d2f84e2591260cd137c44a77ee661467b521f4
Parents: 84a6f7b dc8ee4e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Nov 30 14:06:09 2018 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Nov 30 14:06:09 2018 +0000

----------------------------------------------------------------------
 .../app/components/dsl-editor/dsl-editor.js     | 12 ++++
 .../providers/blueprint-service.provider.js     | 16 +++++
 .../app/components/util/model/entity.model.js   | 68 +++++++++++++++++++-
 3 files changed, 94 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/52d2f84e/ui-modules/blueprint-composer/app/components/dsl-editor/dsl-editor.js
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/52d2f84e/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
----------------------------------------------------------------------


[3/3] brooklyn-ui git commit: remove load-parameter-from-definition as it is not necessary, per PR comments

Posted by he...@apache.org.
remove load-parameter-from-definition as it is not necessary, per PR comments


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/86c69c20
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/86c69c20
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/86c69c20

Branch: refs/heads/master
Commit: 86c69c20f1f220c4f8ab7ef0ccfff4c7e2f7d8ae
Parents: 52d2f84
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Nov 30 14:09:33 2018 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Nov 30 14:09:33 2018 +0000

----------------------------------------------------------------------
 .../providers/blueprint-service.provider.js         | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/86c69c20/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
----------------------------------------------------------------------
diff --git a/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js b/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
index 7cc63b0..be572d7 100644
--- a/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
+++ b/ui-modules/blueprint-composer/app/components/providers/blueprint-service.provider.js
@@ -253,13 +253,11 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
             entity.miscData.set('traits', []);
             deferred.resolve(entity);
             addUnlistedConfigKeysDefinitions(entity);
-            addUnlistedParameterDefinitions(entity);
         } else {
             entity.miscData.set('sensors', []);
             entity.miscData.set('traits', []);
             deferred.resolve(entity);
             addUnlistedConfigKeysDefinitions(entity);
-            addUnlistedParameterDefinitions(entity);
         }
 
         return deferred.promise;
@@ -527,6 +525,8 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
     }
 
     function addUnlistedConfigKeysDefinitions(entity) {
+        // there may be config in the entity definition not in the model; if so, add them.
+        // parameters will all be defined in this model so no need to do this for them. 
         let allConfig = entity.miscData.get('config') || [];
         entity.config.forEach((value, key) => {
             if (!allConfig.some((e) => e.name === key)) {
@@ -536,16 +536,6 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
         entity.miscData.set('config', allConfig);
     }
 
-    function addUnlistedParameterDefinitions(entity) {
-        let allParams = entity.miscData.get('parameters') || [];
-        entity.parameters.forEach((param) => {
-            if (!allParams.some((e) => e.name === param.name)) {
-                allParams.push(param);
-            }
-        });
-        entity.miscData.set('parameters', allParams);
-    }
-
     function populateEntityFromApiSuccess(entity, data) {
         entity.clearIssues({group: 'type'});
         entity.type = data.symbolicName;
@@ -568,7 +558,6 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
         entity.miscData.set('ui-composer-hints', uiHints);
         entity.miscData.set('virtual', data.virtual || null);
         addUnlistedConfigKeysDefinitions(entity);
-        addUnlistedParameterDefinitions(entity);
         return entity;
     }
     function mergeAppendingLists(dst, src) {
@@ -594,7 +583,6 @@ function BlueprintService($log, $q, $sce, paletteApi, iconGenerator, dslService)
         entity.miscData.set('virtual', null);
         entity.icon = typeNotFoundIcon;
         addUnlistedConfigKeysDefinitions(entity);
-        addUnlistedParameterDefinitions(entity);
         return entity;
     }