components.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. module.exports = {
  19. installHostComponent: function(hostName, component) {
  20. var self = this;
  21. var componentName = component.get('componentName');
  22. var displayName = component.get('displayName');
  23. App.ajax.send({
  24. name: 'host.host_component.add_new_component',
  25. sender: self,
  26. data: {
  27. hostName: hostName,
  28. component: component,
  29. data: JSON.stringify({
  30. RequestInfo: {
  31. "context": Em.I18n.t('requestInfo.installHostComponent') + " " + displayName
  32. },
  33. Body: {
  34. host_components: [
  35. {
  36. HostRoles: {
  37. component_name: componentName
  38. }
  39. }
  40. ]
  41. }
  42. })
  43. },
  44. success: 'addNewComponentSuccessCallback',
  45. error: 'ajaxErrorCallback'
  46. });
  47. },
  48. /**
  49. * Success callback for add host component request
  50. * @param {object} data
  51. * @param {object} opt
  52. * @param {object} params
  53. * @method addNewComponentSuccessCallback
  54. */
  55. addNewComponentSuccessCallback: function (data, opt, params) {
  56. console.log('Send request for ADDING NEW COMPONENT successfully');
  57. App.ajax.send({
  58. name: 'common.host.host_component.update',
  59. sender: App.router.get('mainHostDetailsController'),
  60. data: {
  61. hostName: params.hostName,
  62. componentName: params.component.get('componentName'),
  63. serviceName: params.component.get('serviceName'),
  64. component: params.component,
  65. "context": Em.I18n.t('requestInfo.installNewHostComponent') + " " + params.component.get('displayName'),
  66. HostRoles: {
  67. state: 'INSTALLED'
  68. },
  69. urlParams: "HostRoles/state=INIT"
  70. },
  71. success: 'installNewComponentSuccessCallback',
  72. error: 'ajaxErrorCallback'
  73. });
  74. },
  75. /**
  76. * Default error-callback for ajax-requests in current page
  77. * @param {object} request
  78. * @param {object} ajaxOptions
  79. * @param {string} error
  80. * @param {object} opt
  81. * @param {object} params
  82. * @method ajaxErrorCallback
  83. */
  84. ajaxErrorCallback: function (request, ajaxOptions, error, opt, params) {
  85. console.log('error on change component host status');
  86. App.ajax.defaultErrorHandler(request, opt.url, opt.method);
  87. },
  88. downloadClientConfigs: function (data) {
  89. var isForHost = typeof data.hostName !== 'undefined';
  90. var url = App.get('apiPrefix') + '/clusters/' + App.router.getClusterName() + '/' +
  91. (isForHost ? 'hosts/' + data.hostName + '/host_components/' : 'services/' + data.serviceName + '/components/') +
  92. data.componentName + '?format=client_config_tar';
  93. try {
  94. var self = this;
  95. $.fileDownload(url).fail(function (error) {
  96. var errorMessage = '';
  97. var isNoConfigs = false;
  98. if (error && $(error).text()) {
  99. var errorObj = JSON.parse($(error).text());
  100. if (errorObj && errorObj.message && errorObj.status) {
  101. isNoConfigs = errorObj.message.indexOf(Em.I18n.t('services.service.actions.downloadClientConfigs.fail.noConfigFile')) !== -1;
  102. errorMessage += isNoConfigs ? Em.I18n.t('services.service.actions.downloadClientConfigs.fail.noConfigFile') :
  103. Em.I18n.t('services.service.actions.downloadClientConfigs.fail.popup.body.errorMessage').format(data.displayName, errorObj.status, errorObj.message);
  104. } else {
  105. errorMessage += Em.I18n.t('services.service.actions.downloadClientConfigs.fail.popup.body.noErrorMessage').format(data.displayName);
  106. }
  107. errorMessage += isNoConfigs ? '' : Em.I18n.t('services.service.actions.downloadClientConfigs.fail.popup.body.question');
  108. } else {
  109. errorMessage += Em.I18n.t('services.service.actions.downloadClientConfigs.fail.popup.body.noErrorMessage').format(data.displayName) +
  110. Em.I18n.t('services.service.actions.downloadClientConfigs.fail.popup.body.question');
  111. }
  112. App.ModalPopup.show({
  113. header: Em.I18n.t('services.service.actions.downloadClientConfigs.fail.popup.header').format(data.displayName),
  114. bodyClass: Ember.View.extend({
  115. template: Em.Handlebars.compile(errorMessage)
  116. }),
  117. secondary: isNoConfigs ? false : Em.I18n.t('common.cancel'),
  118. onPrimary: function () {
  119. this.hide();
  120. if (!isNoConfigs) {
  121. self.downloadClientConfigs({
  122. context: Em.Object.create(data)
  123. })
  124. }
  125. }
  126. });
  127. });
  128. } catch (err) {
  129. var newWindow = window.open(url);
  130. newWindow.focus();
  131. }
  132. },
  133. /**
  134. * Check if all required components are installed on host.
  135. *
  136. * @param {String} componentName
  137. * @param {Array} installedComponentNames
  138. * @return {Array} - names of missed components
  139. */
  140. checkComponentDependencies: function(componentName, installedComponentNames) {
  141. return App.StackServiceComponent.find(componentName).get('dependencies').filter(function(dependency) {
  142. return !installedComponentNames.contains(dependency)
  143. });
  144. }
  145. };