1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | 1 1 1 1 1 2 2 2 3 3 3 1 1 1 9 9 6 60 60 60 12 4 8 4 4 4 48 10 38 9 2 7 20 16 4 3 3 2 2 2 2 2 2 6 6 2 1 3 3 2 2 1 | 'use strict'; ;require.register("views/main/admin/stack_upgrade/versions_view", function (exports, require, module) { /** * 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 stringUtils = require('utils/string_utils'); App.MainAdminStackVersionsView = Em.View.extend({ templateName: require('templates/main/admin/stack_upgrade/versions'), /** * update timer * @type {number|null} * @default null */ updateTimer: null, /** * @type {Array} */ services: App.Service.find(), /** * Not Installed = the version is not installed or out of sync * Upgrade Ready = the version is installed and ready for upgrade * Current = the version currently being used * Upgrade in Process = UPGRADING * Ready to Finalize = UPGRADED * Installed = All the versions that are installed BUT cannot be upgraded to (meaning: they are lower than the current) * @type {Array} */ categories: [Em.Object.create({ labelKey: 'admin.stackVersions.filter.all', value: '', isSelected: true }), Em.Object.create({ labelKey: 'admin.stackVersions.filter.notInstalled', value: 'NOT_INSTALLED', isSelected: false }), Em.Object.create({ labelKey: 'admin.stackVersions.filter.upgradeReady', value: 'UPGRADE_READY', isSelected: false }), Em.Object.create({ labelKey: 'admin.stackVersions.filter.current', value: 'CURRENT', isSelected: false }), Em.Object.create({ labelKey: 'admin.stackVersions.filter.installed', value: 'INSTALLED', isSelected: false }), Em.Object.create({ labelKey: 'admin.stackVersions.filter.upgrading', value: 'UPGRADING', isSelected: false }), Em.Object.create({ labelKey: 'admin.stackVersions.filter.upgraded', value: 'UPGRADED', isSelected: false })], didInsertElement: function didInsertElement() { this.observesCategories(); }, /** * update categories labels */ observesCategories: function () { this.get('categories').forEach(function (category) { category.set('label', Em.I18n.t(category.labelKey).format(this.filterBy(this.get('repoVersions'), category).length)); }, this); this.filterVersions(this.get('selectedCategory')); }.observes('repoVersions.@each.stackVersion.state', 'controller.isLoaded'), /** * select category * @param event */ selectCategory: function selectCategory(event) { this.get('categories').filterProperty('isSelected').setEach('isSelected', false); event.context.set('isSelected', true); this.filterVersions(event.context); }, /** * filter versions that match category * @param {Em.Object} category */ filterVersions: function filterVersions(category) { var filteredVersionIds = this.filterBy(this.get('repoVersions'), category).mapProperty('id'); this.get('repoVersions').forEach(function (version) { version.set('isVisible', filteredVersionIds.contains(version.get('id'))); }); }, /** * @type {object} */ selectedCategory: Em.computed.findBy('categories', 'isSelected', true), /** * @type {Em.Array} */ repoVersions: App.RepositoryVersion.find(), hasMaintRepoVersion: Em.computed.someBy('repoVersions', 'isMaint', true), hasPatchRepoVersion: Em.computed.someBy('repoVersions', 'isPatch', true), hasServiceRepoVersion: Em.computed.someBy('repoVersions', 'isService', true), hasSpecialTypeRepoVersion: Em.computed.or('hasMaintRepoVersion', 'hasPatchRepoVersion', 'hasServiceRepoVersion'), /** * @type {Em.Array} */ stackVersions: App.StackVersion.find(), /** * @type {?Em.Object} */ stackVersionError: function () { var errorStack = this.get('repoVersions').filterProperty('isVisible').filterProperty('status', 'OUT_OF_SYNC').findProperty('isStandard'); if (errorStack) { return Em.Object.create({ repoId: errorStack.get('id'), title: Em.I18n.t('admin.stackVersions.version.errors.outOfSync.title'), description: Em.I18n.t('admin.stackVersions.version.errors.outOfSync.desc'), stack: errorStack.get('displayNameFull') }); } return null; }.property('repoVersions.@each.status'), /** * filter versions by category * @param versions * @param filter * @return {Array} */ filterBy: function filterBy(versions, filter) { var currentVersion = this.get('controller.currentVersion'); if (filter && filter.get('value')) { versions = versions.filter(function (version) { var status = version.get('status'); var isUpgrading = this.isVersionUpgrading(version); if (status === 'INSTALLED' && ['UPGRADE_READY', 'INSTALLED', 'UPGRADING'].contains(filter.get('value'))) { if (filter.get('value') === 'UPGRADING') { return isUpgrading; } else if (filter.get('value') === 'UPGRADE_READY') { return !isUpgrading && stringUtils.compareVersions(version.get('repositoryVersion'), Em.get(currentVersion, 'repository_version')) === 1; } else Eif (filter.get('value') === 'INSTALLED') { return stringUtils.compareVersions(version.get('repositoryVersion'), Em.get(currentVersion, 'repository_version')) < 1; } } else if (filter.get('value') === 'NOT_INSTALLED') { return ['NOT_REQUIRED', 'INSTALL_FAILED', 'INSTALLING', 'OUT_OF_SYNC'].contains(status); } else { return status === filter.get('value'); } }, this); } if (App.get('supports.displayOlderVersions') || Em.isNone(currentVersion)) { return versions.filterProperty('hidden', false).toArray(); } else { return versions.filterProperty('hidden', false).filter(function (v) { if (v.get('stackVersionType') === Em.get(currentVersion, 'stack_name')) { // PATCH or MAINT version should be visible even if patch number lower than current return v.get('isPatch') || v.get('isMaint') || stringUtils.compareVersions(v.get('repositoryVersion'), Em.get(currentVersion, 'repository_version')) >= 0; } return v.get('isCompatible'); }).toArray(); } }, /** * is version in upgrading or downgrading state * @param version */ isVersionUpgrading: function isVersionUpgrading(version) { var upgradeController = App.router.get('mainAdminStackAndUpgradeController'); return upgradeController.get('upgradeVersion') === version.get('displayName') || upgradeController.get('fromVersion') === version.get('repositoryVersion'); }, /** * route to versions in Admin View * @return {App.ModalPopup} */ goToVersions: function goToVersions() { var self = this; return App.showConfirmationPopup(function () { App.ajax.send({ name: 'ambari.service.load_server_version', sender: self }).then(function (data) { var components = Em.get(data, 'components'); Eif (Em.isArray(components)) { var mappedVersions = components.map(function (component) { Eif (Em.get(component, 'RootServiceComponents.component_version')) { return Em.get(component, 'RootServiceComponents.component_version'); } }), sortedMappedVersions = mappedVersions.sort(), latestVersion = sortedMappedVersions[sortedMappedVersions.length - 1].replace(/[^\d.-]/g, ''); window.location.replace(App.appURLRoot + 'views/ADMIN_VIEW/' + latestVersion + '/INSTANCE/#/stackVersions'); } }); }, Em.I18n.t('admin.stackVersions.manageVersions.popup.body'), null, Em.I18n.t('admin.stackVersions.manageVersions')); }, /** * load ClusterStackVersions data */ willInsertElement: function willInsertElement() { this.poll(); }, /** * stop polling upgrade state */ willDestroyElement: function willDestroyElement() { window.clearTimeout(this.get('updateTimer')); App.ajax.abortRequests(this.get('controller.runningCheckRequests')); }, /** * set timer for polling */ doPolling: function doPolling() { var self = this; this.set('updateTimer', window.setTimeout(function () { self.poll.apply(self); }, App.bgOperationsUpdateInterval)); }, /** * poll data */ poll: function poll() { var self = this; //skip call if Upgrade wizard opened if (App.router.get('updateController').get('isWorking')) { this.get('controller').load().done(function () { self.set('controller.isLoaded', true); self.doPolling(); }); } } }); }); |