You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sr...@apache.org on 2013/11/12 00:45:32 UTC

git commit: AMBARI-3745. Provide dialog to create new config-group by overriding property. (srimanth)

Updated Branches:
  refs/heads/trunk 5fe89e76b -> 38f6f48d0


AMBARI-3745. Provide dialog to create new config-group by overriding property. (srimanth)


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

Branch: refs/heads/trunk
Commit: 38f6f48d007fc8982ac457294cc03872b9af4837
Parents: 5fe89e7
Author: Srimanth Gunturi <sg...@hortonworks.com>
Authored: Mon Nov 11 15:31:48 2013 -0800
Committer: Srimanth Gunturi <sg...@hortonworks.com>
Committed: Mon Nov 11 15:45:23 2013 -0800

----------------------------------------------------------------------
 ambari-web/app/messages.js                      |  11 +-
 ambari-web/app/styles/application.less          |   9 ++
 .../common/configs/selectCreateConfigGroup.hbs  |  59 ++++++++
 ambari-web/app/utils/ajax.js                    |  17 +++
 ambari-web/app/utils/config.js                  | 141 +++++++++++++++++++
 .../app/views/common/configs/services_config.js |  46 +++---
 6 files changed, 263 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/38f6f48d/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index da1a4d3..f4ac81c 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -1672,6 +1672,13 @@ Em.I18n.translations = {
 
   'quick.links.error.label': 'Hostname is undefined',
 
-  'contact.administrator': 'Contact System Administrator for more information!'
-
+  'contact.administrator': 'Contact System Administrator for more information!',
+
+  'config.group.selection.dialog.title': 'Configuration Group',
+  'config.group.selection.dialog.option.select': 'Select existing configuration group',
+  'config.group.selection.dialog.option.select.msg': 'Overridden property will be changed for hosts belonging to the selected group.',
+  'config.group.selection.dialog.option.create': 'Create new configuration group',
+  'config.group.selection.dialog.option.create.msg': 'A new configuration group will be created with the given name. Initially there will be no hosts in the group, with only the selected property overridden.',
+  'config.group.selection.dialog.err.name.exists': 'Configuration group with given name already exists',
+  'config.group.selection.dialog.err.create': 'Error creating new configuration group [{0}]'
 };

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/38f6f48d/ambari-web/app/styles/application.less
----------------------------------------------------------------------
diff --git a/ambari-web/app/styles/application.less b/ambari-web/app/styles/application.less
index be613de..7ea9c63 100644
--- a/ambari-web/app/styles/application.less
+++ b/ambari-web/app/styles/application.less
@@ -4859,5 +4859,14 @@ i.icon-asterisks {
       }
     }
   }
+}
 
