public void Equals_Same_Value_Returns_True()
        {
            var options1 = new DestinationConfig
            {
                Address  = "https://localhost:10000/destA",
                Health   = "https://localhost:20000/destA",
                Metadata = new Dictionary <string, string> {
                    { "destA-K1", "destA-V1" }, { "destA-K2", "destA-V2" }
                }
            };

            var options2 = new DestinationConfig
            {
                Address  = "https://localhost:10000/destA",
                Health   = "https://localhost:20000/destA",
                Metadata = new Dictionary <string, string> {
                    { "destA-K1", "destA-V1" }, {
                        "destA-K2", "destA-V2"
                    }
                }
            };

            var equals = options1.Equals(options2);

            Assert.True(equals);

            Assert.True(options1.Equals(options1 with {
            }));                                             // Clone
        }
 public AzureDestination(
     DestinationConfig destinationConfig,
     IAzureCommonStorage azureCommonStorage)
 {
     DestinationConfig   = destinationConfig;
     _azureCommonStorage = azureCommonStorage;
 }
        public void Equals_Different_Value_Returns_False()
        {
            var options1 = new DestinationConfig
            {
                Address  = "https://localhost:10000/destA",
                Health   = "https://localhost:20000/destA",
                Metadata = new Dictionary <string, string> {
                    { "destA-K1", "destA-V1" }, {
                        "destA-K2", "destA-V2"
                    }
                }
            };

            Assert.False(options1.Equals(options1 with {
                Address = "different"
            }));
            Assert.False(options1.Equals(options1 with {
                Health = null
            }));
            Assert.False(options1.Equals(options1 with
            {
                Metadata = new Dictionary <string, string>
                {
                    { "destB-K1", "destB-V1" }, { "destB-K2", "destB-V2" }
                }
            }));
        }
 public FileSystemDestination(
     DestinationConfig destinationConfig,
     IFileSystemCommonStorage FileSystemCommonStorage)
 {
     DestinationConfig        = destinationConfig;
     _fileSystemCommonStorage = FileSystemCommonStorage;
 }
Beispiel #5
0
        public void CreateRequest_RequestVersionProperties(string versionString)
        {
            var version = versionString != null?Version.Parse(versionString) : null;

            var clusterConfig = GetClusterConfig("cluster0",
                                                 new ActiveHealthCheckOptions()
            {
                Enabled = true,
                Policy  = "policy",
            },
                                                 version
#if NET
                                                 , HttpVersionPolicy.RequestVersionExact
#endif
                                                 );
            var destinationConfig = new DestinationConfig("https://localhost:10000/", null);
            var factory           = new DefaultProbingRequestFactory();

            var request = factory.CreateRequest(clusterConfig, destinationConfig);

            Assert.Equal(version ?? HttpVersion.Version20, request.Version);
#if NET
            Assert.Equal(HttpVersionPolicy.RequestVersionExact, request.VersionPolicy);
#endif
        }
 public ConsoleDestination(
     DestinationConfig destinationConfig,
     IIdentityServiceHttpRequestConfigurator identityServiceHttpRequestConfigurator)
 {
     DestinationConfig = destinationConfig;
     _identityServiceHttpRequestConfigurator = identityServiceHttpRequestConfigurator;
 }
        public void Equals_Second_Null_Returns_False()
        {
            var options1 = new DestinationConfig();

            var equals = options1.Equals(null);

            Assert.False(equals);
        }
Beispiel #8
0
 public CaseService(
     IOptions <DestinationConfig> destinationConfig,
     IAuthService authService
     )
 {
     this.destinationConfig = destinationConfig.Value;
     this.authService       = authService;
 }
