Skip to content

Commit 0dadbd6

Browse files
Adapt latest protocol changes (#258)
* Squashed 'sdk-core/src/main/service-protocol/' changes from 4378d559..29b28f98 29b28f98 Modify Input/Output schema in deployment_manifest_schema.json (#80) 26d91e69 Replace protocol Empty message with custom one, so we remove the dependency on protobuf built-in messages (#79) 61ae44b2 Update documentation on error codes (#77) 576a1b26 Add HandlerType. Fix #1092 (#76) 0624d092 Payload schema for input and output. This provides basic format awareness. (#74) git-subtree-dir: sdk-core/src/main/service-protocol git-subtree-split: 29b28f9867734bc01dd47c4666d9d56c90b626f5 * Changes due to the protocol update
1 parent 91e31aa commit 0dadbd6

File tree

9 files changed

+99
-38
lines changed

9 files changed

+99
-38
lines changed

sdk-core/src/main/java/dev/restate/sdk/core/DeploymentManifest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ public DeploymentManifest(
3939
.withComponentType(convertComponentType(svc.getComponentType()))
4040
.withHandlers(
4141
svc.getHandlers().stream()
42-
.map(
43-
method ->
44-
new Handler()
45-
.withName(method.getName())
46-
.withInputSchema(method.getInputSchema())
47-
.withOutputSchema(method.getOutputSchema()))
42+
.map(method -> new Handler().withName(method.getName()))
4843
.collect(Collectors.toList())))
4944
.collect(Collectors.toList()));
5045
}

sdk-core/src/main/java/dev/restate/sdk/core/Entries.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package dev.restate.sdk.core;
1010

1111
import com.google.protobuf.ByteString;
12-
import com.google.protobuf.Empty;
1312
import com.google.protobuf.InvalidProtocolBufferException;
1413
import com.google.protobuf.MessageLite;
1514
import dev.restate.generated.service.protocol.Protocol;

sdk-core/src/main/service-protocol/deployment_manifest_schema.json

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,95 @@
4141
"type": "string",
4242
"pattern": "^([a-zA-Z]|_[a-zA-Z0-9])[a-zA-Z0-9_]*$"
4343
},
44-
"inputSchema": {},
45-
"outputSchema": {}
44+
"handlerType": {
45+
"title": "HandlerType",
46+
"enum": ["EXCLUSIVE", "SHARED"],
47+
"description": "If unspecified, defaults to EXCLUSIVE for Virtual Object. This should be unset for Services."
48+
},
49+
"input": {
50+
"type": "object",
51+
"title": "InputPayload",
52+
"description": "Description of an input payload. This will be used by Restate to validate incoming requests.",
53+
"properties": {
54+
"required": {
55+
"type": "boolean",
56+
"description": "If true, a body MUST be sent with a content-type, even if the body length is zero."
57+
},
58+
"contentType": {
59+
"type": "string",
60+
"description": "Content type of the input. It can accept wildcards, in the same format as the 'Accept' header. When this field is unset, it implies emptiness, meaning no content-type/body is expected."
61+
},
62+
"jsonSchema": {}
63+
},
64+
"additionalProperties": false,
65+
"default": {
66+
"contentType": "*/*",
67+
"required": false
68+
},
69+
"examples": {
70+
"empty input": {},
71+
"non empty json input": {
72+
"required": true,
73+
"contentType": "application/json",
74+
"jsonSchema": true
75+
},
76+
"either empty or non empty json input": {
77+
"required": false,
78+
"contentType": "application/json",
79+
"jsonSchema": true
80+
},
81+
"bytes input": {
82+
"required": true,
83+
"contentType": "application/octet-stream"
84+
}
85+
}
86+
},
87+
"output": {
88+
"type": "object",
89+
"title": "OutputPayload",
90+
"description": "Description of an output payload.",
91+
"properties": {
92+
"contentType": {
93+
"type": "string",
94+
"description": "Content type set on output. This will be used by Restate to set the output content type at the ingress."
95+
},
96+
"setContentTypeIfEmpty": {
97+
"type": "boolean",
98+
"description": "If true, the specified content-type is set even if the output is empty."
99+
},
100+
"jsonSchema": {}
101+
},
102+
"additionalProperties": false,
103+
"default": {
104+
"contentType": "application/json",
105+
"setContentTypeIfEmpty": false
106+
},
107+
"examples": {
108+
"empty output": {
109+
"setContentTypeIfEmpty": false
110+
},
111+
"non-empty json output": {
112+
"contentType": "application/json",
113+
"setContentTypeIfEmpty": false,
114+
"jsonSchema": true
115+
},
116+
"protobuf output": {
117+
"contentType": "application/proto",
118+
"setContentTypeIfEmpty": true
119+
}
120+
}
121+
}
46122
},
47-
"required": [ "name" ],
123+
"required": ["name"],
48124
"additionalProperties": false
49125
}
50126
}
51127
},
52-
"required": [ "fullyQualifiedComponentName","componentType", "handlers" ],
128+
"required": ["fullyQualifiedComponentName", "componentType", "handlers"],
53129
"additionalProperties": false
54130
}
55131
}
56132
},
57-
"required": [ "minProtocolVersion", "maxProtocolVersion", "components" ],
133+
"required": ["minProtocolVersion", "maxProtocolVersion", "components"],
58134
"additionalProperties": false
59-
}
135+
}

