services.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. */
  15. var solrAdminServices = angular.module('solrAdminServices', ['ngResource']);
  16. solrAdminServices.factory('System',
  17. ['$resource', function($resource) {
  18. return $resource('admin/info/system', {"wt":"json", "nodes": "@nodes", "_":Date.now()});
  19. }])
  20. .factory('Metrics',
  21. ['$resource', function($resource) {
  22. return $resource('admin/metrics', {"wt":"json", "nodes": "@nodes", "prefix":"@prefix", "_":Date.now()});
  23. }])
  24. .factory('Collections',
  25. ['$resource', function($resource) {
  26. return $resource('admin/collections',
  27. {'wt':'json', '_':Date.now()}, {
  28. "list": {params:{action: "LIST"}},
  29. "status": {params:{action: "CLUSTERSTATUS"}},
  30. "add": {params:{action: "CREATE"}},
  31. "delete": {params:{action: "DELETE"}},
  32. "rename": {params:{action: "RENAME"}},
  33. "createAlias": {params:{action: "CREATEALIAS"}},
  34. "deleteAlias": {params:{action: "DELETEALIAS"}},
  35. "deleteReplica": {params:{action: "DELETEREPLICA"}},
  36. "addReplica": {params:{action: "ADDREPLICA"}},
  37. "deleteShard": {params:{action: "DELETESHARD"}},
  38. "reload": {method: "GET", params:{action:"RELOAD", core: "@core"}}
  39. });
  40. }])
  41. .factory('Cores',
  42. ['$resource', function($resource) {
  43. return $resource('admin/cores',
  44. {'wt':'json', '_':Date.now()}, {
  45. "query": {},
  46. "list": {params:{indexInfo: false}},
  47. "add": {params:{action: "CREATE"}},
  48. "unload": {params:{action: "UNLOAD", core: "@core"}},
  49. "rename": {params:{action: "RENAME"}},
  50. "swap": {params:{action: "SWAP"}},
  51. "reload": {method: "GET", params:{action:"RELOAD", core: "@core"}, headers:{doNotIntercept: "true"}}
  52. });
  53. }])
  54. .factory('Logging',
  55. ['$resource', function($resource) {
  56. return $resource('admin/info/logging', {'wt':'json', '_':Date.now()}, {
  57. "events": {params: {since:'0'}},
  58. "levels": {},
  59. "setLevel": {}
  60. });
  61. }])
  62. .factory('Zookeeper',
  63. ['$resource', function($resource) {
  64. return $resource('admin/zookeeper', {wt:'json', _:Date.now()}, {
  65. "simple": {},
  66. "liveNodes": {params: {path: '/live_nodes'}},
  67. "clusterState": {params: {detail: "true", path: "/clusterstate.json"}},
  68. "detail": {params: {detail: "true", path: "@path"}},
  69. "configs": {params: {detail:false, path: "/configs/"}},
  70. "aliases": {params: {detail: "true", path: "/aliases.json"}, transformResponse:function(data) {
  71. var znode = $.parseJSON(data).znode;
  72. if (znode.data) {
  73. return {aliases: $.parseJSON(znode.data).collection};
  74. } else {
  75. return {aliases: {}};
  76. }
  77. }}
  78. });
  79. }])
  80. .factory('ZookeeperStatus',
  81. ['$resource', function($resource) {
  82. return $resource('admin/zookeeper/status', {wt:'json', _:Date.now()}, {
  83. "monitor": {}
  84. });
  85. }])
  86. .factory('Properties',
  87. ['$resource', function($resource) {
  88. return $resource('admin/info/properties', {'wt':'json', '_':Date.now()});
  89. }])
  90. .factory('Threads',
  91. ['$resource', function($resource) {
  92. return $resource('admin/info/threads', {'wt':'json', '_':Date.now()});
  93. }])
  94. .factory('Properties',
  95. ['$resource', function($resource) {
  96. return $resource('admin/info/properties', {'wt':'json', '_':Date.now()});
  97. }])
  98. .factory('Replication',
  99. ['$resource', function($resource) {
  100. return $resource(':core/replication', {'wt':'json', core: "@core", '_':Date.now()}, {
  101. "details": {params: {command: "details"}},
  102. "command": {params: {}}
  103. });
  104. }])
  105. .factory('CoreSystem',
  106. ['$resource', function($resource) {
  107. return $resource(':core/admin/system', {wt:'json', core: "@core", _:Date.now()});
  108. }])
  109. .factory('Update',
  110. ['$resource', function($resource) {
  111. return $resource(':core/:handler', {core: '@core', wt:'json', _:Date.now(), handler:'update'}, {
  112. "commit": {params: {commit: "true"}},
  113. "post": {headers: {'Content-type': 'application/json'}, method: "POST", params: {handler: '@handler'}},
  114. "postJson": {headers: {'Content-type': 'application/json'}, method: "POST", params: {handler: '@handler'}},
  115. "postXml": {headers: {'Content-type': 'text/xml'}, method: "POST", params: {handler: '@handler'}},
  116. "postCsv": {headers: {'Content-type': 'application/csv'}, method: "POST", params: {handler: '@handler'}}
  117. });
  118. }])
  119. .service('FileUpload', function ($http) {
  120. this.upload = function(params, file, success, error){
  121. var url = "" + params.core + "/" + params.handler + "?";
  122. raw = params.raw;
  123. delete params.core;
  124. delete params.handler;
  125. delete params.raw;
  126. url += $.param(params);
  127. if (raw && raw.length>0) {
  128. if (raw[0] != "&") raw = "&" + raw;
  129. url += raw;
  130. }
  131. var fd = new FormData();
  132. fd.append('file', file);
  133. $http.post(url, fd, {
  134. transformRequest: angular.identity,
  135. headers: {'Content-Type': undefined}
  136. }).success(success).error(error);
  137. }
  138. })
  139. .factory('Luke',
  140. ['$resource', function($resource) {
  141. return $resource(':core/admin/luke', {core: '@core', wt:'json', _:Date.now()}, {
  142. "index": {params: {numTerms: 0, show: 'index'}},
  143. "raw": {params: {numTerms: 0}},
  144. "schema": {params: {show:'schema'}},
  145. "field": {},
  146. "fields": {params: {show:'schema'}, interceptor: {
  147. response: function(response) {
  148. var fieldsAndTypes = [];
  149. for (var field in response.data.schema.fields) {
  150. fieldsAndTypes.push({group: "Fields", label: field, value: "fieldname=" + field});
  151. }
  152. for (var type in response.data.schema.types) {
  153. fieldsAndTypes.push({group: "Types", label: type, value: "fieldtype=" + type});
  154. }
  155. return fieldsAndTypes;
  156. }
  157. }}
  158. });
  159. }])
  160. .factory('Analysis',
  161. ['$resource', function($resource) {
  162. return $resource(':core/analysis/field', {core: '@core', wt:'json', _:Date.now()}, {
  163. "field": {params: {"analysis.showmatch": true}}
  164. });
  165. }])
  166. .factory('DataImport',
  167. ['$resource', function($resource) {
  168. return $resource(':core/:name', {core: '@core', name: '@name', indent:'on', wt:'json', _:Date.now()}, {
  169. "config": {params: {command: "show-config"}, headers: {doNotIntercept: "true"},
  170. transformResponse: function(data) {
  171. return {config: data};
  172. }
  173. },
  174. "status": {params: {command: "status"}, headers: {doNotIntercept: "true"}},
  175. "reload": {params: {command: "reload-config"}},
  176. "post": {method: "POST",
  177. headers: {'Content-type': 'application/x-www-form-urlencoded'},
  178. transformRequest: function(data) { return $.param(data) }}
  179. });
  180. }])
  181. .factory('Ping',
  182. ['$resource', function($resource) {
  183. return $resource(':core/admin/ping', {wt:'json', core: '@core', ts:Date.now(), _:Date.now()}, {
  184. "ping": {},
  185. "status": {params:{action:"status"}, headers: {doNotIntercept: "true"}
  186. }});
  187. }])
  188. .factory('Mbeans',
  189. ['$resource', function($resource) {
  190. return $resource(':core/admin/mbeans', {'wt':'json', core: '@core', '_':Date.now()}, {
  191. stats: {params: {stats: true}},
  192. info: {},
  193. reference: {
  194. params: {wt: "xml", stats: true}, transformResponse: function (data) {
  195. return {reference: data}
  196. }
  197. },
  198. delta: {method: "POST",
  199. params: {stats: true, diff:true},
  200. headers: {'Content-type': 'application/x-www-form-urlencoded'},
  201. transformRequest: function(data) {
  202. return "stream.body=" + encodeURIComponent(data);
  203. }
  204. }
  205. });
  206. }])
  207. .factory('Files',
  208. ['$resource', function($resource) {
  209. return $resource(':core/admin/file', {'wt':'json', core: '@core', '_':Date.now()}, {
  210. "list": {},
  211. "get": {method: "GET", interceptor: {
  212. response: function(config) {return config;}
  213. }, transformResponse: function(data) {
  214. return data;
  215. }}
  216. });
  217. }])
  218. .factory('Query',
  219. ['$resource', function($resource) {
  220. var resource = $resource(':core/:handler', {core: '@core', handler: '@handler', '_':Date.now()}, {
  221. "query": {
  222. method: "GET",
  223. transformResponse: function (data) {
  224. return {data: data}
  225. },
  226. headers: {doNotIntercept: "true"}
  227. }
  228. });
  229. resource.url = function(params) {
  230. var qs = [];
  231. for (key in params) {
  232. if (key != "core" && key != "handler") {
  233. for (var i in params[key]) {
  234. qs.push(key + "=" + encodeURIComponent(params[key][i]));
  235. }
  236. }
  237. }
  238. return "" + params.core + "/" + params.handler + "?" + qs.sort().join("&");
  239. }
  240. return resource;
  241. }])
  242. .factory('Segments',
  243. ['$resource', function($resource) {
  244. return $resource(':core/admin/segments', {'wt':'json', core: '@core', _:Date.now()}, {
  245. get: {}
  246. });
  247. }])
  248. .factory('Schema',
  249. ['$resource', function($resource) {
  250. return $resource(':core/schema', {wt: 'json', core: '@core', _:Date.now()}, {
  251. get: {method: "GET"},
  252. check: {method: "GET", headers: {doNotIntercept: "true"}},
  253. post: {method: "POST"}
  254. });
  255. }])
  256. .factory('Config',
  257. ['$resource', function($resource) {
  258. return $resource(':core/config', {wt: 'json', core: '@core', _:Date.now()}, {
  259. get: {method: "GET"}
  260. })
  261. }])
  262. .factory('AuthenticationService',
  263. ['base64', function (base64) {
  264. var service = {};
  265. service.SetCredentials = function (username, password) {
  266. var authdata = base64.encode(username + ':' + password);
  267. sessionStorage.setItem("auth.header", "Basic " + authdata);
  268. sessionStorage.setItem("auth.username", username);
  269. };
  270. service.ClearCredentials = function () {
  271. sessionStorage.removeItem("auth.header");
  272. sessionStorage.removeItem("auth.scheme");
  273. sessionStorage.removeItem("auth.realm");
  274. sessionStorage.removeItem("auth.username");
  275. sessionStorage.removeItem("auth.wwwAuthHeader");
  276. sessionStorage.removeItem("auth.statusText");
  277. };
  278. return service;
  279. }]);