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 2014/11/19 18:48:06 UTC

[11/13] incubator-brooklyn git commit: Update the Add Application wizard to send CAMP Yaml to server.

Update the Add Application wizard to send CAMP Yaml to server.

Previously a deprecated ApplicationSpec format was used which assumes the catalog items have java types which the YAML catalog items do not have.


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

Branch: refs/heads/master
Commit: f8c44b831adcc1212323defe9a15b7dd7370b119
Parents: fbfd78f
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Nov 19 18:36:24 2014 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Nov 19 19:28:16 2014 +0200

----------------------------------------------------------------------
 .../assets/js/view/application-add-wizard.js    | 79 ++++++++++++--------
 1 file changed, 49 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f8c44b83/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js b/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js
index 51724d3..d0bf8ec 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js
@@ -49,6 +49,35 @@ define([
     function setEnablement(obj, isEnabled) {
         obj.attr("disabled", !isEnabled)
     }
+    
+    function specToCAMP(spec) {
+        var services;
+        if (spec.type) {
+            services = [entityToCAMP(spec)];
+        } else if (spec.entities) {
+            services = [];
+            var entities = spec.entities;
+            for (var i = 0; i < entities.length; i++) {
+                services.push(entityToCAMP(entities[i]));
+            }
+        }
+
+        return {
+            name: spec.name,
+            locations: spec.locations,
+            services: services
+        };
+
+    }
+
+    function entityToCAMP(entity) {
+        return {
+            name: entity.name,
+            type: entity.type,
+            "brooklyn.config": entity.config
+        };
+    }
+
 
     var ModalWizard = Backbone.View.extend({
         tagName:'div',
@@ -166,37 +195,27 @@ define([
             var $modal = $('.add-app #modal-container .modal')
             $modal.fadeTo(500,0.5);
             
+            var yaml;
             if (this.model.mode == "yaml") {
-                $.ajax({
-                    url:'/v1/applications',
-                    type:'post',
-                    contentType:'application/yaml',
-                    processData:false,
-                    data:this.model.yaml,
-                    success:function (data) {
-                        that.onSubmissionComplete(true, data, $modal)
-                    },
-                    error:function (data) {
-                        that.onSubmissionComplete(false, data, $modal)
-                    }
-                })
-
+                yaml = this.model.yaml;
             } else {
-                $.ajax({
-                    url:'/v1/applications',
-                    type:'post',
-                    contentType:'application/json',
-                    processData:false,
-                    data:JSON.stringify(this.model.spec.toJSON()),
-                    success:function (data) {
-                        that.onSubmissionComplete(true, data, $modal)
-                    },
-                    error:function (data) {
-                        that.onSubmissionComplete(false, data, $modal)
-                    }
-                })
+                yaml = JSON.stringify(specToCAMP(this.model.spec.toJSON()));
             }
-            
+
+            $.ajax({
+                url:'/v1/applications',
+                type:'post',
+                contentType:'application/yaml',
+                processData:false,
+                data:yaml,
+                success:function (data) {
+                    that.onSubmissionComplete(true, data, $modal)
+                },
+                error:function (data) {
+                    that.onSubmissionComplete(false, data, $modal)
+                }
+            });
+
             return false
         },
         onSubmissionComplete: function(succeeded, data, $modal) {
@@ -222,7 +241,7 @@ define([
                 that.steps[that.currentStep].view.showFailure(summary)
             }
         },
-        
+
         prevStep:function () {
             this.currentStep -= 1
             this.renderCurrentStep()
@@ -701,7 +720,7 @@ define([
             if (!this.model.spec.get("config") || _.keys(this.model.spec.get("config")).length==0) {
                 delete this.model.spec.attributes["config"]
             }
-            this.$('#app-summary').val(Util.toTextAreaString(this.model.spec))
+            this.$('#app-summary').val(Util.toTextAreaString(specToCAMP(this.model.spec.toJSON())))
         },
         render:function () {
             this.delegateEvents()