diff --git a/README-zh.md b/README-zh.md index 7665946..ab46592 100644 --- a/README-zh.md +++ b/README-zh.md @@ -1,3 +1,10 @@ + + sdk-runtime/sdk-reactor + ↑ ↑ + sdk-domain -> sdk-grpc + ↑ ↑ + sdk-infrastructure spec-pb + ## 如何使用java sdk ### 1. import sdk 对于 Maven 项目,将以下配置添加进 `pom.xml` 文件: diff --git a/examples/pom.xml b/examples/pom.xml index 015e86b..fa724e0 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -57,4 +57,5 @@ + \ No newline at end of file diff --git a/examples/src/test/java/io/mosn/layotto/examples/file/File.java b/examples/src/test/java/io/mosn/layotto/examples/file/File.java index 43f2fc1..8ebe6bc 100644 --- a/examples/src/test/java/io/mosn/layotto/examples/file/File.java +++ b/examples/src/test/java/io/mosn/layotto/examples/file/File.java @@ -15,7 +15,7 @@ package io.mosn.layotto.examples.file; import io.mosn.layotto.v1.RuntimeClientBuilder; -import io.mosn.layotto.v1.config.RuntimeProperties; +import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import spec.sdk.runtime.v1.client.RuntimeClient; diff --git a/examples/src/test/java/io/mosn/layotto/examples/helloworld/Hello.java b/examples/src/test/java/io/mosn/layotto/examples/helloworld/Hello.java index da35ec3..937e293 100644 --- a/examples/src/test/java/io/mosn/layotto/examples/helloworld/Hello.java +++ b/examples/src/test/java/io/mosn/layotto/examples/helloworld/Hello.java @@ -15,7 +15,7 @@ package io.mosn.layotto.examples.helloworld; import io.mosn.layotto.v1.RuntimeClientBuilder; -import io.mosn.layotto.v1.config.RuntimeProperties; +import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties; import spec.sdk.runtime.v1.client.RuntimeClient; public class Hello { diff --git a/examples/src/test/java/io/mosn/layotto/examples/pubsub/publisher/Publisher.java b/examples/src/test/java/io/mosn/layotto/examples/pubsub/publisher/Publisher.java index e7b14d9..5a1e549 100644 --- a/examples/src/test/java/io/mosn/layotto/examples/pubsub/publisher/Publisher.java +++ b/examples/src/test/java/io/mosn/layotto/examples/pubsub/publisher/Publisher.java @@ -15,7 +15,7 @@ package io.mosn.layotto.examples.pubsub.publisher; import io.mosn.layotto.v1.RuntimeClientBuilder; -import io.mosn.layotto.v1.config.RuntimeProperties; +import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties; import spec.sdk.runtime.v1.client.RuntimeClient; public class Publisher { diff --git a/examples/src/test/java/io/mosn/layotto/examples/pubsub/subscriber/impl/RawSubscriber.java b/examples/src/test/java/io/mosn/layotto/examples/pubsub/subscriber/impl/RawSubscriber.java index 3121c4e..183a5c3 100644 --- a/examples/src/test/java/io/mosn/layotto/examples/pubsub/subscriber/impl/RawSubscriber.java +++ b/examples/src/test/java/io/mosn/layotto/examples/pubsub/subscriber/impl/RawSubscriber.java @@ -14,7 +14,7 @@ */ package io.mosn.layotto.examples.pubsub.subscriber.impl; -import io.mosn.layotto.v1.callback.component.pubsub.Subscriber; +import io.mosn.layotto.v1.grpc.callback.component.pubsub.Subscriber; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import spec.sdk.runtime.v1.domain.pubsub.TopicEventRequest; diff --git a/examples/src/test/java/io/mosn/layotto/examples/state/RedisCRUD.java b/examples/src/test/java/io/mosn/layotto/examples/state/RedisCRUD.java index 34e4b13..9a8d9b5 100644 --- a/examples/src/test/java/io/mosn/layotto/examples/state/RedisCRUD.java +++ b/examples/src/test/java/io/mosn/layotto/examples/state/RedisCRUD.java @@ -15,7 +15,7 @@ package io.mosn.layotto.examples.state; import io.mosn.layotto.v1.RuntimeClientBuilder; -import io.mosn.layotto.v1.config.RuntimeProperties; +import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties; import spec.sdk.runtime.v1.client.RuntimeClient; import spec.sdk.runtime.v1.domain.state.GetBulkStateRequest; import spec.sdk.runtime.v1.domain.state.State; @@ -25,6 +25,7 @@ import java.util.List; public class RedisCRUD { + static String storeName = "redis"; static String key1 = "key1"; static String key2 = "key2"; diff --git a/pom.xml b/pom.xml index d57ab0a..eb08874 100644 --- a/pom.xml +++ b/pom.xml @@ -13,10 +13,14 @@ https://github.com/mosn/layotto - sdk examples + sdk sdk-reactor spec + sdk-grpc + sdk-domain-rx + sdk-domain + sdk-infrastructure @@ -36,11 +40,37 @@ runtime-sdk ${project.version} + + io.mosn.layotto + runtime-sdk-reactor + ${project.version} + io.mosn.layotto runtime-spec-pb ${project.version} + + io.mosn.layotto + runtime-sdk-grpc + ${project.version} + + + io.mosn.layotto + runtime-sdk-domain-rx + ${project.version} + + + io.mosn.layotto + runtime-sdk-domain + ${project.version} + + + io.mosn.layotto + runtime-sdk-infrastructure + ${project.version} + + com.alibaba @@ -76,6 +106,7 @@ grpc-stub ${grpc.version} + org.mockito @@ -203,6 +234,7 @@ http://github.com/mosn/layotto scm:git:https://github.com/mosn/layotto.git + release @@ -260,4 +292,5 @@ + diff --git a/sdk-domain-rx/pom.xml b/sdk-domain-rx/pom.xml new file mode 100644 index 0000000..992b4a3 --- /dev/null +++ b/sdk-domain-rx/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + + runtime-sdk-parent + io.mosn.layotto + 1.1.0-SNAPSHOT + + + runtime-sdk-domain-rx + runtime-sdk-domain-rx + Reactor domain definition for Runtime + jar + + + 3.4.12 + + + + + io.mosn.layotto + runtime-sdk-domain + + + + io.projectreactor + reactor-core + ${reactor-core.version} + + + + \ No newline at end of file diff --git a/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/ConfigurationRxRuntime.java b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/ConfigurationRxRuntime.java new file mode 100644 index 0000000..68548d2 --- /dev/null +++ b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/ConfigurationRxRuntime.java @@ -0,0 +1,81 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spec.sdk.runtime.v1.domain.rx; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import spec.sdk.runtime.v1.domain.ConfigurationRuntime; +import spec.sdk.runtime.v1.domain.configuration.ConfigurationItem; +import spec.sdk.runtime.v1.domain.configuration.ConfigurationRequestItem; +import spec.sdk.runtime.v1.domain.configuration.SaveConfigurationRequest; +import spec.sdk.runtime.v1.domain.configuration.SubConfigurationResp; + +import java.util.List; + +public interface ConfigurationRxRuntime extends ConfigurationRuntime { + + /** + * Gets configuration from configuration store + * + * @param configurationRequestItem Request object. + */ + @Override + default List getConfiguration(ConfigurationRequestItem configurationRequestItem) { + return getConfigurationAsync(configurationRequestItem).block(); + } + + Mono> getConfigurationAsync(ConfigurationRequestItem configurationRequestItem); + + /** + * Saves configuration into configuration store. + * ø + * + * @param saveConfigurationRequest Request object. + */ + @Override + default void saveConfiguration(SaveConfigurationRequest saveConfigurationRequest) { + saveConfigurationAsync(saveConfigurationRequest).block(); + } + + Mono saveConfigurationAsync(SaveConfigurationRequest saveConfigurationRequest); + + /** + * Deletes configuration from configuration store. + * + * @param configurationRequestItem Request object. + */ + @Override + default void deleteConfiguration(ConfigurationRequestItem configurationRequestItem) { + deleteConfigurationAsync(configurationRequestItem).block(); + } + + Mono deleteConfigurationAsync(ConfigurationRequestItem configurationRequestItem); + + /** + * Gets configuration from configuration store and subscribe the updates. + * + * @param configurationRequestItem Request object. + */ + @Override + default void subscribeConfiguration(ConfigurationRequestItem configurationRequestItem, Subscriber subscriber) { + Flux subscribeConfigurationAsync = subscribeConfigurationAsync(configurationRequestItem); + subscribeConfigurationAsync.subscribe( + subscriber::onNext, + subscriber::onError, + subscriber::onComplete); + } + + Flux subscribeConfigurationAsync(ConfigurationRequestItem configurationRequestItem); +} diff --git a/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/FileRxRuntime.java b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/FileRxRuntime.java new file mode 100644 index 0000000..db6703f --- /dev/null +++ b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/FileRxRuntime.java @@ -0,0 +1,93 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spec.sdk.runtime.v1.domain.rx; + +import reactor.core.publisher.Mono; +import spec.sdk.runtime.v1.domain.FileRuntime; +import spec.sdk.runtime.v1.domain.file.DelFileRequest; +import spec.sdk.runtime.v1.domain.file.DelFileResponse; +import spec.sdk.runtime.v1.domain.file.GetFileRequest; +import spec.sdk.runtime.v1.domain.file.GetFileResponse; +import spec.sdk.runtime.v1.domain.file.GetMetaRequest; +import spec.sdk.runtime.v1.domain.file.GetMeteResponse; +import spec.sdk.runtime.v1.domain.file.ListFileRequest; +import spec.sdk.runtime.v1.domain.file.ListFileResponse; +import spec.sdk.runtime.v1.domain.file.PutFileRequest; +import spec.sdk.runtime.v1.domain.file.PutFileResponse; + +public interface FileRxRuntime extends FileRuntime { + + /** + * save or update file + * + * @param request the put request + * @param timeoutMs If the time is less than or equal to zero, the method will not wait at all. + * @throws Exception Instance of RuntimeClientException Or StatusRuntimeException + */ + @Override + default PutFileResponse putFile(PutFileRequest request, int timeoutMs) throws Exception { + return putFileAsync(request, timeoutMs).block(); + } + + Mono putFileAsync(PutFileRequest request, int timeoutMs) throws Exception; + + /** + * @param request the get request + * @param timeoutMs If the time is less than or equal to zero, the method will not wait at all. + * @throws Exception Instance of RuntimeClientException Or StatusRuntimeException + */ + @Override + default GetFileResponse getFile(GetFileRequest request, int timeoutMs) throws Exception { + return getFileAsync(request, timeoutMs).block(); + } + + Mono getFileAsync(GetFileRequest request, int timeoutMs) throws Exception; + + /** + * @param request the list requset + * @param timeoutMs If the time is less than or equal to zero, the method will not wait at all. + * @throws Exception Instance of RuntimeClientException Or StatusRuntimeException + */ + @Override + default ListFileResponse listFile(ListFileRequest request, int timeoutMs) throws Exception { + return listFileAsync(request, timeoutMs).block(); + } + + Mono listFileAsync(ListFileRequest request, int timeoutMs) throws Exception; + + /** + * @param request the del request + * @param timeoutMs If the time is less than or equal to zero, the method will not wait at all. + * @throws Exception Instance of RuntimeClientException Or StatusRuntimeException + */ + @Override + default DelFileResponse delFile(DelFileRequest request, int timeoutMs) throws Exception { + return delFileAsync(request, timeoutMs).block(); + } + + Mono delFileAsync(DelFileRequest request, int timeoutMs) throws Exception; + + /** + * @param request the get meta request + * @param timeoutMs If the time is less than or equal to zero, the method will not wait at all. + * @throws Exception Instance of RuntimeClientException Or StatusRuntimeException + */ + @Override + default GetMeteResponse getFileMeta(GetMetaRequest request, int timeoutMs) throws Exception { + return getFileMetaAsync(request, timeoutMs).block(); + } + + Mono getFileMetaAsync(GetMetaRequest request, int timeoutMs) throws Exception; +} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/BooleanProperty.java b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/HelloRxRuntime.java similarity index 54% rename from sdk-reactor/src/main/java/io/mosn/layotto/v1/config/BooleanProperty.java rename to sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/HelloRxRuntime.java index d2211cd..6927ca2 100644 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/BooleanProperty.java +++ b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/HelloRxRuntime.java @@ -12,25 +12,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.config; +package spec.sdk.runtime.v1.domain.rx; -/** - * Boolean configuration property. - */ -public class BooleanProperty extends Property { +import reactor.core.publisher.Mono; +import spec.sdk.runtime.v1.domain.HelloRuntime; + +public interface HelloRxRuntime extends HelloRuntime { - /** - * {@inheritDoc} - */ - BooleanProperty(String name, String envName, Boolean defaultValue) { - super(name, envName, defaultValue); + @Override + default String sayHello(String name) { + return sayHelloAsync(name).block(); } - /** - * {@inheritDoc} - */ + Mono sayHelloAsync(String name); + @Override - protected Boolean parse(String value) { - return Boolean.valueOf(value); + default String sayHello(String name, int timeoutMillisecond) { + return sayHelloAsync(name, timeoutMillisecond).block(); } + + Mono sayHelloAsync(String name, int timeoutMillisecond); } diff --git a/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/InvocationRxRuntime.java b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/InvocationRxRuntime.java new file mode 100644 index 0000000..93fcbc0 --- /dev/null +++ b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/InvocationRxRuntime.java @@ -0,0 +1,54 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spec.sdk.runtime.v1.domain.rx; + +import reactor.core.publisher.Mono; +import spec.sdk.runtime.v1.domain.invocation.InvokeResponse; + +import java.util.Map; + +public interface InvocationRxRuntime { + + /** + * Invoke a service method. + * + * @param appId The Application ID where the service is. + * @param methodName The actual Method to be call in the application. + * @param data The data to be sent to invoke the service, use byte[] to skip serialization. + * @param header Metadata (in GRPC) or headers (in HTTP) to be sent in data. + * @return The response from the service call. + */ + default InvokeResponse invokeMethod(String appId, String methodName, byte[] data, Map header) { + return invokeMethodAsync(appId, methodName, data, header).block(); + } + + Mono> invokeMethodAsync(String appId, String methodName, byte[] data, Map header); + + /** + * Invoke a service method. + * + * @param appId The Application ID where the service is. + * @param methodName The actual Method to be call in the application. + * @param data The data to be sent to invoke the service, use byte[] to skip serialization. + * @param header Metadata (in GRPC) or headers (in HTTP) to be sent in data. + * @param timeoutMs can be customized every time a service method is called, since different services provide different SLA. + * @return The response from the service call. + */ + default InvokeResponse invokeMethod(String appId, String methodName, byte[] data, Map header, int timeoutMs) { + return invokeMethodAsync(appId, methodName, data, header, timeoutMs).block(); + } + + Mono> invokeMethodAsync(String appId, String methodName, byte[] data, Map header, int timeoutMs); +} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/value/LayottoApiProtocol.java b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/LockRxRuntime.java similarity index 81% rename from sdk-reactor/src/main/java/io/mosn/layotto/v1/value/LayottoApiProtocol.java rename to sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/LockRxRuntime.java index 223b264..efba20a 100644 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/value/LayottoApiProtocol.java +++ b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/LockRxRuntime.java @@ -12,12 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.value; +package spec.sdk.runtime.v1.domain.rx; -/** - * Transport protocol for Layotto's API. - */ -public enum LayottoApiProtocol { +import spec.sdk.runtime.v1.domain.LockRuntime; - GRPC; +public interface LockRxRuntime extends LockRuntime { } diff --git a/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/PubSubRxRuntime.java b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/PubSubRxRuntime.java new file mode 100644 index 0000000..b75626a --- /dev/null +++ b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/PubSubRxRuntime.java @@ -0,0 +1,78 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spec.sdk.runtime.v1.domain.rx; + +import reactor.core.publisher.Mono; +import spec.sdk.runtime.v1.domain.PubSubRuntime; +import spec.sdk.runtime.v1.domain.pubsub.PublishEventRequest; + +import java.util.Map; + +public interface PubSubRxRuntime extends PubSubRuntime { + + /** + * Publish an event. + * + * @param pubsubName the pubsub name we will publish the event to + * @param topicName the topicName where the event will be published. + * @param data the event's data to be published, use byte[] for skipping serialization. + */ + //void publishEvent(String pubsubName, String topicName, Object data); + + /** + * Publish an event. + * + * @param pubsubName the pubsub name we will publish the event to + * @param topicName the topicName where the event will be published. + * @param data the event's data to be published, use byte[] for skipping serialization. + * @param metadata The metadata for the published event. + */ + //void publishEvent(String pubsubName, String topicName, Object data, Map metadata); + + /** + * Publish an event. + * + * @param pubsubName the pubsub name we will publish the event to + * @param topicName the topicName where the event will be published. + * @param data the event's data to be published, use byte[] for skipping serialization. + */ + @Override + default void publishEvent(String pubsubName, String topicName, byte[] data) { + publishEventAsync(pubsubName, topicName, data).block(); + } + + Mono publishEventAsync(String pubsubName, String topicName, byte[] data); + + @Override + default void publishEvent(String pubsubName, String topicName, byte[] data, Map metadata) { + publishEventAsync(pubsubName, topicName, data, metadata).block(); + } + + Mono publishEventAsync(String pubsubName, String topicName, byte[] data, Map metadata); + + @Override + default void publishEvent(String pubsubName, String topicName, byte[] data, String contentType, Map metadata) { + publishEventAsync(pubsubName, topicName, data, contentType, metadata).block(); + } + + Mono publishEventAsync(String pubsubName, String topicName, byte[] data, String contentType, Map metadata); + + @Override + default void publishEvent(PublishEventRequest request) { + publishEventAsync(request).block(); + } + + Mono publishEventAsync(PublishEventRequest request); +} diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockRequest.java b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/SequencerRxRuntime.java similarity index 79% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockRequest.java rename to sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/SequencerRxRuntime.java index 49458e6..e64a3da 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockRequest.java +++ b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/SequencerRxRuntime.java @@ -12,10 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.runtime.v1.domain.lock; +package spec.sdk.runtime.v1.domain.rx; -public class UnlockRequest { - public String storeName; - public String resourceId; - public String lockOwner; +import spec.sdk.runtime.v1.domain.SequencerRuntime; + +public interface SequencerRxRuntime extends SequencerRuntime { } diff --git a/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/StateRxRuntime.java b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/StateRxRuntime.java new file mode 100644 index 0000000..69309cc --- /dev/null +++ b/sdk-domain-rx/src/main/java/spec/sdk/runtime/v1/domain/rx/StateRxRuntime.java @@ -0,0 +1,286 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spec.sdk.runtime.v1.domain.rx; + +import reactor.core.publisher.Mono; +import spec.sdk.runtime.v1.domain.StateRuntime; +import spec.sdk.runtime.v1.domain.state.DeleteStateRequest; +import spec.sdk.runtime.v1.domain.state.ExecuteStateTransactionRequest; +import spec.sdk.runtime.v1.domain.state.GetBulkStateRequest; +import spec.sdk.runtime.v1.domain.state.GetStateRequest; +import spec.sdk.runtime.v1.domain.state.SaveStateRequest; +import spec.sdk.runtime.v1.domain.state.State; +import spec.sdk.runtime.v1.domain.state.StateOptions; +import spec.sdk.runtime.v1.domain.state.TransactionalStateOperation; + +import java.util.List; +import java.util.Map; + +public interface StateRxRuntime extends StateRuntime { + + /** + * Retrieve a State based on their key. + * + * @param storeName The name of the state store. + * @param key The key of the State to be retrieved. + * @param clazz The type of State needed as return. + * @param The type of the return. + */ + @Override + default State getState(String storeName, String key, Class clazz) { + return getStateAsync(storeName, key, clazz).block(); + } + + Mono> getStateAsync(String storeName, String key, Class clazz); + + /** + * Retrieve a State based on their key. + * + * @param storeName The name of the state store. + * @param key The key of the State to be retrieved. + * @param options Optional settings for retrieve operation. + * @param clazz The Type of State needed as return. + * @param The Type of the return. + */ + @Override + default State getState(String storeName, String key, StateOptions options, Class clazz) { + return getStateAsync(storeName, key, options, clazz).block(); + } + + Mono> getStateAsync(String storeName, String key, StateOptions options, Class clazz); + + /** + * Retrieve a State based on their key. + * + * @param request The request to get state. + * @param clazz The Class of State needed as return. + * @param The Type of the return. + * @return The requested State. + */ + @Override + default State getState(GetStateRequest request, Class clazz) { + return getStateAsync(request, clazz).block(); + } + + Mono> getStateAsync(GetStateRequest request, Class clazz); + + /** + * Retrieve a State based on their key. + * + * @param request The request to get state. + * @param clazz The Class of State needed as return. + * @param timeoutMs timeout in milliseconds + * @param The Type of the return. + * @return the requested State. + */ + @Override + default State getState(GetStateRequest request, Class clazz, int timeoutMs) { + return getStateAsync(request, clazz, timeoutMs).block(); + } + + Mono> getStateAsync(GetStateRequest request, Class clazz, int timeoutMs); + + /** + * Retrieve bulk States based on their keys. + * + * @param storeName The name of the state store. + * @param keys The keys of the State to be retrieved. + * @param clazz The type of State needed as return. + * @param The type of the return. + */ + @Override + default List> getBulkState(String storeName, List keys, Class clazz) { + return getBulkStateAsync(storeName, keys, clazz).block(); + } + + Mono>> getBulkStateAsync(String storeName, List keys, Class clazz); + + /** + * Retrieve bulk States based on their keys. + * + * @param request The request to get state. + * @param clazz The Class of State needed as return. + * @param The Type of the return. + * @return The requested State. + */ + @Override + default List> getBulkState(GetBulkStateRequest request, Class clazz) { + return getBulkStateAsync(request, clazz).block(); + } + + Mono>> getBulkStateAsync(GetBulkStateRequest request, Class clazz); + + /** + * Retrieve bulk States based on their keys. + * + * @param request The request to get state. + * @param clazz The Class of State needed as return. + * @param The Type of the return. + * @param timeoutMs The time limit(millisecond) of this call. + * @return The requested State. + */ + @Override + default List> getBulkState(GetBulkStateRequest request, Class clazz, int timeoutMs) { + return getBulkStateAsync(request, clazz, timeoutMs).block(); + } + + Mono>> getBulkStateAsync(GetBulkStateRequest request, Class clazz, int timeoutMs); + + /** + * Execute a transaction. + * + * @param storeName The name of the state store. + * @param operations The operations to be performed. + */ + @Override + default void executeStateTransaction(String storeName, List> operations) { + executeStateTransactionAsync(storeName, operations).block(); + } + + Mono executeStateTransactionAsync(String storeName, List> operations); + + /** + * Execute a transaction. + * + * @param request Request to execute transaction. + */ + @Override + default void executeStateTransaction(ExecuteStateTransactionRequest request) { + executeStateTransactionAsync(request).block(); + } + + Mono executeStateTransactionAsync(ExecuteStateTransactionRequest request); + + /** + * Save/Update a list of states. + * + * @param storeName The name of the state store. + * @param states The States to be saved. + */ + @Override + default void saveBulkState(String storeName, List> states) { + saveBulkStateAsync(storeName, states).block(); + } + + Mono saveBulkStateAsync(String storeName, List> states); + + /** + * Save/Update a list of states. + * + * @param request Request to save states. + */ + @Override + default void saveBulkState(SaveStateRequest request) { + saveBulkStateAsync(request).block(); + } + + Mono saveBulkStateAsync(SaveStateRequest request); + + /** + * Save/Update a list of states. + * + * @param request Request to save bulk states. + * @param timeoutMs timeout in milliseconds + */ + @Override + default void saveBulkState(SaveStateRequest request, int timeoutMs) { + saveBulkStateAsync(request, timeoutMs).block(); + } + + Mono saveBulkStateAsync(SaveStateRequest request, int timeoutMs); + + /** + * Save/Update a state. + * + * @param storeName The name of the state store. + * @param key The key of the state. + * @param value The value of the state. + */ + @Override + default void saveState(String storeName, String key, Object value) { + saveStateAsync(storeName, key, value).block(); + } + + Mono saveStateAsync(String storeName, String key, Object value); + + /** + * Save/Update a state. + * + * @param storeName The name of the state store. + * @param key The key of the state. + * @param etag The etag to be used. + * @param value The value of the state. + * @param options The Options to use for each state. + */ + @Override + default void saveState(String storeName, String key, String etag, Object value, StateOptions options, Map metadata) { + saveStateAsync(storeName, key, etag, value, options, metadata).block(); + } + + Mono saveStateAsync(String storeName, String key, String etag, Object value, StateOptions options, Map metadata); + + /** + * Delete a state. + * + * @param storeName The name of the state store. + * @param key The key of the State to be removed. + */ + @Override + default void deleteState(String storeName, String key) { + deleteStateAsync(storeName, key).block(); + } + + Mono deleteStateAsync(String storeName, String key); + + /** + * Delete a state. + * + * @param storeName The name of the state store. + * @param key The key of the State to be removed. + * @param etag Optional etag for conditional delete. + * @param options Optional settings for state operation. + */ + @Override + default void deleteState(String storeName, String key, String etag, StateOptions options) { + deleteStateAsync(storeName, key, etag, options).block(); + } + + Mono deleteStateAsync(String storeName, String key, String etag, StateOptions options); + + /** + * Delete a state. + * + * @param request Request to delete a state. + */ + @Override + default void deleteState(DeleteStateRequest request) { + deleteStateAsync(request).block(); + } + + Mono deleteStateAsync(DeleteStateRequest request); + + /** + * Delete a state. + * + * @param request Request to delete a state. + * @param timeoutMs timeout in milliseconds + */ + @Override + default void deleteState(DeleteStateRequest request, int timeoutMs) { + deleteStateAsync(request, timeoutMs).block(); + } + + Mono deleteStateAsync(DeleteStateRequest request, int timeoutMs); +} diff --git a/sdk-domain/pom.xml b/sdk-domain/pom.xml new file mode 100644 index 0000000..0f23428 --- /dev/null +++ b/sdk-domain/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + + runtime-sdk-parent + io.mosn.layotto + 1.1.0-SNAPSHOT + + + runtime-sdk-domain + runtime-sdk-domain + Domain definition for Runtime + jar + + + + io.mosn.layotto + runtime-sdk-infrastructure + + + + \ No newline at end of file diff --git a/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/ConfigurationRuntime.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/ConfigurationRuntime.java new file mode 100644 index 0000000..e736a91 --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/ConfigurationRuntime.java @@ -0,0 +1,75 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spec.sdk.runtime.v1.domain; + +import spec.sdk.runtime.v1.domain.configuration.ConfigurationItem; +import spec.sdk.runtime.v1.domain.configuration.ConfigurationRequestItem; +import spec.sdk.runtime.v1.domain.configuration.SaveConfigurationRequest; +import spec.sdk.runtime.v1.domain.configuration.SubConfigurationResp; + +import java.util.List; + +public interface ConfigurationRuntime { + + /** + * Gets configuration from configuration store + * + * @param configurationRequestItem Request object. + */ + List getConfiguration(ConfigurationRequestItem configurationRequestItem); + + /** + * Saves configuration into configuration store. + *ø + * @param saveConfigurationRequest Request object. + */ + void saveConfiguration(SaveConfigurationRequest saveConfigurationRequest); + + /** + * Deletes configuration from configuration store. + * + * @param configurationRequestItem Request object. + */ + void deleteConfiguration(ConfigurationRequestItem configurationRequestItem); + + /** + * Gets configuration from configuration store and subscribe the updates. + * + * @param configurationRequestItem Request object. + */ + void subscribeConfiguration(ConfigurationRequestItem configurationRequestItem, Subscriber subscriber); + + interface Subscriber { + + /** + * Data notification sent by the {@code Publisher} in response to requests to {@link Subscription#request(long)}. + * + * @param t the element signaled + */ + void onNext(SubConfigurationResp t); + + /** + * Failed terminal state. + * + * @param t the throwable signaled + */ + void onError(Throwable t); + + /** + * Successful terminal state. + */ + void onComplete(); + } +} diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/FileRuntime.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/FileRuntime.java similarity index 92% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/FileRuntime.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/FileRuntime.java index b4c77db..82dd899 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/FileRuntime.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/FileRuntime.java @@ -30,35 +30,35 @@ public interface FileRuntime { /** * save or update file * - * @param request + * @param request the put request * @param timeoutMs If the time is less than or equal to zero, the method will not wait at all. * @throws Exception Instance of RuntimeClientException Or StatusRuntimeException */ PutFileResponse putFile(PutFileRequest request, int timeoutMs) throws Exception; /** - * @param request + * @param request the get request * @param timeoutMs If the time is less than or equal to zero, the method will not wait at all. * @throws Exception Instance of RuntimeClientException Or StatusRuntimeException */ GetFileResponse getFile(GetFileRequest request, int timeoutMs) throws Exception; /** - * @param request + * @param request the list requset * @param timeoutMs If the time is less than or equal to zero, the method will not wait at all. * @throws Exception Instance of RuntimeClientException Or StatusRuntimeException */ ListFileResponse listFile(ListFileRequest request, int timeoutMs) throws Exception; /** - * @param request + * @param request the del request * @param timeoutMs If the time is less than or equal to zero, the method will not wait at all. * @throws Exception Instance of RuntimeClientException Or StatusRuntimeException */ DelFileResponse delFile(DelFileRequest request, int timeoutMs) throws Exception; /** - * @param request + * @param request the get meta request * @param timeoutMs If the time is less than or equal to zero, the method will not wait at all. * @throws Exception Instance of RuntimeClientException Or StatusRuntimeException */ diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/HelloRuntime.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/HelloRuntime.java similarity index 100% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/HelloRuntime.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/HelloRuntime.java diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/InvocationRuntime.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/InvocationRuntime.java similarity index 60% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/InvocationRuntime.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/InvocationRuntime.java index 83e263f..4fc4923 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/InvocationRuntime.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/InvocationRuntime.java @@ -20,17 +20,26 @@ public interface InvocationRuntime { + /** + * Invoke a service method. + * + * @param appId The Application ID where the service is. + * @param methodName The actual Method to be call in the application. + * @param data The data to be sent to invoke the service, use byte[] to skip serialization. + * @param header Metadata (in GRPC) or headers (in HTTP) to be sent in data. + * @return The response from the service call. + */ InvokeResponse invokeMethod(String appId, String methodName, byte[] data, Map header); /** * Invoke a service method. * - * @param appId - * @param methodName - * @param data - * @param header + * @param appId The Application ID where the service is. + * @param methodName The actual Method to be call in the application. + * @param data The data to be sent to invoke the service, use byte[] to skip serialization. + * @param header Metadata (in GRPC) or headers (in HTTP) to be sent in data. * @param timeoutMs can be customized every time a service method is called, since different services provide different SLA. - * @return + * @return The response from the service call. */ InvokeResponse invokeMethod(String appId, String methodName, byte[] data, Map header, int timeoutMs); diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/LockRuntime.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/LockRuntime.java similarity index 100% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/LockRuntime.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/LockRuntime.java diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/PubSubRuntime.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/PubSubRuntime.java similarity index 90% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/PubSubRuntime.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/PubSubRuntime.java index 0f1b09c..92b1bfd 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/PubSubRuntime.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/PubSubRuntime.java @@ -14,9 +14,12 @@ */ package spec.sdk.runtime.v1.domain; +import spec.sdk.runtime.v1.domain.pubsub.PublishEventRequest; + import java.util.Map; public interface PubSubRuntime { + /** * Publish an event. * @@ -49,4 +52,10 @@ public interface PubSubRuntime { void publishEvent(String pubsubName, String topicName, byte[] data, String contentType, Map metadata); + /** + * Publish an event. + * + * @param request the request for the publish event. + */ + void publishEvent(PublishEventRequest request); } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/SequencerRuntime.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/SequencerRuntime.java similarity index 100% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/SequencerRuntime.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/SequencerRuntime.java diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/StateRuntime.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/StateRuntime.java similarity index 94% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/StateRuntime.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/StateRuntime.java index 0480c99..8355a18 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/StateRuntime.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/StateRuntime.java @@ -64,9 +64,9 @@ public interface StateRuntime { * * @param request The request to get state. * @param clazz The Class of State needed as return. - * @param timeoutMs + * @param timeoutMs timeout in milliseconds * @param The Type of the return. - * @return + * @return the requested State. */ State getState(GetStateRequest request, Class clazz, int timeoutMs); @@ -107,8 +107,7 @@ public interface StateRuntime { * @param storeName The name of the state store. * @param operations The operations to be performed. */ - void executeStateTransaction(String storeName, - List> operations); + void executeStateTransaction(String storeName, List> operations); /** * Execute a transaction. @@ -135,8 +134,8 @@ void executeStateTransaction(String storeName, /** * Save/Update a list of states. * - * @param request - * @param timeoutMs + * @param request Request to save bulk states. + * @param timeoutMs timeout in milliseconds */ void saveBulkState(SaveStateRequest request, int timeoutMs); @@ -190,7 +189,7 @@ void saveState(String storeName, String key, String etag, Object value, StateOpt * Delete a state. * * @param request Request to delete a state. - * @param timeoutMs + * @param timeoutMs timeout in milliseconds */ void deleteState(DeleteStateRequest request, int timeoutMs); } diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/ConfigurationItem.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationItem.java similarity index 79% rename from sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/ConfigurationItem.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationItem.java index a456d87..544f634 100644 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/ConfigurationItem.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationItem.java @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.reactor.v1.domain.core.configuration; +package spec.sdk.runtime.v1.domain.configuration; import java.util.Map; -public class ConfigurationItem { +public class ConfigurationItem { /** * Required. The key of configuration item @@ -26,7 +26,7 @@ public class ConfigurationItem { * The content of configuration item * Empty if the configuration is not set, including the case that the configuration is changed from value-set to value-not-set. */ - private T content; + private Object content; /** * The group of configuration item. */ @@ -52,11 +52,11 @@ public void setKey(String key) { this.key = key; } - public T getContent() { + public Object getContent() { return content; } - public void setContent(T content) { + public void setContent(Object content) { this.content = content; } @@ -91,4 +91,16 @@ public Map getMetadata() { public void setMetadata(Map metadata) { this.metadata = metadata; } + + @Override + public String toString() { + return "ConfigurationItem{" + + "key='" + key + '\'' + + ", content=" + content + + ", group='" + group + '\'' + + ", label='" + label + '\'' + + ", tags=" + tags + + ", metadata=" + metadata + + '}'; + } } diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/ConfigurationRequestItem.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItem.java similarity index 84% rename from sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/ConfigurationRequestItem.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItem.java index 3c937dd..a9fe513 100644 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/ConfigurationRequestItem.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItem.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.reactor.v1.domain.core.configuration; +package spec.sdk.runtime.v1.domain.configuration; import java.util.List; import java.util.Map; @@ -95,4 +95,16 @@ public Map getMetadata() { public void setMetadata(Map metadata) { this.metadata = metadata; } + + @Override + public String toString() { + return "ConfigurationRequestItem{" + + "storeName='" + storeName + '\'' + + ", appId='" + appId + '\'' + + ", group='" + group + '\'' + + ", label='" + label + '\'' + + ", keys=" + keys + + ", metadata=" + metadata + + '}'; + } } diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/ConfigurationRequestItemBuilder.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItemBuilder.java similarity index 82% rename from sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/ConfigurationRequestItemBuilder.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItemBuilder.java index 1c2ad76..d026ba2 100644 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/ConfigurationRequestItemBuilder.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItemBuilder.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.reactor.v1.domain.core.configuration; +package spec.sdk.runtime.v1.domain.configuration; import java.util.List; import java.util.Map; @@ -66,7 +66,7 @@ public ConfigurationRequestItemBuilder withMetadata(Map metadata */ public ConfigurationRequestItem build() { ConfigurationRequestItem request = new ConfigurationRequestItem(); - request.setStoreName(this.appId); + request.setStoreName(this.storeName); request.setAppId(this.appId); request.setGroup(this.group); request.setLabel(this.label); @@ -74,4 +74,16 @@ public ConfigurationRequestItem build() { request.setMetadata(this.metadata); return request; } + + @Override + public String toString() { + return "ConfigurationRequestItemBuilder{" + + "storeName='" + storeName + '\'' + + ", appId='" + appId + '\'' + + ", group='" + group + '\'' + + ", label='" + label + '\'' + + ", keys=" + keys + + ", metadata=" + metadata + + '}'; + } } diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/SaveConfigurationRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SaveConfigurationRequest.java similarity index 80% rename from sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/SaveConfigurationRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SaveConfigurationRequest.java index 9fc5cf6..09ab8f9 100644 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/SaveConfigurationRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SaveConfigurationRequest.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.reactor.v1.domain.core.configuration; +package spec.sdk.runtime.v1.domain.configuration; import java.util.List; import java.util.Map; @@ -22,21 +22,21 @@ public class SaveConfigurationRequest { /** * The name of configuration store. */ - private String storeName; + private String storeName; /** * The application id which * Only used for admin, Ignored and reset for normal client */ - private String appId; + private String appId; /** * The list of configuration items to save. * To delete a exist item, set the key (also label) and let content to be empty */ - private List> items; + private List items; /** * The metadata which will be sent to configuration store components. */ - private Map metadata; + private Map metadata; public String getStoreName() { return storeName; @@ -54,11 +54,11 @@ public void setAppId(String appId) { this.appId = appId; } - public List> getItems() { + public List getItems() { return items; } - public void setItems(List> items) { + public void setItems(List items) { this.items = items; } diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/SubConfigurationResp.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SubConfigurationResp.java similarity index 69% rename from sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/SubConfigurationResp.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SubConfigurationResp.java index 4fe44ae..19b9be8 100644 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/configuration/SubConfigurationResp.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SubConfigurationResp.java @@ -12,26 +12,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.reactor.v1.domain.core.configuration; +package spec.sdk.runtime.v1.domain.configuration; import java.util.List; -public class SubConfigurationResp { +public class SubConfigurationResp { /** * The name of configuration store. */ - private String storeName; + private String storeName; /** * The application id which * Only used for admin, Ignored and reset for normal client */ - private String appId; + private String appId; /** * The list of configuration items to save. * To delete a exist item, set the key (also label) and let content to be empty */ - private List> items; + private List items; public String getStoreName() { return storeName; @@ -49,11 +49,20 @@ public void setAppId(String appId) { this.appId = appId; } - public List> getItems() { + public List getItems() { return items; } - public void setItems(List> items) { + public void setItems(List items) { this.items = items; } + + @Override + public String toString() { + return "SubConfigurationResp{" + + "storeName='" + storeName + '\'' + + ", appId='" + appId + '\'' + + ", items=" + items + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/DelFileRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/DelFileRequest.java similarity index 85% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/DelFileRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/DelFileRequest.java index 79b8cf0..35afb53 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/DelFileRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/DelFileRequest.java @@ -41,11 +41,9 @@ public void setFileName(String fileName) { } public Map getMetaData() { - if (metaData == null) { metaData = new HashMap<>(); } - return metaData; } @@ -53,4 +51,12 @@ public void setMetaData(Map metaData) { this.metaData = metaData; } + @Override + public String toString() { + return "DelFileRequest{" + + "storeName='" + storeName + '\'' + + ", fileName='" + fileName + '\'' + + ", metaData=" + metaData + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/DelFileResponse.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/DelFileResponse.java similarity index 100% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/DelFileResponse.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/DelFileResponse.java diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/FileInfo.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/FileInfo.java similarity index 87% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/FileInfo.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/FileInfo.java index a3a0ae6..8891609 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/FileInfo.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/FileInfo.java @@ -18,6 +18,7 @@ import java.util.Map; public class FileInfo { + private String fileName; private long size; private String lastModified; @@ -55,15 +56,23 @@ public void setLastModified(String lastModified) { } public Map getMetaData() { - if (metaData == null) { metaData = new HashMap<>(); } - return metaData; } public void setMetaData(Map metaData) { this.metaData = metaData; } + + @Override + public String toString() { + return "FileInfo{" + + "fileName='" + fileName + '\'' + + ", size=" + size + + ", lastModified='" + lastModified + '\'' + + ", metaData=" + metaData + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileRequest.java similarity index 85% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileRequest.java index 1d8e534..86bc760 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileRequest.java @@ -41,15 +41,22 @@ public void setFileName(String fileName) { } public Map getMetaData() { - if (metaData == null) { metaData = new HashMap<>(); } - return metaData; } public void setMetaData(Map metaData) { this.metaData = metaData; } + + @Override + public String toString() { + return "GetFileRequest{" + + "storeName='" + storeName + '\'' + + ", fileName='" + fileName + '\'' + + ", metaData=" + metaData + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileResponse.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileResponse.java similarity index 87% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileResponse.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileResponse.java index 905e55c..21b4095 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileResponse.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetFileResponse.java @@ -31,4 +31,11 @@ public InputStream getIn() { public void setIn(InputStream in) { this.in = in; } + + @Override + public String toString() { + return "GetFileResponse{" + + "in=" + in + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetMetaRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetMetaRequest.java similarity index 85% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetMetaRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetMetaRequest.java index b1f856b..f7b071f 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetMetaRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetMetaRequest.java @@ -41,15 +41,22 @@ public void setFileName(String fileName) { } public Map getMetaData() { - if (metaData == null) { metaData = new HashMap<>(); } - return metaData; } public void setMetaData(Map metaData) { this.metaData = metaData; } + + @Override + public String toString() { + return "GetMetaRequest{" + + "storeName='" + storeName + '\'' + + ", fileName='" + fileName + '\'' + + ", metaData=" + metaData + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetMeteResponse.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetMeteResponse.java similarity index 99% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetMeteResponse.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetMeteResponse.java index 38553e7..c5782b0 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/GetMeteResponse.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/GetMeteResponse.java @@ -18,6 +18,7 @@ import java.util.Map; public class GetMeteResponse { + private long size; private String lastModified; private Map meta; @@ -39,11 +40,9 @@ public void setLastModified(String lastModified) { } public Map getMeta() { - if (meta == null) { meta = new HashMap<>(); } - return meta; } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileRequest.java similarity index 85% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileRequest.java index 86ea4d8..d06d09d 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileRequest.java @@ -43,11 +43,9 @@ public void setName(String name) { } public Map getMetaData() { - if (metaData == null) { metaData = new HashMap<>(); } - return metaData; } @@ -70,4 +68,15 @@ public String getMarker() { public void setMarker(String marker) { this.marker = marker; } + + @Override + public String toString() { + return "ListFileRequest{" + + "storeName='" + storeName + '\'' + + ", name='" + name + '\'' + + ", metaData=" + metaData + + ", pageSize=" + pageSize + + ", marker='" + marker + '\'' + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileResponse.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileResponse.java similarity index 82% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileResponse.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileResponse.java index 23db57d..6f43170 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileResponse.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/ListFileResponse.java @@ -14,6 +14,8 @@ */ package spec.sdk.runtime.v1.domain.file; +import java.util.Arrays; + public class ListFileResponse { private boolean isTruncated; @@ -38,15 +40,22 @@ public void setMarker(String marker) { } public FileInfo[] getFiles() { - if (files == null) { files = new FileInfo[0]; } - return files; } public void setFiles(FileInfo[] files) { this.files = files; } + + @Override + public String toString() { + return "ListFileResponse{" + + "isTruncated=" + isTruncated + + ", marker='" + marker + '\'' + + ", files=" + Arrays.toString(files) + + '}'; + } } \ No newline at end of file diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/PutFileRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/PutFileRequest.java similarity index 85% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/PutFileRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/PutFileRequest.java index fdef7c7..e705609 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/PutFileRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/PutFileRequest.java @@ -44,11 +44,9 @@ public void setFileName(String fileName) { } public Map getMetaData() { - if (metaData == null) { metaData = new HashMap<>(); } - return metaData; } @@ -63,4 +61,14 @@ public InputStream getIn() { public void setIn(InputStream in) { this.in = in; } + + @Override + public String toString() { + return "PutFileRequest{" + + "storeName='" + storeName + '\'' + + ", fileName='" + fileName + '\'' + + ", metaData=" + metaData + + ", in=" + in + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/file/PutFileResponse.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/PutFileResponse.java similarity index 100% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/file/PutFileResponse.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/file/PutFileResponse.java diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/invocation/HttpExtension.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/HttpExtension.java similarity index 81% rename from sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/invocation/HttpExtension.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/HttpExtension.java index 8a7a64e..9c0f38d 100644 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/invocation/HttpExtension.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/HttpExtension.java @@ -12,14 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.reactor.v1.domain.core.invocation; - -import okhttp3.HttpUrl; +package spec.sdk.runtime.v1.domain.invocation; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Optional; /** * HTTP Extension class. @@ -124,27 +121,6 @@ public Map getHeaders() { return headers; } - /** - * Encodes the query string for the HTTP request. - * - * @return Encoded HTTP query string. - */ - public String encodeQueryString() { - if ((this.queryParams == null) || (this.queryParams.isEmpty())) { - return ""; - } - - HttpUrl.Builder urlBuilder = new HttpUrl.Builder(); - // Setting required values but we only need query params in the end. - urlBuilder.scheme("http").host("localhost"); - Optional.ofNullable(this.queryParams).orElse(Collections.emptyMap()).entrySet().stream() - .forEach(urlParameter -> - Optional.ofNullable(urlParameter.getValue()).orElse(Collections.emptyList()).stream() - .forEach(urlParameterValue -> - urlBuilder.addQueryParameter(urlParameter.getKey(), urlParameterValue))); - return urlBuilder.build().encodedQuery(); - } - /** * HTTP Methods supported. */ diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/invocation/InvokeMethodRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeMethodRequest.java similarity index 82% rename from sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/invocation/InvokeMethodRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeMethodRequest.java index 696f3a5..aa69737 100644 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/invocation/InvokeMethodRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeMethodRequest.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.reactor.v1.domain.core.invocation; +package spec.sdk.runtime.v1.domain.invocation; import java.util.Map; @@ -80,4 +80,16 @@ public Map getMetadata() { public void setMetadata(Map metadata) { this.metadata = metadata; } + + @Override + public String toString() { + return "InvokeMethodRequest{" + + "appId='" + appId + '\'' + + ", method='" + method + '\'' + + ", body=" + body + + ", httpExtension=" + httpExtension + + ", contentType='" + contentType + '\'' + + ", metadata=" + metadata + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeResponse.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeResponse.java similarity index 89% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeResponse.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeResponse.java index 714c1fc..582ca95 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeResponse.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeResponse.java @@ -15,6 +15,7 @@ package spec.sdk.runtime.v1.domain.invocation; public class InvokeResponse { + private String contentType; private T data; @@ -53,4 +54,12 @@ public T getData() { public void setData(T data) { this.data = data; } + + @Override + public String toString() { + return "InvokeResponse{" + + "contentType='" + contentType + '\'' + + ", data=" + data + + '}'; + } } diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/invocation/Metadata.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/Metadata.java similarity index 94% rename from sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/invocation/Metadata.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/Metadata.java index 19c00a2..268bc45 100644 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/invocation/Metadata.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/Metadata.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.reactor.v1.domain.core.invocation; +package spec.sdk.runtime.v1.domain.invocation; /** * Enumerates commonly used metadata attributes. diff --git a/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockRequest.java new file mode 100644 index 0000000..35d03ec --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockRequest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spec.sdk.runtime.v1.domain.lock; + +public class TryLockRequest { + + public String storeName; + public String resourceId; + public String lockOwner; + public int expire; + + public String getStoreName() { + return storeName; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + public String getLockOwner() { + return lockOwner; + } + + public void setLockOwner(String lockOwner) { + this.lockOwner = lockOwner; + } + + public int getExpire() { + return expire; + } + + public void setExpire(int expire) { + this.expire = expire; + } + + @Override + public String toString() { + return "TryLockRequest{" + + "storeName='" + storeName + '\'' + + ", resourceId='" + resourceId + '\'' + + ", lockOwner='" + lockOwner + '\'' + + ", expire=" + expire + + '}'; + } +} \ No newline at end of file diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockResponse.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java similarity index 65% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockResponse.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java index a12f819..3f4a6e7 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockResponse.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java @@ -14,18 +14,22 @@ */ package spec.sdk.runtime.v1.domain.lock; -enum UnlockResponseStatus { - SUCCESS(0), - LOCK_UNEXIST(1), - LOCK_BELONG_TO_OTHERS(2), - INTERNAL_ERROR(3); - private final int value; +public class TryLockResponse { - UnlockResponseStatus(int value) { - this.value = value; + public boolean success; + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; } -} -public class UnlockResponse { - public UnlockResponseStatus status; -} + @Override + public String toString() { + return "TryLockResponse{" + + "success=" + success + + '}'; + } +} \ No newline at end of file diff --git a/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockRequest.java new file mode 100644 index 0000000..437147f --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockRequest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spec.sdk.runtime.v1.domain.lock; + +public class UnlockRequest { + + public String storeName; + public String resourceId; + public String lockOwner; + + public String getStoreName() { + return storeName; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + public String getLockOwner() { + return lockOwner; + } + + public void setLockOwner(String lockOwner) { + this.lockOwner = lockOwner; + } + + @Override + public String toString() { + return "UnlockRequest{" + + "storeName='" + storeName + '\'' + + ", resourceId='" + resourceId + '\'' + + ", lockOwner='" + lockOwner + '\'' + + '}'; + } +} diff --git a/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockResponse.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockResponse.java new file mode 100644 index 0000000..ea67658 --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockResponse.java @@ -0,0 +1,53 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package spec.sdk.runtime.v1.domain.lock; + +public class UnlockResponse { + + public UnlockResponseStatus status; + + public UnlockResponseStatus getStatus() { + return status; + } + + public void setStatus(UnlockResponseStatus status) { + this.status = status; + } + + @Override + public String toString() { + return "UnlockResponse{" + + "status=" + status + + '}'; + } + + public enum UnlockResponseStatus { + + SUCCESS(0), + LOCK_UNEXIST(1), + LOCK_BELONG_TO_OTHERS(2), + INTERNAL_ERROR(3); + + private final int value; + + UnlockResponseStatus(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + } +} diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/package-info.java similarity index 74% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/package-info.java index 9dcfbc5..97d0b69 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/package-info.java @@ -12,11 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.runtime.v1.domain.lock; - -public class TryLockRequest { - public String storeName; - public String resourceId; - public String lockOwner; - public int expire; -} \ No newline at end of file +/** + * This package was copied from [cloud-runtimes-jvm](https://github.com/reactivegroup/cloud-runtimes-jvm) + * and [Dapr java sdk](https://github.com/dapr/java-sdk) + */ +package spec.sdk.runtime.v1.domain; \ No newline at end of file diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/PublishEventRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/PublishEventRequest.java similarity index 89% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/PublishEventRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/PublishEventRequest.java index 3d7fe28..a3cae43 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/PublishEventRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/PublishEventRequest.java @@ -14,9 +14,11 @@ */ package spec.sdk.runtime.v1.domain.pubsub; +import java.util.Arrays; import java.util.Map; public class PublishEventRequest { + // The name of the pubsub component private String pubsubName; // The pubsub topic @@ -122,4 +124,15 @@ public Map getMetadata() { public void setMetadata(Map metadata) { this.metadata = metadata; } + + @Override + public String toString() { + return "PublishEventRequest{" + + "pubsubName='" + pubsubName + '\'' + + ", topic='" + topic + '\'' + + ", data=" + Arrays.toString(data) + + ", contentType='" + contentType + '\'' + + ", metadata=" + metadata + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventRequest.java similarity index 91% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventRequest.java index e907584..3888b96 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventRequest.java @@ -14,9 +14,11 @@ */ package spec.sdk.runtime.v1.domain.pubsub; +import java.util.Arrays; import java.util.Map; public class TopicEventRequest { + // id identifies the event. Producers MUST ensure that source + id // is unique for each distinct event. If a duplicate event is re-sent // (e.g. due to a network error) it MAY have the same id. @@ -211,4 +213,19 @@ public Map getMetadata() { public void setMetadata(Map metadata) { this.metadata = metadata; } + + @Override + public String toString() { + return "TopicEventRequest{" + + "id='" + id + '\'' + + ", source='" + source + '\'' + + ", type='" + type + '\'' + + ", specVersion='" + specVersion + '\'' + + ", contentType='" + contentType + '\'' + + ", data=" + Arrays.toString(data) + + ", topic='" + topic + '\'' + + ", pubsubName='" + pubsubName + '\'' + + ", metadata=" + metadata + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponse.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponse.java similarity index 88% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponse.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponse.java index 13272da..89a8ecf 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponse.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponse.java @@ -15,6 +15,7 @@ package spec.sdk.runtime.v1.domain.pubsub; public class TopicEventResponse { + private TopicEventResponseStatus status; /** @@ -34,4 +35,11 @@ public TopicEventResponseStatus getStatus() { public void setStatus(TopicEventResponseStatus status) { this.status = status; } + + @Override + public String toString() { + return "TopicEventResponse{" + + "status=" + status + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponseStatus.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponseStatus.java similarity index 99% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponseStatus.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponseStatus.java index e59c760..bed3418 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponseStatus.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicEventResponseStatus.java @@ -16,6 +16,7 @@ // TopicEventResponseStatus allows apps to have finer control over handling of the message. public enum TopicEventResponseStatus { + // SUCCESS is the default behavior: message is acknowledged and not retried or logged. SUCCESS(0), // RETRY status signals runtime to retry the message as part of an expected scenario (no warning is logged). diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicSubscription.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicSubscription.java similarity index 90% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicSubscription.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicSubscription.java index dcd8603..2795b37 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicSubscription.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/pubsub/TopicSubscription.java @@ -17,6 +17,7 @@ import java.util.Map; public class TopicSubscription { + // Required. The name of the pubsub containing the topic below to subscribe to. private String pubsubName; @@ -79,4 +80,13 @@ public Map getMetadata() { public void setMetadata(Map metadata) { this.metadata = metadata; } + + @Override + public String toString() { + return "TopicSubscription{" + + "pubsubName='" + pubsubName + '\'' + + ", topic='" + topic + '\'' + + ", metadata=" + metadata + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/DeleteStateRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/DeleteStateRequest.java similarity index 83% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/state/DeleteStateRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/DeleteStateRequest.java index 3223b21..81aa9f2 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/DeleteStateRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/DeleteStateRequest.java @@ -64,8 +64,12 @@ public void setMetadata(Map metadata) { } public void putMetadata(String key, String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } + if (key == null) { + throw new java.lang.NullPointerException(); + } + if (value == null) { + throw new java.lang.NullPointerException(); + } if (metadata == null) { metadata = new HashMap<>(); } @@ -107,4 +111,15 @@ public StateOptions getStateOptions() { public void setStateOptions(StateOptions stateOptions) { this.stateOptions = stateOptions; } + + @Override + public String toString() { + return "DeleteStateRequest{" + + "stateStoreName='" + stateStoreName + '\'' + + ", key='" + key + '\'' + + ", metadata=" + metadata + + ", etag='" + etag + '\'' + + ", stateOptions=" + stateOptions + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/ExecuteStateTransactionRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/ExecuteStateTransactionRequest.java similarity index 83% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/state/ExecuteStateTransactionRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/ExecuteStateTransactionRequest.java index 0b21f4c..2a28a54 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/ExecuteStateTransactionRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/ExecuteStateTransactionRequest.java @@ -80,12 +80,24 @@ public void setMetadata(Map metadata) { } public void putMetadata(String key, String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } + if (key == null) { + throw new java.lang.NullPointerException(); + } + if (value == null) { + throw new java.lang.NullPointerException(); + } if (metadata == null) { metadata = new HashMap<>(); } metadata.put(key, value); } + @Override + public String toString() { + return "ExecuteStateTransactionRequest{" + + "stateStoreName='" + stateStoreName + '\'' + + ", operations=" + operations + + ", metadata=" + metadata + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/GetBulkStateRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/GetBulkStateRequest.java similarity index 84% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/state/GetBulkStateRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/GetBulkStateRequest.java index fed07d6..4af9e51 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/GetBulkStateRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/GetBulkStateRequest.java @@ -70,8 +70,12 @@ public void setMetadata(Map metadata) { } public void putMetadata(String key, String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } + if (key == null) { + throw new java.lang.NullPointerException(); + } + if (value == null) { + throw new java.lang.NullPointerException(); + } if (metadata == null) { metadata = new HashMap<>(); } @@ -95,4 +99,14 @@ public int getParallelism() { public void setParallelism(int parallelism) { this.parallelism = parallelism; } + + @Override + public String toString() { + return "GetBulkStateRequest{" + + "storeName='" + storeName + '\'' + + ", keys=" + keys + + ", metadata=" + metadata + + ", parallelism=" + parallelism + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/GetStateRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/GetStateRequest.java similarity index 82% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/state/GetStateRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/GetStateRequest.java index e6443c3..27ddbf2 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/GetStateRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/GetStateRequest.java @@ -62,8 +62,12 @@ public void setMetadata(Map metadata) { } public void putMetadata(String key, String value) { - if (key == null) { throw new java.lang.NullPointerException(); } - if (value == null) { throw new java.lang.NullPointerException(); } + if (key == null) { + throw new java.lang.NullPointerException(); + } + if (value == null) { + throw new java.lang.NullPointerException(); + } if (metadata == null) { metadata = new HashMap<>(); } @@ -87,4 +91,14 @@ public StateOptions getStateOptions() { public void setStateOptions(StateOptions stateOptions) { this.stateOptions = stateOptions; } + + @Override + public String toString() { + return "GetStateRequest{" + + "storeName='" + storeName + '\'' + + ", key='" + key + '\'' + + ", metadata=" + metadata + + ", stateOptions=" + stateOptions + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/SaveStateRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/SaveStateRequest.java similarity index 88% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/state/SaveStateRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/SaveStateRequest.java index 9885b85..e3075f8 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/SaveStateRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/SaveStateRequest.java @@ -50,4 +50,12 @@ public List> getStates() { public void setStates(List> states) { this.states = states; } + + @Override + public String toString() { + return "SaveStateRequest{" + + "storeName='" + storeName + '\'' + + ", states=" + states + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/State.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/State.java similarity index 94% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/state/State.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/State.java index 88c2619..6b05b81 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/State.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/State.java @@ -204,4 +204,16 @@ public StateOptions getOptions() { public String getError() { return error; } + + @Override + public String toString() { + return "State{" + + "key='" + key + '\'' + + ", value=" + value + + ", etag='" + etag + '\'' + + ", metadata=" + metadata + + ", error='" + error + '\'' + + ", options=" + options + + '}'; + } } diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/StateOptions.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/StateOptions.java similarity index 91% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/state/StateOptions.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/StateOptions.java index 97b9868..777f81d 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/StateOptions.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/StateOptions.java @@ -15,11 +15,13 @@ package spec.sdk.runtime.v1.domain.state; public class StateOptions { + private final Consistency consistency; private final Concurrency concurrency; /** * Represents options for a state API call. + * * @param consistency The consistency mode. * @param concurrency The concurrency mode. */ @@ -36,7 +38,16 @@ public Consistency getConsistency() { return consistency; } + @Override + public String toString() { + return "StateOptions{" + + "consistency=" + consistency + + ", concurrency=" + concurrency + + '}'; + } + public enum Consistency { + EVENTUAL("eventual"), STRONG("strong"); @@ -56,6 +67,7 @@ public static Consistency fromValue(String value) { } public enum Concurrency { + FIRST_WRITE("first-write"), LAST_WRITE("last-write"); diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateOperation.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateOperation.java similarity index 88% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateOperation.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateOperation.java index 05c3954..88eba26 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateOperation.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateOperation.java @@ -45,6 +45,14 @@ public State getRequest() { return request; } + @Override + public String toString() { + return "TransactionalStateOperation{" + + "operation=" + operation + + ", request=" + request + + '}'; + } + public enum OperationType { UPSERT, DELETE diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateRequest.java similarity index 90% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateRequest.java index fdd0bc7..7a0e3e9 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/state/TransactionalStateRequest.java @@ -58,4 +58,12 @@ public void putMetadata(String key, String value) { } metadata.put(key, value); } + + @Override + public String toString() { + return "TransactionalStateRequest{" + + "operations=" + operations + + ", metadata=" + metadata + + '}'; + } } diff --git a/sdk-grpc/pom.xml b/sdk-grpc/pom.xml new file mode 100644 index 0000000..8b15b85 --- /dev/null +++ b/sdk-grpc/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + + runtime-sdk-parent + io.mosn.layotto + 1.1.0-SNAPSHOT + + + runtime-sdk-grpc + runtime-sdk-grpc + grpc client for Runtime + jar + + + + io.mosn.layotto + runtime-spec-pb + + + io.mosn.layotto + runtime-sdk-domain + + + \ No newline at end of file diff --git a/sdk/src/main/java/io/mosn/layotto/v1/grpc/ExceptionHandler.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/ExceptionHandler.java similarity index 100% rename from sdk/src/main/java/io/mosn/layotto/v1/grpc/ExceptionHandler.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/ExceptionHandler.java diff --git a/sdk/src/main/java/io/mosn/layotto/v1/callback/GrpcAppCallbackImpl.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/GrpcAppCallbackImpl.java similarity index 93% rename from sdk/src/main/java/io/mosn/layotto/v1/callback/GrpcAppCallbackImpl.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/GrpcAppCallbackImpl.java index 3254c0d..a53989b 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/callback/GrpcAppCallbackImpl.java +++ b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/GrpcAppCallbackImpl.java @@ -12,13 +12,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.callback; +package io.mosn.layotto.v1.grpc.callback; import com.google.protobuf.Empty; import io.grpc.stub.StreamObserver; -import io.mosn.layotto.v1.callback.component.pubsub.Subscriber; -import io.mosn.layotto.v1.callback.component.pubsub.SubscriberRegistry; -import io.mosn.layotto.v1.grpc.PubsubConverter; +import io.mosn.layotto.v1.grpc.callback.component.pubsub.Subscriber; +import io.mosn.layotto.v1.grpc.callback.component.pubsub.SubscriberRegistry; +import io.mosn.layotto.v1.grpc.converter.PubsubConverter; import spec.proto.runtime.v1.AppCallbackGrpc; import spec.proto.runtime.v1.AppCallbackProto; import spec.sdk.runtime.v1.domain.pubsub.TopicEventResponse; diff --git a/sdk/src/main/java/io/mosn/layotto/v1/callback/component/Component.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/Component.java similarity index 92% rename from sdk/src/main/java/io/mosn/layotto/v1/callback/component/Component.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/Component.java index f105e03..07ebd71 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/callback/component/Component.java +++ b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/Component.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.callback.component; +package io.mosn.layotto.v1.grpc.callback.component; public interface Component { diff --git a/sdk/src/main/java/io/mosn/layotto/v1/callback/component/pubsub/Subscriber.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/pubsub/Subscriber.java similarity index 89% rename from sdk/src/main/java/io/mosn/layotto/v1/callback/component/pubsub/Subscriber.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/pubsub/Subscriber.java index 21e683d..746162a 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/callback/component/pubsub/Subscriber.java +++ b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/pubsub/Subscriber.java @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.callback.component.pubsub; +package io.mosn.layotto.v1.grpc.callback.component.pubsub; -import io.mosn.layotto.v1.callback.component.Component; +import io.mosn.layotto.v1.grpc.callback.component.Component; import spec.sdk.runtime.v1.domain.pubsub.TopicEventRequest; import spec.sdk.runtime.v1.domain.pubsub.TopicEventResponse; import spec.sdk.runtime.v1.domain.pubsub.TopicSubscription; diff --git a/sdk/src/main/java/io/mosn/layotto/v1/callback/component/pubsub/SubscriberRegistry.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/pubsub/SubscriberRegistry.java similarity index 93% rename from sdk/src/main/java/io/mosn/layotto/v1/callback/component/pubsub/SubscriberRegistry.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/pubsub/SubscriberRegistry.java index aaa36be..be705ab 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/callback/component/pubsub/SubscriberRegistry.java +++ b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/pubsub/SubscriberRegistry.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.callback.component.pubsub; +package io.mosn.layotto.v1.grpc.callback.component.pubsub; import java.util.Collection; diff --git a/sdk/src/main/java/io/mosn/layotto/v1/callback/component/pubsub/SubscriberRegistryImpl.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/pubsub/SubscriberRegistryImpl.java similarity index 97% rename from sdk/src/main/java/io/mosn/layotto/v1/callback/component/pubsub/SubscriberRegistryImpl.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/pubsub/SubscriberRegistryImpl.java index 155995b..729679c 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/callback/component/pubsub/SubscriberRegistryImpl.java +++ b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/callback/component/pubsub/SubscriberRegistryImpl.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.callback.component.pubsub; +package io.mosn.layotto.v1.grpc.callback.component.pubsub; import java.util.Collection; import java.util.HashSet; diff --git a/sdk/src/main/java/io/mosn/layotto/v1/grpc/PubsubConverter.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/converter/PubsubConverter.java similarity index 99% rename from sdk/src/main/java/io/mosn/layotto/v1/grpc/PubsubConverter.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/converter/PubsubConverter.java index 320cc44..93b1f4c 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/grpc/PubsubConverter.java +++ b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/converter/PubsubConverter.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.grpc; +package io.mosn.layotto.v1.grpc.converter; import com.google.protobuf.ByteString; import spec.proto.runtime.v1.AppCallbackProto; diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/ConfigurationRuntime.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/package-info.java similarity index 88% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/ConfigurationRuntime.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/package-info.java index 89ba2c7..9f57d34 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/ConfigurationRuntime.java +++ b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/package-info.java @@ -12,7 +12,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.runtime.v1.domain; - -public interface ConfigurationRuntime { -} +package io.mosn.layotto.v1.grpc; \ No newline at end of file diff --git a/sdk/src/main/java/io/mosn/layotto/v1/grpc/stub/PooledStubManager.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/stub/PooledStubManager.java similarity index 100% rename from sdk/src/main/java/io/mosn/layotto/v1/grpc/stub/PooledStubManager.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/stub/PooledStubManager.java diff --git a/sdk/src/main/java/io/mosn/layotto/v1/grpc/stub/RRPool.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/stub/RRPool.java similarity index 99% rename from sdk/src/main/java/io/mosn/layotto/v1/grpc/stub/RRPool.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/stub/RRPool.java index d0fea1b..03a9b66 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/grpc/stub/RRPool.java +++ b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/stub/RRPool.java @@ -23,6 +23,7 @@ * @param */ public class RRPool { + private final List stubs; private final RRIndex idx; diff --git a/sdk/src/main/java/io/mosn/layotto/v1/grpc/stub/SingleStubManager.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/stub/SingleStubManager.java similarity index 100% rename from sdk/src/main/java/io/mosn/layotto/v1/grpc/stub/SingleStubManager.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/stub/SingleStubManager.java diff --git a/sdk/src/main/java/io/mosn/layotto/v1/grpc/stub/StubCreator.java b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/stub/StubCreator.java similarity index 99% rename from sdk/src/main/java/io/mosn/layotto/v1/grpc/stub/StubCreator.java rename to sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/stub/StubCreator.java index 7b4a471..c2cb8ab 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/grpc/stub/StubCreator.java +++ b/sdk-grpc/src/main/java/io/mosn/layotto/v1/grpc/stub/StubCreator.java @@ -23,5 +23,4 @@ public interface StubCreator + + 4.0.0 + + + runtime-sdk-parent + io.mosn.layotto + 1.1.0-SNAPSHOT + + + runtime-sdk-infrastructure + runtime-sdk-infrastructure + infrastructure for Runtime + jar + + \ No newline at end of file diff --git a/sdk/src/main/java/io/mosn/layotto/v1/config/RuntimeProperties.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/config/RuntimeProperties.java similarity index 89% rename from sdk/src/main/java/io/mosn/layotto/v1/config/RuntimeProperties.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/config/RuntimeProperties.java index 4f09bad..d537a3b 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/config/RuntimeProperties.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/config/RuntimeProperties.java @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.config; +package io.mosn.layotto.v1.infrastructure.config; -import io.mosn.layotto.v1.domain.ApiProtocol; +import io.mosn.layotto.v1.infrastructure.value.ApiProtocol; -public class RuntimeProperties { +public final class RuntimeProperties { /** * Layotto Runtimes default use of GRPC. @@ -42,5 +42,4 @@ public class RuntimeProperties { * Layotto Runtimes default pubsub content type. */ public static final String DEFAULT_PUBSUB_CONTENT_TYPE = ""; - } diff --git a/sdk/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeClientException.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/exceptions/RuntimeClientException.java similarity index 98% rename from sdk/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeClientException.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/exceptions/RuntimeClientException.java index 92ebf6b..65fb7ed 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeClientException.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/exceptions/RuntimeClientException.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.exceptions; +package io.mosn.layotto.v1.infrastructure.exceptions; /** * A Runtime's specific exception. diff --git a/sdk/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeError.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/exceptions/RuntimeError.java similarity index 95% rename from sdk/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeError.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/exceptions/RuntimeError.java index ff2fe00..0240f3f 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeError.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/exceptions/RuntimeError.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.exceptions; +package io.mosn.layotto.v1.infrastructure.exceptions; public enum RuntimeError { ; diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/package-info.java similarity index 85% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/package-info.java index 30a4dbb..e870801 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/package-info.java @@ -12,8 +12,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.runtime.v1.domain.lock; - -public class TryLockResponse { - public boolean success; -} \ No newline at end of file +package io.mosn.layotto.v1.infrastructure; \ No newline at end of file diff --git a/sdk/src/main/java/io/mosn/layotto/v1/serializer/AbstractSerializer.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/serializer/AbstractSerializer.java similarity index 96% rename from sdk/src/main/java/io/mosn/layotto/v1/serializer/AbstractSerializer.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/serializer/AbstractSerializer.java index ad1da68..074ad4d 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/serializer/AbstractSerializer.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/serializer/AbstractSerializer.java @@ -12,11 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.serializer; +package io.mosn.layotto.v1.infrastructure.serializer; import java.io.IOException; public abstract class AbstractSerializer implements ObjectSerializer { + /** * {@inheritDoc} */ diff --git a/sdk/src/main/java/io/mosn/layotto/v1/serializer/ObjectSerializer.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/serializer/ObjectSerializer.java similarity index 96% rename from sdk/src/main/java/io/mosn/layotto/v1/serializer/ObjectSerializer.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/serializer/ObjectSerializer.java index db3950f..6af4f53 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/serializer/ObjectSerializer.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/serializer/ObjectSerializer.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.serializer; +package io.mosn.layotto.v1.infrastructure.serializer; import java.io.IOException; diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/utils/NetworkUtils.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/utils/NetworkUtils.java similarity index 96% rename from sdk-reactor/src/main/java/io/mosn/layotto/v1/utils/NetworkUtils.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/utils/NetworkUtils.java index 4faa324..c6fed75 100644 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/utils/NetworkUtils.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/utils/NetworkUtils.java @@ -12,14 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.utils; +package io.mosn.layotto.v1.infrastructure.utils; import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; /** - * Utility methods for network, internal to Dapr SDK. + * Utility methods for network, internal to Layotto SDK. */ public final class NetworkUtils { diff --git a/sdk/src/main/java/io/mosn/layotto/v1/domain/ApiProtocol.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/value/ApiProtocol.java similarity index 93% rename from sdk/src/main/java/io/mosn/layotto/v1/domain/ApiProtocol.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/value/ApiProtocol.java index a194d33..c3e98ee 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/domain/ApiProtocol.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/value/ApiProtocol.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.domain; +package io.mosn.layotto.v1.infrastructure.value; /** * Transport protocol for Runtime API. diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/value/Headers.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/value/Headers.java similarity index 95% rename from sdk-reactor/src/main/java/io/mosn/layotto/v1/value/Headers.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/value/Headers.java index c8b9cde..66f027e 100644 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/value/Headers.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/infrastructure/value/Headers.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.value; +package io.mosn.layotto.v1.infrastructure.value; /** * Common headers for GRPC and HTTP communication. diff --git a/sdk-reactor/pom.xml b/sdk-reactor/pom.xml index ae43a86..60ca179 100644 --- a/sdk-reactor/pom.xml +++ b/sdk-reactor/pom.xml @@ -11,43 +11,52 @@ runtime-sdk-reactor - runtime-sdk-reactor reactor-style SDK for Runtime jar + + 6.0.53 + 4.9.3 + 2.13.0 + + io.mosn.layotto - runtime-spec-pb + runtime-sdk-grpc - org.slf4j - slf4j-api + io.mosn.layotto + runtime-sdk-domain-rx + - io.projectreactor - reactor-core - 3.3.11.RELEASE + org.slf4j + slf4j-api + com.fasterxml.jackson.core jackson-databind - 2.11.3 + ${jackson-databind.version} + com.squareup.okhttp3 okhttp - 4.9.0 + ${okhttp.version} + org.apache.tomcat annotations-api - 6.0.53 + ${annotations-api.version} provided + diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/AbstractLayottoReactorClient.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/AbstractLayottoReactorClient.java deleted file mode 100644 index bca2ae6..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/AbstractLayottoReactorClient.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.client.reactor; - -import io.mosn.layotto.v1.serializer.LayottoObjectSerializer; -import reactor.core.publisher.Mono; -import spec.sdk.reactor.v1.domain.core.invocation.HttpExtension; -import spec.sdk.reactor.v1.domain.core.invocation.InvokeMethodRequest; -import spec.sdk.reactor.v1.domain.core.pubsub.PublishEventRequest; -import spec.sdk.reactor.v1.domain.core.state.DeleteStateRequest; -import spec.sdk.reactor.v1.domain.core.state.ExecuteStateTransactionRequest; -import spec.sdk.reactor.v1.domain.core.state.GetBulkStateRequest; -import spec.sdk.reactor.v1.domain.core.state.GetStateRequest; -import spec.sdk.reactor.v1.domain.core.state.SaveStateRequest; -import spec.sdk.reactor.v1.domain.core.state.State; -import spec.sdk.reactor.v1.domain.core.state.StateOptions; -import spec.sdk.reactor.v1.domain.core.state.TransactionalStateOperation; -import spec.sdk.reactor.v1.utils.TypeRef; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -abstract class AbstractLayottoReactorClient implements LayottoReactorClient { - - /** - * A utility class for serialize and deserialize the transient objects. - */ - protected LayottoObjectSerializer objectSerializer; - - /** - * A utility class for serialize and deserialize state objects. - */ - protected LayottoObjectSerializer stateSerializer; - - /** - * Common constructor for implementations of this class. - * - * @param objectSerializer Serializer for transient request/response objects. - * @param stateSerializer Serializer for state objects. - */ - AbstractLayottoReactorClient(LayottoObjectSerializer objectSerializer, - LayottoObjectSerializer stateSerializer) { - this.objectSerializer = objectSerializer; - this.stateSerializer = stateSerializer; - } - - /** - * {@inheritDoc} - */ - @Override - public Mono publishEvent(String pubsubName, String topicName, Object data) { - return this.publishEvent(pubsubName, topicName, data, null); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono publishEvent(String pubsubName, String topicName, Object data, Map metadata) { - PublishEventRequest req = new PublishEventRequest(pubsubName, topicName, data) - .setMetadata(metadata); - return this.publishEvent(req).then(); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono invokeMethod(String appId, - String methodName, - Object data, - HttpExtension httpExtension, - Map metadata, - TypeRef type) { - InvokeMethodRequest req = new InvokeMethodRequest(appId, methodName) - .setBody(data) - .setHttpExtension(httpExtension) - .setContentType(objectSerializer.getContentType()); - return this.invokeMethod(req, type); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono invokeMethod(String appId, - String methodName, - Object request, - HttpExtension httpExtension, - Map metadata, - Class clazz) { - return this.invokeMethod(appId, methodName, request, httpExtension, metadata, TypeRef.get(clazz)); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono invokeMethod(String appId, String methodName, HttpExtension httpExtension, - Map metadata, TypeRef type) { - return this.invokeMethod(appId, methodName, null, httpExtension, metadata, type); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono invokeMethod(String appId, String methodName, HttpExtension httpExtension, - Map metadata, Class clazz) { - return this.invokeMethod(appId, methodName, null, httpExtension, metadata, TypeRef.get(clazz)); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - TypeRef type) { - return this.invokeMethod(appId, methodName, request, httpExtension, null, type); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - Class clazz) { - return this.invokeMethod(appId, methodName, request, httpExtension, null, TypeRef.get(clazz)); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension) { - return this.invokeMethod(appId, methodName, request, httpExtension, null, TypeRef.BYTE_ARRAY).then(); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - Map metadata) { - return this.invokeMethod(appId, methodName, request, httpExtension, metadata, TypeRef.BYTE_ARRAY).then(); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono invokeMethod(String appId, String methodName, HttpExtension httpExtension, - Map metadata) { - return this.invokeMethod(appId, methodName, null, httpExtension, metadata, TypeRef.BYTE_ARRAY).then(); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono invokeMethod(String appId, String methodName, byte[] request, HttpExtension httpExtension, - Map metadata) { - return this.invokeMethod(appId, methodName, request, httpExtension, metadata, TypeRef.BYTE_ARRAY); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono> getState(String storeName, State state, TypeRef type) { - return this.getState(storeName, state.getKey(), state.getOptions(), type); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono> getState(String storeName, State state, Class clazz) { - return this.getState(storeName, state.getKey(), state.getOptions(), TypeRef.get(clazz)); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono> getState(String storeName, String key, TypeRef type) { - return this.getState(storeName, key, null, type); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono> getState(String storeName, String key, Class clazz) { - return this.getState(storeName, key, null, TypeRef.get(clazz)); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono> getState(String storeName, String key, StateOptions options, TypeRef type) { - GetStateRequest request = new GetStateRequest(storeName, key) - .setStateOptions(options); - return this.getState(request, type); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono> getState(String storeName, String key, StateOptions options, Class clazz) { - return this.getState(storeName, key, options, TypeRef.get(clazz)); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono>> getBulkState(String storeName, List keys, TypeRef type) { - return this.getBulkState(new GetBulkStateRequest(storeName, keys), type); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono>> getBulkState(String storeName, List keys, Class clazz) { - return this.getBulkState(storeName, keys, TypeRef.get(clazz)); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono executeStateTransaction(String storeName, List> operations) { - ExecuteStateTransactionRequest request = new ExecuteStateTransactionRequest(storeName) - .setOperations(operations); - return executeStateTransaction(request).then(); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono saveBulkState(String storeName, List> states) { - SaveStateRequest request = new SaveStateRequest(storeName) - .setStates(states); - return this.saveBulkState(request).then(); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono saveState(String storeName, String key, Object value) { - return this.saveState(storeName, key, null, value, null); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono saveState(String storeName, String key, String etag, Object value, StateOptions options) { - State state = new State<>(key, value, etag, options); - return this.saveBulkState(storeName, Collections.singletonList(state)); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono deleteState(String storeName, String key) { - return this.deleteState(storeName, key, null, null); - } - - /** - * {@inheritDoc} - */ - @Override - public Mono deleteState(String storeName, String key, String etag, StateOptions options) { - DeleteStateRequest request = new DeleteStateRequest(storeName, key) - .setEtag(etag) - .setStateOptions(options); - return deleteState(request).then(); - } -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/LayottoReactorClient.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/LayottoReactorClient.java deleted file mode 100644 index dc8ea27..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/LayottoReactorClient.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.client.reactor; - -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import spec.sdk.reactor.v1.client.CloudRuntimesClient; -import spec.sdk.reactor.v1.domain.core.configuration.ConfigurationItem; -import spec.sdk.reactor.v1.domain.core.configuration.ConfigurationRequestItem; -import spec.sdk.reactor.v1.domain.core.configuration.SaveConfigurationRequest; -import spec.sdk.reactor.v1.domain.core.configuration.SubConfigurationResp; -import spec.sdk.reactor.v1.domain.core.invocation.HttpExtension; -import spec.sdk.reactor.v1.domain.core.invocation.InvokeMethodRequest; -import spec.sdk.reactor.v1.domain.core.pubsub.PublishEventRequest; -import spec.sdk.reactor.v1.domain.core.state.DeleteStateRequest; -import spec.sdk.reactor.v1.domain.core.state.ExecuteStateTransactionRequest; -import spec.sdk.reactor.v1.domain.core.state.GetBulkStateRequest; -import spec.sdk.reactor.v1.domain.core.state.GetStateRequest; -import spec.sdk.reactor.v1.domain.core.state.SaveStateRequest; -import spec.sdk.reactor.v1.domain.core.state.State; -import spec.sdk.reactor.v1.domain.core.state.StateOptions; -import spec.sdk.reactor.v1.domain.core.state.TransactionalStateOperation; -import spec.sdk.reactor.v1.utils.TypeRef; - -import java.util.List; -import java.util.Map; - -public interface LayottoReactorClient extends CloudRuntimesClient { - - @Override - Mono waitForSidecar(int timeoutInMilliseconds); - - @Override - Mono shutdown(); - - @Override - void close() throws Exception; - - @Override - Mono>> getConfiguration(ConfigurationRequestItem configurationRequestItem, - TypeRef type); - - @Override - Mono saveConfiguration(SaveConfigurationRequest saveConfigurationRequest); - - @Override - Mono deleteConfiguration(ConfigurationRequestItem configurationRequestItem); - - @Override - Flux> subscribeConfiguration(ConfigurationRequestItem configurationRequestItem, - TypeRef type); - - @Override - Mono invokeMethod(String appId, String methodName, Object data, HttpExtension httpExtension, - Map metadata, TypeRef type); - - @Override - Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - Map metadata, Class clazz); - - @Override - Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - TypeRef type); - - @Override - Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - Class clazz); - - @Override - Mono invokeMethod(String appId, String methodName, HttpExtension httpExtension, - Map metadata, TypeRef type); - - @Override - Mono invokeMethod(String appId, String methodName, HttpExtension httpExtension, - Map metadata, Class clazz); - - @Override - Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - Map metadata); - - @Override - Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension); - - @Override - Mono invokeMethod(String appId, String methodName, HttpExtension httpExtension, Map metadata); - - @Override - Mono invokeMethod(String appId, String methodName, byte[] request, HttpExtension httpExtension, - Map metadata); - - @Override - Mono invokeMethod(InvokeMethodRequest invokeMethodRequest, TypeRef type); - - @Override - Mono publishEvent(String pubsubName, String topicName, Object data); - - @Override - Mono publishEvent(String pubsubName, String topicName, Object data, Map metadata); - - @Override - Mono publishEvent(PublishEventRequest request); - - @Override - Mono> getState(String storeName, State state, TypeRef type); - - @Override - Mono> getState(String storeName, State state, Class clazz); - - @Override - Mono> getState(String storeName, String key, TypeRef type); - - @Override - Mono> getState(String storeName, String key, Class clazz); - - @Override - Mono> getState(String storeName, String key, StateOptions options, TypeRef type); - - @Override - Mono> getState(String storeName, String key, StateOptions options, Class clazz); - - @Override - Mono> getState(GetStateRequest request, TypeRef type); - - @Override - Mono>> getBulkState(String storeName, List keys, TypeRef type); - - @Override - Mono>> getBulkState(String storeName, List keys, Class clazz); - - @Override - Mono>> getBulkState(GetBulkStateRequest request, TypeRef type); - - @Override - Mono executeStateTransaction(String storeName, List> operations); - - @Override - Mono executeStateTransaction(ExecuteStateTransactionRequest request); - - @Override - Mono saveBulkState(String storeName, List> states); - - @Override - Mono saveBulkState(SaveStateRequest request); - - @Override - Mono saveState(String storeName, String key, Object value); - - @Override - Mono saveState(String storeName, String key, String etag, Object value, StateOptions options); - - @Override - Mono deleteState(String storeName, String key); - - @Override - Mono deleteState(String storeName, String key, String etag, StateOptions options); - - @Override - Mono deleteState(DeleteStateRequest request); -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/LayottoReactorClientGrpc.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/LayottoReactorClientGrpc.java deleted file mode 100644 index 996502c..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/LayottoReactorClientGrpc.java +++ /dev/null @@ -1,624 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.client.reactor; - -import com.google.common.base.Strings; -import com.google.protobuf.Any; -import com.google.protobuf.ByteString; -import com.google.protobuf.Empty; -import io.grpc.CallOptions; -import io.grpc.Channel; -import io.grpc.ClientCall; -import io.grpc.ClientInterceptor; -import io.grpc.ForwardingClientCall; -import io.grpc.Metadata; -import io.grpc.MethodDescriptor; -import io.grpc.stub.StreamObserver; -import io.mosn.layotto.v1.config.Properties; -import io.mosn.layotto.v1.exceptions.LayottoException; -import io.mosn.layotto.v1.serializer.LayottoObjectSerializer; -import io.mosn.layotto.v1.utils.GrpcWrapper; -import io.mosn.layotto.v1.utils.NetworkUtils; -import io.mosn.layotto.v1.value.Headers; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.core.publisher.MonoSink; -import reactor.util.context.Context; -import spec.proto.runtime.v1.RuntimeGrpc; -import spec.proto.runtime.v1.RuntimeProto; -import spec.sdk.reactor.v1.domain.core.configuration.ConfigurationItem; -import spec.sdk.reactor.v1.domain.core.configuration.ConfigurationRequestItem; -import spec.sdk.reactor.v1.domain.core.configuration.SaveConfigurationRequest; -import spec.sdk.reactor.v1.domain.core.configuration.SubConfigurationResp; -import spec.sdk.reactor.v1.domain.core.invocation.HttpExtension; -import spec.sdk.reactor.v1.domain.core.invocation.InvokeMethodRequest; -import spec.sdk.reactor.v1.domain.core.pubsub.PublishEventRequest; -import spec.sdk.reactor.v1.domain.core.state.DeleteStateRequest; -import spec.sdk.reactor.v1.domain.core.state.ExecuteStateTransactionRequest; -import spec.sdk.reactor.v1.domain.core.state.GetBulkStateRequest; -import spec.sdk.reactor.v1.domain.core.state.GetStateRequest; -import spec.sdk.reactor.v1.domain.core.state.SaveStateRequest; -import spec.sdk.reactor.v1.domain.core.state.State; -import spec.sdk.reactor.v1.domain.core.state.StateOptions; -import spec.sdk.reactor.v1.domain.core.state.TransactionalStateOperation; -import spec.sdk.reactor.v1.utils.TypeRef; - -import java.io.Closeable; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.function.Consumer; -import java.util.stream.Collectors; - -public class LayottoReactorClientGrpc extends AbstractLayottoReactorClient { - - /** - * The GRPC managed channel to be used. - */ - private final Closeable channel; - - /** - * The async gRPC stub. - */ - private final RuntimeGrpc.RuntimeStub asyncStub; - - /** - * Default access level constructor, in order to create an instance of this class. - * - * @param closeableChannel A closeable for a Managed GRPC channel - * @param asyncStub async gRPC stub - */ - LayottoReactorClientGrpc(LayottoObjectSerializer objectSerializer, - LayottoObjectSerializer stateSerializer, - Closeable closeableChannel, - RuntimeGrpc.RuntimeStub asyncStub) { - super(objectSerializer, stateSerializer); - this.channel = closeableChannel; - this.asyncStub = intercept(asyncStub); - } - - @Override - public Mono>> getConfiguration(ConfigurationRequestItem configurationRequestItem, - TypeRef type) { - // TODO: 2021/9/26 - return null; - } - - @Override - public Mono saveConfiguration(SaveConfigurationRequest saveConfigurationRequest) { - // TODO: 2021/9/26 - return null; - } - - @Override - public Mono deleteConfiguration(ConfigurationRequestItem configurationRequestItem) { - // TODO: 2021/9/26 - return null; - } - - @Override - public Flux> subscribeConfiguration(ConfigurationRequestItem configurationRequestItem, - TypeRef type) { - // TODO: 2021/9/26 - return null; - } - - @Override - public Mono invokeMethod(InvokeMethodRequest invokeMethodRequest, TypeRef type) { - try { - String appId = invokeMethodRequest.getAppId(); - String method = invokeMethodRequest.getMethod(); - Object body = invokeMethodRequest.getBody(); - HttpExtension httpExtension = invokeMethodRequest.getHttpExtension(); - RuntimeProto.InvokeServiceRequest envelope = this.buildInvokeServiceRequest( - httpExtension, - appId, - method, - body); - // Regarding missing metadata in method invocation for gRPC: - // gRPC to gRPC does not handle metadata in Layotto runtime proto. - // gRPC to HTTP does not map correctly in Layotto runtime as per https://github.com/layotto/layotto/issues/2342 - - return Mono.subscriberContext().flatMap( - context -> this.createMono( - it -> intercept(context, asyncStub).invokeService(envelope, it) - ) - ).flatMap( - it -> { - try { - return Mono.justOrEmpty(objectSerializer.deserialize(it.getData().getValue().toByteArray(), type)); - } catch (IOException e) { - throw LayottoException.propagate(e); - } - } - ); - } catch (Exception ex) { - return LayottoException.wrapMono(ex); - } - } - - @Override - public Mono publishEvent(PublishEventRequest request) { - try { - String pubsubName = request.getPubsubName(); - String topic = request.getTopic(); - Object data = request.getData(); - RuntimeProto.PublishEventRequest.Builder envelopeBuilder = RuntimeProto.PublishEventRequest.newBuilder() - .setTopic(topic) - .setPubsubName(pubsubName) - .setData(ByteString.copyFrom(objectSerializer.serialize(data))); - - // Content-type can be overwritten on a per-request basis. - // It allows CloudEvents to be handled differently, for example. - String contentType = request.getContentType(); - if (contentType == null || contentType.isEmpty()) { - contentType = objectSerializer.getContentType(); - } - envelopeBuilder.setDataContentType(contentType); - - Map metadata = request.getMetadata(); - if (metadata != null) { - envelopeBuilder.putAllMetadata(metadata); - } - - return Mono.subscriberContext().flatMap( - context -> - this.createMono( - it -> intercept(context, asyncStub).publishEvent(envelopeBuilder.build(), it) - ) - ).then(); - } catch (Exception ex) { - return LayottoException.wrapMono(ex); - } - } - - @Override - public Mono> getState(GetStateRequest request, TypeRef type) { - try { - final String stateStoreName = request.getStoreName(); - final String key = request.getKey(); - final StateOptions options = request.getStateOptions(); - final Map metadata = request.getMetadata(); - - if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { - throw new IllegalArgumentException("State store name cannot be null or empty."); - } - if ((key == null) || (key.trim().isEmpty())) { - throw new IllegalArgumentException("Key cannot be null or empty."); - } - RuntimeProto.GetStateRequest.Builder builder = RuntimeProto.GetStateRequest.newBuilder() - .setStoreName(stateStoreName) - .setKey(key); - if (metadata != null) { - builder.putAllMetadata(metadata); - } - if (options != null && options.getConsistency() != null) { - builder.setConsistency(getGrpcStateConsistency(options)); - } - - RuntimeProto.GetStateRequest envelope = builder.build(); - - return Mono.subscriberContext().flatMap( - context -> - this.createMono( - it -> intercept(context, asyncStub).getState(envelope, it) - ) - ).map( - it -> { - try { - return buildStateKeyValue(it, key, options, type); - } catch (IOException ex) { - throw LayottoException.propagate(ex); - } - } - ); - } catch (Exception ex) { - return LayottoException.wrapMono(ex); - } - } - - @Override - public Mono>> getBulkState(GetBulkStateRequest request, TypeRef type) { - try { - final String stateStoreName = request.getStoreName(); - final List keys = request.getKeys(); - final int parallelism = request.getParallelism(); - final Map metadata = request.getMetadata(); - if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { - throw new IllegalArgumentException("State store name cannot be null or empty."); - } - if (keys == null || keys.isEmpty()) { - throw new IllegalArgumentException("Key cannot be null or empty."); - } - - if (parallelism < 0) { - throw new IllegalArgumentException("Parallelism cannot be negative."); - } - RuntimeProto.GetBulkStateRequest.Builder builder = RuntimeProto.GetBulkStateRequest.newBuilder() - .setStoreName(stateStoreName) - .addAllKeys(keys) - .setParallelism(parallelism); - if (metadata != null) { - builder.putAllMetadata(metadata); - } - - RuntimeProto.GetBulkStateRequest envelope = builder.build(); - - return Mono.subscriberContext().flatMap( - context -> this.createMono(it -> intercept(context, asyncStub) - .getBulkState(envelope, it) - ) - ).map( - it -> - it - .getItemsList() - .stream() - .map(b -> { - try { - return buildStateKeyValue(b, type); - } catch (Exception e) { - throw LayottoException.propagate(e); - } - }) - .collect(Collectors.toList()) - ); - } catch (Exception ex) { - return LayottoException.wrapMono(ex); - } - } - - @Override - public Mono executeStateTransaction(ExecuteStateTransactionRequest request) { - try { - final String stateStoreName = request.getStateStoreName(); - final List> operations = request.getOperations(); - final Map metadata = request.getMetadata(); - if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { - throw new IllegalArgumentException("State store name cannot be null or empty."); - } - RuntimeProto.ExecuteStateTransactionRequest.Builder builder = RuntimeProto.ExecuteStateTransactionRequest - .newBuilder(); - builder.setStoreName(stateStoreName); - if (metadata != null) { - builder.putAllMetadata(metadata); - } - for (TransactionalStateOperation operation : operations) { - RuntimeProto.TransactionalStateOperation.Builder operationBuilder = RuntimeProto.TransactionalStateOperation - .newBuilder(); - operationBuilder.setOperationType(operation.getOperation().toString().toLowerCase()); - operationBuilder.setRequest(buildStateRequest(operation.getRequest()).build()); - builder.addOperations(operationBuilder.build()); - } - RuntimeProto.ExecuteStateTransactionRequest req = builder.build(); - - return Mono.subscriberContext().flatMap( - context -> this.createMono(it -> intercept(context, asyncStub).executeStateTransaction(req, it)) - ).then(); - } catch (Exception e) { - return LayottoException.wrapMono(e); - } - } - - @Override - public Mono saveBulkState(SaveStateRequest request) { - try { - final String stateStoreName = request.getStoreName(); - final List> states = request.getStates(); - if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { - throw new IllegalArgumentException("State store name cannot be null or empty."); - } - RuntimeProto.SaveStateRequest.Builder builder = RuntimeProto.SaveStateRequest.newBuilder(); - builder.setStoreName(stateStoreName); - for (State state : states) { - builder.addStates(buildStateRequest(state).build()); - } - RuntimeProto.SaveStateRequest req = builder.build(); - - return Mono.subscriberContext().flatMap( - context -> this.createMono(it -> intercept(context, asyncStub).saveState(req, it)) - ).then(); - } catch (Exception ex) { - return LayottoException.wrapMono(ex); - } - } - - @Override - public Mono deleteState(DeleteStateRequest request) { - try { - final String stateStoreName = request.getStateStoreName(); - final String key = request.getKey(); - final StateOptions options = request.getStateOptions(); - final String etag = request.getEtag(); - final Map metadata = request.getMetadata(); - - if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { - throw new IllegalArgumentException("State store name cannot be null or empty."); - } - if ((key == null) || (key.trim().isEmpty())) { - throw new IllegalArgumentException("Key cannot be null or empty."); - } - - RuntimeProto.StateOptions.Builder optionBuilder = null; - if (options != null) { - optionBuilder = RuntimeProto.StateOptions.newBuilder(); - if (options.getConcurrency() != null) { - optionBuilder.setConcurrency(getGrpcStateConcurrency(options)); - } - if (options.getConsistency() != null) { - optionBuilder.setConsistency(getGrpcStateConsistency(options)); - } - } - RuntimeProto.DeleteStateRequest.Builder builder = RuntimeProto.DeleteStateRequest.newBuilder() - .setStoreName(stateStoreName) - .setKey(key); - if (metadata != null) { - builder.putAllMetadata(metadata); - } - if (etag != null) { - builder.setEtag(RuntimeProto.Etag.newBuilder().setValue(etag).build()); - } - - if (optionBuilder != null) { - builder.setOptions(optionBuilder.build()); - } - - RuntimeProto.DeleteStateRequest req = builder.build(); - - return Mono.subscriberContext().flatMap( - context -> this.createMono(it -> intercept(context, asyncStub).deleteState(req, it)) - ).then(); - } catch (Exception ex) { - return LayottoException.wrapMono(ex); - } - } - - /** - * Builds the object io.layotto.{@link RuntimeProto.InvokeServiceRequest} to be send based on the parameters. - * - * @param httpExtension Object for HttpExtension - * @param appId The application id to be invoked - * @param method The application method to be invoked - * @param body The body of the request to be send as part of the invocation - * @param The Type of the Body - * @return The object to be sent as part of the invocation. - * @throws IOException If there's an issue serializing the request. - */ - private RuntimeProto.InvokeServiceRequest buildInvokeServiceRequest( - HttpExtension httpExtension, - String appId, - String method, - K body) throws IOException { - if (httpExtension == null) { - throw new IllegalArgumentException("HttpExtension cannot be null. Use HttpExtension.NONE instead."); - } - RuntimeProto.CommonInvokeRequest.Builder requestBuilder = RuntimeProto.CommonInvokeRequest.newBuilder(); - requestBuilder.setMethod(method); - if (body != null) { - byte[] byteRequest = objectSerializer.serialize(body); - Any data = Any.newBuilder().setValue(ByteString.copyFrom(byteRequest)).build(); - requestBuilder.setData(data); - } else { - requestBuilder.setData(Any.newBuilder().build()); - } - RuntimeProto.HTTPExtension.Builder httpExtensionBuilder = RuntimeProto.HTTPExtension.newBuilder(); - - httpExtensionBuilder.setVerb(RuntimeProto.HTTPExtension.Verb.valueOf(httpExtension.getMethod().toString())) - .setQuerystring(httpExtension.encodeQueryString()); - requestBuilder.setHttpExtension(httpExtensionBuilder.build()); - - requestBuilder.setContentType(objectSerializer.getContentType()); - - RuntimeProto.InvokeServiceRequest.Builder envelopeBuilder = RuntimeProto.InvokeServiceRequest.newBuilder() - .setId(appId) - .setMessage(requestBuilder.build()); - return envelopeBuilder.build(); - } - - private State buildStateKeyValue( - RuntimeProto.BulkStateItem item, - TypeRef type) throws IOException { - String key = item.getKey(); - String error = item.getError(); - if (!Strings.isNullOrEmpty(error)) { - return new State<>(key, error); - } - - ByteString payload = item.getData(); - byte[] data = payload == null ? null : payload.toByteArray(); - T value = stateSerializer.deserialize(data, type); - String etag = item.getEtag(); - if (etag.equals("")) { - etag = null; - } - return new State<>(key, value, etag, item.getMetadataMap(), null); - } - - private State buildStateKeyValue( - RuntimeProto.GetStateResponse response, - String requestedKey, - StateOptions stateOptions, - TypeRef type) throws IOException { - ByteString payload = response.getData(); - byte[] data = payload == null ? null : payload.toByteArray(); - T value = stateSerializer.deserialize(data, type); - String etag = response.getEtag(); - if (etag.equals("")) { - etag = null; - } - return new State<>(requestedKey, value, etag, response.getMetadataMap(), stateOptions); - } - - private RuntimeProto.StateItem.Builder buildStateRequest(State state) throws IOException { - byte[] bytes = stateSerializer.serialize(state.getValue()); - - RuntimeProto.StateItem.Builder stateBuilder = RuntimeProto.StateItem.newBuilder(); - if (state.getEtag() != null) { - stateBuilder.setEtag(RuntimeProto.Etag.newBuilder().setValue(state.getEtag()).build()); - } - if (state.getMetadata() != null) { - stateBuilder.putAllMetadata(state.getMetadata()); - } - if (bytes != null) { - stateBuilder.setValue(ByteString.copyFrom(bytes)); - } - stateBuilder.setKey(state.getKey()); - RuntimeProto.StateOptions.Builder optionBuilder = null; - if (state.getOptions() != null) { - StateOptions options = state.getOptions(); - optionBuilder = RuntimeProto.StateOptions.newBuilder(); - if (options.getConcurrency() != null) { - optionBuilder.setConcurrency(getGrpcStateConcurrency(options)); - } - if (options.getConsistency() != null) { - optionBuilder.setConsistency(getGrpcStateConsistency(options)); - } - } - if (optionBuilder != null) { - stateBuilder.setOptions(optionBuilder.build()); - } - return stateBuilder; - } - - private RuntimeProto.StateOptions.StateConsistency getGrpcStateConsistency(StateOptions options) { - switch (options.getConsistency()) { - case EVENTUAL: - return RuntimeProto.StateOptions.StateConsistency.CONSISTENCY_EVENTUAL; - case STRONG: - return RuntimeProto.StateOptions.StateConsistency.CONSISTENCY_STRONG; - default: - throw new IllegalArgumentException("Missing Consistency mapping to gRPC Consistency enum"); - } - } - - private RuntimeProto.StateOptions.StateConcurrency getGrpcStateConcurrency(StateOptions options) { - switch (options.getConcurrency()) { - case FIRST_WRITE: - return RuntimeProto.StateOptions.StateConcurrency.CONCURRENCY_FIRST_WRITE; - case LAST_WRITE: - return RuntimeProto.StateOptions.StateConcurrency.CONCURRENCY_LAST_WRITE; - default: - throw new IllegalArgumentException("Missing StateConcurrency mapping to gRPC Concurrency enum"); - } - } - - // -- Lifecycle Functions - - @Override - public Mono waitForSidecar(int timeoutInMilliseconds) { - return Mono.fromRunnable(() -> { - try { - NetworkUtils.waitForSocket(Properties.SIDECAR_IP.get(), Properties.GRPC_PORT.get(), timeoutInMilliseconds); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - }); - } - - @Override - public Mono shutdown() { - return Mono.subscriberContext() - // FIXME: 2021/9/26 Refer to Dapr - // .flatMap(context -> - // this.createMono(it -> - // intercept(context, asyncStub) - // .shutdown(Empty.getDefaultInstance(), it))) - .then(); - } - - private Mono createMono(Consumer> consumer) { - return Mono.create(sink -> - LayottoException - .wrap(() -> consumer.accept(createStreamObserver(sink))) - .run()); - } - - private StreamObserver createStreamObserver(MonoSink sink) { - return new StreamObserver() { - @Override - public void onNext(T value) { - sink.success(value); - } - - @Override - public void onError(Throwable t) { - sink.error(LayottoException.propagate(new ExecutionException(t))); - } - - @Override - public void onCompleted() { - sink.success(); - } - }; - } - - /** - * Closes the ManagedChannel for GRPC. - * - * @throws IOException on exception. - * @see io.grpc.ManagedChannel#shutdown() - */ - @Override - public void close() throws Exception { - if (channel != null) { - LayottoException - .wrap(() -> { - channel.close(); - return true; - }) - .call(); - } - } - - /** - * Populates GRPC client with interceptors for telemetry. - * - * @param context Reactor's context. - * @param client GRPC client for Layotto. - * @return Client after adding interceptors. - */ - private static RuntimeGrpc.RuntimeStub intercept(Context context, RuntimeGrpc.RuntimeStub client) { - return GrpcWrapper.intercept(context, client); - } - - /** - * Populates GRPC client with interceptors. - * - * @param client GRPC client for Layotto. - * @return Client after adding interceptors. - */ - private static RuntimeGrpc.RuntimeStub intercept(RuntimeGrpc.RuntimeStub client) { - ClientInterceptor interceptor = new ClientInterceptor() { - @Override - public ClientCall interceptCall(MethodDescriptor methodDescriptor, - CallOptions callOptions, - Channel channel) { - ClientCall clientCall = channel.newCall(methodDescriptor, callOptions); - return new ForwardingClientCall.SimpleForwardingClientCall(clientCall) { - @Override - public void start(final Listener responseListener, final Metadata metadata) { - String layottoApiToken = Properties.API_TOKEN.get(); - if (layottoApiToken != null) { - metadata.put(Metadata.Key.of(Headers.DAPR_API_TOKEN, Metadata.ASCII_STRING_MARSHALLER), - layottoApiToken); - } - super.start(responseListener, metadata); - } - }; - } - }; - return client.withInterceptors(interceptor); - } -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/GenericProperty.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/GenericProperty.java deleted file mode 100644 index 3c060b0..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/GenericProperty.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.config; - -import java.util.function.Function; - -/** - * Configuration property for any type. - */ -public class GenericProperty extends Property { - - private final Function parser; - - /** - * {@inheritDoc} - */ - GenericProperty(String name, String envName, T defaultValue, Function parser) { - super(name, envName, defaultValue); - this.parser = parser; - } - - /** - * {@inheritDoc} - */ - @Override - protected T parse(String value) { - return parser.apply(value); - } -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/IntegerProperty.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/IntegerProperty.java deleted file mode 100644 index 8eb6e0b..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/IntegerProperty.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.config; - -/** - * Integer configuration property. - */ -public class IntegerProperty extends Property { - - /** - * {@inheritDoc} - */ - IntegerProperty(String name, String envName, Integer defaultValue) { - super(name, envName, defaultValue); - } - - /** - * {@inheritDoc} - */ - @Override - protected Integer parse(String value) { - return Integer.valueOf(value); - } -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/Properties.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/Properties.java deleted file mode 100644 index 78b0caa..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/Properties.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.config; - - -import io.mosn.layotto.v1.value.LayottoApiProtocol; - -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -/** - * Global properties for Layotto's SDK, using Supplier so they are dynamically resolved. - */ -public class Properties { - - /** - * Layotto's default IP for gRPC communication. - */ - private static final String DEFAULT_SIDECAR_IP = "127.0.0.1"; - - /** - * Layotto's default gRPC port. - */ - private static final Integer DEFAULT_GRPC_PORT = 34904; - - /** - * Layotto's default use of gRPC. - */ - private static final LayottoApiProtocol DEFAULT_API_PROTOCOL = LayottoApiProtocol.GRPC; - - /** - * Layotto's default String encoding: UTF-8. - */ - private static final Charset DEFAULT_STRING_CHARSET = StandardCharsets.UTF_8; - - /** - * IP for Layotto's sidecar. - */ - public static final Property SIDECAR_IP = new StringProperty( - "layotto.sidecar.ip", - "LAYOTTO_SIDECAR_IP", - DEFAULT_SIDECAR_IP); - - /** - * GRPC port for Layotto after checking system property and environment variable. - */ - public static final Property GRPC_PORT = new IntegerProperty( - "layotto.grpc.port", - "LAYOTTO_GRPC_PORT", - DEFAULT_GRPC_PORT); - - /** - * Determines if Layotto client will use gRPC to talk to Layotto's sidecar. - */ - public static final Property API_PROTOCOL = new GenericProperty<>( - "layotto.api.protocol", - "LAYOTTO_API_PROTOCOL", - DEFAULT_API_PROTOCOL, - (s) -> LayottoApiProtocol.valueOf(s.toUpperCase())); - - /** - * API token for authentication between App and Layotto's sidecar. - */ - public static final Property API_TOKEN = new StringProperty( - "layotto.api.token", - "LAYOTTO_API_TOKEN", - null); - - /** - * Determines which string encoding is used in Layotto's Java SDK. - */ - public static final Property STRING_CHARSET = new GenericProperty<>( - "layotto.string.charset", - "LAYOTTO_STRING_CHARSET", - DEFAULT_STRING_CHARSET, - (s) -> Charset.forName(s)); -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/Property.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/Property.java deleted file mode 100644 index f9801e1..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/Property.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.config; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A configuration property in the Layotto's SDK. - */ -public abstract class Property { - - private static final Logger LOGGER = LoggerFactory.getLogger(Property.class.getName()); - - /** - * Property's name as a Java Property. - */ - private final String name; - - /** - * Property's name as a environment variable. - */ - private final String envName; - - /** - * Default value. - */ - private final T defaultValue; - - /** - * Instantiates a new configuration property. - * - * @param name Java property name. - * @param envName Environment variable name. - * @param defaultValue Default value. - */ - Property(String name, String envName, T defaultValue) { - this.name = name; - this.envName = envName; - this.defaultValue = defaultValue; - } - - /** - * Gets the Java property's name. - * - * @return Name. - */ - public String getName() { - return this.name; - } - - /** - * Gets the environment variable's name. - * - * @return Name. - */ - public String getEnvName() { - return this.envName; - } - - /** - * Gets the value defined by system property first, then env variable or sticks to default. - * - * @return Value from system property (1st) or env variable (2nd) or default (last). - */ - public T get() { - String propValue = System.getProperty(this.name); - if (propValue != null && !propValue.trim().isEmpty()) { - try { - return this.parse(propValue); - } catch (IllegalArgumentException e) { - LOGGER.warn(String.format("Invalid value in property: %s", this.name)); - // OK, we tried. Falling back to system environment variable. - } - } - - String envValue = System.getenv(this.envName); - if (envValue != null && !envValue.trim().isEmpty()) { - try { - return this.parse(envValue); - } catch (IllegalArgumentException e) { - LOGGER.warn(String.format("Invalid value in environment variable: %s", this.envName)); - // OK, we tried. Falling back to default. - } - } - - return this.defaultValue; - } - - /** - * Parses the value to the specific type. - * - * @param value String value to be parsed. - * @return Value in the specific type. - */ - protected abstract T parse(String value); -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/exceptions/LayottoError.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/exceptions/LayottoError.java deleted file mode 100644 index c7ddaa0..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/exceptions/LayottoError.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.exceptions; - -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import io.grpc.Status; - -/** - * Represents an error message from Layotto. - */ -@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) -public class LayottoError { - - /** - * Error code. - */ - private String errorCode; - - /** - * Error Message. - */ - private String message; - - /** - * Error code from gRPC. - */ - private Integer code; - - /** - * Gets the error code. - * - * @return Error code. - */ - public String getErrorCode() { - if ((errorCode == null) && (code != null)) { - return Status.fromCodeValue(code).getCode().name(); - } - return errorCode; - } - - /** - * Sets the error code. - * - * @param errorCode Error code. - * @return This instance. - */ - public LayottoError setErrorCode(String errorCode) { - this.errorCode = errorCode; - return this; - } - - /** - * Gets the error message. - * - * @return Error message. - */ - public String getMessage() { - return message; - } - - /** - * Sets the error message. - * - * @param message Error message. - * @return This instance. - */ - public LayottoError setMessage(String message) { - this.message = message; - return this; - } -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/exceptions/LayottoException.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/exceptions/LayottoException.java deleted file mode 100644 index dedadef..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/exceptions/LayottoException.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.exceptions; - -import io.grpc.StatusRuntimeException; -import reactor.core.Exceptions; -import reactor.core.publisher.Mono; - -import java.util.concurrent.Callable; - -/** - * A Layotto's specific exception. - */ -public class LayottoException extends RuntimeException { - - /** - * Layotto's error code for this exception. - */ - private final String errorCode; - - /** - * New exception from a server-side generated error code and message. - * - * @param daprError Server-side error. - */ - public LayottoException(LayottoError daprError) { - this(daprError.getErrorCode(), daprError.getMessage()); - } - - /** - * New exception from a server-side generated error code and message. - * - * @param daprError Client-side error. - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A {@code null} value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - */ - public LayottoException(LayottoError daprError, Throwable cause) { - this(daprError.getErrorCode(), daprError.getMessage(), cause); - } - - /** - * Wraps an exception into a LayottoException. - * - * @param exception the exception to be wrapped. - */ - public LayottoException(Throwable exception) { - this("UNKNOWN", exception.getMessage(), exception); - } - - /** - * New Exception from a client-side generated error code and message. - * - * @param errorCode Client-side error code. - * @param message Client-side error message. - */ - public LayottoException(String errorCode, String message) { - super(String.format("%s: %s", errorCode, message)); - this.errorCode = errorCode; - } - - /** - * New exception from a server-side generated error code and message. - * - * @param errorCode Client-side error code. - * @param message Client-side error message. - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A {@code null} value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - */ - public LayottoException(String errorCode, String message, Throwable cause) { - super(String.format("%s: %s", errorCode, emptyIfNull(message)), cause); - this.errorCode = errorCode; - } - - /** - * Returns the exception's error code. - * - * @return Error code. - */ - public String getErrorCode() { - return this.errorCode; - } - - /** - * Wraps an exception into LayottoException (if not already LayottoException). - * - * @param exception Exception to be wrapped. - */ - public static void wrap(Throwable exception) { - if (exception == null) { - return; - } - - throw propagate(exception); - } - - /** - * Wraps a callable with a try-catch to throw LayottoException. - * - * @param callable callable to be invoked. - * @param type to be returned - * @return object of type T. - */ - public static Callable wrap(Callable callable) { - return () -> { - try { - return callable.call(); - } catch (Exception e) { - wrap(e); - return null; - } - }; - } - - /** - * Wraps a runnable with a try-catch to throw LayottoException. - * - * @param runnable runnable to be invoked. - * @return object of type T. - */ - public static Runnable wrap(Runnable runnable) { - return () -> { - try { - runnable.run(); - } catch (Exception e) { - wrap(e); - } - }; - } - - /** - * Wraps an exception into LayottoException (if not already LayottoException). - * - * @param exception Exception to be wrapped. - * @param Mono's response type. - * @return Mono containing LayottoException. - */ - public static Mono wrapMono(Exception exception) { - try { - wrap(exception); - } catch (Exception e) { - return Mono.error(e); - } - - return Mono.empty(); - } - - /** - * Wraps an exception into LayottoException (if not already LayottoException). - * - * @param exception Exception to be wrapped. - * @return wrapped RuntimeException - */ - public static RuntimeException propagate(Throwable exception) { - Exceptions.throwIfFatal(exception); - - if (exception instanceof LayottoException) { - return (LayottoException) exception; - } - - Throwable e = exception; - while (e != null) { - if (e instanceof StatusRuntimeException) { - StatusRuntimeException statusRuntimeException = (StatusRuntimeException) e; - return new LayottoException( - statusRuntimeException.getStatus().getCode().toString(), - statusRuntimeException.getStatus().getDescription(), - exception); - } - - e = e.getCause(); - } - - if (exception instanceof IllegalArgumentException) { - return (IllegalArgumentException) exception; - } - - return new LayottoException(exception); - } - - private static String emptyIfNull(String str) { - if (str == null) { - return ""; - } - - return str; - } -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/AbstractLayottoReactorClient.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/AbstractLayottoReactorClient.java new file mode 100644 index 0000000..ae652c8 --- /dev/null +++ b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/AbstractLayottoReactorClient.java @@ -0,0 +1,197 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.mosn.layotto.v1.reactor.client; + +import io.mosn.layotto.v1.infrastructure.serializer.ObjectSerializer; +import reactor.core.publisher.Mono; +import spec.sdk.runtime.reactor.v1.client.ReactorRuntimeClient; +import spec.sdk.runtime.v1.domain.invocation.InvokeResponse; +import spec.sdk.runtime.v1.domain.pubsub.PublishEventRequest; +import spec.sdk.runtime.v1.domain.state.DeleteStateRequest; +import spec.sdk.runtime.v1.domain.state.ExecuteStateTransactionRequest; +import spec.sdk.runtime.v1.domain.state.GetBulkStateRequest; +import spec.sdk.runtime.v1.domain.state.GetStateRequest; +import spec.sdk.runtime.v1.domain.state.SaveStateRequest; +import spec.sdk.runtime.v1.domain.state.State; +import spec.sdk.runtime.v1.domain.state.StateOptions; +import spec.sdk.runtime.v1.domain.state.TransactionalStateOperation; + +import java.util.List; +import java.util.Map; + +abstract class AbstractLayottoReactorClient implements ReactorRuntimeClient { + + /** + * A utility class for serialize and deserialize the transient objects. + */ + protected ObjectSerializer objectSerializer; + + /** + * A utility class for serialize and deserialize state objects. + */ + protected ObjectSerializer stateSerializer; + + /** + * Common constructor for implementations of this class. + * + * @param objectSerializer Serializer for transient request/response objects. + * @param stateSerializer Serializer for state objects. + */ + AbstractLayottoReactorClient(ObjectSerializer objectSerializer, + ObjectSerializer stateSerializer) { + this.objectSerializer = objectSerializer; + this.stateSerializer = stateSerializer; + } + + @Override + public Mono sayHelloAsync(String name) { + return sayHelloAsync(name, getTimeoutMs()); + } + + @Override + public Mono> invokeMethodAsync(String appId, String methodName, byte[] data, + Map header) { + return invokeMethodAsync(appId, methodName, data, header, getTimeoutMs()); + } + + @Override + public Mono publishEventAsync(String pubsubName, String topicName, byte[] data) { + PublishEventRequest publishEventRequest = new PublishEventRequest(); + publishEventRequest.setPubsubName(pubsubName); + publishEventRequest.setTopic(topicName); + publishEventRequest.setData(data); + return publishEventAsync(publishEventRequest); + } + + @Override + public Mono publishEventAsync(String pubsubName, String topicName, byte[] data, Map metadata) { + PublishEventRequest publishEventRequest = new PublishEventRequest(); + publishEventRequest.setPubsubName(pubsubName); + publishEventRequest.setTopic(topicName); + publishEventRequest.setData(data); + publishEventRequest.setMetadata(metadata); + return publishEventAsync(publishEventRequest); + } + + @Override + public Mono publishEventAsync(String pubsubName, String topicName, byte[] data, String contentType, + Map metadata) { + PublishEventRequest publishEventRequest = new PublishEventRequest(); + publishEventRequest.setPubsubName(pubsubName); + publishEventRequest.setTopic(topicName); + publishEventRequest.setData(data); + publishEventRequest.setContentType(contentType); + publishEventRequest.setMetadata(metadata); + return publishEventAsync(publishEventRequest); + } + + @Override + public Mono> getStateAsync(String storeName, String key, Class clazz) { + GetStateRequest getStateRequest = new GetStateRequest(storeName, key); + return getStateAsync(getStateRequest, clazz, getTimeoutMs()); + } + + @Override + public Mono> getStateAsync(String storeName, String key, StateOptions options, Class clazz) { + GetStateRequest getStateRequest = new GetStateRequest(storeName, key); + getStateRequest.setStateOptions(options); + return getStateAsync(getStateRequest, clazz, getTimeoutMs()); + } + + @Override + public Mono> getStateAsync(GetStateRequest request, Class clazz) { + return getStateAsync(request, clazz, getTimeoutMs()); + } + + @Override + public Mono>> getBulkStateAsync(String storeName, List keys, Class clazz) { + GetBulkStateRequest getBulkStateRequest = new GetBulkStateRequest(storeName, keys); + return getBulkStateAsync(getBulkStateRequest, clazz, getTimeoutMs()); + } + + @Override + public Mono>> getBulkStateAsync(GetBulkStateRequest request, Class clazz) { + return getBulkStateAsync(request, clazz, getTimeoutMs()); + } + + @Override + public Mono executeStateTransactionAsync(String storeName, List> operations) { + ExecuteStateTransactionRequest executeStateTransactionRequest = new ExecuteStateTransactionRequest(storeName); + executeStateTransactionRequest.setOperations(operations); + return executeStateTransactionAsync(executeStateTransactionRequest); + } + + @Override + public Mono saveBulkStateAsync(String storeName, List> states) { + SaveStateRequest saveStateRequest = new SaveStateRequest(storeName); + saveStateRequest.setStates(states); + return saveBulkStateAsync(saveStateRequest); + } + + @Override + public Mono saveBulkStateAsync(SaveStateRequest request) { + return saveBulkStateAsync(request, getTimeoutMs()); + } + + @Override + public Mono saveStateAsync(String storeName, String key, Object value) { + return saveStateAsync(storeName, key, null, value, null, null); + } + + @Override + public Mono saveStateAsync(String storeName, String key, String etag, Object value, StateOptions options, + Map metadata) { + return null; + } + + @Override + public Mono deleteStateAsync(String storeName, String key) { + return null; + } + + @Override + public Mono deleteStateAsync(String storeName, String key, String etag, StateOptions options) { + return null; + } + + @Override + public Mono deleteStateAsync(DeleteStateRequest request) { + return null; + } + + @Override + public Mono deleteStateAsync(DeleteStateRequest request, int timeoutMs) { + return null; + } + + @Override + public Mono waitForSidecar(int timeoutInMilliseconds) { + return null; + } + + @Override + public Mono shutdown() { + return null; + } + + /** + * Getter method for property timeoutMs. + * + * @return property value of timeoutMs + */ + public int getTimeoutMs() { + return 0; + } +} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/LayottoReactorClientBuilder.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/LayottoReactorClientBuilder.java similarity index 80% rename from sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/LayottoReactorClientBuilder.java rename to sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/LayottoReactorClientBuilder.java index ae51d48..5c3dcd5 100644 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/reactor/LayottoReactorClientBuilder.java +++ b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/LayottoReactorClientBuilder.java @@ -12,15 +12,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.client.reactor; +package io.mosn.layotto.v1.reactor.client; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import io.mosn.layotto.v1.config.Properties; -import io.mosn.layotto.v1.serializer.DefaultObjectSerializer; -import io.mosn.layotto.v1.serializer.LayottoObjectSerializer; -import io.mosn.layotto.v1.value.LayottoApiProtocol; +import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties; +import io.mosn.layotto.v1.infrastructure.serializer.ObjectSerializer; +import io.mosn.layotto.v1.infrastructure.value.ApiProtocol; +import io.mosn.layotto.v1.reactor.serializer.DefaultObjectSerializer; import spec.proto.runtime.v1.RuntimeGrpc; +import spec.sdk.runtime.reactor.v1.client.ReactorRuntimeClient; import java.io.Closeable; @@ -32,17 +33,17 @@ public class LayottoReactorClientBuilder { /** * Determine if this builder will create GRPC clients instead of HTTP clients. */ - private final LayottoApiProtocol apiProtocol; + private final ApiProtocol apiProtocol; /** * Serializer used for request and response objects in LayottoClient. */ - private LayottoObjectSerializer objectSerializer; + private ObjectSerializer objectSerializer; /** * Serializer used for state objects in LayottoClient. */ - private LayottoObjectSerializer stateSerializer; + private ObjectSerializer stateSerializer; /** * Creates a constructor for LayottoClient. @@ -53,7 +54,7 @@ public class LayottoReactorClientBuilder { public LayottoReactorClientBuilder() { this.objectSerializer = new DefaultObjectSerializer(); this.stateSerializer = new DefaultObjectSerializer(); - this.apiProtocol = Properties.API_PROTOCOL.get(); + this.apiProtocol = RuntimeProperties.DEFAULT_API_PROTOCOL; } /** @@ -63,7 +64,7 @@ public LayottoReactorClientBuilder() { * @param objectSerializer Serializer for objects to be sent and received from Layotto. * @return This instance. */ - public LayottoReactorClientBuilder withObjectSerializer(LayottoObjectSerializer objectSerializer) { + public LayottoReactorClientBuilder withObjectSerializer(ObjectSerializer objectSerializer) { if (objectSerializer == null) { throw new IllegalArgumentException("Object serializer is required"); } @@ -83,7 +84,7 @@ public LayottoReactorClientBuilder withObjectSerializer(LayottoObjectSerializer * @param stateSerializer Serializer for objects to be persisted. * @return This instance. */ - public LayottoReactorClientBuilder withStateSerializer(LayottoObjectSerializer stateSerializer) { + public LayottoReactorClientBuilder withStateSerializer(ObjectSerializer stateSerializer) { if (stateSerializer == null) { throw new IllegalArgumentException("State serializer is required"); } @@ -98,7 +99,7 @@ public LayottoReactorClientBuilder withStateSerializer(LayottoObjectSerializer s * @return an instance of the setup Client * @throws java.lang.IllegalStateException if any required field is missing */ - public LayottoReactorClient build() { + public ReactorRuntimeClient build() { return buildLayottoClient(this.apiProtocol); } @@ -109,7 +110,7 @@ public LayottoReactorClient build() { * @return the GRPC Client. * @throws java.lang.IllegalStateException if either host is missing or if port is missing or a negative number. */ - private LayottoReactorClient buildLayottoClient(LayottoApiProtocol protocol) { + private ReactorRuntimeClient buildLayottoClient(ApiProtocol protocol) { if (protocol == null) { throw new IllegalStateException("Protocol is required."); } @@ -128,13 +129,13 @@ private LayottoReactorClient buildLayottoClient(LayottoApiProtocol protocol) { * @return the GRPC Client. * @throws java.lang.IllegalStateException if either host is missing or if port is missing or a negative number. */ - private LayottoReactorClient buildLayottoClientGrpc() { - int port = Properties.GRPC_PORT.get(); + private ReactorRuntimeClient buildLayottoClientGrpc() { + int port = RuntimeProperties.DEFAULT_PORT; if (port <= 0) { throw new IllegalArgumentException("Invalid port."); } ManagedChannel channel = ManagedChannelBuilder - .forAddress(Properties.SIDECAR_IP.get(), port) + .forAddress(RuntimeProperties.DEFAULT_IP, port) .usePlaintext() .build(); Closeable closeableChannel = () -> { diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/LayottoReactorClientGrpc.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/LayottoReactorClientGrpc.java new file mode 100644 index 0000000..00a17ba --- /dev/null +++ b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/LayottoReactorClientGrpc.java @@ -0,0 +1,645 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.mosn.layotto.v1.reactor.client; + +import io.mosn.layotto.v1.infrastructure.serializer.ObjectSerializer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import spec.proto.runtime.v1.RuntimeGrpc; +import spec.sdk.runtime.v1.domain.configuration.ConfigurationItem; +import spec.sdk.runtime.v1.domain.configuration.ConfigurationRequestItem; +import spec.sdk.runtime.v1.domain.configuration.SaveConfigurationRequest; +import spec.sdk.runtime.v1.domain.configuration.SubConfigurationResp; +import spec.sdk.runtime.v1.domain.file.DelFileRequest; +import spec.sdk.runtime.v1.domain.file.DelFileResponse; +import spec.sdk.runtime.v1.domain.file.GetFileRequest; +import spec.sdk.runtime.v1.domain.file.GetFileResponse; +import spec.sdk.runtime.v1.domain.file.GetMetaRequest; +import spec.sdk.runtime.v1.domain.file.GetMeteResponse; +import spec.sdk.runtime.v1.domain.file.ListFileRequest; +import spec.sdk.runtime.v1.domain.file.ListFileResponse; +import spec.sdk.runtime.v1.domain.file.PutFileRequest; +import spec.sdk.runtime.v1.domain.file.PutFileResponse; +import spec.sdk.runtime.v1.domain.invocation.InvokeResponse; +import spec.sdk.runtime.v1.domain.pubsub.PublishEventRequest; +import spec.sdk.runtime.v1.domain.state.ExecuteStateTransactionRequest; +import spec.sdk.runtime.v1.domain.state.GetBulkStateRequest; +import spec.sdk.runtime.v1.domain.state.GetStateRequest; +import spec.sdk.runtime.v1.domain.state.SaveStateRequest; +import spec.sdk.runtime.v1.domain.state.State; + +import java.io.Closeable; +import java.util.List; +import java.util.Map; + +public class LayottoReactorClientGrpc extends AbstractLayottoReactorClient { + + /** + * The GRPC managed channel to be used. + */ + private final Closeable channel; + + /** + * The async gRPC stub. + */ + // private final RuntimeGrpc.RuntimeStub asyncStub; + + /** + * Default access level constructor, in order to create an instance of this class. + * + * @param closeableChannel A closeable for a Managed GRPC channel + * @param asyncStub async gRPC stub + */ + LayottoReactorClientGrpc(ObjectSerializer objectSerializer, + ObjectSerializer stateSerializer, + Closeable closeableChannel, + RuntimeGrpc.RuntimeStub asyncStub) { + super(objectSerializer, stateSerializer); + this.channel = closeableChannel; + // this.asyncStub = intercept(asyncStub); + } + + @Override + public Mono> getConfigurationAsync(ConfigurationRequestItem configurationRequestItem) { + return null; + } + + @Override + public Mono saveConfigurationAsync(SaveConfigurationRequest saveConfigurationRequest) { + return null; + } + + @Override + public Mono deleteConfigurationAsync(ConfigurationRequestItem configurationRequestItem) { + return null; + } + + @Override + public Flux subscribeConfigurationAsync(ConfigurationRequestItem configurationRequestItem) { + return null; + } + + @Override + public Mono putFileAsync(PutFileRequest request, int timeoutMs) throws Exception { + return null; + } + + @Override + public Mono getFileAsync(GetFileRequest request, int timeoutMs) throws Exception { + return null; + } + + @Override + public Mono listFileAsync(ListFileRequest request, int timeoutMs) throws Exception { + return null; + } + + @Override + public Mono delFileAsync(DelFileRequest request, int timeoutMs) throws Exception { + return null; + } + + @Override + public Mono getFileMetaAsync(GetMetaRequest request, int timeoutMs) throws Exception { + return null; + } + + @Override + public Mono sayHelloAsync(String name, int timeoutMillisecond) { + return null; + } + + @Override + public Mono> invokeMethodAsync(String appId, String methodName, byte[] data, Map header, int timeoutMs) { + return null; + } + + @Override + public Mono publishEventAsync(PublishEventRequest request) { + return null; + } + + @Override + public Mono> getStateAsync(GetStateRequest request, Class clazz, int timeoutMs) { + return null; + } + + @Override + public Mono>> getBulkStateAsync(GetBulkStateRequest request, Class clazz, int timeoutMs) { + return null; + } + + @Override + public Mono executeStateTransactionAsync(ExecuteStateTransactionRequest request) { + return null; + } + + @Override + public Mono saveBulkStateAsync(SaveStateRequest request, int timeoutMs) { + return null; + } + + // @Override + // public Mono>> getConfiguration(ConfigurationRequestItem configurationRequestItem, + // TypeRef type) { + // // TODO: 2021/9/26 + // return null; + // } + // + // @Override + // public Mono saveConfiguration(SaveConfigurationRequest saveConfigurationRequest) { + // // TODO: 2021/9/26 + // return null; + // } + // + // @Override + // public Mono deleteConfiguration(ConfigurationRequestItem configurationRequestItem) { + // // TODO: 2021/9/26 + // return null; + // } + // + // @Override + // public Flux> subscribeConfiguration(ConfigurationRequestItem configurationRequestItem, + // TypeRef type) { + // // TODO: 2021/9/26 + // return null; + // } + // + // @Override + // public Mono invokeMethod(InvokeMethodRequest invokeMethodRequest, TypeRef type) { + // try { + // String appId = invokeMethodRequest.getAppId(); + // String method = invokeMethodRequest.getMethod(); + // Object body = invokeMethodRequest.getBody(); + // HttpExtension httpExtension = invokeMethodRequest.getHttpExtension(); + // RuntimeProto.InvokeServiceRequest envelope = this.buildInvokeServiceRequest( + // httpExtension, + // appId, + // method, + // body); + // // Regarding missing metadata in method invocation for gRPC: + // // gRPC to gRPC does not handle metadata in Layotto runtime proto. + // // gRPC to HTTP does not map correctly in Layotto runtime as per https://github.com/layotto/layotto/issues/2342 + // + // return Mono.subscriberContext().flatMap( + // context -> this.createMono( + // it -> intercept(context, asyncStub).invokeService(envelope, it) + // ) + // ).flatMap( + // it -> { + // try { + // return Mono.justOrEmpty(objectSerializer.deserialize(it.getData().getValue().toByteArray(), type)); + // } catch (IOException e) { + // throw LayottoException.propagate(e); + // } + // } + // ); + // } catch (Exception ex) { + // return LayottoException.wrapMono(ex); + // } + // } + // + // @Override + // public Mono publishEvent(PublishEventRequest request) { + // try { + // String pubsubName = request.getPubsubName(); + // String topic = request.getTopic(); + // Object data = request.getData(); + // RuntimeProto.PublishEventRequest.Builder envelopeBuilder = RuntimeProto.PublishEventRequest.newBuilder() + // .setTopic(topic) + // .setPubsubName(pubsubName) + // .setData(ByteString.copyFrom(objectSerializer.serialize(data))); + // + // // Content-type can be overwritten on a per-request basis. + // // It allows CloudEvents to be handled differently, for example. + // String contentType = request.getContentType(); + // if (contentType == null || contentType.isEmpty()) { + // contentType = objectSerializer.getContentType(); + // } + // envelopeBuilder.setDataContentType(contentType); + // + // Map metadata = request.getMetadata(); + // if (metadata != null) { + // envelopeBuilder.putAllMetadata(metadata); + // } + // + // return Mono.subscriberContext().flatMap( + // context -> + // this.createMono( + // it -> intercept(context, asyncStub).publishEvent(envelopeBuilder.build(), it) + // ) + // ).then(); + // } catch (Exception ex) { + // return LayottoException.wrapMono(ex); + // } + // } + // + // @Override + // public Mono> getState(GetStateRequest request, TypeRef type) { + // try { + // final String stateStoreName = request.getStoreName(); + // final String key = request.getKey(); + // final StateOptions options = request.getStateOptions(); + // final Map metadata = request.getMetadata(); + // + // if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { + // throw new IllegalArgumentException("State store name cannot be null or empty."); + // } + // if ((key == null) || (key.trim().isEmpty())) { + // throw new IllegalArgumentException("Key cannot be null or empty."); + // } + // RuntimeProto.GetStateRequest.Builder builder = RuntimeProto.GetStateRequest.newBuilder() + // .setStoreName(stateStoreName) + // .setKey(key); + // if (metadata != null) { + // builder.putAllMetadata(metadata); + // } + // if (options != null && options.getConsistency() != null) { + // builder.setConsistency(getGrpcStateConsistency(options)); + // } + // + // RuntimeProto.GetStateRequest envelope = builder.build(); + // + // return Mono.subscriberContext().flatMap( + // context -> + // this.createMono( + // it -> intercept(context, asyncStub).getState(envelope, it) + // ) + // ).map( + // it -> { + // try { + // return buildStateKeyValue(it, key, options, type); + // } catch (IOException ex) { + // throw LayottoException.propagate(ex); + // } + // } + // ); + // } catch (Exception ex) { + // return LayottoException.wrapMono(ex); + // } + // } + // + // @Override + // public Mono>> getBulkState(GetBulkStateRequest request, TypeRef type) { + // try { + // final String stateStoreName = request.getStoreName(); + // final List keys = request.getKeys(); + // final int parallelism = request.getParallelism(); + // final Map metadata = request.getMetadata(); + // if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { + // throw new IllegalArgumentException("State store name cannot be null or empty."); + // } + // if (keys == null || keys.isEmpty()) { + // throw new IllegalArgumentException("Key cannot be null or empty."); + // } + // + // if (parallelism < 0) { + // throw new IllegalArgumentException("Parallelism cannot be negative."); + // } + // RuntimeProto.GetBulkStateRequest.Builder builder = RuntimeProto.GetBulkStateRequest.newBuilder() + // .setStoreName(stateStoreName) + // .addAllKeys(keys) + // .setParallelism(parallelism); + // if (metadata != null) { + // builder.putAllMetadata(metadata); + // } + // + // RuntimeProto.GetBulkStateRequest envelope = builder.build(); + // + // return Mono.subscriberContext().flatMap( + // context -> this.createMono(it -> intercept(context, asyncStub) + // .getBulkState(envelope, it) + // ) + // ).map( + // it -> + // it + // .getItemsList() + // .stream() + // .map(b -> { + // try { + // return buildStateKeyValue(b, type); + // } catch (Exception e) { + // throw LayottoException.propagate(e); + // } + // }) + // .collect(Collectors.toList()) + // ); + // } catch (Exception ex) { + // return LayottoException.wrapMono(ex); + // } + // } + // + // @Override + // public Mono executeStateTransaction(ExecuteStateTransactionRequest request) { + // try { + // final String stateStoreName = request.getStateStoreName(); + // final List> operations = request.getOperations(); + // final Map metadata = request.getMetadata(); + // if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { + // throw new IllegalArgumentException("State store name cannot be null or empty."); + // } + // RuntimeProto.ExecuteStateTransactionRequest.Builder builder = RuntimeProto.ExecuteStateTransactionRequest + // .newBuilder(); + // builder.setStoreName(stateStoreName); + // if (metadata != null) { + // builder.putAllMetadata(metadata); + // } + // for (TransactionalStateOperation operation : operations) { + // RuntimeProto.TransactionalStateOperation.Builder operationBuilder = RuntimeProto.TransactionalStateOperation + // .newBuilder(); + // operationBuilder.setOperationType(operation.getOperation().toString().toLowerCase()); + // operationBuilder.setRequest(buildStateRequest(operation.getRequest()).build()); + // builder.addOperations(operationBuilder.build()); + // } + // RuntimeProto.ExecuteStateTransactionRequest req = builder.build(); + // + // return Mono.subscriberContext().flatMap( + // context -> this.createMono(it -> intercept(context, asyncStub).executeStateTransaction(req, it)) + // ).then(); + // } catch (Exception e) { + // return LayottoException.wrapMono(e); + // } + // } + // + // @Override + // public Mono saveBulkState(SaveStateRequest request) { + // try { + // final String stateStoreName = request.getStoreName(); + // final List> states = request.getStates(); + // if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { + // throw new IllegalArgumentException("State store name cannot be null or empty."); + // } + // RuntimeProto.SaveStateRequest.Builder builder = RuntimeProto.SaveStateRequest.newBuilder(); + // builder.setStoreName(stateStoreName); + // for (State state : states) { + // builder.addStates(buildStateRequest(state).build()); + // } + // RuntimeProto.SaveStateRequest req = builder.build(); + // + // return Mono.subscriberContext().flatMap( + // context -> this.createMono(it -> intercept(context, asyncStub).saveState(req, it)) + // ).then(); + // } catch (Exception ex) { + // return LayottoException.wrapMono(ex); + // } + // } + // + // @Override + // public Mono deleteState(DeleteStateRequest request) { + // try { + // final String stateStoreName = request.getStateStoreName(); + // final String key = request.getKey(); + // final StateOptions options = request.getStateOptions(); + // final String etag = request.getEtag(); + // final Map metadata = request.getMetadata(); + // + // if ((stateStoreName == null) || (stateStoreName.trim().isEmpty())) { + // throw new IllegalArgumentException("State store name cannot be null or empty."); + // } + // if ((key == null) || (key.trim().isEmpty())) { + // throw new IllegalArgumentException("Key cannot be null or empty."); + // } + // + // RuntimeProto.StateOptions.Builder optionBuilder = null; + // if (options != null) { + // optionBuilder = RuntimeProto.StateOptions.newBuilder(); + // if (options.getConcurrency() != null) { + // optionBuilder.setConcurrency(getGrpcStateConcurrency(options)); + // } + // if (options.getConsistency() != null) { + // optionBuilder.setConsistency(getGrpcStateConsistency(options)); + // } + // } + // RuntimeProto.DeleteStateRequest.Builder builder = RuntimeProto.DeleteStateRequest.newBuilder() + // .setStoreName(stateStoreName) + // .setKey(key); + // if (metadata != null) { + // builder.putAllMetadata(metadata); + // } + // if (etag != null) { + // builder.setEtag(RuntimeProto.Etag.newBuilder().setValue(etag).build()); + // } + // + // if (optionBuilder != null) { + // builder.setOptions(optionBuilder.build()); + // } + // + // RuntimeProto.DeleteStateRequest req = builder.build(); + // + // return Mono.subscriberContext().flatMap( + // context -> this.createMono(it -> intercept(context, asyncStub).deleteState(req, it)) + // ).then(); + // } catch (Exception ex) { + // return LayottoException.wrapMono(ex); + // } + // } + // + // /** + // * Builds the object io.layotto.{@link RuntimeProto.InvokeServiceRequest} to be send based on the parameters. + // * + // * @param httpExtension Object for HttpExtension + // * @param appId The application id to be invoked + // * @param method The application method to be invoked + // * @param body The body of the request to be send as part of the invocation + // * @param The Type of the Body + // * @return The object to be sent as part of the invocation. + // * @throws IOException If there's an issue serializing the request. + // */ + // private RuntimeProto.InvokeServiceRequest buildInvokeServiceRequest( + // HttpExtension httpExtension, + // String appId, + // String method, + // K body) throws IOException { + // if (httpExtension == null) { + // throw new IllegalArgumentException("HttpExtension cannot be null. Use HttpExtension.NONE instead."); + // } + // RuntimeProto.CommonInvokeRequest.Builder requestBuilder = RuntimeProto.CommonInvokeRequest.newBuilder(); + // requestBuilder.setMethod(method); + // if (body != null) { + // byte[] byteRequest = objectSerializer.serialize(body); + // Any data = Any.newBuilder().setValue(ByteString.copyFrom(byteRequest)).build(); + // requestBuilder.setData(data); + // } else { + // requestBuilder.setData(Any.newBuilder().build()); + // } + // RuntimeProto.HTTPExtension.Builder httpExtensionBuilder = RuntimeProto.HTTPExtension.newBuilder(); + // + // httpExtensionBuilder.setVerb(RuntimeProto.HTTPExtension.Verb.valueOf(httpExtension.getMethod().toString())) + // .setQuerystring(httpExtension.encodeQueryString()); + // requestBuilder.setHttpExtension(httpExtensionBuilder.build()); + // + // requestBuilder.setContentType(objectSerializer.getContentType()); + // + // RuntimeProto.InvokeServiceRequest.Builder envelopeBuilder = RuntimeProto.InvokeServiceRequest.newBuilder() + // .setId(appId) + // .setMessage(requestBuilder.build()); + // return envelopeBuilder.build(); + // } + // + // private State buildStateKeyValue( + // RuntimeProto.BulkStateItem item, + // TypeRef type) throws IOException { + // String key = item.getKey(); + // String error = item.getError(); + // if (!Strings.isNullOrEmpty(error)) { + // return new State<>(key, error); + // } + // + // ByteString payload = item.getData(); + // byte[] data = payload == null ? null : payload.toByteArray(); + // T value = stateSerializer.deserialize(data, type); + // String etag = item.getEtag(); + // if (etag.equals("")) { + // etag = null; + // } + // return new State<>(key, value, etag, item.getMetadataMap(), null); + // } + // + // private State buildStateKeyValue( + // RuntimeProto.GetStateResponse response, + // String requestedKey, + // StateOptions stateOptions, + // TypeRef type) throws IOException { + // ByteString payload = response.getData(); + // byte[] data = payload == null ? null : payload.toByteArray(); + // T value = stateSerializer.deserialize(data, type); + // String etag = response.getEtag(); + // if (etag.equals("")) { + // etag = null; + // } + // return new State<>(requestedKey, value, etag, response.getMetadataMap(), stateOptions); + // } + // + // private RuntimeProto.StateItem.Builder buildStateRequest(State state) throws IOException { + // byte[] bytes = stateSerializer.serialize(state.getValue()); + // + // RuntimeProto.StateItem.Builder stateBuilder = RuntimeProto.StateItem.newBuilder(); + // if (state.getEtag() != null) { + // stateBuilder.setEtag(RuntimeProto.Etag.newBuilder().setValue(state.getEtag()).build()); + // } + // if (state.getMetadata() != null) { + // stateBuilder.putAllMetadata(state.getMetadata()); + // } + // if (bytes != null) { + // stateBuilder.setValue(ByteString.copyFrom(bytes)); + // } + // stateBuilder.setKey(state.getKey()); + // RuntimeProto.StateOptions.Builder optionBuilder = null; + // if (state.getOptions() != null) { + // StateOptions options = state.getOptions(); + // optionBuilder = RuntimeProto.StateOptions.newBuilder(); + // if (options.getConcurrency() != null) { + // optionBuilder.setConcurrency(getGrpcStateConcurrency(options)); + // } + // if (options.getConsistency() != null) { + // optionBuilder.setConsistency(getGrpcStateConsistency(options)); + // } + // } + // if (optionBuilder != null) { + // stateBuilder.setOptions(optionBuilder.build()); + // } + // return stateBuilder; + // } + // + // private RuntimeProto.StateOptions.StateConsistency getGrpcStateConsistency(StateOptions options) { + // switch (options.getConsistency()) { + // case EVENTUAL: + // return RuntimeProto.StateOptions.StateConsistency.CONSISTENCY_EVENTUAL; + // case STRONG: + // return RuntimeProto.StateOptions.StateConsistency.CONSISTENCY_STRONG; + // default: + // throw new IllegalArgumentException("Missing Consistency mapping to gRPC Consistency enum"); + // } + // } + // + // private RuntimeProto.StateOptions.StateConcurrency getGrpcStateConcurrency(StateOptions options) { + // switch (options.getConcurrency()) { + // case FIRST_WRITE: + // return RuntimeProto.StateOptions.StateConcurrency.CONCURRENCY_FIRST_WRITE; + // case LAST_WRITE: + // return RuntimeProto.StateOptions.StateConcurrency.CONCURRENCY_LAST_WRITE; + // default: + // throw new IllegalArgumentException("Missing StateConcurrency mapping to gRPC Concurrency enum"); + // } + // } + // + // // -- Lifecycle Functions + // + // @Override + // public Mono waitForSidecar(int timeoutInMilliseconds) { + // return Mono.fromRunnable(() -> { + // try { + // NetworkUtils.waitForSocket(Properties.SIDECAR_IP.get(), Properties.GRPC_PORT.get(), timeoutInMilliseconds); + // } catch (InterruptedException e) { + // throw new RuntimeException(e); + // } + // }); + // } + // + // @Override + // public Mono shutdown() { + // return Mono.subscriberContext() + // // FIXME: 2021/9/26 Refer to Dapr + // // .flatMap(context -> + // // this.createMono(it -> + // // intercept(context, asyncStub) + // // .shutdown(Empty.getDefaultInstance(), it))) + // .then(); + // } + // + // private Mono createMono(Consumer> consumer) { + // return Mono.create(sink -> + // LayottoException + // .wrap(() -> consumer.accept(createStreamObserver(sink))) + // .run()); + // } + // + // private StreamObserver createStreamObserver(MonoSink sink) { + // return new StreamObserver() { + // @Override + // public void onNext(T value) { + // sink.success(value); + // } + // + // @Override + // public void onError(Throwable t) { + // sink.error(LayottoException.propagate(new ExecutionException(t))); + // } + // + // @Override + // public void onCompleted() { + // sink.success(); + // } + // }; + // } + // + // /** + // * Closes the ManagedChannel for GRPC. + // * + // * @throws IOException on exception. + // * @see io.grpc.ManagedChannel#shutdown() + // */ + // @Override + // public void shutdown() throws Exception { + //// if (channel != null) { + //// RuntimeException + //// .wrap(() -> { + //// channel.close(); + //// return true; + //// }) + //// .call(); + //// } + // } +} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/package-info.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/package-info.java similarity index 93% rename from sdk-reactor/src/main/java/io/mosn/layotto/v1/client/package-info.java rename to sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/package-info.java index 3b6fc72..fcb3576 100644 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/client/package-info.java +++ b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/client/package-info.java @@ -15,4 +15,4 @@ /** * SDK JVM Client. */ -package io.mosn.layotto.v1.client; \ No newline at end of file +package io.mosn.layotto.v1.reactor.client; \ No newline at end of file diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/domain/CloudEvent.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/serializer/CloudEvent.java similarity index 99% rename from sdk-reactor/src/main/java/io/mosn/layotto/v1/domain/CloudEvent.java rename to sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/serializer/CloudEvent.java index 312c36d..4f1938b 100644 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/domain/CloudEvent.java +++ b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/serializer/CloudEvent.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.domain; +package io.mosn.layotto.v1.reactor.serializer; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/StringProperty.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/serializer/DefaultObjectSerializer.java similarity index 65% rename from sdk-reactor/src/main/java/io/mosn/layotto/v1/config/StringProperty.java rename to sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/serializer/DefaultObjectSerializer.java index 34939aa..e6bc3a6 100644 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/config/StringProperty.java +++ b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/serializer/DefaultObjectSerializer.java @@ -12,25 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.config; +package io.mosn.layotto.v1.reactor.serializer; /** - * String configuration property. + * Default serializer/deserializer for request/response objects and for state objects too. */ -public class StringProperty extends Property { - - /** - * {@inheritDoc} - */ - StringProperty(String name, String envName, String defaultValue) { - super(name, envName, defaultValue); - } +public class DefaultObjectSerializer extends ExtensionObjectSerializer { /** * {@inheritDoc} */ @Override - protected String parse(String value) { - return value; + public String getContentType() { + return "application/json"; } } diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/serializer/ObjectSerializer.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/serializer/ExtensionObjectSerializer.java similarity index 80% rename from sdk-reactor/src/main/java/io/mosn/layotto/v1/serializer/ObjectSerializer.java rename to sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/serializer/ExtensionObjectSerializer.java index f09ace3..c963e79 100644 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/serializer/ObjectSerializer.java +++ b/sdk-reactor/src/main/java/io/mosn/layotto/v1/reactor/serializer/ExtensionObjectSerializer.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.mosn.layotto.v1.serializer; +package io.mosn.layotto.v1.reactor.serializer; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -20,8 +20,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.protobuf.MessageLite; -import io.mosn.layotto.v1.domain.CloudEvent; -import spec.sdk.reactor.v1.utils.TypeRef; +import io.mosn.layotto.v1.infrastructure.serializer.AbstractSerializer; import java.io.IOException; import java.lang.reflect.Method; @@ -29,7 +28,7 @@ /** * Serializes and deserializes an internal object. */ -public class ObjectSerializer { +public abstract class ExtensionObjectSerializer extends AbstractSerializer { /** * Shared Json serializer/deserializer as per Jackson's documentation. @@ -42,50 +41,38 @@ public class ObjectSerializer { /** * Default constructor to avoid class from being instantiated outside package but still inherited. */ - protected ObjectSerializer() { + protected ExtensionObjectSerializer() { } /** - * Serializes a given state object into byte array. + * Serializes a given object into byte array. * - * @param state State object to be serialized. + * @param o object to be serialized. * @return Array of bytes[] with the serialized content. - * @throws IOException In case state cannot be serialized. + * @throws IOException In case o cannot be serialized. */ - public byte[] serialize(Object state) throws IOException { - if (state == null) { + @Override + public byte[] doSerialize(Object o) throws IOException { + if (o == null) { return null; } - if (state.getClass() == Void.class) { + if (o.getClass() == Void.class) { return null; } // Have this check here to be consistent with deserialization (see deserialize() method below). - if (state instanceof byte[]) { - return (byte[]) state; + if (o instanceof byte[]) { + return (byte[]) o; } // Proto buffer class is serialized directly. - if (state instanceof MessageLite) { - return ((MessageLite) state).toByteArray(); + if (o instanceof MessageLite) { + return ((MessageLite) o).toByteArray(); } // Not string, not primitive, so it is a complex type: we use JSON for that. - return OBJECT_MAPPER.writeValueAsBytes(state); - } - - /** - * Deserializes the byte array into the original object. - * - * @param content Content to be parsed. - * @param type Type of the object being deserialized. - * @param Generic type of the object being deserialized. - * @return Object of type T. - * @throws IOException In case content cannot be deserialized. - */ - public T deserialize(byte[] content, TypeRef type) throws IOException { - return deserialize(content, OBJECT_MAPPER.constructType(type.getType())); + return OBJECT_MAPPER.writeValueAsBytes(o); } /** @@ -97,7 +84,8 @@ public T deserialize(byte[] content, TypeRef type) throws IOException { * @return Object of type T. * @throws IOException In case content cannot be deserialized. */ - public T deserialize(byte[] content, Class clazz) throws IOException { + @Override + public T doDeserialize(byte[] content, Class clazz) throws IOException { return deserialize(content, OBJECT_MAPPER.constructType(clazz)); } diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/serializer/DefaultObjectSerializer.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/serializer/DefaultObjectSerializer.java deleted file mode 100644 index e049d96..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/serializer/DefaultObjectSerializer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.serializer; - -import spec.sdk.reactor.v1.utils.TypeRef; - -import java.io.IOException; - -/** - * Default serializer/deserializer for request/response objects and for state objects too. - */ -public class DefaultObjectSerializer extends ObjectSerializer implements LayottoObjectSerializer { - - /** - * {@inheritDoc} - */ - @Override - public byte[] serialize(Object o) throws IOException { - return super.serialize(o); - } - - /** - * {@inheritDoc} - */ - @Override - public T deserialize(byte[] data, TypeRef type) throws IOException { - return super.deserialize(data, type); - } - - /** - * {@inheritDoc} - */ - @Override - public String getContentType() { - return "application/json"; - } -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/serializer/LayottoObjectSerializer.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/serializer/LayottoObjectSerializer.java deleted file mode 100644 index 6d74a63..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/serializer/LayottoObjectSerializer.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.serializer; - -import spec.sdk.reactor.v1.utils.TypeRef; - -import java.io.IOException; - -/** - * Serializes and deserializes application's objects. - */ -public interface LayottoObjectSerializer { - - /** - * Serializes the given object as byte[]. - * - * @param o Object to be serialized. - * @return Serialized object. - * @throws IOException If cannot serialize. - */ - byte[] serialize(Object o) throws IOException; - - /** - * Deserializes the given byte[] into a object. - * - * @param data Data to be deserialized. - * @param type Type of object to be deserialized. - * @param Type of object to be deserialized. - * @return Deserialized object. - * @throws IOException If cannot deserialize object. - */ - T deserialize(byte[] data, TypeRef type) throws IOException; - - /** - * Returns the content type of the request. - * - * @return content type of the request - */ - String getContentType(); -} diff --git a/sdk-reactor/src/main/java/io/mosn/layotto/v1/utils/GrpcWrapper.java b/sdk-reactor/src/main/java/io/mosn/layotto/v1/utils/GrpcWrapper.java deleted file mode 100644 index ab40749..0000000 --- a/sdk-reactor/src/main/java/io/mosn/layotto/v1/utils/GrpcWrapper.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.mosn.layotto.v1.utils; - -import io.grpc.CallOptions; -import io.grpc.Channel; -import io.grpc.ClientCall; -import io.grpc.ClientInterceptor; -import io.grpc.ForwardingClientCall; -import io.grpc.Metadata; -import io.grpc.MethodDescriptor; -import io.mosn.layotto.v1.config.Property; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import reactor.util.context.Context; -import spec.proto.runtime.v1.RuntimeGrpc; - -/** - * Wraps a Layotto gRPC stub with telemetry interceptor. - */ -public final class GrpcWrapper { - - private static final Logger LOGGER = LoggerFactory.getLogger(Property.class.getName()); - - private static final Metadata.Key GRPC_TRACE_BIN_KEY = - Metadata.Key.of("grpc-trace-bin", - Metadata.BINARY_BYTE_MARSHALLER); - - private static final Metadata.Key TRACEPARENT_KEY = - Metadata.Key.of("traceparent", - Metadata.ASCII_STRING_MARSHALLER); - - private static final Metadata.Key TRACESTATE_KEY = - Metadata.Key.of("tracestate", - Metadata.ASCII_STRING_MARSHALLER); - - private GrpcWrapper() { - } - - /** - * Populates GRPC client with interceptors. - * - * @param context Reactor's context. - * @param client GRPC client for Layotto. - * @return Client after adding interceptors. - */ - public static RuntimeGrpc.RuntimeStub intercept(final Context context, RuntimeGrpc.RuntimeStub client) { - ClientInterceptor interceptor = new ClientInterceptor() { - @Override - public ClientCall interceptCall(MethodDescriptor methodDescriptor, - CallOptions callOptions, - Channel channel) { - ClientCall clientCall = channel.newCall(methodDescriptor, callOptions); - return new ForwardingClientCall.SimpleForwardingClientCall(clientCall) { - @Override - public void start(final Listener responseListener, final Metadata metadata) { - // FIXME: 2021/9/26 Refer to Dapr - super.start(responseListener, metadata); - } - }; - } - }; - return client.withInterceptors(interceptor); - } -} \ No newline at end of file diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/CoreCloudRuntimes.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/CoreCloudRuntimes.java deleted file mode 100644 index b4e2266..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/CoreCloudRuntimes.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1; - -import spec.sdk.reactor.v1.domain.core.ConfigurationRuntimes; -import spec.sdk.reactor.v1.domain.core.InvocationRuntimes; -import spec.sdk.reactor.v1.domain.core.PubSubRuntimes; -import spec.sdk.reactor.v1.domain.core.StateRuntimes; - -/** - * Core Cloud Runtimes standard API defined. - */ -public interface CoreCloudRuntimes extends - InvocationRuntimes, - PubSubRuntimes, - // BindingRuntimes, - StateRuntimes, - // SecretsRuntimes, - ConfigurationRuntimes { -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/EnhancedCloudRuntimes.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/EnhancedCloudRuntimes.java deleted file mode 100644 index 63f243b..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/EnhancedCloudRuntimes.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1; - -import spec.sdk.reactor.v1.domain.enhanced.MetricsRuntimes; - -/** - * Enhanced Cloud Runtimes standard API defined. - */ -public interface EnhancedCloudRuntimes extends - MetricsRuntimes { -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/README.md b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/README.md deleted file mode 100644 index 70996cf..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/README.md +++ /dev/null @@ -1 +0,0 @@ -This package was copied from [cloud-runtimes-jvm](https://github.com/reactivegroup/cloud-runtimes-jvm) and [Dapr java sdk](https://github.com/dapr/java-sdk) \ No newline at end of file diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/ConfigurationRuntimes.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/ConfigurationRuntimes.java deleted file mode 100644 index 2a726fb..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/ConfigurationRuntimes.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core; - -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import spec.sdk.reactor.v1.domain.core.configuration.ConfigurationItem; -import spec.sdk.reactor.v1.domain.core.configuration.ConfigurationRequestItem; -import spec.sdk.reactor.v1.domain.core.configuration.SaveConfigurationRequest; -import spec.sdk.reactor.v1.domain.core.configuration.SubConfigurationResp; -import spec.sdk.reactor.v1.utils.TypeRef; - -import java.util.List; - -/** - * Configuration Runtimes standard API defined. - */ -public interface ConfigurationRuntimes { - - /** - * Gets configuration from configuration store - * - * @param The Type of the return. - * @param configurationRequestItem Request object. - * @param type The Type needed as return for the call. - * @return A Mono Plan of response with type T. - */ - Mono>> getConfiguration(ConfigurationRequestItem configurationRequestItem, - TypeRef type); - - /** - * Saves configuration into configuration store. - * - * @param saveConfigurationRequest Request object. - * @return A Mono Plan of invocation. - */ - Mono saveConfiguration(SaveConfigurationRequest saveConfigurationRequest); - - /** - * Deletes configuration from configuration store. - * - * @param configurationRequestItem Request object. - * @return A Mono Plan of invocation. - */ - Mono deleteConfiguration(ConfigurationRequestItem configurationRequestItem); - - /** - * Gets configuration from configuration store and subscribe the updates. - * - * @param The Type of the return. - * @param configurationRequestItem Request object. - * @param type The Type needed as return for the call. - * @return A Flux Plan of response with type T. Subscribe update listener. - */ - Flux> subscribeConfiguration(ConfigurationRequestItem configurationRequestItem, - TypeRef type); -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/InvocationRuntimes.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/InvocationRuntimes.java deleted file mode 100644 index 7d9f20b..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/InvocationRuntimes.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core; - -import reactor.core.publisher.Mono; -import spec.sdk.reactor.v1.domain.core.invocation.HttpExtension; -import spec.sdk.reactor.v1.domain.core.invocation.InvokeMethodRequest; -import spec.sdk.reactor.v1.utils.TypeRef; - -import java.util.Map; - -/** - * Service-to-Service Invocation Runtimes standard API defined. - */ -public interface InvocationRuntimes { - - /** - * Invoke a service method, using serialization. - * - * @param appId The Application ID where the service is. - * @param methodName The actual Method to be call in the application. - * @param data The data to be sent to invoke the service, use byte[] to skip serialization. - * @param httpExtension Additional fields that are needed if the receiving app is listening on - * HTTP, {@link HttpExtension#NONE} otherwise. - * @param metadata Metadata (in GRPC) or headers (in HTTP) to be sent in data. - * @param type The Type needed as return for the call. - * @param The Type of the return, use byte[] to skip serialization. - * @return A Mono Plan of type T. - */ - Mono invokeMethod(String appId, String methodName, Object data, HttpExtension httpExtension, - Map metadata, TypeRef type); - - /** - * Invoke a service method, using serialization. - * - * @param appId The Application ID where the service is. - * @param methodName The actual Method to be call in the application. - * @param request The request to be sent to invoke the service, use byte[] to skip serialization. - * @param httpExtension Additional fields that are needed if the receiving app is listening on - * HTTP, {@link HttpExtension#NONE} otherwise. - * @param metadata Metadata (in GRPC) or headers (in HTTP) to be sent in request. - * @param clazz The type needed as return for the call. - * @param The Type of the return, use byte[] to skip serialization. - * @return A Mono Plan of type T. - */ - Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - Map metadata, Class clazz); - - /** - * Invoke a service method, using serialization. - * - * @param appId The Application ID where the service is. - * @param methodName The actual Method to be call in the application. - * @param request The request to be sent to invoke the service, use byte[] to skip serialization. - * @param httpExtension Additional fields that are needed if the receiving app is listening on - * HTTP, {@link HttpExtension#NONE} otherwise. - * @param type The Type needed as return for the call. - * @param The Type of the return, use byte[] to skip serialization. - * @return A Mono Plan of type T. - */ - Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - TypeRef type); - - /** - * Invoke a service method, using serialization. - * - * @param appId The Application ID where the service is. - * @param methodName The actual Method to be call in the application. - * @param request The request to be sent to invoke the service, use byte[] to skip serialization. - * @param httpExtension Additional fields that are needed if the receiving app is listening on - * HTTP, {@link HttpExtension#NONE} otherwise. - * @param clazz The type needed as return for the call. - * @param The Type of the return, use byte[] to skip serialization. - * @return A Mono Plan of type T. - */ - Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - Class clazz); - - /** - * Invoke a service method, using serialization. - * - * @param appId The Application ID where the service is. - * @param methodName The actual Method to be call in the application. - * @param httpExtension Additional fields that are needed if the receiving app is listening on - * HTTP, {@link HttpExtension#NONE} otherwise. - * @param metadata Metadata (in GRPC) or headers (in HTTP) to be sent in request. - * @param type The Type needed as return for the call. - * @param The Type of the return, use byte[] to skip serialization. - * @return A Mono Plan of type T. - */ - Mono invokeMethod(String appId, String methodName, HttpExtension httpExtension, - Map metadata, - TypeRef type); - - /** - * Invoke a service method, using serialization. - * - * @param appId The Application ID where the service is. - * @param methodName The actual Method to be call in the application. - * @param httpExtension Additional fields that are needed if the receiving app is listening on - * HTTP, {@link HttpExtension#NONE} otherwise. - * @param metadata Metadata (in GRPC) or headers (in HTTP) to be sent in request. - * @param clazz The type needed as return for the call. - * @param The Type of the return, use byte[] to skip serialization. - * @return A Mono Plan of type T. - */ - Mono invokeMethod(String appId, String methodName, HttpExtension httpExtension, - Map metadata, - Class clazz); - - /** - * Invoke a service method, using serialization. - * - * @param appId The Application ID where the service is. - * @param methodName The actual Method to be call in the application. - * @param request The request to be sent to invoke the service, use byte[] to skip serialization. - * @param httpExtension Additional fields that are needed if the receiving app is listening on - * HTTP, {@link HttpExtension#NONE} otherwise. - * @param metadata Metadata (in GRPC) or headers (in HTTP) to be sent in request. - * @return A Mono Plan of type Void. - */ - Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension, - Map metadata); - - /** - * Invoke a service method, using serialization. - * - * @param appId The Application ID where the service is. - * @param methodName The actual Method to be call in the application. - * @param request The request to be sent to invoke the service, use byte[] to skip serialization. - * @param httpExtension Additional fields that are needed if the receiving app is listening on - * HTTP, {@link HttpExtension#NONE} otherwise. - * @return A Mono Plan of type Void. - */ - Mono invokeMethod(String appId, String methodName, Object request, HttpExtension httpExtension); - - /** - * Invoke a service method, using serialization. - * - * @param appId The Application ID where the service is. - * @param methodName The actual Method to be call in the application. - * @param httpExtension Additional fields that are needed if the receiving app is listening on - * HTTP, {@link HttpExtension#NONE} otherwise. - * @param metadata Metadata (in GRPC) or headers (in HTTP) to be sent in request. - * @return A Mono Plan of type Void. - */ - Mono invokeMethod(String appId, String methodName, HttpExtension httpExtension, Map metadata); - - /** - * Invoke a service method, without using serialization. - * - * @param appId The Application ID where the service is. - * @param methodName The actual Method to be call in the application. - * @param request The request to be sent to invoke the service, use byte[] to skip serialization. - * @param httpExtension Additional fields that are needed if the receiving app is listening on - * HTTP, {@link HttpExtension#NONE} otherwise. - * @param metadata Metadata (in GRPC) or headers (in HTTP) to be sent in request. - * @return A Mono Plan of type byte[]. - */ - Mono invokeMethod(String appId, String methodName, byte[] request, HttpExtension httpExtension, - Map metadata); - - /** - * Invoke a service method. - * - * @param invokeMethodRequest Request object. - * @param type The Type needed as return for the call. - * @param The Type of the return, use byte[] to skip serialization. - * @return A Mono Plan of type T. - */ - Mono invokeMethod(InvokeMethodRequest invokeMethodRequest, TypeRef type); -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/PubSubRuntimes.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/PubSubRuntimes.java deleted file mode 100644 index c09b6b1..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/PubSubRuntimes.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core; - -import reactor.core.publisher.Mono; -import spec.sdk.reactor.v1.domain.core.pubsub.PublishEventRequest; - -import java.util.Map; - -/** - * Publish and Subscribe Runtimes standard API defined. - */ -public interface PubSubRuntimes { - - /** - * Publish an event. - * - * @param pubsubName the pubsub name we will publish the event to - * @param topicName the topicName where the event will be published. - * @param data the event's data to be published, use byte[] for skipping serialization. - * @return a Mono plan of type Void. - */ - Mono publishEvent(String pubsubName, String topicName, Object data); - - /** - * Publish an event. - * - * @param pubsubName the pubsub name we will publish the event to - * @param topicName the topicName where the event will be published. - * @param data the event's data to be published, use byte[] for skipping serialization. - * @param metadata The metadata for the published event. - * @return a Mono plan of type Void. - */ - Mono publishEvent(String pubsubName, String topicName, Object data, Map metadata); - - /** - * Publish an event. - * - * @param request the request for the publish event. - * @return a Mono plan of a CloudRuntimes's void response. - */ - Mono publishEvent(PublishEventRequest request); -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/StateRuntimes.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/StateRuntimes.java deleted file mode 100644 index 465de5f..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/StateRuntimes.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core; - -import reactor.core.publisher.Mono; -import spec.sdk.reactor.v1.domain.core.state.DeleteStateRequest; -import spec.sdk.reactor.v1.domain.core.state.ExecuteStateTransactionRequest; -import spec.sdk.reactor.v1.domain.core.state.GetBulkStateRequest; -import spec.sdk.reactor.v1.domain.core.state.GetStateRequest; -import spec.sdk.reactor.v1.domain.core.state.SaveStateRequest; -import spec.sdk.reactor.v1.domain.core.state.State; -import spec.sdk.reactor.v1.domain.core.state.StateOptions; -import spec.sdk.reactor.v1.domain.core.state.TransactionalStateOperation; -import spec.sdk.reactor.v1.utils.TypeRef; - -import java.util.List; - -/** - * State Management Runtimes standard API defined. - */ -public interface StateRuntimes { - - /** - * Retrieve a State based on their key. - * - * @param storeName The name of the state store. - * @param state State to be re-retrieved. - * @param type The type of State needed as return. - * @param The type of the return. - * @return A Mono Plan for the requested State. - */ - Mono> getState(String storeName, State state, TypeRef type); - - /** - * Retrieve a State based on their key. - * - * @param storeName The name of the state store. - * @param state State to be re-retrieved. - * @param clazz The type of State needed as return. - * @param The type of the return. - * @return A Mono Plan for the requested State. - */ - Mono> getState(String storeName, State state, Class clazz); - - /** - * Retrieve a State based on their key. - * - * @param storeName The name of the state store. - * @param key The key of the State to be retrieved. - * @param type The type of State needed as return. - * @param The type of the return. - * @return A Mono Plan for the requested State. - */ - Mono> getState(String storeName, String key, TypeRef type); - - /** - * Retrieve a State based on their key. - * - * @param storeName The name of the state store. - * @param key The key of the State to be retrieved. - * @param clazz The type of State needed as return. - * @param The type of the return. - * @return A Mono Plan for the requested State. - */ - Mono> getState(String storeName, String key, Class clazz); - - /** - * Retrieve a State based on their key. - * - * @param storeName The name of the state store. - * @param key The key of the State to be retrieved. - * @param options Optional settings for retrieve operation. - * @param type The Type of State needed as return. - * @param The Type of the return. - * @return A Mono Plan for the requested State. - */ - Mono> getState(String storeName, String key, StateOptions options, TypeRef type); - - /** - * Retrieve a State based on their key. - * - * @param storeName The name of the state store. - * @param key The key of the State to be retrieved. - * @param options Optional settings for retrieve operation. - * @param clazz The Type of State needed as return. - * @param The Type of the return. - * @return A Mono Plan for the requested State. - */ - Mono> getState(String storeName, String key, StateOptions options, Class clazz); - - /** - * Retrieve a State based on their key. - * - * @param request The request to get state. - * @param type The Type of State needed as return. - * @param The Type of the return. - * @return A Mono Plan for the requested State. - */ - Mono> getState(GetStateRequest request, TypeRef type); - - /** - * Retrieve bulk States based on their keys. - * - * @param storeName The name of the state store. - * @param keys The keys of the State to be retrieved. - * @param type The type of State needed as return. - * @param The type of the return. - * @return A Mono Plan for the requested State. - */ - Mono>> getBulkState(String storeName, List keys, TypeRef type); - - /** - * Retrieve bulk States based on their keys. - * - * @param storeName The name of the state store. - * @param keys The keys of the State to be retrieved. - * @param clazz The type of State needed as return. - * @param The type of the return. - * @return A Mono Plan for the requested State. - */ - Mono>> getBulkState(String storeName, List keys, Class clazz); - - /** - * Retrieve bulk States based on their keys. - * - * @param request The request to get state. - * @param type The Type of State needed as return. - * @param The Type of the return. - * @return A Mono Plan for the requested State. - */ - Mono>> getBulkState(GetBulkStateRequest request, TypeRef type); - - /** - * Execute a transaction. - * - * @param storeName The name of the state store. - * @param operations The operations to be performed. - * @return a Mono plan of type Void - */ - Mono executeStateTransaction(String storeName, - List> operations); - - /** - * Execute a transaction. - * - * @param request Request to execute transaction. - * @return a Mono plan of type Response Void - */ - Mono executeStateTransaction(ExecuteStateTransactionRequest request); - - /** - * Save/Update a list of states. - * - * @param storeName The name of the state store. - * @param states The States to be saved. - * @return a Mono plan of type Void. - */ - Mono saveBulkState(String storeName, List> states); - - /** - * Save/Update a list of states. - * - * @param request Request to save states. - * @return a Mono plan of type Void. - */ - Mono saveBulkState(SaveStateRequest request); - - /** - * Save/Update a state. - * - * @param storeName The name of the state store. - * @param key The key of the state. - * @param value The value of the state. - * @return a Mono plan of type Void. - */ - Mono saveState(String storeName, String key, Object value); - - /** - * Save/Update a state. - * - * @param storeName The name of the state store. - * @param key The key of the state. - * @param etag The etag to be used. - * @param value The value of the state. - * @param options The Options to use for each state. - * @return a Mono plan of type Void. - */ - Mono saveState(String storeName, String key, String etag, Object value, StateOptions options); - - /** - * Delete a state. - * - * @param storeName The name of the state store. - * @param key The key of the State to be removed. - * @return a Mono plan of type Void. - */ - Mono deleteState(String storeName, String key); - - /** - * Delete a state. - * - * @param storeName The name of the state store. - * @param key The key of the State to be removed. - * @param etag Optional etag for conditional delete. - * @param options Optional settings for state operation. - * @return a Mono plan of type Void. - */ - Mono deleteState(String storeName, String key, String etag, StateOptions options); - - /** - * Delete a state. - * - * @param request Request to delete a state. - * @return a Mono plan of type Void. - */ - Mono deleteState(DeleteStateRequest request); -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/pubsub/PublishEventRequest.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/pubsub/PublishEventRequest.java deleted file mode 100644 index 23ed0ab..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/pubsub/PublishEventRequest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core.pubsub; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * A request to publish an event. - */ -public class PublishEventRequest { - - private final String pubsubName; - - private final String topic; - - private final Object data; - - private String contentType; - - private Map metadata = new HashMap<>(); - - /** - * Constructor for PublishEventRequest. - * - * @param pubsubName name of the pubsub - * @param topic name of the topic in the pubsub - * @param data data to published - */ - public PublishEventRequest(String pubsubName, String topic, Object data) { - this.pubsubName = pubsubName; - this.topic = topic; - this.data = data; - } - - public String getPubsubName() { - return pubsubName; - } - - public String getTopic() { - return topic; - } - - public Object getData() { - return data; - } - - public String getContentType() { - return this.contentType; - } - - public PublishEventRequest setContentType(String contentType) { - this.contentType = contentType; - return this; - } - - public Map getMetadata() { - return metadata; - } - - public PublishEventRequest setMetadata(Map metadata) { - this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata); - return this; - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/DeleteStateRequest.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/DeleteStateRequest.java deleted file mode 100644 index 2e36361..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/DeleteStateRequest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core.state; - -import java.util.Collections; -import java.util.Map; - -/** - * A request to delete a state by key. - */ -public class DeleteStateRequest { - - private final String stateStoreName; - - private final String key; - - private Map metadata; - - private String etag; - - private StateOptions stateOptions; - - public DeleteStateRequest(String storeName, String key) { - this.stateStoreName = storeName; - this.key = key; - } - - public String getStateStoreName() { - return stateStoreName; - } - - public String getKey() { - return key; - } - - public String getEtag() { - return etag; - } - - public DeleteStateRequest setEtag(String etag) { - this.etag = etag; - return this; - } - - public StateOptions getStateOptions() { - return stateOptions; - } - - public DeleteStateRequest setStateOptions(StateOptions stateOptions) { - this.stateOptions = stateOptions; - return this; - } - - public Map getMetadata() { - return metadata; - } - - public DeleteStateRequest setMetadata(Map metadata) { - this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata); - return this; - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/ExecuteStateTransactionRequest.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/ExecuteStateTransactionRequest.java deleted file mode 100644 index 8bed077..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/ExecuteStateTransactionRequest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core.state; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public class ExecuteStateTransactionRequest { - - /** - * Name of the state store. - */ - private final String stateStoreName; - - /** - * Transactional operations list. - */ - private List> operations; - - /** - * Metadata used for transactional operations. - */ - private Map metadata; - - public ExecuteStateTransactionRequest(String stateStoreName) { - this.stateStoreName = stateStoreName; - } - - public String getStateStoreName() { - return stateStoreName; - } - - public ExecuteStateTransactionRequest setOperations(List> operations) { - this.operations = operations == null ? null : Collections.unmodifiableList(operations); - return this; - } - - public List> getOperations() { - return operations; - } - - public ExecuteStateTransactionRequest setMetadata(Map metadata) { - this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata); - return this; - } - - public Map getMetadata() { - return metadata; - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/GetBulkStateRequest.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/GetBulkStateRequest.java deleted file mode 100644 index 11c5f5a..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/GetBulkStateRequest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core.state; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** - * A request to get bulk state by keys. - */ -public class GetBulkStateRequest { - - private final String storeName; - - private final List keys; - - private Map metadata; - - private int parallelism = 1; - - public GetBulkStateRequest(String storeName, List keys) { - this.storeName = storeName; - this.keys = keys == null ? null : Collections.unmodifiableList(keys); - } - - public GetBulkStateRequest(String storeName, String... keys) { - this.storeName = storeName; - this.keys = keys == null ? null : Collections.unmodifiableList(Arrays.asList(keys)); - } - - public String getStoreName() { - return storeName; - } - - public List getKeys() { - return keys; - } - - public int getParallelism() { - return parallelism; - } - - public GetBulkStateRequest setParallelism(int parallelism) { - this.parallelism = parallelism; - return this; - } - - public Map getMetadata() { - return metadata; - } - - public GetBulkStateRequest setMetadata(Map metadata) { - this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata); - return this; - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/GetStateRequest.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/GetStateRequest.java deleted file mode 100644 index 141ef0e..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/GetStateRequest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core.state; - -import java.util.Collections; -import java.util.Map; - -/** - * A request to get a state by key. - */ -public class GetStateRequest { - - private final String storeName; - - private final String key; - - private Map metadata; - - private StateOptions stateOptions; - - public GetStateRequest(String storeName, String key) { - this.storeName = storeName; - this.key = key; - } - - public String getStoreName() { - return storeName; - } - - public String getKey() { - return key; - } - - public StateOptions getStateOptions() { - return stateOptions; - } - - public GetStateRequest setStateOptions(StateOptions stateOptions) { - this.stateOptions = stateOptions; - return this; - } - - public Map getMetadata() { - return metadata; - } - - public GetStateRequest setMetadata(Map metadata) { - this.metadata = metadata == null ? null : Collections.unmodifiableMap(metadata); - return this; - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/SaveStateRequest.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/SaveStateRequest.java deleted file mode 100644 index da6aca2..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/SaveStateRequest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core.state; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -/** - * A request to save states to state store. - */ -public class SaveStateRequest { - - private final String storeName; - - private List> states; - - public SaveStateRequest(String storeName) { - this.storeName = storeName; - } - - public String getStoreName() { - return storeName; - } - - public List> getStates() { - return states; - } - - public SaveStateRequest setStates(List> states) { - this.states = states == null ? null : Collections.unmodifiableList(states); - return this; - } - - public SaveStateRequest setStates(State... states) { - this.states = Collections.unmodifiableList(Arrays.asList(states)); - return this; - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/State.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/State.java deleted file mode 100644 index c25f733..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/State.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core.state; - -import java.util.Map; - -/** - * This class reprent what a State is. - * - * @param The type of the value of the sate - */ -public class State { - - /** - * The value of the state. - */ - private final T value; - - /** - * The key of the state. - */ - private final String key; - - /** - * The ETag to be used - * Keep in mind that for some state stores (like redis) only numbers are supported. - */ - private final String etag; - - /** - * The metadata which will be passed to state store component. - */ - private final Map metadata; - - /** - * The error in case the key could not be retrieved. - */ - private final String error; - - /** - * The options used for saving the state. - */ - private final StateOptions options; - - /** - * Create an immutable state reference to be retrieved or deleted. - * This Constructor CAN be used anytime you need to retrieve or delete a state. - * - * @param key - The key of the state - */ - public State(String key) { - this.key = key; - this.value = null; - this.etag = null; - this.metadata = null; - this.options = null; - this.error = null; - } - - /** - * Create an immutable state reference to be retrieved or deleted. - * This Constructor CAN be used anytime you need to retrieve or delete a state. - * - * @param key - The key of the state - * @param etag - The etag of the state - Keep in mind that for some state stores (like redis) only numbers - * are supported. - * @param options - REQUIRED when saving a state. - */ - public State(String key, String etag, StateOptions options) { - this.value = null; - this.key = key; - this.etag = etag; - this.metadata = null; - this.options = options; - this.error = null; - } - - /** - * Create an immutable state. - * This Constructor CAN be used anytime you want the state to be saved. - * - * @param key - The key of the state. - * @param value - The value of the state. - * @param etag - The etag of the state - for some state stores (like redis) only numbers are supported. - * @param options - REQUIRED when saving a state. - */ - public State(String key, T value, String etag, StateOptions options) { - this.value = value; - this.key = key; - this.etag = etag; - this.metadata = null; - this.options = options; - this.error = null; - } - - /** - * Create an immutable state. - * This Constructor CAN be used anytime you want the state to be saved. - * - * @param key - The key of the state. - * @param value - The value of the state. - * @param etag - The etag of the state - for some state stores (like redis) only numbers are supported. - * @param metadata - The metadata of the state. - * @param options - REQUIRED when saving a state. - */ - public State(String key, T value, String etag, Map metadata, StateOptions options) { - this.value = value; - this.key = key; - this.etag = etag; - this.metadata = metadata; - this.options = options; - this.error = null; - } - - /** - * Create an immutable state. - * This Constructor CAN be used anytime you want the state to be saved. - * - * @param key - The key of the state. - * @param value - The value of the state. - * @param etag - The etag of the state - some state stores (like redis) only numbers are supported. - */ - public State(String key, T value, String etag) { - this.value = value; - this.key = key; - this.etag = etag; - this.metadata = null; - this.options = null; - this.error = null; - } - - /** - * Create an immutable state. - * This Constructor MUST be used anytime the key could not be retrieved and contains an error. - * - * @param key - The key of the state. - * @param error - Error when fetching the state. - */ - public State(String key, String error) { - this.value = null; - this.key = key; - this.etag = null; - this.metadata = null; - this.options = null; - this.error = error; - } - - /** - * Retrieves the Value of the state. - * - * @return The value of the state - */ - public T getValue() { - return value; - } - - /** - * Retrieves the Key of the state. - * - * @return The key of the state - */ - public String getKey() { - return key; - } - - /** - * Retrieve the ETag of this state. - * - * @return The etag of the state - */ - public String getEtag() { - return etag; - } - - /** - * Retrieve the metadata of this state. - * - * @return the metadata of this state - */ - public Map getMetadata() { - return metadata; - } - - /** - * Retrieve the error for this state. - * - * @return The error for this state. - */ - - public String getError() { - return error; - } - - /** - * Retrieve the Options used for saving the state. - * - * @return The options to save the state - */ - public StateOptions getOptions() { - return options; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (!(o instanceof State)) { - return false; - } - - State that = (State) o; - - if (getValue() != null ? !getValue().equals(that.getValue()) : that.getValue() != null) { - return false; - } - - if (getKey() != null ? !getKey().equals(that.getKey()) : that.getKey() != null) { - return false; - } - - if (getEtag() != null ? !getEtag().equals(that.getEtag()) : that.getEtag() != null) { - return false; - } - - if (getError() != null ? !getError().equals(that.getError()) : that.getError() != null) { - return false; - } - - if (getMetadata() != null ? !getMetadata().equals(that.getMetadata()) : that.getMetadata() != null) { - return false; - } - - if (getOptions() != null ? !getOptions().equals(that.getOptions()) : that.getOptions() != null) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = getValue() != null ? getValue().hashCode() : 0; - result = 31 * result + (getKey() != null ? getKey().hashCode() : 0); - result = 31 * result + (getEtag() != null ? getEtag().hashCode() : 0); - result = 31 * result + (getMetadata() != null ? getMetadata().hashCode() : 0); - result = 31 * result + (getError() != null ? getError().hashCode() : 0); - result = 31 * result + (getOptions() != null ? options.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "StateKeyValue{" - + "key='" + key + "'" - + ", value=" + value - + ", etag='" + etag + "'" - + ", metadata={'" + (metadata != null ? metadata.toString() : null) + "'}" - + ", error='" + error + "'" - + ", options={'" + (options != null ? options.toString() : null) + "'}" - + "}"; - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/StateOptions.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/StateOptions.java deleted file mode 100644 index 2874b42..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/StateOptions.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core.state; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -public class StateOptions { - - private final Consistency consistency; - private final Concurrency concurrency; - - /** - * Represents options for a CloudRuntimes state API call. - * - * @param consistency The consistency mode. - * @param concurrency The concurrency mode. - */ - public StateOptions(Consistency consistency, Concurrency concurrency) { - this.consistency = consistency; - this.concurrency = concurrency; - } - - public Concurrency getConcurrency() { - return concurrency; - } - - public Consistency getConsistency() { - return consistency; - } - - /** - * Returns state options as a Map of option name to value. - * - * @return A map of state options. - */ - public Map getStateOptionsAsMap() { - Map mapOptions = new HashMap<>(); - if (this.getConsistency() != null) { - mapOptions.put("consistency", this.getConsistency().getValue()); - } - if (this.getConcurrency() != null) { - mapOptions.put("concurrency", this.getConcurrency().getValue()); - } - return Collections.unmodifiableMap(Optional.ofNullable(mapOptions).orElse(Collections.EMPTY_MAP)); - } - - public enum Consistency { - - EVENTUAL("eventual"), - STRONG("strong"); - - private final String value; - - Consistency(String value) { - this.value = value; - } - - public String getValue() { - return this.value; - } - - public static Consistency fromValue(String value) { - return Consistency.valueOf(value); - } - } - - public enum Concurrency { - - FIRST_WRITE("first-write"), - LAST_WRITE("last-write"); - - private final String value; - - Concurrency(String value) { - this.value = value; - } - - public String getValue() { - return this.value; - } - - public static Concurrency fromValue(String value) { - return Concurrency.valueOf(value); - } - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/TransactionalStateOperation.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/TransactionalStateOperation.java deleted file mode 100644 index 81f8d17..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/TransactionalStateOperation.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core.state; - -import java.util.Objects; - -public class TransactionalStateOperation { - - /** - * The type of operation to be executed. - */ - private final OperationType operation; - - /** - * State values to be operated on. - */ - private final State request; - - /** - * Construct an immutable transactional state operation object. - * - * @param operationType The type of operation done. - * @param state The required state. - */ - public TransactionalStateOperation(OperationType operationType, State state) { - this.operation = operationType; - this.request = state; - } - - public OperationType getOperation() { - return operation; - } - - public State getRequest() { - return request; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TransactionalStateOperation that = (TransactionalStateOperation) o; - return operation.equals(that.operation) - && request.equals(that.request); - } - - @Override - public int hashCode() { - return Objects.hash(operation, request); - } - - @Override - public String toString() { - return "TransactionalStateOperation{" - + "operationType='" + operation + '\'' - + ", state=" + request - + '}'; - } - - public enum OperationType { - UPSERT, - DELETE - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/TransactionalStateRequest.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/TransactionalStateRequest.java deleted file mode 100644 index 620b306..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/core/state/TransactionalStateRequest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.core.state; - -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public class TransactionalStateRequest { - - /** - * Transactional operations list. - */ - private final List> operations; - - /** - * Metadata used for transactional operations. - */ - private final Map metadata; - - /** - * Constructor to create immutable transactional state request object. - * - * @param operations List of operations to be performed. - * @param metadata Metadata used for transactional operations. - */ - public TransactionalStateRequest(List> operations, Map metadata) { - this.operations = operations; - this.metadata = metadata; - } - - public List> getOperations() { - return Collections.unmodifiableList(operations); - } - - public Map getMetadata() { - return metadata; - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/enhanced/MetricsRuntimes.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/enhanced/MetricsRuntimes.java deleted file mode 100644 index db5069b..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/enhanced/MetricsRuntimes.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.domain.enhanced; - -/** - * Metrics Runtimes standard API defined. - */ -public interface MetricsRuntimes { - - // TODO: 2021/8/31 API - // see https://github.com/reactivegroup/cloud-runtimes-jvm/issues/2 -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/package-info.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/package-info.java deleted file mode 100644 index c046d9e..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/domain/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Building blocks address common challenges in building resilient, microservices applications and codify best practices and patterns. - * CloudRuntimes consists of a set of building blocks, with extensibility to add new building blocks. - */ -package spec.sdk.reactor.v1.domain; \ No newline at end of file diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/utils/TypeRef.java b/sdk-reactor/src/main/java/spec/sdk/reactor/v1/utils/TypeRef.java deleted file mode 100644 index 7f6ded6..0000000 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/utils/TypeRef.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2021 Layotto Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package spec.sdk.reactor.v1.utils; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; - -/** - * Used to reference a type. - * - *