Beispiel #9
0
 public AmazonDestination(
     DestinationConfig destinationConfig,
     IAmazonS3 amazonS3,
     IAmazonCommonStorage amazonCommonStorage)
 {
     DestinationConfig    = destinationConfig;
     _amazonS3            = amazonS3;
     _amazonCommonStorage = amazonCommonStorage;
 }
        public void CreateRequest_HealthEndpointIsNotDefined_UseDestinationAddress(string address, string health, string healthPath, string expectedRequestUri)
        {
            var clusterConfig     = GetClusterConfig("cluster0", new ClusterActiveHealthCheckOptions(true, null, null, "policy", healthPath), HttpVersion.Version20);
            var destinationConfig = new DestinationConfig(address, health);
            var factory           = new DefaultProbingRequestFactory();

            var request = factory.CreateRequest(clusterConfig, destinationConfig);

            Assert.Equal(expectedRequestUri, request.RequestUri.AbsoluteUri);
        }
        public HttpRequestMessage CreateRequest(ClusterConfig clusterConfig, DestinationConfig destinationConfig)
        {
            var probeAddress = !string.IsNullOrEmpty(destinationConfig.Health) ? destinationConfig.Health : destinationConfig.Address;
            var probePath    = clusterConfig.HealthCheckOptions.Active.Path;

            UriHelper.FromAbsolute(probeAddress, out var destinationScheme, out var destinationHost, out var destinationPathBase, out _, out _);
            var probeUri = UriHelper.BuildAbsolute(destinationScheme, destinationHost, destinationPathBase, probePath, default);

            return(new HttpRequestMessage(HttpMethod.Get, probeUri)
            {
                Version = ProtocolHelper.Http2Version
            });
        }
        public HttpRequestMessage CreateRequest(ClusterConfig clusterConfig, DestinationConfig destinationConfig)
        {
            var probeAddress = !string.IsNullOrEmpty(destinationConfig.Options.Health) ? destinationConfig.Options.Health : destinationConfig.Options.Address;
            var probePath    = clusterConfig.Options.HealthCheck.Active.Path;

            UriHelper.FromAbsolute(probeAddress, out var destinationScheme, out var destinationHost, out var destinationPathBase, out _, out _);
            var probeUri = UriHelper.BuildAbsolute(destinationScheme, destinationHost, destinationPathBase, probePath, default);

            return(new HttpRequestMessage(HttpMethod.Get, probeUri)
            {
                Version = clusterConfig.Options.HttpRequest?.Version ?? HttpVersion.Version20,
#if NET
                VersionPolicy = clusterConfig.Options.HttpRequest?.VersionPolicy ?? HttpVersionPolicy.RequestVersionOrLower
#endif
            });
        }
