item_test.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  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. App = require('app');
  19. require('ember');
  20. require('models/host_component');
  21. require('views/common/modal_popup');
  22. require('mixins/common/userPref');
  23. require('controllers/application');
  24. require('controllers/global/background_operations_controller');
  25. require('controllers/global/cluster_controller');
  26. require('controllers/main/service/reassign_controller');
  27. require('controllers/main/service/item');
  28. var batchUtils = require('utils/batch_scheduled_requests');
  29. var testHelpers = require('test/helpers');
  30. var stackSerivceModel = {
  31. 'HDFS': Em.Object.create({
  32. serviceName: 'HDFS',
  33. requiredServices: ['ZOOKEEPER']
  34. }),
  35. 'YARN': Em.Object.create({
  36. serviceName: 'YARN',
  37. requiredServices: ['MAPREDUCE2', 'HDFS']
  38. }),
  39. 'MAPREDUCE2': Em.Object.create({
  40. serviceName: 'MAPREDUCE2',
  41. requiredServices: ['YARN']
  42. }),
  43. 'TEZ': Em.Object.create({
  44. serviceName: 'TEZ',
  45. requiredServices: ['YARN']
  46. }),
  47. 'HIVE': Em.Object.create({
  48. serviceName: 'HIVE',
  49. requiredServices: ['YARN', 'TEZ']
  50. })
  51. };
  52. describe('App.MainServiceItemController', function () {
  53. describe('#setStartStopState', function () {
  54. var tests = [
  55. {
  56. serviceController: {
  57. serviceName: "YARN"
  58. },
  59. backgroundOperationsController: {
  60. services: [
  61. {
  62. isRunning: true,
  63. dependentService: "ALL_SERVICES"
  64. }
  65. ]
  66. },
  67. isPending: true,
  68. m: 'operaion is active because all services are running'
  69. },
  70. {
  71. serviceController: {
  72. serviceName: "HBASE"
  73. },
  74. backgroundOperationsController: {
  75. services: [
  76. {
  77. isRunning: true,
  78. dependentService: "HBASE"
  79. }
  80. ]
  81. },
  82. isPending: true,
  83. m: 'operaion is active button because current service is running'
  84. },
  85. {
  86. serviceController: {
  87. serviceName: "HDFS"
  88. },
  89. backgroundOperationsController: {
  90. services: [
  91. ]
  92. },
  93. isPending: true,
  94. m: 'pending is true - backgroundOperationsController.services is empty'
  95. },
  96. {
  97. serviceController: {
  98. serviceName: "HBASE"
  99. },
  100. backgroundOperationsController: {
  101. services: [
  102. {
  103. isRunning: false,
  104. dependentService: "ALL_SERVICES"
  105. }
  106. ]
  107. },
  108. isPending: false,
  109. m: 'pending is false - operation is not running'
  110. },
  111. {
  112. serviceController: {
  113. serviceName: "HBASE"
  114. },
  115. backgroundOperationsController: {
  116. services: [
  117. {
  118. isRunning: true,
  119. dependentService: "HDFS"
  120. }
  121. ]
  122. },
  123. isPending: false,
  124. m: 'pending is false - current service is not running'
  125. }
  126. ];
  127. tests.forEach(function (test) {
  128. describe(test.m, function () {
  129. var mainServiceItemController;
  130. beforeEach(function () {
  131. sinon.stub(App.router, 'get', function(k) {
  132. if ('backgroundOperationsController.services' === k) return test.backgroundOperationsController.services;
  133. return Em.get(App.router, k);
  134. });
  135. mainServiceItemController = App.MainServiceItemController.create({content: {serviceName: test.serviceController.serviceName}});
  136. mainServiceItemController.setStartStopState();
  137. });
  138. afterEach(function () {
  139. App.router.get.restore();
  140. });
  141. it('isPending is ' + test.isPending, function () {
  142. expect(mainServiceItemController.get('isPending')).to.equal(test.isPending);
  143. });
  144. });
  145. })
  146. });
  147. describe('#reassignMaster()', function () {
  148. var tests = [
  149. {
  150. host_components: [
  151. {componentName: "RESOURCEMANGER"}
  152. ],
  153. componentName: "RESOURCEMANGER",
  154. result: true,
  155. m: 'run reassignMaster'
  156. },
  157. {
  158. host_components: [
  159. {componentName: "RESOURCEMANGER"}
  160. ],
  161. componentName: "DATANODE",
  162. result: false,
  163. m: 'don\t run reassignMaster'
  164. }
  165. ];
  166. tests.forEach(function (test) {
  167. describe(test.m, function () {
  168. var reassignMasterController = App.ReassignMasterController.create({currentStep: ''});
  169. beforeEach(function () {
  170. sinon.stub(reassignMasterController, 'saveComponentToReassign', Em.K);
  171. sinon.stub(reassignMasterController, 'setCurrentStep', Em.K);
  172. sinon.stub(App.router, 'transitionTo', Em.K);
  173. var mainServiceItemController = App.MainServiceItemController.create({});
  174. sinon.stub(App.HostComponent, 'find', function() {
  175. return test.host_components
  176. });
  177. sinon.stub(App.router, 'get', function(k) {
  178. if ('reassignMasterController' === k) return reassignMasterController;
  179. return Em.get(App.router, k);
  180. });
  181. mainServiceItemController.reassignMaster(test.componentName);
  182. });
  183. afterEach(function () {
  184. reassignMasterController.saveComponentToReassign.restore();
  185. reassignMasterController.setCurrentStep.restore();
  186. App.HostComponent.find.restore();
  187. App.router.transitionTo.restore();
  188. App.router.get.restore();
  189. });
  190. it('saveComponentToReassign is ' + (test.result ? '' : 'not') + ' called once', function () {
  191. expect(reassignMasterController.saveComponentToReassign.calledOnce).to.equal(test.result);
  192. });
  193. it('setCurrentStep is ' + (test.result ? '' : 'not') + ' called once', function () {
  194. expect(reassignMasterController.setCurrentStep.calledOnce).to.equal(test.result);
  195. });
  196. });
  197. }, this);
  198. });
  199. describe("#doAction", function () {
  200. var el = document.createElement("BUTTON");
  201. el.disabled = false;
  202. var tests = [
  203. {
  204. event: {
  205. target: el,
  206. context: {
  207. action: 'runSmokeTest'
  208. }
  209. },
  210. m: "run runSmokeTest"
  211. },
  212. {
  213. event: {
  214. target: el,
  215. context: {
  216. action: 'refreshConfigs'
  217. }
  218. },
  219. m: "run refreshConfigs"
  220. },
  221. {
  222. event: {
  223. target: el,
  224. context: {
  225. action: 'restartAllHostComponents'
  226. }
  227. },
  228. m: "run restartAllHostComponents"
  229. },
  230. {
  231. event: {
  232. target: el,
  233. context: {
  234. action: 'rollingRestart'
  235. }
  236. },
  237. m: "run rollingRestart"
  238. }
  239. ];
  240. tests.forEach(function (test) {
  241. var mainServiceItemController = App.MainServiceItemController.create({});
  242. mainServiceItemController.set(test.event.context.action, Em.K);
  243. beforeEach(function () {
  244. sinon.spy(mainServiceItemController, test.event.context.action);
  245. });
  246. afterEach(function () {
  247. mainServiceItemController[test.event.context.action].restore();
  248. });
  249. it(test.m, function () {
  250. mainServiceItemController.doAction(test.event);
  251. expect(mainServiceItemController[test.event.context.action].calledOnce).to.equal(!test.event.target.disabled);
  252. });
  253. });
  254. });
  255. describe("#startService , #stopService", function () {
  256. var mainServiceItemController = App.MainServiceItemController.create({startStopPopup: Em.K});
  257. beforeEach(function () {
  258. sinon.spy(mainServiceItemController, "startStopPopup");
  259. });
  260. afterEach(function () {
  261. mainServiceItemController.startStopPopup.restore();
  262. });
  263. it("start service", function () {
  264. mainServiceItemController.startService({});
  265. expect(mainServiceItemController.startStopPopup.calledWith({},App.HostComponentStatus.started)).to.equal(true);
  266. });
  267. it("stop service", function () {
  268. mainServiceItemController.stopService({});
  269. expect(mainServiceItemController.startStopPopup.calledWith({},App.HostComponentStatus.stopped)).to.equal(true);
  270. });
  271. });
  272. describe("#turnOnOffPassive", function () {
  273. var mainServiceItemController = App.MainServiceItemController.create({turnOnOffPassiveRequest: Em.K});
  274. beforeEach(function () {
  275. sinon.spy(batchUtils, "turnOnOffPassiveRequest");
  276. mainServiceItemController.set('content', {serviceName: ''});
  277. });
  278. afterEach(function () {
  279. batchUtils.turnOnOffPassiveRequest.restore();
  280. });
  281. it("turns on/off passive mode for service", function () {
  282. mainServiceItemController.turnOnOffPassive({}).onPrimary();
  283. expect(batchUtils.turnOnOffPassiveRequest.calledOnce).to.equal(true);
  284. });
  285. });
  286. describe("#runSmokeTest", function () {
  287. var tests = [
  288. {
  289. content: {
  290. id: "YARN",
  291. service_name: "YARN",
  292. work_status: "STARTED"
  293. },
  294. startSmoke: true,
  295. serviceName: "MAPREDUCE2",
  296. m: "don't run smoke test primary for MAPREDUCE2"
  297. },
  298. {
  299. content: {
  300. id: "YARN",
  301. service_name: "YARN",
  302. work_status: "STOPPED"
  303. },
  304. startSmoke: false,
  305. serviceName: "MAPREDUCE2",
  306. m: "run smoke test primary for MAPREDUCE2"
  307. },
  308. {
  309. m: "run smoke test primary for all services (not MAPREDUCE2)",
  310. startSmoke: true,
  311. default: true
  312. }
  313. ];
  314. tests.forEach(function (test) {
  315. var mainServiceItemController = test.default ? App.MainServiceItemController.create({runSmokeTestPrimary: Em.K}) :
  316. App.MainServiceItemController.create({content: {serviceName: test.serviceName}, runSmokeTestPrimary: Em.K});
  317. beforeEach(function () {
  318. sinon.spy(mainServiceItemController, "runSmokeTestPrimary");
  319. });
  320. afterEach(function () {
  321. mainServiceItemController.runSmokeTestPrimary.restore();
  322. });
  323. it(test.m, function () {
  324. if (!test.default) {
  325. App.store.load(App.Service, test.content);
  326. }
  327. mainServiceItemController.runSmokeTest({}).onPrimary();
  328. expect(mainServiceItemController.runSmokeTestPrimary.calledOnce).to.equal(test.startSmoke);
  329. });
  330. });
  331. });
  332. describe("#startStopPopup", function () {
  333. var el = document.createElement("BUTTON");
  334. el.disabled = false;
  335. var event = {
  336. target: el
  337. };
  338. var mainServiceItemController = App.MainServiceItemController.create({
  339. content: {
  340. serviceName: "HDFS",
  341. hostComponents: [ {
  342. componentName: 'NAMENODE',
  343. workStatus: 'INSTALLED'
  344. }]
  345. }
  346. });
  347. var mainServiceItemControllerHdfsStarted = App.MainServiceItemController.create({
  348. content: {
  349. serviceName: "HDFS",
  350. hostComponents: [ {
  351. componentName: 'NAMENODE',
  352. workStatus: 'STARTED'
  353. }]
  354. }
  355. });
  356. beforeEach(function () {
  357. sinon.spy(mainServiceItemController, "startStopPopupPrimary");
  358. sinon.spy(mainServiceItemControllerHdfsStarted, "startStopPopupPrimary");
  359. sinon.spy(Em.I18n, "t");
  360. sinon.stub(mainServiceItemControllerHdfsStarted, 'checkNnLastCheckpointTime', function(callback) {
  361. return callback;
  362. });
  363. });
  364. afterEach(function () {
  365. mainServiceItemController.startStopPopupPrimary.restore();
  366. mainServiceItemControllerHdfsStarted.startStopPopupPrimary.restore();
  367. mainServiceItemControllerHdfsStarted.checkNnLastCheckpointTime.restore();
  368. Em.I18n.t.restore();
  369. });
  370. it("start start/stop service popup", function () {
  371. mainServiceItemController.startStopPopup(event, "").onPrimary();
  372. expect(mainServiceItemController.startStopPopupPrimary.calledOnce).to.equal(true);
  373. });
  374. it ("should popup warning to check last checkpoint time if work status is STARTED", function() {
  375. mainServiceItemControllerHdfsStarted.startStopPopup(event, "INSTALLED");
  376. expect(mainServiceItemControllerHdfsStarted.checkNnLastCheckpointTime.calledOnce).to.equal(true);
  377. });
  378. describe("modal messages", function() {
  379. beforeEach(function () {
  380. sinon.stub(App.StackService, 'find').returns([
  381. Em.Object.create({
  382. serviceName: 'HDFS',
  383. displayName: 'HDFS',
  384. isInstalled: true,
  385. isSelected: true,
  386. requiredServices:["ZOOKEEPER"]
  387. }),
  388. Em.Object.create({
  389. serviceName: 'HIVE',
  390. displayName: 'Hive',
  391. isInstalled: true,
  392. isSelected: true
  393. }),
  394. Em.Object.create({
  395. serviceName: 'HBASE',
  396. displayName: 'HBase',
  397. isInstalled: true,
  398. isSelected: true,
  399. requiredServices:["HDFS", "ZOOKEEPER"]
  400. }),
  401. Em.Object.create({
  402. serviceName: 'YARN',
  403. displayName: 'YARN',
  404. isInstalled: true,
  405. isSelected: true,
  406. requiredServices:["HDFS"]
  407. }),
  408. Em.Object.create({
  409. serviceName: 'SPARK',
  410. displayName: 'Spark',
  411. isInstalled: true,
  412. isSelected: true,
  413. requiredServices:["HIVE"]
  414. })
  415. ]);
  416. });
  417. it ("should confirm stop if serviceHealth is INSTALLED", function() {
  418. mainServiceItemController.startStopPopup(event, "INSTALLED");
  419. expect(Em.I18n.t.calledWith('services.service.stop.confirmMsg')).to.be.ok;
  420. expect(Em.I18n.t.calledWith('services.service.stop.confirmButton')).to.be.ok;
  421. });
  422. it ("should confirm start if serviceHealth is not INSTALLED", function() {
  423. mainServiceItemController.startStopPopup(event, "");
  424. expect(Em.I18n.t.calledWith('services.service.start.confirmMsg')).to.be.ok;
  425. expect(Em.I18n.t.calledWith('services.service.start.confirmButton')).to.be.ok;
  426. });
  427. it ("should not display a dependent list if it is to start a service", function() {
  428. var _mainServiceItemController = App.MainServiceItemController.create(
  429. {content: {serviceName: "HDFS", passiveState:'OFF'}});
  430. _mainServiceItemController.startStopPopup(event, "");
  431. expect(Em.I18n.t.calledWith('services.service.stop.warningMsg.dependent.services')).to.not.be.ok;
  432. });
  433. describe ("should display dependent list if other services depend on the one to be stopped", function() {
  434. beforeEach(function () {
  435. var _mainServiceItemController = App.MainServiceItemController.create(
  436. {content: {
  437. serviceName: "HDFS",
  438. passiveState:'OFF',
  439. hostComponents: [{
  440. componentName: 'NAMENODE',
  441. workStatus: 'INSTALLED'
  442. }]
  443. }}
  444. );
  445. _mainServiceItemController.startStopPopup(event, "INSTALLED");
  446. this.dependencies = Em.I18n.t('services.service.stop.warningMsg.dependent.services').format("HDFS", "HBase,YARN");
  447. this.msg = Em.I18n.t('services.service.stop.warningMsg.turnOnMM').format("HDFS");
  448. this.fullMsg = _mainServiceItemController.addAdditionalWarningMessage("INSTALLED", this.msg, "HDFS");
  449. });
  450. it('turnOnMM message is shown', function () {
  451. expect(Em.I18n.t.calledWith('services.service.stop.warningMsg.turnOnMM')).to.be.ok;
  452. });
  453. it('message about dependent services is shown', function () {
  454. expect(Em.I18n.t.calledWith('services.service.stop.warningMsg.dependent.services')).to.be.ok;
  455. });
  456. it('full message is valid', function () {
  457. expect(this.fullMsg).to.be.equal(this.msg + " " + this.dependencies);
  458. });
  459. });
  460. describe("should display the dependent service if another service depends on the one to be stopped", function() {
  461. beforeEach(function () {
  462. var _mainServiceItemController = App.MainServiceItemController.create(
  463. {content: {serviceName: "HIVE", passiveState:'OFF'}});
  464. _mainServiceItemController.startStopPopup(event, "INSTALLED");
  465. this.dependencies = Em.I18n.t('services.service.stop.warningMsg.dependent.services').format("HIVE", "Spark");
  466. this.msg = Em.I18n.t('services.service.stop.warningMsg.turnOnMM').format("HIVE");
  467. this.fullMsg = _mainServiceItemController.addAdditionalWarningMessage("INSTALLED", this.msg, "HIVE");
  468. });
  469. it('message about dependent services is shown', function () {
  470. expect(Em.I18n.t.calledWith('services.service.stop.warningMsg.dependent.services')).to.be.ok;
  471. });
  472. it('full message is valid', function () {
  473. expect(this.fullMsg).to.be.equal(this.msg + " " + this.dependencies);
  474. });
  475. });
  476. afterEach(function () {
  477. App.StackService.find.restore();
  478. });
  479. });
  480. });
  481. describe("#restartAllHostComponents", function () {
  482. var temp = batchUtils.restartAllServiceHostComponents;
  483. var mainServiceItemController = App.MainServiceItemController.create({
  484. content: {
  485. serviceName: "HDFS",
  486. hostComponents: [{
  487. componentName: 'NAMENODE',
  488. workStatus: 'STARTED'
  489. }]
  490. }
  491. });
  492. beforeEach(function () {
  493. batchUtils.restartAllServiceHostComponents = Em.K;
  494. sinon.spy(batchUtils, "restartAllServiceHostComponents");
  495. sinon.stub(App.Service, 'find', function() {
  496. return Em.Object.create({serviceTypes: []});
  497. });
  498. sinon.stub(mainServiceItemController, 'checkNnLastCheckpointTime', function() {
  499. return true;
  500. });
  501. });
  502. afterEach(function () {
  503. batchUtils.restartAllServiceHostComponents.restore();
  504. batchUtils.restartAllServiceHostComponents = temp;
  505. App.Service.find.restore();
  506. mainServiceItemController.checkNnLastCheckpointTime.restore();
  507. });
  508. it("start restartAllHostComponents for service", function () {
  509. var controller = App.MainServiceItemController.create({
  510. content: {
  511. serviceName: "HDFS",
  512. hostComponents: [{
  513. componentName: 'NAMENODE',
  514. workStatus: 'INSTALLED'
  515. }]
  516. }
  517. });
  518. controller.restartAllHostComponents({}).onPrimary();
  519. expect(batchUtils.restartAllServiceHostComponents.calledOnce).to.equal(true);
  520. });
  521. it("check last checkpoint time for NameNode before start restartAllHostComponents for service", function () {
  522. mainServiceItemController.restartAllHostComponents({});
  523. expect(mainServiceItemController.checkNnLastCheckpointTime.calledOnce).to.equal(true);
  524. });
  525. });
  526. describe("#rollingRestart", function () {
  527. var temp = batchUtils.launchHostComponentRollingRestart;
  528. beforeEach(function () {
  529. batchUtils.launchHostComponentRollingRestart = Em.K;
  530. sinon.spy(batchUtils, "launchHostComponentRollingRestart");
  531. });
  532. afterEach(function () {
  533. batchUtils.launchHostComponentRollingRestart.restore();
  534. batchUtils.launchHostComponentRollingRestart = temp;
  535. });
  536. var mainServiceItemController = App.MainServiceItemController.create();
  537. it("start restartAllHostComponents for service", function () {
  538. mainServiceItemController.rollingRestart();
  539. expect(batchUtils.launchHostComponentRollingRestart.calledOnce).to.equal(true);
  540. });
  541. });
  542. describe("#parseNnCheckPointTime", function () {
  543. var tests = [
  544. {
  545. m: "NameNode has JMX data, the last checkpoint time is less than 12 hours ago",
  546. data:
  547. {"href" : "",
  548. "ServiceComponentInfo" : {
  549. "cluster_name" : "c123",
  550. "component_name" : "NAMENODE",
  551. "service_name" : "HDFS"
  552. },
  553. "host_components" : [
  554. {
  555. "href" : "",
  556. "HostRoles" : {
  557. "cluster_name" : "c123",
  558. "component_name" : "NAMENODE",
  559. "host_name" : "c6401.ambari.apache.org"
  560. },
  561. "metrics" : {
  562. "dfs" : {
  563. "FSNamesystem" : {
  564. "HAState" : "active",
  565. "LastCheckpointTime" : 1435775648000
  566. }
  567. }
  568. }
  569. }
  570. ]
  571. },
  572. result: false
  573. },
  574. {
  575. m: "NameNode has JMX data, the last checkpoint time is > 12 hours ago",
  576. data:
  577. {"href" : "",
  578. "ServiceComponentInfo" : {
  579. "cluster_name" : "c123",
  580. "component_name" : "NAMENODE",
  581. "service_name" : "HDFS"
  582. },
  583. "host_components" : [
  584. {
  585. "href" : "",
  586. "HostRoles" : {
  587. "cluster_name" : "c123",
  588. "component_name" : "NAMENODE",
  589. "host_name" : "c6401.ambari.apache.org"
  590. },
  591. "metrics" : {
  592. "dfs" : {
  593. "FSNamesystem" : {
  594. "HAState" : "active",
  595. "LastCheckpointTime" : 1435617248000
  596. }
  597. }
  598. }
  599. }
  600. ]
  601. },
  602. result: "c6401.ambari.apache.org"
  603. },
  604. {
  605. m: "NameNode has no JMX data available",
  606. data:
  607. {"href" : "",
  608. "ServiceComponentInfo" : {
  609. "cluster_name" : "c123",
  610. "component_name" : "NAMENODE",
  611. "service_name" : "HDFS"
  612. },
  613. "host_components" : [
  614. {
  615. "href" : "",
  616. "HostRoles" : {
  617. "cluster_name" : "c123",
  618. "component_name" : "NAMENODE",
  619. "host_name" : "c6401.ambari.apache.org"
  620. },
  621. "metrics" : {
  622. "dfs" : {
  623. "FSNamesystem" : {
  624. "HAState" : "active"
  625. }
  626. }
  627. }
  628. }
  629. ]
  630. },
  631. result: null
  632. },
  633. {
  634. m: "HA enabled, both active and standby NN has JMX data normally.",
  635. data:
  636. {"href" : "",
  637. "ServiceComponentInfo" : {
  638. "cluster_name" : "c123",
  639. "component_name" : "NAMENODE",
  640. "service_name" : "HDFS"
  641. },
  642. "host_components" : [
  643. {
  644. "href" : "",
  645. "HostRoles" : {
  646. "cluster_name" : "c123",
  647. "component_name" : "NAMENODE",
  648. "host_name" : "c6401.ambari.apache.org"
  649. },
  650. "metrics" : {
  651. "dfs" : {
  652. "FSNamesystem" : {
  653. "HAState" : "active",
  654. "LastCheckpointTime" : 1435775648000
  655. }
  656. }
  657. }
  658. },
  659. {
  660. "href" : "",
  661. "HostRoles" : {
  662. "cluster_name" : "c123",
  663. "component_name" : "NAMENODE",
  664. "host_name" : "c6402.ambari.apache.org"
  665. },
  666. "metrics" : {
  667. "dfs" : {
  668. "FSNamesystem" : {
  669. "HAState" : "standby",
  670. "LastCheckpointTime" : 1435775648000
  671. }
  672. }
  673. }
  674. }
  675. ]
  676. },
  677. result: false
  678. },
  679. {
  680. m: "HA enabled, both NamoNodes are standby NN",
  681. data:
  682. {"href" : "",
  683. "ServiceComponentInfo" : {
  684. "cluster_name" : "c123",
  685. "component_name" : "NAMENODE",
  686. "service_name" : "HDFS"
  687. },
  688. "host_components" : [
  689. {
  690. "href" : "",
  691. "HostRoles" : {
  692. "cluster_name" : "c123",
  693. "component_name" : "NAMENODE",
  694. "host_name" : "c6401.ambari.apache.org"
  695. },
  696. "metrics" : {
  697. "dfs" : {
  698. "FSNamesystem" : {
  699. "HAState" : "standby",
  700. "LastCheckpointTime" : 1435775648000
  701. }
  702. }
  703. }
  704. },
  705. {
  706. "href" : "",
  707. "HostRoles" : {
  708. "cluster_name" : "c123",
  709. "component_name" : "NAMENODE",
  710. "host_name" : "c6402.ambari.apache.org"
  711. },
  712. "metrics" : {
  713. "dfs" : {
  714. "FSNamesystem" : {
  715. "HAState" : "standby",
  716. "LastCheckpointTime" : 1435775648000
  717. }
  718. }
  719. }
  720. }
  721. ]
  722. },
  723. result: false
  724. },
  725. {
  726. m: "HA enabled, active NN has no JMX data, use the standby's data",
  727. data:
  728. {"href" : "",
  729. "ServiceComponentInfo" : {
  730. "cluster_name" : "c123",
  731. "component_name" : "NAMENODE",
  732. "service_name" : "HDFS"
  733. },
  734. "host_components" : [
  735. {
  736. "href" : "",
  737. "HostRoles" : {
  738. "cluster_name" : "c123",
  739. "component_name" : "NAMENODE",
  740. "host_name" : "c6401.ambari.apache.org"
  741. },
  742. "metrics" : {
  743. "dfs" : {
  744. "FSNamesystem" : {
  745. "HAState" : "active"
  746. }
  747. }
  748. }
  749. },
  750. {
  751. "href" : "",
  752. "HostRoles" : {
  753. "cluster_name" : "c123",
  754. "component_name" : "NAMENODE",
  755. "host_name" : "c6402.ambari.apache.org"
  756. },
  757. "metrics" : {
  758. "dfs" : {
  759. "FSNamesystem" : {
  760. "HAState" : "standby",
  761. "LastCheckpointTime" : 1435775648000
  762. }
  763. }
  764. }
  765. }
  766. ]
  767. },
  768. result: false
  769. },
  770. {
  771. m: "HA enabled, both NamoNodes no JMX data",
  772. data:
  773. {"href" : "",
  774. "ServiceComponentInfo" : {
  775. "cluster_name" : "c123",
  776. "component_name" : "NAMENODE",
  777. "service_name" : "HDFS"
  778. },
  779. "host_components" : [
  780. {
  781. "href" : "",
  782. "HostRoles" : {
  783. "cluster_name" : "c123",
  784. "component_name" : "NAMENODE",
  785. "host_name" : "c6401.ambari.apache.org"
  786. },
  787. "metrics" : {
  788. "dfs" : {
  789. "FSNamesystem" : {
  790. "HAState" : "active"
  791. }
  792. }
  793. }
  794. },
  795. {
  796. "href" : "",
  797. "HostRoles" : {
  798. "cluster_name" : "c123",
  799. "component_name" : "NAMENODE",
  800. "host_name" : "c6402.ambari.apache.org"
  801. },
  802. "metrics" : {
  803. "dfs" : {
  804. "FSNamesystem" : {
  805. "HAState" : "standby"
  806. }
  807. }
  808. }
  809. }
  810. ]
  811. },
  812. result: null
  813. }
  814. ];
  815. beforeEach(function () {
  816. sinon.stub(App, 'dateTime').returns(1435790048000);
  817. });
  818. afterEach(function () {
  819. App.dateTime.restore();
  820. });
  821. tests.forEach(function (test) {
  822. it(test.m, function () {
  823. var mainServiceItemController = App.MainServiceItemController.create({isNNCheckpointTooOld: null});
  824. mainServiceItemController.parseNnCheckPointTime(test.data);
  825. expect(mainServiceItemController.get('isNNCheckpointTooOld')).to.equal(test.result);
  826. });
  827. });
  828. });
  829. describe("#isStartDisabled", function () {
  830. var tests = [
  831. {
  832. content: {
  833. healthStatus: 'red'
  834. },
  835. isPending: true,
  836. disabled: true,
  837. m: "disabled because of pending"
  838. },
  839. {
  840. content: {
  841. healthStatus: 'green'
  842. },
  843. isPending: false,
  844. disabled: true,
  845. m: "disabled because healthStatus is not red"
  846. },
  847. {
  848. content: {
  849. healthStatus: 'red'
  850. },
  851. isPending: false,
  852. disabled: false,
  853. m: "enabled because healthStatus is red and pending is false"
  854. }
  855. ];
  856. tests.forEach(function (test) {
  857. it(test.m, function () {
  858. var mainServiceItemController = App.MainServiceItemController.create({content: {healthStatus: test.content.healthStatus}, isPending: test.isPending});
  859. expect(mainServiceItemController.get('isStartDisabled')).to.equal(test.disabled);
  860. });
  861. });
  862. });
  863. describe("#isStopDisabled", function () {
  864. var tests = [
  865. {
  866. content: {
  867. healthStatus: 'red'
  868. },
  869. isPending: true,
  870. disabled: true,
  871. m: "disabled because of pending"
  872. },
  873. {
  874. content: {
  875. healthStatus: 'green'
  876. },
  877. isPending: false,
  878. disabled: false,
  879. m: "enabled because healthStatus is green and pending is false"
  880. },
  881. {
  882. content: {
  883. healthStatus: 'red'
  884. },
  885. isPending: false,
  886. disabled: true,
  887. m: "disabled because healthStatus is not green"
  888. }
  889. ];
  890. tests.forEach(function (test) {
  891. it(test.m, function () {
  892. var mainServiceItemController = App.MainServiceItemController.create({content: test.content, isPending: test.isPending});
  893. expect(mainServiceItemController.get('isStopDisabled')).to.equal(test.disabled);
  894. });
  895. });
  896. });
  897. describe("#runRebalancer", function () {
  898. beforeEach(function () {
  899. sinon.stub(App.router, 'get', function(k) {
  900. if ('applicationController' === k) {
  901. return Em.Object.create({
  902. dataLoading: function() {
  903. return {done: Em.K}
  904. }
  905. });
  906. }
  907. return Em.get(App.router, k);
  908. });
  909. });
  910. afterEach(function () {
  911. App.router.get.restore();
  912. });
  913. it("run rebalancer", function () {
  914. var mainServiceItemController = App.MainServiceItemController.create({content: {runRebalancer: false}});
  915. mainServiceItemController.runRebalancer().onPrimary();
  916. expect(mainServiceItemController.get("content.runRebalancer")).to.equal(true);
  917. });
  918. });
  919. describe("#runCompaction", function () {
  920. beforeEach(function () {
  921. sinon.stub(App.router, 'get', function(k) {
  922. if ('applicationController' === k) {
  923. return Em.Object.create({
  924. dataLoading: function() {
  925. return {done: Em.K}
  926. }
  927. });
  928. }
  929. return Em.get(App.router, k);
  930. });
  931. });
  932. afterEach(function () {
  933. App.router.get.restore();
  934. });
  935. it("run compaction", function () {
  936. var mainServiceItemController = App.MainServiceItemController.create({content: {runCompaction: false}});
  937. mainServiceItemController.runCompaction().onPrimary();
  938. expect(mainServiceItemController.get("content.runCompaction")).to.equal(true);
  939. });
  940. });
  941. describe("#runSmokeTestPrimary", function () {
  942. beforeEach(function () {
  943. sinon.stub(App, 'get').withArgs('clusterName').returns('myCluster');
  944. });
  945. afterEach(function () {
  946. App.get.restore();
  947. });
  948. var tests = [
  949. {
  950. data: {
  951. 'serviceName': "HDFS",
  952. 'displayName': "HDFS",
  953. 'query': "test"
  954. },
  955. "RequestInfo": {
  956. "context": "HDFS Service Check",
  957. "command" : "HDFS_SERVICE_CHECK"
  958. },
  959. "Requests/resource_filters": [{"service_name" : "HDFS"}]
  960. },
  961. {
  962. data: {
  963. 'serviceName': "KERBEROS",
  964. 'displayName': "Kerberos",
  965. 'query': "test"
  966. },
  967. "RequestInfo": {
  968. "context": "Kerberos Service Check",
  969. "command" : "KERBEROS_SERVICE_CHECK",
  970. "operation_level": {
  971. "level": "CLUSTER",
  972. "cluster_name": "myCluster"
  973. }
  974. },
  975. "Requests/resource_filters": [{"service_name" : "KERBEROS"}]
  976. }
  977. ];
  978. tests.forEach(function (test) {
  979. var mainServiceItemController = App.MainServiceItemController.create({content: {serviceName: test.data.serviceName,
  980. displayName: test.data.displayName}});
  981. describe('send request to run smoke test for ' + test.data.serviceName, function () {
  982. beforeEach(function () {
  983. mainServiceItemController.set("runSmokeTestErrorCallBack", Em.K);
  984. mainServiceItemController.set("runSmokeTestSuccessCallBack", Em.K);
  985. mainServiceItemController.runSmokeTestPrimary(test.data.query);
  986. this.args = testHelpers.findAjaxRequest('name', 'service.item.smoke')[0];
  987. this.data = this.args.data;
  988. this.data = JSON.parse(App.ajax.fakeGetUrl('service.item.smoke').format(this.data).data);
  989. });
  990. it('ajax request is sent', function () {
  991. expect(this.args).exists;
  992. });
  993. it('RequestInfo.context is valid', function () {
  994. expect(this.data.RequestInfo.context).to.equal(test.RequestInfo.context);
  995. });
  996. it('RequestInfo.command is valid', function () {
  997. expect(this.data.RequestInfo.command).to.equal(test.RequestInfo.command);
  998. });
  999. it('Requests/resource_filter.0.serviceName is valid', function () {
  1000. expect(this.data["Requests/resource_filters"][0].serviceName).to.equal(test["Requests/resource_filters"][0].serviceName);
  1001. });
  1002. it('RequestInfo.operation_level is valid', function () {
  1003. expect(this.data.RequestInfo.operation_level).to.be.deep.equal(test.RequestInfo.operation_level);
  1004. });
  1005. });
  1006. });
  1007. });
  1008. describe('#downloadClientConfigs()', function () {
  1009. var mainServiceItemController = App.MainServiceItemController.create({
  1010. content: {
  1011. clientComponents: [
  1012. Em.Object.create({
  1013. totalCount: 1,
  1014. componentName: 'C1',
  1015. displayName: 'd1'
  1016. })
  1017. ],
  1018. serviceName: 'S1'
  1019. }
  1020. });
  1021. beforeEach(function () {
  1022. sinon.stub(mainServiceItemController, 'downloadClientConfigsCall', Em.K);
  1023. });
  1024. afterEach(function () {
  1025. mainServiceItemController.downloadClientConfigsCall.restore();
  1026. });
  1027. it('should launch $.fileDownload method', function () {
  1028. mainServiceItemController.downloadClientConfigs();
  1029. expect(mainServiceItemController.downloadClientConfigsCall.calledWith({
  1030. serviceName: 'S1',
  1031. componentName: 'C1',
  1032. displayName: 'd1'
  1033. })).to.be.true;
  1034. });
  1035. it('should launch $.fileDownload method, event passed', function () {
  1036. var event = {
  1037. label: 'label1',
  1038. name: 'name1'
  1039. };
  1040. mainServiceItemController.downloadClientConfigs(event);
  1041. expect(mainServiceItemController.downloadClientConfigsCall.calledWith({
  1042. serviceName: 'S1',
  1043. componentName: 'name1',
  1044. displayName: 'label1'
  1045. })).to.be.true;
  1046. });
  1047. });
  1048. describe('#startLdapKnox() and #stopLdapKnox() should call startStopLdapKnox once: ', function () {
  1049. var mainServiceItemController = App.MainServiceItemController.create({content: {serviceName: 'KNOX',
  1050. displayName: 'Knox'}});
  1051. beforeEach(function () {
  1052. sinon.stub(mainServiceItemController, 'startStopLdapKnox', function(){
  1053. return true;
  1054. });
  1055. });
  1056. afterEach(function () {
  1057. mainServiceItemController.startStopLdapKnox.restore();
  1058. });
  1059. var tests = [
  1060. {
  1061. methodName: 'startLdapKnox',
  1062. callback: mainServiceItemController.startLdapKnox
  1063. },
  1064. {
  1065. methodName: 'stopLdapKnox',
  1066. callback: mainServiceItemController.stopLdapKnox
  1067. }
  1068. ];
  1069. tests.forEach(function(test){
  1070. it(test.methodName + ' should call startStopLdapKnox method', function () {
  1071. test.callback.call(mainServiceItemController);
  1072. expect(mainServiceItemController.startStopLdapKnox.calledOnce).to.be.true;
  1073. });
  1074. },this);
  1075. });
  1076. describe("#executeCustomCommand", function () {
  1077. var data = {
  1078. data: {
  1079. 'serviceName': "SAMPLESRV",
  1080. 'displayName': "SAMPLESRV",
  1081. 'query': "test"
  1082. },
  1083. "RequestInfo": {
  1084. "context": "Execute Custom Commands",
  1085. "command" : "SAMPLESRVCUSTOMCOMMANDS"
  1086. },
  1087. "Requests/resource_filters": [{"service_name" : "SAMPLESRV"}]
  1088. };
  1089. var context = {
  1090. label: 'Execute Custom Commands',
  1091. service: data.data.serviceName,
  1092. component: data.data.serviceName,
  1093. command: data.RequestInfo.command
  1094. };
  1095. var mainServiceItemController = App.MainServiceItemController.create({
  1096. content: {
  1097. serviceName: data.data.serviceName,
  1098. displayName: data.data.displayName
  1099. }
  1100. });
  1101. before(function () {
  1102. mainServiceItemController.set("executeCustomCommandErrorCallback", Em.K);
  1103. mainServiceItemController.set("executeCustomCommandSuccessCallback", Em.K);
  1104. sinon.spy(App, 'showConfirmationPopup');
  1105. });
  1106. after(function () {
  1107. App.showConfirmationPopup.restore();
  1108. });
  1109. it('shows a confirmation popup', function () {
  1110. mainServiceItemController.executeCustomCommand(context);
  1111. expect(App.showConfirmationPopup.calledOnce).to.equal(true);
  1112. });
  1113. });
  1114. describe("#findDependentServices()", function() {
  1115. var mainServiceItemController;
  1116. beforeEach(function() {
  1117. mainServiceItemController = App.MainServiceItemController.create({});
  1118. sinon.stub(App.StackService, 'find', function (serviceName) {
  1119. return stackSerivceModel[serviceName];
  1120. });
  1121. this.mockService = sinon.stub(App.Service, 'find');
  1122. });
  1123. afterEach(function() {
  1124. App.StackService.find.restore();
  1125. this.mockService.restore();
  1126. });
  1127. it("no services", function() {
  1128. this.mockService.returns([]);
  1129. expect(mainServiceItemController.findDependentServices(['S1'])).to.be.empty;
  1130. });
  1131. it("service has dependencies", function() {
  1132. this.mockService.returns([
  1133. Em.Object.create({ serviceName: 'HDFS' }),
  1134. Em.Object.create({ serviceName: 'YARN' }),
  1135. Em.Object.create({ serviceName: 'MAPREDUCE2' }),
  1136. Em.Object.create({ serviceName: 'TEZ' }),
  1137. Em.Object.create({ serviceName: 'HIVE' })
  1138. ]);
  1139. expect(mainServiceItemController.findDependentServices(['YARN', 'MAPREDUCE2'])).to.eql(['TEZ', 'HIVE']);
  1140. });
  1141. it("service has no dependencies", function() {
  1142. this.mockService.returns([
  1143. Em.Object.create({ serviceName: 'HDFS' }),
  1144. Em.Object.create({ serviceName: 'YARN' }),
  1145. Em.Object.create({ serviceName: 'MAPREDUCE2' }),
  1146. Em.Object.create({ serviceName: 'TEZ' }),
  1147. Em.Object.create({ serviceName: 'HIVE' })
  1148. ]);
  1149. expect(mainServiceItemController.findDependentServices(['HIVE'])).to.be.empty;
  1150. });
  1151. it("service has no dependencies (except interdependent)", function() {
  1152. this.mockService.returns([
  1153. Em.Object.create({ serviceName: 'HDFS' }),
  1154. Em.Object.create({ serviceName: 'YARN' }),
  1155. Em.Object.create({ serviceName: 'MAPREDUCE2' })
  1156. ]);
  1157. expect(mainServiceItemController.findDependentServices(['YARN', 'MAPREDUCE2'])).to.be.empty;
  1158. });
  1159. });
  1160. describe("#deleteService()", function() {
  1161. var mainServiceItemController;
  1162. beforeEach(function() {
  1163. mainServiceItemController = App.MainServiceItemController.create({});
  1164. this.mockDependentServices = sinon.stub(mainServiceItemController, 'findDependentServices');
  1165. sinon.stub(mainServiceItemController, 'dependentServicesWarning');
  1166. sinon.stub(mainServiceItemController, 'servicesDisplayNames', function(servicesDisplayNames) {
  1167. return servicesDisplayNames;
  1168. });
  1169. this.allowUninstallServices = sinon.stub(mainServiceItemController, 'allowUninstallServices');
  1170. this.mockService = sinon.stub(App.Service, 'find');
  1171. sinon.stub(App, 'showConfirmationPopup');
  1172. sinon.stub(App.ModalPopup, 'show');
  1173. sinon.stub(App.format, 'role', function(name) {return name});
  1174. mainServiceItemController.reopen({
  1175. interDependentServices: []
  1176. })
  1177. });
  1178. afterEach(function() {
  1179. mainServiceItemController.allowUninstallServices.restore();
  1180. mainServiceItemController.servicesDisplayNames.restore();
  1181. this.mockDependentServices.restore();
  1182. this.mockService.restore();
  1183. mainServiceItemController.dependentServicesWarning.restore();
  1184. App.showConfirmationPopup.restore();
  1185. App.ModalPopup.show.restore();
  1186. App.format.role.restore();
  1187. });
  1188. it("only one service installed", function() {
  1189. this.mockDependentServices.returns(['S2']);
  1190. this.mockService.returns(Em.Object.create({length: 1}));
  1191. mainServiceItemController.deleteService('S1');
  1192. expect(App.ModalPopup.show.calledWith({
  1193. secondary: null,
  1194. header: Em.I18n.t('services.service.delete.popup.header'),
  1195. encodeBody: false,
  1196. body: Em.I18n.t('services.service.delete.lastService.popup.body').format('S1')
  1197. })).to.be.true;
  1198. });
  1199. it("service has installed dependent services", function() {
  1200. this.mockDependentServices.returns(['S2']);
  1201. this.mockService.returns([Em.Object.create({workStatus: App.Service.statesMap.stopped}), Em.Object.create({workStatus: App.Service.statesMap.stopped})]);
  1202. mainServiceItemController.deleteService('S1');
  1203. expect(mainServiceItemController.dependentServicesWarning.calledWith('S1', ['S2'])).to.be.true;
  1204. });
  1205. it("service has not dependent services, and stopped", function() {
  1206. this.mockDependentServices.returns([]);
  1207. this.allowUninstallServices.returns(true);
  1208. this.mockService.returns([Em.Object.create({workStatus: App.Service.statesMap.stopped}), Em.Object.create({workStatus: App.Service.statesMap.stopped})]);
  1209. mainServiceItemController.deleteService('S1');
  1210. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1211. });
  1212. it("service has not dependent services, and install failed", function() {
  1213. this.mockDependentServices.returns([]);
  1214. this.allowUninstallServices.returns(true);
  1215. this.mockService.returns([Em.Object.create({workStatus: App.Service.statesMap.install_failed}), Em.Object.create({workStatus: App.Service.statesMap.install_failed})]);
  1216. mainServiceItemController.deleteService('S1');
  1217. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1218. });
  1219. it("service has not dependent services, and not stopped", function() {
  1220. this.mockDependentServices.returns([]);
  1221. this.mockService.returns(Em.Object.create({workStatus: App.Service.statesMap.started}));
  1222. mainServiceItemController.deleteService('S1');
  1223. expect(App.ModalPopup.show.calledWith({
  1224. secondary: null,
  1225. header: Em.I18n.t('services.service.delete.popup.header'),
  1226. encodeBody: false,
  1227. body: Em.I18n.t('services.service.delete.popup.mustBeStopped').format('S1')
  1228. })).to.be.true;
  1229. });
  1230. });
  1231. describe("#dependentServicesWarning()", function() {
  1232. var mainServiceItemController;
  1233. beforeEach(function() {
  1234. mainServiceItemController = App.MainServiceItemController.create({});
  1235. sinon.stub(App.ModalPopup, 'show');
  1236. sinon.stub(App.format, 'role', function(name) {return name});
  1237. });
  1238. afterEach(function() {
  1239. App.ModalPopup.show.restore();
  1240. App.format.role.restore();
  1241. });
  1242. it("App.ModalPopup.show should be called", function() {
  1243. mainServiceItemController.dependentServicesWarning('S1', ['S2']);
  1244. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1245. });
  1246. });
  1247. describe("#confirmDeleteService()", function() {
  1248. var mainServiceItemController;
  1249. beforeEach(function() {
  1250. mainServiceItemController = App.MainServiceItemController.create({});
  1251. sinon.stub(App.ModalPopup, 'show');
  1252. });
  1253. afterEach(function() {
  1254. App.ModalPopup.show.restore();
  1255. });
  1256. it("App.ModalPopup.show should be called", function() {
  1257. mainServiceItemController.confirmDeleteService();
  1258. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1259. });
  1260. });
  1261. describe('#interDependentServices', function() {
  1262. var mainServiceItemController;
  1263. beforeEach(function() {
  1264. sinon.stub(App.StackService, 'find', function (serviceName) {
  1265. return stackSerivceModel[serviceName];
  1266. });
  1267. mainServiceItemController = App.MainServiceItemController.create({
  1268. content: {}
  1269. });
  1270. });
  1271. afterEach(function() {
  1272. App.StackService.find.restore();
  1273. });
  1274. it('get interdependent services for YARN', function() {
  1275. mainServiceItemController.set('content', Em.Object.create({
  1276. serviceName: 'YARN'
  1277. }));
  1278. expect(mainServiceItemController.get('interDependentServices')).to.eql(['MAPREDUCE2']);
  1279. });
  1280. it('get interdependent services for MAPREDUCE2', function() {
  1281. mainServiceItemController.set('content', Em.Object.create({
  1282. serviceName: 'MAPREDUCE2'
  1283. }));
  1284. expect(mainServiceItemController.get('interDependentServices')).to.eql(['YARN']);
  1285. });
  1286. });
  1287. describe("#deleteServiceCall()", function() {
  1288. var mainServiceItemController;
  1289. beforeEach(function() {
  1290. mainServiceItemController = App.MainServiceItemController.create({});
  1291. });
  1292. it("App.ajax.send should be called", function() {
  1293. mainServiceItemController.deleteServiceCall(['S1', 'S2']);
  1294. var args = testHelpers.findAjaxRequest('name', 'common.delete.service');
  1295. expect(args[0]).exists;
  1296. expect(args[0].sender).to.be.eql(mainServiceItemController);
  1297. expect(args[0].data).to.be.eql({
  1298. serviceName : 'S1',
  1299. servicesToDeleteNext: ['S2']
  1300. });
  1301. });
  1302. });
  1303. describe("#deleteServiceCallSuccessCallback()", function() {
  1304. var mainServiceItemController;
  1305. beforeEach(function() {
  1306. mainServiceItemController = App.MainServiceItemController.create({});
  1307. sinon.spy(mainServiceItemController, 'loadConfigRecommendations');
  1308. sinon.spy(mainServiceItemController, 'deleteServiceCall');
  1309. mainServiceItemController.reopen({
  1310. interDependentServices: []
  1311. })
  1312. });
  1313. afterEach(function() {
  1314. mainServiceItemController.loadConfigRecommendations.restore();
  1315. mainServiceItemController.deleteServiceCall.restore();
  1316. });
  1317. it("window.location.reload should be called", function() {
  1318. mainServiceItemController.deleteServiceCallSuccessCallback([], null, {});
  1319. expect(mainServiceItemController.deleteServiceCall.called).to.be.false;
  1320. expect(mainServiceItemController.loadConfigRecommendations.calledOnce).to.be.true;
  1321. });
  1322. it("deleteServiceCall should be called", function() {
  1323. mainServiceItemController.deleteServiceCallSuccessCallback([], null, {servicesToDeleteNext: true});
  1324. expect(mainServiceItemController.deleteServiceCall.calledOnce).to.be.true;
  1325. expect(mainServiceItemController.loadConfigRecommendations.called).to.be.false;
  1326. });
  1327. });
  1328. });