cluster.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. App.MainAdminClusterController = Em.Controller.extend({
  20. name:'mainAdminClusterController',
  21. services: [],
  22. upgradeVersion: '',
  23. /**
  24. * get the newest version of HDP from server
  25. */
  26. updateUpgradeVersion: function(){
  27. if(App.router.get('clusterController.isLoaded')){
  28. var url = App.formatUrl(
  29. App.apiPrefix + "/stacks",
  30. {},
  31. '/data/wizard/stack/stacks.json'
  32. );
  33. var upgradeVersion = this.get('upgradeVersion') || App.defaultStackVersion;
  34. var installedServices = {};
  35. var newServices = {};
  36. $.ajax({
  37. type: "GET",
  38. url: url,
  39. async: false,
  40. dataType: 'json',
  41. timeout: App.timeout,
  42. success: function (data) {
  43. var currentVersion = App.currentStackVersion.replace(/HDP-/, '');
  44. var minUpgradeVersion = currentVersion;
  45. upgradeVersion = upgradeVersion.replace(/HDP-/, '');
  46. data = data.filterProperty('name', 'HDP');
  47. data.mapProperty('version').forEach(function(version){
  48. upgradeVersion = (upgradeVersion < version) ? version : upgradeVersion;
  49. });
  50. //TODO remove hardcoded upgrade version
  51. upgradeVersion = (App.testMode)?'1.3.0': upgradeVersion;
  52. minUpgradeVersion = data.findProperty('version', upgradeVersion).minUpgradeVersion;
  53. minUpgradeVersion = (minUpgradeVersion) ? minUpgradeVersion : currentVersion;
  54. upgradeVersion = (minUpgradeVersion <= currentVersion) ? upgradeVersion : currentVersion;
  55. installedServices = data.findProperty('version', currentVersion);
  56. newServices = data.findProperty('version', upgradeVersion);
  57. upgradeVersion = 'HDP-' + upgradeVersion;
  58. },
  59. error: function (request, ajaxOptions, error) {
  60. console.log('Error message is: ' + request.responseText);
  61. },
  62. statusCode: require('data/statusCodes')
  63. });
  64. this.set('upgradeVersion', upgradeVersion);
  65. if(installedServices && newServices){
  66. this.parseServicesInfo(installedServices, newServices);
  67. } else {
  68. console.log('HDP stack doesn\'t have services with defaultStackVersion');
  69. }
  70. }
  71. }.observes('App.router.clusterController.isLoaded', 'App.currentStackVersion'),
  72. /**
  73. * parse services info(versions, description) by version
  74. */
  75. parseServicesInfo: function (oldServices, newServices) {
  76. var result = [];
  77. var installedServices = App.Service.find().mapProperty('serviceName');
  78. var displayOrderConfig = require('data/services');
  79. if(oldServices.services && newServices.services){
  80. // loop through all the service components
  81. for (var i = 0; i < displayOrderConfig.length; i++) {
  82. var entry = oldServices.services.findProperty("name", displayOrderConfig[i].serviceName);
  83. if (entry) {
  84. if (installedServices.contains(entry.name)) {
  85. var myService = Em.Object.create({
  86. serviceName: entry.name,
  87. displayName: displayOrderConfig[i].displayName,
  88. isDisabled: i === 0,
  89. isSelected: true,
  90. isInstalled: false,
  91. isHidden: displayOrderConfig[i].isHidden,
  92. description: entry.comment,
  93. version: entry.version,
  94. newVersion: newServices.services.findProperty("name", displayOrderConfig[i].serviceName).version
  95. });
  96. //From 1.3.0 for Hive we display only "Hive" (but it installes HCat and WebHCat as well)
  97. if (this.get('upgradeVersion').replace(/HDP-/, '') >= '1.3.0' && displayOrderConfig[i].serviceName == 'HIVE') {
  98. myService.set('displayName', 'Hive');
  99. }
  100. result.push(myService);
  101. }
  102. }
  103. else {
  104. console.warn('Service not found - ', displayOrderConfig[i].serviceName);
  105. }
  106. }
  107. }
  108. this.set('services', result);
  109. }
  110. });