control_flow_initializer_mixin.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. /**
  21. * Mixin with preconfigured initializers that helps to build conditional execution
  22. * based on exit code from App.ConfigInitializerClass._initializerFlowCode.
  23. * Each control flow initializer should has attribute <b>isChecker: true</b>
  24. * Each handler should return exit code value based on App.ConfigInitializerClass._initializerFlowCode.
  25. *
  26. * There are few methods:
  27. * @see App.ConfigInitializerClass.flowNext
  28. * @see App.ConfigInitializerClass.flowSkipNext
  29. * @see App.ConfigInitializerClass.flowSkipAll
  30. *
  31. * For details and examples @see App.AddComponentConfigInitializer
  32. *
  33. * @mixin App.ControlFlowInitializerMixin
  34. */
  35. App.ControlFlowInitializerMixin = Em.Mixin.create({
  36. initializerTypes: [
  37. {
  38. name: 'namenode_ha_enabled',
  39. method: '_initNameNodeHACheck'
  40. },
  41. {
  42. name: 'resourcemanager_ha_enabled',
  43. method: '_initResourceManagerHACheck'
  44. },
  45. {
  46. name: 'hdp_stack_version_checker',
  47. method: '_initHDPStackVersionCheck'
  48. }
  49. ],
  50. /**
  51. * Control flow initializer based on minimal stack version.
  52. *
  53. * @param {string} minStackVersionNumber
  54. * @return {object}
  55. */
  56. getHDPStackVersionControl: function(minStackVersionNumber) {
  57. return { type: 'hdp_stack_version_checker', isChecker: true, stackVersion: minStackVersionNumber };
  58. },
  59. /**
  60. * getHDPStackVersionControl handler.
  61. * When stack version satisfies passed minStackVersionNumber computation process will continue.
  62. * If not all next computation will be skipped.
  63. *
  64. * @param {configProperty} configProperty
  65. * @param {topologyLocalDB} localDB
  66. * @param {dependencies} dependencies
  67. * @param {initializer} initializer
  68. * @return {number} _initializerFlowCode exit code
  69. */
  70. _initHDPStackVersionCheck: function(configProperty, localDB, dependencies, initializer) {
  71. return (stringUtils.compareVersions(App.get('currentStackVersionNumber'), initializer.stackVersion) > -1) ?
  72. this.flowNext() :
  73. this.flowSkipAll();
  74. },
  75. /**
  76. * Control flow initializer based on NameNode HA Status.
  77. *
  78. * @return {initializer}
  79. */
  80. getNameNodeHAControl: function() {
  81. return { type: 'namenode_ha_enabled', isChecker: true };
  82. },
  83. /**
  84. * getNameNodeHAControl handler.
  85. * When NameNode HA enabled next computation will be performed, either next will be skipped.
  86. *
  87. * @param {configProperty} configProperty
  88. * @param {topologyLocalDB} localDB
  89. * @param {dependencies} dependencies
  90. * @param {initializer} initializer
  91. * @return {number} _initializerFlowCode exit code
  92. */
  93. _initNameNodeHACheck: function(configProperty, localDB, dependencies) {
  94. return App.get('isHaEnabled') ? this.flowNext() : this.flowSkipNext();
  95. },
  96. /**
  97. * Control flow initializer based on ResourceManager HA Status.
  98. *
  99. * @return {initializer}
  100. */
  101. getResourceManagerHAControl: function(trueBranch, falseBranch) {
  102. return { type: 'resourcemanager_ha_enabled', isChecker: true };
  103. },
  104. /**
  105. * getResourceManagerHAControl handler.
  106. * When ResourceManager HA enabled next computation will be performed, either next will be skipped.
  107. *
  108. * @param {configProperty} configProperty
  109. * @param {topologyLocalDB} localDB
  110. * @param {dependencies} dependencies
  111. * @param {initializer} initializer
  112. * @return {number} _initializerFlowCode exit code
  113. */
  114. _initResourceManagerHACheck: function(configProperty, localDB, dependencies) {
  115. return App.get('isRMHaEnabled') ? this.flowNext() : this.flowSkipNext();
  116. }
  117. });