123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- /**
- * 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');
- App.db = {};
- var InitialData = {
- 'app': {
- 'loginName': '',
- 'authenticated': false,
- 'configs': [],
- 'tables': {
- 'filterConditions': {},
- 'displayLength': {},
- 'startIndex': {},
- 'sortingConditions': {},
- 'selectedItems': {}
- }
- },
- 'Installer': {},
- 'AddHost': {},
- 'AddService': {},
- 'WidgetWizard': {},
- 'KerberosWizard': {},
- 'ReassignMaster': {},
- 'AddSecurity': {},
- 'AddAlertDefinition': {
- content: {}
- },
- 'HighAvailabilityWizard': {},
- 'RMHighAvailabilityWizard': {},
- 'AddHawqStandbyWizard': {},
- 'ActivateHawqStandbyWizard': {},
- 'RAHighAvailabilityWizard': {},
- 'RollbackHighAvailabilityWizard': {},
- 'MainAdminStackAndUpgrade': {},
- 'KerberosDisable': {},
- 'tmp': {}
- };
- function checkNamespace(namespace) {
- if (!namespace) {
- return false;
- }
- if (Em.isNone(Em.get(App.db.data, namespace))) {
- Em.setFullPath(App.db.data, namespace, {});
- }
- return true;
- }
- if (typeof Storage === 'undefined') {
- // stub for unit testing purposes
- window.localStorage = {};
- localStorage.setItem = function (key, val) {
- this[key] = val;
- };
- localStorage.getItem = function (key) {
- return this[key];
- };
- window.localStorage.setObject = function (key, value) {
- this[key] = value;
- };
- window.localStorage.getObject = function (key) {
- return this[key];
- };
- }
- else {
- Storage.prototype.setObject = function (key, value) {
- this.setItem(key, JSON.stringify(value));
- };
- Storage.prototype.getObject = function (key) {
- var value = this.getItem(key);
- return value && JSON.parse(value);
- };
- }
- App.db.cleanUp = function () {
- App.db.data = InitialData;
- localStorage.setObject('ambari', App.db.data);
- };
- App.db.cleanTmp = function () {
- App.db.data.tmp = {};
- localStorage.setObject('ambari', App.db.data);
- };
- App.db.updateStorage = function () {
- App.db.data = localStorage.getObject('ambari');
- if (Em.get(App, 'db.data.app.tables') && Em.get(App, 'db.data.app.configs')) {
- return true;
- }
- App.db.cleanUp();
- return false;
- };
- /*
- Initialize wizard namespaces if they are not initialized on login.
- This will be required during upgrade.
- */
- App.db.mergeStorage = function () {
- if (localStorage.getObject('ambari') == null) {
- App.db.cleanUp();
- } else {
- localStorage.setObject('ambari', $.extend(true, {}, InitialData, App.db.data));
- }
- };
- // called whenever user logs in
- if (localStorage.getObject('ambari') == null) {
- App.db.cleanUp();
- }
- /**
- *
- * @param {string} namespace
- * @param {string} key
- * @returns {*}
- */
- App.db.get = function (namespace, key) {
- App.db.data = localStorage.getObject('ambari');
- Em.assert('`namespace` should be defined', !!namespace);
- checkNamespace(namespace);
- return Em.get(Em.get(App.db.data, namespace), key);
- };
- /**
- *
- * @param {string} namespace
- * @param {string[]} listOfProperties
- * @returns {object}
- */
- App.db.getProperties = function (namespace, listOfProperties) {
- App.db.data = localStorage.getObject('ambari');
- Em.assert('`namespace` should be defined', !!namespace);
- checkNamespace(namespace);
- return Em.getProperties(Em.get(App.db.data, namespace), listOfProperties);
- };
- /**
- *
- * @param {string} namespace
- * @param {string} key
- * @param {*} value
- */
- App.db.set = function (namespace, key, value) {
- App.db.data = localStorage.getObject('ambari');
- Em.assert('`namespace` should be defined', !!namespace);
- checkNamespace(namespace);
- Em.set(Em.get(App.db.data, namespace), key, value);
- localStorage.setObject('ambari', App.db.data);
- };
- /**
- *
- * @param {string} namespace
- * @param {{key: value}} hash
- */
- App.db.setProperties = function (namespace, hash) {
- App.db.data = localStorage.getObject('ambari');
- Em.assert('`namespace` should be defined', !!namespace);
- checkNamespace(namespace);
- Em.setProperties(Em.get(App.db.data, namespace), hash);
- localStorage.setObject('ambari', App.db.data);
- };
- App.db.setLoginName = function (name) {
- App.db.set('app', 'loginName', name);
- };
- /**
- * Set user model to db
- * @param user
- */
- App.db.setUser = function (user) {
- App.db.set('app', 'user', user);
- };
- App.db.setAuth = function (auth) {
- App.db.set('app', 'auth', auth);
- };
- App.db.setAuthenticated = function (authenticated) {
- App.db.set('app', 'authenticated', authenticated);
- App.db.data = localStorage.getObject('ambari');
- };
- App.db.setFilterConditions = function (name, filterConditions) {
- App.db.set('app.tables.filterConditions', name, filterConditions);
- };
- App.db.setComboSearchQuery = function (name, query) {
- App.db.set('app.tables.comboSearchQuery', name, query);
- };
- App.db.setDisplayLength = function (name, displayLength) {
- App.db.set('app.tables.displayLength', name, displayLength);
- };
- App.db.setStartIndex = function (name, startIndex) {
- App.db.set('app.tables.startIndex', name, startIndex);
- };
- App.db.setSortingStatuses = function (name, sortingConditions) {
- App.db.set('app.tables.sortingConditions', name, sortingConditions);
- };
- App.db.setSelectedHosts = function (name, selectedHosts) {
- App.db.set('app.tables.selectedItems', name, selectedHosts);
- };
- App.db.setHosts = function (hostInfo) {
- App.db.set('Installer', 'hostInfo', hostInfo);
- };
- App.db.setMasterComponentHosts = function (masterComponentHosts) {
- App.db.set('Installer', 'masterComponentHosts', masterComponentHosts);
- };
- App.db.setMasterToReassign = function (masterComponent) {
- App.db.set('ReassignMaster', 'masterComponent', masterComponent);
- };
- App.db.setReassignTasksStatuses = function (tasksStatuses) {
- App.db.set('ReassignMaster', 'tasksStatuses', tasksStatuses);
- };
- App.db.setReassignTasksRequestIds = function (requestIds) {
- App.db.set('ReassignMaster', 'tasksRequestIds', requestIds);
- };
- App.db.setStacks = function (stacks) {
- App.db.set('Installer', 'stacksVersions', stacks);
- };
- App.db.setConfigs = function (configs) {
- App.db.set('app', 'configs', configs);
- };
- /**
- * Set current step value for specified Wizard Type
- * @param wizardType
- * @param currentStep
- */
- App.db.setWizardCurrentStep = function (wizardType, currentStep) {
- App.db.set(wizardType.capitalize(), 'currentStep', currentStep);
- };
- /**
- * Set localStorage with data from server
- */
- App.db.setLocalStorage = function () {
- localStorage.setObject('ambari', App.db.data);
- };
- App.db.setSecurityWizardStatus = function (status) {
- App.db.set('AddSecurity', 'status', status);
- };
- App.db.setDisableSecurityStatus = function (status) {
- App.db.set('AddSecurity', 'disableSecurityStatus', status);
- };
- App.db.setSecurityDeployCommands = function (commands) {
- App.db.set('AddSecurity', 'securityDeployCommands', commands);
- };
- App.db.setHighAvailabilityWizardConfigTag = function (tag) {
- App.db.set('HighAvailabilityWizard', tag.name, tag.value);
- };
- App.db.setHighAvailabilityWizardHdfsClientHosts = function (hostNames) {
- App.db.set('HighAvailabilityWizard', 'hdfsClientHostNames', hostNames);
- };
- App.db.setHighAvailabilityWizardTasksStatuses = function (tasksStatuses) {
- App.db.set('HighAvailabilityWizard', 'tasksStatuses', tasksStatuses);
- };
- App.db.setHighAvailabilityWizardTasksRequestIds = function (requestIds) {
- App.db.set('HighAvailabilityWizard', 'tasksRequestIds', requestIds);
- };
- App.db.setHighAvailabilityWizardHdfsUser = function (hdfsUser) {
- App.db.set('HighAvailabilityWizard', 'hdfsUser', hdfsUser);
- };
- App.db.setHighAvailabilityWizardRequestIds = function (requestIds) {
- App.db.set('HighAvailabilityWizard', 'requestIds', requestIds);
- };
- App.db.setHighAvailabilityWizardNameServiceId = function (nameServiceId) {
- App.db.set('HighAvailabilityWizard', 'nameServiceId', nameServiceId);
- };
- App.db.setRollBackHighAvailabilityWizardAddNNHost = function (host) {
- App.db.set('RollbackHighAvailabilityWizard', 'addNNHost', host);
- };
- App.db.setRollBackHighAvailabilityWizardSNNHost = function (host) {
- App.db.set('RollbackHighAvailabilityWizard', 'sNNHost', host);
- };
- App.db.setRollBackHighAvailabilityWizardSelectedAddNN = function (host) {
- App.db.set('RollbackHighAvailabilityWizard', 'selectedAddNN', host);
- };
- App.db.setRollBackHighAvailabilityWizardSelectedSNN = function (host) {
- App.db.set('RollbackHighAvailabilityWizard', 'selectedSNNH', host);
- };
- App.db.setRollbackHighAvailabilityWizardTasksStatuses = function (tasksStatuses) {
- App.db.set('RollbackHighAvailabilityWizard', 'tasksStatuses', tasksStatuses);
- };
- App.db.setRollbackHighAvailabilityWizardRequestIds = function (requestIds) {
- App.db.set('RollbackHighAvailabilityWizard', 'requestIds', requestIds);
- };
- App.db.setReassignMasterWizardRequestIds = function (requestIds) {
- App.db.set('ReassignMaster', 'requestIds', requestIds);
- };
- App.db.setReassignMasterWizardComponentDir = function (componentDir) {
- App.db.set('ReassignMaster', 'componentDir', componentDir);
- };
- App.db.setReassignMasterWizardReassignHosts = function (reassignHosts) {
- App.db.set('ReassignMaster', 'reassignHosts', reassignHosts);
- };
- App.db.setKerberosWizardConfigTag = function (tag) {
- App.db.set('KerberosWizard', tag.name, tag.value);
- };
- /**
- * Get user model from db
- * @return {*}
- */
- App.db.getUser = function () {
- return App.db.get('app', 'user');
- };
- App.db.getAuth = function () {
- return App.db.get('app', 'auth');
- };
- App.db.getLoginName = function () {
- return App.db.get('app', 'loginName');
- };
- App.db.getAuthenticated = function () {
- return Boolean(App.db.get('app', 'authenticated'));
- };
- App.db.getFilterConditions = function (name) {
- return name ? App.db.get('app.tables.filterConditions', name) : null;
- };
- App.db.getComboSearchQuery = function (name) {
- return name ? App.db.get('app.tables.comboSearchQuery', name) : null;
- };
- App.db.getDisplayLength = function (name) {
- return name ? App.db.get('app.tables.displayLength', name) : null;
- };
- App.db.getStartIndex = function (name) {
- return name ? App.db.get('app.tables.startIndex', name): null;
- };
- App.db.getSortingStatuses = function (name) {
- return name ? App.db.get('app.tables.sortingConditions', name): null;
- };
- App.db.getSelectedHosts = function (name) {
- return App.db.get('app.tables.selectedItems', name) || [];
- };
- /**
- * Return current step for specified Wizard Type
- * @param wizardType
- * @return {*}
- */
- App.db.getWizardCurrentStep = function (wizardType) {
- return App.db.get(wizardType.capitalize(), 'currentStep') || 0;
- };
- App.db.getAllHostNames = function () {
- return App.db.get('Installer', 'hostNames');
- };
- App.db.getHosts = function () {
- return App.db.get('Installer', 'hostInfo');
- };
- App.db.getMasterToReassign = function () {
- return App.db.get('ReassignMaster', 'masterComponent');
- };
- App.db.getReassignTasksStatuses = function () {
- return App.db.get('ReassignMaster', 'tasksStatuses');
- };
- App.db.getReassignTasksRequestIds = function () {
- return App.db.get('ReassignMaster', 'tasksRequestIds');
- };
- App.db.getSecurityWizardStatus = function () {
- return App.db.get('AddSecurity', 'status');
- };
- App.db.getDisableSecurityStatus = function () {
- return App.db.get('AddSecurity', 'disableSecurityStatus');
- };
- App.db.getStacks = function () {
- return App.db.get('Installer', 'stacksVersions');
- };
- App.db.getHighAvailabilityWizardHdfsUser = function () {
- return App.db.get('HighAvailabilityWizard', 'hdfsUser');
- };
- App.db.getHighAvailabilityWizardTasksStatuses = function () {
- return App.db.get('HighAvailabilityWizard', 'tasksStatuses');
- };
- App.db.getHighAvailabilityWizardTasksRequestIds = function () {
- return App.db.get('HighAvailabilityWizard', 'tasksRequestIds');
- };
- App.db.getHighAvailabilityWizardFailedTask = function () {
- return App.db.get('HighAvailabilityWizard', 'failedTask');
- };
- App.db.getHighAvailabilityWizardHdfsClientHosts = function () {
- return App.db.get('HighAvailabilityWizard', 'hdfsClientHostNames');
- };
- App.db.getHighAvailabilityWizardConfigTag = function (tag) {
- return App.db.get('HighAvailabilityWizard', tag);
- };
- App.db.getHighAvailabilityWizardRequestIds = function () {
- return App.db.get('HighAvailabilityWizard', 'requestIds');
- };
- App.db.getHighAvailabilityWizardNameServiceId = function () {
- return App.db.get('HighAvailabilityWizard', 'nameServiceId');
- };
- App.db.getRollbackHighAvailabilityWizardTasksStatuses = function () {
- return App.db.get('RollbackHighAvailabilityWizard', 'tasksStatuses');
- };
- App.db.getRollbackHighAvailabilityWizardRequestIds = function () {
- return App.db.get('RollbackHighAvailabilityWizard', 'requestIds');
- };
- App.db.getRollBackHighAvailabilityWizardAddNNHost = function () {
- return App.db.get('RollbackHighAvailabilityWizard', 'addNNHost');
- };
- App.db.getRollBackHighAvailabilityWizardSNNHost = function () {
- return App.db.get('RollbackHighAvailabilityWizard', 'sNNHost');
- };
- App.db.getReassignMasterWizardRequestIds = function () {
- return App.db.get('ReassignMaster', 'requestIds');
- };
- App.db.getReassignMasterWizardComponentDir = function () {
- return App.db.get('ReassignMaster', 'componentDir');
- };
- App.db.getConfigs = function () {
- return App.db.get('app', 'configs');
- };
- App.db.getReassignMasterWizardReassignHosts = function () {
- return App.db.get('ReassignMaster', 'reassignHosts');
- };
- module.exports = App.db;
|