ajax.js 76 KB

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