Beispiel #13
0
    private static DestinationModel CreateDestinationModel(string queueName)
    {
        var metadata = new Dictionary <string, string>();

        if (queueName != null)
        {
            metadata.Add(DelegationExtensions.HttpSysDelegationQueueMetadataKey, queueName);
        }

        var config = new DestinationConfig()
        {
            Address  = "http://*:80/",
            Metadata = metadata,
        };

        return(new DestinationModel(config));
    }
        public void LambdaGetFunctionEventInvokeConfig()
        {
            #region to-get-an-asynchronous-invocation-configuration-1586481338463

            var response = client.GetFunctionEventInvokeConfig(new GetFunctionEventInvokeConfigRequest
            {
                FunctionName = "my-function",
                Qualifier    = "BLUE"
            });

            DestinationConfig destinationConfig = response.DestinationConfig;
            string            functionArn       = response.FunctionArn;
            DateTime          lastModified      = response.LastModified;
            int maximumEventAgeInSeconds        = response.MaximumEventAgeInSeconds;
            int maximumRetryAttempts            = response.MaximumRetryAttempts;

            #endregion
        }
        public void LambdaPutFunctionEventInvokeConfig()
        {
            #region to-configure-error-handling-for-asynchronous-invocation-1586491524021

            var response = client.PutFunctionEventInvokeConfig(new PutFunctionEventInvokeConfigRequest
            {
                FunctionName             = "my-function",
                MaximumEventAgeInSeconds = 3600,
                MaximumRetryAttempts     = 0
            });

            DestinationConfig destinationConfig = response.DestinationConfig;
            string            functionArn       = response.FunctionArn;
            DateTime          lastModified      = response.LastModified;
            int maximumEventAgeInSeconds        = response.MaximumEventAgeInSeconds;
            int maximumRetryAttempts            = response.MaximumRetryAttempts;

            #endregion
        }
        private ClusterInfo GetClusterInfo(string id, int destinationCount, int?failureThreshold = null)
        {
            var metadata = failureThreshold != null
                ? new Dictionary <string, string> {
                { ConsecutiveFailuresHealthPolicyOptions.ThresholdMetadataName, failureThreshold.ToString() }
            }
                : null;
            var clusterConfig = new ClusterConfig(
                new Cluster
            {
                Id          = id,
                HealthCheck = new HealthCheckOptions()
                {
                    Active = new ActiveHealthCheckOptions
                    {
                        Enabled = true,
                        Policy  = "policy",
                        Path    = "/api/health/",
                    },
                },
                Metadata = metadata,
            },
                null);
            var clusterInfo = new ClusterInfo(id);

            clusterInfo.Config = clusterConfig;
            for (var i = 0; i < destinationCount; i++)
            {
                var destinationConfig = new DestinationConfig(new Destination {
                    Address = $"https://localhost:1000{i}/{id}/", Health = $"https://localhost:2000{i}/{id}/"
                });
                var destinationId = $"destination{i}";
                clusterInfo.Destinations.GetOrAdd(destinationId, id => new DestinationInfo(id)
                {
                    Config = destinationConfig
                });
            }

            clusterInfo.ProcessDestinationChanges();

            return(clusterInfo);
        }
        private ClusterInfo GetClusterInfo(string id, int destinationCount, double?failureRateLimit = null, TimeSpan?reactivationPeriod = null)
        {
            var metadata = failureRateLimit != null
                ? new Dictionary <string, string> {
                { TransportFailureRateHealthPolicyOptions.FailureRateLimitMetadataName, failureRateLimit?.ToString(CultureInfo.InvariantCulture) }
            }
                : null;
            var clusterConfig = new ClusterConfig(
                new Cluster
            {
                Id          = id,
                HealthCheck = new HealthCheckOptions
                {
                    Passive = new PassiveHealthCheckOptions
                    {
                        Enabled            = true,
                        Policy             = "policy",
                        ReactivationPeriod = reactivationPeriod,
                    }
                },
                Metadata = metadata,
            },
                null);
            var clusterInfo = new ClusterInfo(id);

            clusterInfo.Config = clusterConfig;
            for (var i = 0; i < destinationCount; i++)
            {
                var destinationConfig = new DestinationConfig(new Destination {
                    Address = $"https://localhost:1000{i}/{id}/", Health = $"https://localhost:2000{i}/{id}/"
                });
                var destinationId = $"destination{i}";
                clusterInfo.Destinations.GetOrAdd(destinationId, id => new DestinationInfo(id)
                {
                    Config = destinationConfig
                });
            }

            return(clusterInfo);
        }
        public void LambdaUpdateFunctionEventInvokeConfig()
        {
            #region to-update-an-asynchronous-invocation-configuration-1586492061186

            var response = client.UpdateFunctionEventInvokeConfig(new UpdateFunctionEventInvokeConfigRequest
            {
                DestinationConfig = new DestinationConfig {
                    OnFailure = new OnFailure {
                        Destination = "arn:aws:sqs:us-east-2:123456789012:destination"
                    }
                },
                FunctionName = "my-function"
            });

            DestinationConfig destinationConfig = response.DestinationConfig;
            string            functionArn       = response.FunctionArn;
            DateTime          lastModified      = response.LastModified;
            int maximumEventAgeInSeconds        = response.MaximumEventAgeInSeconds;
            int maximumRetryAttempts            = response.MaximumRetryAttempts;

            #endregion
        }
        public void LambdaGetEventSourceMapping()
        {
            #region to-get-a-lambda-functions-event-source-mapping-1481661622799

            var response = client.GetEventSourceMapping(new GetEventSourceMappingRequest
            {
                UUID = "14e0db71-xmpl-4eb5-b481-8945cf9d10c2"
            });

            int  batchSize = response.BatchSize;
            bool bisectBatchOnFunctionError        = response.BisectBatchOnFunctionError;
            DestinationConfig destinationConfig    = response.DestinationConfig;
            string            eventSourceArn       = response.EventSourceArn;
            string            functionArn          = response.FunctionArn;
            DateTime          lastModified         = response.LastModified;
            string            lastProcessingResult = response.LastProcessingResult;
            int    maximumRecordAgeInSeconds       = response.MaximumRecordAgeInSeconds;
            int    maximumRetryAttempts            = response.MaximumRetryAttempts;
            string state = response.State;
            string stateTransitionReason = response.StateTransitionReason;
            string uuid = response.UUID;

            #endregion
        }
