/// <summary> /// Initializes a new instance of the <see cref="TelemetryDataClientBase"/> class. /// </summary> /// <param name="tracer">The tracer</param> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="queryUri">The query URI</param> /// <param name="queryTimeout">The query timeout</param> /// <param name="telemetryDbType">The type of telemetry DB that this data client accesses</param> /// <param name="mainTelemetryDbId">The main telemetry DB ID - the ID of the DB on which all queries will run</param> /// <param name="telemetryResourceIds">the telemetry resource IDs - the IDs of the resources that store the telemetry that this data client accesses</param> protected TelemetryDataClientBase( ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, Uri queryUri, TimeSpan queryTimeout, TelemetryDbType telemetryDbType, string mainTelemetryDbId, IEnumerable <string> telemetryResourceIds) { this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer); this.httpClientWrapper = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper); this.Timeout = Diagnostics.EnsureArgumentInRange(() => queryTimeout, TimeSpan.FromMinutes(0), TimeSpan.FromHours(2)); this.queryUri = queryUri; this.TelemetryDbType = telemetryDbType; this.MainTelemetryDbId = Diagnostics.EnsureStringNotNullOrWhiteSpace(() => mainTelemetryDbId); this.TelemetryResourceIds = telemetryResourceIds?.ToList() ?? new List <string>(); this.retryPolicy = PolicyExtensions.CreateDefaultPolicy(this.tracer, this.TelemetryDbType.ToString()); // Extract the host part of the URI as the credentials resource UriBuilder builder = new UriBuilder() { Scheme = this.queryUri.Scheme, Host = this.queryUri.Host }; Diagnostics.EnsureArgumentNotNull(() => credentialsFactory); this.credentials = credentialsFactory.Create(builder.Uri.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="ActivityLogClient"/> class. /// </summary> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="tracer">The tracer</param> public ActivityLogClient(ICredentialsFactory credentialsFactory, IHttpClientWrapper httpClientWrapper, IExtendedTracer tracer) { this.httpClientWrapper = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper); this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer); this.baseUri = new Uri(ConfigurationManager.AppSettings["ResourceManagerBaseUri"] ?? "https://management.azure.com/"); Diagnostics.EnsureArgumentNotNull(() => credentialsFactory); this.credentials = credentialsFactory.Create(ConfigurationManager.AppSettings["ResourceManagerCredentialsResource"] ?? "https://management.azure.com/"); this.httpRetryPolicy = PolicyExtensions.CreateTransientHttpErrorPolicy(this.tracer, DependencyName); }
public CredentialsCreator( IOAuthToken oAuthToken, ICredentialsFactory credentialsFactory, IOAuthWebRequestGenerator oAuthWebRequestGenerator, IUnityFactory <ITemporaryCredentials> applicationCredentialsUnityFactory) { _oAuthToken = oAuthToken; _credentialsFactory = credentialsFactory; _oAuthWebRequestGenerator = oAuthWebRequestGenerator; _applicationCredentialsUnityFactory = applicationCredentialsUnityFactory; }
public CredentialsCreator( ICredentialsFactory credentialsFactory, ITwitterRequester twitterRequester, IOAuthWebRequestGenerator oAuthWebRequestGenerator, IFactory <ITemporaryCredentials> applicationCredentialsUnityFactory) { _credentialsFactory = credentialsFactory; _twitterRequester = twitterRequester; _oAuthWebRequestGenerator = oAuthWebRequestGenerator; _applicationCredentialsUnityFactory = applicationCredentialsUnityFactory; }
/// <summary> /// Initializes a new instance of the <see cref="MdmClient"/> class /// </summary> /// <param name="tracer">The tracer</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="resourceIdentifier">The resource for which we want to fetch data from MDM</param> /// /// <param name="monitorManagementClient">Monitor management client to use to fetch data from MDM</param> public MdmClient(ITracer tracer, ICredentialsFactory credentialsFactory, ResourceIdentifier resourceIdentifier, IMonitorManagementClient monitorManagementClient) { this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer); Diagnostics.EnsureArgumentNotNull(() => credentialsFactory); this.resourceIdentifier = resourceIdentifier; this.credentials = credentialsFactory.Create("https://management.azure.com/"); this.monitorManagementClient = monitorManagementClient; this.monitorManagementClient.SubscriptionId = resourceIdentifier.SubscriptionId; this.tracer = tracer; this.retryPolicy = PolicyExtensions.CreateDefaultPolicy(this.tracer, DependencyName); }
/// <summary> /// Initializes a new instance of the <see cref="AnalysisServicesFactory"/> class. /// </summary> /// <param name="tracer">The tracer</param> /// <param name="httpClientWrapper">The HTTP client wrapper.</param> /// <param name="credentialsFactory">The credentials factory.</param> /// <param name="azureResourceManagerClient">The azure resource manager client.</param> /// <param name="queryRunInfoProvider">The query run information provider.</param> public AnalysisServicesFactory(ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, IAzureResourceManagerClient azureResourceManagerClient, IQueryRunInfoProvider queryRunInfoProvider) { this.tracer = tracer; this.httpClientWrapper = httpClientWrapper; this.credentialsFactory = credentialsFactory; this.azureResourceManagerClient = azureResourceManagerClient; this.queryRunInfoProvider = queryRunInfoProvider; // string timeoutString = ConfigurationReader.ReadConfig("AnalyticsQueryTimeoutInMinutes", required: true); string timeoutString = "15"; this.queryTimeout = TimeSpan.FromMinutes(int.Parse(timeoutString)); }
/// <summary> /// Initializes a new instance of the <see cref="ExtendedAzureResourceManagerClient"/> class /// </summary> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="tracer">The tracer</param> public ExtendedAzureResourceManagerClient(ICredentialsFactory credentialsFactory, IExtendedTracer tracer) { Diagnostics.EnsureArgumentNotNull(() => credentialsFactory); this.baseUri = new Uri(ConfigurationManager.AppSettings["ResourceManagerBaseUri"] ?? "https://management.azure.com/"); this.credentials = credentialsFactory.Create(ConfigurationManager.AppSettings["ResourceManagerCredentialsResource"] ?? "https://management.azure.com/"); this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer); this.tracer = tracer; this.retryPolicy = Policy .Handle <CloudException>(ex => ex.Request != null && (ex.Response.StatusCode >= HttpStatusCode.InternalServerError || ex.Response.StatusCode == HttpStatusCode.RequestTimeout)) .WaitAndRetryAsync( 3, (i) => TimeSpan.FromSeconds(Math.Pow(2, i)), (exception, span, context) => tracer.TraceError($"Failed accessing DependencyName on {exception.Message}, retry {Math.Log(span.Seconds, 2)} out of 3")); }
/// <summary> /// Initializes a new instance of the <see cref="LogAnalyticsClient"/> class. /// </summary> /// <param name="tracer">The tracer</param> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="queryUri">The URI to use for querying telemetry - this should already include the resource to query</param> /// <param name="queryTimeout">The query timeout</param> public LogAnalyticsClient( ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, Uri queryUri, TimeSpan queryTimeout) { this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer); this.httpClientWrapper = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper); this.credentialsFactory = Diagnostics.EnsureArgumentNotNull(() => credentialsFactory); this.QueryUri = Diagnostics.EnsureArgumentNotNull(() => queryUri); this.Timeout = Diagnostics.EnsureArgumentInRange(() => queryTimeout, TimeSpan.FromMinutes(0), TimeSpan.FromHours(2)); this.retryPolicy = PolicyExtensions.CreateTransientHttpErrorPolicy(this.tracer, "LogAnalytics"); }
/// <summary> /// Initializes a new instance of the <see cref="AnalysisServicesFactory"/> class. /// </summary> /// <param name="tracer">The tracer</param> /// <param name="httpClientWrapper">The HTTP client wrapper.</param> /// <param name="credentialsFactory">The credentials factory.</param> /// <param name="azureResourceManagerClient">The Azure Resource Manager client.</param> public AnalysisServicesFactory(ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, IExtendedAzureResourceManagerClient azureResourceManagerClient) { this.tracer = tracer; this.httpClientWrapper = httpClientWrapper; this.credentialsFactory = credentialsFactory; this.azureResourceManagerClient = azureResourceManagerClient; // string timeoutString = ConfigurationReader.ReadConfig("AnalyticsQueryTimeoutInMinutes", required: true); string timeoutString = "15"; this.queryTimeout = TimeSpan.FromMinutes(int.Parse(timeoutString, CultureInfo.InvariantCulture)); this.UsedLogAnalysisClient = false; this.UsedMetricClient = false; }
public void Start() { if (!_live.CompareAndSet(false, true)) { return; } _credentialsFactory = _client.GetCredentialsFactory(); //start Heartbeat _heartbeatToken = new CancellationTokenSource(); _client.GetClientExecutionService().ScheduleWithFixedDelay(Heartbeat, (long)_heartbeatInterval.TotalMilliseconds, (long)_heartbeatInterval.TotalMilliseconds, TimeUnit.Milliseconds, _heartbeatToken.Token); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationInsightsTelemetryDataClient"/> class. /// </summary> /// <param name="tracer">The tracer</param> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="azureResourceManagerClient">The Azure Resource Manager client</param> /// <param name="applicationsResourceIds">The resource IDs of the applications on which the queries will run.</param> /// <param name="queryTimeout">The query timeout.</param> public ApplicationInsightsTelemetryDataClient( ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, IExtendedAzureResourceManagerClient azureResourceManagerClient, IEnumerable <string> applicationsResourceIds, TimeSpan queryTimeout) : base( tracer, httpClientWrapper, credentialsFactory, azureResourceManagerClient, ConfigurationManager.AppSettings["ApplicationInsightsUriFormat"] ?? UriFormat, queryTimeout, "ApplicationInsights", applicationsResourceIds) { }
/// <summary> /// Initializes a new instance of the <see cref="LogAnalyticsTelemetryDataClient"/> class. /// </summary> /// <param name="tracer">The tracer</param> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="azureResourceManagerClient">The Azure Resource Manager client</param> /// <param name="workspacesResourceIds">The resource IDs of the workspaces on which the queries will run.</param> /// <param name="queryTimeout">The query timeout.</param> public LogAnalyticsTelemetryDataClient( IExtendedTracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, IExtendedAzureResourceManagerClient azureResourceManagerClient, IEnumerable <string> workspacesResourceIds, TimeSpan queryTimeout) : base( tracer, httpClientWrapper, credentialsFactory, azureResourceManagerClient, ConfigurationManager.AppSettings["LogAnalyticsUriFormat"] ?? UriFormat, queryTimeout, TelemetryDbType.LogAnalytics, workspacesResourceIds) { }
private HazelcastClient(ClientConfig config) { _config = config; var groupConfig = config.GetGroupConfig(); _instanceName = "hz.client_" + _id + (groupConfig != null ? "_" + groupConfig.GetName() : string.Empty); _lifecycleService = new LifecycleService(this); try { //TODO make partition strategy parametric var partitioningStrategy = new DefaultPartitioningStrategy(); _serializationService = new SerializationServiceBuilder().SetManagedContext(new HazelcastClientManagedContext(this, config.GetManagedContext())) .SetConfig(config.GetSerializationConfig()) .SetPartitioningStrategy(partitioningStrategy) .SetVersion(SerializationService.SerializerVersion) .Build(); } catch (Exception e) { throw ExceptionUtil.Rethrow(e); } _proxyManager = new ProxyManager(this); //TODO EXECUTION SERVICE _executionService = new ClientExecutionService(_instanceName, config.GetExecutorPoolSize()); _clusterService = new ClientClusterService(this); _loadBalancer = config.GetLoadBalancer() ?? new RoundRobinLB(); _addressProvider = new AddressProvider(_config); _connectionManager = new ClientConnectionManager(this); _invocationService = CreateInvocationService(); _listenerService = new ClientListenerService(this); _userContext = new ConcurrentDictionary <string, object>(); _partitionService = new ClientPartitionService(this); _lockReferenceIdGenerator = new ClientLockReferenceIdGenerator(); _statistics = new Statistics(this); _nearCacheManager = new NearCacheManager(this); _credentialsFactory = InitCredentialsFactory(config); }
protected TelemetryDataClientBase( ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, IExtendedAzureResourceManagerClient azureResourceManagerClient, string queryUriFormat, TimeSpan queryTimeout, string telemetryDbType, IEnumerable <string> telemetryResourceIds) { this.tracer = Diagnostics.EnsureArgumentNotNull(() => tracer); this.httpClientWrapper = Diagnostics.EnsureArgumentNotNull(() => httpClientWrapper); this.credentialsFactory = Diagnostics.EnsureArgumentNotNull(() => credentialsFactory); this.AzureResourceManagerClient = Diagnostics.EnsureArgumentNotNull(() => azureResourceManagerClient); this.queryUriFormat = Diagnostics.EnsureStringNotNullOrWhiteSpace(() => queryUriFormat); this.Timeout = Diagnostics.EnsureArgumentInRange(() => queryTimeout, TimeSpan.FromMinutes(0), TimeSpan.FromHours(2)); this.telemetryDbType = telemetryDbType; int maximumNumberOfTelemetryResources = int.Parse(ConfigurationManager.AppSettings["MaximumNumberOfTelemetryResources"] ?? "300", CultureInfo.InvariantCulture); this.TelemetryResourceIds = telemetryResourceIds?.Take(maximumNumberOfTelemetryResources).ToList() ?? new List <string>(); this.retryPolicy = PolicyExtensions.CreateTransientHttpErrorPolicy(this.tracer, this.telemetryDbType); }
/// <summary> /// Initializes a new instance of the <see cref="MdmClient"/> class /// </summary> /// <param name="tracer">The tracer</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="resourceIdentifier">The resource for which we want to fetch data from MDM</param> public MdmClient(ITracer tracer, ICredentialsFactory credentialsFactory, ResourceIdentifier resourceIdentifier) : this(tracer, credentialsFactory, resourceIdentifier, new MonitorManagementClient(credentialsFactory.Create("https://management.azure.com/"))) { }
/// <summary> /// Initializes a new instance of the <see cref="MetricClient"/> class /// </summary> /// <param name="tracer">The tracer</param> /// <param name="credentialsFactory">The credentials factory</param> public MetricClient(ITracer tracer, ICredentialsFactory credentialsFactory) : this(tracer, new MonitorManagementClient(RestClient.Configure() .WithEnvironment(AzureEnvironment.AzureGlobalCloud) .WithCredentials(credentialsFactory.CreateAzureCredentials("https://management.azure.com/")).Build())) { }
/// <summary> /// Initializes a new instance of the <see cref="MetricClient"/> class /// </summary> /// <param name="tracer">The tracer</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="subscriptionId">The subscription Id</param> public MetricClient(IExtendedTracer tracer, ICredentialsFactory credentialsFactory, string subscriptionId) : this(tracer, subscriptionId, new MonitorManagementClient(credentialsFactory.Create("https://management.azure.com/"))) { }
/// <summary> /// Set the factory instance /// </summary> /// <param name="factoryImpl">factory instance to be configured</param> /// <returns>configured <see cref="CredentialsFactoryConfig"/> for chaining</returns> public CredentialsFactoryConfig SetImplementation(ICredentialsFactory factoryImpl) { _implementation = factoryImpl; return(this); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationInsightsClientFactory"/> class. /// </summary> /// <param name="credentialsFactory">The credentials factory.</param> public ApplicationInsightsClientFactory(ICredentialsFactory credentialsFactory) { this.credentialsFactory = credentialsFactory; }
static TwitterCredentials() { _credentialsFactory = TweetinviContainer.Resolve <ICredentialsFactory>(); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationInsightsTelemetryDataClient"/> class. /// </summary> /// <param name="tracer">The tracer</param> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="applicationId">The application Id on which the queries will run. If there are multiple applications, this should be the ID of one of them.</param> /// <param name="applicationsResourceIds"> /// The resource IDs of the applications on which the queries will run. /// Can be null or empty if there is only one application to analyze. If there are multiple applications, /// one of these IDs need to match the application identified by the specified <paramref name="applicationId"/>. /// </param> /// <param name="queryTimeout">The query timeout.</param> public ApplicationInsightsTelemetryDataClient(ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, string applicationId, IEnumerable <string> applicationsResourceIds, TimeSpan queryTimeout) : base( tracer, httpClientWrapper, credentialsFactory, new Uri(string.Format(UriFormat, applicationId)), queryTimeout, TelemetryDbType.ApplicationInsights, applicationId, applicationsResourceIds) { }
public TextAnalyticsClientFactory(ICredentialsFactory credentialsFactory) { _credentialsFactory = credentialsFactory; }
/// <summary> /// Initializes a new instance of the <see cref="AzureResourceManagerClient"/> class /// </summary> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="tracer">The tracer</param> public AzureResourceManagerClient(ICredentialsFactory credentialsFactory, ITracer tracer) { this.credentials = credentialsFactory.Create("https://management.azure.com/"); this.tracer = tracer; this.retryPolicy = PolicyExtensions.CreateDefaultPolicy(this.tracer, DependencyName); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationInsightsClient"/> class. /// </summary> /// <param name="applicationId">The AI application id.</param> /// <param name="credentialsFactory">The credentials factory (for AI authentication)</param> public ApplicationInsightsClient(string applicationId, ICredentialsFactory credentialsFactory) { this.applicationId = applicationId; this.credentials = credentialsFactory.Create(ApplicationInsightsResource); this.httpClient = new HttpClientWrapper(); }
/// <summary> /// Initializes a new instance of the <see cref="ApplicationInsightsClient"/> class. /// We are using this constructor for UTs. /// </summary> /// <param name="applicationId">The AI application id.</param> /// <param name="httpClient">The HTTP client.</param> /// <param name="credentialsFactory">The credentials factory (for AI authentication)</param> internal ApplicationInsightsClient(string applicationId, IHttpClientWrapper httpClient, ICredentialsFactory credentialsFactory) { this.applicationId = applicationId; this.httpClient = httpClient; this.credentials = credentialsFactory.Create(ApplicationInsightsResource); }
// tries to authenticate // returns a result if successful // returns null if failed due to credentials (may want to retry) // throws if anything else went wrong private async ValueTask <AuthenticationResult> TryAuthenticateAsync(MemberConnection client, string clusterName, Guid clusterClientId, string clusterClientName, ISet <string> labels, ICredentialsFactory credentialsFactory, CancellationToken cancellationToken) { const string clientType = "CSP"; // CSharp var serializationVersion = _serializationService.GetVersion(); var clientVersion = ClientVersion; var credentials = credentialsFactory.NewCredentials(); ClientMessage requestMessage; switch (credentials) { case IPasswordCredentials passwordCredentials: requestMessage = ClientAuthenticationCodec.EncodeRequest(clusterName, passwordCredentials.Name, passwordCredentials.Password, clusterClientId, clientType, serializationVersion, clientVersion, clusterClientName, labels); break; case ITokenCredentials tokenCredentials: requestMessage = ClientAuthenticationCustomCodec.EncodeRequest(clusterName, tokenCredentials.GetToken(), clusterClientId, clientType, serializationVersion, clientVersion, clusterClientName, labels); break; default: var bytes = _serializationService.ToData(credentials).ToByteArray(); requestMessage = ClientAuthenticationCustomCodec.EncodeRequest(clusterName, bytes, clusterClientId, clientType, serializationVersion, clientVersion, clusterClientName, labels); break; } cancellationToken.ThrowIfCancellationRequested(); HConsole.WriteLine(this, "Send auth request"); var responseMessage = await client.SendAsync(requestMessage).CfAwait(); HConsole.WriteLine(this, "Rcvd auth response"); var response = ClientAuthenticationCodec.DecodeResponse(responseMessage); HConsole.WriteLine(this, "Auth response is: " + (AuthenticationStatus)response.Status); return((AuthenticationStatus)response.Status switch { AuthenticationStatus.Authenticated => new AuthenticationResult(response.ClusterId, response.MemberUuid, response.Address, response.ServerHazelcastVersion, response.FailoverSupported, response.PartitionCount, response.SerializationVersion, credentials.Name), AuthenticationStatus.CredentialsFailed => null, // could want to retry AuthenticationStatus.NotAllowedInCluster => throw new AuthenticationException("Client is not allowed in cluster."), AuthenticationStatus.SerializationVersionMismatch => throw new AuthenticationException("Serialization mismatch."), _ => throw new AuthenticationException($"Received unsupported status code {response.Status}.") });
/// <summary> /// Initializes a new instance of the <see cref="LogAnalyticsTelemetryDataClient"/> class. /// </summary> /// <param name="tracer">The tracer</param> /// <param name="httpClientWrapper">The HTTP client wrapper</param> /// <param name="credentialsFactory">The credentials factory</param> /// <param name="workspaceId">The workspace Id on which the queries will run. If there are multiple workspaces, this should be the ID of one of them.</param> /// <param name="workspacesResourceIds"> /// The resource IDs of the workspaces on which the queries will run. /// Can be null or empty if there is only one workspace to analyze. If there are multiple workspaces, /// one of these IDs need to match the workspace identified by the specified <paramref name="workspaceId"/>. /// </param> /// <param name="queryTimeout">The query timeout.</param> public LogAnalyticsTelemetryDataClient(ITracer tracer, IHttpClientWrapper httpClientWrapper, ICredentialsFactory credentialsFactory, string workspaceId, IEnumerable <string> workspacesResourceIds, TimeSpan queryTimeout) : base( tracer, httpClientWrapper, credentialsFactory, new Uri(string.Format(UriFormat, workspaceId)), queryTimeout, TelemetryDbType.LogAnalytics, workspaceId, workspacesResourceIds) { }