Skip to content

Commit 10f30a7

Browse files
Merge branch 'Develop'
2 parents 64dac66 + ed0ebd9 commit 10f30a7

File tree

5 files changed

+41
-33
lines changed

5 files changed

+41
-33
lines changed

App/ConnectedNodes.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
using Newtonsoft.Json;
2-
using Swashbuckle.AspNetCore.SwaggerGen;
3-
using System.Xml.Linq;
4-
using ServiceRegistry.Requests;
52
using Newtonsoft.Json.Linq;
63
//using ServiceRegistry.App;
74

@@ -14,7 +11,6 @@ public class ConnectedNodes
1411
static readonly string connectedRepositoriesPath = Path.Combine(Directory.GetCurrentDirectory(), "connectedRepositories.json");
1512
private static Dictionary<string, Boolean> onlineStatus = new();
1613
private static Dictionary<string, JToken> configurations = new();
17-
1814
public static ConnectedNodes Instance
1915
{
2016
get
@@ -31,7 +27,6 @@ private static List<string> GetRegisteredNodes(string pathToFile)
3127
{
3228
string fileAsString = File.ReadAllText(pathToFile);
3329
List<string> nodeUrls = JsonConvert.DeserializeObject<List<string>>(fileAsString);
34-
//Dictionary<string, Node>? nodes = JsonConvert.DeserializeObject<Dictionary<string, Node>>(fileAsString);
3530
nodeUrls ??= new List<string>();
3631
return nodeUrls;
3732
}
@@ -68,12 +63,13 @@ public async Task<IResult> AddNode(string bodyString, NodeType type)
6863

6964
string nodeUrl = bodyDict["Host"]; // TODO: Consider deserializing this body to avoid problems with capitalized letters
7065

71-
if (!nodes.Contains(nodeUrl)) // We only add nodes to the file if they don't exist. Overwriting config is fine.
66+
if (!nodes.Contains(nodeUrl)) // We only add nodes to the file if they don't exist.
7267
{
7368
nodes.Add(nodeUrl);
7469
UpdateNodeFile(nodes, type);
7570
}
76-
71+
72+
//Writing or overwriting config.
7773
string configString = await Requests.Requests.GetConfigFromNode(nodeUrl);
7874
bool configFetched = AddConfiguration(nodeUrl, configString);
7975
if(!configFetched) return Results.Ok($"Node {nodeUrl} added but unable to get config.");
@@ -93,7 +89,7 @@ public IResult RemoveNode(string bodyString, NodeType type)
9389
configurations.Remove(nodeUrl);
9490
onlineStatus.Remove(nodeUrl);
9591

96-
return Results.Ok($"Repository {nodeUrl} successfully removed");
92+
return Results.Ok($"Node {nodeUrl} successfully removed");
9793
}
9894

9995
public void UpdateOnlineStatus()

App/Node.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using Newtonsoft.Json;
2-
using Newtonsoft.Json.Converters;
3-
4-
namespace ServiceRegistry.ConnectedNodes
1+
namespace ServiceRegistry.ConnectedNodes
52
{
63
public enum NodeType
74
{

Endpoints/Endpoints.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
using System.Collections.Generic;
2-
using System.IO;
3-
using System.Linq;
4-
using System.Xml.Linq;
5-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
62
using ServiceRegistry.ConnectedNodes;
7-
using ServiceRegistry.Requests;
83

94
namespace ServiceRegistry.Endpoints
105
{
@@ -61,6 +56,7 @@ public Endpoints(WebApplication app)
6156
return "pong";
6257
});
6358

59+
// Recieves a list of URLs and responds with online status for each entry
6460
app.MapPost("/connections/filters", async (HttpRequest request) =>
6561
{
6662
var body = new StreamReader(request.Body);
@@ -75,6 +71,7 @@ public Endpoints(WebApplication app)
7571
return Results.Ok(requestedNodeUrls);
7672
});
7773

74+
// Recieves a list of URLs and responds with a list of configs for each entry
7875
app.MapPost("config/filters", async (HttpRequest request) =>
7976
{
8077
var body = new StreamReader(request.Body);

README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
# Service registry
22

3+
## Starting the service registry
4+
This section describes how to start the service registry
5+
6+
Open visual studio and click the run button at the top.
7+
8+
## How to add services
9+
This sections describes how to add services to the service registry
10+
11+
Send a post request to https://{host}:{port}/repository or https://{host}:{port}/miner with a json body consisting of a key-value pair as follows:
12+
13+
```
14+
{
15+
"Host": "http://my_new_host:1234"
16+
}
17+
```
18+
19+
## How to remove services
20+
21+
Functions exactly the same as adding hosts, except the request must be a delete request with a key-value pair as follows to https://{host}:{port}/repository or https://{host}:{port}/miner:
22+
23+
```
24+
{
25+
"Host": "http://my_new_host:1234"
26+
}
27+
```
28+
29+
330
## Docker
31+
This does not fulfill it's intended functionality when all services are running through docker on the same windows machine.
32+
433
This project supports docker runtime environment, for which you will need to download docker from here: https://www.docker.com/products/docker-desktop/.
534

635
For this project, be aware that express listens on a specfic port (can be found in /Endpoints), which must be the same port that is used in the docker file.
@@ -35,15 +64,15 @@ docker network create -d bridge data
3564
## Docker Compose
3665
It is recommended to use this approach to run the application. To run this project using docker-compose you need to follow the steps below:
3766

38-
Build the docker image:
67+
Build the docker image:
3968
```
4069
docker-compose build
4170
```
42-
Run the docker image:
71+
Run the docker image:
4372
```
4473
docker-compose up
4574
```
46-
Stop the docker image:
75+
Stop the docker image:
4776
```
4877
docker-compose down
4978
```

Requests/Requests.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
using System.Text;
2-
using System;
3-
using Newtonsoft.Json;
4-
using System.Collections.Specialized;
5-
using Newtonsoft.Json.Linq;
6-
//using ServiceRegistry.App;
7-
8-
namespace ServiceRegistry.Requests
1+
namespace ServiceRegistry.Requests
92
{
103
public class Requests
114
{
@@ -26,7 +19,6 @@ public static async Task<bool> GetPing(string path)
2619
{
2720
return false;
2821
}
29-
3022
}
3123

3224
public static async Task<string> GetConfigFromNode(string nodeUrl)
@@ -36,9 +28,6 @@ public static async Task<string> GetConfigFromNode(string nodeUrl)
3628
{
3729
Console.WriteLine("Requesting config from: " + requestPath);
3830

39-
//var message = new HttpRequestMessage(HttpMethod.Get, requestPath) { Version = new Version(2, 0) };
40-
//var response = await client.SendAsync(message);
41-
4231
HttpResponseMessage response = await client.GetAsync(requestPath);
4332
if (response.IsSuccessStatusCode)
4433
{

0 commit comments

Comments
 (0)