You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2016/09/16 13:57:34 UTC
[01/27] ambari git commit: AMBARI-18388. Link UI: add missing unit
tests for models/configs/* and models/stack_version/* files (alexantonenko)
Repository: ambari
Updated Branches:
refs/heads/branch-dev-patch-upgrade 752e7c463 -> 9dbcac6d5
AMBARI-18388. Link UI: add missing unit tests for models/configs/* and models/stack_version/* files
(alexantonenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/08e426ac
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/08e426ac
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/08e426ac
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 08e426ac790957e3fab3edeef128a331fd5860bc
Parents: 752e7c4
Author: Alex Antonenko <hi...@gmail.com>
Authored: Wed Sep 14 18:32:11 2016 +0300
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Wed Sep 14 21:40:26 2016 +0300
----------------------------------------------------------------------
ambari-web/app/assets/test/tests.js | 7 +-
.../app/models/stack_version/service_simple.js | 2 +-
ambari-web/app/models/stack_version/version.js | 2 +-
ambari-web/test/aliases/computed/concat.js | 92 ++++++++++
ambari-web/test/aliases/computed/empty.js | 125 ++++++++++++++
ambari-web/test/aliases/computed/equal.js | 6 +-
ambari-web/test/init_computed_aliases.js | 23 ++-
ambari-web/test/models/configs/section_test.js | 55 ------
.../test/models/configs/sub_section_test.js | 103 -----------
.../test/models/configs/theme/section_test.js | 55 ++++++
.../configs/theme/sub_section_tab_test.js | 169 +++++++++++++++++++
.../models/configs/theme/sub_section_test.js | 103 +++++++++++
.../models/stack_version/service_simple_test.js | 119 +++++++++++++
.../test/models/stack_version/version_test.js | 38 +++++
14 files changed, 734 insertions(+), 165 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index d918900..78c6196 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -401,16 +401,19 @@ var files = [
'test/models/host_stack_version_test',
'test/models/upgrade_entity_test',
'test/models/finished_upgrade_entity_test',
- 'test/models/configs/sub_section_test',
- 'test/models/configs/section_test',
'test/models/configs/service_config_version_test',
'test/models/configs/config_group_test',
'test/models/configs/stack_config_property_test',
'test/models/configs/objects/service_config_test',
'test/models/configs/objects/service_config_category_test',
'test/models/configs/objects/service_config_property_test',
+ 'test/models/configs/theme/section_test',
+ 'test/models/configs/theme/sub_section_test',
+ 'test/models/configs/theme/sub_section_tab_test',
'test/models/configs/theme/tab_test',
'test/models/stack_version/repository_version_test',
+ 'test/models/stack_version/service_simple_test',
+ 'test/models/stack_version/version_test',
'test/routes/views_test',
//contains test with fake timers that affect Date
'test/utils/lazy_loading_test',
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/app/models/stack_version/service_simple.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/stack_version/service_simple.js b/ambari-web/app/models/stack_version/service_simple.js
index f693cc8..c7d94e5 100644
--- a/ambari-web/app/models/stack_version/service_simple.js
+++ b/ambari-web/app/models/stack_version/service_simple.js
@@ -30,7 +30,7 @@ App.ServiceSimple = DS.Model.extend({
doNotShowAndInstall: function () {
var skipServices = ['KERBEROS'];
- if(!App.supports.installGanglia) {
+ if(!App.get('supports.installGanglia')) {
skipServices.push('GANGLIA');
}
return skipServices.contains(this.get('name'));
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/app/models/stack_version/version.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/stack_version/version.js b/ambari-web/app/models/stack_version/version.js
index 3f2fe37..4e18ca4 100644
--- a/ambari-web/app/models/stack_version/version.js
+++ b/ambari-web/app/models/stack_version/version.js
@@ -35,7 +35,7 @@ App.StackVersion = DS.Model.extend({
upgradeFailedHosts: DS.attr('array'),
currentHosts: DS.attr('array'),
- noInstalledHosts: Em.computed.empty('installedHosts'),
+ noInstalledHosts: Em.computed.empty('installedHosts'),
noCurrentHosts: Em.computed.empty('currentHosts'),
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/aliases/computed/concat.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/aliases/computed/concat.js b/ambari-web/test/aliases/computed/concat.js
new file mode 100644
index 0000000..846b42a
--- /dev/null
+++ b/ambari-web/test/aliases/computed/concat.js
@@ -0,0 +1,92 @@
+/**
+ * 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.
+ */
+
+var helpers = App.TestAliases.helpers;
+
+App.TestAliases.testAsComputedConcat = function (context, propertyName, separator, dependentValues) {
+
+ describe('#' + propertyName + ' as Em.computed.concat', function () {
+
+ var cases = [
+ {
+ firstItem: undefined
+ },
+ {
+ firstItem: null
+ },
+ {
+ firstItem: '',
+ description: 'empty string'
+ },
+ {
+ firstItem: 0,
+ description: 'number'
+ },
+ {
+ firstItem: [1, 2],
+ description: 'array'
+ },
+ {
+ firstItem: {
+ property: 'value'
+ },
+ description: 'object'
+ },
+ {
+ firstItem: NaN
+ },
+ {
+ firstItem: Em.K,
+ description: 'function'
+ }
+ ],
+ values = dependentValues.map(function (key, index) {
+ return index.toString();
+ }),
+ valuesHash = {};
+
+ dependentValues.forEach(function (key, index) {
+ valuesHash[key] = index;
+ });
+
+ afterEach(function () {
+ helpers.smartRestoreGet(context);
+ });
+
+ it('has valid dependent keys', function () {
+ expect(Em.meta(context).descs[propertyName]._dependentKeys).to.eql(dependentValues);
+ });
+
+ cases.forEach(function (item) {
+
+ var description = item.description || item.firstItem;
+
+ it('values contain ' + description, function () {
+ if (item.hasOwnProperty('firstItem')) {
+ values[0] = item.firstItem;
+ valuesHash[dependentValues[0]] = item.firstItem;
+ }
+ helpers.smartStubGet(context, valuesHash).propertyDidChange(context, propertyName);
+ expect(helpers.smartGet(context, propertyName)).to.equal(values.join(separator));
+ });
+
+ });
+
+ });
+
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/aliases/computed/empty.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/aliases/computed/empty.js b/ambari-web/test/aliases/computed/empty.js
new file mode 100644
index 0000000..c054963
--- /dev/null
+++ b/ambari-web/test/aliases/computed/empty.js
@@ -0,0 +1,125 @@
+/**
+ * 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.
+ */
+
+var helpers = App.TestAliases.helpers;
+
+App.TestAliases.testAsComputedEmpty = function (context, propertyName, dependentKey) {
+
+ describe('#' + propertyName + ' as Em.computed.empty', function () {
+
+ var values = [
+ {
+ value: undefined,
+ result: true
+ },
+ {
+ value: null,
+ result: true
+ },
+ {
+ value: '',
+ result: true,
+ description: 'empty string'
+ },
+ {
+ value: [],
+ result: true,
+ description: 'empty array'
+ },
+ {
+ value: false,
+ result: false
+ },
+ {
+ value: true,
+ result: false
+ },
+ {
+ value: 0,
+ result: false
+ },
+ {
+ value: NaN,
+ result: false
+ },
+ {
+ value: {},
+ result: false,
+ description: 'empty object'
+ },
+ {
+ value: '0',
+ result: false,
+ description: 'non-empty string'
+ },
+ {
+ value: 1,
+ result: false,
+ description: 'non-zero number'
+ },
+ {
+ value: [0],
+ result: false,
+ description: 'non-empty array'
+ },
+ {
+ value: {
+ i: 0
+ },
+ result: false,
+ description: 'non-empty object'
+ },
+ {
+ value: Em.K,
+ result: false,
+ description: 'function'
+ }
+ ],
+ descs = Em.meta(context).descs;
+
+ it('has valid dependent keys', function () {
+ expect(descs[propertyName]._dependentKeys).to.eql([dependentKey]);
+ });
+
+ values.forEach(function (item) {
+
+ var description = item.description || item.value,
+ initialDefinition = Boolean(descs[dependentKey]) ? descs[dependentKey] : context.get(dependentKey);
+
+ describe(dependentKey + ' is ' + description, function () {
+
+ beforeEach(function () {
+ helpers.reopenProperty(context, dependentKey, item.value);
+ context.propertyDidChange(propertyName);
+ });
+
+ afterEach(function () {
+ helpers.reopenProperty(context, dependentKey, initialDefinition);
+ });
+
+ it(propertyName + ' should be `' + item.result + '`', function () {
+ expect(context.get(propertyName)).to.equal(item.result);
+ });
+
+ });
+
+ });
+
+ });
+
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/aliases/computed/equal.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/aliases/computed/equal.js b/ambari-web/test/aliases/computed/equal.js
index 00ec2d1..77616ea 100644
--- a/ambari-web/test/aliases/computed/equal.js
+++ b/ambari-web/test/aliases/computed/equal.js
@@ -45,7 +45,11 @@ App.TestAliases.testAsComputedEqual = function (context, propertyName, dependent
});
it('should be `false` if ' + JSON.stringify(dependentKey) + ' is not equal to the ' + JSON.stringify(neededValue), function () {
- helpers.smartStubGet(context, dependentKey, Math.random())
+ var randomValue = Math.random();
+ if (randomValue === neededValue) {
+ randomValue++;
+ }
+ helpers.smartStubGet(context, dependentKey, randomValue)
.propertyDidChange(context, propertyName);
var value = helpers.smartGet(context, propertyName);
expect(value).to.be.false;
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/init_computed_aliases.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/init_computed_aliases.js b/ambari-web/test/init_computed_aliases.js
index 44faf4f..81ae5fa 100644
--- a/ambari-web/test/init_computed_aliases.js
+++ b/ambari-web/test/init_computed_aliases.js
@@ -88,7 +88,7 @@ App.TestAliases = {
* @returns {App.TestAliases}
* @private
*/
- _stubOneKey: function (self,dependentKey, value) {
+ _stubOneKey: function (self, dependentKey, value) {
var isApp = dependentKey.startsWith('App.');
var name = isApp ? dependentKey.replace('App.', '') : dependentKey;
var context = isApp ? App : self;
@@ -160,6 +160,23 @@ App.TestAliases = {
result.push(combo);
}
return result;
+ },
+
+ /**
+ * Reopens property of the given object as constant with the given value
+ * @param {Ember.Object} context
+ * @param {String} key
+ * @param {*} value
+ */
+ reopenProperty: function (context, key, value) {
+ var reopenObject = {},
+ isUndefined = typeof value === 'undefined';
+ // if the only property in reopen argument is undefined, context won't be changed
+ reopenObject[key] = isUndefined ? null : value;
+ context.reopen(reopenObject);
+ if (isUndefined) {
+ context.set(key, undefined);
+ }
}
}
@@ -199,4 +216,6 @@ require('test/aliases/computed/and');
require('test/aliases/computed/or');
require('test/aliases/computed/formatUnavailable');
require('test/aliases/computed/getByKey');
-require('test/aliases/computed/truncate');
\ No newline at end of file
+require('test/aliases/computed/truncate');
+require('test/aliases/computed/concat');
+require('test/aliases/computed/empty');
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/models/configs/section_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/configs/section_test.js b/ambari-web/test/models/configs/section_test.js
deleted file mode 100644
index 3c9ab40..0000000
--- a/ambari-web/test/models/configs/section_test.js
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * 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.
- */
-
-var App = require('app');
-var model;
-
-function getModel() {
- return App.Section.createRecord();
-}
-
-describe('App.Section', function () {
-
- beforeEach(function () {
- model = getModel();
- });
-
- describe('#errorsCount', function () {
-
- beforeEach(function () {
- model.reopen({subSections: [
- App.SubSection.createRecord({configs: [
- App.ServiceConfigProperty.create({isValid: true}),
- App.ServiceConfigProperty.create({isValid: false})
- ]}),
- App.SubSection.createRecord({configs: [
- App.ServiceConfigProperty.create({isValid: true}),
- App.ServiceConfigProperty.create({isValid: false})
- ]})
- ]});
- });
-
- it('should use subsections.@each.errorsCount', function () {
- expect(model.get('errorsCount')).to.equal(2);
- });
-
- });
-
- App.TestAliases.testAsComputedEveryBy(getModel(), 'isHiddenByFilter', 'subSections', 'isSectionVisible', false);
-
-});
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/models/configs/sub_section_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/configs/sub_section_test.js b/ambari-web/test/models/configs/sub_section_test.js
deleted file mode 100644
index e89bce9..0000000
--- a/ambari-web/test/models/configs/sub_section_test.js
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * 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.
- */
-
-var App = require('app');
-var model;
-
-function getModel() {
- return App.SubSection.createRecord();
-}
-
-describe('App.SubSection', function () {
-
- beforeEach(function () {
- model = getModel();
- });
-
- App.TestAliases.testAsComputedAnd(getModel(), 'showTabs', ['hasTabs', 'someSubSectionTabIsVisible']);
-
- App.TestAliases.testAsComputedAnd(getModel(), 'addLeftVerticalSplitter', ['!isFirstColumn', 'leftVerticalSplitter']);
-
- App.TestAliases.testAsComputedAnd(getModel(), 'showTopSplitter', ['!isFirstRow', '!border']);
-
- App.TestAliases.testAsComputedAnd(getModel(), 'isSectionVisible', ['!isHiddenByFilter', '!isHiddenByConfig', 'someConfigIsVisible']);
-
- describe('#errorsCount', function () {
-
- beforeEach(function () {
- model.set('configs', [
- App.ServiceConfigProperty.create({isValid: true}),
- App.ServiceConfigProperty.create({isValid: false}),
- App.ServiceConfigProperty.create({isValid: false}),
- App.ServiceConfigProperty.create({isValid: false}),
- ]);
- });
-
- it('should use configs.@each.isValid', function () {
- expect(model.get('errorsCount')).to.equal(3);
- });
-
- it('should use configs.@each.isValidOverride', function() {
- // original value is valid
- var validOriginalSCP = model.get('configs').objectAt(0);
- // add override with not valid value
- validOriginalSCP.set('isValidOverride', false);
- validOriginalSCP.set('isValid', true);
- expect(model.get('errorsCount')).to.equal(3);
- });
-
- });
-
- describe('#isHiddenByFilter', function () {
-
- Em.A([
- {
- configs: [],
- e: false,
- m: 'Can\'t be hidden if there is no configs'
- },
- {
- configs: [Em.Object.create({isHiddenByFilter: true, isVisible: true}), Em.Object.create({isHiddenByFilter: true, isVisible: true})],
- e: true,
- m: 'All configs are hidden'
- },
- {
- configs: [Em.Object.create({isHiddenByFilter: false, isVisible: true}), Em.Object.create({isHiddenByFilter: true, isVisible: true})],
- e: false,
- m: 'Some configs are hidden'
- },
- {
- configs: [Em.Object.create({isHiddenByFilter: false, isVisible: true}), Em.Object.create({isHiddenByFilter: true, isVisible: true})],
- e: false,
- m: 'Some configs are hidden'
- },
- {
- configs: [Em.Object.create({isHiddenByFilter: false, isVisible: true}), Em.Object.create({isHiddenByFilter: false, isVisible: true})],
- e: false,
- m: 'No configs are hidden'
- }
- ]).forEach(function (test) {
- it(test.m, function () {
- model.set('configs', test.configs);
- expect(model.get('isHiddenByFilter')).to.equal(test.e);
- })
- });
-
- });
-
-});
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/models/configs/theme/section_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/configs/theme/section_test.js b/ambari-web/test/models/configs/theme/section_test.js
new file mode 100644
index 0000000..3c9ab40
--- /dev/null
+++ b/ambari-web/test/models/configs/theme/section_test.js
@@ -0,0 +1,55 @@
+/**
+ * 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.
+ */
+
+var App = require('app');
+var model;
+
+function getModel() {
+ return App.Section.createRecord();
+}
+
+describe('App.Section', function () {
+
+ beforeEach(function () {
+ model = getModel();
+ });
+
+ describe('#errorsCount', function () {
+
+ beforeEach(function () {
+ model.reopen({subSections: [
+ App.SubSection.createRecord({configs: [
+ App.ServiceConfigProperty.create({isValid: true}),
+ App.ServiceConfigProperty.create({isValid: false})
+ ]}),
+ App.SubSection.createRecord({configs: [
+ App.ServiceConfigProperty.create({isValid: true}),
+ App.ServiceConfigProperty.create({isValid: false})
+ ]})
+ ]});
+ });
+
+ it('should use subsections.@each.errorsCount', function () {
+ expect(model.get('errorsCount')).to.equal(2);
+ });
+
+ });
+
+ App.TestAliases.testAsComputedEveryBy(getModel(), 'isHiddenByFilter', 'subSections', 'isSectionVisible', false);
+
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/models/configs/theme/sub_section_tab_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/configs/theme/sub_section_tab_test.js b/ambari-web/test/models/configs/theme/sub_section_tab_test.js
new file mode 100644
index 0000000..6044432
--- /dev/null
+++ b/ambari-web/test/models/configs/theme/sub_section_tab_test.js
@@ -0,0 +1,169 @@
+/**
+ * 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.
+ */
+
+var App = require('app');
+require('models/configs/theme/sub_section_tab');
+
+describe('App.SubSectionTab', function () {
+
+ var subSectionTab,
+ getModel = function () {
+ return App.SubSectionTab.createRecord();
+ };
+
+ beforeEach(function () {
+ subSectionTab = getModel();
+ });
+
+ describe('#visibleProperties', function () {
+
+ var configs = [
+ Em.Object.create({
+ id: 0,
+ isVisible: false,
+ hiddenBySection: false
+ }),
+ Em.Object.create({
+ id: 1,
+ isVisible: false,
+ hiddenBySection: true
+ }),
+ Em.Object.create({
+ id: 2,
+ isVisible: true,
+ hiddenBySection: false
+ }),
+ Em.Object.create({
+ id: 3,
+ isVisible: true,
+ hiddenBySection: true
+ }),
+ Em.Object.create({
+ id: 4,
+ isVisible: false
+ }),
+ Em.Object.create({
+ id: 5,
+ isVisible: true
+ })
+ ];
+
+ it('should include visible properties from visible sections only', function () {
+ subSectionTab.set('configs', configs);
+ expect(subSectionTab.get('visibleProperties').mapProperty('id')).to.eql([2, 5]);
+ });
+
+ });
+
+ describe('#errorsCount', function () {
+
+ var configs = [
+ Em.Object.create({
+ isVisible: true,
+ isValid: true,
+ isValidOverride: true
+ }),
+ Em.Object.create({
+ isVisible: false,
+ isValid: true,
+ isValidOverride: true
+ }),
+ Em.Object.create({
+ isVisible: true,
+ isValid: true,
+ isValidOverride: false
+ }),
+ Em.Object.create({
+ isVisible: false,
+ isValid: true,
+ isValidOverride: false
+ }),
+ Em.Object.create({
+ isVisible: true,
+ isValid: false,
+ isValidOverride: true
+ }),
+ Em.Object.create({
+ isVisible: false,
+ isValid: false,
+ isValidOverride: true
+ }),
+ Em.Object.create({
+ isVisible: true,
+ isValid: false,
+ isValidOverride: false
+ }),
+ Em.Object.create({
+ isVisible: false,
+ isValid: false,
+ isValidOverride: false
+ }),
+ Em.Object.create({
+ isVisible: true,
+ isValid: true
+ }),
+ Em.Object.create({
+ isVisible: false,
+ isValid: true
+ }),
+ Em.Object.create({
+ isVisible: true,
+ isValid: false
+ }),
+ Em.Object.create({
+ isVisible: false,
+ isValid: false
+ }),
+ Em.Object.create({
+ isVisible: true,
+ isValidOverride: true
+ }),
+ Em.Object.create({
+ isVisible: false,
+ isValidOverride: true
+ }),
+ Em.Object.create({
+ isVisible: true,
+ isValidOverride: false
+ }),
+ Em.Object.create({
+ isVisible: false,
+ isValidOverride: false
+ }),
+ Em.Object.create({
+ isVisible: true
+ }),
+ Em.Object.create({
+ isVisible: false
+ })
+ ];
+
+ it('should include visible properties with errors', function () {
+ subSectionTab.set('configs', configs);
+ expect(subSectionTab.get('errorsCount')).to.eql(8);
+ });
+
+ });
+
+ App.TestAliases.testAsComputedEveryBy(getModel(), 'isHiddenByFilter', 'visibleProperties', 'isHiddenByFilter', true);
+
+ App.TestAliases.testAsComputedGt(getModel(), 'someConfigIsVisible', 'visibleProperties.length', 0);
+
+ App.TestAliases.testAsComputedAnd(getModel(), 'isVisible', ['!isHiddenByFilter', '!isHiddenByConfig', 'someConfigIsVisible']);
+
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/models/configs/theme/sub_section_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/configs/theme/sub_section_test.js b/ambari-web/test/models/configs/theme/sub_section_test.js
new file mode 100644
index 0000000..e89bce9
--- /dev/null
+++ b/ambari-web/test/models/configs/theme/sub_section_test.js
@@ -0,0 +1,103 @@
+/**
+ * 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.
+ */
+
+var App = require('app');
+var model;
+
+function getModel() {
+ return App.SubSection.createRecord();
+}
+
+describe('App.SubSection', function () {
+
+ beforeEach(function () {
+ model = getModel();
+ });
+
+ App.TestAliases.testAsComputedAnd(getModel(), 'showTabs', ['hasTabs', 'someSubSectionTabIsVisible']);
+
+ App.TestAliases.testAsComputedAnd(getModel(), 'addLeftVerticalSplitter', ['!isFirstColumn', 'leftVerticalSplitter']);
+
+ App.TestAliases.testAsComputedAnd(getModel(), 'showTopSplitter', ['!isFirstRow', '!border']);
+
+ App.TestAliases.testAsComputedAnd(getModel(), 'isSectionVisible', ['!isHiddenByFilter', '!isHiddenByConfig', 'someConfigIsVisible']);
+
+ describe('#errorsCount', function () {
+
+ beforeEach(function () {
+ model.set('configs', [
+ App.ServiceConfigProperty.create({isValid: true}),
+ App.ServiceConfigProperty.create({isValid: false}),
+ App.ServiceConfigProperty.create({isValid: false}),
+ App.ServiceConfigProperty.create({isValid: false}),
+ ]);
+ });
+
+ it('should use configs.@each.isValid', function () {
+ expect(model.get('errorsCount')).to.equal(3);
+ });
+
+ it('should use configs.@each.isValidOverride', function() {
+ // original value is valid
+ var validOriginalSCP = model.get('configs').objectAt(0);
+ // add override with not valid value
+ validOriginalSCP.set('isValidOverride', false);
+ validOriginalSCP.set('isValid', true);
+ expect(model.get('errorsCount')).to.equal(3);
+ });
+
+ });
+
+ describe('#isHiddenByFilter', function () {
+
+ Em.A([
+ {
+ configs: [],
+ e: false,
+ m: 'Can\'t be hidden if there is no configs'
+ },
+ {
+ configs: [Em.Object.create({isHiddenByFilter: true, isVisible: true}), Em.Object.create({isHiddenByFilter: true, isVisible: true})],
+ e: true,
+ m: 'All configs are hidden'
+ },
+ {
+ configs: [Em.Object.create({isHiddenByFilter: false, isVisible: true}), Em.Object.create({isHiddenByFilter: true, isVisible: true})],
+ e: false,
+ m: 'Some configs are hidden'
+ },
+ {
+ configs: [Em.Object.create({isHiddenByFilter: false, isVisible: true}), Em.Object.create({isHiddenByFilter: true, isVisible: true})],
+ e: false,
+ m: 'Some configs are hidden'
+ },
+ {
+ configs: [Em.Object.create({isHiddenByFilter: false, isVisible: true}), Em.Object.create({isHiddenByFilter: false, isVisible: true})],
+ e: false,
+ m: 'No configs are hidden'
+ }
+ ]).forEach(function (test) {
+ it(test.m, function () {
+ model.set('configs', test.configs);
+ expect(model.get('isHiddenByFilter')).to.equal(test.e);
+ })
+ });
+
+ });
+
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/models/stack_version/service_simple_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/stack_version/service_simple_test.js b/ambari-web/test/models/stack_version/service_simple_test.js
new file mode 100644
index 0000000..ae00f9c
--- /dev/null
+++ b/ambari-web/test/models/stack_version/service_simple_test.js
@@ -0,0 +1,119 @@
+/**
+ * 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.
+ */
+
+var App = require('app');
+require('models/stack_version/service_simple');
+
+describe('App.ServiceSimple', function () {
+
+ var serviceSimple;
+
+ beforeEach(function () {
+ serviceSimple = App.ServiceSimple.createRecord();
+ });
+
+ describe('#isHidden', function () {
+
+ var cases = [
+ {
+ name: 'MAPREDUCE2',
+ doNotShowAndInstall: false,
+ isHidden: true,
+ title: 'MapReduce2 isn\'t displayed in wizard as separate service'
+ },
+ {
+ name: 'KERBEROS',
+ doNotShowAndInstall: true,
+ isHidden: true,
+ title: 'Kerberos isn\'t displayed in wizard'
+ },
+ {
+ name: 'ZOOKEEPER',
+ doNotShowAndInstall: false,
+ isHidden: false,
+ title: 'ZooKeeper is displayed in wizard'
+ }
+ ];
+
+ cases.forEach(function (item) {
+
+ it(item.title, function () {
+ serviceSimple.reopen({
+ doNotShowAndInstall: item.doNotShowAndInstall
+ });
+ serviceSimple.set('name', item.name);
+ expect(serviceSimple.get('isHidden')).to.equal(item.isHidden);
+ });
+
+ });
+
+ });
+
+ describe('#doNotShowAndInstall', function () {
+
+ var cases = [
+ {
+ name: 'KERBEROS',
+ isGangliaSupported: false,
+ doNotShowAndInstall: true,
+ title: 'Kerberos can\'t be installed from wizard'
+ },
+ {
+ name: 'GANGLIA',
+ isGangliaSupported: false,
+ doNotShowAndInstall: true,
+ title: 'Ganglia can\'t be installed from wizard by default'
+ },
+ {
+ name: 'GANGLIA',
+ isGangliaSupported: true,
+ doNotShowAndInstall: false,
+ title: 'Ganglia can be installed from wizard only if experimental feature is enabled'
+ },
+ {
+ name: 'ZOOKEEPER',
+ isGangliaSupported: false,
+ doNotShowAndInstall: false,
+ title: 'ZooKeeper can be installed from wizard'
+ }
+ ];
+
+ cases.forEach(function (item) {
+
+ describe(item.name, function () {
+
+ beforeEach(function () {
+ sinon.stub(App, 'get').withArgs('supports.installGanglia').returns(item.isGangliaSupported);
+ serviceSimple.set('name', item.name);
+ });
+
+ afterEach(function () {
+ App.get.restore();
+ });
+
+ it(item.title, function () {
+ expect(serviceSimple.get('doNotShowAndInstall')).to.equal(item.doNotShowAndInstall);
+ });
+
+ });
+
+ });
+
+ });
+
+});
http://git-wip-us.apache.org/repos/asf/ambari/blob/08e426ac/ambari-web/test/models/stack_version/version_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/stack_version/version_test.js b/ambari-web/test/models/stack_version/version_test.js
new file mode 100644
index 0000000..d097bbd
--- /dev/null
+++ b/ambari-web/test/models/stack_version/version_test.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.
+ */
+
+var App = require('app');
+require('models/stack_version/version');
+
+describe('App.StackVersion', function () {
+
+ var getModel = function () {
+ return App.StackVersion.createRecord();
+ };
+
+ App.TestAliases.testAsComputedConcat(getModel(), 'name', ' ', ['stack', 'version']);
+
+ App.TestAliases.testAsComputedEmpty(getModel(), 'noInstalledHosts', 'installedHosts');
+
+ App.TestAliases.testAsComputedEmpty(getModel(), 'noCurrentHosts', 'currentHosts');
+
+ App.TestAliases.testAsComputedEmpty(getModel(), 'noInitHosts', 'notInstalledHosts');
+
+ App.TestAliases.testAsComputedEqual(getModel(), 'isCurrent', 'state', 'CURRENT');
+
+});
\ No newline at end of file
[11/27] ambari git commit: AMBARI-18389 - Config compare shows
incorrect value after enabling kerberos (rzang)
Posted by nc...@apache.org.
AMBARI-18389 - Config compare shows incorrect value after enabling kerberos <fix1> (rzang)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/561dc8ee
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/561dc8ee
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/561dc8ee
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 561dc8ee0f524744b92c19e860e923ed890c1a36
Parents: 1123ba2
Author: Richard Zang <rz...@apache.org>
Authored: Thu Sep 15 04:42:32 2016 -0700
Committer: Richard Zang <rz...@apache.org>
Committed: Thu Sep 15 04:52:05 2016 -0700
----------------------------------------------------------------------
.../configs/widgets/plain_config_text_field.js | 2 +-
.../objects/service_config_property_test.js | 38 ++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/561dc8ee/ambari-web/app/views/common/configs/widgets/plain_config_text_field.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/widgets/plain_config_text_field.js b/ambari-web/app/views/common/configs/widgets/plain_config_text_field.js
index 5444b27..b70fb40 100644
--- a/ambari-web/app/views/common/configs/widgets/plain_config_text_field.js
+++ b/ambari-web/app/views/common/configs/widgets/plain_config_text_field.js
@@ -29,7 +29,7 @@ App.PlainConfigTextField = Ember.View.extend(App.SupportsDependentConfigs, App.W
templateName: require('templates/common/configs/widgets/plain_config_text_field'),
valueBinding: 'config.value',
classNames: ['widget-config-plain-text-field'],
- placeholderBinding: 'config.savedValue',
+ placeholderBinding: 'config.placeholder',
disabled: Em.computed.not('config.isEditable'),
http://git-wip-us.apache.org/repos/asf/ambari/blob/561dc8ee/ambari-web/test/models/configs/objects/service_config_property_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/configs/objects/service_config_property_test.js b/ambari-web/test/models/configs/objects/service_config_property_test.js
index d462025..49613a44 100644
--- a/ambari-web/test/models/configs/objects/service_config_property_test.js
+++ b/ambari-web/test/models/configs/objects/service_config_property_test.js
@@ -188,6 +188,44 @@ describe('App.ServiceConfigProperty', function () {
App.TestAliases.testAsComputedAnd(getProperty(), 'hideFinalIcon', ['!isFinal', 'isNotEditable']);
+ describe('#placeholder', function () {
+ it('should equal foo', function() {
+ serviceConfigProperty.set('isEditable', true);
+ var testCases = [
+ {
+ placeholderText: 'foo',
+ savedValue: ''
+ },
+ {
+ placeholderText: '',
+ savedValue: 'foo'
+ },
+ {
+ placeholderText: 'foo',
+ savedValue: 'bar'
+ }
+ ];
+ testCases.forEach(function (item) {
+ serviceConfigProperty.set('placeholderText', item.placeholderText);
+ serviceConfigProperty.set('savedValue', item.savedValue);
+ expect(serviceConfigProperty.get('placeholder')).to.equal('foo');
+ });
+ });
+ it('should equal null', function() {
+ serviceConfigProperty.set('isEditable', false);
+ var testCases = [
+ {
+ placeholderText: 'foo',
+ savedValue: 'bar'
+ }
+ ];
+ testCases.forEach(function (item) {
+ serviceConfigProperty.set('placeholderText', item.placeholderText);
+ serviceConfigProperty.set('savedValue', item.savedValue);
+ expect(serviceConfigProperty.get('placeholder')).to.equal(null);
+ });
+ });
+ });
describe('#isPropertyOverridable', function () {
overridableFalseData.forEach(function (item) {
it('should be false', function () {
[20/27] ambari git commit: AMBARI-18368. ADDENDUM. Atlas web UI alert
after performing stack upgrade to HDP 2.5 and adding Atlas Service
(alejandro)
Posted by nc...@apache.org.
AMBARI-18368. ADDENDUM. Atlas web UI alert after performing stack upgrade to HDP 2.5 and adding Atlas Service (alejandro)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1efc99c5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1efc99c5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1efc99c5
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 1efc99c5adc536044425b9df45b72421c5a8323c
Parents: d5cca62
Author: Alejandro Fernandez <af...@hortonworks.com>
Authored: Wed Sep 14 18:42:59 2016 -0700
Committer: Alejandro Fernandez <af...@hortonworks.com>
Committed: Thu Sep 15 14:46:37 2016 -0700
----------------------------------------------------------------------
.../libraries/functions/conf_select.py | 39 +++++++++++++++++---
.../hooks/after-INSTALL/test_after_install.py | 18 +++++++++
2 files changed, 52 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/1efc99c5/ambari-common/src/main/python/resource_management/libraries/functions/conf_select.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/conf_select.py b/ambari-common/src/main/python/resource_management/libraries/functions/conf_select.py
index c60b324..8d54053 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/conf_select.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/conf_select.py
@@ -343,7 +343,27 @@ def select(stack_name, package, version, try_create=True, ignore_errors=False):
else:
# missing entirely
# /etc/<component>/conf -> <stack-root>/current/<component>/conf
- Link(conf_dir, to = current_dir)
+ if package in ["atlas", ]:
+ #HACK for Atlas
+ '''
+ In the case of Atlas, the Hive RPM installs /usr/$stack/$version/atlas with some partial packages that
+ contain Hive hooks, while the Atlas RPM is responsible for installing the full content.
+
+ If the user does not have Atlas currently installed on their stack, then /usr/$stack/current/atlas-client
+ will be a broken symlink, and we should not create the
+ symlink /etc/atlas/conf -> /usr/$stack/current/atlas-client/conf .
+ If we mistakenly create this symlink, then when the user performs an EU/RU and then adds Atlas service
+ then the Atlas RPM will not be able to copy its artifacts into /etc/atlas/conf directory and therefore
+ prevent Ambari from by copying those unmanaged contents into /etc/atlas/$version/0
+ '''
+ parent_dir = os.path.dirname(current_dir)
+ if os.path.exists(parent_dir):
+ Link(conf_dir, to=current_dir)
+ else:
+ Logger.info("Will not create symlink from {0} to {1} because the destination's parent dir does not exist.".format(conf_dir, current_dir))
+ else:
+ # Normal path for other packages
+ Link(conf_dir, to=current_dir)
except Exception, exception:
if ignore_errors is True:
@@ -579,15 +599,24 @@ def convert_conf_directories_to_symlinks(package, version, dirs, skip_existing_l
else:
Link(new_symlink, action = "delete")
+ old_conf = dir_def['conf_dir']
+ backup_dir = _get_backup_conf_directory(old_conf)
# link /etc/[component]/conf -> /etc/[component]/conf.backup
# or
# link /etc/[component]/conf -> <stack-root>/current/[component]-client/conf
if link_to == DIRECTORY_TYPE_BACKUP:
- old_conf = dir_def['conf_dir']
- backup_dir = _get_backup_conf_directory(old_conf)
- Link(new_symlink, to = backup_dir)
+ Link(new_symlink, to=backup_dir)
else:
- Link(new_symlink, to = dir_def['current_dir'])
+ Link(new_symlink, to=dir_def['current_dir'])
+
+ #HACK
+ if package in ["atlas", ]:
+ Logger.info("Seeding the new conf symlink {0} from the old backup directory {1} in case any "
+ "unmanaged artifacts are needed.".format(new_symlink, backup_dir))
+ # If /etc/[component]/conf.backup exists, then copy any artifacts not managed by Ambari to the new symlink target
+ # Be careful not to clobber any existing files.
+ Execute(as_sudo(["cp", "-R", "--no-clobber", os.path.join(backup_dir, "*"), new_symlink], auto_escape=False),
+ only_if=format("test -e {new_symlink}"))
except Exception, e:
Logger.warning("Could not change symlink for package {0} to point to {1} directory. Error: {2}".format(package, link_to, e))
http://git-wip-us.apache.org/repos/asf/ambari/blob/1efc99c5/ambari-server/src/test/python/stacks/2.0.6/hooks/after-INSTALL/test_after_install.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/hooks/after-INSTALL/test_after_install.py b/ambari-server/src/test/python/stacks/2.0.6/hooks/after-INSTALL/test_after_install.py
index 434ef51..1bfa173 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/hooks/after-INSTALL/test_after_install.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/hooks/after-INSTALL/test_after_install.py
@@ -89,6 +89,7 @@ class TestHookAfterInstall(RMFTestCase):
self.assertResourceCalled('Execute', ('cp', '-R', '-p', conf_dir, conf_backup_dir),
not_if = 'test -e ' + conf_backup_dir,
sudo = True,)
+
for dir_def in dir_defs:
conf_dir = dir_def['conf_dir']
current_dir = dir_def['current_dir']
@@ -97,6 +98,11 @@ class TestHookAfterInstall(RMFTestCase):
self.assertResourceCalled('Link', conf_dir,
to = current_dir,)
+ #HACK for Atlas
+ if package in ["atlas", ]:
+ self.assertResourceCalled('Execute', 'ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E cp -R --no-clobber /etc/atlas/conf.backup/* /etc/atlas/conf',
+ only_if = 'test -e ' + "/etc/atlas/conf")
+
self.assertNoMoreResources()
@patch("shared_initialization.load_version", new = MagicMock(return_value="2.3.0.0-1243"))
@@ -150,6 +156,7 @@ class TestHookAfterInstall(RMFTestCase):
self.assertResourceCalled('Execute', ('cp', '-R', '-p', conf_dir, conf_backup_dir),
not_if = 'test -e ' + conf_backup_dir,
sudo = True,)
+
for dir_def in dir_defs:
conf_dir = dir_def['conf_dir']
current_dir = dir_def['current_dir']
@@ -158,6 +165,11 @@ class TestHookAfterInstall(RMFTestCase):
self.assertResourceCalled('Link', conf_dir,
to = current_dir,)
+ #HACK for Atlas
+ if package in ["atlas", ]:
+ self.assertResourceCalled('Execute', 'ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E cp -R --no-clobber /etc/atlas/conf.backup/* /etc/atlas/conf',
+ only_if = 'test -e ' + "/etc/atlas/conf")
+
self.assertNoMoreResources()
@@ -244,6 +256,7 @@ class TestHookAfterInstall(RMFTestCase):
self.assertResourceCalled('Execute', ('cp', '-R', '-p', conf_dir, conf_backup_dir),
not_if = 'test -e ' + conf_backup_dir,
sudo = True,)
+
for dir_def in dir_defs:
conf_dir = dir_def['conf_dir']
current_dir = dir_def['current_dir']
@@ -252,6 +265,11 @@ class TestHookAfterInstall(RMFTestCase):
self.assertResourceCalled('Link', conf_dir,
to = current_dir,)
+ #HACK for Atlas
+ if package in ["atlas", ]:
+ self.assertResourceCalled('Execute', 'ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E cp -R --no-clobber /etc/atlas/conf.backup/* /etc/atlas/conf',
+ only_if = 'test -e ' + "/etc/atlas/conf")
+
self.assertNoMoreResources()
[05/27] ambari git commit: AMBARI-18125 : Allow for certain metrics
to skip aggregation determined by client. (avijayan)
Posted by nc...@apache.org.
AMBARI-18125 : Allow for certain metrics to skip aggregation determined by client. (avijayan)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f5ad1de8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f5ad1de8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f5ad1de8
Branch: refs/heads/branch-dev-patch-upgrade
Commit: f5ad1de8689fc45980e5439d873a9331ea6f4723
Parents: 0e34358
Author: Aravindan Vijayan <av...@hortonworks.com>
Authored: Wed Sep 14 15:03:23 2016 -0700
Committer: Aravindan Vijayan <av...@hortonworks.com>
Committed: Wed Sep 14 15:03:34 2016 -0700
----------------------------------------------------------------------
.../metrics2/sink/timeline/TimelineMetric.java | 11 ++
.../timeline/HadoopTimelineMetricsSink.java | 35 ++++--
.../timeline/HadoopTimelineMetricsSinkTest.java | 4 +-
.../src/main/python/core/host_info.py | 4 +-
.../src/test/python/core/TestHostInfo.py | 43 +++----
.../timeline/TimelineMetricConfiguration.java | 3 +
.../TimelineMetricClusterAggregatorSecond.java | 30 ++++-
.../TimelineMetricMetadataManager.java | 9 +-
.../metrics/timeline/query/Condition.java | 1 +
.../timeline/query/DefaultCondition.java | 84 +++++++++++---
.../metrics/timeline/query/EmptyCondition.java | 6 +
.../query/SplitByMetricNamesCondition.java | 6 +
.../timeline/TestPhoenixTransactSQL.java | 50 ++++----
...melineMetricClusterAggregatorSecondTest.java | 5 +
.../timeline/query/DefaultConditionTest.java | 116 +++++++++++++++++++
.../0.1.0/configuration/ams-site.xml | 12 ++
16 files changed, 340 insertions(+), 79 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetric.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetric.java b/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetric.java
index 98f4978..44c9d4a 100644
--- a/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetric.java
+++ b/ambari-metrics/ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/TimelineMetric.java
@@ -17,6 +17,7 @@
*/
package org.apache.hadoop.metrics2.sink.timeline;
+import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
@@ -44,6 +45,7 @@ public class TimelineMetric implements Comparable<TimelineMetric> {
private String type;
private String units;
private TreeMap<Long, Double> metricValues = new TreeMap<Long, Double>();
+ private Map<String, String> metadata = new HashMap<>();
// default
public TimelineMetric() {
@@ -148,6 +150,15 @@ public class TimelineMetric implements Comparable<TimelineMetric> {
this.metricValues.putAll(metricValues);
}
+ @XmlElement(name = "metadata")
+ public Map<String,String> getMetadata () {
+ return metadata;
+ }
+
+ public void setMetadata (Map<String,String> metadata) {
+ this.metadata = metadata;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-hadoop-sink/src/main/java/org/apache/hadoop/metrics2/sink/timeline/HadoopTimelineMetricsSink.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-hadoop-sink/src/main/java/org/apache/hadoop/metrics2/sink/timeline/HadoopTimelineMetricsSink.java b/ambari-metrics/ambari-metrics-hadoop-sink/src/main/java/org/apache/hadoop/metrics2/sink/timeline/HadoopTimelineMetricsSink.java
index c534121..b720ba9 100644
--- a/ambari-metrics/ambari-metrics-hadoop-sink/src/main/java/org/apache/hadoop/metrics2/sink/timeline/HadoopTimelineMetricsSink.java
+++ b/ambari-metrics/ambari-metrics-hadoop-sink/src/main/java/org/apache/hadoop/metrics2/sink/timeline/HadoopTimelineMetricsSink.java
@@ -34,6 +34,7 @@ import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -228,6 +229,7 @@ public class HadoopTimelineMetricsSink extends AbstractTimelineMetricsSink imple
String contextName = record.context();
StringBuilder sb = new StringBuilder();
+ boolean skipAggregation = false;
// Transform ipc.8020 -> ipc.client, ipc.8040 -> ipc.datanode, etc.
if (contextName.startsWith("ipc.")) {
@@ -239,17 +241,19 @@ public class HadoopTimelineMetricsSink extends AbstractTimelineMetricsSink imple
sb.append(contextName);
sb.append('.');
- // Similar to GangliaContext adding processName to distinguish jvm
- // metrics for co-hosted daemons. We only do this for HBase since the
- // appId is shared for Master and RS.
- if (contextName.equals("jvm")) {
- if (record.tags() != null) {
- for (MetricsTag tag : record.tags()) {
- if (tag.info().name().equalsIgnoreCase("processName") &&
- (tag.value().equals("RegionServer") || tag.value().equals("Master"))) {
- sb.append(tag.value());
- sb.append('.');
- }
+
+ if (record.tags() != null) {
+ for (MetricsTag tag : record.tags()) {
+ if (StringUtils.isNotEmpty(tag.name()) && tag.name().equals("skipAggregation")) {
+ skipAggregation = String.valueOf(true).equals(tag.value());
+ }
+ // Similar to GangliaContext adding processName to distinguish jvm
+ // metrics for co-hosted daemons. We only do this for HBase since the
+ // appId is shared for Master and RS.
+ if (contextName.equals("jvm") && tag.info().name().equalsIgnoreCase("processName") &&
+ (tag.value().equals("RegionServer") || tag.value().equals("Master"))) {
+ sb.append(tag.value());
+ sb.append('.');
}
}
}
@@ -281,6 +285,12 @@ public class HadoopTimelineMetricsSink extends AbstractTimelineMetricsSink imple
Collection<AbstractMetric> metrics = (Collection<AbstractMetric>) record.metrics();
List<TimelineMetric> metricList = new ArrayList<TimelineMetric>();
+ Map<String, String> metadata = null;
+ if (skipAggregation) {
+ metadata = Collections.singletonMap("skipAggregation", "true");
+ }
+
+
long startTime = record.timestamp();
for (AbstractMetric metric : metrics) {
@@ -294,6 +304,9 @@ public class HadoopTimelineMetricsSink extends AbstractTimelineMetricsSink imple
timelineMetric.setStartTime(startTime);
timelineMetric.setType(metric.type() != null ? metric.type().name() : null);
timelineMetric.getMetricValues().put(startTime, value.doubleValue());
+ if (metadata != null) {
+ timelineMetric.setMetadata(metadata);
+ }
// Put intermediate values into the cache until it is time to send
boolean isCounter = MetricType.COUNTER == metric.type();
metricsCache.putTimelineMetric(timelineMetric, isCounter);
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-hadoop-sink/src/test/java/org/apache/hadoop/metrics2/sink/timeline/HadoopTimelineMetricsSinkTest.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-hadoop-sink/src/test/java/org/apache/hadoop/metrics2/sink/timeline/HadoopTimelineMetricsSinkTest.java b/ambari-metrics/ambari-metrics-hadoop-sink/src/test/java/org/apache/hadoop/metrics2/sink/timeline/HadoopTimelineMetricsSinkTest.java
index ea7f72d..f44ca35 100644
--- a/ambari-metrics/ambari-metrics-hadoop-sink/src/test/java/org/apache/hadoop/metrics2/sink/timeline/HadoopTimelineMetricsSinkTest.java
+++ b/ambari-metrics/ambari-metrics-hadoop-sink/src/test/java/org/apache/hadoop/metrics2/sink/timeline/HadoopTimelineMetricsSinkTest.java
@@ -362,8 +362,8 @@ public class HadoopTimelineMetricsSinkTest {
}
}, "8040")
);
- expect(record.tags()).andReturn(tags1).times(6);
- expect(record.tags()).andReturn(tags2).times(6);
+ expect(record.tags()).andReturn(tags1).times(12);
+ expect(record.tags()).andReturn(tags2).times(12);
sink.appendPrefix(eq(record), (StringBuilder) anyObject());
expectLastCall().anyTimes().andStubAnswer(new IAnswer<Object>() {
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
index f79cacd..632c86b 100644
--- a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
+++ b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
@@ -248,8 +248,10 @@ class HostInfo():
skip_disk_patterns = self.__config.get_disk_metrics_skip_pattern()
logger.debug('skip_disk_patterns: %s' % skip_disk_patterns)
+ print skip_disk_patterns
if not skip_disk_patterns or skip_disk_patterns == 'None':
io_counters = psutil.disk_io_counters()
+ print io_counters
else:
sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
'read_bytes', 'write_bytes',
@@ -303,7 +305,7 @@ class HostInfo():
disk = item[0]
logger.debug('Adding disk counters for %s' % str(disk))
sdiskio = item[1]
- prefix = 'disk_{0}_'.format(disk_counter)
+ prefix = 'sdisk_{0}_'.format(disk)
counter_dict = {
prefix + 'read_count' : sdiskio.read_count if hasattr(sdiskio, 'read_count') else 0,
prefix + 'write_count' : sdiskio.write_count if hasattr(sdiskio, 'write_count') else 0,
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py b/ambari-metrics/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py
index d3d3f05..63a1ae1 100644
--- a/ambari-metrics/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py
+++ b/ambari-metrics/ambari-metrics-host-monitoring/src/test/python/core/TestHostInfo.py
@@ -23,6 +23,7 @@ from host_info import HostInfo
import platform
from unittest import TestCase
from mock.mock import patch, MagicMock
+from core.config_reader import Configuration
import collections
logger = logging.getLogger()
@@ -138,7 +139,9 @@ class TestHostInfo(TestCase):
'read_time', 'write_time'])
io_mock.return_value = Counters(0, 1, 2, 3, 4, 5)
- hostinfo = HostInfo(MagicMock())
+ c = MagicMock()
+ c.get_disk_metrics_skip_pattern.return_value = None
+ hostinfo = HostInfo(c)
disk_counters = hostinfo.get_combined_disk_io_counters()
@@ -179,28 +182,28 @@ class TestHostInfo(TestCase):
disk_counter_per_disk = hostinfo.get_disk_io_counters_per_disk()
- # Assert for sda1
- self.assertEqual(disk_counter_per_disk['disk_1_read_count'], 0)
- self.assertEqual(disk_counter_per_disk['disk_1_write_count'], 1)
- self.assertEqual(disk_counter_per_disk['disk_1_read_bytes'], 2)
- self.assertEqual(disk_counter_per_disk['disk_1_write_bytes'], 3)
- self.assertEqual(disk_counter_per_disk['disk_1_read_time'], 4)
- self.assertEqual(disk_counter_per_disk['disk_1_write_time'], 5)
- self.assertEqual(disk_counter_per_disk['disk_1_busy_time'], 6)
- self.assertEqual(disk_counter_per_disk['disk_1_read_merged_count'], 7)
- self.assertEqual(disk_counter_per_disk['disk_1_write_merged_count'], 8)
+ # Assert for sdisk_sda1
+ self.assertEqual(disk_counter_per_disk['sdisk_sda1_read_count'], 0)
+ self.assertEqual(disk_counter_per_disk['sdisk_sda1_write_count'], 1)
+ self.assertEqual(disk_counter_per_disk['sdisk_sda1_read_bytes'], 2)
+ self.assertEqual(disk_counter_per_disk['sdisk_sda1_write_bytes'], 3)
+ self.assertEqual(disk_counter_per_disk['sdisk_sda1_read_time'], 4)
+ self.assertEqual(disk_counter_per_disk['sdisk_sda1_write_time'], 5)
+ self.assertEqual(disk_counter_per_disk['sdisk_sda1_busy_time'], 6)
+ self.assertEqual(disk_counter_per_disk['sdisk_sda1_read_merged_count'], 7)
+ self.assertEqual(disk_counter_per_disk['sdisk_sda1_write_merged_count'], 8)
# Assert for sdb1
- self.assertEqual(disk_counter_per_disk['disk_2_read_count'], 9)
- self.assertEqual(disk_counter_per_disk['disk_2_write_count'], 10)
- self.assertEqual(disk_counter_per_disk['disk_2_read_bytes'], 11)
- self.assertEqual(disk_counter_per_disk['disk_2_write_bytes'], 12)
- self.assertEqual(disk_counter_per_disk['disk_2_read_time'], 13)
- self.assertEqual(disk_counter_per_disk['disk_2_write_time'], 14)
- self.assertEqual(disk_counter_per_disk['disk_2_busy_time'], 15)
- self.assertEqual(disk_counter_per_disk['disk_2_read_merged_count'], 16)
- self.assertEqual(disk_counter_per_disk['disk_2_write_merged_count'], 17)
+ self.assertEqual(disk_counter_per_disk['sdisk_sdb1_read_count'], 9)
+ self.assertEqual(disk_counter_per_disk['sdisk_sdb1_write_count'], 10)
+ self.assertEqual(disk_counter_per_disk['sdisk_sdb1_read_bytes'], 11)
+ self.assertEqual(disk_counter_per_disk['sdisk_sdb1_write_bytes'], 12)
+ self.assertEqual(disk_counter_per_disk['sdisk_sdb1_read_time'], 13)
+ self.assertEqual(disk_counter_per_disk['sdisk_sdb1_write_time'], 14)
+ self.assertEqual(disk_counter_per_disk['sdisk_sdb1_busy_time'], 15)
+ self.assertEqual(disk_counter_per_disk['sdisk_sdb1_read_merged_count'], 16)
+ self.assertEqual(disk_counter_per_disk['sdisk_sdb1_write_merged_count'], 17)
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TimelineMetricConfiguration.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TimelineMetricConfiguration.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TimelineMetricConfiguration.java
index 1da68ba..22710b0 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TimelineMetricConfiguration.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TimelineMetricConfiguration.java
@@ -255,6 +255,9 @@ public class TimelineMetricConfiguration {
public static final String DEFAULT_TOPN_HOSTS_LIMIT =
"timeline.metrics.default.topn.hosts.limit";
+ public static final String TIMELINE_METRIC_AGGREGATION_SQL_FILTERS =
+ "timeline.metrics.cluster.aggregation.sql.filters";
+
public static final String HOST_APP_ID = "HOST";
public static final String DEFAULT_INSTANCE_PORT = "12001";
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
index 5f40d21..6bc0f18 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
@@ -23,9 +23,11 @@ import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.metrics2.sink.timeline.PostProcessingUtil;
import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
+import org.apache.hadoop.metrics2.sink.timeline.TimelineMetricMetadata;
import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixHBaseAccessor;
import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.availability.AggregationTaskRunner.AGGREGATOR_NAME;
import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.availability.MetricCollectorHAController;
+import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.discovery.TimelineMetricMetadataKey;
import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.discovery.TimelineMetricMetadataManager;
import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.query.Condition;
import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.query.DefaultCondition;
@@ -34,6 +36,7 @@ import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -47,6 +50,7 @@ import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.ti
import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.TimelineMetricConfiguration.TIMELINE_METRICS_CLUSTER_AGGREGATOR_INTERPOLATION_ENABLED;
import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.query.PhoenixTransactSQL.GET_METRIC_SQL;
import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.query.PhoenixTransactSQL.METRICS_RECORD_TABLE_NAME;
+import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.TimelineMetricConfiguration.TIMELINE_METRIC_AGGREGATION_SQL_FILTERS;
/**
* Aggregates a metric across all hosts in the cluster. Reads metrics from
@@ -60,6 +64,8 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
// 1 minute client side buffering adjustment
private final Long serverTimeShiftAdjustment;
private final boolean interpolationEnabled;
+ private TimelineMetricMetadataManager metadataManagerInstance;
+ private String skipAggrPatternStrings;
public TimelineMetricClusterAggregatorSecond(AGGREGATOR_NAME aggregatorName,
TimelineMetricMetadataManager metadataManager,
@@ -78,10 +84,12 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
sleepIntervalMillis, checkpointCutOffMultiplier, aggregatorDisabledParam,
tableName, outputTableName, nativeTimeRangeDelay, haController);
+ this.metadataManagerInstance = metadataManager;
appAggregator = new TimelineMetricAppAggregator(metadataManager, metricsConf);
this.timeSliceIntervalMillis = timeSliceInterval;
this.serverTimeShiftAdjustment = Long.parseLong(metricsConf.get(SERVER_SIDE_TIMESIFT_ADJUSTMENT, "90000"));
this.interpolationEnabled = Boolean.parseBoolean(metricsConf.get(TIMELINE_METRICS_CLUSTER_AGGREGATOR_INTERPOLATION_ENABLED, "true"));
+ this.skipAggrPatternStrings = metricsConf.get(TIMELINE_METRIC_AGGREGATION_SQL_FILTERS);
}
@Override
@@ -103,8 +111,19 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
@Override
protected Condition prepareMetricQueryCondition(long startTime, long endTime) {
- Condition condition = new DefaultCondition(null, null, null, null, startTime - serverTimeShiftAdjustment,
+
+ List<String> metricNames = new ArrayList<>();
+ boolean metricNamesNotCondition = false;
+
+ if (!StringUtils.isEmpty(skipAggrPatternStrings)) {
+ LOG.info("Skipping aggregation for metric patterns : " + skipAggrPatternStrings);
+ metricNames.addAll(Arrays.asList(skipAggrPatternStrings.split(",")));
+ metricNamesNotCondition = true;
+ }
+
+ Condition condition = new DefaultCondition(metricNames, null, null, null, startTime - serverTimeShiftAdjustment,
endTime, null, null, true);
+ condition.setMetricNamesNotCondition(metricNamesNotCondition);
condition.setNoLimit();
condition.setFetchSize(resultsetFetchSize);
condition.setStatement(String.format(GET_METRIC_SQL,
@@ -180,6 +199,15 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
protected int processAggregateClusterMetrics(Map<TimelineClusterMetric, MetricClusterAggregate> aggregateClusterMetrics,
TimelineMetric metric, List<Long[]> timeSlices) {
// Create time slices
+
+ TimelineMetricMetadataKey appKey = new TimelineMetricMetadataKey(metric.getMetricName(), metric.getAppId());
+ TimelineMetricMetadata metricMetadata = metadataManagerInstance.getMetadataCacheValue(appKey);
+
+ if (metricMetadata != null && !metricMetadata.isSupportsAggregates()) {
+ LOG.debug("Skipping cluster aggregation for " + metric.getMetricName());
+ return 0;
+ }
+
Map<TimelineClusterMetric, Double> clusterMetrics = sliceFromTimelineMetric(metric, timeSlices);
int numHosts = 0;
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/discovery/TimelineMetricMetadataManager.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/discovery/TimelineMetricMetadataManager.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/discovery/TimelineMetricMetadataManager.java
index fd471fb..d0d1dbf 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/discovery/TimelineMetricMetadataManager.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/discovery/TimelineMetricMetadataManager.java
@@ -17,6 +17,8 @@
*/
package org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.discovery;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -202,7 +204,7 @@ public class TimelineMetricMetadataManager {
timelineMetric.getUnits(),
timelineMetric.getType(),
timelineMetric.getStartTime(),
- true
+ supportAggregates(timelineMetric)
);
}
@@ -229,4 +231,9 @@ public class TimelineMetricMetadataManager {
Map<String, Set<String>> getHostedAppsFromStore() throws SQLException {
return hBaseAccessor.getHostedAppsMetadata();
}
+
+ private boolean supportAggregates(TimelineMetric metric) {
+ return MapUtils.isEmpty(metric.getMetadata()) ||
+ !(String.valueOf(true).equals(metric.getMetadata().get("skipAggregation")));
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/Condition.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/Condition.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/Condition.java
index 4873c24..9aa64bd 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/Condition.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/Condition.java
@@ -44,4 +44,5 @@ public interface Condition {
void addOrderByColumn(String column);
void setNoLimit();
boolean doUpdate();
+ void setMetricNamesNotCondition(boolean metricNamesNotCondition);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/DefaultCondition.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/DefaultCondition.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/DefaultCondition.java
index 0851e8f..a4f7014 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/DefaultCondition.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/DefaultCondition.java
@@ -16,12 +16,14 @@
* limitations under the License.
*/
package org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.query;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.metrics2.sink.timeline.TopNConfig;
import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixHBaseAccessor;
import org.apache.hadoop.metrics2.sink.timeline.Precision;
+import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -40,6 +42,7 @@ public class DefaultCondition implements Condition {
Integer fetchSize;
String statement;
Set<String> orderByColumns = new LinkedHashSet<String>();
+ boolean metricNamesNotCondition = false;
private static final Log LOG = LogFactory.getLog(DefaultCondition.class);
@@ -215,44 +218,85 @@ public class DefaultCondition implements Condition {
protected boolean appendMetricNameClause(StringBuilder sb) {
boolean appendConjunction = false;
- StringBuilder metricsLike = new StringBuilder();
- StringBuilder metricsIn = new StringBuilder();
+ List<String> metricsLike = new ArrayList<>();
+ List<String> metricsIn = new ArrayList<>();
if (getMetricNames() != null) {
for (String name : getMetricNames()) {
if (name.contains("%")) {
- if (metricsLike.length() > 1) {
- metricsLike.append(" OR ");
- }
- metricsLike.append("METRIC_NAME LIKE ?");
+ metricsLike.add(name);
} else {
- if (metricsIn.length() > 0) {
- metricsIn.append(", ");
- }
- metricsIn.append("?");
+ metricsIn.add(name);
}
}
- if (metricsIn.length() > 0) {
- sb.append("(METRIC_NAME IN (");
- sb.append(metricsIn);
+ // Put a '(' first
+ sb.append("(");
+
+ //IN clause
+ // METRIC_NAME (NOT) IN (?,?,?,?)
+ if (CollectionUtils.isNotEmpty(metricsIn)) {
+ sb.append("METRIC_NAME");
+ if (metricNamesNotCondition) {
+ sb.append(" NOT");
+ }
+ sb.append(" IN (");
+ //Append ?,?,?,?
+ for (int i = 0; i < metricsIn.size(); i++) {
+ sb.append("?");
+ if (i < metricsIn.size() - 1) {
+ sb.append(", ");
+ }
+ }
sb.append(")");
appendConjunction = true;
}
- if (metricsLike.length() > 0) {
- if (appendConjunction) {
- sb.append(" OR ");
+ //Put an OR/AND if both types are present
+ if (CollectionUtils.isNotEmpty(metricsIn) &&
+ CollectionUtils.isNotEmpty(metricsLike)) {
+ if (metricNamesNotCondition) {
+ sb.append(" AND ");
} else {
- sb.append("(");
+ sb.append(" OR ");
+ }
+ }
+
+ //LIKE clause
+ // METRIC_NAME (NOT) LIKE ? OR(AND) METRIC_NAME LIKE ?
+ if (CollectionUtils.isNotEmpty(metricsLike)) {
+
+ for (int i = 0; i < metricsLike.size(); i++) {
+ sb.append("METRIC_NAME");
+ if (metricNamesNotCondition) {
+ sb.append(" NOT");
+ }
+ sb.append(" LIKE ");
+ sb.append("?");
+
+ if (i < metricsLike.size() - 1) {
+ if (metricNamesNotCondition) {
+ sb.append(" AND ");
+ } else {
+ sb.append(" OR ");
+ }
+ }
}
- sb.append(metricsLike);
appendConjunction = true;
}
+ // Finish with a ')'
if (appendConjunction) {
sb.append(")");
}
+
+ metricNames.clear();
+ if (CollectionUtils.isNotEmpty(metricsIn)) {
+ metricNames.addAll(metricsIn);
+ }
+ if (CollectionUtils.isNotEmpty(metricsLike)) {
+ metricNames.addAll(metricsLike);
+ }
}
return appendConjunction;
}
@@ -333,4 +377,8 @@ public class DefaultCondition implements Condition {
}
return false;
}
+
+ public void setMetricNamesNotCondition(boolean metricNamesNotCondition) {
+ this.metricNamesNotCondition = metricNamesNotCondition;
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/EmptyCondition.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/EmptyCondition.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/EmptyCondition.java
index 34174e2..43ab88c 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/EmptyCondition.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/EmptyCondition.java
@@ -27,6 +27,7 @@ import java.util.List;
public class EmptyCondition implements Condition {
String statement;
boolean doUpdate = false;
+ boolean metricNamesNotCondition = false;
@Override
public boolean isEmpty() {
@@ -144,4 +145,9 @@ public class EmptyCondition implements Condition {
" doUpdate = " + this.doUpdate() +
" }";
}
+
+ @Override
+ public void setMetricNamesNotCondition(boolean metricNamesNotCondition) {
+ this.metricNamesNotCondition = metricNamesNotCondition;
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/SplitByMetricNamesCondition.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/SplitByMetricNamesCondition.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/SplitByMetricNamesCondition.java
index b8ca599..bb4dced 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/SplitByMetricNamesCondition.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/SplitByMetricNamesCondition.java
@@ -25,6 +25,7 @@ import java.util.List;
public class SplitByMetricNamesCondition implements Condition {
private final Condition adaptee;
private String currentMetric;
+ private boolean metricNamesNotCondition = false;
public SplitByMetricNamesCondition(Condition condition){
this.adaptee = condition;
@@ -180,4 +181,9 @@ public class SplitByMetricNamesCondition implements Condition {
public void setCurrentMetric(String currentMetric) {
this.currentMetric = currentMetric;
}
+
+ @Override
+ public void setMetricNamesNotCondition(boolean metricNamesNotCondition) {
+ this.metricNamesNotCondition = metricNamesNotCondition;
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
index a95655d..e988a61 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/TestPhoenixTransactSQL.java
@@ -47,7 +47,7 @@ public class TestPhoenixTransactSQL {
@Test
public void testConditionClause() throws Exception {
Condition condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", 1407959718L, 1407959918L, null, null, false);
String preparedClause = condition.getConditionClause().toString();
@@ -78,7 +78,7 @@ public class TestPhoenixTransactSQL {
@Test
public void testLikeConditionClause() throws Exception {
Condition condition = new DefaultCondition(
- Arrays.asList("cpu_user", "some=%.metric"),
+ new ArrayList<>(Arrays.asList("cpu_user", "some=%.metric")),
Collections.singletonList("h1"), "a1", "i1", 1407959718L, 1407959918L,
null, null, false);
@@ -115,7 +115,7 @@ public class TestPhoenixTransactSQL {
condition = new DefaultCondition(
- Arrays.asList("some=%.metric"), Collections.singletonList("h1"), "a1", "i1",
+ new ArrayList<>(Arrays.asList("some=%.metric")), Collections.singletonList("h1"), "a1", "i1",
1407959718L, 1407959918L, null, null, false);
preparedClause = condition.getConditionClause().toString();
@@ -127,7 +127,7 @@ public class TestPhoenixTransactSQL {
condition = new DefaultCondition(
- Arrays.asList("some=%.metric1", "some=%.metric2", "some=%.metric3"),
+ new ArrayList<>(Arrays.asList("some=%.metric1", "some=%.metric2", "some=%.metric3")),
Collections.singletonList("h1"), "a1", "i1",
1407959718L, 1407959918L, null, null, false);
@@ -142,7 +142,7 @@ public class TestPhoenixTransactSQL {
@Test
public void testPrepareGetAggregatePrecisionMINUTES() throws SQLException {
Condition condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", 1407959718L, 1407959918L, Precision.MINUTES, null, false);
Connection connection = createNiceMock(Connection.class);
PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class);
@@ -163,7 +163,7 @@ public class TestPhoenixTransactSQL {
Long startTime = 1407959718L;
//SECONDS precision
Condition condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", startTime, endTime, null, null, false);
Connection connection = createNiceMock(Connection.class);
PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class);
@@ -181,7 +181,7 @@ public class TestPhoenixTransactSQL {
// MINUTES precision
startTime = endTime-PhoenixTransactSQL.DAY/1000;
condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", startTime, endTime, null, null, false);
connection = createNiceMock(Connection.class);
preparedStatement = createNiceMock(PreparedStatement.class);
@@ -199,7 +199,7 @@ public class TestPhoenixTransactSQL {
// HOURS precision
startTime = endTime-PhoenixTransactSQL.DAY*30/1000;
condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", startTime, endTime, null, null, false);
connection = createNiceMock(Connection.class);
preparedStatement = createNiceMock(PreparedStatement.class);
@@ -217,7 +217,7 @@ public class TestPhoenixTransactSQL {
// DAYS precision
startTime = endTime-PhoenixTransactSQL.DAY*30*2/1000;
condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", startTime, endTime, null, null, false);
connection = createNiceMock(Connection.class);
preparedStatement = createNiceMock(PreparedStatement.class);
@@ -236,7 +236,7 @@ public class TestPhoenixTransactSQL {
@Test
public void testPrepareGetAggregatePrecisionHours() throws SQLException {
Condition condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", 1407959718L, 1407959918L, Precision.HOURS, null, false);
Connection connection = createNiceMock(Connection.class);
PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class);
@@ -254,7 +254,7 @@ public class TestPhoenixTransactSQL {
@Test
public void testPrepareGetMetricsPrecisionMinutes() throws SQLException {
Condition condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", 1407959718L, 1407959918L, Precision.MINUTES, null, false);
Connection connection = createNiceMock(Connection.class);
PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class);
@@ -275,7 +275,7 @@ public class TestPhoenixTransactSQL {
Long startTime = endTime - 200;
// SECONDS precision
Condition condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", startTime, endTime, null, null, false);
Connection connection = createNiceMock(Connection.class);
PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class);
@@ -294,7 +294,7 @@ public class TestPhoenixTransactSQL {
// SECONDS precision
startTime = endTime-PhoenixTransactSQL.HOUR*2/1000;
condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", startTime, endTime, null, null, false);
connection = createNiceMock(Connection.class);
preparedStatement = createNiceMock(PreparedStatement.class);
@@ -311,7 +311,7 @@ public class TestPhoenixTransactSQL {
// MINUTES precision
startTime = endTime-PhoenixTransactSQL.DAY/1000;
condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", startTime, endTime, null, null, false);
connection = createNiceMock(Connection.class);
preparedStatement = createNiceMock(PreparedStatement.class);
@@ -328,7 +328,7 @@ public class TestPhoenixTransactSQL {
// HOURS precision
startTime = endTime-PhoenixTransactSQL.DAY*30/1000;
condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", startTime, endTime, null, null, false);
connection = createNiceMock(Connection.class);
preparedStatement = createNiceMock(PreparedStatement.class);
@@ -345,7 +345,7 @@ public class TestPhoenixTransactSQL {
// DAYS precision
startTime = endTime-PhoenixTransactSQL.DAY*30*2/1000;
condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", startTime, endTime, null, null, false);
connection = createNiceMock(Connection.class);
preparedStatement = createNiceMock(PreparedStatement.class);
@@ -364,7 +364,7 @@ public class TestPhoenixTransactSQL {
@Test
public void testPrepareGetLatestMetricSqlStmtMultipleHostNames() throws SQLException {
Condition condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Arrays.asList("h1", "h2"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Arrays.asList("h1", "h2"),
"a1", "i1", null, null, null, null, false);
Connection connection = createNiceMock(Connection.class);
PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class);
@@ -390,7 +390,7 @@ public class TestPhoenixTransactSQL {
public void testPrepareGetLatestMetricSqlStmtSortMergeJoinAlgorithm()
throws SQLException {
Condition condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Arrays.asList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Arrays.asList("h1"),
"a1", "i1", null, null, null, null, false);
Connection connection = createNiceMock(Connection.class);
PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class);
@@ -413,7 +413,7 @@ public class TestPhoenixTransactSQL {
@Test
public void testPrepareGetMetricsPrecisionHours() throws SQLException {
Condition condition = new DefaultCondition(
- Arrays.asList("cpu_user", "mem_free"), Collections.singletonList("h1"),
+ new ArrayList<>(Arrays.asList("cpu_user", "mem_free")), Collections.singletonList("h1"),
"a1", "i1", 1407959718L, 1407959918L, Precision.HOURS, null, false);
Connection connection = createNiceMock(Connection.class);
PreparedStatement preparedStatement = createNiceMock(PreparedStatement.class);
@@ -561,7 +561,7 @@ public class TestPhoenixTransactSQL {
List<String> hosts = Arrays.asList("h1", "h2", "h3", "h4");
Condition condition = new TopNCondition(
- Arrays.asList("cpu_user"), hosts,
+ new ArrayList<>(Collections.singletonList("cpu_user")), hosts,
"a1", "i1", 1407959718L, 1407959918L, null, null, false, 2, null, false);
String conditionClause = condition.getConditionClause().toString();
@@ -580,7 +580,7 @@ public class TestPhoenixTransactSQL {
@Test
public void testTopNMetricsConditionClause() throws Exception {
- List<String> metricNames = Arrays.asList("m1", "m2", "m3");
+ List<String> metricNames = new ArrayList<>(Arrays.asList("m1", "m2", "m3"));
Condition condition = new TopNCondition(
metricNames, Collections.singletonList("h1"),
@@ -602,7 +602,7 @@ public class TestPhoenixTransactSQL {
@Test
public void testTopNMetricsIllegalConditionClause() throws Exception {
- List<String> metricNames = Arrays.asList("m1", "m2");
+ List<String> metricNames = new ArrayList<>(Arrays.asList("m1", "m2"));
List<String> hosts = Arrays.asList("h1", "h2");
@@ -616,7 +616,7 @@ public class TestPhoenixTransactSQL {
@Test
public void testHostsRegexpConditionClause() {
Condition condition = new TopNCondition(
- Arrays.asList("m1"), Arrays.asList("%.ambari", "host1.apache"),
+ new ArrayList<>(Arrays.asList("m1")), Arrays.asList("%.ambari", "host1.apache"),
"a1", "i1", 1407959718L, 1407959918L, null, null, false, 2, null, false);
String conditionClause = condition.getConditionClause().toString();
@@ -629,7 +629,7 @@ public class TestPhoenixTransactSQL {
Assert.assertEquals(expectedClause, conditionClause);
condition = new TopNCondition(
- Arrays.asList("m1"), Arrays.asList("%.ambari"),
+ new ArrayList<>(Arrays.asList("m1")), Arrays.asList("%.ambari"),
"a1", "i1", 1407959718L, 1407959918L, null, null, false, 2, null, false);
conditionClause = condition.getConditionClause().toString();
@@ -643,7 +643,7 @@ public class TestPhoenixTransactSQL {
Assert.assertEquals(expectedClause, conditionClause);
condition = new TopNCondition(
- Arrays.asList("m1", "m2", "m3"), Arrays.asList("h1.ambari"),
+ new ArrayList<>(Arrays.asList("m1", "m2", "m3")), Arrays.asList("h1.ambari"),
"a1", "i1", 1407959718L, 1407959918L, null, null, false, 2, null, false);
conditionClause = condition.getConditionClause().toString();
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecondTest.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecondTest.java b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecondTest.java
index 014772f..97b6258 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecondTest.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecondTest.java
@@ -20,6 +20,7 @@ package org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline
import junit.framework.Assert;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
+import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.discovery.TimelineMetricMetadataKey;
import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.discovery.TimelineMetricMetadataManager;
import org.easymock.EasyMock;
import org.junit.Test;
@@ -115,6 +116,10 @@ public class TimelineMetricClusterAggregatorSecondTest {
Configuration configuration = new Configuration();
TimelineMetricMetadataManager metricMetadataManagerMock = EasyMock.createNiceMock(TimelineMetricMetadataManager.class);
+ EasyMock.expect(metricMetadataManagerMock.getMetadataCacheValue((TimelineMetricMetadataKey)EasyMock.anyObject()))
+ .andReturn(null).anyTimes();
+ EasyMock.replay(metricMetadataManagerMock);
+
TimelineMetricClusterAggregatorSecond secondAggregator = new TimelineMetricClusterAggregatorSecond(
METRIC_AGGREGATE_SECOND, metricMetadataManagerMock, null, configuration, null,
aggregatorInterval, 2, "false", "", "", aggregatorInterval, sliceInterval, null
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/DefaultConditionTest.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/DefaultConditionTest.java b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/DefaultConditionTest.java
new file mode 100644
index 0000000..e4e9225
--- /dev/null
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/query/DefaultConditionTest.java
@@ -0,0 +1,116 @@
+/**
+ * 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.
+ */
+
+package org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.query;
+
+import junit.framework.Assert;
+import org.apache.commons.collections.CollectionUtils;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DefaultConditionTest {
+
+ @Test
+ public void testMetricNameWhereCondition() {
+ List<String> metricNames = new ArrayList<>();
+
+ //Only IN clause.
+
+ metricNames.add("M1");
+ DefaultCondition condition = new DefaultCondition(metricNames,null,null,null,null,null,null,null,true);
+ StringBuilder sb = new StringBuilder();
+ condition.appendMetricNameClause(sb);
+ Assert.assertEquals(sb.toString(), "(METRIC_NAME IN (?))");
+ Assert.assertTrue(CollectionUtils.isEqualCollection(metricNames, condition.getMetricNames()));
+
+ metricNames.add("m2");
+ condition = new DefaultCondition(metricNames,null,null,null,null,null,null,null,true);
+ sb = new StringBuilder();
+ condition.appendMetricNameClause(sb);
+ Assert.assertEquals(sb.toString(), "(METRIC_NAME IN (?, ?))");
+ Assert.assertTrue(CollectionUtils.isEqualCollection(metricNames, condition.getMetricNames()));
+
+ // Only NOT IN clause
+ condition = new DefaultCondition(metricNames,null,null,null,null,null,null,null,true);
+ condition.setMetricNamesNotCondition(true);
+ sb = new StringBuilder();
+ condition.appendMetricNameClause(sb);
+ Assert.assertEquals(sb.toString(), "(METRIC_NAME NOT IN (?, ?))");
+ Assert.assertTrue(CollectionUtils.isEqualCollection(metricNames, condition.getMetricNames()));
+
+ metricNames.clear();
+
+ //Only LIKE clause
+ metricNames.add("disk%");
+ condition = new DefaultCondition(metricNames,null,null,null,null,null,null,null,true);
+ sb = new StringBuilder();
+ condition.appendMetricNameClause(sb);
+ Assert.assertEquals(sb.toString(), "(METRIC_NAME LIKE ?)");
+ Assert.assertTrue(CollectionUtils.isEqualCollection(metricNames, condition.getMetricNames()));
+
+ metricNames.add("cpu%");
+ condition = new DefaultCondition(metricNames,null,null,null,null,null,null,null,true);
+ sb = new StringBuilder();
+ condition.appendMetricNameClause(sb);
+ Assert.assertEquals(sb.toString(), "(METRIC_NAME LIKE ? OR METRIC_NAME LIKE ?)");
+ Assert.assertTrue(CollectionUtils.isEqualCollection(metricNames, condition.getMetricNames()));
+
+ //Only NOT LIKE clause
+ condition = new DefaultCondition(metricNames,null,null,null,null,null,null,null,true);
+ condition.setMetricNamesNotCondition(true);
+ sb = new StringBuilder();
+ condition.appendMetricNameClause(sb);
+ Assert.assertEquals(sb.toString(), "(METRIC_NAME NOT LIKE ? AND METRIC_NAME NOT LIKE ?)");
+ Assert.assertTrue(CollectionUtils.isEqualCollection(metricNames, condition.getMetricNames()));
+
+ metricNames.clear();
+
+ // IN followed by LIKE clause
+ metricNames.add("M1");
+ metricNames.add("disk%");
+ metricNames.add("M2");
+ condition = new DefaultCondition(metricNames,null,null,null,null,null,null,null,true);
+ sb = new StringBuilder();
+ condition.appendMetricNameClause(sb);
+ Assert.assertEquals(sb.toString(), "(METRIC_NAME IN (?, ?) OR METRIC_NAME LIKE ?)");
+ Assert.assertEquals(metricNames.get(2), "disk%");
+
+ metricNames.clear();
+ //NOT IN followed by NOT LIKE clause
+ metricNames.add("disk%");
+ metricNames.add("metric1");
+ metricNames.add("cpu%");
+ condition = new DefaultCondition(metricNames,null,null,null,null,null,null,null,true);
+ sb = new StringBuilder();
+ condition.setMetricNamesNotCondition(true);
+ condition.appendMetricNameClause(sb);
+ Assert.assertEquals(sb.toString(), "(METRIC_NAME NOT IN (?) AND METRIC_NAME NOT LIKE ? AND METRIC_NAME NOT LIKE ?)");
+ Assert.assertEquals(metricNames.get(0), "metric1");
+
+ //Empty
+ metricNames.clear();
+ condition = new DefaultCondition(metricNames,null,null,null,null,null,null,null,true);
+ sb = new StringBuilder();
+ condition.appendMetricNameClause(sb);
+ Assert.assertEquals(sb.toString(), "");
+
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/ambari/blob/f5ad1de8/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-site.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-site.xml b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-site.xml
index 68b53f2..2f2e114 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-site.xml
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-site.xml
@@ -744,4 +744,16 @@
</description>
<on-ambari-upgrade add="true"/>
</property>
+ <property>
+ <name>timeline.metrics.cluster.aggregation.sql.filters</name>
+ <value>sdisk\_%,boottime</value>
+ <description>
+ Commas separated list of Metric names or Phoenix 'LIKE' class expressions that match metric names
+ which prevents certain metrics from being aggregated across hosts.
+ </description>
+ <on-ambari-upgrade add="true"/>
+ <value-attributes>
+ <empty-value-valid>true</empty-value-valid>
+ </value-attributes>
+ </property>
</configuration>
[15/27] ambari git commit: AMBARI-18402 - Alert definition should
include AGGREGATE source type
Posted by nc...@apache.org.
AMBARI-18402 - Alert definition should include AGGREGATE source type
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/513965f5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/513965f5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/513965f5
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 513965f5850e4d3d900eb63d6b429d841498d529
Parents: 3c06ca3
Author: Tim Thorpe <tt...@apache.org>
Authored: Thu Sep 15 09:19:40 2016 -0700
Committer: Tim Thorpe <tt...@apache.org>
Committed: Thu Sep 15 09:19:40 2016 -0700
----------------------------------------------------------------------
ambari-server/docs/api/v1/alert-definitions.md | 25 ++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/513965f5/ambari-server/docs/api/v1/alert-definitions.md
----------------------------------------------------------------------
diff --git a/ambari-server/docs/api/v1/alert-definitions.md b/ambari-server/docs/api/v1/alert-definitions.md
index fae356a..9785379 100644
--- a/ambari-server/docs/api/v1/alert-definitions.md
+++ b/ambari-server/docs/api/v1/alert-definitions.md
@@ -136,6 +136,29 @@ PORT definitions are used to check TCP connectivity to a remote endpoint.
}
}
+###### AGGREGATE
+AGGREGATE definitions are used to combine the results of another alert definition from different nodes. The `source/alert_name` field must match the `name` field of another alert definition.
+
+ "source": {
+ "type": "AGGREGATE",
+ "alert_name": "datanode_process",
+ "reporting": {
+ "ok": {
+ "text": "affected: [{1}], total: [{0}]"
+ },
+ "warning": {
+ "text": "affected: [{1}], total: [{0}]",
+ "value": 10
+ },
+ "critical": {
+ "text": "affected: [{1}], total: [{0}]",
+ "value": 30
+ },
+ "units" : "%",
+ "type": "PERCENT"
+ }
+ }
+
#### Structures & Concepts
- `uri` Definition types that contain a URI can depend on any number of valid subproperties. In some cases, the URI may be very simple and only include a single port. In other scenarios, the URI may be more complex and include properties for plaintext, SSL, and secure endpoints protected by Kerberos.
@@ -309,4 +332,4 @@ Using the `run_now` directive, a definition can be scheduled to run immediately
PUT http://<server>/api/v1/clusters/<cluster>/alert_definitions/<definition-id>?run_now=true
###### Response
- HTTP 200 OK
\ No newline at end of file
+ HTTP 200 OK
[26/27] ambari git commit: AMBARI-18226. Remove Redundant Embedded
Postgres SQL (aonishuk)
Posted by nc...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/9dbcac6d/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
index 8f03989..9943cae 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
@@ -26,1707 +26,4 @@ GRANT ALL PRIVILEGES ON DATABASE :dbname TO :username;
CREATE SCHEMA ambari AUTHORIZATION :username;
ALTER SCHEMA ambari OWNER TO :username;
ALTER ROLE :username SET search_path TO 'ambari';
-
-------create tables and grant privileges to db user---------
-CREATE TABLE ambari.stack(
- stack_id BIGINT NOT NULL,
- stack_name VARCHAR(255) NOT NULL,
- stack_version VARCHAR(255) NOT NULL,
- CONSTRAINT PK_stack PRIMARY KEY (stack_id),
- CONSTRAINT UQ_stack UNIQUE (stack_name, stack_version)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.stack TO :username;
-
-CREATE TABLE ambari.extension(
- extension_id BIGINT NOT NULL,
- extension_name VARCHAR(255) NOT NULL,
- extension_version VARCHAR(255) NOT NULL,
- CONSTRAINT PK_extension PRIMARY KEY (extension_id),
- CONSTRAINT UQ_extension UNIQUE(extension_name, extension_version));
-GRANT ALL PRIVILEGES ON TABLE ambari.extension TO :username;
-
-CREATE TABLE ambari.extensionlink(
- link_id BIGINT NOT NULL,
- stack_id BIGINT NOT NULL,
- extension_id BIGINT NOT NULL,
- CONSTRAINT PK_extensionlink PRIMARY KEY (link_id),
- CONSTRAINT FK_extensionlink_stack_id FOREIGN KEY (stack_id) REFERENCES ambari.stack(stack_id),
- CONSTRAINT FK_extensionlink_extension_id FOREIGN KEY (extension_id) REFERENCES ambari.extension(extension_id),
- CONSTRAINT UQ_extension_link UNIQUE(stack_id, extension_id));
-GRANT ALL PRIVILEGES ON TABLE ambari.extensionlink TO :username;
-
-CREATE TABLE ambari.adminresourcetype (
- resource_type_id INTEGER NOT NULL,
- resource_type_name VARCHAR(255) NOT NULL,
- CONSTRAINT PK_adminresourcetype PRIMARY KEY (resource_type_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.adminresourcetype TO :username;
-
-CREATE TABLE ambari.adminresource (
- resource_id BIGINT NOT NULL,
- resource_type_id INTEGER NOT NULL,
- CONSTRAINT PK_adminresource PRIMARY KEY (resource_id),
- CONSTRAINT FK_resource_resource_type_id FOREIGN KEY (resource_type_id) REFERENCES ambari.adminresourcetype(resource_type_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.adminresource TO :username;
-
-CREATE TABLE ambari.clusters (
- cluster_id BIGINT NOT NULL,
- resource_id BIGINT NOT NULL,
- upgrade_id BIGINT,
- cluster_info VARCHAR(255) NOT NULL,
- cluster_name VARCHAR(100) NOT NULL UNIQUE,
- provisioning_state VARCHAR(255) NOT NULL DEFAULT 'INIT',
- security_type VARCHAR(32) NOT NULL DEFAULT 'NONE',
- desired_cluster_state VARCHAR(255) NOT NULL,
- desired_stack_id BIGINT NOT NULL,
- CONSTRAINT PK_clusters PRIMARY KEY (cluster_id),
- CONSTRAINT FK_clusters_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES ambari.stack(stack_id),
- CONSTRAINT FK_clusters_resource_id FOREIGN KEY (resource_id) REFERENCES ambari.adminresource(resource_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.clusters TO :username;
-
-CREATE TABLE ambari.clusterconfig (
- config_id BIGINT NOT NULL,
- version_tag VARCHAR(255) NOT NULL,
- version BIGINT NOT NULL,
- type_name VARCHAR(255) NOT NULL,
- cluster_id BIGINT NOT NULL,
- stack_id BIGINT NOT NULL,
- config_data TEXT NOT NULL,
- config_attributes TEXT,
- create_timestamp BIGINT NOT NULL,
- CONSTRAINT PK_clusterconfig PRIMARY KEY (config_id),
- CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id),
- CONSTRAINT FK_clusterconfig_stack_id FOREIGN KEY (stack_id) REFERENCES ambari.stack(stack_id),
- CONSTRAINT UQ_config_type_tag UNIQUE (cluster_id, type_name, version_tag),
- CONSTRAINT UQ_config_type_version UNIQUE (cluster_id, type_name, version)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.clusterconfig TO :username;
-
-CREATE TABLE ambari.clusterconfigmapping (
- cluster_id BIGINT NOT NULL,
- type_name VARCHAR(255) NOT NULL,
- version_tag VARCHAR(255) NOT NULL,
- create_timestamp BIGINT NOT NULL,
- selected INTEGER NOT NULL DEFAULT 0,
- user_name VARCHAR(255) NOT NULL DEFAULT '_db',
- CONSTRAINT PK_clusterconfigmapping PRIMARY KEY (cluster_id, type_name, create_timestamp),
- CONSTRAINT clusterconfigmappingcluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.clusterconfigmapping TO :username;
-
-CREATE TABLE ambari.serviceconfig (
- service_config_id BIGINT NOT NULL,
- cluster_id BIGINT NOT NULL,
- service_name VARCHAR(255) NOT NULL,
- version BIGINT NOT NULL,
- create_timestamp BIGINT NOT NULL,
- stack_id BIGINT NOT NULL,
- user_name VARCHAR(255) NOT NULL DEFAULT '_db',
- group_id BIGINT,
- note TEXT,
- CONSTRAINT PK_serviceconfig PRIMARY KEY (service_config_id),
- CONSTRAINT FK_serviceconfig_stack_id FOREIGN KEY (stack_id) REFERENCES ambari.stack(stack_id),
- CONSTRAINT UQ_scv_service_version UNIQUE (cluster_id, service_name, version)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.serviceconfig TO :username;
-
-CREATE TABLE ambari.hosts (
- host_id BIGINT NOT NULL,
- host_name VARCHAR(255) NOT NULL,
- cpu_count INTEGER NOT NULL,
- ph_cpu_count INTEGER,
- cpu_info VARCHAR(255) NOT NULL,
- discovery_status VARCHAR(2000) NOT NULL,
- host_attributes VARCHAR(20000) NOT NULL,
- ipv4 VARCHAR(255),
- ipv6 VARCHAR(255),
- public_host_name VARCHAR(255),
- last_registration_time BIGINT NOT NULL,
- os_arch VARCHAR(255) NOT NULL,
- os_info VARCHAR(1000) NOT NULL,
- os_type VARCHAR(255) NOT NULL,
- rack_info VARCHAR(255) NOT NULL,
- total_mem BIGINT NOT NULL,
- CONSTRAINT PK_hosts PRIMARY KEY (host_id),
- CONSTRAINT UQ_hosts_host_name UNIQUE (host_name)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.hosts TO :username;
-
-CREATE TABLE ambari.serviceconfighosts (
- service_config_id BIGINT NOT NULL,
- host_id BIGINT NOT NULL,
- CONSTRAINT PK_serviceconfighosts PRIMARY KEY (service_config_id, host_id),
- CONSTRAINT FK_scvhosts_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts(host_id),
- CONSTRAINT FK_scvhosts_scv FOREIGN KEY (service_config_id) REFERENCES ambari.serviceconfig(service_config_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.serviceconfighosts TO :username;
-
-CREATE TABLE ambari.serviceconfigmapping (
- service_config_id BIGINT NOT NULL,
- config_id BIGINT NOT NULL,
- CONSTRAINT PK_serviceconfigmapping PRIMARY KEY (service_config_id, config_id),
- CONSTRAINT FK_scvm_config FOREIGN KEY (config_id) REFERENCES ambari.clusterconfig(config_id),
- CONSTRAINT FK_scvm_scv FOREIGN KEY (service_config_id) REFERENCES ambari.serviceconfig(service_config_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.serviceconfigmapping TO :username;
-
-CREATE TABLE ambari.clusterservices (
- service_name VARCHAR(255) NOT NULL,
- cluster_id BIGINT NOT NULL,
- service_enabled INTEGER NOT NULL,
- CONSTRAINT PK_clusterservices PRIMARY KEY (service_name, cluster_id),
- CONSTRAINT FK_clusterservices_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.clusterservices TO :username;
-
-CREATE TABLE ambari.clusterstate (
- cluster_id BIGINT NOT NULL,
- current_cluster_state VARCHAR(255) NOT NULL,
- current_stack_id BIGINT NOT NULL,
- CONSTRAINT PK_clusterstate PRIMARY KEY (cluster_id),
- CONSTRAINT FK_clusterstate_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id),
- CONSTRAINT FK_cs_current_stack_id FOREIGN KEY (current_stack_id) REFERENCES ambari.stack(stack_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.clusterstate TO :username;
-
-CREATE TABLE ambari.repo_version (
- repo_version_id BIGINT NOT NULL,
- stack_id BIGINT NOT NULL,
- version VARCHAR(255) NOT NULL,
- display_name VARCHAR(128) NOT NULL,
- repositories TEXT NOT NULL,
- repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
- version_url VARCHAR(1024),
- version_xml TEXT,
- version_xsd VARCHAR(512),
- parent_id BIGINT,
- CONSTRAINT PK_repo_version PRIMARY KEY (repo_version_id),
- CONSTRAINT FK_repoversion_stack_id FOREIGN KEY (stack_id) REFERENCES ambari.stack(stack_id),
- CONSTRAINT UQ_repo_version_display_name UNIQUE (display_name),
- CONSTRAINT UQ_repo_version_stack_id UNIQUE (stack_id, version)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.repo_version TO :username;
-
-CREATE TABLE ambari.cluster_version (
- id BIGINT NOT NULL,
- repo_version_id BIGINT NOT NULL,
- cluster_id BIGINT NOT NULL,
- state VARCHAR(32) NOT NULL,
- start_time BIGINT NOT NULL,
- end_time BIGINT,
- user_name VARCHAR(32),
- CONSTRAINT PK_cluster_version PRIMARY KEY (id),
- CONSTRAINT FK_cluster_version_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id),
- CONSTRAINT FK_cluster_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES ambari.repo_version (repo_version_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.cluster_version TO :username;
-
-CREATE TABLE ambari.servicecomponentdesiredstate (
- id BIGINT NOT NULL,
- component_name VARCHAR(255) NOT NULL,
- cluster_id BIGINT NOT NULL,
- desired_stack_id BIGINT NOT NULL,
- desired_version VARCHAR(255) NOT NULL DEFAULT 'UNKNOWN',
- desired_state VARCHAR(255) NOT NULL,
- service_name VARCHAR(255) NOT NULL,
- recovery_enabled SMALLINT NOT NULL DEFAULT 0,
- CONSTRAINT pk_sc_desiredstate PRIMARY KEY (id),
- CONSTRAINT UQ_scdesiredstate_name UNIQUE(component_name, service_name, cluster_id),
- CONSTRAINT FK_scds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES ambari.stack(stack_id),
- CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES ambari.clusterservices (service_name, cluster_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.servicecomponentdesiredstate TO :username;
-
-CREATE TABLE ambari.hostcomponentdesiredstate (
- cluster_id BIGINT NOT NULL,
- component_name VARCHAR(255) NOT NULL,
- desired_stack_id BIGINT NOT NULL,
- desired_state VARCHAR(255) NOT NULL,
- host_id BIGINT NOT NULL,
- service_name VARCHAR(255) NOT NULL,
- admin_state VARCHAR(32),
- maintenance_state VARCHAR(32) NOT NULL,
- security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED',
- restart_required SMALLINT NOT NULL DEFAULT 0,
- CONSTRAINT PK_hostcomponentdesiredstate PRIMARY KEY (cluster_id, component_name, host_id, service_name),
- CONSTRAINT FK_hcdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id),
- CONSTRAINT FK_hcds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES ambari.stack(stack_id),
- CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES ambari.servicecomponentdesiredstate (component_name, service_name, cluster_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentdesiredstate TO :username;
-
-CREATE TABLE ambari.hostcomponentstate (
- id BIGINT NOT NULL,
- cluster_id BIGINT NOT NULL,
- component_name VARCHAR(255) NOT NULL,
- version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN',
- current_stack_id BIGINT NOT NULL,
- current_state VARCHAR(255) NOT NULL,
- host_id BIGINT NOT NULL,
- service_name VARCHAR(255) NOT NULL,
- upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE',
- security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED',
- CONSTRAINT pk_hostcomponentstate PRIMARY KEY (id),
- CONSTRAINT FK_hcs_current_stack_id FOREIGN KEY (current_stack_id) REFERENCES ambari.stack(stack_id),
- CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id),
- CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, service_name, cluster_id) REFERENCES ambari.servicecomponentdesiredstate (component_name, service_name, cluster_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentstate TO :username;
-CREATE INDEX idx_host_component_state on ambari.hostcomponentstate(host_id, component_name, service_name, cluster_id);
-
-CREATE TABLE ambari.hoststate (
- agent_version VARCHAR(255) NOT NULL,
- available_mem BIGINT NOT NULL,
- current_state VARCHAR(255) NOT NULL,
- health_status VARCHAR(255),
- host_id BIGINT NOT NULL,
- time_in_state BIGINT NOT NULL,
- maintenance_state VARCHAR(512),
- CONSTRAINT PK_hoststate PRIMARY KEY (host_id),
- CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.hoststate TO :username;
-
-CREATE TABLE ambari.host_version (
- id BIGINT NOT NULL,
- repo_version_id BIGINT NOT NULL,
- host_id BIGINT NOT NULL,
- state VARCHAR(32) NOT NULL,
- CONSTRAINT PK_host_version PRIMARY KEY (id),
- CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id),
- CONSTRAINT FK_host_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES ambari.repo_version (repo_version_id),
- CONSTRAINT UQ_host_repo UNIQUE(repo_version_id, host_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.host_version TO :username;
-
-CREATE TABLE ambari.servicedesiredstate (
- cluster_id BIGINT NOT NULL,
- desired_host_role_mapping INTEGER NOT NULL,
- desired_stack_id BIGINT NOT NULL,
- desired_state VARCHAR(255) NOT NULL,
- service_name VARCHAR(255) NOT NULL,
- maintenance_state VARCHAR(32) NOT NULL,
- security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED',
- CONSTRAINT PK_servicedesiredstate PRIMARY KEY (cluster_id, service_name),
- CONSTRAINT FK_sds_desired_stack_id FOREIGN KEY (desired_stack_id) REFERENCES ambari.stack(stack_id),
- CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES ambari.clusterservices (service_name, cluster_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.servicedesiredstate TO :username;
-
-CREATE TABLE ambari.adminprincipaltype (
- principal_type_id INTEGER NOT NULL,
- principal_type_name VARCHAR(255) NOT NULL,
- CONSTRAINT PK_adminprincipaltype PRIMARY KEY (principal_type_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.adminprincipaltype TO :username;
-
-CREATE TABLE ambari.adminprincipal (
- principal_id BIGINT NOT NULL,
- principal_type_id INTEGER NOT NULL,
- CONSTRAINT PK_adminprincipal PRIMARY KEY (principal_id),
- CONSTRAINT FK_principal_principal_type_id FOREIGN KEY (principal_type_id) REFERENCES ambari.adminprincipaltype(principal_type_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.adminprincipal TO :username;
-
-CREATE TABLE ambari.users (
- user_id INTEGER,
- principal_id BIGINT NOT NULL,
- ldap_user INTEGER NOT NULL DEFAULT 0,
- user_name VARCHAR(255) NOT NULL,
- user_type VARCHAR(255) NOT NULL DEFAULT 'LOCAL',
- create_time TIMESTAMP DEFAULT NOW(),
- user_password VARCHAR(255),
- active INTEGER NOT NULL DEFAULT 1,
- active_widget_layouts VARCHAR(1024) DEFAULT NULL,
- CONSTRAINT PK_users PRIMARY KEY (user_id),
- CONSTRAINT FK_users_principal_id FOREIGN KEY (principal_id) REFERENCES ambari.adminprincipal(principal_id),
- CONSTRAINT UNQ_users_0 UNIQUE (user_name, user_type)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.users TO :username;
-
-CREATE TABLE ambari.groups (
- group_id INTEGER,
- principal_id BIGINT NOT NULL,
- group_name VARCHAR(255) NOT NULL,
- ldap_group INTEGER NOT NULL DEFAULT 0,
- CONSTRAINT PK_groups PRIMARY KEY (group_id),
- UNIQUE (ldap_group, group_name),
- CONSTRAINT FK_groups_principal_id FOREIGN KEY (principal_id) REFERENCES ambari.adminprincipal(principal_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.groups TO :username;
-
-CREATE TABLE ambari.members (
- member_id INTEGER,
- group_id INTEGER NOT NULL,
- user_id INTEGER NOT NULL,
- CONSTRAINT PK_members PRIMARY KEY (member_id),
- UNIQUE(group_id, user_id),
- CONSTRAINT FK_members_group_id FOREIGN KEY (group_id) REFERENCES ambari.groups (group_id),
- CONSTRAINT FK_members_user_id FOREIGN KEY (user_id) REFERENCES ambari.users (user_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.members TO :username;
-
-CREATE TABLE ambari.requestschedule (
- schedule_id bigint,
- cluster_id bigint NOT NULL,
- description varchar(255),
- status varchar(255),
- batch_separation_seconds smallint,
- batch_toleration_limit smallint,
- authenticated_user_id INTEGER,
- create_user varchar(255),
- create_timestamp bigint,
- update_user varchar(255),
- update_timestamp bigint,
- minutes varchar(10),
- hours varchar(10),
- days_of_month varchar(10),
- month varchar(10),
- day_of_week varchar(10),
- yearToSchedule varchar(10),
- startTime varchar(50),
- endTime varchar(50),
- last_execution_status varchar(255),
- CONSTRAINT PK_requestschedule PRIMARY KEY (schedule_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.requestschedule TO :username;
-
-CREATE TABLE ambari.request (
- request_id BIGINT NOT NULL,
- cluster_id BIGINT,
- command_name VARCHAR(255),
- create_time BIGINT NOT NULL,
- end_time BIGINT NOT NULL,
- exclusive_execution SMALLINT NOT NULL DEFAULT 0,
- inputs BYTEA,
- request_context VARCHAR(255),
- request_type VARCHAR(255),
- request_schedule_id BIGINT,
- start_time BIGINT NOT NULL,
- status VARCHAR(255),
- CONSTRAINT PK_request PRIMARY KEY (request_id),
- CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES ambari.requestschedule (schedule_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.request TO :username;
-
-CREATE TABLE ambari.stage (
- stage_id BIGINT NOT NULL,
- request_id BIGINT NOT NULL,
- cluster_id BIGINT NOT NULL,
- skippable SMALLINT DEFAULT 0 NOT NULL,
- supports_auto_skip_failure SMALLINT DEFAULT 0 NOT NULL,
- log_info VARCHAR(255) NOT NULL,
- request_context VARCHAR(255),
- cluster_host_info BYTEA NOT NULL,
- command_params BYTEA,
- host_params BYTEA,
- CONSTRAINT PK_stage PRIMARY KEY (stage_id, request_id),
- CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES ambari.request (request_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.stage TO :username;
-
-CREATE TABLE ambari.host_role_command (
- task_id BIGINT NOT NULL,
- attempt_count SMALLINT NOT NULL,
- retry_allowed SMALLINT DEFAULT 0 NOT NULL,
- event VARCHAR(32000) NOT NULL,
- exitcode INTEGER NOT NULL,
- host_id BIGINT,
- last_attempt_time BIGINT NOT NULL,
- request_id BIGINT NOT NULL,
- role VARCHAR(255),
- stage_id BIGINT NOT NULL,
- start_time BIGINT NOT NULL,
- original_start_time BIGINT NOT NULL,
- end_time BIGINT,
- status VARCHAR(255),
- auto_skip_on_failure SMALLINT DEFAULT 0 NOT NULL,
- std_error BYTEA,
- std_out BYTEA,
- output_log VARCHAR(255) NULL,
- error_log VARCHAR(255) NULL,
- structured_out BYTEA,
- role_command VARCHAR(255),
- command_detail VARCHAR(255),
- custom_command_name VARCHAR(255),
- CONSTRAINT PK_host_role_command PRIMARY KEY (task_id),
- CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id),
- CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES ambari.stage (stage_id, request_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.host_role_command TO :username;
-
-CREATE TABLE ambari.execution_command (
- command BYTEA,
- task_id BIGINT NOT NULL,
- CONSTRAINT PK_execution_command PRIMARY KEY (task_id),
- CONSTRAINT FK_execution_command_task_id FOREIGN KEY (task_id) REFERENCES ambari.host_role_command (task_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.execution_command TO :username;
-
-CREATE TABLE ambari.role_success_criteria (
- role VARCHAR(255) NOT NULL,
- request_id BIGINT NOT NULL,
- stage_id BIGINT NOT NULL,
- success_factor FLOAT NOT NULL,
- CONSTRAINT PK_role_success_criteria PRIMARY KEY (role, request_id, stage_id),
- CONSTRAINT role_success_criteria_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES ambari.stage (stage_id, request_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.role_success_criteria TO :username;
-
-CREATE TABLE ambari.requestresourcefilter (
- filter_id BIGINT NOT NULL,
- request_id BIGINT NOT NULL,
- service_name VARCHAR(255),
- component_name VARCHAR(255),
- hosts BYTEA,
- CONSTRAINT PK_requestresourcefilter PRIMARY KEY (filter_id),
- CONSTRAINT FK_reqresfilter_req_id FOREIGN KEY (request_id) REFERENCES ambari.request (request_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.requestresourcefilter TO :username;
-
-CREATE TABLE ambari.requestoperationlevel (
- operation_level_id BIGINT NOT NULL,
- request_id BIGINT NOT NULL,
- level_name VARCHAR(255),
- cluster_name VARCHAR(255),
- service_name VARCHAR(255),
- host_component_name VARCHAR(255),
- host_id BIGINT NULL, -- unlike most host_id columns, this one allows NULLs because the request can be at the service level
- CONSTRAINT PK_requestoperationlevel PRIMARY KEY (operation_level_id),
- CONSTRAINT FK_req_op_level_req_id FOREIGN KEY (request_id) REFERENCES ambari.request (request_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.requestoperationlevel TO :username;
-
-CREATE TABLE ambari.ClusterHostMapping (
- cluster_id BIGINT NOT NULL,
- host_id BIGINT NOT NULL,
- CONSTRAINT PK_ClusterHostMapping PRIMARY KEY (cluster_id, host_id),
- CONSTRAINT FK_clhostmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id),
- CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.ClusterHostMapping TO :username;
-
-CREATE TABLE ambari.key_value_store (
- "key" VARCHAR(255),
- "value" VARCHAR,
- CONSTRAINT PK_key_value_store PRIMARY KEY ("key")
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.key_value_store TO :username;
-
-CREATE TABLE ambari.hostconfigmapping (
- cluster_id BIGINT NOT NULL,
- host_id BIGINT NOT NULL,
- type_name VARCHAR(255) NOT NULL,
- version_tag VARCHAR(255) NOT NULL,
- service_name VARCHAR(255),
- create_timestamp BIGINT NOT NULL,
- selected INTEGER NOT NULL DEFAULT 0,
- user_name VARCHAR(255) NOT NULL DEFAULT '_db',
- CONSTRAINT PK_hostconfigmapping PRIMARY KEY (cluster_id, host_id, type_name, create_timestamp),
- CONSTRAINT FK_hostconfmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id),
- CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.hostconfigmapping TO :username;
-
-CREATE TABLE ambari.metainfo (
- "metainfo_key" VARCHAR(255),
- "metainfo_value" VARCHAR,
- CONSTRAINT PK_metainfo PRIMARY KEY ("metainfo_key")
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.metainfo TO :username;
-
-CREATE TABLE ambari.ambari_sequences (
- sequence_name VARCHAR(255),
- sequence_value BIGINT NOT NULL,
- CONSTRAINT pk_ambari_sequences PRIMARY KEY (sequence_name)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.ambari_sequences TO :username;
-
-CREATE TABLE ambari.configgroup (
- group_id BIGINT,
- cluster_id BIGINT NOT NULL,
- group_name VARCHAR(255) NOT NULL,
- tag VARCHAR(1024) NOT NULL,
- description VARCHAR(1024),
- create_timestamp BIGINT NOT NULL,
- service_name VARCHAR(255),
- CONSTRAINT PK_configgroup PRIMARY KEY (group_id),
- CONSTRAINT FK_configgroup_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.configgroup TO :username;
-
-CREATE TABLE ambari.confgroupclusterconfigmapping (
- config_group_id BIGINT NOT NULL,
- cluster_id BIGINT NOT NULL,
- config_type VARCHAR(255) NOT NULL,
- version_tag VARCHAR(255) NOT NULL,
- user_name VARCHAR(255) DEFAULT '_db',
- create_timestamp BIGINT NOT NULL,
- CONSTRAINT PK_confgroupclustercfgmapping PRIMARY KEY (config_group_id, cluster_id, config_type),
- CONSTRAINT FK_cgccm_gid FOREIGN KEY (config_group_id) REFERENCES ambari.configgroup (group_id),
- CONSTRAINT FK_confg FOREIGN KEY (version_tag, config_type, cluster_id) REFERENCES ambari.clusterconfig (version_tag, type_name, cluster_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.confgroupclusterconfigmapping TO :username;
-
-CREATE TABLE ambari.configgrouphostmapping (
- config_group_id BIGINT NOT NULL,
- host_id BIGINT NOT NULL,
- CONSTRAINT PK_configgrouphostmapping PRIMARY KEY (config_group_id, host_id),
- CONSTRAINT FK_cghm_cgid FOREIGN KEY (config_group_id) REFERENCES ambari.configgroup (group_id),
- CONSTRAINT FK_cghm_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.configgrouphostmapping TO :username;
-
-CREATE TABLE ambari.requestschedulebatchrequest (
- schedule_id bigint,
- batch_id bigint,
- request_id bigint,
- request_type varchar(255),
- request_uri varchar(1024),
- request_body BYTEA,
- request_status varchar(255),
- return_code smallint,
- return_message varchar(20000),
- CONSTRAINT PK_requestschedulebatchrequest PRIMARY KEY (schedule_id, batch_id),
- CONSTRAINT FK_rsbatchrequest_schedule_id FOREIGN KEY (schedule_id) REFERENCES ambari.requestschedule (schedule_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.requestschedulebatchrequest TO :username;
-
-CREATE TABLE ambari.blueprint (
- blueprint_name VARCHAR(255) NOT NULL,
- stack_id BIGINT NOT NULL,
- security_type VARCHAR(32) NOT NULL DEFAULT 'NONE',
- security_descriptor_reference VARCHAR(255),
- CONSTRAINT PK_blueprint PRIMARY KEY (blueprint_name),
- CONSTRAINT FK_blueprint_stack_id FOREIGN KEY (stack_id) REFERENCES ambari.stack(stack_id));
-
-CREATE TABLE ambari.hostgroup (
- blueprint_name VARCHAR(255) NOT NULL,
- name VARCHAR(255) NOT NULL,
- cardinality VARCHAR(255) NOT NULL,
- CONSTRAINT PK_hostgroup PRIMARY KEY (blueprint_name, name),
- CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES ambari.blueprint(blueprint_name));
-
-CREATE TABLE ambari.hostgroup_component (
- blueprint_name VARCHAR(255) NOT NULL,
- hostgroup_name VARCHAR(255) NOT NULL,
- name VARCHAR(255) NOT NULL,
- provision_action VARCHAR(255),
- CONSTRAINT PK_hostgroup_component PRIMARY KEY (blueprint_name, hostgroup_name, name),
- CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES ambari.hostgroup (blueprint_name, name));
-
-CREATE TABLE ambari.blueprint_configuration (
- blueprint_name varchar(255) NOT NULL,
- type_name varchar(255) NOT NULL,
- config_data TEXT NOT NULL,
- config_attributes TEXT,
- CONSTRAINT PK_blueprint_configuration PRIMARY KEY (blueprint_name, type_name),
- CONSTRAINT FK_cfg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES ambari.blueprint(blueprint_name));
-
-CREATE TABLE ambari.blueprint_setting (
- id BIGINT NOT NULL,
- blueprint_name varchar(255) NOT NULL,
- setting_name varchar(255) NOT NULL,
- setting_data TEXT NOT NULL,
- CONSTRAINT PK_blueprint_setting PRIMARY KEY (id),
- CONSTRAINT UQ_blueprint_setting_name UNIQUE(blueprint_name,setting_name),
- CONSTRAINT FK_blueprint_setting_name FOREIGN KEY (blueprint_name) REFERENCES ambari.blueprint(blueprint_name));
-
-CREATE TABLE ambari.hostgroup_configuration (
- blueprint_name VARCHAR(255) NOT NULL,
- hostgroup_name VARCHAR(255) NOT NULL,
- type_name VARCHAR(255) NOT NULL,
- config_data TEXT NOT NULL,
- config_attributes TEXT,
- CONSTRAINT PK_hostgroup_configuration PRIMARY KEY (blueprint_name, hostgroup_name, type_name),
- CONSTRAINT FK_hg_cfg_bp_hg_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES ambari.hostgroup (blueprint_name, name)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.blueprint TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.hostgroup TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.hostgroup_component TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.blueprint_configuration TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.blueprint_setting TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.hostgroup_configuration TO :username;
-
-CREATE TABLE ambari.viewmain (
- view_name VARCHAR(255) NOT NULL,
- label VARCHAR(255),
- description VARCHAR(2048),
- version VARCHAR(255),
- build VARCHAR(128),
- resource_type_id INTEGER NOT NULL,
- icon VARCHAR(255),
- icon64 VARCHAR(255),
- archive VARCHAR(255),
- mask VARCHAR(255),
- system_view SMALLINT NOT NULL DEFAULT 0,
- CONSTRAINT PK_viewmain PRIMARY KEY (view_name),
- CONSTRAINT FK_view_resource_type_id FOREIGN KEY (resource_type_id) REFERENCES ambari.adminresourcetype(resource_type_id));
-
-
-
-CREATE table ambari.viewurl(
- url_id BIGINT ,
- url_name VARCHAR(255) NOT NULL ,
- url_suffix VARCHAR(255) NOT NULL,
- PRIMARY KEY(url_id)
-);
-
-
-CREATE TABLE ambari.viewinstance (
- view_instance_id BIGINT,
- resource_id BIGINT NOT NULL,
- view_name VARCHAR(255) NOT NULL,
- name VARCHAR(255) NOT NULL,
- label VARCHAR(255),
- description VARCHAR(2048),
- visible CHAR(1),
- icon VARCHAR(255),
- icon64 VARCHAR(255),
- xml_driven CHAR(1),
- alter_names SMALLINT NOT NULL DEFAULT 1,
- cluster_handle BIGINT,
- cluster_type VARCHAR(100) NOT NULL DEFAULT 'LOCAL_AMBARI',
- short_url BIGINT,
- CONSTRAINT PK_viewinstance PRIMARY KEY (view_instance_id),
- CONSTRAINT FK_instance_url_id FOREIGN KEY (short_url) REFERENCES ambari.viewurl(url_id),
- CONSTRAINT FK_viewinst_view_name FOREIGN KEY (view_name) REFERENCES ambari.viewmain(view_name),
- CONSTRAINT FK_viewinstance_resource_id FOREIGN KEY (resource_id) REFERENCES ambari.adminresource(resource_id),
- CONSTRAINT UQ_viewinstance_name UNIQUE (view_name, name),
- CONSTRAINT UQ_viewinstance_name_id UNIQUE (view_instance_id, view_name, name));
-
-CREATE TABLE ambari.viewinstancedata (
- view_instance_id BIGINT,
- view_name VARCHAR(255) NOT NULL,
- view_instance_name VARCHAR(255) NOT NULL,
- name VARCHAR(255) NOT NULL,
- user_name VARCHAR(255) NOT NULL,
- value VARCHAR(2000),
- CONSTRAINT PK_viewinstancedata PRIMARY KEY (view_instance_id, name, user_name),
- CONSTRAINT FK_viewinstdata_view_name FOREIGN KEY (view_instance_id, view_name, view_instance_name) REFERENCES ambari.viewinstance(view_instance_id, view_name, name));
-
-CREATE TABLE ambari.viewinstanceproperty (
- view_name VARCHAR(255) NOT NULL,
- view_instance_name VARCHAR(255) NOT NULL,
- name VARCHAR(255) NOT NULL,
- value VARCHAR(2000),
- CONSTRAINT PK_viewinstanceproperty PRIMARY KEY (view_name, view_instance_name, name),
- CONSTRAINT FK_viewinstprop_view_name FOREIGN KEY (view_name, view_instance_name) REFERENCES ambari.viewinstance(view_name, name));
-
-CREATE TABLE ambari.viewparameter (
- view_name VARCHAR(255) NOT NULL,
- name VARCHAR(255) NOT NULL,
- description VARCHAR(2048),
- label VARCHAR(255),
- placeholder VARCHAR(255),
- default_value VARCHAR(2000),
- cluster_config VARCHAR(255),
- required CHAR(1),
- masked CHAR(1),
- CONSTRAINT PK_viewparameter PRIMARY KEY (view_name, name),
- CONSTRAINT FK_viewparam_view_name FOREIGN KEY (view_name) REFERENCES ambari.viewmain(view_name));
-
-CREATE TABLE ambari.viewresource (
- view_name VARCHAR(255) NOT NULL,
- name VARCHAR(255) NOT NULL,
- plural_name VARCHAR(255),
- id_property VARCHAR(255),
- subResource_names VARCHAR(255),
- provider VARCHAR(255),
- service VARCHAR(255),
- resource VARCHAR(255),
- CONSTRAINT PK_viewresource PRIMARY KEY (view_name, name),
- CONSTRAINT FK_viewres_view_name FOREIGN KEY (view_name) REFERENCES ambari.viewmain(view_name));
-
-CREATE TABLE ambari.viewentity (
- id BIGINT NOT NULL,
- view_name VARCHAR(255) NOT NULL,
- view_instance_name VARCHAR(255) NOT NULL,
- class_name VARCHAR(255) NOT NULL,
- id_property VARCHAR(255),
- CONSTRAINT PK_viewentity PRIMARY KEY (id),
- CONSTRAINT FK_viewentity_view_name FOREIGN KEY (view_name, view_instance_name) REFERENCES ambari.viewinstance(view_name, name)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.viewmain TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.viewinstancedata TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.viewurl TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.viewinstance TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.viewinstanceproperty TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.viewparameter TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.viewresource TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.viewentity TO :username;
-
-CREATE TABLE ambari.adminpermission (
- permission_id BIGINT NOT NULL,
- permission_name VARCHAR(255) NOT NULL,
- resource_type_id INTEGER NOT NULL,
- permission_label VARCHAR(255),
- principal_id BIGINT NOT NULL,
- sort_order SMALLINT NOT NULL DEFAULT 1,
- CONSTRAINT PK_adminpermission PRIMARY KEY (permission_id),
- CONSTRAINT FK_permission_resource_type_id FOREIGN KEY (resource_type_id) REFERENCES ambari.adminresourcetype(resource_type_id),
- CONSTRAINT FK_permission_principal_id FOREIGN KEY (principal_id) REFERENCES ambari.adminprincipal(principal_id),
- CONSTRAINT UQ_perm_name_resource_type_id UNIQUE (permission_name, resource_type_id));
-
-CREATE TABLE ambari.roleauthorization (
- authorization_id VARCHAR(100) NOT NULL,
- authorization_name VARCHAR(255) NOT NULL,
- CONSTRAINT PK_roleauthorization PRIMARY KEY (authorization_id));
-
-CREATE TABLE ambari.permission_roleauthorization (
- permission_id BIGINT NOT NULL,
- authorization_id VARCHAR(100) NOT NULL,
- CONSTRAINT PK_permsn_roleauthorization PRIMARY KEY (permission_id, authorization_id),
- CONSTRAINT FK_permission_roleauth_aid FOREIGN KEY (authorization_id) REFERENCES ambari.roleauthorization(authorization_id),
- CONSTRAINT FK_permission_roleauth_pid FOREIGN KEY (permission_id) REFERENCES ambari.adminpermission(permission_id));
-
-CREATE TABLE ambari.adminprivilege (
- privilege_id BIGINT,
- permission_id BIGINT NOT NULL,
- resource_id BIGINT NOT NULL,
- principal_id BIGINT NOT NULL,
- CONSTRAINT PK_adminprivilege PRIMARY KEY (privilege_id),
- CONSTRAINT FK_privilege_permission_id FOREIGN KEY (permission_id) REFERENCES ambari.adminpermission(permission_id),
- CONSTRAINT FK_privilege_principal_id FOREIGN KEY (principal_id) REFERENCES ambari.adminprincipal(principal_id),
- CONSTRAINT FK_privilege_resource_id FOREIGN KEY (resource_id) REFERENCES ambari.adminresource(resource_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.adminpermission TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.roleauthorization TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.permission_roleauthorization TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.adminprivilege TO :username;
-
-CREATE TABLE ambari.artifact (
- artifact_name VARCHAR(255) NOT NULL,
- artifact_data TEXT NOT NULL,
- foreign_keys VARCHAR(255) NOT NULL,
- CONSTRAINT PK_artifact PRIMARY KEY (artifact_name, foreign_keys)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.artifact TO :username;
-
-CREATE TABLE ambari.widget (
- id BIGINT NOT NULL,
- widget_name VARCHAR(255) NOT NULL,
- widget_type VARCHAR(255) NOT NULL,
- metrics TEXT,
- time_created BIGINT NOT NULL,
- author VARCHAR(255),
- description VARCHAR(2048),
- default_section_name VARCHAR(255),
- scope VARCHAR(255),
- widget_values TEXT,
- properties TEXT,
- cluster_id BIGINT NOT NULL,
- CONSTRAINT PK_widget PRIMARY KEY (id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.widget TO :username;
-
-CREATE TABLE ambari.widget_layout (
- id BIGINT NOT NULL,
- layout_name VARCHAR(255) NOT NULL,
- section_name VARCHAR(255) NOT NULL,
- scope VARCHAR(255) NOT NULL,
- user_name VARCHAR(255) NOT NULL,
- display_name VARCHAR(255),
- cluster_id BIGINT NOT NULL,
- CONSTRAINT PK_widget_layout PRIMARY KEY (id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.widget_layout TO :username;
-
-CREATE TABLE ambari.widget_layout_user_widget (
- widget_layout_id BIGINT NOT NULL,
- widget_id BIGINT NOT NULL,
- widget_order smallint,
- CONSTRAINT PK_widget_layout_user_widget PRIMARY KEY (widget_layout_id, widget_id),
- CONSTRAINT FK_widget_id FOREIGN KEY (widget_id) REFERENCES ambari.widget(id),
- CONSTRAINT FK_widget_layout_id FOREIGN KEY (widget_layout_id) REFERENCES ambari.widget_layout(id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.widget_layout_user_widget TO :username;
-
-CREATE TABLE ambari.topology_request (
- id BIGINT NOT NULL,
- action VARCHAR(255) NOT NULL,
- cluster_id BIGINT NOT NULL,
- bp_name VARCHAR(100) NOT NULL,
- cluster_properties TEXT,
- cluster_attributes TEXT,
- description VARCHAR(1024),
- provision_action VARCHAR(255),
- CONSTRAINT PK_topology_request PRIMARY KEY (id),
- CONSTRAINT FK_topology_request_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters(cluster_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.topology_request TO :username;
-
-CREATE TABLE ambari.topology_hostgroup (
- id BIGINT NOT NULL,
- name VARCHAR(255) NOT NULL,
- group_properties TEXT,
- group_attributes TEXT,
- request_id BIGINT NOT NULL,
- CONSTRAINT PK_topology_hostgroup PRIMARY KEY (id),
- CONSTRAINT FK_hostgroup_req_id FOREIGN KEY (request_id) REFERENCES ambari.topology_request(id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.topology_hostgroup TO :username;
-
-CREATE TABLE ambari.topology_host_info (
- id BIGINT NOT NULL,
- group_id BIGINT NOT NULL,
- fqdn VARCHAR(255),
- host_id BIGINT,
- host_count INTEGER,
- predicate VARCHAR(2048),
- rack_info VARCHAR(255),
- CONSTRAINT PK_topology_host_info PRIMARY KEY (id),
- CONSTRAINT FK_hostinfo_group_id FOREIGN KEY (group_id) REFERENCES ambari.topology_hostgroup(id),
- CONSTRAINT FK_hostinfo_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts(host_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.topology_host_info TO :username;
-
-CREATE TABLE ambari.topology_logical_request (
- id BIGINT NOT NULL,
- request_id BIGINT NOT NULL,
- description VARCHAR(1024),
- CONSTRAINT PK_topology_logical_request PRIMARY KEY (id),
- CONSTRAINT FK_logicalreq_req_id FOREIGN KEY (request_id) REFERENCES ambari.topology_request(id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.topology_logical_request TO :username;
-
-CREATE TABLE ambari.topology_host_request (
- id BIGINT NOT NULL,
- logical_request_id BIGINT NOT NULL,
- group_id BIGINT NOT NULL,
- stage_id BIGINT NOT NULL,
- host_name VARCHAR(255),
- CONSTRAINT PK_topology_host_request PRIMARY KEY (id),
- CONSTRAINT FK_hostreq_group_id FOREIGN KEY (group_id) REFERENCES ambari.topology_hostgroup(id),
- CONSTRAINT FK_hostreq_logicalreq_id FOREIGN KEY (logical_request_id) REFERENCES ambari.topology_logical_request(id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.topology_host_request TO :username;
-
-CREATE TABLE ambari.topology_host_task (
- id BIGINT NOT NULL,
- host_request_id BIGINT NOT NULL,
- type VARCHAR(255) NOT NULL,
- CONSTRAINT PK_topology_host_task PRIMARY KEY (id),
- CONSTRAINT FK_hosttask_req_id FOREIGN KEY (host_request_id) REFERENCES ambari.topology_host_request (id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.topology_host_task TO :username;
-
-CREATE TABLE ambari.topology_logical_task (
- id BIGINT NOT NULL,
- host_task_id BIGINT NOT NULL,
- physical_task_id BIGINT,
- component VARCHAR(255) NOT NULL,
- CONSTRAINT PK_topology_logical_task PRIMARY KEY (id),
- CONSTRAINT FK_ltask_hosttask_id FOREIGN KEY (host_task_id) REFERENCES ambari.topology_host_task (id),
- CONSTRAINT FK_ltask_hrc_id FOREIGN KEY (physical_task_id) REFERENCES ambari.host_role_command (task_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.topology_logical_task TO :username;
-
-CREATE TABLE ambari.setting (
- id BIGINT NOT NULL,
- name VARCHAR(255) NOT NULL UNIQUE,
- setting_type VARCHAR(255) NOT NULL,
- content TEXT NOT NULL,
- updated_by VARCHAR(255) NOT NULL DEFAULT '_db',
- update_timestamp BIGINT NOT NULL,
- CONSTRAINT PK_setting PRIMARY KEY (id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.setting TO :username;
-
--- Remote Cluster table
-
-CREATE TABLE ambari.remoteambaricluster(
- cluster_id BIGINT NOT NULL,
- name VARCHAR(255) NOT NULL,
- username VARCHAR(255) NOT NULL,
- url VARCHAR(255) NOT NULL,
- password VARCHAR(255) NOT NULL,
- CONSTRAINT PK_remote_ambari_cluster PRIMARY KEY (cluster_id),
- CONSTRAINT UQ_remote_ambari_cluster UNIQUE (name)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.remoteambaricluster TO :username;
-
-CREATE TABLE ambari.remoteambariclusterservice(
- id BIGINT NOT NULL,
- cluster_id BIGINT NOT NULL,
- service_name VARCHAR(255) NOT NULL,
- CONSTRAINT PK_remote_ambari_service PRIMARY KEY (id),
- CONSTRAINT FK_remote_ambari_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.remoteambaricluster(cluster_id)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.remoteambariclusterservice TO :username;
-
--- Remote Cluster table ends
-
--- upgrade tables
-CREATE TABLE ambari.upgrade (
- upgrade_id BIGINT NOT NULL,
- cluster_id BIGINT NOT NULL,
- request_id BIGINT NOT NULL,
- from_version VARCHAR(255) DEFAULT '' NOT NULL,
- to_version VARCHAR(255) DEFAULT '' NOT NULL,
- direction VARCHAR(255) DEFAULT 'UPGRADE' NOT NULL,
- upgrade_package VARCHAR(255) NOT NULL,
- upgrade_type VARCHAR(32) NOT NULL,
- skip_failures SMALLINT DEFAULT 0 NOT NULL,
- skip_sc_failures SMALLINT DEFAULT 0 NOT NULL,
- downgrade_allowed SMALLINT DEFAULT 1 NOT NULL,
- suspended SMALLINT DEFAULT 0 NOT NULL,
- CONSTRAINT PK_upgrade PRIMARY KEY (upgrade_id),
- FOREIGN KEY (cluster_id) REFERENCES ambari.clusters(cluster_id),
- FOREIGN KEY (request_id) REFERENCES ambari.request(request_id)
-);
-
-CREATE TABLE ambari.upgrade_group (
- upgrade_group_id BIGINT NOT NULL,
- upgrade_id BIGINT NOT NULL,
- group_name VARCHAR(255) DEFAULT '' NOT NULL,
- group_title VARCHAR(1024) DEFAULT '' NOT NULL,
- CONSTRAINT PK_upgrade_group PRIMARY KEY (upgrade_group_id),
- FOREIGN KEY (upgrade_id) REFERENCES ambari.upgrade(upgrade_id)
-);
-
-CREATE TABLE ambari.upgrade_item (
- upgrade_item_id BIGINT NOT NULL,
- upgrade_group_id BIGINT NOT NULL,
- stage_id BIGINT NOT NULL,
- state VARCHAR(255) DEFAULT 'NONE' NOT NULL,
- hosts TEXT,
- tasks TEXT,
- item_text VARCHAR(1024),
- CONSTRAINT PK_upgrade_item PRIMARY KEY (upgrade_item_id),
- FOREIGN KEY (upgrade_group_id) REFERENCES ambari.upgrade_group(upgrade_group_id)
-);
-
-CREATE TABLE ambari.servicecomponent_history(
- id BIGINT NOT NULL,
- component_id BIGINT NOT NULL,
- upgrade_id BIGINT NOT NULL,
- from_stack_id BIGINT NOT NULL,
- to_stack_id BIGINT NOT NULL,
- CONSTRAINT PK_sc_history PRIMARY KEY (id),
- CONSTRAINT FK_sc_history_component_id FOREIGN KEY (component_id) REFERENCES ambari.servicecomponentdesiredstate (id),
- CONSTRAINT FK_sc_history_upgrade_id FOREIGN KEY (upgrade_id) REFERENCES ambari.upgrade (upgrade_id),
- CONSTRAINT FK_sc_history_from_stack_id FOREIGN KEY (from_stack_id) REFERENCES ambari.stack (stack_id),
- CONSTRAINT FK_sc_history_to_stack_id FOREIGN KEY (to_stack_id) REFERENCES ambari.stack (stack_id)
-);
-
-CREATE TABLE ambari.ambari_operation_history(
- id BIGINT NOT NULL,
- from_version VARCHAR(255) NOT NULL,
- to_version VARCHAR(255) NOT NULL,
- start_time BIGINT NOT NULL,
- end_time BIGINT,
- operation_type VARCHAR(255) NOT NULL,
- comments TEXT,
- CONSTRAINT PK_ambari_operation_history PRIMARY KEY (id)
-);
-
-GRANT ALL PRIVILEGES ON TABLE ambari.upgrade TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.upgrade_group TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.upgrade_item TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.servicecomponent_history TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.ambari_operation_history TO :username;
-
--- tasks indices --
-CREATE INDEX idx_stage_request_id ON ambari.stage (request_id);
-CREATE INDEX idx_hrc_request_id ON ambari.host_role_command (request_id);
-CREATE INDEX idx_hrc_status_role ON ambari.host_role_command (status, role);
-CREATE INDEX idx_rsc_request_id ON ambari.role_success_criteria (request_id);
-
--------- altering tables by creating foreign keys ----------
--- #1: This should always be an exceptional case. FK constraints should be inlined in table definitions when possible
--- (reorder table definitions if necessary).
--- #2: Oracle has a limitation of 30 chars in the constraint names name, and we should use the same constraint names in all DB types.
-ALTER TABLE ambari.clusters ADD CONSTRAINT FK_clusters_upgrade_id FOREIGN KEY (upgrade_id) REFERENCES ambari.upgrade (upgrade_id);
-
--- Kerberos
-CREATE TABLE ambari.kerberos_principal (
- principal_name VARCHAR(255) NOT NULL,
- is_service SMALLINT NOT NULL DEFAULT 1,
- cached_keytab_path VARCHAR(255),
- CONSTRAINT PK_kerberos_principal PRIMARY KEY (principal_name)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.kerberos_principal TO :username;
-
-CREATE TABLE ambari.kerberos_principal_host (
- principal_name VARCHAR(255) NOT NULL,
- host_id BIGINT NOT NULL,
- CONSTRAINT PK_kerberos_principal_host PRIMARY KEY (principal_name, host_id),
- CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id),
- CONSTRAINT FK_krb_pr_host_principalname FOREIGN KEY (principal_name) REFERENCES ambari.kerberos_principal (principal_name)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.kerberos_principal_host TO :username;
-
-CREATE TABLE ambari.kerberos_descriptor
-(
- kerberos_descriptor_name VARCHAR(255) NOT NULL,
- kerberos_descriptor TEXT NOT NULL,
- CONSTRAINT PK_kerberos_descriptor PRIMARY KEY (kerberos_descriptor_name)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.kerberos_descriptor TO :username;
-
--- Kerberos (end)
-
--- Alerting Framework
-CREATE TABLE ambari.alert_definition (
- definition_id BIGINT NOT NULL,
- cluster_id BIGINT NOT NULL,
- definition_name VARCHAR(255) NOT NULL,
- service_name VARCHAR(255) NOT NULL,
- component_name VARCHAR(255),
- scope VARCHAR(255) DEFAULT 'ANY' NOT NULL,
- label VARCHAR(255),
- help_url VARCHAR(512),
- description TEXT,
- enabled SMALLINT DEFAULT 1 NOT NULL,
- schedule_interval INTEGER NOT NULL,
- source_type VARCHAR(255) NOT NULL,
- alert_source TEXT NOT NULL,
- hash VARCHAR(64) NOT NULL,
- ignore_host SMALLINT DEFAULT 0 NOT NULL,
- repeat_tolerance INTEGER DEFAULT 1 NOT NULL,
- repeat_tolerance_enabled SMALLINT DEFAULT 0 NOT NULL,
- CONSTRAINT PK_alert_definition PRIMARY KEY (definition_id),
- FOREIGN KEY (cluster_id) REFERENCES ambari.clusters(cluster_id),
- CONSTRAINT uni_alert_def_name UNIQUE(cluster_id,definition_name)
-);
-
-CREATE TABLE ambari.alert_history (
- alert_id BIGINT NOT NULL,
- cluster_id BIGINT NOT NULL,
- alert_definition_id BIGINT NOT NULL,
- service_name VARCHAR(255) NOT NULL,
- component_name VARCHAR(255),
- host_name VARCHAR(255),
- alert_instance VARCHAR(255),
- alert_timestamp BIGINT NOT NULL,
- alert_label VARCHAR(1024),
- alert_state VARCHAR(255) NOT NULL,
- alert_text TEXT,
- CONSTRAINT PK_alert_history PRIMARY KEY (alert_id),
- FOREIGN KEY (alert_definition_id) REFERENCES ambari.alert_definition(definition_id),
- FOREIGN KEY (cluster_id) REFERENCES ambari.clusters(cluster_id)
-);
-
-CREATE TABLE ambari.alert_current (
- alert_id BIGINT NOT NULL,
- definition_id BIGINT NOT NULL,
- history_id BIGINT NOT NULL UNIQUE,
- maintenance_state VARCHAR(255) NOT NULL,
- original_timestamp BIGINT NOT NULL,
- latest_timestamp BIGINT NOT NULL,
- latest_text TEXT,
- occurrences BIGINT NOT NULL DEFAULT 1,
- firmness VARCHAR(255) NOT NULL DEFAULT 'HARD',
- CONSTRAINT PK_alert_current PRIMARY KEY (alert_id),
- FOREIGN KEY (definition_id) REFERENCES ambari.alert_definition(definition_id),
- FOREIGN KEY (history_id) REFERENCES ambari.alert_history(alert_id)
-);
-
-CREATE TABLE ambari.alert_group (
- group_id BIGINT NOT NULL,
- cluster_id BIGINT NOT NULL,
- group_name VARCHAR(255) NOT NULL,
- is_default SMALLINT NOT NULL DEFAULT 0,
- service_name VARCHAR(255),
- CONSTRAINT PK_alert_group PRIMARY KEY (group_id),
- CONSTRAINT uni_alert_group_name UNIQUE(cluster_id,group_name)
-);
-
-CREATE TABLE ambari.alert_target (
- target_id BIGINT NOT NULL,
- target_name VARCHAR(255) NOT NULL UNIQUE,
- notification_type VARCHAR(64) NOT NULL,
- properties TEXT,
- description VARCHAR(1024),
- is_global SMALLINT NOT NULL DEFAULT 0,
- is_enabled SMALLINT NOT NULL DEFAULT 1,
- CONSTRAINT PK_alert_target PRIMARY KEY (target_id)
-);
-
-CREATE TABLE ambari.alert_target_states (
- target_id BIGINT NOT NULL,
- alert_state VARCHAR(255) NOT NULL,
- FOREIGN KEY (target_id) REFERENCES ambari.alert_target(target_id)
-);
-
-CREATE TABLE ambari.alert_group_target (
- group_id BIGINT NOT NULL,
- target_id BIGINT NOT NULL,
- CONSTRAINT PK_alert_group_target PRIMARY KEY (group_id, target_id),
- FOREIGN KEY (group_id) REFERENCES ambari.alert_group(group_id),
- FOREIGN KEY (target_id) REFERENCES ambari.alert_target(target_id)
-);
-
-CREATE TABLE ambari.alert_grouping (
- definition_id BIGINT NOT NULL,
- group_id BIGINT NOT NULL,
- CONSTRAINT PK_alert_grouping PRIMARY KEY (group_id, definition_id),
- FOREIGN KEY (definition_id) REFERENCES ambari.alert_definition(definition_id),
- FOREIGN KEY (group_id) REFERENCES ambari.alert_group(group_id)
-);
-
-CREATE TABLE ambari.alert_notice (
- notification_id BIGINT NOT NULL,
- target_id BIGINT NOT NULL,
- history_id BIGINT NOT NULL,
- notify_state VARCHAR(255) NOT NULL,
- uuid VARCHAR(64) NOT NULL UNIQUE,
- CONSTRAINT PK_alert_notice PRIMARY KEY (notification_id),
- FOREIGN KEY (target_id) REFERENCES ambari.alert_target(target_id),
- FOREIGN KEY (history_id) REFERENCES ambari.alert_history(alert_id)
-);
-
-GRANT ALL PRIVILEGES ON TABLE ambari.alert_definition TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.alert_history TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.alert_current TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.alert_group TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.alert_target TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.alert_target_states TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.alert_group_target TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.alert_grouping TO :username;
-GRANT ALL PRIVILEGES ON TABLE ambari.alert_notice TO :username;
-
-CREATE INDEX idx_alert_history_def_id on ambari.alert_history(alert_definition_id);
-CREATE INDEX idx_alert_history_service on ambari.alert_history(service_name);
-CREATE INDEX idx_alert_history_host on ambari.alert_history(host_name);
-CREATE INDEX idx_alert_history_time on ambari.alert_history(alert_timestamp);
-CREATE INDEX idx_alert_history_state on ambari.alert_history(alert_state);
-CREATE INDEX idx_alert_group_name on ambari.alert_group(group_name);
-CREATE INDEX idx_alert_notice_state on ambari.alert_notice(notify_state);
-
----------inserting some data-----------
--- In order for the first ID to be 1, must initialize the ambari_sequences table with a sequence_value of 0.
-BEGIN;
-INSERT INTO ambari.ambari_sequences (sequence_name, sequence_value) VALUES
- ('cluster_id_seq', 1),
- ('host_id_seq', 0),
- ('user_id_seq', 2),
- ('group_id_seq', 1),
- ('member_id_seq', 1),
- ('host_role_command_id_seq', 1),
- ('configgroup_id_seq', 1),
- ('requestschedule_id_seq', 1),
- ('resourcefilter_id_seq', 1),
- ('viewentity_id_seq', 0),
- ('operation_level_id_seq', 1),
- ('view_instance_id_seq', 1),
- ('resource_type_id_seq', 4),
- ('resource_id_seq', 2),
- ('principal_type_id_seq', 8),
- ('principal_id_seq', 13),
- ('permission_id_seq', 7),
- ('privilege_id_seq', 1),
- ('alert_definition_id_seq', 0),
- ('alert_group_id_seq', 0),
- ('alert_target_id_seq', 0),
- ('alert_history_id_seq', 0),
- ('alert_notice_id_seq', 0),
- ('alert_current_id_seq', 0),
- ('config_id_seq', 1),
- ('repo_version_id_seq', 0),
- ('cluster_version_id_seq', 0),
- ('host_version_id_seq', 0),
- ('service_config_id_seq', 1),
- ('upgrade_id_seq', 0),
- ('upgrade_group_id_seq', 0),
- ('widget_id_seq', 0),
- ('widget_layout_id_seq', 0),
- ('upgrade_item_id_seq', 0),
- ('stack_id_seq', 0),
- ('extension_id_seq', 0),
- ('link_id_seq', 0),
- ('topology_host_info_id_seq', 0),
- ('topology_host_request_id_seq', 0),
- ('topology_host_task_id_seq', 0),
- ('topology_logical_request_id_seq', 0),
- ('topology_logical_task_id_seq', 0),
- ('topology_request_id_seq', 0),
- ('topology_host_group_id_seq', 0),
- ('setting_id_seq', 0),
- ('hostcomponentstate_id_seq', 0),
- ('servicecomponentdesiredstate_id_seq', 0),
- ('servicecomponent_history_id_seq', 0),
- ('blueprint_setting_id_seq', 0),
- ('ambari_operation_history_id_seq', 0),
- ('remote_cluster_id_seq', 0),
- ('remote_cluster_service_id_seq', 0);
-
-INSERT INTO ambari.adminresourcetype (resource_type_id, resource_type_name) VALUES
- (1, 'AMBARI'),
- (2, 'CLUSTER'),
- (3, 'VIEW');
-
-INSERT INTO ambari.adminresource (resource_id, resource_type_id) VALUES
- (1, 1);
-
-INSERT INTO ambari.adminprincipaltype (principal_type_id, principal_type_name) VALUES
- (1, 'USER'),
- (2, 'GROUP'),
- (3, 'ALL.CLUSTER.ADMINISTRATOR'),
- (4, 'ALL.CLUSTER.OPERATOR'),
- (5, 'ALL.CLUSTER.USER'),
- (6, 'ALL.SERVICE.ADMINISTRATOR'),
- (7, 'ALL.SERVICE.OPERATOR'),
- (8, 'ROLE');
-
-INSERT INTO ambari.adminprincipal (principal_id, principal_type_id) VALUES
- (1, 1),
- (2, 3),
- (3, 4),
- (4, 5),
- (5, 6),
- (6, 7),
- (7, 8),
- (8, 8),
- (9, 8),
- (10, 8),
- (11, 8),
- (12, 8),
- (13, 8);
-
-INSERT INTO ambari.Users (user_id, principal_id, user_name, user_password)
- SELECT 1, 1, 'admin', '538916f8943ec225d97a9a86a2c6ec0818c1cd400e09e03b660fdaaec4af29ddbb6f2b1033b81b00';
-
-INSERT INTO ambari.adminpermission(permission_id, permission_name, resource_type_id, permission_label, principal_id, sort_order)
- SELECT 1, 'AMBARI.ADMINISTRATOR', 1, 'Ambari Administrator', 7, 1 UNION ALL
- SELECT 2, 'CLUSTER.USER', 2, 'Cluster User', 8, 6 UNION ALL
- SELECT 3, 'CLUSTER.ADMINISTRATOR', 2, 'Cluster Administrator', 9, 2 UNION ALL
- SELECT 4, 'VIEW.USER', 3, 'View User', 10, 7 UNION ALL
- SELECT 5, 'CLUSTER.OPERATOR', 2, 'Cluster Operator', 11, 3 UNION ALL
- SELECT 6, 'SERVICE.ADMINISTRATOR', 2, 'Service Administrator', 12, 4 UNION ALL
- SELECT 7, 'SERVICE.OPERATOR', 2, 'Service Operator', 13, 5;
-
-INSERT INTO ambari.roleauthorization(authorization_id, authorization_name)
- SELECT 'VIEW.USE', 'Use View' UNION ALL
- SELECT 'SERVICE.VIEW_METRICS', 'View metrics' UNION ALL
- SELECT 'SERVICE.VIEW_STATUS_INFO', 'View status information' UNION ALL
- SELECT 'SERVICE.VIEW_CONFIGS', 'View configurations' UNION ALL
- SELECT 'SERVICE.COMPARE_CONFIGS', 'Compare configurations' UNION ALL
- SELECT 'SERVICE.VIEW_ALERTS', 'View service-level alerts' UNION ALL
- SELECT 'SERVICE.START_STOP', 'Start/Stop/Restart Service' UNION ALL
- SELECT 'SERVICE.DECOMMISSION_RECOMMISSION', 'Decommission/recommission' UNION ALL
- SELECT 'SERVICE.RUN_SERVICE_CHECK', 'Run service checks' UNION ALL
- SELECT 'SERVICE.TOGGLE_MAINTENANCE', 'Turn on/off maintenance mode' UNION ALL
- SELECT 'SERVICE.RUN_CUSTOM_COMMAND', 'Perform service-specific tasks' UNION ALL
- SELECT 'SERVICE.MODIFY_CONFIGS', 'Modify configurations' UNION ALL
- SELECT 'SERVICE.MANAGE_CONFIG_GROUPS', 'Manage configuration groups' UNION ALL
- SELECT 'SERVICE.MANAGE_ALERTS', 'Manage service-level alerts' UNION ALL
- SELECT 'SERVICE.MOVE', 'Move to another host' UNION ALL
- SELECT 'SERVICE.ENABLE_HA', 'Enable HA' UNION ALL
- SELECT 'SERVICE.TOGGLE_ALERTS', 'Enable/disable service-level alerts' UNION ALL
- SELECT 'SERVICE.ADD_DELETE_SERVICES', 'Add/delete services' UNION ALL
- SELECT 'SERVICE.VIEW_OPERATIONAL_LOGS', 'View service operational logs' UNION ALL
- SELECT 'SERVICE.SET_SERVICE_USERS_GROUPS', 'Set service users and groups' UNION ALL
- SELECT 'HOST.VIEW_METRICS', 'View metrics' UNION ALL
- SELECT 'HOST.VIEW_STATUS_INFO', 'View status information' UNION ALL
- SELECT 'HOST.VIEW_CONFIGS', 'View configuration' UNION ALL
- SELECT 'HOST.TOGGLE_MAINTENANCE', 'Turn on/off maintenance mode' UNION ALL
- SELECT 'HOST.ADD_DELETE_COMPONENTS', 'Install components' UNION ALL
- SELECT 'HOST.ADD_DELETE_HOSTS', 'Add/Delete hosts' UNION ALL
- SELECT 'CLUSTER.VIEW_METRICS', 'View metrics' UNION ALL
- SELECT 'CLUSTER.VIEW_STATUS_INFO', 'View status information' UNION ALL
- SELECT 'CLUSTER.VIEW_CONFIGS', 'View configuration' UNION ALL
- SELECT 'CLUSTER.VIEW_STACK_DETAILS', 'View stack version details' UNION ALL
- SELECT 'CLUSTER.VIEW_ALERTS', 'View cluster-level alerts' UNION ALL
- SELECT 'CLUSTER.MANAGE_CREDENTIALS', 'Manage external credentials' UNION ALL
- SELECT 'CLUSTER.MODIFY_CONFIGS', 'Modify cluster configurations' UNION ALL
- SELECT 'CLUSTER.MANAGE_ALERTS', 'Manage cluster-level alerts' UNION ALL
- SELECT 'CLUSTER.MANAGE_USER_PERSISTED_DATA', 'Manage cluster-level user persisted data' UNION ALL
- SELECT 'CLUSTER.TOGGLE_ALERTS', 'Enable/disable cluster-level alerts' UNION ALL
- SELECT 'CLUSTER.MANAGE_CONFIG_GROUPS', 'Manage cluster config groups' UNION ALL
- SELECT 'CLUSTER.TOGGLE_KERBEROS', 'Enable/disable Kerberos' UNION ALL
- SELECT 'CLUSTER.UPGRADE_DOWNGRADE_STACK', 'Upgrade/downgrade stack' UNION ALL
- SELECT 'AMBARI.ADD_DELETE_CLUSTERS', 'Create new clusters' UNION ALL
- SELECT 'AMBARI.RENAME_CLUSTER', 'Rename clusters' UNION ALL
- SELECT 'AMBARI.MANAGE_SETTINGS', 'Manage settings' UNION ALL
- SELECT 'AMBARI.MANAGE_USERS', 'Manage users' UNION ALL
- SELECT 'AMBARI.MANAGE_GROUPS', 'Manage groups' UNION ALL
- SELECT 'AMBARI.MANAGE_VIEWS', 'Manage Ambari Views' UNION ALL
- SELECT 'AMBARI.ASSIGN_ROLES', 'Assign roles' UNION ALL
- SELECT 'AMBARI.MANAGE_STACK_VERSIONS', 'Manage stack versions' UNION ALL
- SELECT 'AMBARI.EDIT_STACK_REPOS', 'Edit stack repository URLs';
-
--- Set authorizations for View User role
-INSERT INTO ambari.permission_roleauthorization(permission_id, authorization_id)
- SELECT permission_id, 'VIEW.USE' FROM ambari.adminpermission WHERE permission_name='VIEW.USER';
-
--- Set authorizations for Cluster User role
-INSERT INTO ambari.permission_roleauthorization(permission_id, authorization_id)
- SELECT permission_id, 'SERVICE.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'SERVICE.COMPARE_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'HOST.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'HOST.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'HOST.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STACK_DETAILS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_USER_PERSISTED_DATA' FROM ambari.adminpermission WHERE permission_name='CLUSTER.USER';
-
--- Set authorizations for Service Operator role
-INSERT INTO ambari.permission_roleauthorization(permission_id, authorization_id)
- SELECT permission_id, 'SERVICE.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.COMPARE_CONFIGS' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.START_STOP' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.DECOMMISSION_RECOMMISSION' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.RUN_SERVICE_CHECK' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.TOGGLE_MAINTENANCE' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.RUN_CUSTOM_COMMAND' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STACK_DETAILS' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_USER_PERSISTED_DATA' FROM ambari.adminpermission WHERE permission_name='SERVICE.OPERATOR';
-
--- Set authorizations for Service Administrator role
-INSERT INTO ambari.permission_roleauthorization(permission_id, authorization_id)
- SELECT permission_id, 'SERVICE.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.COMPARE_CONFIGS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.START_STOP' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.DECOMMISSION_RECOMMISSION' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.RUN_SERVICE_CHECK' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.TOGGLE_MAINTENANCE' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.RUN_CUSTOM_COMMAND' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MODIFY_CONFIGS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MANAGE_CONFIG_GROUPS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_OPERATIONAL_LOGS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STACK_DETAILS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_CONFIG_GROUPS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_USER_PERSISTED_DATA' FROM ambari.adminpermission WHERE permission_name='SERVICE.ADMINISTRATOR';
-
--- Set authorizations for Cluster Operator role
-INSERT INTO ambari.permission_roleauthorization(permission_id, authorization_id)
- SELECT permission_id, 'SERVICE.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.COMPARE_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.START_STOP' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.DECOMMISSION_RECOMMISSION' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.RUN_SERVICE_CHECK' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.TOGGLE_MAINTENANCE' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.RUN_CUSTOM_COMMAND' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MODIFY_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MANAGE_CONFIG_GROUPS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MOVE' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.ENABLE_HA' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_OPERATIONAL_LOGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'HOST.TOGGLE_MAINTENANCE' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'HOST.ADD_DELETE_COMPONENTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'HOST.ADD_DELETE_HOSTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STACK_DETAILS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_CONFIG_GROUPS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_CREDENTIALS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_USER_PERSISTED_DATA' FROM ambari.adminpermission WHERE permission_name='CLUSTER.OPERATOR';
-
--- Set authorizations for Cluster Administrator role
-INSERT INTO ambari.permission_roleauthorization(permission_id, authorization_id)
- SELECT permission_id, 'SERVICE.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.COMPARE_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.START_STOP' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.DECOMMISSION_RECOMMISSION' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.RUN_SERVICE_CHECK' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.TOGGLE_MAINTENANCE' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.RUN_CUSTOM_COMMAND' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MODIFY_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MANAGE_CONFIG_GROUPS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MANAGE_ALERTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MOVE' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.ENABLE_HA' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.TOGGLE_ALERTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.ADD_DELETE_SERVICES' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_OPERATIONAL_LOGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.SET_SERVICE_USERS_GROUPS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.TOGGLE_MAINTENANCE' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.ADD_DELETE_COMPONENTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.ADD_DELETE_HOSTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STACK_DETAILS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_CREDENTIALS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MODIFY_CONFIGS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_CONFIG_GROUPS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_ALERTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.TOGGLE_ALERTS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.TOGGLE_KERBEROS' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.UPGRADE_DOWNGRADE_STACK' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_USER_PERSISTED_DATA' FROM ambari.adminpermission WHERE permission_name='CLUSTER.ADMINISTRATOR';
-
--- Set authorizations for Administrator role
-INSERT INTO ambari.permission_roleauthorization(permission_id, authorization_id)
- SELECT permission_id, 'VIEW.USE' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.COMPARE_CONFIGS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.START_STOP' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.DECOMMISSION_RECOMMISSION' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.RUN_SERVICE_CHECK' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.TOGGLE_MAINTENANCE' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.RUN_CUSTOM_COMMAND' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MODIFY_CONFIGS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MANAGE_CONFIG_GROUPS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MANAGE_ALERTS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.MOVE' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.ENABLE_HA' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.TOGGLE_ALERTS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.ADD_DELETE_SERVICES' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.VIEW_OPERATIONAL_LOGS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'SERVICE.SET_SERVICE_USERS_GROUPS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.TOGGLE_MAINTENANCE' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.ADD_DELETE_COMPONENTS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'HOST.ADD_DELETE_HOSTS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_METRICS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STATUS_INFO' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_CONFIGS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_STACK_DETAILS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.VIEW_ALERTS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_CREDENTIALS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MODIFY_CONFIGS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_ALERTS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_CONFIG_GROUPS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.TOGGLE_ALERTS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.TOGGLE_KERBEROS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.UPGRADE_DOWNGRADE_STACK' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'CLUSTER.MANAGE_USER_PERSISTED_DATA' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.ADD_DELETE_CLUSTERS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.RENAME_CLUSTER' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_SETTINGS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_USERS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_GROUPS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_VIEWS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.ASSIGN_ROLES' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.MANAGE_STACK_VERSIONS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR' UNION ALL
- SELECT permission_id, 'AMBARI.EDIT_STACK_REPOS' FROM ambari.adminpermission WHERE permission_name='AMBARI.ADMINISTRATOR';
-
-
-INSERT INTO ambari.adminprivilege (privilege_id, permission_id, resource_id, principal_id) VALUES
- (1, 1, 1, 1);
-
-INSERT INTO ambari.metainfo (metainfo_key, metainfo_value) VALUES
- ('version', '${ambariSchemaVersion}');
-COMMIT;
-
--- Quartz tables
-
-CREATE TABLE ambari.qrtz_job_details
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- JOB_NAME VARCHAR(200) NOT NULL,
- JOB_GROUP VARCHAR(200) NOT NULL,
- DESCRIPTION VARCHAR(250) NULL,
- JOB_CLASS_NAME VARCHAR(250) NOT NULL,
- IS_DURABLE BOOL NOT NULL,
- IS_NONCONCURRENT BOOL NOT NULL,
- IS_UPDATE_DATA BOOL NOT NULL,
- REQUESTS_RECOVERY BOOL NOT NULL,
- JOB_DATA BYTEA NULL,
- PRIMARY KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_job_details TO :username;
-
-CREATE TABLE ambari.qrtz_triggers
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- TRIGGER_NAME VARCHAR(200) NOT NULL,
- TRIGGER_GROUP VARCHAR(200) NOT NULL,
- JOB_NAME VARCHAR(200) NOT NULL,
- JOB_GROUP VARCHAR(200) NOT NULL,
- DESCRIPTION VARCHAR(250) NULL,
- NEXT_FIRE_TIME BIGINT NULL,
- PREV_FIRE_TIME BIGINT NULL,
- PRIORITY INTEGER NULL,
- TRIGGER_STATE VARCHAR(16) NOT NULL,
- TRIGGER_TYPE VARCHAR(8) NOT NULL,
- START_TIME BIGINT NOT NULL,
- END_TIME BIGINT NULL,
- CALENDAR_NAME VARCHAR(200) NULL,
- MISFIRE_INSTR SMALLINT NULL,
- JOB_DATA BYTEA NULL,
- PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
- FOREIGN KEY (SCHED_NAME,JOB_NAME,JOB_GROUP)
- REFERENCES ambari.QRTZ_JOB_DETAILS(SCHED_NAME,JOB_NAME,JOB_GROUP)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_triggers TO :username;
-
-CREATE TABLE ambari.qrtz_simple_triggers
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- TRIGGER_NAME VARCHAR(200) NOT NULL,
- TRIGGER_GROUP VARCHAR(200) NOT NULL,
- REPEAT_COUNT BIGINT NOT NULL,
- REPEAT_INTERVAL BIGINT NOT NULL,
- TIMES_TRIGGERED BIGINT NOT NULL,
- PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
- FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
- REFERENCES ambari.QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_simple_triggers TO :username;
-
-CREATE TABLE ambari.qrtz_cron_triggers
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- TRIGGER_NAME VARCHAR(200) NOT NULL,
- TRIGGER_GROUP VARCHAR(200) NOT NULL,
- CRON_EXPRESSION VARCHAR(120) NOT NULL,
- TIME_ZONE_ID VARCHAR(80),
- PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
- FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
- REFERENCES ambari.QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_cron_triggers TO :username;
-
-CREATE TABLE ambari.qrtz_simprop_triggers
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- TRIGGER_NAME VARCHAR(200) NOT NULL,
- TRIGGER_GROUP VARCHAR(200) NOT NULL,
- STR_PROP_1 VARCHAR(512) NULL,
- STR_PROP_2 VARCHAR(512) NULL,
- STR_PROP_3 VARCHAR(512) NULL,
- INT_PROP_1 INT NULL,
- INT_PROP_2 INT NULL,
- LONG_PROP_1 BIGINT NULL,
- LONG_PROP_2 BIGINT NULL,
- DEC_PROP_1 NUMERIC(13,4) NULL,
- DEC_PROP_2 NUMERIC(13,4) NULL,
- BOOL_PROP_1 BOOL NULL,
- BOOL_PROP_2 BOOL NULL,
- PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
- FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
- REFERENCES ambari.QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_simprop_triggers TO :username;
-
-CREATE TABLE ambari.qrtz_blob_triggers
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- TRIGGER_NAME VARCHAR(200) NOT NULL,
- TRIGGER_GROUP VARCHAR(200) NOT NULL,
- BLOB_DATA BYTEA NULL,
- PRIMARY KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP),
- FOREIGN KEY (SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
- REFERENCES ambari.QRTZ_TRIGGERS(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_blob_triggers TO :username;
-
-CREATE TABLE ambari.qrtz_calendars
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- CALENDAR_NAME VARCHAR(200) NOT NULL,
- CALENDAR BYTEA NOT NULL,
- PRIMARY KEY (SCHED_NAME,CALENDAR_NAME)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_calendars TO :username;
-
-
-CREATE TABLE ambari.qrtz_paused_trigger_grps
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- TRIGGER_GROUP VARCHAR(200) NOT NULL,
- PRIMARY KEY (SCHED_NAME,TRIGGER_GROUP)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_paused_trigger_grps TO :username;
-
-CREATE TABLE ambari.qrtz_fired_triggers
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- ENTRY_ID VARCHAR(95) NOT NULL,
- TRIGGER_NAME VARCHAR(200) NOT NULL,
- TRIGGER_GROUP VARCHAR(200) NOT NULL,
- INSTANCE_NAME VARCHAR(200) NOT NULL,
- FIRED_TIME BIGINT NOT NULL,
- SCHED_TIME BIGINT NOT NULL,
- PRIORITY INTEGER NOT NULL,
- STATE VARCHAR(16) NOT NULL,
- JOB_NAME VARCHAR(200) NULL,
- JOB_GROUP VARCHAR(200) NULL,
- IS_NONCONCURRENT BOOL NULL,
- REQUESTS_RECOVERY BOOL NULL,
- PRIMARY KEY (SCHED_NAME,ENTRY_ID)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_fired_triggers TO :username;
-
-CREATE TABLE ambari.qrtz_scheduler_state
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- INSTANCE_NAME VARCHAR(200) NOT NULL,
- LAST_CHECKIN_TIME BIGINT NOT NULL,
- CHECKIN_INTERVAL BIGINT NOT NULL,
- PRIMARY KEY (SCHED_NAME,INSTANCE_NAME)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_scheduler_state TO :username;
-
-CREATE TABLE ambari.qrtz_locks
-(
- SCHED_NAME VARCHAR(120) NOT NULL,
- LOCK_NAME VARCHAR(40) NOT NULL,
- PRIMARY KEY (SCHED_NAME,LOCK_NAME)
-);
-GRANT ALL PRIVILEGES ON TABLE ambari.qrtz_locks TO :username;
-
-create index idx_qrtz_j_req_recovery on ambari.qrtz_job_details(SCHED_NAME,REQUESTS_RECOVERY);
-create index idx_qrtz_j_grp on ambari.qrtz_job_details(SCHED_NAME,JOB_GROUP);
-
-create index idx_qrtz_t_j on ambari.qrtz_triggers(SCHED_NAME,JOB_NAME,JOB_GROUP);
-create index idx_qrtz_t_jg on ambari.qrtz_triggers(SCHED_NAME,JOB_GROUP);
-create index idx_qrtz_t_c on ambari.qrtz_triggers(SCHED_NAME,CALENDAR_NAME);
-create index idx_qrtz_t_g on ambari.qrtz_triggers(SCHED_NAME,TRIGGER_GROUP);
-create index idx_qrtz_t_state on ambari.qrtz_triggers(SCHED_NAME,TRIGGER_STATE);
-create index idx_qrtz_t_n_state on ambari.qrtz_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_STATE);
-create index idx_qrtz_t_n_g_state on ambari.qrtz_triggers(SCHED_NAME,TRIGGER_GROUP,TRIGGER_STATE);
-create index idx_qrtz_t_next_fire_time on ambari.qrtz_triggers(SCHED_NAME,NEXT_FIRE_TIME);
-create index idx_qrtz_t_nft_st on ambari.qrtz_triggers(SCHED_NAME,TRIGGER_STATE,NEXT_FIRE_TIME);
-create index idx_qrtz_t_nft_misfire on ambari.qrtz_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME);
-create index idx_qrtz_t_nft_st_misfire on ambari.qrtz_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_STATE);
-create index idx_qrtz_t_nft_st_misfire_grp on ambari.qrtz_triggers(SCHED_NAME,MISFIRE_INSTR,NEXT_FIRE_TIME,TRIGGER_GROUP,TRIGGER_STATE);
-
-create index idx_qrtz_ft_trig_inst_name on ambari.qrtz_fired_triggers(SCHED_NAME,INSTANCE_NAME);
-create index idx_qrtz_ft_inst_job_req_rcvry on ambari.qrtz_fired_triggers(SCHED_NAME,INSTANCE_NAME,REQUESTS_RECOVERY);
-create index idx_qrtz_ft_j_g on ambari.qrtz_fired_triggers(SCHED_NAME,JOB_NAME,JOB_GROUP);
-create index idx_qrtz_ft_jg on ambari.qrtz_fired_triggers(SCHED_NAME,JOB_GROUP);
-create index idx_qrtz_ft_t_g on ambari.qrtz_fired_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);
-create index idx_qrtz_ft_tg on ambari.qrtz_fired_triggers(SCHED_NAME,TRIGGER_GROUP);
+------all table creation located in Ambari-DLLPostgres-CREATE.sql---------
[27/27] ambari git commit: AMBARI-18226. Remove Redundant Embedded
Postgres SQL (aonishuk)
Posted by nc...@apache.org.
AMBARI-18226. Remove Redundant Embedded Postgres SQL (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9dbcac6d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9dbcac6d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9dbcac6d
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 9dbcac6d5c30cd30d90e5643d87c0010d91317be
Parents: 51cbf0d
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Fri Sep 16 13:54:08 2016 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Fri Sep 16 13:54:08 2016 +0300
----------------------------------------------------------------------
.../ambari_server/dbConfiguration_linux.py | 164 +-
.../python/ambari_server/serverConfiguration.py | 2 +
.../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql | 1705 +-----------------
.../src/main/resources/scripts/change_owner.sh | 66 -
.../src/test/python/TestAmbariServer.py | 118 +-
5 files changed, 192 insertions(+), 1863 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9dbcac6d/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
index 429a36e..797466d 100644
--- a/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
+++ b/ambari-server/src/main/python/ambari_server/dbConfiguration_linux.py
@@ -45,7 +45,7 @@ from ambari_server.serverConfiguration import encrypt_password, store_password_f
JDBC_RCA_DRIVER_PROPERTY, JDBC_RCA_URL_PROPERTY, \
PERSISTENCE_TYPE_PROPERTY, JDBC_CONNECTION_POOL_TYPE, JDBC_CONNECTION_POOL_ACQUISITION_SIZE, \
JDBC_CONNECTION_POOL_IDLE_TEST_INTERVAL, JDBC_CONNECTION_POOL_MAX_AGE, JDBC_CONNECTION_POOL_MAX_IDLE_TIME, \
- JDBC_CONNECTION_POOL_MAX_IDLE_TIME_EXCESS, JDBC_SQLA_SERVER_NAME
+ JDBC_CONNECTION_POOL_MAX_IDLE_TIME_EXCESS, JDBC_SQLA_SERVER_NAME, LOCAL_DATABASE_ADMIN_PROPERTY
from ambari_commons.constants import AMBARI_SUDO_BINARY
@@ -75,6 +75,8 @@ class LinuxDBMSConfig(DBMSConfig):
self.database_username = DBMSConfig._init_member_with_prop_default(options, "database_username",
properties, JDBC_USER_NAME_PROPERTY, DEFAULT_USERNAME)
+ self.local_admin_user = DBMSConfig._init_member_with_prop_default(options, "local_admin_user",
+ properties, LOCAL_DATABASE_ADMIN_PROPERTY, "postgres")
self.database_password = getattr(options, "database_password", "")
if not self.database_password:
self.database_password = DBMSConfig._read_password_from_properties(properties, options)
@@ -109,7 +111,14 @@ class LinuxDBMSConfig(DBMSConfig):
"Invalid port.",
False
)
-
+ if self.persistence_type == STORAGE_TYPE_LOCAL:
+ self.local_admin_user = get_validated_string_input(
+ "Database admin user ("+ self.local_admin_user + "): ",
+ self.local_admin_user,
+ ".+",
+ "Invalid username.",
+ False
+ )
if not self._configure_database_name():
return False
@@ -315,13 +324,13 @@ class LinuxDBMSConfig(DBMSConfig):
# PostgreSQL configuration and setup
class PGConfig(LinuxDBMSConfig):
# PostgreSQL settings
- SETUP_DB_CMD = [AMBARI_SUDO_BINARY, 'su', 'postgres', '-',
+ SETUP_DB_CMD = [AMBARI_SUDO_BINARY, 'su', 'postgres', '-',
'--command=psql -f {0} -v username=\'"{1}"\' -v password="\'{2}\'" -v dbname="{3}"']
- UPGRADE_STACK_CMD = [AMBARI_SUDO_BINARY, 'su', 'postgres',
- '--command=psql -f {0} -v stack_name="\'{1}\'" -v stack_version="\'{2}\'" -v dbname="{3}"']
- CHANGE_OWNER_COMMAND = [AMBARI_SUDO_BINARY, 'su', 'postgres', '-',
- '--command=' + AmbariPath.get("/var/lib/ambari-server/resources/scripts/change_owner.sh") + ' -d {0} -s {1} -o {2}']
+ EXECUTE_SCRIPT_AS_USER = [AMBARI_SUDO_BINARY, "bash", "-c", 'export PGPASSWORD={0} && psql -U {1} -f {2}']
+
+ EXECUTE_QUERY_AS_POSTGRES_FOR_DB_SILENT = [AMBARI_SUDO_BINARY, 'su', 'postgres', '-', '--command=psql -qAt -c "{0}" {1}']
+ EXECUTE_QUERY_AS_POSTGRES_FOR_DB = [AMBARI_SUDO_BINARY, 'su', 'postgres', '-', '--command=psql -c "{0}" {1}']
PG_ERROR_BLOCKED = "is being accessed by other users"
PG_STATUS_RUNNING = None
@@ -447,10 +456,6 @@ class PGConfig(LinuxDBMSConfig):
err = 'Unable to start PostgreSQL server. Exiting'
raise FatalException(retcode, err)
print 'Configuring local database...'
- retcode, out, err = self._setup_db()
- if not retcode == 0:
- err = 'Running database init script failed. Exiting.'
- raise FatalException(retcode, err)
if self._is_user_changed:
#remove backup for pg_hba in order to reconfigure postgres
remove_file(PGConfig.PG_HBA_CONF_FILE_BACKUP)
@@ -459,6 +464,10 @@ class PGConfig(LinuxDBMSConfig):
if not retcode == 0:
err = 'Unable to configure PostgreSQL server. Exiting'
raise FatalException(retcode, err)
+ retcode, out, err = self._setup_db()
+ if not retcode == 0:
+ err = 'Running database init script failed. Exiting.'
+ raise FatalException(retcode, err)
def _reset_local_database(self):
#force reset if silent option provided
@@ -480,6 +489,7 @@ class PGConfig(LinuxDBMSConfig):
username = self.database_username
password = self.database_password
command = PGConfig.SETUP_DB_CMD[:]
+ command[2] = self.local_admin_user
command[-1] = command[-1].format(filename, username, password, dbname)
drop_retcode, drop_outdata, drop_errdata = run_os_command(command)
if not drop_retcode == 0:
@@ -571,6 +581,8 @@ class PGConfig(LinuxDBMSConfig):
# connection pooling (internal JPA by default)
properties.process_pair(JDBC_CONNECTION_POOL_TYPE, "internal")
+ properties.process_pair(LOCAL_DATABASE_ADMIN_PROPERTY, self.local_admin_user)
+
self._store_password_property(properties, JDBC_PASSWORD_PROPERTY, options)
@@ -643,22 +655,39 @@ class PGConfig(LinuxDBMSConfig):
#setup DB
command = PGConfig.SETUP_DB_CMD[:]
+ command[2] = self.local_admin_user
command[-1] = command[-1].format(scriptFile, username, password, dbname)
+ retcode, outdata, errdata = self.run_with_retries(command, "Creating schema and user...")
+ if retcode == 0:
+ ddl_command = PGConfig.EXECUTE_SCRIPT_AS_USER[:]
+ ddl_command[-1] = ddl_command[-1].format(
+ password,
+ username,
+ PGConfig.POSTGRES_INIT_FILE
+ )
+ retcode, outdata, errdata = self.run_with_retries(ddl_command, "Creating tables...")
+ return retcode, outdata, errdata
+ @staticmethod
+ def run_with_retries(command, message):
+ """
+ Run given command SETUP_DB_CONNECT_ATTEMPTS times in case of failures
+ :param command: command to execute
+ :param message: message to be printed
+ :return: (code, out, err)
+ """
for i in range(SETUP_DB_CONNECT_ATTEMPTS):
- sys.stdout.write('Connecting to local database...')
+ print message
retcode, outdata, errdata = run_os_command(command)
if retcode == 0:
print 'done.'
return retcode, outdata, errdata
- timeOutMsg = 'connection timed out'
if (i+1) < SETUP_DB_CONNECT_ATTEMPTS:
- timeOutMsg += '...retrying (%d)' % (i+1)
- print timeOutMsg
+ print_error_msg("Failed to execute command:" + str(command))
+ print_error_msg("stderr:" + errdata)
+ print_error_msg("stdout:" + outdata)
+ print 'failed to execute queries ...retrying (%d)' % (i+1)
time.sleep(SETUP_DB_CONNECT_TIMEOUT)
-
- print 'unable to connect to database'
- print_error_msg(errdata)
return retcode, outdata, errdata
@staticmethod
@@ -739,27 +768,92 @@ class PGConfig(LinuxDBMSConfig):
properties.process_pair(JDBC_POSTGRES_SCHEMA_PROPERTY, self.postgres_schema)
def _change_db_files_owner(self):
- database_name = self.database_name
- new_owner = self.database_username
- if '"' not in new_owner:
- #wrap to allow old username "ambari-server", postgres only
- new_owner = '\'"{0}"\''.format(new_owner)
- pass
-
- command = PGConfig.CHANGE_OWNER_COMMAND[:]
- command[-1] = command[-1].format(database_name, 'ambari', new_owner)
- retcode, stdout, stderr = run_os_command(command)
- if not retcode == 0:
- if get_verbose():
- if stderr:
- print_error_msg("stderr:\n" + stderr.strip())
- if stdout:
- print_error_msg("stdout:\n" + stdout.strip())
+ retcode = 0
+
+ if not self._change_tables_owner():
+ print_error_msg("""Ambari is unable to change ownership of the database tables in {database} to {user}.
+This may be because the administrator user ({admin_user}) does not have permission to make the changes.
+Make sure that all tables returned by following SQL are owned by {user}:
+ "SELECT tablename FROM pg_tables WHERE schemaname = 'ambari';",
+ "SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = 'ambari';",
+ "SELECT table_name FROM information_schema.views WHERE table_schema = 'ambari';
+""".format(database=self.database_name, admin_user=self.local_admin_user, user=self.database_username))
+ continue_ = get_YN_input("Is it safe to continue [yes/no](no)? ", "no")
+ if continue_ and continue_ != "no":
+ retcode = 0
else:
print_info_msg('Fixed database objects owner')
return retcode
+ @staticmethod
+ def _check_for_psql_error(out, err):
+ error_messages = [
+ "psql: FATAL:",
+ "psql: could not connect to server:"
+ ]
+ for message in error_messages:
+ if message in out or message in err:
+ return True
+ False
+
+ def _change_tables_owner(self):
+ """
+ Changes owner for local postgres database tables.
+ :return: True, if owner was changed or already correct
+ """
+ tables = []
+
+ get_tables_queries = [
+ "SELECT tablename FROM pg_tables WHERE schemaname = 'ambari';",
+ "SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = 'ambari';",
+ "SELECT table_name FROM information_schema.views WHERE table_schema = 'ambari';"
+ ]
+
+ for query in get_tables_queries:
+ retcode, stdout, stderr = self._execute_psql_query(query, self.database_name)
+ if retcode != 0 or self._check_for_psql_error(stdout, stderr):
+ print_error_msg("Failed to get list of ambari tables. Message from psql:\n"
+ " stdout:{0}\n"
+ " stderr:{1}\n".format(stdout, stderr))
+ return False
+ for tbl in stdout.splitlines():
+ tables.append(tbl)
+
+ if not tables:
+ print_error_msg("Failed to get list of ambari tables")
+ return False
+
+ for tbl in tables:
+ retcode, stdout, stderr = self._execute_psql_query("select u.usename from information_schema.tables t "
+ "join pg_catalog.pg_class c on (t.table_name = c.relname) "
+ "join pg_catalog.pg_user u on (c.relowner = u.usesysid) "
+ "where t.table_schema='ambari' and t.table_name='"+tbl+"';",
+ self.database_name)
+ owner = stdout.strip()
+ if owner != self.database_username:
+ retcode, stdout, stderr = self._execute_psql_query("ALTER TABLE \"ambari\".\""+tbl+
+ "\" OWNER TO \""+self.database_username+"\"",
+ self.database_name, False)
+ if retcode != 0 or "ALTER TABLE" not in stdout:
+ print_error_msg("Failed to change owner of table:{0} to user:{1}".format(tbl, owner))
+ return False
+
+ return True
+
+ @staticmethod
+ def _execute_psql_query(query, databse, silent=True):
+ """
+ Executes psql query on local database as configured admin user.
+ :param query: query to execute
+ :param databse: database for executing query
+ :param silent: if True, only data returned by query will be printed
+ :return: (code, out, err)
+ """
+ cmd = PGConfig.EXECUTE_QUERY_AS_POSTGRES_FOR_DB_SILENT[:] if silent else PGConfig.EXECUTE_QUERY_AS_POSTGRES_FOR_DB[:]
+ cmd[-1] = cmd[-1].format(query, databse)
+ return run_os_command(cmd)
+
def createPGConfig(options, properties, storage_type, dbId):
return PGConfig(options, properties, storage_type)
@@ -1089,7 +1183,7 @@ class SQLAConfig(LinuxDBMSConfig):
def _extract_client_tarball(self, properties):
files = []
files.extend(glob.glob(configDefaults.SHARE_PATH + os.sep + self.client_tarball_pattern))
-
+
if len(files) > 1:
raise FatalException(-1, "More than One SQl Anywhere client tarball detected")
elif len(files) == 0:
http://git-wip-us.apache.org/repos/asf/ambari/blob/9dbcac6d/ambari-server/src/main/python/ambari_server/serverConfiguration.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverConfiguration.py b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
index 652bbf8..766f4cc 100644
--- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
@@ -140,6 +140,8 @@ JDBC_USE_INTEGRATED_AUTH_PROPERTY = "server.jdbc.use.integrated.auth"
JDBC_RCA_USE_INTEGRATED_AUTH_PROPERTY = "server.jdbc.rca.use.integrated.auth"
### # End Windows-specific # ###
+# The user which will bootstrap embedded postgres database setup by creating the default schema and ambari user.
+LOCAL_DATABASE_ADMIN_PROPERTY = "local.database.user"
# resources repo configuration
RESOURCES_DIR_PROPERTY = "resources.dir"
[13/27] ambari git commit: AMBARI-18399. Ambari UI to auto select
Slider client to get deployed on the History Server host (akovalenko)
Posted by nc...@apache.org.
AMBARI-18399. Ambari UI to auto select Slider client to get deployed on the History Server host (akovalenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/41a9190f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/41a9190f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/41a9190f
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 41a9190fc011dcfd9bc4b99dcba90ad0397b9f94
Parents: cc684be
Author: Aleksandr Kovalenko <ak...@hortonworks.com>
Authored: Thu Sep 15 15:19:19 2016 +0300
Committer: Aleksandr Kovalenko <ak...@hortonworks.com>
Committed: Thu Sep 15 15:22:16 2016 +0300
----------------------------------------------------------------------
.../resources/common-services/YARN/2.1.0.2.0/metainfo.xml | 7 +++++++
1 file changed, 7 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/41a9190f/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/metainfo.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/metainfo.xml b/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/metainfo.xml
index f80fa8a..25e242b 100644
--- a/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/metainfo.xml
+++ b/ambari-server/src/main/resources/common-services/YARN/2.1.0.2.0/metainfo.xml
@@ -217,6 +217,13 @@
<enabled>true</enabled>
</auto-deploy>
</dependency>
+ <dependency>
+ <name>SLIDER/SLIDER</name>
+ <scope>host</scope>
+ <auto-deploy>
+ <enabled>true</enabled>
+ </auto-deploy>
+ </dependency>
</dependencies>
<commandScript>
<script>scripts/historyserver.py</script>
[14/27] ambari git commit: AMBARI-18400 Config group other than
Default group takes forever to load (atkach)
Posted by nc...@apache.org.
AMBARI-18400 Config group other than Default group takes forever to load (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3c06ca3b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3c06ca3b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3c06ca3b
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 3c06ca3b654e0abd6fd4265fb16693e1d1f7f97f
Parents: 41a9190
Author: Andrii Tkach <at...@apache.org>
Authored: Thu Sep 15 15:51:39 2016 +0300
Committer: Andrii Tkach <at...@apache.org>
Committed: Thu Sep 15 17:28:59 2016 +0300
----------------------------------------------------------------------
.../common/configs/config_with_override_recommendation_parser.js | 4 +++-
.../configs/config_with_override_recommendation_parser_test.js | 4 ++--
2 files changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/3c06ca3b/ambari-web/app/mixins/common/configs/config_with_override_recommendation_parser.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/configs/config_with_override_recommendation_parser.js b/ambari-web/app/mixins/common/configs/config_with_override_recommendation_parser.js
index f866451..86ccb65 100644
--- a/ambari-web/app/mixins/common/configs/config_with_override_recommendation_parser.js
+++ b/ambari-web/app/mixins/common/configs/config_with_override_recommendation_parser.js
@@ -107,10 +107,12 @@ App.ConfigWithOverrideRecommendationParser = Em.Mixin.create(App.ConfigRecommend
* @param {Object} stackProperty
* @param {string} attr
* @param {Number|String|Boolean} value
+ * @param {String} name
+ * @param {String} fileName
* @param {App.ServiceConfigGroup} configGroup
* @protected
*/
- _updateOverrideBoundaries: function(stackProperty, attr, value, configGroup) {
+ _updateOverrideBoundaries: function(stackProperty, attr, value, name, fileName, configGroup) {
if (!stackProperty.valueAttributes[configGroup.get('name')]) {
stackProperty.valueAttributes[configGroup.get('name')] = {};
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/3c06ca3b/ambari-web/test/mixins/common/configs/config_with_override_recommendation_parser_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/common/configs/config_with_override_recommendation_parser_test.js b/ambari-web/test/mixins/common/configs/config_with_override_recommendation_parser_test.js
index 5b7b48c..dc92e88 100644
--- a/ambari-web/test/mixins/common/configs/config_with_override_recommendation_parser_test.js
+++ b/ambari-web/test/mixins/common/configs/config_with_override_recommendation_parser_test.js
@@ -193,12 +193,12 @@ describe('App.ConfigWithOverrideRecommendationParser', function() {
};
it("modify attributes on existing group", function() {
- mixin._updateOverrideBoundaries(stackProperty, 'attr1', 'false', Em.Object.create({name: 'g1'}));
+ mixin._updateOverrideBoundaries(stackProperty, 'attr1', 'false', 'n1', 'file1', Em.Object.create({name: 'g1'}));
expect(stackProperty.valueAttributes.g1.attr1).to.be.equal('false');
});
it("modify attributes on new group", function() {
- mixin._updateOverrideBoundaries(stackProperty, 'attr1', 'true', Em.Object.create({name: 'g2'}));
+ mixin._updateOverrideBoundaries(stackProperty, 'attr1', 'true', 'n2', 'file1', Em.Object.create({name: 'g2'}));
expect(stackProperty.valueAttributes.g2.attr1).to.be.equal('true');
});
});
[03/27] ambari git commit: AMBARI-18332: Blueprints: API should make
available "setting" property from blueprint
Posted by nc...@apache.org.
AMBARI-18332: Blueprints: API should make available "setting" property from blueprint
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1b89d686
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1b89d686
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1b89d686
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 1b89d6866e369906902f759a7a5d2ba865e8cbe0
Parents: 9496772
Author: Nahappan Somasundaram <ns...@hortonworks.com>
Authored: Tue Sep 13 11:06:32 2016 -0700
Committer: Nahappan Somasundaram <ns...@hortonworks.com>
Committed: Wed Sep 14 14:42:16 2016 -0700
----------------------------------------------------------------------
.../internal/BlueprintResourceProvider.java | 31 ++++++
.../internal/BlueprintResourceProviderTest.java | 104 +++++++++++++++++++
2 files changed, 135 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/1b89d686/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java
index 775827b..1c127c0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintResourceProvider.java
@@ -21,6 +21,7 @@ package org.apache.ambari.server.controller.internal;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.gson.Gson;
+import org.apache.ambari.server.orm.entities.BlueprintSettingEntity;
import org.apache.ambari.server.utils.SecretReference;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.DuplicateResourceException;
@@ -96,6 +97,10 @@ public class BlueprintResourceProvider extends AbstractControllerResourceProvide
// Configurations
public static final String CONFIGURATION_PROPERTY_ID = "configurations";
+
+ // Setting
+ public static final String SETTING_PROPERTY_ID = "settings";
+
public static final String PROPERTIES_PROPERTY_ID = "properties";
public static final String PROPERTIES_ATTRIBUTES_PROPERTY_ID = "properties_attributes";
public static final String SCHEMA_IS_NOT_SUPPORTED_MESSAGE =
@@ -320,6 +325,8 @@ public class BlueprintResourceProvider extends AbstractControllerResourceProvide
setResourceProperty(resource, HOST_GROUP_PROPERTY_ID, listGroupProps, requestedIds);
setResourceProperty(resource, CONFIGURATION_PROPERTY_ID,
populateConfigurationList(entity.getConfigurations()), requestedIds);
+ setResourceProperty(resource, SETTING_PROPERTY_ID,
+ populateSettingList(entity.getSettings()), requestedIds);
if (entity.getSecurityType() != null) {
Map<String, String> securityConfigMap = new LinkedHashMap<>();
@@ -387,6 +394,30 @@ public class BlueprintResourceProvider extends AbstractControllerResourceProvide
}
/**
+ * Populate a list of setting property maps from a collection of setting entities.
+ *
+ * @param settings collection of setting entities
+ *
+ * @return list of setting property maps
+ */
+ public static List<Map<String, Object>> populateSettingList(
+ Collection<? extends BlueprintSettingEntity> settings) throws NoSuchResourceException {
+ List<Map<String, Object>> listSettings = new ArrayList<Map<String, Object>>();
+
+ if (settings != null) {
+ for (BlueprintSettingEntity setting : settings) {
+ List<Map<String, String>> propertiesList = jsonSerializer.<List<Map<String, String>>>fromJson(
+ setting.getSettingData(), List.class);
+ Map<String, Object> settingMap = new HashMap<>();
+ settingMap.put(setting.getSettingName(), propertiesList);
+ listSettings.add(settingMap);
+ }
+ }
+
+ return listSettings;
+ }
+
+ /**
* Populate blueprint configurations.
*
* @param propertyMaps collection of configuration property maps
http://git-wip-us.apache.org/repos/asf/ambari/blob/1b89d686/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
index 75eff7e..0943bc9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
@@ -40,6 +40,7 @@ import org.apache.ambari.server.orm.dao.StackDAO;
import org.apache.ambari.server.orm.entities.BlueprintConfigEntity;
import org.apache.ambari.server.orm.entities.BlueprintConfiguration;
import org.apache.ambari.server.orm.entities.BlueprintEntity;
+import org.apache.ambari.server.orm.entities.BlueprintSettingEntity;
import org.apache.ambari.server.orm.entities.HostGroupComponentEntity;
import org.apache.ambari.server.orm.entities.HostGroupConfigEntity;
import org.apache.ambari.server.orm.entities.HostGroupEntity;
@@ -1138,5 +1139,108 @@ public class BlueprintResourceProviderTest {
assertEquals("attrValue1", finalAttrs.get("key3"));
assertEquals("attrValue2", finalAttrs.get("key4"));
}
+
+ @Test
+ public void testPopulateSettingList() throws Exception {
+ StackEntity stackEntity = new StackEntity();
+ stackEntity.setStackName("test-stack-name");
+ stackEntity.setStackVersion("test-stack-version");
+ BlueprintEntity entity = createMock(BlueprintEntity.class);
+ expect(entity.getStack()).andReturn(stackEntity).anyTimes();
+
+ HashMap<PropertyInfo.PropertyType, Set<String>> pwdProperties = new HashMap<PropertyInfo.PropertyType, Set<String>>() {{
+ put(PropertyInfo.PropertyType.PASSWORD, new HashSet<String>(){{
+ add("test.password");
+ }});
+ }};
+
+ StackInfo info = createMock(StackInfo.class);
+ expect(info.getConfigPropertiesTypes("type1")).andReturn(new HashMap<PropertyInfo.PropertyType, Set<String>>()).anyTimes();
+ expect(info.getConfigPropertiesTypes("type2")).andReturn(new HashMap<PropertyInfo.PropertyType, Set<String>>()).anyTimes();
+ expect(info.getConfigPropertiesTypes("type3")).andReturn(pwdProperties).anyTimes();
+ expect(metaInfo.getStack("test-stack-name", "test-stack-version")).andReturn(info).anyTimes();
+
+ replay(info, metaInfo, entity);
+
+ // Blueprint setting entities
+ // Global recovery setting
+ BlueprintSettingEntity settingEntity1 = new BlueprintSettingEntity();
+ settingEntity1.setSettingName("recovery_settings");
+ settingEntity1.setSettingData("[{\"recovery_enabled\":\"true\"}]");
+ settingEntity1.setBlueprintEntity(entity);
+
+ // Service exceptions setting
+ BlueprintSettingEntity settingEntity2 = new BlueprintSettingEntity();
+ settingEntity2.setSettingName("service_settings");
+ settingEntity2.setSettingData("[{\"name\":\"HDFS\", \"recovery_enabled\":\"false\"}, " +
+ "{\"name\":\"ZOOKEEPER\", \"recovery_enabled\":\"false\"}]");
+ settingEntity2.setBlueprintEntity(entity);
+
+ // Service component exceptions setting
+ BlueprintSettingEntity settingEntity3 = new BlueprintSettingEntity();
+ settingEntity3.setSettingName("component_settings");
+ settingEntity3.setSettingData("[{\"name\":\"METRICS_MONITOR\", \"recovery_enabled\":\"false\"}," +
+ "{\"name\":\"KAFKA_CLIENT\", \"recovery_enabled\":\"false\"}]");
+ settingEntity3.setBlueprintEntity(entity);
+
+ List<BlueprintSettingEntity> settingEntities = new ArrayList();
+ settingEntities.add(settingEntity1);
+ settingEntities.add(settingEntity2);
+ settingEntities.add(settingEntity3);
+
+ List<Map<String, Object>> settings = provider.populateSettingList(settingEntities);
+
+ assertNotNull(settings);
+ assertEquals(settingEntities.size(), settings.size());
+
+ // Verify global recovery setting
+ Map<String, Object> setting1 = settings.get(0);
+ assertNotNull(setting1);
+ assertEquals(1, setting1.size());
+ assertTrue(setting1.containsKey("recovery_settings"));
+ List<Map<String, String>> setting1value = (List<Map<String, String>>) setting1.get("recovery_settings");
+ assertNotNull(setting1value);
+ assertEquals(1, setting1value.size());
+ assertTrue(setting1value.get(0).containsKey("recovery_enabled"));
+ assertEquals(setting1value.get(0).get("recovery_enabled"), "true");
+
+ // Verify service exceptions
+ Map<String, Object> setting2 = settings.get(1);
+ assertNotNull(setting2);
+ assertEquals(1, setting2.size());
+ assertTrue(setting2.containsKey("service_settings"));
+ List<Map<String, String>> setting2value = (List<Map<String, String>>) setting2.get("service_settings");
+ assertNotNull(setting2value);
+ assertEquals(2, setting2value.size());
+ // first service exception is HDFS
+ assertTrue(setting2value.get(0).containsKey("name"));
+ assertEquals(setting2value.get(0).get("name"), "HDFS");
+ assertTrue(setting2value.get(0).containsKey("recovery_enabled"));
+ assertEquals(setting2value.get(0).get("recovery_enabled"), "false");
+ // second service exception is ZOOKEEPER
+ assertTrue(setting2value.get(1).containsKey("name"));
+ assertEquals(setting2value.get(1).get("name"), "ZOOKEEPER");
+ assertTrue(setting2value.get(1).containsKey("recovery_enabled"));
+ assertEquals(setting2value.get(1).get("recovery_enabled"), "false");
+
+ // Verify service component exceptions
+ Map<String, Object> setting3 = settings.get(2);
+ assertNotNull(setting3);
+ assertEquals(1, setting3.size());
+ assertTrue(setting3.containsKey("component_settings"));
+ List<Map<String, String>> setting3value = (List<Map<String, String>>) setting3.get("component_settings");
+ assertNotNull(setting3value);
+ assertEquals(2, setting3value.size());
+ // first service component exception is METRICS_MONITOR
+ assertTrue(setting3value.get(0).containsKey("name"));
+ assertEquals(setting3value.get(0).get("name"), "METRICS_MONITOR");
+ assertTrue(setting3value.get(0).containsKey("recovery_enabled"));
+ assertEquals(setting3value.get(0).get("recovery_enabled"), "false");
+ // second service component exception is KAFKA_CLIENT
+ assertTrue(setting3value.get(1).containsKey("name"));
+ assertEquals(setting3value.get(1).get("name"), "KAFKA_CLIENT");
+ assertTrue(setting3value.get(1).containsKey("recovery_enabled"));
+ assertEquals(setting3value.get(1).get("recovery_enabled"), "false");
+ }
}
[19/27] ambari git commit: AMBARI-18367. Create authentication filter
to encapsulate the various Ambari authentication methods (rlevas)
Posted by nc...@apache.org.
AMBARI-18367. Create authentication filter to encapsulate the various Ambari authentication methods (rlevas)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d5cca62c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d5cca62c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d5cca62c
Branch: refs/heads/branch-dev-patch-upgrade
Commit: d5cca62c85f97118ed9e2a3e14729d9e6cb6023d
Parents: edf1b9b
Author: Robert Levas <rl...@hortonworks.com>
Authored: Thu Sep 15 13:19:32 2016 -0400
Committer: Robert Levas <rl...@hortonworks.com>
Committed: Thu Sep 15 13:19:40 2016 -0400
----------------------------------------------------------------------
.../ambari/server/controller/AmbariServer.java | 15 +-
.../server/controller/ControllerModule.java | 12 +-
.../AmbariAuthenticationFilter.java | 158 ++------------
.../AmbariBasicAuthenticationFilter.java | 211 +++++++++++++++++++
.../AmbariDelegatingAuthenticationFilter.java | 146 +++++++++++++
.../AmbariJWTAuthenticationFilter.java | 139 ++++++++++++
.../AmbariAuthorizationFilter.java | 49 ++++-
.../AuthenticationJwtUserNotFoundException.java | 43 ++++
.../jwt/JwtAuthenticationFilter.java | 162 ++++++++------
.../webapp/WEB-INF/spring-security.xml | 31 ++-
.../AmbariAuthenticationFilterTest.java | 139 ------------
.../AmbariBasicAuthenticationFilterTest.java | 139 ++++++++++++
...mbariDelegatingAuthenticationFilterTest.java | 186 ++++++++++++++++
.../AmbariJWTAuthenticationFilterTest.java | 190 +++++++++++++++++
.../AmbariAuthorizationFilterTest.java | 48 ++---
.../jwt/JwtAuthenticationFilterTest.java | 77 ++++++-
16 files changed, 1347 insertions(+), 398 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
index deac313..0e6e6b1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -7,7 +7,7 @@
* "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
+ * 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,
@@ -99,15 +99,12 @@ import org.apache.ambari.server.security.AmbariServerSecurityHeaderFilter;
import org.apache.ambari.server.security.AmbariViewsSecurityHeaderFilter;
import org.apache.ambari.server.security.CertificateManager;
import org.apache.ambari.server.security.SecurityFilter;
-import org.apache.ambari.server.security.authentication.AmbariAuthenticationFilter;
-import org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter;
import org.apache.ambari.server.security.authorization.AmbariLdapAuthenticationProvider;
import org.apache.ambari.server.security.authorization.AmbariLocalUserProvider;
import org.apache.ambari.server.security.authorization.AmbariUserAuthorizationFilter;
import org.apache.ambari.server.security.authorization.PermissionHelper;
import org.apache.ambari.server.security.authorization.Users;
import org.apache.ambari.server.security.authorization.internal.AmbariInternalAuthenticationProvider;
-import org.apache.ambari.server.security.authorization.jwt.JwtAuthenticationFilter;
import org.apache.ambari.server.security.ldap.AmbariLdapDataPopulator;
import org.apache.ambari.server.security.unsecured.rest.CertificateDownload;
import org.apache.ambari.server.security.unsecured.rest.CertificateSign;
@@ -319,6 +316,8 @@ public class AmbariServer {
getBeanFactory();
factory.registerSingleton("guiceInjector", injector);
+ factory.registerSingleton("ambariConfiguration", injector.getInstance(Configuration.class));
+ factory.registerSingleton("ambariUsers", injector.getInstance(Users.class));
factory.registerSingleton("passwordEncoder",
injector.getInstance(PasswordEncoder.class));
factory.registerSingleton("auditLogger",
@@ -331,16 +330,10 @@ public class AmbariServer {
injector.getInstance(AmbariLocalUserProvider.class));
factory.registerSingleton("ambariLdapDataPopulator",
injector.getInstance(AmbariLdapDataPopulator.class));
- factory.registerSingleton("ambariAuthorizationFilter",
- injector.getInstance(AmbariAuthorizationFilter.class));
factory.registerSingleton("ambariUserAuthorizationFilter",
injector.getInstance(AmbariUserAuthorizationFilter.class));
factory.registerSingleton("ambariInternalAuthenticationProvider",
injector.getInstance(AmbariInternalAuthenticationProvider.class));
- factory.registerSingleton("ambariJwtAuthenticationFilter",
- injector.getInstance(JwtAuthenticationFilter.class));
- factory.registerSingleton("ambariAuthenticationFilter",
- injector.getInstance(AmbariAuthenticationFilter.class));
// Spring Security xml config depends on this Bean
String[] contextLocations = {SPRING_CONTEXT_LOCATION};
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index bd34c25..af710ee 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -6,9 +6,9 @@
* 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * 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.
@@ -88,7 +88,6 @@ import org.apache.ambari.server.orm.PersistenceType;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.scheduler.ExecutionScheduler;
import org.apache.ambari.server.scheduler.ExecutionSchedulerImpl;
-import org.apache.ambari.server.security.AmbariEntryPoint;
import org.apache.ambari.server.security.SecurityHelper;
import org.apache.ambari.server.security.SecurityHelperImpl;
import org.apache.ambari.server.security.authorization.AuthorizationHelper;
@@ -144,7 +143,6 @@ import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;
-import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.util.ClassUtils;
import org.springframework.web.filter.DelegatingFilterProxy;
@@ -369,8 +367,6 @@ public class ControllerModule extends AbstractModule {
bind(PersistedState.class).to(PersistedStateImpl.class);
- bind(AuthenticationEntryPoint.class).to(AmbariEntryPoint.class).in(Scopes.SINGLETON);
-
// factory to create LoggingRequestHelper instances for LogSearch integration
bind(LoggingRequestHelperFactory.class).to(LoggingRequestHelperFactoryImpl.class);
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariAuthenticationFilter.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariAuthenticationFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariAuthenticationFilter.java
index 0a312f3..b3bc4c3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariAuthenticationFilter.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariAuthenticationFilter.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -7,7 +7,7 @@
* "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
+ * 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,
@@ -15,151 +15,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.ambari.server.security.authentication;
-import java.io.IOException;
+import javax.servlet.Filter;
import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.ambari.server.audit.event.AuditEvent;
-import org.apache.ambari.server.audit.AuditLogger;
-import org.apache.ambari.server.audit.event.LoginAuditEvent;
-import org.apache.ambari.server.security.AmbariEntryPoint;
-import org.apache.ambari.server.security.authorization.AuthorizationHelper;
-import org.apache.ambari.server.security.authorization.PermissionHelper;
-import org.apache.ambari.server.utils.RequestUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.AuthenticationException;
-import org.springframework.security.crypto.codec.Base64;
-import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
/**
- * The purpose of this class is to check whether authentication is successful or not,
- * and make an audit event
+ * AmbariAuthenticationFilter is a {@link Filter} interface to be implemented
+ * by authentication filters used by the Ambari server. More specifically, implementations
+ * of this interface may be used in the {@link AmbariDelegatingAuthenticationFilter}.
+ *
+ * @see AmbariDelegatingAuthenticationFilter
*/
-public class AmbariAuthenticationFilter extends BasicAuthenticationFilter {
- private static final Logger LOG = LoggerFactory.getLogger(AmbariAuthenticationFilter.class);
-
- /**
- * Audit logger
- */
- private AuditLogger auditLogger;
-
- private PermissionHelper permissionHelper;
-
- public AmbariAuthenticationFilter() {
- super();
- }
-
- public AmbariAuthenticationFilter(AuthenticationManager authenticationManager, AuditLogger auditLogger, PermissionHelper permissionHelper, AmbariEntryPoint ambariEntryPoint) {
- super(authenticationManager, ambariEntryPoint);
- this.auditLogger = auditLogger;
- this.permissionHelper = permissionHelper;
- }
-
- /**
- * Checks whether the authentication information is filled. If it is not, then a login failed audit event is logged
- * @param req
- * @param res
- * @param chain
- * @throws IOException
- * @throws ServletException
- */
- @Override
- public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
- HttpServletRequest request = (HttpServletRequest) req;
- String header = request.getHeader("Authorization");
- if (auditLogger.isEnabled() && AuthorizationHelper.getAuthenticatedName() == null && (header == null || !header.startsWith("Basic "))) {
- AuditEvent loginFailedAuditEvent = LoginAuditEvent.builder()
- .withRemoteIp(RequestUtils.getRemoteAddress(request))
- .withTimestamp(System.currentTimeMillis())
- .withReasonOfFailure("Authentication required")
- .withUserName(null)
- .build();
- auditLogger.log(loginFailedAuditEvent);
- }
- super.doFilter(req, res, chain);
- }
-
- /**
- * If the authentication was successful, then an audit event is logged about the success
- * @param request
- * @param response
- * @param authResult
- * @throws IOException
- */
- @Override
- protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException {
- if(!auditLogger.isEnabled()) {
- return;
- }
- AuditEvent loginSucceededAuditEvent = LoginAuditEvent.builder()
- .withRemoteIp(RequestUtils.getRemoteAddress(request))
- .withUserName(authResult.getName())
- .withTimestamp(System.currentTimeMillis())
- .withRoles(permissionHelper.getPermissionLabels(authResult))
- .build();
- auditLogger.log(loginSucceededAuditEvent);
- }
+public interface AmbariAuthenticationFilter extends Filter {
/**
- * In the case of invalid username or password, the authentication fails and it is logged
- * @param request
- * @param response
- * @param authEx
- * @throws IOException
+ * Tests this AmbariAuthenticationFilter to see if it should be applied to the filter chain
+ * - meaning its {@link Filter#doFilter(ServletRequest, ServletResponse, FilterChain)} method
+ * should be called.
+ * <p>
+ * Each implementation will have its own requirements on whether it should be applied and care must
+ * be taken such that <code>true</code> is returned on if warranted, else other implementations may
+ * not get a chance to execute
+ *
+ * @param httpServletRequest the HttpServletRequest
+ * @return true if this AmbariAuthenticationFilter should be applied to the filter chain; otherwise false.
*/
- @Override
- protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx) throws IOException {
- String header = request.getHeader("Authorization");
- String username = null;
- try {
- String[] decodedAuth = decodeAuth(header, request);
- username = decodedAuth[0];
- } catch (Exception e) {
- LOG.warn("Error occurred during decoding authorization header.",e);
- }
- if(auditLogger.isEnabled()) {
- AuditEvent loginFailedAuditEvent = LoginAuditEvent.builder()
- .withRemoteIp(RequestUtils.getRemoteAddress(request))
- .withTimestamp(System.currentTimeMillis())
- .withReasonOfFailure("Invalid username/password combination")
- .withUserName(username)
- .build();
- auditLogger.log(loginFailedAuditEvent);
- }
- }
-
- /**
- * Helper function to decode Authorization header
- * @param header
- * @param request
- * @return
- * @throws IOException
- */
- private String[] decodeAuth(String header, HttpServletRequest request) throws IOException {
- byte[] base64Token = header.substring(6).getBytes("UTF-8");
-
- byte[] decoded;
- try {
- decoded = Base64.decode(base64Token);
- } catch (IllegalArgumentException ex) {
- throw new BadCredentialsException("Failed to decode basic authentication token");
- }
-
- String token = new String(decoded, this.getCredentialsCharset(request));
- int delim = token.indexOf(":");
- if(delim == -1) {
- throw new BadCredentialsException("Invalid basic authentication token");
- } else {
- return new String[]{token.substring(0, delim), token.substring(delim + 1)};
- }
- }
+ boolean shouldApply(HttpServletRequest httpServletRequest);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariBasicAuthenticationFilter.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariBasicAuthenticationFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariBasicAuthenticationFilter.java
new file mode 100644
index 0000000..9e83f73
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariBasicAuthenticationFilter.java
@@ -0,0 +1,211 @@
+/*
+ * 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.
+ */
+package org.apache.ambari.server.security.authentication;
+
+import java.io.IOException;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.AuditLogger;
+import org.apache.ambari.server.audit.event.LoginAuditEvent;
+import org.apache.ambari.server.security.AmbariEntryPoint;
+import org.apache.ambari.server.security.authorization.AuthorizationHelper;
+import org.apache.ambari.server.security.authorization.PermissionHelper;
+import org.apache.ambari.server.utils.RequestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.security.authentication.AuthenticationManager;
+import org.springframework.security.authentication.BadCredentialsException;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.crypto.codec.Base64;
+import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
+
+/**
+ * AmbariBasicAuthenticationFilter extends a {@link BasicAuthenticationFilter} to allow for auditing
+ * of authentication attempts
+ * <p>
+ * This authentication filter is expected to be used withing an {@link AmbariDelegatingAuthenticationFilter}.
+ *
+ * @see AmbariDelegatingAuthenticationFilter
+ */
+public class AmbariBasicAuthenticationFilter extends BasicAuthenticationFilter implements AmbariAuthenticationFilter {
+ private static final Logger LOG = LoggerFactory.getLogger(AmbariBasicAuthenticationFilter.class);
+
+ /**
+ * Audit logger
+ */
+ private AuditLogger auditLogger;
+
+ /**
+ * PermissionHelper to help create audit entries
+ */
+ private PermissionHelper permissionHelper;
+
+ /**
+ * Constructor.
+ *
+ * @param authenticationManager the Spring authencation manager
+ * @param ambariEntryPoint the Spring entry point
+ * @param auditLogger an Audit Logger
+ * @param permissionHelper a permission helper
+ */
+ public AmbariBasicAuthenticationFilter(AuthenticationManager authenticationManager,
+ AmbariEntryPoint ambariEntryPoint,
+ AuditLogger auditLogger,
+ PermissionHelper permissionHelper) {
+ super(authenticationManager, ambariEntryPoint);
+ this.auditLogger = auditLogger;
+ this.permissionHelper = permissionHelper;
+ }
+
+ /**
+ * Tests to see if this {@link AmbariBasicAuthenticationFilter} should be applied in the authentication
+ * filter chain.
+ * <p>
+ * <code>true</code> will be returned if the HTTP request contains the basic authentication header;
+ * otherwise <code>false</code> will be returned.
+ * <p>
+ * The basic authentication header is named "Authorization" and the value begins with the string
+ * "Basic" following by the encoded username and password information.
+ * <p>
+ * For example:
+ * <code>
+ * Authorization: Basic YWRtaW46YWRtaW4=
+ * </code>
+ *
+ * @param httpServletRequest the HttpServletRequest the HTTP service request
+ * @return <code>true</code> if the HTTP request contains the basic authentication header; otherwise <code>false</code>
+ */
+ @Override
+ public boolean shouldApply(HttpServletRequest httpServletRequest) {
+ String header = httpServletRequest.getHeader("Authorization");
+ return (header != null) && header.startsWith("Basic ");
+ }
+
+ /**
+ * Checks whether the authentication information is filled. If it is not, then a login failed audit event is logged
+ *
+ * @param servletRequest the request
+ * @param servletResponse the response
+ * @param chain the Spring filter chain
+ * @throws IOException
+ * @throws ServletException
+ */
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
+ HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
+
+ if (auditLogger.isEnabled() && shouldApply(httpServletRequest) && (AuthorizationHelper.getAuthenticatedName() == null)) {
+ AuditEvent loginFailedAuditEvent = LoginAuditEvent.builder()
+ .withRemoteIp(RequestUtils.getRemoteAddress(httpServletRequest))
+ .withTimestamp(System.currentTimeMillis())
+ .withReasonOfFailure("Authentication required")
+ .withUserName(null)
+ .build();
+ auditLogger.log(loginFailedAuditEvent);
+ }
+
+ super.doFilter(servletRequest, servletResponse, chain);
+ }
+
+ /**
+ * If the authentication was successful, then an audit event is logged about the success
+ *
+ * @param servletRequest the request
+ * @param servletResponse the response
+ * @param authResult the Authentication result
+ * @throws IOException
+ */
+ @Override
+ protected void onSuccessfulAuthentication(HttpServletRequest servletRequest,
+ HttpServletResponse servletResponse,
+ Authentication authResult) throws IOException {
+ if (auditLogger.isEnabled()) {
+ AuditEvent loginSucceededAuditEvent = LoginAuditEvent.builder()
+ .withRemoteIp(RequestUtils.getRemoteAddress(servletRequest))
+ .withUserName(authResult.getName())
+ .withTimestamp(System.currentTimeMillis())
+ .withRoles(permissionHelper.getPermissionLabels(authResult))
+ .build();
+ auditLogger.log(loginSucceededAuditEvent);
+ }
+ }
+
+ /**
+ * In the case of invalid username or password, the authentication fails and it is logged
+ *
+ * @param servletRequest the request
+ * @param servletResponse the response
+ * @param authExecption the exception, if any, causing the unsuccessful authentication attempt
+ * @throws IOException
+ */
+ @Override
+ protected void onUnsuccessfulAuthentication(HttpServletRequest servletRequest,
+ HttpServletResponse servletResponse,
+ AuthenticationException authExecption) throws IOException {
+ String header = servletRequest.getHeader("Authorization");
+ String username = null;
+ try {
+ username = getUsernameFromAuth(header, getCredentialsCharset(servletRequest));
+ } catch (Exception e) {
+ LOG.warn("Error occurred during decoding authorization header.", e);
+ }
+ if (auditLogger.isEnabled()) {
+ AuditEvent loginFailedAuditEvent = LoginAuditEvent.builder()
+ .withRemoteIp(RequestUtils.getRemoteAddress(servletRequest))
+ .withTimestamp(System.currentTimeMillis())
+ .withReasonOfFailure("Invalid username/password combination")
+ .withUserName(username)
+ .build();
+ auditLogger.log(loginFailedAuditEvent);
+ }
+ }
+
+ /**
+ * Helper function to decode Authorization header
+ *
+ * @param authenticationValue the authentication value to parse
+ * @param charSet the character set of the authentication value
+ * @return the username parsed from the authentication header value
+ * @throws IOException
+ */
+ private String getUsernameFromAuth(String authenticationValue, String charSet) throws IOException {
+ byte[] base64Token = authenticationValue.substring(6).getBytes("UTF-8");
+
+ byte[] decoded;
+ try {
+ decoded = Base64.decode(base64Token);
+ } catch (IllegalArgumentException ex) {
+ throw new BadCredentialsException("Failed to decode basic authentication token");
+ }
+
+ String token = new String(decoded, charSet);
+ int delimiter = token.indexOf(":");
+ if (delimiter == -1) {
+ throw new BadCredentialsException("Invalid basic authentication token");
+ } else {
+ return token.substring(0, delimiter);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariDelegatingAuthenticationFilter.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariDelegatingAuthenticationFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariDelegatingAuthenticationFilter.java
new file mode 100644
index 0000000..aab87a2
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariDelegatingAuthenticationFilter.java
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+package org.apache.ambari.server.security.authentication;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * The AmbariDelegatingAuthenticationFilter is an authentication filter that holds zero or more
+ * {@link org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter}s.
+ * <p>
+ * This container iterates though the contained Filters to delegate {@link Filter} operations.
+ * For {@link Filter#init(FilterConfig)} and {@link Filter#destroy()} operations, all contained filters
+ * will be called. For {@link Filter#doFilter(ServletRequest, ServletResponse, FilterChain)}, each
+ * filter will be accessed in order to test whether is should be used or skipped. Once a filter
+ * claims it is to be used for the operation, interation stops ensuring at most only one of the contained
+ * filters is invoked.
+ */
+public class AmbariDelegatingAuthenticationFilter implements Filter {
+ private static final Logger LOG = LoggerFactory.getLogger(AmbariDelegatingAuthenticationFilter.class);
+
+ /**
+ * The ordered collections of {@link org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter}s
+ */
+ private final Collection<AmbariAuthenticationFilter> filters;
+
+ /**
+ * Constructor.
+ *
+ * @param filters an ordered collections of {@link org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter}s
+ */
+ public AmbariDelegatingAuthenticationFilter(Collection<AmbariAuthenticationFilter> filters) {
+
+ this.filters = (filters == null) ? Collections.<AmbariAuthenticationFilter>emptyList() : filters;
+
+ if (this.filters.isEmpty()) {
+ LOG.warn("The delegated filters list is empty. No authentication tests will be performed by this " +
+ "authentication filter.");
+ } else if (LOG.isDebugEnabled()) {
+ StringBuffer filterNames = new StringBuffer();
+
+ for (AmbariAuthenticationFilter filter : this.filters) {
+ filterNames.append("\n\t");
+ filterNames.append(filter.getClass().getName());
+ }
+
+ LOG.debug("This authentication filter will attempt to authenticate a user using one of the " +
+ "following delegated authentication filters: {}",
+ filterNames);
+ }
+ }
+
+ /**
+ * Iterates over the contained {@link org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter}s
+ * to invoke each's init method.
+ *
+ * @param filterConfig a filter configuration
+ * @throws ServletException
+ */
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ for (AmbariAuthenticationFilter filter : filters) {
+ filter.init(filterConfig);
+ }
+ }
+
+ /**
+ * Iterates over the contained {@link org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter}s
+ * to test each to see if they should be invoked. If one tests positive, its doFilter method will be
+ * invoked and processing will stop ensuring only at most one of the contained filter is invoked.
+ *
+ * @param servletRequest the request
+ * @param servletResponse the response
+ * @param chain the Spring filter change
+ * @throws IOException
+ * @throws ServletException
+ */
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
+ throws IOException, ServletException {
+ boolean handled = false;
+ HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
+
+ for (AmbariAuthenticationFilter filter : filters) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Attempting to apply authentication filter {}", filter.getClass().getName());
+ }
+
+ if (filter.shouldApply(httpServletRequest)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using authentication filter {} since it applies", filter.getClass().getName());
+ }
+
+ filter.doFilter(servletRequest, servletResponse, chain);
+ handled = true;
+ break;
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Filter {} does not apply skipping", filter.getClass().getName());
+ }
+ }
+ }
+
+ if (!handled) {
+ LOG.debug("No delegated filters applied while attempting to authenticate a user, continuing with the filter chain.");
+ chain.doFilter(servletRequest, servletResponse);
+ }
+ }
+
+ /**
+ * Iterates over the contained {@link org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter}s
+ * to invoke each's destroy method.
+ */
+ @Override
+ public void destroy() {
+ for (AmbariAuthenticationFilter filter : filters) {
+ filter.destroy();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilter.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilter.java
new file mode 100644
index 0000000..2c15a38
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilter.java
@@ -0,0 +1,139 @@
+/*
+ * 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.
+ */
+
+package org.apache.ambari.server.security.authentication;
+
+import org.apache.ambari.server.audit.AuditLogger;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.event.LoginAuditEvent;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.security.authorization.AuthorizationHelper;
+import org.apache.ambari.server.security.authorization.PermissionHelper;
+import org.apache.ambari.server.security.authorization.Users;
+import org.apache.ambari.server.security.authorization.jwt.AuthenticationJwtUserNotFoundException;
+import org.apache.ambari.server.security.authorization.jwt.JwtAuthenticationFilter;
+import org.apache.ambari.server.utils.RequestUtils;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.springframework.security.web.AuthenticationEntryPoint;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * AmbariBasicAuthenticationFilter extends a {@link org.apache.ambari.server.security.authorization.jwt.JwtAuthenticationFilter}
+ * to allow for auditing of authentication attempts.
+ * <p>
+ * This authentication filter is expected to be used withing an {@link AmbariDelegatingAuthenticationFilter}.
+ *
+ * @see AmbariDelegatingAuthenticationFilter
+ */
+public class AmbariJWTAuthenticationFilter extends JwtAuthenticationFilter implements AmbariAuthenticationFilter {
+
+ /**
+ * Audit logger
+ */
+ private AuditLogger auditLogger;
+
+ /**
+ * PermissionHelper to help create audit entries
+ */
+ private PermissionHelper permissionHelper;
+
+
+ /**
+ * Constructor.
+ *
+ * @param ambariEntryPoint the Spring entry point
+ * @param configuration the Ambari configuration
+ * @param users the Ambari users object
+ * @param auditLogger an Audit Logger
+ * @param permissionHelper a permission helper
+ */
+ public AmbariJWTAuthenticationFilter(AuthenticationEntryPoint ambariEntryPoint,
+ Configuration configuration,
+ Users users,
+ AuditLogger auditLogger,
+ PermissionHelper permissionHelper) {
+ super(configuration, ambariEntryPoint, users);
+ this.auditLogger = auditLogger;
+ this.permissionHelper = permissionHelper;
+ }
+
+ /**
+ * Checks whether the authentication information is filled. If it is not, then a login failed audit event is logged
+ *
+ * @param servletRequest the request
+ * @param servletResponse the response
+ * @param chain the Spring filter chain
+ * @throws IOException
+ * @throws ServletException
+ */
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
+ HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
+
+ if (auditLogger.isEnabled() && shouldApply(httpServletRequest) && (AuthorizationHelper.getAuthenticatedName() == null)) {
+ AuditEvent loginFailedAuditEvent = LoginAuditEvent.builder()
+ .withRemoteIp(RequestUtils.getRemoteAddress(httpServletRequest))
+ .withTimestamp(System.currentTimeMillis())
+ .withReasonOfFailure("Authentication required")
+ .withUserName(null)
+ .build();
+ auditLogger.log(loginFailedAuditEvent);
+ }
+
+ super.doFilter(servletRequest, servletResponse, chain);
+ }
+
+ @Override
+ protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException {
+ if (auditLogger.isEnabled()) {
+ AuditEvent loginSucceededAuditEvent = LoginAuditEvent.builder()
+ .withRemoteIp(RequestUtils.getRemoteAddress(request))
+ .withUserName(authResult.getName())
+ .withTimestamp(System.currentTimeMillis())
+ .withRoles(permissionHelper.getPermissionLabels(authResult))
+ .build();
+ auditLogger.log(loginSucceededAuditEvent);
+ }
+ }
+
+ @Override
+ protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
+ if (auditLogger.isEnabled()) {
+ String username = null;
+ if (authException instanceof AuthenticationJwtUserNotFoundException) {
+ username = ((AuthenticationJwtUserNotFoundException) authException).getUsername();
+ }
+
+ AuditEvent loginFailedAuditEvent = LoginAuditEvent.builder()
+ .withRemoteIp(RequestUtils.getRemoteAddress(request))
+ .withTimestamp(System.currentTimeMillis())
+ .withReasonOfFailure(authException.getLocalizedMessage())
+ .withUserName(username)
+ .build();
+ auditLogger.log(loginFailedAuditEvent);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilter.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilter.java
index 2f676b4..ac26a43 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilter.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilter.java
@@ -18,7 +18,6 @@
package org.apache.ambari.server.security.authorization;
-import com.google.inject.Inject;
import org.apache.ambari.server.audit.event.AccessUnauthorizedAuditEvent;
import org.apache.ambari.server.audit.event.AuditEvent;
import org.apache.ambari.server.audit.AuditLogger;
@@ -26,11 +25,13 @@ import org.apache.ambari.server.audit.event.LoginAuditEvent;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.orm.entities.PermissionEntity;
import org.apache.ambari.server.orm.entities.PrivilegeEntity;
+import org.apache.ambari.server.security.AmbariEntryPoint;
import org.apache.ambari.server.security.authorization.internal.InternalAuthenticationToken;
import org.apache.ambari.server.utils.RequestUtils;
import org.apache.ambari.server.view.ViewRegistry;
import org.apache.commons.lang.StringUtils;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
+import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
@@ -91,27 +92,56 @@ public class AmbariAuthorizationFilter implements Filter {
protected static final String LOGIN_REDIRECT_BASE = "/#/login?targetURI=";
/**
+ * The Ambari authentication entry point
+ */
+ private final AmbariEntryPoint entryPoint;
+
+ /**
* Access to Ambari configuration data
*/
- @Inject
- private Configuration configuration;
+ private final Configuration configuration;
/**
* Access to user information
*/
- @Inject
- private Users users;
+ private final Users users;
- @Inject
- private AuditLogger auditLogger;
+ /**
+ * The audit logger
+ */
+ private final AuditLogger auditLogger;
- @Inject PermissionHelper permissionHelper;
+ /**
+ * A Permission Helper used to provided inforamtion for the Audit Logger
+ */
+ private final PermissionHelper permissionHelper;
/**
* The realm to use for the basic http auth
*/
private String realm;
+ /**
+ * Constructor.
+ *
+ * @param entryPoint the authentication entrypoint
+ * @param configuration the Ambari configuration
+ * @param users Ambari user access
+ * @param auditLogger the Audit logger
+ * @param permissionHelper the permission helper
+ */
+ public AmbariAuthorizationFilter(AmbariEntryPoint entryPoint,
+ Configuration configuration,
+ Users users,
+ AuditLogger auditLogger,
+ PermissionHelper permissionHelper) {
+ this.entryPoint = entryPoint;
+ this.configuration = configuration;
+ this.users = users;
+ this.auditLogger = auditLogger;
+ this.permissionHelper = permissionHelper;
+ }
+
@Override
public void init(FilterConfig filterConfig) throws ServletException {
realm = getParameterValue(filterConfig, REALM_PARAM, DEFAULT_REALM);
@@ -160,8 +190,7 @@ public class AmbariAuthorizationFilter implements Filter {
String redirectURL = httpResponse.encodeRedirectURL(LOGIN_REDIRECT_BASE + requestedURL);
httpResponse.sendRedirect(redirectURL);
} else {
- httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "Authentication required");
- httpResponse.flushBuffer();
+ entryPoint.commence(httpRequest, httpResponse, new AuthenticationCredentialsNotFoundException("Missing authentication token"));
}
return;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/jwt/AuthenticationJwtUserNotFoundException.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/jwt/AuthenticationJwtUserNotFoundException.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/jwt/AuthenticationJwtUserNotFoundException.java
new file mode 100644
index 0000000..f18af10
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/jwt/AuthenticationJwtUserNotFoundException.java
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+package org.apache.ambari.server.security.authorization.jwt;
+
+import org.springframework.security.core.AuthenticationException;
+
+/**
+ * AuthenticationJwtUserNotFoundException is an AuthenticationException implementation to be thrown
+ * when the user specified in a JTW token is not found in the Ambari user database.
+ */
+public class AuthenticationJwtUserNotFoundException extends AuthenticationException {
+ private final String username;
+
+ public AuthenticationJwtUserNotFoundException(String username, String message) {
+ super(message);
+ this.username = username;
+ }
+
+ public AuthenticationJwtUserNotFoundException(String username, String message, Throwable throwable) {
+ super(message, throwable);
+ this.username = username;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/jwt/JwtAuthenticationFilter.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/jwt/JwtAuthenticationFilter.java b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/jwt/JwtAuthenticationFilter.java
index 760621e..890326f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/jwt/JwtAuthenticationFilter.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/jwt/JwtAuthenticationFilter.java
@@ -17,13 +17,13 @@
*/
package org.apache.ambari.server.security.authorization.jwt;
-import com.google.inject.Inject;
import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.JWSObject;
import com.nimbusds.jose.JWSVerifier;
import com.nimbusds.jose.crypto.RSASSAVerifier;
import com.nimbusds.jwt.SignedJWT;
import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.security.authentication.AmbariAuthenticationFilter;
import org.apache.ambari.server.security.authorization.AmbariGrantedAuthority;
import org.apache.ambari.server.security.authorization.User;
import org.apache.ambari.server.security.authorization.UserType;
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.AuthenticationEntryPoint;
@@ -52,8 +53,8 @@ import java.util.List;
* Filter is used to validate JWT token and authenticate user.
* It is also responsive for creating user in local Ambari database for further management
*/
-public class JwtAuthenticationFilter implements Filter {
- Logger LOG = LoggerFactory.getLogger(JwtAuthenticationFilter.class);
+public class JwtAuthenticationFilter implements AmbariAuthenticationFilter {
+ private static final Logger LOG = LoggerFactory.getLogger(JwtAuthenticationFilter.class);
private final JwtAuthenticationProperties jwtProperties;
@@ -67,7 +68,6 @@ public class JwtAuthenticationFilter implements Filter {
private AuthenticationEntryPoint entryPoint;
private Users users;
- @Inject
public JwtAuthenticationFilter(Configuration configuration, AuthenticationEntryPoint entryPoint, Users users) {
this.entryPoint = entryPoint;
this.users = users;
@@ -83,6 +83,28 @@ public class JwtAuthenticationFilter implements Filter {
loadJwtProperties();
}
+ /**
+ * Tests to see if this JwtAuthenticationFilter should be applied in the authentication
+ * filter chain.
+ * <p>
+ * <code>true</code> will be returned if JWT authentication is enabled and the HTTP request contains
+ * a JWT authentication token cookie; otherwise <code>false</code> will be returned.
+ *
+ * @param httpServletRequest the HttpServletRequest the HTTP service request
+ * @return <code>true</code> if the HTTP request contains the basic authentication header; otherwise <code>false</code>
+ */
+ @Override
+ public boolean shouldApply(HttpServletRequest httpServletRequest) {
+ boolean shouldApply = false;
+
+ if (jwtProperties != null) {
+ String serializedJWT = getJWTFromCookie(httpServletRequest);
+ shouldApply = (serializedJWT != null && isAuthenticationRequired(serializedJWT));
+ }
+
+ return shouldApply;
+ }
+
@Override
public void init(FilterConfig filterConfig) throws ServletException {
@@ -91,7 +113,7 @@ public class JwtAuthenticationFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
- if(jwtProperties == null){
+ if (jwtProperties == null) {
//disable filter if not configured
filterChain.doFilter(servletRequest, servletResponse);
return;
@@ -100,71 +122,68 @@ public class JwtAuthenticationFilter implements Filter {
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
- String serializedJWT = getJWTFromCookie(httpServletRequest);
- if (serializedJWT != null && isAuthenticationRequired(serializedJWT)) {
- SignedJWT jwtToken;
- try {
- jwtToken = SignedJWT.parse(serializedJWT);
-
- boolean valid = validateToken(jwtToken);
-
- if (valid) {
- String userName = jwtToken.getJWTClaimsSet().getSubject();
- User user = users.getUser(userName, UserType.JWT);
- //fixme temporary solution for LDAP username conflicts, auth ldap users via JWT
- if (user == null) {
- user = users.getUser(userName, UserType.LDAP);
- }
-
- if (user == null) {
+ try {
+ String serializedJWT = getJWTFromCookie(httpServletRequest);
+ if (serializedJWT != null && isAuthenticationRequired(serializedJWT)) {
+ try {
+ SignedJWT jwtToken = SignedJWT.parse(serializedJWT);
- //TODO this is temporary check for conflicts, until /users API will change to use user_id instead of name as PK
- User existingUser = users.getUser(userName, UserType.LOCAL);
- if (existingUser != null) {
+ boolean valid = validateToken(jwtToken);
- LOG.error("Access for JWT user [{}] restricted. Detected conflict with local user ", userName);
+ if (valid) {
+ String userName = jwtToken.getJWTClaimsSet().getSubject();
+ User user = users.getUser(userName, UserType.JWT);
+ //fixme temporary solution for LDAP username conflicts, auth ldap users via JWT
+ if (user == null) {
+ user = users.getUser(userName, UserType.LDAP);
}
- //TODO we temporary expect that LDAP is configured to same server as JWT source
- httpServletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
- "Cannot find user from JWT. Please, ensure LDAP is configured and users are synced.");
-
- //interrupt filter chain
- return;
- }
-
- Collection<AmbariGrantedAuthority> userAuthorities =
- users.getUserAuthorities(user.getUserName(), user.getUserType());
-
- JwtAuthentication authentication = new JwtAuthentication(serializedJWT, user, userAuthorities);
- authentication.setAuthenticated(true);
+ if (user == null) {
+ //TODO this is temporary check for conflicts, until /users API will change to use user_id instead of name as PK
+ User existingUser = users.getUser(userName, UserType.LOCAL);
+ if (existingUser != null) {
+ LOG.error("Access for JWT user [{}] restricted. Detected conflict with local user ", userName);
+ }
- SecurityContextHolder.getContext().setAuthentication(authentication);
+ //TODO we temporary expect that LDAP is configured to same server as JWT source
+ throw new AuthenticationJwtUserNotFoundException(userName, "Cannot find user from JWT. Please, ensure LDAP is configured and users are synced.");
+ }
+ Collection<AmbariGrantedAuthority> userAuthorities =
+ users.getUserAuthorities(user.getUserName(), user.getUserType());
- } else {
- //clear security context if authentication was required, but failed
- SecurityContextHolder.clearContext();
+ JwtAuthentication authentication = new JwtAuthentication(serializedJWT, user, userAuthorities);
+ authentication.setAuthenticated(true);
- LOG.warn("JWT authentication failed");
- if (ignoreFailure) {
- filterChain.doFilter(servletRequest, servletResponse);
+ SecurityContextHolder.getContext().setAuthentication(authentication);
+ onSuccessfulAuthentication(httpServletRequest, httpServletResponse, authentication);
} else {
- //used to indicate authentication failure, not used here as we have more than one filter
- entryPoint.commence(httpServletRequest, httpServletResponse, new BadCredentialsException("Invalid JWT " +
- "token"));
+ throw new BadCredentialsException("Invalid JWT token");
}
+ } catch (ParseException e) {
+ LOG.warn("Unable to parse the JWT token", e);
+ throw new BadCredentialsException("Unable to parse the JWT token - " + e.getLocalizedMessage());
}
+ } else {
+ LOG.trace("No JWT cookie found, do nothing");
+ }
+
+ filterChain.doFilter(servletRequest, servletResponse);
+ } catch (AuthenticationException e) {
+ LOG.warn("JWT authentication failed - {}", e.getLocalizedMessage());
+ //clear security context if authentication was required, but failed
+ SecurityContextHolder.clearContext();
- } catch (ParseException e) {
- LOG.warn("Unable to parse the JWT token", e);
+ onUnsuccessfulAuthentication(httpServletRequest, httpServletResponse, e);
+
+ if (ignoreFailure) {
+ filterChain.doFilter(servletRequest, servletResponse);
+ } else {
+ //used to indicate authentication failure, not used here as we have more than one filter
+ entryPoint.commence(httpServletRequest, httpServletResponse, e);
}
- } else {
- LOG.trace("No JWT cookie found, do nothing");
}
-
- filterChain.doFilter(servletRequest, servletResponse);
}
private void loadJwtProperties() {
@@ -179,18 +198,19 @@ public class JwtAuthenticationFilter implements Filter {
/**
* Do not try to validate JWT if user already authenticated via other provider
+ *
* @return true, if JWT validation required
*/
private boolean isAuthenticationRequired(String token) {
Authentication existingAuth = SecurityContextHolder.getContext().getAuthentication();
//authenticate if no auth
- if(existingAuth == null || !existingAuth.isAuthenticated() ){
+ if (existingAuth == null || !existingAuth.isAuthenticated()) {
return true;
}
//revalidate if token was changed
- if(existingAuth instanceof JwtAuthentication && !StringUtils.equals(token, (String) existingAuth.getCredentials())){
+ if (existingAuth instanceof JwtAuthentication && !StringUtils.equals(token, (String) existingAuth.getCredentials())) {
return true;
}
@@ -224,6 +244,7 @@ public class JwtAuthenticationFilter implements Filter {
}
return serializedJWT;
}
+
/**
* Create the URL to be used for authentication of the user in the absence of
* a JWT token within the incoming request.
@@ -304,8 +325,7 @@ public class JwtAuthenticationFilter implements Filter {
* issued token claims list for audience. Override this method in subclasses
* in order to customize the audience validation behavior.
*
- * @param jwtToken
- * the JWT token where the allowed audiences will be found
+ * @param jwtToken the JWT token where the allowed audiences will be found
* @return true if an expected audience is present, otherwise false
*/
protected boolean validateAudiences(SignedJWT jwtToken) {
@@ -366,6 +386,30 @@ public class JwtAuthenticationFilter implements Filter {
return valid;
}
+ /**
+ * Called to declare an authentication attempt was successful. Classes may override this method
+ * to perform additional tasks when authentication completes.
+ *
+ * @param request the request
+ * @param response the response
+ * @param authResult the authenticated user
+ * @throws IOException
+ */
+ protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException {
+ }
+
+ /**
+ * Called to declare an authentication attempt failed. Classes may override this method
+ * to perform additional tasks when authentication fails.
+ *
+ * @param request the request
+ * @param response the response
+ * @param authException the cause for the faulure
+ * @throws IOException
+ */
+ protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
+ }
+
@Override
public void destroy() {
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/main/resources/webapp/WEB-INF/spring-security.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/webapp/WEB-INF/spring-security.xml b/ambari-server/src/main/resources/webapp/WEB-INF/spring-security.xml
index e1697e2..a86973c 100644
--- a/ambari-server/src/main/resources/webapp/WEB-INF/spring-security.xml
+++ b/ambari-server/src/main/resources/webapp/WEB-INF/spring-security.xml
@@ -26,8 +26,7 @@
disable-url-rewriting="true" entry-point-ref="ambariEntryPoint">
<intercept-url pattern="/**" access="isAuthenticated()"/>
<custom-filter ref="ambariUserAuthorizationFilter" before="BASIC_AUTH_FILTER"/>
- <custom-filter ref="ambariAuthenticationFilter" position="BASIC_AUTH_FILTER"/>
- <custom-filter ref="ambariJwtAuthenticationFilter" after="BASIC_AUTH_FILTER" />
+ <custom-filter ref="ambariDelegatingAuthenticationFilter" position="BASIC_AUTH_FILTER"/>
<custom-filter ref="ambariAuthorizationFilter" before="FILTER_SECURITY_INTERCEPTOR"/>
</http>
@@ -46,10 +45,36 @@
<beans:bean id="ambariEntryPoint" class="org.apache.ambari.server.security.AmbariEntryPoint">
</beans:bean>
- <beans:bean id="ambariAuthenticationFilter" class="org.apache.ambari.server.security.authentication.AmbariAuthenticationFilter">
+ <beans:bean id="ambariDelegatingAuthenticationFilter" class="org.apache.ambari.server.security.authentication.AmbariDelegatingAuthenticationFilter">
+ <beans:constructor-arg>
+ <beans:list>
+ <beans:ref bean="ambariBasicAuthenticationFilter"/>
+ <beans:ref bean="ambariJwtAuthenticationFilter"/>
+ </beans:list>
+ </beans:constructor-arg>
+ </beans:bean>
+
+ <beans:bean id="ambariBasicAuthenticationFilter" class="org.apache.ambari.server.security.authentication.AmbariBasicAuthenticationFilter">
<beans:constructor-arg ref="authenticationManager"/>
+ <beans:constructor-arg ref="ambariEntryPoint"/>
<beans:constructor-arg ref="auditLogger"/>
<beans:constructor-arg ref="permissionHelper"/>
+ </beans:bean>
+
+ <beans:bean id="ambariJwtAuthenticationFilter" class="org.apache.ambari.server.security.authentication.AmbariJWTAuthenticationFilter">
<beans:constructor-arg ref="ambariEntryPoint"/>
+ <beans:constructor-arg ref="ambariConfiguration"/>
+ <beans:constructor-arg ref="ambariUsers"/>
+ <beans:constructor-arg ref="auditLogger"/>
+ <beans:constructor-arg ref="permissionHelper"/>
</beans:bean>
+
+ <beans:bean id="ambariAuthorizationFilter" class="org.apache.ambari.server.security.authorization.AmbariAuthorizationFilter">
+ <beans:constructor-arg ref="ambariEntryPoint"/>
+ <beans:constructor-arg ref="ambariConfiguration"/>
+ <beans:constructor-arg ref="ambariUsers"/>
+ <beans:constructor-arg ref="auditLogger"/>
+ <beans:constructor-arg ref="permissionHelper"/>
+ </beans:bean>
+
</beans:beans>
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariAuthenticationFilterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariAuthenticationFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariAuthenticationFilterTest.java
deleted file mode 100644
index 0f2b104..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariAuthenticationFilterTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/**
- * 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.
- */
-package org.apache.ambari.server.security.authentication;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.ambari.server.audit.event.AuditEvent;
-import org.apache.ambari.server.audit.AuditLogger;
-import org.apache.ambari.server.security.AmbariEntryPoint;
-import org.apache.ambari.server.security.authorization.AuthorizationHelper;
-import org.apache.ambari.server.security.authorization.PermissionHelper;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.AuthenticationException;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import org.springframework.security.crypto.codec.Base64;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(AuthorizationHelper.class)
-public class AmbariAuthenticationFilterTest {
-
- private AmbariAuthenticationFilter underTest;
-
- private AuditLogger mockedAuditLogger;
-
- private PermissionHelper permissionHelper;
-
- private AmbariEntryPoint entryPoint;
-
- @Before
- public void setUp() {
- mockedAuditLogger = createMock(AuditLogger.class);
- permissionHelper = createMock(PermissionHelper.class);
- entryPoint = createMock(AmbariEntryPoint.class);
- underTest = new AmbariAuthenticationFilter(null, mockedAuditLogger, permissionHelper, entryPoint);
- replay(entryPoint);
- }
-
- @Test
- public void testDoFilter() throws IOException, ServletException {
- // GIVEN
- HttpServletRequest request = createMock(HttpServletRequest.class);
- HttpServletResponse response = createMock(HttpServletResponse.class);
- FilterChain filterChain = createMock(FilterChain.class);
- expect(request.getHeader("Authorization")).andReturn("header").andReturn(null);
- expect(request.getHeader("X-Forwarded-For")).andReturn("1.2.3.4");
- expect(mockedAuditLogger.isEnabled()).andReturn(true);
- mockedAuditLogger.log(anyObject(AuditEvent.class));
- expectLastCall().times(1);
- filterChain.doFilter(request, response);
- expectLastCall();
- replay(mockedAuditLogger, request, filterChain);
- // WHEN
- underTest.doFilter(request, response, filterChain);
- // THEN
- verify(mockedAuditLogger, request, filterChain);
- }
-
- @Test
- public void testOnSuccessfulAuthentication() throws IOException, ServletException {
- // GIVEN
- HttpServletRequest request = createMock(HttpServletRequest.class);
- HttpServletResponse response = createMock(HttpServletResponse.class);
- Authentication authentication = createMock(Authentication.class);
- PowerMock.mockStatic(AuthorizationHelper.class);
-
- Map<String, List<String>> roles = new HashMap<>();
- roles.put("a", Arrays.asList("r1", "r2", "r3"));
- expect(permissionHelper.getPermissionLabels(authentication))
- .andReturn(roles);
- expect(AuthorizationHelper.getAuthorizationNames(authentication))
- .andReturn(Arrays.asList("perm1", "perm2"));
- expect(AuthorizationHelper.getAuthenticatedName()).andReturn("perm1");
- expect(request.getHeader("X-Forwarded-For")).andReturn("1.2.3.4");
- expect(authentication.getName()).andReturn("admin");
- expect(mockedAuditLogger.isEnabled()).andReturn(true);
- mockedAuditLogger.log(anyObject(AuditEvent.class));
- expectLastCall().times(1);
- replay(mockedAuditLogger, request, authentication, permissionHelper);
- PowerMock.replayAll();
- // WHEN
- underTest.onSuccessfulAuthentication(request, response, authentication);
- // THEN
- verify(mockedAuditLogger, request);
- }
-
- @Test
- public void testOnUnsuccessfulAuthentication() throws IOException, ServletException {
- // GIVEN
- HttpServletRequest request = createMock(HttpServletRequest.class);
- HttpServletResponse response = createMock(HttpServletResponse.class);
- AuthenticationException authEx = createMock(AuthenticationException.class);
- expect(request.getHeader("X-Forwarded-For")).andReturn("1.2.3.4");
- expect(request.getHeader("Authorization")).andReturn(
- "Basic " + new String(Base64.encode("admin:admin".getBytes("UTF-8"))));
- expect(mockedAuditLogger.isEnabled()).andReturn(true);
- mockedAuditLogger.log(anyObject(AuditEvent.class));
- expectLastCall().times(1);
- replay(mockedAuditLogger, request, authEx);
- // WHEN
- underTest.onUnsuccessfulAuthentication(request, response, authEx);
- // THEN
- verify(mockedAuditLogger, request, authEx);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariBasicAuthenticationFilterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariBasicAuthenticationFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariBasicAuthenticationFilterTest.java
new file mode 100644
index 0000000..7344b62
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariBasicAuthenticationFilterTest.java
@@ -0,0 +1,139 @@
+/**
+ * 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.
+ */
+package org.apache.ambari.server.security.authentication;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.ambari.server.audit.event.AuditEvent;
+import org.apache.ambari.server.audit.AuditLogger;
+import org.apache.ambari.server.security.AmbariEntryPoint;
+import org.apache.ambari.server.security.authorization.AuthorizationHelper;
+import org.apache.ambari.server.security.authorization.PermissionHelper;
+import org.junit.runner.RunWith;
+import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.AuthenticationException;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import org.springframework.security.crypto.codec.Base64;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(AuthorizationHelper.class)
+public class AmbariBasicAuthenticationFilterTest {
+
+ private AmbariBasicAuthenticationFilter underTest;
+
+ private AuditLogger mockedAuditLogger;
+
+ private PermissionHelper permissionHelper;
+
+ private AmbariEntryPoint entryPoint;
+
+ @Before
+ public void setUp() {
+ mockedAuditLogger = createMock(AuditLogger.class);
+ permissionHelper = createMock(PermissionHelper.class);
+ entryPoint = createMock(AmbariEntryPoint.class);
+ underTest = new AmbariBasicAuthenticationFilter(null, entryPoint, mockedAuditLogger, permissionHelper);
+ replay(entryPoint);
+ }
+
+ @Test
+ public void testDoFilter() throws IOException, ServletException {
+ // GIVEN
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ HttpServletResponse response = createMock(HttpServletResponse.class);
+ FilterChain filterChain = createMock(FilterChain.class);
+ expect(request.getHeader("Authorization")).andReturn("Basic ").andReturn(null);
+ expect(request.getHeader("X-Forwarded-For")).andReturn("1.2.3.4");
+ expect(mockedAuditLogger.isEnabled()).andReturn(true);
+ mockedAuditLogger.log(anyObject(AuditEvent.class));
+ expectLastCall().times(1);
+ filterChain.doFilter(request, response);
+ expectLastCall();
+ replay(mockedAuditLogger, request, filterChain);
+ // WHEN
+ underTest.doFilter(request, response, filterChain);
+ // THEN
+ verify(mockedAuditLogger, request, filterChain);
+ }
+
+ @Test
+ public void testOnSuccessfulAuthentication() throws IOException, ServletException {
+ // GIVEN
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ HttpServletResponse response = createMock(HttpServletResponse.class);
+ Authentication authentication = createMock(Authentication.class);
+ PowerMock.mockStatic(AuthorizationHelper.class);
+
+ Map<String, List<String>> roles = new HashMap<>();
+ roles.put("a", Arrays.asList("r1", "r2", "r3"));
+ expect(permissionHelper.getPermissionLabels(authentication))
+ .andReturn(roles);
+ expect(AuthorizationHelper.getAuthorizationNames(authentication))
+ .andReturn(Arrays.asList("perm1", "perm2"));
+ expect(AuthorizationHelper.getAuthenticatedName()).andReturn("perm1");
+ expect(request.getHeader("X-Forwarded-For")).andReturn("1.2.3.4");
+ expect(authentication.getName()).andReturn("admin");
+ expect(mockedAuditLogger.isEnabled()).andReturn(true);
+ mockedAuditLogger.log(anyObject(AuditEvent.class));
+ expectLastCall().times(1);
+ replay(mockedAuditLogger, request, authentication, permissionHelper);
+ PowerMock.replayAll();
+ // WHEN
+ underTest.onSuccessfulAuthentication(request, response, authentication);
+ // THEN
+ verify(mockedAuditLogger, request);
+ }
+
+ @Test
+ public void testOnUnsuccessfulAuthentication() throws IOException, ServletException {
+ // GIVEN
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ HttpServletResponse response = createMock(HttpServletResponse.class);
+ AuthenticationException authEx = createMock(AuthenticationException.class);
+ expect(request.getHeader("X-Forwarded-For")).andReturn("1.2.3.4");
+ expect(request.getHeader("Authorization")).andReturn(
+ "Basic " + new String(Base64.encode("admin:admin".getBytes("UTF-8"))));
+ expect(mockedAuditLogger.isEnabled()).andReturn(true);
+ mockedAuditLogger.log(anyObject(AuditEvent.class));
+ expectLastCall().times(1);
+ replay(mockedAuditLogger, request, authEx);
+ // WHEN
+ underTest.onUnsuccessfulAuthentication(request, response, authEx);
+ // THEN
+ verify(mockedAuditLogger, request, authEx);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariDelegatingAuthenticationFilterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariDelegatingAuthenticationFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariDelegatingAuthenticationFilterTest.java
new file mode 100644
index 0000000..d775136
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariDelegatingAuthenticationFilterTest.java
@@ -0,0 +1,186 @@
+/*
+ * 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.
+ */
+
+package org.apache.ambari.server.security.authentication;
+
+import org.easymock.EasyMockSupport;
+import org.junit.Test;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.Arrays;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+
+public class AmbariDelegatingAuthenticationFilterTest extends EasyMockSupport {
+ @Test
+ public void testInit() throws Exception {
+ FilterConfig filterConfig = createMock(FilterConfig.class);
+
+ AmbariAuthenticationFilter filter1 = createMock(AmbariAuthenticationFilter.class);
+ filter1.init(filterConfig);
+ expectLastCall().once();
+
+ AmbariAuthenticationFilter filter2 = createMock(AmbariAuthenticationFilter.class);
+ filter2.init(filterConfig);
+ expectLastCall().once();
+
+ AmbariAuthenticationFilter filter3 = createMock(AmbariAuthenticationFilter.class);
+ filter3.init(filterConfig);
+ expectLastCall().once();
+
+ replayAll();
+
+ Filter filter = new AmbariDelegatingAuthenticationFilter(Arrays.asList(filter1, filter2, filter3));
+ filter.init(filterConfig);
+
+ verifyAll();
+ }
+
+ @Test
+ public void testDoFilterNoneApply() throws Exception {
+ HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
+ HttpServletResponse httpServletResponse = createMock(HttpServletResponse.class);
+
+ AmbariAuthenticationFilter filter1 = createMock(AmbariAuthenticationFilter.class);
+ expect(filter1.shouldApply(httpServletRequest)).andReturn(false).once();
+
+ AmbariAuthenticationFilter filter2 = createMock(AmbariAuthenticationFilter.class);
+ expect(filter2.shouldApply(httpServletRequest)).andReturn(false).once();
+
+ AmbariAuthenticationFilter filter3 = createMock(AmbariAuthenticationFilter.class);
+ expect(filter3.shouldApply(httpServletRequest)).andReturn(false).once();
+
+ FilterChain filterChain = createMock(FilterChain.class);
+ filterChain.doFilter(httpServletRequest, httpServletResponse);
+ expectLastCall().once();
+
+ replayAll();
+
+ Filter filter = new AmbariDelegatingAuthenticationFilter(Arrays.asList(filter1, filter2, filter3));
+ filter.doFilter(httpServletRequest, httpServletResponse, filterChain);
+
+ verifyAll();
+ }
+
+ @Test
+ public void testDoFilterFirstApplies() throws Exception {
+ HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
+ HttpServletResponse httpServletResponse = createMock(HttpServletResponse.class);
+
+ FilterChain filterChain = createMock(FilterChain.class);
+
+ AmbariAuthenticationFilter filter1 = createMock(AmbariAuthenticationFilter.class);
+ expect(filter1.shouldApply(httpServletRequest)).andReturn(true).once();
+ filter1.doFilter(httpServletRequest, httpServletResponse, filterChain);
+ expectLastCall().once();
+
+ AmbariAuthenticationFilter filter2 = createMock(AmbariAuthenticationFilter.class);
+
+ AmbariAuthenticationFilter filter3 = createMock(AmbariAuthenticationFilter.class);
+
+ replayAll();
+
+ Filter filter = new AmbariDelegatingAuthenticationFilter(Arrays.asList(filter1, filter2, filter3));
+ filter.doFilter(httpServletRequest, httpServletResponse, filterChain);
+
+ verifyAll();
+ }
+
+ @Test
+ public void testDoFilterLastApplies() throws Exception {
+ HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
+ HttpServletResponse httpServletResponse = createMock(HttpServletResponse.class);
+
+ FilterChain filterChain = createMock(FilterChain.class);
+
+ AmbariAuthenticationFilter filter1 = createMock(AmbariAuthenticationFilter.class);
+ expect(filter1.shouldApply(httpServletRequest)).andReturn(false).once();
+
+ AmbariAuthenticationFilter filter2 = createMock(AmbariAuthenticationFilter.class);
+ expect(filter2.shouldApply(httpServletRequest)).andReturn(false).once();
+
+ AmbariAuthenticationFilter filter3 = createMock(AmbariAuthenticationFilter.class);
+ expect(filter3.shouldApply(httpServletRequest)).andReturn(true).once();
+ filter3.doFilter(httpServletRequest, httpServletResponse, filterChain);
+ expectLastCall().once();
+
+ replayAll();
+
+ Filter filter = new AmbariDelegatingAuthenticationFilter(Arrays.asList(filter1, filter2, filter3));
+ filter.doFilter(httpServletRequest, httpServletResponse, filterChain);
+
+ verifyAll();
+ }
+
+ @Test
+ public void testDoFilterNthApplies() throws Exception {
+ HttpServletRequest httpServletRequest = createMock(HttpServletRequest.class);
+ HttpServletResponse httpServletResponse = createMock(HttpServletResponse.class);
+
+ FilterChain filterChain = createMock(FilterChain.class);
+
+ AmbariAuthenticationFilter filter1 = createMock(AmbariAuthenticationFilter.class);
+ expect(filter1.shouldApply(httpServletRequest)).andReturn(false).once();
+
+ AmbariAuthenticationFilter filter2 = createMock(AmbariAuthenticationFilter.class);
+ expect(filter2.shouldApply(httpServletRequest)).andReturn(false).once();
+
+ AmbariAuthenticationFilter filterN = createMock(AmbariAuthenticationFilter.class);
+ expect(filterN.shouldApply(httpServletRequest)).andReturn(true).once();
+ filterN.doFilter(httpServletRequest, httpServletResponse, filterChain);
+ expectLastCall().once();
+
+ AmbariAuthenticationFilter filter3 = createMock(AmbariAuthenticationFilter.class);
+
+ replayAll();
+
+ Filter filter = new AmbariDelegatingAuthenticationFilter(Arrays.asList(filter1, filter2, filterN, filter3));
+ filter.doFilter(httpServletRequest, httpServletResponse, filterChain);
+
+ verifyAll();
+ }
+
+ @Test
+ public void testDestroy() throws Exception {
+ AmbariAuthenticationFilter filter1 = createMock(AmbariAuthenticationFilter.class);
+ filter1.destroy();
+ expectLastCall().once();
+
+ AmbariAuthenticationFilter filter2 = createMock(AmbariAuthenticationFilter.class);
+ filter2.destroy();
+ expectLastCall().once();
+
+ AmbariAuthenticationFilter filter3 = createMock(AmbariAuthenticationFilter.class);
+ filter3.destroy();
+ expectLastCall().once();
+
+ replayAll();
+
+ Filter filter = new AmbariDelegatingAuthenticationFilter(Arrays.asList(filter1, filter2, filter3));
+ filter.destroy();
+
+ verifyAll();
+
+ }
+
+}
\ No newline at end of file
[06/27] ambari git commit: AMBARI-18132 : Remove FIFO and Normalizer
in ams-env config. (avijayan)
Posted by nc...@apache.org.
AMBARI-18132 : Remove FIFO and Normalizer in ams-env config. (avijayan)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0e343585
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0e343585
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0e343585
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 0e3435856a2aee7951f765e90e55e027b6455c1a
Parents: 9455b52
Author: Aravindan Vijayan <av...@hortonworks.com>
Authored: Tue Sep 13 20:32:07 2016 -0700
Committer: Aravindan Vijayan <av...@hortonworks.com>
Committed: Wed Sep 14 15:03:34 2016 -0700
----------------------------------------------------------------------
.../server/upgrade/UpgradeCatalog250.java | 62 ++++++++++-
.../0.1.0/configuration/ams-env.xml | 6 -
.../0.1.0/package/scripts/params.py | 2 -
.../server/upgrade/UpgradeCatalog250Test.java | 110 +++++++++++++++++++
4 files changed, 171 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/0e343585/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
index 43f489b..35c773a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog250.java
@@ -18,9 +18,18 @@
package org.apache.ambari.server.upgrade;
import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.orm.dao.DaoUtils;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
+import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,7 +42,7 @@ import com.google.inject.Injector;
public class UpgradeCatalog250 extends AbstractUpgradeCatalog {
protected static final String HOST_VERSION_TABLE = "host_version";
-
+ private static final String AMS_ENV = "ams-env";
/**
* Logger.
*/
@@ -97,6 +106,7 @@ public class UpgradeCatalog250 extends AbstractUpgradeCatalog {
*/
@Override
protected void executeDMLUpdates() throws AmbariException, SQLException {
+ updateAMSConfigs();
}
protected void updateHostVersionTable() throws SQLException {
@@ -106,6 +116,56 @@ public class UpgradeCatalog250 extends AbstractUpgradeCatalog {
dbAccessor.addUniqueConstraint(HOST_VERSION_TABLE, "UQ_host_repo", "repo_version_id", "host_id");
}
+ protected void updateAMSConfigs() throws AmbariException {
+ AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+ Clusters clusters = ambariManagementController.getClusters();
+
+ if (clusters != null) {
+ Map<String, Cluster> clusterMap = clusters.getClusters();
+
+ if (clusterMap != null && !clusterMap.isEmpty()) {
+ for (final Cluster cluster : clusterMap.values()) {
+
+ Config amsEnv = cluster.getDesiredConfigByType(AMS_ENV);
+ if (amsEnv != null) {
+ Map<String, String> amsEnvProperties = amsEnv.getProperties();
+ String content = amsEnvProperties.get("content");
+ Map<String, String> newProperties = new HashMap<>();
+ newProperties.put("content", updateAmsEnvContent(content));
+ updateConfigurationPropertiesForCluster(cluster, AMS_ENV, newProperties, true, true);
+ }
+
+ }
+ }
+ }
+ }
+
+
+ protected String updateAmsEnvContent(String content) {
+ if (content == null) {
+ return null;
+ }
+
+ List<String> toReplaceList = new ArrayList<>();
+ toReplaceList.add("\n# HBase normalizer enabled\n");
+ toReplaceList.add("\n# HBase compaction policy enabled\n");
+ toReplaceList.add("export AMS_HBASE_NORMALIZER_ENABLED={{ams_hbase_normalizer_enabled}}\n");
+ toReplaceList.add("export AMS_HBASE_FIFO_COMPACTION_ENABLED={{ams_hbase_fifo_compaction_enabled}}\n");
+
+ //Because of AMBARI-15331 : AMS HBase FIFO compaction policy and Normalizer settings are not handled correctly
+ toReplaceList.add("export HBASE_NORMALIZATION_ENABLED={{ams_hbase_normalizer_enabled}}\n");
+ toReplaceList.add("export HBASE_FIFO_COMPACTION_POLICY_ENABLED={{ams_hbase_fifo_compaction_policy_enabled}}\n");
+
+
+ for (String toReplace : toReplaceList) {
+ if (content.contains(toReplace)) {
+ content = content.replace(toReplace, StringUtils.EMPTY);
+ }
+ }
+
+ return content;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0e343585/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-env.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-env.xml b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-env.xml
index a52cb82..48232af 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-env.xml
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-env.xml
@@ -130,12 +130,6 @@ export AMS_HBASE_PID_DIR={{hbase_pid_dir}}
# AMS Collector heapsize
export AMS_COLLECTOR_HEAPSIZE={{metrics_collector_heapsize}}
-# HBase normalizer enabled
-export AMS_HBASE_NORMALIZER_ENABLED={{ams_hbase_normalizer_enabled}}
-
-# HBase compaction policy enabled
-export AMS_HBASE_FIFO_COMPACTION_ENABLED={{ams_hbase_fifo_compaction_enabled}}
-
# HBase Tables Initialization check enabled
export AMS_HBASE_INIT_CHECK_ENABLED={{ams_hbase_init_check_enabled}}
http://git-wip-us.apache.org/repos/asf/ambari/blob/0e343585/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
index 61b89f8..22024bb 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
@@ -159,8 +159,6 @@ ams_grafana_cert_key = default("/configurations/ams-grafana-ini/cert_key", '/etc
ams_hbase_home_dir = "/usr/lib/ams-hbase/"
-ams_hbase_normalizer_enabled = default("/configurations/ams-hbase-site/hbase.normalizer.enabled", None)
-ams_hbase_fifo_compaction_enabled = default("/configurations/ams-site/timeline.metrics.hbase.fifo.compaction.enabled", None)
ams_hbase_init_check_enabled = default("/configurations/ams-site/timeline.metrics.hbase.init.check.enabled", True)
#hadoop params
http://git-wip-us.apache.org/repos/asf/ambari/blob/0e343585/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
index 6dadb22..c4e0a7c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
@@ -28,8 +28,21 @@ import static org.easymock.EasyMock.verify;
import javax.persistence.EntityManager;
+import com.google.common.collect.Maps;
+import com.google.gson.Gson;
+import org.apache.ambari.server.actionmanager.ActionManager;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.AmbariManagementControllerImpl;
+import org.apache.ambari.server.controller.KerberosHelper;
+import org.apache.ambari.server.controller.MaintenanceStateHelper;
import org.apache.ambari.server.orm.DBAccessor;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
import org.apache.ambari.server.state.stack.OsFamily;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.easymock.EasyMockSupport;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -40,6 +53,15 @@ import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Provider;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.junit.Assert.assertTrue;
/**
* {@link UpgradeCatalog250} unit tests.
*/
@@ -86,4 +108,92 @@ public class UpgradeCatalog250Test {
verify(dbAccessor);
}
+ @Test
+ public void testExecuteDMLUpdates() throws Exception {
+ Method updateAmsConfigs = UpgradeCatalog250.class.getDeclaredMethod("updateAMSConfigs");
+
+ UpgradeCatalog250 upgradeCatalog250 = createMockBuilder(UpgradeCatalog250.class)
+ .addMockedMethod(updateAmsConfigs)
+ .createMock();
+
+ upgradeCatalog250.updateAMSConfigs();
+ expectLastCall().once();
+
+ replay(upgradeCatalog250);
+
+ upgradeCatalog250.executeDMLUpdates();
+
+ verify(upgradeCatalog250);
+ }
+
+ @Test
+ public void testAmsEnvUpdateConfigs() throws Exception{
+
+ Map<String, String> oldPropertiesAmsEnv = new HashMap<String, String>() {
+ {
+ put("content", "\n" +
+ "# AMS Collector heapsize\n" +
+ "export AMS_COLLECTOR_HEAPSIZE={{metrics_collector_heapsize}}\n" +
+ "\n" +
+ "# HBase normalizer enabled\n" +
+ "export AMS_HBASE_NORMALIZER_ENABLED={{ams_hbase_normalizer_enabled}}\n" +
+ "\n" +
+ "# HBase compaction policy enabled\n" +
+ "export HBASE_FIFO_COMPACTION_POLICY_ENABLED={{ams_hbase_fifo_compaction_policy_enabled}}\n" +
+ "\n" +
+ "# HBase Tables Initialization check enabled\n" +
+ "export AMS_HBASE_INIT_CHECK_ENABLED={{ams_hbase_init_check_enabled}}\n");
+ }
+ };
+ Map<String, String> newPropertiesAmsEnv = new HashMap<String, String>() {
+ {
+ put("content", "\n" +
+ "# AMS Collector heapsize\n" +
+ "export AMS_COLLECTOR_HEAPSIZE={{metrics_collector_heapsize}}\n" +
+ "\n" +
+ "# HBase Tables Initialization check enabled\n" +
+ "export AMS_HBASE_INIT_CHECK_ENABLED={{ams_hbase_init_check_enabled}}\n");
+ }
+ };
+ EasyMockSupport easyMockSupport = new EasyMockSupport();
+
+ Clusters clusters = easyMockSupport.createNiceMock(Clusters.class);
+ final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class);
+ Config mockAmsEnv = easyMockSupport.createNiceMock(Config.class);
+
+ expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
+ put("normal", cluster);
+ }}).once();
+ expect(cluster.getDesiredConfigByType("ams-env")).andReturn(mockAmsEnv).atLeastOnce();
+ expect(mockAmsEnv.getProperties()).andReturn(oldPropertiesAmsEnv).anyTimes();
+
+ Injector injector = easyMockSupport.createNiceMock(Injector.class);
+ expect(injector.getInstance(Gson.class)).andReturn(null).anyTimes();
+ expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).anyTimes();
+ expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)).anyTimes();
+
+ replay(injector, clusters, mockAmsEnv, cluster);
+
+ AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class)
+ .addMockedMethod("createConfiguration")
+ .addMockedMethod("getClusters", new Class[] { })
+ .addMockedMethod("createConfig")
+ .withConstructor(createNiceMock(ActionManager.class), clusters, injector)
+ .createNiceMock();
+
+ Injector injector2 = easyMockSupport.createNiceMock(Injector.class);
+ Capture<Map> propertiesCapture = EasyMock.newCapture();
+
+ expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
+ expect(controller.getClusters()).andReturn(clusters).anyTimes();
+ expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+ anyObject(Map.class))).andReturn(createNiceMock(Config.class)).once();
+
+ replay(controller, injector2);
+ new UpgradeCatalog250(injector2).updateAMSConfigs();
+ easyMockSupport.verifyAll();
+
+ Map<String, String> updatedProperties = propertiesCapture.getValue();
+ assertTrue(Maps.difference(newPropertiesAmsEnv, updatedProperties).areEqual());
+ }
}
[02/27] ambari git commit: AMBARI-18389 - Config compare shows
incorrect value after enabling kerberos (rzang)
Posted by nc...@apache.org.
AMBARI-18389 - Config compare shows incorrect value after enabling kerberos (rzang)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9496772d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9496772d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9496772d
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 9496772d9f662daefcb78f971a201df0172c2430
Parents: 08e426a
Author: Richard Zang <rz...@apache.org>
Authored: Wed Sep 14 13:50:08 2016 -0700
Committer: Richard Zang <rz...@apache.org>
Committed: Wed Sep 14 13:50:08 2016 -0700
----------------------------------------------------------------------
.../app/models/configs/objects/service_config_property.js | 9 +++++++--
.../models/configs/objects/service_config_property_test.js | 2 --
2 files changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9496772d/ambari-web/app/models/configs/objects/service_config_property.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/configs/objects/service_config_property.js b/ambari-web/app/models/configs/objects/service_config_property.js
index 0c7673d..5d85ae0 100644
--- a/ambari-web/app/models/configs/objects/service_config_property.js
+++ b/ambari-web/app/models/configs/objects/service_config_property.js
@@ -118,8 +118,13 @@ App.ServiceConfigProperty = Em.Object.extend({
/**
* Placeholder used for configs with input type text
*/
- placeholder: Em.computed.firstNotBlank('placeholderText', 'savedValue'),
-
+ placeholder: function() {
+ if (this.isEditable) {
+ return this.get('placeholderText') || this.get('savedValue');
+ }
+ return null;
+ }.property('isEditable', 'placeholderText', 'savedValue'),
+
retypedPassword: '',
description: '',
displayType: 'string', // string, digits, number, directories, custom
http://git-wip-us.apache.org/repos/asf/ambari/blob/9496772d/ambari-web/test/models/configs/objects/service_config_property_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/configs/objects/service_config_property_test.js b/ambari-web/test/models/configs/objects/service_config_property_test.js
index a6772d3..d462025 100644
--- a/ambari-web/test/models/configs/objects/service_config_property_test.js
+++ b/ambari-web/test/models/configs/objects/service_config_property_test.js
@@ -186,8 +186,6 @@ describe('App.ServiceConfigProperty', function () {
serviceConfigProperty = getProperty();
});
- App.TestAliases.testAsComputedFirstNotBlank(getProperty(), 'placeholder', ['placeholderText', 'savedValue']);
-
App.TestAliases.testAsComputedAnd(getProperty(), 'hideFinalIcon', ['!isFinal', 'isNotEditable']);
describe('#isPropertyOverridable', function () {
[04/27] ambari git commit: AMBARI-18185 : Selecting one host when
topN is set, throws an error. (avijayan)
Posted by nc...@apache.org.
AMBARI-18185 : Selecting one host when topN is set, throws an error. (avijayan)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4a099342
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4a099342
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4a099342
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 4a099342c1b5a8c1b7dbf77fda3ef0f24bfd26cd
Parents: 1b89d68
Author: Aravindan Vijayan <av...@hortonworks.com>
Authored: Tue Sep 13 20:16:03 2016 -0700
Committer: Aravindan Vijayan <av...@hortonworks.com>
Committed: Wed Sep 14 15:03:33 2016 -0700
----------------------------------------------------------------------
.../metrics/timeline/HBaseTimelineMetricStore.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/4a099342/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
index 60ebdcf..a6f8e2f 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/HBaseTimelineMetricStore.java
@@ -228,7 +228,8 @@ public class HBaseTimelineMetricStore extends AbstractService implements Timelin
.grouped(groupedByHosts);
if (topNConfig != null) {
- if (TopNCondition.isTopNHostCondition(metricNames, hostnames) || TopNCondition.isTopNMetricCondition(metricNames, hostnames)) {
+ if (TopNCondition.isTopNHostCondition(metricNames, hostnames) ^ //Only 1 condition should be true.
+ TopNCondition.isTopNMetricCondition(metricNames, hostnames)) {
conditionBuilder.topN(topNConfig.getTopN());
conditionBuilder.isBottomN(topNConfig.getIsBottomN());
Function.ReadFunction readFunction = Function.ReadFunction.getFunction(topNConfig.getTopNFunction());
[17/27] ambari git commit: AMBARI-18403 - YAML Maps Can Include
Dashes and Other Non-Word Characters (jonathanhurley)
Posted by nc...@apache.org.
AMBARI-18403 - YAML Maps Can Include Dashes and Other Non-Word Characters (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/edf1b9b9
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/edf1b9b9
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/edf1b9b9
Branch: refs/heads/branch-dev-patch-upgrade
Commit: edf1b9b9f2182de2e14a194c5ca243f6cf39170d
Parents: bead01c
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Thu Sep 15 11:51:12 2016 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Thu Sep 15 12:37:27 2016 -0400
----------------------------------------------------------------------
.../main/python/ambari_commons/yaml_utils.py | 16 ++++++++---
ambari-server/src/test/python/TestYAMLUtils.py | 30 ++++++++++++++------
2 files changed, 34 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/edf1b9b9/ambari-common/src/main/python/ambari_commons/yaml_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/ambari_commons/yaml_utils.py b/ambari-common/src/main/python/ambari_commons/yaml_utils.py
index 9753177..dae5b56 100644
--- a/ambari-common/src/main/python/ambari_commons/yaml_utils.py
+++ b/ambari-common/src/main/python/ambari_commons/yaml_utils.py
@@ -26,13 +26,21 @@ REGEX_LIST = '^\w*\[.+\]\w*$'
REGEX_DICTIONARY = '^\w*\{.+\}\w*$'
"""
-storm:
+storm-cluster:
hosts:
- [c6401.ambari.apache.org, c6402.ambari.apache.org]
+ [c6401.ambari.apache.org, c6402.ambari.apache.org, c6403-master.ambari.apache.org]
groups:
- [hadoop, foo]
+ [hadoop, hadoop-secure]
+
+^\s* - allow any whitespace or newlines to start
+\S+ - at least 1 word character (including dashes)
+[ ]*:[ ]* - followed by a colon (allowing spaces around the colon)
+[\r\n\f]+ - at least 1 newline
+
+\s*\S+[ ]*:[ ]*[\r\n\f] - follow with the same basically to ensure a map of maps
"""
-REGEX_NESTED_MAPS = '^[\w+\s*:\s*\n\s*]+\[(.*?)\]+'
+REGEX_NESTED_MAPS = "^\s*\S+[ ]*:[ ]*[\r\n\f]+\s*\S+[ ]*:[ ]*[\r\n\f]"
+
def escape_yaml_property(value):
unquouted_values = ["null", "Null", "NULL", "true", "True", "TRUE", "false",
http://git-wip-us.apache.org/repos/asf/ambari/blob/edf1b9b9/ambari-server/src/test/python/TestYAMLUtils.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestYAMLUtils.py b/ambari-server/src/test/python/TestYAMLUtils.py
index c6ee343..4d2d035 100644
--- a/ambari-server/src/test/python/TestYAMLUtils.py
+++ b/ambari-server/src/test/python/TestYAMLUtils.py
@@ -64,19 +64,33 @@ class TestYAMLUtils(TestCase):
# test maps
map = """
- storm:
+ storm-cluster:
hosts:
- [c6401.ambari.apache.org, c6402.ambari.apache.org]
+ [c6401.ambari.apache.org, c6402.ambari.apache.org, c6403-master.ambari.apache.org]
groups:
- [hadoop, foo]
- foo:
- [bar, baz]
- foo2:
- bar2:
- [baz2]
+ [hadoop, hadoop-secure]
"""
escaped_map = yaml_utils.escape_yaml_property(map)
self.assertTrue(escaped_map.startswith("\n"))
self.assertFalse("'" in escaped_map)
+ # try some weird but valid formatting
+ map = """
+
+
+ storm-cluster :
+ hosts :
+[c6401.ambari.apache.org, c6402.ambari.apache.org, c6403-master.ambari.apache.org]
+ groups :
+ [hadoop!!!, hadoop-secure!!!!-----]
+ """
+ escaped_map = yaml_utils.escape_yaml_property(map)
+ self.assertTrue(escaped_map.startswith("\n"))
+ self.assertFalse("'" in escaped_map)
+ # try some bad formatting - this is not a map
+ map = """ foo : bar :
+ [baz]"""
+ escaped_map = yaml_utils.escape_yaml_property(map)
+ self.assertFalse(escaped_map.startswith("\n"))
+ self.assertTrue("'" in escaped_map)
[21/27] ambari git commit: AMBARI-18404 - Upgrade Summary Endpoint
Throws NPEs Due To JPA Cached Entities With Missing IDs (jonathanhurley)
Posted by nc...@apache.org.
AMBARI-18404 - Upgrade Summary Endpoint Throws NPEs Due To JPA Cached Entities With Missing IDs (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/da560570
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/da560570
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/da560570
Branch: refs/heads/branch-dev-patch-upgrade
Commit: da5605706555d3aecca7a67fb399d9c501972ad4
Parents: 1efc99c
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Thu Sep 15 12:12:06 2016 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Thu Sep 15 23:57:36 2016 -0400
----------------------------------------------------------------------
.../actionmanager/ActionDBAccessorImpl.java | 14 +++++-----
.../server/actionmanager/HostRoleCommand.java | 16 +++++++++++
.../orm/entities/HostRoleCommandEntity.java | 19 +++++++++++++
.../ambari/server/topology/HostRequest.java | 25 ++++++++---------
.../actionmanager/TestActionDBAccessorImpl.java | 29 ++++++++++++++++++++
5 files changed, 82 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/da560570/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
index b7e7f2d..c31ca7e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
@@ -344,7 +344,6 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
StageEntity stageEntity = stage.constructNewPersistenceEntity();
stageEntities.add(stageEntity);
stageEntity.setClusterId(clusterId);
- //TODO refactor to reduce merges
stageEntity.setRequest(requestEntity);
stageDAO.create(stageEntity);
@@ -353,9 +352,6 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
for (HostRoleCommand hostRoleCommand : orderedHostRoleCommands) {
HostRoleCommandEntity hostRoleCommandEntity = hostRoleCommand.constructNewPersistenceEntity();
hostRoleCommandEntity.setStage(stageEntity);
-
- HostEntity hostEntity = null;
-
hostRoleCommandDAO.create(hostRoleCommandEntity);
assert hostRoleCommandEntity.getTaskId() != null;
@@ -365,6 +361,7 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
String output = "output-" + hostRoleCommandEntity.getTaskId() + ".txt";
String error = "errors-" + hostRoleCommandEntity.getTaskId() + ".txt";
+ HostEntity hostEntity = null;
if (null != hostRoleCommandEntity.getHostId()) {
hostEntity = hostDAO.findById(hostRoleCommandEntity.getHostId());
if (hostEntity == null) {
@@ -372,6 +369,7 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
LOG.error(msg);
throw new AmbariException(msg);
}
+
hostRoleCommandEntity.setHostEntity(hostEntity);
try {
@@ -401,9 +399,10 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
hostRoleCommandEntity.setExecutionCommand(executionCommandEntity);
executionCommandDAO.create(hostRoleCommandEntity.getExecutionCommand());
- hostRoleCommandDAO.merge(hostRoleCommandEntity);
+ hostRoleCommandEntity = hostRoleCommandDAO.merge(hostRoleCommandEntity);
+
if (null != hostEntity) {
- hostDAO.merge(hostEntity);
+ hostEntity = hostDAO.merge(hostEntity);
}
}
@@ -411,8 +410,9 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
roleSuccessCriteriaDAO.create(roleSuccessCriteriaEntity);
}
- stageDAO.create(stageEntity);
+ stageEntity = stageDAO.merge(stageEntity);
}
+
requestEntity.setStages(stageEntities);
requestDAO.merge(requestEntity);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/da560570/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java
index ff2ce92..85c8e9f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java
@@ -209,6 +209,22 @@ public class HostRoleCommand {
hostRoleCommandEntity.setEvent(event.getEventJson());
+ // set IDs if the wrapping object has them - they are most likely
+ // non-updatable in JPA since they are retrieved from a relationship,
+ // however the JPA cache may choose to not refresh the entity so they would
+ // end up being null if not set before persisting the command entity
+ if (requestId >= 0) {
+ hostRoleCommandEntity.setRequestId(requestId);
+ }
+
+ if (stageId >= 0) {
+ hostRoleCommandEntity.setStageId(stageId);
+ }
+
+ if (taskId >= 0) {
+ hostRoleCommandEntity.setTaskId(taskId);
+ }
+
return hostRoleCommandEntity;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/da560570/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
index 6288091..74271b9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
@@ -511,8 +511,27 @@ public class HostRoleCommandEntity {
return stage;
}
+ /**
+ * Sets the associated {@link StageEntity} for this command. If the
+ * {@link StageEntity} has been persisted, then this will also set the
+ * commands stage and request ID fields.
+ *
+ * @param stage
+ */
public void setStage(StageEntity stage) {
this.stage = stage;
+
+ // ensure that the IDs are also set since they may not be retrieved from JPA
+ // when this entity is cached
+ if (null != stage) {
+ if (null == stageId) {
+ stageId = stage.getStageId();
+ }
+
+ if (null == requestId) {
+ requestId = stage.getRequestId();
+ }
+ }
}
public HostEntity getHostEntity() {
http://git-wip-us.apache.org/repos/asf/ambari/blob/da560570/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
index c3b44b8..6a65b48 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
@@ -18,6 +18,17 @@
package org.apache.ambari.server.topology;
+import static org.apache.ambari.server.controller.internal.ProvisionAction.INSTALL_AND_START;
+import static org.apache.ambari.server.controller.internal.ProvisionAction.INSTALL_ONLY;
+import static org.apache.ambari.server.controller.internal.ProvisionAction.START_ONLY;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.api.predicate.InvalidQueryException;
import org.apache.ambari.server.api.predicate.PredicateCompiler;
@@ -37,17 +48,6 @@ import org.apache.ambari.server.state.host.HostImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import static org.apache.ambari.server.controller.internal.ProvisionAction.INSTALL_AND_START;
-import static org.apache.ambari.server.controller.internal.ProvisionAction.INSTALL_ONLY;
-import static org.apache.ambari.server.controller.internal.ProvisionAction.START_ONLY;
-
/**
* Represents a set of requests to a single host such as install, start, etc.
*/
@@ -355,9 +355,6 @@ public class HostRequest implements Comparable<HostRequest> {
for (HostRoleCommand task : logicalTasks.values()) {
HostRoleCommandEntity entity = task.constructNewPersistenceEntity();
// the above method doesn't set all of the fields for some unknown reason
- entity.setRequestId(task.getRequestId());
- entity.setStageId(task.getStageId());
- entity.setTaskId(task.getTaskId());
entity.setOutputLog(task.getOutputLog());
entity.setErrorLog(task.errorLog);
http://git-wip-us.apache.org/repos/asf/ambari/blob/da560570/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
index 0813dff..bf9d0db 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
@@ -27,6 +27,7 @@ import java.util.Collections;
import java.util.List;
import javax.persistence.EntityManager;
+import javax.persistence.NamedQuery;
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.Role;
@@ -611,6 +612,34 @@ public class TestActionDBAccessorImpl {
}
+ /**
+ * Tests that entities created int he {@link ActionDBAccessor} can be
+ * retrieved with their IDs intact. EclipseLink seems to execute the
+ * {@link NamedQuery} but then use its cached entities to fill in the data.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testEntitiesCreatedWithIDs() throws Exception {
+ List<Stage> stages = new ArrayList<Stage>();
+ Stage stage = createStubStage(hostName, requestId, stageId);
+
+ stages.add(stage);
+
+ Request request = new Request(stages, clusters);
+
+ // persist entities
+ db.persistActions(request);
+
+ // query entities immediately to ensure IDs are populated
+ List<HostRoleCommandEntity> commandEntities = hostRoleCommandDAO.findByRequest(requestId);
+ Assert.assertEquals(2, commandEntities.size());
+
+ for (HostRoleCommandEntity entity : commandEntities) {
+ Assert.assertEquals(Long.valueOf(requestId), entity.getRequestId());
+ Assert.assertEquals(Long.valueOf(stageId), entity.getStageId());
+ }
+ }
private static class TestActionDBAccessorModule extends AbstractModule {
@Override
[09/27] ambari git commit: AMBARI-18393. Hive Server Interactive
(HSI) fails to start with 'Permission denied' for User Hive,
if HSI starts before HS2.
Posted by nc...@apache.org.
AMBARI-18393. Hive Server Interactive (HSI) fails to start with 'Permission denied' for User Hive, if HSI starts before HS2.
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/565685d3
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/565685d3
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/565685d3
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 565685d326e5a877f8e4479736e75f59f728c9ec
Parents: f5ad1de
Author: Swapan Shridhar <ss...@hortonworks.com>
Authored: Wed Sep 14 15:37:51 2016 -0700
Committer: Swapan Shridhar <ss...@hortonworks.com>
Committed: Wed Sep 14 15:37:51 2016 -0700
----------------------------------------------------------------------
.../0.12.0.2.0/package/scripts/hive_interactive.py | 8 ++++++++
.../python/stacks/2.5/HIVE/test_hive_server_int.py | 17 ++++++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/565685d3/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_interactive.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_interactive.py b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_interactive.py
index 1bcb954..6511d0e 100644
--- a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_interactive.py
+++ b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/hive_interactive.py
@@ -58,6 +58,14 @@ Sets up the configs, jdbc connection and tarball copy to HDFS for Hive Server In
def hive_interactive(name=None):
import params
+ # Create Hive User Dir
+ params.HdfsResource(params.hive_hdfs_user_dir,
+ type="directory",
+ action="create_on_execute",
+ owner=params.hive_user,
+ mode=params.hive_hdfs_user_mode
+ )
+
# list of properties that should be excluded from the config
# this approach is a compromise against adding a dedicated config
# type for hive_server_interactive or needed config groups on a
http://git-wip-us.apache.org/repos/asf/ambari/blob/565685d3/ambari-server/src/test/python/stacks/2.5/HIVE/test_hive_server_int.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.5/HIVE/test_hive_server_int.py b/ambari-server/src/test/python/stacks/2.5/HIVE/test_hive_server_int.py
index b97c377..7477457 100644
--- a/ambari-server/src/test/python/stacks/2.5/HIVE/test_hive_server_int.py
+++ b/ambari-server/src/test/python/stacks/2.5/HIVE/test_hive_server_int.py
@@ -224,7 +224,22 @@ class TestHiveServerInteractive(RMFTestCase):
self.assertNoMoreResources()
- def assert_configure_default(self, no_tmp=False, default_fs_default='hdfs://c6401.ambari.apache.org:8020'):
+ def assert_configure_default(self, no_tmp=False, default_fs_default=u'hdfs://c6401.ambari.apache.org:8020'):
+
+ self.assertResourceCalled('HdfsResource', '/user/hive',
+ immutable_paths = self.DEFAULT_IMMUTABLE_PATHS,
+ security_enabled = False,
+ hadoop_bin_dir = '/usr/hdp/current/hadoop-client/bin',
+ keytab = UnknownConfigurationMock(),
+ kinit_path_local = '/usr/bin/kinit',
+ user = 'hdfs',
+ dfs_type = '',
+ owner = 'hive',
+ hadoop_conf_dir = '/usr/hdp/current/hadoop-client/conf',
+ type = 'directory',
+ action = ['create_on_execute'], hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore', hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name='missing_principal', default_fs=default_fs_default,
+ mode = 0755,
+ )
self.assertResourceCalled('Directory', '/etc/hive2',
mode=0755,
[16/27] ambari git commit: AMBARI-18392 : Cluster failure due to
APP_TIMELINE_SERVER and RESOURCEMANAGER failed to start. (avijayan)
Posted by nc...@apache.org.
AMBARI-18392 : Cluster failure due to APP_TIMELINE_SERVER and RESOURCEMANAGER failed to start. (avijayan)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bead01cf
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bead01cf
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bead01cf
Branch: refs/heads/branch-dev-patch-upgrade
Commit: bead01cfe1a10be6a8dae0c9e681d4254b35db4e
Parents: 513965f
Author: Aravindan Vijayan <av...@hortonworks.com>
Authored: Thu Sep 15 09:25:50 2016 -0700
Committer: Aravindan Vijayan <av...@hortonworks.com>
Committed: Thu Sep 15 09:25:50 2016 -0700
----------------------------------------------------------------------
.../main/resources/scripts/Ambaripreupload.py | 76 ++++++++++----------
1 file changed, 38 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/bead01cf/ambari-server/src/main/resources/scripts/Ambaripreupload.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/scripts/Ambaripreupload.py b/ambari-server/src/main/resources/scripts/Ambaripreupload.py
index 09dcd7e..1082b5e 100644
--- a/ambari-server/src/main/resources/scripts/Ambaripreupload.py
+++ b/ambari-server/src/main/resources/scripts/Ambaripreupload.py
@@ -331,50 +331,50 @@ with Environment() as env:
spark_client_dir = format("/usr/hdp/{stack_version}/spark")
if os.path.exists(spark_client_dir):
- # Rename /usr/hdp/{stack_version}/oozie/share/lib/spark to spark-orig
- Execute(("mv",
- format("{oozie_shared_lib}/lib/spark"),
- format("{oozie_shared_lib}/lib/spark-orig")),
- sudo=True)
+ try:
+ # Rename /usr/hdp/{stack_version}/oozie/share/lib/spark to spark-orig
+ if not os.path.exists(format("{oozie_shared_lib}/lib/spark-orig")):
+ Execute(("mv",
+ format("{oozie_shared_lib}/lib/spark"),
+ format("{oozie_shared_lib}/lib/spark-orig")),
+ sudo=True)
- # Create /usr/hdp/{stack_version}/oozie/share/lib/spark
- Directory(format("{oozie_shared_lib}/lib/spark"),
- owner = oozie_user,
- create_parents = True
- )
+ # Create /usr/hdp/{stack_version}/oozie/share/lib/spark
+ if not os.path.exists(format("{oozie_shared_lib}/lib/spark")):
+ Execute(('mkdir', format('{oozie_shared_lib}/lib/spark')),
+ sudo=True)
- # Copy oozie-sharelib-spark from /usr/hdp/{stack_version}/oozie/share/lib/spark-orig to spark
- Execute(format("cp -f {oozie_shared_lib}/lib/spark-orig/oozie-sharelib-spark*.jar {oozie_shared_lib}/lib/spark"),
- user=oozie_user)
+ # Copy oozie-sharelib-spark from /usr/hdp/{stack_version}/oozie/share/lib/spark-orig to spark
+ Execute(format("cp -f {oozie_shared_lib}/lib/spark-orig/oozie-sharelib-spark*.jar {oozie_shared_lib}/lib/spark"))
- # Copy /usr/hdp/{stack_version}/spark-client/*.jar except spark-examples*.jar
- Execute(format("cp -P {spark_client_dir}/lib/*.jar {oozie_shared_lib}/lib/spark"),
- user=oozie_user)
- Execute(format("find {oozie_shared_lib}/lib/spark/ -type l -delete"),
- user=oozie_user)
- try:
- Execute(format("rm -f {oozie_shared_lib}/lib/spark/spark-examples*.jar"),
- user=oozie_user)
- except:
- print "No spark-examples jar files found in Spark client lib."
+ # Copy /usr/hdp/{stack_version}/spark-client/*.jar except spark-examples*.jar
+ Execute(format("cp -P {spark_client_dir}/lib/*.jar {oozie_shared_lib}/lib/spark"))
+ Execute(format("find {oozie_shared_lib}/lib/spark/ -type l -delete"))
+ try:
+ Execute(format("rm -f {oozie_shared_lib}/lib/spark/spark-examples*.jar"))
+ except:
+ print "No spark-examples jar files found in Spark client lib."
- # Copy /usr/hdp/{stack_version}/spark-client/python/lib/*.zip & *.jar to /usr/hdp/{stack_version}/oozie/share/lib/spark
- Execute(format("cp -f {spark_client_dir}/python/lib/*.zip {oozie_shared_lib}/lib/spark"),
- user=oozie_user)
+ # Copy /usr/hdp/{stack_version}/spark-client/python/lib/*.zip & *.jar to /usr/hdp/{stack_version}/oozie/share/lib/spark
+ Execute(format("cp -f {spark_client_dir}/python/lib/*.zip {oozie_shared_lib}/lib/spark"))
- try:
- Execute(format("cp -f {spark_client_dir}/python/lib/*.jar {oozie_shared_lib}/lib/spark"),
- user=oozie_user)
- except:
- print "No jar files found in Spark client python lib."
+ try:
+ Execute(format("cp -f {spark_client_dir}/python/lib/*.jar {oozie_shared_lib}/lib/spark"))
+ except:
+ print "No jar files found in Spark client python lib."
+
+ Execute(("chmod", "-R", "0755", format('{oozie_shared_lib}/lib/spark')),
+ sudo=True)
- # Skipping this step since it might cause issues to automated scripts that rely on hdfs://user/oozie/share/lib
- # Rename /usr/hdp/{stack_version}/oozie/share/lib to lib_ts
- # millis = int(round(time.time() * 1000))
- # Execute(("mv",
- # format("{oozie_shared_lib}/lib"),
- # format("{oozie_shared_lib}/lib_{millis}")),
- # sudo=True)
+ # Skipping this step since it might cause issues to automated scripts that rely on hdfs://user/oozie/share/lib
+ # Rename /usr/hdp/{stack_version}/oozie/share/lib to lib_ts
+ # millis = int(round(time.time() * 1000))
+ # Execute(("mv",
+ # format("{oozie_shared_lib}/lib"),
+ # format("{oozie_shared_lib}/lib_{millis}")),
+ # sudo=True)
+ except Exception, e:
+ print 'Exception occurred while preparing oozie share lib: '+ repr(e)
params.HdfsResource(format("{oozie_hdfs_user_dir}/share"),
action="create_on_execute",
[12/27] ambari git commit: AMBARI-18338. Microsoft-R client should
work in a secured cluster (Balazs bence Sari via magyari_sandor)
Posted by nc...@apache.org.
AMBARI-18338. Microsoft-R client should work in a secured cluster (Balazs bence Sari via magyari_sandor)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/cc684be1
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cc684be1
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cc684be1
Branch: refs/heads/branch-dev-patch-upgrade
Commit: cc684be15b1fa5404ed86918f8b13d8ae2b0f1ae
Parents: 561dc8e
Author: Balazs Bence Sari <bs...@hortonworks.com>
Authored: Thu Sep 15 14:18:38 2016 +0200
Committer: Sandor Magyari <sm...@hortonworks.com>
Committed: Thu Sep 15 14:18:38 2016 +0200
----------------------------------------------------------------------
.../MICROSOFT_R/8.0.0/kerberos.json | 15 ++++++++++
.../MICROSOFT_R/8.0.0/package/scripts/params.py | 1 +
.../8.0.0/package/scripts/params_linux.py | 29 ++++++++++++++++++++
.../8.0.0/package/scripts/service_check.py | 11 +++++++-
4 files changed, 55 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc684be1/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/kerberos.json
----------------------------------------------------------------------
diff --git a/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/kerberos.json b/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/kerberos.json
new file mode 100644
index 0000000..86fab2d
--- /dev/null
+++ b/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/kerberos.json
@@ -0,0 +1,15 @@
+{
+ "services": [
+ {
+ "name": "MICROSOFT_R",
+ "identities": [
+ {
+ "name": "/HDFS/NAMENODE/hdfs"
+ },
+ {
+ "name": "/smokeuser"
+ }
+ ]
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc684be1/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/params.py b/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/params.py
index 36541e7..aa20797 100644
--- a/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/params.py
+++ b/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/params.py
@@ -28,3 +28,4 @@ else:
host_sys_prepped = default("/hostLevelParams/host_sys_prepped", False)
+revo_share_hdfs_folder = "/user/RevoShare"
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc684be1/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/params_linux.py
----------------------------------------------------------------------
diff --git a/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/params_linux.py b/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/params_linux.py
index d72c42e..71f17b6 100644
--- a/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/params_linux.py
+++ b/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/params_linux.py
@@ -44,7 +44,36 @@ smoke_hdfs_user_mode = 0770
user_group = config['configurations']['cluster-env']['user_group']
security_enabled = config['configurations']['cluster-env']['security_enabled']
smoke_user_keytab = config['configurations']['cluster-env']['smokeuser_keytab']
+hdfs_user_keytab = config['configurations']['hadoop-env']['hdfs_user_keytab']
+hdfs_user = config['configurations']['hadoop-env']['hdfs_user']
kinit_path_local = get_kinit_path(default('/configurations/kerberos-env/executable_search_paths', None))
# not supporting 32 bit jdk.
java64_home = config['hostLevelParams']['java_home']
+
+hadoop_bin_dir = stack_select.get_hadoop_dir("bin")
+hdfs_user_principal = default('/configurations/hadoop-env/hdfs_principal_name', None)
+hdfs_site = config['configurations']['hdfs-site']
+default_fs = config['configurations']['core-site']['fs.defaultFS']
+dfs_type = default("/commandParams/dfs_type", "")
+hadoop_conf_dir = "/etc/hadoop/conf"
+
+
+import functools
+#create partial functions with common arguments for every HdfsResource call
+#to create/delete/copyfromlocal hdfs directories/files we need to call params.HdfsResource in code
+HdfsResource = functools.partial(
+ HdfsResource,
+ user=hdfs_user,
+ hdfs_resource_ignore_file = "/var/lib/ambari-agent/data/.hdfs_resource_ignore",
+ security_enabled = security_enabled,
+ keytab = hdfs_user_keytab,
+ kinit_path_local = kinit_path_local,
+ hadoop_bin_dir = hadoop_bin_dir,
+ hadoop_conf_dir = hadoop_conf_dir,
+ principal_name = hdfs_user_principal,
+ hdfs_site = hdfs_site,
+ default_fs = default_fs,
+ immutable_paths = get_not_managed_resources(),
+ dfs_type = dfs_type
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/cc684be1/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/service_check.py
----------------------------------------------------------------------
diff --git a/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/service_check.py b/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/service_check.py
index 8a425ca..547476b 100644
--- a/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/service_check.py
+++ b/contrib/management-packs/microsoft-r_mpack/src/main/resources/common-services/MICROSOFT_R/8.0.0/package/scripts/service_check.py
@@ -27,9 +27,9 @@ from resource_management.core.resources.system import Execute, File
from resource_management.core.source import InlineTemplate, StaticFile
from resource_management.libraries.functions.format import format
from resource_management.libraries.script.script import Script
-from ambari_commons import OSConst
from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
+
class MicrosoftRServiceCheck(Script):
pass
@@ -39,6 +39,15 @@ class MicrosoftRServiceCheckLinux(MicrosoftRServiceCheck):
import params
env.set_params(params)
+ try:
+ params.HdfsResource(params.revo_share_hdfs_folder,
+ type="directory",
+ action="create_on_execute",
+ owner=params.hdfs_user,
+ mode=0777)
+ except Exception as exception:
+ Logger.warning("Could not check the existence of /user/RevoShare on HDFS, exception: {0}".format(str(exception)))
+
if params.security_enabled:
kinit_cmd = format("{kinit_path_local} -kt {smoke_user_keytab} {smokeuser_principal};")
Execute(kinit_cmd,
[10/27] ambari git commit: AMBARI-18384. Analyze and Optimize Ambari
Server Unit Tests - Group 3.(vbrodetskyi)
Posted by nc...@apache.org.
AMBARI-18384. Analyze and Optimize Ambari Server Unit Tests - Group 3.(vbrodetskyi)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1123ba26
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1123ba26
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1123ba26
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 1123ba265592958f188eaf9b1eac843bcb4d3f1c
Parents: 565685d
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Thu Sep 15 14:40:43 2016 +0300
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Thu Sep 15 14:40:43 2016 +0300
----------------------------------------------------------------------
.../server/agent/TestHeartbeatMonitor.java | 100 +++---
.../security/authorization/TestUsers.java | 321 ++++++++++---------
.../upgrades/UpgradeActionTest.java | 119 ++++---
.../svccomphost/ServiceComponentHostTest.java | 142 ++++----
.../server/upgrade/UpgradeCatalog210Test.java | 63 ++--
5 files changed, 419 insertions(+), 326 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/1123ba26/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
index 31e3a09..b6f5ec2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
@@ -58,6 +58,7 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpSucceede
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartedEvent;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.slf4j.Logger;
@@ -65,7 +66,6 @@ import org.slf4j.LoggerFactory;
import com.google.inject.Guice;
import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
public class TestHeartbeatMonitor {
@@ -76,23 +76,42 @@ public class TestHeartbeatMonitor {
private String clusterName = "cluster1";
private String serviceName = "HDFS";
private int heartbeatMonitorWakeupIntervalMS = 30;
- private AmbariMetaInfo ambariMetaInfo;
- private OrmTestHelper helper;
+ private static AmbariMetaInfo ambariMetaInfo;
+ private static OrmTestHelper helper;
private static final Logger LOG =
LoggerFactory.getLogger(TestHeartbeatMonitor.class);
- @Before
- public void setup() throws Exception {
+ @BeforeClass
+ public static void classSetUp() {
injector = Guice.createInjector(new InMemoryDefaultTestModule());
injector.getInstance(GuiceJpaInitializer.class);
helper = injector.getInstance(OrmTestHelper.class);
ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
}
+ @Before
+ public void setup() throws Exception {
+ cleanup();
+ }
+
@After
public void teardown() {
- injector.getInstance(PersistService.class).stop();
+
+ }
+
+ private void cleanup() throws AmbariException {
+ Clusters clusters = injector.getInstance(Clusters.class);
+ Map<String, Cluster> clusterMap = clusters.getClusters();
+
+
+ for (String clusterName : clusterMap.keySet()) {
+ clusters.deleteCluster(clusterName);
+ }
+
+ for (Host host : clusters.getHosts()) {
+ clusters.deleteHost(host.getHostName());
+ }
}
private void setOsFamily(Host host, String osFamily, String osVersion) {
@@ -104,6 +123,41 @@ public class TestHeartbeatMonitor {
}
@Test
+ public void testHeartbeatLoss() throws AmbariException, InterruptedException,
+ InvalidStateTransitionException {
+ Clusters fsm = injector.getInstance(Clusters.class);
+ String hostname = "host1";
+ fsm.addHost(hostname);
+ ActionQueue aq = new ActionQueue();
+ ActionManager am = mock(ActionManager.class);
+ HeartbeatMonitor hm = new HeartbeatMonitor(fsm, aq, am, 10, injector);
+ HeartBeatHandler handler = new HeartBeatHandler(fsm, aq, am, injector);
+ Register reg = new Register();
+ reg.setHostname(hostname);
+ reg.setResponseId(12);
+ reg.setTimestamp(System.currentTimeMillis() - 300);
+ reg.setAgentVersion(ambariMetaInfo.getServerVersion());
+ HostInfo hi = new HostInfo();
+ hi.setOS("Centos5");
+ reg.setHardwareProfile(hi);
+ handler.handleRegistration(reg);
+ HeartBeat hb = new HeartBeat();
+ hb.setHostname(hostname);
+ hb.setNodeStatus(new HostStatus(HostStatus.Status.HEALTHY, "cool"));
+ hb.setTimestamp(System.currentTimeMillis());
+ hb.setResponseId(12);
+ handler.handleHeartBeat(hb);
+ hm.start();
+ aq.enqueue(hostname, new ExecutionCommand());
+ //Heartbeat will expire and action queue will be flushed
+ while (aq.size(hostname) != 0) {
+ Thread.sleep(1);
+ }
+ assertEquals(fsm.getHost(hostname).getState(), HostState.HEARTBEAT_LOST);
+ classSetUp();
+ }
+
+ @Test
public void testStateCommandsGeneration() throws AmbariException, InterruptedException,
InvalidStateTransitionException {
StackId stackId = new StackId("HDP-0.1");
@@ -401,40 +455,6 @@ public class TestHeartbeatMonitor {
}
@Test
- public void testHeartbeatLoss() throws AmbariException, InterruptedException,
- InvalidStateTransitionException {
- Clusters fsm = injector.getInstance(Clusters.class);
- String hostname = "host1";
- fsm.addHost(hostname);
- ActionQueue aq = new ActionQueue();
- ActionManager am = mock(ActionManager.class);
- HeartbeatMonitor hm = new HeartbeatMonitor(fsm, aq, am, 10, injector);
- HeartBeatHandler handler = new HeartBeatHandler(fsm, aq, am, injector);
- Register reg = new Register();
- reg.setHostname(hostname);
- reg.setResponseId(12);
- reg.setTimestamp(System.currentTimeMillis() - 300);
- reg.setAgentVersion(ambariMetaInfo.getServerVersion());
- HostInfo hi = new HostInfo();
- hi.setOS("Centos5");
- reg.setHardwareProfile(hi);
- handler.handleRegistration(reg);
- HeartBeat hb = new HeartBeat();
- hb.setHostname(hostname);
- hb.setNodeStatus(new HostStatus(HostStatus.Status.HEALTHY, "cool"));
- hb.setTimestamp(System.currentTimeMillis());
- hb.setResponseId(12);
- handler.handleHeartBeat(hb);
- hm.start();
- aq.enqueue(hostname, new ExecutionCommand());
- //Heartbeat will expire and action queue will be flushed
- while (aq.size(hostname) != 0) {
- Thread.sleep(1);
- }
- assertEquals(fsm.getHost(hostname).getState(), HostState.HEARTBEAT_LOST);
- }
-
- @Test
public void testHeartbeatLossWithComponent() throws AmbariException, InterruptedException,
InvalidStateTransitionException {
StackId stackId = new StackId("HDP-0.1");
http://git-wip-us.apache.org/repos/asf/ambari/blob/1123ba26/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
index 4571c86..9b9fee5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/TestUsers.java
@@ -17,6 +17,7 @@
*/
package org.apache.ambari.server.security.authorization;
+import junit.framework.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
@@ -25,13 +26,10 @@ import static org.junit.Assert.assertTrue;
import java.util.List;
-import javax.persistence.EntityManager;
-
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.dao.GroupDAO;
-import org.apache.ambari.server.orm.dao.MemberDAO;
import org.apache.ambari.server.orm.dao.PermissionDAO;
import org.apache.ambari.server.orm.dao.PrincipalDAO;
import org.apache.ambari.server.orm.dao.PrincipalTypeDAO;
@@ -46,6 +44,7 @@ import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
import org.apache.ambari.server.orm.entities.UserEntity;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
@@ -55,78 +54,170 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
import com.google.inject.Guice;
-import com.google.inject.Inject;
import com.google.inject.Injector;
-import com.google.inject.Provider;
-import com.google.inject.persist.PersistService;
-
-import junit.framework.Assert;
public class TestUsers {
- private Injector injector;
-
- @Inject
- protected Users users;
- @Inject
- protected UserDAO userDAO;
- @Inject
- protected GroupDAO groupDAO;
- @Inject
- protected MemberDAO memberDAO;
- @Inject
- protected PermissionDAO permissionDAO;
- @Inject
- protected ResourceDAO resourceDAO;
- @Inject
- protected ResourceTypeDAO resourceTypeDAO;
- @Inject
- protected PrincipalTypeDAO principalTypeDAO;
- @Inject
- protected PrincipalDAO principalDAO;
- @Inject
- protected PasswordEncoder passwordEncoder;
- @Inject
- Provider<EntityManager> entityManagerProvider;
+ private static Injector injector;
+
+
+ protected static Users users;
+ protected static UserDAO userDAO;
+ protected static GroupDAO groupDAO;
+ protected static PermissionDAO permissionDAO;
+ protected static ResourceDAO resourceDAO;
+ protected static ResourceTypeDAO resourceTypeDAO;
+ protected static PrincipalTypeDAO principalTypeDAO;
+ protected static PrincipalDAO principalDAO;
+ protected static PasswordEncoder passwordEncoder;
+
+
+ @BeforeClass
+ public static void classSetUp() {
+ injector = Guice.createInjector(new InMemoryDefaultTestModule());
+ injector.getInstance(GuiceJpaInitializer.class);
+ users = injector.getInstance(Users.class);
+ userDAO = injector.getInstance(UserDAO.class);
+ groupDAO = injector.getInstance(GroupDAO.class);
+ permissionDAO = injector.getInstance(PermissionDAO.class);
+ resourceDAO = injector.getInstance(ResourceDAO.class);
+ resourceTypeDAO = injector.getInstance(ResourceTypeDAO.class);
+ principalTypeDAO = injector.getInstance(PrincipalTypeDAO.class);
+ principalDAO = injector.getInstance(PrincipalDAO.class);
+ passwordEncoder = injector.getInstance(PasswordEncoder.class);
+ }
@Before
public void setup() throws AmbariException {
- InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
- injector = Guice.createInjector(module);
- injector.getInstance(GuiceJpaInitializer.class);
- injector.injectMembers(this);
+ //injector.injectMembers(this);
Authentication auth = new UsernamePasswordAuthenticationToken("admin", null);
SecurityContextHolder.getContext().setAuthentication(auth);
- // create admin permission
- ResourceTypeEntity resourceTypeEntity = new ResourceTypeEntity();
- resourceTypeEntity.setId(ResourceType.AMBARI.getId());
- resourceTypeEntity.setName(ResourceType.AMBARI.name());
- resourceTypeDAO.create(resourceTypeEntity);
+ if (resourceTypeDAO.findByName(ResourceType.AMBARI.name()) == null) {
+ // create admin permission
+ ResourceTypeEntity resourceTypeEntity = new ResourceTypeEntity();
+ resourceTypeEntity.setId(ResourceType.AMBARI.getId());
+ resourceTypeEntity.setName(ResourceType.AMBARI.name());
+ resourceTypeDAO.create(resourceTypeEntity);
+
+ ResourceEntity resourceEntity = new ResourceEntity();
+ resourceEntity.setId(ResourceEntity.AMBARI_RESOURCE_ID);
+ resourceEntity.setResourceType(resourceTypeEntity);
+ resourceDAO.create(resourceEntity);
+
+ PrincipalTypeEntity principalTypeEntity = new PrincipalTypeEntity();
+ principalTypeEntity.setName("ROLE");
+ principalTypeEntity = principalTypeDAO.merge(principalTypeEntity);
+
+ PrincipalEntity principalEntity = new PrincipalEntity();
+ principalEntity.setPrincipalType(principalTypeEntity);
+ principalEntity = principalDAO.merge(principalEntity);
+
+ PermissionEntity adminPermissionEntity = new PermissionEntity();
+ adminPermissionEntity.setId(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION);
+ adminPermissionEntity.setPermissionName(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION_NAME);
+ adminPermissionEntity.setPrincipal(principalEntity);
+ adminPermissionEntity.setResourceType(resourceTypeEntity);
+ permissionDAO.create(adminPermissionEntity);
+
+ users.createUser("admin", "admin", UserType.LOCAL, true, true);
+ }
+ cleanup();
+ }
- ResourceEntity resourceEntity = new ResourceEntity();
- resourceEntity.setId(ResourceEntity.AMBARI_RESOURCE_ID);
- resourceEntity.setResourceType(resourceTypeEntity);
- resourceDAO.create(resourceEntity);
+ @After
+ public void tearDown() throws AmbariException {
- PrincipalTypeEntity principalTypeEntity = new PrincipalTypeEntity();
- principalTypeEntity.setName("ROLE");
- principalTypeEntity = principalTypeDAO.merge(principalTypeEntity);
+ }
- PrincipalEntity principalEntity = new PrincipalEntity();
- principalEntity.setPrincipalType(principalTypeEntity);
- principalEntity = principalDAO.merge(principalEntity);
+ private void cleanup() throws AmbariException {
+ for (User user : users.getAllUsers()) {
+ if (!user.getUserName().equals("admin")) {
+ users.removeUser(user);
+ }
+ }
- PermissionEntity adminPermissionEntity = new PermissionEntity();
- adminPermissionEntity.setId(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION);
- adminPermissionEntity.setPermissionName(PermissionEntity.AMBARI_ADMINISTRATOR_PERMISSION_NAME);
- adminPermissionEntity.setPrincipal(principalEntity);
- adminPermissionEntity.setResourceType(resourceTypeEntity);
- permissionDAO.create(adminPermissionEntity);
+ for (Group group : users.getAllGroups()) {
+ users.removeGroup(group);
+ }
}
- @After
- public void tearDown() throws AmbariException {
- injector.getInstance(PersistService.class).stop();
+ @Test
+ public void testIsUserCanBeRemoved() throws Exception {
+ //users.createUser("admin", "admin", UserType.LOCAL, true, true);
+ users.createUser("admin222", "admin222", UserType.LOCAL, true, true);
+
+ Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin")));
+ Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin222")));
+
+ users.removeUser(users.getAnyUser("admin222"));
+
+ Assert.assertFalse(users.isUserCanBeRemoved(userDAO.findUserByName("admin")));
+ users.createUser("user", "user");
+ Assert.assertFalse(users.isUserCanBeRemoved(userDAO.findUserByName("admin")));
+
+ users.createUser("admin333", "admin333", UserType.LOCAL, true, true);
+ Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin")));
+ Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin333")));
+ }
+
+ @Test
+ public void testGetUserIfUnique() throws Exception {
+ users.createUser("user333", "user333", UserType.LOCAL, true, false);
+
+ Assert.assertNotNull(users.getUserIfUnique("user333"));
+
+ users.createUser("user333", "user333", UserType.LDAP, true, false);
+
+ Assert.assertNull(users.getUserIfUnique("user333"));
+ }
+
+ @Test
+ public void testModifyPassword_UserByAdmin() throws Exception {
+ users.createUser("new_admin", "new_admin", UserType.LOCAL, true, true);
+ users.createUser("user", "user");
+
+ UserEntity userEntity = userDAO.findUserByName("user");
+
+ assertNotSame("user", userEntity.getUserPassword());
+ assertTrue(passwordEncoder.matches("user", userEntity.getUserPassword()));
+
+ users.modifyPassword("user", "admin", "user_new_password");
+ assertTrue(passwordEncoder.matches("user_new_password", userDAO.findUserByName("user").getUserPassword()));
+ }
+
+ @Test
+ public void testRevokeAdminPrivilege() throws Exception {
+ users.createUser("old_admin", "old_admin", UserType.LOCAL, true, true);
+
+ final User admin = users.getAnyUser("old_admin");
+ users.revokeAdminPrivilege(admin.getUserId());
+
+ Assert.assertFalse(users.getAnyUser("old_admin").isAdmin());
+ }
+
+ @Test
+ public void testGrantAdminPrivilege() throws Exception {
+ users.createUser("user", "user");
+
+ final User user = users.getAnyUser("user");
+ users.grantAdminPrivilege(user.getUserId());
+
+ Assert.assertTrue(users.getAnyUser("user").isAdmin());
+ }
+
+ @Test
+ public void testGetGroupMembers() throws Exception {
+ final String groupNameTwoMembers = "engineering";
+ final String groupNameZeroMembers = "management";
+ users.createGroup(groupNameTwoMembers);
+ users.createGroup(groupNameZeroMembers);
+ users.createUser("user1", "user1");
+ users.createUser("user2", "user2");
+ users.addMemberToGroup(groupNameTwoMembers, "user1");
+ users.addMemberToGroup(groupNameTwoMembers, "user2");
+
+ assertEquals(users.getGroupMembers(groupNameTwoMembers).size(), 2);
+ assertEquals(users.getGroupMembers(groupNameZeroMembers).size(), 0);
}
@Test
@@ -135,7 +226,6 @@ public class TestUsers {
SecurityContextHolder.getContext().setAuthentication(auth);
users.createUser("user", "user");
- users.createUser("admin", "admin");
List<User> userList = users.getAllUsers();
@@ -317,24 +407,10 @@ public class TestUsers {
assertEquals(0, groupDAO.findGroupByName(groupName).getMemberEntities().size());
}
- @Test
- public void testGetGroupMembers() throws Exception {
- final String groupNameTwoMembers = "engineering";
- final String groupNameZeroMembers = "management";
- users.createGroup(groupNameTwoMembers);
- users.createGroup(groupNameZeroMembers);
- users.createUser("user", "user");
- users.createUser("admin", "admin");
- users.addMemberToGroup(groupNameTwoMembers, "user");
- users.addMemberToGroup(groupNameTwoMembers, "admin");
-
- assertEquals(users.getGroupMembers(groupNameTwoMembers).size(), 2);
- assertEquals(users.getGroupMembers(groupNameZeroMembers).size(), 0);
- }
@Test
public void testGetGroupMembersUnexistingGroup() throws Exception {
- assertEquals(users.getGroupMembers("unexisting"), null);
+ assertEquals(users.getGroupMembers("unexisting"), null);
}
@Test
@@ -394,20 +470,6 @@ public class TestUsers {
}
@Test
- public void testModifyPassword_UserByAdmin() throws Exception {
- users.createUser("admin", "admin", UserType.LOCAL, true, true);
- users.createUser("user", "user");
-
- UserEntity userEntity = userDAO.findUserByName("user");
-
- assertNotSame("user", userEntity.getUserPassword());
- assertTrue(passwordEncoder.matches("user", userEntity.getUserPassword()));
-
- users.modifyPassword("user", "admin", "user_new_password");
- assertTrue(passwordEncoder.matches("user_new_password", userDAO.findUserByName("user").getUserPassword()));
- }
-
- @Test
public void testCreateUserTwoParams() throws Exception {
users.createUser("user", "user");
@@ -426,23 +488,6 @@ public class TestUsers {
Mockito.verify(spy).createUser("user", "user", UserType.LOCAL, true, false);
}
- @Test
- public void testCreateUserFiveParams() throws Exception {
- users.createUser("user", "user", UserType.LOCAL, false, false);
-
- final User createdUser = users.getAnyUser("user");
- Assert.assertEquals("user", createdUser.getUserName());
- Assert.assertEquals(false, createdUser.isActive());
- Assert.assertEquals(false, createdUser.isLdapUser());
- Assert.assertEquals(false, createdUser.isAdmin());
-
- users.createUser("user2", "user2", UserType.LDAP, true, true);
- final User createdUser2 = users.getAnyUser("user2");
- Assert.assertEquals("user2", createdUser2.getUserName());
- Assert.assertEquals(true, createdUser2.isActive());
- Assert.assertEquals(true, createdUser2.isLdapUser());
- Assert.assertEquals(true, createdUser2.isAdmin());
- }
@Test(expected = AmbariException.class)
public void testCreateUserDuplicate() throws Exception {
@@ -461,62 +506,30 @@ public class TestUsers {
users.createUser("user1", "user1");
users.createUser("user2", "user2");
users.createUser("user3", "user3");
- Assert.assertEquals(3, users.getAllUsers().size());
+ Assert.assertEquals(4, users.getAllUsers().size());
users.removeUser(users.getAnyUser("user1"));
Assert.assertNull(users.getAnyUser("user1"));
- Assert.assertEquals(2, users.getAllUsers().size());
- }
-
- @Test
- public void testGrantAdminPrivilege() throws Exception {
- users.createUser("user", "user");
-
- final User user = users.getAnyUser("user");
- users.grantAdminPrivilege(user.getUserId());
-
- Assert.assertTrue(users.getAnyUser("user").isAdmin());
- }
-
- @Test
- public void testRevokeAdminPrivilege() throws Exception {
- users.createUser("admin", "admin", UserType.LOCAL, true, true);
-
- final User admin = users.getAnyUser("admin");
- users.revokeAdminPrivilege(admin.getUserId());
-
- Assert.assertFalse(users.getAnyUser("admin").isAdmin());
- }
-
- @Test
- public void testIsUserCanBeRemoved() throws Exception {
- users.createUser("admin", "admin", UserType.LOCAL, true, true);
- users.createUser("admin2", "admin2", UserType.LOCAL, true, true);
-
- Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin")));
- Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin2")));
-
- users.removeUser(users.getAnyUser("admin"));
-
- Assert.assertFalse(users.isUserCanBeRemoved(userDAO.findUserByName("admin2")));
- users.createUser("user", "user");
- Assert.assertFalse(users.isUserCanBeRemoved(userDAO.findUserByName("admin2")));
-
- users.createUser("admin3", "admin3", UserType.LOCAL, true, true);
- Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin2")));
- Assert.assertTrue(users.isUserCanBeRemoved(userDAO.findUserByName("admin3")));
+ Assert.assertEquals(3, users.getAllUsers().size());
}
@Test
- public void testGetUserIfUnique() throws Exception {
- users.createUser("admin", "admin", UserType.LOCAL, true, false);
-
- Assert.assertNotNull(users.getUserIfUnique("admin"));
+ public void testCreateUserFiveParams() throws Exception {
+ users.createUser("user", "user", UserType.LOCAL, false, false);
- users.createUser("admin", "admin", UserType.LDAP, true, false);
+ final User createdUser = users.getAnyUser("user");
+ Assert.assertEquals("user", createdUser.getUserName());
+ Assert.assertEquals(false, createdUser.isActive());
+ Assert.assertEquals(false, createdUser.isLdapUser());
+ Assert.assertEquals(false, createdUser.isAdmin());
- Assert.assertNull(users.getUserIfUnique("admin"));
+ users.createUser("user2", "user2", UserType.LDAP, true, true);
+ final User createdUser2 = users.getAnyUser("user2");
+ Assert.assertEquals("user2", createdUser2.getUserName());
+ Assert.assertEquals(true, createdUser2.isActive());
+ Assert.assertEquals(true, createdUser2.isLdapUser());
+ Assert.assertEquals(true, createdUser2.isAdmin());
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/1123ba26/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
index 8f4e445..cb63b0f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
@@ -83,6 +83,8 @@ import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import com.google.gson.Gson;
@@ -112,54 +114,42 @@ public class UpgradeActionTest {
private static final String HDP_211_CENTOS6_REPO_URL = "http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos6/2.x/BUILDS/2.1.1.0-118";
- private Injector m_injector;
-
- private AmbariManagementController amc;
-
- @Inject
- private OrmTestHelper m_helper;
-
- @Inject
- private RepositoryVersionDAO repoVersionDAO;
-
- @Inject
- private Clusters clusters;
-
- @Inject
- private ClusterVersionDAO clusterVersionDAO;
-
- @Inject
- private HostVersionDAO hostVersionDAO;
-
- @Inject
- private HostDAO hostDAO;
-
- @Inject
- private HostRoleCommandFactory hostRoleCommandFactory;
-
- @Inject
- private ServiceFactory serviceFactory;
-
- @Inject
- private ServiceComponentFactory serviceComponentFactory;
-
- @Inject
- private ServiceComponentHostFactory serviceComponentHostFactory;
-
- @Inject
- private RequestDAO requestDAO;
-
- @Inject
- private UpgradeDAO upgradeDAO;
-
- @Inject
- private ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO;
-
- @Before
- public void setup() throws Exception {
+ private static Injector m_injector;
+ private static AmbariManagementController amc;
+ private static OrmTestHelper m_helper;
+ private static RepositoryVersionDAO repoVersionDAO;
+ private static Clusters clusters;
+ private static ClusterVersionDAO clusterVersionDAO;
+ private static HostVersionDAO hostVersionDAO;
+ private static HostDAO hostDAO;
+ private static HostRoleCommandFactory hostRoleCommandFactory;
+ private static ServiceFactory serviceFactory;
+ private static ServiceComponentFactory serviceComponentFactory;
+ private static ServiceComponentHostFactory serviceComponentHostFactory;
+ private static RequestDAO requestDAO;
+ private static UpgradeDAO upgradeDAO;
+ private static ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO;
+
+ @BeforeClass
+ public static void classSetUp() throws NoSuchFieldException, IllegalAccessException {
m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
m_injector.getInstance(GuiceJpaInitializer.class);
- m_injector.injectMembers(this);
+
+ amc = m_injector.getInstance(AmbariManagementController.class);
+ m_helper = m_injector.getInstance(OrmTestHelper.class);
+ repoVersionDAO = m_injector.getInstance(RepositoryVersionDAO.class);
+ clusters = m_injector.getInstance(Clusters.class);
+ clusterVersionDAO = m_injector.getInstance(ClusterVersionDAO.class);
+ hostVersionDAO = m_injector.getInstance(HostVersionDAO.class);
+ hostDAO = m_injector.getInstance(HostDAO.class);
+ hostRoleCommandFactory = m_injector.getInstance(HostRoleCommandFactory.class);
+ serviceFactory = m_injector.getInstance(ServiceFactory.class);
+ serviceComponentFactory = m_injector.getInstance(ServiceComponentFactory.class);
+ serviceComponentHostFactory = m_injector.getInstance(ServiceComponentHostFactory.class);
+ requestDAO = m_injector.getInstance(RequestDAO.class);
+ upgradeDAO = m_injector.getInstance(UpgradeDAO.class);
+ serviceComponentDesiredStateDAO = m_injector.getInstance(ServiceComponentDesiredStateDAO.class);
+
m_injector.getInstance(UnitOfWork.class).begin();
// Initialize AmbariManagementController
@@ -172,8 +162,41 @@ public class UpgradeActionTest {
@After
public void teardown() throws Exception {
- m_injector.getInstance(UnitOfWork.class).end();
- m_injector.getInstance(PersistService.class).stop();
+ cleanup();
+ }
+
+ private void cleanup() throws AmbariException {
+ Map<String, Cluster> clusterMap = clusters.getClusters();
+
+ List<ClusterVersionEntity> clusterVersionEntities = clusterVersionDAO.findAll();
+ if (clusterVersionEntities != null) {
+ for (ClusterVersionEntity cve : clusterVersionEntities) {
+ clusterVersionDAO.remove(cve);
+ }
+ }
+
+ List<RepositoryVersionEntity> repositoryVersionEntities = repoVersionDAO.findAll();
+ if (repositoryVersionEntities != null) {
+ for (RepositoryVersionEntity rve : repositoryVersionEntities) {
+ repoVersionDAO.remove(rve);
+ }
+ }
+
+ List<HostVersionEntity> hostVersionEntities = hostVersionDAO.findAll();
+ if (clusterVersionEntities != null) {
+ for (HostVersionEntity hve : hostVersionEntities) {
+ hostVersionDAO.remove(hve);
+ }
+ }
+
+ for (String clusterName : clusterMap.keySet()) {
+ clusters.deleteCluster(clusterName);
+ }
+
+ for (Host host : clusters.getHosts()) {
+ clusters.deleteHost(host.getHostName());
+ }
+
}
private void makeDowngradeCluster(StackId sourceStack, String sourceRepo, StackId targetStack, String targetRepo) throws Exception {
http://git-wip-us.apache.org/repos/asf/ambari/blob/1123ba26/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
index 0383e4c..afcc90e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
@@ -26,12 +26,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.persistence.EntityManager;
-
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.ServiceComponentNotFoundException;
import org.apache.ambari.server.ServiceNotFoundException;
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.ServiceComponentHostResponse;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -49,7 +46,6 @@ import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Config;
import org.apache.ambari.server.state.ConfigFactory;
-import org.apache.ambari.server.state.ConfigHelper;
import org.apache.ambari.server.state.Host;
import org.apache.ambari.server.state.HostConfig;
import org.apache.ambari.server.state.MaintenanceState;
@@ -71,74 +67,103 @@ import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Guice;
-import com.google.inject.Inject;
import com.google.inject.Injector;
-import com.google.inject.Provider;
import com.google.inject.persist.PersistService;
public class ServiceComponentHostTest {
private static Logger LOG = LoggerFactory.getLogger(ServiceComponentHostTest.class);
- @Inject
- private Injector injector;
- @Inject
- private Clusters clusters;
- @Inject
- private ServiceFactory serviceFactory;
- @Inject
- private ServiceComponentFactory serviceComponentFactory;
- @Inject
- private ServiceComponentHostFactory serviceComponentHostFactory;
- @Inject
- private AmbariMetaInfo metaInfo;
- @Inject
- Provider<EntityManager> entityManagerProvider;
- @Inject
- private ConfigFactory configFactory;
- @Inject
- private ConfigGroupFactory configGroupFactory;
- @Inject
- private ConfigHelper configHelper;
- @Inject
- private OrmTestHelper helper;
- @Inject
- private ClusterDAO clusterDAO;
- @Inject
- private HostDAO hostDAO;
+
+ private static Injector injector;
+ private static Clusters clusters;
+ private static ServiceFactory serviceFactory;
+ private static ServiceComponentFactory serviceComponentFactory;
+ private static ServiceComponentHostFactory serviceComponentHostFactory;
+ private static ConfigFactory configFactory;
+ private static ConfigGroupFactory configGroupFactory;
+ private static OrmTestHelper helper;
+ private static ClusterDAO clusterDAO;
+ private static HostDAO hostDAO;
private String clusterName = "c1";
private String hostName1 = "h1";
private Map<String, String> hostAttributes = new HashMap<String, String>();
+ @BeforeClass
+ public static void classSetUp() {
+ injector = Guice.createInjector(new InMemoryDefaultTestModule());
+ injector.getInstance(GuiceJpaInitializer.class);
+ clusters = injector.getInstance(Clusters.class);
+ serviceFactory = injector.getInstance(ServiceFactory.class);
+ serviceComponentFactory = injector.getInstance(ServiceComponentFactory.class);
+ serviceComponentHostFactory = injector.getInstance(ServiceComponentHostFactory.class);
+ configFactory = injector.getInstance(ConfigFactory.class);
+ configGroupFactory = injector.getInstance(ConfigGroupFactory.class);
+ helper = injector.getInstance(OrmTestHelper.class);
+ clusterDAO = injector.getInstance(ClusterDAO.class);
+ hostDAO = injector.getInstance(HostDAO.class);
+ }
@Before
public void setup() throws Exception {
- injector = Guice.createInjector(new InMemoryDefaultTestModule());
- injector.getInstance(GuiceJpaInitializer.class);
- injector.injectMembers(this);
- StackId stackId = new StackId("HDP-0.1");
- createCluster(stackId, clusterName);
- hostAttributes.put("os_family", "redhat");
- hostAttributes.put("os_release_version", "5.9");
- Set<String> hostNames = new HashSet<String>();
- hostNames.add(hostName1);
- addHostsToCluster(clusterName, hostAttributes, hostNames);
+ if (clusters.getClusters().size() == 0) {
+ StackId stackId = new StackId("HDP-0.1");
+ createCluster(stackId, clusterName);
+ hostAttributes.put("os_family", "redhat");
+ hostAttributes.put("os_release_version", "5.9");
- Cluster c1 = clusters.getCluster(clusterName);
- helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
- c1.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
- RepositoryVersionState.INSTALLING);
+ Set<String> hostNames = new HashSet<String>();
+ hostNames.add(hostName1);
+ addHostsToCluster(clusterName, hostAttributes, hostNames);
+
+ Cluster c1 = clusters.getCluster(clusterName);
+ helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
+ c1.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
+ RepositoryVersionState.INSTALLING);
+ }
}
@After
- public void teardown() {
- injector.getInstance(PersistService.class).stop();
+ public void teardown() throws AmbariException {
+ cleanup();
+ }
+
+ private void cleanup() throws AmbariException {
+ try {
+ Map<String, Cluster> clusterMap = clusters.getClusters();
+
+ HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class);
+ List<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities = hostComponentDesiredStateDAO.findAll();
+ if (hostComponentDesiredStateEntities != null) {
+ for (HostComponentDesiredStateEntity hcdse : hostComponentDesiredStateEntities) {
+ hostComponentDesiredStateDAO.remove(hcdse);
+ }
+ }
+
+ HostComponentStateDAO hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class);
+ List<HostComponentStateEntity> hostComponentStateEntities = hostComponentStateDAO.findAll();
+ if (hostComponentStateEntities != null) {
+ for (HostComponentStateEntity hcse : hostComponentStateEntities) {
+ hostComponentStateDAO.remove(hcse);
+ }
+ }
+
+ for (String clusterName : clusterMap.keySet()) {
+ clusters.deleteCluster(clusterName);
+ }
+
+ for (Host host : clusters.getHosts()) {
+ clusters.deleteHost(host.getHostName());
+ }
+ } catch (IllegalStateException ise) {}
}
private ClusterEntity createCluster(StackId stackId, String clusterName) throws AmbariException {
@@ -516,18 +541,19 @@ public class ServiceComponentHostTest {
State.UNINSTALLED);
runStateChanges(impl, ServiceComponentHostEventType.HOST_SVCCOMP_WIPEOUT,
- State.UNINSTALLED,
- State.WIPING_OUT,
- State.WIPING_OUT,
- State.INIT);
+ State.UNINSTALLED,
+ State.WIPING_OUT,
+ State.WIPING_OUT,
+ State.INIT);
}
+ @Ignore
@Test
public void testJobHandling() {
// TODO fix once jobs are handled
}
-
+ @Ignore
@Test
public void testGetAndSetConfigs() {
// FIXME config handling
@@ -552,7 +578,7 @@ public class ServiceComponentHostTest {
Assert.assertEquals("HDP-1.2.0",
sch.getStackVersion().getStackId());
Assert.assertEquals("HDP-1.2.0",
- sch.getDesiredStackVersion().getStackId());
+ sch.getDesiredStackVersion().getStackId());
}
@Test
@@ -657,7 +683,7 @@ public class ServiceComponentHostTest {
Assert.assertEquals(-1, impl.getLastOpLastUpdateTime());
Assert.assertEquals(-1, impl.getLastOpEndTime());
Assert.assertEquals(State.STOPPING,
- impl.getState());
+ impl.getState());
}
@Test
@@ -929,6 +955,9 @@ public class ServiceComponentHostTest {
tags.remove(id.toString());
sch3.updateActualConfigs(actual);
Assert.assertFalse(sch3.convertToResponse(null).isStaleConfig());
+
+ injector.getInstance(PersistService.class).stop();
+ classSetUp();
}
@Test
@@ -1046,6 +1075,9 @@ public class ServiceComponentHostTest {
Assert.assertTrue(sch1.convertToResponse(null).isStaleConfig());
Assert.assertTrue(sch2.convertToResponse(null).isStaleConfig());
Assert.assertFalse(sch3.convertToResponse(null).isStaleConfig());
+
+ injector.getInstance(PersistService.class).stop();
+ classSetUp();
}
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/1123ba26/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
index 08374da..50ba3ef 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
@@ -18,6 +18,24 @@
package org.apache.ambari.server.upgrade;
+import javax.persistence.EntityManager;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -33,8 +51,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.persistence.EntityManager;
-
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
@@ -75,6 +91,7 @@ import org.easymock.EasyMockSupport;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import com.google.inject.AbstractModule;
@@ -83,40 +100,19 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Provider;
-import com.google.inject.persist.PersistService;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertTrue;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.anyString;
-import static org.easymock.EasyMock.capture;
-import static org.easymock.EasyMock.createMockBuilder;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.reset;
-import static org.easymock.EasyMock.verify;
/**
* {@link org.apache.ambari.server.upgrade.UpgradeCatalog210} unit tests.
*/
public class UpgradeCatalog210Test {
- private Injector injector;
+ private static Injector injector;
private Provider<EntityManager> entityManagerProvider = createStrictMock(Provider.class);
private EntityManager entityManager = createNiceMock(EntityManager.class);
- private UpgradeCatalogHelper upgradeCatalogHelper;
- private StackEntity desiredStackEntity;
+ private static UpgradeCatalogHelper upgradeCatalogHelper;
+ private static StackEntity desiredStackEntity;
- @Before
- public void init() {
- reset(entityManagerProvider);
- expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
- replay(entityManagerProvider);
+ @BeforeClass
+ public static void classSetUp() {
injector = Guice.createInjector(new InMemoryDefaultTestModule());
injector.getInstance(GuiceJpaInitializer.class);
@@ -128,9 +124,18 @@ public class UpgradeCatalog210Test {
desiredStackEntity = stackDAO.find("HDP", "2.2.0");
}
+ @Before
+ public void init() {
+ reset(entityManagerProvider);
+ expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
+ replay(entityManagerProvider);
+
+
+ }
+
@After
public void tearDown() {
- injector.getInstance(PersistService.class).stop();
+
}
@Test
[08/27] ambari git commit: AMBARI-18289 : Invalid negative values for
some AMS metrics. (avijayan)
Posted by nc...@apache.org.
AMBARI-18289 : Invalid negative values for some AMS metrics. (avijayan)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9455b52d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9455b52d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9455b52d
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 9455b52dd3126248ccea0d077d5da4512f4e2f21
Parents: aa0528e
Author: Aravindan Vijayan <av...@hortonworks.com>
Authored: Tue Sep 13 20:22:56 2016 -0700
Committer: Aravindan Vijayan <av...@hortonworks.com>
Committed: Wed Sep 14 15:03:34 2016 -0700
----------------------------------------------------------------------
.../conf/unix/metric_monitor.ini | 1 +
.../src/main/python/core/config_reader.py | 3 ++
.../src/main/python/core/host_info.py | 39 ++++++++++++++++----
.../0.1.0/configuration/ams-env.xml | 9 +++++
.../0.1.0/package/scripts/params.py | 1 +
.../package/templates/metric_monitor.ini.j2 | 1 +
6 files changed, 46 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9455b52d/ambari-metrics/ambari-metrics-host-monitoring/conf/unix/metric_monitor.ini
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-host-monitoring/conf/unix/metric_monitor.ini b/ambari-metrics/ambari-metrics-host-monitoring/conf/unix/metric_monitor.ini
index 59ca5d7..e98c65c 100644
--- a/ambari-metrics/ambari-metrics-host-monitoring/conf/unix/metric_monitor.ini
+++ b/ambari-metrics/ambari-metrics-host-monitoring/conf/unix/metric_monitor.ini
@@ -21,6 +21,7 @@ debug_level = INFO
metrics_servers = localhost
enable_time_threshold = false
enable_value_threshold = false
+skip_disk_patterns =
[emitter]
send_interval = 60
http://git-wip-us.apache.org/repos/asf/ambari/blob/9455b52d/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/config_reader.py
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/config_reader.py b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/config_reader.py
index 44692f6..2e8a170 100644
--- a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/config_reader.py
+++ b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/config_reader.py
@@ -245,3 +245,6 @@ class Configuration:
def get_ca_certs(self):
return self._ca_cert_file_path
+
+ def get_disk_metrics_skip_pattern(self):
+ return self.get("default", "skip_disk_patterns")
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/9455b52d/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
index 845b270..f79cacd 100644
--- a/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
+++ b/ambari-metrics/ambari-metrics-host-monitoring/src/main/python/core/host_info.py
@@ -26,6 +26,8 @@ import time
import threading
import socket
import operator
+import re
+from collections import namedtuple
logger = logging.getLogger()
cached_hostname = None
@@ -244,16 +246,37 @@ class HostInfo():
if delta <= 0:
delta = float("inf")
- io_counters = psutil.disk_io_counters()
+ skip_disk_patterns = self.__config.get_disk_metrics_skip_pattern()
+ logger.debug('skip_disk_patterns: %s' % skip_disk_patterns)
+ if not skip_disk_patterns or skip_disk_patterns == 'None':
+ io_counters = psutil.disk_io_counters()
+ else:
+ sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
+ 'read_bytes', 'write_bytes',
+ 'read_time', 'write_time'])
+ skip_disk_pattern_list = skip_disk_patterns.split(',')
+ rawdict = psutil.disk_io_counters(True)
+ if not rawdict:
+ raise RuntimeError("Couldn't find any physical disk")
+ trimmed_dict = {}
+ for disk, fields in rawdict.items():
+ ignore_disk = False
+ for p in skip_disk_pattern_list:
+ if re.match(p, disk):
+ ignore_disk = True
+ if not ignore_disk:
+ trimmed_dict[disk] = sdiskio(*fields)
+ io_counters = sdiskio(*[sum(x) for x in zip(*trimmed_dict.values())])
new_disk_stats = {
- 'read_count' : io_counters.read_count if hasattr(io_counters, 'read_count') else 0,
- 'write_count' : io_counters.write_count if hasattr(io_counters, 'write_count') else 0,
- 'read_bytes' : io_counters.read_bytes if hasattr(io_counters, 'read_bytes') else 0,
- 'write_bytes' : io_counters.write_bytes if hasattr(io_counters, 'write_bytes') else 0,
- 'read_time' : io_counters.read_time if hasattr(io_counters, 'read_time') else 0,
- 'write_time' : io_counters.write_time if hasattr(io_counters, 'write_time') else 0
- }
+ 'read_count' : io_counters.read_count if hasattr(io_counters, 'read_count') else 0,
+ 'write_count' : io_counters.write_count if hasattr(io_counters, 'write_count') else 0,
+ 'read_bytes' : io_counters.read_bytes if hasattr(io_counters, 'read_bytes') else 0,
+ 'write_bytes' : io_counters.write_bytes if hasattr(io_counters, 'write_bytes') else 0,
+ 'read_time' : io_counters.read_time if hasattr(io_counters, 'read_time') else 0,
+ 'write_time' : io_counters.write_time if hasattr(io_counters, 'write_time') else 0
+ }
+
if not self.__last_disk_data:
self.__last_disk_data = new_disk_stats
read_bps = (new_disk_stats['read_bytes'] - self.__last_disk_data['read_bytes']) / delta
http://git-wip-us.apache.org/repos/asf/ambari/blob/9455b52d/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-env.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-env.xml b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-env.xml
index b6ce3a2..a52cb82 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-env.xml
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/configuration/ams-env.xml
@@ -92,6 +92,15 @@
<on-ambari-upgrade add="true"/>
</property>
<property>
+ <name>timeline.metrics.skip.disk.metrics.patterns</name>
+ <value>true</value>
+ <description>
+ Comma separated list of disk patterns to be ignored while collecting aggregate disk usage and counter metrics.
+ For example, volume groups managed by docker can be ignored by using the pattern "dm-[0-9]+"
+ </description>
+ <on-ambari-upgrade add="true"/>
+ </property>
+ <property>
<name>content</name>
<display-name>ams-env template</display-name>
<value>
http://git-wip-us.apache.org/repos/asf/ambari/blob/9455b52d/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
index 3908b27..61b89f8 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/params.py
@@ -192,6 +192,7 @@ metrics_collector_heapsize = default('/configurations/ams-env/metrics_collector_
host_sys_prepped = default("/hostLevelParams/host_sys_prepped", False)
metrics_report_interval = default("/configurations/ams-site/timeline.metrics.sink.report.interval", 60)
metrics_collection_period = default("/configurations/ams-site/timeline.metrics.sink.collection.period", 10)
+skip_disk_metrics_patterns = default("/configurations/ams-env/timeline.metrics.skip.disk.metrics.patterns", None)
hbase_log_dir = config['configurations']['ams-hbase-env']['hbase_log_dir']
hbase_classpath_additional = default("/configurations/ams-hbase-env/hbase_classpath_additional", None)
http://git-wip-us.apache.org/repos/asf/ambari/blob/9455b52d/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metric_monitor.ini.j2
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metric_monitor.ini.j2 b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metric_monitor.ini.j2
index 65129f8..b011fd5 100644
--- a/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metric_monitor.ini.j2
+++ b/ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/templates/metric_monitor.ini.j2
@@ -21,6 +21,7 @@ debug_level = INFO
metrics_servers = {{ams_collector_hosts}}
enable_time_threshold = false
enable_value_threshold = false
+skip_disk_patterns = {{skip_disk_metrics_patterns}}
[emitter]
send_interval = {{metrics_report_interval}}
[22/27] ambari git commit: AMBARI-18386. Handle Ranger hive repo
config jdbc url change for stack 2.5 (mugdha)
Posted by nc...@apache.org.
AMBARI-18386. Handle Ranger hive repo config jdbc url change for stack 2.5 (mugdha)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/bdd261ef
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/bdd261ef
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/bdd261ef
Branch: refs/heads/branch-dev-patch-upgrade
Commit: bdd261ef10eef1a5daa9d89f7b509bf6e23c370c
Parents: da56057
Author: Mugdha Varadkar <mu...@apache.org>
Authored: Thu Sep 15 10:37:06 2016 +0530
Committer: Mugdha Varadkar <mu...@apache.org>
Committed: Fri Sep 16 10:33:32 2016 +0530
----------------------------------------------------------------------
.../resource_management/libraries/functions/constants.py | 3 ++-
.../HIVE/0.12.0.2.0/package/scripts/params_linux.py | 10 +++++++++-
.../stacks/HDP/2.0.6/properties/stack_features.json | 5 +++++
3 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/bdd261ef/ambari-common/src/main/python/resource_management/libraries/functions/constants.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/constants.py b/ambari-common/src/main/python/resource_management/libraries/functions/constants.py
index 169fbff..1396bd8 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/constants.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/constants.py
@@ -99,4 +99,5 @@ class StackFeature:
RANGER_ADMIN_PASSWD_CHANGE = "ranger_admin_password_change"
STORM_METRICS_APACHE_CLASSES = "storm_metrics_apache_classes"
SPARK_JAVA_OPTS_SUPPORT = "spark_java_opts_support"
- ATLAS_HBASE_SETUP="atlas_hbase_setup"
+ ATLAS_HBASE_SETUP = "atlas_hbase_setup"
+ RANGER_HIVE_PLUGIN_JDBC_URL = "ranger_hive_plugin_jdbc_url"
http://git-wip-us.apache.org/repos/asf/ambari/blob/bdd261ef/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
index 56e3ce6..5f78a1f 100644
--- a/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
+++ b/ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/scripts/params_linux.py
@@ -89,6 +89,7 @@ version_for_stack_feature_checks = get_stack_feature_version(config)
upgrade_direction = default("/commandParams/upgrade_direction", None)
stack_supports_ranger_kerberos = check_stack_feature(StackFeature.RANGER_KERBEROS_SUPPORT, version_for_stack_feature_checks)
stack_supports_ranger_audit_db = check_stack_feature(StackFeature.RANGER_AUDIT_DB_SUPPORT, version_for_stack_feature_checks)
+stack_supports_ranger_hive_jdbc_url_change = check_stack_feature(StackFeature.RANGER_HIVE_PLUGIN_JDBC_URL, version_for_stack_feature_checks)
# component ROLE directory (like hive-metastore or hive-server2-hive2)
component_directory = status_params.component_directory
@@ -617,6 +618,9 @@ if has_hive_interactive:
hive_llap_principal = (config['configurations']['hive-interactive-site']['hive.llap.zk.sm.principal']).replace('_HOST',hostname.lower())
pass
+hive_server2_zookeeper_namespace = config['configurations']['hive-site']['hive.server2.zookeeper.namespace']
+hive_zookeeper_quorum = config['configurations']['hive-site']['hive.zookeeper.quorum']
+
# ranger host
ranger_admin_hosts = default("/clusterHostInfo/ranger_admin_hosts", [])
has_ranger_admin = not len(ranger_admin_hosts) == 0
@@ -688,11 +692,15 @@ if has_ranger_admin:
ranger_previous_jdbc_jar = format("{hive_lib}/{ranger_previous_jdbc_jar_name}") if stack_supports_ranger_audit_db else None
sql_connector_jar = ''
+ ranger_hive_url = format("{hive_url}/default;principal={hive_principal}") if security_enabled else hive_url
+ if stack_supports_ranger_hive_jdbc_url_change:
+ ranger_hive_url = format("jdbc:hive2://{hive_zookeeper_quorum}/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace={hive_server2_zookeeper_namespace}")
+
hive_ranger_plugin_config = {
'username': repo_config_username,
'password': repo_config_password,
'jdbc.driverClassName': jdbc_driver_class_name,
- 'jdbc.url': format("{hive_url}/default;principal={hive_principal}") if security_enabled else hive_url,
+ 'jdbc.url': ranger_hive_url,
'commonNameForCertificate': common_name_for_certificate
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/bdd261ef/ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_features.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_features.json b/ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_features.json
index 8c838db..dbde58b 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_features.json
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/properties/stack_features.json
@@ -303,6 +303,11 @@
"name": "atlas_hbase_setup",
"description": "Use script to create Atlas tables in Hbase and set permissions for Atlas user.",
"min_version": "2.5.0.0"
+ },
+ {
+ "name": "ranger_hive_plugin_jdbc_url",
+ "description": "Handle Ranger hive repo config jdbc url change for stack 2.5 (AMBARI-18386)",
+ "min_version": "2.5.0.0"
}
]
}
[07/27] ambari git commit: AMBARI-18154 : Ambari Dashboard,
Cluster load widget - Incorrect value in Nodes._avg metric. (avijayan)
Posted by nc...@apache.org.
AMBARI-18154 : Ambari Dashboard, Cluster load widget - Incorrect value in Nodes._avg metric. (avijayan)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/aa0528ec
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/aa0528ec
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/aa0528ec
Branch: refs/heads/branch-dev-patch-upgrade
Commit: aa0528ecab47850f44dd5575ab7861083e67c6ea
Parents: 4a09934
Author: Aravindan Vijayan <av...@hortonworks.com>
Authored: Tue Sep 13 20:17:40 2016 -0700
Committer: Aravindan Vijayan <av...@hortonworks.com>
Committed: Wed Sep 14 15:03:34 2016 -0700
----------------------------------------------------------------------
.../TimelineMetricClusterAggregatorSecond.java | 34 ++++++++++++++++++--
...melineMetricClusterAggregatorSecondTest.java | 6 ++--
.../src/main/resources/ganglia_properties.json | 2 +-
3 files changed, 36 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/aa0528ec/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
index 6731eb3..5f40d21 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecond.java
@@ -34,11 +34,15 @@ import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.TimelineMetricConfiguration.HOST_APP_ID;
import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.TimelineMetricConfiguration.SERVER_SIDE_TIMESIFT_ADJUSTMENT;
import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.TimelineMetricConfiguration.TIMELINE_METRICS_CLUSTER_AGGREGATOR_INTERPOLATION_ENABLED;
import static org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.query.PhoenixTransactSQL.GET_METRIC_SQL;
@@ -130,6 +134,7 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
throws SQLException, IOException {
Map<TimelineClusterMetric, MetricClusterAggregate> aggregateClusterMetrics =
new HashMap<TimelineClusterMetric, MetricClusterAggregate>();
+ int numLiveHosts = 0;
TimelineMetric metric = null;
if (rs.next()) {
@@ -145,18 +150,25 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
metric.addMetricValues(nextMetric.getMetricValues());
} else {
// Process the current metric
- processAggregateClusterMetrics(aggregateClusterMetrics, metric, timeSlices);
+ int numHosts = processAggregateClusterMetrics(aggregateClusterMetrics, metric, timeSlices);
+ numLiveHosts = Math.max(numHosts, numLiveHosts);
metric = nextMetric;
}
}
}
// Process last metric
if (metric != null) {
- processAggregateClusterMetrics(aggregateClusterMetrics, metric, timeSlices);
+ int numHosts = processAggregateClusterMetrics(aggregateClusterMetrics, metric, timeSlices);
+ numLiveHosts = Math.max(numHosts, numLiveHosts);
}
// Add app level aggregates to save
aggregateClusterMetrics.putAll(appAggregator.getAggregateClusterMetrics());
+
+ // Add liveHosts metric.
+ long timestamp = timeSlices.get(timeSlices.size() - 1)[1];
+ processLiveHostsMetric(aggregateClusterMetrics, numLiveHosts, timestamp);
+
return aggregateClusterMetrics;
}
@@ -165,10 +177,11 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
* timeline.metrics.cluster.aggregator.minute.timeslice.interval
* Normalize value by averaging them within the interval
*/
- protected void processAggregateClusterMetrics(Map<TimelineClusterMetric, MetricClusterAggregate> aggregateClusterMetrics,
+ protected int processAggregateClusterMetrics(Map<TimelineClusterMetric, MetricClusterAggregate> aggregateClusterMetrics,
TimelineMetric metric, List<Long[]> timeSlices) {
// Create time slices
Map<TimelineClusterMetric, Double> clusterMetrics = sliceFromTimelineMetric(metric, timeSlices);
+ int numHosts = 0;
if (clusterMetrics != null && !clusterMetrics.isEmpty()) {
for (Map.Entry<TimelineClusterMetric, Double> clusterMetricEntry :
@@ -188,10 +201,13 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
aggregate.updateMax(avgValue);
aggregate.updateMin(avgValue);
}
+
+ numHosts = aggregate.getNumberOfHosts();
// Update app level aggregates
appAggregator.processTimelineClusterMetric(clusterMetric, metric.getHostName(), avgValue);
}
}
+ return numHosts;
}
protected Map<TimelineClusterMetric, Double> sliceFromTimelineMetric(
@@ -374,4 +390,16 @@ public class TimelineMetricClusterAggregatorSecond extends AbstractTimelineAggre
return -1l;
}
+ private void processLiveHostsMetric(Map<TimelineClusterMetric, MetricClusterAggregate> aggregateClusterMetrics,
+ int numLiveHosts, long timestamp) {
+
+ TimelineClusterMetric timelineClusterMetric = new TimelineClusterMetric(
+ "live_hosts", HOST_APP_ID, null, timestamp, null);
+
+ MetricClusterAggregate metricClusterAggregate = new MetricClusterAggregate((double) numLiveHosts,
+ 1, null, (double) numLiveHosts, (double) numLiveHosts);
+
+ aggregateClusterMetrics.put(timelineClusterMetric, metricClusterAggregate);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/aa0528ec/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecondTest.java
----------------------------------------------------------------------
diff --git a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecondTest.java b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecondTest.java
index 0f93bab..014772f 100644
--- a/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecondTest.java
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/aggregators/TimelineMetricClusterAggregatorSecondTest.java
@@ -259,8 +259,9 @@ public class TimelineMetricClusterAggregatorSecondTest {
aggregateClusterMetrics.clear();
timelineMetric.setType("COUNTER");
- secondAggregator.processAggregateClusterMetrics(aggregateClusterMetrics, timelineMetric, timeslices);
+ int liveHosts = secondAggregator.processAggregateClusterMetrics(aggregateClusterMetrics, timelineMetric, timeslices);
+ Assert.assertEquals(liveHosts, 1);
Assert.assertEquals(aggregateClusterMetrics.size(), 4);
timelineClusterMetric.setTimestamp(startTime + 30*seconds);
Assert.assertTrue(aggregateClusterMetrics.containsKey(timelineClusterMetric));
@@ -294,8 +295,9 @@ public class TimelineMetricClusterAggregatorSecondTest {
aggregateClusterMetrics.clear();
timelineMetric.setType("COUNTER");
- secondAggregator.processAggregateClusterMetrics(aggregateClusterMetrics, timelineMetric, timeslices);
+ liveHosts = secondAggregator.processAggregateClusterMetrics(aggregateClusterMetrics, timelineMetric, timeslices);
+ Assert.assertEquals(liveHosts, 1);
Assert.assertEquals(aggregateClusterMetrics.size(), 4);
timelineClusterMetric.setTimestamp(startTime + 60*seconds);
Assert.assertTrue(aggregateClusterMetrics.containsKey(timelineClusterMetric));
http://git-wip-us.apache.org/repos/asf/ambari/blob/aa0528ec/ambari-server/src/main/resources/ganglia_properties.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/ganglia_properties.json b/ambari-server/src/main/resources/ganglia_properties.json
index 5632bc0..bd2a547 100644
--- a/ambari-server/src/main/resources/ganglia_properties.json
+++ b/ambari-server/src/main/resources/ganglia_properties.json
@@ -47,7 +47,7 @@
"metric":"load_report.Nodes",
"pointInTime":false,
"temporal":true,
- "amsId":"cpu_num"
+ "amsId":"live_hosts"
},
"metrics/load/Procs":{
"metric":"load_report.Procs",
[23/27] ambari git commit: AMBARI-14883. Express Upgrade - All
Service Checks Failure - Queue State (aonishuk)
Posted by nc...@apache.org.
AMBARI-14883. Express Upgrade - All Service Checks Failure - Queue State (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9f9e89af
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9f9e89af
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9f9e89af
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 9f9e89afb2fd927500718321dc658fb7e0292bad
Parents: bdd261e
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Fri Sep 16 11:35:39 2016 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Fri Sep 16 11:35:39 2016 +0300
----------------------------------------------------------------------
.../stacks/HDP/2.1/upgrades/nonrolling-upgrade-2.3.xml | 10 ++++++++++
.../stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.2.xml | 11 +++++++++++
.../stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.3.xml | 11 +++++++++++
.../stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.4.xml | 11 +++++++++++
.../stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.3.xml | 11 +++++++++++
.../stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.4.xml | 13 +++++++++++++
.../stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml | 11 +++++++++++
.../stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.4.xml | 11 +++++++++++
.../stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml | 11 +++++++++++
.../stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.5.xml | 11 +++++++++++
10 files changed, 111 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9f9e89af/ambari-server/src/main/resources/stacks/HDP/2.1/upgrades/nonrolling-upgrade-2.3.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.1/upgrades/nonrolling-upgrade-2.3.xml b/ambari-server/src/main/resources/stacks/HDP/2.1/upgrades/nonrolling-upgrade-2.3.xml
index 8cba53f..e3bb29d 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.1/upgrades/nonrolling-upgrade-2.3.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.1/upgrades/nonrolling-upgrade-2.3.xml
@@ -628,6 +628,16 @@
</execute-stage>
</group>
+ <group xsi:type="cluster" name="MANUAL_STEPS" title="Finishing Upgrade">
+ <direction>UPGRADE</direction>
+
+ <execute-stage service="YARN" component="RESOURCEMANAGER" title="Start YARN Queues">
+ <task xsi:type="manual">
+ <message>Please start previously stopped YARN queues. If yarn-site's yarn.resourcemanager.work-preserving-recovery.enabled is set to true, then you can skip this step since the clients will retry on their own.</message>
+ </task>
+ </execute-stage>
+ </group>
+
<group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
<skippable>true</skippable>
<supports-auto-skip-failure>false</supports-auto-skip-failure>
http://git-wip-us.apache.org/repos/asf/ambari/blob/9f9e89af/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.2.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.2.xml b/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.2.xml
index 5aee3a8..d282888 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.2.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.2.xml
@@ -554,6 +554,16 @@
</execute-stage>
</group>
+ <group xsi:type="cluster" name="MANUAL_STEPS" title="Finishing Upgrade">
+ <direction>UPGRADE</direction>
+
+ <execute-stage service="YARN" component="RESOURCEMANAGER" title="Start YARN Queues">
+ <task xsi:type="manual">
+ <message>Please start previously stopped YARN queues. If yarn-site's yarn.resourcemanager.work-preserving-recovery.enabled is set to true, then you can skip this step since the clients will retry on their own.</message>
+ </task>
+ </execute-stage>
+ </group>
+
<group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
<skippable>true</skippable>
<supports-auto-skip-failure>false</supports-auto-skip-failure>
@@ -576,6 +586,7 @@
<task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
</task>
</execute-stage>
+
</group>
</order>
http://git-wip-us.apache.org/repos/asf/ambari/blob/9f9e89af/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.3.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.3.xml b/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.3.xml
index 66ef30e..391524a 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.3.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.3.xml
@@ -856,6 +856,16 @@
</execute-stage>
</group>
+ <group xsi:type="cluster" name="MANUAL_STEPS" title="Finishing Upgrade">
+ <direction>UPGRADE</direction>
+
+ <execute-stage service="YARN" component="RESOURCEMANAGER" title="Start YARN Queues">
+ <task xsi:type="manual">
+ <message>Please start previously stopped YARN queues. If yarn-site's yarn.resourcemanager.work-preserving-recovery.enabled is set to true, then you can skip this step since the clients will retry on their own.</message>
+ </task>
+ </execute-stage>
+ </group>
+
<group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
<skippable>true</skippable>
<supports-auto-skip-failure>false</supports-auto-skip-failure>
@@ -878,6 +888,7 @@
<task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
</task>
</execute-stage>
+
</group>
</order>
http://git-wip-us.apache.org/repos/asf/ambari/blob/9f9e89af/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.4.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.4.xml b/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.4.xml
index 2d921a2..27a41f4 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.4.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.2/upgrades/nonrolling-upgrade-2.4.xml
@@ -895,6 +895,16 @@
</execute-stage>
</group>
+ <group xsi:type="cluster" name="MANUAL_STEPS" title="Finishing Upgrade">
+ <direction>UPGRADE</direction>
+
+ <execute-stage service="YARN" component="RESOURCEMANAGER" title="Start YARN Queues">
+ <task xsi:type="manual">
+ <message>Please start previously stopped YARN queues. If yarn-site's yarn.resourcemanager.work-preserving-recovery.enabled is set to true, then you can skip this step since the clients will retry on their own.</message>
+ </task>
+ </execute-stage>
+ </group>
+
<group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
<skippable>true</skippable>
<supports-auto-skip-failure>false</supports-auto-skip-failure>
@@ -917,6 +927,7 @@
<task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
</task>
</execute-stage>
+
</group>
</order>
http://git-wip-us.apache.org/repos/asf/ambari/blob/9f9e89af/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.3.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.3.xml b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.3.xml
index e3957d6..d3b2696 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.3.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.3.xml
@@ -629,6 +629,16 @@
</execute-stage>
</group>
+ <group xsi:type="cluster" name="MANUAL_STEPS" title="Finishing Upgrade">
+ <direction>UPGRADE</direction>
+
+ <execute-stage service="YARN" component="RESOURCEMANAGER" title="Start YARN Queues">
+ <task xsi:type="manual">
+ <message>Please start previously stopped YARN queues. If yarn-site's yarn.resourcemanager.work-preserving-recovery.enabled is set to true, then you can skip this step since the clients will retry on their own.</message>
+ </task>
+ </execute-stage>
+ </group>
+
<group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
<skippable>true</skippable>
<supports-auto-skip-failure>false</supports-auto-skip-failure>
@@ -651,6 +661,7 @@
<task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
</task>
</execute-stage>
+
</group>
</order>
http://git-wip-us.apache.org/repos/asf/ambari/blob/9f9e89af/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.4.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.4.xml b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.4.xml
index 8603e24..38c8796 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.4.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.4.xml
@@ -679,6 +679,16 @@
</execute-stage>
</group>
+ <group xsi:type="cluster" name="MANUAL_STEPS" title="Finishing Upgrade">
+ <direction>UPGRADE</direction>
+
+ <execute-stage service="YARN" component="RESOURCEMANAGER" title="Start YARN Queues">
+ <task xsi:type="manual">
+ <message>Please start previously stopped YARN queues. If yarn-site's yarn.resourcemanager.work-preserving-recovery.enabled is set to true, then you can skip this step since the clients will retry on their own.</message>
+ </task>
+ </execute-stage>
+ </group>
+
<group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
<skippable>true</skippable>
<supports-auto-skip-failure>false</supports-auto-skip-failure>
@@ -701,7 +711,10 @@
<task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
</task>
</execute-stage>
+
</group>
+
+
</order>
<processing>
http://git-wip-us.apache.org/repos/asf/ambari/blob/9f9e89af/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml
index d6fa4f3..c8b1e8c 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml
@@ -812,6 +812,16 @@
</execute-stage>
</group>
+ <group xsi:type="cluster" name="MANUAL_STEPS" title="Finishing Upgrade">
+ <direction>UPGRADE</direction>
+
+ <execute-stage service="YARN" component="RESOURCEMANAGER" title="Start YARN Queues">
+ <task xsi:type="manual">
+ <message>Please start previously stopped YARN queues. If yarn-site's yarn.resourcemanager.work-preserving-recovery.enabled is set to true, then you can skip this step since the clients will retry on their own.</message>
+ </task>
+ </execute-stage>
+ </group>
+
<group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
<skippable>true</skippable>
<supports-auto-skip-failure>false</supports-auto-skip-failure>
@@ -834,6 +844,7 @@
<task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
</task>
</execute-stage>
+
</group>
</order>
http://git-wip-us.apache.org/repos/asf/ambari/blob/9f9e89af/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.4.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.4.xml b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.4.xml
index 9622031..b5c5c03 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.4.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.4.xml
@@ -622,6 +622,16 @@
</execute-stage>
</group>
+ <group xsi:type="cluster" name="MANUAL_STEPS" title="Finishing Upgrade">
+ <direction>UPGRADE</direction>
+
+ <execute-stage service="YARN" component="RESOURCEMANAGER" title="Start YARN Queues">
+ <task xsi:type="manual">
+ <message>Please start previously stopped YARN queues. If yarn-site's yarn.resourcemanager.work-preserving-recovery.enabled is set to true, then you can skip this step since the clients will retry on their own.</message>
+ </task>
+ </execute-stage>
+ </group>
+
<group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
<skippable>true</skippable>
<supports-auto-skip-failure>false</supports-auto-skip-failure>
@@ -644,6 +654,7 @@
<task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
</task>
</execute-stage>
+
</group>
</order>
http://git-wip-us.apache.org/repos/asf/ambari/blob/9f9e89af/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml
index 0229719..0a14581 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml
@@ -763,6 +763,16 @@
</execute-stage>
</group>
+ <group xsi:type="cluster" name="MANUAL_STEPS" title="Finishing Upgrade">
+ <direction>UPGRADE</direction>
+
+ <execute-stage service="YARN" component="RESOURCEMANAGER" title="Start YARN Queues">
+ <task xsi:type="manual">
+ <message>Please start previously stopped YARN queues. If yarn-site's yarn.resourcemanager.work-preserving-recovery.enabled is set to true, then you can skip this step since the clients will retry on their own.</message>
+ </task>
+ </execute-stage>
+ </group>
+
<group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
<skippable>true</skippable>
<supports-auto-skip-failure>false</supports-auto-skip-failure>
@@ -785,6 +795,7 @@
<task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
</task>
</execute-stage>
+
</group>
</order>
http://git-wip-us.apache.org/repos/asf/ambari/blob/9f9e89af/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.5.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.5.xml b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.5.xml
index 69405c5..1df16a2 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.5.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.5.xml
@@ -686,6 +686,16 @@
</execute-stage>
</group>
+ <group xsi:type="cluster" name="MANUAL_STEPS" title="Finishing Upgrade">
+ <direction>UPGRADE</direction>
+
+ <execute-stage service="YARN" component="RESOURCEMANAGER" title="Start YARN Queues">
+ <task xsi:type="manual">
+ <message>Please start previously stopped YARN queues. If yarn-site's yarn.resourcemanager.work-preserving-recovery.enabled is set to true, then you can skip this step since the clients will retry on their own.</message>
+ </task>
+ </execute-stage>
+ </group>
+
<group xsi:type="cluster" name="POST_CLUSTER" title="Finalize {{direction.text.proper}}">
<skippable>true</skippable>
<supports-auto-skip-failure>false</supports-auto-skip-failure>
@@ -708,6 +718,7 @@
<task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction">
</task>
</execute-stage>
+
</group>
</order>
[18/27] ambari git commit: AMBARI-18367. Create authentication filter
to encapsulate the various Ambari authentication methods (rlevas)
Posted by nc...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilterTest.java
new file mode 100644
index 0000000..f042a70
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authentication/AmbariJWTAuthenticationFilterTest.java
@@ -0,0 +1,190 @@
+/*
+ * 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.
+ */
+
+package org.apache.ambari.server.security.authentication;
+
+import com.nimbusds.jose.JOSEException;
+import com.nimbusds.jose.JWSAlgorithm;
+import com.nimbusds.jose.JWSHeader;
+import com.nimbusds.jose.crypto.RSASSASigner;
+import com.nimbusds.jwt.JWTClaimsSet;
+import com.nimbusds.jwt.SignedJWT;
+import org.apache.ambari.server.audit.AuditLogger;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.security.AmbariEntryPoint;
+import org.apache.ambari.server.security.authorization.PermissionHelper;
+import org.apache.ambari.server.security.authorization.User;
+import org.apache.ambari.server.security.authorization.UserType;
+import org.apache.ambari.server.security.authorization.Users;
+import org.apache.ambari.server.security.authorization.jwt.JwtAuthenticationProperties;
+import org.easymock.EasyMockSupport;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.servlet.FilterChain;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.interfaces.RSAPrivateKey;
+import java.security.interfaces.RSAPublicKey;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+
+public class AmbariJWTAuthenticationFilterTest extends EasyMockSupport {
+ private static RSAPublicKey publicKey;
+ private static RSAPrivateKey privateKey;
+
+ @BeforeClass
+ public static void generateKeyPair() throws NoSuchAlgorithmException {
+ KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
+ keyPairGenerator.initialize(512);
+ KeyPair keyPair = keyPairGenerator.generateKeyPair();
+ publicKey = (RSAPublicKey) keyPair.getPublic();
+ privateKey = (RSAPrivateKey) keyPair.getPrivate();
+ }
+
+ @Test
+ public void testDoFilterSuccess() throws Exception {
+ SignedJWT token = getSignedToken("foobar");
+
+ AmbariEntryPoint entryPoint = createMock(AmbariEntryPoint.class);
+
+ JwtAuthenticationProperties properties = createMock(JwtAuthenticationProperties.class);
+ expect(properties.getAuthenticationProviderUrl()).andReturn("some url").once();
+ expect(properties.getPublicKey()).andReturn(publicKey).once();
+ expect(properties.getAudiences()).andReturn(Collections.singletonList("foobar")).once();
+ expect(properties.getCookieName()).andReturn("chocolate chip").once();
+ expect(properties.getOriginalUrlQueryParam()).andReturn("question").once();
+
+ Configuration configuration = createMock(Configuration.class);
+ expect(configuration.getJwtProperties()).andReturn(properties).once();
+
+ User user = createMock(User.class);
+ expect(user.getUserName()).andReturn("test-user").once();
+ expect(user.getUserType()).andReturn(UserType.JWT).once();
+
+ Users users = createMock(Users.class);
+ expect(users.getUser("test-user", UserType.JWT)).andReturn(user).once();
+ expect(users.getUserAuthorities("test-user", UserType.JWT)).andReturn(null).once();
+
+ AuditLogger auditLogger = createMock(AuditLogger.class);
+ expect(auditLogger.isEnabled()).andReturn(false).times(2);
+
+ PermissionHelper permissionHelper = createMock(PermissionHelper.class);
+
+ Cookie cookie = createMock(Cookie.class);
+ expect(cookie.getName()).andReturn("chocolate chip").once();
+ expect(cookie.getValue()).andReturn(token.serialize()).once();
+
+
+ HttpServletRequest servletRequest = createMock(HttpServletRequest.class);
+ expect(servletRequest.getCookies()).andReturn(new Cookie[]{cookie}).once();
+
+ HttpServletResponse servletResponse = createMock(HttpServletResponse.class);
+
+ FilterChain filterChain = createMock(FilterChain.class);
+ filterChain.doFilter(servletRequest, servletResponse);
+ expectLastCall().once();
+
+ replayAll();
+
+ AmbariJWTAuthenticationFilter filter = new AmbariJWTAuthenticationFilter(entryPoint, configuration, users, auditLogger, permissionHelper);
+ filter.doFilter(servletRequest, servletResponse, filterChain);
+
+ verifyAll();
+ }
+
+ @Test
+ public void testDoFilterFailure() throws Exception {
+ AmbariEntryPoint entryPoint = createMock(AmbariEntryPoint.class);
+
+ JwtAuthenticationProperties properties = createMock(JwtAuthenticationProperties.class);
+ expect(properties.getAuthenticationProviderUrl()).andReturn("some url").once();
+ expect(properties.getPublicKey()).andReturn(publicKey).once();
+ expect(properties.getAudiences()).andReturn(Collections.singletonList("foobar")).once();
+ expect(properties.getCookieName()).andReturn("chocolate chip").once();
+ expect(properties.getOriginalUrlQueryParam()).andReturn("question").once();
+
+ Configuration configuration = createMock(Configuration.class);
+ expect(configuration.getJwtProperties()).andReturn(properties).once();
+
+ Users users = createMock(Users.class);
+
+ AuditLogger auditLogger = createMock(AuditLogger.class);
+ expect(auditLogger.isEnabled()).andReturn(false).times(2);
+
+ PermissionHelper permissionHelper = createMock(PermissionHelper.class);
+
+ Cookie cookie = createMock(Cookie.class);
+ expect(cookie.getName()).andReturn("chocolate chip").once();
+ expect(cookie.getValue()).andReturn("invalid token").once();
+
+
+ HttpServletRequest servletRequest = createMock(HttpServletRequest.class);
+ expect(servletRequest.getCookies()).andReturn(new Cookie[]{cookie}).once();
+
+ HttpServletResponse servletResponse = createMock(HttpServletResponse.class);
+
+ FilterChain filterChain = createMock(FilterChain.class);
+ filterChain.doFilter(servletRequest, servletResponse);
+ expectLastCall().once();
+
+ replayAll();
+
+ AmbariJWTAuthenticationFilter filter = new AmbariJWTAuthenticationFilter(entryPoint, configuration, users, auditLogger, permissionHelper);
+ filter.doFilter(servletRequest, servletResponse, filterChain);
+
+ verifyAll();
+ }
+
+
+ private SignedJWT getSignedToken(String audience) throws JOSEException {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ calendar.add(Calendar.DATE, 1); //add one day
+ return getSignedToken(calendar.getTime(), audience);
+ }
+
+ private SignedJWT getSignedToken(Date expirationTime, String audience) throws JOSEException {
+ RSASSASigner signer = new RSASSASigner(privateKey);
+
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(System.currentTimeMillis());
+ JWTClaimsSet claimsSet = new JWTClaimsSet();
+ claimsSet.setSubject("test-user");
+ claimsSet.setIssuer("unit-test");
+ claimsSet.setIssueTime(calendar.getTime());
+
+ claimsSet.setExpirationTime(expirationTime);
+
+ claimsSet.setAudience(audience);
+
+ SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claimsSet);
+ signedJWT.sign(signer);
+
+ return signedJWT;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java
index 1d71fe6..10de0a9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java
@@ -30,6 +30,7 @@ import org.apache.ambari.server.audit.AuditLogger;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.orm.DBAccessor;
import org.apache.ambari.server.orm.dao.UserDAO;
+import org.apache.ambari.server.security.AmbariEntryPoint;
import org.apache.ambari.server.security.TestAuthenticationFactory;
import org.apache.ambari.server.state.stack.OsFamily;
import org.apache.ambari.server.view.ViewRegistry;
@@ -324,7 +325,8 @@ public class AmbariAuthorizationFilterTest {
}
});
- AmbariAuthorizationFilter filter = new AmbariAuthorizationFilter();
+ AmbariAuthorizationFilter filter = new AmbariAuthorizationFilter(createNiceMock(AmbariEntryPoint.class), injector.getInstance(Configuration.class),
+ injector.getInstance(Users.class), injector.getInstance(AuditLogger.class), injector.getInstance(PermissionHelper.class));
injector.injectMembers(filter);
filter.doFilter(request, response, chain);
@@ -338,14 +340,28 @@ public class AmbariAuthorizationFilterTest {
* @param authentication the authentication to use
* @param urlTests map of triples: url - http method - is allowed
* @param expectRedirect true if the requests should redirect to login
- * @throws Exception
+ * @throws Exception if an exception occurs
*/
private void performGeneralDoFilterTest(Authentication authentication, Table<String, String, Boolean> urlTests, boolean expectRedirect) throws Exception {
final SecurityContext securityContext = createNiceMock(SecurityContext.class);
final FilterConfig filterConfig = createNiceMock(FilterConfig.class);
+
+ final Configuration configuration = EasyMock.createMock(Configuration.class);
+ expect(configuration.getDefaultApiAuthenticatedUser()).andReturn(null).anyTimes();
+
+ final AuditLogger auditLogger = EasyMock.createNiceMock(AuditLogger.class);
+ expect(auditLogger.isEnabled()).andReturn(false).anyTimes();
+
final AmbariAuthorizationFilter filter = createMockBuilder(AmbariAuthorizationFilter.class)
- .addMockedMethod("getSecurityContext").addMockedMethod("getViewRegistry").withConstructor().createMock();
- injectMembers(filter);
+ .addMockedMethod("getSecurityContext")
+ .addMockedMethod("getViewRegistry")
+ .withConstructor(createNiceMock(AmbariEntryPoint.class),
+ configuration,
+ createNiceMock(Users.class),
+ auditLogger,
+ createNiceMock(PermissionHelper.class))
+ .createMock();
+
final ViewRegistry viewRegistry = createNiceMock(ViewRegistry.class);
expect(filterConfig.getInitParameter("realm")).andReturn("AuthFilter").anyTimes();
@@ -355,7 +371,7 @@ public class AmbariAuthorizationFilterTest {
expect(securityContext.getAuthentication()).andReturn(authentication).anyTimes();
expect(viewRegistry.checkPermission(EasyMock.eq("DeniedView"), EasyMock.<String>anyObject(), EasyMock.<String>anyObject(), EasyMock.anyBoolean())).andReturn(false).anyTimes();
- replay(filterConfig, filter, securityContext, viewRegistry);
+ replay(filterConfig, filter, securityContext, viewRegistry, configuration, auditLogger);
for (final Cell<String, String, Boolean> urlTest: urlTests.cellSet()) {
final FilterChain chain = EasyMock.createStrictMock(FilterChain.class);
@@ -399,26 +415,4 @@ public class AmbariAuthorizationFilterTest {
}
}
}
-
- private void injectMembers(AmbariAuthorizationFilter filter) {
- final Configuration configuration = EasyMock.createMock(Configuration.class);
- expect(configuration.getDefaultApiAuthenticatedUser()).andReturn(null).anyTimes();
- final AuditLogger auditLogger = EasyMock.createNiceMock(AuditLogger.class);
- expect(auditLogger.isEnabled()).andReturn(false).anyTimes();
- Injector injector = Guice.createInjector(new AbstractModule() {
- @Override
- protected void configure() {
- bind(Configuration.class).toInstance(configuration);
- bind(Users.class).toInstance(EasyMock.createMock(Users.class));
- bind(EntityManager.class).toInstance(EasyMock.createMock(EntityManager.class));
- bind(UserDAO.class).toInstance(EasyMock.createMock(UserDAO.class));
- bind(DBAccessor.class).toInstance(EasyMock.createMock(DBAccessor.class));
- bind(PasswordEncoder.class).toInstance(EasyMock.createMock(PasswordEncoder.class));
- bind(OsFamily.class).toInstance(EasyMock.createMock(OsFamily.class));
- bind(AuditLogger.class).toInstance(auditLogger);
- }
- });
- injector.injectMembers(filter);
- replay(configuration, auditLogger);
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/d5cca62c/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/jwt/JwtAuthenticationFilterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/jwt/JwtAuthenticationFilterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/jwt/JwtAuthenticationFilterTest.java
index b08d1ac..5814203 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/jwt/JwtAuthenticationFilterTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/jwt/JwtAuthenticationFilterTest.java
@@ -24,13 +24,12 @@ import com.nimbusds.jose.JWSHeader;
import com.nimbusds.jose.crypto.RSASSASigner;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;
+import junit.framework.Assert;
import org.apache.ambari.server.security.authorization.AmbariGrantedAuthority;
import org.apache.ambari.server.security.authorization.AuthorizationHelper;
import org.apache.ambari.server.security.authorization.User;
import org.apache.ambari.server.security.authorization.UserType;
import org.apache.ambari.server.security.authorization.Users;
-import org.easymock.EasyMock;
-import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -46,10 +45,8 @@ import javax.servlet.http.HttpServletResponse;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
-import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
@@ -57,6 +54,7 @@ import java.util.List;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
@@ -299,4 +297,75 @@ public class JwtAuthenticationFilterTest {
assertEquals(false, isValid);
}
+
+ @Test
+ public void testShouldApplyTrue() throws JOSEException {
+ JwtAuthenticationProperties properties = createTestProperties();
+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter(properties, null, null);
+
+ SignedJWT token = getInvalidToken();
+
+ Cookie cookie = createMock(Cookie.class);
+ expect(cookie.getName()).andReturn("non-default").atLeastOnce();
+ expect(cookie.getValue()).andReturn(token.serialize()).atLeastOnce();
+
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ expect(request.getCookies()).andReturn(new Cookie[]{cookie});
+
+ replay(request, cookie);
+
+ Assert.assertTrue(filter.shouldApply(request));
+
+ verify(request, cookie);
+ }
+
+ @Test
+ public void testShouldApplyTrueBadToken() throws JOSEException {
+ JwtAuthenticationProperties properties = createTestProperties();
+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter(properties, null, null);
+
+ Cookie cookie = createMock(Cookie.class);
+ expect(cookie.getName()).andReturn("non-default").atLeastOnce();
+ expect(cookie.getValue()).andReturn("bad token").atLeastOnce();
+
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ expect(request.getCookies()).andReturn(new Cookie[]{cookie});
+
+ replay(request, cookie);
+
+ Assert.assertTrue(filter.shouldApply(request));
+
+ verify(request, cookie);
+ }
+
+ @Test
+ public void testShouldApplyFalseMissingCookie() throws JOSEException {
+ JwtAuthenticationProperties properties = createTestProperties();
+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter(properties, null, null);
+
+ Cookie cookie = createMock(Cookie.class);
+ expect(cookie.getName()).andReturn("some-other-cookie").atLeastOnce();
+
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+ expect(request.getCookies()).andReturn(new Cookie[]{cookie});
+
+ replay(request, cookie);
+
+ Assert.assertFalse(filter.shouldApply(request));
+
+ verify(request, cookie);
+ }
+
+ @Test
+ public void testShouldApplyFalseNotEnabled() throws JOSEException {
+ JwtAuthenticationFilter filter = new JwtAuthenticationFilter((JwtAuthenticationProperties) null, null, null);
+
+ HttpServletRequest request = createMock(HttpServletRequest.class);
+
+ replay(request);
+
+ Assert.assertFalse(filter.shouldApply(request));
+
+ verify(request);
+ }
}
\ No newline at end of file
[25/27] ambari git commit: AMBARI-18226. Remove Redundant Embedded
Postgres SQL (aonishuk)
Posted by nc...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/9dbcac6d/ambari-server/src/main/resources/scripts/change_owner.sh
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/scripts/change_owner.sh b/ambari-server/src/main/resources/scripts/change_owner.sh
deleted file mode 100755
index 6f0ac3d..0000000
--- a/ambari-server/src/main/resources/scripts/change_owner.sh
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/bin/bash
-# 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.
-
-usage()
-{
-cat << EOF
-usage: $0 options
-
-This script set ownership for all table, sequence and views for a given database
-
-OPTIONS:
- -h Show this message
- -d Database name
- -o Owner
- -s Schema (defaults to public)
-EOF
-}
-
-DB_NAME="";
-NEW_OWNER="";
-SCHEMA="public";
-while getopts "hd:o:s:" OPTION; do
- case $OPTION in
- h)
- usage;
- exit 1;
- ;;
- d)
- DB_NAME=$OPTARG;
- ;;
- o)
- NEW_OWNER=$OPTARG;
- ;;
- s)
- SCHEMA=$OPTARG;
- ;;
- esac
-done
-
-if [[ -z $DB_NAME ]] || [[ -z $NEW_OWNER ]]; then
- usage;
- exit 1;
-fi
-
-# Using the NULL byte as the separator as its the only character disallowed from PG table names
-IFS=\0;
-for tbl in `psql -qAt -R\0 -c "SELECT tablename FROM pg_tables WHERE schemaname = '${SCHEMA}';" ${DB_NAME}` \
- `psql -qAt -R\0 -c "SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = '${SCHEMA}';" ${DB_NAME}` \
- `psql -qAt -R\0 -c "SELECT table_name FROM information_schema.views WHERE table_schema = '${SCHEMA}';" ${DB_NAME}` ;
-do
- psql -c "ALTER TABLE \"${SCHEMA}\".\"$tbl\" OWNER TO ${NEW_OWNER}" ${DB_NAME};
-done
-unset IFS;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/9dbcac6d/ambari-server/src/test/python/TestAmbariServer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestAmbariServer.py b/ambari-server/src/test/python/TestAmbariServer.py
index 9992eb3..cd1d294 100644
--- a/ambari-server/src/test/python/TestAmbariServer.py
+++ b/ambari-server/src/test/python/TestAmbariServer.py
@@ -1021,6 +1021,7 @@ class TestAmbariServer(TestCase):
run_os_command_mock.return_value = (0, None, None)
result = dbms._setup_db()
self.assertTrue(run_os_command_mock.called)
+ self.assertEqual(run_os_command_mock.call_count, 2)
self.assertEqual((0, None, None), result)
pass
@@ -3318,7 +3319,7 @@ class TestAmbariServer(TestCase):
def test_prompt_db_properties_postgre_adv(self, gyni_mock, gvsi_mock, gvsi_2_mock, rp_mock, print_info_msg_mock, sls_mock,
get_os_family_mock, get_pw_nam_mock, chown_mock, mkdir_mock, isdir_mock):
gyni_mock.return_value = True
- list_of_return_values = ["ambari-server", "ambari", "ambari", "1"]
+ list_of_return_values = ["ambari-server", "postgres", "ambari", "ambari", "1"]
get_os_family_mock.return_value = OSConst.SUSE_FAMILY
pw = MagicMock()
pw.setattr('pw_uid', 0)
@@ -3391,12 +3392,13 @@ class TestAmbariServer(TestCase):
db_name = "db_ambari"
postgres_schema = "sc_ambari"
port = "1234"
+ local_admin_user = "postgres"
oracle_service = "1"
oracle_service_name = "ambari"
user_name = "ambari"
# Input values
- postgres_embedded_values = [db_name, postgres_schema, hostname]
+ postgres_embedded_values = [local_admin_user, db_name, postgres_schema, hostname]
oracle_values = [hostname, port, oracle_service, oracle_service_name, user_name]
mysql_values = [hostname, port, db_name, user_name]
postgres_external_values = [hostname, port, db_name, postgres_schema, user_name]
@@ -3435,6 +3437,7 @@ class TestAmbariServer(TestCase):
del args.dbms
del args.database_host
+ del args.local_admin_user
del args.database_port
del args.database_name
del args.database_username
@@ -5218,7 +5221,8 @@ class TestAmbariServer(TestCase):
@patch("ambari_server.serverUpgrade.update_ambari_env")
@patch("ambari_server.setupMpacks.get_replay_log_file")
@patch("ambari_server.serverUpgrade.logger")
- def test_upgrade_from_161(self, logger_mock, get_replay_log_file_mock, update_ambari_env_mock, update_krb_jaas_login_properties_mock, move_user_custom_actions_mock, upgrade_local_repo_mock, get_ambari_properties_mock,
+ @patch.object(PGConfig, "_change_db_files_owner", return_value=0)
+ def test_upgrade_from_161(self, change_db_files_owner_mock, logger_mock, get_replay_log_file_mock, update_ambari_env_mock, update_krb_jaas_login_properties_mock, move_user_custom_actions_mock, upgrade_local_repo_mock, get_ambari_properties_mock,
get_ambari_properties_2_mock, get_ambari_properties_3_mock, get_ambari_version_mock, write_property_mock,
is_root_mock, update_ambari_properties_mock, find_properties_file_mock, run_os_command_mock,
run_schema_upgrade_mock, read_ambari_user_mock, print_warning_msg_mock,
@@ -5300,7 +5304,6 @@ class TestAmbariServer(TestCase):
self.assertEquals(write_property_mock.call_args_list[0][0][1], "ambari")
self.assertEquals(write_property_mock.call_args_list[1][0][0], JDBC_DATABASE_PROPERTY)
self.assertEquals(write_property_mock.call_args_list[1][0][1], "postgres")
- self.assertTrue(run_os_command_mock.called)
self.assertFalse(move_user_custom_actions_mock.called)
args = reset_mocks()
@@ -8369,19 +8372,12 @@ class TestAmbariServer(TestCase):
self.assertTrue(perform_housekeeping_mock.called)
pass
- @not_for_platform(PLATFORM_WINDOWS)
- @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
- @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+ @patch("ambari_server.dbConfiguration.decrypt_password_for_alias")
@patch("ambari_server.dbConfiguration_linux.run_os_command")
@patch("ambari_server.dbConfiguration_linux.print_error_msg")
- @patch("ambari_server.dbConfiguration.get_ambari_properties")
- def test_change_objects_owner_both(self,
- get_ambari_properties_mock,
- print_error_msg_mock,
- run_os_command_mock):
+ def test_change_tables_owner_no_tables(self, print_error_msg_mock, run_os_command_mock,
+ decrypt_password_for_alias_mock):
args = MagicMock()
- args.master_key = None
-
del args.database_index
del args.dbms
del args.database_host
@@ -8389,30 +8385,27 @@ class TestAmbariServer(TestCase):
del args.database_name
del args.database_username
del args.database_password
- del args.persistence_type
+ del args.init_script_file
+ del args.drop_script_file
- stdout = " stdout "
- stderr = " stderr "
- run_os_command_mock.return_value = 1, stdout, stderr
- get_ambari_properties_mock.return_value = Properties()
+ properties = Properties()
+ properties.process_pair(JDBC_PASSWORD_PROPERTY, get_alias_string("mypwdalias"))
- set_verbose(True)
- self.assertRaises(FatalException, change_objects_owner, args)
- print_error_msg_mock.assert_any_call("stderr:\nstderr")
- print_error_msg_mock.assert_any_call("stdout:\nstdout")
- pass
+ decrypt_password_for_alias_mock.return_value = "password"
- @not_for_platform(PLATFORM_WINDOWS)
- @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+ run_os_command_mock.return_value = 0, "", ""
+
+ dbms = PGConfig(args, properties, "local")
+ result = dbms._change_tables_owner()
+ self.assertFalse(result)
+ self.assertEquals(print_error_msg_mock.call_args_list[0][0][0], 'Failed to get list of ambari tables')
+
+ @patch("ambari_server.dbConfiguration.decrypt_password_for_alias")
@patch("ambari_server.dbConfiguration_linux.run_os_command")
@patch("ambari_server.dbConfiguration_linux.print_error_msg")
- @patch("ambari_server.dbConfiguration.get_ambari_properties")
- def test_change_objects_owner_only_stdout(self,
- get_ambari_properties_mock,
- print_error_msg_mock,
- run_os_command_mock):
+ def test_change_tables_owner_fatal_psql(self, print_error_msg_mock, run_os_command_mock,
+ decrypt_password_for_alias_mock):
args = MagicMock()
-
del args.database_index
del args.dbms
del args.database_host
@@ -8420,29 +8413,30 @@ class TestAmbariServer(TestCase):
del args.database_name
del args.database_username
del args.database_password
- del args.persistence_type
+ del args.init_script_file
+ del args.drop_script_file
- stdout = " stdout "
- stderr = ""
- run_os_command_mock.return_value = 1, stdout, stderr
- get_ambari_properties_mock.return_value = Properties()
+ properties = Properties()
+ properties.process_pair(JDBC_PASSWORD_PROPERTY, get_alias_string("mypwdalias"))
- set_verbose(True)
- self.assertRaises(FatalException, change_objects_owner, args)
- print_error_msg_mock.assert_called_once_with("stdout:\nstdout")
- pass
+ decrypt_password_for_alias_mock.return_value = "password"
- @not_for_platform(PLATFORM_WINDOWS)
- @patch.object(OSCheck, "os_distribution", new = MagicMock(return_value = os_distro_value))
+ run_os_command_mock.return_value = 0, "", "psql: could not connect to server: No such file or directory"
+
+ dbms = PGConfig(args, properties, "local")
+ result = dbms._change_tables_owner()
+ self.assertFalse(result)
+ self.assertEquals(print_error_msg_mock.call_args_list[0][0][0], """Failed to get list of ambari tables. Message from psql:
+ stdout:
+ stderr:psql: could not connect to server: No such file or directory
+""")
+
+ @patch("ambari_server.dbConfiguration.decrypt_password_for_alias")
@patch("ambari_server.dbConfiguration_linux.run_os_command")
@patch("ambari_server.dbConfiguration_linux.print_error_msg")
- @patch("ambari_server.dbConfiguration.get_ambari_properties")
- def test_change_objects_owner_only_stderr(self,
- get_ambari_properties_mock,
- print_error_msg_mock,
- run_os_command_mock):
+ def test_change_tables_owner(self, print_error_msg_mock, run_os_command_mock,
+ decrypt_password_for_alias_mock):
args = MagicMock()
-
del args.database_index
del args.dbms
del args.database_host
@@ -8450,18 +8444,26 @@ class TestAmbariServer(TestCase):
del args.database_name
del args.database_username
del args.database_password
- del args.persistence_type
+ del args.init_script_file
+ del args.drop_script_file
- stdout = ""
- stderr = " stderr "
- run_os_command_mock.return_value = 1, stdout, stderr
- get_ambari_properties_mock.return_value = Properties()
+ properties = Properties()
+ properties.process_pair(JDBC_PASSWORD_PROPERTY, get_alias_string("mypwdalias"))
- set_verbose(True)
- self.assertRaises(FatalException, change_objects_owner, args)
- print_error_msg_mock.assert_called_once_with("stderr:\nstderr")
- pass
+ decrypt_password_for_alias_mock.return_value = "password"
+ run_os_command_mock.side_effect = [(0, "tbl1\n,tbl2", ""),
+ (0, "", ""),
+ (0, "", ""),
+ (0, "postgres", ""),
+ (0, "ALTER TABLE", ""),
+ (0, "postgres", ""),
+ (0, "ALTER TABLE", "")]
+
+ dbms = PGConfig(args, properties, "local")
+ result = dbms._change_tables_owner()
+ self.assertTrue(result)
+ self.assertEquals(run_os_command_mock.call_count, 7)
@patch("os.path.isdir", new = MagicMock(return_value=True))
@patch("os.access", new = MagicMock(return_value=True))
[24/27] ambari git commit: AMBARI-18407
BE:api/v1/persist/CLUSTER_CURRENT_STATUS takes more than 2s for transferring
307KB response. (atkach)
Posted by nc...@apache.org.
AMBARI-18407 BE:api/v1/persist/CLUSTER_CURRENT_STATUS takes more than 2s for transferring 307KB response. (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/51cbf0df
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/51cbf0df
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/51cbf0df
Branch: refs/heads/branch-dev-patch-upgrade
Commit: 51cbf0df6b6ba6922b236c3a0a4cfa39e3d919e5
Parents: 9f9e89a
Author: Andrii Tkach <at...@apache.org>
Authored: Thu Sep 15 21:56:50 2016 +0300
Committer: Andrii Tkach <at...@apache.org>
Committed: Fri Sep 16 12:38:27 2016 +0300
----------------------------------------------------------------------
.../global/user_settings_controller.js | 6 ++--
ambari-web/app/controllers/login_controller.js | 1 -
ambari-web/app/router.js | 3 +-
.../views/common/widget/graph_widget_view.js | 5 ++--
.../global/user_settings_controller_test.js | 31 +++++++++++++++++---
.../test/controllers/login_controller_test.js | 4 +++
.../common/widget/graph_widget_view_test.js | 4 +--
.../manage_alert_notifications_view_test.js | 5 ++++
8 files changed, 44 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/51cbf0df/ambari-web/app/controllers/global/user_settings_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/user_settings_controller.js b/ambari-web/app/controllers/global/user_settings_controller.js
index 8bcba75..9580400 100644
--- a/ambari-web/app/controllers/global/user_settings_controller.js
+++ b/ambari-web/app/controllers/global/user_settings_controller.js
@@ -81,13 +81,13 @@ App.UserSettingsController = Em.Controller.extend(App.UserPref, {
/**
* Success-callback for user pref
*
- * @param {*} response
+ * @param {?object} response
* @param {object} opt
- * @returns {*}
+ * @returns {?object}
* @method getUserPrefSuccessCallback
*/
getUserPrefSuccessCallback: function (response, opt) {
- var getAllRequest = opt.url.contains('persist/?_');
+ var getAllRequest = opt.url.endsWith('persist/');
if (Em.isNone(response)) {
this.updateUserPrefWithDefaultValues(response, getAllRequest);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/51cbf0df/ambari-web/app/controllers/login_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/login_controller.js b/ambari-web/app/controllers/login_controller.js
index 24c04f7..350da87 100644
--- a/ambari-web/app/controllers/login_controller.js
+++ b/ambari-web/app/controllers/login_controller.js
@@ -49,7 +49,6 @@ App.LoginController = Em.Object.extend({
}
this.set('errorMessage', errorMessage);
}
- App.router.get('userSettingsController').dataLoading();
this.set('isSubmitDisabled', false);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/51cbf0df/ambari-web/app/router.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/router.js b/ambari-web/app/router.js
index c7a70f1..0270771 100644
--- a/ambari-web/app/router.js
+++ b/ambari-web/app/router.js
@@ -420,7 +420,6 @@ App.Router = Em.Router.extend({
loginSuccessCallback: function(data, opt, params) {
var self = this;
- App.router.set('loginController.isSubmitDisabled', false);
App.usersMapper.map({"items": [data]});
this.setUserLoggedIn(data.Users.user_name);
var requestData = {
@@ -585,7 +584,7 @@ App.Router = Em.Router.extend({
}
}
App.set('isPermissionDataLoaded', true);
- App.router.get('userSettingsController').dataLoading();
+ App.router.get('loginController').postLogin(true, true);
},
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/51cbf0df/ambari-web/app/views/common/widget/graph_widget_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/widget/graph_widget_view.js b/ambari-web/app/views/common/widget/graph_widget_view.js
index 6348077..2ee76be 100644
--- a/ambari-web/app/views/common/widget/graph_widget_view.js
+++ b/ambari-web/app/views/common/widget/graph_widget_view.js
@@ -336,8 +336,9 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, App.ExportMetricsMixin, {
},
loadData: function () {
- Em.run.next(this, function () {
- this._refreshGraph(this.get('parentView.data'), this.get('parentView'));
+ var self = this;
+ Em.run.next(function () {
+ self._refreshGraph(self.get('parentView.data'), self.get('parentView'));
});
},
http://git-wip-us.apache.org/repos/asf/ambari/blob/51cbf0df/ambari-web/test/controllers/global/user_settings_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/global/user_settings_controller_test.js b/ambari-web/test/controllers/global/user_settings_controller_test.js
index 849fb2f..5ae17f8 100644
--- a/ambari-web/test/controllers/global/user_settings_controller_test.js
+++ b/ambari-web/test/controllers/global/user_settings_controller_test.js
@@ -17,21 +17,44 @@
*/
var App = require('app');
-var userSettingsController;
describe('App.UserSettingsController', function () {
+ var controller;
beforeEach(function () {
- userSettingsController = App.UserSettingsController.create();
+ controller = App.UserSettingsController.create();
});
afterEach(function () {
- userSettingsController.destroy();
+ controller.destroy();
});
describe('#userSettingsKeys', function () {
it('should not be empty', function () {
- expect(Object.keys(userSettingsController.get('userSettingsKeys'))).to.have.length.gt(0);
+ expect(Object.keys(controller.get('userSettingsKeys'))).to.have.length.gt(0);
+ });
+ });
+
+ describe("#getUserPrefSuccessCallback()", function () {
+
+ beforeEach(function() {
+ sinon.stub(controller, 'updateUserPrefWithDefaultValues');
+ });
+
+ afterEach(function() {
+ controller.updateUserPrefWithDefaultValues.restore();
+ });
+
+ it("response is null, updateUserPrefWithDefaultValues should be called", function() {
+ expect(controller.getUserPrefSuccessCallback(null, {url: ''})).to.be.null;
+ expect(controller.updateUserPrefWithDefaultValues.calledWith(null, false)).to.be.true;
+ expect(controller.get('currentPrefObject')).to.be.null;
+ });
+
+ it("response is correct, updateUserPrefWithDefaultValues should not be called", function() {
+ expect(controller.getUserPrefSuccessCallback({}, {url: ''})).to.be.object;
+ expect(controller.updateUserPrefWithDefaultValues.called).to.be.false;
+ expect(controller.get('currentPrefObject')).to.be.object;
});
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/51cbf0df/ambari-web/test/controllers/login_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/login_controller_test.js b/ambari-web/test/controllers/login_controller_test.js
index 15a310b..eaaf12d 100644
--- a/ambari-web/test/controllers/login_controller_test.js
+++ b/ambari-web/test/controllers/login_controller_test.js
@@ -51,6 +51,10 @@ describe('App.LoginController', function () {
loginController.postLogin(true, false, 'Login Failed: Please append your domain to your username and try again. Example: user_dup@domain');
expect(loginController.get('errorMessage')).to.be.equal('Login Failed: Please append your domain to your username and try again. Example: user_dup@domain');
});
+ it ('isSubmitDisabled should be false', function() {
+ loginController.postLogin(true, true);
+ expect(loginController.get('isSubmitDisabled')).to.be.false;
+ });
});
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/51cbf0df/ambari-web/test/views/common/widget/graph_widget_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/widget/graph_widget_view_test.js b/ambari-web/test/views/common/widget/graph_widget_view_test.js
index e19feaf..cceecbd 100644
--- a/ambari-web/test/views/common/widget/graph_widget_view_test.js
+++ b/ambari-web/test/views/common/widget/graph_widget_view_test.js
@@ -762,9 +762,7 @@ describe('App.GraphWidgetView', function () {
describe("#loadData()", function () {
beforeEach(function() {
- sinon.stub(Em.run, 'next', function(context, callback) {
- callback.apply(context);
- });
+ sinon.stub(Em.run, 'next', Em.clb);
sinon.stub(graphView, '_refreshGraph');
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/51cbf0df/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js b/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js
index 39570dd..bb04a0d 100644
--- a/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js
+++ b/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js
@@ -115,10 +115,15 @@ describe('App.ManageAlertNotificationsView', function () {
describe("#onAlertNotificationSelect()", function () {
beforeEach(function () {
+ sinon.stub(Em.run, 'later');
view.removeObserver('selectedAlertNotification', view, 'onAlertNotificationSelect');
view.set('controller', Em.Object.create({selectedAlertNotification: null}));
});
+ afterEach(function() {
+ Em.run.later.restore();
+ });
+
it("selectedAlertNotification is null", function () {
view.set('selectedAlertNotification', null);
view.onAlertNotificationSelect();