mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 10:46:30 +00:00
add gps matcher service
This commit is contained in:
@@ -15,5 +15,5 @@ public class InferenceClientConfig : ExternalClientConfig
|
||||
|
||||
public class GpsDeniedClientConfig : ExternalClientConfig
|
||||
{
|
||||
public int ZeroMqReceiverPort { get; set; }
|
||||
public int ZeroMqSubscriberPort { get; set; }
|
||||
}
|
||||
@@ -9,7 +9,6 @@ public enum RoleEnum
|
||||
Validator = 20, //annotator + dataset explorer. This role allows to receive annotations from the queue.
|
||||
CompanionPC = 30,
|
||||
Admin = 40, //
|
||||
ResourceUploader = 50, //Uploading dll and ai models
|
||||
ApiAdmin = 1000 //everything
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@ public class SecurityConstants
|
||||
|
||||
#region ExternalClientsConfig
|
||||
public const string EXTERNAL_INFERENCE_PATH = "azaion-inference.exe";
|
||||
public const string EXTERNAL_GPS_DENIED_PATH = "image-matcher.exe";
|
||||
public const string EXTERNAL_GPS_DENIED_FOLDER = "gps-denied";
|
||||
public static readonly string ExternalGpsDeniedPath = Path.Combine(EXTERNAL_GPS_DENIED_FOLDER, "image-matcher.exe");
|
||||
|
||||
public const string DEFAULT_ZMQ_INFERENCE_HOST = "127.0.0.1";
|
||||
public const int DEFAULT_ZMQ_INFERENCE_PORT = 5227;
|
||||
|
||||
@@ -10,14 +10,14 @@ public interface IAuthProvider
|
||||
User CurrentUser { get; }
|
||||
}
|
||||
|
||||
public class AuthProvider([FromKeyedServices(SecurityConstants.EXTERNAL_INFERENCE_PATH)] IExternalClient externalClient) : IAuthProvider
|
||||
public class AuthProvider(IInferenceClient inferenceClient) : IAuthProvider
|
||||
{
|
||||
public User CurrentUser { get; private set; } = null!;
|
||||
|
||||
public void Login(ApiCredentials credentials)
|
||||
{
|
||||
externalClient.Send(RemoteCommand.Create(CommandType.Login, credentials));
|
||||
var user = externalClient.Get<User>();
|
||||
inferenceClient.Send(RemoteCommand.Create(CommandType.Login, credentials));
|
||||
var user = inferenceClient.Get<User>();
|
||||
if (user == null)
|
||||
throw new Exception("Can't get user from Auth provider");
|
||||
|
||||
|
||||
+11
-24
@@ -9,27 +9,23 @@ using NetMQ.Sockets;
|
||||
|
||||
namespace Azaion.CommonSecurity.Services;
|
||||
|
||||
public interface IExternalClient
|
||||
public interface IInferenceClient
|
||||
{
|
||||
void Stop();
|
||||
|
||||
void Send(RemoteCommand create);
|
||||
T? Get<T>(int retries = 24, int tryTimeoutSeconds = 5, CancellationToken ct = default) where T : class;
|
||||
byte[]? GetBytes(int retries = 24, int tryTimeoutSeconds = 5, CancellationToken ct = default);
|
||||
void Stop();
|
||||
}
|
||||
|
||||
public abstract class BaseZeroMqExternalClient : IExternalClient
|
||||
public class InferenceClient : IInferenceClient
|
||||
{
|
||||
private readonly DealerSocket _dealer = new();
|
||||
private readonly Guid _clientId = Guid.NewGuid();
|
||||
private readonly InferenceClientConfig _inferenceClientConfig;
|
||||
|
||||
private readonly ExternalClientConfig _externalClientConfig;
|
||||
|
||||
protected abstract string ClientPath { get; }
|
||||
|
||||
protected BaseZeroMqExternalClient(ExternalClientConfig config)
|
||||
public InferenceClient(IOptions<InferenceClientConfig> config)
|
||||
{
|
||||
_externalClientConfig = config;
|
||||
_inferenceClientConfig = config.Value;
|
||||
Start();
|
||||
}
|
||||
|
||||
@@ -40,7 +36,7 @@ public abstract class BaseZeroMqExternalClient : IExternalClient
|
||||
using var process = new Process();
|
||||
process.StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = ClientPath,
|
||||
FileName = SecurityConstants.EXTERNAL_INFERENCE_PATH,
|
||||
//Arguments = $"-e {credentials.Email} -p {credentials.Password} -f {apiConfig.ResourcesFolder}",
|
||||
//RedirectStandardOutput = true,
|
||||
//RedirectStandardError = true,
|
||||
@@ -58,7 +54,7 @@ public abstract class BaseZeroMqExternalClient : IExternalClient
|
||||
}
|
||||
|
||||
_dealer.Options.Identity = Encoding.UTF8.GetBytes(_clientId.ToString("N"));
|
||||
_dealer.Connect($"tcp://{_externalClientConfig.ZeroMqHost}:{_externalClientConfig.ZeroMqPort}");
|
||||
_dealer.Connect($"tcp://{_inferenceClientConfig.ZeroMqHost}:{_inferenceClientConfig.ZeroMqPort}");
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
@@ -75,6 +71,9 @@ public abstract class BaseZeroMqExternalClient : IExternalClient
|
||||
_dealer.SendFrame(MessagePackSerializer.Serialize(command));
|
||||
}
|
||||
|
||||
public void SendString(string text) =>
|
||||
Send(new RemoteCommand(CommandType.Load, MessagePackSerializer.Serialize(text)));
|
||||
|
||||
public T? Get<T>(int retries = 24, int tryTimeoutSeconds = 5, CancellationToken ct = default) where T : class
|
||||
{
|
||||
var bytes = GetBytes(retries, tryTimeoutSeconds, ct);
|
||||
@@ -98,15 +97,3 @@ public abstract class BaseZeroMqExternalClient : IExternalClient
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class InferenceExternalClient(IOptions<InferenceClientConfig> inferenceClientConfig)
|
||||
: BaseZeroMqExternalClient(inferenceClientConfig.Value)
|
||||
{
|
||||
protected override string ClientPath => SecurityConstants.EXTERNAL_INFERENCE_PATH;
|
||||
}
|
||||
|
||||
public class GpsDeniedExternalClient(IOptions<GpsDeniedClientConfig> gpsDeniedClientConfig)
|
||||
: BaseZeroMqExternalClient(gpsDeniedClientConfig.Value)
|
||||
{
|
||||
protected override string ClientPath => SecurityConstants.EXTERNAL_GPS_DENIED_PATH;
|
||||
}
|
||||
@@ -8,12 +8,12 @@ public interface IResourceLoader
|
||||
MemoryStream LoadFile(string fileName, string? folder = null);
|
||||
}
|
||||
|
||||
public class ResourceLoader([FromKeyedServices(SecurityConstants.EXTERNAL_INFERENCE_PATH)] IExternalClient externalClient) : IResourceLoader
|
||||
public class ResourceLoader([FromKeyedServices(SecurityConstants.EXTERNAL_INFERENCE_PATH)] IInferenceClient inferenceClient) : IResourceLoader
|
||||
{
|
||||
public MemoryStream LoadFile(string fileName, string? folder = null)
|
||||
{
|
||||
externalClient.Send(RemoteCommand.Create(CommandType.Load, new LoadFileData(fileName, folder)));
|
||||
var bytes = externalClient.GetBytes();
|
||||
inferenceClient.Send(RemoteCommand.Create(CommandType.Load, new LoadFileData(fileName, folder)));
|
||||
var bytes = inferenceClient.GetBytes();
|
||||
if (bytes == null)
|
||||
throw new Exception($"Unable to receive {fileName}");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user