You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by on...@apache.org on 2014/05/20 15:06:33 UTC
git commit: AMBARI-5826. Create mapper for Slider apps view status.
(onechiporenko)
Repository: ambari
Updated Branches:
refs/heads/trunk 82ffda436 -> 9e92faa56
AMBARI-5826. Create mapper for Slider apps view status. (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9e92faa5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9e92faa5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9e92faa5
Branch: refs/heads/trunk
Commit: 9e92faa563657e2bffc21c3f9d0d5cbef5b79d59
Parents: 82ffda4
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Tue May 20 16:04:03 2014 +0300
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Tue May 20 16:06:25 2014 +0300
----------------------------------------------------------------------
.../app/assets/data/resource/status_false.json | 7 ++
.../app/assets/data/resource/status_true.json | 5 ++
.../src/main/resources/ui/app/initialize.js | 83 ++++++++++++++------
.../ui/app/mappers/application_status.js | 83 ++++++++++++++++++++
.../src/main/resources/ui/app/mappers/mapper.js | 63 +++++++++++++++
.../resources/ui/app/mixins/run_periodically.js | 78 ++++++++++++++++++
6 files changed, 295 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9e92faa5/contrib/views/slider/src/main/resources/ui/app/assets/data/resource/status_false.json
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/assets/data/resource/status_false.json b/contrib/views/slider/src/main/resources/ui/app/assets/data/resource/status_false.json
new file mode 100644
index 0000000..2fc22dc
--- /dev/null
+++ b/contrib/views/slider/src/main/resources/ui/app/assets/data/resource/status_false.json
@@ -0,0 +1,7 @@
+{
+ "version": "0.0.1-SNAPSHOT",
+ "viewEnabled": false,
+ "viewErrors": [
+ "Slider applications view requires HDFS service to be started"
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/9e92faa5/contrib/views/slider/src/main/resources/ui/app/assets/data/resource/status_true.json
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/assets/data/resource/status_true.json b/contrib/views/slider/src/main/resources/ui/app/assets/data/resource/status_true.json
new file mode 100644
index 0000000..409bb2f
--- /dev/null
+++ b/contrib/views/slider/src/main/resources/ui/app/assets/data/resource/status_true.json
@@ -0,0 +1,5 @@
+{
+ "version": "0.0.1-SNAPSHOT",
+ "viewEnabled": true,
+ "viewErrors": []
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/9e92faa5/contrib/views/slider/src/main/resources/ui/app/initialize.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/initialize.js b/contrib/views/slider/src/main/resources/ui/app/initialize.js
index 0e9541a..1d67664 100755
--- a/contrib/views/slider/src/main/resources/ui/app/initialize.js
+++ b/contrib/views/slider/src/main/resources/ui/app/initialize.js
@@ -22,38 +22,73 @@ window.App = require('config/app');
require('config/router');
require('config/store');
require('translations');
+require('mappers/mapper');
-App.reopen({
- /**
- * @type {string}
- */
- name: 'SLIDER',
+App.initializer({
+ name: "preload",
- /**
- * @type {string}
- */
- version: '1.0.0',
+ initialize: function(container, application) {
- /**
- * @type {string}
- */
- instance: 'SLIDER_1',
+ application.reopen({
+ /**
+ * Test mode is automatically enabled if running on brunch server
+ * @type {bool}
+ */
+ testMode: (location.port == '3333'),
- /**
- * API url for Slider
- * Format:
- * <code>/api/v1/views/[VIEW_NAME]/versions/[VERSION]/instances/[INSTANCE_NAME]/</code>
- * @type {string}
- */
- urlPrefix: function() {
- return '/api/v1/views/%@1/versions/%@2/instances/%@3/'.fmt(this.get('name'), this.get('version'), this.get('instance'));
- }.property('name', 'version', 'instance')
+ /**
+ * @type {string}
+ */
+ name: 'SLIDER',
+
+ /**
+ * Slider version
+ * @type {string}
+ */
+ version: '1.0.0',
+
+ /**
+ * Version of SLIDER_1 resource
+ * @type {string}
+ */
+ resourcesVersion: '',
+
+ /**
+ * @type {string}
+ */
+ instance: 'SLIDER_1',
+
+ /**
+ * API url for Slider
+ * Format:
+ * <code>/api/v1/views/[VIEW_NAME]/versions/[VERSION]/instances/[INSTANCE_NAME]/</code>
+ * @type {string}
+ */
+ urlPrefix: function() {
+ return '/api/v1/views/%@1/versions/%@2/instances/%@3/'.fmt(this.get('name'), this.get('version'), this.get('instance'));
+ }.property('name', 'version', 'instance'),
+
+ /**
+ * Should Slider View be enabled
+ * @type {bool}
+ */
+ viewEnabled: true,
+
+ /**
+ * List of errors
+ * @type {string[]}
+ */
+ viewErrors: []
+
+ });
+ application.ApplicationStatusMapper.loop('load');
+ }
});
// Load all modules in order automagically. Ember likes things to work this
// way so everything is in the App.* namespace.
var folderOrder = [
- 'initializers', 'mixins', 'routes', 'models',
+ 'initializers', 'mixins', 'routes', 'models', 'mappers',
'views', 'controllers', 'helpers',
'templates', 'components'
];
@@ -64,4 +99,4 @@ folderOrder.forEach(function(folder) {
}).forEach(function(module) {
require(module);
});
-});
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/9e92faa5/contrib/views/slider/src/main/resources/ui/app/mappers/application_status.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/mappers/application_status.js b/contrib/views/slider/src/main/resources/ui/app/mappers/application_status.js
new file mode 100644
index 0000000..930207a
--- /dev/null
+++ b/contrib/views/slider/src/main/resources/ui/app/mappers/application_status.js
@@ -0,0 +1,83 @@
+/**
+ * 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.
+ */
+
+/**
+ * Mapper for SLIDER_1 status
+ * Save mapped data to App properties
+ * @type {App.Mapper}
+ */
+App.ApplicationStatusMapper = App.Mapper.createWithMixins(App.RunPeriodically, {
+
+ /**
+ * Url suffix
+ * Used with <code>App.urlPrefix</code>
+ * @type {string}
+ */
+ urlSuffix: 'resources/status',
+
+ /**
+ * Map for parsing JSON received from server
+ * Format:
+ * <code>
+ * {
+ * key1: 'path1',
+ * key2: 'path2',
+ * key3: 'path3'
+ * }
+ * </code>
+ * Keys - names for properties in App
+ * Values - pathes in JSON
+ * @type {object}
+ */
+ map: {
+ viewEnabled: 'viewEnabled',
+ viewErrors: 'viewErrors',
+ resourcesVersion: 'version'
+ },
+
+ /**
+ * Load data from <code>App.urlPrefix + this.urlSuffix</code> one time
+ * @method load
+ * @return {$.ajax}
+ */
+ load: function() {
+ console.log('App.ApplicationStatusMapper loading data');
+ var self = this,
+ url = App.get('testMode') ? '/data/resource/status_true.json' : App.get('urlPrefix') + this.get('urlSuffix');
+
+ return $.ajax({
+ url: url,
+ async: true,
+ success: function(data) {self.parse(data);}
+ });
+ },
+
+ /**
+ * Parse loaded data according to <code>map</code>
+ * Set <code>App</code> properties
+ * @param {object} data received from server data
+ * @method parse
+ */
+ parse: function(data) {
+ var map = this.get('map');
+ Ember.keys(map).forEach(function(key) {
+ App.set(key, Ember.getWithDefault(data, map[key], ''));
+ });
+ }
+
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/9e92faa5/contrib/views/slider/src/main/resources/ui/app/mappers/mapper.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/mappers/mapper.js b/contrib/views/slider/src/main/resources/ui/app/mappers/mapper.js
new file mode 100644
index 0000000..d5c79a4
--- /dev/null
+++ b/contrib/views/slider/src/main/resources/ui/app/mappers/mapper.js
@@ -0,0 +1,63 @@
+/**
+ * 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.
+ */
+
+/**
+ * Common mapper-object
+ * Extending this object you should implement <code>load</code> and <code>parse</code> methods
+ * @type {Ember.Object}
+ */
+App.Mapper = Ember.Object.extend({
+
+ /**
+ * Url suffix
+ * Used with <code>App.urlPrefix</code>
+ * @type {string}
+ */
+ urlSuffix: '',
+
+ /**
+ * Map for parsing JSON received from server
+ * Format:
+ * <code>
+ * {
+ * key1: 'path1',
+ * key2: 'path2',
+ * key3: 'path3'
+ * }
+ * </code>
+ * Keys - names for properties in object
+ * Values - pathes in JSON
+ * @type {object}
+ */
+ map: {},
+
+ /**
+ * Load data from <code>App.urlPrefix + this.urlSuffix</code>
+ * @method load
+ */
+ load: Ember.required(Function),
+
+ /**
+ * Parse loaded data according to <code>map</code>
+ * Set <code>App</code> properties
+ * @param {object} data received data
+ * @method parse
+ */
+ parse: Ember.required(Function)
+
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/9e92faa5/contrib/views/slider/src/main/resources/ui/app/mixins/run_periodically.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/mixins/run_periodically.js b/contrib/views/slider/src/main/resources/ui/app/mixins/run_periodically.js
new file mode 100644
index 0000000..25d5aaf
--- /dev/null
+++ b/contrib/views/slider/src/main/resources/ui/app/mixins/run_periodically.js
@@ -0,0 +1,78 @@
+/**
+ * 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.
+ */
+
+/**
+ * Allow to run object method periodically and stop it
+ * Example:
+ * <code>
+ * var obj = Ember.Object.createWithMixins(App.RunPeriodically, {
+ * method: Ember.K
+ * });
+ * obj.set('interval', 10000); // override default value
+ * obj.loop('method'); // run periodically
+ * obj.stop(); // stop running
+ * </code>
+ * @type {Ember.Mixin}
+ */
+App.RunPeriodically = Ember.Mixin.create({
+
+ /**
+ * Interval for loop
+ * @type {number}
+ */
+ interval: 5000,
+
+ /**
+ * setTimeout's return value
+ * @type {number}
+ */
+ timer: null,
+
+ /**
+ * Run <code>methodName</code> periodically with <code>interval</code>
+ * @param {string} methodName method name to run periodically
+ * @param {bool} initRun should methodName be run before setInterval call (default - true)
+ * @method run
+ */
+ loop: function(methodName, initRun) {
+ initRun = Em.isNone(initRun) ? true : initRun;
+ var self = this,
+ interval = this.get('interval');
+ Ember.assert('Interval should be numeric and greated than 0', $.isNumeric(interval) && interval > 0);
+ if (initRun) {
+ this[methodName]();
+ }
+ this.set('timer',
+ setInterval(function () {
+ self[methodName]();
+ }, interval)
+ );
+ },
+
+ /**
+ * Stop running <code>timer</code>
+ * @method stop
+ */
+ stop: function() {
+ var timer = this.get('timer');
+ if (!Em.isNone(timer)) {
+ clearTimeout(timer);
+ }
+ }
+
+});
\ No newline at end of file