Usage: new TypeRef<MyClass>(){}

- * - * @param Type to be deserialized. - */ -public abstract class TypeRef { - - public static final TypeRef STRING = new TypeRef() { - }; - - public static final TypeRef BOOLEAN = new TypeRef(boolean.class) { - }; - - public static final TypeRef INT = new TypeRef(int.class) { - }; - - public static final TypeRef LONG = new TypeRef(long.class) { - }; - - public static final TypeRef CHAR = new TypeRef(char.class) { - }; - - public static final TypeRef BYTE = new TypeRef(byte.class) { - }; - - public static final TypeRef VOID = new TypeRef(void.class) { - }; - - public static final TypeRef FLOAT = new TypeRef(float.class) { - }; - - public static final TypeRef DOUBLE = new TypeRef(double.class) { - }; - - public static final TypeRef BYTE_ARRAY = new TypeRef() { - }; - - public static final TypeRef INT_ARRAY = new TypeRef() { - }; - - public static final TypeRef STRING_ARRAY = new TypeRef() { - }; - - private final Type type; - - /** - * Constructor. - */ - public TypeRef() { - Type superClass = this.getClass().getGenericSuperclass(); - if (superClass instanceof Class) { - throw new IllegalArgumentException("TypeReference requires type."); - } - - this.type = ((ParameterizedType) superClass).getActualTypeArguments()[0]; - } - - /** - * Constructor for reflection. - * - * @param type Type to be referenced. - */ - private TypeRef(Type type) { - this.type = type; - } - - /** - * Gets the type referenced. - * - * @return type referenced. - */ - public Type getType() { - return this.type; - } - - /** - * Creates a reference to a given class type. - * - * @param clazz Class type to be referenced. - * @param Type to be referenced. - * @return Class type reference. - */ - public static TypeRef get(Class clazz) { - if (clazz == String.class) { - return (TypeRef) STRING; - } - if (clazz == boolean.class) { - return (TypeRef) BOOLEAN; - } - if (clazz == int.class) { - return (TypeRef) INT; - } - if (clazz == long.class) { - return (TypeRef) LONG; - } - if (clazz == char.class) { - return (TypeRef) CHAR; - } - if (clazz == byte.class) { - return (TypeRef) BYTE; - } - if (clazz == void.class) { - return (TypeRef) VOID; - } - if (clazz == float.class) { - return (TypeRef) FLOAT; - } - if (clazz == double.class) { - return (TypeRef) DOUBLE; - } - if (clazz == byte[].class) { - return (TypeRef) BYTE_ARRAY; - } - if (clazz == int[].class) { - return (TypeRef) INT_ARRAY; - } - if (clazz == String[].class) { - return (TypeRef) STRING_ARRAY; - } - - return new TypeRef(clazz) { - }; - } - - /** - * Creates a reference to a given class type. - * - * @param type Type to be referenced. - * @param Type to be referenced. - * @return Class type reference. - */ - public static TypeRef get(Type type) { - if (type instanceof Class) { - Class clazz = (Class) type; - return get(clazz); - } - - return new TypeRef(type) { - }; - } -} diff --git a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/client/CloudRuntimesClient.java b/sdk-reactor/src/main/java/spec/sdk/runtime/reactor/v1/client/ReactorRuntimeClient.java similarity index 59% rename from sdk-reactor/src/main/java/spec/sdk/reactor/v1/client/CloudRuntimesClient.java rename to sdk-reactor/src/main/java/spec/sdk/runtime/reactor/v1/client/ReactorRuntimeClient.java index 60b19c9..45c4287 100644 --- a/sdk-reactor/src/main/java/spec/sdk/reactor/v1/client/CloudRuntimesClient.java +++ b/sdk-reactor/src/main/java/spec/sdk/runtime/reactor/v1/client/ReactorRuntimeClient.java @@ -12,16 +12,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package spec.sdk.reactor.v1.client; +package spec.sdk.runtime.reactor.v1.client; import reactor.core.publisher.Mono; -import spec.sdk.reactor.v1.CoreCloudRuntimes; -import spec.sdk.reactor.v1.EnhancedCloudRuntimes; +import spec.sdk.runtime.v1.domain.rx.ConfigurationRxRuntime; +import spec.sdk.runtime.v1.domain.rx.FileRxRuntime; +import spec.sdk.runtime.v1.domain.rx.HelloRxRuntime; +import spec.sdk.runtime.v1.domain.rx.InvocationRxRuntime; +import spec.sdk.runtime.v1.domain.rx.LockRxRuntime; +import spec.sdk.runtime.v1.domain.rx.PubSubRxRuntime; +import spec.sdk.runtime.v1.domain.rx.SequencerRxRuntime; +import spec.sdk.runtime.v1.domain.rx.StateRxRuntime; /** * Cloud Runtimes JVM Client. */ -public interface CloudRuntimesClient extends AutoCloseable, CoreCloudRuntimes, EnhancedCloudRuntimes { +public interface ReactorRuntimeClient extends + ConfigurationRxRuntime, + FileRxRuntime, + HelloRxRuntime, + InvocationRxRuntime, + LockRxRuntime, + PubSubRxRuntime, + SequencerRxRuntime, + StateRxRuntime { /** * Waits for the sidecar, giving up after timeout. diff --git a/sdk/pom.xml b/sdk/pom.xml index 792b2e7..d12e039 100644 --- a/sdk/pom.xml +++ b/sdk/pom.xml @@ -18,8 +18,9 @@ io.mosn.layotto - runtime-spec-pb + runtime-sdk-grpc + com.alibaba @@ -31,11 +32,6 @@ slf4j-api - - io.grpc - grpc-all - - junit junit diff --git a/sdk/src/main/java/io/mosn/layotto/v1/AbstractRuntimeClient.java b/sdk/src/main/java/io/mosn/layotto/v1/AbstractRuntimeClient.java index 16ca30c..424617b 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/AbstractRuntimeClient.java +++ b/sdk/src/main/java/io/mosn/layotto/v1/AbstractRuntimeClient.java @@ -14,12 +14,13 @@ */ package io.mosn.layotto.v1; -import io.mosn.layotto.v1.config.RuntimeProperties; -import io.mosn.layotto.v1.exceptions.RuntimeClientException; -import io.mosn.layotto.v1.serializer.ObjectSerializer; +import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties; +import io.mosn.layotto.v1.infrastructure.exceptions.RuntimeClientException; +import io.mosn.layotto.v1.infrastructure.serializer.ObjectSerializer; import org.slf4j.Logger; import spec.sdk.runtime.v1.client.RuntimeClient; import spec.sdk.runtime.v1.domain.invocation.InvokeResponse; +import spec.sdk.runtime.v1.domain.pubsub.PublishEventRequest; import spec.sdk.runtime.v1.domain.state.DeleteStateRequest; import spec.sdk.runtime.v1.domain.state.ExecuteStateTransactionRequest; import spec.sdk.runtime.v1.domain.state.GetBulkStateRequest; @@ -85,6 +86,18 @@ public void publishEvent(String pubsubName, String topicName, byte[] data, Map metadata) { + PublishEventRequest publishEventRequest = new PublishEventRequest(); + publishEventRequest.setPubsubName(pubsubName); + publishEventRequest.setTopic(topicName); + publishEventRequest.setData(data); + publishEventRequest.setContentType(contentType); + publishEventRequest.setMetadata(metadata); + this.publishEvent(publishEventRequest); + } + /** * Retrieve a State based on their key. * @@ -182,7 +195,7 @@ public void deleteState(String storeName, String key, String etag, StateOptions */ @Override public void deleteState(DeleteStateRequest request) { - deleteState(request, getTimeoutMs()); + deleteState(request, this.getTimeoutMs()); } /** diff --git a/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientBuilder.java b/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientBuilder.java index f488d18..b668307 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientBuilder.java +++ b/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientBuilder.java @@ -17,15 +17,15 @@ import com.google.errorprone.annotations.DoNotCall; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import io.mosn.layotto.v1.config.RuntimeProperties; -import io.mosn.layotto.v1.domain.ApiProtocol; import io.mosn.layotto.v1.grpc.GrpcRuntimeClient; import io.mosn.layotto.v1.grpc.stub.PooledStubManager; import io.mosn.layotto.v1.grpc.stub.SingleStubManager; import io.mosn.layotto.v1.grpc.stub.StubCreator; import io.mosn.layotto.v1.grpc.stub.StubManager; +import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties; +import io.mosn.layotto.v1.infrastructure.serializer.ObjectSerializer; +import io.mosn.layotto.v1.infrastructure.value.ApiProtocol; import io.mosn.layotto.v1.serializer.JSONSerializer; -import io.mosn.layotto.v1.serializer.ObjectSerializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import spec.proto.runtime.v1.RuntimeGrpc; diff --git a/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientGrpc.java b/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientGrpc.java index 21bf4a8..da09435 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientGrpc.java +++ b/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientGrpc.java @@ -22,14 +22,17 @@ import io.grpc.StatusRuntimeException; import io.grpc.stub.MetadataUtils; import io.grpc.stub.StreamObserver; -import io.mosn.layotto.v1.config.RuntimeProperties; -import io.mosn.layotto.v1.exceptions.RuntimeClientException; import io.mosn.layotto.v1.grpc.GrpcRuntimeClient; import io.mosn.layotto.v1.grpc.stub.StubManager; -import io.mosn.layotto.v1.serializer.ObjectSerializer; +import io.mosn.layotto.v1.infrastructure.config.RuntimeProperties; +import io.mosn.layotto.v1.infrastructure.exceptions.RuntimeClientException; +import io.mosn.layotto.v1.infrastructure.serializer.ObjectSerializer; import org.slf4j.Logger; import spec.proto.runtime.v1.RuntimeGrpc; import spec.proto.runtime.v1.RuntimeProto; +import spec.sdk.runtime.v1.domain.configuration.ConfigurationItem; +import spec.sdk.runtime.v1.domain.configuration.ConfigurationRequestItem; +import spec.sdk.runtime.v1.domain.configuration.SaveConfigurationRequest; import spec.sdk.runtime.v1.domain.file.DelFileRequest; import spec.sdk.runtime.v1.domain.file.DelFileResponse; import spec.sdk.runtime.v1.domain.file.FileInfo; @@ -42,6 +45,7 @@ import spec.sdk.runtime.v1.domain.file.PutFileRequest; import spec.sdk.runtime.v1.domain.file.PutFileResponse; import spec.sdk.runtime.v1.domain.invocation.InvokeResponse; +import spec.sdk.runtime.v1.domain.pubsub.PublishEventRequest; import spec.sdk.runtime.v1.domain.state.DeleteStateRequest; import spec.sdk.runtime.v1.domain.state.ExecuteStateTransactionRequest; import spec.sdk.runtime.v1.domain.state.GetBulkStateRequest; @@ -154,26 +158,32 @@ public InvokeResponse invokeMethod(String appId, String methodName, byte } @Override - public void publishEvent(String pubsubName, String topicName, byte[] data, String contentType, - Map metadata) { + public void publishEvent(PublishEventRequest request) { try { + byte[] data = request.getData(); // 1. prepare data if (data == null) { data = new byte[] {}; } final ByteString byteString = ByteString.copyFrom(data); + + String contentType = request.getContentType(); // Content-type can be overwritten on a per-request basis. // It allows CloudEvents to be handled differently, for example. if (contentType == null || contentType.isEmpty()) { contentType = RuntimeProperties.DEFAULT_PUBSUB_CONTENT_TYPE; } + String pubsubName = request.getPubsubName(); + String topicName = request.getTopic(); // 2. prepare request RuntimeProto.PublishEventRequest.Builder envelopeBuilder = RuntimeProto.PublishEventRequest.newBuilder() .setTopic(topicName) .setPubsubName(pubsubName) .setData(byteString) .setDataContentType(contentType); + + Map metadata = request.getMetadata(); // metadata if (metadata != null) { envelopeBuilder.putAllMetadata(metadata); @@ -510,7 +520,7 @@ private State parseGetStateResult(RuntimeProto.BulkStateItem bulkStateIt /** * Getter method for property stubManager. - * + *

* Do not use it ! * This method is deprecated and might be refactored in the future. * We want this client to expose grpc Channels instead of grpc stubs. @@ -523,6 +533,11 @@ public StubManager get return stubManager; } + @Override + public void waitForSidecar(int timeoutInMilliseconds) { + + } + @Override public void shutdown() { stubManager.destroy(); @@ -707,6 +722,26 @@ private void checkParamOfGetFileMeta(GetMetaRequest request) { } } + @Override + public List getConfiguration(ConfigurationRequestItem configurationRequestItem) { + return null; + } + + @Override + public void saveConfiguration(SaveConfigurationRequest saveConfigurationRequest) { + + } + + @Override + public void deleteConfiguration(ConfigurationRequestItem configurationRequestItem) { + + } + + @Override + public void subscribeConfiguration(ConfigurationRequestItem configurationRequestItem, Subscriber subscriber) { + + } + private class PutFileFuture implements StreamObserver { private final String fileName; diff --git a/sdk/src/main/java/io/mosn/layotto/v1/RuntimeServerGrpc.java b/sdk/src/main/java/io/mosn/layotto/v1/RuntimeServerGrpc.java index 6409d10..8a32c12 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/RuntimeServerGrpc.java +++ b/sdk/src/main/java/io/mosn/layotto/v1/RuntimeServerGrpc.java @@ -16,11 +16,11 @@ import io.grpc.Server; import io.grpc.ServerBuilder; -import io.mosn.layotto.v1.callback.GrpcAppCallbackImpl; -import io.mosn.layotto.v1.callback.component.pubsub.Subscriber; -import io.mosn.layotto.v1.callback.component.pubsub.SubscriberRegistry; -import io.mosn.layotto.v1.callback.component.pubsub.SubscriberRegistryImpl; import io.mosn.layotto.v1.grpc.ExceptionHandler; +import io.mosn.layotto.v1.grpc.callback.GrpcAppCallbackImpl; +import io.mosn.layotto.v1.grpc.callback.component.pubsub.Subscriber; +import io.mosn.layotto.v1.grpc.callback.component.pubsub.SubscriberRegistry; +import io.mosn.layotto.v1.grpc.callback.component.pubsub.SubscriberRegistryImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/sdk/src/main/java/io/mosn/layotto/v1/grpc/GrpcRuntimeClient.java b/sdk/src/main/java/io/mosn/layotto/v1/grpc/GrpcRuntimeClient.java index 38c3d7e..64123dc 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/grpc/GrpcRuntimeClient.java +++ b/sdk/src/main/java/io/mosn/layotto/v1/grpc/GrpcRuntimeClient.java @@ -22,7 +22,7 @@ public interface GrpcRuntimeClient extends RuntimeClient { /** * Getter method for property stubManager. - * + *

* Do not use it ! * This method is deprecated and might be refactored in the future. * We want this client to expose grpc Channels instead of grpc stubs. diff --git a/sdk/src/main/java/io/mosn/layotto/v1/serializer/JSONSerializer.java b/sdk/src/main/java/io/mosn/layotto/v1/serializer/JSONSerializer.java index 6ba4ba1..127656f 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/serializer/JSONSerializer.java +++ b/sdk/src/main/java/io/mosn/layotto/v1/serializer/JSONSerializer.java @@ -15,6 +15,7 @@ package io.mosn.layotto.v1.serializer; import com.alibaba.fastjson.JSONObject; +import io.mosn.layotto.v1.infrastructure.serializer.AbstractSerializer; import java.io.IOException; diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/client/RuntimeClient.java b/sdk/src/main/java/spec/sdk/runtime/v1/client/RuntimeClient.java index f19f7d5..ddea8bb 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/client/RuntimeClient.java +++ b/sdk/src/main/java/spec/sdk/runtime/v1/client/RuntimeClient.java @@ -33,5 +33,12 @@ public interface RuntimeClient extends SequencerRuntime, FileRuntime { + /** + * Waits for the sidecar, giving up after timeout. + * + * @param timeoutInMilliseconds Timeout in milliseconds to wait for sidecar. + */ + void waitForSidecar(int timeoutInMilliseconds); + void shutdown(); } \ No newline at end of file diff --git a/sdk/src/test/java/io/mosn/layotto/v1/RuntimeClientBuilderTest.java b/sdk/src/test/java/io/mosn/layotto/v1/RuntimeClientBuilderTest.java index 28ad487..c609916 100644 --- a/sdk/src/test/java/io/mosn/layotto/v1/RuntimeClientBuilderTest.java +++ b/sdk/src/test/java/io/mosn/layotto/v1/RuntimeClientBuilderTest.java @@ -16,7 +16,7 @@ // Modified some test cases to test layotto's code package io.mosn.layotto.v1; -import io.mosn.layotto.v1.serializer.ObjectSerializer; +import io.mosn.layotto.v1.infrastructure.serializer.ObjectSerializer; import org.junit.Assert; import org.junit.Test; import spec.sdk.runtime.v1.client.RuntimeClient; diff --git a/sdk/src/test/java/io/mosn/layotto/v1/SubscriberTest.java b/sdk/src/test/java/io/mosn/layotto/v1/SubscriberTest.java index a3e6ec9..4d4ecf4 100644 --- a/sdk/src/test/java/io/mosn/layotto/v1/SubscriberTest.java +++ b/sdk/src/test/java/io/mosn/layotto/v1/SubscriberTest.java @@ -19,9 +19,9 @@ import io.grpc.inprocess.InProcessChannelBuilder; import io.grpc.inprocess.InProcessServerBuilder; import io.grpc.testing.GrpcCleanupRule; -import io.mosn.layotto.v1.callback.GrpcAppCallbackImpl; -import io.mosn.layotto.v1.callback.component.pubsub.SubscriberRegistry; -import io.mosn.layotto.v1.callback.component.pubsub.SubscriberRegistryImpl; +import io.mosn.layotto.v1.grpc.callback.GrpcAppCallbackImpl; +import io.mosn.layotto.v1.grpc.callback.component.pubsub.SubscriberRegistry; +import io.mosn.layotto.v1.grpc.callback.component.pubsub.SubscriberRegistryImpl; import io.mosn.layotto.v1.mock.MySubscriber; import org.junit.Before; import org.junit.Rule; diff --git a/sdk/src/test/java/io/mosn/layotto/v1/mock/MySubscriber.java b/sdk/src/test/java/io/mosn/layotto/v1/mock/MySubscriber.java index a3e8343..f221bab 100644 --- a/sdk/src/test/java/io/mosn/layotto/v1/mock/MySubscriber.java +++ b/sdk/src/test/java/io/mosn/layotto/v1/mock/MySubscriber.java @@ -14,7 +14,7 @@ */ package io.mosn.layotto.v1.mock; -import io.mosn.layotto.v1.callback.component.pubsub.Subscriber; +import io.mosn.layotto.v1.grpc.callback.component.pubsub.Subscriber; import spec.sdk.runtime.v1.domain.pubsub.TopicEventRequest; import spec.sdk.runtime.v1.domain.pubsub.TopicEventResponse; import spec.sdk.runtime.v1.domain.pubsub.TopicEventResponseStatus; diff --git a/sdk/src/test/java/io/mosn/layotto/v1/serializer/JSONSerializerTest.java b/sdk/src/test/java/io/mosn/layotto/v1/serializer/JSONSerializerTest.java index 4a1b555..36d7aef 100644 --- a/sdk/src/test/java/io/mosn/layotto/v1/serializer/JSONSerializerTest.java +++ b/sdk/src/test/java/io/mosn/layotto/v1/serializer/JSONSerializerTest.java @@ -16,6 +16,7 @@ // Modified some test cases to test layotto's code package io.mosn.layotto.v1.serializer; +import io.mosn.layotto.v1.infrastructure.serializer.ObjectSerializer; import org.junit.Assert; import org.junit.Test; diff --git a/spec/pom.xml b/spec/pom.xml index 5eed022..6094343 100644 --- a/spec/pom.xml +++ b/spec/pom.xml @@ -1,101 +1,101 @@ - 4.0.0 + 4.0.0 - - io.mosn.layotto - runtime-sdk-parent - 1.1.0-SNAPSHOT - + + io.mosn.layotto + runtime-sdk-parent + 1.1.0-SNAPSHOT + - runtime-spec-pb - runtime-spec-pb - jar + runtime-spec-pb + runtime-spec-pb + jar - - - io.grpc - grpc-all - - + + + io.grpc + grpc-all + + - - src/main/java - - - src/main/resources - true - - **/** - - - - proto - true - - **/*.proto - - - + + src/main/java + + + src/main/resources + true + + **/** + + + + proto + true + + **/*.proto + + + - src/test/java - - - src/test/resources - true - - **/** - - - + src/test/java + + + src/test/resources + true + + **/** + + + - - - kr.motd.maven - os-maven-plugin - 1.4.1.Final - - + + + kr.motd.maven + os-maven-plugin + 1.4.1.Final + + - - - - - - - - - - - - - - - - - - - - - - - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar + + + + + + \ No newline at end of file diff --git a/spec/src/main/java/spec/proto/runtime/v1/AppCallbackGrpc.java b/spec/src/main/java/spec/proto/runtime/v1/AppCallbackGrpc.java index 33bc7b9..a5bbe30 100644 --- a/spec/src/main/java/spec/proto/runtime/v1/AppCallbackGrpc.java +++ b/spec/src/main/java/spec/proto/runtime/v1/AppCallbackGrpc.java @@ -1,3 +1,17 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package spec.proto.runtime.v1; import static io.grpc.MethodDescriptor.generateFullMethodName; diff --git a/spec/src/main/java/spec/proto/runtime/v1/AppCallbackProto.java b/spec/src/main/java/spec/proto/runtime/v1/AppCallbackProto.java index 3477433..91a5fd5 100644 --- a/spec/src/main/java/spec/proto/runtime/v1/AppCallbackProto.java +++ b/spec/src/main/java/spec/proto/runtime/v1/AppCallbackProto.java @@ -1,3 +1,17 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: proto/runtime/v1/appcallback.proto diff --git a/spec/src/main/java/spec/proto/runtime/v1/RuntimeGrpc.java b/spec/src/main/java/spec/proto/runtime/v1/RuntimeGrpc.java index 9e194c5..aff843d 100644 --- a/spec/src/main/java/spec/proto/runtime/v1/RuntimeGrpc.java +++ b/spec/src/main/java/spec/proto/runtime/v1/RuntimeGrpc.java @@ -1,3 +1,17 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package spec.proto.runtime.v1; import static io.grpc.MethodDescriptor.generateFullMethodName; diff --git a/spec/src/main/java/spec/proto/runtime/v1/RuntimeProto.java b/spec/src/main/java/spec/proto/runtime/v1/RuntimeProto.java index 92b8cd8..415158a 100644 --- a/spec/src/main/java/spec/proto/runtime/v1/RuntimeProto.java +++ b/spec/src/main/java/spec/proto/runtime/v1/RuntimeProto.java @@ -1,3 +1,17 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: proto/runtime/v1/runtime.proto