ajax.js 76 KB

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