cluster.js 3.7 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. installedServices: function(){
  23. return App.Service.find().mapProperty('serviceName');
  24. }.property(),
  25. currentVersion: function(){
  26. return App.get('currentStackVersion');
  27. }.property('App.currentStackVersion'),
  28. upgradeVersion: '',
  29. /**
  30. * get the newest version of HDP from server
  31. * and update if it newer than current
  32. */
  33. updateUpgradeVersion: function(){
  34. var url = App.formatUrl(
  35. App.apiPrefix + "/stacks",
  36. {},
  37. '/data/wizard/stack/stacks.json'
  38. );
  39. var result = this.get('upgradeVersion') || App.defaultStackVersion;
  40. $.ajax({
  41. type: "GET",
  42. url: url,
  43. async: false,
  44. dataType: 'json',
  45. timeout: App.timeout,
  46. success: function (data) {
  47. result = result.replace(/HDP-/, '');
  48. data.filterProperty('name', 'HDP').mapProperty('version').forEach(function(version){
  49. result = (result < version) ? version : result;
  50. });
  51. result = 'HDP-' + result;
  52. },
  53. error: function (request, ajaxOptions, error) {
  54. console.log('Error message is: ' + request.responseText);
  55. },
  56. statusCode: require('data/statusCodes')
  57. });
  58. if(result && result !== this.get('upgradeVersion')){
  59. this.set('upgradeVersion', result);
  60. }
  61. },
  62. /**
  63. * load services info(versions, description)
  64. */
  65. loadServicesFromServer: function () {
  66. var displayOrderConfig = require('data/services');
  67. var result = [];
  68. var method = 'GET';
  69. var url = App.formatUrl(
  70. App.apiPrefix + App.get('stackVersionURL'),
  71. {},
  72. '/data/wizard/stack/hdp/version/1.2.0.json'
  73. );
  74. var self = this;
  75. $.ajax({
  76. type: method,
  77. url: url,
  78. async: false,
  79. dataType: 'text',
  80. timeout: App.timeout,
  81. success: function (data) {
  82. var jsonData = jQuery.parseJSON(data);
  83. // loop through all the service components
  84. for (var i = 0; i < displayOrderConfig.length; i++) {
  85. var entry = jsonData.services.findProperty("name", displayOrderConfig[i].serviceName);
  86. if(self.get('installedServices').contains(entry.name)){
  87. var myService = Em.Object.create({
  88. serviceName: entry.name,
  89. displayName: displayOrderConfig[i].displayName,
  90. isDisabled: i === 0,
  91. isSelected: true,
  92. isInstalled: false,
  93. isHidden: displayOrderConfig[i].isHidden,
  94. description: entry.comment,
  95. version: entry.version,
  96. newVersion: '1.3.0'
  97. });
  98. result.push(myService);
  99. }
  100. }
  101. },
  102. error: function (request, ajaxOptions, error) {
  103. console.log('Error message is: ' + request.responseText);
  104. },
  105. statusCode: require('data/statusCodes')
  106. });
  107. this.set('services', result);
  108. }.observes('upgradeVersion')
  109. });