ajax.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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?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. 'type': 'GET'
  176. },
  177. 'reassign.create_configs': {
  178. 'real': '/clusters/{clusterName}/configurations',
  179. 'type': 'POST',
  180. 'format': function (data) {
  181. return {
  182. data: JSON.stringify(data.configs),
  183. configs: data.configs
  184. }
  185. }
  186. },
  187. 'reassign.check_configs': {
  188. 'real': '/clusters/{clusterName}/services/{serviceName}',
  189. 'type': 'GET'
  190. },
  191. 'reassign.apply_configs': {
  192. 'real': '/clusters/{clusterName}/services/{serviceName}',
  193. 'type': 'PUT',
  194. 'format': function (data) {
  195. return {
  196. data: JSON.stringify(data.configs)
  197. }
  198. }
  199. },
  200. 'config.advanced': {
  201. 'real': '{stack2VersionUrl}/stackServices/{serviceName}/configurations?fields=*',
  202. 'mock': '/data/wizard/stack/hdp/version{stackVersion}/{serviceName}.json',
  203. 'format': function (data) {
  204. return {
  205. async: false
  206. };
  207. }
  208. },
  209. 'config.advanced.global': {
  210. 'real': '{stack2VersionUrl}/stackServices?fields=configurations/StackConfigurations/type',
  211. 'mock': '/data/wizard/stack/hdp/version1.3.0/global.json',
  212. 'format': function (data) {
  213. return {
  214. async: false
  215. };
  216. }
  217. },
  218. 'config.tags': {
  219. 'real': '/clusters/{clusterName}',
  220. 'mock': '/data/clusters/cluster.json'
  221. },
  222. 'config.on-site': {
  223. 'real': '/clusters/{clusterName}/configurations?{params}',
  224. 'mock': '/data/configurations/cluster_level_configs.json?{params}',
  225. 'format': function (data) {
  226. return {
  227. async: false
  228. };
  229. }
  230. },
  231. 'config.host_overrides': {
  232. 'real': '/clusters/{clusterName}/configurations?{params}',
  233. 'mock': '/data/configurations/host_level_overrides_configs.json?{params}',
  234. 'format': function (data) {
  235. return {
  236. async: false
  237. };
  238. }
  239. },
  240. 'service.metrics.hbase.cluster_requests': {
  241. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/cluster_requests[{fromSeconds},{toSeconds},{stepSeconds}]',
  242. 'mock': '/data/services/metrics/hbase/cluster_requests.json',
  243. 'testInProduction': true
  244. },
  245. 'service.metrics.hbase.hlog_split_size': {
  246. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/splitSize_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  247. 'mock': '/data/services/metrics/hbase/hlog_split_size.json',
  248. 'testInProduction': true
  249. },
  250. 'service.metrics.hbase.hlog_split_time': {
  251. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_MASTER?fields=metrics/hbase/master/splitTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  252. 'mock': '/data/services/metrics/hbase/hlog_split_time.json',
  253. 'testInProduction': true
  254. },
  255. 'service.metrics.hbase.regionserver_queuesize': {
  256. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/flushQueueSize[{fromSeconds},{toSeconds},{stepSeconds}],metrics/hbase/regionserver/compactionQueueSize[{fromSeconds},{toSeconds},{stepSeconds}]',
  257. 'mock': '/data/services/metrics/hbase/regionserver_queuesize.json',
  258. 'testInProduction': true
  259. },
  260. 'service.metrics.hbase.regionserver_regions': {
  261. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/regions[{fromSeconds},{toSeconds},{stepSeconds}]',
  262. 'mock': '/data/services/metrics/hbase/regionserver_regions.json',
  263. 'testInProduction': true
  264. },
  265. 'service.metrics.hbase.regionserver_rw_requests': {
  266. 'real': '/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=metrics/hbase/regionserver/readRequestsCount[{fromSeconds},{toSeconds},{stepSeconds}],metrics/hbase/regionserver/writeRequestsCount[{fromSeconds},{toSeconds},{stepSeconds}]',
  267. 'mock': '/data/services/metrics/hbase/regionserver_rw_requests.json',
  268. 'testInProduction': true
  269. },
  270. 'service.metrics.mapreduce.gc': {
  271. 'real': '/clusters/{clusterName}/hosts/{jobTrackerNode}/host_components/JOBTRACKER?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  272. 'mock': '/data/services/metrics/mapreduce/gc.json',
  273. 'testInProduction': true
  274. },
  275. 'service.metrics.mapreduce.jobs_status': {
  276. '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}]',
  277. 'mock': '/data/services/metrics/mapreduce/jobs_status.json',
  278. 'testInProduction': true
  279. },
  280. 'service.metrics.mapreduce.jobs_heap': {
  281. '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}]',
  282. 'mock': '/data/services/metrics/mapreduce/jvm_heap.json',
  283. 'testInProduction': true
  284. },
  285. 'service.metrics.mapreduce.jobs_threads': {
  286. '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}]',
  287. 'mock': '/data/services/metrics/mapreduce/jvm_threads.json',
  288. 'testInProduction': true
  289. },
  290. 'service.metrics.mapreduce.map_slots': {
  291. '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}]',
  292. 'mock': '/data/services/metrics/mapreduce/map_slots.json',
  293. 'testInProduction': true
  294. },
  295. 'service.metrics.mapreduce.reduce_slots': {
  296. '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}]',
  297. 'mock': '/data/services/metrics/mapreduce/reduce_slots.json',
  298. 'testInProduction': true
  299. },
  300. 'service.metrics.mapreduce.rpc': {
  301. 'real': '/clusters/{clusterName}/hosts/{jobTrackerNode}/host_components/JOBTRACKER?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  302. 'mock': '/data/services/metrics/mapreduce/rpc.json',
  303. 'testInProduction': true
  304. },
  305. 'service.metrics.mapreduce.tasks_running_waiting': {
  306. '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}]',
  307. 'mock': '/data/services/metrics/mapreduce/tasks_running_waiting.json',
  308. 'testInProduction': true
  309. },
  310. 'service.metrics.hdfs.block_status': {
  311. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/dfs/FSNamesystem/PendingReplicationBlocks[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/FSNamesystem/UnderReplicatedBlocks[{fromSeconds},{toSeconds},{stepSeconds}]',
  312. 'mock': '/data/services/metrics/hdfs/block_status.json',
  313. 'testInProduction': true
  314. },
  315. 'service.metrics.hdfs.file_operations': {
  316. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/dfs/namenode/FileInfoOps[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/namenode/CreateFileOps[{fromSeconds},{toSeconds},{stepSeconds}]',
  317. 'mock': '/data/services/metrics/hdfs/file_operations.json',
  318. 'testInProduction': true
  319. },
  320. 'service.metrics.hdfs.gc': {
  321. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/jvm/gcTimeMillis[{fromSeconds},{toSeconds},{stepSeconds}]',
  322. 'mock': '/data/services/metrics/hdfs/gc.json',
  323. 'testInProduction': true
  324. },
  325. 'service.metrics.hdfs.io': {
  326. 'real': '/clusters/{clusterName}/services/HDFS/components/DATANODE?fields=metrics/dfs/datanode/bytes_written[{fromSeconds},{toSeconds},{stepSeconds}],metrics/dfs/datanode/bytes_read[{fromSeconds},{toSeconds},{stepSeconds}]',
  327. 'mock': '/data/services/metrics/hdfs/io.json',
  328. 'testInProduction': true
  329. },
  330. 'service.metrics.hdfs.jvm_heap': {
  331. '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}]',
  332. 'mock': '/data/services/metrics/hdfs/jvm_heap.json',
  333. 'testInProduction': true
  334. },
  335. 'service.metrics.hdfs.jvm_threads': {
  336. '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}]',
  337. 'mock': '/data/services/metrics/hdfs/jvm_threads.json',
  338. 'testInProduction': true
  339. },
  340. 'service.metrics.hdfs.rpc': {
  341. 'real': '/clusters/{clusterName}/hosts/{nameNodeName}/host_components/NAMENODE?fields=metrics/rpc/RpcQueueTime_avg_time[{fromSeconds},{toSeconds},{stepSeconds}]',
  342. 'mock': '/data/services/metrics/hdfs/rpc.json',
  343. 'testInProduction': true
  344. },
  345. 'service.metrics.hdfs.space_utilization': {
  346. '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}]',
  347. 'mock': '/data/services/metrics/hdfs/space_utilization.json',
  348. 'testInProduction': true
  349. },
  350. 'dashboard.cluster_metrics.cpu': {
  351. 'real': '/clusters/{clusterName}/?fields=metrics/cpu[{fromSeconds},{toSeconds},{stepSeconds}]',
  352. 'mock': '/data/cluster_metrics/cpu_1hr.json',
  353. 'testInProduction': true
  354. },
  355. 'dashboard.cluster_metrics.load': {
  356. 'real': '/clusters/{clusterName}/?fields=metrics/load[{fromSeconds},{toSeconds},{stepSeconds}]',
  357. 'mock': '/data/cluster_metrics/load_1hr.json',
  358. 'testInProduction': true
  359. },
  360. 'dashboard.cluster_metrics.memory': {
  361. 'real': '/clusters/{clusterName}/?fields=metrics/memory[{fromSeconds},{toSeconds},{stepSeconds}]',
  362. 'mock': '/data/cluster_metrics/memory_1hr.json',
  363. 'testInProduction': true
  364. },
  365. 'dashboard.cluster_metrics.network': {
  366. 'real': '/clusters/{clusterName}/?fields=metrics/network[{fromSeconds},{toSeconds},{stepSeconds}]',
  367. 'mock': '/data/cluster_metrics/network_1hr.json',
  368. 'testInProduction': true
  369. },
  370. 'host.metrics.cpu': {
  371. '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}]',
  372. 'mock': '/data/hosts/metrics/cpu.json',
  373. 'testInProduction': true
  374. },
  375. 'host.metrics.disk': {
  376. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/disk/disk_total[{fromSeconds},{toSeconds},{stepSeconds}],metrics/disk/disk_free[{fromSeconds},{toSeconds},{stepSeconds}]',
  377. 'mock': '/data/hosts/metrics/disk.json',
  378. 'testInProduction': true
  379. },
  380. 'host.metrics.load': {
  381. '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}]',
  382. 'mock': '/data/hosts/metrics/load.json',
  383. 'testInProduction': true
  384. },
  385. 'host.metrics.memory': {
  386. '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}]',
  387. 'mock': '/data/hosts/metrics/memory.json',
  388. 'testInProduction': true
  389. },
  390. 'host.metrics.network': {
  391. '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}]',
  392. 'mock': '/data/hosts/metrics/network.json',
  393. 'testInProduction': true
  394. },
  395. 'host.metrics.processes': {
  396. 'real': '/clusters/{clusterName}/hosts/{hostName}?fields=metrics/process/proc_total[{fromSeconds},{toSeconds},{stepSeconds}],metrics/process/proc_run[{fromSeconds},{toSeconds},{stepSeconds}]',
  397. 'mock': '/data/hosts/metrics/processes.json',
  398. 'testInProduction': true
  399. },
  400. 'admin.security_status': {
  401. 'real': '/clusters/{clusterName}',
  402. 'format': function (data, opt) {
  403. return {
  404. timeout: 10000,
  405. async: false
  406. };
  407. }
  408. },
  409. 'admin.service_config': {
  410. 'real': '/clusters/{clusterName}/configurations/?type={siteName}&tag={tagName}',
  411. 'format': function (data, opt) {
  412. return {
  413. timeout: 10000,
  414. async: false
  415. };
  416. }
  417. },
  418. 'router.set_ambari_stacks': {
  419. 'real': '/stacks',
  420. 'mock': '/data/wizard/stack/stacks.json',
  421. 'format': function (data, opt) {
  422. return {
  423. async: false
  424. };
  425. }
  426. },
  427. 'cluster.load_cluster_name': {
  428. 'real': '/clusters',
  429. 'mock': '/data/clusters/info.json',
  430. 'format': function (data, opt) {
  431. return {
  432. async: false
  433. };
  434. }
  435. },
  436. 'cluster.update_upgrade_version': {
  437. 'real': '/stacks2/HDP/versions?fields=stackServices/StackServices,Versions',
  438. 'mock': '/data/wizard/stack/stacks.json',
  439. 'format': function (data, opt) {
  440. return {
  441. async: false
  442. };
  443. }
  444. },
  445. 'wizard.launch_bootstrap': {
  446. 'real': '/bootstrap',
  447. 'mock': '/data/wizard/bootstrap/bootstrap.json',
  448. 'type': 'POST',
  449. 'format': function (data) {
  450. return {
  451. async: false,
  452. contentType: 'application/json',
  453. data: data.bootStrapData
  454. }
  455. }
  456. },
  457. 'admin.security.cluster_configs': {
  458. 'real': '/clusters/{clusterName}',
  459. 'format': function (data, opt) {
  460. return {
  461. timeout: 10000
  462. };
  463. }
  464. },
  465. 'admin.security.all_configurations': {
  466. 'real': '/clusters/{clusterName}/configurations?{urlParams}',
  467. 'format': function (data, opt) {
  468. return {
  469. timeout: 10000
  470. };
  471. }
  472. },
  473. 'admin.security.apply_configuration': {
  474. 'real': '/clusters/{clusterName}',
  475. 'format': function (data, opt) {
  476. return {
  477. type: 'PUT',
  478. async: false,
  479. timeout: 5000,
  480. data: JSON.stringify(data.clusterData)
  481. };
  482. }
  483. },
  484. 'admin.security.add.cluster_configs': {
  485. 'real': '/clusters/{clusterName}',
  486. 'format': function (data, opt) {
  487. return {
  488. timeout: 10000
  489. };
  490. }
  491. },
  492. 'service.start_stop': {
  493. 'real': '/clusters/{clusterName}/services?ServiceInfo',
  494. 'mock': '/data/mirroring/poll/poll_6.json',
  495. 'format': function (data, opt) {
  496. return {
  497. type: 'PUT',
  498. async: false,
  499. data: data.data
  500. };
  501. }
  502. },
  503. 'admin.stack_upgrade.run_upgrade': {
  504. 'real': '/clusters/{clusterName}',
  505. 'format': function (data, opt) {
  506. return {
  507. type: 'PUT',
  508. async: false,
  509. data: data.data
  510. };
  511. }
  512. },
  513. 'admin.stack_upgrade.stop_services': {
  514. 'real': '/clusters/{clusterName}/services?ServiceInfo/state=STARTED',
  515. 'format': function (data, opt) {
  516. return {
  517. type: 'PUT',
  518. async: false,
  519. data: data.data
  520. };
  521. }
  522. },
  523. 'admin.stack_upgrade.do_poll': {
  524. 'real': '/clusters/{cluster}/requests/{requestId}?fields=tasks/*',
  525. 'mock': '/data/wizard/{mock}'
  526. },
  527. 'host.service_config_hosts_overrides': {
  528. 'real': '/clusters/{clusterName}/configurations?{urlParams}',
  529. 'format': function (data, opt) {
  530. return {
  531. async: false,
  532. timeout: 10000
  533. };
  534. }
  535. },
  536. 'wizard.install_services.add_host_controller.is_retry': {
  537. 'real': '/clusters/{cluster}/host_components',
  538. 'format': function (data, opt) {
  539. return {
  540. type: 'PUT',
  541. async: false,
  542. data: data.data
  543. };
  544. }
  545. },
  546. 'wizard.install_services.add_host_controller.not_is_retry': {
  547. 'real': '/clusters/{cluster}/host_components',
  548. 'format': function (data, opt) {
  549. return {
  550. type: 'PUT',
  551. async: false,
  552. data: data.data
  553. };
  554. }
  555. },
  556. 'wizard.install_services.installer_controller.is_retry': {
  557. 'real': '/clusters/{cluster}/host_components?HostRoles/state=INSTALLED',
  558. 'mock': '/data/wizard/deploy/2_hosts/poll_1.json',
  559. 'format': function (data, opt) {
  560. return {
  561. type: 'PUT',
  562. async: false,
  563. data: data.data
  564. };
  565. }
  566. },
  567. 'wizard.install_services.installer_controller.not_is_retry': {
  568. 'real': '/clusters/{cluster}/services?ServiceInfo/state=INIT',
  569. 'mock': '/data/wizard/deploy/2_hosts/poll_1.json',
  570. 'format': function (data, opt) {
  571. return {
  572. type: 'PUT',
  573. async: false,
  574. data: data.data
  575. };
  576. }
  577. },
  578. 'wizard.service_components': {
  579. 'real': '{stackUrl}/stackServices?fields=StackServices',
  580. 'mock': '/data/wizard/stack/hdp/version/{stackVersion}.json',
  581. 'format': function (data, opt) {
  582. return {
  583. async: false
  584. };
  585. }
  586. },
  587. 'wizard.step9.installer.launch_start_services': {
  588. 'real': '/clusters/{cluster}/services?ServiceInfo/state=INSTALLED&params/run_smoke_test=true&params/reconfigure_client=false',
  589. 'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
  590. 'format': function (data, opt) {
  591. var data = {
  592. type: 'PUT',
  593. async: false,
  594. data: data.data
  595. };
  596. if (App.testMode) {
  597. data.type = 'GET';
  598. }
  599. return data;
  600. }
  601. },
  602. 'wizard.step9.add_host.launch_start_services': {
  603. 'real': '/clusters/{cluster}/host_components',
  604. 'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
  605. 'format': function (data, opt) {
  606. return {
  607. type: 'PUT',
  608. async: false,
  609. data: data.data
  610. };
  611. }
  612. },
  613. 'wizard.step8.delete_cluster': {
  614. 'real': '/clusters/{name}',
  615. 'format': function (data, opt) {
  616. return {
  617. type: 'DELETE',
  618. async: false
  619. };
  620. }
  621. },
  622. 'wizard.step8.existing_cluster_names': {
  623. 'real': '/clusters',
  624. 'format': function (data, opt) {
  625. return {
  626. async: false
  627. };
  628. }
  629. },
  630. 'wizard.step3.host_info': {
  631. 'real': '/hosts?fields=Hosts/total_mem,Hosts/cpu_count,Hosts/disk_info,Hosts/last_agent_env,Hosts/host_name',
  632. 'mock': '/data/wizard/bootstrap/two_hosts_information.json',
  633. 'format': function (data, opt) {
  634. return {
  635. contentType: 'application/json'
  636. };
  637. }
  638. },
  639. 'wizard.step3.rerun_checks': {
  640. 'real': '/hosts?fields=Hosts/last_agent_env',
  641. 'mock': '/data/wizard/bootstrap/two_hosts_information.json',
  642. 'format': function (data, opt) {
  643. return {
  644. contentType: 'application/json'
  645. };
  646. }
  647. },
  648. 'wizard.step3.bootstrap': {
  649. 'real': '/bootstrap/{bootRequestId}',
  650. 'mock': '/data/wizard/bootstrap/poll_{numPolls}.json'
  651. },
  652. 'wizard.step3.is_hosts_registered': {
  653. 'real': '/hosts',
  654. 'mock': '/data/wizard/bootstrap/single_host_registration.json'
  655. },
  656. 'wizard.stacks': {
  657. 'real': '/stacks2',
  658. 'mock': '/data/wizard/stack/stacks2.json',
  659. 'format': function (data) {
  660. return {
  661. async: false
  662. };
  663. }
  664. },
  665. 'wizard.stacks_versions': {
  666. 'real': '/stacks2/{stackName}/versions?fields=Versions',
  667. 'mock': '/data/wizard/stack/{stackName}_versions.json',
  668. 'format': function (data) {
  669. return {
  670. async: false
  671. };
  672. }
  673. },
  674. 'router.login': {
  675. 'real': '/users/{loginName}',
  676. 'mock': '/data/users/user_{usr}.json',
  677. 'format': function (data, opt) {
  678. var statusCode = jQuery.extend({}, require('data/statusCodes'));
  679. statusCode['403'] = function () {
  680. console.log("Error code 403: Forbidden.");
  681. }
  682. return {
  683. statusCode: statusCode
  684. };
  685. }
  686. },
  687. 'router.login2': {
  688. 'real': '/clusters',
  689. 'mock': '/data/clusters/info.json'
  690. },
  691. 'router.logoff': {
  692. 'real': '/logout'
  693. },
  694. 'router.authentication': {
  695. 'real': '/clusters',
  696. 'mock': '/data/clusters/info.json',
  697. 'format': function (data, opt) {
  698. return {
  699. async: false
  700. };
  701. }
  702. }
  703. };
  704. /**
  705. * Replace data-placeholders to its values
  706. *
  707. * @param {String} url
  708. * @param {Object} data
  709. * @return {String}
  710. */
  711. var formatUrl = function (url, data) {
  712. var keys = url.match(/\{\w+\}/g);
  713. keys = (keys === null) ? [] : keys;
  714. if (keys) {
  715. keys.forEach(function (key) {
  716. var raw_key = key.substr(1, key.length - 2);
  717. var replace;
  718. if (!data[raw_key]) {
  719. replace = '';
  720. }
  721. else {
  722. replace = data[raw_key];
  723. }
  724. url = url.replace(new RegExp(key, 'g'), replace);
  725. });
  726. }
  727. return url;
  728. };
  729. /**
  730. * this = object from config
  731. * @return {Object}
  732. */
  733. var formatRequest = function (data) {
  734. var opt = {
  735. type: this.type || 'GET',
  736. timeout: App.timeout,
  737. dataType: 'json',
  738. statusCode: require('data/statusCodes')
  739. };
  740. if (App.testMode) {
  741. opt.url = formatUrl(this.mock, data);
  742. opt.type = 'GET';
  743. }
  744. else {
  745. opt.url = App.apiPrefix + formatUrl(this.real, data);
  746. }
  747. if (this.format) {
  748. jQuery.extend(opt, this.format(data, opt));
  749. }
  750. return opt;
  751. };
  752. /**
  753. * Wrapper for all ajax requests
  754. *
  755. * @type {Object}
  756. */
  757. App.ajax = {
  758. /**
  759. * Send ajax request
  760. *
  761. * @param {Object} config
  762. * @return Object jquery ajax object
  763. *
  764. * config fields:
  765. * name - url-key in the urls-object *required*
  766. * sender - object that send request (need for proper callback initialization) *required*
  767. * data - object with data for url-format
  768. * beforeSend - method-name for ajax beforeSend response callback
  769. * success - method-name for ajax success response callback
  770. * error - method-name for ajax error response callback
  771. * callback - callback from <code>App.updater.run</code> library
  772. */
  773. send: function (config) {
  774. console.warn('============== ajax ==============', config.name, config.data);
  775. if (!config.sender) {
  776. console.warn('Ajax sender should be defined!');
  777. return null;
  778. }
  779. // default parameters
  780. var params = {
  781. clusterName: App.get('clusterName')
  782. };
  783. // extend default parameters with provided
  784. if (config.data) {
  785. jQuery.extend(params, config.data);
  786. }
  787. var opt = {};
  788. opt = formatRequest.call(urls[config.name], params);
  789. // object sender should be provided for processing beforeSend, success and error responses
  790. opt.beforeSend = function (xhr) {
  791. if (config.beforeSend) {
  792. config.sender[config.beforeSend](opt, xhr, params);
  793. }
  794. };
  795. opt.success = function (data) {
  796. console.log("TRACE: The url is: " + opt.url);
  797. if (config.success) {
  798. config.sender[config.success](data, opt, params);
  799. }
  800. };
  801. opt.error = function (request, ajaxOptions, error) {
  802. if (config.error) {
  803. config.sender[config.error](request, ajaxOptions, error, opt);
  804. }
  805. };
  806. opt.complete = function () {
  807. if (config.callback) {
  808. config.callback();
  809. }
  810. };
  811. if ($.mocho) {
  812. opt.url = 'http://' + $.hostName + opt.url;
  813. }
  814. return $.ajax(opt);
  815. }
  816. }