stack_and_upgrade_controller_test.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  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. require('controllers/main/admin/stack_and_upgrade_controller');
  20. require('utils/string_utils');
  21. describe('App.MainAdminStackAndUpgradeController', function() {
  22. var controller = App.MainAdminStackAndUpgradeController.create({
  23. getDBProperty: Em.K,
  24. setDBProperty: Em.K
  25. });
  26. describe("#realRepoUrl", function() {
  27. before(function () {
  28. this.mock = sinon.stub(App, 'get');
  29. });
  30. after(function () {
  31. this.mock.restore();
  32. });
  33. it("", function() {
  34. this.mock.withArgs('apiPrefix').returns('apiPrefix');
  35. this.mock.withArgs('stackVersionURL').returns('stackVersionURL');
  36. controller.propertyDidChange('realRepoUrl');
  37. expect(controller.get('realRepoUrl')).to.equal('apiPrefixstackVersionURL/compatible_repository_versions?fields=*,operating_systems/*,operating_systems/repositories/*');
  38. });
  39. });
  40. describe("#realStackUrl", function() {
  41. before(function () {
  42. this.mock = sinon.stub(App, 'get');
  43. });
  44. after(function () {
  45. this.mock.restore();
  46. });
  47. it("", function() {
  48. this.mock.withArgs('apiPrefix').returns('apiPrefix');
  49. this.mock.withArgs('clusterName').returns('clusterName');
  50. controller.propertyDidChange('realStackUrl');
  51. expect(controller.get('realStackUrl')).to.equal('apiPrefix/clusters/clusterName/stack_versions?fields=*,repository_versions/*,repository_versions/operating_systems/repositories/*');
  52. });
  53. });
  54. describe("#realUpdateUrl", function() {
  55. before(function () {
  56. this.mock = sinon.stub(App, 'get');
  57. });
  58. after(function () {
  59. this.mock.restore();
  60. });
  61. it("", function() {
  62. this.mock.withArgs('apiPrefix').returns('apiPrefix');
  63. this.mock.withArgs('clusterName').returns('clusterName');
  64. controller.propertyDidChange('realUpdateUrl');
  65. expect(controller.get('realUpdateUrl')).to.equal('apiPrefix/clusters/clusterName/stack_versions?fields=ClusterStackVersions/*');
  66. });
  67. });
  68. describe("#requestStatus", function() {
  69. it("isSuspended false", function() {
  70. controller.set('isSuspended', false);
  71. controller.set('upgradeData', { Upgrade: {request_status: 'ABORTED'}});
  72. controller.propertyDidChange('requestStatus');
  73. expect(controller.get('requestStatus')).to.equal('ABORTED');
  74. });
  75. it("isSuspended true", function() {
  76. controller.set('isSuspended', true);
  77. controller.set('upgradeData', { Upgrade: {request_status: 'ABORTED'}});
  78. controller.propertyDidChange('requestStatus');
  79. expect(controller.get('requestStatus')).to.equal('SUSPENDED');
  80. });
  81. });
  82. describe("#load()", function() {
  83. before(function(){
  84. sinon.stub(controller, 'loadUpgradeData').returns({
  85. done: function(callback) {callback();}
  86. });
  87. sinon.stub(controller, 'loadStackVersionsToModel').returns({
  88. done: function(callback) {callback();}
  89. });
  90. sinon.stub(controller, 'loadRepoVersionsToModel').returns({
  91. done: function(callback) {callback();}
  92. });
  93. sinon.stub(App.StackVersion, 'find').returns([Em.Object.create({
  94. state: 'CURRENT',
  95. repositoryVersion: {
  96. repositoryVersion: '2.2',
  97. displayName: 'HDP-2.2'
  98. }
  99. })]);
  100. });
  101. after(function(){
  102. controller.loadUpgradeData.restore();
  103. controller.loadStackVersionsToModel.restore();
  104. controller.loadRepoVersionsToModel.restore();
  105. App.StackVersion.find.restore();
  106. });
  107. it("", function() {
  108. controller.load();
  109. expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
  110. expect(controller.loadStackVersionsToModel.calledWith(true)).to.be.true;
  111. expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
  112. expect(controller.get('currentVersion')).to.eql({
  113. "repository_version": "2.2",
  114. "repository_name": "HDP-2.2"
  115. });
  116. });
  117. });
  118. describe("#loadUpgradeData()", function() {
  119. beforeEach(function () {
  120. sinon.stub(App.ajax, 'send').returns({
  121. then: Em.K,
  122. complete: Em.K
  123. });
  124. });
  125. afterEach(function () {
  126. App.ajax.send.restore();
  127. });
  128. it("get entire data", function() {
  129. controller.set('upgradeId', 1);
  130. controller.loadUpgradeData();
  131. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  132. name: 'admin.upgrade.data',
  133. sender: controller,
  134. data: {
  135. id: 1
  136. },
  137. success: 'loadUpgradeDataSuccessCallback'
  138. })
  139. });
  140. it("get only state", function() {
  141. controller.set('upgradeId', 1);
  142. controller.loadUpgradeData(true);
  143. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  144. name: 'admin.upgrade.state',
  145. sender: controller,
  146. data: {
  147. id: 1
  148. },
  149. success: 'loadUpgradeDataSuccessCallback'
  150. })
  151. });
  152. it("upgrade id is null", function() {
  153. controller.set('upgradeId', null);
  154. controller.loadUpgradeData();
  155. expect(App.ajax.send.called).to.be.false;
  156. });
  157. });
  158. describe("#loadUpgradeDataSuccessCallback()", function() {
  159. var retryCases = [
  160. {
  161. isRetryPendingInitial: true,
  162. status: 'ABORTED',
  163. isRetryPending: true,
  164. requestInProgress: true,
  165. title: 'retry request not yet applied'
  166. },
  167. {
  168. isRetryPendingInitial: true,
  169. status: 'UPGRADING',
  170. isRetryPending: false,
  171. requestInProgress: false,
  172. title: 'retry request applied'
  173. },
  174. {
  175. isRetryPendingInitial: false,
  176. status: 'ABORTED',
  177. isRetryPending: false,
  178. requestInProgress: true,
  179. title: 'no retry request sent'
  180. },
  181. {
  182. isRetryPendingInitial: false,
  183. status: 'UPGRADING',
  184. isRetryPending: false,
  185. requestInProgress: true,
  186. title: 'upgrade wasn\'t aborted'
  187. }
  188. ];
  189. beforeEach(function () {
  190. sinon.stub(controller, 'updateUpgradeData', Em.K);
  191. sinon.stub(controller, 'setDBProperty', Em.K);
  192. });
  193. afterEach(function () {
  194. controller.updateUpgradeData.restore();
  195. controller.setDBProperty.restore();
  196. });
  197. it("correct data", function() {
  198. var data = {
  199. "Upgrade": {
  200. "request_status": "UPGRADED"
  201. },
  202. "upgrade_groups": [
  203. {
  204. "UpgradeGroup": {
  205. "id": 1
  206. },
  207. "upgrade_items": []
  208. }
  209. ]};
  210. controller.loadUpgradeDataSuccessCallback(data);
  211. expect(App.get('upgradeState')).to.equal('UPGRADED');
  212. expect(controller.updateUpgradeData.calledOnce).to.be.true;
  213. expect(controller.setDBProperty.calledWith('upgradeState', 'UPGRADED')).to.be.true;
  214. });
  215. it("data is null", function() {
  216. var data = null;
  217. controller.loadUpgradeDataSuccessCallback(data);
  218. expect(controller.updateUpgradeData.called).to.be.false;
  219. expect(controller.setDBProperty.called).to.be.false;
  220. });
  221. retryCases.forEach(function (item) {
  222. it(item.title, function () {
  223. var data = {
  224. "Upgrade": {
  225. "request_status": item.status
  226. }
  227. };
  228. controller.setProperties({
  229. isRetryPending: item.isRetryPendingInitial,
  230. requestInProgress: true
  231. });
  232. controller.loadUpgradeDataSuccessCallback(data);
  233. expect(controller.getProperties(['isRetryPending', 'requestInProgress'])).to.eql({
  234. isRetryPending: item.isRetryPending,
  235. requestInProgress: item.requestInProgress
  236. });
  237. });
  238. });
  239. });
  240. describe("#getUpgradeItem()", function() {
  241. beforeEach(function () {
  242. sinon.stub(App.ajax, 'send', Em.K);
  243. });
  244. afterEach(function () {
  245. App.ajax.send.restore();
  246. });
  247. it("default callback", function() {
  248. var item = Em.Object.create({
  249. request_id: 1,
  250. group_id: 2,
  251. stage_id: 3
  252. });
  253. controller.getUpgradeItem(item);
  254. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  255. name: 'admin.upgrade.upgrade_item',
  256. sender: controller,
  257. data: {
  258. upgradeId: 1,
  259. groupId: 2,
  260. stageId: 3
  261. },
  262. success: 'getUpgradeItemSuccessCallback'
  263. });
  264. });
  265. it("custom callback", function() {
  266. var item = Em.Object.create({
  267. request_id: 1,
  268. group_id: 2,
  269. stage_id: 3
  270. });
  271. controller.getUpgradeItem(item, 'customCallback');
  272. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  273. name: 'admin.upgrade.upgrade_item',
  274. sender: controller,
  275. data: {
  276. upgradeId: 1,
  277. groupId: 2,
  278. stageId: 3
  279. },
  280. success: 'customCallback'
  281. });
  282. });
  283. });
  284. describe("#openUpgradeDialog()", function () {
  285. before(function () {
  286. sinon.stub(App.router, 'transitionTo', Em.K);
  287. });
  288. after(function () {
  289. App.router.transitionTo.restore();
  290. });
  291. it("should open dialog", function () {
  292. controller.openUpgradeDialog();
  293. expect(App.router.transitionTo.calledWith('admin.stackUpgrade')).to.be.true;
  294. });
  295. });
  296. describe("#runPreUpgradeCheck()", function() {
  297. before(function () {
  298. sinon.stub(App.ajax, 'send', Em.K);
  299. });
  300. after(function () {
  301. App.ajax.send.restore();
  302. });
  303. it("make ajax call", function() {
  304. controller.runPreUpgradeCheck(Em.Object.create({
  305. repositoryVersion: '2.2',
  306. displayName: 'HDP-2.2',
  307. upgradeType: 'ROLLING',
  308. skipComponentFailures: false,
  309. skipSCFailures: false
  310. }));
  311. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  312. name: "admin.upgrade.pre_upgrade_check",
  313. sender: controller,
  314. data: {
  315. value: '2.2',
  316. label: 'HDP-2.2',
  317. type: 'ROLLING',
  318. skipComponentFailures: 'false',
  319. skipSCFailures: 'false'
  320. },
  321. success: "runPreUpgradeCheckSuccess",
  322. error: "runPreUpgradeCheckError"
  323. });
  324. });
  325. });
  326. describe("#runPreUpgradeCheckSuccess()", function () {
  327. var cases = [
  328. {
  329. check: {
  330. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  331. "status": "FAIL",
  332. "reason": "FAIL",
  333. "failed_on": [],
  334. "check_type": "SERVICE"
  335. },
  336. showClusterCheckPopupCalledCount: 1,
  337. upgradeCalledCount: 0,
  338. title: 'popup is displayed if fails are present'
  339. },
  340. {
  341. check: {
  342. "check": "Configuration Merge Check",
  343. "status": "WARNING",
  344. "reason": "Conflict",
  345. "failed_on": [],
  346. "failed_detail": [
  347. {
  348. type: 't0',
  349. property: 'p0',
  350. current: 'c0',
  351. new_stack_value: 'n0',
  352. result_value: 'n0'
  353. },
  354. {
  355. type: 't1',
  356. property: 'p1',
  357. current: 'c1',
  358. new_stack_value: null,
  359. result_value: 'c1'
  360. },
  361. {
  362. type: 't2',
  363. property: 'p2',
  364. current: 'c2',
  365. new_stack_value: null,
  366. result_value: null
  367. }
  368. ],
  369. "check_type": "CLUSTER",
  370. "id": "CONFIG_MERGE"
  371. },
  372. showClusterCheckPopupCalledCount: 1,
  373. upgradeCalledCount: 0,
  374. configs: [
  375. {
  376. type: 't0',
  377. name: 'p0',
  378. currentValue: 'c0',
  379. recommendedValue: 'n0',
  380. resultingValue: 'n0',
  381. isDeprecated: false,
  382. willBeRemoved: false
  383. },
  384. {
  385. type: 't1',
  386. name: 'p1',
  387. currentValue: 'c1',
  388. recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
  389. resultingValue: 'c1',
  390. isDeprecated: true,
  391. willBeRemoved: false
  392. },
  393. {
  394. type: 't2',
  395. name: 'p2',
  396. currentValue: 'c2',
  397. recommendedValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.deprecated'),
  398. resultingValue: Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.willBeRemoved'),
  399. isDeprecated: true,
  400. willBeRemoved: true
  401. }
  402. ],
  403. title: 'popup is displayed if warnings are present; configs merge conflicts'
  404. },
  405. {
  406. check: {
  407. "check": "Work-preserving RM/NM restart is enabled in YARN configs",
  408. "status": "PASS",
  409. "reason": "OK",
  410. "failed_on": [],
  411. "check_type": "SERVICE"
  412. },
  413. showClusterCheckPopupCalledCount: 0,
  414. upgradeCalledCount: 1,
  415. title: 'upgrade is started if fails and warnings are absent'
  416. }
  417. ];
  418. beforeEach(function () {
  419. sinon.stub(App, 'showClusterCheckPopup', Em.K);
  420. sinon.stub(controller, 'upgrade', Em.K);
  421. });
  422. afterEach(function () {
  423. App.showClusterCheckPopup.restore();
  424. controller.upgrade.restore();
  425. });
  426. cases.forEach(function (item) {
  427. it(item.title, function () {
  428. controller.runPreUpgradeCheckSuccess(
  429. {
  430. items: [
  431. {
  432. UpgradeChecks: item.check
  433. }
  434. ]
  435. }, null, {
  436. label: 'name'
  437. }
  438. );
  439. expect(controller.upgrade.callCount).to.equal(item.upgradeCalledCount);
  440. expect(App.showClusterCheckPopup.callCount).to.equal(item.showClusterCheckPopupCalledCount);
  441. if (item.check.id == 'CONFIG_MERGE') {
  442. expect(App.showClusterCheckPopup.firstCall.args[7]).to.eql(item.configs);
  443. }
  444. });
  445. });
  446. });
  447. describe("#initDBProperties()", function() {
  448. before(function () {
  449. this.mock = sinon.stub(controller, 'getDBProperties');
  450. });
  451. after(function () {
  452. this.mock.restore();
  453. });
  454. it("set string properties", function () {
  455. this.mock.returns({prop: 'string'});
  456. controller.initDBProperties();
  457. expect(controller.get('prop')).to.equal('string');
  458. });
  459. it("set number properties", function () {
  460. this.mock.returns({prop: 0});
  461. controller.initDBProperties();
  462. expect(controller.get('prop')).to.equal(0);
  463. });
  464. it("set boolean properties", function () {
  465. this.mock.returns({prop: false});
  466. controller.initDBProperties();
  467. expect(controller.get('prop')).to.be.false;
  468. });
  469. it("set undefined properties", function () {
  470. this.mock.returns({prop: undefined});
  471. controller.set('prop', 'value');
  472. controller.initDBProperties();
  473. expect(controller.get('prop')).to.equal('value');
  474. });
  475. it("set null properties", function () {
  476. this.mock.returns({prop: null});
  477. controller.set('prop', 'value');
  478. controller.initDBProperties();
  479. expect(controller.get('prop')).to.equal('value');
  480. });
  481. });
  482. describe("#init()", function() {
  483. before(function () {
  484. sinon.stub(controller, 'initDBProperties', Em.K);
  485. });
  486. after(function () {
  487. controller.initDBProperties.restore();
  488. });
  489. it("call initDBProperties", function () {
  490. controller.init();
  491. expect(controller.initDBProperties.calledOnce).to.be.true;
  492. });
  493. });
  494. describe("#upgrade()", function() {
  495. before(function () {
  496. sinon.stub(App.ajax, 'send', Em.K);
  497. sinon.stub(controller, 'setDBProperty', Em.K);
  498. });
  499. after(function () {
  500. App.ajax.send.restore();
  501. controller.setDBProperty.restore();
  502. });
  503. it("make ajax call", function() {
  504. controller.set('currentVersion', {
  505. repository_version: '2.2'
  506. });
  507. controller.upgrade({
  508. value: '2.2',
  509. label: 'HDP-2.2'
  510. });
  511. expect(App.ajax.send.getCall(0).args[0].data).to.eql({"value": '2.2', "label": 'HDP-2.2'});
  512. expect(App.ajax.send.getCall(0).args[0].name).to.eql('admin.upgrade.start');
  513. expect(App.ajax.send.getCall(0).args[0].sender).to.eql(controller);
  514. expect(App.ajax.send.getCall(0).args[0].success).to.eql('upgradeSuccessCallback');
  515. expect(App.ajax.send.getCall(0).args[0].callback).to.be.called;
  516. expect(controller.setDBProperty.calledWith('currentVersion', {
  517. repository_version: '2.2'
  518. })).to.be.true;
  519. });
  520. });
  521. describe("#upgradeSuccessCallback()", function() {
  522. before(function () {
  523. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  524. sinon.stub(controller, 'openUpgradeDialog', Em.K);
  525. sinon.stub(controller, 'setDBProperties', Em.K);
  526. sinon.stub(controller, 'load', Em.K);
  527. });
  528. after(function () {
  529. App.clusterStatus.setClusterStatus.restore();
  530. controller.openUpgradeDialog.restore();
  531. controller.setDBProperties.restore();
  532. controller.load.restore();
  533. });
  534. it("open upgrade dialog", function() {
  535. var data = {
  536. resources: [
  537. {
  538. Upgrade: {
  539. request_id: 1
  540. }
  541. }
  542. ]
  543. };
  544. controller.upgradeSuccessCallback(data, {}, {label: 'HDP-2.2.1', isDowngrade: true});
  545. expect(controller.load.calledOnce).to.be.true;
  546. expect(controller.get('upgradeVersion')).to.equal('HDP-2.2.1');
  547. expect(controller.get('upgradeData')).to.be.null;
  548. expect(controller.get('isDowngrade')).to.be.true;
  549. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  550. expect(controller.openUpgradeDialog.calledOnce).to.be.true;
  551. });
  552. });
  553. describe("#updateUpgradeData()", function() {
  554. beforeEach(function () {
  555. sinon.stub(controller, 'initUpgradeData', Em.K);
  556. });
  557. afterEach(function () {
  558. controller.initUpgradeData.restore();
  559. });
  560. it("data loaded first time", function() {
  561. controller.set('upgradeData', null);
  562. controller.updateUpgradeData({});
  563. expect(controller.initUpgradeData.calledWith({})).to.be.true;
  564. });
  565. it("update loaded data", function() {
  566. var oldData = Em.Object.create({
  567. upgradeGroups: [
  568. Em.Object.create({
  569. group_id: 1,
  570. upgradeItems: [
  571. Em.Object.create({
  572. stage_id: 1
  573. })
  574. ]
  575. }),
  576. Em.Object.create({
  577. group_id: 2,
  578. upgradeItems: [
  579. Em.Object.create({
  580. stage_id: 2
  581. }),
  582. Em.Object.create({
  583. stage_id: 3
  584. })
  585. ]
  586. })
  587. ]
  588. });
  589. var newData = {
  590. Upgrade: {
  591. request_id: 1
  592. },
  593. upgrade_groups: [
  594. {
  595. UpgradeGroup: {
  596. group_id: 1,
  597. status: 'COMPLETED',
  598. progress_percent: 100,
  599. completed_task_count: 3
  600. },
  601. upgrade_items: [
  602. {
  603. UpgradeItem: {
  604. stage_id: 1,
  605. status: 'COMPLETED',
  606. progress_percent: 100
  607. }
  608. }
  609. ]
  610. },
  611. {
  612. UpgradeGroup: {
  613. group_id: 2,
  614. status: 'ABORTED',
  615. progress_percent: 50,
  616. completed_task_count: 1
  617. },
  618. upgrade_items: [
  619. {
  620. UpgradeItem: {
  621. stage_id: 2,
  622. status: 'ABORTED',
  623. progress_percent: 99
  624. }
  625. },
  626. {
  627. UpgradeItem: {
  628. stage_id: 3,
  629. status: 'PENDING',
  630. progress_percent: 0
  631. }
  632. }
  633. ]
  634. }
  635. ]
  636. };
  637. controller.set('upgradeData', oldData);
  638. controller.updateUpgradeData(newData);
  639. expect(controller.get('upgradeData.upgradeGroups')[0].get('status')).to.equal('COMPLETED');
  640. expect(controller.get('upgradeData.upgradeGroups')[0].get('progress_percent')).to.equal(100);
  641. expect(controller.get('upgradeData.upgradeGroups')[0].get('completed_task_count')).to.equal(3);
  642. expect(controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].get('status')).to.equal('COMPLETED');
  643. expect(controller.get('upgradeData.upgradeGroups')[0].get('upgradeItems')[0].get('progress_percent')).to.equal(100);
  644. expect(controller.get('upgradeData.upgradeGroups')[0].get('hasExpandableItems')).to.be.true;
  645. expect(controller.get('upgradeData.upgradeGroups')[1].get('status')).to.equal('ABORTED');
  646. expect(controller.get('upgradeData.upgradeGroups')[1].get('progress_percent')).to.equal(50);
  647. expect(controller.get('upgradeData.upgradeGroups')[1].get('completed_task_count')).to.equal(1);
  648. expect(controller.get('upgradeData.upgradeGroups')[1].get('upgradeItems')[0].get('status')).to.equal('ABORTED');
  649. expect(controller.get('upgradeData.upgradeGroups')[1].get('upgradeItems')[1].get('status')).to.equal('PENDING');
  650. expect(controller.get('upgradeData.upgradeGroups')[1].get('upgradeItems')[0].get('progress_percent')).to.equal(99);
  651. expect(controller.get('upgradeData.upgradeGroups')[1].get('upgradeItems')[1].get('progress_percent')).to.equal(0);
  652. expect(controller.get('upgradeData.upgradeGroups')[1].get('hasExpandableItems')).to.be.false;
  653. });
  654. });
  655. describe("#initUpgradeData()", function() {
  656. beforeEach(function () {
  657. sinon.stub(controller, 'setDBProperty');
  658. });
  659. afterEach(function () {
  660. controller.setDBProperty.restore();
  661. });
  662. it("", function() {
  663. var newData = {
  664. Upgrade: {
  665. request_id: 1,
  666. downgrade_allowed: false
  667. },
  668. upgrade_groups: [
  669. {
  670. UpgradeGroup: {
  671. group_id: 1
  672. },
  673. upgrade_items: [
  674. {
  675. UpgradeItem: {
  676. stage_id: 1,
  677. status: 'IN_PROGRESS'
  678. }
  679. },
  680. {
  681. UpgradeItem: {
  682. stage_id: 2
  683. }
  684. }
  685. ]
  686. },
  687. {
  688. UpgradeGroup: {
  689. group_id: 2
  690. },
  691. upgrade_items: []
  692. },
  693. {
  694. UpgradeGroup: {
  695. group_id: 3
  696. },
  697. upgrade_items: [
  698. {
  699. UpgradeItem: {
  700. stage_id: 3,
  701. status: 'ABORTED'
  702. }
  703. },
  704. {
  705. UpgradeItem: {
  706. stage_id: 4,
  707. status: 'PENDING'
  708. }
  709. }
  710. ]
  711. }
  712. ]
  713. };
  714. controller.initUpgradeData(newData);
  715. expect(controller.setDBProperty.calledWith('downgradeAllowed', false)).to.be.true;
  716. expect(controller.get('downgradeAllowed')).to.be.false;
  717. expect(controller.get('upgradeData.Upgrade.request_id')).to.equal(1);
  718. expect(controller.get('upgradeData.upgradeGroups')[0].get('group_id')).to.equal(3);
  719. expect(controller.get('upgradeData.upgradeGroups')[1].get('group_id')).to.equal(2);
  720. expect(controller.get('upgradeData.upgradeGroups')[2].get('group_id')).to.equal(1);
  721. expect(controller.get('upgradeData.upgradeGroups')[2].get('upgradeItems')[0].get('stage_id')).to.equal(2);
  722. expect(controller.get('upgradeData.upgradeGroups')[2].get('upgradeItems')[1].get('stage_id')).to.equal(1);
  723. expect(controller.get('upgradeData.upgradeGroups')[0].get('hasExpandableItems')).to.be.false;
  724. expect(controller.get('upgradeData.upgradeGroups')[1].get('hasExpandableItems')).to.be.false;
  725. expect(controller.get('upgradeData.upgradeGroups')[2].get('hasExpandableItems')).to.be.true;
  726. });
  727. });
  728. describe.skip("#finish()", function() {
  729. before(function () {
  730. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  731. sinon.stub(controller, 'setDBProperty', Em.K);
  732. });
  733. after(function () {
  734. App.clusterStatus.setClusterStatus.restore();
  735. controller.setDBProperty.restore();
  736. });
  737. it("upgradeState is not COMPLETED", function() {
  738. App.set('upgradeState', 'UPGRADING');
  739. controller.finish();
  740. expect(App.clusterStatus.setClusterStatus.called).to.be.false;
  741. });
  742. it("upgradeState is COMPLETED", function() {
  743. App.set('upgradeState', 'COMPLETED');
  744. controller.finish();
  745. expect(controller.setDBProperty.calledWith('upgradeId', undefined)).to.be.true;
  746. expect(controller.setDBProperty.calledWith('upgradeVersion', undefined)).to.be.true;
  747. expect(controller.setDBProperty.calledWith('upgradeState', 'INIT')).to.be.true;
  748. expect(controller.setDBProperty.calledWith('currentVersion', undefined)).to.be.true;
  749. expect(App.get('upgradeState')).to.equal('INIT');
  750. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  751. });
  752. });
  753. describe("#confirmDowngrade()", function() {
  754. before(function () {
  755. sinon.spy(App, 'showConfirmationPopup');
  756. sinon.stub(controller, 'downgrade', Em.K);
  757. });
  758. after(function () {
  759. App.showConfirmationPopup.restore();
  760. controller.downgrade.restore();
  761. });
  762. it("show confirmation popup", function() {
  763. controller.set('currentVersion', Em.Object.create({
  764. repository_version: '2.2',
  765. repository_name: 'HDP-2.2'
  766. }));
  767. var popup = controller.confirmDowngrade();
  768. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  769. popup.onPrimary();
  770. expect(controller.downgrade.calledWith(Em.Object.create({
  771. repository_version: '2.2',
  772. repository_name: 'HDP-2.2'
  773. }))).to.be.true;
  774. });
  775. });
  776. describe("#upgradeOptions()", function() {
  777. before(function () {
  778. sinon.spy(App, 'ModalPopup');
  779. sinon.spy(App, 'showConfirmationFeedBackPopup');
  780. this.mock = sinon.stub(controller, 'getSupportedUpgradeTypes');
  781. sinon.stub(controller, 'runPreUpgradeCheck', Em.K);
  782. });
  783. after(function () {
  784. App.ModalPopup.restore();
  785. App.showConfirmationFeedBackPopup.restore();
  786. controller.runPreUpgradeCheck.restore();
  787. this.mock.restore();
  788. controller.get('upgradeMethods').setEach('selected', false);
  789. });
  790. it("show confirmation popup", function() {
  791. var version = Em.Object.create({displayName: 'HDP-2.2'});
  792. this.mock.returns({
  793. done: function(callback) {callback([1]);}
  794. });
  795. controller.get('upgradeMethods')[0].set('selected', true);
  796. controller.set('isDowngrade', false);
  797. var popup = controller.upgradeOptions(false, version);
  798. expect(App.ModalPopup.calledOnce).to.be.true;
  799. var confirmPopup = popup.onPrimary();
  800. expect(App.showConfirmationFeedBackPopup.calledOnce).to.be.true;
  801. confirmPopup.onPrimary();
  802. expect(controller.runPreUpgradeCheck.calledWith(version)).to.be.true;
  803. });
  804. it("NOT show confirmation popup on Downgrade", function() {
  805. var version = Em.Object.create({displayName: 'HDP-2.2'});
  806. this.mock.returns({
  807. done: function(callback) {callback([1]);}
  808. });
  809. controller.set('isDowngrade', true);
  810. var popup = controller.upgradeOptions(false, version);
  811. expect(App.ModalPopup.calledOnce).to.be.false;
  812. });
  813. });
  814. describe("#confirmUpgrade()", function() {
  815. before(function () {
  816. sinon.stub(controller, 'upgradeOptions', Em.K);
  817. });
  818. after(function () {
  819. controller.upgradeOptions.restore();
  820. });
  821. it("show show upgrade options popup window", function() {
  822. var version = Em.Object.create({displayName: 'HDP-2.2'});
  823. controller.confirmUpgrade(version);
  824. expect(controller.upgradeOptions.calledWith(false, version)).to.be.true;
  825. });
  826. });
  827. describe("#downgrade()", function() {
  828. before(function () {
  829. sinon.stub(App.ajax, 'send', Em.K);
  830. sinon.stub(controller, 'abortUpgrade');
  831. sinon.stub(App.RepositoryVersion, 'find').returns([
  832. Em.Object.create({
  833. displayName: 'HDP-2.3',
  834. repositoryVersion: '2.3'
  835. })
  836. ]);
  837. });
  838. after(function () {
  839. App.ajax.send.restore();
  840. controller.abortUpgrade.restore();
  841. App.RepositoryVersion.find.restore();
  842. });
  843. it("make ajax call", function() {
  844. controller.set('upgradeVersion', 'HDP-2.3');
  845. controller.set('upgradeType', 'NON_ROLLING');
  846. controller.downgrade(Em.Object.create({
  847. repository_version: '2.2',
  848. repository_name: 'HDP-2.2'
  849. }), {context: 'context'});
  850. expect(controller.abortUpgrade.calledOnce).to.be.true;
  851. expect(App.ajax.send.getCall(0).args[0].data).to.eql({
  852. from: '2.3',
  853. value: '2.2',
  854. label: 'HDP-2.2',
  855. isDowngrade: true,
  856. upgradeType: "NON_ROLLING"
  857. });
  858. expect(App.ajax.send.getCall(0).args[0].name).to.eql('admin.downgrade.start');
  859. expect(App.ajax.send.getCall(0).args[0].sender).to.eql(controller);
  860. expect(App.ajax.send.getCall(0).args[0].success).to.eql('upgradeSuccessCallback');
  861. expect(App.ajax.send.getCall(0).args[0].callback).to.be.called;
  862. });
  863. });
  864. describe("#installRepoVersionConfirmation()", function () {
  865. before(function () {
  866. sinon.stub(controller, 'installRepoVersion', Em.K);
  867. });
  868. after(function () {
  869. controller.installRepoVersion.restore();
  870. });
  871. it("show popup", function () {
  872. var repo = Em.Object.create({'displayName': 'HDP-2.2'});
  873. var popup = controller.installRepoVersionConfirmation(repo);
  874. popup.onPrimary();
  875. expect(controller.installRepoVersion.calledWith(repo)).to.be.true;
  876. });
  877. });
  878. describe("#installRepoVersion()", function () {
  879. before(function () {
  880. sinon.stub(App.ajax, 'send', Em.K);
  881. });
  882. after(function () {
  883. App.ajax.send.restore();
  884. });
  885. it("make ajax call", function () {
  886. var repo = Em.Object.create({
  887. stackVersionType: 'HDP',
  888. stackVersionNumber: '2.2',
  889. repositoryVersion: '2.2.1',
  890. repoId: 1
  891. });
  892. controller.installRepoVersion(repo);
  893. expect(App.ajax.send.calledOnce).to.be.true;
  894. });
  895. });
  896. describe("#installRepoVersionSuccess()", function() {
  897. var mock = Em.Object.create({
  898. id: 1,
  899. defaultStatus: 'INIT',
  900. stackVersion: {}
  901. });
  902. before(function () {
  903. sinon.spy(mock, 'set');
  904. sinon.stub(App.db, 'set', Em.K);
  905. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  906. sinon.stub(App.RepositoryVersion, 'find').returns(mock);
  907. });
  908. after(function () {
  909. App.db.set.restore();
  910. App.clusterStatus.setClusterStatus.restore();
  911. App.RepositoryVersion.find.restore();
  912. });
  913. it("", function() {
  914. controller.installRepoVersionSuccess({Requests: {id: 1}}, {}, {id: 1});
  915. expect(App.db.set.calledWith('repoVersionInstall', 'id', [1])).to.be.true;
  916. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  917. expect(App.RepositoryVersion.find.calledWith(1)).to.be.true;
  918. expect(App.RepositoryVersion.find(1).get('defaultStatus')).to.equal('INSTALLING');
  919. expect(App.RepositoryVersion.find(1).get('stackVersion.state')).to.equal('INSTALLING');
  920. });
  921. });
  922. describe("#setUpgradeItemStatus()", function () {
  923. before(function () {
  924. sinon.stub(App.ajax, 'send', function () {
  925. return {
  926. done: function (callback) {
  927. callback();
  928. }
  929. }
  930. });
  931. });
  932. after(function () {
  933. App.ajax.send.restore();
  934. });
  935. it("", function () {
  936. var item = Em.Object.create({
  937. request_id: 1,
  938. stage_id: 1,
  939. group_id: 1
  940. });
  941. controller.setUpgradeItemStatus(item, 'PENDING');
  942. expect(App.ajax.send.getCall(0).args[0].data).to.eql({upgradeId: 1, itemId: 1, groupId: 1, status: 'PENDING'});
  943. expect(App.ajax.send.getCall(0).args[0].name).to.eql('admin.upgrade.upgradeItem.setState');
  944. expect(App.ajax.send.getCall(0).args[0].sender).to.eql(controller);
  945. expect(App.ajax.send.getCall(0).args[0].callback).to.be.called;
  946. expect(item.get('status')).to.equal('PENDING');
  947. });
  948. });
  949. describe("#prepareRepoForSaving()", function () {
  950. it("prepare date for saving", function () {
  951. var repo = Em.Object.create({
  952. operatingSystems: [
  953. Em.Object.create({
  954. osType: "redhat6",
  955. isDisabled: Ember.computed.not('isSelected'),
  956. repositories: [Em.Object.create({
  957. "baseUrl": "111121",
  958. "repoId": "HDP-2.2",
  959. "repoName": "HDP",
  960. hasError: false
  961. }),
  962. Em.Object.create({
  963. "baseUrl": "1",
  964. "repoId": "HDP-UTILS-1.1.0.20",
  965. "repoName": "HDP-UTILS",
  966. hasError: false
  967. })]
  968. })
  969. ]
  970. });
  971. var result = {
  972. "operating_systems": [
  973. {
  974. "OperatingSystems": {
  975. "os_type": "redhat6"
  976. },
  977. "repositories": [
  978. {
  979. "Repositories": {
  980. "base_url": "111121",
  981. "repo_id": "HDP-2.2",
  982. "repo_name": "HDP"
  983. }
  984. },
  985. {
  986. "Repositories": {
  987. "base_url": "1",
  988. "repo_id": "HDP-UTILS-1.1.0.20",
  989. "repo_name": "HDP-UTILS"
  990. }
  991. }
  992. ]
  993. }
  994. ]};
  995. expect(controller.prepareRepoForSaving(repo)).to.eql(result);
  996. });
  997. });
  998. describe("#getStackVersionNumber()", function(){
  999. it("get stack version number", function(){
  1000. var repo = Em.Object.create({
  1001. "stackVersionType": 'HDP',
  1002. "stackVersion": '2.3',
  1003. "repositoryVersion": '2.2.1'
  1004. });
  1005. var stackVersion = controller.getStackVersionNumber(repo);
  1006. expect(stackVersion).to.equal('2.3');
  1007. });
  1008. it("get default stack version number", function(){
  1009. App.set('currentStackVersion', '1.2.3');
  1010. var repo = Em.Object.create({
  1011. "stackVersionType": 'HDP',
  1012. "repositoryVersion": '2.2.1'
  1013. });
  1014. var stackVersion = controller.getStackVersionNumber(repo);
  1015. expect(stackVersion).to.equal('1.2.3');
  1016. });
  1017. });
  1018. describe("#saveRepoOS()", function() {
  1019. before(function(){
  1020. this.mock = sinon.stub(controller, 'validateRepoVersions');
  1021. sinon.stub(controller, 'prepareRepoForSaving', Em.K);
  1022. sinon.stub(App.ajax, 'send').returns({success: Em.K});
  1023. });
  1024. after(function(){
  1025. this.mock.restore();
  1026. controller.prepareRepoForSaving.restore();
  1027. App.ajax.send.restore();
  1028. });
  1029. it("validation errors present", function() {
  1030. this.mock.returns({
  1031. done: function(callback) {callback([1]);}
  1032. });
  1033. controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
  1034. expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
  1035. expect(controller.prepareRepoForSaving.called).to.be.false;
  1036. expect(App.ajax.send.called).to.be.false;
  1037. });
  1038. it("no validation errors", function() {
  1039. this.mock.returns({
  1040. done: function(callback) {callback([]);}
  1041. });
  1042. controller.saveRepoOS(Em.Object.create({repoVersionId: 1}), true);
  1043. expect(controller.validateRepoVersions.calledWith(Em.Object.create({repoVersionId: 1}), true)).to.be.true;
  1044. expect(controller.prepareRepoForSaving.calledWith(Em.Object.create({repoVersionId: 1}))).to.be.true;
  1045. expect(App.ajax.send.calledOnce).to.be.true;
  1046. });
  1047. });
  1048. describe("#validateRepoVersions()", function () {
  1049. before(function () {
  1050. sinon.stub(App.ajax, 'send').returns({success: Em.K, error: Em.K});
  1051. });
  1052. after(function () {
  1053. App.ajax.send.restore();
  1054. });
  1055. it("skip validation", function () {
  1056. controller.validateRepoVersions(Em.Object.create({repoVersionId: 1}), true);
  1057. expect(App.ajax.send.called).to.be.false;
  1058. });
  1059. it("do validation", function () {
  1060. var repo = Em.Object.create({
  1061. repoVersionId: 1,
  1062. operatingSystems: [
  1063. Em.Object.create({
  1064. isSelected: true,
  1065. repositories: [
  1066. Em.Object.create()
  1067. ]
  1068. })
  1069. ]
  1070. });
  1071. controller.validateRepoVersions(repo, false);
  1072. expect(App.ajax.send.calledOnce).to.be.true;
  1073. });
  1074. });
  1075. describe("#showProgressPopup()", function () {
  1076. var mock = {
  1077. initPopup: Em.K
  1078. };
  1079. before(function () {
  1080. sinon.stub(App.router, 'get').withArgs('highAvailabilityProgressPopupController').returns(mock);
  1081. sinon.spy(mock, 'initPopup');
  1082. });
  1083. after(function () {
  1084. App.router.get.restore();
  1085. mock.initPopup.restore();
  1086. });
  1087. it("", function () {
  1088. controller.showProgressPopup(Em.Object.create());
  1089. expect(mock.initPopup.calledOnce).to.be.true;
  1090. });
  1091. });
  1092. describe("#getUrl()", function() {
  1093. beforeEach(function(){
  1094. controller.reopen({
  1095. realStackUrl: 'realStackUrl',
  1096. realRepoUrl: 'realRepoUrl',
  1097. realUpdateUrl: 'realUpdateUrl'
  1098. });
  1099. });
  1100. it("full load is true, stack is null", function() {
  1101. expect(controller.getUrl(null, true)).to.equal('realRepoUrl');
  1102. });
  1103. it("full load is true, stack is valid", function() {
  1104. expect(controller.getUrl({}, true)).to.equal('realStackUrl');
  1105. });
  1106. it("full load is false, stack is valid", function() {
  1107. expect(controller.getUrl({}, false)).to.equal('realUpdateUrl');
  1108. });
  1109. });
  1110. describe("#loadStackVersionsToModel()", function () {
  1111. before(function () {
  1112. sinon.stub(App.HttpClient, 'get');
  1113. });
  1114. after(function () {
  1115. App.HttpClient.get.restore();
  1116. });
  1117. it("", function () {
  1118. controller.loadStackVersionsToModel();
  1119. expect(App.HttpClient.get.calledOnce).to.be.true;
  1120. });
  1121. });
  1122. describe("#loadRepoVersionsToModel()", function () {
  1123. before(function () {
  1124. sinon.stub(App.HttpClient, 'get');
  1125. });
  1126. after(function () {
  1127. App.HttpClient.get.restore();
  1128. });
  1129. it("", function () {
  1130. controller.loadRepoVersionsToModel();
  1131. expect(App.HttpClient.get.calledOnce).to.be.true;
  1132. });
  1133. });
  1134. describe('#currentVersionObserver()', function () {
  1135. var cases = [
  1136. {
  1137. stackVersionType: 'HDP',
  1138. repoVersion: '2.2.1.1.0-1',
  1139. isStormMetricsSupported: false,
  1140. title: 'HDP < 2.2.2'
  1141. },
  1142. {
  1143. stackVersionType: 'HDP',
  1144. repoVersion: '2.2.2.1.0-1',
  1145. isStormMetricsSupported: true,
  1146. title: 'HDP 2.2.2'
  1147. },
  1148. {
  1149. stackVersionType: 'HDP',
  1150. repoVersion: '2.2.3.1.0-1',
  1151. isStormMetricsSupported: true,
  1152. title: 'HDP > 2.2.2'
  1153. },
  1154. {
  1155. stackVersionType: 'BIGTOP',
  1156. repoVersion: '0.8.1.1.0-1',
  1157. isStormMetricsSupported: true,
  1158. title: 'not HDP'
  1159. }
  1160. ];
  1161. afterEach(function () {
  1162. App.RepositoryVersion.find.restore();
  1163. });
  1164. cases.forEach(function (item) {
  1165. it(item.title, function () {
  1166. sinon.stub(App.RepositoryVersion, 'find').returns([
  1167. Em.Object.create({
  1168. status: 'CURRENT',
  1169. stackVersionType: item.stackVersionType
  1170. })
  1171. ]);
  1172. controller.set('currentVersion', {
  1173. repository_version: item.repoVersion
  1174. });
  1175. expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
  1176. });
  1177. });
  1178. });
  1179. describe('#updateFinalize', function () {
  1180. beforeEach(function() {
  1181. sinon.stub($, 'ajax', Em.K);
  1182. controller.set('isFinalizeItem', true);
  1183. });
  1184. afterEach(function () {
  1185. $.ajax.restore();
  1186. });
  1187. it('should do ajax-request', function () {
  1188. sinon.stub(App, 'get').withArgs('upgradeState').returns('HOLDING');
  1189. controller.updateFinalize();
  1190. App.get.restore();
  1191. expect($.ajax.calledOnce).to.be.true;
  1192. });
  1193. it('shouldn\'t do ajax-request', function () {
  1194. sinon.stub(App, 'get').withArgs('upgradeState').returns('HOLDING_TIMEDOUT');
  1195. controller.updateFinalize();
  1196. App.get.restore();
  1197. expect(controller.get('isFinalizeItem')).to.be.false;
  1198. expect($.ajax.calledOnce).to.be.false;
  1199. });
  1200. });
  1201. describe('#updateFinalizeSuccessCallback', function () {
  1202. it('data exists and Finalize should be true', function() {
  1203. var data = {
  1204. items: [
  1205. {
  1206. upgrade_groups: [
  1207. {
  1208. upgrade_items: [
  1209. {
  1210. UpgradeItem: {
  1211. context: controller.get('finalizeContext'),
  1212. status: "HOLDING"
  1213. }
  1214. }
  1215. ]
  1216. }
  1217. ]
  1218. }
  1219. ]
  1220. };
  1221. controller.set('isFinalizeItem', false);
  1222. controller.updateFinalizeSuccessCallback(data);
  1223. expect(controller.get('isFinalizeItem')).to.be.true;
  1224. });
  1225. it('data exists and Finalize should be false', function() {
  1226. var data = {
  1227. upgrade_groups: [
  1228. {
  1229. upgrade_items: [
  1230. {
  1231. UpgradeItem: {
  1232. context: '!@#$%^&',
  1233. status: "HOLDING"
  1234. }
  1235. }
  1236. ]
  1237. }
  1238. ]
  1239. };
  1240. controller.set('isFinalizeItem', true);
  1241. controller.updateFinalizeSuccessCallback(data);
  1242. expect(controller.get('isFinalizeItem')).to.be.false;
  1243. });
  1244. it('data doesn\'t exist', function() {
  1245. var data = null;
  1246. controller.set('isFinalizeItem', true);
  1247. controller.updateFinalizeSuccessCallback(data);
  1248. expect(controller.get('isFinalizeItem')).to.be.false;
  1249. });
  1250. });
  1251. describe('#updateFinalizeErrorCallback', function () {
  1252. it('should set isFinalizeItem to false', function () {
  1253. controller.set('isFinalizeItem', true);
  1254. controller.updateFinalizeErrorCallback();
  1255. expect(controller.get('isFinalizeItem')).to.be.false;
  1256. });
  1257. });
  1258. describe("#suspendUpgrade()", function() {
  1259. beforeEach(function () {
  1260. sinon.stub(controller, 'abortUpgrade').returns({
  1261. done: function (callback) {
  1262. callback();
  1263. }
  1264. });
  1265. sinon.stub(controller, 'setDBProperty', Em.K);
  1266. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  1267. });
  1268. afterEach(function () {
  1269. controller.abortUpgrade.restore();
  1270. controller.setDBProperty.restore();
  1271. App.clusterStatus.setClusterStatus.restore();
  1272. });
  1273. it("", function() {
  1274. controller.suspendUpgrade();
  1275. expect(controller.abortUpgrade.calledOnce).to.be.true;
  1276. expect(App.get('upgradeState')).to.equal('ABORTED');
  1277. expect(controller.get('isSuspended')).to.be.true;
  1278. expect(controller.setDBProperty.calledWith('upgradeState', 'ABORTED')).to.be.true;
  1279. expect(controller.setDBProperty.calledWith('isSuspended', true)).to.be.true;
  1280. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1281. });
  1282. });
  1283. describe("#resumeUpgrade()", function() {
  1284. beforeEach(function () {
  1285. sinon.stub(controller, 'retryUpgrade').returns({
  1286. done: function (callback) {
  1287. callback();
  1288. }
  1289. });
  1290. sinon.stub(controller, 'setDBProperty', Em.K);
  1291. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  1292. });
  1293. afterEach(function () {
  1294. controller.retryUpgrade.restore();
  1295. controller.setDBProperty.restore();
  1296. App.clusterStatus.setClusterStatus.restore();
  1297. });
  1298. it("", function() {
  1299. controller.resumeUpgrade();
  1300. expect(controller.retryUpgrade.calledOnce).to.be.true;
  1301. expect(App.get('upgradeState')).to.equal('PENDING');
  1302. expect(controller.get('isSuspended')).to.be.false;
  1303. expect(controller.setDBProperty.calledWith('upgradeState', 'PENDING')).to.be.true;
  1304. expect(controller.setDBProperty.calledWith('isSuspended', false)).to.be.true;
  1305. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  1306. });
  1307. });
  1308. describe("#runUpgradeMethodChecks()", function() {
  1309. beforeEach(function () {
  1310. sinon.stub(controller, 'runPreUpgradeCheckOnly');
  1311. });
  1312. afterEach(function () {
  1313. controller.runPreUpgradeCheckOnly.restore();
  1314. controller.get('upgradeMethods').setEach('allowed', true);
  1315. });
  1316. it("no allowed upgrade methods", function () {
  1317. controller.get('upgradeMethods').setEach('allowed', false);
  1318. controller.runUpgradeMethodChecks();
  1319. expect(controller.runPreUpgradeCheckOnly.called).to.be.false;
  1320. });
  1321. it("Rolling method allowed", function () {
  1322. controller.get('upgradeMethods').setEach('allowed', true);
  1323. controller.runUpgradeMethodChecks(Em.Object.create({
  1324. repositoryVersion: 'v1',
  1325. displayName: 'V1'
  1326. }));
  1327. expect(controller.runPreUpgradeCheckOnly.calledWith({
  1328. value: 'v1',
  1329. label: 'V1',
  1330. type: 'ROLLING'
  1331. })).to.be.true;
  1332. });
  1333. });
  1334. describe("#restoreLastUpgrade()", function () {
  1335. beforeEach(function () {
  1336. sinon.stub(App.RepositoryVersion, 'find').returns([Em.Object.create({
  1337. repositoryVersion: '1',
  1338. displayName: 'HDP-1'
  1339. })]);
  1340. sinon.stub(controller, 'setDBProperties');
  1341. sinon.stub(controller, 'loadRepoVersionsToModel', function () {
  1342. return {
  1343. done: function (callback) {
  1344. callback();
  1345. }
  1346. }
  1347. });
  1348. sinon.stub(controller, 'setDBProperty');
  1349. sinon.stub(controller, 'initDBProperties');
  1350. sinon.stub(controller, 'loadUpgradeData');
  1351. });
  1352. afterEach(function () {
  1353. App.RepositoryVersion.find.restore();
  1354. controller.setDBProperties.restore();
  1355. controller.loadRepoVersionsToModel.restore();
  1356. controller.setDBProperty.restore();
  1357. controller.initDBProperties.restore();
  1358. controller.loadUpgradeData.restore();
  1359. });
  1360. it("", function () {
  1361. var data = {
  1362. Upgrade: {
  1363. request_id: 1,
  1364. direction: 'UPGRADE',
  1365. request_status: 'PENDING',
  1366. upgrade_type: 'ROLLING',
  1367. downgrade_allowed: true,
  1368. skip_failures: true,
  1369. skip_service_check_failures: true,
  1370. to_version: '1'
  1371. }
  1372. };
  1373. controller.restoreLastUpgrade(data);
  1374. expect(controller.setDBProperties.getCall(0).args[0]).to.eql({
  1375. upgradeId: 1,
  1376. isDowngrade: false,
  1377. upgradeState: 'PENDING',
  1378. upgradeType: "ROLLING",
  1379. downgradeAllowed: true,
  1380. upgradeTypeDisplayName: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.RU.title'),
  1381. failuresTolerance: Em.Object.create({
  1382. skipComponentFailures: true,
  1383. skipSCFailures: true
  1384. })
  1385. });
  1386. expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
  1387. expect(controller.setDBProperty.calledWith('upgradeVersion', 'HDP-1')).to.be.true;
  1388. expect(controller.initDBProperties.calledOnce).to.be.true;
  1389. expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
  1390. });
  1391. });
  1392. describe("#getServiceCheckItemSuccessCallback()", function() {
  1393. var testCases = [
  1394. {
  1395. title: 'no tasks',
  1396. data: {
  1397. tasks: []
  1398. },
  1399. expected: {
  1400. slaveComponentStructuredInfo: null,
  1401. serviceCheckFailuresServicenames: []
  1402. }
  1403. },
  1404. {
  1405. title: 'no structured_out property',
  1406. data: {
  1407. tasks: [
  1408. {
  1409. Tasks: {}
  1410. }
  1411. ]
  1412. },
  1413. expected: {
  1414. slaveComponentStructuredInfo: null,
  1415. serviceCheckFailuresServicenames: []
  1416. }
  1417. },
  1418. {
  1419. title: 'no failures',
  1420. data: {
  1421. tasks: [
  1422. {
  1423. Tasks: {
  1424. structured_out: {}
  1425. }
  1426. }
  1427. ]
  1428. },
  1429. expected: {
  1430. slaveComponentStructuredInfo: null,
  1431. serviceCheckFailuresServicenames: []
  1432. }
  1433. },
  1434. {
  1435. title: 'service check failures',
  1436. data: {
  1437. tasks: [
  1438. {
  1439. Tasks: {
  1440. structured_out: {
  1441. failures: {
  1442. service_check: ['HDSF', 'YARN']
  1443. }
  1444. }
  1445. }
  1446. }
  1447. ]
  1448. },
  1449. expected: {
  1450. slaveComponentStructuredInfo: {
  1451. hosts: [],
  1452. host_detail: {}
  1453. },
  1454. serviceCheckFailuresServicenames: ['HDSF', 'YARN']
  1455. }
  1456. },
  1457. {
  1458. title: 'host-component failures',
  1459. data: {
  1460. tasks: [
  1461. {
  1462. Tasks: {
  1463. structured_out: {
  1464. failures: {
  1465. service_check: ['HDSF'],
  1466. host_component: {
  1467. "host1": [
  1468. {
  1469. component: "DATANODE",
  1470. service: 'HDFS'
  1471. }
  1472. ]
  1473. }
  1474. }
  1475. }
  1476. }
  1477. }
  1478. ]
  1479. },
  1480. expected: {
  1481. slaveComponentStructuredInfo: {
  1482. hosts: ['host1'],
  1483. host_detail: {
  1484. "host1": [
  1485. {
  1486. component: "DATANODE",
  1487. service: 'HDFS'
  1488. }
  1489. ]
  1490. }
  1491. },
  1492. serviceCheckFailuresServicenames: ['HDSF']
  1493. }
  1494. }
  1495. ];
  1496. testCases.forEach(function(test) {
  1497. it(test.title, function() {
  1498. controller.set('slaveComponentStructuredInfo', null);
  1499. controller.set('serviceCheckFailuresServicenames', []);
  1500. controller.getServiceCheckItemSuccessCallback(test.data);
  1501. expect(controller.get('serviceCheckFailuresServicenames')).eql(test.expected.serviceCheckFailuresServicenames);
  1502. expect(controller.get('slaveComponentStructuredInfo')).eql(test.expected.slaveComponentStructuredInfo);
  1503. });
  1504. });
  1505. });
  1506. describe("#getSlaveComponentItemSuccessCallback()", function () {
  1507. var testCases = [
  1508. {
  1509. title: 'no tasks',
  1510. data: {
  1511. tasks: []
  1512. },
  1513. expected: {
  1514. slaveComponentStructuredInfo: null
  1515. }
  1516. },
  1517. {
  1518. title: 'structured_out property absent',
  1519. data: {
  1520. tasks: [
  1521. {
  1522. Tasks: {}
  1523. }
  1524. ]
  1525. },
  1526. expected: {
  1527. slaveComponentStructuredInfo: null
  1528. }
  1529. },
  1530. {
  1531. title: 'structured_out property present',
  1532. data: {
  1533. tasks: [
  1534. {
  1535. Tasks: {
  1536. "structured_out" : {
  1537. "hosts" : [
  1538. "host1"
  1539. ],
  1540. "host_detail" : {
  1541. "host1" : [
  1542. {
  1543. "service" : "FLUME",
  1544. "component" : "FLUME_HANDLER"
  1545. }
  1546. ]
  1547. }
  1548. }
  1549. }
  1550. }
  1551. ]
  1552. },
  1553. expected: {
  1554. slaveComponentStructuredInfo: {
  1555. "hosts" : [
  1556. "host1"
  1557. ],
  1558. "host_detail" : {
  1559. "host1" : [
  1560. {
  1561. "service" : "FLUME",
  1562. "component" : "FLUME_HANDLER"
  1563. }
  1564. ]
  1565. }
  1566. }
  1567. }
  1568. }
  1569. ];
  1570. testCases.forEach(function (test) {
  1571. it(test.title, function () {
  1572. controller.set('slaveComponentStructuredInfo', null);
  1573. controller.getSlaveComponentItemSuccessCallback(test.data);
  1574. expect(controller.get('slaveComponentStructuredInfo')).eql(test.expected.slaveComponentStructuredInfo);
  1575. });
  1576. });
  1577. });
  1578. describe("#openConfigsInNewWindow()", function () {
  1579. var mock = {
  1580. document: {
  1581. write: function () {}
  1582. },
  1583. focus: function () {}
  1584. };
  1585. before(function(){
  1586. sinon.stub(window, 'open', function () {
  1587. return mock;
  1588. });
  1589. sinon.spy(mock.document, 'write');
  1590. sinon.spy(mock, 'focus');
  1591. });
  1592. after(function(){
  1593. window.open.restore();
  1594. });
  1595. it("should open window and write table to it", function () {
  1596. controller.openConfigsInNewWindow({
  1597. context: [
  1598. {
  1599. type: 'type1',
  1600. name: 'name1',
  1601. currentValue: 'currentValue1',
  1602. recommendedValue: 'recommendedValue1',
  1603. resultingValue: 'resultingValue1'
  1604. },
  1605. {
  1606. type: 'type2',
  1607. name: 'name2',
  1608. currentValue: 'currentValue2',
  1609. recommendedValue: 'recommendedValue2',
  1610. resultingValue: 'resultingValue2'
  1611. }
  1612. ]
  1613. });
  1614. expect(window.open.calledOnce).to.be.true;
  1615. expect(mock.document.write.calledWith('<table style="text-align: left;"><thead><tr>' +
  1616. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.configType') + '</th>' +
  1617. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.propertyName') + '</th>' +
  1618. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.currentValue') + '</th>' +
  1619. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.recommendedValue') + '</th>' +
  1620. '<th>' + Em.I18n.t('popup.clusterCheck.Upgrade.configsMerge.resultingValue') + '</th>' +
  1621. '</tr></thead><tbody>' +
  1622. '<tr>' +
  1623. '<td>' + 'type1' + '</td>' +
  1624. '<td>' + 'name1' + '</td>' +
  1625. '<td>' + 'currentValue1' + '</td>' +
  1626. '<td>' + 'recommendedValue1' + '</td>' +
  1627. '<td>' + 'resultingValue1' + '</td>' +
  1628. '</tr>' +
  1629. '<tr>' +
  1630. '<td>' + 'type2' + '</td>' +
  1631. '<td>' + 'name2' + '</td>' +
  1632. '<td>' + 'currentValue2' + '</td>' +
  1633. '<td>' + 'recommendedValue2' + '</td>' +
  1634. '<td>' + 'resultingValue2' + '</td>' +
  1635. '</tr></tbody></table>')).to.be.true;
  1636. expect(mock.focus.calledOnce).to.be.true;
  1637. });
  1638. });
  1639. });