stack_and_upgrade_controller.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.MainAdminStackAndUpgradeController = Em.Controller.extend({
  21. name: 'mainAdminStackAndUpgradeController',
  22. /**
  23. * @type {Object|null}
  24. */
  25. serviceToInstall: null,
  26. /**
  27. * @type {Array}
  28. */
  29. upgradeGroups: [],
  30. /**
  31. * TODO should have actual value from call that start upgrade
  32. * @type {Number|null}
  33. */
  34. upgradeId: 1,
  35. /**
  36. * version that currently applied to server
  37. * @type {Object|null}
  38. */
  39. currentVersion: null,
  40. /**
  41. * versions to which cluster could be upgraded
  42. * @type {Array}
  43. */
  44. targetVersions: [],
  45. /**
  46. * @type {Array}
  47. */
  48. services: function() {
  49. return App.StackService.find().map(function(s) {
  50. s.set('isInstalled', App.Service.find().someProperty('serviceName', s.get('serviceName')));
  51. return s;
  52. });
  53. }.property('App.router.clusterController.isLoaded'),
  54. /**
  55. * launch Add Service wizard
  56. * @param event
  57. */
  58. goToAddService: function (event) {
  59. this.set('serviceToInstall', event.context);
  60. App.get('router').transitionTo('main.serviceAdd');
  61. },
  62. /**
  63. * call to fetch cluster stack versions
  64. * @return {$.ajax}
  65. */
  66. loadVersionsInfo: function () {
  67. return App.ajax.send({
  68. name: 'admin.stack_versions.all',
  69. sender: this,
  70. data: {},
  71. success: 'loadVersionsInfoSuccessCallback'
  72. });
  73. },
  74. /**
  75. * parse stack versions and
  76. * set <code>currentVersion</code>
  77. * set <code>targetVersions</code>
  78. * @param data
  79. */
  80. loadVersionsInfoSuccessCallback: function (data) {
  81. var current = data.items.findProperty('ClusterStackVersions.state', 'CURRENT');
  82. var currentVersion = current.repository_versions[0].RepositoryVersions.repository_version;
  83. var targetVersions = data.items.without(current)
  84. .filter(function (version) {
  85. var repositoryVersion = version.repository_versions[0].RepositoryVersions.repository_version;
  86. //Only higher versions that have already been installed to all the hosts are shown
  87. return (version.ClusterStackVersions.state === 'INSTALLED' &&
  88. stringUtils.compareVersions(repositoryVersion, currentVersion) === 1);
  89. }).map(function (version) {
  90. return version.ClusterStackVersions;
  91. });
  92. this.set('currentVersion', current.ClusterStackVersions);
  93. this.set('targetVersions', targetVersions);
  94. },
  95. /**
  96. * load upgrade tasks by upgrade id
  97. * @return {$.ajax}
  98. */
  99. loadUpgradeData: function () {
  100. return App.ajax.send({
  101. name: 'admin.upgrade.data',
  102. sender: this,
  103. data: {
  104. id: this.get('upgradeId')
  105. },
  106. success: 'loadUpgradeDataSuccessCallback'
  107. });
  108. },
  109. /**
  110. * parse and push upgrade tasks to controller
  111. * @param data
  112. */
  113. loadUpgradeDataSuccessCallback: function (data) {
  114. this.set("upgradeGroups", data.upgrade_groups);
  115. },
  116. /**
  117. * make call to start downgrade process
  118. */
  119. downgrade: function () {
  120. //TODO start downgrade
  121. },
  122. /**
  123. * make call to start upgrade process and show popup with current progress
  124. */
  125. upgrade: function () {
  126. //TODO start upgrade
  127. this.loadUpgradeData();
  128. this.openUpgradeDialog();
  129. },
  130. /**
  131. * make call to resume upgrade process and show popup with current progress
  132. */
  133. resumeUpgrade: function () {
  134. //TODO resume upgrade
  135. },
  136. /**
  137. * make call to stop upgrade process
  138. */
  139. stopUpgrade: function () {
  140. //TODO stop upgrade
  141. },
  142. /**
  143. * make call to finish upgrade process
  144. */
  145. finalize: function () {
  146. //TODO start finalize
  147. },
  148. /**
  149. * show dialog with tasks of upgrade
  150. * @return {App.ModalPopup}
  151. */
  152. openUpgradeDialog: function () {
  153. App.router.transitionTo('admin.stackUpgrade');
  154. }
  155. });