http://git-wip-us.apache.org/repos/asf/ignite/blob/6af6560a/modules/web-console/src/main/js/app/services/ModelNormalizer.service.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/app/services/ModelNormalizer.service.js b/modules/web-console/src/main/js/app/services/ModelNormalizer.service.js deleted file mode 100644 index 4c7052b..0000000 --- a/modules/web-console/src/main/js/app/services/ModelNormalizer.service.js +++ /dev/null @@ -1,59 +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. - */ - -// Service to normalize objects for dirty checks. -export default ['IgniteModelNormalizer', () => { - /** - * Normalize object for dirty checks. - * - * @param original - * @param dest - * @returns {*} - */ - const normalize = (original, dest) => { - if (_.isUndefined(original)) - return dest; - - if (_.isObject(original)) { - _.forOwn(original, (value, key) => { - if (/\$\$hashKey/.test(key)) - return; - - const attr = normalize(value); - - if (!_.isNil(attr)) { - dest = dest || {}; - dest[key] = attr; - } - }); - } else if (_.isBoolean(original) && original === true) - dest = original; - else if ((_.isString(original) && original.length) || _.isNumber(original)) - dest = original; - else if (_.isArray(original) && original.length) - dest = _.map(original, (value) => normalize(value, {})); - - return dest; - }; - - return { - normalize, - isEqual(prev, cur) { - return _.isEqual(prev, normalize(cur)); - } - }; -}];
http://git-wip-us.apache.org/repos/asf/ignite/blob/6af6560a/modules/web-console/src/main/js/app/services/UnsavedChangesGuard.service.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/app/services/UnsavedChangesGuard.service.js b/modules/web-console/src/main/js/app/services/UnsavedChangesGuard.service.js deleted file mode 100644 index 91244b0..0000000 --- a/modules/web-console/src/main/js/app/services/UnsavedChangesGuard.service.js +++ /dev/null @@ -1,38 +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. - */ - -const MSG = 'You have unsaved changes.\n\nAre you sure you want to discard them?'; - -// Service that show confirmation about unsaved changes on user change location. -export default ['IgniteUnsavedChangesGuard', ['$rootScope', ($root) => { - return { - install(scope, customDirtyCheck = () => scope.ui.inputForm.$dirty) { - scope.$on('$destroy', () => window.onbeforeunload = null); - - const unbind = $root.$on('$stateChangeStart', (event) => { - if (_.get(scope, 'ui.inputForm', false) && customDirtyCheck()) { - if (!confirm(MSG)) // eslint-disable-line no-alert - event.preventDefault(); - else - unbind(); - } - }); - - window.onbeforeunload = () => _.get(scope, 'ui.inputForm.$dirty', false) ? MSG : null; - } - }; -}]]; http://git-wip-us.apache.org/repos/asf/ignite/blob/6af6560a/modules/web-console/src/main/js/app/vendor.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/app/vendor.js b/modules/web-console/src/main/js/app/vendor.js deleted file mode 100644 index a8eeea7..0000000 --- a/modules/web-console/src/main/js/app/vendor.js +++ /dev/null @@ -1,54 +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. - */ - -import 'jquery'; -import 'angular'; -import 'angular-animate'; -import 'angular-sanitize'; -import 'angular-strap'; -import 'angular-strap/dist/angular-strap.tpl'; -import 'angular-socket-io'; -import 'angular-retina'; -import 'angular-ui-router'; -import 'ui-router-metatags/dist/ui-router-metatags'; -import 'angular-smart-table'; -import 'angular-ui-grid/ui-grid'; -import 'angular-drag-and-drop-lists'; -import 'angular-nvd3'; -import 'angular-tree-control'; -import 'angular-gridster'; -import 'bootstrap-sass/assets/javascripts/bootstrap/transition'; -import 'bootstrap-sass/assets/javascripts/bootstrap/carousel'; -import 'brace'; -import 'brace/mode/xml'; -import 'brace/mode/sql'; -import 'brace/mode/java'; -import 'brace/mode/dockerfile'; -import 'brace/mode/snippets'; -import 'brace/theme/chrome'; -import 'brace/ext/language_tools'; -import 'brace/ext/searchbox'; -import 'file-saver'; -import 'jszip'; -import 'nvd3'; -import 'query-command-supported'; -import 'angular-gridster/dist/angular-gridster.min.css'; -import 'angular-tree-control/css/tree-control-attribute.css'; -import 'angular-tree-control/css/tree-control.css'; -import 'angular-ui-grid/ui-grid.css'; -import 'angular-motion/dist/angular-motion.css'; -import 'nvd3/build/nv.d3.css'; http://git-wip-us.apache.org/repos/asf/ignite/blob/6af6560a/modules/web-console/src/main/js/controllers/admin-controller.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/controllers/admin-controller.js b/modules/web-console/src/main/js/controllers/admin-controller.js deleted file mode 100644 index 9e5aea7..0000000 --- a/modules/web-console/src/main/js/controllers/admin-controller.js +++ /dev/null @@ -1,91 +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. - */ - -// Controller for Admin screen. -export default ['adminController', [ - '$rootScope', '$scope', '$http', '$q', '$state', 'IgniteMessages', 'IgniteConfirm', 'User', 'IgniteCountries', - ($rootScope, $scope, $http, $q, $state, Messages, Confirm, User, Countries) => { - $scope.users = null; - - const _reloadUsers = () => { - $http.post('/api/v1/admin/list') - .then(({data}) => { - $scope.users = data; - - _.forEach($scope.users, (user) => { - user.userName = user.firstName + ' ' + user.lastName; - user.countryCode = Countries.getByName(user.country).code; - user.label = user.userName + ' ' + user.email + ' ' + - (user.company || '') + ' ' + (user.countryCode || ''); - }); - }) - .catch(Messages.showError); - }; - - _reloadUsers(); - - $scope.becomeUser = function(user) { - $http.get('/api/v1/admin/become', { params: {viewedUserId: user._id}}) - .then(User.read) - .then((becomeUser) => { - $rootScope.$broadcast('user', becomeUser); - - $state.go('base.configuration.clusters'); - }) - .catch(Messages.showError); - }; - - $scope.removeUser = (user) => { - Confirm.confirm('Are you sure you want to remove user: "' + user.userName + '"?') - .then(() => { - $http.post('/api/v1/admin/remove', {userId: user._id}) - .success(() => { - const i = _.findIndex($scope.users, (u) => u._id === user._id); - - if (i >= 0) - $scope.users.splice(i, 1); - - Messages.showInfo('User has been removed: "' + user.userName + '"'); - }) - .error((err, status) => { - if (status === 503) - Messages.showInfo(err); - else - Messages.showError(Messages.errorMessage('Failed to remove user: ', err)); - }); - }); - }; - - $scope.toggleAdmin = (user) => { - if (user.adminChanging) - return; - - user.adminChanging = true; - - $http.post('/api/v1/admin/save', {userId: user._id, adminFlag: !user.admin}) - .success(() => { - user.admin = !user.admin; - - Messages.showInfo('Admin right was successfully toggled for user: "' + user.userName + '"'); - }) - .error((err) => { - Messages.showError(Messages.errorMessage('Failed to toggle admin right for user: ', err)); - }) - .finally(() => user.adminChanging = false); - }; - } -]]; http://git-wip-us.apache.org/repos/asf/ignite/blob/6af6560a/modules/web-console/src/main/js/controllers/caches-controller.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/controllers/caches-controller.js b/modules/web-console/src/main/js/controllers/caches-controller.js deleted file mode 100644 index cbd681e..0000000 --- a/modules/web-console/src/main/js/controllers/caches-controller.js +++ /dev/null @@ -1,470 +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. - */ - -// Controller for Caches screen. -export default ['cachesController', [ - '$scope', '$http', '$state', '$filter', '$timeout', 'IgniteLegacyUtils', 'IgniteMessages', 'IgniteConfirm', 'IgniteClone', 'IgniteLoading', 'IgniteModelNormalizer', 'IgniteUnsavedChangesGuard', - function($scope, $http, $state, $filter, $timeout, LegacyUtils, Messages, Confirm, Clone, Loading, ModelNormalizer, UnsavedChangesGuard) { - UnsavedChangesGuard.install($scope); - - const emptyCache = {empty: true}; - - let __original_value; - - const blank = { - evictionPolicy: {}, - cacheStoreFactory: {}, - nearConfiguration: {} - }; - - // We need to initialize backupItem with empty object in order to properly used from angular directives. - $scope.backupItem = emptyCache; - - $scope.ui = LegacyUtils.formUI(); - $scope.ui.activePanels = [0]; - $scope.ui.topPanels = [0, 1, 2, 3]; - - $scope.hidePopover = LegacyUtils.hidePopover; - $scope.saveBtnTipText = LegacyUtils.saveBtnTipText; - $scope.widthIsSufficient = LegacyUtils.widthIsSufficient; - - const showPopoverMessage = LegacyUtils.showPopoverMessage; - - $scope.contentVisible = function() { - const item = $scope.backupItem; - - return !item.empty && (!item._id || _.find($scope.displayedRows, {_id: item._id})); - }; - - $scope.toggleExpanded = function() { - $scope.ui.expanded = !$scope.ui.expanded; - - LegacyUtils.hidePopover(); - }; - - $scope.caches = []; - $scope.domains = []; - - function _cacheLbl(cache) { - return cache.name + ', ' + cache.cacheMode + ', ' + cache.atomicityMode; - } - - function selectFirstItem() { - if ($scope.caches.length > 0) - $scope.selectItem($scope.caches[0]); - } - - function cacheDomains(item) { - return _.reduce($scope.domains, function(memo, domain) { - if (item && _.includes(item.domains, domain.value)) - memo.push(domain.meta); - - return memo; - }, []); - } - - Loading.start('loadingCachesScreen'); - - // When landing on the page, get caches and show them. - $http.post('/api/v1/configuration/caches/list') - .success(function(data) { - const validFilter = $filter('domainsValidation'); - - $scope.spaces = data.spaces; - $scope.caches = data.caches; - - _.forEach($scope.caches, (cache) => cache.label = _cacheLbl(cache)); - - $scope.clusters = _.map(data.clusters, function(cluster) { - return { - value: cluster._id, - label: cluster.name, - caches: cluster.caches - }; - }); - - $scope.domains = _.sortBy(_.map(validFilter(data.domains, true, false), function(domain) { - return { - value: domain._id, - label: domain.valueType, - kind: domain.kind, - meta: domain - }; - }), 'label'); - - if ($state.params.linkId) - $scope.createItem($state.params.linkId); - else { - const lastSelectedCache = angular.fromJson(sessionStorage.lastSelectedCache); - - if (lastSelectedCache) { - const idx = _.findIndex($scope.caches, function(cache) { - return cache._id === lastSelectedCache; - }); - - if (idx >= 0) - $scope.selectItem($scope.caches[idx]); - else { - sessionStorage.removeItem('lastSelectedCache'); - - selectFirstItem(); - } - } - else - selectFirstItem(); - } - - $scope.$watch('ui.inputForm.$valid', function(valid) { - if (valid && ModelNormalizer.isEqual(__original_value, $scope.backupItem)) - $scope.ui.inputForm.$dirty = false; - }); - - $scope.$watch('backupItem', function(val) { - const form = $scope.ui.inputForm; - - if (form.$pristine || (form.$valid && ModelNormalizer.isEqual(__original_value, val))) - form.$setPristine(); - else - form.$setDirty(); - }, true); - }) - .catch(Messages.showError) - .finally(function() { - $scope.ui.ready = true; - $scope.ui.inputForm.$setPristine(); - Loading.finish('loadingCachesScreen'); - }); - - $scope.selectItem = function(item, backup) { - function selectItem() { - $scope.selectedItem = item; - - if (item && !_.get(item.cacheStoreFactory.CacheJdbcBlobStoreFactory, 'connectVia')) - _.set(item.cacheStoreFactory, 'CacheJdbcBlobStoreFactory.connectVia', 'DataSource'); - - try { - if (item && item._id) - sessionStorage.lastSelectedCache = angular.toJson(item._id); - else - sessionStorage.removeItem('lastSelectedCache'); - } - catch (ignored) { - // No-op. - } - - if (backup) - $scope.backupItem = backup; - else if (item) - $scope.backupItem = angular.copy(item); - else - $scope.backupItem = emptyCache; - - $scope.backupItem = angular.merge({}, blank, $scope.backupItem); - - __original_value = ModelNormalizer.normalize($scope.backupItem); - - if (LegacyUtils.getQueryVariable('new')) - $state.go('base.configuration.caches'); - } - - LegacyUtils.confirmUnsavedChanges($scope.backupItem && $scope.ui.inputForm.$dirty, selectItem); - }; - - $scope.linkId = () => $scope.backupItem._id ? $scope.backupItem._id : 'create'; - - function prepareNewItem(linkId) { - return { - space: $scope.spaces[0]._id, - cacheMode: 'PARTITIONED', - atomicityMode: 'ATOMIC', - readFromBackup: true, - copyOnRead: true, - clusters: linkId && _.find($scope.clusters, {value: linkId}) - ? [linkId] : _.map($scope.clusters, function(cluster) { return cluster.value; }), - domains: linkId && _.find($scope.domains, { value: linkId }) ? [linkId] : [], - cacheStoreFactory: {CacheJdbcBlobStoreFactory: {connectVia: 'DataSource'}} - }; - } - - // Add new cache. - $scope.createItem = function(linkId) { - $timeout(() => LegacyUtils.ensureActivePanel($scope.ui, 'general', 'cacheName')); - - $scope.selectItem(null, prepareNewItem(linkId)); - }; - - function cacheClusters() { - return _.filter($scope.clusters, (cluster) => _.includes($scope.backupItem.clusters, cluster.value)); - } - - function clusterCaches(cluster) { - const caches = _.filter($scope.caches, - (cache) => cache._id !== $scope.backupItem._id && _.includes(cluster.caches, cache._id)); - - caches.push($scope.backupItem); - - return caches; - } - - function checkDataSources() { - const clusters = cacheClusters(); - - let checkRes = {checked: true}; - - const failCluster = _.find(clusters, (cluster) => { - const caches = clusterCaches(cluster); - - checkRes = LegacyUtils.checkCachesDataSources(caches, $scope.backupItem); - - return !checkRes.checked; - }); - - if (!checkRes.checked) { - return showPopoverMessage($scope.ui, 'store', checkRes.firstCache.cacheStoreFactory.kind === 'CacheJdbcPojoStoreFactory' ? 'pojoDialect' : 'blobDialect', - 'Found cache "' + checkRes.secondCache.name + '" in cluster "' + failCluster.label + '" ' + - 'with the same data source bean name "' + checkRes.firstCache.cacheStoreFactory[checkRes.firstCache.cacheStoreFactory.kind].dataSourceBean + - '" and different database: "' + LegacyUtils.cacheStoreJdbcDialectsLabel(checkRes.firstDB) + '" in current cache and "' + - LegacyUtils.cacheStoreJdbcDialectsLabel(checkRes.secondDB) + '" in "' + checkRes.secondCache.name + '"', 10000); - } - - return true; - } - - function checkSQLSchemas() { - const clusters = cacheClusters(); - - let checkRes = {checked: true}; - - const failCluster = _.find(clusters, (cluster) => { - const caches = clusterCaches(cluster); - - checkRes = LegacyUtils.checkCacheSQLSchemas(caches, $scope.backupItem); - - return !checkRes.checked; - }); - - if (!checkRes.checked) { - return showPopoverMessage($scope.ui, 'query', 'sqlSchema', - 'Found cache "' + checkRes.secondCache.name + '" in cluster "' + failCluster.label + '" ' + - 'with the same SQL schema name "' + checkRes.firstCache.sqlSchema + '"', 10000); - } - - return true; - } - - function checkStoreFactoryBean(storeFactory, beanFieldId) { - if (!LegacyUtils.isValidJavaIdentifier('Data source bean', storeFactory.dataSourceBean, beanFieldId, $scope.ui, 'store')) - return false; - - return checkDataSources(); - } - - function checkStoreFactory(item) { - const cacheStoreFactorySelected = item.cacheStoreFactory && item.cacheStoreFactory.kind; - - if (cacheStoreFactorySelected) { - const storeFactory = item.cacheStoreFactory[item.cacheStoreFactory.kind]; - - if (item.cacheStoreFactory.kind === 'CacheJdbcPojoStoreFactory' && !checkStoreFactoryBean(storeFactory, 'pojoDataSourceBean')) - return false; - - if (item.cacheStoreFactory.kind === 'CacheJdbcBlobStoreFactory' && storeFactory.connectVia !== 'URL' - && !checkStoreFactoryBean(storeFactory, 'blobDataSourceBean')) - return false; - } - - if ((item.readThrough || item.writeThrough) && !cacheStoreFactorySelected) - return showPopoverMessage($scope.ui, 'store', 'cacheStoreFactory', (item.readThrough ? 'Read' : 'Write') + ' through are enabled but store is not configured!'); - - if (item.writeBehindEnabled && !cacheStoreFactorySelected) - return showPopoverMessage($scope.ui, 'store', 'cacheStoreFactory', 'Write behind enabled but store is not configured!'); - - if (cacheStoreFactorySelected && !item.readThrough && !item.writeThrough) - return showPopoverMessage($scope.ui, 'store', 'readThroughTooltip', 'Store is configured but read/write through are not enabled!'); - - return true; - } - - // Check cache logical consistency. - function validate(item) { - LegacyUtils.hidePopover(); - - if (LegacyUtils.isEmptyString(item.name)) - return showPopoverMessage($scope.ui, 'general', 'cacheName', 'Cache name should not be empty!'); - - if (item.memoryMode === 'ONHEAP_TIERED' && item.offHeapMaxMemory > 0 && !LegacyUtils.isDefined(item.evictionPolicy.kind)) - return showPopoverMessage($scope.ui, 'memory', 'evictionPolicyKind', 'Eviction policy should not be configured!'); - - if (!LegacyUtils.checkFieldValidators($scope.ui)) - return false; - - if (item.memoryMode === 'OFFHEAP_VALUES' && !_.isEmpty(item.domains)) - return showPopoverMessage($scope.ui, 'memory', 'memoryMode', 'Query indexing could not be enabled while values are stored off-heap!'); - - if (item.memoryMode === 'OFFHEAP_TIERED' && (!LegacyUtils.isDefined(item.offHeapMaxMemory) || item.offHeapMaxMemory < 0)) - return showPopoverMessage($scope.ui, 'memory', 'offHeapMaxMemory', 'Off-heap max memory should be specified!'); - - if (!checkSQLSchemas()) - return false; - - if (!checkStoreFactory(item)) - return false; - - if (item.writeBehindFlushSize === 0 && item.writeBehindFlushFrequency === 0) - return showPopoverMessage($scope.ui, 'store', 'writeBehindFlushSize', 'Both "Flush frequency" and "Flush size" are not allowed as 0!'); - - return true; - } - - // Save cache in database. - function save(item) { - $http.post('/api/v1/configuration/caches/save', item) - .success(function(_id) { - item.label = _cacheLbl(item); - - $scope.ui.inputForm.$setPristine(); - - const idx = _.findIndex($scope.caches, function(cache) { - return cache._id === _id; - }); - - if (idx >= 0) - angular.merge($scope.caches[idx], item); - else { - item._id = _id; - $scope.caches.push(item); - } - - _.forEach($scope.clusters, (cluster) => { - if (_.includes(item.clusters, cluster.value)) - cluster.caches = _.union(cluster.caches, [_id]); - else - _.remove(cluster.caches, (id) => id === _id); - }); - - _.forEach($scope.domains, (domain) => { - if (_.includes(item.domains, domain.value)) - domain.meta.caches = _.union(domain.meta.caches, [_id]); - else - _.remove(domain.meta.caches, (id) => id === _id); - }); - - $scope.selectItem(item); - - Messages.showInfo('Cache "' + item.name + '" saved.'); - }) - .error(Messages.showError); - } - - // Save cache. - $scope.saveItem = function() { - const item = $scope.backupItem; - - angular.extend(item, LegacyUtils.autoCacheStoreConfiguration(item, cacheDomains(item))); - - if (validate(item)) - save(item); - }; - - function _cacheNames() { - return _.map($scope.caches, function(cache) { - return cache.name; - }); - } - - // Clone cache with new name. - $scope.cloneItem = function() { - if (validate($scope.backupItem)) { - Clone.confirm($scope.backupItem.name, _cacheNames()).then(function(newName) { - const item = angular.copy($scope.backupItem); - - delete item._id; - - item.name = newName; - - delete item.sqlSchema; - - save(item); - }); - } - }; - - // Remove cache from db. - $scope.removeItem = function() { - const selectedItem = $scope.selectedItem; - - Confirm.confirm('Are you sure you want to remove cache: "' + selectedItem.name + '"?') - .then(function() { - const _id = selectedItem._id; - - $http.post('/api/v1/configuration/caches/remove', {_id}) - .success(function() { - Messages.showInfo('Cache has been removed: ' + selectedItem.name); - - const caches = $scope.caches; - - const idx = _.findIndex(caches, function(cache) { - return cache._id === _id; - }); - - if (idx >= 0) { - caches.splice(idx, 1); - - if (caches.length > 0) - $scope.selectItem(caches[0]); - else { - $scope.backupItem = emptyCache; - $scope.ui.inputForm.$setPristine(); - } - - _.forEach($scope.clusters, (cluster) => _.remove(cluster.caches, (id) => id === _id)); - _.forEach($scope.domains, (domain) => _.remove(domain.meta.caches, (id) => id === _id)); - } - }) - .error(Messages.showError); - }); - }; - - // Remove all caches from db. - $scope.removeAllItems = function() { - Confirm.confirm('Are you sure you want to remove all caches?') - .then(function() { - $http.post('/api/v1/configuration/caches/remove/all') - .success(function() { - Messages.showInfo('All caches have been removed'); - - $scope.caches = []; - - _.forEach($scope.clusters, (cluster) => cluster.caches = []); - _.forEach($scope.domains, (domain) => domain.meta.caches = []); - - $scope.backupItem = emptyCache; - $scope.ui.inputForm.$setPristine(); - }) - .error(Messages.showError); - }); - }; - - $scope.resetAll = function() { - Confirm.confirm('Are you sure you want to undo all changes for current cache?') - .then(function() { - $scope.backupItem = $scope.selectedItem ? angular.copy($scope.selectedItem) : prepareNewItem(); - $scope.ui.inputForm.$setPristine(); - }); - }; - } -]]; http://git-wip-us.apache.org/repos/asf/ignite/blob/6af6560a/modules/web-console/src/main/js/controllers/clusters-controller.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/controllers/clusters-controller.js b/modules/web-console/src/main/js/controllers/clusters-controller.js deleted file mode 100644 index 5f86d08..0000000 --- a/modules/web-console/src/main/js/controllers/clusters-controller.js +++ /dev/null @@ -1,626 +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. - */ - -// Controller for Clusters screen. -export default ['clustersController', [ - '$rootScope', '$scope', '$http', '$state', '$timeout', 'IgniteLegacyUtils', 'IgniteMessages', 'IgniteConfirm', 'IgniteClone', 'IgniteLoading', 'IgniteModelNormalizer', 'IgniteUnsavedChangesGuard', 'igniteEventGroups', 'DemoInfo', 'IgniteLegacyTable', - function($root, $scope, $http, $state, $timeout, LegacyUtils, Messages, Confirm, Clone, Loading, ModelNormalizer, UnsavedChangesGuard, igniteEventGroups, DemoInfo, LegacyTable) { - UnsavedChangesGuard.install($scope); - - const emptyCluster = {empty: true}; - - let __original_value; - - const blank = { - atomicConfiguration: {}, - binaryConfiguration: {}, - communication: {}, - connector: {}, - discovery: {}, - marshaller: {}, - sslContextFactory: {}, - swapSpaceSpi: {}, - transactionConfiguration: {}, - collision: {} - }; - - const pairFields = { - attributes: {id: 'Attribute', idPrefix: 'Key', searchCol: 'name', valueCol: 'key', dupObjName: 'name', group: 'attributes'}, - 'collision.JobStealing.stealingAttributes': {id: 'CAttribute', idPrefix: 'Key', searchCol: 'name', valueCol: 'key', dupObjName: 'name', group: 'collision'} - }; - - const showPopoverMessage = LegacyUtils.showPopoverMessage; - - $scope.tablePairValid = function(item, field, index) { - const pairField = pairFields[field.model]; - - const pairValue = LegacyTable.tablePairValue(field, index); - - if (pairField) { - const model = _.get(item, field.model); - - if (LegacyUtils.isDefined(model)) { - const idx = _.findIndex(model, (pair) => { - return pair[pairField.searchCol] === pairValue[pairField.valueCol]; - }); - - // Found duplicate by key. - if (idx >= 0 && idx !== index) - return showPopoverMessage($scope.ui, pairField.group, LegacyTable.tableFieldId(index, pairField.idPrefix + pairField.id), 'Attribute with such ' + pairField.dupObjName + ' already exists!'); - } - } - - return true; - }; - - $scope.tableSave = function(field, index, stopEdit) { - if (LegacyTable.tablePairSaveVisible(field, index)) - return LegacyTable.tablePairSave($scope.tablePairValid, $scope.backupItem, field, index, stopEdit); - - return true; - }; - - $scope.tableReset = (trySave) => { - const field = LegacyTable.tableField(); - - if (trySave && LegacyUtils.isDefined(field) && !$scope.tableSave(field, LegacyTable.tableEditedRowIndex(), true)) - return false; - - LegacyTable.tableReset(); - - return true; - }; - - $scope.tableNewItem = function(field) { - if ($scope.tableReset(true)) { - if (field.type === 'failoverSpi') { - if (LegacyUtils.isDefined($scope.backupItem.failoverSpi)) - $scope.backupItem.failoverSpi.push({}); - else - $scope.backupItem.failoverSpi = {}; - } - else - LegacyTable.tableNewItem(field); - } - }; - - $scope.tableNewItemActive = LegacyTable.tableNewItemActive; - - $scope.tableStartEdit = function(item, field, index) { - if ($scope.tableReset(true)) - LegacyTable.tableStartEdit(item, field, index, $scope.tableSave); - }; - - $scope.tableEditing = LegacyTable.tableEditing; - - $scope.tableRemove = function(item, field, index) { - if ($scope.tableReset(true)) - LegacyTable.tableRemove(item, field, index); - }; - - $scope.tablePairSave = LegacyTable.tablePairSave; - $scope.tablePairSaveVisible = LegacyTable.tablePairSaveVisible; - - $scope.attributesTbl = { - type: 'attributes', - model: 'attributes', - focusId: 'Attribute', - ui: 'table-pair', - keyName: 'name', - valueName: 'value', - save: $scope.tableSave - }; - - $scope.stealingAttributesTbl = { - type: 'attributes', - model: 'collision.JobStealing.stealingAttributes', - focusId: 'CAttribute', - ui: 'table-pair', - keyName: 'name', - valueName: 'value', - save: $scope.tableSave - }; - - $scope.removeFailoverConfiguration = function(idx) { - $scope.backupItem.failoverSpi.splice(idx, 1); - }; - - // We need to initialize backupItem with empty object in order to properly used from angular directives. - $scope.backupItem = emptyCluster; - - $scope.ui = LegacyUtils.formUI(); - $scope.ui.activePanels = [0]; - $scope.ui.topPanels = [0]; - - $scope.hidePopover = LegacyUtils.hidePopover; - $scope.saveBtnTipText = LegacyUtils.saveBtnTipText; - $scope.widthIsSufficient = LegacyUtils.widthIsSufficient; - - $scope.contentVisible = function() { - const item = $scope.backupItem; - - return !item.empty && (!item._id || _.find($scope.displayedRows, {_id: item._id})); - }; - - $scope.toggleExpanded = function() { - $scope.ui.expanded = !$scope.ui.expanded; - - LegacyUtils.hidePopover(); - }; - - $scope.discoveries = [ - {value: 'Vm', label: 'Static IPs'}, - {value: 'Multicast', label: 'Multicast'}, - {value: 'S3', label: 'AWS S3'}, - {value: 'Cloud', label: 'Apache jclouds'}, - {value: 'GoogleStorage', label: 'Google cloud storage'}, - {value: 'Jdbc', label: 'JDBC'}, - {value: 'SharedFs', label: 'Shared filesystem'}, - {value: 'ZooKeeper', label: 'Apache ZooKeeper'} - ]; - - $scope.swapSpaceSpis = [ - {value: 'FileSwapSpaceSpi', label: 'File-based swap'}, - {value: null, label: 'Not set'} - ]; - - $scope.eventGroups = igniteEventGroups; - - $scope.clusters = []; - - function _clusterLbl(cluster) { - return cluster.name + ', ' + _.find($scope.discoveries, {value: cluster.discovery.kind}).label; - } - - function selectFirstItem() { - if ($scope.clusters.length > 0) - $scope.selectItem($scope.clusters[0]); - } - - Loading.start('loadingClustersScreen'); - - // When landing on the page, get clusters and show them. - $http.post('/api/v1/configuration/clusters/list') - .success(function(data) { - $scope.spaces = data.spaces; - $scope.clusters = data.clusters; - $scope.caches = _.map(data.caches, (cache) => ({value: cache._id, label: cache.name, cache})); - $scope.igfss = _.map(data.igfss, (igfs) => ({value: igfs._id, label: igfs.name, igfs})); - - _.forEach($scope.clusters, (cluster) => { - cluster.label = _clusterLbl(cluster); - - if (!cluster.collision || !cluster.collision.kind) - cluster.collision = {kind: 'Noop', JobStealing: {stealingEnabled: true}, PriorityQueue: {starvationPreventionEnabled: true}}; - - if (!cluster.failoverSpi) - cluster.failoverSpi = []; - - if (!cluster.logger) - cluster.logger = {Log4j: { mode: 'Default'}}; - }); - - if ($state.params.linkId) - $scope.createItem($state.params.linkId); - else { - const lastSelectedCluster = angular.fromJson(sessionStorage.lastSelectedCluster); - - if (lastSelectedCluster) { - const idx = _.findIndex($scope.clusters, (cluster) => cluster._id === lastSelectedCluster); - - if (idx >= 0) - $scope.selectItem($scope.clusters[idx]); - else { - sessionStorage.removeItem('lastSelectedCluster'); - - selectFirstItem(); - } - } - else - selectFirstItem(); - } - - $scope.$watch('ui.inputForm.$valid', function(valid) { - if (valid && ModelNormalizer.isEqual(__original_value, $scope.backupItem)) - $scope.ui.inputForm.$dirty = false; - }); - - $scope.$watch('backupItem', function(val) { - const form = $scope.ui.inputForm; - - if (form.$pristine || (form.$valid && ModelNormalizer.isEqual(__original_value, val))) - form.$setPristine(); - else - form.$setDirty(); - }, true); - - if ($root.IgniteDemoMode && sessionStorage.showDemoInfo !== 'true') { - sessionStorage.showDemoInfo = 'true'; - - DemoInfo.show(); - } - }) - .catch(Messages.showError) - .finally(function() { - $scope.ui.ready = true; - $scope.ui.inputForm.$setPristine(); - Loading.finish('loadingClustersScreen'); - }); - - $scope.selectItem = function(item, backup) { - function selectItem() { - $scope.selectedItem = item; - - try { - if (item && item._id) - sessionStorage.lastSelectedCluster = angular.toJson(item._id); - else - sessionStorage.removeItem('lastSelectedCluster'); - } - catch (ignored) { - // No-op. - } - - if (backup) - $scope.backupItem = backup; - else if (item) - $scope.backupItem = angular.copy(item); - else - $scope.backupItem = emptyCluster; - - $scope.backupItem = angular.merge({}, blank, $scope.backupItem); - - __original_value = ModelNormalizer.normalize($scope.backupItem); - - if (LegacyUtils.getQueryVariable('new')) - $state.go('base.configuration.clusters'); - } - - LegacyUtils.confirmUnsavedChanges($scope.backupItem && $scope.ui.inputForm.$dirty, selectItem); - }; - - $scope.linkId = () => $scope.backupItem._id ? $scope.backupItem._id : 'create'; - - function prepareNewItem(linkId) { - return angular.merge({}, blank, { - space: $scope.spaces[0]._id, - discovery: {kind: 'Multicast', Vm: {addresses: ['127.0.0.1:47500..47510']}, Multicast: {addresses: ['127.0.0.1:47500..47510']}}, - binaryConfiguration: {typeConfigurations: [], compactFooter: true}, - communication: {tcpNoDelay: true}, - connector: {noDelay: true}, - collision: {kind: 'Noop', JobStealing: {stealingEnabled: true}, PriorityQueue: {starvationPreventionEnabled: true}}, - failoverSpi: [], - logger: {Log4j: { mode: 'Default'}}, - caches: linkId && _.find($scope.caches, {value: linkId}) ? [linkId] : [], - igfss: linkId && _.find($scope.igfss, {value: linkId}) ? [linkId] : [] - }); - } - - // Add new cluster. - $scope.createItem = function(linkId) { - $timeout(() => LegacyUtils.ensureActivePanel($scope.ui, 'general', 'clusterName')); - - $scope.selectItem(null, prepareNewItem(linkId)); - }; - - $scope.indexOfCache = function(cacheId) { - return _.findIndex($scope.caches, (cache) => cache.value === cacheId); - }; - - function clusterCaches(item) { - return _.filter(_.map($scope.caches, (scopeCache) => scopeCache.cache), - (cache) => _.includes(item.caches, cache._id)); - } - - function checkCacheDatasources(item) { - const caches = clusterCaches(item); - - const checkRes = LegacyUtils.checkCachesDataSources(caches); - - if (!checkRes.checked) { - return showPopoverMessage($scope.ui, 'general', 'caches', - 'Found caches "' + checkRes.firstCache.name + '" and "' + checkRes.secondCache.name + '" ' + - 'with the same data source bean name "' + checkRes.firstCache.cacheStoreFactory[checkRes.firstCache.cacheStoreFactory.kind].dataSourceBean + - '" and different databases: "' + LegacyUtils.cacheStoreJdbcDialectsLabel(checkRes.firstDB) + '" in "' + checkRes.firstCache.name + '" and "' + - LegacyUtils.cacheStoreJdbcDialectsLabel(checkRes.secondDB) + '" in "' + checkRes.secondCache.name + '"', 10000); - } - - return true; - } - - function checkCacheSQLSchemas(item) { - const caches = clusterCaches(item); - - const checkRes = LegacyUtils.checkCacheSQLSchemas(caches); - - if (!checkRes.checked) { - return showPopoverMessage($scope.ui, 'general', 'caches', - 'Found caches "' + checkRes.firstCache.name + '" and "' + checkRes.secondCache.name + '" ' + - 'with the same SQL schema name "' + checkRes.firstCache.sqlSchema + '"', 10000); - } - - return true; - } - - function checkBinaryConfiguration(item) { - const b = item.binaryConfiguration; - - if (LegacyUtils.isDefined(b)) { - if (!_.isEmpty(b.typeConfigurations)) { - for (let typeIx = 0; typeIx < b.typeConfigurations.length; typeIx++) { - const type = b.typeConfigurations[typeIx]; - - if (LegacyUtils.isEmptyString(type.typeName)) - return showPopoverMessage($scope.ui, 'binary', 'typeName' + typeIx, 'Type name should be specified!'); - - if (_.find(b.typeConfigurations, (t, ix) => ix < typeIx && t.typeName === type.typeName)) - return showPopoverMessage($scope.ui, 'binary', 'typeName' + typeIx, 'Type with such name is already specified!'); - } - } - } - - return true; - } - - function checkCommunicationConfiguration(item) { - const c = item.communication; - - if (LegacyUtils.isDefined(c)) { - if (LegacyUtils.isDefined(c.unacknowledgedMessagesBufferSize)) { - if (LegacyUtils.isDefined(c.messageQueueLimit) && c.unacknowledgedMessagesBufferSize < 5 * c.messageQueueLimit) - return showPopoverMessage($scope.ui, 'communication', 'unacknowledgedMessagesBufferSize', 'Maximum number of stored unacknowledged messages should be at least 5 * message queue limit!'); - - if (LegacyUtils.isDefined(c.ackSendThreshold) && c.unacknowledgedMessagesBufferSize < 5 * c.ackSendThreshold) - return showPopoverMessage($scope.ui, 'communication', 'unacknowledgedMessagesBufferSize', 'Maximum number of stored unacknowledged messages should be at least 5 * ack send threshold!'); - } - - if (c.sharedMemoryPort === 0) - return showPopoverMessage($scope.ui, 'communication', 'sharedMemoryPort', 'Shared memory port should be more than "0" or equals to "-1"!'); - } - - return true; - } - - function checkDiscoveryConfiguration(item) { - const d = item.discovery; - - if (d) { - if ((_.isNil(d.maxAckTimeout) ? 600000 : d.maxAckTimeout) < (d.ackTimeout || 5000)) - return showPopoverMessage($scope.ui, 'discovery', 'ackTimeout', 'Acknowledgement timeout should be less than max acknowledgement timeout!'); - - if (d.kind === 'Vm' && d.Vm && d.Vm.addresses.length === 0) - return showPopoverMessage($scope.ui, 'general', 'addresses', 'Addresses are not specified!'); - } - - return true; - } - - function checkSwapConfiguration(item) { - const swapKind = item.swapSpaceSpi && item.swapSpaceSpi.kind; - - if (swapKind && item.swapSpaceSpi[swapKind]) { - const swap = item.swapSpaceSpi[swapKind]; - - const sparsity = swap.maximumSparsity; - - if (LegacyUtils.isDefined(sparsity) && (sparsity < 0 || sparsity >= 1)) - return showPopoverMessage($scope.ui, 'swap', 'maximumSparsity', 'Maximum sparsity should be more or equal 0 and less than 1!'); - - const readStripesNumber = swap.readStripesNumber; - - if (readStripesNumber && !(readStripesNumber === -1 || (readStripesNumber & (readStripesNumber - 1)) === 0)) - return showPopoverMessage($scope.ui, 'swap', 'readStripesNumber', 'Read stripe size must be positive and power of two!'); - } - - return true; - } - - function checkSslConfiguration(item) { - const r = item.connector; - - if (LegacyUtils.isDefined(r)) { - if (r.sslEnabled && LegacyUtils.isEmptyString(r.sslFactory)) - return showPopoverMessage($scope.ui, 'connector', 'connectorSslFactory', 'SSL factory should not be empty!'); - } - - if (item.sslEnabled) { - if (!LegacyUtils.isDefined(item.sslContextFactory) || LegacyUtils.isEmptyString(item.sslContextFactory.keyStoreFilePath)) - return showPopoverMessage($scope.ui, 'sslConfiguration', 'keyStoreFilePath', 'Key store file should not be empty!'); - - if (LegacyUtils.isEmptyString(item.sslContextFactory.trustStoreFilePath) && _.isEmpty(item.sslContextFactory.trustManagers)) - return showPopoverMessage($scope.ui, 'sslConfiguration', 'sslConfiguration-title', 'Trust storage file or managers should be configured!'); - } - - return true; - } - - function checkPoolSizes(item) { - if (item.rebalanceThreadPoolSize && item.systemThreadPoolSize && item.systemThreadPoolSize <= item.rebalanceThreadPoolSize) - return showPopoverMessage($scope.ui, 'pools', 'rebalanceThreadPoolSize', 'Rebalance thread pool size exceed or equals System thread pool size!'); - - return true; - } - - // Check cluster logical consistency. - function validate(item) { - LegacyUtils.hidePopover(); - - if (LegacyUtils.isEmptyString(item.name)) - return showPopoverMessage($scope.ui, 'general', 'clusterName', 'Cluster name should not be empty!'); - - if (!LegacyUtils.checkFieldValidators($scope.ui)) - return false; - - if (!checkCacheSQLSchemas(item)) - return false; - - if (!checkCacheDatasources(item)) - return false; - - if (!checkBinaryConfiguration(item)) - return false; - - if (!checkCommunicationConfiguration(item)) - return false; - - if (!checkDiscoveryConfiguration(item)) - return false; - - if (!checkSwapConfiguration(item)) - return false; - - if (!checkSslConfiguration(item)) - return false; - - if (!checkPoolSizes(item)) - return false; - - return true; - } - - // Save cluster in database. - function save(item) { - $http.post('/api/v1/configuration/clusters/save', item) - .success(function(_id) { - item.label = _clusterLbl(item); - - $scope.ui.inputForm.$setPristine(); - - const idx = _.findIndex($scope.clusters, (cluster) => cluster._id === _id); - - if (idx >= 0) - angular.merge($scope.clusters[idx], item); - else { - item._id = _id; - $scope.clusters.push(item); - } - - _.forEach($scope.caches, (cache) => { - if (_.includes(item.caches, cache.value)) - cache.cache.clusters = _.union(cache.cache.clusters, [_id]); - else - _.remove(cache.cache.clusters, (id) => id === _id); - }); - - _.forEach($scope.igfss, (igfs) => { - if (_.includes(item.igfss, igfs.value)) - igfs.igfs.clusters = _.union(igfs.igfs.clusters, [_id]); - else - _.remove(igfs.igfs.clusters, (id) => id === _id); - }); - - $scope.selectItem(item); - - Messages.showInfo('Cluster "' + item.name + '" saved.'); - }) - .error(Messages.showError); - } - - // Save cluster. - $scope.saveItem = function() { - const item = $scope.backupItem; - - const swapSpi = LegacyUtils.autoClusterSwapSpiConfiguration(item, clusterCaches(item)); - - if (swapSpi) - angular.extend(item, swapSpi); - - if (validate(item)) - save(item); - }; - - function _clusterNames() { - return _.map($scope.clusters, (cluster) => cluster.name); - } - - // Clone cluster with new name. - $scope.cloneItem = function() { - if (validate($scope.backupItem)) { - Clone.confirm($scope.backupItem.name, _clusterNames()).then(function(newName) { - const item = angular.copy($scope.backupItem); - - delete item._id; - item.name = newName; - - save(item); - }); - } - }; - - // Remove cluster from db. - $scope.removeItem = function() { - const selectedItem = $scope.selectedItem; - - Confirm.confirm('Are you sure you want to remove cluster: "' + selectedItem.name + '"?') - .then(function() { - const _id = selectedItem._id; - - $http.post('/api/v1/configuration/clusters/remove', {_id}) - .success(function() { - Messages.showInfo('Cluster has been removed: ' + selectedItem.name); - - const clusters = $scope.clusters; - - const idx = _.findIndex(clusters, (cluster) => cluster._id === _id); - - if (idx >= 0) { - clusters.splice(idx, 1); - - if (clusters.length > 0) - $scope.selectItem(clusters[0]); - else { - $scope.backupItem = emptyCluster; - $scope.ui.inputForm.$setPristine(); - } - - _.forEach($scope.caches, (cache) => _.remove(cache.cache.clusters, (id) => id === _id)); - _.forEach($scope.igfss, (igfs) => _.remove(igfs.igfs.clusters, (id) => id === _id)); - } - }) - .error(Messages.showError); - }); - }; - - // Remove all clusters from db. - $scope.removeAllItems = function() { - Confirm.confirm('Are you sure you want to remove all clusters?') - .then(function() { - $http.post('/api/v1/configuration/clusters/remove/all') - .success(() => { - Messages.showInfo('All clusters have been removed'); - - $scope.clusters = []; - - _.forEach($scope.caches, (cache) => cache.cache.clusters = []); - _.forEach($scope.igfss, (igfs) => igfs.igfs.clusters = []); - - $scope.backupItem = emptyCluster; - $scope.ui.inputForm.$setPristine(); - }) - .error(Messages.showError); - }); - }; - - $scope.resetAll = function() { - Confirm.confirm('Are you sure you want to undo all changes for current cluster?') - .then(function() { - $scope.backupItem = $scope.selectedItem ? angular.copy($scope.selectedItem) : prepareNewItem(); - $scope.ui.inputForm.$setPristine(); - }); - }; - } -]];