+#config-group-select-create-dialog {
+  .select-create-config-group-div {
+    margin-left: 20px;
+    margin-bottom: 20px;
+    .message{
+      color: #777;
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/38f6f48d/ambari-web/app/templates/common/configs/selectCreateConfigGroup.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/configs/selectCreateConfigGroup.hbs b/ambari-web/app/templates/common/configs/selectCreateConfigGroup.hbs
new file mode 100644
index 0000000..9414cb0
--- /dev/null
+++ b/ambari-web/app/templates/common/configs/selectCreateConfigGroup.hbs
@@ -0,0 +1,59 @@
+{{!
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+}}
+<div id="config-group-select-create-dialog">
+  <div class="text-warning">
+  {{#if view.parentView.warningMessage}}
+    {{view.parentView.warningMessage}}
+  {{else}}
+    &nbsp;
+  {{/if}}
+  </div>
+  <label class="radio">
+    {{view view.selectConfigGroupRadioButton}} 
+    {{t config.group.selection.dialog.option.select}}
+  </label>
+  <div class="select-create-config-group-div">
+    <span class="btn-group">
+      <button class="btn" {{bindAttr disabled="view.parentView.optionCreateConfigGroup"}}>{{view.parentView.selectedConfigGroup.name}}</button>
+      <button class="btn dropdown-toggle" data-toggle="dropdown" {{bindAttr disabled="view.parentView.optionCreateConfigGroup"}}>
+        <span class="caret"></span>
+      </button>
+      <ul class="dropdown-menu">
+        <!-- available config group menu links -->
+        {{#each configGroup in view.parentView.availableConfigGroups}}
+           <li>
+             <a href="#" {{action "doSelectConfigGroup" configGroup target="view.parentView"}}>
+               {{configGroup.name}}
+             </a>
+           </li>
+        {{/each}}
+      </ul>
+    </span>
+    <div class="message">{{t config.group.selection.dialog.option.select.msg}}</div>
+  </div>
+
+  <label class="radio">
+    {{view view.createConfigGroupRadioButton}}
+    {{t config.group.selection.dialog.option.create}}
+  </label>
+  <div class="select-create-config-group-div">
+    {{view Ember.TextField valueBinding="view.parentView.newConfigGroupName"
+      disabledBinding="view.parentView.optionSelectConfigGroup" class="span5"}}
+    <div class="message">{{t config.group.selection.dialog.option.create.msg}}</div>
+  </div>
+</div>

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/38f6f48d/ambari-web/app/utils/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax.js b/ambari-web/app/utils/ajax.js
index a06b7c3..52cd32e 100644
--- a/ambari-web/app/utils/ajax.js
+++ b/ambari-web/app/utils/ajax.js
@@ -1113,6 +1113,23 @@ var urls = {
         data: JSON.stringify(data.keyValuePair)
       }
     }
+  },
+  'config_groups.create': {
+    'real': '/clusters/{clusterName}/config_groups',
+    'mock': '',
+    'format': function (data) {
+      return {
+        async: false,
+        type: 'POST',
+        data: JSON.stringify([{
+          "ConfigGroup": {
+            "group_name": data.group_name,
+            "tag": data.service_id,
+            "description": data.description
+          }
+        }])
+      }
+    }
   }
 };
 /**

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/38f6f48d/ambari-web/app/utils/config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js
index 3a81b60..3008a10 100644
--- a/ambari-web/app/utils/config.js
+++ b/ambari-web/app/utils/config.js
@@ -974,6 +974,147 @@ App.config = Em.Object.create({
     }
   },
   
+  /**
+   * Launches a dialog where an existing config-group can be selected, or a new
+   * one can be created. This is different than the config-group management
+   * dialog where host membership can be managed.
+   *
+   * The callback will be passed the created/selected config-group in the form
+   * of {id:2, name:'New hardware group'}. In the case of dialog being cancelled,
+   * the callback is provided <code>null</code>
+   *
+   * @param callback  Callback function which is invoked when dialog
+   *  is closed, cancelled or OK is pressed.
+   */
+  launchConfigGroupSelectionCreationDialog : function(serviceId, availableConfigGroups, callback) {
+    var self = this;
+    var selectedConfigGroup = availableConfigGroups && availableConfigGroups.length > 0 ?
+        availableConfigGroups[0] : null;
+    App.ModalPopup.show({
+      classNames: [ 'sixty-percent-width-modal' ],
+      header: Em.I18n.t('config.group.selection.dialog.title'),
+      primary: Em.I18n.t('ok'),
+      secondary: Em.I18n.t('common.cancel'),
+      warningMessage: null,
+      optionSelectConfigGroup: true,
+      optionCreateConfigGroup: function(){
+        return !this.get('optionSelectConfigGroup');
+      }.property('optionSelectConfigGroup'),
+      availableConfigGroups: availableConfigGroups,
+      selectedConfigGroup: selectedConfigGroup,
+      newConfigGroupName: '',
+      onPrimary: function () {
+        if (this.get('optionSelectConfigGroup')) {
+          var selectedConfigGroup = this.get('selectedConfigGroup');
+          this.hide();
+          callback(selectedConfigGroup);
+        } else {
+          var newConfigGroupName = this.get('newConfigGroupName');
+          var newConfigGroup = self.createNewConfigurationGroup(serviceId, newConfigGroupName);
+          if (newConfigGroup.configGroup!=null) {
+            this.hide();
+            newConfigGroup.configGroup.name = newConfigGroupName;
+            callback(newConfigGroup.configGroup);
+          } else {
+            this.set('warningMessage', this.t('config.group.selection.dialog.err.create').format(newConfigGroup.error));
+          }
+        }
+      },
+      onSecondary: function () {
+        this.hide();
+        callback(null);
+      },
+      doSelectConfigGroup: function (event) {
+        var configGroup = event.context;
+        console.log(configGroup);
+        this.set('selectedConfigGroup', configGroup);
+      },
+      validate: function () {
+        var msg = null;
+        var optionSelect = this.get('optionSelectConfigGroup');
+        if (optionSelect) {
+        } else {
+          var nn = this.get('newConfigGroupName');
+          var allCG = this.get('availableConfigGroups');
+          if (nn) {
+            allCG.forEach(function(cg){
+              if(!msg && nn === cg.get('name')) {
+                msg = Em.I18n.t("config.group.selection.dialog.err.name.exists");
+              }
+            });
+          }
+        }
+        this.set('warningMessage', msg);
+      }.observes('newConfigGroupName', 'availableConfigGroups', 'optionSelectConfigGroup'),
+      bodyClass: Ember.View.extend({
+        templateName: require('templates/common/configs/selectCreateConfigGroup'),
+        controllerBinding: 'App.router.mainServiceInfoConfigsController',
+        selectConfigGroupRadioButton: Ember.Checkbox.extend({
+          tagName: 'input',
+          attributeBindings: ['type', 'checked'],
+          checked: function () {
+            return this.get('parentView.parentView.optionSelectConfigGroup');
+          }.property('parentView.parentView.optionSelectConfigGroup'),
+          type: 'radio',
+          click: function () {
+            this.set('parentView.parentView.optionSelectConfigGroup', true);
+          }
+        }),
+        createConfigGroupRadioButton: Ember.Checkbox.extend({
+          tagName: 'input',
+          attributeBindings: ['type', 'checked'],
+          checked: function () {
+            return !this.get('parentView.parentView.optionSelectConfigGroup');
+          }.property('parentView.parentView.optionSelectConfigGroup'),
+          type: 'radio',
+          click: function () {
+            this.set('parentView.parentView.optionSelectConfigGroup', false);
+          }
+        })
+      })
+    });
+  },
+
+  /**
+   * Creates a new config-group for a service.
+   *
+   * @param serviceId   Service for which this group has to be created
+   * @param configGroupName    Name of the new config-group
+   * @return  Returns the created config-group or error as
+   *        { configGroup: {id:4}, error: {...}}
+   */
+  createNewConfigurationGroup: function (serviceId, configGroupName) {
+    var newConfigGroupData = {
+        configGroup: null,
+        error: null
+    };
+    var sendData = {
+      name: 'config_groups.create',
+      data: {
+        'group_name': configGroupName,
+        'service_id': serviceId,
+        'description': "New configuration group created on " + new Date().toDateString()
+      },
+      success: 'successFunction',
+      error: 'errorFunction',
+      successFunction: function(response){
+        newConfigGroupData.configGroup = response.resources[0].ConfigGroup;
+        newConfigGroupData.error = null;
+      },
+      errorFunction: function(request, ajaxOptions, error){
+        newConfigGroupData.configGroup = null;
+        try{
+          var errResponse = JSON.parse(request.responseText);
+          error = errResponse.message;
+        }catch(e){
+        }
+        newConfigGroupData.error = request.status + ": " + error;
+      }
+    };
+    sendData.sender = sendData;
+    App.ajax.send(sendData);
+    return newConfigGroupData;
+  },
 
   /**
    * Gets all the configuration-groups for the given service.

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/38f6f48d/ambari-web/app/views/common/configs/services_config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/services_config.js b/ambari-web/app/views/common/configs/services_config.js
index 030e673..748c51e 100644
--- a/ambari-web/app/views/common/configs/services_config.js
+++ b/ambari-web/app/views/common/configs/services_config.js
@@ -488,24 +488,34 @@ App.ServiceConfigsByCategoryView = Ember.View.extend({
 
   createOverrideProperty: function (event) {
     var serviceConfigProperty = event.contexts[0];
-    var overrides = serviceConfigProperty.get('overrides');
-    if (!overrides) {
-      overrides = [];
-      serviceConfigProperty.set('overrides', overrides);
-    }
-
-    // create new override with new value
-    var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
-    newSCP.set('value', '');
-    newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
-    newSCP.set('parentSCP', serviceConfigProperty);
-    newSCP.set('selectedHostOptions', Ember.A([]));
-    console.debug("createOverrideProperty(): Added:", newSCP, " to main-property:", serviceConfigProperty);
-    overrides.pushObject(newSCP);
-
-    // Launch override window
-    var dummyEvent = {contexts: [newSCP]};
-    this.showOverrideWindow(dummyEvent);
+    // Launch dialog to pick/create Config-group
+    var serviceConfigGroups = [];
+    App.config.launchConfigGroupSelectionCreationDialog(this.get('service.serviceName'), 
+        serviceConfigGroups, function(selectedConfigGroup){
+      console.log("launchConfigGroupSelectionCreationDialog(): Selected/Created:", selectedConfigGroup);
+      if (selectedConfigGroup) {
+        // TODO - show configurations for this new config-group
+//        var overrides = serviceConfigProperty.get('overrides');
+//        if (!overrides) {
+//          overrides = [];
+//          serviceConfigProperty.set('overrides', overrides);
+//        }
+//        // create new override with new value
+//        var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
+//        newSCP.set('value', '');
+//        newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
+//        newSCP.set('parentSCP', serviceConfigProperty);
+//        newSCP.set('selectedHostOptions', Ember.A([]));
+//        console.debug("createOverrideProperty(): Added:", newSCP, " to main-property:", serviceConfigProperty);
+//        overrides.pushObject(newSCP);
+//
+//        // Launch override window
+//        var dummyEvent = {contexts: [newSCP]};
+//        this.showOverrideWindow(dummyEvent);
+      } else {
+        // Cancelled dialog
+      }
+    });
   },
 
   showOverrideWindow: function (event) {