Skip to content

Commit c67ca60

Browse files
Add NexusInfo (#2658)
Add NexusInfo
1 parent bf0b196 commit c67ca60

File tree

11 files changed

+131
-4
lines changed

11 files changed

+131
-4
lines changed

docker/native-image-musl/dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ WORKDIR /opt
1212
RUN ./install-musl.sh
1313
ENV MUSL_HOME=/opt/musl-toolchain
1414
ENV PATH="$MUSL_HOME/bin:$PATH"
15+
# Verify installation
16+
RUN x86_64-linux-musl-gcc --version
1517
# Avoid errors like: "fatal: detected dubious ownership in repository"
1618
RUN git config --global --add safe.directory '*'

docker/native-image-musl/install-musl.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ curl -O https://zlib.net/fossils/zlib-1.2.13.tar.gz
77

88
# Build musl from source
99
tar -xzvf musl-1.2.5.tar.gz
10-
cd musl-1.2.5
10+
cd musl-1.2.5 || exit
1111
./configure --prefix=$MUSL_HOME --static
1212
# The next operation may require privileged access to system resources, so use sudo
1313
make && make install
@@ -22,7 +22,7 @@ x86_64-linux-musl-gcc --version
2222

2323
# Build zlib with musl from source and install into the MUSL_HOME directory
2424
tar -xzvf zlib-1.2.13.tar.gz
25-
cd zlib-1.2.13
25+
cd zlib-1.2.13 || exit
2626
CC=musl-gcc ./configure --prefix=$MUSL_HOME --static
2727
make && make install
2828
cd ..

temporal-sdk/src/main/java/io/temporal/common/interceptors/NexusOperationOutboundCallsInterceptor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.uber.m3.tally.Scope;
44
import io.temporal.client.WorkflowClient;
55
import io.temporal.common.Experimental;
6+
import io.temporal.nexus.NexusOperationInfo;
67

78
/**
89
* Can be used to intercept calls from a Nexus operation into the Temporal APIs.
@@ -20,6 +21,9 @@
2021
*/
2122
@Experimental
2223
public interface NexusOperationOutboundCallsInterceptor {
24+
/** Intercepts call to get the Nexus info in a Nexus operation. */
25+
NexusOperationInfo getInfo();
26+
2327
/** Intercepts call to get the metric scope in a Nexus operation. */
2428
Scope getMetricsScope();
2529

temporal-sdk/src/main/java/io/temporal/common/interceptors/NexusOperationOutboundCallsInterceptorBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.uber.m3.tally.Scope;
44
import io.temporal.client.WorkflowClient;
55
import io.temporal.common.Experimental;
6+
import io.temporal.nexus.NexusOperationInfo;
67

78
/** Convenience base class for {@link NexusOperationOutboundCallsInterceptor} implementations. */
89
@Experimental
@@ -14,6 +15,11 @@ public NexusOperationOutboundCallsInterceptorBase(NexusOperationOutboundCallsInt
1415
this.next = next;
1516
}
1617

18+
@Override
19+
public NexusOperationInfo getInfo() {
20+
return next.getInfo();
21+
}
22+
1723
@Override
1824
public Scope getMetricsScope() {
1925
return next.getMetricsScope();

temporal-sdk/src/main/java/io/temporal/internal/nexus/InternalNexusOperationContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.temporal.client.WorkflowClient;
66
import io.temporal.common.interceptors.NexusOperationOutboundCallsInterceptor;
77
import io.temporal.nexus.NexusOperationContext;
8+
import io.temporal.nexus.NexusOperationInfo;
89

910
public class InternalNexusOperationContext {
1011
private final String namespace;
@@ -58,6 +59,11 @@ public Link getStartWorkflowResponseLink() {
5859
}
5960

6061
private class NexusOperationContextImpl implements NexusOperationContext {
62+
@Override
63+
public NexusOperationInfo getInfo() {
64+
return outboundCalls.getInfo();
65+
}
66+
6167
@Override
6268
public Scope getMetricsScope() {
6369
return outboundCalls.getMetricsScope();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.temporal.internal.nexus;
2+
3+
import io.temporal.nexus.NexusOperationInfo;
4+
5+
class NexusInfoImpl implements NexusOperationInfo {
6+
private final String namespace;
7+
private final String taskQueue;
8+
9+
NexusInfoImpl(String namespace, String taskQueue) {
10+
this.namespace = namespace;
11+
this.taskQueue = taskQueue;
12+
}
13+
14+
@Override
15+
public String getNamespace() {
16+
return namespace;
17+
}
18+
19+
@Override
20+
public String getTaskQueue() {
21+
return taskQueue;
22+
}
23+
}

temporal-sdk/src/main/java/io/temporal/internal/nexus/RootNexusOperationOutboundCallsInterceptor.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@
33
import com.uber.m3.tally.Scope;
44
import io.temporal.client.WorkflowClient;
55
import io.temporal.common.interceptors.NexusOperationOutboundCallsInterceptor;
6+
import io.temporal.nexus.NexusOperationInfo;
67

78
public class RootNexusOperationOutboundCallsInterceptor
89
implements NexusOperationOutboundCallsInterceptor {
910
private final Scope scope;
1011
private final WorkflowClient client;
12+
private final NexusOperationInfo nexusInfo;
1113

12-
RootNexusOperationOutboundCallsInterceptor(Scope scope, WorkflowClient client) {
14+
RootNexusOperationOutboundCallsInterceptor(
15+
Scope scope, WorkflowClient client, NexusOperationInfo nexusInfo) {
1316
this.scope = scope;
1417
this.client = client;
18+
this.nexusInfo = nexusInfo;
19+
}
20+
21+
@Override
22+
public NexusOperationInfo getInfo() {
23+
return nexusInfo;
1524
}
1625

1726
@Override

temporal-sdk/src/main/java/io/temporal/internal/nexus/TemporalInterceptorMiddleware.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public OperationHandler<Object, Object> intercept(
2727
InternalNexusOperationContext temporalNexusContext = CurrentNexusOperationContext.get();
2828
inboundCallsInterceptor.init(
2929
new RootNexusOperationOutboundCallsInterceptor(
30-
temporalNexusContext.getMetricsScope(), temporalNexusContext.getWorkflowClient()));
30+
temporalNexusContext.getMetricsScope(),
31+
temporalNexusContext.getWorkflowClient(),
32+
new NexusInfoImpl(
33+
temporalNexusContext.getNamespace(), temporalNexusContext.getTaskQueue())));
3134
return new OperationInterceptorConverter(inboundCallsInterceptor);
3235
}
3336

temporal-sdk/src/main/java/io/temporal/nexus/NexusOperationContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
*/
1111
public interface NexusOperationContext {
1212

13+
/** Get Temporal information about the Nexus Operation. */
14+
NexusOperationInfo getInfo();
15+
1316
/**
1417
* Get scope for reporting business metrics in a nexus handler. This scope is tagged with the
1518
* service and operation.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.temporal.nexus;
2+
3+
/**
4+
* Temporal information about the Nexus Operation. Use {@link NexusOperationContext#getInfo()} from
5+
* a Nexus Operation implementation to access.
6+
*/
7+
public interface NexusOperationInfo {
8+
/**
9+
* @return Namespace of the worker that is executing the Nexus Operation
10+
*/
11+
String getNamespace();
12+
13+
/**
14+
* @return Nexus Task Queue of the worker that is executing the Nexus Operation
15+
*/
16+
String getTaskQueue();
17+
}

0 commit comments

Comments
 (0)