Skip to content

Commit 07ffef9

Browse files
committed
Introduce CONSTANT class for port management; update NodeStarter and ClusterStarter to use dynamic ports; enhance CommandLogics with updated API endpoints for bone and cluster operations
1 parent 817ffe0 commit 07ffef9

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

src/main/java/io/nodelink/server/app/cluster/ClusterStarter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import io.javalin.Javalin;
44
import io.javalin.plugin.bundled.CorsPluginConfig;
55
import io.nodelink.server.NodeLink;
6+
import io.nodelink.server.app.infra.CONSTANT;
67
import io.nodelink.server.app.infra.RouteHandler;
8+
import io.nodelink.server.app.infra.handler.SyncH;
79
import org.slf4j.LoggerFactory;
810
import ch.qos.logback.classic.Level;
911
import ch.qos.logback.classic.LoggerContext;
@@ -31,11 +33,16 @@ public void startServer() {
3133
config.bundledPlugins.enableCors(cors -> {
3234
cors.addRule(CorsPluginConfig.CorsRule::anyHost);
3335
});
34-
}).start(8080);
36+
}).start(CONSTANT.PORT_CLUSTER);
3537

3638
RouteHandler.registerAllRoutes(app, "io.nodelink.server.app.cluster.api.routes");
3739

3840
NodeLink.getInstance().getLogger().SUCCESS("Cluster API Server started");
41+
42+
SyncH syncHandler = new SyncH();
43+
44+
app.get("/api/v1/sync", syncHandler::handle);
45+
app.post("/api/v1/sync", syncHandler::handle);
3946
})
4047
.subscribeOn(Schedulers.boundedElastic())
4148
.subscribe();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.nodelink.server.app.infra;
2+
3+
public class CONSTANT {
4+
public static int PORT_CLUSTER = 3002;
5+
public static int PORT_BONE = 3001;
6+
}

src/main/java/io/nodelink/server/app/node/NodeStarter.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.javalin.Javalin;
44
import io.javalin.plugin.bundled.CorsPluginConfig;
55
import io.nodelink.server.NodeLink;
6+
import io.nodelink.server.app.infra.CONSTANT;
67
import io.nodelink.server.app.infra.RouteHandler;
78
import io.nodelink.server.app.infra.handler.SyncH;
89
import org.slf4j.LoggerFactory;
@@ -32,16 +33,16 @@ public void startServer() {
3233
config.bundledPlugins.enableCors(cors -> {
3334
cors.addRule(CorsPluginConfig.CorsRule::anyHost);
3435
});
35-
36-
SyncH syncHandler = new SyncH();
37-
38-
app.get("/api/v1/sync", syncHandler::handle);
39-
app.post("/api/v1/sync", syncHandler::handle);
40-
}).start(8080);
36+
}).start(CONSTANT.PORT_BONE);
4137

4238
RouteHandler.registerAllRoutes(app, "io.nodelink.server.app.node.api.routes");
4339

4440
NodeLink.getInstance().getLogger().SUCCESS("Node API Server started");
41+
42+
SyncH syncHandler = new SyncH();
43+
44+
app.get("/api/v1/sync", syncHandler::handle);
45+
app.post("/api/v1/sync", syncHandler::handle);
4546
})
4647
.subscribeOn(Schedulers.boundedElastic())
4748
.subscribe();

src/main/java/io/nodelink/server/command/CommandLogics.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.nodelink.server.NodeLink;
55
import io.nodelink.server.app.data.BONE_LOCATION;
66
import io.nodelink.server.app.data.CLUSTER_LOCATION;
7+
import io.nodelink.server.app.infra.CONSTANT;
78
import io.nodelink.server.app.infra.DatabaseService;
89
import io.nodelink.server.app.infra.SyncEngine;
910
import io.nodelink.server.enums.CommandsEnum;
@@ -90,15 +91,15 @@ public CommandLogics(CommandDispatcher dispatcher, LineReader reader, Terminal t
9091
terminal.writer().println("Emplacement du bone défini sur : " + boneLocation.name());
9192

9293
HttpRequest idRequest = HttpRequest.newBuilder()
93-
.uri(URI.create("http://localhost:8080/bone/api/v1/getId"))
94+
.uri(URI.create("http://localhost:" + CONSTANT.PORT_BONE + "/bone/api/v1/getId"))
9495
.GET()
9596
.build();
9697

9798
HttpResponse<String> idResponse = client.send(idRequest, HttpResponse.BodyHandlers.ofString());
9899
int generatedId = mapper.readTree(idResponse.body()).get("id").asInt();
99100

100101
String location = boneLocation.name();
101-
String finalUrl = String.format("http://%d." + boneLocation.getLocation() + ".nodelinkapp.xyz:8080", generatedId);
102+
String finalUrl = String.format("http://%d." + boneLocation.getLocation() + ".nodelinkapp.xyz", generatedId);
102103

103104
String registrationJson = String.format(
104105
"{\"id\": \"%d\", \"location\": \"%s\", \"url\": \"%s\"}",
@@ -108,7 +109,7 @@ public CommandLogics(CommandDispatcher dispatcher, LineReader reader, Terminal t
108109
);
109110

110111
HttpRequest registerReq = HttpRequest.newBuilder()
111-
.uri(URI.create("http://localhost:8080/bone/api/v1/addBone"))
112+
.uri(URI.create("http://localhost:" + CONSTANT.PORT_BONE + "/bone/api/v1/addBone"))
112113
.header("Content-Type", "application/json")
113114
.POST(HttpRequest.BodyPublishers.ofString(registrationJson))
114115
.build();
@@ -159,7 +160,7 @@ public CommandLogics(CommandDispatcher dispatcher, LineReader reader, Terminal t
159160
// --- PHASE 1 : Récupération de l'ID (SYNCHRONE) ---
160161
// Vérifie bien si l'URL est /bone/ ou /cluster/ dans ton RouteHandler
161162
HttpRequest idRequest = HttpRequest.newBuilder()
162-
.uri(URI.create("http://localhost:8080/cluster/api/v1/getId"))
163+
.uri(URI.create("http://localhost:" + CONSTANT.PORT_CLUSTER + "/cluster/api/v1/getId"))
163164
.GET()
164165
.build();
165166

@@ -184,7 +185,7 @@ public CommandLogics(CommandDispatcher dispatcher, LineReader reader, Terminal t
184185
);
185186

186187
HttpRequest registerReq = HttpRequest.newBuilder()
187-
.uri(URI.create("http://localhost:8080/cluster/api/v1/addCluster"))
188+
.uri(URI.create("http://localhost:" + CONSTANT.PORT_CLUSTER + "/cluster/api/v1/addCluster"))
188189
.header("Content-Type", "application/json")
189190
.POST(HttpRequest.BodyPublishers.ofString(registrationJson))
190191
.build();

0 commit comments

Comments
 (0)