sdk-core/src/main/service-protocol/dev/restate/service/protocol.proto

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ syntax = "proto3";
1111

1212
package dev.restate.service.protocol;
1313

14-
import "google/protobuf/empty.proto";
15-
1614
option java_package = "dev.restate.generated.service.protocol";
1715
option go_package = "restate.dev/sdk-go/pb/service/protocol";
1816

@@ -49,7 +47,7 @@ message CompletionMessage {
4947
uint32 entry_index = 1;
5048

5149
oneof result {
52-
google.protobuf.Empty empty = 13;
50+
Empty empty = 13;
5351
bytes value = 14;
5452
Failure failure = 15;
5553
};
@@ -68,12 +66,10 @@ message SuspensionMessage {
6866

6967
// Type: 0x0000 + 3
7068
message ErrorMessage {
71-
// The code can be:
72-
// * Any of the error codes defined by OutputStreamEntry.failure (see Failure message)
73-
// * JOURNAL_MISMATCH = 32, that is when the SDK cannot replay a journal due to the mismatch between the journal and the actual code.
74-
// * PROTOCOL_VIOLATION = 33, that is when the SDK receives an unexpected message or an expected message variant, given its state.
75-
//
76-
// If 16 < code < 32, or code > 33, the runtime will interpret it as code 2 (UNKNOWN).
69+
// The code can be any HTTP status code, as described https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml.
70+
// In addition, we define the following error codes that MAY be used by the SDK for better error reporting:
71+
// * JOURNAL_MISMATCH = 570, that is when the SDK cannot replay a journal due to the mismatch between the journal and the actual code.
72+
// * PROTOCOL_VIOLATION = 571, that is when the SDK receives an unexpected message or an expected message variant, given its state.
7773
uint32 code = 1;
7874
// Contains a concise error message, e.g. Throwable#getMessage() in Java.
7975
string message = 2;
@@ -132,7 +128,7 @@ message GetStateEntryMessage {
132128
bytes key = 1;
133129

134130
oneof result {
135-
google.protobuf.Empty empty = 13;
131+
Empty empty = 13;
136132
bytes value = 14;
137133
Failure failure = 15;
138134
};
@@ -184,7 +180,7 @@ message SleepEntryMessage {
184180
uint64 wake_up_time = 1;
185181

186182
oneof result {
187-
google.protobuf.Empty empty = 13;
183+
Empty empty = 13;
188184
Failure failure = 15;
189185
}
190186
}
@@ -259,10 +255,7 @@ message CompleteAwakeableEntryMessage {
259255
// This failure object carries user visible errors,
260256
// e.g. invocation failure return value or failure result of an InvokeEntryMessage.
261257
message Failure {
262-
// The code should be any of the gRPC error codes,
263-
// as defined here: https://github.com/grpc/grpc/blob/master/doc/statuscodes.md#status-codes-and-their-use-in-grpc
264-
//
265-
// If code > 16, the runtime will interpret it as code 2 (UNKNOWN).
258+
// The code can be any HTTP status code, as described https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml.
266259
uint32 code = 1;
267260
// Contains a concise error message, e.g. Throwable#getMessage() in Java.
268261
string message = 2;
@@ -272,3 +265,6 @@ message Header {
272265
string key = 1;
273266
string value = 2;
274267
}
268+
269+
message Empty {
270+
}

sdk-core/src/test/java/dev/restate/sdk/core/DeferredTestSuite.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import static org.assertj.core.api.InstanceOfAssertFactories.list;
1515
import static org.assertj.core.api.InstanceOfAssertFactories.type;
1616

17-
import com.google.protobuf.Empty;
1817
import dev.restate.generated.sdk.java.Java;
1918
import dev.restate.generated.service.protocol.Protocol;
2019
import java.util.function.Supplier;
@@ -370,7 +369,7 @@ public Stream<TestDefinition> definitions() {
370369
ProtoUtils.inputMessage(),
371370
Protocol.CompletionMessage.newBuilder()
372371
.setEntryIndex(2)
373-
.setEmpty(Empty.getDefaultInstance()))
372+
.setEmpty(Protocol.Empty.getDefaultInstance()))
374373
.onlyUnbuffered()
375374
.assertingOutput(
376375
messages -> {

sdk-core/src/test/java/dev/restate/sdk/core/ProtoUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package dev.restate.sdk.core;
1010

1111
import com.google.protobuf.ByteString;
12-
import com.google.protobuf.Empty;
1312
import com.google.protobuf.MessageLite;
1413
import com.google.protobuf.MessageLiteOrBuilder;
1514
import dev.restate.generated.sdk.java.Java;
@@ -160,7 +159,7 @@ public static Protocol.GetStateEntryMessage.Builder getStateMessage(String key,
160159
public static Protocol.GetStateEntryMessage getStateEmptyMessage(String key) {
161160
return Protocol.GetStateEntryMessage.newBuilder()
162161
.setKey(ByteString.copyFromUtf8(key))
163-
.setEmpty(Empty.getDefaultInstance())
162+
.setEmpty(Protocol.Empty.getDefaultInstance())
164163
.build();
165164
}
166165

sdk-core/src/test/java/dev/restate/sdk/core/SleepTestSuite.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import static org.assertj.core.api.InstanceOfAssertFactories.LONG;
1515
import static org.assertj.core.api.InstanceOfAssertFactories.type;
1616

17-
import com.google.protobuf.Empty;
1817
import com.google.protobuf.MessageLiteOrBuilder;
1918
import dev.restate.generated.service.protocol.Protocol;
2019
import dev.restate.sdk.common.TerminalException;
@@ -55,7 +54,7 @@ public Stream<TestDefinitions.TestDefinition> definitions() {
5554
inputMessage("Till"),
5655
Protocol.SleepEntryMessage.newBuilder()
5756
.setWakeUpTime(Instant.now().toEpochMilli())
58-
.setEmpty(Empty.getDefaultInstance())
57+
.setEmpty(Protocol.Empty.getDefaultInstance())
5958
.build())
6059
.expectingOutput(outputMessage("Hello"), END_MESSAGE)
6160
.named("Sleep 1000 ms sleep completed"),
@@ -78,7 +77,7 @@ public Stream<TestDefinitions.TestDefinition> definitions() {
7877
(i % 3 == 0)
7978
? Protocol.SleepEntryMessage.newBuilder()
8079
.setWakeUpTime(Instant.now().toEpochMilli())
81-
.setEmpty(Empty.getDefaultInstance())
80+
.setEmpty(Protocol.Empty.getDefaultInstance())
8281
.build()
8382
: Protocol.SleepEntryMessage.newBuilder()
8483
.setWakeUpTime(Instant.now().toEpochMilli())

sdk-core/src/test/java/dev/restate/sdk/core/StateTestSuite.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import static dev.restate.sdk.core.ProtoUtils.*;
1313
import static org.assertj.core.api.Assertions.assertThat;
1414

15-
import com.google.protobuf.Empty;
1615
import dev.restate.generated.service.protocol.Protocol;
1716
import dev.restate.sdk.common.TerminalException;
1817
import dev.restate.sdk.core.TestDefinitions.TestInvocationBuilder;
@@ -37,7 +36,7 @@ public Stream<TestDefinitions.TestDefinition> definitions() {
3736
.withInput(
3837
startMessage(2),
3938
inputMessage("Till"),
40-
getStateMessage("STATE").setEmpty(Empty.getDefaultInstance()))
39+
getStateMessage("STATE").setEmpty(Protocol.Empty.getDefaultInstance()))
4140
.expectingOutput(outputMessage("Hello Unknown"), END_MESSAGE)
4241
.named("With GetStateEntry already completed empty"),
4342
this.getState()

sdk-http-vertx/src/test/kotlin/dev/restate/sdk/http/vertx/RestateHttpEndpointTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ package dev.restate.sdk.http.vertx
1010

1111
import com.fasterxml.jackson.databind.ObjectMapper
1212
import com.google.protobuf.ByteString
13-
import com.google.protobuf.Empty
1413
import com.google.protobuf.MessageLite
1514
import dev.restate.generated.service.protocol.Protocol.*
1615
import dev.restate.sdk.common.CoreSerdes

0 commit comments

Comments
 (0)