cluster.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var stringUtils = require('utils/string_utils');
  20. App.MainAdminClusterController = Em.Controller.extend({
  21. name:'mainAdminClusterController',
  22. services: [],
  23. upgradeVersion: '',
  24. /**
  25. * get the newest version of HDP from server
  26. */
  27. updateUpgradeVersion: function(){
  28. if(App.router.get('clusterController.isLoaded')){
  29. App.ajax.send({
  30. name: 'cluster.update_upgrade_version',
  31. sender: this,
  32. success: 'updateUpgradeVersionSuccessCallback',
  33. error: 'updateUpgradeVersionErrorCallback'
  34. });
  35. }
  36. }.observes('App.router.clusterController.isLoaded', 'App.currentStackVersion'),
  37. updateUpgradeVersionSuccessCallback: function(data) {
  38. var upgradeVersion = this.get('upgradeVersion') || App.defaultStackVersion;
  39. var currentStack = {};
  40. var upgradeStack = {};
  41. var currentVersion = App.get('currentStackVersionNumber');
  42. var minUpgradeVersion = currentVersion;
  43. upgradeVersion = upgradeVersion.replace(/HDP-/, '');
  44. data.items.mapProperty('Versions.stack_version').forEach(function(version){
  45. upgradeVersion = (stringUtils.compareVersions(upgradeVersion, version) === -1) ? version : upgradeVersion;
  46. });
  47. currentStack = data.items.findProperty('Versions.stack_version', currentVersion);
  48. upgradeStack = data.items.findProperty('Versions.stack_version', upgradeVersion);
  49. minUpgradeVersion = upgradeStack.Versions.min_upgrade_version;
  50. if(minUpgradeVersion && (stringUtils.compareVersions(minUpgradeVersion, currentVersion) === 1)){
  51. upgradeVersion = currentVersion;
  52. upgradeStack = currentStack;
  53. }
  54. upgradeVersion = 'HDP-' + upgradeVersion;
  55. this.set('upgradeVersion', upgradeVersion);
  56. if(currentStack && upgradeStack) {
  57. this.parseServicesInfo(currentStack, upgradeStack);
  58. }
  59. else {
  60. console.log('HDP stack doesn\'t have services with defaultStackVersion');
  61. }
  62. },
  63. updateUpgradeVersionErrorCallback: function(request, ajaxOptions, error) {
  64. console.log('Error message is: ' + request.responseText);
  65. console.log('HDP stack doesn\'t have services with defaultStackVersion');
  66. },
  67. /**
  68. * parse services info(versions, description) by version
  69. */
  70. parseServicesInfo: function (currentStack, upgradeStack) {
  71. var result = [];
  72. var installedServices = App.Service.find().mapProperty('serviceName');
  73. var displayOrderConfig = require('data/services');
  74. if(currentStack.stackServices.length && upgradeStack.stackServices.length){
  75. // loop through all the service components
  76. for (var i = 0; i < displayOrderConfig.length; i++) {
  77. var entry = currentStack.stackServices.
  78. findProperty("StackServices.service_name", displayOrderConfig[i].serviceName);
  79. if (entry) {
  80. entry = entry.StackServices;
  81. if (installedServices.contains(entry.service_name)) {
  82. var myService = Em.Object.create({
  83. serviceName: entry.service_name,
  84. displayName: displayOrderConfig[i].displayName,
  85. isDisabled: i === 0,
  86. isSelected: true,
  87. isInstalled: false,
  88. isHidden: displayOrderConfig[i].isHidden,
  89. description: entry.comments,
  90. version: entry.service_version,
  91. newVersion: ''
  92. });
  93. // it's possible that there is no corresponding service in the new stack
  94. var matchedService = upgradeStack.stackServices.findProperty("StackServices.service_name", displayOrderConfig[i].serviceName);
  95. if (matchedService) {
  96. myService.newVersion = matchedService.StackServices.service_version;
  97. }
  98. //From 1.3.0 for Hive we display only "Hive" (but it install HCat and WebHCat as well)
  99. if (this.get('upgradeVersion').replace(/HDP-/, '') >= '1.3.0' && displayOrderConfig[i].serviceName == 'HIVE') {
  100. myService.set('displayName', 'Hive');
  101. }
  102. result.push(myService);
  103. }
  104. }
  105. else {
  106. console.warn('Service not found - ', displayOrderConfig[i].serviceName);
  107. }
  108. }
  109. }
  110. this.set('services', result);
  111. }
  112. });