ajax.js 58 KB

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