public IControlConnection Create( IInternalCluster cluster, IProtocolEventDebouncer protocolEventDebouncer, ProtocolVersion initialProtocolVersion, Configuration config, Metadata metadata, IEnumerable <IContactPoint> contactPoints) { var cc = Mock.Of <IControlConnection>(); Mock.Get(cc).Setup(c => c.InitAsync()).Returns(Task.Run(async() => { var cps = new Dictionary <IContactPoint, IEnumerable <IConnectionEndPoint> >(); foreach (var cp in contactPoints) { var connectionEndpoints = (await cp.GetConnectionEndPointsAsync(true).ConfigureAwait(false)).ToList(); cps.Add(cp, connectionEndpoints); foreach (var connectionEndpoint in connectionEndpoints) { var endpt = connectionEndpoint.GetHostIpEndPointWithFallback(); var host = metadata.AddHost(endpt, cp); host.SetInfo(BuildRow()); Mock.Get(cc).Setup(c => c.Host).Returns(host); } } metadata.SetResolvedContactPoints(cps); })); Mock.Get(cc).Setup(c => c.Serializer).Returns(new SerializerManager(ProtocolVersion.V3)); return(cc); }
public Dictionary <string, string> GetInformation(IInternalCluster cluster, IInternalSession session) { var antiPatterns = new Dictionary <string, string>(); var resolvedContactPoints = cluster.Metadata.ResolvedContactPoints; var contactPointsEndPoints = resolvedContactPoints .Values .SelectMany(endPoints => endPoints) .Select(c => c.GetHostIpEndPointWithFallback()) .ToList(); var contactPointsHosts = cluster .AllHosts() .Where(host => (host.ContactPoint != null && resolvedContactPoints.ContainsKey(host.ContactPoint)) || contactPointsEndPoints.Contains(host.Address)) .ToList(); if (contactPointsHosts.Select(c => c.Datacenter).Where(dc => dc != null).Distinct().Count() > 1) { antiPatterns["contactPointsMultipleDCs"] = "Contact points contain hosts from multiple data centers"; } var loadBalancingPolicy = cluster.Configuration.Policies.LoadBalancingPolicy; antiPatterns = ConfigAntiPatternsInfoProvider.AddAntiPatterns(loadBalancingPolicy, antiPatterns); var retryPolicy = cluster.Configuration.Policies.RetryPolicy; antiPatterns = ConfigAntiPatternsInfoProvider.AddAntiPatterns(retryPolicy, antiPatterns); return(antiPatterns); }
public IControlConnection Create( IInternalCluster cluster, IProtocolEventDebouncer protocolEventDebouncer, ProtocolVersion initialProtocolVersion, Configuration config, Metadata metadata, IEnumerable <object> contactPoints) { var cc = Mock.Of <IControlConnection>(); Mock.Get(cc).Setup(c => c.InitAsync()).Returns(Task.Run(() => { var cps = new Dictionary <string, IEnumerable <IPEndPoint> >(); foreach (var cp in contactPoints) { if (cp is string cpStr && IPAddress.TryParse(cpStr, out var addr)) { var host = metadata.AddHost(new IPEndPoint(addr, config.ProtocolOptions.Port)); host.SetInfo(BuildRow()); Mock.Get(cc).Setup(c => c.Host).Returns(host); cps.Add(cpStr, new List <IPEndPoint> { host.Address }); }
internal UdtMappingDefinitions(IInternalSession session, Serializer serializer) { _udtByNetType = new ConcurrentDictionary <Type, UdtMap>(); _cluster = session.InternalCluster; _session = session; _serializer = serializer; }
private IInternalSession GetSession(IInternalCluster cluster) { var session = Mock.Of <IInternalSession>(); var mockPool1 = Mock.Of <IHostConnectionPool>(); var mockPool2 = Mock.Of <IHostConnectionPool>(); Mock.Get(mockPool1).SetupGet(m => m.InFlight).Returns(1); Mock.Get(mockPool1).SetupGet(m => m.OpenConnections).Returns(3); Mock.Get(mockPool2).SetupGet(m => m.InFlight).Returns(2); Mock.Get(mockPool2).SetupGet(m => m.OpenConnections).Returns(4); var host1 = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9042); var host2 = new IPEndPoint(IPAddress.Parse("127.0.0.2"), 9042); var pools = new Dictionary <IPEndPoint, IHostConnectionPool> { { host1, mockPool1 }, { host2, mockPool2 } }; Mock.Get(cluster).Setup(m => m.GetHost(host1)).Returns(new Host(host1, contactPoint: null)); Mock.Get(cluster).Setup(m => m.GetHost(host2)).Returns(new Host(host2, contactPoint: null)); Mock.Get(session).Setup(s => s.GetPools()).Returns(pools.ToArray()); Mock.Get(session).Setup(m => m.Cluster).Returns(cluster); Mock.Get(session).SetupGet(m => m.InternalSessionId).Returns(Guid.Parse("E21EAB96-D91E-4790-80BD-1D5FB5472258")); return(session); }
public HashSet <string> GetInformation(IInternalCluster cluster, IInternalSession session) { var dataCenters = new HashSet <string>(); var remoteConnectionsLength = cluster .Configuration .GetOrCreatePoolingOptions(cluster.Metadata.ControlConnection.ProtocolVersion) .GetCoreConnectionsPerHost(HostDistance.Remote); foreach (var h in cluster.AllHosts()) { if (h.Datacenter == null) { continue; } var distance = cluster.Configuration.Policies.LoadBalancingPolicy.Distance(h); if (distance == HostDistance.Local || (distance == HostDistance.Remote && remoteConnectionsLength > 0)) { dataCenters.Add(h.Datacenter); } } return(dataCenters); }
public DriverInfo GetInformation(IInternalCluster cluster, IInternalSession session) { return(new DriverInfo { DriverName = AssemblyHelpers.GetAssemblyTitle(typeof(DriverInfoProvider)), DriverVersion = AssemblyHelpers.GetAssemblyInformationalVersion(typeof(DriverInfoProvider)) }); }
public AuthProviderInfo GetInformation(IInternalCluster cluster, IInternalSession session) { var type = cluster.Configuration.AuthProvider.GetType(); return(new AuthProviderInfo { Namespace = type.Namespace, Type = type.Name }); }
public InsightsClient( IInternalCluster cluster, IInternalSession session, IInsightsMessageFactory <InsightsStartupData> startupMessageFactory, IInsightsMessageFactory <InsightsStatusData> statusMessageFactory) { _cluster = cluster; _session = session; _monitorReportingOptions = cluster.Configuration.MonitorReportingOptions; _startupMessageFactory = startupMessageFactory; _statusMessageFactory = statusMessageFactory; }
public PolicyInfo GetInformation(IInternalCluster cluster, IInternalSession session) { var policy = cluster.Configuration.Policies.ReconnectionPolicy; var type = policy.GetType(); ReconnectionPolicyInfoProvider.PolicyOptionsProviders.TryGetValue(type, out var optionsProvider); return(new PolicyInfo { Namespace = type.Namespace, Type = type.Name, Options = optionsProvider?.Invoke(policy) }); }
public PoolSizeByHostDistance GetInformation(IInternalCluster cluster, IInternalSession session) { return(new PoolSizeByHostDistance { Local = cluster .Configuration .GetOrCreatePoolingOptions(cluster.Metadata.ControlConnection.ProtocolVersion) .GetCoreConnectionsPerHost(HostDistance.Local), Remote = cluster .Configuration .GetOrCreatePoolingOptions(cluster.Metadata.ControlConnection.ProtocolVersion) .GetCoreConnectionsPerHost(HostDistance.Remote) }); }
private ControlConnection NewInstance(IInternalCluster cluster, Configuration config, Metadata metadata) { return(new ControlConnection( cluster, GetEventDebouncer(config), ProtocolVersion.MaxSupported, config, metadata, new List <IContactPoint> { new IpLiteralContactPoint( IPAddress.Parse("127.0.0.1"), config.ProtocolOptions, config.ServerNameResolver) })); }
public Insight <InsightsStartupData> CreateMessage(IInternalCluster cluster, IInternalSession session) { var metadata = _metadataFactory.CreateInsightsMetadata( InsightsStartupMessageFactory.StartupMessageName, InsightsStartupMessageFactory.StartupV1MappingId, InsightType.Event); var driverInfo = _infoProviders.DriverInfoProvider.GetInformation(cluster, session); var startupData = new InsightsStartupData { ClientId = cluster.Configuration.ClusterId.ToString(), SessionId = session.InternalSessionId.ToString(), DriverName = driverInfo.DriverName, DriverVersion = driverInfo.DriverVersion, ApplicationName = cluster.Configuration.ApplicationName, ApplicationVersion = cluster.Configuration.ApplicationVersion, ApplicationNameWasGenerated = cluster.Configuration.ApplicationNameWasGenerated, ContactPoints = cluster.Metadata.ResolvedContactPoints.ToDictionary( kvp => kvp.Key, kvp => kvp.Value.Select(ipEndPoint => ipEndPoint.ToString()).ToList()), DataCenters = _infoProviders.DataCentersInfoProvider.GetInformation(cluster, session), InitialControlConnection = cluster.Metadata.ControlConnection.EndPoint?.GetHostIpEndPointWithFallback().ToString(), LocalAddress = cluster.Metadata.ControlConnection.LocalAddress?.ToString(), HostName = _infoProviders.HostnameProvider.GetInformation(cluster, session), ProtocolVersion = (byte)cluster.Metadata.ControlConnection.ProtocolVersion, ExecutionProfiles = _infoProviders.ExecutionProfileInfoProvider.GetInformation(cluster, session), PoolSizeByHostDistance = _infoProviders.PoolSizeByHostDistanceInfoProvider.GetInformation(cluster, session), HeartbeatInterval = cluster .Configuration .GetOrCreatePoolingOptions(cluster.Metadata.ControlConnection.ProtocolVersion) .GetHeartBeatInterval() ?? 0, Compression = cluster.Configuration.ProtocolOptions.Compression, ReconnectionPolicy = _infoProviders.ReconnectionPolicyInfoProvider.GetInformation(cluster, session), Ssl = new SslInfo { Enabled = cluster.Configuration.ProtocolOptions.SslOptions != null }, AuthProvider = _infoProviders.AuthProviderInfoProvider.GetInformation(cluster, session), OtherOptions = _infoProviders.OtherOptionsInfoProvider.GetInformation(cluster, session), PlatformInfo = _infoProviders.PlatformInfoProvider.GetInformation(cluster, session), ConfigAntiPatterns = _infoProviders.ConfigAntiPatternsInfoProvider.GetInformation(cluster, session), PeriodicStatusInterval = cluster.Configuration.MonitorReportingOptions.StatusEventDelayMilliseconds / 1000 }; return(new Insight <InsightsStartupData> { Metadata = metadata, Data = startupData }); }
public IControlConnection Create( IInternalCluster cluster, IProtocolEventDebouncer protocolEventDebouncer, ProtocolVersion initialProtocolVersion, Configuration config, Metadata metadata, IEnumerable <IContactPoint> contactPoints) { return(new ControlConnection( cluster, protocolEventDebouncer, initialProtocolVersion, config, metadata, contactPoints)); }
public Insight <InsightsStatusData> CreateMessage(IInternalCluster cluster, IInternalSession session) { var metadata = _insightsMetadataFactory.CreateInsightsMetadata( InsightsStatusMessageFactory.StatusMessageName, InsightsStatusMessageFactory.StatusV1MappingId, InsightType.Event); var data = new InsightsStatusData { ClientId = cluster.Configuration.ClusterId.ToString(), SessionId = session.InternalSessionId.ToString(), ControlConnection = cluster.Metadata.ControlConnection.EndPoint?.GetHostIpEndPointWithFallback().ToString(), ConnectedNodes = _connectedNodesInfoProvider.GetInformation(cluster, session) }; return(new Insight <InsightsStatusData> { Metadata = metadata, Data = data }); }
public InsightsPlatformInfo GetInformation(IInternalCluster cluster, IInternalSession session) { var cpuInfo = PlatformHelper.GetCpuInfo(); var dependencies = typeof(PlatformInfoProvider).GetTypeInfo().Assembly.GetReferencedAssemblies().Select(name => new AssemblyInfo { FullName = name.FullName, Name = name.Name, Version = name.Version?.ToString() }); var dependenciesDictionary = new Dictionary <string, AssemblyInfo>(); foreach (var p in dependencies) { // Use the first value in list if (!dependenciesDictionary.ContainsKey(p.Name)) { dependenciesDictionary[p.Name] = p; } } return(new InsightsPlatformInfo { CentralProcessingUnits = new CentralProcessingUnitsInfo { Length = cpuInfo.Length, Model = cpuInfo.FirstCpuName }, OperatingSystem = new OperatingSystemInfo { Name = RuntimeInformation.OSDescription, Version = RuntimeInformation.OSDescription, Arch = RuntimeInformation.OSArchitecture.ToString() }, Runtime = new RuntimeInfo { Dependencies = dependenciesDictionary, RuntimeFramework = RuntimeInformation.FrameworkDescription, TargetFramework = PlatformHelper.GetTargetFramework(), } }); }
public Dictionary <string, ExecutionProfileInfo> GetInformation(IInternalCluster cluster, IInternalSession session) { // add default first so that it is on top var dict = new Dictionary <string, ExecutionProfileInfo> { { "default", GetExecutionProfileInfo( cluster.Configuration.ExecutionProfiles[Configuration.DefaultExecutionProfileName]) } }; foreach (var profile in cluster.Configuration .ExecutionProfiles .Where(kvp => kvp.Key != Configuration.DefaultExecutionProfileName)) { dict.Add(profile.Key, GetExecutionProfileInfo(profile.Value)); } return(dict); }
public Dictionary <string, NodeStatusInfo> GetInformation(IInternalCluster cluster, IInternalSession session) { var nodeStatusDictionary = new Dictionary <string, NodeStatusInfo>(); var state = session.GetState(); var connectedHosts = state.GetConnectedHosts(); foreach (var h in connectedHosts) { var inFlightQueries = state.GetInFlightQueries(h); var openConnections = state.GetOpenConnections(h); nodeStatusDictionary.Add( h.Address.ToString(), new NodeStatusInfo { Connections = openConnections, InFlightQueries = inFlightQueries }); } return(nodeStatusDictionary); }
public string GetInformation(IInternalCluster cluster, IInternalSession session) { return(Dns.GetHostName()); }
public IPrepareHandler CreatePrepareHandler( ISerializerManager serializerManager, IInternalCluster cluster) { return(new PrepareHandler(serializerManager, cluster, CreateReprepareHandler())); }
public bool SupportsInsights(IInternalCluster cluster) { var allHosts = cluster.AllHosts(); return(allHosts.Count != 0 && allHosts.All(h => DseVersionSupportsInsights(h.DseVersion))); }
public PrepareHandler(ISerializer serializer, IInternalCluster cluster, IReprepareHandler reprepareHandler) { _serializer = serializer; _cluster = cluster; _reprepareHandler = reprepareHandler; }
public Dictionary <string, object> GetInformation(IInternalCluster cluster, IInternalSession session) { return(null); }
private ControlConnectionCreateResult NewInstance( IDictionary <IPEndPoint, IRow> rows = null, IInternalCluster cluster = null, Configuration config = null, Metadata metadata = null, Action <TestConfigurationBuilder> configBuilderAct = null) { if (rows == null) { rows = new Dictionary <IPEndPoint, IRow> { { new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9042), TestHelper.CreateRow(new Dictionary <string, object> { { "cluster_name", "ut-cluster" }, { "data_center", "ut-dc" }, { "rack", "ut-rack" }, { "tokens", null }, { "release_version", "2.2.1-SNAPSHOT" } }) } }; } if (cluster == null) { cluster = Mock.Of <IInternalCluster>(); } var connectionFactory = new FakeConnectionFactory(); if (config == null) { var builder = new TestConfigurationBuilder { ConnectionFactory = connectionFactory, TopologyRefresherFactory = new FakeTopologyRefresherFactory(rows), SchemaParserFactory = new FakeSchemaParserFactory(), SupportedOptionsInitializerFactory = new FakeSupportedOptionsInitializerFactory(), ProtocolVersionNegotiator = new FakeProtocolVersionNegotiator(), ServerEventsSubscriber = new FakeServerEventsSubscriber() }; configBuilderAct?.Invoke(builder); config = builder.Build(); } if (metadata == null) { metadata = new Metadata(config); } return(new ControlConnectionCreateResult { ConnectionFactory = connectionFactory, Metadata = metadata, Cluster = cluster, Config = config, ControlConnection = new ControlConnection( cluster, GetEventDebouncer(config), ProtocolVersion.MaxSupported, config, metadata, new List <IContactPoint> { new IpLiteralContactPoint( IPAddress.Parse("127.0.0.1"), config.ProtocolOptions, config.ServerNameResolver) }) }); }
public Task <IInternalSession> CreateSessionAsync( IInternalCluster cluster, string keyspace, ISerializerManager serializer, string sessionName) { return(Task.FromResult( new Session(cluster, cluster.Configuration, keyspace, serializer, sessionName).InternalRef)); }
public IPrepareHandler Create(ISerializer serializer, IInternalCluster cluster) { return(new PrepareHandler(serializer, cluster)); }
private static InsightsClient GetInsightsClient(IInternalCluster cluster, IInternalSession session) { var hostnameInfoMock = Mock.Of <IInsightsInfoProvider <string> >(); var driverInfoMock = Mock.Of <IInsightsInfoProvider <DriverInfo> >(); var timestampGeneratorMock = Mock.Of <IInsightsMetadataTimestampGenerator>(); var platformInfoMock = Mock.Of <IInsightsInfoProvider <InsightsPlatformInfo> >(); Mock.Get(hostnameInfoMock).Setup(m => m.GetInformation(cluster, session)).Returns("awesome_hostname"); Mock.Get(driverInfoMock).Setup(m => m.GetInformation(cluster, session)).Returns(new DriverInfo { DriverVersion = "1.1.2", DriverName = "Driver Name" }); Mock.Get(timestampGeneratorMock).Setup(m => m.GenerateTimestamp()).Returns(124219041); Mock.Get(platformInfoMock).Setup(m => m.GetInformation(cluster, session)).Returns(new InsightsPlatformInfo { CentralProcessingUnits = new CentralProcessingUnitsInfo { Length = 2, Model = "Awesome CPU" }, Runtime = new RuntimeInfo { Dependencies = new Dictionary <string, AssemblyInfo> { { "Assembly1", new AssemblyInfo { Version = "1.2.0", Name = "Assembly1", FullName = "Assembly1FullName" } } }, RuntimeFramework = "runtime-framework", TargetFramework = "target-framework" }, OperatingSystem = new OperatingSystemInfo { Version = "os version", Name = "os name", Arch = "os arch" } }); var target = new InsightsClient( cluster, session, new InsightsStartupMessageFactory( new InsightsMetadataFactory(timestampGeneratorMock), new InsightsInfoProvidersCollection( platformInfoMock, new ExecutionProfileInfoProvider( new LoadBalancingPolicyInfoProvider(new ReconnectionPolicyInfoProvider()), new SpeculativeExecutionPolicyInfoProvider(), new RetryPolicyInfoProvider()), new PoolSizeByHostDistanceInfoProvider(), new AuthProviderInfoProvider(), new DataCentersInfoProvider(), new OtherOptionsInfoProvider(), new ConfigAntiPatternsInfoProvider(), new ReconnectionPolicyInfoProvider(), driverInfoMock, hostnameInfoMock)), new InsightsStatusMessageFactory( new InsightsMetadataFactory(timestampGeneratorMock), new NodeStatusInfoProvider())); return(target); }
public IInsightsClient Create(IInternalCluster cluster, IInternalSession session) { return(new InsightsClient(cluster, session, _startupMessageFactory, _statusMessageFactory)); }
public SessionFactory(IInternalCluster cluster) { _cluster = cluster; }
public ClusterLifecycleManager(IInternalCluster cluster) { _cluster = cluster; }