quick_link_view_test.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  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('views/common/quick_view_link_view');
  20. var testHelpers = require('test/helpers');
  21. describe('App.QuickViewLinks', function () {
  22. var quickViewLinks = App.QuickViewLinks.create({
  23. content: Em.Object.create()
  24. });
  25. describe("#linkTarget", function () {
  26. it("blank link", function () {
  27. quickViewLinks.set('content.serviceName', 'HDFS');
  28. quickViewLinks.propertyDidChange('linkTarget');
  29. expect(quickViewLinks.get('linkTarget')).to.equal('_blank');
  30. });
  31. it("non-blank link", function () {
  32. quickViewLinks.set('content.serviceName', 'S1');
  33. quickViewLinks.propertyDidChange('linkTarget');
  34. expect(quickViewLinks.get('linkTarget')).to.be.empty;
  35. });
  36. });
  37. describe("#ambariProperties", function () {
  38. beforeEach(function () {
  39. sinon.stub(App.router, 'get').returns({p: 1});
  40. });
  41. afterEach(function () {
  42. App.router.get.restore();
  43. });
  44. it("ambariProperties are updated", function () {
  45. expect(quickViewLinks.get('ambariProperties')).to.eql({p: 1});
  46. });
  47. });
  48. describe("#didInsertElement()", function () {
  49. beforeEach(function () {
  50. sinon.stub(App.router, 'get').returns({p: 1});
  51. sinon.stub(quickViewLinks, 'loadQuickLinksConfigurations');
  52. });
  53. afterEach(function () {
  54. App.router.get.restore();
  55. quickViewLinks.loadQuickLinksConfigurations.restore();
  56. });
  57. it("loadQuickLinksConfigurations is called once", function () {
  58. quickViewLinks.didInsertElement();
  59. expect(quickViewLinks.loadQuickLinksConfigurations.calledOnce).to.be.true;
  60. });
  61. });
  62. describe("#willDestroyElement()", function () {
  63. beforeEach(function () {
  64. quickViewLinks.setProperties({
  65. configProperties: [{}],
  66. actualTags: [""],
  67. quickLinks: [{}]
  68. });
  69. quickViewLinks.willDestroyElement();
  70. });
  71. it("configProperties empty", function () {
  72. expect(quickViewLinks.get('configProperties')).to.be.empty;
  73. });
  74. it("actualTags empty", function () {
  75. expect(quickViewLinks.get('actualTags')).to.be.empty;
  76. });
  77. it("quickLinks empty", function () {
  78. expect(quickViewLinks.get('quickLinks')).to.be.empty;
  79. });
  80. });
  81. describe("#setQuickLinks()", function () {
  82. beforeEach(function () {
  83. this.mock = sinon.stub(App, 'get');
  84. sinon.stub(quickViewLinks, 'loadTags', Em.K);
  85. });
  86. afterEach(function () {
  87. this.mock.restore();
  88. quickViewLinks.loadTags.restore();
  89. });
  90. it("data loaded", function () {
  91. this.mock.returns(true);
  92. quickViewLinks.setQuickLinks();
  93. expect(quickViewLinks.loadTags.calledOnce).to.be.true;
  94. });
  95. it("data not loaded", function () {
  96. this.mock.returns(false);
  97. quickViewLinks.setQuickLinks();
  98. expect(quickViewLinks.loadTags.called).to.be.false;
  99. });
  100. });
  101. describe("#loadTags()", function () {
  102. it("call $.ajax", function () {
  103. quickViewLinks.loadTags();
  104. var args = testHelpers.findAjaxRequest('name', 'config.tags');
  105. expect(args[0]).exists;
  106. expect(args[0].sender).to.be.eql(quickViewLinks);
  107. });
  108. });
  109. describe("#loadTagsSuccess()", function () {
  110. beforeEach(function () {
  111. sinon.stub(quickViewLinks, 'setConfigProperties', function () {
  112. return {
  113. done: Em.clb
  114. }
  115. });
  116. sinon.stub(quickViewLinks, 'getQuickLinksHosts');
  117. var data = {
  118. Clusters: {
  119. desired_configs: {
  120. site1: {
  121. tag: 'tag1'
  122. }
  123. }
  124. }
  125. };
  126. quickViewLinks.loadTagsSuccess(data);
  127. });
  128. afterEach(function () {
  129. quickViewLinks.setConfigProperties.restore();
  130. quickViewLinks.getQuickLinksHosts.restore();
  131. });
  132. it("actualTags is valid", function () {
  133. expect(quickViewLinks.get('actualTags')[0]).to.eql(Em.Object.create({
  134. siteName: 'site1',
  135. tagName: 'tag1'
  136. }));
  137. });
  138. it("setConfigProperties is called once", function () {
  139. expect(quickViewLinks.setConfigProperties.calledOnce).to.be.true;
  140. });
  141. it("getQuickLinksHosts is called once", function () {
  142. expect(quickViewLinks.getQuickLinksHosts.calledOnce).to.be.true;
  143. });
  144. });
  145. describe("#loadTagsError()", function () {
  146. beforeEach(function () {
  147. sinon.stub(quickViewLinks, 'getQuickLinksHosts');
  148. });
  149. afterEach(function () {
  150. quickViewLinks.getQuickLinksHosts.restore();
  151. });
  152. it("call loadQuickLinksConfigurations", function () {
  153. quickViewLinks.loadTagsError();
  154. expect(quickViewLinks.getQuickLinksHosts.calledOnce).to.be.true;
  155. });
  156. });
  157. describe("#loadQuickLinksConfigSuccessCallback()", function () {
  158. var mock;
  159. beforeEach(function () {
  160. sinon.stub(App.store, 'commit', Em.K);
  161. mock = sinon.stub(quickViewLinks, 'getQuickLinksConfiguration');
  162. });
  163. afterEach(function () {
  164. App.store.commit.restore();
  165. mock.restore();
  166. });
  167. it("requiredSites consistent", function () {
  168. var quickLinksConfigHBASE = {
  169. protocol: {
  170. type: "http"
  171. },
  172. links: [
  173. {
  174. port: {
  175. site: "hbase-site"
  176. }
  177. }
  178. ]
  179. };
  180. var quickLinksConfigYARN = {
  181. protocol: {
  182. checks: [
  183. {
  184. site: "yarn-site"
  185. }
  186. ],
  187. type: "https"
  188. },
  189. links: [
  190. {
  191. port: {
  192. site: "yarn-site"
  193. }
  194. }
  195. ]
  196. };
  197. quickViewLinks.set('content.serviceName', 'HBASE');
  198. mock.returns(quickLinksConfigHBASE);
  199. quickViewLinks.loadQuickLinksConfigSuccessCallback({items: []});
  200. quickViewLinks.set('content.serviceName', 'YARN');
  201. mock.returns(quickLinksConfigYARN);
  202. quickViewLinks.loadQuickLinksConfigSuccessCallback({items: []});
  203. expect(quickViewLinks.get('requiredSiteNames')).to.be.eql(["core-site", "hdfs-site", "hbase-site", "yarn-site"]);
  204. });
  205. });
  206. describe("#getQuickLinksHosts()", function () {
  207. beforeEach(function () {
  208. sinon.stub(App.HostComponent, 'find').returns([
  209. Em.Object.create({
  210. isMaster: true,
  211. hostName: 'host1'
  212. })
  213. ]);
  214. });
  215. afterEach(function () {
  216. App.HostComponent.find.restore();
  217. });
  218. it("call $.ajax", function () {
  219. quickViewLinks.getQuickLinksHosts();
  220. var args = testHelpers.findAjaxRequest('name', 'hosts.for_quick_links');
  221. expect(args[0]).exists;
  222. expect(args[0].sender).to.be.eql(quickViewLinks);
  223. expect(args[0].data).to.be.eql({
  224. clusterName: App.get('clusterName'),
  225. masterHosts: 'host1',
  226. urlParams: ''
  227. });
  228. });
  229. it("call $.ajax, HBASE service", function () {
  230. quickViewLinks.set('content.serviceName', 'HBASE');
  231. quickViewLinks.getQuickLinksHosts();
  232. var args = testHelpers.findAjaxRequest('name', 'hosts.for_quick_links');
  233. expect(args[0]).exists;
  234. expect(args[0].sender).to.be.eql(quickViewLinks);
  235. expect(args[0].data).to.be.eql({
  236. clusterName: App.get('clusterName'),
  237. masterHosts: 'host1',
  238. urlParams: ',host_components/metrics/hbase/master/IsActiveMaster'
  239. });
  240. });
  241. });
  242. describe("#setQuickLinksSuccessCallback()", function () {
  243. beforeEach(function () {
  244. this.mock = sinon.stub(quickViewLinks, 'getHosts');
  245. sinon.stub(quickViewLinks, 'setEmptyLinks');
  246. sinon.stub(quickViewLinks, 'setSingleHostLinks');
  247. sinon.stub(quickViewLinks, 'setMultipleHostLinks');
  248. quickViewLinks.set('content.quickLinks', []);
  249. });
  250. afterEach(function () {
  251. this.mock.restore();
  252. quickViewLinks.setEmptyLinks.restore();
  253. quickViewLinks.setSingleHostLinks.restore();
  254. quickViewLinks.setMultipleHostLinks.restore();
  255. });
  256. it("no hosts", function () {
  257. this.mock.returns([]);
  258. quickViewLinks.setQuickLinksSuccessCallback();
  259. expect(quickViewLinks.setEmptyLinks.calledOnce).to.be.true;
  260. });
  261. it("quickLinks is not configured", function () {
  262. this.mock.returns([{}]);
  263. quickViewLinks.setQuickLinksSuccessCallback();
  264. expect(quickViewLinks.setEmptyLinks.calledOnce).to.be.false;
  265. });
  266. it("single host", function () {
  267. this.mock.returns([{hostName: 'host1'}]);
  268. quickViewLinks.setQuickLinksSuccessCallback();
  269. expect(quickViewLinks.setSingleHostLinks.calledWith([{hostName: 'host1'}])).to.be.true;
  270. });
  271. it("multiple hosts", function () {
  272. this.mock.returns([{hostName: 'host1'}, {hostName: 'host2'}]);
  273. quickViewLinks.setQuickLinksSuccessCallback();
  274. expect(quickViewLinks.setMultipleHostLinks.calledWith(
  275. [{hostName: 'host1'}, {hostName: 'host2'}]
  276. )).to.be.true;
  277. });
  278. });
  279. describe("#getPublicHostName()", function () {
  280. it("host present", function () {
  281. var hosts = [{
  282. Hosts: {
  283. host_name: 'host1',
  284. public_host_name: 'public_name'
  285. }
  286. }];
  287. expect(quickViewLinks.getPublicHostName(hosts, 'host1')).to.equal('public_name');
  288. });
  289. it("host absent", function () {
  290. expect(quickViewLinks.getPublicHostName([], 'host1')).to.be.null;
  291. });
  292. });
  293. describe("#setConfigProperties()", function () {
  294. var mock = {getConfigsByTags: Em.K};
  295. beforeEach(function () {
  296. sinon.stub(App.router, 'get').returns(mock);
  297. sinon.spy(mock, 'getConfigsByTags');
  298. });
  299. afterEach(function () {
  300. mock.getConfigsByTags.restore();
  301. App.router.get.restore();
  302. });
  303. it("getConfigsByTags called with correct data", function () {
  304. quickViewLinks.set('actualTags', [{siteName: 'hdfs-site'}]);
  305. quickViewLinks.set('requiredSiteNames', ['hdfs-site']);
  306. quickViewLinks.setConfigProperties();
  307. expect(mock.getConfigsByTags.calledWith([{siteName: 'hdfs-site'}])).to.be.true;
  308. });
  309. });
  310. describe("#setEmptyLinks()", function () {
  311. it("empty links are set", function () {
  312. quickViewLinks.setEmptyLinks();
  313. expect(quickViewLinks.get('quickLinks')).to.eql([{
  314. label: quickViewLinks.get('quickLinksErrorMessage'),
  315. }]);
  316. expect(quickViewLinks.get('isLoaded')).to.be.true;
  317. });
  318. });
  319. describe("#processOozieHosts()", function () {
  320. it("host status is valid", function () {
  321. quickViewLinks.set('content.hostComponents', [Em.Object.create({
  322. componentName: 'OOZIE_SERVER',
  323. workStatus: 'STARTED',
  324. hostName: 'host1'
  325. })]);
  326. var host = {hostName: 'host1'};
  327. quickViewLinks.processOozieHosts([host]);
  328. expect(host.status).to.equal(Em.I18n.t('quick.links.label.active'));
  329. });
  330. it("host status is invalid", function () {
  331. quickViewLinks.set('content.hostComponents', [Em.Object.create({
  332. componentName: 'OOZIE_SERVER',
  333. workStatus: 'INSTALLED',
  334. hostName: 'host1'
  335. })]);
  336. var host = {hostName: 'host1'};
  337. quickViewLinks.processOozieHosts([host]);
  338. expect(quickViewLinks.get('quickLinksErrorMessage')).to.equal(Em.I18n.t('quick.links.error.oozie.label'));
  339. });
  340. });
  341. describe("#processHdfsHosts()", function () {
  342. beforeEach(function () {
  343. quickViewLinks.set('content.activeNameNode', null);
  344. quickViewLinks.set('content.standbyNameNode', null);
  345. quickViewLinks.set('content.standbyNameNode2', null);
  346. });
  347. it("active namenode host", function () {
  348. quickViewLinks.set('content.activeNameNode', Em.Object.create({hostName: 'host1'}));
  349. var host = {hostName: 'host1'};
  350. quickViewLinks.processHdfsHosts([host]);
  351. expect(host.status).to.equal(Em.I18n.t('quick.links.label.active'));
  352. });
  353. it("standby namenode host", function () {
  354. quickViewLinks.set('content.standbyNameNode', Em.Object.create({hostName: 'host1'}));
  355. var host = {hostName: 'host1'};
  356. quickViewLinks.processHdfsHosts([host]);
  357. expect(host.status).to.equal(Em.I18n.t('quick.links.label.standby'));
  358. });
  359. it("second standby namenode host", function () {
  360. quickViewLinks.set('content.standbyNameNode2', Em.Object.create({hostName: 'host1'}));
  361. var host = {hostName: 'host1'};
  362. quickViewLinks.processHdfsHosts([host]);
  363. expect(host.status).to.equal(Em.I18n.t('quick.links.label.standby'));
  364. });
  365. });
  366. describe("#processHbaseHosts()", function () {
  367. it("isActiveMaster is true", function () {
  368. var response = {
  369. items: [
  370. {
  371. Hosts: {
  372. host_name: 'host1'
  373. },
  374. host_components: [
  375. {
  376. HostRoles: {
  377. component_name: 'HBASE_MASTER'
  378. },
  379. metrics: {
  380. hbase: {
  381. master: {
  382. IsActiveMaster: 'true'
  383. }
  384. }
  385. }
  386. }
  387. ]
  388. }
  389. ]
  390. };
  391. var host = {hostName: 'host1'};
  392. quickViewLinks.processHbaseHosts([host], response);
  393. expect(host.status).to.equal(Em.I18n.t('quick.links.label.active'));
  394. });
  395. it("isActiveMaster is false", function () {
  396. var response = {
  397. items: [
  398. {
  399. Hosts: {
  400. host_name: 'host1'
  401. },
  402. host_components: [
  403. {
  404. HostRoles: {
  405. component_name: 'HBASE_MASTER'
  406. },
  407. metrics: {
  408. hbase: {
  409. master: {
  410. IsActiveMaster: 'false'
  411. }
  412. }
  413. }
  414. }
  415. ]
  416. }
  417. ]
  418. };
  419. var host = {hostName: 'host1'};
  420. quickViewLinks.processHbaseHosts([host], response);
  421. expect(host.status).to.equal(Em.I18n.t('quick.links.label.standby'));
  422. });
  423. it("isActiveMaster is undefined", function () {
  424. var response = {
  425. items: [
  426. {
  427. Hosts: {
  428. host_name: 'host1'
  429. },
  430. host_components: [
  431. {
  432. HostRoles: {
  433. component_name: 'HBASE_MASTER'
  434. }
  435. }
  436. ]
  437. }
  438. ]
  439. };
  440. var host = {hostName: 'host1'};
  441. quickViewLinks.processHbaseHosts([host], response);
  442. expect(host.status).to.be.undefined;
  443. });
  444. });
  445. describe("#processYarnHosts()", function () {
  446. it("haStatus is ACTIVE", function () {
  447. quickViewLinks.set('content.hostComponents', [Em.Object.create({
  448. componentName: 'RESOURCEMANAGER',
  449. hostName: 'host1',
  450. haStatus: 'ACTIVE'
  451. })]);
  452. var host = {hostName: 'host1'};
  453. quickViewLinks.processYarnHosts([host]);
  454. expect(host.status).to.equal(Em.I18n.t('quick.links.label.active'));
  455. });
  456. it("haStatus is STANDBY", function () {
  457. quickViewLinks.set('content.hostComponents', [Em.Object.create({
  458. componentName: 'RESOURCEMANAGER',
  459. hostName: 'host1',
  460. haStatus: 'STANDBY'
  461. })]);
  462. var host = {hostName: 'host1'};
  463. quickViewLinks.processYarnHosts([host]);
  464. expect(host.status).to.equal(Em.I18n.t('quick.links.label.standby'));
  465. });
  466. it("haStatus is undefined", function () {
  467. quickViewLinks.set('content.hostComponents', [Em.Object.create({
  468. componentName: 'RESOURCEMANAGER',
  469. hostName: 'host1'
  470. })]);
  471. var host = {hostName: 'host1'};
  472. quickViewLinks.processYarnHosts([host]);
  473. expect(host.status).to.be.undefined;
  474. });
  475. });
  476. describe("#findHosts()", function () {
  477. beforeEach(function () {
  478. sinon.stub(quickViewLinks, 'getPublicHostName').returns('public_name');
  479. });
  480. afterEach(function () {
  481. quickViewLinks.getPublicHostName.restore();
  482. });
  483. it("public_name from getPublicHostName", function () {
  484. quickViewLinks.set('content.hostComponents', [Em.Object.create({
  485. componentName: 'C1',
  486. hostName: 'host1'
  487. })]);
  488. expect(quickViewLinks.findHosts('C1', {})).to.eql([{
  489. hostName: 'host1',
  490. publicHostName: 'public_name'
  491. }]);
  492. });
  493. });
  494. describe('#setProtocol', function () {
  495. var tests = [
  496. //Yarn
  497. {
  498. serviceName: "YARN",
  499. configProperties: [
  500. {type: 'yarn-site', properties: {'yarn.http.policy': 'HTTPS_ONLY'}}
  501. ],
  502. quickLinksConfig: {
  503. protocol:{
  504. type:"https",
  505. checks:[
  506. {property:"yarn.http.policy",
  507. desired:"HTTPS_ONLY",
  508. site:"yarn-site"}
  509. ]
  510. }
  511. },
  512. m: "https for yarn (checks for https passed)",
  513. result: "https"
  514. },
  515. {
  516. serviceName: "YARN",
  517. configProperties: [
  518. {type: 'yarn-site', properties: {'yarn.http.policy': 'HTTP_ONLY'}}
  519. ],
  520. quickLinksConfig: {
  521. protocol:{
  522. type:"http",
  523. checks:[
  524. {property:"yarn.http.policy",
  525. desired:"HTTP_ONLY",
  526. site:"yarn-site"}
  527. ]
  528. }
  529. },
  530. m: "http for yarn (checks for http passed)",
  531. result: "http"
  532. },
  533. {
  534. serviceName: "YARN",
  535. configProperties: [
  536. {type: 'yarn-site', properties: {'yarn.http.policy': 'HTTP_ONLY'}}
  537. ],
  538. quickLinksConfig: {
  539. protocol:{
  540. type:"https",
  541. checks:[
  542. {property:"yarn.http.policy",
  543. desired:"HTTPS_ONLY",
  544. site:"yarn-site"}
  545. ]
  546. }
  547. },
  548. m: "http for yarn (checks for https did not pass)",
  549. result: "http"
  550. },
  551. {
  552. serviceName: "YARN",
  553. configProperties: [
  554. {type: 'yarn-site', properties: {'yarn.http.policy': 'HTTPS_ONLY'}}
  555. ],
  556. quickLinksConfig: {
  557. protocol:{
  558. type:"http",
  559. checks:[
  560. {property:"yarn.http.policy",
  561. desired:"HTTP_ONLY",
  562. site:"yarn-site"}
  563. ]
  564. }
  565. },
  566. m: "https for yarn (checks for http did not pass)",
  567. result: "https"
  568. },
  569. {
  570. serviceName: "YARN",
  571. configProperties: [
  572. {type: 'yarn-site', properties: {'yarn.http.policy': 'HTTP_ONLY'}}
  573. ],
  574. quickLinksConfig: {
  575. protocol:{
  576. type:"HTTP_ONLY",
  577. checks:[
  578. {property:"yarn.http.policy",
  579. desired:"HTTPS_ONLY",
  580. site:"yarn-site"}
  581. ]
  582. }
  583. },
  584. m: "http for yarn (override checks with specific protocol type)",
  585. result: "http"
  586. },
  587. {
  588. serviceName: "YARN",
  589. configProperties: [
  590. {type: 'yarn-site', properties: {'yarn.http.policy': 'HTTPS_ONLY'}}
  591. ],
  592. quickLinksConfig: {
  593. protocol:{
  594. type:"HTTPS_ONLY",
  595. checks:[
  596. {property:"yarn.http.policy",
  597. desired:"HTTPS_ONLY",
  598. site:"yarn-site"}
  599. ]
  600. }
  601. },
  602. m: "https for yarn (override checks with specific protocol type)",
  603. result: "https"
  604. },
  605. //Any service - override hadoop.ssl.enabled
  606. {
  607. serviceName: "MyService",
  608. configProperties: [
  609. {type: 'myservice-site', properties: {'myservice.http.policy': 'HTTPS_ONLY'}},
  610. {type: 'hdfs-site', properties: {'dfs.http.policy':'HTTP_ONLY'}}
  611. ],
  612. quickLinksConfig: {
  613. protocol:{
  614. type:"https",
  615. checks:[
  616. {property:"myservice.http.policy",
  617. desired:"HTTPS_ONLY",
  618. site:"myservice-site"}
  619. ]
  620. }
  621. },
  622. m: "https for MyService (checks for https passed, override hadoop.ssl.enabled)",
  623. result: "https"
  624. },
  625. //Oozie
  626. {
  627. serviceName: "OOZIE",
  628. configProperties: [
  629. {type: 'oozie-site', properties: {'oozie.https.port': '12345', 'oozie.https.keystore.file':'/tmp/oozie.jks', 'oozie.https.keystore.pass':'mypass'}}
  630. ],
  631. quickLinksConfig: {
  632. protocol:{
  633. type:"https",
  634. checks:
  635. [
  636. {
  637. "property":"oozie.https.port",
  638. "desired":"EXIST",
  639. "site":"oozie-site"
  640. },
  641. {
  642. "property":"oozie.https.keystore.file",
  643. "desired":"EXIST",
  644. "site":"oozie-site"
  645. },
  646. {
  647. "property":"oozie.https.keystore.pass",
  648. "desired":"EXIST",
  649. "site":"oozie-site"
  650. }
  651. ]
  652. }
  653. },
  654. m: "https for oozie (checks for https passed)",
  655. result: "https"
  656. },
  657. {
  658. serviceName: "OOZIE",
  659. configProperties: [
  660. {type: 'oozie-site', properties: {"oozie.base.url":"http://c6401.ambari.apache.org:11000/oozie"}}
  661. ],
  662. quickLinksConfig: {
  663. protocol:{
  664. type:"https",
  665. checks:
  666. [
  667. {
  668. "property":"oozie.https.port",
  669. "desired":"EXIST",
  670. "site":"oozie-site"
  671. },
  672. {
  673. "property":"oozie.https.keystore.file",
  674. "desired":"EXIST",
  675. "site":"oozie-site"
  676. },
  677. {
  678. "property":"oozie.https.keystore.pass",
  679. "desired":"EXIST",
  680. "site":"oozie-site"
  681. }
  682. ]
  683. }
  684. },
  685. m: "http for oozie (checks for https did not pass)",
  686. result: "http"
  687. },
  688. //Ranger: HDP 2.2
  689. {
  690. serviceName: "RANGER",
  691. configProperties: [{type: 'ranger-site', properties: {'http.enabled': 'false'}}],
  692. quickLinksConfig: {
  693. protocol:{
  694. type:"https",
  695. checks:
  696. [
  697. {
  698. "property":"http.enabled",
  699. "desired":"false",
  700. "site":"ranger-site"
  701. }
  702. ]
  703. }
  704. },
  705. m: "https for ranger (HDP2.2, checks passed)",
  706. result: "https"
  707. },
  708. {
  709. serviceName: "RANGER",
  710. configProperties: [{type: 'ranger-site', properties: {'http.enabled': 'true'}}],
  711. quickLinksConfig: {
  712. protocol:{
  713. type:"https",
  714. checks:
  715. [
  716. {
  717. "property":"http.enabled",
  718. "desired":"false",
  719. "site":"ranger-site"
  720. }
  721. ]
  722. }
  723. },
  724. m: "http for ranger (HDP2.2, checks for https did not pass)",
  725. result: "http"
  726. },
  727. //Ranger: HDP 2.3
  728. {
  729. serviceName: "RANGER",
  730. configProperties:
  731. [
  732. {
  733. type: 'ranger-admin-site',
  734. properties: {'ranger.service.http.enabled': 'false', 'ranger.service.https.attrib.ssl.enabled': 'true'}
  735. },
  736. ],
  737. quickLinksConfig: {
  738. protocol:{
  739. type:"https",
  740. checks:
  741. [
  742. {
  743. "property":"ranger.service.http.enabled",
  744. "desired":"false",
  745. "site":"ranger-admin-site"
  746. },
  747. {
  748. "property":"ranger.service.https.attrib.ssl.enabled",
  749. "desired":"true",
  750. "site":"ranger-admin-site"
  751. }
  752. ]
  753. }
  754. },
  755. m: "https for ranger (HDP2.3, checks passed)",
  756. result: "https"
  757. },
  758. {
  759. serviceName: "RANGER",
  760. configProperties:
  761. [
  762. {
  763. type: 'ranger-admin-site',
  764. properties: {'ranger.service.http.enabled': 'true', 'ranger.service.https.attrib.ssl.enabled': 'false'}
  765. },
  766. ],
  767. quickLinksConfig: {
  768. protocol:{
  769. type:"https",
  770. checks:
  771. [
  772. {
  773. "property":"ranger.service.http.enabled",
  774. "desired":"false",
  775. "site":"ranger-admin-site"
  776. },
  777. {
  778. "property":"ranger.service.https.attrib.ssl.enabled",
  779. "desired":"true",
  780. "site":"ranger-admin-site"
  781. }
  782. ]
  783. }
  784. },
  785. m: "http for ranger (HDP2.3, checks for https did not pass)",
  786. result: "http"
  787. }
  788. ];
  789. tests.forEach(function (t) {
  790. it(t.m, function () {
  791. quickViewLinks.set('servicesSupportsHttps', t.servicesSupportsHttps);
  792. expect(quickViewLinks.setProtocol(t.configProperties, t.quickLinksConfig)).to.equal(t.result);
  793. });
  794. });
  795. });
  796. describe('#setPort', function () {
  797. var testData = [
  798. Em.Object.create({
  799. 'protocol': 'http',
  800. 'port':{
  801. 'http_property':'yarn.timeline-service.webapp.address',
  802. 'http_default_port':'8188',
  803. 'https_property':'yarn.timeline-service.webapp.https.address',
  804. 'https_default_port':'8090',
  805. 'regex': '\\w*:(\\d+)',
  806. 'site':'yarn-site'
  807. },
  808. 'configProperties':
  809. [
  810. {
  811. 'type': 'yarn-site',
  812. 'properties': {'yarn.timeline-service.webapp.address': 'c6401.ambari.apache.org:8188'}
  813. },
  814. ],
  815. 'result': '8188'
  816. }),
  817. Em.Object.create({
  818. 'protocol': 'https',
  819. 'port':{
  820. 'http_property':'yarn.timeline-service.webapp.address',
  821. 'http_default_port':'8188',
  822. 'https_property':'yarn.timeline-service.webapp.https.address',
  823. 'https_default_port':'8090',
  824. 'regex': '\\w*:(\\d+)',
  825. 'site':'yarn-site'
  826. },
  827. 'configProperties':
  828. [
  829. {
  830. 'type': 'yarn-site',
  831. 'properties': {'yarn.timeline-service.webapp.https.address': 'c6401.ambari.apache.org:8090'}
  832. }
  833. ],
  834. 'result': '8090'
  835. })
  836. ];
  837. after(function () {
  838. quickViewLinks.set('configProperties', []);
  839. });
  840. testData.forEach(function (item) {
  841. it(item.service_id + ' ' + item.protocol, function () {
  842. quickViewLinks.set('configProperties', item.configProperties || []);
  843. expect(quickViewLinks.setPort(item.port, item.protocol, item.configProperties)).to.equal(item.result);
  844. })
  845. }, this);
  846. });
  847. describe("#getHosts()", function() {
  848. beforeEach(function() {
  849. sinon.stub(quickViewLinks, 'processOozieHosts').returns(['oozieHost']);
  850. sinon.stub(quickViewLinks, 'processHdfsHosts').returns(['hdfsHost']);
  851. sinon.stub(quickViewLinks, 'processHbaseHosts').returns(['hbaseHost']);
  852. sinon.stub(quickViewLinks, 'processYarnHosts').returns(['yarnHost']);
  853. sinon.stub(quickViewLinks, 'findHosts').returns(['host1']);
  854. App.set('singleNodeInstall', false);
  855. quickViewLinks.set('content', Em.Object.create({
  856. hostComponents: []
  857. }));
  858. });
  859. afterEach(function() {
  860. quickViewLinks.processOozieHosts.restore();
  861. quickViewLinks.processHdfsHosts.restore();
  862. quickViewLinks.processHbaseHosts.restore();
  863. quickViewLinks.findHosts.restore();
  864. quickViewLinks.processYarnHosts.restore();
  865. });
  866. it("singleNodeInstall is true", function() {
  867. App.set('singleNodeInstall', true);
  868. App.set('singleNodeAlias', 'host1');
  869. expect(quickViewLinks.getHosts({}, 'S1')).to.eql([{
  870. hostName: 'host1',
  871. publicHostName: 'host1'
  872. }])
  873. });
  874. it("content is null", function() {
  875. quickViewLinks.set('content', null);
  876. expect(quickViewLinks.getHosts({}, 'S1')).to.be.empty;
  877. });
  878. it("OOZIE service", function() {
  879. expect(quickViewLinks.getHosts({}, 'OOZIE')).to.eql(['oozieHost']);
  880. expect(quickViewLinks.findHosts.calledWith('OOZIE_SERVER', {})).to.be.true;
  881. expect(quickViewLinks.processOozieHosts.calledOnce).to.be.true;
  882. });
  883. it("HDFS service", function() {
  884. expect(quickViewLinks.getHosts({}, 'HDFS')).to.eql(['hdfsHost']);
  885. expect(quickViewLinks.findHosts.calledWith('NAMENODE', {})).to.be.true;
  886. expect(quickViewLinks.processHdfsHosts.calledOnce).to.be.true;
  887. });
  888. it("HBASE service", function() {
  889. expect(quickViewLinks.getHosts({}, 'HBASE')).to.eql(['hbaseHost']);
  890. expect(quickViewLinks.findHosts.calledWith('HBASE_MASTER', {})).to.be.true;
  891. expect(quickViewLinks.processHbaseHosts.calledOnce).to.be.true;
  892. });
  893. it("YARN service", function() {
  894. expect(quickViewLinks.getHosts({}, 'YARN')).to.eql(['yarnHost']);
  895. expect(quickViewLinks.findHosts.calledWith('RESOURCEMANAGER', {})).to.be.true;
  896. expect(quickViewLinks.processYarnHosts.calledOnce).to.be.true;
  897. });
  898. it("STORM service", function() {
  899. expect(quickViewLinks.getHosts({}, 'STORM')).to.eql(['host1']);
  900. expect(quickViewLinks.findHosts.calledWith('STORM_UI_SERVER', {})).to.be.true;
  901. });
  902. it("ACCUMULO service", function() {
  903. expect(quickViewLinks.getHosts({}, 'ACCUMULO')).to.eql(['host1']);
  904. expect(quickViewLinks.findHosts.calledWith('ACCUMULO_MONITOR', {})).to.be.true;
  905. });
  906. it("ATLAS service", function() {
  907. expect(quickViewLinks.getHosts({}, 'ATLAS')).to.eql(['host1']);
  908. expect(quickViewLinks.findHosts.calledWith('ATLAS_SERVER', {})).to.be.true;
  909. });
  910. it("MAPREDUCE2 service", function() {
  911. expect(quickViewLinks.getHosts({}, 'MAPREDUCE2')).to.eql(['host1']);
  912. expect(quickViewLinks.findHosts.calledWith('HISTORYSERVER', {})).to.be.true;
  913. });
  914. it("AMBARI_METRICS service", function() {
  915. expect(quickViewLinks.getHosts({}, 'AMBARI_METRICS')).to.eql(['host1']);
  916. expect(quickViewLinks.findHosts.calledWith('METRICS_GRAFANA', {})).to.be.true;
  917. });
  918. it("custom service without master", function() {
  919. expect(quickViewLinks.getHosts({}, 'S1')).to.be.empty;
  920. });
  921. it("custom service with master", function() {
  922. quickViewLinks.set('content', Em.Object.create({
  923. hostComponents: [
  924. Em.Object.create({
  925. isMaster: true,
  926. componentName: 'C1'
  927. })
  928. ]
  929. }));
  930. expect(quickViewLinks.getHosts({}, 'S1')).to.eql(['host1']);
  931. expect(quickViewLinks.findHosts.calledWith('C1', {})).to.be.true;
  932. });
  933. });
  934. });