Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt latest protocol changes #258

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ public DeploymentManifest(
.withComponentType(convertComponentType(svc.getComponentType()))
.withHandlers(
svc.getHandlers().stream()
.map(
method ->
new Handler()
.withName(method.getName())
.withInputSchema(method.getInputSchema())
.withOutputSchema(method.getOutputSchema()))
.map(method -> new Handler().withName(method.getName()))
.collect(Collectors.toList())))
.collect(Collectors.toList()));
}
Expand Down
1 change: 0 additions & 1 deletion sdk-core/src/main/java/dev/restate/sdk/core/Entries.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package dev.restate.sdk.core;

import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageLite;
import dev.restate.generated.service.protocol.Protocol;
Expand Down
88 changes: 82 additions & 6 deletions sdk-core/src/main/service-protocol/deployment_manifest_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,95 @@
"type": "string",
"pattern": "^([a-zA-Z]|_[a-zA-Z0-9])[a-zA-Z0-9_]*$"
},
"inputSchema": {},
"outputSchema": {}
"handlerType": {
"title": "HandlerType",
"enum": ["EXCLUSIVE", "SHARED"],
"description": "If unspecified, defaults to EXCLUSIVE for Virtual Object. This should be unset for Services."
},
"input": {
"type": "object",
"title": "InputPayload",
"description": "Description of an input payload. This will be used by Restate to validate incoming requests.",
"properties": {
"required": {
"type": "boolean",
"description": "If true, a body MUST be sent with a content-type, even if the body length is zero."
},
"contentType": {
"type": "string",
"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."
},
"jsonSchema": {}
},
"additionalProperties": false,
"default": {
"contentType": "*/*",
"required": false
},
"examples": {
"empty input": {},
"non empty json input": {
"required": true,
"contentType": "application/json",
"jsonSchema": true
},
"either empty or non empty json input": {
"required": false,
"contentType": "application/json",
"jsonSchema": true
},
"bytes input": {
"required": true,
"contentType": "application/octet-stream"
}
}
},
"output": {
"type": "object",
"title": "OutputPayload",
"description": "Description of an output payload.",
"properties": {
"contentType": {
"type": "string",
"description": "Content type set on output. This will be used by Restate to set the output content type at the ingress."
},
"setContentTypeIfEmpty": {
"type": "boolean",
"description": "If true, the specified content-type is set even if the output is empty."
},
"jsonSchema": {}
},
"additionalProperties": false,
"default": {
"contentType": "application/json",
"setContentTypeIfEmpty": false
},
"examples": {
"empty output": {
"setContentTypeIfEmpty": false
},
"non-empty json output": {
"contentType": "application/json",
"setContentTypeIfEmpty": false,
"jsonSchema": true
},
"protobuf output": {
"contentType": "application/proto",
"setContentTypeIfEmpty": true
}
}
}
},
"required": [ "name" ],
"required": ["name"],
"additionalProperties": false
}
}
},
"required": [ "fullyQualifiedComponentName","componentType", "handlers" ],
"required": ["fullyQualifiedComponentName", "componentType", "handlers"],
"additionalProperties": false
}
}
},
"required": [ "minProtocolVersion", "maxProtocolVersion", "components" ],
"required": ["minProtocolVersion", "maxProtocolVersion", "components"],
"additionalProperties": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ syntax = "proto3";

package dev.restate.service.protocol;

import "google/protobuf/empty.proto";

option java_package = "dev.restate.generated.service.protocol";
option go_package = "restate.dev/sdk-go/pb/service/protocol";

