seninel部署
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.1KB

  1. var app = angular.module('sentinelDashboardApp');
  2. app.service('FlowService', ['$http', function ($http) {
  3. this.queryMachineRules = function (app, ip, port) {
  4. var param = {
  5. app: app,
  6. ip: ip,
  7. port: port
  8. };
  9. return $http({
  10. url: 'flow/rules.json',
  11. params: param,
  12. method: 'GET'
  13. });
  14. };
  15. this.newRule = function (rule) {
  16. var param = {
  17. resource: rule.resource,
  18. limitApp: rule.limitApp,
  19. grade: rule.grade,
  20. count: rule.count,
  21. strategy: rule.strategy,
  22. refResource: rule.refResource,
  23. controlBehavior: rule.controlBehavior,
  24. warmUpPeriodSec: rule.warmUpPeriodSec,
  25. maxQueueingTimeMs: rule.maxQueueingTimeMs,
  26. app: rule.app,
  27. ip: rule.ip,
  28. port: rule.port
  29. };
  30. return $http({
  31. url: '/flow/new.json',
  32. params: param,
  33. method: 'GET'
  34. });
  35. };
  36. this.saveRule = function (rule) {
  37. var param = {
  38. id: rule.id,
  39. resource: rule.resource,
  40. limitApp: rule.limitApp,
  41. grade: rule.grade,
  42. count: rule.count,
  43. strategy: rule.strategy,
  44. refResource: rule.refResource,
  45. controlBehavior: rule.controlBehavior,
  46. warmUpPeriodSec: rule.warmUpPeriodSec,
  47. maxQueueingTimeMs: rule.maxQueueingTimeMs,
  48. };
  49. return $http({
  50. url: '/flow/save.json',
  51. params: param,
  52. method: 'GET'
  53. });
  54. };
  55. this.deleteRule = function (rule) {
  56. var param = {
  57. id: rule.id,
  58. app: rule.app
  59. };
  60. return $http({
  61. url: '/flow/delete.json',
  62. params: param,
  63. method: 'GET'
  64. });
  65. };
  66. function notNumberAtLeastZero(num) {
  67. return num === undefined || num === '' || isNaN(num) || num < 0;
  68. }
  69. function notNumberGreaterThanZero(num) {
  70. return num === undefined || num === '' || isNaN(num) || num <= 0;
  71. }
  72. this.checkRuleValid = function (rule) {
  73. if (rule.resource === undefined || rule.resource === '') {
  74. alert('资源名称不能为空');
  75. return false;
  76. }
  77. if (rule.count === undefined || rule.count < 0) {
  78. alert('限流阈值必须大于等于 0');
  79. return false;
  80. }
  81. if (rule.strategy === undefined || rule.strategy < 0) {
  82. alert('无效的流控模式');
  83. return false;
  84. }
  85. if (rule.strategy == 1 || rule.strategy == 2) {
  86. if (rule.refResource === undefined || rule.refResource == '') {
  87. alert('请填写关联资源或入口');
  88. return false;
  89. }
  90. }
  91. if (rule.controlBehavior === undefined || rule.controlBehavior < 0) {
  92. alert('无效的流控整形方式');
  93. return false;
  94. }
  95. if (rule.controlBehavior == 1 && notNumberGreaterThanZero(rule.warmUpPeriodSec)) {
  96. alert('预热时长必须大于 0');
  97. return false;
  98. }
  99. if (rule.controlBehavior == 2 && notNumberGreaterThanZero(rule.maxQueueingTimeMs)) {
  100. alert('排队超时时间必须大于 0');
  101. return false;
  102. }
  103. return true;
  104. };
  105. }]);