ajax.js 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792
  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/start_time,tasks/Tasks/end_time,tasks/Tasks/exit_code,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status',
  47. 'mock': '/data/background_operations/task_by_request{requestId}.json',
  48. 'testInProduction': true,
  49. 'format': function (data) {
  50. return {
  51. async: !data.sync
  52. };
  53. }
  54. },
  55. 'background_operations.get_by_task': {
  56. 'real': '/clusters/{clusterName}/requests/{requestId}/tasks/{taskId}',
  57. 'mock': '/data/background_operations/list_on_start.json',
  58. 'testInProduction': true,
  59. 'format': function (data) {
  60. return {
  61. async: !data.sync
  62. };
  63. }
  64. },
  65. 'service.item.start_stop': {
  66. 'real': '/clusters/{clusterName}/services/{serviceName}',
  67. 'mock': '/data/wizard/deploy/poll_1.json',
  68. 'format': function (data) {
  69. return {
  70. type: 'PUT',
  71. data: JSON.stringify({
  72. RequestInfo: {
  73. "context": data.requestInfo
  74. },
  75. Body: {
  76. ServiceInfo: {
  77. state: data.state
  78. }
  79. }
  80. })
  81. };
  82. }
  83. },
  84. 'service.item.smoke': {
  85. 'real': '/clusters/{clusterName}/requests',
  86. 'mock': '/data/wizard/deploy/poll_1.json',
  87. 'format': function (data) {
  88. return {
  89. 'type': 'POST',
  90. data: JSON.stringify({
  91. RequestInfo: {
  92. "context": data.displayName + " Service Check",
  93. "command" : data.actionName,
  94. "service_name" : data.serviceName
  95. }
  96. })
  97. };
  98. }
  99. },
  100. 'service.stale_host_components.start_stop': {
  101. 'real': '/clusters/{clusterName}/host_components?' +
  102. 'HostRoles/stale_configs=true&HostRoles/component_name.in({componentNames})',
  103. 'mock': '/data/wizard/deploy/poll_1.json',
  104. 'format': function (data) {
  105. return {
  106. type: 'PUT',
  107. data: JSON.stringify({
  108. RequestInfo: {
  109. "context": data.requestInfo
  110. },
  111. Body: {
  112. HostRoles: {
  113. state: data.state
  114. }
  115. }
  116. })
  117. };
  118. }
  119. },
  120. 'service.load_config_groups': {
  121. 'real': '/clusters/{clusterName}/config_groups?ConfigGroup/tag={serviceName}&fields=*',
  122. 'mock': ''
  123. },
  124. 'reassign.stop_services': {
  125. 'real': '/clusters/{clusterName}/services',
  126. 'mock': '',
  127. 'format': function() {
  128. return {
  129. type: 'PUT',
  130. data: JSON.stringify({
  131. "RequestInfo": {
  132. "context": "Stop all services"
  133. },
  134. "Body": {
  135. "ServiceInfo": {
  136. "state": "INSTALLED"
  137. }
  138. }
  139. })
  140. }
  141. }
  142. },
  143. 'reassign.start_services': {
  144. 'real': '/clusters/{clusterName}/services?params/run_smoke_test=true',
  145. 'mock': '',
  146. 'format': function() {
  147. return {
  148. type: 'PUT',
  149. data: JSON.stringify({
  150. "RequestInfo": {
  151. "context": "Start all services"
  152. },
  153. "Body": {
  154. "ServiceInfo": {
  155. "state": "STARTED"
  156. }
  157. }
  158. })
  159. }
  160. }
  161. },
  162. 'reassign.maintenance_mode': {
  163. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  164. 'mock': '',
  165. 'type': 'PUT',
  166. 'format': function () {
  167. return {
  168. data: JSON.stringify(
  169. {
  170. "HostRoles": {
  171. "state": "MAINTENANCE"
  172. }
  173. }
  174. )
  175. }
  176. }
  177. },
  178. 'reassign.remove_component': {
  179. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  180. 'mock': '',
  181. 'type': 'DELETE'
  182. },
  183. 'reassign.load_configs': {
  184. 'real': '/clusters/{clusterName}/configurations?{urlParams}',
  185. 'mock': ''
  186. },
  187. 'reassign.save_configs': {
  188. 'real': '/clusters/{clusterName}',
  189. 'mock': '',
  190. 'type': 'PUT',
  191. 'format': function (data) {
  192. return {
  193. async: false,
  194. data: JSON.stringify({
  195. Clusters: {
  196. desired_config: {
  197. "type": data.siteName,
  198. "tag": 'version' + (new Date).getTime(),
  199. "properties": data.properties
  200. }
  201. }
  202. })
  203. }
  204. }
  205. },
  206. 'host_component.passive': {
  207. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  208. 'mock': '',
  209. 'type': 'PUT',
  210. 'format': function(data) {
  211. return {
  212. data: JSON.stringify({
  213. RequestInfo: {
  214. "context": data.requestInfo
  215. },
  216. Body: {
  217. HostRoles: {
  218. passive_state: data.passive_state
  219. }
  220. }
  221. })
  222. };
  223. }
  224. },
  225. 'config.advanced': {
  226. 'real': '{stack2VersionUrl}/stackServices/{serviceName}/configurations?fields=*',
  227. 'mock': '/data/wizard/stack/hdp/version{stackVersion}/{serviceName}.json',
  228. 'format': function() {
  229. return {
  230. async: false
  231. };
  232. }
  233. },
  234. 'config.advanced.global': {
  235. 'real': '{stack2VersionUrl}/stackServices?fields=configurations/StackConfigurations/type',
  236. 'mock': '/data/wizard/stack/hdp/version1.3.0/global.json',
  237. 'format': function() {
  238. return {
  239. async: false
  240. };
  241. }
  242. },
  243. 'config.tags': {
  244. 'real': '/clusters/{clusterName}?fields=Clusters/desired_configs',
  245. 'mock': '/data/clusters/cluster.json'
  246. },
  247. 'config.tags_and_groups': {
  248. 'real': '/clusters/{clusterName}?fields=Clusters/desired_configs,config_groups/*',
  249. 'mock': '/data/clusters/tags_and_groups.json'
  250. },
  251. 'config.tags.sync': {
  252. 'real': '/clusters/{clusterName}?fields=Clusters/desired_configs',
  253. 'mock': '/data/clusters/cluster.json',
  254. 'format': function() {
  255. return {
  256. async: false
  257. };
  258. }
  259. },
  260. 'config_groups.all_fields': {
  261. 'real': '/clusters/{clusterName}/config_groups?fields=*',
  262. 'mock': ''
  263. },
  264. 'config_groups.get_config_group_by_id': {
  265. 'real': '/clusters/{clusterName}/config_groups/{id}',
  266. 'mock': ''
  267. },
  268. 'config_groups.update_config_group': {
  269. 'real': '/clusters/{clusterName}/config_groups/{id}',
  270. 'mock': '',
  271. 'type': 'PUT',
  272. 'format': function (data) {
  273. return {
  274. async: false,
  275. data: JSON.stringify(
  276. [
  277. data.configGroup
  278. ]
  279. )
  280. }
  281. }
  282. },
  283. 'config_groups.delete_config_group': {
  284. 'real': '/clusters/{clusterName}/config_groups/{id}',
  285. 'mock': '',
  286. 'type': 'DELETE'
  287. },
  288. 'config.on_site': {
  289. 'real': '/clusters/{clusterName}/configurations?{params}',
  290. 'mock': '/data/configurations/cluster_level_configs.json?{params}',
  291. 'format': function() {
  292. return {
  293. async: false
  294. };
  295. }
  296. },
  297. 'config.host_overrides': {
  298. 'real': '/clusters/{clusterName}/configurations?{params}',
  299. 'mock': '/data/configurations/host_level_overrides_configs.json?{params}',
  300. 'format': function() {
  301. return {
  302. async: false
  303. };
  304. }
  305. },
  306. 'host.host_component.action': {
  307. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  308. 'mock': '',
  309. 'type': 'PUT',
  310. 'format': function (data) {
  311. return {
  312. data: JSON.stringify({
  313. RequestInfo: {
  314. "context": data.context
  315. },
  316. Body: {
  317. "HostRoles": {
  318. "state": data.state
  319. }
  320. }
  321. })
  322. }
  323. }
  324. },
  325. 'host.host_component.slave_desired_admin_state': {
  326. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}/?fields=HostRoles/desired_admin_state',
  327. 'mock': '',
  328. 'type': 'GET'
  329. },
  330. 'host.host_component.datanodes_decommission_status': {
  331. 'real': '/clusters/{clusterName}/services/HDFS/components/NAMENODE/?fields=ServiceComponentInfo',
  332. 'mock': '',
  333. 'type': 'GET'
  334. },
  335. 'host.host_component.nodemanager_decommission_status': {
  336. 'real': '/clusters/{clusterName}/services/YARN/components/RESOURCEMANAGER/?fields=ServiceComponentInfo',
  337. 'mock': '',
  338. 'type': 'GET'
  339. },
  340. 'host.host_component.tasktracker_decommission_status': {
  341. 'real': '/clusters/{clusterName}/services/MAPREDUCE/components/JOBTRACKER/?fields=ServiceComponentInfo',
  342. 'mock': '',
  343. 'type': 'GET'
  344. },
  345. 'host.host_component.decommission_slave': {
  346. 'real' : '/clusters/{clusterName}/requests',
  347. 'mock' : '',
  348. 'format' : function(data) {
  349. return {
  350. type : 'POST',
  351. data : JSON.stringify({
  352. RequestInfo: {
  353. 'context': data.context,
  354. 'command': data.command,
  355. 'service_name': data.serviceName,
  356. 'component_name': data.componentName,
  357. 'parameters': {
  358. 'slave_type': data.slaveType,
  359. 'excluded_hosts': data.hostName
  360. }
  361. }
  362. })
  363. }
  364. }
  365. },
  366. 'host.host_component.recommission_and_restart': {
  367. 'real': '/clusters/{clusterName}/request_schedules',
  368. 'mock': '',
  369. 'format' : function(data) {
  370. return {
  371. type : 'POST',
  372. data : JSON.stringify([ {
  373. "RequestSchedule" : {
  374. "batch" : [ {
  375. "requests" : data.batches
  376. }, {
  377. "batch_settings" : {
  378. "batch_separation_in_seconds" : data.intervalTimeSeconds,
  379. "task_failure_tolerance" : data.tolerateSize
  380. }
  381. } ]
  382. }
  383. } ])
  384. }
  385. }
  386. },
  387. 'host.host_component.recommission_slave' : {
  388. 'real' : '/clusters/{clusterName}/requests',
  389. 'mock' : '',
  390. 'format' : function(data) {
  391. return {
  392. type : 'POST',
  393. data : JSON.stringify({
  394. RequestInfo: {
  395. context: data.context,
  396. command: data.command,
  397. service_name: data.serviceName,
  398. component_name: data.componentName,
  399. parameters: {
  400. slave_type: data.slaveType,
  401. included_hosts: data.hostName
  402. }
  403. }
  404. })
  405. }
  406. }
  407. },
  408. 'host.stale_host_components.start_stop': {
  409. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components?HostRoles/stale_configs=true&' +
  410. 'HostRoles/component_name.in({componentNames})',
  411. 'mock': '',
  412. 'type': 'PUT',
  413. 'format': function (data) {
  414. return {
  415. data: JSON.stringify({
  416. RequestInfo: {
  417. "context": data.context
  418. },
  419. Body: {
  420. "HostRoles": {
  421. "state": data.state
  422. }
  423. }
  424. })
  425. }
  426. }
  427. },
  428. 'host.delete': {
  429. 'real': '/clusters/{clusterName}/hosts/{hostName}',
  430. 'mock': '',
  431. 'type': 'DELETE',
  432. 'format': function() {
  433. return {
  434. async: false
  435. }
  436. }
  437. },
  438. 'hosts.metrics': {
  439. 'real': '/clusters/{clusterName}/hosts?fields={metricName}',
  440. 'mock': '/data/cluster_metrics/cpu_1hr.json'
  441. },
  442. 'hosts.metrics.host_component': {
  443. 'real': '/clusters/{clusterName}/services/{serviceName}/components/{componentName}?fields=host_components/{metricName}',
  444. 'mock': '/data/cluster_metrics/cpu_1hr.json'
  445. },
  446. 'service.metrics.flume.channel_fill_percent': {
  447. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/CHANNEL/*/ChannelFillPercentage[{fromSeconds},{toSeconds},{stepSeconds}]',
  448. 'mock': '/data/services/metrics/flume/channelFillPct.json',
  449. 'testInProduction': true
  450. },
  451. 'service.metrics.flume.channel_size': {
  452. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/CHANNEL/*/ChannelSize[{fromSeconds},{toSeconds},{stepSeconds}]',
  453. 'mock': '/data/services/metrics/flume/channelSize.json',
  454. 'testInProduction': true
  455. },
  456. 'service.metrics.flume.sink_drain_success': {
  457. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/SINK/*/EventDrainSuccessCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  458. 'mock': '/data/services/metrics/flume/sinkDrainSuccessCount.json',
  459. 'testInProduction': true
  460. },
  461. 'service.metrics.flume.sink_connection_failed': {
  462. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/SINK/*/ConnectionFailedCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  463. 'mock': '/data/services/metrics/flume/sinkConnectionFailedCount.json',
  464. 'testInProduction': true
  465. },
  466. 'service.metrics.flume.gc': {
  467. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  468. 'mock': '/data/services/metrics/flume/jvmGcTime.json',
  469. 'testInProduction': true
  470. },
  471. 'service.metrics.flume.jvm_heap_used': {
  472. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/jvm/memHeapUsedM[{fromSeconds},{toSeconds},{stepSeconds}]',
  473. 'mock': '/data/services/metrics/flume/jvmMemHeapUsedM.json',
  474. 'testInProduction': true
  475. },
  476. 'service.metrics.flume.jvm_threads_runnable': {
  477. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/jvm/threadsRunnable[{fromSeconds},{toSeconds},{stepSeconds}]',
  478. 'mock': '/data/services/metrics/flume/jvmThreadsRunnable.json',
  479. 'testInProduction': true
  480. },
  481. 'service.metrics.flume.cpu_user': {
  482. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/cpu/cpu_user[{fromSeconds},{toSeconds},{stepSeconds}]',
  483. 'mock': '',
  484. 'testInProduction': true
  485. },
  486. 'service.metrics.flume.source_accepted': {
  487. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/SOURCE/*/EventAcceptedCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  488. 'mock': '/data/services/metrics/flume/sourceEventAccepted.json',
  489. 'testInProduction': true
  490. },
  491. 'service.metrics.hbase.cluster_requests': {
  492. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/cluster_requests[{fromSeconds},{toSeconds},{stepSeconds}]',
  493. 'mock': '/data/services/metrics/hbase/cluster_requests.json',
  494. 'testInProduction': true
  495. },
  496. 'service.metrics.hbase.hlog_split_size': {
  497. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/splitSize_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  498. 'mock': '/data/services/metrics/hbase/hlog_split_size.json',
  499. 'testInProduction': true
  500. },
  501. 'service.metrics.hbase.hlog_split_time': {
  502. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/splitTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  503. 'mock': '/data/services/metrics/hbase/hlog_split_time.json',
  504. 'testInProduction': true
  505. },
  506. 'service.metrics.hbase.regionserver_queuesize': {
  507. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/flushQueueSize[{fromSeconds},{toSeconds},{stepSeconds}],metrics/hbase/regionserver/compactionQueueSize[{fromSeconds},{toSeconds},{stepSeconds}]',
  508. 'mock': '/data/services/metrics/hbase/regionserver_queuesize.json',
  509. 'testInProduction': true
  510. },
  511. 'service.metrics.hbase.regionserver_regions': {
  512. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/regions[{fromSeconds},{toSeconds},{stepSeconds}]',
  513. 'mock': '/data/services/metrics/hbase/regionserver_regions.json',
  514. 'testInProduction': true
  515. },
  516. 'service.metrics.hbase.regionserver_rw_requests': {
  517. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/readRequestsCount[{fromSeconds},{toSeconds},{stepSeconds}],metrics/hbase/regionserver/writeRequestsCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  518. 'mock': '/data/services/metrics/hbase/regionserver_rw_requests.json',
  519. 'testInProduction': true
  520. },
  521. 'service.metrics.mapreduce.gc': {
  522. 'real': '/clusters/{clusterName}/hosts/{jobTrackerNode}/host_components/JOBTRACKER?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  523. 'mock': '/data/services/metrics/mapreduce/gc.json',
  524. 'testInProduction': true
  525. },
  526. 'service.metrics.mapreduce.jobs_status': {
  527. '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}]',
  528. 'mock': '/data/services/metrics/mapreduce/jobs_status.json',
  529. 'testInProduction': true
  530. },
  531. 'service.metrics.mapreduce.jobs_heap': {
  532. '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}]',
  533. 'mock': '/data/services/metrics/mapreduce/jvm_heap.json',
  534. 'testInProduction': true
  535. },
  536. 'service.metrics.mapreduce.jobs_threads': {
  537. '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}]',
  538. 'mock': '/data/services/metrics/mapreduce/jvm_threads.json',
  539. 'testInProduction': true
  540. },
  541. 'service.metrics.mapreduce.map_slots': {
  542. '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}]',
  543. 'mock': '/data/services/metrics/mapreduce/map_slots.json',
  544. 'testInProduction': true
  545. },
  546. 'service.metrics.mapreduce.reduce_slots': {
  547. '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}]',
  548. 'mock': '/data/services/metrics/mapreduce/reduce_slots.json',
  549. 'testInProduction': true
  550. },
  551. 'service.metrics.mapreduce.rpc': {
  552. 'real': '/clusters/{clusterName}/hosts/{jobTrackerNode}/host_components/JOBTRACKER?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  553. 'mock': '/data/services/metrics/mapreduce/rpc.json',
  554. 'testInProduction': true
  555. },
  556. 'service.metrics.mapreduce.tasks_running_waiting': {
  557. '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}]',
  558. 'mock': '/data/services/metrics/mapreduce/tasks_running_waiting.json',
  559. 'testInProduction': true
  560. },
  561. 'service.metrics.hdfs.block_status': {
  562. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/dfs/FSNamesystem/PendingReplicationBlocks[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/FSNamesystem/UnderReplicatedBlocks[{fromSeconds},{toSeconds},{stepSeconds}]',
  563. 'mock': '/data/services/metrics/hdfs/block_status.json',
  564. 'testInProduction': true
  565. },
  566. 'service.metrics.hdfs.file_operations': {
  567. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/dfs/namenode/FileInfoOps[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/namenode/CreateFileOps[{fromSeconds},{toSeconds},{stepSeconds}]',
  568. 'mock': '/data/services/metrics/hdfs/file_operations.json',
  569. 'testInProduction': true
  570. },
  571. 'service.metrics.hdfs.gc': {
  572. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  573. 'mock': '/data/services/metrics/hdfs/gc.json',
  574. 'testInProduction': true
  575. },
  576. 'service.metrics.hdfs.io': {
  577. 'real': '/clusters/{clusterName}/services/HDFS/components/DATANODE?fields=metrics/dfs/datanode/bytes_written[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/datanode/bytes_read[{fromSeconds},{toSeconds},{stepSeconds}]',
  578. 'mock': '/data/services/metrics/hdfs/io.json',
  579. 'testInProduction': true
  580. },
  581. 'service.metrics.hdfs.jvm_heap': {
  582. '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}]',
  583. 'mock': '/data/services/metrics/hdfs/jvm_heap.json',
  584. 'testInProduction': true
  585. },
  586. 'service.metrics.hdfs.jvm_threads': {
  587. '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}]',
  588. 'mock': '/data/services/metrics/hdfs/jvm_threads.json',
  589. 'testInProduction': true
  590. },
  591. 'service.metrics.hdfs.rpc': {
  592. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  593. 'mock': '/data/services/metrics/hdfs/rpc.json',
  594. 'testInProduction': true
  595. },
  596. 'service.metrics.hdfs.space_utilization': {
  597. '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}]',
  598. 'mock': '/data/services/metrics/hdfs/space_utilization.json',
  599. 'testInProduction': true
  600. },
  601. 'service.start_stop': {
  602. 'real': '/clusters/{clusterName}/services?params/run_smoke_test=true',
  603. 'mock': '/data/mirroring/poll/poll_6.json',
  604. 'format': function (data) {
  605. return {
  606. type: 'PUT',
  607. async: false,
  608. data: data.data
  609. };
  610. }
  611. },
  612. 'service.metrics.yarn.gc': {
  613. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  614. 'mock': '/data/services/metrics/yarn/gc.json',
  615. 'testInProduction': true
  616. },
  617. 'service.metrics.yarn.jobs_threads': {
  618. '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}]',
  619. 'mock': '/data/services/metrics/yarn/jvm_threads.json',
  620. 'testInProduction': true
  621. },
  622. 'service.metrics.yarn.rpc': {
  623. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  624. 'mock': '/data/services/metrics/yarn/rpc.json',
  625. 'testInProduction': true
  626. },
  627. 'service.metrics.yarn.jobs_heap': {
  628. '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}]',
  629. 'mock': '/data/services/metrics/yarn/jvm_heap.json',
  630. 'testInProduction': true
  631. },
  632. 'service.metrics.yarn.queue.allocated': {
  633. '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}]',
  634. 'mock': '',
  635. 'testInProduction': true
  636. },
  637. 'service.metrics.yarn.queue.allocated.container': {
  638. '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}]',
  639. 'mock': '',
  640. 'testInProduction': true
  641. },
  642. 'service.metrics.yarn.node.manager.statuses': {
  643. '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}]',
  644. 'mock': '',
  645. 'testInProduction': true
  646. },
  647. 'service.metrics.yarn.queue.memory.resource': {
  648. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=',
  649. 'mock': '',
  650. 'format': function (data, opt) {
  651. var field1 = 'metrics/yarn/Queue/{queueName}/AllocatedMB[{fromSeconds},{toSeconds},{stepSeconds}]';
  652. var field2 = 'metrics/yarn/Queue/{queueName}/AvailableMB[{fromSeconds},{toSeconds},{stepSeconds}]';
  653. if (opt.url != null && data.queueNames != null && data.queueNames.length > 0) {
  654. data.queueNames.forEach(function (q) {
  655. data.queueName = q;
  656. opt.url += (formatUrl(field1, data) + ",");
  657. opt.url += (formatUrl(field2, data) + ",");
  658. });
  659. } else {
  660. opt.url += (formatUrl(field1, data) + ",");
  661. opt.url += (formatUrl(field2, data) + ",");
  662. }
  663. },
  664. 'testInProduction': true
  665. },
  666. 'service.metrics.yarn.queue.apps.states.current': {
  667. '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}]',
  668. 'mock': '',
  669. 'testInProduction': true
  670. },
  671. 'service.metrics.yarn.queue.apps.states.finished': {
  672. '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}]',
  673. 'mock': '',
  674. 'testInProduction': true
  675. },
  676. 'dashboard.cluster_metrics.cpu': {
  677. 'real': '/clusters/{clusterName}/?fields=metrics/cpu[{fromSeconds},{toSeconds},{stepSeconds}]',
  678. 'mock': '/data/cluster_metrics/cpu_1hr.json',
  679. 'testInProduction': true
  680. },
  681. 'dashboard.cluster_metrics.load': {
  682. 'real': '/clusters/{clusterName}/?fields=metrics/load[{fromSeconds},{toSeconds},{stepSeconds}]',
  683. 'mock': '/data/cluster_metrics/load_1hr.json',
  684. 'testInProduction': true
  685. },
  686. 'dashboard.cluster_metrics.memory': {
  687. 'real': '/clusters/{clusterName}/?fields=metrics/memory[{fromSeconds},{toSeconds},{stepSeconds}]',
  688. 'mock': '/data/cluster_metrics/memory_1hr.json',
  689. 'testInProduction': true
  690. },
  691. 'dashboard.cluster_metrics.network': {
  692. 'real': '/clusters/{clusterName}/?fields=metrics/network[{fromSeconds},{toSeconds},{stepSeconds}]',
  693. 'mock': '/data/cluster_metrics/network_1hr.json',
  694. 'testInProduction': true
  695. },
  696. 'host.metrics.cpu': {
  697. '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}]',
  698. 'mock': '/data/hosts/metrics/cpu.json',
  699. 'testInProduction': true
  700. },
  701. 'host.metrics.disk': {
  702. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/disk/disk_total[{fromSeconds},{toSeconds},{stepSeconds}],metrics/disk/disk_free[{fromSeconds},{toSeconds},{stepSeconds}]',
  703. 'mock': '/data/hosts/metrics/disk.json',
  704. 'testInProduction': true
  705. },
  706. 'host.metrics.load': {
  707. '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}]',
  708. 'mock': '/data/hosts/metrics/load.json',
  709. 'testInProduction': true
  710. },
  711. 'host.metrics.memory': {
  712. '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}]',
  713. 'mock': '/data/hosts/metrics/memory.json',
  714. 'testInProduction': true
  715. },
  716. 'host.metrics.network': {
  717. '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}]',
  718. 'mock': '/data/hosts/metrics/network.json',
  719. 'testInProduction': true
  720. },
  721. 'host.metrics.processes': {
  722. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/process/proc_total[{fromSeconds},{toSeconds},{stepSeconds}],metrics/process/proc_run[{fromSeconds},{toSeconds},{stepSeconds}]',
  723. 'mock': '/data/hosts/metrics/processes.json',
  724. 'testInProduction': true
  725. },
  726. 'host.service_config_hosts_overrides': {
  727. 'real': '/clusters/{clusterName}/configurations?{urlParams}',
  728. 'mock': '',
  729. 'format': function() {
  730. return {
  731. async: false,
  732. timeout: 10000
  733. };
  734. }
  735. },
  736. 'admin.security_status': {
  737. 'real': '/clusters/{clusterName}?fields=Clusters/desired_configs',
  738. 'mock': '',
  739. 'format': function() {
  740. return {
  741. timeout: 10000
  742. };
  743. }
  744. },
  745. 'settings.get.user_pref': {
  746. 'real': '/persist/{key}',
  747. 'mock': '/data/user_settings/{key}.json'
  748. },
  749. 'settings.post.user_pref': {
  750. 'real': '/persist',
  751. 'mock': '',
  752. 'type': 'POST',
  753. 'format': function (data) {
  754. return {
  755. data: JSON.stringify(data.keyValuePair)
  756. }
  757. }
  758. },
  759. 'cluster.load_cluster_name': {
  760. 'real': '/clusters',
  761. 'mock': '/data/clusters/info.json',
  762. 'format': function() {
  763. return {
  764. async: false
  765. };
  766. }
  767. },
  768. 'cluster.state': {
  769. 'type': 'POST',
  770. 'real': '/persist/',
  771. 'mock': '',
  772. 'format': function(data) {
  773. return {
  774. async: false,
  775. data: JSON.stringify(data.keyValuePair)
  776. };
  777. }
  778. },
  779. 'cluster.update_upgrade_version': {
  780. 'real': '/stacks2/HDP/versions?fields=stackServices/StackServices,Versions',
  781. 'mock': '/data/wizard/stack/stacks.json',
  782. 'format': function() {
  783. return {
  784. async: false
  785. };
  786. }
  787. },
  788. 'cluster.load_repositories': {
  789. 'real': '/stacks2/{stackName}/versions/{stackVersion}/operatingSystems?fields=repositories/*',
  790. 'mock': '',
  791. 'type': 'GET',
  792. 'format': function (data) {
  793. return {
  794. data: data.data
  795. };
  796. }
  797. },
  798. 'admin.high_availability.stop_all_services': {
  799. 'real': '/clusters/{clusterName}/services',
  800. 'mock': '',
  801. 'format': function() {
  802. return {
  803. type: 'PUT',
  804. data: JSON.stringify({
  805. "RequestInfo": {
  806. "context": "Stop all services"
  807. },
  808. "Body": {
  809. "ServiceInfo": {
  810. "state": "INSTALLED"
  811. }
  812. }
  813. })
  814. }
  815. }
  816. },
  817. 'admin.high_availability.start_all_services': {
  818. 'real': '/clusters/{clusterName}/services',
  819. 'mock': '',
  820. 'format': function() {
  821. return {
  822. type: 'PUT',
  823. data: JSON.stringify({
  824. "RequestInfo": {
  825. "context": "Start all services"
  826. },
  827. "Body": {
  828. "ServiceInfo": {
  829. "state": "STARTED"
  830. }
  831. }
  832. })
  833. }
  834. }
  835. },
  836. 'admin.high_availability.polling': {
  837. 'real': '/clusters/{clusterName}/requests/{requestId}?fields=tasks/*',
  838. 'mock': '',
  839. 'type': 'GET'
  840. },
  841. 'admin.high_availability.getNnCheckPointStatus': {
  842. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/NAMENODE',
  843. 'mock': '',
  844. 'type': 'GET'
  845. },
  846. 'admin.high_availability.getJnCheckPointStatus': {
  847. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/JOURNALNODE?fields=metrics',
  848. 'mock': ''
  849. },
  850. 'admin.high_availability.getHostComponent': {
  851. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  852. 'mock': ''
  853. },
  854. 'admin.high_availability.create_component': {
  855. 'real': '/clusters/{clusterName}/hosts?Hosts/host_name={hostName}',
  856. 'mock': '',
  857. 'type': 'POST',
  858. 'format': function (data) {
  859. return {
  860. data: JSON.stringify({
  861. "host_components": [
  862. {
  863. "HostRoles": {
  864. "component_name": data.componentName
  865. }
  866. }
  867. ]
  868. })
  869. }
  870. }
  871. },
  872. 'admin.high_availability.create_journalnode': {
  873. 'real': '/clusters/{clusterName}/services?ServiceInfo/service_name=HDFS',
  874. 'mock': '',
  875. 'type': 'POST',
  876. 'format': function() {
  877. return {
  878. data: JSON.stringify({
  879. "components": [
  880. {
  881. "ServiceComponentInfo": {
  882. "component_name": "JOURNALNODE"
  883. }
  884. }
  885. ]
  886. })
  887. }
  888. }
  889. },
  890. 'admin.high_availability.create_zkfc': {
  891. 'real': '/clusters/{clusterName}/services?ServiceInfo/service_name=HDFS',
  892. 'mock': '',
  893. 'type': 'POST',
  894. 'format': function() {
  895. return {
  896. data: JSON.stringify({
  897. "components": [
  898. {
  899. "ServiceComponentInfo": {
  900. "component_name": "ZKFC"
  901. }
  902. }
  903. ]
  904. })
  905. }
  906. }
  907. },
  908. 'admin.high_availability.install_component': {
  909. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  910. 'mock': '',
  911. 'type': 'PUT',
  912. 'format': function (data) {
  913. return {
  914. data: JSON.stringify({
  915. RequestInfo: {
  916. "context": "Install " + data.displayName
  917. },
  918. Body: {
  919. "HostRoles": {
  920. "state": "INSTALLED"
  921. }
  922. }
  923. })
  924. }
  925. }
  926. },
  927. 'admin.high_availability.start_component': {
  928. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  929. 'mock': '',
  930. 'type': 'PUT',
  931. 'format': function (data) {
  932. return {
  933. data: JSON.stringify({
  934. RequestInfo: {
  935. "context": "Start " + data.displayName
  936. },
  937. Body: {
  938. "HostRoles": {
  939. "state": "STARTED"
  940. }
  941. }
  942. })
  943. }
  944. }
  945. },
  946. 'admin.high_availability.maintenance_mode': {
  947. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  948. 'mock': '',
  949. 'type': 'PUT',
  950. 'format': function () {
  951. return {
  952. data: JSON.stringify({
  953. "HostRoles": {
  954. "state": "MAINTENANCE"
  955. }
  956. })
  957. }
  958. }
  959. },
  960. 'admin.high_availability.stop_component': {
  961. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  962. 'mock': '',
  963. 'type': 'PUT',
  964. 'format': function (data) {
  965. return {
  966. data: JSON.stringify({
  967. RequestInfo: {
  968. "context": "Stop " + data.displayName
  969. },
  970. Body: {
  971. "HostRoles": {
  972. "state": "INSTALLED"
  973. }
  974. }
  975. })
  976. }
  977. }
  978. },
  979. 'admin.high_availability.load_configs': {
  980. 'real': '/clusters/{clusterName}/configurations?(type=core-site&tag={coreSiteTag})|(type=hdfs-site&tag={hdfsSiteTag})',
  981. 'mock': '',
  982. 'type': 'GET'
  983. },
  984. 'admin.high_availability.save_configs': {
  985. 'real': '/clusters/{clusterName}',
  986. 'mock': '',
  987. 'type': 'PUT',
  988. 'format': function (data) {
  989. return {
  990. async: false,
  991. data: JSON.stringify({
  992. Clusters: {
  993. desired_config: {
  994. "type": data.siteName,
  995. "tag": 'version' + (new Date).getTime(),
  996. "properties": data.properties
  997. }
  998. }
  999. })
  1000. }
  1001. }
  1002. },
  1003. 'admin.high_availability.load_hbase_configs': {
  1004. 'real': '/clusters/{clusterName}/configurations?type=hbase-site&tag={hbaseSiteTag}',
  1005. 'mock': '',
  1006. 'type': 'GET'
  1007. },
  1008. 'admin.high_availability.delete_component': {
  1009. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  1010. 'mock': '',
  1011. 'type': 'DELETE'
  1012. },
  1013. 'admin.security.cluster_configs': {
  1014. 'real': '/clusters/{clusterName}',
  1015. 'mock': '',
  1016. 'format': function() {
  1017. return {
  1018. timeout: 10000
  1019. };
  1020. }
  1021. },
  1022. 'admin.delete_host': {
  1023. 'real': '/clusters/{clusterName}/hosts/{hostName}',
  1024. 'mock': '',
  1025. 'type': 'DELETE'
  1026. },
  1027. 'admin.get.all_configurations': {
  1028. 'real': '/clusters/{clusterName}/configurations?{urlParams}',
  1029. 'mock': '',
  1030. 'format': function() {
  1031. return {
  1032. timeout: 10000
  1033. };
  1034. }
  1035. },
  1036. 'admin.security.apply_configurations': {
  1037. 'real': '/clusters/{clusterName}',
  1038. 'mock': '',
  1039. 'format': function (data) {
  1040. return {
  1041. type: 'PUT',
  1042. timeout: 10000,
  1043. data: data.configData
  1044. };
  1045. }
  1046. },
  1047. 'admin.security.apply_configuration': {
  1048. 'real': '/clusters/{clusterName}',
  1049. 'mock': '',
  1050. 'format': function(data) {
  1051. return {
  1052. type: 'PUT',
  1053. async: false,
  1054. timeout: 5000,
  1055. data: JSON.stringify(data.clusterData)
  1056. };
  1057. }
  1058. },
  1059. 'admin.security.add.cluster_configs': {
  1060. 'real': '/clusters/{clusterName}' + '?fields=Clusters/desired_configs',
  1061. 'mock': '',
  1062. 'format': function() {
  1063. return {
  1064. timeout: 10000
  1065. };
  1066. }
  1067. },
  1068. 'admin.stack_upgrade.run_upgrade': {
  1069. 'real': '/clusters/{clusterName}',
  1070. 'mock': '',
  1071. 'format': function () {
  1072. return {
  1073. type: 'PUT',
  1074. async: false,
  1075. data: data.data
  1076. };
  1077. }
  1078. },
  1079. 'admin.stack_upgrade.stop_services': {
  1080. 'real': '/clusters/{clusterName}/services?ServiceInfo/state=STARTED',
  1081. 'mock': '',
  1082. 'format': function () {
  1083. return {
  1084. type: 'PUT',
  1085. async: false,
  1086. data: data.data
  1087. };
  1088. }
  1089. },
  1090. 'admin.stack_upgrade.do_poll': {
  1091. 'real': '/clusters/{cluster}/requests/{requestId}?fields=tasks/*',
  1092. 'mock': '/data/wizard/{mock}'
  1093. },
  1094. 'wizard.advanced_repositories.valid_url': {
  1095. 'real': '/stacks2/{stackName}/versions/{stackVersion}/operatingSystems/{osType}/repositories/{nameVersionCombo}',
  1096. 'mock': '',
  1097. 'type': 'PUT',
  1098. 'format': function (data) {
  1099. return {
  1100. async: true,
  1101. data: JSON.stringify(data.data)
  1102. }
  1103. }
  1104. },
  1105. 'wizard.install_services.add_host_controller.is_retry': {
  1106. 'real': '/clusters/{cluster}/host_components',
  1107. 'mock': '',
  1108. 'format': function (data) {
  1109. return {
  1110. type: 'PUT',
  1111. async: false,
  1112. data: data.data
  1113. };
  1114. }
  1115. },
  1116. 'wizard.install_services.add_host_controller.not_is_retry': {
  1117. 'real': '/clusters/{cluster}/host_components',
  1118. 'mock': '',
  1119. 'format': function(data) {
  1120. return {
  1121. type: 'PUT',
  1122. async: false,
  1123. data: data.data
  1124. };
  1125. }
  1126. },
  1127. 'wizard.install_services.installer_controller.is_retry': {
  1128. 'real': '/clusters/{cluster}/host_components?HostRoles/state=INSTALLED',
  1129. 'mock': '/data/wizard/deploy/2_hosts/poll_1.json',
  1130. 'type': 'PUT',
  1131. 'format': function (data) {
  1132. return {
  1133. async: false,
  1134. data: data.data
  1135. };
  1136. }
  1137. },
  1138. 'wizard.install_services.installer_controller.not_is_retry': {
  1139. 'real': '/clusters/{cluster}/services?ServiceInfo/state=INIT',
  1140. 'mock': '/data/wizard/deploy/2_hosts/poll_1.json',
  1141. 'type': 'PUT',
  1142. 'format': function (data) {
  1143. return {
  1144. async: false,
  1145. data: data.data
  1146. };
  1147. }
  1148. },
  1149. 'wizard.install_services.add_service_controller.get_failed_host_components': {
  1150. 'real': '/clusters/{clusterName}/host_components?fields=HostRoles/state,component/ServiceComponentInfo/service_name',
  1151. 'mock': '',
  1152. 'format': function() {
  1153. return {
  1154. async: false
  1155. };
  1156. }
  1157. },
  1158. 'wizard.service_components': {
  1159. 'real': '{stackUrl}/stackServices?fields=StackServices',
  1160. 'mock': '/data/wizard/stack/hdp/version/{stackVersion}.json',
  1161. 'format': function() {
  1162. return {
  1163. timeout: 10000,
  1164. async: false
  1165. };
  1166. }
  1167. },
  1168. 'wizard.step9.installer.launch_start_services': {
  1169. 'real': '/clusters/{cluster}/services?ServiceInfo/state=INSTALLED&params/run_smoke_test=true&params/reconfigure_client=false',
  1170. 'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
  1171. 'format': function (data) {
  1172. var d = {
  1173. type: 'PUT',
  1174. async: false,
  1175. data: data.data
  1176. };
  1177. if (App.testMode) {
  1178. d.type = 'GET';
  1179. }
  1180. return d;
  1181. }
  1182. },
  1183. 'wizard.step9.add_host.launch_start_services': {
  1184. 'real': '/clusters/{cluster}/host_components',
  1185. 'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
  1186. 'format': function (data) {
  1187. return {
  1188. type: 'PUT',
  1189. async: false,
  1190. data: data.data
  1191. };
  1192. }
  1193. },
  1194. 'wizard.step8.delete_cluster': {
  1195. 'real': '/clusters/{name}',
  1196. 'mock': '',
  1197. 'format': function() {
  1198. return {
  1199. type: 'DELETE',
  1200. async: false
  1201. };
  1202. }
  1203. },
  1204. 'wizard.step8.existing_cluster_names': {
  1205. 'real': '/clusters',
  1206. 'mock': '',
  1207. 'format': function() {
  1208. return {
  1209. async: false
  1210. };
  1211. }
  1212. },
  1213. 'wizard.step3.host_info': {
  1214. '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',
  1215. 'mock': '/data/wizard/bootstrap/two_hosts_information.json',
  1216. 'format': function() {
  1217. return {
  1218. contentType: 'application/json'
  1219. };
  1220. }
  1221. },
  1222. 'wizard.step3.rerun_checks': {
  1223. 'real': '/hosts?fields=Hosts/last_agent_env',
  1224. 'mock': '/data/wizard/bootstrap/two_hosts_information.json',
  1225. 'format': function() {
  1226. return {
  1227. contentType: 'application/json'
  1228. };
  1229. }
  1230. },
  1231. 'wizard.step3.bootstrap': {
  1232. 'real': '/bootstrap/{bootRequestId}',
  1233. 'mock': '/data/wizard/bootstrap/poll_{numPolls}.json'
  1234. },
  1235. 'wizard.step3.is_hosts_registered': {
  1236. 'real': '/hosts',
  1237. 'mock': '/data/wizard/bootstrap/single_host_registration.json'
  1238. },
  1239. 'wizard.stacks': {
  1240. 'real': '/stacks2',
  1241. 'mock': '/data/wizard/stack/stacks2.json',
  1242. 'format': function() {
  1243. return {
  1244. async: false
  1245. };
  1246. }
  1247. },
  1248. 'wizard.stacks_versions': {
  1249. 'real': '/stacks2/{stackName}/versions?fields=Versions,operatingSystems/repositories/Repositories',
  1250. 'mock': '/data/wizard/stack/{stackName}_versions.json',
  1251. 'format': function() {
  1252. return {
  1253. async: false
  1254. };
  1255. }
  1256. },
  1257. 'wizard.launch_bootstrap': {
  1258. 'real': '/bootstrap',
  1259. 'mock': '/data/wizard/bootstrap/bootstrap.json',
  1260. 'type': 'POST',
  1261. 'format': function (data) {
  1262. return {
  1263. async: false,
  1264. contentType: 'application/json',
  1265. data: data.bootStrapData
  1266. }
  1267. }
  1268. },
  1269. 'router.login': {
  1270. 'real': '/users/{loginName}',
  1271. 'mock': '/data/users/user_{usr}.json',
  1272. 'format': function (data) {
  1273. var statusCode = jQuery.extend({}, require('data/statusCodes'));
  1274. statusCode['403'] = function () {
  1275. console.log("Error code 403: Forbidden.");
  1276. };
  1277. return {
  1278. statusCode: statusCode
  1279. };
  1280. }
  1281. },
  1282. 'router.login2': {
  1283. 'real': '/clusters',
  1284. 'mock': '/data/clusters/info.json'
  1285. },
  1286. 'router.logoff': {
  1287. 'real': '/logout',
  1288. 'mock': ''
  1289. },
  1290. 'router.set_ambari_stacks': {
  1291. 'real': '/stacks',
  1292. 'mock': '/data/wizard/stack/stacks.json',
  1293. 'format': function() {
  1294. return {
  1295. async: false
  1296. };
  1297. }
  1298. },
  1299. 'router.authentication': {
  1300. 'real': '/clusters',
  1301. 'mock': '/data/clusters/info.json',
  1302. 'format': function() {
  1303. return {
  1304. async: false
  1305. };
  1306. }
  1307. },
  1308. 'ambari.service': {
  1309. 'real': '/services/AMBARI/components/AMBARI_SERVER',
  1310. 'mock': ''
  1311. },
  1312. 'dashboard.get.user_pref': {
  1313. 'real': '/persist/{key}',
  1314. 'mock': '',
  1315. 'format': function() {
  1316. return {
  1317. async: false
  1318. };
  1319. }
  1320. },
  1321. 'dashboard.post.user_pref': {
  1322. 'real': '/persist',
  1323. 'mock': '',
  1324. 'type': 'POST',
  1325. 'format': function (data) {
  1326. return {
  1327. async: false,
  1328. data: JSON.stringify(data.keyValuePair)
  1329. }
  1330. }
  1331. },
  1332. 'config_groups.create': {
  1333. 'real': '/clusters/{clusterName}/config_groups',
  1334. 'mock': '',
  1335. 'format': function (data) {
  1336. return {
  1337. async: false,
  1338. type: 'POST',
  1339. data: JSON.stringify([{
  1340. "ConfigGroup": {
  1341. "group_name": data.group_name,
  1342. "tag": data.service_id,
  1343. "description": data.description,
  1344. "desired_configs": data.desired_configs,
  1345. "hosts": data.hosts
  1346. }
  1347. }])
  1348. }
  1349. }
  1350. },
  1351. 'config_groups.update': {
  1352. 'real': '/clusters/{clusterName}/config_groups/{id}',
  1353. 'mock': '',
  1354. 'format': function (data) {
  1355. return {
  1356. async: true,
  1357. type: 'PUT',
  1358. data: JSON.stringify(data.data)
  1359. }
  1360. }
  1361. },
  1362. 'rolling_restart.post': {
  1363. 'real': '/clusters/{clusterName}/request_schedules',
  1364. 'mock': '',
  1365. 'format' : function(data) {
  1366. return {
  1367. type : 'POST',
  1368. data : JSON.stringify([ {
  1369. "RequestSchedule" : {
  1370. "batch" : [ {
  1371. "requests" : data.batches
  1372. }, {
  1373. "batch_settings" : {
  1374. "batch_separation_in_seconds" : data.intervalTimeSeconds,
  1375. "task_failure_tolerance" : data.tolerateSize
  1376. }
  1377. } ]
  1378. }
  1379. } ])
  1380. }
  1381. }
  1382. },
  1383. 'request_schedule.delete': {
  1384. 'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
  1385. 'mock': '',
  1386. 'format' : function() {
  1387. return {
  1388. type : 'DELETE'
  1389. }
  1390. }
  1391. },
  1392. 'request_schedule.get': {
  1393. 'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
  1394. 'mock': ''
  1395. },
  1396. 'restart.service.hostComponents' : {
  1397. 'real' : '/clusters/{clusterName}/requests',
  1398. 'mock' : '',
  1399. 'format' : function(data) {
  1400. var componentDisplayName = App.format.role(data.componentName);
  1401. var serviceDisplayName = App.Service.DisplayNames[data.serviceName];
  1402. return {
  1403. type : 'POST',
  1404. data : JSON.stringify({
  1405. "RequestInfo" : {
  1406. "context" : Em.I18n.t('restart.service.rest.context').format(serviceDisplayName, componentDisplayName),
  1407. "command" : "RESTART",
  1408. "service_name" : data.serviceName,
  1409. "component_name" : data.componentName,
  1410. "hosts" : data.hosts
  1411. }
  1412. })
  1413. }
  1414. }
  1415. },
  1416. 'mirroring.get_all_datasets': {
  1417. 'real': 'falcon/entities/list/feed',
  1418. 'mock': '/data/mirroring/datasets.json'
  1419. },
  1420. 'mirroring.get_dataset_definition': {
  1421. 'real': 'falcon/entities/definition/feed/{dataset}',
  1422. 'mock': '/data/mirroring/{dataset}_definition.xml',
  1423. 'format': function () {
  1424. return {
  1425. dataType: 'xml'
  1426. }
  1427. }
  1428. },
  1429. 'mirroring.dataset.get_all_instances': {
  1430. 'real': 'falcon/instance/status/feed/{dataset}',
  1431. 'mock': '/data/mirroring/{dataset}_instances.json'
  1432. },
  1433. 'bulk_request.host_components': {
  1434. 'real': '/clusters/{clusterName}/host_components',
  1435. 'mock': '',
  1436. 'format': function(data) {
  1437. return {
  1438. type: 'PUT',
  1439. data: JSON.stringify({
  1440. RequestInfo: {
  1441. context: data.requestInfo,
  1442. query: 'HostRoles/component_name=' + data.componentName + '&HostRoles/host_name.in(' + data.hostNames + ')'
  1443. },
  1444. Body: {
  1445. HostRoles: {
  1446. state: data.state
  1447. }
  1448. }
  1449. })
  1450. }
  1451. }
  1452. },
  1453. 'bulk_request.hosts.all_components': {
  1454. 'real': '/clusters/{clusterName}/host_components',
  1455. 'mock': '',
  1456. 'format': function(data) {
  1457. return {
  1458. type: 'PUT',
  1459. data: JSON.stringify({
  1460. RequestInfo: {
  1461. context: data.requestInfo,
  1462. query: data.query
  1463. },
  1464. Body: {
  1465. HostRoles: {
  1466. state: data.state
  1467. }
  1468. }
  1469. })
  1470. }
  1471. }
  1472. },
  1473. 'bulk_request.decommission': {
  1474. 'real' : '/clusters/{clusterName}/requests',
  1475. 'mock' : '',
  1476. 'format': function(data) {
  1477. return {
  1478. type: 'POST',
  1479. data: JSON.stringify({
  1480. 'RequestInfo': {
  1481. 'context': data.context,
  1482. 'command': 'DECOMMISSION',
  1483. 'service_name': data.serviceName,
  1484. 'component_name': data.componentName,
  1485. 'parameters': data.parameters
  1486. }
  1487. })
  1488. }
  1489. }
  1490. },
  1491. 'bulk_request.hosts.passive_state': {
  1492. 'real': '/clusters/{clusterName}/hosts',
  1493. 'mock': '',
  1494. 'format': function(data) {
  1495. return {
  1496. type: 'PUT',
  1497. data: JSON.stringify({
  1498. RequestInfo: {
  1499. context: data.requestInfo,
  1500. query: 'Hosts/host_name.in(' + data.hostNames + ')'
  1501. },
  1502. Body: {
  1503. Hosts: {
  1504. passive_state: data.passive_state
  1505. }
  1506. }
  1507. })
  1508. }
  1509. }
  1510. },
  1511. 'bulk_request.hosts.all_components.passive_state': {
  1512. 'real': '/clusters/{clusterName}/host_components',
  1513. 'mock': '',
  1514. 'format': function(data) {
  1515. return {
  1516. type: 'PUT',
  1517. data: JSON.stringify({
  1518. RequestInfo: {
  1519. context: data.requestInfo,
  1520. query: data.query
  1521. },
  1522. Body: {
  1523. HostRoles: {
  1524. passive_state: data.passive_state
  1525. }
  1526. }
  1527. })
  1528. }
  1529. }
  1530. },
  1531. 'mirroring.create_new_dataset': {
  1532. 'real': '/falcon/entities/submitAndSchedule/feed',
  1533. 'mock': '/data/mirroring/succeeded.json',
  1534. 'type': 'POST',
  1535. 'format': function (data) {
  1536. return {
  1537. contentType: 'text/xml',
  1538. data: data.dataset
  1539. }
  1540. }
  1541. },
  1542. 'jobs.tezDag.NametoID': {
  1543. 'real': '/proxy?url=http://{historyServerHostName}:8188/ws/v1/apptimeline/TEZ_DAG_ID?primaryFilter=dagName:{tezDagName}',
  1544. 'mock': '/data/jobs/tezDag-name-to-id.json'
  1545. },
  1546. 'jobs.tezDag.tezDagId': {
  1547. 'real': '/proxy?url=http://{historyServerHostName}:8188/ws/v1/apptimeline/TEZ_DAG_ID/{tezDagId}',
  1548. 'mock': '/data/jobs/tezDag.json'
  1549. },
  1550. 'jobs.tezDag.tezDagVertexId': {
  1551. 'real': '/proxy?url=http://{historyServerHostName}:8188/ws/v1/apptimeline/TEZ_VERTEX_ID/{tezDagVertexId}',
  1552. 'mock': '/data/jobs/tezDagVertex.json'
  1553. }
  1554. };
  1555. /**
  1556. * Replace data-placeholders to its values
  1557. *
  1558. * @param {String} url
  1559. * @param {Object} data
  1560. * @return {String}
  1561. */
  1562. var formatUrl = function (url, data) {
  1563. if (!url) return null;
  1564. var keys = url.match(/\{\w+\}/g);
  1565. keys = (keys === null) ? [] : keys;
  1566. if (keys) {
  1567. keys.forEach(function (key) {
  1568. var raw_key = key.substr(1, key.length - 2);
  1569. var replace;
  1570. if (!data || !data[raw_key]) {
  1571. replace = '';
  1572. }
  1573. else {
  1574. replace = data[raw_key];
  1575. }
  1576. url = url.replace(new RegExp(key, 'g'), replace);
  1577. });
  1578. }
  1579. return url;
  1580. };
  1581. /**
  1582. * this = object from config
  1583. * @return {Object}
  1584. */
  1585. var formatRequest = function (data) {
  1586. var opt = {
  1587. type: this.type || 'GET',
  1588. timeout: App.timeout,
  1589. dataType: 'json',
  1590. statusCode: require('data/statusCodes')
  1591. };
  1592. if (App.testMode) {
  1593. opt.url = formatUrl(this.mock ? this.mock : '', data);
  1594. opt.type = 'GET';
  1595. }
  1596. else {
  1597. opt.url = App.apiPrefix + formatUrl(this.real, data);
  1598. }
  1599. if (this.format) {
  1600. jQuery.extend(opt, this.format(data, opt));
  1601. }
  1602. return opt;
  1603. };
  1604. /**
  1605. * Wrapper for all ajax requests
  1606. *
  1607. * @type {Object}
  1608. */
  1609. var ajax = Em.Object.extend({
  1610. /**
  1611. * Send ajax request
  1612. *
  1613. * @param {Object} config
  1614. * @return Object jquery ajax object
  1615. *
  1616. * config fields:
  1617. * name - url-key in the urls-object *required*
  1618. * sender - object that send request (need for proper callback initialization) *required*
  1619. * data - object with data for url-format
  1620. * beforeSend - method-name for ajax beforeSend response callback
  1621. * success - method-name for ajax success response callback
  1622. * error - method-name for ajax error response callback
  1623. * callback - callback from <code>App.updater.run</code> library
  1624. */
  1625. send: function (config) {
  1626. console.warn('============== ajax ==============', config.name, config.data);
  1627. if (!config.sender) {
  1628. console.warn('Ajax sender should be defined!');
  1629. return null;
  1630. }
  1631. // default parameters
  1632. var params = {
  1633. clusterName: App.get('clusterName')
  1634. };
  1635. // extend default parameters with provided
  1636. if (config.data) {
  1637. jQuery.extend(params, config.data);
  1638. }
  1639. var opt = {};
  1640. if (!urls[config.name]) {
  1641. console.warn('Invalid name provided!');
  1642. return null;
  1643. }
  1644. opt = formatRequest.call(urls[config.name], params);
  1645. opt.context = this;
  1646. // object sender should be provided for processing beforeSend, success and error responses
  1647. opt.beforeSend = function (xhr) {
  1648. if (config.beforeSend) {
  1649. config.sender[config.beforeSend](opt, xhr, params);
  1650. }
  1651. };
  1652. opt.success = function (data) {
  1653. console.log("TRACE: The url is: " + opt.url);
  1654. if (config.success) {
  1655. config.sender[config.success](data, opt, params);
  1656. }
  1657. };
  1658. opt.error = function (request, ajaxOptions, error) {
  1659. if (config.error) {
  1660. config.sender[config.error](request, ajaxOptions, error, opt);
  1661. } else {
  1662. this.defaultErrorHandler(request, opt.url, opt.type);
  1663. }
  1664. };
  1665. opt.complete = function () {
  1666. if (config.callback) {
  1667. config.callback();
  1668. }
  1669. };
  1670. if ($.mocho) {
  1671. opt.url = 'http://' + $.hostName + opt.url;
  1672. }
  1673. return $.ajax(opt);
  1674. },
  1675. // A single instance of App.ModalPopup view
  1676. modalPopup: null,
  1677. /**
  1678. * defaultErrorHandler function is referred from App.ajax.send function and App.HttpClient.defaultErrorHandler function
  1679. * @jqXHR {jqXHR Object}
  1680. * @url {string}
  1681. * @method {String} Http method
  1682. * @showStatus {number} HTTP response code which should be shown. Default is 500.
  1683. */
  1684. defaultErrorHandler: function (jqXHR, url, method, showStatus) {
  1685. method = method || 'GET';
  1686. var self = this;
  1687. var api = " received on " + method + " method for API: " + url;
  1688. var showMessage = true;
  1689. try {
  1690. var json = $.parseJSON(jqXHR.responseText);
  1691. var message = json.message;
  1692. } catch (err) {
  1693. }
  1694. if (showStatus === null) {
  1695. showStatus = 500;
  1696. }
  1697. if (message === undefined) {
  1698. showMessage = false;
  1699. }
  1700. var statusCode = jqXHR.status + " status code";
  1701. if (jqXHR.status === showStatus && !this.modalPopup) {
  1702. this.modalPopup = App.ModalPopup.show({
  1703. header: jqXHR.statusText,
  1704. secondary: false,
  1705. onPrimary: function () {
  1706. this.hide();
  1707. self.modalPopup = null;
  1708. },
  1709. bodyClass: Ember.View.extend({
  1710. classNames: ['api-error'],
  1711. templateName: require('templates/utils/ajax'),
  1712. api: api,
  1713. statusCode: statusCode,
  1714. message: message,
  1715. showMessage: showMessage
  1716. })
  1717. });
  1718. }
  1719. }
  1720. });
  1721. /**
  1722. * Add few access-methods for test purposes
  1723. */
  1724. if ($.mocho) {
  1725. ajax.reopen({
  1726. /**
  1727. * Don't use it anywhere except tests!
  1728. * @returns {Array}
  1729. */
  1730. fakeGetUrlNames: function() {
  1731. return Em.keys(urls);
  1732. },
  1733. /**
  1734. * Don't use it anywhere except tests!
  1735. * @param name
  1736. * @returns {*}
  1737. */
  1738. fakeGetUrl: function(name) {
  1739. return urls[name];
  1740. },
  1741. /**
  1742. * Don't use it anywhere except tests!
  1743. * @param url
  1744. * @param data
  1745. * @returns {String}
  1746. */
  1747. fakeFormatUrl: function(url, data) {
  1748. return formatUrl(url, data);
  1749. },
  1750. /**
  1751. * Don't use it anywhere except tests!
  1752. * @param urlObj
  1753. * @param data
  1754. * @returns {Object}
  1755. */
  1756. fakeFormatRequest: function(urlObj, data) {
  1757. return formatRequest.call(urlObj, data);
  1758. }
  1759. });
  1760. }
  1761. App.ajax = ajax.create({});