Skip to content

Commit

Permalink
chore: write server info for sideinput sdk (#93)
Browse files Browse the repository at this point in the history
Signed-off-by: a3hadi <[email protected]>
  • Loading branch information
ayildirim21 committed Jan 29, 2024
1 parent cb91f37 commit d7ce392
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/io/numaproj/numaflow/sideinput/GRPCConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.numaproj.numaflow.sideinput;

import io.numaproj.numaflow.info.ServerInfoAccessor;
import lombok.Builder;
import lombok.Getter;

Expand All @@ -11,12 +12,14 @@
public class GRPCConfig {
private String socketPath;
private int maxMessageSize;
private String infoFilePath;

/**
* Static method to create default GRPCConfig.
*/
static GRPCConfig defaultGrpcConfig() {
return GRPCConfig.newBuilder()
.infoFilePath(ServerInfoAccessor.DEFAULT_SERVER_INFO_FILE_PATH)
.maxMessageSize(Constants.DEFAULT_MESSAGE_SIZE)
.socketPath(Constants.DEFAULT_SOCKET_PATH).build();
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/numaproj/numaflow/sideinput/Server.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package io.numaproj.numaflow.sideinput;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import io.grpc.ServerBuilder;
import io.numaproj.numaflow.shared.GrpcServerUtils;
import io.numaproj.numaflow.info.ServerInfoAccessor;
import io.numaproj.numaflow.info.ServerInfoAccessorImpl;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
Expand All @@ -15,6 +18,7 @@ public class Server {

private final GRPCConfig grpcConfig;
private final Service service;
private final ServerInfoAccessor serverInfoAccessor = new ServerInfoAccessorImpl(new ObjectMapper());
private io.grpc.Server server;

/**
Expand Down Expand Up @@ -43,6 +47,10 @@ public Server(SideInputRetriever sideInputRetriever, GRPCConfig grpcConfig) {
* @throws Exception if server fails to start
*/
public void start() throws Exception {
GrpcServerUtils.writeServerInfo(
serverInfoAccessor,
grpcConfig.getSocketPath(),
grpcConfig.getInfoFilePath());

if (this.server == null) {
// create server builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.numaproj.numaflow.sideinput;

import io.numaproj.numaflow.info.ServerInfoAccessor;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -9,6 +10,9 @@ public class GRPCConfigTest {
public void testDefaultGrpcConfig() {
GRPCConfig grpcConfig = GRPCConfig.defaultGrpcConfig();
Assert.assertNotNull(grpcConfig);
Assert.assertEquals(
ServerInfoAccessor.DEFAULT_SERVER_INFO_FILE_PATH,
grpcConfig.getInfoFilePath());
Assert.assertEquals(Constants.DEFAULT_MESSAGE_SIZE, grpcConfig.getMaxMessageSize());
Assert.assertEquals(Constants.DEFAULT_SOCKET_PATH, grpcConfig.getSocketPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void setUp() throws Exception {
GRPCConfig grpcServerConfig = GRPCConfig.newBuilder()
.maxMessageSize(Constants.DEFAULT_MESSAGE_SIZE)
.socketPath(Constants.DEFAULT_SOCKET_PATH)
.infoFilePath("/tmp/numaflow-test-server-info)")
.build();

server = new Server(
Expand Down

0 comments on commit d7ce392

Please sign in to comment.