Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#36368 log filed2 #181

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
23c470e
install + small change in ExtracPropertiesMetadata
arkovean Jun 14, 2018
126e2c1
PropertiesMetadataPropertiesCache - small refactoring
arkovean Jun 15, 2018
68d2365
MetadataCacheParam - Removing redundant code + small amedments
arkovean Jun 17, 2018
428d40b
rename propertyInfo into memberInfo.
arkovean Jun 17, 2018
2434625
Missing Test
arkovean Jun 17, 2018
0543ffa
Missing verification.
arkovean Jun 17, 2018
6143c99
Eran - Returning to ReflectionMetadataInfo
arkovean Jun 17, 2018
4f01d19
CanRead Fix
arkovean Jun 17, 2018
1f99c98
Properties without Getter - Bug Fix
arkovean Jun 17, 2018
72a2062
Moving SensitivityAttributesValidator from Infra to Microdot
arkovean Jun 17, 2018
9041d13
Validating whether Sensitivity Attribute appears in property level wh…
arkovean Jun 17, 2018
5a038bf
Adding SensitivityAttributeValidatorTest
arkovean Jun 17, 2018
b6128cb
Personal Code Review
arkovean Jun 18, 2018
4da2069
Remarks
arkovean Jun 18, 2018
6e5a9db
Daniel - Bug Fix
arkovean Jun 18, 2018
4ae9efc
review
daniel-lamberger Jun 18, 2018
a9be890
review
daniel-lamberger Jun 18, 2018
271fdc3
Daniels remarks
arkovean Jun 19, 2018
ffc6556
Small Refactoring
arkovean Jun 19, 2018
9941772
review
daniel-lamberger Jun 20, 2018
9a1bb33
Service Contract version 2.5.6
arkovean Jun 20, 2018
c27c09d
review
daniel-lamberger Jun 20, 2018
9e5fb8f
.
daniel-lamberger Jun 20, 2018
dbd2fab
renaming
arkovean Jun 20, 2018
6e03e62
adding reverse
arkovean Jun 20, 2018
5f40581
New discovery (#179)
bronsh Jul 9, 2018
254106d
fix test
Jul 9, 2018
939ee06
Merged 'develop'.
arkovean Jul 12, 2018
8d7fbcf
version fix
arkovean Jul 12, 2018
3b1b040
fixing conflict
arkovean Jul 12, 2018
492de7d
merge accepted
arkovean Jul 12, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .paket/install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off
cd /d %~dp0
paket.bootstrapper.exe
paket.exe install
echo.
echo.
pause
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,4 @@
</ItemGroup>
</When>
</Choose>
<Import Project="..\packages\NETStandard.Library\build\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library\build\NETStandard.Library.targets')" Label="Paket" />
</Project>
26 changes: 22 additions & 4 deletions Gigya.Microdot.Fakes/DateTimeFake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Gigya.Microdot.Interfaces.SystemWrappers;

namespace Gigya.Microdot.Fakes
{
public class DateTimeFake: IDateTime
public class DateTimeFake : IDateTime
{
public DateTime UtcNow { get; set; }
public DateTime UtcNow { get; set; } = DateTime.UtcNow;

private TaskCompletionSource<bool> _delayTask = new TaskCompletionSource<bool>();

Expand All @@ -46,10 +47,27 @@ public DateTimeFake(bool manualDelay)
_manualDelay = manualDelay;
}

public Task Delay(TimeSpan delay)
public async Task Delay(TimeSpan delay, CancellationToken cancellationToken = default(CancellationToken))
{
DelaysRequested.Add(delay);
return _manualDelay ? _delayTask.Task : Task.Delay(delay);

if (_manualDelay)
await _delayTask.Task;
else
await Task.Delay(delay, cancellationToken);

UtcNow += delay;
}

public async Task DelayUntil(DateTime until, CancellationToken cancellationToken = default(CancellationToken))
{
TimeSpan delayTime = until - UtcNow;

if (delayTime > TimeSpan.Zero)
{
await Delay(delayTime, cancellationToken).ConfigureAwait(false);
UtcNow += delayTime;
}
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Gigya.Microdot.Fakes/Discovery/AlwaysLocalHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace Gigya.Microdot.Fakes.Discovery
{
public class AlwaysLocalHost : IDiscoverySourceLoader
{
public IServiceDiscoverySource GetDiscoverySource(ServiceDeployment serviceDeployment, ServiceDiscoveryConfig serviceDiscoveryConfig)
public IServiceDiscoverySource GetDiscoverySource(DeploymentIdentifier deploymentIdentifier, ServiceDiscoveryConfig serviceDiscoveryConfig)
{
return new LocalDiscoverySource(serviceDeployment);
return new LocalDiscoverySource(deploymentIdentifier);
}
}
}
55 changes: 55 additions & 0 deletions Gigya.Microdot.Fakes/Discovery/AlwaysLocalHostDiscovery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#region Copyright
// Copyright 2017 Gigya Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#endregion

using System;
using System.Threading.Tasks;
using Gigya.Microdot.ServiceDiscovery;
using Gigya.Microdot.ServiceDiscovery.Config;
using Gigya.Microdot.ServiceDiscovery.Rewrite;
using Gigya.Microdot.SharedLogic.Rewrite;

namespace Gigya.Microdot.Fakes.Discovery
{
public class AlwaysLocalhostDiscovery : IDiscovery
{
private Func<DeploymentIdentifier, INodeSource, ReachabilityCheck, TrafficRoutingStrategy, ILoadBalancer> CreateLoadBalancer {get;}

public AlwaysLocalhostDiscovery(Func<DeploymentIdentifier, INodeSource, ReachabilityCheck, TrafficRoutingStrategy, ILoadBalancer> createLoadBalancer)
{
CreateLoadBalancer = createLoadBalancer;
}

public async Task<ILoadBalancer> TryCreateLoadBalancer(DeploymentIdentifier deploymentIdentifier, ReachabilityCheck reachabilityCheck, TrafficRoutingStrategy trafficRoutingStrategy)
{
return CreateLoadBalancer(deploymentIdentifier, new LocalNodeSource(), reachabilityCheck, trafficRoutingStrategy);
}

public async Task<Node[]> GetNodes(DeploymentIdentifier deploymentIdentifier)
{
return new LocalNodeSource().GetNodes();
}

public void Dispose()
{
}
}
}
38 changes: 28 additions & 10 deletions Gigya.Microdot.Fakes/Discovery/LocalhostServiceDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,49 @@
// POSSIBILITY OF SUCH DAMAGE.
#endregion

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
using Gigya.Microdot.Interfaces.HttpService;
using Gigya.Microdot.ServiceDiscovery;
using Gigya.Microdot.ServiceDiscovery.Rewrite;
using Gigya.Microdot.SharedLogic.HttpService;
using Gigya.Microdot.SharedLogic.Rewrite;

namespace Gigya.Microdot.Fakes.Discovery
{

public class LocalhostServiceDiscovery : IServiceDiscovery
public class LocalhostServiceDiscovery : INewServiceDiscovery
{
private static readonly IEndPointHandle handle = new LocalhostEndPointHandle();
private readonly ILoadBalancer _localhostLoadBalancer = new LocalhostLoadBalancer();

private readonly Task<IEndPointHandle> _source = Task.FromResult(handle);
public Task<ILoadBalancer> GetLoadBalancer()
{
return Task.FromResult(_localhostLoadBalancer);
}

private readonly Task<EndPoint[]> allHosts = Task.FromResult(new[] { new EndPoint { HostName = handle.HostName, Port = handle.Port } });
}

public class LocalhostLoadBalancer : ILoadBalancer
{
readonly INodeSource _localNodeSource = new LocalNodeSource();

public Task<IEndPointHandle> GetNextHost(string affinityToken = null) => _source;
public async Task<Node> GetNode()
{
return _localNodeSource.GetNodes().First();
}

public Task<IEndPointHandle> GetOrWaitForNextHost(CancellationToken cancellationToken) => _source;
public Task<bool> WasUndeployed() => Task.FromResult(false);

public ISourceBlock<string> EndPointsChanged => new BroadcastBlock<string>(null);
public void ReportUnreachable(Node node, Exception ex = null)
{
}

public ISourceBlock<ServiceReachabilityStatus> ReachabilityChanged => new BroadcastBlock<ServiceReachabilityStatus>(null);
public void Dispose()
{

public Task<EndPoint[]> GetAllEndPoints() => allHosts;
}
}

}
2 changes: 1 addition & 1 deletion Gigya.Microdot.Fakes/Gigya.Microdot.Fakes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<Link>Properties\SolutionVersion.cs</Link>
</Compile>
<Compile Include="Discovery\AlwaysLocalHost.cs" />
<Compile Include="Discovery\AlwaysLocalHostDiscovery.cs" />
<Compile Include="MetricsInitializerFake.cs" />
<Compile Include="ConsoleLog.cs" />
<Compile Include="DateTimeFake.cs" />
Expand Down Expand Up @@ -127,5 +128,4 @@
</ItemGroup>
</When>
</Choose>
<Import Project="..\packages\NETStandard.Library\build\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library\build\NETStandard.Library.targets')" Label="Paket" />
</Project>
2 changes: 1 addition & 1 deletion Gigya.Microdot.Hosting/Events/ServiceCallEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
using System.Linq;
using System.Text.RegularExpressions;
using Gigya.Microdot.Interfaces.Events;
using Gigya.Microdot.Interfaces.HttpService;
using Gigya.Microdot.SharedLogic.Events;
using Gigya.Microdot.SharedLogic.HttpService;

namespace Gigya.Microdot.Hosting.Events
{
Expand Down
2 changes: 1 addition & 1 deletion Gigya.Microdot.Hosting/Gigya.Microdot.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<Compile Include="HttpService\ServiceMethodResolver.cs" />
<Compile Include="Metrics\MetricsConfiguration.cs" />
<Compile Include="Metrics\MetricsInitializer.cs" />
<Compile Include="Validators\SensitivityAttributesValidator.cs" />
<Compile Include="Service\ServiceHostBase.cs" />
<Compile Include="Service\HostExtensionMethods.cs" />
<Compile Include="HttpService\Endpoints\HealthStatusResult.cs" />
Expand Down Expand Up @@ -195,5 +196,4 @@
</ItemGroup>
</When>
</Choose>
<Import Project="..\packages\NETStandard.Library\build\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library\build\NETStandard.Library.targets')" Label="Paket" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,21 @@
// POSSIBILITY OF SUCH DAMAGE.
#endregion

using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Gigya.Common.Contracts.HttpService;
using Newtonsoft.Json;

namespace Gigya.Microdot.Hosting.HttpService.Endpoints
{

public class SchemaEndpoint : ICustomEndpoint
{
private readonly string _jsonSchema;

public SchemaEndpoint(IServiceInterfaceMapper mapper)
public SchemaEndpoint(ServiceSchema schemaProvider)
{
_jsonSchema = JsonConvert.SerializeObject(new ServiceSchema(mapper.ServiceInterfaceTypes.ToArray()), new JsonSerializerSettings{Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore});
}

_jsonSchema = JsonConvert.SerializeObject(schemaProvider, new JsonSerializerSettings{Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore});
}

public async Task<bool> TryHandle(HttpListenerContext context, WriteResponseDelegate writeResponse)
{
Expand Down
22 changes: 15 additions & 7 deletions Gigya.Microdot.Hosting/HttpService/HttpServiceListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@
using System.Threading.Tasks;
using Gigya.Common.Contracts;
using Gigya.Common.Contracts.Exceptions;
using Gigya.Common.Contracts.HttpService;
using Gigya.Microdot.Hosting.Events;
using Gigya.Microdot.Hosting.HttpService.Endpoints;
using Gigya.Microdot.Interfaces.Configuration;
using Gigya.Microdot.Interfaces.Events;
using Gigya.Microdot.Interfaces.HttpService;
using Gigya.Microdot.Interfaces.Logging;
using Gigya.Microdot.SharedLogic;
using Gigya.Microdot.SharedLogic.Configurations;
using Gigya.Microdot.SharedLogic.Events;
using Gigya.Microdot.SharedLogic.Exceptions;
using Gigya.Microdot.SharedLogic.HttpService;
using Gigya.Microdot.SharedLogic.Measurement;
using Gigya.Microdot.SharedLogic.Security;
using Metrics;
Expand Down Expand Up @@ -87,6 +88,7 @@ public sealed class HttpServiceListener : IDisposable
private JsonExceptionSerializer ExceptionSerializer { get; }
private Func<LoadShedding> LoadSheddingConfig { get; }

private ServiceSchema ServiceSchema { get; }

private readonly Timer _serializationTime;
private readonly Timer _deserializationTime;
Expand All @@ -100,9 +102,13 @@ public sealed class HttpServiceListener : IDisposable
public HttpServiceListener(IActivator activator, IWorker worker, IServiceEndPointDefinition serviceEndPointDefinition,
ICertificateLocator certificateLocator, ILog log, IEventPublisher<ServiceCallEvent> eventPublisher,
IEnumerable<ICustomEndpoint> customEndpoints, IEnvironmentVariableProvider environmentVariableProvider,
IServerRequestPublisher serverRequestPublisher,
JsonExceptionSerializer exceptionSerializer, Func<LoadShedding> loadSheddingConfig)
JsonExceptionSerializer exceptionSerializer,
ServiceSchema serviceSchema,
Func<LoadShedding> loadSheddingConfig,
IServerRequestPublisher serverRequestPublisher)

{
ServiceSchema = serviceSchema;
_serverRequestPublisher = serverRequestPublisher;
ServiceEndPointDefinition = serviceEndPointDefinition;
Worker = worker;
Expand Down Expand Up @@ -356,12 +362,12 @@ private static IEnumerable<Exception> GetAllExceptions(Exception ex)

private void ValidateRequest(HttpListenerContext context)
{
var clientVersion = context.Request.Headers[GigyaHttpHeaders.Version];
var clientVersion = context.Request.Headers[GigyaHttpHeaders.ProtocolVersion];

if (clientVersion != null && clientVersion != HttpServiceRequest.Version)
if (clientVersion != null && clientVersion != HttpServiceRequest.ProtocolVersion)
{
_failureCounter.Increment("ProtocolVersionMismatch");
throw new RequestException($"Client protocol version {clientVersion} is not supported by the server protocol version {HttpServiceRequest.Version}.");
throw new RequestException($"Client protocol version {clientVersion} is not supported by the server protocol version {HttpServiceRequest.ProtocolVersion}.");
}

if (context.Request.HttpMethod != "POST")
Expand Down Expand Up @@ -416,7 +422,7 @@ private async Task CheckSecureConnection(HttpListenerContext context)

private async Task TryWriteResponse(HttpListenerContext context, string data, HttpStatusCode httpStatus = HttpStatusCode.OK, string contentType = "application/json")
{
context.Response.Headers.Add(GigyaHttpHeaders.Version, HttpServiceRequest.Version);
context.Response.Headers.Add(GigyaHttpHeaders.ProtocolVersion, HttpServiceRequest.ProtocolVersion);

var body = Encoding.UTF8.GetBytes(data ?? "");

Expand All @@ -427,6 +433,8 @@ private async Task TryWriteResponse(HttpListenerContext context, string data, Ht
context.Response.Headers.Add(GigyaHttpHeaders.Environment, EnvironmentVariableProvider.DeploymentEnvironment);
context.Response.Headers.Add(GigyaHttpHeaders.ServiceVersion, CurrentApplicationInfo.Version.ToString());
context.Response.Headers.Add(GigyaHttpHeaders.ServerHostname, CurrentApplicationInfo.HostName);
context.Response.Headers.Add(GigyaHttpHeaders.SchemaHash, ServiceSchema.Hash);

try
{
await context.Response.OutputStream.WriteAsync(body, 0, body.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
using System;
using System.Collections.Generic;
using Gigya.Common.Contracts.HttpService;
using Gigya.Microdot.Interfaces.HttpService;
using Gigya.Microdot.SharedLogic.HttpService;

namespace Gigya.Microdot.Hosting.HttpService
{
Expand Down
3 changes: 1 addition & 2 deletions Gigya.Microdot.Hosting/HttpService/ServerRequestPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
using System.Linq;
using Gigya.Microdot.Hosting.Events;
using Gigya.Microdot.Interfaces.Events;
using Gigya.Microdot.Interfaces.HttpService;
using Gigya.Microdot.SharedLogic.Events;
using Newtonsoft.Json;
using Gigya.Microdot.SharedLogic.HttpService;

namespace Gigya.Microdot.Hosting.HttpService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
using Gigya.Common.Contracts.Exceptions;
using Gigya.Common.Contracts.HttpService;
using Gigya.Microdot.Interfaces;
using Gigya.Microdot.Interfaces.HttpService;
using Gigya.Microdot.ServiceDiscovery.Config;
using Gigya.Microdot.SharedLogic;
using Gigya.Microdot.SharedLogic.Exceptions;
using Gigya.Microdot.SharedLogic.HttpService;

namespace Gigya.Microdot.Hosting.HttpService
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public ServiceEndPointDefinition(IServiceInterfaceMapper mapper,

ServiceNames = serviceInterfaces
.Where(i => i.GetCustomAttribute<HttpServiceAttribute>() != null)
.ToDictionary(x => x, x => x.GetCustomAttribute<HttpServiceAttribute>().Name ?? x.Name);
.ToDictionary(x => x, x => x.Name);

var interfacePorts = serviceInterfaces.Select(i =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
using System.Linq;
using System.Reflection;
using Gigya.Common.Contracts.Exceptions;
using Gigya.Microdot.Interfaces.HttpService;
using Gigya.Microdot.SharedLogic.HttpService;

namespace Gigya.Microdot.Hosting.HttpService
{
Expand Down
Loading