diff --git a/core/revapi.json b/core/revapi.json index 5aa46a3ccad..383f5e2cf32 100644 --- a/core/revapi.json +++ b/core/revapi.json @@ -7386,6 +7386,163 @@ "old": "method com.datastax.oss.driver.api.core.type.reflect.GenericType> com.datastax.oss.driver.api.core.type.reflect.GenericType::vectorOf(java.lang.Class)", "new": "method com.datastax.oss.driver.api.core.type.reflect.GenericType> com.datastax.oss.driver.api.core.type.reflect.GenericType::vectorOf(java.lang.Class)", "justification": "JAVA-3143: Extend driver vector support to arbitrary subtypes and fix handling of variable length types (OSS C* 5.0)" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.CONTINUOUS_PAGING_METRICS_SESSION_CQL_REQUESTS_LOWEST", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.CONTINUOUS_PAGING_METRICS_SESSION_CQL_REQUESTS_LOWEST", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.CONTINUOUS_PAGING_METRICS_SESSION_CQL_REQUESTS_SLO", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.CONTINUOUS_PAGING_METRICS_SESSION_CQL_REQUESTS_SLO", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_PAGES", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_PAGES", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_CONTINUOUS_PAGING_PAGE_SIZE", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_CONTINUOUS_PAGING_PAGE_SIZE", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_PAGING_ENABLED", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_PAGING_ENABLED", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_NODE_GRAPH_MESSAGES_DIGITS", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_NODE_GRAPH_MESSAGES_DIGITS", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_NODE_GRAPH_MESSAGES_HIGHEST", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_NODE_GRAPH_MESSAGES_HIGHEST", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_NODE_GRAPH_MESSAGES_INTERVAL", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_NODE_GRAPH_MESSAGES_INTERVAL", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_NODE_GRAPH_MESSAGES_LOWEST", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_NODE_GRAPH_MESSAGES_LOWEST", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_NODE_GRAPH_MESSAGES_SLO", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_NODE_GRAPH_MESSAGES_SLO", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_SESSION_GRAPH_REQUESTS_DIGITS", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_SESSION_GRAPH_REQUESTS_DIGITS", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_SESSION_GRAPH_REQUESTS_HIGHEST", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_SESSION_GRAPH_REQUESTS_HIGHEST", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_SESSION_GRAPH_REQUESTS_INTERVAL", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_SESSION_GRAPH_REQUESTS_INTERVAL", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_SESSION_GRAPH_REQUESTS_LOWEST", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_SESSION_GRAPH_REQUESTS_LOWEST", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.enumConstantOrderChanged", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_SESSION_GRAPH_REQUESTS_SLO", + "new": "field com.datastax.dse.driver.api.core.config.DseDriverOption.METRICS_SESSION_GRAPH_REQUESTS_SLO", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.removed", + "old": "field com.datastax.dse.driver.api.core.config.DseDriverOption.MONITOR_REPORTING_ENABLED", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.field.removed", + "old": "field com.datastax.oss.driver.api.core.config.TypedDriverOption.MONITOR_REPORTING_ENABLED", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.method.removed", + "old": "method com.datastax.oss.driver.api.core.session.ProgrammaticArguments.Builder com.datastax.oss.driver.api.core.session.ProgrammaticArguments.Builder::withStartupApplicationName(java.lang.String)", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.method.removed", + "old": "method com.datastax.oss.driver.api.core.session.ProgrammaticArguments.Builder com.datastax.oss.driver.api.core.session.ProgrammaticArguments.Builder::withStartupApplicationVersion(java.lang.String)", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.method.removed", + "old": "method com.datastax.oss.driver.api.core.session.ProgrammaticArguments.Builder com.datastax.oss.driver.api.core.session.ProgrammaticArguments.Builder::withStartupClientId(java.util.UUID)", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.method.removed", + "old": "method java.lang.String com.datastax.oss.driver.api.core.session.ProgrammaticArguments::getStartupApplicationName()", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.method.removed", + "old": "method java.lang.String com.datastax.oss.driver.api.core.session.ProgrammaticArguments::getStartupApplicationVersion()", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.method.removed", + "old": "method java.util.UUID com.datastax.oss.driver.api.core.session.ProgrammaticArguments::getStartupClientId()", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.method.removed", + "old": "method SelfT com.datastax.oss.driver.api.core.session.SessionBuilder::withApplicationName(java.lang.String)", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.method.removed", + "old": "method SelfT com.datastax.oss.driver.api.core.session.SessionBuilder::withApplicationVersion(java.lang.String)", + "justification": "CASSJAVA-73: Remove Insights support" + }, + { + "code": "java.method.removed", + "old": "method SelfT com.datastax.oss.driver.api.core.session.SessionBuilder::withClientId(java.util.UUID)", + "justification": "CASSJAVA-73: Remove Insights support" } ] } diff --git a/core/src/main/java/com/datastax/dse/driver/api/core/config/DseDriverOption.java b/core/src/main/java/com/datastax/dse/driver/api/core/config/DseDriverOption.java index 4d10501f6d2..34535a014ab 100644 --- a/core/src/main/java/com/datastax/dse/driver/api/core/config/DseDriverOption.java +++ b/core/src/main/java/com/datastax/dse/driver/api/core/config/DseDriverOption.java @@ -169,13 +169,6 @@ public enum DseDriverOption implements DriverOption { */ GRAPH_TIMEOUT("basic.graph.timeout"), - /** - * Whether to send events for Insights monitoring. - * - *

Value type: boolean - */ - MONITOR_REPORTING_ENABLED("advanced.monitor-reporting.enabled"), - /** * Whether to enable paging for Graph queries. * diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/InsightsClientLifecycleListener.java b/core/src/main/java/com/datastax/dse/driver/internal/core/InsightsClientLifecycleListener.java deleted file mode 100644 index e4dd6f93bf7..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/InsightsClientLifecycleListener.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core; - -import static com.datastax.dse.driver.api.core.config.DseDriverOption.MONITOR_REPORTING_ENABLED; - -import com.datastax.dse.driver.internal.core.insights.InsightsClient; -import com.datastax.dse.driver.internal.core.insights.configuration.InsightsConfiguration; -import com.datastax.oss.driver.internal.core.context.InternalDriverContext; -import com.datastax.oss.driver.internal.core.context.LifecycleListener; - -public class InsightsClientLifecycleListener implements LifecycleListener { - private static final boolean DEFAULT_INSIGHTS_ENABLED = true; - private static final long STATUS_EVENT_DELAY_MILLIS = 300000L; - private final InternalDriverContext context; - private final StackTraceElement[] initCallStackTrace; - private volatile InsightsClient insightsClient; - - public InsightsClientLifecycleListener( - InternalDriverContext context, StackTraceElement[] initCallStackTrace) { - this.context = context; - this.initCallStackTrace = initCallStackTrace; - } - - @Override - public void onSessionReady() { - boolean monitorReportingEnabled = - context - .getConfig() - .getDefaultProfile() - .getBoolean(MONITOR_REPORTING_ENABLED, DEFAULT_INSIGHTS_ENABLED); - - this.insightsClient = - InsightsClient.createInsightsClient( - new InsightsConfiguration( - monitorReportingEnabled, - STATUS_EVENT_DELAY_MILLIS, - context.getNettyOptions().adminEventExecutorGroup().next()), - context, - initCallStackTrace); - insightsClient.sendStartupMessage(); - insightsClient.scheduleStatusMessageSend(); - } - - @Override - public void close() { - if (insightsClient != null) { - insightsClient.shutdown(); - } - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/AddressFormatter.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/AddressFormatter.java deleted file mode 100644 index cecc951a3ab..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/AddressFormatter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import java.net.InetAddress; -import java.net.InetSocketAddress; - -class AddressFormatter { - - static String nullSafeToString(Object address) { - if (address instanceof InetAddress) { - return nullSafeToString((InetAddress) address); - } else if (address instanceof InetSocketAddress) { - return nullSafeToString((InetSocketAddress) address); - } else if (address instanceof String) { - return address.toString(); - } else { - return ""; - } - } - - static String nullSafeToString(InetAddress inetAddress) { - return inetAddress != null ? inetAddress.getHostAddress() : null; - } - - static String nullSafeToString(InetSocketAddress inetSocketAddress) { - if (inetSocketAddress != null) { - if (inetSocketAddress.isUnresolved()) { - return String.format( - "%s:%s", - nullSafeToString(inetSocketAddress.getHostName()), inetSocketAddress.getPort()); - } else { - return String.format( - "%s:%s", nullSafeToString(inetSocketAddress.getAddress()), inetSocketAddress.getPort()); - } - } - return null; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/ConfigAntiPatternsFinder.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/ConfigAntiPatternsFinder.java deleted file mode 100644 index 7f5b9c20a0e..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/ConfigAntiPatternsFinder.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.SSL_ENGINE_FACTORY_CLASS; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.SSL_HOSTNAME_VALIDATION; - -import com.datastax.oss.driver.internal.core.context.InternalDriverContext; -import java.util.HashMap; -import java.util.Map; - -class ConfigAntiPatternsFinder { - Map findAntiPatterns(InternalDriverContext driverContext) { - Map antiPatterns = new HashMap<>(); - findSslAntiPattern(driverContext, antiPatterns); - return antiPatterns; - } - - private void findSslAntiPattern( - InternalDriverContext driverContext, Map antiPatterns) { - boolean isSslDefined = - driverContext.getConfig().getDefaultProfile().isDefined(SSL_ENGINE_FACTORY_CLASS); - boolean certValidation = - driverContext.getConfig().getDefaultProfile().getBoolean(SSL_HOSTNAME_VALIDATION, false); - if (isSslDefined && !certValidation) { - antiPatterns.put( - "sslWithoutCertValidation", - "Client-to-node encryption is enabled but server certificate validation is disabled"); - } - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/DataCentersFinder.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/DataCentersFinder.java deleted file mode 100644 index 7112b8dcdf7..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/DataCentersFinder.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.CONNECTION_POOL_REMOTE_SIZE; - -import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; -import com.datastax.oss.driver.api.core.loadbalancing.NodeDistance; -import com.datastax.oss.driver.api.core.metadata.Node; -import com.datastax.oss.driver.internal.core.context.InternalDriverContext; -import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -class DataCentersFinder { - - Set getDataCenters(InternalDriverContext driverContext) { - return getDataCenters( - driverContext.getMetadataManager().getMetadata().getNodes().values(), - driverContext.getConfig().getDefaultProfile()); - } - - @VisibleForTesting - Set getDataCenters(Collection nodes, DriverExecutionProfile executionProfile) { - - int remoteConnectionsLength = executionProfile.getInt(CONNECTION_POOL_REMOTE_SIZE); - - Set dataCenters = new HashSet<>(); - for (Node n : nodes) { - NodeDistance distance = n.getDistance(); - - if (distance.equals(NodeDistance.LOCAL) - || (distance.equals(NodeDistance.REMOTE) && remoteConnectionsLength > 0)) { - dataCenters.add(n.getDatacenter()); - } - } - return dataCenters; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/ExecutionProfilesInfoFinder.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/ExecutionProfilesInfoFinder.java deleted file mode 100644 index a7c92d80d96..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/ExecutionProfilesInfoFinder.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_TRAVERSAL_SOURCE; - -import com.datastax.dse.driver.internal.core.insights.PackageUtil.ClassSettingDetails; -import com.datastax.dse.driver.internal.core.insights.schema.LoadBalancingInfo; -import com.datastax.dse.driver.internal.core.insights.schema.SpecificExecutionProfile; -import com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo; -import com.datastax.oss.driver.api.core.config.DefaultDriverOption; -import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; -import com.datastax.oss.driver.internal.core.context.InternalDriverContext; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.Function; -import java.util.stream.Collectors; - -class ExecutionProfilesInfoFinder { - Map getExecutionProfilesInfo( - InternalDriverContext driverContext) { - - SpecificExecutionProfile defaultProfile = - mapToSpecificProfile(driverContext.getConfig().getDefaultProfile()); - - return driverContext.getConfig().getProfiles().entrySet().stream() - .collect( - Collectors.toMap( - Map.Entry::getKey, - e -> { - if (isNotDefaultProfile(e)) { - SpecificExecutionProfile specificExecutionProfile = - mapToSpecificProfile(e.getValue()); - return retainOnlyDifferentFieldsFromSpecificProfile( - defaultProfile, specificExecutionProfile); - } else { - return defaultProfile; - } - })); - } - - private boolean isNotDefaultProfile(Map.Entry e) { - return !e.getKey().equals("default"); - } - - private SpecificExecutionProfile retainOnlyDifferentFieldsFromSpecificProfile( - SpecificExecutionProfile defaultProfile, SpecificExecutionProfile specificExecutionProfile) { - Integer readTimeout = - getIfDifferentOrReturnNull( - defaultProfile, specificExecutionProfile, SpecificExecutionProfile::getReadTimeout); - LoadBalancingInfo loadBalancingInfo = - getIfDifferentOrReturnNull( - defaultProfile, specificExecutionProfile, SpecificExecutionProfile::getLoadBalancing); - - SpeculativeExecutionInfo speculativeExecutionInfo = - getIfDifferentOrReturnNull( - defaultProfile, - specificExecutionProfile, - SpecificExecutionProfile::getSpeculativeExecution); - - String consistency = - getIfDifferentOrReturnNull( - defaultProfile, specificExecutionProfile, SpecificExecutionProfile::getConsistency); - - String serialConsistency = - getIfDifferentOrReturnNull( - defaultProfile, - specificExecutionProfile, - SpecificExecutionProfile::getSerialConsistency); - - Map graphOptions = - getIfDifferentOrReturnNull( - defaultProfile, specificExecutionProfile, SpecificExecutionProfile::getGraphOptions); - - return new SpecificExecutionProfile( - readTimeout, - loadBalancingInfo, - speculativeExecutionInfo, - consistency, - serialConsistency, - graphOptions); - } - - private T getIfDifferentOrReturnNull( - SpecificExecutionProfile defaultProfile, - SpecificExecutionProfile profile, - Function valueExtractor) { - T defaultProfileValue = valueExtractor.apply(defaultProfile); - T specificProfileValue = valueExtractor.apply(profile); - if (defaultProfileValue.equals(specificProfileValue)) { - return null; - } else { - return specificProfileValue; - } - } - - private SpecificExecutionProfile mapToSpecificProfile( - DriverExecutionProfile driverExecutionProfile) { - return new SpecificExecutionProfile( - (int) driverExecutionProfile.getDuration(DefaultDriverOption.REQUEST_TIMEOUT).toMillis(), - getLoadBalancingInfo(driverExecutionProfile), - getSpeculativeExecutionInfo(driverExecutionProfile), - driverExecutionProfile.getString(DefaultDriverOption.REQUEST_CONSISTENCY), - driverExecutionProfile.getString(DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY), - getGraphOptions(driverExecutionProfile)); - } - - private SpeculativeExecutionInfo getSpeculativeExecutionInfo( - DriverExecutionProfile driverExecutionProfile) { - Map options = new LinkedHashMap<>(); - - putIfExists( - options, - "maxSpeculativeExecutions", - DefaultDriverOption.SPECULATIVE_EXECUTION_MAX, - driverExecutionProfile); - putIfExists( - options, "delay", DefaultDriverOption.SPECULATIVE_EXECUTION_DELAY, driverExecutionProfile); - - ClassSettingDetails speculativeExecutionDetails = - PackageUtil.getSpeculativeExecutionDetails( - driverExecutionProfile.getString( - DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS)); - return new SpeculativeExecutionInfo( - speculativeExecutionDetails.getClassName(), - options, - speculativeExecutionDetails.getFullPackage()); - } - - private void putIfExists( - Map options, - String key, - DefaultDriverOption option, - DriverExecutionProfile executionProfile) { - if (executionProfile.isDefined(option)) { - options.put(key, executionProfile.getInt(option)); - } - } - - private LoadBalancingInfo getLoadBalancingInfo(DriverExecutionProfile driverExecutionProfile) { - Map options = new LinkedHashMap<>(); - if (driverExecutionProfile.isDefined(DefaultDriverOption.LOAD_BALANCING_LOCAL_DATACENTER)) { - options.put( - "localDataCenter", - driverExecutionProfile.getString(DefaultDriverOption.LOAD_BALANCING_LOCAL_DATACENTER)); - } - @SuppressWarnings("deprecation") - boolean hasNodeFiltering = - driverExecutionProfile.isDefined(DefaultDriverOption.LOAD_BALANCING_FILTER_CLASS) - || driverExecutionProfile.isDefined( - DefaultDriverOption.LOAD_BALANCING_DISTANCE_EVALUATOR_CLASS); - options.put("filterFunction", hasNodeFiltering); - ClassSettingDetails loadBalancingDetails = - PackageUtil.getLoadBalancingDetails( - driverExecutionProfile.getString(DefaultDriverOption.LOAD_BALANCING_POLICY_CLASS)); - return new LoadBalancingInfo( - loadBalancingDetails.getClassName(), options, loadBalancingDetails.getFullPackage()); - } - - private Map getGraphOptions(DriverExecutionProfile driverExecutionProfile) { - Map graphOptionsMap = new HashMap<>(); - String graphTraversalSource = driverExecutionProfile.getString(GRAPH_TRAVERSAL_SOURCE, null); - if (graphTraversalSource != null) { - graphOptionsMap.put("source", graphTraversalSource); - } - return graphOptionsMap; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/InsightsClient.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/InsightsClient.java deleted file mode 100644 index f19687adf45..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/InsightsClient.java +++ /dev/null @@ -1,491 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.AUTH_PROVIDER_CLASS; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.CONNECTION_POOL_REMOTE_SIZE; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.HEARTBEAT_INTERVAL; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.PROTOCOL_COMPRESSION; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.SSL_ENGINE_FACTORY_CLASS; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.SSL_HOSTNAME_VALIDATION; - -import com.datastax.dse.driver.api.core.DseProtocolVersion; -import com.datastax.dse.driver.internal.core.insights.PackageUtil.ClassSettingDetails; -import com.datastax.dse.driver.internal.core.insights.configuration.InsightsConfiguration; -import com.datastax.dse.driver.internal.core.insights.exceptions.InsightEventFormatException; -import com.datastax.dse.driver.internal.core.insights.schema.AuthProviderType; -import com.datastax.dse.driver.internal.core.insights.schema.Insight; -import com.datastax.dse.driver.internal.core.insights.schema.InsightMetadata; -import com.datastax.dse.driver.internal.core.insights.schema.InsightType; -import com.datastax.dse.driver.internal.core.insights.schema.InsightsStartupData; -import com.datastax.dse.driver.internal.core.insights.schema.InsightsStatusData; -import com.datastax.dse.driver.internal.core.insights.schema.PoolSizeByHostDistance; -import com.datastax.dse.driver.internal.core.insights.schema.SSL; -import com.datastax.dse.driver.internal.core.insights.schema.SessionStateForNode; -import com.datastax.oss.driver.api.core.config.DefaultDriverOption; -import com.datastax.oss.driver.api.core.metadata.Node; -import com.datastax.oss.driver.api.core.session.SessionBuilder; -import com.datastax.oss.driver.api.core.type.DataTypes; -import com.datastax.oss.driver.api.core.type.codec.TypeCodec; -import com.datastax.oss.driver.api.core.uuid.Uuids; -import com.datastax.oss.driver.internal.core.adminrequest.AdminRequestHandler; -import com.datastax.oss.driver.internal.core.context.DefaultDriverContext; -import com.datastax.oss.driver.internal.core.context.InternalDriverContext; -import com.datastax.oss.driver.internal.core.context.StartupOptionsBuilder; -import com.datastax.oss.driver.internal.core.control.ControlConnection; -import com.datastax.oss.driver.internal.core.pool.ChannelPool; -import com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures; -import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting; -import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; -import com.datastax.oss.protocol.internal.request.Query; -import com.datastax.oss.protocol.internal.request.query.QueryOptions; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; -import java.time.Duration; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class InsightsClient { - private static final Logger LOGGER = LoggerFactory.getLogger(InsightsClient.class); - private static final String STARTUP_MESSAGE_NAME = "driver.startup"; - private static final String STATUS_MESSAGE_NAME = "driver.status"; - private static final String REPORT_INSIGHT_RPC = "CALL InsightsRpc.reportInsight(?)"; - private static final Map TAGS = ImmutableMap.of("language", "java"); - private static final String STARTUP_VERSION_1_ID = "v1"; - private static final String STATUS_VERSION_1_ID = "v1"; - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - private static final int MAX_NUMBER_OF_STATUS_ERROR_LOGS = 5; - static final String DEFAULT_JAVA_APPLICATION = "Default Java Application"; - - private final ControlConnection controlConnection; - private final String id = Uuids.random().toString(); - private final InsightsConfiguration insightsConfiguration; - private final AtomicInteger numberOfStatusEventErrors = new AtomicInteger(); - - private final InternalDriverContext driverContext; - private final Supplier timestampSupplier; - private final PlatformInfoFinder platformInfoFinder; - private final ReconnectionPolicyInfoFinder reconnectionPolicyInfoInfoFinder; - private final ExecutionProfilesInfoFinder executionProfilesInfoFinder; - private final ConfigAntiPatternsFinder configAntiPatternsFinder; - private final DataCentersFinder dataCentersFinder; - private final StackTraceElement[] initCallStackTrace; - - private volatile ScheduledFuture scheduleInsightsTask; - - public static InsightsClient createInsightsClient( - InsightsConfiguration insightsConfiguration, - InternalDriverContext driverContext, - StackTraceElement[] initCallStackTrace) { - DataCentersFinder dataCentersFinder = new DataCentersFinder(); - return new InsightsClient( - driverContext, - () -> new Date().getTime(), - insightsConfiguration, - new PlatformInfoFinder(), - new ReconnectionPolicyInfoFinder(), - new ExecutionProfilesInfoFinder(), - new ConfigAntiPatternsFinder(), - dataCentersFinder, - initCallStackTrace); - } - - InsightsClient( - InternalDriverContext driverContext, - Supplier timestampSupplier, - InsightsConfiguration insightsConfiguration, - PlatformInfoFinder platformInfoFinder, - ReconnectionPolicyInfoFinder reconnectionPolicyInfoInfoFinder, - ExecutionProfilesInfoFinder executionProfilesInfoFinder, - ConfigAntiPatternsFinder configAntiPatternsFinder, - DataCentersFinder dataCentersFinder, - StackTraceElement[] initCallStackTrace) { - this.driverContext = driverContext; - this.controlConnection = driverContext.getControlConnection(); - this.timestampSupplier = timestampSupplier; - this.insightsConfiguration = insightsConfiguration; - this.platformInfoFinder = platformInfoFinder; - this.reconnectionPolicyInfoInfoFinder = reconnectionPolicyInfoInfoFinder; - this.executionProfilesInfoFinder = executionProfilesInfoFinder; - this.configAntiPatternsFinder = configAntiPatternsFinder; - this.dataCentersFinder = dataCentersFinder; - this.initCallStackTrace = initCallStackTrace; - } - - public CompletionStage sendStartupMessage() { - try { - if (!shouldSendEvent()) { - return CompletableFuture.completedFuture(null); - } else { - String startupMessage = createStartupMessage(); - return sendJsonMessage(startupMessage) - .whenComplete( - (aVoid, throwable) -> { - if (throwable != null) { - LOGGER.debug( - "Error while sending startup message to Insights. Message was: " - + trimToFirst500characters(startupMessage), - throwable); - } - }); - } - } catch (Exception e) { - LOGGER.debug("Unexpected error while sending startup message to Insights.", e); - return CompletableFutures.failedFuture(e); - } - } - - private static String trimToFirst500characters(String startupMessage) { - return startupMessage.substring(0, Math.min(startupMessage.length(), 500)); - } - - public void scheduleStatusMessageSend() { - if (!shouldSendEvent()) { - return; - } - scheduleInsightsTask = - scheduleInsightsTask( - insightsConfiguration.getStatusEventDelayMillis(), - insightsConfiguration.getExecutor(), - this::sendStatusMessage); - } - - public void shutdown() { - if (scheduleInsightsTask != null) { - scheduleInsightsTask.cancel(false); - } - } - - @VisibleForTesting - public CompletionStage sendStatusMessage() { - try { - String statusMessage = createStatusMessage(); - CompletionStage result = sendJsonMessage(statusMessage); - return result.whenComplete( - (aVoid, throwable) -> { - if (throwable != null) { - if (numberOfStatusEventErrors.getAndIncrement() < MAX_NUMBER_OF_STATUS_ERROR_LOGS) { - LOGGER.debug( - "Error while sending status message to Insights. Message was: " - + trimToFirst500characters(statusMessage), - throwable); - } - } - }); - } catch (Exception e) { - LOGGER.debug("Unexpected error while sending status message to Insights.", e); - return CompletableFutures.failedFuture(e); - } - } - - private CompletionStage sendJsonMessage(String jsonMessage) { - - QueryOptions queryOptions = createQueryOptionsWithJson(jsonMessage); - String logPrefix = driverContext.getSessionName(); - Duration timeout = - driverContext - .getConfig() - .getDefaultProfile() - .getDuration(DefaultDriverOption.CONTROL_CONNECTION_TIMEOUT); - LOGGER.debug("sending JSON message: {}", jsonMessage); - - Query query = new Query(REPORT_INSIGHT_RPC, queryOptions); - return AdminRequestHandler.call(controlConnection.channel(), query, timeout, logPrefix).start(); - } - - private QueryOptions createQueryOptionsWithJson(String json) { - TypeCodec codec = - driverContext.getCodecRegistry().codecFor(DataTypes.TEXT, String.class); - ByteBuffer startupMessageSerialized = codec.encode(json, DseProtocolVersion.DSE_V2); - return new QueryOptions( - QueryOptions.DEFAULT.consistency, - Collections.singletonList(startupMessageSerialized), - QueryOptions.DEFAULT.namedValues, - QueryOptions.DEFAULT.skipMetadata, - QueryOptions.DEFAULT.pageSize, - QueryOptions.DEFAULT.pagingState, - QueryOptions.DEFAULT.serialConsistency, - QueryOptions.DEFAULT.defaultTimestamp, - QueryOptions.DEFAULT.keyspace, - QueryOptions.DEFAULT.nowInSeconds); - } - - private boolean shouldSendEvent() { - try { - return insightsConfiguration.isMonitorReportingEnabled() - && InsightsSupportVerifier.supportsInsights( - driverContext.getMetadataManager().getMetadata().getNodes().values()); - } catch (Exception e) { - LOGGER.debug("Unexpected error while checking Insights support.", e); - return false; - } - } - - @VisibleForTesting - String createStartupMessage() { - InsightMetadata insightMetadata = createMetadata(STARTUP_MESSAGE_NAME, STARTUP_VERSION_1_ID); - InsightsStartupData data = createStartupData(); - - try { - return OBJECT_MAPPER.writeValueAsString(new Insight<>(insightMetadata, data)); - } catch (JsonProcessingException e) { - throw new InsightEventFormatException("Problem when creating: " + STARTUP_MESSAGE_NAME, e); - } - } - - @VisibleForTesting - String createStatusMessage() { - InsightMetadata insightMetadata = createMetadata(STATUS_MESSAGE_NAME, STATUS_VERSION_1_ID); - InsightsStatusData data = createStatusData(); - - try { - return OBJECT_MAPPER.writeValueAsString(new Insight<>(insightMetadata, data)); - } catch (JsonProcessingException e) { - throw new InsightEventFormatException("Problem when creating: " + STATUS_MESSAGE_NAME, e); - } - } - - private InsightsStatusData createStatusData() { - Map startupOptions = driverContext.getStartupOptions(); - return InsightsStatusData.builder() - .withClientId(getClientId(startupOptions)) - .withSessionId(id) - .withControlConnection(getControlConnectionSocketAddress()) - .withConnectedNodes(getConnectedNodes()) - .build(); - } - - private Map getConnectedNodes() { - Map pools = driverContext.getPoolManager().getPools(); - return pools.entrySet().stream() - .collect( - Collectors.toMap( - entry -> AddressFormatter.nullSafeToString(entry.getKey().getEndPoint().resolve()), - this::constructSessionStateForNode)); - } - - private SessionStateForNode constructSessionStateForNode(Map.Entry entry) { - return new SessionStateForNode( - entry.getKey().getOpenConnections(), entry.getValue().getInFlight()); - } - - private InsightsStartupData createStartupData() { - Map startupOptions = driverContext.getStartupOptions(); - return InsightsStartupData.builder() - .withClientId(getClientId(startupOptions)) - .withSessionId(id) - .withApplicationName(getApplicationName(startupOptions)) - .withApplicationVersion(getApplicationVersion(startupOptions)) - .withDriverName(getDriverName(startupOptions)) - .withDriverVersion(getDriverVersion(startupOptions)) - .withContactPoints( - getResolvedContactPoints( - driverContext.getMetadataManager().getContactPoints().stream() - .map(n -> n.getEndPoint().resolve()) - .filter(InetSocketAddress.class::isInstance) - .map(InetSocketAddress.class::cast) - .collect(Collectors.toSet()))) - .withInitialControlConnection(getControlConnectionSocketAddress()) - .withProtocolVersion(driverContext.getProtocolVersion().getCode()) - .withLocalAddress(getLocalAddress()) - .withExecutionProfiles(executionProfilesInfoFinder.getExecutionProfilesInfo(driverContext)) - .withPoolSizeByHostDistance(getPoolSizeByHostDistance()) - .withHeartbeatInterval( - driverContext - .getConfig() - .getDefaultProfile() - .getDuration(HEARTBEAT_INTERVAL) - .toMillis()) - .withCompression( - driverContext.getConfig().getDefaultProfile().getString(PROTOCOL_COMPRESSION, "none")) - .withReconnectionPolicy( - reconnectionPolicyInfoInfoFinder.getReconnectionPolicyInfo( - driverContext.getReconnectionPolicy(), - driverContext.getConfig().getDefaultProfile())) - .withSsl(getSsl()) - .withAuthProvider(getAuthProvider()) - .withOtherOptions(getOtherOptions()) - .withPlatformInfo(platformInfoFinder.getInsightsPlatformInfo()) - .withConfigAntiPatterns(configAntiPatternsFinder.findAntiPatterns(driverContext)) - .withPeriodicStatusInterval(getPeriodicStatusInterval()) - .withHostName(getLocalHostName()) - .withApplicationNameWasGenerated(isApplicationNameGenerated(startupOptions)) - .withDataCenters(dataCentersFinder.getDataCenters(driverContext)) - .build(); - } - - private AuthProviderType getAuthProvider() { - String authProviderClassName = - driverContext - .getConfig() - .getDefaultProfile() - .getString(AUTH_PROVIDER_CLASS, "NoAuthProvider"); - ClassSettingDetails authProviderDetails = - PackageUtil.getAuthProviderDetails(authProviderClassName); - return new AuthProviderType( - authProviderDetails.getClassName(), authProviderDetails.getFullPackage()); - } - - private long getPeriodicStatusInterval() { - return TimeUnit.MILLISECONDS.toSeconds(insightsConfiguration.getStatusEventDelayMillis()); - } - - @VisibleForTesting - static Map> getResolvedContactPoints(Set contactPoints) { - if (contactPoints == null) { - return Collections.emptyMap(); - } - return contactPoints.stream() - .collect( - Collectors.groupingBy( - InetSocketAddress::getHostName, - Collectors.mapping(AddressFormatter::nullSafeToString, Collectors.toList()))); - } - - private String getDriverVersion(Map startupOptions) { - return startupOptions.get(StartupOptionsBuilder.DRIVER_VERSION_KEY); - } - - private String getDriverName(Map startupOptions) { - return startupOptions.get(StartupOptionsBuilder.DRIVER_NAME_KEY); - } - - private String getClientId(Map startupOptions) { - return startupOptions.get(StartupOptionsBuilder.CLIENT_ID_KEY); - } - - private boolean isApplicationNameGenerated(Map startupOptions) { - return startupOptions.get(StartupOptionsBuilder.APPLICATION_NAME_KEY) == null; - } - - private String getApplicationVersion(Map startupOptions) { - String applicationVersion = startupOptions.get(StartupOptionsBuilder.APPLICATION_VERSION_KEY); - if (applicationVersion == null) { - return ""; - } - return applicationVersion; - } - - private String getApplicationName(Map startupOptions) { - String applicationName = startupOptions.get(StartupOptionsBuilder.APPLICATION_NAME_KEY); - if (applicationName == null || applicationName.isEmpty()) { - return getClusterCreateCaller(initCallStackTrace); - } - return applicationName; - } - - @VisibleForTesting - static String getClusterCreateCaller(StackTraceElement[] stackTrace) { - for (int i = 0; i < stackTrace.length - 1; i++) { - if (isClusterStackTrace(stackTrace[i])) { - int nextElement = i + 1; - if (!isClusterStackTrace(stackTrace[nextElement])) { - return stackTrace[nextElement].getClassName(); - } - } - } - return DEFAULT_JAVA_APPLICATION; - } - - private static boolean isClusterStackTrace(StackTraceElement stackTraceElement) { - return stackTraceElement.getClassName().equals(DefaultDriverContext.class.getName()) - || stackTraceElement.getClassName().equals(SessionBuilder.class.getName()); - } - - private String getLocalHostName() { - try { - return InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - LOGGER.warn("Can not resolve the name of a host, returning null", e); - return null; - } - } - - private Map getOtherOptions() { - return Collections.emptyMap(); // todo - } - - private SSL getSsl() { - boolean isSslDefined = - driverContext.getConfig().getDefaultProfile().isDefined(SSL_ENGINE_FACTORY_CLASS); - boolean certValidation = - driverContext.getConfig().getDefaultProfile().getBoolean(SSL_HOSTNAME_VALIDATION, false); - return new SSL(isSslDefined, certValidation); - } - - private PoolSizeByHostDistance getPoolSizeByHostDistance() { - - return new PoolSizeByHostDistance( - driverContext.getConfig().getDefaultProfile().getInt(CONNECTION_POOL_LOCAL_SIZE), - driverContext.getConfig().getDefaultProfile().getInt(CONNECTION_POOL_REMOTE_SIZE), - 0); - } - - private String getControlConnectionSocketAddress() { - SocketAddress controlConnectionAddress = controlConnection.channel().getEndPoint().resolve(); - return AddressFormatter.nullSafeToString(controlConnectionAddress); - } - - private String getLocalAddress() { - SocketAddress controlConnectionLocalAddress = controlConnection.channel().localAddress(); - if (controlConnectionLocalAddress instanceof InetSocketAddress) { - return AddressFormatter.nullSafeToString( - ((InetSocketAddress) controlConnectionLocalAddress).getAddress()); - } - return null; - } - - private InsightMetadata createMetadata(String messageName, String messageVersion) { - return new InsightMetadata( - messageName, timestampSupplier.get(), TAGS, InsightType.EVENT, messageVersion); - } - - @VisibleForTesting - static ScheduledFuture scheduleInsightsTask( - long statusEventDelayMillis, - ScheduledExecutorService scheduledTasksExecutor, - Runnable runnable) { - long initialDelay = - (long) Math.floor(statusEventDelayMillis - zeroToTenPercentRandom(statusEventDelayMillis)); - return scheduledTasksExecutor.scheduleWithFixedDelay( - runnable, initialDelay, statusEventDelayMillis, TimeUnit.MILLISECONDS); - } - - private static double zeroToTenPercentRandom(long statusEventDelayMillis) { - return 0.1 * statusEventDelayMillis * Math.random(); - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/InsightsSupportVerifier.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/InsightsSupportVerifier.java deleted file mode 100644 index ec016ef52d8..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/InsightsSupportVerifier.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import com.datastax.dse.driver.api.core.metadata.DseNodeProperties; -import com.datastax.oss.driver.api.core.Version; -import com.datastax.oss.driver.api.core.metadata.Node; -import java.util.Collection; - -class InsightsSupportVerifier { - private static final Version minDse6Version = Version.parse("6.0.5"); - private static final Version minDse51Version = Version.parse("5.1.13"); - private static final Version dse600Version = Version.parse("6.0.0"); - - static boolean supportsInsights(Collection nodes) { - assert minDse6Version != null; - assert dse600Version != null; - assert minDse51Version != null; - if (nodes.isEmpty()) return false; - - for (Node node : nodes) { - Object version = node.getExtras().get(DseNodeProperties.DSE_VERSION); - if (version == null) { - return false; - } - Version dseVersion = (Version) version; - if (!(dseVersion.compareTo(minDse6Version) >= 0 - || (dseVersion.compareTo(dse600Version) < 0 - && dseVersion.compareTo(minDse51Version) >= 0))) { - return false; - } - } - return true; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/PackageUtil.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/PackageUtil.java deleted file mode 100644 index 3c61dec4f20..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/PackageUtil.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting; -import com.datastax.oss.driver.shaded.guava.common.base.Joiner; -import java.util.Arrays; -import java.util.regex.Pattern; - -class PackageUtil { - static final String DEFAULT_SPECULATIVE_EXECUTION_PACKAGE = - "com.datastax.oss.driver.internal.core.specex"; - static final String DEFAULT_LOAD_BALANCING_PACKAGE = - "com.datastax.oss.driver.internal.core.loadbalancing"; - static final String DEFAULT_AUTH_PROVIDER_PACKAGE = "com.datastax.oss.driver.internal.core.auth"; - private static final Pattern PACKAGE_SPLIT_REGEX = Pattern.compile("\\."); - private static final Joiner DOT_JOINER = Joiner.on("."); - - static String getNamespace(Class tClass) { - String namespace = ""; - Package packageInfo = tClass.getPackage(); - if (packageInfo != null) { - namespace = packageInfo.getName(); - } - return namespace; - } - - static ClassSettingDetails getSpeculativeExecutionDetails(String classSetting) { - return getClassSettingDetails(classSetting, DEFAULT_SPECULATIVE_EXECUTION_PACKAGE); - } - - static ClassSettingDetails getLoadBalancingDetails(String classSetting) { - return getClassSettingDetails(classSetting, DEFAULT_LOAD_BALANCING_PACKAGE); - } - - static ClassSettingDetails getAuthProviderDetails(String classSetting) { - return getClassSettingDetails(classSetting, DEFAULT_AUTH_PROVIDER_PACKAGE); - } - - private static ClassSettingDetails getClassSettingDetails( - String classSetting, String packageName) { - String className = getClassName(classSetting); - String fullPackage = getFullPackageOrDefault(classSetting, packageName); - return new ClassSettingDetails(className, fullPackage); - } - - @VisibleForTesting - static String getClassName(String classSetting) { - String[] split = PACKAGE_SPLIT_REGEX.split(classSetting); - if (split.length == 0) { - return ""; - } - return split[split.length - 1]; - } - - @VisibleForTesting - static String getFullPackageOrDefault(String classSetting, String defaultValue) { - String[] split = PACKAGE_SPLIT_REGEX.split(classSetting); - if (split.length <= 1) return defaultValue; - return DOT_JOINER.join(Arrays.copyOf(split, split.length - 1)); - } - - static class ClassSettingDetails { - private final String className; - private final String fullPackage; - - ClassSettingDetails(String className, String fullPackage) { - this.className = className; - this.fullPackage = fullPackage; - } - - String getClassName() { - return className; - } - - String getFullPackage() { - return fullPackage; - } - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/PlatformInfoFinder.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/PlatformInfoFinder.java deleted file mode 100644 index 30d41d40836..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/PlatformInfoFinder.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.OS; -import static com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.RuntimeAndCompileTimeVersions; - -import com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo; -import com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.CPUS; -import com.datastax.oss.driver.internal.core.os.Native; -import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Properties; -import java.util.function.Function; -import java.util.regex.Pattern; - -class PlatformInfoFinder { - private static final String MAVEN_IGNORE_LINE = "The following files have been resolved:"; - private static final Pattern DEPENDENCY_SPLIT_REGEX = Pattern.compile(":"); - static final String UNVERIFIED_RUNTIME_VERSION = "UNVERIFIED"; - private final Function propertiesUrlProvider; - - @SuppressWarnings("UnnecessaryLambda") - private static final Function M2_PROPERTIES_PROVIDER = - d -> { - ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - if (contextClassLoader == null) { - contextClassLoader = PlatformInfoFinder.class.getClassLoader(); - } - return contextClassLoader.getResource( - "META-INF/maven/" + d.groupId + "/" + d.artifactId + "/pom.properties"); - }; - - PlatformInfoFinder() { - this(M2_PROPERTIES_PROVIDER); - } - - @VisibleForTesting - PlatformInfoFinder(Function pomPropertiesUrlProvider) { - this.propertiesUrlProvider = pomPropertiesUrlProvider; - } - - InsightsPlatformInfo getInsightsPlatformInfo() { - OS os = getOsInfo(); - CPUS cpus = getCpuInfo(); - Map> runtimeInfo = getRuntimeInfo(); - - return new InsightsPlatformInfo(os, cpus, runtimeInfo); - } - - private Map> getRuntimeInfo() { - Map coreDeps = - fetchDependenciesFromFile( - this.getClass().getResourceAsStream("/com/datastax/dse/driver/internal/deps.txt")); - - Map queryBuilderDeps = - fetchDependenciesFromFile( - this.getClass() - .getResourceAsStream("/com/datastax/dse/driver/internal/querybuilder/deps.txt")); - - Map mapperProcessorDeps = - fetchDependenciesFromFile( - this.getClass() - .getResourceAsStream( - "/com/datastax/dse/driver/internal/mapper/processor/deps.txt")); - - Map mapperRuntimeDeps = - fetchDependenciesFromFile( - this.getClass() - .getResourceAsStream("/com/datastax/dse/driver/internal/mapper/deps.txt")); - - Map> runtimeDependencies = - new LinkedHashMap<>(); - putIfNonEmpty(coreDeps, runtimeDependencies, "core"); - putIfNonEmpty(queryBuilderDeps, runtimeDependencies, "query-builder"); - putIfNonEmpty(mapperProcessorDeps, runtimeDependencies, "mapper-processor"); - putIfNonEmpty(mapperRuntimeDeps, runtimeDependencies, "mapper-runtime"); - addJavaVersion(runtimeDependencies); - return runtimeDependencies; - } - - private void putIfNonEmpty( - Map moduleDependencies, - Map> runtimeDependencies, - String moduleName) { - if (!moduleDependencies.isEmpty()) { - runtimeDependencies.put(moduleName, moduleDependencies); - } - } - - @VisibleForTesting - void addJavaVersion(Map> runtimeDependencies) { - Package javaPackage = Runtime.class.getPackage(); - Map javaDependencies = new LinkedHashMap<>(); - javaDependencies.put( - "version", toSameRuntimeAndCompileVersion(javaPackage.getImplementationVersion())); - javaDependencies.put( - "vendor", toSameRuntimeAndCompileVersion(javaPackage.getImplementationVendor())); - javaDependencies.put( - "title", toSameRuntimeAndCompileVersion(javaPackage.getImplementationTitle())); - putIfNonEmpty(javaDependencies, runtimeDependencies, "java"); - } - - private RuntimeAndCompileTimeVersions toSameRuntimeAndCompileVersion(String version) { - return new RuntimeAndCompileTimeVersions(version, version, false); - } - - /** - * Method is fetching dependencies from file. Lines in file should be in format: - * com.organization:artifactId:jar:1.2.0 or com.organization:artifactId:jar:native:1.2.0 - * - *

For such file the output will be: Map - * "com.organization:artifactId",{"runtimeVersion":"1.2.0", "compileVersion:"1.2.0", "optional": - * false} Duplicates will be omitted. If there are two dependencies for the exactly the same - * organizationId:artifactId it is not deterministic which version will be taken. In the case of - * an error while opening file this method will fail silently returning an empty Map - */ - @VisibleForTesting - Map fetchDependenciesFromFile(InputStream inputStream) { - Map dependencies = new LinkedHashMap<>(); - if (inputStream == null) { - return dependencies; - } - try { - List dependenciesFromFile = extractMavenDependenciesFromFile(inputStream); - for (DependencyFromFile d : dependenciesFromFile) { - dependencies.put(formatDependencyName(d), getRuntimeAndCompileVersion(d)); - } - } catch (IOException e) { - return dependencies; - } - return dependencies; - } - - private RuntimeAndCompileTimeVersions getRuntimeAndCompileVersion(DependencyFromFile d) { - URL url = propertiesUrlProvider.apply(d); - if (url == null) { - return new RuntimeAndCompileTimeVersions( - UNVERIFIED_RUNTIME_VERSION, d.getVersion(), d.isOptional()); - } - Properties properties = new Properties(); - try { - properties.load(url.openStream()); - } catch (IOException e) { - return new RuntimeAndCompileTimeVersions( - UNVERIFIED_RUNTIME_VERSION, d.getVersion(), d.isOptional()); - } - Object version = properties.get("version"); - if (version == null) { - return new RuntimeAndCompileTimeVersions( - UNVERIFIED_RUNTIME_VERSION, d.getVersion(), d.isOptional()); - } else { - return new RuntimeAndCompileTimeVersions(version.toString(), d.getVersion(), d.isOptional()); - } - } - - private String formatDependencyName(DependencyFromFile d) { - return String.format("%s:%s", d.getGroupId(), d.getArtifactId()); - } - - private List extractMavenDependenciesFromFile(InputStream inputStream) - throws IOException { - List dependenciesFromFile = new ArrayList<>(); - BufferedReader reader = - new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); - for (String line; (line = reader.readLine()) != null; ) { - if (lineWithDependencyInfo(line)) { - dependenciesFromFile.add(extractDependencyFromLine(line.trim())); - } - } - return dependenciesFromFile; - } - - private DependencyFromFile extractDependencyFromLine(String line) { - String[] split = DEPENDENCY_SPLIT_REGEX.split(line); - if (split.length == 6) { // case for i.e.: com.github.jnr:jffi:jar:native:1.2.16:compile - return new DependencyFromFile(split[0], split[1], split[4], checkIsOptional(split[5])); - } else { // case for normal: org.ow2.asm:asm:jar:5.0.3:compile - return new DependencyFromFile(split[0], split[1], split[3], checkIsOptional(split[4])); - } - } - - private boolean checkIsOptional(String scope) { - return scope.contains("(optional)"); - } - - private boolean lineWithDependencyInfo(String line) { - return (!line.equals(MAVEN_IGNORE_LINE) && !line.isEmpty()); - } - - private CPUS getCpuInfo() { - int numberOfProcessors = Runtime.getRuntime().availableProcessors(); - String model = Native.getCpu(); - return new CPUS(numberOfProcessors, model); - } - - private OS getOsInfo() { - String osName = System.getProperty("os.name"); - String osVersion = System.getProperty("os.version"); - String osArch = System.getProperty("os.arch"); - return new OS(osName, osVersion, osArch); - } - - static class DependencyFromFile { - private final String groupId; - private final String artifactId; - private final String version; - private final boolean optional; - - DependencyFromFile(String groupId, String artifactId, String version, boolean optional) { - this.groupId = groupId; - this.artifactId = artifactId; - this.version = version; - this.optional = optional; - } - - String getGroupId() { - return groupId; - } - - String getArtifactId() { - return artifactId; - } - - String getVersion() { - return version; - } - - boolean isOptional() { - return optional; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof DependencyFromFile)) { - return false; - } - DependencyFromFile that = (DependencyFromFile) o; - return optional == that.optional - && Objects.equals(groupId, that.groupId) - && Objects.equals(artifactId, that.artifactId) - && Objects.equals(version, that.version); - } - - @Override - public int hashCode() { - return Objects.hash(groupId, artifactId, version, optional); - } - - @Override - public String toString() { - return "DependencyFromFile{" - + "groupId='" - + groupId - + '\'' - + ", artifactId='" - + artifactId - + '\'' - + ", version='" - + version - + '\'' - + ", optional=" - + optional - + '}'; - } - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/ReconnectionPolicyInfoFinder.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/ReconnectionPolicyInfoFinder.java deleted file mode 100644 index af8aff74035..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/ReconnectionPolicyInfoFinder.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import com.datastax.dse.driver.internal.core.insights.schema.ReconnectionPolicyInfo; -import com.datastax.oss.driver.api.core.config.DefaultDriverOption; -import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; -import com.datastax.oss.driver.api.core.connection.ReconnectionPolicy; -import com.datastax.oss.driver.internal.core.connection.ConstantReconnectionPolicy; -import com.datastax.oss.driver.internal.core.connection.ExponentialReconnectionPolicy; -import java.util.HashMap; -import java.util.Map; - -class ReconnectionPolicyInfoFinder { - ReconnectionPolicyInfo getReconnectionPolicyInfo( - ReconnectionPolicy reconnectionPolicy, DriverExecutionProfile executionProfile) { - Class reconnectionPolicyClass = reconnectionPolicy.getClass(); - String type = reconnectionPolicyClass.getSimpleName(); - String namespace = PackageUtil.getNamespace(reconnectionPolicyClass); - Map options = new HashMap<>(); - if (reconnectionPolicy instanceof ConstantReconnectionPolicy) { - options.put( - "delayMs", - executionProfile.getDuration(DefaultDriverOption.RECONNECTION_BASE_DELAY).toMillis()); - } else if (reconnectionPolicy instanceof ExponentialReconnectionPolicy) { - ExponentialReconnectionPolicy exponentialReconnectionPolicy = - (ExponentialReconnectionPolicy) reconnectionPolicy; - options.put("maxDelayMs", exponentialReconnectionPolicy.getMaxDelayMs()); - options.put("baseDelayMs", exponentialReconnectionPolicy.getBaseDelayMs()); - options.put("maxAttempts", exponentialReconnectionPolicy.getMaxAttempts()); - } - return new ReconnectionPolicyInfo(type, options, namespace); - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/configuration/InsightsConfiguration.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/configuration/InsightsConfiguration.java deleted file mode 100644 index ac27bb76389..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/configuration/InsightsConfiguration.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.configuration; - -import io.netty.util.concurrent.EventExecutor; - -public class InsightsConfiguration { - private final boolean monitorReportingEnabled; - private final long statusEventDelayMillis; - private final EventExecutor executor; - - public InsightsConfiguration( - boolean monitorReportingEnabled, long statusEventDelayMillis, EventExecutor executor) { - this.monitorReportingEnabled = monitorReportingEnabled; - this.statusEventDelayMillis = statusEventDelayMillis; - this.executor = executor; - } - - public boolean isMonitorReportingEnabled() { - return monitorReportingEnabled; - } - - public long getStatusEventDelayMillis() { - return statusEventDelayMillis; - } - - public EventExecutor getExecutor() { - return executor; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/exceptions/InsightEventFormatException.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/exceptions/InsightEventFormatException.java deleted file mode 100644 index cfce68971ef..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/exceptions/InsightEventFormatException.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.exceptions; - -public class InsightEventFormatException extends RuntimeException { - - public InsightEventFormatException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/AuthProviderType.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/AuthProviderType.java deleted file mode 100644 index 18aec53e899..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/AuthProviderType.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Objects; - -public class AuthProviderType { - @JsonProperty("type") - private final String type; - - @JsonProperty("namespace") - private final String namespace; - - @JsonCreator - public AuthProviderType( - @JsonProperty("type") String type, @JsonProperty("namespace") String namespace) { - this.type = type; - this.namespace = namespace; - } - - public String getType() { - return type; - } - - public String getNamespace() { - return namespace; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof AuthProviderType)) { - return false; - } - AuthProviderType that = (AuthProviderType) o; - return Objects.equals(type, that.type) && Objects.equals(namespace, that.namespace); - } - - @Override - public int hashCode() { - return Objects.hash(type, namespace); - } - - @Override - public String toString() { - return "AuthProviderType{" + "type='" + type + '\'' + ", namespace='" + namespace + '\'' + '}'; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/Insight.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/Insight.java deleted file mode 100644 index ca4e6455345..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/Insight.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public class Insight { - @JsonProperty("metadata") - private final InsightMetadata metadata; - - @JsonProperty("data") - private final T insightData; - - @JsonCreator - public Insight(@JsonProperty("metadata") InsightMetadata metadata, @JsonProperty("data") T data) { - this.metadata = metadata; - this.insightData = data; - } - - public InsightMetadata getMetadata() { - return metadata; - } - - public T getInsightData() { - return insightData; - } - - @Override - public String toString() { - return "Insight{" + "metadata=" + metadata + ", insightData=" + insightData + '}'; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightMetadata.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightMetadata.java deleted file mode 100644 index cfa2644b0c7..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightMetadata.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.datastax.oss.driver.shaded.guava.common.base.Preconditions; -import com.datastax.oss.driver.shaded.guava.common.base.Strings; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Map; -import java.util.Objects; - -public class InsightMetadata { - @JsonProperty("name") - private final String name; - - @JsonProperty("timestamp") - private final long timestamp; - - @JsonProperty("tags") - private final Map tags; - - @JsonProperty("insightType") - private final InsightType insightType; - - @JsonProperty("insightMappingId") - @JsonInclude(JsonInclude.Include.NON_NULL) - private String insightMappingId; - - @JsonCreator - public InsightMetadata( - @JsonProperty("name") String name, - @JsonProperty("timestamp") long timestamp, - @JsonProperty("tags") Map tags, - @JsonProperty("insightType") InsightType insightType, - @JsonProperty("insightMappingId") String insightMappingId) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "name is required"); - - this.name = name; - this.timestamp = timestamp; - this.tags = tags; - this.insightType = insightType; - this.insightMappingId = insightMappingId; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof InsightMetadata)) { - return false; - } - InsightMetadata that = (InsightMetadata) o; - return Objects.equals(name, that.name) - && Objects.equals(timestamp, that.timestamp) - && Objects.equals(tags, that.tags) - && insightType == that.insightType - && Objects.equals(insightMappingId, that.insightMappingId); - } - - @Override - public int hashCode() { - return Objects.hash(name, timestamp, tags, insightType, insightMappingId); - } - - @Override - public String toString() { - return "InsightMetadata{" - + "name='" - + name - + '\'' - + ", timestamp=" - + timestamp - + ", tags=" - + tags - + ", insightType=" - + insightType - + ", insightMappingId=" - + insightMappingId - + '}'; - } - - public String getName() { - return name; - } - - public long getTimestamp() { - return timestamp; - } - - public Map getTags() { - return tags; - } - - public InsightType getInsightType() { - return insightType; - } - - public String getInsightMappingId() { - return insightMappingId; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightType.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightType.java deleted file mode 100644 index ae91e27d227..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightType.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -public enum InsightType { - EVENT, - GAUGE, - COUNTER, - HISTOGRAM, - TIMER, - METER, - LOG; -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightsPlatformInfo.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightsPlatformInfo.java deleted file mode 100644 index 231f082d785..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightsPlatformInfo.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Map; -import java.util.Objects; - -public class InsightsPlatformInfo { - @JsonProperty("os") - private final OS os; - - @JsonProperty("cpus") - private CPUS cpus; - - /** - * All dependencies in a map format grouped by the module: {"core" : {"com.datastax.driver:core": - * {"runtimeVersion:" : "1.0.0", "compileVersion": "1.0.1"},...}}, "extras"" {...} - */ - @JsonProperty("runtime") - private Map> runtime; - - @JsonCreator - public InsightsPlatformInfo( - @JsonProperty("os") OS os, - @JsonProperty("cpus") CPUS cpus, - @JsonProperty("runtime") Map> runtime) { - this.os = os; - this.cpus = cpus; - this.runtime = runtime; - } - - public OS getOs() { - return os; - } - - public CPUS getCpus() { - return cpus; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof InsightsPlatformInfo)) { - return false; - } - InsightsPlatformInfo that = (InsightsPlatformInfo) o; - return Objects.equals(os, that.os) - && Objects.equals(cpus, that.cpus) - && Objects.equals(runtime, that.runtime); - } - - @Override - public int hashCode() { - return Objects.hash(os, cpus, runtime); - } - - Map> getRuntime() { - return runtime; - } - - public static class OS { - @JsonProperty("name") - private final String name; - - @JsonProperty("version") - private final String version; - - @JsonProperty("arch") - private final String arch; - - @JsonCreator - public OS( - @JsonProperty("name") String name, - @JsonProperty("version") String version, - @JsonProperty("arch") String arch) { - this.name = name; - this.version = version; - this.arch = arch; - } - - public String getName() { - return name; - } - - public String getVersion() { - return version; - } - - public String getArch() { - return arch; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof OS)) { - return false; - } - OS os = (OS) o; - return Objects.equals(name, os.name) - && Objects.equals(version, os.version) - && Objects.equals(arch, os.arch); - } - - @Override - public int hashCode() { - return Objects.hash(name, version, arch); - } - } - - public static class CPUS { - @JsonProperty("length") - private final int length; - - @JsonProperty("model") - private final String model; - - @JsonCreator - public CPUS(@JsonProperty("length") int length, @JsonProperty("model") String model) { - this.length = length; - this.model = model; - } - - public int getLength() { - return length; - } - - public String getModel() { - return model; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof CPUS)) { - return false; - } - CPUS cpus = (CPUS) o; - return length == cpus.length && Objects.equals(model, cpus.model); - } - - @Override - public int hashCode() { - return Objects.hash(length, model); - } - } - - public static class RuntimeAndCompileTimeVersions { - @JsonProperty("runtimeVersion") - private final String runtimeVersion; - - @JsonProperty("compileVersion") - private final String compileVersion; - - @JsonProperty("optional") - private final boolean optional; - - @JsonCreator - public RuntimeAndCompileTimeVersions( - @JsonProperty("runtimeVersion") String runtimeVersion, - @JsonProperty("compileVersion") String compileVersion, - @JsonProperty("optional") boolean optional) { - this.runtimeVersion = runtimeVersion; - this.compileVersion = compileVersion; - this.optional = optional; - } - - public String getRuntimeVersion() { - return runtimeVersion; - } - - public String getCompileVersion() { - return compileVersion; - } - - public boolean isOptional() { - return optional; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof RuntimeAndCompileTimeVersions)) { - return false; - } - RuntimeAndCompileTimeVersions that = (RuntimeAndCompileTimeVersions) o; - return optional == that.optional - && Objects.equals(runtimeVersion, that.runtimeVersion) - && Objects.equals(compileVersion, that.compileVersion); - } - - @Override - public int hashCode() { - return Objects.hash(runtimeVersion, compileVersion, optional); - } - - @Override - public String toString() { - return "RuntimeAndCompileTimeVersions{" - + "runtimeVersion='" - + runtimeVersion - + '\'' - + ", compileVersion='" - + compileVersion - + '\'' - + ", optional=" - + optional - + '}'; - } - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightsStartupData.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightsStartupData.java deleted file mode 100644 index bddd3ef94b3..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightsStartupData.java +++ /dev/null @@ -1,425 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class InsightsStartupData { - @JsonProperty("clientId") - private final String clientId; - - @JsonProperty("sessionId") - private final String sessionId; - - @JsonProperty("applicationName") - private final String applicationName; - - @JsonProperty("applicationVersion") - private final String applicationVersion; - - @JsonProperty("contactPoints") - private final Map> contactPoints; - - @JsonProperty("initialControlConnection") - private final String initialControlConnection; - - @JsonProperty("protocolVersion") - private final int protocolVersion; - - @JsonProperty("localAddress") - private final String localAddress; - - @JsonProperty("executionProfiles") - private final Map executionProfiles; - - @JsonProperty("poolSizeByHostDistance") - private final PoolSizeByHostDistance poolSizeByHostDistance; - - @JsonProperty("heartbeatInterval") - private final long heartbeatInterval; - - @JsonProperty("compression") - private final String compression; - - @JsonProperty("reconnectionPolicy") - private final ReconnectionPolicyInfo reconnectionPolicy; - - @JsonProperty("ssl") - private final SSL ssl; - - @JsonProperty("authProvider") - private final AuthProviderType authProvider; - - @JsonProperty("otherOptions") - private final Map otherOptions; - - @JsonProperty("configAntiPatterns") - private final Map configAntiPatterns; - - @JsonProperty("periodicStatusInterval") - private final long periodicStatusInterval; - - @JsonProperty("platformInfo") - private final InsightsPlatformInfo platformInfo; - - @JsonProperty("hostName") - private final String hostName; - - @JsonProperty("driverName") - private String driverName; - - @JsonProperty("applicationNameWasGenerated") - private boolean applicationNameWasGenerated; - - @JsonProperty("driverVersion") - private String driverVersion; - - @JsonProperty("dataCenters") - private Set dataCenters; - - @JsonCreator - private InsightsStartupData( - @JsonProperty("clientId") String clientId, - @JsonProperty("sessionId") String sessionId, - @JsonProperty("applicationName") String applicationName, - @JsonProperty("applicationVersion") String applicationVersion, - @JsonProperty("contactPoints") Map> contactPoints, - @JsonProperty("initialControlConnection") String initialControlConnection, - @JsonProperty("protocolVersion") int protocolVersion, - @JsonProperty("localAddress") String localAddress, - @JsonProperty("executionProfiles") Map executionProfiles, - @JsonProperty("poolSizeByHostDistance") PoolSizeByHostDistance poolSizeByHostDistance, - @JsonProperty("heartbeatInterval") long heartbeatInterval, - @JsonProperty("compression") String compression, - @JsonProperty("reconnectionPolicy") ReconnectionPolicyInfo reconnectionPolicy, - @JsonProperty("ssl") SSL ssl, - @JsonProperty("authProvider") AuthProviderType authProvider, - @JsonProperty("otherOptions") Map otherOptions, - @JsonProperty("configAntiPatterns") Map configAntiPatterns, - @JsonProperty("periodicStatusInterval") long periodicStatusInterval, - @JsonProperty("platformInfo") InsightsPlatformInfo platformInfo, - @JsonProperty("hostName") String hostName, - @JsonProperty("driverName") String driverName, - @JsonProperty("applicationNameWasGenerated") boolean applicationNameWasGenerated, - @JsonProperty("driverVersion") String driverVersion, - @JsonProperty("dataCenters") Set dataCenters) { - this.clientId = clientId; - this.sessionId = sessionId; - this.applicationName = applicationName; - this.applicationVersion = applicationVersion; - this.contactPoints = contactPoints; - this.initialControlConnection = initialControlConnection; - this.protocolVersion = protocolVersion; - this.localAddress = localAddress; - this.executionProfiles = executionProfiles; - this.poolSizeByHostDistance = poolSizeByHostDistance; - this.heartbeatInterval = heartbeatInterval; - this.compression = compression; - this.reconnectionPolicy = reconnectionPolicy; - this.ssl = ssl; - this.authProvider = authProvider; - this.otherOptions = otherOptions; - this.configAntiPatterns = configAntiPatterns; - this.periodicStatusInterval = periodicStatusInterval; - this.platformInfo = platformInfo; - this.hostName = hostName; - this.driverName = driverName; - this.applicationNameWasGenerated = applicationNameWasGenerated; - this.driverVersion = driverVersion; - this.dataCenters = dataCenters; - } - - public String getClientId() { - return clientId; - } - - public String getSessionId() { - return sessionId; - } - - public String getApplicationName() { - return applicationName; - } - - public String getApplicationVersion() { - return applicationVersion; - } - - public Map> getContactPoints() { - return contactPoints; - } - - public String getInitialControlConnection() { - return initialControlConnection; - } - - public int getProtocolVersion() { - return protocolVersion; - } - - public String getLocalAddress() { - return localAddress; - } - - public Map getExecutionProfiles() { - return executionProfiles; - } - - public PoolSizeByHostDistance getPoolSizeByHostDistance() { - return poolSizeByHostDistance; - } - - public long getHeartbeatInterval() { - return heartbeatInterval; - } - - public String getCompression() { - return compression; - } - - public ReconnectionPolicyInfo getReconnectionPolicy() { - return reconnectionPolicy; - } - - public SSL getSsl() { - return ssl; - } - - public AuthProviderType getAuthProvider() { - return authProvider; - } - - public Map getOtherOptions() { - return otherOptions; - } - - public Map getConfigAntiPatterns() { - return configAntiPatterns; - } - - public long getPeriodicStatusInterval() { - return periodicStatusInterval; - } - - public InsightsPlatformInfo getPlatformInfo() { - return platformInfo; - } - - public String getHostName() { - return hostName; - } - - public String getDriverName() { - return driverName; - } - - public boolean isApplicationNameWasGenerated() { - return applicationNameWasGenerated; - } - - public String getDriverVersion() { - return driverVersion; - } - - public Set getDataCenters() { - return dataCenters; - } - - public static InsightsStartupData.Builder builder() { - return new InsightsStartupData.Builder(); - } - - public static class Builder { - private String clientId; - private String sessionId; - private String applicationName; - private String applicationVersion; - private Map> contactPoints; - private String initialControlConnection; - private int protocolVersion; - private String localAddress; - private Map executionProfiles; - private PoolSizeByHostDistance poolSizeByHostDistance; - private long heartbeatInterval; - private String compression; - private ReconnectionPolicyInfo reconnectionPolicy; - private SSL ssl; - private AuthProviderType authProvider; - private Map otherOptions; - private Map configAntiPatterns; - private long periodicStatusInterval; - private InsightsPlatformInfo platformInfo; - private String hostName; - private String driverName; - private String driverVersion; - private boolean applicationNameWasGenerated; - private Set dataCenters; - - public InsightsStartupData build() { - return new InsightsStartupData( - clientId, - sessionId, - applicationName, - applicationVersion, - contactPoints, - initialControlConnection, - protocolVersion, - localAddress, - executionProfiles, - poolSizeByHostDistance, - heartbeatInterval, - compression, - reconnectionPolicy, - ssl, - authProvider, - otherOptions, - configAntiPatterns, - periodicStatusInterval, - platformInfo, - hostName, - driverName, - applicationNameWasGenerated, - driverVersion, - dataCenters); - } - - public Builder withClientId(String clientId) { - this.clientId = clientId; - return this; - } - - public Builder withSessionId(String id) { - this.sessionId = id; - return this; - } - - public Builder withApplicationName(String applicationName) { - this.applicationName = applicationName; - return this; - } - - public Builder withApplicationVersion(String applicationVersion) { - this.applicationVersion = applicationVersion; - return this; - } - - public Builder withContactPoints(Map> contactPoints) { - this.contactPoints = contactPoints; - return this; - } - - public Builder withInitialControlConnection(String inetSocketAddress) { - this.initialControlConnection = inetSocketAddress; - return this; - } - - public Builder withProtocolVersion(int protocolVersion) { - this.protocolVersion = protocolVersion; - return this; - } - - public Builder withLocalAddress(String localAddress) { - this.localAddress = localAddress; - return this; - } - - public Builder withExecutionProfiles(Map executionProfiles) { - this.executionProfiles = executionProfiles; - return this; - } - - public Builder withPoolSizeByHostDistance(PoolSizeByHostDistance poolSizeByHostDistance) { - this.poolSizeByHostDistance = poolSizeByHostDistance; - return this; - } - - public Builder withHeartbeatInterval(long heartbeatInterval) { - this.heartbeatInterval = heartbeatInterval; - return this; - } - - public Builder withCompression(String compression) { - this.compression = compression; - return this; - } - - public Builder withReconnectionPolicy(ReconnectionPolicyInfo reconnectionPolicy) { - this.reconnectionPolicy = reconnectionPolicy; - return this; - } - - public Builder withSsl(SSL ssl) { - this.ssl = ssl; - return this; - } - - public Builder withAuthProvider(AuthProviderType authProvider) { - this.authProvider = authProvider; - return this; - } - - public Builder withOtherOptions(Map otherOptions) { - this.otherOptions = otherOptions; - return this; - } - - public Builder withConfigAntiPatterns(Map configAntiPatterns) { - this.configAntiPatterns = configAntiPatterns; - return this; - } - - public Builder withPeriodicStatusInterval(long periodicStatusInterval) { - this.periodicStatusInterval = periodicStatusInterval; - return this; - } - - public Builder withPlatformInfo(InsightsPlatformInfo insightsPlatformInfo) { - this.platformInfo = insightsPlatformInfo; - return this; - } - - public Builder withHostName(String hostName) { - this.hostName = hostName; - return this; - } - - public Builder withDriverName(String driverName) { - this.driverName = driverName; - return this; - } - - public Builder withDriverVersion(String driverVersion) { - this.driverVersion = driverVersion; - return this; - } - - public Builder withApplicationNameWasGenerated(boolean applicationNameWasGenerated) { - this.applicationNameWasGenerated = applicationNameWasGenerated; - return this; - } - - public Builder withDataCenters(Set dataCenters) { - this.dataCenters = dataCenters; - return this; - } - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightsStatusData.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightsStatusData.java deleted file mode 100644 index 6f5a135f7c4..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/InsightsStatusData.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Map; -import java.util.Objects; - -public class InsightsStatusData { - @JsonProperty("clientId") - private final String clientId; - - @JsonProperty("sessionId") - private final String sessionId; - - @JsonProperty("controlConnection") - private final String controlConnection; - - @JsonProperty("connectedNodes") - private final Map connectedNodes; - - @JsonCreator - private InsightsStatusData( - @JsonProperty("clientId") String clientId, - @JsonProperty("sessionId") String sessionId, - @JsonProperty("controlConnection") String controlConnection, - @JsonProperty("connectedNodes") Map connectedNodes) { - this.clientId = clientId; - this.sessionId = sessionId; - this.controlConnection = controlConnection; - this.connectedNodes = connectedNodes; - } - - public String getClientId() { - return clientId; - } - - public String getSessionId() { - return sessionId; - } - - public String getControlConnection() { - return controlConnection; - } - - public Map getConnectedNodes() { - return connectedNodes; - } - - @Override - public String toString() { - return "InsightsStatusData{" - + "clientId='" - + clientId - + '\'' - + ", sessionId='" - + sessionId - + '\'' - + ", controlConnection=" - + controlConnection - + ", connectedNodes=" - + connectedNodes - + '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof InsightsStatusData)) { - return false; - } - InsightsStatusData that = (InsightsStatusData) o; - return Objects.equals(clientId, that.clientId) - && Objects.equals(sessionId, that.sessionId) - && Objects.equals(controlConnection, that.controlConnection) - && Objects.equals(connectedNodes, that.connectedNodes); - } - - @Override - public int hashCode() { - return Objects.hash(clientId, sessionId, controlConnection, connectedNodes); - } - - public static InsightsStatusData.Builder builder() { - return new InsightsStatusData.Builder(); - } - - public static class Builder { - private String clientId; - private String sessionId; - private String controlConnection; - private Map connectedNodes; - - public Builder withClientId(String clientId) { - this.clientId = clientId; - return this; - } - - public Builder withSessionId(String id) { - this.sessionId = id; - return this; - } - - public Builder withControlConnection(String controlConnection) { - this.controlConnection = controlConnection; - return this; - } - - public Builder withConnectedNodes(Map connectedNodes) { - this.connectedNodes = connectedNodes; - return this; - } - - public InsightsStatusData build() { - return new InsightsStatusData(clientId, sessionId, controlConnection, connectedNodes); - } - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/LoadBalancingInfo.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/LoadBalancingInfo.java deleted file mode 100644 index 594583e3f28..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/LoadBalancingInfo.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Map; -import java.util.Objects; - -public class LoadBalancingInfo { - @JsonProperty("type") - private final String type; - - @JsonProperty("options") - private final Map options; - - @JsonProperty("namespace") - private final String namespace; - - @JsonCreator - public LoadBalancingInfo( - @JsonProperty("type") String type, - @JsonProperty("options") Map options, - @JsonProperty("namespace") String namespace) { - this.type = type; - this.options = options; - this.namespace = namespace; - } - - public String getType() { - return type; - } - - public Map getOptions() { - return options; - } - - public String getNamespace() { - return namespace; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof LoadBalancingInfo)) { - return false; - } - LoadBalancingInfo that = (LoadBalancingInfo) o; - return Objects.equals(type, that.type) - && Objects.equals(options, that.options) - && Objects.equals(namespace, that.namespace); - } - - @Override - public int hashCode() { - return Objects.hash(type, options, namespace); - } - - @Override - public String toString() { - return "LoadBalancingInfo{" - + "type='" - + type - + '\'' - + ", options=" - + options - + ", namespace='" - + namespace - + '\'' - + '}'; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/PoolSizeByHostDistance.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/PoolSizeByHostDistance.java deleted file mode 100644 index 07f76a18d40..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/PoolSizeByHostDistance.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Objects; - -public class PoolSizeByHostDistance { - @JsonProperty("local") - private final int local; - - @JsonProperty("remote") - private final int remote; - - @JsonProperty("ignored") - private final int ignored; - - @JsonCreator - public PoolSizeByHostDistance( - @JsonProperty("local") int local, - @JsonProperty("remote") int remote, - @JsonProperty("ignored") int ignored) { - - this.local = local; - this.remote = remote; - this.ignored = ignored; - } - - public int getLocal() { - return local; - } - - public int getRemote() { - return remote; - } - - public int getIgnored() { - return ignored; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof PoolSizeByHostDistance)) { - return false; - } - PoolSizeByHostDistance that = (PoolSizeByHostDistance) o; - return local == that.local && remote == that.remote && ignored == that.ignored; - } - - @Override - public int hashCode() { - return Objects.hash(local, remote, ignored); - } - - @Override - public String toString() { - return "PoolSizeByHostDistance{" - + "local=" - + local - + ", remote=" - + remote - + ", ignored=" - + ignored - + '}'; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/ReconnectionPolicyInfo.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/ReconnectionPolicyInfo.java deleted file mode 100644 index 463c23a4325..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/ReconnectionPolicyInfo.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Map; -import java.util.Objects; - -public class ReconnectionPolicyInfo { - @JsonProperty("type") - private final String type; - - @JsonProperty("options") - private final Map options; - - @JsonProperty("namespace") - private final String namespace; - - @JsonCreator - public ReconnectionPolicyInfo( - @JsonProperty("type") String type, - @JsonProperty("options") Map options, - @JsonProperty("namespace") String namespace) { - - this.type = type; - this.options = options; - this.namespace = namespace; - } - - public String getType() { - return type; - } - - public Map getOptions() { - return options; - } - - public String getNamespace() { - return namespace; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof ReconnectionPolicyInfo)) { - return false; - } - ReconnectionPolicyInfo that = (ReconnectionPolicyInfo) o; - return Objects.equals(type, that.type) - && Objects.equals(options, that.options) - && Objects.equals(namespace, that.namespace); - } - - @Override - public int hashCode() { - return Objects.hash(type, options, namespace); - } - - @Override - public String toString() { - return "ReconnectionPolicyInfo{" - + "type='" - + type - + '\'' - + ", options=" - + options - + ", namespace='" - + namespace - + '\'' - + '}'; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SSL.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SSL.java deleted file mode 100644 index debcd85c025..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SSL.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Objects; - -public class SSL { - @JsonProperty("enabled") - private final boolean enabled; - - @JsonProperty("certValidation") - private final boolean certValidation; - - @JsonCreator - public SSL( - @JsonProperty("enabled") boolean enabled, - @JsonProperty("certValidation") boolean certValidation) { - this.enabled = enabled; - this.certValidation = certValidation; - } - - public boolean isEnabled() { - return enabled; - } - - public boolean isCertValidation() { - return certValidation; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof SSL)) { - return false; - } - SSL that = (SSL) o; - return enabled == that.enabled && certValidation == that.certValidation; - } - - @Override - public int hashCode() { - return Objects.hash(enabled, certValidation); - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SessionStateForNode.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SessionStateForNode.java deleted file mode 100644 index 8b50e5b2313..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SessionStateForNode.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Objects; - -public class SessionStateForNode { - @JsonProperty("connections") - private final Integer connections; - - @JsonProperty("inFlightQueries") - private final Integer inFlightQueries; - - @JsonCreator - public SessionStateForNode( - @JsonProperty("connections") Integer connections, - @JsonProperty("inFlightQueries") Integer inFlightQueries) { - this.connections = connections; - this.inFlightQueries = inFlightQueries; - } - - public Integer getConnections() { - return connections; - } - - public Integer getInFlightQueries() { - return inFlightQueries; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof SessionStateForNode)) { - return false; - } - SessionStateForNode that = (SessionStateForNode) o; - return Objects.equals(connections, that.connections) - && Objects.equals(inFlightQueries, that.inFlightQueries); - } - - @Override - public int hashCode() { - return Objects.hash(connections, inFlightQueries); - } - - @Override - public String toString() { - return "SessionStateForNode{" - + "connections=" - + connections - + ", inFlightQueries=" - + inFlightQueries - + '}'; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SpecificExecutionProfile.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SpecificExecutionProfile.java deleted file mode 100644 index 58652fdf885..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SpecificExecutionProfile.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Map; -import java.util.Objects; - -@JsonInclude(JsonInclude.Include.NON_NULL) -public class SpecificExecutionProfile { - @JsonProperty("readTimeout") - private final Integer readTimeout; - - @JsonProperty("loadBalancing") - private final LoadBalancingInfo loadBalancing; - - @JsonProperty("speculativeExecution") - private SpeculativeExecutionInfo speculativeExecution; - - @JsonProperty("consistency") - private final String consistency; - - @JsonProperty("serialConsistency") - private final String serialConsistency; - - @JsonProperty("graphOptions") - private Map graphOptions; - - @JsonCreator - public SpecificExecutionProfile( - @JsonProperty("readTimeout") Integer readTimeoutMillis, - @JsonProperty("loadBalancing") LoadBalancingInfo loadBalancing, - @JsonProperty("speculativeExecution") SpeculativeExecutionInfo speculativeExecutionInfo, - @JsonProperty("consistency") String consistency, - @JsonProperty("serialConsistency") String serialConsistency, - @JsonProperty("graphOptions") Map graphOptions) { - readTimeout = readTimeoutMillis; - this.loadBalancing = loadBalancing; - this.speculativeExecution = speculativeExecutionInfo; - this.consistency = consistency; - this.serialConsistency = serialConsistency; - this.graphOptions = graphOptions; - } - - public Integer getReadTimeout() { - return readTimeout; - } - - public LoadBalancingInfo getLoadBalancing() { - return loadBalancing; - } - - public SpeculativeExecutionInfo getSpeculativeExecution() { - return speculativeExecution; - } - - public String getConsistency() { - return consistency; - } - - public String getSerialConsistency() { - return serialConsistency; - } - - public Map getGraphOptions() { - return graphOptions; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof SpecificExecutionProfile)) { - return false; - } - SpecificExecutionProfile that = (SpecificExecutionProfile) o; - return Objects.equals(readTimeout, that.readTimeout) - && Objects.equals(loadBalancing, that.loadBalancing) - && Objects.equals(speculativeExecution, that.speculativeExecution) - && Objects.equals(consistency, that.consistency) - && Objects.equals(serialConsistency, that.serialConsistency) - && Objects.equals(graphOptions, that.graphOptions); - } - - @Override - public int hashCode() { - return Objects.hash( - readTimeout, - loadBalancing, - speculativeExecution, - consistency, - serialConsistency, - graphOptions); - } - - @Override - public String toString() { - return "SpecificExecutionProfile{" - + "readTimeout=" - + readTimeout - + ", loadBalancing=" - + loadBalancing - + ", speculativeExecution=" - + speculativeExecution - + ", consistency='" - + consistency - + '\'' - + ", serialConsistency='" - + serialConsistency - + '\'' - + ", graphOptions=" - + graphOptions - + '}'; - } -} diff --git a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SpeculativeExecutionInfo.java b/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SpeculativeExecutionInfo.java deleted file mode 100644 index 779a4ed9e51..00000000000 --- a/core/src/main/java/com/datastax/dse/driver/internal/core/insights/schema/SpeculativeExecutionInfo.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights.schema; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Map; -import java.util.Objects; - -public class SpeculativeExecutionInfo { - @JsonProperty("type") - private final String type; - - @JsonProperty("options") - private final Map options; - - @JsonProperty("namespace") - private String namespace; - - @JsonCreator - public SpeculativeExecutionInfo( - @JsonProperty("type") String type, - @JsonProperty("options") Map options, - @JsonProperty("namespace") String namespace) { - this.type = type; - this.options = options; - this.namespace = namespace; - } - - public String getType() { - return type; - } - - public Map getOptions() { - return options; - } - - public String getNamespace() { - return namespace; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof SpeculativeExecutionInfo)) { - return false; - } - SpeculativeExecutionInfo that = (SpeculativeExecutionInfo) o; - return Objects.equals(type, that.type) - && Objects.equals(options, that.options) - && Objects.equals(namespace, that.namespace); - } - - @Override - public int hashCode() { - return Objects.hash(type, options, namespace); - } - - @Override - public String toString() { - return "SpeculativeExecutionInfo{" - + "type='" - + type - + '\'' - + ", options=" - + options - + ", namespace='" - + namespace - + '\'' - + '}'; - } -} diff --git a/core/src/main/java/com/datastax/oss/driver/api/core/config/OptionsMap.java b/core/src/main/java/com/datastax/oss/driver/api/core/config/OptionsMap.java index 98faf3e590c..a46d1ac6274 100644 --- a/core/src/main/java/com/datastax/oss/driver/api/core/config/OptionsMap.java +++ b/core/src/main/java/com/datastax/oss/driver/api/core/config/OptionsMap.java @@ -306,7 +306,6 @@ protected static void fillWithDriverDefaults(OptionsMap map) { map.put(TypedDriverOption.CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES, continuousMaxEnqueuedPages); map.put(TypedDriverOption.CONTINUOUS_PAGING_TIMEOUT_FIRST_PAGE, Duration.ofSeconds(2)); map.put(TypedDriverOption.CONTINUOUS_PAGING_TIMEOUT_OTHER_PAGES, Duration.ofSeconds(1)); - map.put(TypedDriverOption.MONITOR_REPORTING_ENABLED, true); map.put(TypedDriverOption.METRICS_SESSION_ENABLED, Collections.emptyList()); map.put(TypedDriverOption.METRICS_SESSION_CQL_REQUESTS_HIGHEST, Duration.ofSeconds(3)); map.put(TypedDriverOption.METRICS_SESSION_CQL_REQUESTS_LOWEST, Duration.ofMillis(1)); diff --git a/core/src/main/java/com/datastax/oss/driver/api/core/config/TypedDriverOption.java b/core/src/main/java/com/datastax/oss/driver/api/core/config/TypedDriverOption.java index 93e2b468461..a8ccd9b18a6 100644 --- a/core/src/main/java/com/datastax/oss/driver/api/core/config/TypedDriverOption.java +++ b/core/src/main/java/com/datastax/oss/driver/api/core/config/TypedDriverOption.java @@ -782,9 +782,6 @@ public String toString() { /** How long the driver waits for a graph request to complete. */ public static final TypedDriverOption GRAPH_TIMEOUT = new TypedDriverOption<>(DseDriverOption.GRAPH_TIMEOUT, GenericType.DURATION); - /** Whether to send events for Insights monitoring. */ - public static final TypedDriverOption MONITOR_REPORTING_ENABLED = - new TypedDriverOption<>(DseDriverOption.MONITOR_REPORTING_ENABLED, GenericType.BOOLEAN); /** Whether to enable paging for Graph queries. */ public static final TypedDriverOption GRAPH_PAGING_ENABLED = new TypedDriverOption<>(DseDriverOption.GRAPH_PAGING_ENABLED, GenericType.STRING); diff --git a/core/src/main/java/com/datastax/oss/driver/api/core/session/ProgrammaticArguments.java b/core/src/main/java/com/datastax/oss/driver/api/core/session/ProgrammaticArguments.java index 4e08bd5434c..d2a08329776 100644 --- a/core/src/main/java/com/datastax/oss/driver/api/core/session/ProgrammaticArguments.java +++ b/core/src/main/java/com/datastax/oss/driver/api/core/session/ProgrammaticArguments.java @@ -39,7 +39,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Objects; -import java.util.UUID; import java.util.function.Predicate; /** @@ -66,9 +65,6 @@ public static Builder builder() { private final AuthProvider authProvider; private final SslEngineFactory sslEngineFactory; private final InetSocketAddress cloudProxyAddress; - private final UUID startupClientId; - private final String startupApplicationName; - private final String startupApplicationVersion; private final MutableCodecRegistry codecRegistry; private final Object metricRegistry; @@ -84,9 +80,6 @@ private ProgrammaticArguments( @Nullable AuthProvider authProvider, @Nullable SslEngineFactory sslEngineFactory, @Nullable InetSocketAddress cloudProxyAddress, - @Nullable UUID startupClientId, - @Nullable String startupApplicationName, - @Nullable String startupApplicationVersion, @Nullable MutableCodecRegistry codecRegistry, @Nullable Object metricRegistry) { @@ -101,9 +94,6 @@ private ProgrammaticArguments( this.authProvider = authProvider; this.sslEngineFactory = sslEngineFactory; this.cloudProxyAddress = cloudProxyAddress; - this.startupClientId = startupClientId; - this.startupApplicationName = startupApplicationName; - this.startupApplicationVersion = startupApplicationVersion; this.codecRegistry = codecRegistry; this.metricRegistry = metricRegistry; } @@ -165,21 +155,6 @@ public InetSocketAddress getCloudProxyAddress() { return cloudProxyAddress; } - @Nullable - public UUID getStartupClientId() { - return startupClientId; - } - - @Nullable - public String getStartupApplicationName() { - return startupApplicationName; - } - - @Nullable - public String getStartupApplicationVersion() { - return startupApplicationVersion; - } - @Nullable public MutableCodecRegistry getCodecRegistry() { return codecRegistry; @@ -205,9 +180,6 @@ public static class Builder { private AuthProvider authProvider; private SslEngineFactory sslEngineFactory; private InetSocketAddress cloudProxyAddress; - private UUID startupClientId; - private String startupApplicationName; - private String startupApplicationVersion; private MutableCodecRegistry codecRegistry; private Object metricRegistry; @@ -380,24 +352,6 @@ public Builder withSslEngineFactory(@Nullable SslEngineFactory sslEngineFactory) return this; } - @NonNull - public Builder withStartupClientId(@Nullable UUID startupClientId) { - this.startupClientId = startupClientId; - return this; - } - - @NonNull - public Builder withStartupApplicationName(@Nullable String startupApplicationName) { - this.startupApplicationName = startupApplicationName; - return this; - } - - @NonNull - public Builder withStartupApplicationVersion(@Nullable String startupApplicationVersion) { - this.startupApplicationVersion = startupApplicationVersion; - return this; - } - @NonNull public Builder withCodecRegistry(@Nullable MutableCodecRegistry codecRegistry) { this.codecRegistry = codecRegistry; @@ -424,9 +378,6 @@ public ProgrammaticArguments build() { authProvider, sslEngineFactory, cloudProxyAddress, - startupClientId, - startupApplicationName, - startupApplicationVersion, codecRegistry, metricRegistry); } diff --git a/core/src/main/java/com/datastax/oss/driver/api/core/session/SessionBuilder.java b/core/src/main/java/com/datastax/oss/driver/api/core/session/SessionBuilder.java index cbf896a0873..d2bcfd44a59 100644 --- a/core/src/main/java/com/datastax/oss/driver/api/core/session/SessionBuilder.java +++ b/core/src/main/java/com/datastax/oss/driver/api/core/session/SessionBuilder.java @@ -38,7 +38,6 @@ import com.datastax.oss.driver.api.core.tracker.RequestTracker; import com.datastax.oss.driver.api.core.type.codec.TypeCodec; import com.datastax.oss.driver.api.core.type.codec.registry.MutableCodecRegistry; -import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.internal.core.ContactPoints; import com.datastax.oss.driver.internal.core.config.cloud.CloudConfig; import com.datastax.oss.driver.internal.core.config.cloud.CloudConfigFactory; @@ -63,7 +62,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.UUID; import java.util.concurrent.Callable; import java.util.concurrent.CompletionStage; import java.util.function.Predicate; @@ -729,61 +727,6 @@ public SelfT withCloudProxyAddress(@Nullable InetSocketAddress cloudProxyAddress return self; } - /** - * A unique identifier for the created session. - * - *

It will be sent in the {@code STARTUP} protocol message, under the key {@code CLIENT_ID}, - * for each new connection established by the driver. Currently, this information is used by - * Insights monitoring (if the target cluster does not support Insights, the entry will be ignored - * by the server). - * - *

If you don't call this method, the driver will generate an identifier with {@link - * Uuids#random()}. - */ - @NonNull - public SelfT withClientId(@Nullable UUID clientId) { - this.programmaticArgumentsBuilder.withStartupClientId(clientId); - return self; - } - - /** - * The name of the application using the created session. - * - *

It will be sent in the {@code STARTUP} protocol message, under the key {@code - * APPLICATION_NAME}, for each new connection established by the driver. Currently, this - * information is used by Insights monitoring (if the target cluster does not support Insights, - * the entry will be ignored by the server). - * - *

This can also be defined in the driver configuration with the option {@code - * basic.application.name}; if you specify both, this method takes precedence and the - * configuration option will be ignored. If neither is specified, the entry is not included in the - * message. - */ - @NonNull - public SelfT withApplicationName(@Nullable String applicationName) { - this.programmaticArgumentsBuilder.withStartupApplicationName(applicationName); - return self; - } - - /** - * The version of the application using the created session. - * - *

It will be sent in the {@code STARTUP} protocol message, under the key {@code - * APPLICATION_VERSION}, for each new connection established by the driver. Currently, this - * information is used by Insights monitoring (if the target cluster does not support Insights, - * the entry will be ignored by the server). - * - *

This can also be defined in the driver configuration with the option {@code - * basic.application.version}; if you specify both, this method takes precedence and the - * configuration option will be ignored. If neither is specified, the entry is not included in the - * message. - */ - @NonNull - public SelfT withApplicationVersion(@Nullable String applicationVersion) { - this.programmaticArgumentsBuilder.withStartupApplicationVersion(applicationVersion); - return self; - } - /** * The metric registry object for storing driver metrics. * diff --git a/core/src/main/java/com/datastax/oss/driver/internal/core/context/DefaultDriverContext.java b/core/src/main/java/com/datastax/oss/driver/internal/core/context/DefaultDriverContext.java index a24b632f640..d86cd04deee 100644 --- a/core/src/main/java/com/datastax/oss/driver/internal/core/context/DefaultDriverContext.java +++ b/core/src/main/java/com/datastax/oss/driver/internal/core/context/DefaultDriverContext.java @@ -17,10 +17,6 @@ */ package com.datastax.oss.driver.internal.core.context; -import static com.datastax.oss.driver.internal.core.util.Dependency.JACKSON; - -import com.datastax.dse.driver.api.core.config.DseDriverOption; -import com.datastax.dse.driver.internal.core.InsightsClientLifecycleListener; import com.datastax.dse.driver.internal.core.type.codec.DseTypeCodecsRegistrar; import com.datastax.dse.protocol.internal.DseProtocolV1ClientCodecs; import com.datastax.dse.protocol.internal.DseProtocolV2ClientCodecs; @@ -90,7 +86,6 @@ import com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker; import com.datastax.oss.driver.internal.core.tracker.RequestLogFormatter; import com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry; -import com.datastax.oss.driver.internal.core.util.DefaultDependencyChecker; import com.datastax.oss.driver.internal.core.util.Reflection; import com.datastax.oss.driver.internal.core.util.concurrent.CycleDetector; import com.datastax.oss.driver.internal.core.util.concurrent.LazyReference; @@ -110,7 +105,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import net.jcip.annotations.ThreadSafe; @@ -240,13 +234,7 @@ public class DefaultDriverContext implements InternalDriverContext { private final InetSocketAddress cloudProxyAddress; private final LazyReference requestLogFormatterRef = new LazyReference<>("requestLogFormatter", this::buildRequestLogFormatter, cycleDetector); - private final UUID startupClientId; - private final String startupApplicationName; - private final String startupApplicationVersion; private final Object metricRegistry; - // A stack trace captured in the constructor. Used to extract information about the client - // application. - private final StackTraceElement[] initStackTrace; public DefaultDriverContext( DriverConfigLoader configLoader, ProgrammaticArguments programmaticArguments) { @@ -293,17 +281,6 @@ public DefaultDriverContext( this.nodeDistanceEvaluatorsFromBuilder = programmaticArguments.getNodeDistanceEvaluators(); this.classLoader = programmaticArguments.getClassLoader(); this.cloudProxyAddress = programmaticArguments.getCloudProxyAddress(); - this.startupClientId = programmaticArguments.getStartupClientId(); - this.startupApplicationName = programmaticArguments.getStartupApplicationName(); - this.startupApplicationVersion = programmaticArguments.getStartupApplicationVersion(); - StackTraceElement[] stackTrace; - try { - stackTrace = Thread.currentThread().getStackTrace(); - } catch (Exception ex) { - // ignore and use empty - stackTrace = new StackTraceElement[] {}; - } - this.initStackTrace = stackTrace; this.metricRegistry = programmaticArguments.getMetricRegistry(); } @@ -340,11 +317,7 @@ public DefaultDriverContext( * @see #getStartupOptions() */ protected Map buildStartupOptions() { - return new StartupOptionsBuilder(this) - .withClientId(startupClientId) - .withApplicationName(startupApplicationName) - .withApplicationVersion(startupApplicationVersion) - .build(); + return new StartupOptionsBuilder(this).build(); } protected Map buildLoadBalancingPolicies() { @@ -721,16 +694,7 @@ protected Optional buildAuthProvider(AuthProvider authProviderFrom } protected List buildLifecycleListeners() { - if (DefaultDependencyChecker.isPresent(JACKSON)) { - return Collections.singletonList(new InsightsClientLifecycleListener(this, initStackTrace)); - } else { - if (config.getDefaultProfile().getBoolean(DseDriverOption.MONITOR_REPORTING_ENABLED)) { - LOG.info( - "Could not initialize Insights monitoring; " - + "this is normal if Jackson was explicitly excluded from classpath"); - } - return Collections.emptyList(); - } + return Collections.emptyList(); } @NonNull diff --git a/core/src/main/java/com/datastax/oss/driver/internal/core/context/InternalDriverContext.java b/core/src/main/java/com/datastax/oss/driver/internal/core/context/InternalDriverContext.java index 81349b0c665..3345cdf2df4 100644 --- a/core/src/main/java/com/datastax/oss/driver/internal/core/context/InternalDriverContext.java +++ b/core/src/main/java/com/datastax/oss/driver/internal/core/context/InternalDriverContext.java @@ -179,9 +179,8 @@ public interface InternalDriverContext extends DriverContext { /** * A list of additional components to notify of session lifecycle events. * - *

For historical reasons, this method has a default implementation that returns an empty list. - * The built-in {@link DefaultDriverContext} overrides it to plug in the Insights monitoring - * listener. Custom driver extensions might override this method to add their own components. + *

The default implementation returns an empty list. Custom driver extensions might override + * this method to add their own components. * *

Note that the driver assumes that the returned list is constant; there is no way to add * listeners dynamically. diff --git a/core/src/main/java/com/datastax/oss/driver/internal/core/context/StartupOptionsBuilder.java b/core/src/main/java/com/datastax/oss/driver/internal/core/context/StartupOptionsBuilder.java index 684d6b01b9c..11b67a11476 100644 --- a/core/src/main/java/com/datastax/oss/driver/internal/core/context/StartupOptionsBuilder.java +++ b/core/src/main/java/com/datastax/oss/driver/internal/core/context/StartupOptionsBuilder.java @@ -17,15 +17,10 @@ */ package com.datastax.oss.driver.internal.core.context; -import com.datastax.dse.driver.api.core.config.DseDriverOption; -import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; import com.datastax.oss.driver.api.core.session.Session; -import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.protocol.internal.request.Startup; import com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableMap; -import edu.umd.cs.findbugs.annotations.Nullable; import java.util.Map; -import java.util.UUID; import net.jcip.annotations.Immutable; @Immutable @@ -33,52 +28,13 @@ public class StartupOptionsBuilder { public static final String DRIVER_NAME_KEY = "DRIVER_NAME"; public static final String DRIVER_VERSION_KEY = "DRIVER_VERSION"; - public static final String APPLICATION_NAME_KEY = "APPLICATION_NAME"; - public static final String APPLICATION_VERSION_KEY = "APPLICATION_VERSION"; - public static final String CLIENT_ID_KEY = "CLIENT_ID"; protected final InternalDriverContext context; - private UUID clientId; - private String applicationName; - private String applicationVersion; public StartupOptionsBuilder(InternalDriverContext context) { this.context = context; } - /** - * Sets the client ID to be sent in the Startup message options. - * - *

If this method is not invoked, or the id passed in is null, a random {@link UUID} will be - * generated and used by default. - */ - public StartupOptionsBuilder withClientId(@Nullable UUID clientId) { - this.clientId = clientId; - return this; - } - - /** - * Sets the client application name to be sent in the Startup message options. - * - *

If this method is not invoked, or the name passed in is null, no application name option - * will be sent in the startup message options. - */ - public StartupOptionsBuilder withApplicationName(@Nullable String applicationName) { - this.applicationName = applicationName; - return this; - } - - /** - * Sets the client application version to be sent in the Startup message options. - * - *

If this method is not invoked, or the name passed in is null, no application version option - * will be sent in the startup message options. - */ - public StartupOptionsBuilder withApplicationVersion(@Nullable String applicationVersion) { - this.applicationVersion = applicationVersion; - return this; - } - /** * Builds a map of options to send in a Startup message. * @@ -92,8 +48,6 @@ public StartupOptionsBuilder withApplicationVersion(@Nullable String application * @return Map of Startup Options. */ public Map build() { - DriverExecutionProfile config = context.getConfig().getDefaultProfile(); - NullAllowingImmutableMap.Builder builder = NullAllowingImmutableMap.builder(3); // add compression (if configured) and driver name and version String compressionAlgorithm = context.getCompressor().algorithm(); @@ -102,24 +56,6 @@ public Map build() { } builder.put(DRIVER_NAME_KEY, getDriverName()).put(DRIVER_VERSION_KEY, getDriverVersion()); - // Add Insights entries, falling back to generation / config if no programmatic values provided: - if (clientId == null) { - clientId = Uuids.random(); - } - builder.put(CLIENT_ID_KEY, clientId.toString()); - if (applicationName == null) { - applicationName = config.getString(DseDriverOption.APPLICATION_NAME, null); - } - if (applicationName != null) { - builder.put(APPLICATION_NAME_KEY, applicationName); - } - if (applicationVersion == null) { - applicationVersion = config.getString(DseDriverOption.APPLICATION_VERSION, null); - } - if (applicationVersion != null) { - builder.put(APPLICATION_VERSION_KEY, applicationVersion); - } - return builder.build(); } diff --git a/core/src/main/resources/reference.conf b/core/src/main/resources/reference.conf index f09ffd18a10..44e5cca992c 100644 --- a/core/src/main/resources/reference.conf +++ b/core/src/main/resources/reference.conf @@ -272,35 +272,6 @@ datastax-java-driver { // secure-connect-bundle = /location/of/secure/connect/bundle } - # DataStax Insights monitoring. - basic.application { - # The name of the application using the session. - # - # It will be sent in the STARTUP protocol message for each new connection established by the - # driver. - # - # This can also be defined programmatically with DseSessionBuilder.withApplicationName(). If you - # specify both, the programmatic value takes precedence and this option is ignored. - # - # Required: no - # Modifiable at runtime: no - # Overridable in a profile: no - // name = - - # The version of the application using the session. - # - # It will be sent in the STARTUP protocol message for each new connection established by the - # driver. - # - # This can also be defined programmatically with DseSessionBuilder.withApplicationVersion(). If - # you specify both, the programmatic value takes precedence and this option is ignored. - # - # Required: no - # Modifiable at runtime: no - # Overridable in a profile: no - // version = - } - # Graph (DataStax Enterprise only) basic.graph { # The name of the graph targeted by graph statements. @@ -1361,18 +1332,6 @@ datastax-java-driver { } } - # DataStax Insights - advanced.monitor-reporting { - # Whether to send monitoring events. - # - # The default is true. - # - # Required: no (defaults to true) - # Modifiable at runtime: no - # Overridable in a profile: no - enabled = true - } - advanced.metrics { # Metrics Factory configuration. factory { diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/context/DseStartupOptionsBuilderTest.java b/core/src/test/java/com/datastax/dse/driver/internal/core/context/DseStartupOptionsBuilderTest.java index 9e4556e528d..2886855fb84 100644 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/context/DseStartupOptionsBuilderTest.java +++ b/core/src/test/java/com/datastax/dse/driver/internal/core/context/DseStartupOptionsBuilderTest.java @@ -30,13 +30,11 @@ import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; import com.datastax.oss.driver.api.core.session.ProgrammaticArguments; import com.datastax.oss.driver.api.core.session.Session; -import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.internal.core.context.DefaultDriverContext; import com.datastax.oss.driver.internal.core.context.StartupOptionsBuilder; import com.datastax.oss.protocol.internal.request.Startup; import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import java.util.UUID; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -60,15 +58,9 @@ public void before() { when(defaultProfile.isDefined(DseDriverOption.CONTINUOUS_PAGING_PAGE_SIZE)).thenReturn(true); } - private void buildContext(UUID clientId, String applicationName, String applicationVersion) { + private void buildContext() { this.driverContext = - new DefaultDriverContext( - configLoader, - ProgrammaticArguments.builder() - .withStartupClientId(clientId) - .withStartupApplicationName(applicationName) - .withStartupApplicationVersion(applicationVersion) - .build()); + new DefaultDriverContext(configLoader, ProgrammaticArguments.builder().build()); } private void assertDefaultStartupOptions(Startup startup) { @@ -79,14 +71,13 @@ private void assertDefaultStartupOptions(Startup startup) { assertThat(startup.options).containsKey(StartupOptionsBuilder.DRIVER_VERSION_KEY); Version version = Version.parse(startup.options.get(StartupOptionsBuilder.DRIVER_VERSION_KEY)); assertThat(version).isEqualTo(Session.OSS_DRIVER_COORDINATES.getVersion()); - assertThat(startup.options).containsKey(StartupOptionsBuilder.CLIENT_ID_KEY); } @Test public void should_build_startup_options_with_no_compression_if_undefined() { when(defaultProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")) .thenReturn("none"); - buildContext(null, null, null); + buildContext(); Startup startup = new Startup(driverContext.getStartupOptions()); assertThat(startup.options).doesNotContainKey(Startup.COMPRESSION_KEY); assertDefaultStartupOptions(startup); @@ -97,12 +88,10 @@ public void should_build_startup_options_with_no_compression_if_undefined() { public void should_build_startup_options_with_compression(String compression) { when(defaultProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")) .thenReturn(compression); - buildContext(null, null, null); + buildContext(); Startup startup = new Startup(driverContext.getStartupOptions()); // assert the compression option is present assertThat(startup.options).containsEntry(Startup.COMPRESSION_KEY, compression); - assertThat(startup.options).doesNotContainKey(StartupOptionsBuilder.APPLICATION_NAME_KEY); - assertThat(startup.options).doesNotContainKey(StartupOptionsBuilder.APPLICATION_VERSION_KEY); assertDefaultStartupOptions(startup); } @@ -110,87 +99,20 @@ public void should_build_startup_options_with_compression(String compression) { public void should_fail_to_build_startup_options_with_invalid_compression() { when(defaultProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")) .thenReturn("foobar"); - buildContext(null, null, null); + buildContext(); assertThatIllegalArgumentException() .isThrownBy(() -> new Startup(driverContext.getStartupOptions())); } - @Test - public void should_build_startup_options_with_client_id() { - when(defaultProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")) - .thenReturn("none"); - UUID customClientId = Uuids.random(); - buildContext(customClientId, null, null); - Startup startup = new Startup(driverContext.getStartupOptions()); - // assert the client id is present - assertThat(startup.options) - .containsEntry(StartupOptionsBuilder.CLIENT_ID_KEY, customClientId.toString()); - assertThat(startup.options).doesNotContainKey(Startup.COMPRESSION_KEY); - assertThat(startup.options).doesNotContainKey(StartupOptionsBuilder.APPLICATION_NAME_KEY); - assertThat(startup.options).doesNotContainKey(StartupOptionsBuilder.APPLICATION_VERSION_KEY); - assertDefaultStartupOptions(startup); - } - - @Test - public void should_build_startup_options_with_application_version_and_name() { - when(defaultProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")) - .thenReturn("none"); - buildContext(null, "Custom_App_Name", "Custom_App_Version"); - Startup startup = new Startup(driverContext.getStartupOptions()); - // assert the app name and version are present - assertThat(startup.options) - .containsEntry(StartupOptionsBuilder.APPLICATION_NAME_KEY, "Custom_App_Name"); - assertThat(startup.options) - .containsEntry(StartupOptionsBuilder.APPLICATION_VERSION_KEY, "Custom_App_Version"); - assertThat(startup.options).doesNotContainKey(Startup.COMPRESSION_KEY); - assertDefaultStartupOptions(startup); - } - @Test public void should_build_startup_options_with_all_options() { // mock config to specify "snappy" compression when(defaultProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")) .thenReturn("snappy"); - UUID customClientId = Uuids.random(); - - buildContext(customClientId, "Custom_App_Name", "Custom_App_Version"); + buildContext(); Startup startup = new Startup(driverContext.getStartupOptions()); - assertThat(startup.options) - .containsEntry(StartupOptionsBuilder.CLIENT_ID_KEY, customClientId.toString()) - .containsEntry(StartupOptionsBuilder.APPLICATION_NAME_KEY, "Custom_App_Name") - .containsEntry(StartupOptionsBuilder.APPLICATION_VERSION_KEY, "Custom_App_Version"); assertThat(startup.options).containsEntry(Startup.COMPRESSION_KEY, "snappy"); assertDefaultStartupOptions(startup); } - - @Test - public void should_use_configuration_when_no_programmatic_values_provided() { - when(defaultProfile.getString(DseDriverOption.APPLICATION_NAME, null)) - .thenReturn("Config_App_Name"); - when(defaultProfile.getString(DseDriverOption.APPLICATION_VERSION, null)) - .thenReturn("Config_App_Version"); - when(defaultProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")) - .thenReturn("none"); - - buildContext(null, null, null); - Startup startup = new Startup(driverContext.getStartupOptions()); - - assertThat(startup.options) - .containsEntry(StartupOptionsBuilder.APPLICATION_NAME_KEY, "Config_App_Name") - .containsEntry(StartupOptionsBuilder.APPLICATION_VERSION_KEY, "Config_App_Version"); - } - - @Test - public void should_ignore_configuration_when_programmatic_values_provided() { - when(defaultProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")) - .thenReturn("none"); - - buildContext(null, "Custom_App_Name", "Custom_App_Version"); - Startup startup = new Startup(driverContext.getStartupOptions()); - - assertThat(startup.options) - .containsEntry(StartupOptionsBuilder.APPLICATION_NAME_KEY, "Custom_App_Name") - .containsEntry(StartupOptionsBuilder.APPLICATION_VERSION_KEY, "Custom_App_Version"); - } } diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/AddressFormatterTest.java b/core/src/test/java/com/datastax/dse/driver/internal/core/insights/AddressFormatterTest.java deleted file mode 100644 index 85af9b5691b..00000000000 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/AddressFormatterTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(DataProviderRunner.class) -public class AddressFormatterTest { - - @Test - @UseDataProvider("addressesProvider") - public void should_format_addresses(Object address, String expected) { - // when - String result = AddressFormatter.nullSafeToString(address); - - // then - assertThat(result).isEqualTo(expected); - } - - @DataProvider - public static Object[][] addressesProvider() throws UnknownHostException { - return new Object[][] { - {new InetSocketAddress(8888), "0.0.0.0:8888"}, - {new InetSocketAddress("127.0.0.1", 8888), "127.0.0.1:8888"}, - {InetSocketAddress.createUnresolved("127.0.0.2", 8080), "127.0.0.2:8080"}, - {InetAddress.getByName("127.0.0.1"), "127.0.0.1"}, - }; - } -} diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ConfigAntiPatternsFinderTest.java b/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ConfigAntiPatternsFinderTest.java deleted file mode 100644 index d5466b23dbc..00000000000 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ConfigAntiPatternsFinderTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.SSL_ENGINE_FACTORY_CLASS; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.SSL_HOSTNAME_VALIDATION; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.datastax.oss.driver.api.core.config.DriverConfig; -import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; -import com.datastax.oss.driver.internal.core.context.InternalDriverContext; -import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; -import java.util.Collections; -import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(DataProviderRunner.class) -public class ConfigAntiPatternsFinderTest { - - private static final ImmutableMap SSL_ANTI_PATTERN = - ImmutableMap.of( - "sslWithoutCertValidation", - "Client-to-node encryption is enabled but server certificate validation is disabled"); - - @Test - @UseDataProvider("sslConfigProvider") - public void should_find_ssl_anti_pattern( - boolean sslEngineFactoryClassDefined, - boolean hostnameValidation, - Map expected) { - // given - InternalDriverContext context = - mockDefaultProfile(sslEngineFactoryClassDefined, hostnameValidation); - - // when - Map antiPatterns = new ConfigAntiPatternsFinder().findAntiPatterns(context); - - // then - assertThat(antiPatterns).isEqualTo(expected); - } - - private InternalDriverContext mockDefaultProfile( - boolean sslEngineFactoryClassDefined, boolean hostnameValidation) { - InternalDriverContext context = mock(InternalDriverContext.class); - DriverConfig driverConfig = mock(DriverConfig.class); - when(context.getConfig()).thenReturn(driverConfig); - DriverExecutionProfile profile = mock(DriverExecutionProfile.class); - when(profile.isDefined(SSL_ENGINE_FACTORY_CLASS)).thenReturn(sslEngineFactoryClassDefined); - when(profile.getBoolean(SSL_HOSTNAME_VALIDATION, false)).thenReturn(hostnameValidation); - when(driverConfig.getDefaultProfile()).thenReturn(profile); - return context; - } - - @DataProvider - public static Object[][] sslConfigProvider() { - return new Object[][] { - {true, true, Collections.emptyMap()}, - {true, false, SSL_ANTI_PATTERN}, - {false, false, Collections.emptyMap()}, - {false, true, Collections.emptyMap()} - }; - } -} diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/DataCentersFinderTest.java b/core/src/test/java/com/datastax/dse/driver/internal/core/insights/DataCentersFinderTest.java deleted file mode 100644 index dde6db6059e..00000000000 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/DataCentersFinderTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.CONNECTION_POOL_REMOTE_SIZE; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; -import com.datastax.oss.driver.api.core.loadbalancing.NodeDistance; -import com.datastax.oss.driver.api.core.metadata.Node; -import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet; -import com.datastax.oss.driver.shaded.guava.common.collect.Sets; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; -import java.util.Collection; -import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(DataProviderRunner.class) -public class DataCentersFinderTest { - - @Test - @UseDataProvider("hostProvider") - public void should_detect_data_centers( - int numberOfRemoteHosts, - String dc1, - NodeDistance h1Distance, - String dc2, - NodeDistance h2Distance, - Set expected) { - // given - DriverExecutionProfile executionProfile = mock(DriverExecutionProfile.class); - when(executionProfile.getInt(CONNECTION_POOL_REMOTE_SIZE)).thenReturn(numberOfRemoteHosts); - Collection nodes = mockNodes(dc1, h1Distance, dc2, h2Distance); - - // when - Set dataCenters = new DataCentersFinder().getDataCenters(nodes, executionProfile); - - // then - assertThat(dataCenters).isEqualTo(Sets.newHashSet(expected)); - } - - @DataProvider - public static Object[][] hostProvider() { - return new Object[][] { - {1, "dc1", NodeDistance.LOCAL, "dc2", NodeDistance.REMOTE, Sets.newHashSet("dc1", "dc2")}, - {1, "dc1", NodeDistance.LOCAL, "dc1", NodeDistance.REMOTE, Sets.newHashSet("dc1")}, - {0, "dc1", NodeDistance.LOCAL, "dc2", NodeDistance.REMOTE, Sets.newHashSet("dc1")}, - {0, "dc1", NodeDistance.IGNORED, "dc2", NodeDistance.REMOTE, Sets.newHashSet()}, - {1, "dc1", NodeDistance.IGNORED, "dc2", NodeDistance.REMOTE, Sets.newHashSet("dc2")}, - {1, "dc1", NodeDistance.LOCAL, "dc2", NodeDistance.IGNORED, Sets.newHashSet("dc1")}, - {0, "dc1", NodeDistance.IGNORED, "dc2", NodeDistance.REMOTE, Sets.newHashSet()}, - {0, "dc1", NodeDistance.LOCAL, "dc2", NodeDistance.IGNORED, Sets.newHashSet("dc1")}, - }; - } - - private Collection mockNodes( - String dc1, NodeDistance h1Distance, String dc2, NodeDistance h2Distance) { - Node n1 = mock(Node.class); - when(n1.getDatacenter()).thenReturn(dc1); - when(n1.getDistance()).thenReturn(h1Distance); - - Node n2 = mock(Node.class); - when(n2.getDatacenter()).thenReturn(dc2); - when(n2.getDistance()).thenReturn(h2Distance); - - return ImmutableSet.of(n1, n2); - } -} diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ExecutionProfileMockUtil.java b/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ExecutionProfileMockUtil.java deleted file mode 100644 index de0f3a9d60b..00000000000 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ExecutionProfileMockUtil.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.dse.driver.api.core.config.DseDriverOption.GRAPH_TRAVERSAL_SOURCE; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.AUTH_PROVIDER_CLASS; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.CONNECTION_POOL_LOCAL_SIZE; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.CONNECTION_POOL_REMOTE_SIZE; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.HEARTBEAT_INTERVAL; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.LOAD_BALANCING_DISTANCE_EVALUATOR_CLASS; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.LOAD_BALANCING_LOCAL_DATACENTER; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.LOAD_BALANCING_POLICY_CLASS; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.PROTOCOL_COMPRESSION; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.RECONNECTION_BASE_DELAY; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.REQUEST_CONSISTENCY; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.REQUEST_TIMEOUT; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.SPECULATIVE_EXECUTION_DELAY; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.SPECULATIVE_EXECUTION_MAX; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS; -import static com.datastax.oss.driver.api.core.config.DefaultDriverOption.SSL_ENGINE_FACTORY_CLASS; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; -import java.time.Duration; - -class ExecutionProfileMockUtil { - static final String DEFAULT_LOCAL_DC = "local-dc"; - static final int SPECEX_MAX_DEFAULT = 100; - static final int SPECEX_DELAY_DEFAULT = 20; - - static DriverExecutionProfile mockDefaultExecutionProfile() { - DriverExecutionProfile profile = mock(DriverExecutionProfile.class); - - when(profile.getDuration(REQUEST_TIMEOUT)).thenReturn(Duration.ofMillis(100)); - when(profile.getString(LOAD_BALANCING_POLICY_CLASS)).thenReturn("LoadBalancingPolicyImpl"); - when(profile.isDefined(LOAD_BALANCING_DISTANCE_EVALUATOR_CLASS)).thenReturn(true); - when(profile.isDefined(LOAD_BALANCING_LOCAL_DATACENTER)).thenReturn(true); - when(profile.getString(LOAD_BALANCING_LOCAL_DATACENTER)).thenReturn(DEFAULT_LOCAL_DC); - when(profile.isDefined(SPECULATIVE_EXECUTION_MAX)).thenReturn(true); - when(profile.getInt(SPECULATIVE_EXECUTION_MAX)).thenReturn(SPECEX_MAX_DEFAULT); - when(profile.isDefined(SPECULATIVE_EXECUTION_DELAY)).thenReturn(true); - when(profile.getInt(SPECULATIVE_EXECUTION_DELAY)).thenReturn(SPECEX_DELAY_DEFAULT); - when(profile.getString(SPECULATIVE_EXECUTION_POLICY_CLASS)) - .thenReturn("SpeculativeExecutionImpl"); - when(profile.getString(REQUEST_CONSISTENCY)).thenReturn("LOCAL_ONE"); - when(profile.getString(REQUEST_SERIAL_CONSISTENCY)).thenReturn("SERIAL"); - when(profile.getInt(CONNECTION_POOL_LOCAL_SIZE)).thenReturn(2); - when(profile.getInt(CONNECTION_POOL_REMOTE_SIZE)).thenReturn(1); - when(profile.getString(eq(PROTOCOL_COMPRESSION), any())).thenReturn("none"); - when(profile.getDuration(HEARTBEAT_INTERVAL)).thenReturn(Duration.ofMillis(100)); - when(profile.getDuration(RECONNECTION_BASE_DELAY)).thenReturn(Duration.ofMillis(100)); - when(profile.isDefined(SSL_ENGINE_FACTORY_CLASS)).thenReturn(true); - when(profile.getString(eq(AUTH_PROVIDER_CLASS), any())).thenReturn("AuthProviderImpl"); - when(profile.getString(GRAPH_TRAVERSAL_SOURCE, null)).thenReturn("src-graph"); - return profile; - } - - static DriverExecutionProfile mockNonDefaultRequestTimeoutExecutionProfile() { - DriverExecutionProfile profile = mockDefaultExecutionProfile(); - when(profile.getDuration(REQUEST_TIMEOUT)).thenReturn(Duration.ofMillis(50)); - return profile; - } - - static DriverExecutionProfile mockNonDefaultLoadBalancingExecutionProfile() { - DriverExecutionProfile profile = mockDefaultExecutionProfile(); - when(profile.getString(LOAD_BALANCING_POLICY_CLASS)).thenReturn("NonDefaultLoadBalancing"); - return profile; - } - - static DriverExecutionProfile mockUndefinedLocalDcExecutionProfile() { - DriverExecutionProfile profile = mockNonDefaultLoadBalancingExecutionProfile(); - when(profile.isDefined(LOAD_BALANCING_LOCAL_DATACENTER)).thenReturn(false); - return profile; - } - - static DriverExecutionProfile mockNonDefaultSpeculativeExecutionInfo() { - DriverExecutionProfile profile = mockDefaultExecutionProfile(); - when(profile.getString(SPECULATIVE_EXECUTION_POLICY_CLASS)) - .thenReturn("NonDefaultSpecexPolicy"); - return profile; - } - - static DriverExecutionProfile mockNonDefaultConsistency() { - DriverExecutionProfile profile = mockDefaultExecutionProfile(); - when(profile.getString(REQUEST_CONSISTENCY)).thenReturn("ALL"); - return profile; - } - - static DriverExecutionProfile mockNonDefaultSerialConsistency() { - DriverExecutionProfile profile = mockDefaultExecutionProfile(); - when(profile.getString(REQUEST_SERIAL_CONSISTENCY)).thenReturn("ONE"); - return profile; - } - - static DriverExecutionProfile mockNonDefaultGraphOptions() { - DriverExecutionProfile profile = mockDefaultExecutionProfile(); - when(profile.getString(GRAPH_TRAVERSAL_SOURCE, null)).thenReturn("non-default-graph"); - return profile; - } -} diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ExecutionProfilesInfoFinderTest.java b/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ExecutionProfilesInfoFinderTest.java deleted file mode 100644 index fc92ab20521..00000000000 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ExecutionProfilesInfoFinderTest.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.DEFAULT_LOCAL_DC; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.SPECEX_DELAY_DEFAULT; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.SPECEX_MAX_DEFAULT; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockDefaultExecutionProfile; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultConsistency; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultGraphOptions; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultLoadBalancingExecutionProfile; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultRequestTimeoutExecutionProfile; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultSerialConsistency; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockUndefinedLocalDcExecutionProfile; -import static com.datastax.dse.driver.internal.core.insights.PackageUtil.DEFAULT_LOAD_BALANCING_PACKAGE; -import static com.datastax.dse.driver.internal.core.insights.PackageUtil.DEFAULT_SPECULATIVE_EXECUTION_PACKAGE; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.datastax.dse.driver.internal.core.insights.schema.LoadBalancingInfo; -import com.datastax.dse.driver.internal.core.insights.schema.SpecificExecutionProfile; -import com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo; -import com.datastax.oss.driver.api.core.config.DriverConfig; -import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; -import com.datastax.oss.driver.internal.core.context.InternalDriverContext; -import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; -import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; - -@RunWith(DataProviderRunner.class) -public class ExecutionProfilesInfoFinderTest { - - @Test - public void should_include_info_about_default_profile() { - // given - DriverExecutionProfile defaultExecutionProfile = mockDefaultExecutionProfile(); - Map profiles = - ImmutableMap.of("default", defaultExecutionProfile); - - InternalDriverContext context = - mockDriverContextWithProfiles(defaultExecutionProfile, profiles); - - // when - Map executionProfilesInfo = - new ExecutionProfilesInfoFinder().getExecutionProfilesInfo(context); - - // then - assertThat(executionProfilesInfo) - .isEqualTo( - ImmutableMap.of( - "default", - new SpecificExecutionProfile( - 100, - new LoadBalancingInfo( - "LoadBalancingPolicyImpl", - ImmutableMap.of("localDataCenter", "local-dc", "filterFunction", true), - DEFAULT_LOAD_BALANCING_PACKAGE), - new SpeculativeExecutionInfo( - "SpeculativeExecutionImpl", - ImmutableMap.of("maxSpeculativeExecutions", 100, "delay", 20), - DEFAULT_SPECULATIVE_EXECUTION_PACKAGE), - "LOCAL_ONE", - "SERIAL", - ImmutableMap.of("source", "src-graph")))); - } - - @Test - @UseDataProvider("executionProfileProvider") - public void should_include_info_about_default_profile_and_only_difference_for_specific_profile( - DriverExecutionProfile nonDefaultExecutionProfile, SpecificExecutionProfile expected) { - // given - - DriverExecutionProfile defaultExecutionProfile = mockDefaultExecutionProfile(); - Map profiles = - ImmutableMap.of( - "default", defaultExecutionProfile, "non-default", nonDefaultExecutionProfile); - InternalDriverContext context = - mockDriverContextWithProfiles(defaultExecutionProfile, profiles); - // when - Map executionProfilesInfo = - new ExecutionProfilesInfoFinder().getExecutionProfilesInfo(context); - - // then - assertThat(executionProfilesInfo) - .isEqualTo( - ImmutableMap.of( - "default", - new SpecificExecutionProfile( - 100, - new LoadBalancingInfo( - "LoadBalancingPolicyImpl", - ImmutableMap.of("localDataCenter", "local-dc", "filterFunction", true), - DEFAULT_LOAD_BALANCING_PACKAGE), - new SpeculativeExecutionInfo( - "SpeculativeExecutionImpl", - ImmutableMap.of("maxSpeculativeExecutions", 100, "delay", 20), - DEFAULT_SPECULATIVE_EXECUTION_PACKAGE), - "LOCAL_ONE", - "SERIAL", - ImmutableMap.of("source", "src-graph")), - "non-default", - expected)); - } - - @DataProvider - public static Object[][] executionProfileProvider() { - return new Object[][] { - { - mockNonDefaultRequestTimeoutExecutionProfile(), - new SpecificExecutionProfile(50, null, null, null, null, null) - }, - { - mockNonDefaultLoadBalancingExecutionProfile(), - new SpecificExecutionProfile( - null, - new LoadBalancingInfo( - "NonDefaultLoadBalancing", - ImmutableMap.of("localDataCenter", DEFAULT_LOCAL_DC, "filterFunction", true), - DEFAULT_LOAD_BALANCING_PACKAGE), - null, - null, - null, - null) - }, - { - mockUndefinedLocalDcExecutionProfile(), - new SpecificExecutionProfile( - null, - new LoadBalancingInfo( - "NonDefaultLoadBalancing", - ImmutableMap.of("filterFunction", true), - DEFAULT_LOAD_BALANCING_PACKAGE), - null, - null, - null, - null) - }, - { - mockNonDefaultSpeculativeExecutionInfo(), - new SpecificExecutionProfile( - null, - null, - new SpeculativeExecutionInfo( - "NonDefaultSpecexPolicy", - ImmutableMap.of( - "maxSpeculativeExecutions", SPECEX_MAX_DEFAULT, "delay", SPECEX_DELAY_DEFAULT), - DEFAULT_SPECULATIVE_EXECUTION_PACKAGE), - null, - null, - null) - }, - { - mockNonDefaultConsistency(), - new SpecificExecutionProfile(null, null, null, "ALL", null, null) - }, - { - mockNonDefaultSerialConsistency(), - new SpecificExecutionProfile(null, null, null, null, "ONE", null) - }, - { - mockNonDefaultGraphOptions(), - new SpecificExecutionProfile( - null, null, null, null, null, ImmutableMap.of("source", "non-default-graph")) - }, - { - mockDefaultExecutionProfile(), - new SpecificExecutionProfile(null, null, null, null, null, null) - } - }; - } - - @Test - public void should_not_include_null_fields_in_json() throws JsonProcessingException { - // given - SpecificExecutionProfile specificExecutionProfile = - new SpecificExecutionProfile(50, null, null, "ONE", null, ImmutableMap.of("a", "b")); - - // when - String result = new ObjectMapper().writeValueAsString(specificExecutionProfile); - - // then - assertThat(result) - .isEqualTo("{\"readTimeout\":50,\"consistency\":\"ONE\",\"graphOptions\":{\"a\":\"b\"}}"); - } - - @Test - public void should_include_empty_execution_profile_if_has_all_nulls() - throws JsonProcessingException { - // given - Map executionProfiles = - ImmutableMap.of("p", new SpecificExecutionProfile(null, null, null, null, null, null)); - - // when - String result = new ObjectMapper().writeValueAsString(executionProfiles); - - // then - assertThat(result).isEqualTo("{\"p\":{}}"); - } - - private InternalDriverContext mockDriverContextWithProfiles( - DriverExecutionProfile defaultExecutionProfile, - Map profiles) { - InternalDriverContext context = mock(InternalDriverContext.class); - DriverConfig driverConfig = mock(DriverConfig.class); - Mockito.>when(driverConfig.getProfiles()) - .thenReturn(profiles); - when(driverConfig.getDefaultProfile()).thenReturn(defaultExecutionProfile); - when(context.getConfig()).thenReturn(driverConfig); - return context; - } -} diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/InsightsClientTest.java b/core/src/test/java/com/datastax/dse/driver/internal/core/insights/InsightsClientTest.java deleted file mode 100644 index 74869893b72..00000000000 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/InsightsClientTest.java +++ /dev/null @@ -1,535 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.dse.driver.api.core.DseProtocolVersion.DSE_V2; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockDefaultExecutionProfile; -import static com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultRequestTimeoutExecutionProfile; -import static com.datastax.dse.driver.internal.core.insights.PackageUtil.DEFAULT_AUTH_PROVIDER_PACKAGE; -import static com.datastax.dse.driver.internal.core.insights.PackageUtil.DEFAULT_LOAD_BALANCING_PACKAGE; -import static com.datastax.dse.driver.internal.core.insights.PackageUtil.DEFAULT_SPECULATIVE_EXECUTION_PACKAGE; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.datastax.dse.driver.api.core.metadata.DseNodeProperties; -import com.datastax.dse.driver.internal.core.insights.configuration.InsightsConfiguration; -import com.datastax.dse.driver.internal.core.insights.schema.AuthProviderType; -import com.datastax.dse.driver.internal.core.insights.schema.Insight; -import com.datastax.dse.driver.internal.core.insights.schema.InsightMetadata; -import com.datastax.dse.driver.internal.core.insights.schema.InsightType; -import com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo; -import com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.CPUS; -import com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.OS; -import com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.RuntimeAndCompileTimeVersions; -import com.datastax.dse.driver.internal.core.insights.schema.InsightsStartupData; -import com.datastax.dse.driver.internal.core.insights.schema.InsightsStatusData; -import com.datastax.dse.driver.internal.core.insights.schema.LoadBalancingInfo; -import com.datastax.dse.driver.internal.core.insights.schema.PoolSizeByHostDistance; -import com.datastax.dse.driver.internal.core.insights.schema.ReconnectionPolicyInfo; -import com.datastax.dse.driver.internal.core.insights.schema.SSL; -import com.datastax.dse.driver.internal.core.insights.schema.SessionStateForNode; -import com.datastax.dse.driver.internal.core.insights.schema.SpecificExecutionProfile; -import com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo; -import com.datastax.oss.driver.api.core.Version; -import com.datastax.oss.driver.api.core.config.DriverConfig; -import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; -import com.datastax.oss.driver.api.core.metadata.EndPoint; -import com.datastax.oss.driver.api.core.metadata.Metadata; -import com.datastax.oss.driver.api.core.metadata.Node; -import com.datastax.oss.driver.internal.core.channel.DriverChannel; -import com.datastax.oss.driver.internal.core.context.DefaultDriverContext; -import com.datastax.oss.driver.internal.core.context.StartupOptionsBuilder; -import com.datastax.oss.driver.internal.core.control.ControlConnection; -import com.datastax.oss.driver.internal.core.metadata.DefaultNode; -import com.datastax.oss.driver.internal.core.metadata.MetadataManager; -import com.datastax.oss.driver.internal.core.pool.ChannelPool; -import com.datastax.oss.driver.internal.core.session.PoolManager; -import com.datastax.oss.driver.shaded.guava.common.base.Suppliers; -import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList; -import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; -import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet; -import com.datastax.oss.driver.shaded.guava.common.collect.Sets; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; -import io.netty.channel.DefaultEventLoop; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Supplier; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; - -@RunWith(DataProviderRunner.class) -public class InsightsClientTest { - private static final StackTraceElement[] EMPTY_STACK_TRACE = {}; - private static final Map EMPTY_OBJECT_MAP = Collections.emptyMap(); - private static final Supplier MOCK_TIME_SUPPLIER = Suppliers.ofInstance(1L); - private static final InsightsConfiguration INSIGHTS_CONFIGURATION = - new InsightsConfiguration(true, 300000L, new DefaultEventLoop()); - - @Test - public void should_construct_json_event_startup_message() throws IOException { - // given - DefaultDriverContext context = mockDefaultDriverContext(); - PlatformInfoFinder platformInfoFinder = mock(PlatformInfoFinder.class); - OS os = new OS("linux", "1.2", "x64"); - CPUS cpus = new CPUS(8, "intel i7"); - Map javaDeps = - ImmutableMap.of("version", new RuntimeAndCompileTimeVersions("1.8.0", "1.8.0", false)); - Map> runtimeInfo = - ImmutableMap.of("java", javaDeps); - InsightsPlatformInfo insightsPlatformInfo = new InsightsPlatformInfo(os, cpus, runtimeInfo); - when(platformInfoFinder.getInsightsPlatformInfo()).thenReturn(insightsPlatformInfo); - - ConfigAntiPatternsFinder configAntiPatternsFinder = mock(ConfigAntiPatternsFinder.class); - when(configAntiPatternsFinder.findAntiPatterns(any(DefaultDriverContext.class))) - .thenReturn( - ImmutableMap.of( - "contactPointsMultipleDCs", - "Contact points contain hosts from multiple data centers")); - - DataCentersFinder dataCentersFinder = mock(DataCentersFinder.class); - when(dataCentersFinder.getDataCenters(any(DefaultDriverContext.class))) - .thenReturn(Sets.newHashSet("dc1", "dc2")); - ReconnectionPolicyInfoFinder reconnectionPolicyInfoFinder = - mock(ReconnectionPolicyInfoFinder.class); - when(reconnectionPolicyInfoFinder.getReconnectionPolicyInfo(any(), any())) - .thenReturn( - new ReconnectionPolicyInfo( - "reconnection-policy-a", ImmutableMap.of("opt-a", 1), "com.datastax.dse")); - - InsightsClient insightsClient = - new InsightsClient( - context, - MOCK_TIME_SUPPLIER, - INSIGHTS_CONFIGURATION, - platformInfoFinder, - reconnectionPolicyInfoFinder, - new ExecutionProfilesInfoFinder(), - configAntiPatternsFinder, - dataCentersFinder, - EMPTY_STACK_TRACE); - - // when - String startupMessage = insightsClient.createStartupMessage(); - Insight insight = - new ObjectMapper() - .readValue(startupMessage, new TypeReference>() {}); - - // then - assertThat(insight.getMetadata()) - .isEqualTo( - new InsightMetadata( - "driver.startup", - 1L, - ImmutableMap.of("language", "java"), - InsightType.EVENT, - "v1")); - - InsightsStartupData insightData = insight.getInsightData(); - assertThat(insightData.getClientId()).isEqualTo("client-id"); - assertThat(insightData.getSessionId()).isNotNull(); - assertThat(insightData.getDriverName()).isEqualTo("DataStax Enterprise Java Driver"); - assertThat(insightData.getDriverVersion()).isNotEmpty(); - assertThat(insightData.getApplicationName()).isEqualTo("app-name"); - assertThat(insightData.getApplicationVersion()).isEqualTo("1.0.0"); - assertThat(insightData.isApplicationNameWasGenerated()).isEqualTo(false); - assertThat(insightData.getContactPoints()) - .isEqualTo(ImmutableMap.of("localhost", Collections.singletonList("127.0.0.1:9999"))); - - assertThat(insightData.getInitialControlConnection()).isEqualTo("127.0.0.1:10"); - assertThat(insightData.getLocalAddress()).isEqualTo("127.0.0.1"); - assertThat(insightData.getHostName()).isNotEmpty(); - assertThat(insightData.getProtocolVersion()).isEqualTo(DSE_V2.getCode()); - assertThat(insightData.getExecutionProfiles()) - .isEqualTo( - ImmutableMap.of( - "default", - new SpecificExecutionProfile( - 100, - new LoadBalancingInfo( - "LoadBalancingPolicyImpl", - ImmutableMap.of("localDataCenter", "local-dc", "filterFunction", true), - DEFAULT_LOAD_BALANCING_PACKAGE), - new SpeculativeExecutionInfo( - "SpeculativeExecutionImpl", - ImmutableMap.of("maxSpeculativeExecutions", 100, "delay", 20), - DEFAULT_SPECULATIVE_EXECUTION_PACKAGE), - "LOCAL_ONE", - "SERIAL", - ImmutableMap.of("source", "src-graph")), - "non-default", - new SpecificExecutionProfile(50, null, null, null, null, null))); - assertThat(insightData.getPoolSizeByHostDistance()) - .isEqualTo(new PoolSizeByHostDistance(2, 1, 0)); - assertThat(insightData.getHeartbeatInterval()).isEqualTo(100); - assertThat(insightData.getCompression()).isEqualTo("none"); - assertThat(insightData.getReconnectionPolicy()) - .isEqualTo( - new ReconnectionPolicyInfo( - "reconnection-policy-a", ImmutableMap.of("opt-a", 1), "com.datastax.dse")); - assertThat(insightData.getSsl()).isEqualTo(new SSL(true, false)); - assertThat(insightData.getAuthProvider()) - .isEqualTo(new AuthProviderType("AuthProviderImpl", DEFAULT_AUTH_PROVIDER_PACKAGE)); - assertThat(insightData.getOtherOptions()).isEqualTo(EMPTY_OBJECT_MAP); - assertThat(insightData.getPlatformInfo()).isEqualTo(insightsPlatformInfo); - assertThat(insightData.getConfigAntiPatterns()) - .isEqualTo( - ImmutableMap.of( - "contactPointsMultipleDCs", - "Contact points contain hosts from multiple data centers")); - assertThat(insightData.getPeriodicStatusInterval()).isEqualTo(300); - assertThat(insightData.getDataCenters()).isEqualTo(Sets.newHashSet("dc1", "dc2")); - } - - @Test - public void should_group_contact_points_by_host_name() { - // given - Set contactPoints = - ImmutableSet.of( - InetSocketAddress.createUnresolved("127.0.0.1", 8080), - InetSocketAddress.createUnresolved("127.0.0.1", 8081), - InetSocketAddress.createUnresolved("127.0.0.2", 8081)); - - Map> expected = - ImmutableMap.of( - "127.0.0.1", - ImmutableList.of("127.0.0.1:8080", "127.0.0.1:8081"), - "127.0.0.2", - ImmutableList.of("127.0.0.2:8081")); - - // when - Map> resolvedContactPoints = - InsightsClient.getResolvedContactPoints(contactPoints); - - // then - assertThat(resolvedContactPoints).isEqualTo(expected); - } - - @Test - public void should_construct_json_event_status_message() throws IOException { - // given - InsightsClient insightsClient = - new InsightsClient( - mockDefaultDriverContext(), - MOCK_TIME_SUPPLIER, - INSIGHTS_CONFIGURATION, - null, - null, - null, - null, - null, - EMPTY_STACK_TRACE); - - // when - String statusMessage = insightsClient.createStatusMessage(); - - // then - Insight insight = - new ObjectMapper() - .readValue(statusMessage, new TypeReference>() {}); - assertThat(insight.getMetadata()) - .isEqualTo( - new InsightMetadata( - "driver.status", 1L, ImmutableMap.of("language", "java"), InsightType.EVENT, "v1")); - InsightsStatusData insightData = insight.getInsightData(); - assertThat(insightData.getClientId()).isEqualTo("client-id"); - assertThat(insightData.getSessionId()).isNotNull(); - assertThat(insightData.getControlConnection()).isEqualTo("127.0.0.1:10"); - assertThat(insightData.getConnectedNodes()) - .isEqualTo( - ImmutableMap.of( - "127.0.0.1:10", new SessionStateForNode(1, 10), - "127.0.0.1:20", new SessionStateForNode(2, 20))); - } - - @Test - public void should_schedule_task_with_initial_delay() { - // given - final AtomicInteger counter = new AtomicInteger(); - Runnable runnable = counter::incrementAndGet; - - // when - InsightsClient.scheduleInsightsTask(100L, Executors.newScheduledThreadPool(1), runnable); - - // then - await().atMost(1, SECONDS).until(() -> counter.get() >= 1); - } - - @Test - @UseDataProvider(value = "stackTraceProvider") - public void should_get_caller_of_create_cluster(StackTraceElement[] stackTrace, String expected) { - // when - String result = InsightsClient.getClusterCreateCaller(stackTrace); - - // then - assertThat(result).isEqualTo(expected); - } - - @Test - @SuppressWarnings("ResultOfMethodCallIgnored") - public void should_execute_should_send_event_check_only_once() - throws UnknownHostException, InterruptedException { - // given - InsightsConfiguration insightsConfiguration = mock(InsightsConfiguration.class); - when(insightsConfiguration.isMonitorReportingEnabled()).thenReturn(true); - when(insightsConfiguration.getStatusEventDelayMillis()).thenReturn(10L); - when(insightsConfiguration.getExecutor()).thenReturn(new DefaultEventLoop()); - - InsightsClient insightsClient = - new InsightsClient( - mockDefaultDriverContext(), - MOCK_TIME_SUPPLIER, - insightsConfiguration, - null, - null, - null, - null, - null, - EMPTY_STACK_TRACE); - - // when - insightsClient.scheduleStatusMessageSend(); - // emulate periodic calls to sendStatusMessage - insightsClient.sendStatusMessage(); - insightsClient.sendStatusMessage(); - insightsClient.sendStatusMessage(); - - // then - verify(insightsConfiguration, times(1)).isMonitorReportingEnabled(); - } - - @DataProvider - public static Object[][] stackTraceProvider() { - StackTraceElement[] onlyInitCall = - new StackTraceElement[] { - new StackTraceElement( - "com.datastax.oss.driver.internal.core.context.DefaultDriverContext", - "", - "DefaultDriverContext.java", - 94), - }; - - StackTraceElement[] stackTraceElementsWithoutInitCall = - new StackTraceElement[] { - new StackTraceElement("java.lang.Thread", "getStackTrace", "Thread.java", 1559), - new StackTraceElement( - "com.datastax.driver.core.InsightsClient", - "getClusterCreateCaller", - "InsightsClient.java", - 302) - }; - StackTraceElement[] stackTraceWithOneInitCall = - new StackTraceElement[] { - new StackTraceElement("java.lang.Thread", "getStackTrace", "Thread.java", 1559), - new StackTraceElement( - "com.datastax.oss.driver.internal.core.context.DefaultDriverContext", - "", - "DefaultDriverContext.java", - 243), - }; - StackTraceElement[] stackTraceWithOneInitCallAndCaller = - new StackTraceElement[] { - new StackTraceElement("java.lang.Thread", "getStackTrace", "Thread.java", 1559), - new StackTraceElement( - "com.datastax.oss.driver.internal.core.context.DefaultDriverContext", - "", - "DefaultDriverContext.java", - 243), - new StackTraceElement( - "com.example.ActualCallerNameApp", "main", "ActualCallerNameApp.java", 1) - }; - - StackTraceElement[] stackTraceWithTwoInitCallsAndCaller = - new StackTraceElement[] { - new StackTraceElement("java.lang.Thread", "getStackTrace", "Thread.java", 1559), - new StackTraceElement( - "com.datastax.oss.driver.internal.core.context.DefaultDriverContext", - "", - "DefaultDriverContext.java", - 243), - new StackTraceElement( - "com.datastax.oss.driver.api.core.session.SessionBuilder", - "buildDefaultSessionAsync", - "SessionBuilder.java", - 300), - new StackTraceElement( - "com.example.ActualCallerNameApp", "main", "ActualCallerNameApp.java", 1) - }; - StackTraceElement[] stackTraceWithChainOfInitCalls = - new StackTraceElement[] { - new StackTraceElement( - "com.datastax.oss.driver.internal.core.context.DefaultDriverContext", - "", - "DefaultDriverContext.java", - 243), - new StackTraceElement( - "com.datastax.oss.driver.api.core.session.SessionBuilder", - "buildDefaultSessionAsync", - "SessionBuilder.java", - 332), - new StackTraceElement( - "com.datastax.oss.driver.api.core.session.SessionBuilder", - "buildAsync", - "SessionBuilder.java", - 291), - new StackTraceElement( - "com.datastax.oss.driver.api.core.session.SessionBuilder", - "build", - "SessionBuilder.java", - 306) - }; - StackTraceElement[] stackTraceWithChainOfInitCallsAndCaller = - new StackTraceElement[] { - new StackTraceElement("java.lang.Thread", "getStackTrace", "Thread.java", 1559), - new StackTraceElement( - "com.datastax.oss.driver.internal.core.context.DefaultDriverContext", - "", - "DefaultDriverContext.java", - 243), - new StackTraceElement( - "com.datastax.oss.driver.api.core.session.SessionBuilder", - "buildContext", - "SessionBuilder.java", - 687), - new StackTraceElement( - "com.datastax.oss.driver.api.core.session.SessionBuilder", - "buildDefaultSessionAsync", - "SessionBuilder.java", - 332), - new StackTraceElement( - "com.datastax.oss.driver.api.core.session.SessionBuilder", - "buildAsync", - "SessionBuilder.java", - 291), - new StackTraceElement( - "com.datastax.oss.driver.api.core.session.SessionBuilder", - "build", - "SessionBuilder.java", - 306), - new StackTraceElement( - "com.example.ActualCallerNameApp", "main", "ActualCallerNameApp.java", 8) - }; - - return new Object[][] { - {new StackTraceElement[] {}, InsightsClient.DEFAULT_JAVA_APPLICATION}, - {stackTraceElementsWithoutInitCall, InsightsClient.DEFAULT_JAVA_APPLICATION}, - {stackTraceWithOneInitCall, InsightsClient.DEFAULT_JAVA_APPLICATION}, - {onlyInitCall, InsightsClient.DEFAULT_JAVA_APPLICATION}, - {stackTraceWithOneInitCallAndCaller, "com.example.ActualCallerNameApp"}, - {stackTraceWithTwoInitCallsAndCaller, "com.example.ActualCallerNameApp"}, - {stackTraceWithChainOfInitCalls, InsightsClient.DEFAULT_JAVA_APPLICATION}, - {stackTraceWithChainOfInitCallsAndCaller, "com.example.ActualCallerNameApp"} - }; - } - - private DefaultDriverContext mockDefaultDriverContext() throws UnknownHostException { - DefaultDriverContext context = mock(DefaultDriverContext.class); - mockConnectionPools(context); - MetadataManager manager = mock(MetadataManager.class); - when(context.getMetadataManager()).thenReturn(manager); - Metadata metadata = mock(Metadata.class); - when(manager.getMetadata()).thenReturn(metadata); - Node node = mock(Node.class); - when(node.getExtras()) - .thenReturn( - ImmutableMap.of( - DseNodeProperties.DSE_VERSION, Objects.requireNonNull(Version.parse("6.0.5")))); - when(metadata.getNodes()).thenReturn(ImmutableMap.of(UUID.randomUUID(), node)); - DriverExecutionProfile defaultExecutionProfile = mockDefaultExecutionProfile(); - DriverExecutionProfile nonDefaultExecutionProfile = - mockNonDefaultRequestTimeoutExecutionProfile(); - - Map startupOptions = new HashMap<>(); - startupOptions.put(StartupOptionsBuilder.CLIENT_ID_KEY, "client-id"); - startupOptions.put(StartupOptionsBuilder.APPLICATION_VERSION_KEY, "1.0.0"); - startupOptions.put(StartupOptionsBuilder.APPLICATION_NAME_KEY, "app-name"); - startupOptions.put(StartupOptionsBuilder.DRIVER_VERSION_KEY, "2.x"); - startupOptions.put(StartupOptionsBuilder.DRIVER_NAME_KEY, "DataStax Enterprise Java Driver"); - - when(context.getStartupOptions()).thenReturn(startupOptions); - when(context.getProtocolVersion()).thenReturn(DSE_V2); - DefaultNode contactPoint = mock(DefaultNode.class); - EndPoint contactEndPoint = mock(EndPoint.class); - when(contactEndPoint.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 9999)); - when(contactPoint.getEndPoint()).thenReturn(contactEndPoint); - when(manager.getContactPoints()).thenReturn(ImmutableSet.of(contactPoint)); - - DriverConfig driverConfig = mock(DriverConfig.class); - when(context.getConfig()).thenReturn(driverConfig); - Map profiles = - ImmutableMap.of( - "default", defaultExecutionProfile, "non-default", nonDefaultExecutionProfile); - Mockito.>when(driverConfig.getProfiles()) - .thenReturn(profiles); - when(driverConfig.getDefaultProfile()).thenReturn(defaultExecutionProfile); - - ControlConnection controlConnection = mock(ControlConnection.class); - DriverChannel channel = mock(DriverChannel.class); - EndPoint controlConnectionEndpoint = mock(EndPoint.class); - when(controlConnectionEndpoint.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 10)); - - when(channel.getEndPoint()).thenReturn(controlConnectionEndpoint); - when(channel.localAddress()).thenReturn(new InetSocketAddress("127.0.0.1", 10)); - when(controlConnection.channel()).thenReturn(channel); - when(context.getControlConnection()).thenReturn(controlConnection); - return context; - } - - private void mockConnectionPools(DefaultDriverContext driverContext) { - Node node1 = mock(Node.class); - EndPoint endPoint1 = mock(EndPoint.class); - when(endPoint1.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 10)); - when(node1.getEndPoint()).thenReturn(endPoint1); - when(node1.getOpenConnections()).thenReturn(1); - ChannelPool channelPool1 = mock(ChannelPool.class); - when(channelPool1.getInFlight()).thenReturn(10); - - Node node2 = mock(Node.class); - EndPoint endPoint2 = mock(EndPoint.class); - when(endPoint2.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 20)); - when(node2.getEndPoint()).thenReturn(endPoint2); - when(node2.getOpenConnections()).thenReturn(2); - ChannelPool channelPool2 = mock(ChannelPool.class); - when(channelPool2.getInFlight()).thenReturn(20); - - Map channelPools = ImmutableMap.of(node1, channelPool1, node2, channelPool2); - PoolManager poolManager = mock(PoolManager.class); - when(poolManager.getPools()).thenReturn(channelPools); - when(driverContext.getPoolManager()).thenReturn(poolManager); - } -} diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/InsightsSupportVerifierTest.java b/core/src/test/java/com/datastax/dse/driver/internal/core/insights/InsightsSupportVerifierTest.java deleted file mode 100644 index 9edd4494bdd..00000000000 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/InsightsSupportVerifierTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.datastax.dse.driver.api.core.metadata.DseNodeProperties; -import com.datastax.oss.driver.api.core.Version; -import com.datastax.oss.driver.api.core.metadata.Node; -import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList; -import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; -import java.util.Collection; -import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(DataProviderRunner.class) -public class InsightsSupportVerifierTest { - - @Test - @UseDataProvider(value = "dseHostsProvider") - public void should_detect_DSE_versions_that_supports_insights( - Collection hosts, boolean expected) { - // when - boolean result = InsightsSupportVerifier.supportsInsights(hosts); - - // then - assertThat(result).isEqualTo(expected); - } - - @DataProvider - public static Object[][] dseHostsProvider() { - Node dse605 = mock(Node.class); - when(dse605.getExtras()) - .thenReturn(ImmutableMap.of(DseNodeProperties.DSE_VERSION, Version.parse("6.0.5"))); - Node dse604 = mock(Node.class); - when(dse604.getExtras()) - .thenReturn(ImmutableMap.of(DseNodeProperties.DSE_VERSION, Version.parse("6.0.4"))); - Node dse600 = mock(Node.class); - when(dse600.getExtras()) - .thenReturn(ImmutableMap.of(DseNodeProperties.DSE_VERSION, Version.parse("6.0.0"))); - Node dse5113 = mock(Node.class); - when(dse5113.getExtras()) - .thenReturn(ImmutableMap.of(DseNodeProperties.DSE_VERSION, Version.parse("5.1.13"))); - Node dse500 = mock(Node.class); - when(dse500.getExtras()) - .thenReturn(ImmutableMap.of(DseNodeProperties.DSE_VERSION, Version.parse("5.0.0"))); - Node nodeWithoutExtras = mock(Node.class); - when(nodeWithoutExtras.getExtras()).thenReturn(Collections.emptyMap()); - - return new Object[][] { - {ImmutableList.of(dse605), true}, - {ImmutableList.of(dse604), false}, - {ImmutableList.of(dse600), false}, - {ImmutableList.of(dse5113), true}, - {ImmutableList.of(dse500), false}, - {ImmutableList.of(dse5113, dse605), true}, - {ImmutableList.of(dse5113, dse600), false}, - {ImmutableList.of(dse500, dse600), false}, - {ImmutableList.of(), false}, - {ImmutableList.of(nodeWithoutExtras), false} - }; - } -} diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/PackageUtilTest.java b/core/src/test/java/com/datastax/dse/driver/internal/core/insights/PackageUtilTest.java deleted file mode 100644 index 336f19184d3..00000000000 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/PackageUtilTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(DataProviderRunner.class) -public class PackageUtilTest { - - private static final String DEFAULT_PACKAGE = "default.package"; - - @Test - public void should_find_package_name_for_class() { - // given - TestClass testClass = new TestClass(); - - // then - String namespace = PackageUtil.getNamespace(testClass.getClass()); - - // then - assertThat(namespace).isEqualTo("com.datastax.dse.driver.internal.core.insights"); - } - - @Test - @UseDataProvider("packagesProvider") - public void should_get_full_package_or_return_default(String fullClassSetting, String expected) { - // when - String result = PackageUtil.getFullPackageOrDefault(fullClassSetting, DEFAULT_PACKAGE); - - // then - assertThat(result).isEqualTo(expected); - } - - @Test - @UseDataProvider("classesProvider") - public void should_get_class_name_from_full_class_setting( - String fullClassSetting, String expected) { - // when - String result = PackageUtil.getClassName(fullClassSetting); - - // then - assertThat(result).isEqualTo(expected); - } - - @DataProvider - public static Object[][] packagesProvider() { - return new Object[][] { - {"com.P", "com"}, - {"ClassName", DEFAULT_PACKAGE}, - {"", DEFAULT_PACKAGE}, - {"com.p.a.2.x.12.Class", "com.p.a.2.x.12"}, - }; - } - - @DataProvider - public static Object[][] classesProvider() { - return new Object[][] { - {"com.P", "P"}, - {"ClassName", "ClassName"}, - {"", ""}, - {"com.p.a.2.x.12.Class", "Class"}, - }; - } - - private static class TestClass {} -} diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/PlatformInfoFinderTest.java b/core/src/test/java/com/datastax/dse/driver/internal/core/insights/PlatformInfoFinderTest.java deleted file mode 100644 index 80294ea6b7d..00000000000 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/PlatformInfoFinderTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static com.datastax.dse.driver.internal.core.insights.PlatformInfoFinder.UNVERIFIED_RUNTIME_VERSION; -import static org.assertj.core.api.Assertions.assertThat; - -import com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.RuntimeAndCompileTimeVersions; -import java.io.InputStream; -import java.net.URL; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; -import org.junit.Test; - -public class PlatformInfoFinderTest { - - private URL nullUrlProvider(PlatformInfoFinder.DependencyFromFile d) { - return null; - } - - private URL nettyUrlProvider(PlatformInfoFinder.DependencyFromFile d) { - return this.getClass().getResource("/insights/pom.properties"); - } - - private URL malformedUrlProvider(PlatformInfoFinder.DependencyFromFile d) { - return this.getClass().getResource("/insights/malformed-pom.properties"); - } - - private URL nonExistingUrlProvider(PlatformInfoFinder.DependencyFromFile d) { - return this.getClass().getResource("/insights/non-existing.pom"); - } - - @Test - public void should_find_dependencies_from_file() { - // given - InputStream inputStream = - this.getClass().getResourceAsStream("/insights/test-dependencies.txt"); - Map expected = new HashMap<>(); - expected.put( - "io.netty:netty-transport-native-epoll", - withUnverifiedRuntimeVersionOptional("4.0.56.Final")); - expected.put("org.slf4j:slf4j-api", withUnverifiedRuntimeVersion("1.7.25")); - expected.put("org.ow2.asm:asm", withUnverifiedRuntimeVersion("5.0.3")); - expected.put("com.esri.geometry:esri-geometry-api", withUnverifiedRuntimeVersion("1.2.1")); - expected.put("io.netty:netty-transport", withUnverifiedRuntimeVersion("4.0.56.Final")); - expected.put("com.github.jnr:jnr-x86asm", withUnverifiedRuntimeVersion("1.0.2")); - expected.put("org.ow2.asm:asm-analysis", withUnverifiedRuntimeVersion("5.0.3")); - expected.put("com.github.jnr:jnr-constants", withUnverifiedRuntimeVersion("0.9.9")); - expected.put("io.netty:netty-common", withUnverifiedRuntimeVersion("4.0.56.Final")); - expected.put("com.google.guava:guava", withUnverifiedRuntimeVersion("19.0")); - expected.put("org.xerial.snappy:snappy-java", withUnverifiedRuntimeVersionOptional("1.1.2.6")); - expected.put("io.dropwizard.metrics:metrics-core", withUnverifiedRuntimeVersion("3.2.2")); - expected.put("org.ow2.asm:asm-tree", withUnverifiedRuntimeVersion("5.0.3")); - expected.put("com.github.jnr:jnr-posix", withUnverifiedRuntimeVersion("3.0.44")); - expected.put("org.codehaus.jackson:jackson-core-asl", withUnverifiedRuntimeVersion("1.9.12")); - expected.put( - "com.fasterxml.jackson.core:jackson-databind", withUnverifiedRuntimeVersion("2.7.9.3")); - expected.put("io.netty:netty-codec", withUnverifiedRuntimeVersion("4.0.56.Final")); - expected.put( - "com.fasterxml.jackson.core:jackson-annotations", withUnverifiedRuntimeVersion("2.8.11")); - expected.put("com.fasterxml.jackson.core:jackson-core", withUnverifiedRuntimeVersion("2.8.11")); - expected.put("io.netty:netty-handler", withUnverifiedRuntimeVersion("4.0.56.Final")); - expected.put("org.lz4:lz4-java", withUnverifiedRuntimeVersionOptional("1.4.1")); - expected.put("org.hdrhistogram:HdrHistogram", withUnverifiedRuntimeVersionOptional("2.1.10")); - expected.put("com.github.jnr:jffi", withUnverifiedRuntimeVersion("1.2.16")); - expected.put("io.netty:netty-buffer", withUnverifiedRuntimeVersion("4.0.56.Final")); - expected.put("org.ow2.asm:asm-commons", withUnverifiedRuntimeVersion("5.0.3")); - expected.put("org.json:json", withUnverifiedRuntimeVersion("20090211")); - expected.put("org.ow2.asm:asm-util", withUnverifiedRuntimeVersion("5.0.3")); - expected.put("com.github.jnr:jnr-ffi", withUnverifiedRuntimeVersion("2.1.7")); - - // when - Map stringStringMap = - new PlatformInfoFinder(this::nullUrlProvider).fetchDependenciesFromFile(inputStream); - - // then - assertThat(stringStringMap).hasSize(28); - assertThat(stringStringMap).isEqualTo(expected); - } - - @Test - public void should_find_dependencies_from_file_without_duplicate() { - // given - InputStream inputStream = - this.getClass().getResourceAsStream("/insights/duplicate-dependencies.txt"); - - // when - Map stringStringMap = - new PlatformInfoFinder(this::nullUrlProvider).fetchDependenciesFromFile(inputStream); - - // then - assertThat(stringStringMap).hasSize(1); - } - - @Test - public void should_keep_order_of_dependencies() { - // given - InputStream inputStream = - this.getClass().getResourceAsStream("/insights/ordered-dependencies.txt"); - Map expected = new LinkedHashMap<>(); - expected.put("b-org.com:art1", withUnverifiedRuntimeVersion("1.0")); - expected.put("a-org.com:art1", withUnverifiedRuntimeVersion("2.0")); - expected.put("c-org.com:art1", withUnverifiedRuntimeVersion("3.0")); - - // when - Map stringStringMap = - new PlatformInfoFinder(this::nullUrlProvider).fetchDependenciesFromFile(inputStream); - - // then - assertThat(stringStringMap).isEqualTo(expected); - Iterator iterator = expected.keySet().iterator(); - assertThat(iterator.next()).isEqualTo("b-org.com:art1"); - assertThat(iterator.next()).isEqualTo("a-org.com:art1"); - assertThat(iterator.next()).isEqualTo("c-org.com:art1"); - } - - @Test - public void should_add_information_about_java_platform() { - // given - Map> runtimeDependencies = new HashMap<>(); - - // when - new PlatformInfoFinder(this::nullUrlProvider).addJavaVersion(runtimeDependencies); - - // then - Map javaDependencies = runtimeDependencies.get("java"); - assertThat(javaDependencies.size()).isEqualTo(3); - } - - @Test - public void should_load_runtime_version_from_pom_properties_URL() { - // given - InputStream inputStream = this.getClass().getResourceAsStream("/insights/netty-dependency.txt"); - Map expected = new LinkedHashMap<>(); - expected.put( - "io.netty:netty-handler", - new RuntimeAndCompileTimeVersions("4.0.56.Final", "4.0.0.Final", false)); - - // when - Map stringStringMap = - new PlatformInfoFinder(this::nettyUrlProvider).fetchDependenciesFromFile(inputStream); - - // then - assertThat(stringStringMap).isEqualTo(expected); - } - - @Test - public void should_load_runtime_version_of_optional_dependency_from_pom_properties_URL() { - // given - InputStream inputStream = - this.getClass().getResourceAsStream("/insights/netty-dependency-optional.txt"); - Map expected = new LinkedHashMap<>(); - expected.put( - "io.netty:netty-handler", - new RuntimeAndCompileTimeVersions("4.0.56.Final", "4.0.0.Final", true)); - - // when - Map stringStringMap = - new PlatformInfoFinder(this::nettyUrlProvider).fetchDependenciesFromFile(inputStream); - - // then - assertThat(stringStringMap).isEqualTo(expected); - } - - @Test - public void should_not_load_runtime_dependency_from_malformed_pom_properties() { - // given - InputStream inputStream = this.getClass().getResourceAsStream("/insights/netty-dependency.txt"); - Map expected = new LinkedHashMap<>(); - expected.put("io.netty:netty-handler", withUnverifiedRuntimeVersion("4.0.0.Final")); - - // when - Map stringStringMap = - new PlatformInfoFinder(this::malformedUrlProvider).fetchDependenciesFromFile(inputStream); - - // then - assertThat(stringStringMap).isEqualTo(expected); - } - - @Test - public void should_not_load_runtime_dependency_from_non_existing_pom_properties() { - // given - InputStream inputStream = this.getClass().getResourceAsStream("/insights/netty-dependency.txt"); - Map expected = new LinkedHashMap<>(); - expected.put("io.netty:netty-handler", withUnverifiedRuntimeVersion("4.0.0.Final")); - - // when - Map stringStringMap = - new PlatformInfoFinder(this::nonExistingUrlProvider).fetchDependenciesFromFile(inputStream); - - // then - assertThat(stringStringMap).isEqualTo(expected); - } - - private RuntimeAndCompileTimeVersions withUnverifiedRuntimeVersion(String compileVersion) { - return new RuntimeAndCompileTimeVersions(UNVERIFIED_RUNTIME_VERSION, compileVersion, false); - } - - private RuntimeAndCompileTimeVersions withUnverifiedRuntimeVersionOptional( - String compileVersion) { - return new RuntimeAndCompileTimeVersions(UNVERIFIED_RUNTIME_VERSION, compileVersion, true); - } -} diff --git a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ReconnectionPolicyInfoFinderTest.java b/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ReconnectionPolicyInfoFinderTest.java deleted file mode 100644 index a076ca38b1c..00000000000 --- a/core/src/test/java/com/datastax/dse/driver/internal/core/insights/ReconnectionPolicyInfoFinderTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 com.datastax.dse.driver.internal.core.insights; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import com.datastax.dse.driver.internal.core.insights.schema.ReconnectionPolicyInfo; -import com.datastax.oss.driver.api.core.config.DefaultDriverOption; -import com.datastax.oss.driver.api.core.config.DriverExecutionProfile; -import com.datastax.oss.driver.api.core.connection.ReconnectionPolicy; -import com.datastax.oss.driver.internal.core.connection.ConstantReconnectionPolicy; -import com.datastax.oss.driver.internal.core.connection.ExponentialReconnectionPolicy; -import java.time.Duration; -import org.assertj.core.data.MapEntry; -import org.junit.Test; - -public class ReconnectionPolicyInfoFinderTest { - - @Test - public void should_find_an_info_about_constant_reconnection_policy() { - // given - DriverExecutionProfile driverExecutionProfile = mock(DriverExecutionProfile.class); - when(driverExecutionProfile.getDuration(DefaultDriverOption.RECONNECTION_BASE_DELAY)) - .thenReturn(Duration.ofMillis(100)); - ReconnectionPolicy constantReconnectionPolicy = mock(ConstantReconnectionPolicy.class); - - // when - ReconnectionPolicyInfo reconnectionPolicyInfo = - new ReconnectionPolicyInfoFinder() - .getReconnectionPolicyInfo(constantReconnectionPolicy, driverExecutionProfile); - - // then - assertThat(reconnectionPolicyInfo.getOptions()).contains(MapEntry.entry("delayMs", 100L)); - assertThat(reconnectionPolicyInfo.getType()).contains("ConstantReconnectionPolicy"); - } - - @Test - public void should_find_an_info_about_exponential_reconnection_policy() { - ExponentialReconnectionPolicy exponentialReconnectionPolicy = - mock(ExponentialReconnectionPolicy.class); - when(exponentialReconnectionPolicy.getBaseDelayMs()).thenReturn(100L); - when(exponentialReconnectionPolicy.getMaxAttempts()).thenReturn(10L); - when(exponentialReconnectionPolicy.getMaxDelayMs()).thenReturn(200L); - - // when - ReconnectionPolicyInfo reconnectionPolicyInfo = - new ReconnectionPolicyInfoFinder() - .getReconnectionPolicyInfo(exponentialReconnectionPolicy, null); - - // then - assertThat(reconnectionPolicyInfo.getOptions()).contains(MapEntry.entry("baseDelayMs", 100L)); - assertThat(reconnectionPolicyInfo.getOptions()).contains(MapEntry.entry("maxAttempts", 10L)); - assertThat(reconnectionPolicyInfo.getOptions()).contains(MapEntry.entry("maxDelayMs", 200L)); - assertThat(reconnectionPolicyInfo.getType()).contains("ExponentialReconnectionPolicy"); - } -} diff --git a/integration-tests/src/test/java/com/datastax/dse/driver/api/core/insights/InsightsClientIT.java b/integration-tests/src/test/java/com/datastax/dse/driver/api/core/insights/InsightsClientIT.java deleted file mode 100644 index 0296908be44..00000000000 --- a/integration-tests/src/test/java/com/datastax/dse/driver/api/core/insights/InsightsClientIT.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 com.datastax.dse.driver.api.core.insights; - -import com.datastax.dse.driver.internal.core.insights.InsightsClient; -import com.datastax.dse.driver.internal.core.insights.configuration.InsightsConfiguration; -import com.datastax.oss.driver.api.core.CqlSession; -import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule; -import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement; -import com.datastax.oss.driver.api.testinfra.requirement.BackendType; -import com.datastax.oss.driver.api.testinfra.session.SessionRule; -import com.datastax.oss.driver.internal.core.context.InternalDriverContext; -import io.netty.util.concurrent.DefaultEventExecutor; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.RuleChain; -import org.junit.rules.TestRule; - -@BackendRequirement( - type = BackendType.DSE, - minInclusive = "6.7.0", - description = "DSE 6.7.0 required for Insights support") -public class InsightsClientIT { - private static final StackTraceElement[] EMPTY_STACK_TRACE = {}; - - private static CustomCcmRule ccmRule = - CustomCcmRule.builder() - .withNodes(1) - .withJvmArgs( - "-Dinsights.service_options_enabled=true", - "-Dinsights.default_mode=ENABLED_WITH_LOCAL_STORAGE") - .build(); - - private static SessionRule sessionRule = SessionRule.builder(ccmRule).build(); - - @ClassRule public static TestRule chain = RuleChain.outerRule(ccmRule).around(sessionRule); - - @Test - public void should_send_insights_startup_event_using_client() - throws ExecutionException, InterruptedException, TimeoutException { - // given - InsightsClient insightsClient = - InsightsClient.createInsightsClient( - new InsightsConfiguration(true, 300000L, new DefaultEventExecutor()), - (InternalDriverContext) sessionRule.session().getContext(), - EMPTY_STACK_TRACE); - - // when - insightsClient.sendStartupMessage().toCompletableFuture().get(1000, TimeUnit.SECONDS); - - // then no exception - } - - @Test - public void should_send_insights_status_event_using_client() - throws ExecutionException, InterruptedException, TimeoutException { - // given - InsightsClient insightsClient = - InsightsClient.createInsightsClient( - new InsightsConfiguration(true, 300000L, new DefaultEventExecutor()), - (InternalDriverContext) sessionRule.session().getContext(), - EMPTY_STACK_TRACE); - - // when - insightsClient.sendStatusMessage().toCompletableFuture().get(1000, TimeUnit.SECONDS); - - // then no exception - } -} diff --git a/integration-tests/src/test/java/com/datastax/oss/driver/internal/core/util/concurrent/DriverBlockHoundIntegrationCcmIT.java b/integration-tests/src/test/java/com/datastax/oss/driver/internal/core/util/concurrent/DriverBlockHoundIntegrationCcmIT.java index e0f058b00d0..c6594e102f2 100644 --- a/integration-tests/src/test/java/com/datastax/oss/driver/internal/core/util/concurrent/DriverBlockHoundIntegrationCcmIT.java +++ b/integration-tests/src/test/java/com/datastax/oss/driver/internal/core/util/concurrent/DriverBlockHoundIntegrationCcmIT.java @@ -66,9 +66,6 @@ public class DriverBlockHoundIntegrationCcmIT extends ContinuousPagingITBase { private static final CustomCcmRule CCM_RULE = CustomCcmRule.builder().build(); - // Note: Insights monitoring will be detected by BlockHound, but the error is swallowed and - // logged by DefaultSession.SingleThreaded.notifyListeners, so it's not necessary to explicitly - // disable Insights here. private static final SessionRule SESSION_RULE = SessionRule.builder(CCM_RULE).build(); @ClassRule public static TestRule chain = RuleChain.outerRule(CCM_RULE).around(SESSION_RULE); diff --git a/manual/core/integration/README.md b/manual/core/integration/README.md index f2a96160bce..a1fd8a70a2e 100644 --- a/manual/core/integration/README.md +++ b/manual/core/integration/README.md @@ -473,7 +473,6 @@ dependency: [Jackson](https://github.com/FasterXML/jackson) is used: * when connecting to [DataStax Astra](../../cloud/); -* when Insights monitoring is enabled; * when [Json codecs](../custom_codecs) are being used. Jackson is declared as a required dependency, but the driver can operate normally without it. If you diff --git a/manual/core/non_blocking/README.md b/manual/core/non_blocking/README.md index 7abe9d856a3..a44404266c8 100644 --- a/manual/core/non_blocking/README.md +++ b/manual/core/non_blocking/README.md @@ -256,10 +256,6 @@ When connecting to clusters running recent DSE versions, the driver automaticall status reporting. When preparing the status report, the driver has to hit the local filesystem, and because of that, the status reporting process does not qualify as lock-free. -If lock-freedom is being enforced, then automatic status reporting must be disabled by setting the -`datastax-java-driver.advanced.monitor-reporting.enabled` property to false in the driver -configuration. - ### Driver mechanism for detection of blocking calls The driver has its own mechanism for detecting blocking calls happening on an internal driver