17
17
*/
18
18
package com .datastax .oss .driver .internal .core .addresstranslation ;
19
19
20
+ import static com .datastax .oss .driver .api .core .config .DefaultDriverOption .ADDRESS_TRANSLATOR_DEFAULT_ADDRESS ;
21
+ import static com .datastax .oss .driver .api .core .config .DefaultDriverOption .ADDRESS_TRANSLATOR_RESOLVE_ADDRESSES ;
22
+ import static com .datastax .oss .driver .api .core .config .DefaultDriverOption .ADDRESS_TRANSLATOR_SUBNET_ADDRESSES ;
23
+
20
24
import com .datastax .oss .driver .api .core .addresstranslation .AddressTranslator ;
21
- import com .datastax .oss .driver .api .core .config .DriverOption ;
22
25
import com .datastax .oss .driver .api .core .context .DriverContext ;
23
26
import com .datastax .oss .driver .internal .core .util .AddressUtils ;
24
27
import edu .umd .cs .findbugs .annotations .NonNull ;
45
48
public class SubnetAddressTranslator implements AddressTranslator {
46
49
private static final Logger LOG = LoggerFactory .getLogger (SubnetAddressTranslator .class );
47
50
48
- /**
49
- * A map of Cassandra node subnets (CIDR notations) to target addresses, for example (note quoted
50
- * keys):
51
- *
52
- * <pre>
53
- * advanced.address-translator.subnet-addresses {
54
- * "100.64.0.0/15" = "cassandra.datacenter1.com:9042"
55
- * "100.66.0.0/15" = "cassandra.datacenter2.com:9042"
56
- * # IPv6 example:
57
- * # "::ffff:6440:0/111" = "cassandra.datacenter1.com:9042"
58
- * # "::ffff:6442:0/111" = "cassandra.datacenter2.com:9042"
59
- * }
60
- * </pre>
61
- *
62
- * Note: subnets must be represented as prefix blocks, see {@link
63
- * inet.ipaddr.Address#isPrefixBlock()}.
64
- */
65
- public static final String ADDRESS_TRANSLATOR_SUBNET_ADDRESSES =
66
- "advanced.address-translator.subnet-addresses" ;
67
-
68
- /**
69
- * A default address to fallback to if Cassandra node IP isn't contained in any of the configured
70
- * subnets.
71
- */
72
- public static final String ADDRESS_TRANSLATOR_DEFAULT_ADDRESS =
73
- "advanced.address-translator.default-address" ;
74
-
75
- /**
76
- * Whether to resolve the addresses on initialization (if true) or on each node (re-)connection
77
- * (if false). Defaults to false.
78
- */
79
- public static final String ADDRESS_TRANSLATOR_RESOLVE_ADDRESSES =
80
- "advanced.address-translator.resolve-addresses" ;
81
-
82
- public static DriverOption ADDRESS_TRANSLATOR_SUBNET_ADDRESSES_OPTION =
83
- new DriverOption () {
84
- @ NonNull
85
- @ Override
86
- public String getPath () {
87
- return ADDRESS_TRANSLATOR_SUBNET_ADDRESSES ;
88
- }
89
- };
90
-
91
- public static DriverOption ADDRESS_TRANSLATOR_DEFAULT_ADDRESS_OPTION =
92
- new DriverOption () {
93
- @ NonNull
94
- @ Override
95
- public String getPath () {
96
- return ADDRESS_TRANSLATOR_DEFAULT_ADDRESS ;
97
- }
98
- };
99
-
100
- public static DriverOption ADDRESS_TRANSLATOR_RESOLVE_ADDRESSES_OPTION =
101
- new DriverOption () {
102
- @ NonNull
103
- @ Override
104
- public String getPath () {
105
- return ADDRESS_TRANSLATOR_RESOLVE_ADDRESSES ;
106
- }
107
- };
108
-
109
51
private final List <SubnetAddress > subnetAddresses ;
110
52
111
53
@ SuppressWarnings ("OptionalUsedAsFieldOrParameterType" )
@@ -119,10 +61,10 @@ public SubnetAddressTranslator(@NonNull DriverContext context) {
119
61
context
120
62
.getConfig ()
121
63
.getDefaultProfile ()
122
- .getBoolean (ADDRESS_TRANSLATOR_RESOLVE_ADDRESSES_OPTION , false );
64
+ .getBoolean (ADDRESS_TRANSLATOR_RESOLVE_ADDRESSES , false );
123
65
this .subnetAddresses =
124
- context .getConfig ().getDefaultProfile ()
125
- .getStringMap ( ADDRESS_TRANSLATOR_SUBNET_ADDRESSES_OPTION ). entrySet ().stream ()
66
+ context .getConfig ().getDefaultProfile (). getStringMap ( ADDRESS_TRANSLATOR_SUBNET_ADDRESSES )
67
+ .entrySet ().stream ()
126
68
.map (
127
69
e -> {
128
70
// Quoted and/or containing forward slashes map keys in reference.conf are read to
@@ -138,7 +80,7 @@ public SubnetAddressTranslator(@NonNull DriverContext context) {
138
80
context
139
81
.getConfig ()
140
82
.getDefaultProfile ()
141
- .getString (ADDRESS_TRANSLATOR_DEFAULT_ADDRESS_OPTION , null ))
83
+ .getString (ADDRESS_TRANSLATOR_DEFAULT_ADDRESS , null ))
142
84
.map (address -> parseAddress (address , resolveAddresses ));
143
85
144
86
validateSubnetsAreNotOverlapping (this .subnetAddresses );
0 commit comments