ajax.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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. 'background_operations': {
  33. 'real': '/clusters/{clusterName}/requests/?fields=tasks/*',
  34. 'mock': '/data/background_operations/list_on_start.json',
  35. 'testInProduction': true
  36. },
  37. 'background_operations.update_task': {
  38. 'real': '/clusters/{clusterName}/requests/{requestId}/tasks/{taskId}',
  39. 'mock': '/data/background_operations/one_task.json',
  40. 'testInProduction': true
  41. },
  42. 'background_operations.get_most_recent': {
  43. 'real': '/clusters/{clusterName}/requests?to=end&page_size=10&fields=*,tasks/Tasks/*',
  44. 'mock': '/data/background_operations/list_on_start.json',
  45. 'testInProduction': true
  46. },
  47. 'service.item.start_stop': {
  48. 'real': '/clusters/{clusterName}/services/{serviceName}?params/run_smoke_test=true',
  49. 'mock': '/data/wizard/deploy/poll_1.json',
  50. 'format': function (data, opt) {
  51. return {
  52. type: 'PUT',
  53. data: JSON.stringify({
  54. RequestInfo: {
  55. "context": data.requestInfo
  56. },
  57. Body: {
  58. ServiceInfo: {
  59. state: data.state
  60. }
  61. }
  62. })
  63. };
  64. }
  65. },
  66. 'service.item.smoke': {
  67. 'real': '/clusters/{clusterName}/services/{serviceName}/actions/{actionName}',
  68. 'mock': '/data/wizard/deploy/poll_1.json',
  69. 'format': function (data) {
  70. return {
  71. 'type': 'POST',
  72. data: JSON.stringify({
  73. RequestInfo: {
  74. "context": data.displayName + " Smoke Test"
  75. }
  76. })
  77. };
  78. }
  79. },
  80. 'reassign.stop_service': {
  81. 'mock': '/data/wizard/reassign/request_id.json',
  82. 'real': '/clusters/{clusterName}/services/{serviceName}',
  83. 'type': 'PUT',
  84. 'format': function (data) {
  85. return {
  86. data: JSON.stringify({
  87. RequestInfo: {
  88. "context": "Stop service " + data.displayName
  89. },
  90. Body: {
  91. ServiceInfo: {
  92. "state": "INSTALLED"
  93. }
  94. }
  95. })
  96. }
  97. }
  98. },
  99. 'reassign.create_master': {
  100. 'real': '/clusters/{clusterName}/hosts?Hosts/host_name={hostName}',
  101. 'type': 'POST',
  102. 'format': function (data) {
  103. return {
  104. data: JSON.stringify({
  105. "host_components": [
  106. {
  107. "HostRoles": {
  108. "component_name": data.componentName
  109. }
  110. }
  111. ]
  112. })
  113. }
  114. }
  115. },
  116. 'reassign.maintenance_mode': {
  117. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  118. 'type': 'PUT',
  119. 'format': function () {
  120. return {
  121. data: JSON.stringify(
  122. {
  123. "HostRoles": {
  124. "state": "MAINTENANCE"
  125. }
  126. }
  127. )
  128. }
  129. }
  130. },
  131. 'reassign.install_component': {
  132. 'mock': '/data/wizard/reassign/request_id.json',
  133. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  134. 'type': 'PUT',
  135. 'format': function (data) {
  136. return {
  137. data: JSON.stringify({
  138. RequestInfo: {
  139. "context": "Install " + data.displayName
  140. },
  141. Body: {
  142. "HostRoles": {
  143. "state": "INSTALLED"
  144. }
  145. }
  146. })
  147. }
  148. }
  149. },
  150. 'reassign.start_components': {
  151. 'mock': '/data/wizard/reassign/request_id.json',
  152. 'real': '/clusters/{clusterName}/services/{serviceName}',
  153. 'type': 'PUT',
  154. 'format': function (data) {
  155. return {
  156. data: JSON.stringify({
  157. RequestInfo: {
  158. "context": "Start service " + data.displayName
  159. },
  160. Body: {
  161. ServiceInfo: {
  162. "state": "STARTED"
  163. }
  164. }
  165. })
  166. }
  167. }
  168. },
  169. 'reassign.remove_component': {
  170. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  171. 'type': 'DELETE'
  172. },
  173. 'reassign.get_logs': {
  174. 'real': '/clusters/{clusterName}/requests/{requestId}?fields=tasks/*',
  175. 'mock': '/data/wizard/reassign/step14PolledData/tasks_poll{pollCounter}.json',
  176. 'type': 'GET'
  177. },
  178. 'reassign.create_configs': {
  179. 'real': '/clusters/{clusterName}/configurations',
  180. 'type': 'POST',
  181. 'format': function (data) {
  182. return {
  183. data: JSON.stringify(data.configs),
  184. configs: data.configs
  185. }
  186. }
  187. },
  188. 'reassign.check_configs': {
  189. 'real': '/clusters/{clusterName}/services/{serviceName}',
  190. 'type': 'GET'
  191. },
  192. 'reassign.apply_configs': {
  193. 'real': '/clusters/{clusterName}/services/{serviceName}',
  194. 'type': 'PUT',
  195. 'format': function (data) {
  196. return {
  197. data: JSON.stringify(data.configs)
  198. }
  199. }
  200. },
  201. 'config.advanced': {
  202. 'real': '{stack2VersionUrl}/stackServices/{serviceName}/configurations?fields=*',
  203. 'mock': '/data/wizard/stack/hdp/version{stackVersion}/{serviceName}.json',
  204. 'format': function (data) {
  205. return {
  206. async: false
  207. };
  208. }
  209. },
  210. 'config.advanced.global': {
  211. 'real': '{stack2VersionUrl}/stackServices?fields=configurations/StackConfigurations/type',
  212. 'mock': '/data/wizard/stack/hdp/version1.3.0/global.json',
  213. 'format': function (data) {
  214. return {
  215. async: false
  216. };
  217. }
  218. },
  219. 'config.tags': {
  220. 'real': '/clusters/{clusterName}',
  221. 'mock': '/data/clusters/cluster.json'
  222. },
  223. 'config.on_site': {
  224. 'real': '/clusters/{clusterName}/configurations?{params}',
  225. 'mock': '/data/configurations/cluster_level_configs.json?{params}',
  226. 'format': function (data) {
  227. return {
  228. async: false
  229. };
  230. }
  231. },
  232. 'config.host_overrides': {
  233. 'real': '/clusters/{clusterName}/configurations?{params}',
  234. 'mock': '/data/configurations/host_level_overrides_configs.json?{params}',
  235. 'format': function (data) {
  236. return {
  237. async: false
  238. };
  239. }
  240. },
  241. 'service.metrics.flume.channel_fill_percent': {
  242. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/CHANNEL/*/ChannelFillPercentage[{fromSeconds},{toSeconds},{stepSeconds}]',
  243. 'mock': '/data/services/metrics/flume/channelFillPct.json',
  244. 'testInProduction': true
  245. },
  246. 'service.metrics.flume.channel_size': {
  247. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/CHANNEL/*/ChannelSize[{fromSeconds},{toSeconds},{stepSeconds}]',
  248. 'mock': '/data/services/metrics/flume/channelSize.json',
  249. 'testInProduction': true
  250. },
  251. 'service.metrics.flume.sink_drain_success': {
  252. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/SINK/*/EventDrainSuccessCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  253. 'mock': '/data/services/metrics/flume/sinkDrainSuccessCount.json',
  254. 'testInProduction': true
  255. },
  256. 'service.metrics.flume.sink_connection_failed': {
  257. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/SINK/*/ConnectionFailedCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  258. 'mock': '/data/services/metrics/flume/sinkConnectionFailedCount.json',
  259. 'testInProduction': true
  260. },
  261. 'service.metrics.flume.gc': {
  262. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  263. 'mock': '/data/services/metrics/flume/jvmGcTime.json',
  264. 'testInProduction': true
  265. },
  266. 'service.metrics.flume.jvm_heap_used': {
  267. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/jvm/memHeapUsedM[{fromSeconds},{toSeconds},{stepSeconds}]',
  268. 'mock': '/data/services/metrics/flume/jvmMemHeapUsedM.json',
  269. 'testInProduction': true
  270. },
  271. 'service.metrics.flume.jvm_threads_runnable': {
  272. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/jvm/threadsRunnable[{fromSeconds},{toSeconds},{stepSeconds}]',
  273. 'mock': '/data/services/metrics/flume/jvmThreadsRunnable.json',
  274. 'testInProduction': true
  275. },
  276. 'service.metrics.flume.cpu_user': {
  277. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/cpu/cpu_user[{fromSeconds},{toSeconds},{stepSeconds}]',
  278. 'mock': '',
  279. 'testInProduction': true
  280. },
  281. 'service.metrics.flume.source_accepted': {
  282. 'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/SOURCE/*/EventAcceptedCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  283. 'mock': '/data/services/metrics/flume/sourceEventAccepted.json',
  284. 'testInProduction': true
  285. },
  286. 'service.metrics.hbase.cluster_requests': {
  287. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/cluster_requests[{fromSeconds},{toSeconds},{stepSeconds}]',
  288. 'mock': '/data/services/metrics/hbase/cluster_requests.json',
  289. 'testInProduction': true
  290. },
  291. 'service.metrics.hbase.hlog_split_size': {
  292. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/splitSize_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  293. 'mock': '/data/services/metrics/hbase/hlog_split_size.json',
  294. 'testInProduction': true
  295. },
  296. 'service.metrics.hbase.hlog_split_time': {
  297. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/splitTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  298. 'mock': '/data/services/metrics/hbase/hlog_split_time.json',
  299. 'testInProduction': true
  300. },
  301. 'service.metrics.hbase.regionserver_queuesize': {
  302. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/flushQueueSize[{fromSeconds},{toSeconds},{stepSeconds}],metrics/hbase/regionserver/compactionQueueSize[{fromSeconds},{toSeconds},{stepSeconds}]',
  303. 'mock': '/data/services/metrics/hbase/regionserver_queuesize.json',
  304. 'testInProduction': true
  305. },
  306. 'service.metrics.hbase.regionserver_regions': {
  307. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/regions[{fromSeconds},{toSeconds},{stepSeconds}]',
  308. 'mock': '/data/services/metrics/hbase/regionserver_regions.json',
  309. 'testInProduction': true
  310. },
  311. 'service.metrics.hbase.regionserver_rw_requests': {
  312. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/readRequestsCount[{fromSeconds},{toSeconds},{stepSeconds}],metrics/hbase/regionserver/writeRequestsCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  313. 'mock': '/data/services/metrics/hbase/regionserver_rw_requests.json',
  314. 'testInProduction': true
  315. },
  316. 'service.metrics.mapreduce.gc': {
  317. 'real': '/clusters/{clusterName}/hosts/{jobTrackerNode}/host_components/JOBTRACKER?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  318. 'mock': '/data/services/metrics/mapreduce/gc.json',
  319. 'testInProduction': true
  320. },
  321. 'service.metrics.mapreduce.jobs_status': {
  322. '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}]',
  323. 'mock': '/data/services/metrics/mapreduce/jobs_status.json',
  324. 'testInProduction': true
  325. },
  326. 'service.metrics.mapreduce.jobs_heap': {
  327. '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}]',
  328. 'mock': '/data/services/metrics/mapreduce/jvm_heap.json',
  329. 'testInProduction': true
  330. },
  331. 'service.metrics.mapreduce.jobs_threads': {
  332. '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}]',
  333. 'mock': '/data/services/metrics/mapreduce/jvm_threads.json',
  334. 'testInProduction': true
  335. },
  336. 'service.metrics.mapreduce.map_slots': {
  337. '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}]',
  338. 'mock': '/data/services/metrics/mapreduce/map_slots.json',
  339. 'testInProduction': true
  340. },
  341. 'service.metrics.mapreduce.reduce_slots': {
  342. '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}]',
  343. 'mock': '/data/services/metrics/mapreduce/reduce_slots.json',
  344. 'testInProduction': true
  345. },
  346. 'service.metrics.mapreduce.rpc': {
  347. 'real': '/clusters/{clusterName}/hosts/{jobTrackerNode}/host_components/JOBTRACKER?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  348. 'mock': '/data/services/metrics/mapreduce/rpc.json',
  349. 'testInProduction': true
  350. },
  351. 'service.metrics.mapreduce.tasks_running_waiting': {
  352. '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}]',
  353. 'mock': '/data/services/metrics/mapreduce/tasks_running_waiting.json',
  354. 'testInProduction': true
  355. },
  356. 'service.metrics.hdfs.block_status': {
  357. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/dfs/FSNamesystem/PendingReplicationBlocks[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/FSNamesystem/UnderReplicatedBlocks[{fromSeconds},{toSeconds},{stepSeconds}]',
  358. 'mock': '/data/services/metrics/hdfs/block_status.json',
  359. 'testInProduction': true
  360. },
  361. 'service.metrics.hdfs.file_operations': {
  362. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/dfs/namenode/FileInfoOps[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/namenode/CreateFileOps[{fromSeconds},{toSeconds},{stepSeconds}]',
  363. 'mock': '/data/services/metrics/hdfs/file_operations.json',
  364. 'testInProduction': true
  365. },
  366. 'service.metrics.hdfs.gc': {
  367. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  368. 'mock': '/data/services/metrics/hdfs/gc.json',
  369. 'testInProduction': true
  370. },
  371. 'service.metrics.hdfs.io': {
  372. 'real': '/clusters/{clusterName}/services/HDFS/components/DATANODE?fields=metrics/dfs/datanode/bytes_written[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/datanode/bytes_read[{fromSeconds},{toSeconds},{stepSeconds}]',
  373. 'mock': '/data/services/metrics/hdfs/io.json',
  374. 'testInProduction': true
  375. },
  376. 'service.metrics.hdfs.jvm_heap': {
  377. '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}]',
  378. 'mock': '/data/services/metrics/hdfs/jvm_heap.json',
  379. 'testInProduction': true
  380. },
  381. 'service.metrics.hdfs.jvm_threads': {
  382. '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}]',
  383. 'mock': '/data/services/metrics/hdfs/jvm_threads.json',
  384. 'testInProduction': true
  385. },
  386. 'service.metrics.hdfs.rpc': {
  387. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  388. 'mock': '/data/services/metrics/hdfs/rpc.json',
  389. 'testInProduction': true
  390. },
  391. 'service.metrics.hdfs.space_utilization': {
  392. '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}]',
  393. 'mock': '/data/services/metrics/hdfs/space_utilization.json',
  394. 'testInProduction': true
  395. },
  396. 'service.start_stop': {
  397. 'real': '/clusters/{clusterName}/services?ServiceInfo',
  398. 'mock': '/data/mirroring/poll/poll_6.json',
  399. 'format': function (data, opt) {
  400. return {
  401. type: 'PUT',
  402. async: false,
  403. data: data.data
  404. };
  405. }
  406. },
  407. 'service.metrics.yarn.gc': {
  408. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  409. 'mock': '/data/services/metrics/yarn/gc.json',
  410. 'testInProduction': true
  411. },
  412. 'service.metrics.yarn.jobs_threads': {
  413. '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}]',
  414. 'mock': '/data/services/metrics/yarn/jvm_threads.json',
  415. 'testInProduction': true
  416. },
  417. 'service.metrics.yarn.rpc': {
  418. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  419. 'mock': '/data/services/metrics/yarn/rpc.json',
  420. 'testInProduction': true
  421. },
  422. 'service.metrics.yarn.jobs_heap': {
  423. '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}]',
  424. 'mock': '/data/services/metrics/yarn/jvm_heap.json',
  425. 'testInProduction': true
  426. },
  427. 'service.metrics.yarn.queue.allocated': {
  428. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/yarn/Queue/AvailableMB[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/PendingMB[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/AllocatedMB[{fromSeconds},{toSeconds},{stepSeconds}]',
  429. 'mock': '',
  430. 'testInProduction': true
  431. },
  432. 'service.metrics.yarn.queue.allocated.container': {
  433. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=metrics/yarn/Queue/AllocatedContainers[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/ReservedContainers[{fromSeconds},{toSeconds},{stepSeconds}],metrics/yarn/Queue/PendingContainers[{fromSeconds},{toSeconds},{stepSeconds}]',
  434. 'mock': '',
  435. 'testInProduction': true
  436. },
  437. 'service.metrics.yarn.node.manager.statuses': {
  438. '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}]',
  439. 'mock': '',
  440. 'testInProduction': true
  441. },
  442. 'service.metrics.yarn.queue.memory.resource': {
  443. 'real': '/clusters/{clusterName}/hosts/{resourceManager}/host_components/RESOURCEMANAGER?fields=',
  444. 'mock': '',
  445. 'format': function (data, opt) {
  446. var field1 = 'metrics/yarn/Queue/{queueName}/AllocatedMB[{fromSeconds},{toSeconds},{stepSeconds}]';
  447. var field2 = 'metrics/yarn/Queue/{queueName}/AvailableMB[{fromSeconds},{toSeconds},{stepSeconds}]';
  448. if (opt.url != null && data.queueNames != null) {
  449. data.queueNames.forEach(function (q) {
  450. data.queueName = q;
  451. opt.url += (formatUrl(field1, data) + ",");
  452. opt.url += (formatUrl(field2, data) + ",");
  453. });
  454. }
  455. },
  456. 'testInProduction': true
  457. },
  458. 'dashboard.cluster_metrics.cpu': {
  459. 'real': '/clusters/{clusterName}/?fields=metrics/cpu[{fromSeconds},{toSeconds},{stepSeconds}]',
  460. 'mock': '/data/cluster_metrics/cpu_1hr.json',
  461. 'testInProduction': true
  462. },
  463. 'dashboard.cluster_metrics.load': {
  464. 'real': '/clusters/{clusterName}/?fields=metrics/load[{fromSeconds},{toSeconds},{stepSeconds}]',
  465. 'mock': '/data/cluster_metrics/load_1hr.json',
  466. 'testInProduction': true
  467. },
  468. 'dashboard.cluster_metrics.memory': {
  469. 'real': '/clusters/{clusterName}/?fields=metrics/memory[{fromSeconds},{toSeconds},{stepSeconds}]',
  470. 'mock': '/data/cluster_metrics/memory_1hr.json',
  471. 'testInProduction': true
  472. },
  473. 'dashboard.cluster_metrics.network': {
  474. 'real': '/clusters/{clusterName}/?fields=metrics/network[{fromSeconds},{toSeconds},{stepSeconds}]',
  475. 'mock': '/data/cluster_metrics/network_1hr.json',
  476. 'testInProduction': true
  477. },
  478. 'host.metrics.cpu': {
  479. '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}]',
  480. 'mock': '/data/hosts/metrics/cpu.json',
  481. 'testInProduction': true
  482. },
  483. 'host.metrics.disk': {
  484. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/disk/disk_total[{fromSeconds},{toSeconds},{stepSeconds}],metrics/disk/disk_free[{fromSeconds},{toSeconds},{stepSeconds}]',
  485. 'mock': '/data/hosts/metrics/disk.json',
  486. 'testInProduction': true
  487. },
  488. 'host.metrics.load': {
  489. '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}]',
  490. 'mock': '/data/hosts/metrics/load.json',
  491. 'testInProduction': true
  492. },
  493. 'host.metrics.memory': {
  494. '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}]',
  495. 'mock': '/data/hosts/metrics/memory.json',
  496. 'testInProduction': true
  497. },
  498. 'host.metrics.network': {
  499. '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}]',
  500. 'mock': '/data/hosts/metrics/network.json',
  501. 'testInProduction': true
  502. },
  503. 'host.metrics.processes': {
  504. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/process/proc_total[{fromSeconds},{toSeconds},{stepSeconds}],metrics/process/proc_run[{fromSeconds},{toSeconds},{stepSeconds}]',
  505. 'mock': '/data/hosts/metrics/processes.json',
  506. 'testInProduction': true
  507. },
  508. 'host.service_config_hosts_overrides': {
  509. 'real': '/clusters/{clusterName}/configurations?{urlParams}',
  510. 'format': function (data, opt) {
  511. return {
  512. async: false,
  513. timeout: 10000
  514. };
  515. }
  516. },
  517. 'admin.service_config': {
  518. 'real': '/clusters/{clusterName}/configurations/?type={siteName}&tag={tagName}',
  519. 'format': function (data, opt) {
  520. return {
  521. timeout: 10000,
  522. async: false
  523. };
  524. }
  525. },
  526. 'admin.security_status': {
  527. 'real': '/clusters/{clusterName}',
  528. 'format': function (data, opt) {
  529. return {
  530. async: false,
  531. timeout: 10000
  532. };
  533. }
  534. },
  535. 'cluster.load_cluster_name': {
  536. 'real': '/clusters',
  537. 'mock': '/data/clusters/info.json',
  538. 'format': function (data, opt) {
  539. return {
  540. async: false
  541. };
  542. }
  543. },
  544. 'cluster.state': {
  545. 'type': 'POST',
  546. 'real': '/persist/',
  547. 'format': function (data, opt) {
  548. return {
  549. async: false,
  550. data: JSON.stringify(data.key),
  551. newValue: data.newVal
  552. };
  553. }
  554. },
  555. 'cluster.update_upgrade_version': {
  556. 'real': '/stacks2/HDP/versions?fields=stackServices/StackServices,Versions',
  557. 'mock': '/data/wizard/stack/stacks.json',
  558. 'format': function (data, opt) {
  559. return {
  560. async: false
  561. };
  562. }
  563. },
  564. 'admin.high_availability.stop_all_services': {
  565. 'real': '/clusters/{clusterName}/services?ServiceInfo/state=STARTED',
  566. 'mock': 'fsdfs',
  567. 'format': function (data, opt) {
  568. return {
  569. type: 'PUT',
  570. data: JSON.stringify({
  571. "RequestInfo": {
  572. "context": "Stop all services"
  573. },
  574. "Body": {
  575. "ServiceInfo": {
  576. "state": "INSTALLED"
  577. }
  578. }
  579. })
  580. }
  581. }
  582. },
  583. 'admin.high_availability.polling': {
  584. 'real': '/clusters/{clusterName}/requests/{requestId}?fields=tasks/*',
  585. 'mock': '',
  586. 'type': 'GET'
  587. },
  588. 'admin.high_availability.create_component': {
  589. 'real': '/clusters/{clusterName}/hosts?Hosts/host_name={hostName}',
  590. 'mock': '',
  591. 'type': 'POST',
  592. 'format': function (data) {
  593. return {
  594. data: JSON.stringify({
  595. "host_components": [
  596. {
  597. "HostRoles": {
  598. "component_name": data.componentName
  599. }
  600. }
  601. ]
  602. })
  603. }
  604. }
  605. },
  606. 'admin.high_availability.install_component': {
  607. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  608. 'type': 'PUT',
  609. 'format': function (data) {
  610. return {
  611. data: JSON.stringify({
  612. RequestInfo: {
  613. "context": "Install " + data.displayName
  614. },
  615. Body: {
  616. "HostRoles": {
  617. "state": "INSTALLED"
  618. }
  619. }
  620. })
  621. }
  622. }
  623. },
  624. 'admin.high_availability.start_component': {
  625. 'real': '/clusters/{clusterName}/services/{serviceName}',
  626. 'type': 'PUT',
  627. 'format': function (data) {
  628. return {
  629. data: JSON.stringify({
  630. RequestInfo: {
  631. "context": "Start service " + data.displayName
  632. },
  633. Body: {
  634. ServiceInfo: {
  635. "state": "STARTED"
  636. }
  637. }
  638. })
  639. }
  640. }
  641. },
  642. 'admin.high_availability.maintenance_mode': {
  643. 'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
  644. 'type': 'PUT',
  645. 'format': function () {
  646. return {
  647. data: {
  648. "HostRoles": {
  649. "state": "MAINTENANCE"
  650. }
  651. }
  652. }
  653. }
  654. },
  655. 'admin.security.cluster_configs': {
  656. 'real': '/clusters/{clusterName}',
  657. 'format': function (data, opt) {
  658. return {
  659. timeout: 10000
  660. };
  661. }
  662. },
  663. 'admin.security.all_configurations': {
  664. 'real': '/clusters/{clusterName}/configurations?{urlParams}',
  665. 'format': function (data, opt) {
  666. return {
  667. timeout: 10000
  668. };
  669. }
  670. },
  671. 'admin.security.apply_configuration': {
  672. 'real': '/clusters/{clusterName}',
  673. 'format': function (data, opt) {
  674. return {
  675. type: 'PUT',
  676. async: false,
  677. timeout: 5000,
  678. data: JSON.stringify(data.clusterData)
  679. };
  680. }
  681. },
  682. 'admin.security.add.cluster_configs': {
  683. 'real': '/clusters/{clusterName}',
  684. 'format': function (data, opt) {
  685. return {
  686. timeout: 10000
  687. };
  688. }
  689. },
  690. 'admin.stack_upgrade.run_upgrade': {
  691. 'real': '/clusters/{clusterName}',
  692. 'format': function (data, opt) {
  693. return {
  694. type: 'PUT',
  695. async: false,
  696. data: data.data
  697. };
  698. }
  699. },
  700. 'admin.stack_upgrade.stop_services': {
  701. 'real': '/clusters/{clusterName}/services?ServiceInfo/state=STARTED',
  702. 'format': function (data, opt) {
  703. return {
  704. type: 'PUT',
  705. async: false,
  706. data: data.data
  707. };
  708. }
  709. },
  710. 'admin.stack_upgrade.do_poll': {
  711. 'real': '/clusters/{cluster}/requests/{requestId}?fields=tasks/*',
  712. 'mock': '/data/wizard/{mock}'
  713. },
  714. 'wizard.install_services.add_host_controller.is_retry': {
  715. 'real': '/clusters/{cluster}/host_components',
  716. 'format': function (data, opt) {
  717. return {
  718. type: 'PUT',
  719. async: false,
  720. data: data.data
  721. };
  722. }
  723. },
  724. 'wizard.install_services.add_host_controller.not_is_retry': {
  725. 'real': '/clusters/{cluster}/host_components',
  726. 'format': function (data, opt) {
  727. return {
  728. type: 'PUT',
  729. async: false,
  730. data: data.data
  731. };
  732. }
  733. },
  734. 'wizard.install_services.installer_controller.is_retry': {
  735. 'real': '/clusters/{cluster}/host_components?HostRoles/state=INSTALLED',
  736. 'mock': '/data/wizard/deploy/2_hosts/poll_1.json',
  737. 'type': 'PUT',
  738. 'format': function (data, opt) {
  739. return {
  740. async: false,
  741. data: data.data
  742. };
  743. }
  744. },
  745. 'wizard.install_services.installer_controller.not_is_retry': {
  746. 'real': '/clusters/{cluster}/services?ServiceInfo/state=INIT',
  747. 'mock': '/data/wizard/deploy/2_hosts/poll_1.json',
  748. 'type': 'PUT',
  749. 'format': function (data, opt) {
  750. return {
  751. async: false,
  752. data: data.data
  753. };
  754. }
  755. },
  756. 'wizard.service_components': {
  757. 'real': '{stackUrl}/stackServices?fields=StackServices',
  758. 'mock': '/data/wizard/stack/hdp/version/{stackVersion}.json',
  759. 'format': function (data, opt) {
  760. return {
  761. timeout: 10000,
  762. async: false
  763. };
  764. }
  765. },
  766. 'wizard.step9.installer.launch_start_services': {
  767. 'real': '/clusters/{cluster}/services?ServiceInfo/state=INSTALLED&params/run_smoke_test=true&params/reconfigure_client=false',
  768. 'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
  769. 'format': function (data, opt) {
  770. var data = {
  771. type: 'PUT',
  772. async: false,
  773. data: data.data
  774. };
  775. if (App.testMode) {
  776. data.type = 'GET';
  777. }
  778. return data;
  779. }
  780. },
  781. 'wizard.step9.add_host.launch_start_services': {
  782. 'real': '/clusters/{cluster}/host_components',
  783. 'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
  784. 'format': function (data, opt) {
  785. return {
  786. type: 'PUT',
  787. async: false,
  788. data: data.data
  789. };
  790. }
  791. },
  792. 'wizard.step8.delete_cluster': {
  793. 'real': '/clusters/{name}',
  794. 'format': function (data, opt) {
  795. return {
  796. type: 'DELETE',
  797. async: false
  798. };
  799. }
  800. },
  801. 'wizard.step8.existing_cluster_names': {
  802. 'real': '/clusters',
  803. 'format': function (data, opt) {
  804. return {
  805. async: false
  806. };
  807. }
  808. },
  809. 'wizard.step3.host_info': {
  810. 'real': '/hosts?fields=Hosts/total_mem,Hosts/cpu_count,Hosts/disk_info,Hosts/last_agent_env,Hosts/host_name',
  811. 'mock': '/data/wizard/bootstrap/two_hosts_information.json',
  812. 'format': function (data, opt) {
  813. return {
  814. contentType: 'application/json'
  815. };
  816. }
  817. },
  818. 'wizard.step3.rerun_checks': {
  819. 'real': '/hosts?fields=Hosts/last_agent_env',
  820. 'mock': '/data/wizard/bootstrap/two_hosts_information.json',
  821. 'format': function (data, opt) {
  822. return {
  823. contentType: 'application/json'
  824. };
  825. }
  826. },
  827. 'wizard.step3.bootstrap': {
  828. 'real': '/bootstrap/{bootRequestId}',
  829. 'mock': '/data/wizard/bootstrap/poll_{numPolls}.json'
  830. },
  831. 'wizard.step3.is_hosts_registered': {
  832. 'real': '/hosts',
  833. 'mock': '/data/wizard/bootstrap/single_host_registration.json'
  834. },
  835. 'wizard.stacks': {
  836. 'real': '/stacks2',
  837. 'mock': '/data/wizard/stack/stacks2.json',
  838. 'format': function (data) {
  839. return {
  840. async: false
  841. };
  842. }
  843. },
  844. 'wizard.stacks_versions': {
  845. 'real': '/stacks2/{stackName}/versions?fields=Versions,operatingSystems/repositories/Repositories',
  846. 'mock': '/data/wizard/stack/{stackName}_versions.json',
  847. 'format': function (data) {
  848. return {
  849. async: false
  850. };
  851. }
  852. },
  853. 'wizard.launch_bootstrap': {
  854. 'real': '/bootstrap',
  855. 'mock': '/data/wizard/bootstrap/bootstrap.json',
  856. 'type': 'POST',
  857. 'format': function (data) {
  858. return {
  859. async: false,
  860. contentType: 'application/json',
  861. data: data.bootStrapData
  862. }
  863. }
  864. },
  865. 'router.login': {
  866. 'real': '/users/{loginName}',
  867. 'mock': '/data/users/user_{usr}.json',
  868. 'format': function (data, opt) {
  869. var statusCode = jQuery.extend({}, require('data/statusCodes'));
  870. statusCode['403'] = function () {
  871. console.log("Error code 403: Forbidden.");
  872. }
  873. return {
  874. statusCode: statusCode
  875. };
  876. }
  877. },
  878. 'router.login2': {
  879. 'real': '/clusters',
  880. 'mock': '/data/clusters/info.json'
  881. },
  882. 'router.logoff': {
  883. 'real': '/logout'
  884. },
  885. 'router.set_ambari_stacks': {
  886. 'real': '/stacks',
  887. 'mock': '/data/wizard/stack/stacks.json',
  888. 'format': function (data, opt) {
  889. return {
  890. async: false
  891. };
  892. }
  893. },
  894. 'router.authentication': {
  895. 'real': '/clusters',
  896. 'mock': '/data/clusters/info.json',
  897. 'format': function (data, opt) {
  898. return {
  899. async: false
  900. };
  901. }
  902. }
  903. };
  904. /**
  905. * Replace data-placeholders to its values
  906. *
  907. * @param {String} url
  908. * @param {Object} data
  909. * @return {String}
  910. */
  911. var formatUrl = function (url, data) {
  912. var keys = url.match(/\{\w+\}/g);
  913. keys = (keys === null) ? [] : keys;
  914. if (keys) {
  915. keys.forEach(function (key) {
  916. var raw_key = key.substr(1, key.length - 2);
  917. var replace;
  918. if (!data[raw_key]) {
  919. replace = '';
  920. }
  921. else {
  922. replace = data[raw_key];
  923. }
  924. url = url.replace(new RegExp(key, 'g'), replace);
  925. });
  926. }
  927. return url;
  928. };
  929. /**
  930. * this = object from config
  931. * @return {Object}
  932. */
  933. var formatRequest = function (data) {
  934. var opt = {
  935. type: this.type || 'GET',
  936. timeout: App.timeout,
  937. dataType: 'json',
  938. statusCode: require('data/statusCodes')
  939. };
  940. if (App.testMode) {
  941. opt.url = formatUrl(this.mock, data);
  942. opt.type = 'GET';
  943. }
  944. else {
  945. opt.url = App.apiPrefix + formatUrl(this.real, data);
  946. }
  947. if (this.format) {
  948. jQuery.extend(opt, this.format(data, opt));
  949. }
  950. return opt;
  951. };
  952. /**
  953. * Wrapper for all ajax requests
  954. *
  955. * @type {Object}
  956. */
  957. App.ajax = {
  958. /**
  959. * Send ajax request
  960. *
  961. * @param {Object} config
  962. * @return Object jquery ajax object
  963. *
  964. * config fields:
  965. * name - url-key in the urls-object *required*
  966. * sender - object that send request (need for proper callback initialization) *required*
  967. * data - object with data for url-format
  968. * beforeSend - method-name for ajax beforeSend response callback
  969. * success - method-name for ajax success response callback
  970. * error - method-name for ajax error response callback
  971. * callback - callback from <code>App.updater.run</code> library
  972. */
  973. send: function (config) {
  974. console.warn('============== ajax ==============', config.name, config.data);
  975. if (!config.sender) {
  976. console.warn('Ajax sender should be defined!');
  977. return null;
  978. }
  979. // default parameters
  980. var params = {
  981. clusterName: App.get('clusterName')
  982. };
  983. // extend default parameters with provided
  984. if (config.data) {
  985. jQuery.extend(params, config.data);
  986. }
  987. var opt = {};
  988. opt = formatRequest.call(urls[config.name], params);
  989. // object sender should be provided for processing beforeSend, success and error responses
  990. opt.beforeSend = function (xhr) {
  991. if (config.beforeSend) {
  992. config.sender[config.beforeSend](opt, xhr, params);
  993. }
  994. };
  995. opt.success = function (data) {
  996. console.log("TRACE: The url is: " + opt.url);
  997. if (config.success) {
  998. config.sender[config.success](data, opt, params);
  999. }
  1000. };
  1001. opt.error = function (request, ajaxOptions, error) {
  1002. if (config.error) {
  1003. config.sender[config.error](request, ajaxOptions, error, opt);
  1004. }
  1005. };
  1006. opt.complete = function () {
  1007. if (config.callback) {
  1008. config.callback();
  1009. }
  1010. };
  1011. if ($.mocho) {
  1012. opt.url = 'http://' + $.hostName + opt.url;
  1013. }
  1014. return $.ajax(opt);
  1015. }
  1016. }