Skip to content

Commit ac34a31

Browse files
authored
fix: retrieve numaflow-java SDK version instead of java SDK version (#40)
Update the getSDKVersion() implementation to read current numaflow-java version from the maven pom.xml file. Signed-off-by: Keran Yang <[email protected]>
1 parent dbd9b4c commit ac34a31

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

examples/src/main/java/io/numaproj/numaflow/examples/function/map/evenodd/EvenOddFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public MessageList processMessage(String[] keys, Datum data) {
3030
return MessageList.newBuilder().addMessage(Message.toDrop()).build();
3131
}
3232

33-
String[] outputKeys = value % 2 == 0 ? new String[]{"even"} : new String[]{"odd"};
33+
String[] outputKeys = value % 2 == 0 ? new String[]{"even"}:new String[]{"odd"};
3434

3535
// tags will be used for conditional forwarding
36-
String[] tags = value % 2 == 0 ? new String[]{"even-tag"} : new String[]{"odd-tag"};
36+
String[] tags = value % 2 == 0 ? new String[]{"even-tag"}:new String[]{"odd-tag"};
3737

3838
return MessageList
3939
.newBuilder()

examples/src/main/java/io/numaproj/numaflow/examples/sink/simple/SimpleSink.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import io.numaproj.numaflow.sink.SinkServer;
99
import lombok.extern.slf4j.Slf4j;
1010

11-
1211
/**
1312
* This is a simple User Defined Sink example which logs the input message
1413
*/

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,11 @@
249249
</plugin>
250250
</plugins>
251251
</pluginManagement>
252+
<resources>
253+
<resource>
254+
<directory>src/main/java/io/numaproj/numaflow/info</directory>
255+
<filtering>true</filtering>
256+
</resource>
257+
</resources>
252258
</build>
253259
</project>

src/main/java/io/numaproj/numaflow/info/ServerInfoAccessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
public interface ServerInfoAccessor {
44
/**
5-
* Get runtime Java SDK version.
5+
* Get current runtime numaflow-java SDK version.
66
*/
77
String getSDKVersion();
88

src/main/java/io/numaproj/numaflow/info/ServerInfoAccessorImpl.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,31 @@
55

66
import java.io.File;
77
import java.io.FileWriter;
8+
import java.io.IOException;
9+
import java.io.InputStream;
810
import java.nio.file.Files;
911
import java.nio.file.Path;
12+
import java.util.Properties;
1013

1114
@AllArgsConstructor
1215
public class ServerInfoAccessorImpl implements ServerInfoAccessor {
1316
private ObjectMapper objectMapper;
1417

1518
@Override
1619
public String getSDKVersion() {
17-
// This only works for Java 9 and above.
18-
// Since we already use 11+ for numaflow SDK, it's safe to apply this approach.
19-
return String.valueOf(Runtime.version().version().get(0));
20+
String version = "";
21+
try (InputStream in = getClass()
22+
.getClassLoader()
23+
.getResourceAsStream("version.properties")) {
24+
if (in != null) {
25+
Properties properties = new Properties();
26+
properties.load(in);
27+
version = properties.getProperty("sdk.version");
28+
}
29+
} catch (IOException e) {
30+
return version;
31+
}
32+
return version;
2033
}
2134

2235
@Override
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sdk.version=${project.version}

src/test/java/io/numaproj/numaflow/info/ServerInfoAccessorImplTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,25 @@
88
import java.util.HashMap;
99

1010
import static org.junit.Assert.assertEquals;
11-
import static org.junit.Assert.assertNotEquals;
11+
import static org.junit.Assert.assertTrue;
1212
import static org.junit.Assert.fail;
1313

1414
@RunWith(JUnit4.class)
1515
public class ServerInfoAccessorImplTest {
1616
private ServerInfoAccessor underTest = new ServerInfoAccessorImpl(new ObjectMapper());
1717

1818
@Test
19-
public void given_localEnvironment_when_getJavaSDKVersion_then_returnAValidVersion() {
19+
public void given_localEnvironment_when_getNumaflowJavaSDKVersion_then_returnAValidVersion() {
2020
String got = this.underTest.getSDKVersion();
21-
assertNotEquals("", got);
22-
try {
23-
Integer.parseInt(got);
24-
} catch (NumberFormatException e) {
25-
fail("Expected java SDK version to be a valid integer.");
26-
}
21+
assertTrue(got.matches("^\\d+\\.\\d+\\.\\d+$"));
2722
}
2823

2924
@Test
3025
public void given_writeServerInfo_when_read_then_returnExactSame() {
3126
ServerInfo testServerInfo = new ServerInfo(
3227
Protocol.TCP_PROTOCOL,
3328
Language.JAVA,
34-
"11",
29+
"0.4.3",
3530
new HashMap<>() {{
3631
put("key1", "value1");
3732
put("key2", "value2");

0 commit comments

Comments
 (0)