Beispiel #20
0
        private List <FixPoint> GetFixPointDestinations()
        {
            List <FixPoint> list = new List <FixPoint>();

            // Example Input = D1=RO 10;D2=RO 12;D3=RO 14;D4=RO 16;
            var configArray = DestinationConfig.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var item in configArray)
            {
                var fixPointArray = item.Split('=');
                if (fixPointArray.Length == 2)
                {
                    var           fixPointName     = fixPointArray[0];
                    var           destinationArray = fixPointArray[1].Split(',');
                    List <string> destinationList  = new List <string>(destinationArray);
                    list.Add(new FixPoint()
                    {
                        Name = fixPointName, Destinations = destinationList
                    });
                }
            }

            return(list);
        }
        public IDestination GetDestination(DestinationConfig destinationConfig)
        {
            var destination = _destinationResolver.GetDestination(destinationConfig);

            return(_loggingDestinationFactory(destination));
        }
 public IDestination GetDestination(DestinationConfig destinationConfig)
 {
     return(_amazonDestinationFactory(destinationConfig));
 }
Beispiel #23
0
 public IDestination GetDestination(DestinationConfig destinationConfig)
 {
     return(_AzureDestinationFactory(destinationConfig));
 }
Beispiel #24
0
 public bool CanResolve(DestinationConfig destinationConfig)
 {
     return(string.Equals(destinationConfig.DestinationType, "Azure"));
 }
    public async Task RequestDelegated()
    {
        IHttpSysDelegator      delegator  = null;
        IForwarderErrorFeature proxyError = null;
        Exception unhandledError          = null;
        var       expectedRepsone         = "Hello World!";
        var       queueName = nameof(HttpSysDelegationTests) + Random.Shared.Next().ToString("x8");
        string    urlPrefix = null;

        var test = new HttpSysTestEnvironment(
            destinationServices => { },
            destinationHttpSysOptions => destinationHttpSysOptions.RequestQueueName = queueName,
            destinationApp => destinationApp.Run(context => context.Response.WriteAsync(expectedRepsone)),
            proxyServices => { },
            proxyBuilder => { },
            proxyApp =>
        {
            delegator = proxyApp.ApplicationServices.GetRequiredService <IHttpSysDelegator>();
            proxyApp.Use(async(context, next) =>
            {
                try
                {
                    await next();
                    proxyError = context.Features.Get <IForwarderErrorFeature>();
                }
                catch (Exception ex)
                {
                    unhandledError = ex;
                    throw;
                }
            });
        },
            proxyPipeline =>
        {
            proxyPipeline.UseHttpSysDelegation();
        },
            (cluster, route) =>
        {
            urlPrefix       = cluster.Destinations.First().Value.Address;
            var destination = new DestinationConfig()
            {
                Address  = urlPrefix,
                Metadata = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
                {
                    { DelegationExtensions.HttpSysDelegationQueueMetadataKey, queueName },
                },
            };

            cluster = new ClusterConfig
            {
                ClusterId    = cluster.ClusterId,
                Destinations = new Dictionary <string, DestinationConfig>(StringComparer.OrdinalIgnoreCase)
                {
                    { "destination1", destination },
                },
            };

            return(cluster, route);
        });

        await test.Invoke(async proxyUri =>
        {
            using var httpClient = new HttpClient();
            var response         = await httpClient.GetStringAsync(proxyUri);

            Assert.Null(proxyError);
            Assert.Null(unhandledError);
            Assert.Equal(expectedRepsone, response);

            Assert.NotNull(delegator);
            delegator.ResetQueue(queueName, urlPrefix);

            response = await httpClient.GetStringAsync(proxyUri);

            Assert.Null(proxyError);
            Assert.Null(unhandledError);
            Assert.Equal(expectedRepsone, response);
        });
    }
 public IDestinationResolver GetResolver(DestinationConfig destinationConfig)
 {
     return(_destinationResolvers.Where(x => x.CanResolve(destinationConfig)).Single());
 }
Beispiel #27
0
 internal bool HasChanged(DestinationConfig destination)
 {
     return(Config != destination);
 }
Beispiel #28
0
 /// <summary>
 /// Creates a new instance. This constructor is for tests and infrastructure, this type is normally constructed by
 /// the configuration loading infrastructure.
 /// </summary>
 public DestinationModel(DestinationConfig destination)
 {
     Config = destination ?? throw new ArgumentNullException(nameof(destination));
 }
Beispiel #29
0
 public IDestination GetDestination(DestinationConfig destinationConfig)
 {
     return(_fileSystemDestinationFactory(destinationConfig));
 }
Beispiel #30
0
 public AuthService(
     IOptions <DestinationConfig> destinationConfig
     )
 {
     this.destinationConfig = destinationConfig.Value;
 }