From c206ff71fe7e28c9bec9772ce0bd72bd94221751 Mon Sep 17 00:00:00 2001 From: Ogoun Date: Fri, 5 Apr 2019 18:07:27 +0300 Subject: [PATCH] Fix service exchange --- .../Controllers/RoutesController.cs | 4 +- ZeroLevel.Discovery/DiscoveryService.cs | 9 +- ZeroLevel.Discovery/RouteTable.cs | 6 +- ...el.Discovery.csprojAssemblyReference.cache | Bin 168267 -> 168267 bytes .../Application/BaseWindowsExService.cs | 100 ++++++++++++++++++ .../Application/BaseWindowsService.cs | 8 +- .../{BusinessApplication.cs => Bootstrap.cs} | 13 +-- .../Services/Application/IZeroService.cs | 6 +- .../Network/Models/ServiceEndpointInfo.cs | 15 ++- .../Network/Models/ServiceEndpointsInfo.cs | 22 +++- ZeroLevel/ZeroLevel.csproj | 5 +- .../ZeroLevel.csproj.CoreCompileInputs.cache | 2 +- 12 files changed, 166 insertions(+), 24 deletions(-) create mode 100644 ZeroLevel/Services/Application/BaseWindowsExService.cs rename ZeroLevel/Services/Application/{BusinessApplication.cs => Bootstrap.cs} (92%) diff --git a/ZeroLevel.Discovery/Controllers/RoutesController.cs b/ZeroLevel.Discovery/Controllers/RoutesController.cs index 86d0f8c..779fa98 100644 --- a/ZeroLevel.Discovery/Controllers/RoutesController.cs +++ b/ZeroLevel.Discovery/Controllers/RoutesController.cs @@ -4,7 +4,7 @@ using System.Net.Http; using System.Web.Http; using System.Web.Http.Description; using ZeroLevel.Models; -using ZeroLevel.Network.Microservices; +using ZeroLevel.Network; namespace ZeroLevel.Discovery { @@ -37,7 +37,7 @@ namespace ZeroLevel.Discovery [HttpPost] [Route("api/v0/routes")] [ResponseType(typeof(InvokeResult))] - public HttpResponseMessage AddRoute(HttpRequestMessage request, MicroserviceInfo service) + public HttpResponseMessage AddRoute(HttpRequestMessage request, ExServiceInfo service) { try { diff --git a/ZeroLevel.Discovery/DiscoveryService.cs b/ZeroLevel.Discovery/DiscoveryService.cs index 846fe22..b36e4c9 100644 --- a/ZeroLevel.Discovery/DiscoveryService.cs +++ b/ZeroLevel.Discovery/DiscoveryService.cs @@ -1,10 +1,7 @@ -using System.Collections; -using System.Collections.Generic; +using System.Collections.Generic; using ZeroLevel.Models; using ZeroLevel.Network; -using ZeroLevel.Network.Microservices; using ZeroLevel.Services.Applications; -using ZeroLevel.Services.Network; namespace ZeroLevel.Discovery { @@ -18,6 +15,10 @@ namespace ZeroLevel.Discovery { } + public override void DisposeResources() + { + } + public override void PauseAction() { } diff --git a/ZeroLevel.Discovery/RouteTable.cs b/ZeroLevel.Discovery/RouteTable.cs index 3426f93..d1e00b9 100644 --- a/ZeroLevel.Discovery/RouteTable.cs +++ b/ZeroLevel.Discovery/RouteTable.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Threading; using ZeroLevel.Models; using ZeroLevel.Network; -using ZeroLevel.Network.Microservices; namespace ZeroLevel.Discovery { @@ -98,7 +97,8 @@ namespace ZeroLevel.Discovery { using (var client = ExchangeTransportFactory.GetClient(protocol, endpoint)) { - return client.Status == Services.Network.ZTransportStatus.Working; + client.ForceConnect(); + return client.Status == ZTransportStatus.Working; } } catch (Exception ex) @@ -190,7 +190,7 @@ namespace ZeroLevel.Discovery Endpoint = serviceInfo.Endpoint, Protocol = serviceInfo.Protocol }); - Log.SystemInfo($"The service '{serviceInfo.ServiceKey}' registered on protocol {serviceInfo.Protocol}, endpoint: {serviceInfo.Endpoint}"); + Log.Info($"The service '{serviceInfo.ServiceKey}' registered on protocol {serviceInfo.Protocol}, endpoint: {serviceInfo.Endpoint}"); } else { diff --git a/ZeroLevel.Discovery/obj/Debug/ZeroLevel.Discovery.csprojAssemblyReference.cache b/ZeroLevel.Discovery/obj/Debug/ZeroLevel.Discovery.csprojAssemblyReference.cache index 7e437ec59b7e20e91592e8593d40333d35ca1d2f..34790e8f6264c689ca693d088304db9873f5a209 100644 GIT binary patch delta 8651 zcmZXY33yaRw#QQ?-JN^0Hr*iv0t8S*z!3JZgt*PaiCKUE0c6Y4U?3!rge`l3=Y&m! z0k2v95I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F+v|Fbo^t%u4f7TNulH41D3uk<;nT(GsbV(M4{6` zk@z0m`7J%T{TDi{f4@w&bhG^&t;PuERw-iV3ikX!Y*4SZbTg_-OX6o6-RxQ6Sfe;D z6OOB@v`BOLEKN7JRcU>#U$Lg*{73QD_2zcajoDbG=^k8|trUVM$$buSl57+VTzu`l z{;tD3Fjb3VheQ&%zuFsdR3vdi=(vqqdaw~Eg??JR09Q==3(knodS1liT4#^HAmTq2 zorGJOUB4{!FD%`IYnP=5Tll5Fh1Y}wu21#^zM&Rwr(Nl$cmr-i_BVVd-f-K}&D+&9 zAkdq!A(&%yV$_0dW#*}cTD%tO5qgc#afq_(D}=sU=s3OD z^;%2Uo)e!8=McNTLFk)>j$?&guNV3YmTtx_(fV3nc9j1|Y=aW9*NQM3m-q+4*?=of z2zGd*fWIqVj_uyAAF^~tlN?_kJGWgwA#|GL(6JHQ_0vK>BXn%8cKy82KNdQ+NxObg z=$9(string[] args, Func preStartConfiguration = null, Func postStartConfiguration = null) where T : IZeroService, new() { + IZeroService service = null; var cmd = Configuration.ReadFromCommandLine(args); if (cmd.Contains("install", "setup")) { @@ -90,8 +91,7 @@ namespace ZeroLevel else { Configuration.Save(Configuration.ReadFromApplicationConfig()); - Log.CreateLoggingFromConfiguration(Configuration.Default); - IZeroService service = null; + Log.CreateLoggingFromConfiguration(Configuration.Default); if (preStartConfiguration != null) { try @@ -159,9 +159,10 @@ namespace ZeroLevel } } } - try { Sheduller.Dispose(); } catch { } - try { Log.Dispose(); } catch { } - try { Injector.Default.Dispose(); Injector.Dispose(); } catch { } + try { Sheduller.Dispose(); } catch (Exception ex) { Log.Error(ex, "Dispose default sheduller error"); } + try { Log.Dispose(); } catch (Exception ex) { Log.Error(ex, "Dispose log error"); } + try { Injector.Default.Dispose(); Injector.Dispose(); } catch (Exception ex) { Log.Error(ex, "Dispose DI containers error"); } + try { service?.DisposeResources(); } catch (Exception ex) { Log.Error(ex, "Dispose service error"); } } } } \ No newline at end of file diff --git a/ZeroLevel/Services/Application/IZeroService.cs b/ZeroLevel/Services/Application/IZeroService.cs index 33208c1..2b077e3 100644 --- a/ZeroLevel/Services/Application/IZeroService.cs +++ b/ZeroLevel/Services/Application/IZeroService.cs @@ -1,4 +1,6 @@ -namespace ZeroLevel.Services.Applications +using System; + +namespace ZeroLevel.Services.Applications { public interface IZeroService { @@ -13,5 +15,7 @@ void ResumeAction(); void InteractiveStart(string[] args); + + void DisposeResources(); } } \ No newline at end of file diff --git a/ZeroLevel/Services/Network/Models/ServiceEndpointInfo.cs b/ZeroLevel/Services/Network/Models/ServiceEndpointInfo.cs index 6983b56..7efb5e5 100644 --- a/ZeroLevel/Services/Network/Models/ServiceEndpointInfo.cs +++ b/ZeroLevel/Services/Network/Models/ServiceEndpointInfo.cs @@ -1,4 +1,5 @@ using System; +using ZeroLevel.Services.Serialization; namespace ZeroLevel.Network { @@ -6,7 +7,7 @@ namespace ZeroLevel.Network /// Endpoint /// public class ServiceEndpointInfo : - IEquatable + IEquatable, IBinarySerializable { public string Endpoint { get; set; } public string Protocol { get; set; } @@ -28,5 +29,17 @@ namespace ZeroLevel.Network { return Endpoint?.GetHashCode() ?? 0 ^ Protocol?.GetHashCode() ?? 0; } + + public void Serialize(IBinaryWriter writer) + { + writer.WriteString(this.Protocol); + writer.WriteString(this.Endpoint); + } + + public void Deserialize(IBinaryReader reader) + { + this.Protocol = reader.ReadString(); + this.Endpoint = reader.ReadString(); + } } } \ No newline at end of file diff --git a/ZeroLevel/Services/Network/Models/ServiceEndpointsInfo.cs b/ZeroLevel/Services/Network/Models/ServiceEndpointsInfo.cs index 191e57a..8ca4ea6 100644 --- a/ZeroLevel/Services/Network/Models/ServiceEndpointsInfo.cs +++ b/ZeroLevel/Services/Network/Models/ServiceEndpointsInfo.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using ZeroLevel.Services.Serialization; namespace ZeroLevel.Network { @@ -7,13 +8,12 @@ namespace ZeroLevel.Network /// Information about service connection points /// public class ServiceEndpointsInfo : - IEquatable + IEquatable, IBinarySerializable { public string ServiceKey { get; set; } public string Version { get; set; } public string ServiceGroup { get; set; } public string ServiceType { get; set; } - public List Endpoints { get; set; } public bool Equals(ServiceEndpointsInfo other) @@ -36,5 +36,23 @@ namespace ZeroLevel.Network { return ServiceKey?.GetHashCode() ?? 0 ^ Version?.GetHashCode() ?? 0 ^ ServiceGroup?.GetHashCode() ?? 0 ^ ServiceType?.GetHashCode() ?? 0; } + + public void Serialize(IBinaryWriter writer) + { + writer.WriteString(this.ServiceKey); + writer.WriteString(this.Version); + writer.WriteString(this.ServiceGroup); + writer.WriteString(this.ServiceType); + writer.WriteCollection(this.Endpoints); + } + + public void Deserialize(IBinaryReader reader) + { + this.ServiceKey = reader.ReadString(); + this.Version = reader.ReadString(); + this.ServiceGroup = reader.ReadString(); + this.ServiceType = reader.ReadString(); + this.Endpoints = reader.ReadCollection(); + } } } \ No newline at end of file diff --git a/ZeroLevel/ZeroLevel.csproj b/ZeroLevel/ZeroLevel.csproj index 9464011..85aee82 100644 --- a/ZeroLevel/ZeroLevel.csproj +++ b/ZeroLevel/ZeroLevel.csproj @@ -57,11 +57,14 @@ + + Component + Component - + diff --git a/ZeroLevel/obj/Debug/ZeroLevel.csproj.CoreCompileInputs.cache b/ZeroLevel/obj/Debug/ZeroLevel.csproj.CoreCompileInputs.cache index 7af6f21..91b6aaf 100644 --- a/ZeroLevel/obj/Debug/ZeroLevel.csproj.CoreCompileInputs.cache +++ b/ZeroLevel/obj/Debug/ZeroLevel.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -ee06969e2b1f87052733e2a64f8bf6d27363d162 +f165fe7fc045ddedd4b08504422209fd88e56cc6