ajax.js 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390
  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. /**
  20. * Config for each ajax-request
  21. *
  22. * Fields example:
  23. * mock - testMode url
  24. * real - real url (without API prefix)
  25. * type - request type (also may be defined in the format method)
  26. * format - function for processing ajax params after default formatRequest. May be called with one or two parameters (data, opt). Return ajax-params object
  27. * testInProduction - can this request be executed on production tests (used only in tests)
  28. *
  29. * @type {Object}
  30. */
  31. var urls = {
  32. 'alerts.get_by_service': {
  33. 'real': '/clusters/{clusterName}/services/{serviceName}?fields=alerts',
  34. 'mock': '/data/alerts/HDP2/service_alerts.json'
  35. },
  36. 'alerts.get_by_host': {
  37. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=alerts',
  38. 'mock': '/data/alerts/HDP2/host_alerts.json'
  39. },
  40. 'background_operations.get_most_recent': {
  41. 'real': '/clusters/{clusterName}/requests?to=end&page_size=10&fields=Requests',
  42. 'mock': '/data/background_operations/list_on_start.json',
  43. 'testInProduction': true
  44. },
  45. 'background_operations.get_by_request': {
  46. 'real': '/clusters/{clusterName}/requests/{requestId}?fields=*,tasks/Tasks/command,tasks/Tasks/command_detail,tasks/Tasks/start_time,tasks/Tasks/end_time,tasks/Tasks/exit_code,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status&minimal_response=true',
  47. 'mock': '/data/background_operations/task_by_request{requestId}.json',
  48. 'testInProduction': true
  49. },
  50. 'background_operations.get_by_task': {
  51. 'real': '/clusters/{clusterName}/requests/{requestId}/tasks/{taskId}',
  52. 'mock': '/data/background_operations/list_on_start.json',
  53. 'testInProduction': true
  54. },
  55. 'service.item.start_stop': {
  56. 'real': '/clusters/{clusterName}/services/{serviceName}',
  57. 'mock': '/data/wizard/deploy/poll_1.json',
  58. 'format': function (data) {
  59. return {
  60. type: 'PUT',
  61. data: JSON.stringify({
  62. RequestInfo: {
  63. "context": data.requestInfo,
  64. "operation_level": {
  65. "level": "SERVICE",
  66. "cluster_name" : data.clusterName,
  67. "service_name" : data.serviceName
  68. }
  69. },
  70. Body: {
  71. ServiceInfo: {
  72. state: data.state
  73. }
  74. }
  75. })
  76. };
  77. }
  78. },
  79. 'service.item.smoke': {
  80. 'real': '/clusters/{clusterName}/requests',
  81. 'mock': '/data/wizard/deploy/poll_1.json',
  82. 'format': function (data) {
  83. return {
  84. 'type': 'POST',
  85. data: JSON.stringify({
  86. "RequestInfo": {
  87. "context": data.displayName + " Service Check",
  88. "command" : data.actionName
  89. },
  90. "Requests/resource_filters": [{"service_name" : data.serviceName}]
  91. })
  92. };
  93. }
  94. },
  95. 'service.item.passive': {
  96. 'real': '/clusters/{clusterName}/services/{serviceName}',
  97. 'mock': '',
  98. 'format': function (data) {
  99. return {
  100. type: 'PUT',
  101. data: JSON.stringify({
  102. RequestInfo: {
  103. "context": data.requestInfo
  104. },
  105. Body: {
  106. ServiceInfo: {
  107. maintenance_state: data.passive_state
  108. }
  109. }
  110. })
  111. };
  112. }
  113. },
  114. 'service.stale_host_components.start_stop': {
  115. 'real': '/clusters/{clusterName}/host_components?' +
  116. 'HostRoles/stale_configs=true&HostRoles/component_name.in({componentNames})',
  117. 'mock': '/data/wizard/deploy/poll_1.json',
  118. 'format': function (data) {
  119. return {
  120. type: 'PUT',
  121. data: JSON.stringify({
  122. RequestInfo: {
  123. "context": data.requestInfo
  124. },
  125. Body: {
  126. HostRoles: {
  127. state: data.state
  128. }
  129. }
  130. })
  131. };
  132. }
  133. },
  134. 'service.load_config_groups': {
  135. 'real': '/clusters/{clusterName}/config_groups?ConfigGroup/tag={serviceName}&fields=*',
  136. 'mock': '/data/configurations/config_group.json'
  137. },
  138. 'service.flume.agent.command': {
  139. 'real': '/clusters/{clusterName}/hosts/{host}/host_components/FLUME_HANDLER',
  140. 'mock': '',
  141. 'format': function (data) {
  142. return {
  143. type: 'PUT',
  144. data: JSON.stringify({
  145. "RequestInfo": {
  146. "context": data.context,
  147. "flume_handler": data.agentName
  148. },
  149. "Body": {
  150. "HostRoles": {
  151. "state": data.state
  152. }
  153. }
  154. })
  155. }
  156. }
  157. },
  158. 'reassign.stop_services': {
  159. 'real': '/clusters/{clusterName}/services',
  160. 'mock': '',
  161. 'format': function() {
  162. return {
  163. type: 'PUT',
  164. data: JSON.stringify({
  165. "RequestInfo": {
  166. "context": "Stop all services"
  167. },
  168. "Body": {
  169. "ServiceInfo": {
  170. "state": "INSTALLED"
  171. }
  172. }
  173. })
  174. }
  175. }
  176. },
  177. 'reassign.stop_YMR2_services': {
  178. 'real': '/clusters/{clusterName}/services?ServiceInfo/service_name.in({servicesList})',
  179. 'mock': '',
  180. 'format': function() {
  181. return {
  182. type: 'PUT',
  183. data: JSON.stringify({
  184. "RequestInfo": {
  185. "context": "Stop without HDFS"
  186. },
  187. "Body": {
  188. "ServiceInfo": {
  189. "state": "INSTALLED"
  190. }
  191. }
  192. })
  193. }
  194. }
  195. },
  196. 'reassign.start_services': {
  197. 'real': '/clusters/{clusterName}/services?params/run_smoke_test=true',
  198. 'mock': '',
  199. 'format': function() {
  200. return {
  201. type: 'PUT',
  202. data: JSON.stringify({
  203. "RequestInfo": {
  204. "context": "Start all services"
  205. },
  206. "Body": {
  207. "ServiceInfo": {
  208. "state": "STARTED"
  209. }
  210. }
  211. })
  212. }
  213. }
  214. },
  215. 'reassign.start_YMR2_services': {
  216. 'real': '/clusters/{clusterName}/services/?ServiceInfo/service_name.in({servicesList})',
  217. 'mock': '',
  218. 'format': function() {
  219. return {
  220. type: 'PUT',
  221. data: JSON.stringify({
  222. "RequestInfo": {
  223. "context": "Start without HDFS"
  224. },
  225. "Body": {
  226. "ServiceInfo": {
  227. "state": "STARTED"
  228. }
  229. }
  230. })
  231. }
  232. }
  233. },
  234. 'reassign.maintenance_mode': {
  235. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  236. 'mock': '',
  237. 'type': 'PUT',
  238. 'format': function () {
  239. return {
  240. data: JSON.stringify(
  241. {
  242. "HostRoles": {
  243. "state": "DISABLED"
  244. }
  245. }
  246. )
  247. }
  248. }
  249. },
  250. 'reassign.remove_component': {
  251. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  252. 'mock': '',
  253. 'type': 'DELETE'
  254. },
  255. 'reassign.load_configs': {
  256. 'real': '/clusters/{clusterName}/configurations?{urlParams}',
  257. 'mock': ''
  258. },
  259. 'reassign.save_configs': {
  260. 'real': '/clusters/{clusterName}',
  261. 'mock': '',
  262. 'type': 'PUT',
  263. 'format': function (data) {
  264. return {
  265. data: JSON.stringify({
  266. Clusters: {
  267. desired_config: {
  268. "type": data.siteName,
  269. "tag": 'version' + (new Date).getTime(),
  270. "properties": data.properties
  271. }
  272. }
  273. })
  274. }
  275. }
  276. },
  277. 'host_component.passive': {
  278. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  279. 'mock': '',
  280. 'type': 'PUT',
  281. 'format': function(data) {
  282. return {
  283. data: JSON.stringify({
  284. RequestInfo: {
  285. "context": data.requestInfo
  286. },
  287. Body: {
  288. HostRoles: {
  289. maintenance_state: data.passive_state
  290. }
  291. }
  292. })
  293. };
  294. }
  295. },
  296. 'config.cluster_configuration.put': {
  297. 'real': '/clusters/{cluster}',
  298. 'mock': '',
  299. 'format': function(data) {
  300. return {
  301. type: 'PUT',
  302. dataType: 'text',
  303. data: data.data
  304. }
  305. }
  306. },
  307. 'config.advanced': {
  308. 'real': '{stackVersionUrl}/services/{serviceName}/configurations?fields=*',
  309. 'mock': '/data/wizard/stack/hdp/version{stackVersion}/{serviceName}.json'
  310. },
  311. 'config.tags': {
  312. 'real': '/clusters/{clusterName}?fields=Clusters/desired_configs',
  313. 'mock': '/data/clusters/cluster.json'
  314. },
  315. 'config.tags_and_groups': {
  316. 'real': '/clusters/{clusterName}?fields=Clusters/desired_configs,config_groups/*{urlParams}',
  317. 'mock': '/data/clusters/tags_and_groups.json'
  318. },
  319. 'config.ambari.database.info': {
  320. 'real': '/services/AMBARI/components/AMBARI_SERVER?fields=hostComponents/RootServiceHostComponents/properties/server.jdbc.database,hostComponents/RootServiceHostComponents/properties/server.jdbc.url',
  321. 'mock': '',
  322. 'format': function() {
  323. return {
  324. async: false
  325. };
  326. }
  327. },
  328. 'config_groups.all_fields': {
  329. 'real': '/clusters/{clusterName}/config_groups?fields=*',
  330. 'mock': ''
  331. },
  332. 'config_groups.get_config_group_by_id': {
  333. 'real': '/clusters/{clusterName}/config_groups/{id}',
  334. 'mock': ''
  335. },
  336. 'config_groups.update_config_group': {
  337. 'real': '/clusters/{clusterName}/config_groups/{id}',
  338. 'mock': '',
  339. 'type': 'PUT',
  340. 'format': function (data) {
  341. return {
  342. data: JSON.stringify(
  343. [
  344. data.configGroup
  345. ]
  346. )
  347. }
  348. }
  349. },
  350. 'config_groups.delete_config_group': {
  351. 'real': '/clusters/{clusterName}/config_groups/{id}',
  352. 'mock': '',
  353. 'type': 'DELETE'
  354. },
  355. 'config.on_site': {
  356. 'real': '/clusters/{clusterName}/configurations?{params}',
  357. 'mock': '/data/configurations/cluster_level_configs.json?{params}',
  358. 'format': function() {
  359. return {
  360. async: false
  361. };
  362. }
  363. },
  364. 'config.host_overrides': {
  365. 'real': '/clusters/{clusterName}/configurations?{params}',
  366. 'mock': '/data/configurations/host_level_overrides_configs.json?{params}'
  367. },
  368. 'host.host_component.delete': {
  369. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  370. 'mock': '',
  371. 'format': function() {
  372. return {
  373. type: 'DELETE',
  374. async: false
  375. }
  376. }
  377. },
  378. 'host.host_components.delete': {
  379. 'real': '/clusters/{clusterName}/hosts/{hostName}',
  380. 'mock': '',
  381. 'format': function() {
  382. return {
  383. type: 'DELETE',
  384. async: false
  385. }
  386. }
  387. },
  388. 'host.host_component.stop': {
  389. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  390. 'mock': '/data/wizard/deploy/poll_1.json',
  391. 'format': function(data) {
  392. return {
  393. type: 'PUT',
  394. data: data.data
  395. }
  396. }
  397. },
  398. 'host.host_components.stop': {
  399. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components',
  400. 'mock': '/data/wizard/deploy/poll_1.json',
  401. 'format': function(data) {
  402. return {
  403. type: 'PUT',
  404. async: false,
  405. data: data.data
  406. }
  407. }
  408. },
  409. 'host.host_component.start': {
  410. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  411. 'mock': '/data/wizard/deploy/poll_1.json',
  412. 'format': function(data) {
  413. return {
  414. type: 'PUT',
  415. data: data.data
  416. }
  417. }
  418. },
  419. 'host.host_component.install': {
  420. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  421. 'mock': '/data/wizard/deploy/poll_1.json',
  422. 'format': function(data) {
  423. return {
  424. type: 'PUT',
  425. data: data.data
  426. }
  427. }
  428. },
  429. 'host.host_component.update': {
  430. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  431. 'mock': '/data/wizard/deploy/poll_1.json',
  432. 'format': function(data) {
  433. return {
  434. type: 'PUT',
  435. data: data.data
  436. }
  437. }
  438. },
  439. 'host.host_component.add_new_component': {
  440. 'real': '/clusters/{clusterName}/hosts?Hosts/host_name={hostName}',
  441. 'mock': '/data/wizard/deploy/poll_1.json',
  442. 'format': function(data) {
  443. return {
  444. type: 'POST',
  445. data: data.data
  446. }
  447. }
  448. },
  449. 'host.host_component.install_new_component': {
  450. 'real': '/clusters/{clusterName}/host_components?HostRoles/host_name={hostName}\&HostRoles/component_name={componentName}\&HostRoles/state=INIT',
  451. 'mock': '/data/wizard/deploy/poll_1.json',
  452. 'format': function(data) {
  453. return {
  454. type: 'PUT',
  455. data: data.data
  456. }
  457. }
  458. },
  459. 'host.host_component.slave_desired_admin_state': {
  460. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}/?fields=HostRoles/desired_admin_state',
  461. 'mock': ''
  462. },
  463. 'host.host_component.decommission_status': {
  464. 'real': '/clusters/{clusterName}/services/{serviceName}/components/{componentName}/?fields=ServiceComponentInfo',
  465. 'mock': ''
  466. },
  467. 'host.host_component.decommission_status_datanode': {
  468. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}?fields=metrics/dfs/namenode',
  469. 'mock': ''
  470. },
  471. 'host.host_component.decommission_slave': {
  472. 'real' : '/clusters/{clusterName}/requests',
  473. 'mock' : '',
  474. 'format' : function(data) {
  475. return {
  476. type : 'POST',
  477. data : JSON.stringify({
  478. RequestInfo: {
  479. 'context': data.context,
  480. 'command': data.command,
  481. 'parameters': {
  482. 'slave_type': data.slaveType,
  483. 'excluded_hosts': data.hostName
  484. }
  485. },
  486. "Requests/resource_filters": [{"service_name" : data.serviceName, "component_name" : data.componentName}]
  487. })
  488. }
  489. }
  490. },
  491. 'host.host_component.recommission_and_restart': {
  492. 'real': '/clusters/{clusterName}/request_schedules',
  493. 'mock': '',
  494. 'format' : function(data) {
  495. return {
  496. type : 'POST',
  497. data : JSON.stringify([ {
  498. "RequestSchedule" : {
  499. "batch" : [ {
  500. "requests" : data.batches
  501. }, {
  502. "batch_settings" : {
  503. "batch_separation_in_seconds" : data.intervalTimeSeconds,
  504. "task_failure_tolerance" : data.tolerateSize
  505. }
  506. } ]
  507. }
  508. } ])
  509. }
  510. }
  511. },
  512. 'host.host_component.recommission_slave' : {
  513. 'real' : '/clusters/{clusterName}/requests',
  514. 'mock' : '',
  515. 'format' : function(data) {
  516. return {
  517. type : 'POST',
  518. data : JSON.stringify({
  519. RequestInfo: {
  520. context: data.context,
  521. command: data.command,
  522. parameters: {
  523. slave_type: data.slaveType,
  524. included_hosts: data.hostName
  525. }
  526. },
  527. "Requests/resource_filters": [{"service_name" : data.serviceName, "component_name" : data.componentName}]
  528. })
  529. }
  530. }
  531. },
  532. 'host.stale_host_components.start_stop': {
  533. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components?HostRoles/stale_configs=true&' +
  534. 'HostRoles/component_name.in({componentNames})',
  535. 'mock': '',
  536. 'type': 'PUT',
  537. 'format': function (data) {
  538. return {
  539. data: JSON.stringify({
  540. RequestInfo: {
  541. "context": data.context
  542. },
  543. Body: {
  544. "HostRoles": {
  545. "state": data.state
  546. }
  547. }
  548. })
  549. }
  550. }
  551. },
  552. 'host.host_component.refresh_configs': {
  553. 'real':'/clusters/{clusterName}/requests',
  554. 'mock':'',
  555. 'format': function(data) {
  556. return {
  557. type : 'POST',
  558. data : JSON.stringify({
  559. "RequestInfo": {
  560. "command": "CONFIGURE",
  561. "context": data.context
  562. },
  563. "Requests/resource_filters": data.resource_filters
  564. })
  565. }
  566. }
  567. },
  568. 'host.delete': {
  569. 'real': '/clusters/{clusterName}/hosts/{hostName}',
  570. 'mock': '',
  571. 'type': 'DELETE',
  572. 'format': function() {
  573. return {
  574. async: false
  575. }
  576. }
  577. },
  578. 'hosts.metrics': {
  579. 'real': '/clusters/{clusterName}/hosts?fields={metricName}',
  580. 'mock': '/data/cluster_metrics/cpu_1hr.json'
  581. },
  582. 'hosts.metrics.host_component': {
  583. 'real': '/clusters/{clusterName}/services/{serviceName}/components/{componentName}?fields=host_components/{metricName}',
  584. 'mock': '/data/cluster_metrics/cpu_1hr.json'
  585. },
  586. 'service.service_component': {
  587. 'real': '/clusters/{clusterName}/services/{serviceName}/components/{componentName}',
  588. 'mock': '',
  589. 'format': function(data) {
  590. return {
  591. async: data.async
  592. };
  593. }
  594. },
  595. 'service.metrics.flume.channel_fill_percent': {
  596. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_HANDLER?fields=host_components/metrics/flume/flume/CHANNEL/*/ChannelFillPercentage[{fromSeconds},{toSeconds},{stepSeconds}]',
  597. 'mock': '/data/services/metrics/flume/channelFillPct.json',
  598. 'testInProduction': true
  599. },
  600. 'service.metrics.flume.channel_size': {
  601. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_HANDLER?fields=host_components/metrics/flume/flume/CHANNEL/*/ChannelSize[{fromSeconds},{toSeconds},{stepSeconds}]',
  602. 'mock': '/data/services/metrics/flume/channelSize.json',
  603. 'testInProduction': true
  604. },
  605. 'service.metrics.flume.sink_drain_success': {
  606. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_HANDLER?fields=host_components/metrics/flume/flume/SINK/*/EventDrainSuccessCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  607. 'mock': '/data/services/metrics/flume/sinkDrainSuccessCount.json',
  608. 'testInProduction': true
  609. },
  610. 'service.metrics.flume.sink_connection_failed': {
  611. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_HANDLER?fields=host_components/metrics/flume/flume/SINK/*/ConnectionFailedCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  612. 'mock': '/data/services/metrics/flume/sinkConnectionFailedCount.json',
  613. 'testInProduction': true
  614. },
  615. 'service.metrics.flume.gc': {
  616. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_HANDLER?fields=host_components/metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  617. 'mock': '/data/services/metrics/flume/jvmGcTime.json',
  618. 'testInProduction': true
  619. },
  620. 'service.metrics.flume.jvm_heap_used': {
  621. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_HANDLER?fields=host_components/metrics/jvm/memHeapUsedM[{fromSeconds},{toSeconds},{stepSeconds}]',
  622. 'mock': '/data/services/metrics/flume/jvmMemHeapUsedM.json',
  623. 'testInProduction': true
  624. },
  625. 'service.metrics.flume.jvm_threads_runnable': {
  626. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_HANDLER?fields=host_components/metrics/jvm/threadsRunnable[{fromSeconds},{toSeconds},{stepSeconds}]',
  627. 'mock': '/data/services/metrics/flume/jvmThreadsRunnable.json',
  628. 'testInProduction': true
  629. },
  630. 'service.metrics.flume.cpu_user': {
  631. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_HANDLER?fields=host_components/metrics/cpu/cpu_user[{fromSeconds},{toSeconds},{stepSeconds}]',
  632. 'mock': '',
  633. 'testInProduction': true
  634. },
  635. 'service.metrics.flume.source_accepted': {
  636. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_HANDLER?fields=host_components/metrics/flume/flume/SOURCE/*/EventAcceptedCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  637. 'mock': '/data/services/metrics/flume/sourceEventAccepted.json',
  638. 'testInProduction': true
  639. },
  640. 'service.metrics.hbase.cluster_requests': {
  641. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/cluster_requests[{fromSeconds},{toSeconds},{stepSeconds}]',
  642. 'mock': '/data/services/metrics/hbase/cluster_requests.json',
  643. 'testInProduction': true
  644. },
  645. 'service.metrics.hbase.hlog_split_size': {
  646. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/splitSize_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  647. 'mock': '/data/services/metrics/hbase/hlog_split_size.json',
  648. 'testInProduction': true
  649. },
  650. 'service.metrics.hbase.hlog_split_time': {
  651. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/splitTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  652. 'mock': '/data/services/metrics/hbase/hlog_split_time.json',
  653. 'testInProduction': true
  654. },
  655. 'service.metrics.hbase.regionserver_queuesize': {
  656. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/flushQueueSize[{fromSeconds},{toSeconds},{stepSeconds}],metrics/hbase/regionserver/compactionQueueSize[{fromSeconds},{toSeconds},{stepSeconds}]',
  657. 'mock': '/data/services/metrics/hbase/regionserver_queuesize.json',
  658. 'testInProduction': true
  659. },
  660. 'service.metrics.hbase.regionserver_regions': {
  661. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/regions[{fromSeconds},{toSeconds},{stepSeconds}]',
  662. 'mock': '/data/services/metrics/hbase/regionserver_regions.json',
  663. 'testInProduction': true
  664. },
  665. 'service.metrics.hbase.regionserver_rw_requests': {
  666. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/readRequestsCount[{fromSeconds},{toSeconds},{stepSeconds}],metrics/hbase/regionserver/writeRequestsCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  667. 'mock': '/data/services/metrics/hbase/regionserver_rw_requests.json',
  668. 'testInProduction': true
  669. },
  670. 'service.metrics.mapreduce.gc': {
  671. 'real': '/clusters/{clusterName}/hosts/{jobTrackerNode}/host_components/JOBTRACKER?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  672. 'mock': '/data/services/metrics/mapreduce/gc.json',
  673. 'testInProduction': true
  674. },
  675. 'service.metrics.mapreduce.jobs_status': {
  676. 'real': '/clusters/{clusterName}/services/MAPREDUCE/components/JOBTRACKER?fields=metrics/mapred/jobtracker/jobs_completed[{fromSeconds},{toSeconds},{stepSeconds}],metrics/mapred/jobtracker/jobs_preparing[{fromSeconds},{toSeconds},{stepSeconds}],metrics/mapred/jobtracker/jobs_failed[{fromSeconds},{toSeconds},{stepSeconds}],metrics/mapred/jobtracker/jobs_submitted[{fromSeconds},{toSeconds},{stepSeconds}],metrics/mapred/jobtracker/jobs_failed[{fromSeconds},{toSeconds},{stepSeconds}],metrics/mapred/jobtracker/jobs_running[{fromSeconds},{toSeconds},{stepSeconds}]',
  677. 'mock': '/data/services/metrics/mapreduce/jobs_status.json',
  678. 'testInProduction': true
  679. },
  680. 'service.metrics.mapreduce.jobs_heap': {
  681. 'real': '/clusters/{clusterName}/hosts/{jobTrackerNode}/host_components/JOBTRACKER?fields=metrics/jvm/memNonHeapUsedM[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/memNonHeapCommittedM[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/memHeapUsedM[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/memHeapCommittedM[{fromSeconds},{toSeconds},{stepSeconds}]',
  682. 'mock': '/data/services/metrics/mapreduce/jvm_heap.json',
  683. 'testInProduction': true
  684. },
  685. 'service.metrics.mapreduce.jobs_threads': {
  686. 'real': '/clusters/{clusterName}/hosts/{jobTrackerNode}/host_components/JOBTRACKER?fields=metrics/jvm/threadsRunnable[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/threadsBlocked[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/threadsWaiting[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/threadsTimedWaiting[{fromSeconds},{toSeconds},{stepSeconds}]',
  687. 'mock': '/data/services/metrics/mapreduce/jvm_threads.json',
  688. 'testInProduction': true
  689. },
  690. 'service.metrics.mapreduce.map_slots': {
  691. 'real': '/clusters/{clusterName}/services/MAPREDUCE/components/JOBTRACKER?fields=metrics/mapred/jobtracker/occupied_map_slots[{fromSeconds},{toSeconds},{stepSeconds}],metrics/mapred/jobtracker/reserved_map_slots[{fromSeconds},{toSeconds},{stepSeconds}]',
  692. 'mock': '/data/services/metrics/mapreduce/map_slots.json',
  693. 'testInProduction': true
  694. },
  695. 'service.metrics.mapreduce.reduce_slots': {
  696. 'real': '/clusters/{clusterName}/services/MAPREDUCE/components/JOBTRACKER?fields=metrics/mapred/jobtracker/occupied_reduce_slots[{fromSeconds},{toSeconds},{stepSeconds}],metrics/mapred/jobtracker/reserved_reduce_slots[{fromSeconds},{toSeconds},{stepSeconds}]',
  697. 'mock': '/data/services/metrics/mapreduce/reduce_slots.json',
  698. 'testInProduction': true
  699. },
  700. 'service.metrics.mapreduce.rpc': {
  701. 'real': '/clusters/{clusterName}/hosts/{jobTrackerNode}/host_components/JOBTRACKER?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  702. 'mock': '/data/services/metrics/mapreduce/rpc.json',
  703. 'testInProduction': true
  704. },
  705. 'service.metrics.mapreduce.tasks_running_waiting': {
  706. 'real': '/clusters/{clusterName}/services/MAPREDUCE/components/JOBTRACKER?fields=metrics/mapred/jobtracker/running_maps[{fromSeconds},{toSeconds},{stepSeconds}],metrics/mapred/jobtracker/running_reduces[{fromSeconds},{toSeconds},{stepSeconds}],metrics/mapred/jobtracker/waiting_maps[{fromSeconds},{toSeconds},{stepSeconds}],metrics/mapred/jobtracker/waiting_reduces[{fromSeconds},{toSeconds},{stepSeconds}]',
  707. 'mock': '/data/services/metrics/mapreduce/tasks_running_waiting.json',
  708. 'testInProduction': true
  709. },
  710. 'service.metrics.hdfs.block_status': {
  711. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/dfs/FSNamesystem/PendingReplicationBlocks[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/FSNamesystem/UnderReplicatedBlocks[{fromSeconds},{toSeconds},{stepSeconds}]',
  712. 'mock': '/data/services/metrics/hdfs/block_status.json',
  713. 'testInProduction': true
  714. },
  715. 'service.metrics.hdfs.file_operations': {
  716. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/dfs/namenode/FileInfoOps[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/namenode/CreateFileOps[{fromSeconds},{toSeconds},{stepSeconds}]',
  717. 'mock': '/data/services/metrics/hdfs/file_operations.json',
  718. 'testInProduction': true
  719. },
  720. 'service.metrics.hdfs.gc': {
  721. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  722. 'mock': '/data/services/metrics/hdfs/gc.json',
  723. 'testInProduction': true
  724. },
  725. 'service.metrics.hdfs.io': {
  726. 'real': '/clusters/{clusterName}/services/HDFS/components/DATANODE?fields=metrics/dfs/datanode/bytes_written[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/datanode/bytes_read[{fromSeconds},{toSeconds},{stepSeconds}]',
  727. 'mock': '/data/services/metrics/hdfs/io.json',
  728. 'testInProduction': true
  729. },
  730. 'service.metrics.hdfs.jvm_heap': {
  731. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/jvm/memNonHeapUsedM[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/memNonHeapCommittedM[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/memHeapUsedM[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/memHeapCommittedM[{fromSeconds},{toSeconds},{stepSeconds}]',
  732. 'mock': '/data/services/metrics/hdfs/jvm_heap.json',
  733. 'testInProduction': true
  734. },
  735. 'service.metrics.hdfs.jvm_threads': {
  736. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/jvm/threadsRunnable[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/threadsBlocked[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/threadsWaiting[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/threadsTimedWaiting[{fromSeconds},{toSeconds},{stepSeconds}]',
  737. 'mock': '/data/services/metrics/hdfs/jvm_threads.json',
  738. 'testInProduction': true
  739. },
  740. 'service.metrics.hdfs.rpc': {
  741. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  742. 'mock': '/data/services/metrics/hdfs/rpc.json',
  743. 'testInProduction': true
  744. },
  745. 'service.metrics.hdfs.space_utilization': {
  746. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/dfs/FSNamesystem/CapacityRemainingGB[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/FSNamesystem/CapacityUsedGB[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/FSNamesystem/CapacityTotalGB[{fromSeconds},{toSeconds},{stepSeconds}]',
  747. 'mock': '/data/services/metrics/hdfs/space_utilization.json',
  748. 'testInProduction': true
  749. },
  750. 'service.start_stop': {
  751. 'real': '/clusters/{clusterName}/services?params/run_smoke_test=true',
  752. 'mock': '/data/mirroring/poll/poll_6.json',
  753. 'format': function (data) {
  754. return {
  755. type: 'PUT',
  756. async: false,
  757. data: data.data
  758. };
  759. }
  760. },
  761. 'service.metrics.yarn.gc': {
  762. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  763. 'mock': '/data/services/metrics/yarn/gc.json',
  764. 'testInProduction': true
  765. },
  766. 'service.metrics.yarn.jobs_threads': {
  767. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/jvm/threadsRunnable[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/threadsBlocked[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/threadsWaiting[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/threadsTimedWaiting[{fromSeconds},{toSeconds},{stepSeconds}]',
  768. 'mock': '/data/services/metrics/yarn/jvm_threads.json',
  769. 'testInProduction': true
  770. },
  771. 'service.metrics.yarn.rpc': {
  772. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  773. 'mock': '/data/services/metrics/yarn/rpc.json',
  774. 'testInProduction': true
  775. },
  776. 'service.metrics.yarn.jobs_heap': {
  777. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/jvm/memNonHeapUsedM[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/memNonHeapCommittedM[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/memHeapUsedM[{fromSeconds},{toSeconds},{stepSeconds}],metrics/jvm/memHeapCommittedM[{fromSeconds},{toSeconds},{stepSeconds}]',
  778. 'mock': '/data/services/metrics/yarn/jvm_heap.json',
  779. 'testInProduction': true
  780. },
  781. 'service.metrics.yarn.queue.allocated': {
  782. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/yarn/Queue/root/AvailableMB[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/root/PendingMB[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/root/AllocatedMB[{fromSeconds},{toSeconds},{stepSeconds}]',
  783. 'mock': '',
  784. 'testInProduction': true
  785. },
  786. 'service.metrics.yarn.queue.allocated.container': {
  787. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/yarn/Queue/root/AllocatedContainers[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/root/ReservedContainers[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/root/PendingContainers[{fromSeconds},{toSeconds},{stepSeconds}]',
  788. 'mock': '',
  789. 'testInProduction': true
  790. },
  791. 'service.metrics.yarn.node.manager.statuses': {
  792. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/yarn/ClusterMetrics/NumActiveNMs[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/ClusterMetrics/NumDecommissionedNMs[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/ClusterMetrics/NumLostNMs[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/ClusterMetrics/NumRebootedNMs[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/ClusterMetrics/NumUnhealthyNMs[{fromSeconds},{toSeconds},{stepSeconds}]',
  793. 'mock': '',
  794. 'testInProduction': true
  795. },
  796. 'service.metrics.yarn.queue.memory.resource': {
  797. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=',
  798. 'mock': '',
  799. 'format': function (data, opt) {
  800. var field1 = 'metrics/yarn/Queue/{queueName}/AllocatedMB[{fromSeconds},{toSeconds},{stepSeconds}]';
  801. var field2 = 'metrics/yarn/Queue/{queueName}/AvailableMB[{fromSeconds},{toSeconds},{stepSeconds}]';
  802. if (opt.url != null && data.queueNames != null && data.queueNames.length > 0) {
  803. data.queueNames.forEach(function (q) {
  804. data.queueName = q;
  805. opt.url += (formatUrl(field1, data) + ",");
  806. opt.url += (formatUrl(field2, data) + ",");
  807. });
  808. } else {
  809. opt.url += (formatUrl(field1, data) + ",");
  810. opt.url += (formatUrl(field2, data) + ",");
  811. }
  812. },
  813. 'testInProduction': true
  814. },
  815. 'service.metrics.yarn.queue.apps.states.current': {
  816. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/yarn/Queue/root/AppsPending[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/root/AppsRunning[{fromSeconds},{toSeconds},{stepSeconds}]',
  817. 'mock': '',
  818. 'testInProduction': true
  819. },
  820. 'service.metrics.yarn.queue.apps.states.finished': {
  821. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/yarn/Queue/root/AppsKilled[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/root/AppsFailed[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/root/AppsSubmitted[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/root/AppsCompleted[{fromSeconds},{toSeconds},{stepSeconds}]',
  822. 'mock': '',
  823. 'testInProduction': true
  824. },
  825. 'service.metrics.storm.nimbus': {
  826. 'real': '/clusters/{clusterName}/services/STORM/components/NIMBUS?fields={metricsTemplate}',
  827. 'mock': ''
  828. },
  829. 'dashboard.cluster_metrics.cpu': {
  830. 'real': '/clusters/{clusterName}/?fields=metrics/cpu[{fromSeconds},{toSeconds},{stepSeconds}]',
  831. 'mock': '/data/cluster_metrics/cpu_1hr.json',
  832. 'testInProduction': true
  833. },
  834. 'dashboard.cluster_metrics.load': {
  835. 'real': '/clusters/{clusterName}/?fields=metrics/load[{fromSeconds},{toSeconds},{stepSeconds}]',
  836. 'mock': '/data/cluster_metrics/load_1hr.json',
  837. 'testInProduction': true
  838. },
  839. 'dashboard.cluster_metrics.memory': {
  840. 'real': '/clusters/{clusterName}/?fields=metrics/memory[{fromSeconds},{toSeconds},{stepSeconds}]',
  841. 'mock': '/data/cluster_metrics/memory_1hr.json',
  842. 'testInProduction': true
  843. },
  844. 'dashboard.cluster_metrics.network': {
  845. 'real': '/clusters/{clusterName}/?fields=metrics/network[{fromSeconds},{toSeconds},{stepSeconds}]',
  846. 'mock': '/data/cluster_metrics/network_1hr.json',
  847. 'testInProduction': true
  848. },
  849. 'host.metrics.cpu': {
  850. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/cpu/cpu_user[{fromSeconds},{toSeconds},{stepSeconds}],metrics/cpu/cpu_wio[{fromSeconds},{toSeconds},{stepSeconds}],metrics/cpu/cpu_nice[{fromSeconds},{toSeconds},{stepSeconds}],metrics/cpu/cpu_aidle[{fromSeconds},{toSeconds},{stepSeconds}],metrics/cpu/cpu_system[{fromSeconds},{toSeconds},{stepSeconds}],metrics/cpu/cpu_idle[{fromSeconds},{toSeconds},{stepSeconds}]',
  851. 'mock': '/data/hosts/metrics/cpu.json',
  852. 'testInProduction': true
  853. },
  854. 'host.metrics.disk': {
  855. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/disk/disk_total[{fromSeconds},{toSeconds},{stepSeconds}],metrics/disk/disk_free[{fromSeconds},{toSeconds},{stepSeconds}]',
  856. 'mock': '/data/hosts/metrics/disk.json',
  857. 'testInProduction': true
  858. },
  859. 'host.metrics.load': {
  860. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/load/load_fifteen[{fromSeconds},{toSeconds},{stepSeconds}],metrics/load/load_one[{fromSeconds},{toSeconds},{stepSeconds}],metrics/load/load_five[{fromSeconds},{toSeconds},{stepSeconds}]',
  861. 'mock': '/data/hosts/metrics/load.json',
  862. 'testInProduction': true
  863. },
  864. 'host.metrics.memory': {
  865. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/memory/swap_free[{fromSeconds},{toSeconds},{stepSeconds}],metrics/memory/mem_shared[{fromSeconds},{toSeconds},{stepSeconds}],metrics/memory/mem_free[{fromSeconds},{toSeconds},{stepSeconds}],metrics/memory/mem_cached[{fromSeconds},{toSeconds},{stepSeconds}],metrics/memory/mem_buffers[{fromSeconds},{toSeconds},{stepSeconds}]',
  866. 'mock': '/data/hosts/metrics/memory.json',
  867. 'testInProduction': true
  868. },
  869. 'host.metrics.network': {
  870. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/network/bytes_in[{fromSeconds},{toSeconds},{stepSeconds}],metrics/network/bytes_out[{fromSeconds},{toSeconds},{stepSeconds}],metrics/network/pkts_in[{fromSeconds},{toSeconds},{stepSeconds}],metrics/network/pkts_out[{fromSeconds},{toSeconds},{stepSeconds}]',
  871. 'mock': '/data/hosts/metrics/network.json',
  872. 'testInProduction': true
  873. },
  874. 'host.metrics.processes': {
  875. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/process/proc_total[{fromSeconds},{toSeconds},{stepSeconds}],metrics/process/proc_run[{fromSeconds},{toSeconds},{stepSeconds}]',
  876. 'mock': '/data/hosts/metrics/processes.json',
  877. 'testInProduction': true
  878. },
  879. 'admin.security_status': {
  880. 'real': '/clusters/{clusterName}?fields=Clusters/desired_configs',
  881. 'mock': '',
  882. 'format': function() {
  883. return {
  884. timeout: 10000
  885. };
  886. }
  887. },
  888. 'settings.get.user_pref': {
  889. 'real': '/persist/{key}',
  890. 'mock': '/data/user_settings/{key}.json',
  891. 'format': function(data) {
  892. return {
  893. async: data.async
  894. };
  895. }
  896. },
  897. 'settings.post.user_pref': {
  898. 'real': '/persist',
  899. 'mock': '',
  900. 'type': 'POST',
  901. 'format': function (data) {
  902. return {
  903. async: data.async,
  904. data: JSON.stringify(data.keyValuePair)
  905. }
  906. }
  907. },
  908. 'cluster.load_cluster_name': {
  909. 'real': '/clusters',
  910. 'mock': '/data/clusters/info.json',
  911. 'format': function() {
  912. return {
  913. async: false
  914. };
  915. }
  916. },
  917. 'cluster.update_upgrade_version': {
  918. 'real': '/stacks/HDP/versions?fields=stackServices/StackServices,Versions',
  919. 'mock': '/data/wizard/stack/stacks.json',
  920. 'format': function() {
  921. return {
  922. async: false
  923. };
  924. }
  925. },
  926. 'cluster.load_repositories': {
  927. 'real': '/stacks/{stackName}/versions/{stackVersion}/operating_systems?fields=repositories/*',
  928. 'mock': '',
  929. 'type': 'GET',
  930. 'format': function (data) {
  931. return {
  932. data: data.data
  933. };
  934. }
  935. },
  936. 'admin.high_availability.stop_all_services': {
  937. 'real': '/clusters/{clusterName}/services',
  938. 'mock': '',
  939. 'format': function() {
  940. return {
  941. type: 'PUT',
  942. data: JSON.stringify({
  943. "RequestInfo": {
  944. "context": "Stop all services"
  945. },
  946. "Body": {
  947. "ServiceInfo": {
  948. "state": "INSTALLED"
  949. }
  950. }
  951. })
  952. }
  953. }
  954. },
  955. 'admin.high_availability.start_all_services': {
  956. 'real': '/clusters/{clusterName}/services',
  957. 'mock': '',
  958. 'format': function() {
  959. return {
  960. type: 'PUT',
  961. data: JSON.stringify({
  962. "RequestInfo": {
  963. "context": "Start all services"
  964. },
  965. "Body": {
  966. "ServiceInfo": {
  967. "state": "STARTED"
  968. }
  969. }
  970. })
  971. }
  972. }
  973. },
  974. 'admin.high_availability.polling': {
  975. 'real': '/clusters/{clusterName}/requests/{requestId}?fields=tasks/*,Requests/*',
  976. 'mock': '',
  977. 'type': 'GET'
  978. },
  979. 'admin.high_availability.getNnCheckPointStatus': {
  980. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/NAMENODE',
  981. 'mock': '',
  982. 'type': 'GET'
  983. },
  984. 'admin.high_availability.getJnCheckPointStatus': {
  985. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/JOURNALNODE?fields=metrics',
  986. 'mock': ''
  987. },
  988. 'admin.high_availability.getHostComponent': {
  989. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  990. 'mock': ''
  991. },
  992. 'admin.high_availability.create_component': {
  993. 'real': '/clusters/{clusterName}/hosts?Hosts/host_name={hostName}',
  994. 'mock': '',
  995. 'type': 'POST',
  996. 'format': function (data) {
  997. return {
  998. data: JSON.stringify({
  999. "host_components": [
  1000. {
  1001. "HostRoles": {
  1002. "component_name": data.componentName
  1003. }
  1004. }
  1005. ]
  1006. })
  1007. }
  1008. }
  1009. },
  1010. 'admin.high_availability.install_component': {
  1011. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  1012. 'mock': '',
  1013. 'type': 'PUT',
  1014. 'format': function (data) {
  1015. return {
  1016. data: JSON.stringify({
  1017. RequestInfo: {
  1018. "context": "Install " + data.displayName
  1019. },
  1020. Body: {
  1021. "HostRoles": {
  1022. "state": "INSTALLED"
  1023. }
  1024. }
  1025. })
  1026. }
  1027. }
  1028. },
  1029. 'admin.high_availability.start_component': {
  1030. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  1031. 'mock': '',
  1032. 'type': 'PUT',
  1033. 'format': function (data) {
  1034. return {
  1035. data: JSON.stringify({
  1036. RequestInfo: {
  1037. "context": "Start " + data.displayName
  1038. },
  1039. Body: {
  1040. "HostRoles": {
  1041. "state": "STARTED"
  1042. }
  1043. }
  1044. })
  1045. }
  1046. }
  1047. },
  1048. 'admin.high_availability.maintenance_mode': {
  1049. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  1050. 'mock': '',
  1051. 'type': 'PUT',
  1052. 'format': function () {
  1053. return {
  1054. data: JSON.stringify({
  1055. "HostRoles": {
  1056. "state": "DISABLED"
  1057. }
  1058. })
  1059. }
  1060. }
  1061. },
  1062. 'admin.high_availability.stop_component': {
  1063. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  1064. 'mock': '',
  1065. 'type': 'PUT',
  1066. 'format': function (data) {
  1067. return {
  1068. data: JSON.stringify({
  1069. RequestInfo: {
  1070. "context": "Stop " + data.displayName
  1071. },
  1072. Body: {
  1073. "HostRoles": {
  1074. "state": "INSTALLED"
  1075. }
  1076. }
  1077. })
  1078. }
  1079. }
  1080. },
  1081. 'admin.high_availability.load_configs': {
  1082. 'real': '/clusters/{clusterName}/configurations?(type=core-site&tag={coreSiteTag})|(type=hdfs-site&tag={hdfsSiteTag})',
  1083. 'mock': '',
  1084. 'type': 'GET'
  1085. },
  1086. 'admin.high_availability.save_configs': {
  1087. 'real': '/clusters/{clusterName}',
  1088. 'mock': '',
  1089. 'type': 'PUT',
  1090. 'format': function (data) {
  1091. return {
  1092. async: false,
  1093. data: JSON.stringify({
  1094. Clusters: {
  1095. desired_config: {
  1096. "type": data.siteName,
  1097. "tag": 'version' + (new Date).getTime(),
  1098. "properties": data.properties
  1099. }
  1100. }
  1101. })
  1102. }
  1103. }
  1104. },
  1105. 'admin.high_availability.load_hbase_configs': {
  1106. 'real': '/clusters/{clusterName}/configurations?type=hbase-site&tag={hbaseSiteTag}',
  1107. 'mock': '',
  1108. 'type': 'GET'
  1109. },
  1110. 'admin.delete_component': {
  1111. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  1112. 'mock': '',
  1113. 'type': 'DELETE'
  1114. },
  1115. 'admin.security.cluster_configs': {
  1116. 'real': '/clusters/{clusterName}',
  1117. 'mock': '',
  1118. 'format': function() {
  1119. return {
  1120. timeout: 10000
  1121. };
  1122. }
  1123. },
  1124. 'admin.delete_host': {
  1125. 'real': '/clusters/{clusterName}/hosts/{hostName}',
  1126. 'mock': '',
  1127. 'type': 'DELETE'
  1128. },
  1129. 'admin.get.all_configurations': {
  1130. 'real': '/clusters/{clusterName}/configurations?{urlParams}',
  1131. 'mock': '',
  1132. 'format': function() {
  1133. return {
  1134. timeout: 10000
  1135. };
  1136. }
  1137. },
  1138. 'admin.security.apply_configurations': {
  1139. 'real': '/clusters/{clusterName}',
  1140. 'mock': '',
  1141. 'format': function (data) {
  1142. return {
  1143. type: 'PUT',
  1144. timeout: 10000,
  1145. data: data.configData
  1146. };
  1147. }
  1148. },
  1149. 'admin.security.apply_configuration': {
  1150. 'real': '/clusters/{clusterName}',
  1151. 'mock': '',
  1152. 'format': function(data) {
  1153. return {
  1154. type: 'PUT',
  1155. async: false,
  1156. timeout: 5000,
  1157. data: JSON.stringify(data.clusterData)
  1158. };
  1159. }
  1160. },
  1161. 'admin.security.add.cluster_configs': {
  1162. 'real': '/clusters/{clusterName}' + '?fields=Clusters/desired_configs',
  1163. 'mock': '',
  1164. 'format': function() {
  1165. return {
  1166. timeout: 10000
  1167. };
  1168. }
  1169. },
  1170. 'admin.stack_upgrade.run_upgrade': {
  1171. 'real': '/clusters/{clusterName}',
  1172. 'mock': '',
  1173. 'format': function (data) {
  1174. return {
  1175. type: 'PUT',
  1176. async: false,
  1177. data: data.data
  1178. };
  1179. }
  1180. },
  1181. 'admin.stack_upgrade.stop_services': {
  1182. 'real': '/clusters/{clusterName}/services?ServiceInfo/state=STARTED',
  1183. 'mock': '',
  1184. 'format': function (data) {
  1185. return {
  1186. type: 'PUT',
  1187. async: false,
  1188. data: data.data
  1189. };
  1190. }
  1191. },
  1192. 'admin.user.create': {
  1193. 'real': '/users/{user}',
  1194. 'mock': '/data/users/users.json',
  1195. 'format': function(data) {
  1196. return {
  1197. type: 'POST',
  1198. data: JSON.stringify(data.data)
  1199. }
  1200. }
  1201. },
  1202. 'admin.user.delete': {
  1203. 'real': '/users/{user}',
  1204. 'mock': '/data/users/users.json',
  1205. 'format': function() {
  1206. return {
  1207. type: 'DELETE'
  1208. }
  1209. }
  1210. },
  1211. 'admin.user.edit': {
  1212. 'real': '/users/{user}',
  1213. 'mock':'/data/users/users.json',
  1214. 'format': function(data) {
  1215. return {
  1216. type: 'PUT',
  1217. data: data.data
  1218. }
  1219. }
  1220. },
  1221. 'admin.stack_upgrade.do_poll': {
  1222. 'real': '/clusters/{cluster}/requests/{requestId}?fields=tasks/*',
  1223. 'mock': '/data/wizard/{mock}'
  1224. },
  1225. 'wizard.advanced_repositories.valid_url': {
  1226. 'real': '/stacks/{stackName}/versions/{stackVersion}/operating_systems/{osType}/repositories/{repoId}',
  1227. 'mock': '',
  1228. 'type': 'PUT',
  1229. 'format': function (data) {
  1230. return {
  1231. data: JSON.stringify(data.data)
  1232. }
  1233. }
  1234. },
  1235. 'wizard.install_services.add_host_controller.is_retry': {
  1236. 'real': '/clusters/{cluster}/host_components',
  1237. 'mock': '',
  1238. 'format': function (data) {
  1239. return {
  1240. type: 'PUT',
  1241. async: false,
  1242. data: data.data
  1243. };
  1244. }
  1245. },
  1246. 'wizard.install_services.add_host_controller.not_is_retry': {
  1247. 'real': '/clusters/{cluster}/host_components',
  1248. 'mock': '',
  1249. 'format': function(data) {
  1250. return {
  1251. type: 'PUT',
  1252. async: false,
  1253. data: data.data
  1254. };
  1255. }
  1256. },
  1257. 'wizard.install_services.installer_controller.is_retry': {
  1258. 'real': '/clusters/{cluster}/host_components?HostRoles/state=INSTALLED',
  1259. 'mock': '/data/wizard/deploy/2_hosts/poll_1.json',
  1260. 'type': 'PUT',
  1261. 'format': function (data) {
  1262. return {
  1263. async: false,
  1264. data: data.data
  1265. };
  1266. }
  1267. },
  1268. 'wizard.install_services.installer_controller.not_is_retry': {
  1269. 'real': '/clusters/{cluster}/services?ServiceInfo/state=INIT',
  1270. 'mock': '/data/wizard/deploy/2_hosts/poll_1.json',
  1271. 'type': 'PUT',
  1272. 'format': function (data) {
  1273. return {
  1274. async: false,
  1275. data: data.data
  1276. };
  1277. }
  1278. },
  1279. 'wizard.install_services.add_service_controller.get_failed_host_components': {
  1280. 'real': '/clusters/{clusterName}/host_components?fields=HostRoles/state,component/ServiceComponentInfo/service_name',
  1281. 'mock': '',
  1282. 'format': function() {
  1283. return {
  1284. async: false
  1285. };
  1286. }
  1287. },
  1288. 'wizard.service_components': {
  1289. 'real': '{stackUrl}/services?fields=StackServices/comments,StackServices/service_version,serviceComponents/*',
  1290. 'mock': '/data/stacks/HDP-2.1/service_components.json',
  1291. 'format': function(data) {
  1292. return {
  1293. timeout: 10000,
  1294. async: !!data.async
  1295. };
  1296. }
  1297. },
  1298. 'wizard.step9.installer.get_host_status': {
  1299. 'real': '/clusters/{cluster}/hosts?fields=Hosts/host_state,host_components/HostRoles/state',
  1300. 'mock': '/data/wizard/deploy/5_hosts/get_host_state.json',
  1301. 'format': function () {
  1302. return {
  1303. async: false
  1304. };
  1305. }
  1306. },
  1307. 'wizard.step9.installer.launch_start_services': {
  1308. 'real': '/clusters/{cluster}/services?ServiceInfo/state=INSTALLED&params/run_smoke_test=true&params/reconfigure_client=false',
  1309. 'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
  1310. 'format': function (data) {
  1311. var d = {
  1312. type: 'PUT',
  1313. async: false,
  1314. data: data.data
  1315. };
  1316. if (App.testMode) {
  1317. d.type = 'GET';
  1318. }
  1319. return d;
  1320. }
  1321. },
  1322. 'wizard.step9.add_service.launch_start_services': {
  1323. 'real': '/clusters/{cluster}/services?ServiceInfo/state=INSTALLED&ServiceInfo/service_name.in({servicesList})&params/reconfigure_client=false',
  1324. 'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
  1325. 'format': function (data) {
  1326. var d = {
  1327. type: 'PUT',
  1328. async: false,
  1329. data: data.data
  1330. };
  1331. if (App.testMode) {
  1332. d.type = 'GET';
  1333. }
  1334. return d;
  1335. }
  1336. },
  1337. 'wizard.step9.add_host.launch_start_services': {
  1338. 'real': '/clusters/{cluster}/host_components',
  1339. 'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
  1340. 'format': function (data) {
  1341. return {
  1342. type: 'PUT',
  1343. async: false,
  1344. data: data.data
  1345. };
  1346. }
  1347. },
  1348. 'wizard.step9.load_log': {
  1349. 'real': '/clusters/{cluster}/requests/{requestId}?fields=tasks/Tasks/command,tasks/Tasks/exit_code,tasks/Tasks/start_time,tasks/Tasks/end_time,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status&minimal_response=true',
  1350. 'mock': '/data/wizard/deploy/5_hosts/poll_{numPolls}.json',
  1351. 'format': function () {
  1352. return {
  1353. type: 'GET',
  1354. dataType: 'text'
  1355. };
  1356. }
  1357. },
  1358. 'wizard.step8.delete_cluster': {
  1359. 'real': '/clusters/{name}',
  1360. 'mock': '',
  1361. 'format': function() {
  1362. return {
  1363. type: 'DELETE',
  1364. async: false
  1365. };
  1366. }
  1367. },
  1368. 'wizard.step8.existing_cluster_names': {
  1369. 'real': '/clusters',
  1370. 'mock': '',
  1371. 'format': function() {
  1372. return {
  1373. async: false
  1374. };
  1375. }
  1376. },
  1377. 'wizard.step8.create_cluster': {
  1378. 'real':'/clusters/{cluster}',
  1379. 'mock':'',
  1380. 'format': function(data) {
  1381. return {
  1382. type: 'POST',
  1383. dataType: 'text',
  1384. data: data.data
  1385. }
  1386. }
  1387. },
  1388. 'wizard.step8.create_selected_services': {
  1389. 'real':'/clusters/{cluster}/services',
  1390. 'mock':'',
  1391. 'format': function(data) {
  1392. return {
  1393. type: 'POST',
  1394. dataType: 'text',
  1395. data: data.data
  1396. }
  1397. }
  1398. },
  1399. 'wizard.step8.create_components': {
  1400. 'real':'/clusters/{cluster}/services?ServiceInfo/service_name={serviceName}',
  1401. 'mock':'',
  1402. 'format': function(data) {
  1403. return {
  1404. type: 'POST',
  1405. dataType: 'text',
  1406. data: data.data
  1407. }
  1408. }
  1409. },
  1410. 'wizard.step8.register_host_to_cluster': {
  1411. 'real':'/clusters/{cluster}/hosts',
  1412. 'mock':'',
  1413. 'format': function(data) {
  1414. return {
  1415. type: 'POST',
  1416. dataType: 'text',
  1417. data: data.data
  1418. }
  1419. }
  1420. },
  1421. 'wizard.step8.register_host_to_component': {
  1422. 'real':'/clusters/{cluster}/hosts',
  1423. 'mock':'',
  1424. 'format': function(data) {
  1425. return {
  1426. type: 'POST',
  1427. dataType: 'text',
  1428. data: data.data
  1429. }
  1430. }
  1431. },
  1432. 'wizard.step8.apply_configuration_to_cluster': {
  1433. 'real':'/clusters/{cluster}',
  1434. 'mock':'',
  1435. 'format': function(data) {
  1436. return {
  1437. type: 'PUT',
  1438. dataType: 'text',
  1439. data: data.data
  1440. }
  1441. }
  1442. },
  1443. 'wizard.step8.apply_configuration_groups': {
  1444. 'real':'/clusters/{cluster}/config_groups',
  1445. 'mock':'',
  1446. 'format': function(data) {
  1447. return {
  1448. type: 'POST',
  1449. dataType: 'text',
  1450. data: data.data
  1451. }
  1452. }
  1453. },
  1454. 'wizard.step8.set_local_repos': {
  1455. 'real':'{stackVersionURL}/operating_systems/{osType}/repositories/{repoId}',
  1456. 'mock':'',
  1457. 'format': function(data) {
  1458. return {
  1459. type: 'PUT',
  1460. dataType: 'text',
  1461. data: data.data
  1462. }
  1463. }
  1464. },
  1465. 'wizard.step3.jdk_check': {
  1466. 'real': '/requests',
  1467. 'mock': '',
  1468. 'format': function (data) {
  1469. return {
  1470. type: 'POST',
  1471. data: JSON.stringify({
  1472. "RequestInfo": {
  1473. "context": "Check hosts",
  1474. "action": "check_host",
  1475. "parameters" : {
  1476. "threshold" : "60",
  1477. "java_home" : data.java_home,
  1478. "jdk_location": data.jdk_location,
  1479. "check_execute_list" : "java_home_check"
  1480. }
  1481. },
  1482. "Requests/resource_filters": [{
  1483. "hosts": data.host_names
  1484. }]
  1485. })
  1486. }
  1487. }
  1488. },
  1489. 'wizard.step3.jdk_check.get_results': {
  1490. 'real': '/requests/{requestIndex}?fields=*,tasks/Tasks/host_name,tasks/Tasks/status,tasks/Tasks/structured_out',
  1491. 'mock': '/data/requests/host_check/jdk_check_results.json'
  1492. },
  1493. 'wizard.step3.host_info': {
  1494. 'real': '/hosts?fields=Hosts/total_mem,Hosts/cpu_count,Hosts/disk_info,Hosts/last_agent_env,Hosts/host_name,Hosts/os_type,Hosts/os_arch,Hosts/ip',
  1495. 'mock': '/data/wizard/bootstrap/two_hosts_information.json',
  1496. 'format': function() {
  1497. return {
  1498. contentType: 'application/json'
  1499. };
  1500. }
  1501. },
  1502. 'preinstalled.checks': {
  1503. 'real':'/requests',
  1504. 'mock':'',
  1505. 'format': function(data) {
  1506. return {
  1507. type : 'POST',
  1508. data : JSON.stringify({
  1509. "RequestInfo": data.RequestInfo,
  1510. "Requests/resource_filters": [data.resource_filters]
  1511. })
  1512. }
  1513. }
  1514. },
  1515. 'preinstalled.checks.tasks': {
  1516. 'real':'/requests/{requestId}?fields=tasks/Tasks',
  1517. 'mock':'/data/requests/host_check/1.json'
  1518. },
  1519. 'wizard.step3.rerun_checks': {
  1520. 'real': '/hosts?fields=Hosts/last_agent_env',
  1521. 'mock': '/data/wizard/bootstrap/two_hosts_information.json',
  1522. 'format': function() {
  1523. return {
  1524. contentType: 'application/json'
  1525. };
  1526. }
  1527. },
  1528. 'wizard.step3.bootstrap': {
  1529. 'real': '/bootstrap/{bootRequestId}',
  1530. 'mock': '/data/wizard/bootstrap/poll_{numPolls}.json'
  1531. },
  1532. 'wizard.step3.is_hosts_registered': {
  1533. 'real': '/hosts',
  1534. 'mock': '/data/wizard/bootstrap/single_host_registration.json'
  1535. },
  1536. 'wizard.stacks': {
  1537. 'real': '/stacks',
  1538. 'mock': '/data/wizard/stack/stacks2.json',
  1539. 'format': function() {
  1540. return {
  1541. async: false
  1542. };
  1543. }
  1544. },
  1545. 'wizard.stacks_versions': {
  1546. 'real': '/stacks/{stackName}/versions?fields=Versions,operatingSystems/repositories/Repositories',
  1547. 'mock': '/data/wizard/stack/{stackName}_versions.json',
  1548. 'format': function() {
  1549. return {
  1550. async: false
  1551. };
  1552. }
  1553. },
  1554. 'wizard.launch_bootstrap': {
  1555. 'real': '/bootstrap',
  1556. 'mock': '/data/wizard/bootstrap/bootstrap.json',
  1557. 'type': 'POST',
  1558. 'format': function (data) {
  1559. return {
  1560. contentType: 'application/json',
  1561. data: data.bootStrapData,
  1562. popup: data.popup
  1563. }
  1564. }
  1565. },
  1566. 'router.login': {
  1567. 'real': '/users/{loginName}',
  1568. 'mock': '/data/users/user_{usr}.json',
  1569. 'format': function (data) {
  1570. var statusCode = jQuery.extend({}, require('data/statusCodes'));
  1571. statusCode['403'] = function () {
  1572. console.log("Error code 403: Forbidden.");
  1573. };
  1574. return {
  1575. statusCode: statusCode
  1576. };
  1577. }
  1578. },
  1579. 'router.login2': {
  1580. 'real': '/clusters',
  1581. 'mock': '/data/clusters/info.json'
  1582. },
  1583. 'router.logoff': {
  1584. 'real': '/logout',
  1585. 'mock': ''
  1586. },
  1587. 'router.set_ambari_stacks': {
  1588. 'real': '/stacks',
  1589. 'mock': '/data/wizard/stack/stacks.json',
  1590. 'format': function() {
  1591. return {
  1592. async: false
  1593. };
  1594. }
  1595. },
  1596. 'router.authentication': {
  1597. 'real': '/clusters',
  1598. 'mock': '/data/clusters/info.json',
  1599. 'format': function() {
  1600. return {
  1601. async: false
  1602. };
  1603. }
  1604. },
  1605. 'ambari.service.load_jdk_name': {
  1606. 'real': '/services/AMBARI/components/AMBARI_SERVER?fields=RootServiceComponents/properties/jdk.name,RootServiceComponents/properties/java.home,RootServiceComponents/properties/jdk_location',
  1607. 'mock': '/data/requests/host_check/jdk_name.json'
  1608. },
  1609. 'ambari.service.load_server_version': {
  1610. 'real': '/services/AMBARI/components/AMBARI_SERVER?fields=RootServiceComponents/component_version',
  1611. 'mock': ''
  1612. },
  1613. 'ambari.service': {
  1614. 'real': '/services/AMBARI/components/AMBARI_SERVER',
  1615. 'mock': '/data/services/ambari_server.json'
  1616. },
  1617. 'ambari.service.load_server_clock': {
  1618. 'real': '/services/AMBARI/components/AMBARI_SERVER?fields=RootServiceComponents/server_clock',
  1619. 'mock': ''
  1620. },
  1621. 'config_groups.create': {
  1622. 'real': '/clusters/{clusterName}/config_groups',
  1623. 'mock': '',
  1624. 'format': function (data) {
  1625. return {
  1626. type: 'POST',
  1627. data: JSON.stringify([{
  1628. "ConfigGroup": {
  1629. "group_name": data.group_name,
  1630. "tag": data.service_id,
  1631. "description": data.description,
  1632. "desired_configs": data.desired_configs,
  1633. "hosts": data.hosts
  1634. }
  1635. }])
  1636. }
  1637. }
  1638. },
  1639. 'config_groups.update': {
  1640. 'real': '/clusters/{clusterName}/config_groups/{id}',
  1641. 'mock': '',
  1642. 'format': function (data) {
  1643. return {
  1644. type: 'PUT',
  1645. data: JSON.stringify(data.data)
  1646. }
  1647. }
  1648. },
  1649. 'rolling_restart.post': {
  1650. 'real': '/clusters/{clusterName}/request_schedules',
  1651. 'mock': '',
  1652. 'format' : function(data) {
  1653. return {
  1654. type : 'POST',
  1655. data : JSON.stringify([ {
  1656. "RequestSchedule" : {
  1657. "batch" : [ {
  1658. "requests" : data.batches
  1659. }, {
  1660. "batch_settings" : {
  1661. "batch_separation_in_seconds" : data.intervalTimeSeconds,
  1662. "task_failure_tolerance" : data.tolerateSize
  1663. }
  1664. } ]
  1665. }
  1666. } ])
  1667. }
  1668. }
  1669. },
  1670. 'request_schedule.delete': {
  1671. 'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
  1672. 'mock': '',
  1673. 'format' : function() {
  1674. return {
  1675. type : 'DELETE'
  1676. }
  1677. }
  1678. },
  1679. 'request_schedule.get': {
  1680. 'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
  1681. 'mock': ''
  1682. },
  1683. 'restart.hostComponents': {
  1684. 'real':'/clusters/{clusterName}/requests',
  1685. 'mock':'',
  1686. 'format': function(data) {
  1687. return {
  1688. type : 'POST',
  1689. data : JSON.stringify({
  1690. "RequestInfo": {
  1691. "command": "RESTART",
  1692. "context": data.context,
  1693. "operation_level": data.operation_level
  1694. },
  1695. "Requests/resource_filters": data.resource_filters
  1696. })
  1697. }
  1698. }
  1699. },
  1700. 'mirroring.get_all_entities': {
  1701. 'real': '/proxy?url=http://{falconServer}:15000/api/entities/list/{type}?fields=status&user.name=ambari-qa',
  1702. 'mock': '/data/mirroring/{type}s.xml',
  1703. 'apiPrefix': '',
  1704. 'format': function () {
  1705. return {
  1706. dataType: 'xml'
  1707. }
  1708. }
  1709. },
  1710. 'mirroring.get_definition': {
  1711. 'real': '/proxy?url=http://{falconServer}:15000/api/entities/definition/{type}/{name}?user.name=ambari-qa',
  1712. 'mock': '/data/mirroring/{name}_definition.xml',
  1713. 'apiPrefix': '',
  1714. 'format': function () {
  1715. return {
  1716. cache: true,
  1717. dataType: 'xml'
  1718. }
  1719. }
  1720. },
  1721. 'mirroring.dataset.get_all_instances': {
  1722. 'real': '/proxy?url=http://{falconServer}:15000/api/instance/status/feed/{dataset}?start={start}&end={end}&user.name=ambari-qa',
  1723. 'mock': '/data/mirroring/{dataset}_instances.json',
  1724. 'apiPrefix': ''
  1725. },
  1726. 'mirroring.create_new_dataset': {
  1727. 'real': '/proxy?url=http://{falconServer}:15000/api/entities/submitAndSchedule/feed?user.name=ambari-qa',
  1728. 'mock': '/data/mirroring/succeeded.json',
  1729. 'apiPrefix': '',
  1730. 'type': 'POST',
  1731. 'format': function (data) {
  1732. return {
  1733. contentType: 'text/xml',
  1734. dataType: 'xml',
  1735. data: data.entity,
  1736. headers: {
  1737. 'AmbariProxy-Content-Type': 'text/xml'
  1738. }
  1739. }
  1740. }
  1741. },
  1742. 'mirroring.submit_entity': {
  1743. 'real': '/proxy?url=http://{falconServer}:15000/api/entities/submit/{type}?user.name=ambari-qa',
  1744. 'mock': '/data/mirroring/succeeded.json',
  1745. 'apiPrefix': '',
  1746. 'type': 'POST',
  1747. 'format': function (data) {
  1748. return {
  1749. contentType: 'text/xml',
  1750. dataType: 'xml',
  1751. data: data.entity,
  1752. headers: {
  1753. 'AmbariProxy-Content-Type': 'text/xml'
  1754. }
  1755. }
  1756. }
  1757. },
  1758. 'mirroring.update_entity': {
  1759. 'real': '/proxy?url=http://{falconServer}:15000/api/entities/update/{type}/{name}?user.name=ambari-qa',
  1760. 'mock': '/data/mirroring/succeeded.json',
  1761. 'apiPrefix': '',
  1762. 'type': 'POST',
  1763. 'format': function (data) {
  1764. return {
  1765. contentType: 'text/xml',
  1766. dataType: 'xml',
  1767. data: data.entity,
  1768. headers: {
  1769. 'AmbariProxy-Content-Type': 'text/xml'
  1770. }
  1771. }
  1772. }
  1773. },
  1774. 'mirroring.delete_entity': {
  1775. 'real': '/proxy?url=http://{falconServer}:15000/api/entities/delete/{type}/{name}?user.name=ambari-qa',
  1776. 'mock': '/data/mirroring/succeeded.json',
  1777. 'apiPrefix': '',
  1778. 'type': 'DELETE',
  1779. 'format': function () {
  1780. return {
  1781. dataType: 'xml'
  1782. }
  1783. }
  1784. },
  1785. 'mirroring.suspend_entity': {
  1786. 'real': '/proxy?url=http://{falconServer}:15000/api/entities/suspend/{type}/{name}?user.name=ambari-qa',
  1787. 'mock': '/data/mirroring/succeeded.json',
  1788. 'apiPrefix': '',
  1789. 'type': 'POST',
  1790. 'format': function (data) {
  1791. return {
  1792. dataType: 'xml',
  1793. data: data.entity
  1794. }
  1795. }
  1796. },
  1797. 'mirroring.resume_entity': {
  1798. 'real': '/proxy?url=http://{falconServer}:15000/api/entities/resume/{type}/{name}?user.name=ambari-qa',
  1799. 'mock': '/data/mirroring/succeeded.json',
  1800. 'apiPrefix': '',
  1801. 'type': 'POST',
  1802. 'format': function () {
  1803. return {
  1804. dataType: 'xml'
  1805. }
  1806. }
  1807. },
  1808. 'mirroring.schedule_entity': {
  1809. 'real': '/proxy?url=http://{falconServer}:15000/api/entities/schedule/{type}/{name}?user.name=ambari-qa',
  1810. 'mock': '/data/mirroring/succeeded.json',
  1811. 'apiPrefix': '',
  1812. 'type': 'POST',
  1813. 'format': function () {
  1814. return {
  1815. dataType: 'xml'
  1816. }
  1817. }
  1818. },
  1819. 'mirroring.suspend_instance': {
  1820. 'real': '/proxy?url=http://{falconServer}:15000/api/instance/suspend/feed/{feed}?start={name}&user.name=ambari-qa',
  1821. 'mock': '/data/mirroring/succeeded.json',
  1822. 'apiPrefix': '',
  1823. 'type': 'POST'
  1824. },
  1825. 'mirroring.resume_instance': {
  1826. 'real': '/proxy?url=http://{falconServer}:15000/api/instance/resume/feed/{feed}?start={name}&user.name=ambari-qa',
  1827. 'mock': '/data/mirroring/succeeded.json',
  1828. 'apiPrefix': '',
  1829. 'type': 'POST'
  1830. },
  1831. 'mirroring.kill_instance': {
  1832. 'real': '/proxy?url=http://{falconServer}:15000/api/instance/kill/feed/{feed}?start={name}&user.name=ambari-qa',
  1833. 'mock': '/data/mirroring/succeeded.json',
  1834. 'apiPrefix': '',
  1835. 'type': 'POST'
  1836. },
  1837. 'bulk_request.host_components': {
  1838. 'real': '/clusters/{clusterName}/host_components',
  1839. 'mock': '',
  1840. 'format': function(data) {
  1841. return {
  1842. type: 'PUT',
  1843. data: JSON.stringify({
  1844. RequestInfo: {
  1845. context: data.requestInfo,
  1846. query: 'HostRoles/component_name=' + data.componentName + '&HostRoles/host_name.in(' + data.hostNames + ')&HostRoles/maintenance_state=OFF'
  1847. },
  1848. Body: {
  1849. HostRoles: {
  1850. state: data.state
  1851. }
  1852. }
  1853. })
  1854. }
  1855. }
  1856. },
  1857. 'bulk_request.hosts.all_components': {
  1858. 'real': '/clusters/{clusterName}/host_components',
  1859. 'mock': '',
  1860. 'format': function(data) {
  1861. return {
  1862. type: 'PUT',
  1863. data: JSON.stringify({
  1864. RequestInfo: {
  1865. context: data.requestInfo,
  1866. query: data.query,
  1867. operation_level: {
  1868. level: "HOST",
  1869. cluster_name: data.clusterName,
  1870. host_name: data.hostName
  1871. }
  1872. },
  1873. Body: {
  1874. HostRoles: {
  1875. state: data.state
  1876. }
  1877. }
  1878. })
  1879. }
  1880. }
  1881. },
  1882. 'bulk_request.decommission': {
  1883. 'real' : '/clusters/{clusterName}/requests',
  1884. 'mock' : '',
  1885. 'format': function(data) {
  1886. return {
  1887. type: 'POST',
  1888. data: JSON.stringify({
  1889. 'RequestInfo': {
  1890. 'context': data.context,
  1891. 'command': 'DECOMMISSION',
  1892. 'parameters': data.parameters
  1893. },
  1894. "Requests/resource_filters": [{"service_name" : data.serviceName, "component_name" : data.componentName}]
  1895. })
  1896. }
  1897. }
  1898. },
  1899. 'bulk_request.hosts.passive_state': {
  1900. 'real': '/clusters/{clusterName}/hosts',
  1901. 'mock': '',
  1902. 'format': function(data) {
  1903. return {
  1904. type: 'PUT',
  1905. data: JSON.stringify({
  1906. RequestInfo: {
  1907. context: data.requestInfo,
  1908. query: 'Hosts/host_name.in(' + data.hostNames + ')'
  1909. },
  1910. Body: {
  1911. Hosts: {
  1912. maintenance_state: data.passive_state
  1913. }
  1914. }
  1915. })
  1916. }
  1917. }
  1918. },
  1919. 'bulk_request.hosts.all_components.passive_state': {
  1920. 'real': '/clusters/{clusterName}/host_components',
  1921. 'mock': '',
  1922. 'format': function(data) {
  1923. return {
  1924. type: 'PUT',
  1925. data: JSON.stringify({
  1926. RequestInfo: {
  1927. context: data.requestInfo,
  1928. query: data.query
  1929. },
  1930. Body: {
  1931. HostRoles: {
  1932. maintenance_state: data.passive_state
  1933. }
  1934. }
  1935. })
  1936. }
  1937. }
  1938. },
  1939. 'jobs.lastID': {
  1940. 'real': '/proxy?url=http://{historyServerHostName}:{ahsWebPort}/ws/v1/timeline/HIVE_QUERY_ID?limit=1&secondaryFilter=tez:true',
  1941. 'mock': 'data/jobs/hive-queries.json',
  1942. 'apiPrefix': ''
  1943. },
  1944. 'jobs.tezDag.NametoID': {
  1945. 'real': '/proxy?url=http://{historyServerHostName}:{ahsWebPort}/ws/v1/timeline/TEZ_DAG_ID?primaryFilter=dagName:{tezDagName}',
  1946. 'mock': '/data/jobs/tezDag-name-to-id.json',
  1947. 'apiPrefix': ''
  1948. },
  1949. 'jobs.tezDag.tezDagId': {
  1950. 'real': '/proxy?url=http://{historyServerHostName}:{ahsWebPort}/ws/v1/timeline/TEZ_DAG_ID/{tezDagId}?fields=relatedentities,otherinfo',
  1951. 'mock': '/data/jobs/tezDag.json',
  1952. 'apiPrefix': ''
  1953. },
  1954. 'jobs.tezDag.tezDagVertexId': {
  1955. 'real': '/proxy?url=http://{historyServerHostName}:{ahsWebPort}/ws/v1/timeline/TEZ_VERTEX_ID/{tezDagVertexId}?fields=otherinfo',
  1956. 'mock': '/data/jobs/tezDagVertex.json',
  1957. 'apiPrefix': ''
  1958. },
  1959. 'views.info': {
  1960. 'real': '/views',
  1961. 'mock':''
  1962. },
  1963. /**
  1964. * Get all instances of all views across versions
  1965. */
  1966. 'views.instances': {
  1967. 'real': '/views?fields=versions/instances/ViewInstanceInfo,versions/ViewVersionInfo/label',
  1968. 'mock':''
  1969. },
  1970. 'host.host_component.flume.metrics': {
  1971. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/FLUME_HANDLER?fields=metrics/flume/flume/{flumeComponent}/*',
  1972. 'mock': '',
  1973. 'format': function(data) {
  1974. return {
  1975. async: data.async
  1976. }
  1977. }
  1978. },
  1979. 'host.host_component.flume.metrics.timeseries': {
  1980. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/FLUME_HANDLER?fields=metrics/flume/flume/{flumeComponent}/*/{flumeComponentMetric}[{fromSeconds},{toSeconds},{stepSeconds}]',
  1981. 'mock': ''
  1982. },
  1983. 'host.host_components.filtered': {
  1984. 'real': '/clusters/{clusterName}/hosts',
  1985. 'mock': '',
  1986. format: function(data, opt) {
  1987. return {
  1988. url: opt.url + data.urlParams
  1989. }
  1990. }
  1991. },
  1992. 'host.status.counters': {
  1993. 'real': '/clusters/{clusterName}?fields=alerts,Clusters/health_report,Clusters/total_hosts&minimal_response=true',
  1994. 'mock': '/data/hosts/HDP2/host_status_counters.json'
  1995. },
  1996. 'components.filter_by_status': {
  1997. 'real': '/clusters/{clusterName}/components?fields=host_components/HostRoles/host_name,ServiceComponentInfo/component_name,ServiceComponentInfo/started_count{urlParams}&minimal_response=true',
  1998. 'mock': ''
  1999. },
  2000. 'hosts.all.install': {
  2001. 'real': '/hosts?minimal_response=true',
  2002. 'mock': ''
  2003. },
  2004. 'hosts.all': {
  2005. 'real': '/clusters/{clusterName}/hosts?minimal_response=true',
  2006. 'mock': ''
  2007. },
  2008. 'hosts.with_public_host_names': {
  2009. 'real': '/clusters/{clusterName}/hosts?fields=Hosts/public_host_name&minimal_response=true',
  2010. 'mock': ''
  2011. },
  2012. 'hosts.for_quick_links': {
  2013. 'real': '/clusters/{clusterName}/hosts?host_components/HostRoles/component_name.in({masterComponents})&fields=Hosts/public_host_name,host_components/HostRoles/component_name{urlParams}&minimal_response=true',
  2014. 'mock': ''
  2015. },
  2016. 'hosts.confirmed.install': {
  2017. 'real': '/hosts?fields=Hosts/cpu_count,Hosts/disk_info,Hosts/total_mem&minimal_response=true',
  2018. 'mock': ''
  2019. },
  2020. 'hosts.confirmed': {
  2021. 'real': '/clusters/{clusterName}/hosts?fields=Hosts/cpu_count,Hosts/disk_info,Hosts/total_mem,host_components/HostRoles/state&minimal_response=true',
  2022. 'mock': ''
  2023. },
  2024. 'host_components.all': {
  2025. 'real': '/clusters/{clusterName}/host_components?fields=HostRoles/host_name&minimal_response=true',
  2026. 'mock': ''
  2027. },
  2028. 'host_components.with_services_names': {
  2029. 'real': '/clusters/{clusterName}/host_components?fields=component/ServiceComponentInfo/service_name,HostRoles/host_name&minimal_response=true',
  2030. 'mock': ''
  2031. },
  2032. 'components.get_installed': {
  2033. 'real': '/clusters/{clusterName}/components',
  2034. 'mock': ''
  2035. },
  2036. 'hosts.heatmaps': {
  2037. 'real': '/clusters/{clusterName}/hosts?fields=Hosts/host_name,Hosts/public_host_name,Hosts/os_type,Hosts/ip,host_components,metrics/disk,metrics/cpu/cpu_system,metrics/cpu/cpu_user,metrics/memory/mem_total,metrics/memory/mem_free&minimal_response=true',
  2038. 'mock': ''
  2039. },
  2040. 'custom_action.create': {
  2041. 'real': '/requests',
  2042. 'mock': '',
  2043. 'format': function(data) {
  2044. var requestInfo = {
  2045. context: 'Check host',
  2046. action: 'check_host',
  2047. parameters: { }
  2048. };
  2049. $.extend(true, requestInfo, data.requestInfo)
  2050. return {
  2051. type: 'POST',
  2052. data: JSON.stringify({
  2053. 'RequestInfo': requestInfo,
  2054. 'Requests/resource_filters': [{
  2055. hosts: data.filteredHosts.join(',')
  2056. }]
  2057. })
  2058. }
  2059. }
  2060. },
  2061. 'custom_action.request': {
  2062. 'real': '/requests/{requestId}/tasks/{taskId}',
  2063. 'mock': '',
  2064. 'format': function(data) {
  2065. return {
  2066. requestId: data.requestId,
  2067. taskId: data.taskId || ''
  2068. }
  2069. }
  2070. },
  2071. 'hosts.total_count': {
  2072. 'real': '/clusters/{clusterName}?fields=Clusters/total_hosts&minimal_response=true',
  2073. 'mock': '',
  2074. 'format': function() {
  2075. return {
  2076. async: false
  2077. }
  2078. }
  2079. },
  2080. 'hosts.high_availability.wizard': {
  2081. 'real': '/clusters/{clusterName}/hosts?fields=Hosts/cpu_count,Hosts/disk_info,Hosts/total_mem&minimal_response=true',
  2082. 'mock': ''
  2083. },
  2084. 'hosts.security.wizard': {
  2085. 'real': '/clusters/{clusterName}/hosts?fields=host_components/HostRoles/service_name&minimal_response=true',
  2086. 'mock': ''
  2087. },
  2088. 'host_component.installed.on_hosts': {
  2089. 'real': '/clusters/{clusterName}/host_components?HostRoles/component_name={componentName}&HostRoles/host_name.in({hostNames})&fields=HostRoles/host_name&minimal_response=true',
  2090. 'mock': '',
  2091. 'format': function() {
  2092. return {
  2093. async: false
  2094. }
  2095. }
  2096. },
  2097. 'hosts.config_groups': {
  2098. 'real': '/clusters/{clusterName}/hosts?fields=Hosts/cpu_count,Hosts/disk_info,Hosts/total_mem,Hosts/ip,Hosts/os_type,Hosts/os_arch,Hosts/public_host_name,host_components&minimal_response=true',
  2099. 'mock': ''
  2100. },
  2101. 'cluster.fields': {
  2102. real: '/clusters/{clusterName}?fields={fields}',
  2103. mock: '',
  2104. format: function(data) {
  2105. return {
  2106. async: true,
  2107. fields: data.fields.join(',')
  2108. }
  2109. }
  2110. }
  2111. };
  2112. /**
  2113. * Replace data-placeholders to its values
  2114. *
  2115. * @param {String} url
  2116. * @param {Object} data
  2117. * @return {String}
  2118. */
  2119. var formatUrl = function (url, data) {
  2120. if (!url) return null;
  2121. var keys = url.match(/\{\w+\}/g);
  2122. keys = (keys === null) ? [] : keys;
  2123. if (keys) {
  2124. keys.forEach(function (key) {
  2125. var raw_key = key.substr(1, key.length - 2);
  2126. var replace;
  2127. if (!data || !data[raw_key]) {
  2128. replace = '';
  2129. }
  2130. else {
  2131. replace = data[raw_key];
  2132. }
  2133. url = url.replace(new RegExp(key, 'g'), replace);
  2134. });
  2135. }
  2136. return url;
  2137. };
  2138. /**
  2139. * this = object from config
  2140. * @return {Object}
  2141. */
  2142. var formatRequest = function (data) {
  2143. var opt = {
  2144. type: this.type || 'GET',
  2145. timeout: App.timeout,
  2146. dataType: 'json',
  2147. statusCode: require('data/statusCodes')
  2148. };
  2149. if (App.testMode) {
  2150. opt.url = formatUrl(this.mock ? this.mock : '', data);
  2151. opt.type = 'GET';
  2152. }
  2153. else {
  2154. var prefix = this.apiPrefix != null ? this.apiPrefix : App.apiPrefix;
  2155. opt.url = prefix + formatUrl(this.real, data);
  2156. }
  2157. if (this.format) {
  2158. jQuery.extend(opt, this.format(data, opt));
  2159. }
  2160. return opt;
  2161. };
  2162. /**
  2163. * Wrapper for all ajax requests
  2164. *
  2165. * @type {Object}
  2166. */
  2167. var ajax = Em.Object.extend({
  2168. /**
  2169. * Send ajax request
  2170. *
  2171. * @param {Object} config
  2172. * @return {$.ajax} jquery ajax object
  2173. *
  2174. * config fields:
  2175. * name - url-key in the urls-object *required*
  2176. * sender - object that send request (need for proper callback initialization) *required*
  2177. * data - object with data for url-format
  2178. * beforeSend - method-name for ajax beforeSend response callback
  2179. * success - method-name for ajax success response callback
  2180. * error - method-name for ajax error response callback
  2181. * callback - callback from <code>App.updater.run</code> library
  2182. */
  2183. send: function (config) {
  2184. console.warn('============== ajax ==============', config.name, config.data);
  2185. if (!config.sender) {
  2186. console.warn('Ajax sender should be defined!');
  2187. return null;
  2188. }
  2189. // default parameters
  2190. var params = {
  2191. clusterName: App.get('clusterName')
  2192. };
  2193. // extend default parameters with provided
  2194. if (config.data) {
  2195. jQuery.extend(params, config.data);
  2196. }
  2197. var opt = {};
  2198. if (!urls[config.name]) {
  2199. console.warn('Invalid name provided!');
  2200. return null;
  2201. }
  2202. opt = formatRequest.call(urls[config.name], params);
  2203. opt.context = this;
  2204. // object sender should be provided for processing beforeSend, success and error responses
  2205. opt.beforeSend = function (xhr) {
  2206. if (config.beforeSend) {
  2207. config.sender[config.beforeSend](opt, xhr, params);
  2208. }
  2209. };
  2210. opt.success = function (data) {
  2211. console.log("TRACE: The url is: " + opt.url);
  2212. if (config.success) {
  2213. config.sender[config.success](data, opt, params);
  2214. }
  2215. };
  2216. opt.error = function (request, ajaxOptions, error) {
  2217. if (config.error) {
  2218. config.sender[config.error](request, ajaxOptions, error, opt, params);
  2219. } else {
  2220. this.defaultErrorHandler(request, opt.url, opt.type);
  2221. }
  2222. };
  2223. opt.complete = function () {
  2224. if (config.callback) {
  2225. config.callback();
  2226. }
  2227. };
  2228. if ($.mocho) {
  2229. opt.url = 'http://' + $.hostName + opt.url;
  2230. }
  2231. return $.ajax(opt);
  2232. },
  2233. // A single instance of App.ModalPopup view
  2234. modalPopup: null,
  2235. /**
  2236. * defaultErrorHandler function is referred from App.ajax.send function and App.HttpClient.defaultErrorHandler function
  2237. * @jqXHR {jqXHR Object}
  2238. * @url {string}
  2239. * @method {String} Http method
  2240. * @showStatus {number} HTTP response code which should be shown. Default is 500.
  2241. */
  2242. defaultErrorHandler: function (jqXHR, url, method, showStatus) {
  2243. method = method || 'GET';
  2244. var self = this;
  2245. var api = " received on " + method + " method for API: " + url;
  2246. try {
  2247. var json = $.parseJSON(jqXHR.responseText);
  2248. var message = json.message;
  2249. } catch (err) {
  2250. }
  2251. if (!showStatus) {
  2252. showStatus = 500;
  2253. }
  2254. var statusCode = jqXHR.status + " status code";
  2255. if (jqXHR.status === showStatus && !this.modalPopup) {
  2256. this.modalPopup = App.ModalPopup.show({
  2257. header: jqXHR.statusText,
  2258. secondary: false,
  2259. onPrimary: function () {
  2260. this.hide();
  2261. self.modalPopup = null;
  2262. },
  2263. bodyClass: Ember.View.extend({
  2264. classNames: ['api-error'],
  2265. templateName: require('templates/utils/ajax'),
  2266. api: api,
  2267. statusCode: statusCode,
  2268. message: message,
  2269. showMessage: !!message
  2270. })
  2271. });
  2272. }
  2273. }
  2274. });
  2275. /**
  2276. * Add few access-methods for test purposes
  2277. */
  2278. if ($.mocho) {
  2279. ajax.reopen({
  2280. /**
  2281. * Don't use it anywhere except tests!
  2282. * @returns {Array}
  2283. */
  2284. fakeGetUrlNames: function() {
  2285. return Em.keys(urls);
  2286. },
  2287. /**
  2288. * Don't use it anywhere except tests!
  2289. * @param name
  2290. * @returns {*}
  2291. */
  2292. fakeGetUrl: function(name) {
  2293. return urls[name];
  2294. },
  2295. /**
  2296. * Don't use it anywhere except tests!
  2297. * @param url
  2298. * @param data
  2299. * @returns {String}
  2300. */
  2301. fakeFormatUrl: function(url, data) {
  2302. return formatUrl(url, data);
  2303. },
  2304. /**
  2305. * Don't use it anywhere except tests!
  2306. * @param urlObj
  2307. * @param data
  2308. * @returns {Object}
  2309. */
  2310. fakeFormatRequest: function(urlObj, data) {
  2311. return formatRequest.call(urlObj, data);
  2312. }
  2313. });
  2314. }
  2315. App.ajax = ajax.create({});