Skip to content

Commit 58e0743

Browse files
authored
chore: adding examples, release version (#11)
Signed-off-by: Yashash H L <[email protected]>
1 parent 7f2fa33 commit 58e0743

File tree

11 files changed

+91
-31
lines changed

11 files changed

+91
-31
lines changed

.github/workflows/maven-publish.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Maven Package
55

66
on:
77
release:
8-
types: [created]
8+
types: [ created ]
99

1010
jobs:
1111
build:
@@ -16,19 +16,19 @@ jobs:
1616
packages: write
1717

1818
steps:
19-
- uses: actions/checkout@v3
20-
- name: Set up JDK 11
21-
uses: actions/setup-java@v3
22-
with:
23-
java-version: '11'
24-
distribution: 'temurin'
25-
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
26-
settings-path: ${{ github.workspace }} # location for the settings.xml file
19+
- uses: actions/checkout@v3
20+
- name: Set up JDK 11
21+
uses: actions/setup-java@v3
22+
with:
23+
java-version: '11'
24+
distribution: 'temurin'
25+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
26+
settings-path: ${{ github.workspace }} # location for the settings.xml file
2727

28-
- name: Build with Maven
29-
run: mvn -B package --file pom.xml
28+
- name: Build with Maven
29+
run: mvn -B package --file pom.xml
3030

31-
- name: Publish to GitHub Packages Apache Maven
32-
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
33-
env:
34-
GITHUB_TOKEN: ${{ github.token }}
31+
- name: Publish to GitHub Packages Apache Maven
32+
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
33+
env:
34+
GITHUB_TOKEN: ${{ github.token }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.numaproj.numaflow.examples.function.evenodd;
2+
3+
import io.numaproj.numaflow.function.FunctionServer;
4+
import io.numaproj.numaflow.function.Message;
5+
import io.numaproj.numaflow.function.map.MapFunc;
6+
import io.numaproj.numaflow.function.v1.Udfunction;
7+
8+
import java.io.IOException;
9+
import java.util.logging.Logger;
10+
11+
public class Forward {
12+
private static final Logger logger = Logger.getLogger(Forward.class.getName());
13+
14+
private static Message[] process(String key, Udfunction.Datum data) {
15+
int value = Integer.parseInt(new String(data.getValue().toByteArray()));
16+
if (value % 2 == 0) {
17+
return new Message[]{Message.to("even", data.getValue().toByteArray())};
18+
}
19+
return new Message[]{Message.to("odd", data.getValue().toByteArray())};
20+
}
21+
22+
public static void main(String[] args) throws IOException {
23+
logger.info("Forward invoked");
24+
new FunctionServer().registerMapper(new MapFunc(Forward::process)).start();
25+
}
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package io.numaproj.numaflow.examples.function.flatmap;
2+
3+
import io.numaproj.numaflow.function.FunctionServer;
4+
import io.numaproj.numaflow.function.Message;
5+
import io.numaproj.numaflow.function.map.MapFunc;
6+
import io.numaproj.numaflow.function.v1.Udfunction;
7+
8+
import java.io.IOException;
9+
import java.util.logging.Logger;
10+
11+
public class FlatMap {
12+
private static final Logger logger = Logger.getLogger(FlatMap.class.getName());
13+
14+
private static Message[] process(String key, Udfunction.Datum data) {
15+
String msg = new String(data.getValue().toByteArray());
16+
String[] strs = msg.split(",");
17+
Message[] results = new Message[strs.length];
18+
19+
for (int i = 0; i < strs.length; i++) {
20+
results[i] = Message.toAll(strs[i].getBytes());
21+
}
22+
return results;
23+
}
24+
25+
public static void main(String[] args) throws IOException {
26+
logger.info("Flatmap invoked");
27+
new FunctionServer().registerMapper(new MapFunc(FlatMap::process)).start();
28+
}
29+
}

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

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

33
import io.numaproj.numaflow.sink.Response;
44
import io.numaproj.numaflow.sink.SinkDatumStream;
5-
import io.numaproj.numaflow.sink.SinkDatumStreamImpl;
65
import io.numaproj.numaflow.sink.SinkFunc;
76
import io.numaproj.numaflow.sink.SinkServer;
87
import io.numaproj.numaflow.sink.v1.Udsink;
@@ -20,7 +19,7 @@ private static List<Response> process(SinkDatumStream datumStream) {
2019

2120
while (true) {
2221
Udsink.Datum datum = datumStream.ReadMessage();
23-
// DONE indicates the end of the input
22+
// EOF indicates the end of the input
2423
if (datum == SinkDatumStream.EOF) {
2524
break;
2625
}

pom.xml

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

77
<groupId>io.numaproj.numaflow</groupId>
88
<artifactId>numaflow-java</artifactId>
9-
<version>0.3.0-SNAPSHOT</version>
9+
<version>0.3.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>numaflow-java</name>

settings.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
44
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
55
<activeProfiles>
66
<activeProfile>github</activeProfile>
@@ -13,8 +13,12 @@
1313
<repository>
1414
<id>central</id>
1515
<url>https://repo1.maven.org/maven2</url>
16-
<releases><enabled>true</enabled></releases>
17-
<snapshots><enabled>false</enabled></snapshots>
16+
<releases>
17+
<enabled>true</enabled>
18+
</releases>
19+
<snapshots>
20+
<enabled>false</enabled>
21+
</snapshots>
1822
</repository>
1923
<repository>
2024
<id>github</id>
@@ -32,4 +36,4 @@
3236
<password>${env.JAVA_SDK_MAVEN_PASSWORD}</password>
3337
</server>
3438
</servers>
35-
</settings>
39+
</settings>

src/main/java/io/numaproj/numaflow/function/reduce/ReduceDatumStream.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
* reduce handlers to read input messages.
88
*/
99
public interface ReduceDatumStream {
10+
// EOF indicates the end of input
11+
Udfunction.Datum EOF = Udfunction.Datum.newBuilder().setKey("EOF").build();
12+
1013
/* ReadMessage can be used to read message from the stream
1114
* returns null if there are no more messages to consume.*/
1215
Udfunction.Datum ReadMessage();
13-
// EOF indicates the end of input
14-
Udfunction.Datum EOF = Udfunction.Datum.newBuilder().setKey("EOF").build();
1516
}

src/main/java/io/numaproj/numaflow/function/reduce/ReduceDatumStreamImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public Udfunction.Datum ReadMessage() {
2323
try {
2424
readMessage = blockingQueue.take();
2525
} catch (InterruptedException e) {
26-
logger.severe("Error occurred while reading message from datum stream" + e.getMessage());
26+
logger.severe(
27+
"Error occurred while reading message from datum stream" + e.getMessage());
2728
Thread.interrupted();
2829
}
2930
return readMessage;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package io.numaproj.numaflow.sink;
22

3-
import io.numaproj.numaflow.function.v1.Udfunction;
43
import io.numaproj.numaflow.sink.v1.Udsink;
54

65
/**
76
* SinkDatumStream is an interface which will be passed to
87
* sink handlers to read input messages.
98
*/
109
public interface SinkDatumStream {
10+
// EOF indicates the end of input
11+
Udsink.Datum EOF = Udsink.Datum.newBuilder().setKey("EOF").build();
12+
1113
/* ReadMessage can be used to read message from the stream
1214
* returns null if there are no more messages to consume.*/
1315
Udsink.Datum ReadMessage();
14-
// EOF indicates the end of input
15-
Udsink.Datum EOF = Udsink.Datum.newBuilder().setKey("EOF").build();
1616
}

src/main/java/io/numaproj/numaflow/sink/SinkDatumStreamImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public Udsink.Datum ReadMessage() {
2323
try {
2424
readMessage = blockingQueue.take();
2525
} catch (InterruptedException e) {
26-
logger.severe("Error occurred while reading message from datum stream" + e.getMessage());
26+
logger.severe(
27+
"Error occurred while reading message from datum stream" + e.getMessage());
2728
Thread.interrupted();
2829
}
2930
return readMessage;

0 commit comments

Comments
 (0)