components.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. var self = this;
  94. $.fileDownload(url).fail(function (error) {
  95. var errorObj = JSON.parse($(error).text());
  96. var isNoConfigs = errorObj.message.contains(Em.I18n.t('services.service.actions.downloadClientConfigs.fail.noConfigFile'));
  97. var errorMessage = isNoConfigs ? Em.I18n.t('services.service.actions.downloadClientConfigs.fail.noConfigFile') :
  98. Em.I18n.t('services.service.actions.downloadClientConfigs.fail.popup.body').format(data.displayName, errorObj.status, errorObj.message);
  99. App.ModalPopup.show({
  100. header: Em.I18n.t('services.service.actions.downloadClientConfigs.fail.popup.header').format(data.displayName),
  101. bodyClass: Ember.View.extend({
  102. template: Em.Handlebars.compile(errorMessage)
  103. }),
  104. secondary: isNoConfigs ? false : Em.I18n.t('common.cancel'),
  105. onPrimary: function () {
  106. this.hide();
  107. if (!isNoConfigs) {
  108. self.downloadClientConfigs({
  109. context: Em.Object.create(data)
  110. })
  111. }
  112. }
  113. });
  114. });
  115. }
  116. };