Expand Down Expand Up @@ -49,7 +47,7 @@ message CompletionMessage {
uint32 entry_index = 1;

oneof result {
google.protobuf.Empty empty = 13;
Empty empty = 13;
bytes value = 14;
Failure failure = 15;
};
Expand All @@ -68,12 +66,10 @@ message SuspensionMessage {

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

oneof result {
google.protobuf.Empty empty = 13;
Empty empty = 13;
bytes value = 14;
Failure failure = 15;
};
Expand Down Expand Up @@ -184,7 +180,7 @@ message SleepEntryMessage {
uint64 wake_up_time = 1;

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

message Empty {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static org.assertj.core.api.InstanceOfAssertFactories.list;
import static org.assertj.core.api.InstanceOfAssertFactories.type;

import com.google.protobuf.Empty;
import dev.restate.generated.sdk.java.Java;
import dev.restate.generated.service.protocol.Protocol;
import java.util.function.Supplier;
Expand Down Expand Up @@ -370,7 +369,7 @@ public Stream<TestDefinition> definitions() {
ProtoUtils.inputMessage(),
Protocol.CompletionMessage.newBuilder()
.setEntryIndex(2)
.setEmpty(Empty.getDefaultInstance()))
.setEmpty(Protocol.Empty.getDefaultInstance()))
.onlyUnbuffered()
.assertingOutput(
messages -> {
Expand Down
3 changes: 1 addition & 2 deletions sdk-core/src/test/java/dev/restate/sdk/core/ProtoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package dev.restate.sdk.core;

import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
import com.google.protobuf.MessageLite;
import com.google.protobuf.MessageLiteOrBuilder;
import dev.restate.generated.sdk.java.Java;
Expand Down Expand Up @@ -160,7 +159,7 @@ public static Protocol.GetStateEntryMessage.Builder getStateMessage(String key,
public static Protocol.GetStateEntryMessage getStateEmptyMessage(String key) {
return Protocol.GetStateEntryMessage.newBuilder()
.setKey(ByteString.copyFromUtf8(key))
.setEmpty(Empty.getDefaultInstance())
.setEmpty(Protocol.Empty.getDefaultInstance())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import static org.assertj.core.api.InstanceOfAssertFactories.LONG;
import static org.assertj.core.api.InstanceOfAssertFactories.type;

import com.google.protobuf.Empty;
import com.google.protobuf.MessageLiteOrBuilder;
import dev.restate.generated.service.protocol.Protocol;
import dev.restate.sdk.common.TerminalException;
Expand Down Expand Up @@ -55,7 +54,7 @@ public Stream<TestDefinitions.TestDefinition> definitions() {
inputMessage("Till"),
Protocol.SleepEntryMessage.newBuilder()
.setWakeUpTime(Instant.now().toEpochMilli())
.setEmpty(Empty.getDefaultInstance())
.setEmpty(Protocol.Empty.getDefaultInstance())
.build())
.expectingOutput(outputMessage("Hello"), END_MESSAGE)
.named("Sleep 1000 ms sleep completed"),
Expand All @@ -78,7 +77,7 @@ public Stream<TestDefinitions.TestDefinition> definitions() {
(i % 3 == 0)
? Protocol.SleepEntryMessage.newBuilder()
.setWakeUpTime(Instant.now().toEpochMilli())
.setEmpty(Empty.getDefaultInstance())
.setEmpty(Protocol.Empty.getDefaultInstance())
.build()
: Protocol.SleepEntryMessage.newBuilder()
.setWakeUpTime(Instant.now().toEpochMilli())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import static dev.restate.sdk.core.ProtoUtils.*;
import static org.assertj.core.api.Assertions.assertThat;

import com.google.protobuf.Empty;
import dev.restate.generated.service.protocol.Protocol;
import dev.restate.sdk.common.TerminalException;
import dev.restate.sdk.core.TestDefinitions.TestInvocationBuilder;
Expand All @@ -37,7 +36,7 @@ public Stream<TestDefinitions.TestDefinition> definitions() {
.withInput(
startMessage(2),
inputMessage("Till"),
getStateMessage("STATE").setEmpty(Empty.getDefaultInstance()))
getStateMessage("STATE").setEmpty(Protocol.Empty.getDefaultInstance()))
.expectingOutput(outputMessage("Hello Unknown"), END_MESSAGE)
.named("With GetStateEntry already completed empty"),
this.getState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package dev.restate.sdk.http.vertx

import com.fasterxml.jackson.databind.ObjectMapper
import com.google.protobuf.ByteString
import com.google.protobuf.Empty
import com.google.protobuf.MessageLite
import dev.restate.generated.service.protocol.Protocol.*
import dev.restate.sdk.common.CoreSerdes
Expand Down
Loading