/
ShenyuConfig.java
1709 lines (1460 loc) · 39 KB
/
ShenyuConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.shenyu.common.config;
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.common.concurrent.MemoryLimitCalculator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* The type shenyu config.
*/
public class ShenyuConfig {
private SwitchConfig switchConfig = new SwitchConfig();
private FileConfig file = new FileConfig();
private ExcludePath exclude = new ExcludePath();
private Health health = new Health();
private FallbackPath fallback = new FallbackPath();
private ExtPlugin extPlugin = new ExtPlugin();
private MatchCache matchCache = new MatchCache();
private Scheduler scheduler = new Scheduler();
private UpstreamCheck upstreamCheck = new UpstreamCheck();
private CrossFilterConfig cross = new CrossFilterConfig();
private RibbonConfig ribbon = new RibbonConfig();
private Local local = new Local();
private WebsocketConfig websocket = new WebsocketConfig();
private SharedPool sharedPool = new SharedPool();
private MetricsConfig metrics = new MetricsConfig();
/**
* Gets health.
*
* @return the health
*/
public Health getHealth() {
return health;
}
/**
* Sets health.
*
* @param health the health
*/
public void setHealth(final Health health) {
this.health = health;
}
/**
* Gets metrics.
*
* @return the metrics
*/
public MetricsConfig getMetrics() {
return metrics;
}
/**
* Sets metrics.
*
* @param metrics the metrics
*/
public void setMetrics(final MetricsConfig metrics) {
this.metrics = metrics;
}
/**
* Gets the shared thread pool config.
*
* @return the shared thread pool config
*/
public SharedPool getSharedPool() {
return sharedPool;
}
/**
* Sets the shared thread pool config.
*
* @param sharedPool the shared thread pool config
*/
public void setSharedPool(final SharedPool sharedPool) {
this.sharedPool = sharedPool;
}
/**
* Gets the local config.
*
* @return the local config
*/
public Local getLocal() {
return local;
}
/**
* Sets the local config.
*
* @param local the local config
*/
public void setLocal(final Local local) {
this.local = local;
}
/**
* Gets ribbon.
*
* @return the ribbon
*/
public RibbonConfig getRibbon() {
return ribbon;
}
/**
* Sets ribbon.
*
* @param ribbon the ribbon
*/
public void setRibbon(final RibbonConfig ribbon) {
this.ribbon = ribbon;
}
/**
* Gets switch config.
*
* @return the switch config
*/
public SwitchConfig getSwitchConfig() {
return switchConfig;
}
/**
* Sets switch config.
*
* @param switchConfig the switch config
*/
public void setSwitchConfig(final SwitchConfig switchConfig) {
this.switchConfig = switchConfig;
}
/**
* Gets scheduler.
*
* @return the scheduler
*/
public Scheduler getScheduler() {
return scheduler;
}
/**
* Sets scheduler.
*
* @param scheduler the scheduler
*/
public void setScheduler(final Scheduler scheduler) {
this.scheduler = scheduler;
}
/**
* Gets ext plugin.
*
* @return the ext plugin
*/
public ExtPlugin getExtPlugin() {
return extPlugin;
}
/**
* Sets ext plugin.
*
* @param extPlugin the ext plugin
*/
public void setExtPlugin(final ExtPlugin extPlugin) {
this.extPlugin = extPlugin;
}
/**
* Gets match cache.
*
* @return the match cache
*/
public MatchCache getMatchCache() {
return matchCache;
}
/**
* Sets match cache.
*
* @param matchCache the match cache
*/
public void setMatchCache(final MatchCache matchCache) {
this.matchCache = matchCache;
}
/**
* Gets file.
*
* @return the file
*/
public FileConfig getFile() {
return file;
}
/**
* Sets file.
*
* @param file the file
*/
public void setFile(final FileConfig file) {
this.file = file;
}
/**
* Gets exclude.
*
* @return the exclude
*/
public ExcludePath getExclude() {
return exclude;
}
/**
* Sets exclude.
*
* @param exclude the exclude
*/
public void setExclude(final ExcludePath exclude) {
this.exclude = exclude;
}
/**
* Gets fallback.
*
* @return the fallback
*/
public FallbackPath getFallback() {
return fallback;
}
/**
* Sets fallback.
*
* @param fallback the fallback
*/
public void setFallback(final FallbackPath fallback) {
this.fallback = fallback;
}
/**
* Gets upstream check.
*
* @return the upstream check
*/
public UpstreamCheck getUpstreamCheck() {
return upstreamCheck;
}
/**
* Sets upstream check.
*
* @param upstreamCheck the upstream check
*/
public void setUpstreamCheck(final UpstreamCheck upstreamCheck) {
this.upstreamCheck = upstreamCheck;
}
/**
* Gets cross.
*
* @return the cross
*/
public CrossFilterConfig getCross() {
return cross;
}
/**
* Gets the websocket config.
*
* @return the websocket config
*/
public WebsocketConfig getWebsocket() {
return websocket;
}
/**
* Sets the websocket config.
*
* @param websocket the websocket config
*/
public void setWebsocket(final WebsocketConfig websocket) {
this.websocket = websocket;
}
/**
* Sets cross.
*
* @param cross the cross
*/
public void setCross(final CrossFilterConfig cross) {
this.cross = cross;
}
/**
* The type Scheduler.
*/
public static class Scheduler {
private boolean enabled;
private String type = "fixed";
private Integer threads = Math.max((Runtime.getRuntime().availableProcessors() << 1) + 1, 16);
/**
* Gets enabled.
*
* @return the enabled
*/
public boolean getEnabled() {
return enabled;
}
/**
* Sets enabled.
*
* @param enabled the enabled
*/
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
/**
* Gets type.
*
* @return the type
*/
public String getType() {
return type;
}
/**
* Sets type.
*
* @param type the type
*/
public void setType(final String type) {
this.type = type;
}
/**
* Gets threads.
*
* @return the threads
*/
public Integer getThreads() {
return threads;
}
/**
* Sets threads.
*
* @param threads the threads
*/
public void setThreads(final Integer threads) {
this.threads = threads;
}
}
/**
* The type Ext plugin.
*/
public static class ExtPlugin {
private String path;
private boolean enabled;
private Integer threads = 1;
private Integer scheduleTime = 300;
private Integer scheduleDelay = 30;
/**
* Gets path.
*
* @return the path
*/
public String getPath() {
return path;
}
/**
* Sets path.
*
* @param path the path
*/
public void setPath(final String path) {
this.path = path;
}
/**
* Gets enabled.
*
* @return the enabled
*/
public boolean getEnabled() {
return enabled;
}
/**
* Sets enabled.
*
* @param enabled the enabled
*/
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
/**
* Gets threads.
*
* @return the threads
*/
public Integer getThreads() {
return threads;
}
/**
* Sets threads.
*
* @param threads the threads
*/
public void setThreads(final Integer threads) {
this.threads = threads;
}
/**
* Gets schedule time.
*
* @return the schedule time
*/
public Integer getScheduleTime() {
return scheduleTime;
}
/**
* Sets schedule time.
*
* @param scheduleTime the schedule time
*/
public void setScheduleTime(final Integer scheduleTime) {
this.scheduleTime = scheduleTime;
}
/**
* Gets schedule delay.
*
* @return the schedule delay
*/
public Integer getScheduleDelay() {
return scheduleDelay;
}
/**
* Sets schedule delay.
*
* @param scheduleDelay the schedule delay
*/
public void setScheduleDelay(final Integer scheduleDelay) {
this.scheduleDelay = scheduleDelay;
}
}
/**
* the match cache.
*/
public static class MatchCache {
private boolean selectorEnabled;
private boolean ruleEnabled;
/**
* Max free memory, unit mb.
*/
private Integer maxSelectorFreeMemory = 256;
private Integer maxRuleFreeMemory = 256;
/**
* Get selector cache enabled.
*
* @return the enabled
*/
public boolean getSelectorEnabled() {
return selectorEnabled;
}
/**
* Set selector enabled.
*
* @param selectorEnabled the enabled
*/
public void setSelectorEnabled(final boolean selectorEnabled) {
this.selectorEnabled = selectorEnabled;
}
/**
* get rule cache enabled.
*
* @return rule enabled
*/
public boolean getRuleEnabled() {
return ruleEnabled;
}
/**
* set rule cache enabled.
*
* @param ruleEnabled rule cache enabled
*/
public void setRuleEnabled(final boolean ruleEnabled) {
this.ruleEnabled = ruleEnabled;
}
/**
* Gets maxFreeMemory.
*
* @return the maxFreeMemory
*/
public Integer getMaxSelectorFreeMemory() {
return maxSelectorFreeMemory;
}
/**
* Sets maxFreeMemory.
*
* @param maxSelectorFreeMemory the maxFreeMemory
*/
public void setMaxSelectorFreeMemory(final Integer maxSelectorFreeMemory) {
this.maxSelectorFreeMemory = maxSelectorFreeMemory;
}
/**
* Gets maxFreeMemory.
*
* @return the maxFreeMemory
*/
public Integer getMaxRuleFreeMemory() {
return maxRuleFreeMemory;
}
/**
* Sets maxFreeMemory.
*
* @param maxRuleFreeMemory the maxFreeMemory
*/
public void setMaxRuleFreeMemory(final Integer maxRuleFreeMemory) {
this.maxRuleFreeMemory = maxRuleFreeMemory;
}
}
/**
* The type Exclude path.
*/
public static class ExcludePath {
private boolean enabled;
private List<String> paths = new ArrayList<>();
/**
* Gets enabled.
*
* @return the enabled
*/
public boolean getEnabled() {
return enabled;
}
/**
* Sets enabled.
*
* @param enabled the enabled
*/
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
/**
* Sets paths.
*
* @param paths the paths
*/
public void setPaths(final List<String> paths) {
this.paths = paths;
}
/**
* get paths.
*
* @return paths paths
*/
public List<String> getPaths() {
return paths;
}
}
/**
* The type fallback path.
*/
public static class FallbackPath {
private boolean enabled;
private List<String> paths = new ArrayList<>();
/**
* Gets enabled.
*
* @return the enabled
*/
public boolean getEnabled() {
return enabled;
}
/**
* Sets enabled.
*
* @param enabled the enabled
*/
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
/**
* Sets paths.
*
* @param paths the paths
*/
public void setPaths(final List<String> paths) {
this.paths = paths;
}
/**
* get paths.
*
* @return paths paths
*/
public List<String> getPaths() {
return paths;
}
}
/**
* The type Health.
*/
public static class Health {
private boolean enabled;
private List<String> paths = new ArrayList<>();
/**
* Gets enabled.
*
* @return the enabled
*/
public boolean getEnabled() {
return enabled;
}
/**
* Sets enabled.
*
* @param enabled the enabled
*/
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
/**
* Sets paths.
*
* @param paths the paths
*/
public void setPaths(final List<String> paths) {
this.paths = paths;
}
/**
* get paths.
*
* @return paths paths
*/
public List<String> getPaths() {
return paths;
}
}
/**
* The type File config.
*/
public static class FileConfig {
private boolean enabled;
private Integer maxSize = 10;
/**
* Gets enabled.
*
* @return the enabled
*/
public boolean getEnabled() {
return enabled;
}
/**
* Sets enabled.
*
* @param enabled the enabled
*/
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
/**
* Gets file max size.
*
* @return the file max size
*/
public Integer getMaxSize() {
return maxSize;
}
/**
* Sets file max size.
*
* @param maxSize the file max size
*/
public void setMaxSize(final Integer maxSize) {
this.maxSize = maxSize;
}
}
/**
* The type Switch config.
*/
public static class SwitchConfig {
private boolean local = true;
/**
* Gets local.
*
* @return the local
*/
public boolean getLocal() {
return local;
}
/**
* Sets local.
*
* @param local the local
*/
public void setLocal(final boolean local) {
this.local = local;
}
}
/**
* The type Upstream check.
*/
public static class UpstreamCheck {
private boolean enabled;
private Integer timeout = 3000;
private Integer healthyThreshold = 1;
private Integer unhealthyThreshold = 1;
private Integer interval = 5000;
private boolean printEnabled;
private Integer printInterval = 60000;
/**
* Gets enabled.
*
* @return the enabled
*/
public boolean getEnabled() {
return enabled;
}
/**
* Sets enabled.
*
* @param enabled the enabled
*/
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
/**
* Gets timeout.
*
* @return the timeout
*/
public Integer getTimeout() {
return timeout;
}
/**
* Sets timeout.
*
* @param timeout the timeout
*/
public void setTimeout(final Integer timeout) {
this.timeout = timeout;
}
/**
* Gets healthy threshold.
*
* @return the healthy threshold
*/
public Integer getHealthyThreshold() {
return healthyThreshold;
}
/**
* Sets healthy threshold.
*
* @param healthyThreshold the healthy threshold
*/
public void setHealthyThreshold(final Integer healthyThreshold) {
this.healthyThreshold = healthyThreshold;
}
/**
* Gets unhealthy threshold.
*
* @return the unhealthy threshold
*/
public Integer getUnhealthyThreshold() {
return unhealthyThreshold;
}
/**
* Sets unhealthy threshold.
*
* @param unhealthyThreshold the unhealthy threshold
*/
public void setUnhealthyThreshold(final Integer unhealthyThreshold) {
this.unhealthyThreshold = unhealthyThreshold;
}
/**
* Gets interval.
*
* @return the interval
*/
public Integer getInterval() {
return interval;
}
/**
* Sets interval.
*
* @param interval the interval
*/
public void setInterval(final Integer interval) {
this.interval = interval;
}
/**
* Gets print enabled.
*
* @return the print enabled
*/
public boolean getPrintEnabled() {
return printEnabled;
}
/**
* Sets print enabled.
*
* @param printEnabled the print enabled
*/
public void setPrintEnabled(final boolean printEnabled) {
this.printEnabled = printEnabled;
}
/**
* Gets print interval.
*
* @return the print interval
*/
public Integer getPrintInterval() {
return printInterval;
}
/**
* Sets print interval.
*
* @param printInterval the print interval
*/
public void setPrintInterval(final Integer printInterval) {
this.printInterval = printInterval;
}
}
/**
* The Cross Filter Config.
*/
public static class CrossFilterConfig {
private static final Set<String> DEFAULT_ALLOWED_HEADERS;
static {
DEFAULT_ALLOWED_HEADERS = new HashSet<String>() {
{
add("x-requested-with");
add("authorization");
add("Content-Type");
add("Authorization");
add("credential");
add("X-XSRF-TOKEN");
add("token");
add("username");
add("client");
}
};
}
private boolean enabled;
/**
* Comma-separated of “header”.
*/
private String allowedHeaders = "";
/**
* Comma-separated of “method”.
*/
private String allowedMethods = "*";
private AllowedOriginConfig allowedOrigin = new AllowedOriginConfig();
private boolean allowedAnyOrigin;
private String allowedExpose = "";
private String maxAge = "18000";
private boolean allowCredentials;
/**