diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/builders/DistributedNativeBuilder.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/builders/DistributedNativeBuilder.java index 39d57163f..6e7cf8e32 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/builders/DistributedNativeBuilder.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/builders/DistributedNativeBuilder.java @@ -14,9 +14,9 @@ */ package com.ericsson.bss.cassandra.ecchronos.connection.impl.builders; +import com.ericsson.bss.cassandra.ecchronos.connection.CustomDriverOption; import com.ericsson.bss.cassandra.ecchronos.connection.DataCenterAwarePolicy; import com.ericsson.bss.cassandra.ecchronos.connection.impl.enums.ConnectionType; - import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.CqlSessionBuilder; import com.datastax.oss.driver.api.core.auth.AuthProvider; @@ -339,7 +339,7 @@ private static ProgrammaticDriverConfigLoaderBuilder loaderBuilder( SCHEMA_REFRESHED_KEYSPACES); if (builder.myType.equals(ConnectionType.datacenterAware)) { - DataCenterAwarePolicy.setAllowedDcs(builder.myDatacenterAware); + loaderBuilder.withStringList(CustomDriverOption.PartitionAwarePolicyAllowedDCs, builder.myDatacenterAware); loaderBuilder.withString(DefaultDriverOption.LOAD_BALANCING_POLICY_CLASS, builder.myDatacenterAwarePolicy.getCanonicalName()); loaderBuilder.withInt(DefaultDriverOption.LOAD_BALANCING_DC_FAILOVER_MAX_NODES_PER_REMOTE_DC, diff --git a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/CustomDriverOption.java b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/CustomDriverOption.java new file mode 100644 index 000000000..276a76151 --- /dev/null +++ b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/CustomDriverOption.java @@ -0,0 +1,37 @@ +/* + * Copyright 2024 Telefonaktiebolaget LM Ericsson + * + * Licensed 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 com.ericsson.bss.cassandra.ecchronos.connection; + +import com.datastax.oss.driver.api.core.config.DriverOption; + +public enum CustomDriverOption implements DriverOption +{ + + PartitionAwarePolicyAllowedDCs("basic.allowed-dcs"); + + private final String myPath; + + CustomDriverOption(final String path) + { + myPath = path; + } + + @Override + public String getPath() + { + return myPath; + } + +} diff --git a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/DataCenterAwarePolicy.java b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/DataCenterAwarePolicy.java index e8e26fef0..34e2001ca 100644 --- a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/DataCenterAwarePolicy.java +++ b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/DataCenterAwarePolicy.java @@ -52,19 +52,14 @@ public class DataCenterAwarePolicy extends DefaultLoadBalancingPolicy private final ConcurrentMap> myPerDcLiveNodes = new ConcurrentHashMap<>(); private final AtomicInteger myIndex = new AtomicInteger(); - private static List myAllowedDcs; + private final List myAllowedDcs; public DataCenterAwarePolicy(final DriverContext context, final String profileName) { super(context, profileName); - } - - public static void setAllowedDcs(final List allowedDcs) - { - if (allowedDcs != null) - { - myAllowedDcs = allowedDcs; - } + myAllowedDcs = context.getConfig() + .getDefaultProfile() + .getStringList(CustomDriverOption.PartitionAwarePolicyAllowedDCs); } @Override diff --git a/connection/src/test/java/com/ericsson/bss/cassandra/ecchronos/connection/TestDataCenterAwarePolicy.java b/connection/src/test/java/com/ericsson/bss/cassandra/ecchronos/connection/TestDataCenterAwarePolicy.java index b5cac68be..890d2be69 100644 --- a/connection/src/test/java/com/ericsson/bss/cassandra/ecchronos/connection/TestDataCenterAwarePolicy.java +++ b/connection/src/test/java/com/ericsson/bss/cassandra/ecchronos/connection/TestDataCenterAwarePolicy.java @@ -122,18 +122,20 @@ public void setup() when(myDriverContextMock.getMetadataManager()).thenReturn(myMetadataManagerMock); when(myMetadataManagerMock.getMetadata()).thenReturn(myMetadataMock); when(myDriverConfigMock.getProfile(any(String.class))).thenReturn(myDriverExecutionProfileMock); + when(myDriverConfigMock.getDefaultProfile()).thenReturn(myDriverExecutionProfileMock); when(myDriverExecutionProfileMock.getName()).thenReturn("unittest"); when(myDriverExecutionProfileMock.getInt(DefaultDriverOption.LOAD_BALANCING_DC_FAILOVER_MAX_NODES_PER_REMOTE_DC)).thenReturn(999); when(myDriverExecutionProfileMock.getBoolean(DefaultDriverOption.LOAD_BALANCING_DC_FAILOVER_ALLOW_FOR_LOCAL_CONSISTENCY_LEVELS)).thenReturn(false); when(myDriverExecutionProfileMock.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).thenReturn("LOCAL_QUORUM"); when(myDriverContextMock.getConsistencyLevelRegistry()).thenReturn(myConsistencyLevelRegistryMock); when(myConsistencyLevelRegistryMock.nameToLevel(any(String.class))).thenReturn(ConsistencyLevel.LOCAL_QUORUM); + when(myDriverConfigMock.getDefaultProfile().getStringList(CustomDriverOption.PartitionAwarePolicyAllowedDCs)).thenReturn(null); } @Test public void testDistanceHost() { - DataCenterAwarePolicy.setAllowedDcs(null); +// DataCenterAwarePolicy.setAllowedDcs(null); DataCenterAwarePolicy policy = new DataCenterAwarePolicy(myDriverContextMock, ""); policy.init(myNodes, myDistanceReporterMock); @@ -153,7 +155,7 @@ public void testDistanceHost() @Test public void testDistanceHostWithAllowedDcs() { - DataCenterAwarePolicy.setAllowedDcs(List.of(myAllowedDcs)); + when(myDriverConfigMock.getDefaultProfile().getStringList(CustomDriverOption.PartitionAwarePolicyAllowedDCs)).thenReturn(List.of(myAllowedDcs)); DataCenterAwarePolicy policy = new DataCenterAwarePolicy(myDriverContextMock, ""); policy.init(myNodes, myDistanceReporterMock);