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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | 1 1 1 1 1 1 2 4 1 1 1 14 4 4 10 5 5 5 5 20 1 1 2 2 2 2 2 2 1 1 1 1 1 1 1 2 1 1 1 1 3 3 2 1 2 1 1 1 2 2 2 1 1 3 3 3 3 4 1 3 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 4 4 4 4 2 4 2 2 2 2 2 2 2 2 1 2 20 20 20 15 5 15 15 20 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 6 6 6 6 1 5 5 5 5 5 5 5 5 10 10 | 'use strict'; ;require.register("controllers/main/service/manage_config_groups_controller", 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 validator = require('utils/validator'); var hostsManagement = require('utils/hosts'); var numberUtils = require('utils/number_utils'); App.ManageConfigGroupsController = Em.Controller.extend(App.ConfigOverridable, { name: 'manageConfigGroupsController', /** * Determines if needed data is already loaded * Loading chain starts at <code>loadHosts</code> and is complete on the <code>loadConfigGroups</code> (if user on * the Installer) or on the <code>_onLoadConfigGroupsSuccess</code> (otherwise) * @type {boolean} */ isLoaded: false, /** * Determines if user currently is on the Cluster Installer * @type {boolean} */ isInstaller: false, /** * Determines if user currently is on the Add Service Wizard * @type {boolean} */ isAddService: false, /** * Current service name * @type {string} */ serviceName: null, /** * @type {App.ConfigGroup[]} */ configGroups: [], /** * @type {App.ConfigGroup[]} */ originalConfigGroups: [], /** * @type {App.ConfigGroup} */ selectedConfigGroup: null, /** * @type {string[]} */ selectedHosts: [], /** * List of all hosts in the cluster * @type {{ * id: string, * ip: string, * osType: string, * osArch: string, * hostName: string, * publicHostName: string, * cpu: number, * memory: number, * diskTotal: string, * diskFree: string, * disksMounted: number, * hostComponents: { * componentName: string, * displayName: string * }[] * }[]} */ clusterHosts: [], /** * trigger <code>selectDefaultGroup</code> after group delete * @type {null} */ groupDeleteTrigger: null, /** * List of available service components for <code>serviceName</code> * @type {{componentName: string, displayName: string, selected: boolean}[]} */ componentsForFilter: function () { return App.StackServiceComponent.find().filterProperty('serviceName', this.get('serviceName')).map(function (component) { return Em.Object.create({ componentName: component.get('componentName'), displayName: App.format.role(component.get('componentName'), false), selected: false }); }); }.property('serviceName'), /** * Determines when host may be deleted from config group * @type {boolean} */ isDeleteHostsDisabled: function () { var selectedConfigGroup = this.get('selectedConfigGroup'); Eif (selectedConfigGroup) { return selectedConfigGroup.get('isDefault') || this.get('selectedHosts').length === 0; } return true; }.property('selectedConfigGroup', 'selectedConfigGroup.hosts.length', 'selectedHosts.length'), /** * Map with modified/deleted/created config groups * @type {{ * toClearHosts: App.ConfigGroup[], * toDelete: App.ConfigGroup[], * toSetHosts: App.ConfigGroup[], * toCreate: App.ConfigGroup[] * }} */ hostsModifiedConfigGroups: {}, /** * Trim the tooltip text to show first 500 characters of properties list * @type {string} */ tooltipText: function () { var selectedConfigGroup = this.get('selectedConfigGroup'), propertiesList = selectedConfigGroup.get('propertiesList'), trimLength = 500, trimmedText = "", noOfRemainingProperties = 0, index = 0, propertyText = "", addDots = false; if (propertiesList.length > trimLength) { // Adjust trim length based on occurrence of <br/> around trim length index = propertiesList.substring(trimLength - 10, trimLength + 10).indexOf("<br/>"); if (index > -1) { trimLength = trimLength - 10 + index; } else { addDots = true; } trimmedText = propertiesList.substring(0, trimLength); if (addDots) { trimmedText += " ..."; } noOfRemainingProperties = (propertiesList.substring(trimLength).match(new RegExp("<br/>", "g")) || []).length - 1; if (noOfRemainingProperties > 0) { propertyText = noOfRemainingProperties > 1 ? "properties" : "property"; trimmedText += "<br/> and " + noOfRemainingProperties + " more " + propertyText; } } else { trimmedText = propertiesList; } return trimmedText; }.property('selectedConfigGroup.propertiesList'), /** * Check when some config group was changed and updates <code>hostsModifiedConfigGroups</code> once * @method hostsModifiedConfigGroupsObs */ hostsModifiedConfigGroupsObs: function () { Em.run.once(this, this.hostsModifiedConfigGroupsObsOnce); }.observes('selectedConfigGroup.hosts.@each', 'selectedConfigGroup.hosts.length', 'selectedConfigGroup.description', 'configGroups', 'isLoaded'), /** * Update <code>hostsModifiedConfigGroups</code>-value * Called once in the <code>hostsModifiedConfigGroupsObs</code> * @method hostsModifiedConfigGroupsObsOnce * @returns {boolean} */ hostsModifiedConfigGroupsObsOnce: function hostsModifiedConfigGroupsObsOnce() { Eif (!this.get('isLoaded')) { return false; } var groupsToClearHosts = []; var groupsToDelete = []; var groupsToSetHosts = []; var groupsToCreate = []; var groups = this.get('configGroups'); var originalGroups = []; var originalGroupsMap = {}; this.get('originalConfigGroups').forEach(function (item) { if (!item.is_default) { originalGroupsMap[item.id] = item; originalGroups.push(item); } }, this); groups.forEach(function (groupRecord) { if (!groupRecord.get('isDefault')) { var originalGroup = originalGroupsMap[groupRecord.get('id')]; if (originalGroup) { if (!(JSON.stringify(groupRecord.get('hosts').slice().sort()) === JSON.stringify(originalGroup.hosts.sort()))) { groupsToClearHosts.push(groupRecord); if (groupRecord.get('hosts').length) { groupsToSetHosts.push(groupRecord); } // should update name or description } else if (groupRecord.get('description') !== originalGroup.description || groupRecord.get('name') !== originalGroup.name) { groupsToSetHosts.push(groupRecord); } delete originalGroupsMap[groupRecord.get('id')]; } else { groupsToCreate.push({ id: groupRecord.get('id'), name: groupRecord.get('name'), description: groupRecord.get('description'), hosts: groupRecord.get('hosts').slice(0), service_id: groupRecord.get('serviceName'), desired_configs: groupRecord.get('desiredConfigs'), properties: groupRecord.get('properties') }); } } }); //groups to delete for (var id in originalGroupsMap) { groupsToDelete.push(App.ServiceConfigGroup.find(id)); } this.set('hostsModifiedConfigGroups', { toClearHosts: groupsToClearHosts, toDelete: groupsToDelete, toSetHosts: groupsToSetHosts, toCreate: groupsToCreate, initialGroups: originalGroups }); }, /** * Determines if some changes were done with config groups * @use hostsModifiedConfigGroups * @type {boolean} */ isHostsModified: function () { if (!this.get('isLoaded')) { return false; } var ignoreKeys = ['initialGroups']; var modifiedGroups = this.get('hostsModifiedConfigGroups'); return Em.keys(modifiedGroups).map(function (key) { return ignoreKeys.contains(key) ? 0 : Em.get(modifiedGroups[key], 'length'); }).reduce(Em.sum, 0) > 0; }.property('hostsModifiedConfigGroups'), /** * Resort config groups according to order: * default group first, other - last * @method resortConfigGroup */ resortConfigGroup: function () { var configGroups = Em.copy(this.get('configGroups')); Eif (configGroups.length < 2) return; var defaultConfigGroup = configGroups.findProperty('isDefault'); configGroups.removeObject(defaultConfigGroup); var sorted = [defaultConfigGroup].concat(configGroups.sortProperty('name')); this.removeObserver('configGroups.@each.name', this, 'resortConfigGroup'); this.set('configGroups', sorted); this.addObserver('configGroups.@each.name', this, 'resortConfigGroup'); }.observes('configGroups.@each.name'), /** * Load hosts from server or * get them from installerController if user on the install wizard * get them from isAddServiceController if user on the add service wizard * @method loadHosts */ loadHosts: function loadHosts() { this.set('isLoaded', false); Iif (this.get('isInstaller') && !this.get('isAddService')) { var hostNames = App.router.get('installerController').get('allHosts').mapProperty('hostName').join(); this.loadInstallerHostsFromServer(hostNames); } else { this.loadHostsFromServer(); } this.loadConfigGroups(this.get('serviceName')); }, /** * Request all hosts directly from server * @method loadHostsFromServer * @return {$.ajax} */ loadHostsFromServer: function loadHostsFromServer() { return App.ajax.send({ name: 'hosts.config_groups', sender: this, data: {}, success: '_loadHostsFromServerSuccessCallback', error: '_loadHostsFromServerErrorCallback' }); }, /** * Success-callback for <code>loadHostsFromServer</code> * Parse hosts response and wrap them into Ember.Object * @param {object} data * @method _loadHostsFromServerSuccessCallback * @private */ _loadHostsFromServerSuccessCallback: function _loadHostsFromServerSuccessCallback(data) { var wrappedHosts = [], newlyAddedHostComponentsMap = this.getNewlyAddedHostComponentsMap(); data.items.forEach(function (host) { var hostComponents = []; var diskInfo = host.Hosts.disk_info.filter(function (item) { return (/^ext|^ntfs|^fat|^xfs/i.test(item.type) ); }); if (diskInfo.length) { diskInfo = diskInfo.reduce(function (a, b) { return { available: parseInt(a.available) + parseInt(b.available), size: parseInt(a.size) + parseInt(b.size) }; }); } host.host_components.forEach(function (hostComponent) { hostComponents.push(Em.Object.create({ componentName: hostComponent.HostRoles.component_name, displayName: App.format.role(hostComponent.HostRoles.component_name, false) })); }, this); if (this.get('isAddService') && newlyAddedHostComponentsMap[host.Hosts.host_name]) { hostComponents.pushObjects(newlyAddedHostComponentsMap[host.Hosts.host_name]); } wrappedHosts.pushObject(Em.Object.create({ id: host.Hosts.host_name, ip: host.Hosts.ip, osType: host.Hosts.os_type, osArch: host.Hosts.os_arch, hostName: host.Hosts.host_name, publicHostName: host.Hosts.public_host_name, cpu: host.Hosts.cpu_count, memory: host.Hosts.total_mem, diskTotal: numberUtils.bytesToSize(diskInfo.size, 0, undefined, 1024), diskFree: numberUtils.bytesToSize(diskInfo.available, 0, undefined, 1024), disksMounted: host.Hosts.disk_info.length, hostComponents: hostComponents })); }, this); this.set('clusterHosts', wrappedHosts); }, /** * Error-callback for <code>loadHostsFromServer</code> * @method _loadHostsFromServerErrorCallback * @private */ _loadHostsFromServerErrorCallback: function _loadHostsFromServerErrorCallback() { this.set('clusterHosts', []); }, /** * * @returns {{}} */ getNewlyAddedHostComponentsMap: function getNewlyAddedHostComponentsMap() { var newlyAddedHostComponentsMap = {}; var masters = App.router.get('addServiceController.content.masterComponentHosts') || []; var slaves = App.router.get('addServiceController.content.slaveComponentHosts') || []; var clients = App.router.get('addServiceController.content.clients') || []; clients = clients.filterProperty('isInstalled', false).map(function (component) { return Em.Object.create({ componentName: component.component_name, displayName: component.display_name }); }); masters.forEach(function (component) { if (!component.isInstalled) { Eif (!newlyAddedHostComponentsMap[component.hostName]) { newlyAddedHostComponentsMap[component.hostName] = []; } newlyAddedHostComponentsMap[component.hostName].push(Em.Object.create({ componentName: component.component, displayName: component.display_name })); } }); slaves.forEach(function (component) { component.hosts.forEach(function (host) { if (!host.isInstalled) { if (!newlyAddedHostComponentsMap[host.hostName]) { newlyAddedHostComponentsMap[host.hostName] = []; } if (component.componentName === 'CLIENT') { newlyAddedHostComponentsMap[host.hostName].pushObjects(clients); } else { newlyAddedHostComponentsMap[host.hostName].push(Em.Object.create({ componentName: component.componentName, displayName: component.displayName })); } } }); }); return newlyAddedHostComponentsMap; }, /** * Load config groups from server if user is on the already installed cluster * If not - use loaded data form wizardStep7Controller * @param {string} serviceName * @method loadConfigGroups */ loadConfigGroups: function loadConfigGroups(serviceName) { Iif (this.get('isInstaller')) { var configGroups = App.router.get('wizardStep7Controller.selectedService.configGroups').slice(0); var originalConfigGroups = this.generateOriginalConfigGroups(configGroups); this.setProperties({ configGroups: configGroups, originalConfigGroups: originalConfigGroups, isLoaded: true }); } else { this.set('serviceName', serviceName); App.ajax.send({ name: 'service.load_config_groups', data: { serviceName: serviceName }, sender: this, success: '_onLoadConfigGroupsSuccess' }); } }, /** * Success-callback for <code>loadConfigGroups</code> * @param {object} data * @private * @method _onLoadConfigGroupsSuccess */ _onLoadConfigGroupsSuccess: function _onLoadConfigGroupsSuccess(data) { var serviceName = this.get('serviceName'); App.configGroupsMapper.map(data, false, [serviceName]); var configGroups = App.ServiceConfigGroup.find().filterProperty('serviceName', serviceName); var rawConfigGroups = this.generateOriginalConfigGroups(configGroups); var groupToTypeToTagMap = {}; rawConfigGroups.forEach(function (item) { if (Array.isArray(item.desired_configs)) { item.desired_configs.forEach(function (config) { if (!groupToTypeToTagMap[item.name]) { groupToTypeToTagMap[item.name] = {}; } groupToTypeToTagMap[item.name][config.type] = config.tag; }); } }); this.set('configGroups', configGroups); this.set('originalConfigGroups', rawConfigGroups); this.loadProperties(groupToTypeToTagMap); this.set('isLoaded', true); }, /** * * @param {Array} configGroups * @returns {Array} */ generateOriginalConfigGroups: function generateOriginalConfigGroups(configGroups) { var self = this; return configGroups.map(function (item) { return self.createOriginalRecord(item); }); }, /** * Return object to use for loading to model with correct names for object keys * @param configGroup - config group object from model * @returns {Object} */ createOriginalRecord: function createOriginalRecord(configGroup) { return { id: configGroup.get('id'), name: configGroup.get('name'), service_name: configGroup.get('serviceName'), description: configGroup.get('description'), hosts: configGroup.get('hosts').slice(0), service_id: configGroup.get('serviceName'), desired_configs: configGroup.get('desiredConfigs'), is_default: configGroup.get('isDefault'), child_config_groups: configGroup.get('childConfigGroups') ? configGroup.get('childConfigGroups').mapProperty('id') : [], parent_config_group_id: configGroup.get('parentConfigGroup.id'), properties: configGroup.get('properties') }; }, /** * * @param {object} groupToTypeToTagMap * @method loadProperties */ loadProperties: function loadProperties(groupToTypeToTagMap) { var typeTagToGroupMap = {}; var urlParams = []; for (var group in groupToTypeToTagMap) { var overrideTypeTags = groupToTypeToTagMap[group]; for (var type in overrideTypeTags) { var tag = overrideTypeTags[type]; typeTagToGroupMap[type + "///" + tag] = group; urlParams.push('(type=' + type + '&tag=' + tag + ')'); } } var params = urlParams.join('|'); if (urlParams.length) { App.ajax.send({ name: 'config.host_overrides', sender: this, data: { params: params, typeTagToGroupMap: typeTagToGroupMap }, success: '_onLoadPropertiesSuccess' }); } }, /** * Success-callback for <code>loadProperties</code> * @param {object} data * @param {object} opt * @param {object} params * @private * @method _onLoadPropertiesSuccess */ _onLoadPropertiesSuccess: function _onLoadPropertiesSuccess(data, opt, params) { var groupToPropertiesMap = {}; data.items.forEach(function (configs) { var group = params.typeTagToGroupMap[configs.type + "///" + configs.tag]; Eif (!groupToPropertiesMap[group]) { groupToPropertiesMap[group] = []; } for (var config in configs.properties) { groupToPropertiesMap[group].push({ name: config, value: configs.properties[config], type: configs.type }); } }, this); for (var g in groupToPropertiesMap) { this.get('configGroups').findProperty('name', g).set('properties', groupToPropertiesMap[g]); } }, /** * Show popup with properties overridden in the selected config group * @method showProperties */ showProperties: function showProperties() { var properties = this.get('selectedConfigGroup.propertiesList').htmlSafe(); if (properties) { App.showAlertPopup(Em.I18n.t('services.service.config_groups_popup.properties'), properties); } }, /** * Show popup with hosts to add to the selected config group * @returns {boolean} * @method addHosts */ addHosts: function addHosts() { if (this.get('selectedConfigGroup.isAddHostsDisabled')) { return false; } var availableHosts = this.get('selectedConfigGroup.availableHosts'); var popupDescription = { header: Em.I18n.t('hosts.selectHostsDialog.title'), dialogMessage: Em.I18n.t('hosts.selectHostsDialog.message').format(this.get('selectedConfigGroup.displayName')) }; hostsManagement.launchHostsSelectionDialog(availableHosts, [], false, this.get('componentsForFilter'), this.addHostsCallback.bind(this), popupDescription); }, /** * Remove selected hosts from default group (<code>selectedConfigGroup.parentConfigGroup</code>) and add them to the <code>selectedConfigGroup</code> * @param {string[]} selectedHosts * @method addHostsCallback */ addHostsCallback: function addHostsCallback(selectedHosts) { Eif (selectedHosts) { var sortedHosts; var group = this.get('selectedConfigGroup'); var parentGroupHosts = group.get('parentConfigGroup.hosts'); var newHostsForParentGroup = parentGroupHosts.filter(function (hostName) { return !selectedHosts.contains(hostName); }); group.get('hosts').pushObjects(selectedHosts); sortedHosts = group.get('hosts').sort(); group.set('hosts', sortedHosts); group.set('parentConfigGroup.hosts', newHostsForParentGroup); } }, /** * Delete hosts from <code>selectedConfigGroup</code> and move them to the Default group (<code>selectedConfigGroup.parentConfigGroup</code>) * @method deleteHosts */ deleteHosts: function deleteHosts() { Iif (this.get('isDeleteHostsDisabled')) { return; } var hosts = this.get('selectedHosts').slice(); var newHosts = []; var selectedGroup = this.get('selectedConfigGroup'); var parentGroup = this.get('selectedConfigGroup.parentConfigGroup'); selectedGroup.get('hosts').forEach(function (host) { Iif (!hosts.contains(host)) { newHosts.pushObject(host); } }); selectedGroup.set('hosts', newHosts); parentGroup.set('hosts', parentGroup.get('hosts').pushObjects(hosts).slice().sort()); this.set('selectedHosts', []); }, /** * show popup for confirmation delete config group * @method confirmDelete */ confirmDelete: function confirmDelete() { var self = this; App.showConfirmationPopup(function () { self.deleteConfigGroup(); }); }, /** * delete selected config group (stored in the <code>selectedConfigGroup</code>) * then select default config group * @method deleteConfigGroup */ deleteConfigGroup: function deleteConfigGroup() { var selectedConfigGroup = this.get('selectedConfigGroup'); Iif (this.get('isDeleteGroupDisabled')) { return; } //move hosts of group to default group (available hosts) this.set('selectedHosts', selectedConfigGroup.get('hosts')); this.deleteHosts(); this.get('configGroups').removeObject(selectedConfigGroup); App.configGroupsMapper.deleteRecord(selectedConfigGroup); this.set('selectedConfigGroup', this.get('configGroups').findProperty('isDefault')); this.propertyDidChange('groupDeleteTrigger'); }, /** * rename new config group (not allowed for default group) * @method renameConfigGroup */ renameConfigGroup: function renameConfigGroup() { Iif (this.get('selectedConfigGroup.isDefault')) { return; } var self = this; var renameGroupPopup = App.ModalPopup.show({ header: Em.I18n.t('services.service.config_groups.rename_config_group_popup.header'), bodyClass: Em.View.extend({ templateName: require('templates/main/service/new_config_group') }), configGroupName: self.get('selectedConfigGroup.name'), configGroupDesc: self.get('selectedConfigGroup.description'), warningMessage: null, isDescriptionDirty: false, validate: function () { var warningMessage = ''; var originalGroup = self.get('selectedConfigGroup'); var groupName = this.get('configGroupName').trim(); Iif (originalGroup.get('description') !== this.get('configGroupDesc') && !this.get('isDescriptionDirty')) { this.set('isDescriptionDirty', true); } Iif (originalGroup.get('name').trim() === groupName) { if (this.get('isDescriptionDirty')) { warningMessage = ''; } else { warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists"); } } else { Iif (self.get('configGroups').mapProperty('name').contains(groupName)) { warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists"); } else if (groupName && !validator.isValidConfigGroupName(groupName)) { warningMessage = Em.I18n.t("form.validator.configGroupName"); } } this.set('warningMessage', warningMessage); }.observes('configGroupName', 'configGroupDesc'), disablePrimary: function () { return !(this.get('configGroupName').trim().length > 0 && this.get('warningMessage') !== null && !this.get('warningMessage')); }.property('warningMessage', 'configGroupName', 'configGroupDesc'), onPrimary: function onPrimary() { self.get('selectedConfigGroup').setProperties({ name: this.get('configGroupName'), description: this.get('configGroupDesc') }); App.store.fastCommit(); this.hide(); } }); this.set('renameGroupPopup', renameGroupPopup); }, /** * add new config group (or copy existing) * @param {boolean} duplicated true - copy <code>selectedConfigGroup</code>, false - create a new one * @method addConfigGroup */ addConfigGroup: function addConfigGroup(duplicated) { duplicated = duplicated === true; var self = this; var addGroupPopup = App.ModalPopup.show({ header: Em.I18n.t('services.service.config_groups.add_config_group_popup.header'), bodyClass: Em.View.extend({ templateName: require('templates/main/service/new_config_group') }), configGroupName: duplicated ? self.get('selectedConfigGroup.name') + ' Copy' : "", configGroupDesc: duplicated ? self.get('selectedConfigGroup.description') + ' (Copy)' : "", warningMessage: '', didInsertElement: function didInsertElement() { this._super(); this.validate(); this.$('input').focus(); }, validate: function () { var warningMessage = ''; var groupName = this.get('configGroupName').trim(); Iif (self.get('configGroups').mapProperty('name').contains(groupName)) { warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists"); } else if (groupName && !validator.isValidConfigGroupName(groupName)) { warningMessage = Em.I18n.t("form.validator.configGroupName"); } this.set('warningMessage', warningMessage); }.observes('configGroupName'), disablePrimary: function () { return !(this.get('configGroupName').trim().length > 0 && !this.get('warningMessage')); }.property('warningMessage', 'configGroupName'), onPrimary: function onPrimary() { var defaultConfigGroup = self.get('configGroups').findProperty('isDefault'), properties = [], serviceName = self.get('serviceName'), groupName = this.get('configGroupName').trim(), newGroupId = new Date().getTime(); if (duplicated) { self.get('selectedConfigGroup.properties').forEach(function (item) { var property = App.ServiceConfigProperty.create($.extend(false, {}, item)); property.set('group', App.ServiceConfigGroup.find(newGroupId)); properties.push(property); }); } App.store.safeLoad(App.ServiceConfigGroup, { id: newGroupId, name: groupName, description: this.get('configGroupDesc'), isDefault: false, parent_config_group_id: App.ServiceConfigGroup.getParentConfigGroupId(serviceName), service_id: serviceName, service_name: serviceName, hosts: [], desired_configs: duplicated ? self.get('selectedConfigGroup.desiredConfigs') : [], properties: duplicated ? properties : [], is_temporary: true }); App.store.fastCommit(); var childConfigGroups = defaultConfigGroup.get('childConfigGroups').mapProperty('id'); childConfigGroups.push(newGroupId); App.store.safeLoad(App.ServiceConfigGroup, App.configGroupsMapper.generateDefaultGroup(self.get('serviceName'), defaultConfigGroup.get('hosts'), childConfigGroups)); App.store.fastCommit(); self.get('configGroups').pushObject(App.ServiceConfigGroup.find(newGroupId)); this.hide(); } }); this.set('addGroupPopup', addGroupPopup); }, /** * Duplicate existing config group * @method duplicateConfigGroup */ duplicateConfigGroup: function duplicateConfigGroup() { this.addConfigGroup(true); }, /** * Show popup with config groups * User may edit/create/delete them * @param {Em.Controller} controller * @param {App.Service} service * @returns {App.ModalPopup} * @method manageConfigurationGroups */ manageConfigurationGroups: function manageConfigurationGroups(controller, service) { var configsController = this; var serviceData = controller && controller.get('selectedService') || service; var serviceName = serviceData.get('serviceName'); var displayName = serviceData.get('displayName'); this.setProperties({ isInstaller: !!controller, serviceName: serviceName }); if (controller) { configsController.set('isAddService', controller.get('content.controllerName') == 'addServiceController'); } return App.ModalPopup.show({ header: Em.I18n.t('services.service.config_groups_popup.header').format(displayName), bodyClass: App.MainServiceManageConfigGroupView.extend({ serviceName: serviceName, displayName: displayName, controller: configsController }), classNames: ['common-modal-wrapper', 'manage-configuration-group-popup'], modalDialogClasses: ['modal-lg'], primary: Em.I18n.t('common.save'), autoHeight: false, subViewController: configsController, /** * handle onPrimary action particularly in wizard * @param {Em.Controller} controller * @param {object} modifiedConfigGroups */ onPrimaryWizard: function onPrimaryWizard(controller, modifiedConfigGroups) { controller.set('selectedService.configGroups', configsController.get('configGroups')); controller.selectedServiceObserver(); if (controller.get('name') == "wizardStep7Controller") { if (controller.get('selectedService.selected') === false && modifiedConfigGroups.toDelete.length > 0) { controller.setGroupsToDelete(modifiedConfigGroups.toDelete); } configsController.persistConfigGroups(); this.updateConfigGroupOnServicePage(); } this.hide(); }, onClose: function onClose() { //<code>_super</code> has to be called before <code>resetGroupChanges</code> var originalGroups = this.get('subViewController.originalConfigGroups').slice(0); this._super(); this.resetGroupChanges(originalGroups); }, onSecondary: function onSecondary() { this.onClose(); }, /** * reset group changes made by user * @param {Array} originalGroups */ resetGroupChanges: function resetGroupChanges(originalGroups) { if (this.get('subViewController.isHostsModified')) { App.ServiceConfigGroup.find().clear(); App.store.safeLoadMany(App.ServiceConfigGroup, originalGroups); } }, /** * run requests which delete config group and clear its hosts * @param {Function} finishFunction * @param {object} modifiedConfigGroups */ runClearCGQueue: function runClearCGQueue(finishFunction, modifiedConfigGroups) { var counter = 0; var dfd = $.Deferred(); var doneFunction = function doneFunction(xhr, text, errorThrown) { counter--; if (counter === 0) dfd.resolve(); finishFunction(xhr, text, errorThrown); }; modifiedConfigGroups.toClearHosts.forEach(function (cg) { counter++; configsController.updateConfigurationGroup(cg, doneFunction, doneFunction); }, this); modifiedConfigGroups.toDelete.forEach(function (cg) { counter++; configsController.deleteConfigurationGroup(cg, doneFunction, doneFunction); }, this); Iif (counter === 0) dfd.resolve(); return dfd.promise(); }, /** * run requests which change properties of config group * @param {Function} finishFunction * @param {object} modifiedConfigGroups */ runModifyCGQueue: function runModifyCGQueue(finishFunction, modifiedConfigGroups) { var counter = 0; var dfd = $.Deferred(); var doneFunction = function doneFunction(xhr, text, errorThrown) { counter--; if (counter === 0) dfd.resolve(); finishFunction(xhr, text, errorThrown); }; modifiedConfigGroups.toSetHosts.forEach(function (cg) { counter++; configsController.updateConfigurationGroup(cg, doneFunction, doneFunction); }, this); Iif (counter === 0) dfd.resolve(); return dfd.promise(); }, /** * run requests which create new config group * @param {Function} finishFunction * @param {object} modifiedConfigGroups */ runCreateCGQueue: function runCreateCGQueue(finishFunction, modifiedConfigGroups) { var counter = 0; var dfd = $.Deferred(); var doneFunction = function doneFunction(xhr, text, errorThrown) { counter--; if (counter === 0) dfd.resolve(); finishFunction(xhr, text, errorThrown); }; modifiedConfigGroups.toCreate.forEach(function (cg) { counter++; configsController.postNewConfigurationGroup(cg, doneFunction); }, this); Iif (counter === 0) dfd.resolve(); return dfd.promise(); }, onPrimary: function onPrimary() { var modifiedConfigGroups = configsController.get('hostsModifiedConfigGroups'); var errors = []; var self = this; var finishFunction = function finishFunction(xhr, text, errorThrown) { if (xhr && typeof errorThrown === 'string') { var error = xhr.status + "(" + errorThrown + ") "; try { var json = $.parseJSON(xhr.responseText); error += json.message; } catch (err) {} errors.push(error); } }; // Save modified config-groups if (controller) { //called only in Wizard return this.onPrimaryWizard(controller, modifiedConfigGroups); } this.runClearCGQueue(finishFunction, modifiedConfigGroups).done(function () { self.runModifyCGQueue(finishFunction, modifiedConfigGroups).done(function () { self.runCreateCGQueue(finishFunction, modifiedConfigGroups).done(function () { Iif (errors.length > 0) { self.get('subViewController').set('errorMessage', errors.join(". ")); } else { Eif (!self.get('isAddService') && !self.get('isInstaller')) { //update service config versions only if it is service configs page App.router.get('mainServiceInfoConfigsController').loadServiceConfigVersions().done(function () { self.updateConfigGroupOnServicePage(); self.hide(); }); } else { self.updateConfigGroupOnServicePage(); self.hide(); } } }); }); }); }, updateConfigGroupOnServicePage: function updateConfigGroupOnServicePage() { var selectedConfigGroup = configsController.get('selectedConfigGroup'); var managedConfigGroups = configsController.get('configGroups').slice(0); if (!controller) { controller = App.router.get('mainServiceInfoConfigsController'); //controller.set('configGroups', managedConfigGroups); controller.loadConfigGroups([controller.get('content.serviceName')]); } else { controller.set('selectedService.configGroups', managedConfigGroups); } var selectEventObject = {}; //check whether selectedConfigGroup exists if (selectedConfigGroup && controller.get('configGroups').someProperty('name', selectedConfigGroup.get('name'))) { selectEventObject.context = selectedConfigGroup; } else { selectEventObject.context = managedConfigGroups.findProperty('isDefault', true); } controller.selectConfigGroup(selectEventObject); }, updateButtons: function () { var modified = this.get('subViewController.isHostsModified'); this.set('disablePrimary', !modified); }.observes('subViewController.isHostsModified') }); }, loadInstallerHostsFromServer: function loadInstallerHostsFromServer(hostNames) { return App.ajax.send({ name: 'hosts.info.install', sender: this, data: { hostNames: hostNames }, success: 'loadInstallerHostsSuccessCallback' }); }, loadInstallerHostsSuccessCallback: function loadInstallerHostsSuccessCallback(data) { var allHosts = App.router.get('installerController.allHosts').toMapByProperty('hostName'), slaveComponents = App.router.get('installerController.content.slaveComponentHosts'), clientComponents = App.router.get('installerController.content.clients'), clients = clientComponents.map(function (client) { return { componentName: client.component_name, displayName: client.display_name }; }); var hosts = []; slaveComponents.forEach(function (component) { component.hosts.forEach(function (rawHost) { var host = allHosts[rawHost.hostName]; if (!host.hostComponents) { host.hostComponents = []; } if (component.componentName === 'CLIENT') { host.hostComponents.pushObjects(clients); } }); }); data.items.forEach(function (host) { var disksOverallCapacity = 0, diskFree = 0; host.Hosts.disk_info.forEach(function (disk) { disksOverallCapacity += parseFloat(disk.size); diskFree += parseFloat(disk.available); }); hosts.pushObject(Em.Object.create({ id: host.Hosts.host_name, ip: host.Hosts.ip, osType: host.Hosts.os_type, osArch: host.Hosts.os_arch, hostName: host.Hosts.host_name, publicHostName: host.Hosts.public_host_name, cpu: host.Hosts.cpu_count, memory: host.Hosts.total_mem.toFixed(2), diskInfo: host.Hosts.disk_info, diskTotal: disksOverallCapacity / (1024 * 1024), diskFree: diskFree / (1024 * 1024), hostComponents: allHosts[host.Hosts.host_name] && allHosts[host.Hosts.host_name].hostComponents || [] })); }); this.set('clusterHosts', hosts); } }); }); |