TEZ-3021. Tez UI 2: Add env service & initializer (sree)
Project: http://git-wip-us.apache.org/repos/asf/tez/repo Commit: http://git-wip-us.apache.org/repos/asf/tez/commit/1292bf41 Tree: http://git-wip-us.apache.org/repos/asf/tez/tree/1292bf41 Diff: http://git-wip-us.apache.org/repos/asf/tez/diff/1292bf41 Branch: refs/heads/TEZ-2980 Commit: 1292bf41a36026b2bfd245f081a920168cfbb51d Parents: 6e18c9b Author: Sreenath Somarajapuram <s...@apache.org> Authored: Mon Jan 4 16:28:41 2016 +0530 Committer: Sreenath Somarajapuram <s...@apache.org> Committed: Thu Feb 25 03:31:59 2016 +0530 ---------------------------------------------------------------------- TEZ-2980-CHANGES.txt | 1 + tez-ui2/src/main/webapp/app/initializers/env.js | 28 ++++++++ tez-ui2/src/main/webapp/app/services/env.js | 55 +++++++++++++++ tez-ui2/src/main/webapp/app/services/hosts.js | 11 +-- tez-ui2/src/main/webapp/config/configs.env | 6 +- .../src/main/webapp/config/default-app-conf.js | 38 +++++++++++ tez-ui2/src/main/webapp/config/environment.js | 12 ++-- .../webapp/tests/unit/initializers/env-test.js | 40 +++++++++++ .../main/webapp/tests/unit/services/env-test.js | 70 ++++++++++++++++++++ .../webapp/tests/unit/services/hosts-test.js | 8 ++- 10 files changed, 252 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tez/blob/1292bf41/TEZ-2980-CHANGES.txt ---------------------------------------------------------------------- diff --git a/TEZ-2980-CHANGES.txt b/TEZ-2980-CHANGES.txt index 4cf5c4a..77a8d29 100644 --- a/TEZ-2980-CHANGES.txt +++ b/TEZ-2980-CHANGES.txt @@ -7,3 +7,4 @@ ALL CHANGES: TEZ-2984. Tez UI 2: Create abstract classes TEZ-3020. Tez UI 2: Add entity blueprint TEZ-2985. Tez UI 2: Create loader and entity classes + TEZ-3021. Tez UI 2: Add env service & initializer http://git-wip-us.apache.org/repos/asf/tez/blob/1292bf41/tez-ui2/src/main/webapp/app/initializers/env.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/app/initializers/env.js b/tez-ui2/src/main/webapp/app/initializers/env.js new file mode 100644 index 0000000..43bc291 --- /dev/null +++ b/tez-ui2/src/main/webapp/app/initializers/env.js @@ -0,0 +1,28 @@ +/** + * 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. + */ + +export function initialize(application) { + application.inject('controller', 'env', 'service:env'); + application.inject('route', 'env', 'service:env'); + application.inject('adapter', 'env', 'service:env'); +} + +export default { + name: 'env', + initialize +}; http://git-wip-us.apache.org/repos/asf/tez/blob/1292bf41/tez-ui2/src/main/webapp/app/services/env.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/app/services/env.js b/tez-ui2/src/main/webapp/app/services/env.js new file mode 100644 index 0000000..397293d --- /dev/null +++ b/tez-ui2/src/main/webapp/app/services/env.js @@ -0,0 +1,55 @@ +/*global more*/ +/** + * 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. + */ + +import Ember from 'ember'; + +import environment from '../config/environment'; + +var MoreObject = more.Object; + +export default Ember.Service.extend({ + _configs: null, + + init: function () { + this.collateConfigs(); + }, + + collateConfigs: function () { + var configs = {}, + ENV = window.ENV; + + MoreObject.merge(configs, environment); + + if(ENV) { + MoreObject.merge(configs.APP, ENV); + } + + this.set("_configs", configs); + }, + + getConfig: function (path) { + var configs = this.get("_configs"); + return Ember.get(configs, path); + }, + + getAppConfig: function (path) { + var configs = this.get("_configs.APP"); + return Ember.get(configs, path); + } +}); http://git-wip-us.apache.org/repos/asf/tez/blob/1292bf41/tez-ui2/src/main/webapp/app/services/hosts.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/app/services/hosts.js b/tez-ui2/src/main/webapp/app/services/hosts.js index f549f2c..07de04d 100644 --- a/tez-ui2/src/main/webapp/app/services/hosts.js +++ b/tez-ui2/src/main/webapp/app/services/hosts.js @@ -17,10 +17,11 @@ */ import Ember from 'ember'; -import environment from '../config/environment'; export default Ember.Service.extend({ + env: Ember.inject.service("env"), + correctProtocol: function (url, localProto) { var urlProto; @@ -55,13 +56,13 @@ export default Ember.Service.extend({ }, timeline: Ember.computed(function () { - var ENV = window.ENV; - return this.normalizeURL((ENV && ENV.timelineHost) || environment.hosts.timeline); + var env = this.get("env"); + return this.normalizeURL(env.getAppConfig("hosts.timeline")); }), rm: Ember.computed(function () { - var ENV = window.ENV; - return this.normalizeURL((ENV && ENV.rmHost) || environment.hosts.RM); + var env = this.get("env"); + return this.normalizeURL(env.getAppConfig("hosts.rm")); }), }); http://git-wip-us.apache.org/repos/asf/tez/blob/1292bf41/tez-ui2/src/main/webapp/config/configs.env ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/config/configs.env b/tez-ui2/src/main/webapp/config/configs.env index 5f5ec17..60421fd 100644 --- a/tez-ui2/src/main/webapp/config/configs.env +++ b/tez-ui2/src/main/webapp/config/configs.env @@ -1,4 +1,6 @@ ENV = { - //timelineHost: "http://localhost:8188", - //rmHost: "http://localhost:8088" + hosts: { + //timeline: "http://localhost:8188", + //rm: "http://localhost:8088" + } }; http://git-wip-us.apache.org/repos/asf/tez/blob/1292bf41/tez-ui2/src/main/webapp/config/default-app-conf.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/config/default-app-conf.js b/tez-ui2/src/main/webapp/config/default-app-conf.js new file mode 100644 index 0000000..c8f6dd9 --- /dev/null +++ b/tez-ui2/src/main/webapp/config/default-app-conf.js @@ -0,0 +1,38 @@ +/** + * 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. + */ + +module.exports = { // Tez App configurations + hosts: { + timeline: 'localhost:8188', + rm: 'localhost:8088', + }, + namespaces: { + webService: { + timeline: 'ws/v1/timeline', + history: 'ws/v1/applicationhistory', + am: { + v1: 'proxy/__app_id__/ws/v1/tez', + v2: 'proxy/__app_id__/ws/v2/tez', + }, + cluster: 'ws/v1/cluster', + }, + web: { + cluster: 'cluster' + }, + }, +}; http://git-wip-us.apache.org/repos/asf/tez/blob/1292bf41/tez-ui2/src/main/webapp/config/environment.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/config/environment.js b/tez-ui2/src/main/webapp/config/environment.js index e061066..4201f9a 100644 --- a/tez-ui2/src/main/webapp/config/environment.js +++ b/tez-ui2/src/main/webapp/config/environment.js @@ -18,6 +18,8 @@ * limitations under the License. */ +const DEFAULT_APP_CONF = require('./default-app-conf'); + module.exports = function(environment) { var ENV = { modulePrefix: 'tez-ui', @@ -31,14 +33,10 @@ module.exports = function(environment) { } }, - APP: { - // Here you can pass flags/options to your application instance - // when it is created - }, + APP: DEFAULT_APP_CONF, - hosts: { - timeline: 'localhost:8188', - RM: 'localhost:8088' + contentSecurityPolicy: { + 'connect-src': "* 'self'" } }; http://git-wip-us.apache.org/repos/asf/tez/blob/1292bf41/tez-ui2/src/main/webapp/tests/unit/initializers/env-test.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/tests/unit/initializers/env-test.js b/tez-ui2/src/main/webapp/tests/unit/initializers/env-test.js new file mode 100644 index 0000000..7f6f287 --- /dev/null +++ b/tez-ui2/src/main/webapp/tests/unit/initializers/env-test.js @@ -0,0 +1,40 @@ +/** + * 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. + */ + +import Ember from 'ember'; +import EnvInitializer from '../../../initializers/env'; +import { module, test } from 'qunit'; + +let application; + +module('Unit | Initializer | env', { + beforeEach() { + Ember.run(function() { + application = Ember.Application.create(); + application.deferReadiness(); + }); + } +}); + +// Replace this with your real tests. +test('it works', function(assert) { + EnvInitializer.initialize(application); + + // you would normally confirm the results of the initializer here + assert.ok(true); +}); http://git-wip-us.apache.org/repos/asf/tez/blob/1292bf41/tez-ui2/src/main/webapp/tests/unit/services/env-test.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/tests/unit/services/env-test.js b/tez-ui2/src/main/webapp/tests/unit/services/env-test.js new file mode 100644 index 0000000..a8a064b --- /dev/null +++ b/tez-ui2/src/main/webapp/tests/unit/services/env-test.js @@ -0,0 +1,70 @@ +/** + * 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. + */ + +import { moduleFor, test } from 'ember-qunit'; + +import environment from '../../../config/environment'; + +moduleFor('service:env', 'Unit | Service | env', { + // Specify the other units that are required for this test. + // needs: ['service:foo'] +}); + +test('Basic creation test', function(assert) { + let service = this.subject(); + + assert.ok(service); + assert.ok(service.collateConfigs); + assert.ok(service.getConfig); + assert.ok(service.getAppConfig); +}); + +test('collateConfigs test', function(assert) { + let service = this.subject(), + APP = environment.APP; + + APP.a = 11; + APP.b = 22; + window.ENV = { + a: 1 + }; + + service.collateConfigs(); + + APP = service._configs.APP; + assert.equal(APP.a, 1, "Test window.ENV merge onto environment.APP"); + assert.equal(APP.b, 22); +}); + +test('getConfig test', function(assert) { + let service = this.subject(); + + window.ENV = {}; + environment.a = 11; + service.collateConfigs(); + assert.equal(service.getConfig("a"), environment.a); +}); + +test('getAppConfig test', function(assert) { + let service = this.subject(); + + window.ENV = {}; + environment.APP.a = 11; + service.collateConfigs(); + assert.equal(service.getAppConfig("a"), environment.APP.a); +}); http://git-wip-us.apache.org/repos/asf/tez/blob/1292bf41/tez-ui2/src/main/webapp/tests/unit/services/hosts-test.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/tests/unit/services/hosts-test.js b/tez-ui2/src/main/webapp/tests/unit/services/hosts-test.js index 055fccd..026f21b 100644 --- a/tez-ui2/src/main/webapp/tests/unit/services/hosts-test.js +++ b/tez-ui2/src/main/webapp/tests/unit/services/hosts-test.js @@ -20,7 +20,7 @@ import { moduleFor, test } from 'ember-qunit'; moduleFor('service:hosts', 'Unit | Service | hosts', { // Specify the other units that are required for this test. - // needs: ['service:foo'] + needs: ['service:env'] }); test('Test creation', function(assert) { @@ -67,8 +67,10 @@ test('Test host URLs with ENV set', function(assert) { let service = this.subject(); window.ENV = { - timelineHost: "https://localhost:3333", - rmHost: "https://localhost:4444" + hosts: { + timeline: "https://localhost:3333", + rm: "https://localhost:4444" + } }; assert.equal(service.get("timeline"), "http://localhost:3333"); assert.equal(service.get("rm"), "http://localhost:4444");