diff --git a/pom.xml b/pom.xml index d57ab0a..3940643 100644 --- a/pom.xml +++ b/pom.xml @@ -13,10 +13,12 @@ https://github.com/mosn/layotto - sdk examples sdk-reactor + sdk spec + sdk-domain + sdk-infrastructure @@ -41,6 +43,17 @@ runtime-spec-pb ${project.version} + + io.mosn.layotto + runtime-sdk-domain + ${project.version} + + + io.mosn.layotto + runtime-sdk-infrastructure + ${project.version} + + com.alibaba @@ -76,6 +89,7 @@ grpc-stub ${grpc.version} + org.mockito @@ -260,4 +274,5 @@ + 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..0ff47c7 --- /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..6106568 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-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationItem.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationItem.java new file mode 100644 index 0000000..544f634 --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationItem.java @@ -0,0 +1,106 @@ +/* + * 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.configuration; + +import java.util.Map; + +public class ConfigurationItem { + + /** + * Required. The key of configuration item + */ + private String key; + /** + * 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 Object content; + /** + * The group of configuration item. + */ + private String group; + /** + * The label of configuration item. + */ + private String label; + /** + * The tag list of configuration item. + */ + private Map tags; + /** + * The metadata which will be passed to configuration store component. + */ + private Map metadata; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Object getContent() { + return content; + } + + public void setContent(Object content) { + this.content = content; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public Map getTags() { + return tags; + } + + public void setTags(Map tags) { + this.tags = tags; + } + + public Map getMetadata() { + return metadata; + } + + 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-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItem.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItem.java new file mode 100644 index 0000000..a9fe513 --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItem.java @@ -0,0 +1,110 @@ +/* + * 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.configuration; + +import java.util.List; +import java.util.Map; + +/** + * ConfigurationRequestItem used for GET,DEL,SUB request + */ +public class ConfigurationRequestItem { + + /** + * The name of configuration store. + */ + private String storeName; + /** + * The application id which + * Only used for admin, Ignored and reset for normal client + */ + private String appId; + /** + * The group of keys. + */ + private String group; + /** + * The label for keys. + */ + private String label; + /** + * The keys to get. + */ + private List keys; + /** + * The metadata which will be sent to configuration store components. + */ + private Map metadata; + + public String getStoreName() { + return storeName; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getGroup() { + return group; + } + + public void setGroup(String group) { + this.group = group; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public List getKeys() { + return keys; + } + + public void setKeys(List keys) { + this.keys = keys; + } + + public Map getMetadata() { + return metadata; + } + + 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-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItemBuilder.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItemBuilder.java new file mode 100644 index 0000000..d026ba2 --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/ConfigurationRequestItemBuilder.java @@ -0,0 +1,89 @@ +/* + * 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.configuration; + +import java.util.List; +import java.util.Map; + +/** + * Builds a request to invoke configuration. + */ +public class ConfigurationRequestItemBuilder { + + private final String storeName; + + private final String appId; + + private String group; + + private String label; + + private List keys; + + private Map metadata; + + public ConfigurationRequestItemBuilder(String storeName, String appId) { + this.storeName = storeName; + this.appId = appId; + } + + public ConfigurationRequestItemBuilder withGroup(String group) { + this.group = group; + return this; + } + + public ConfigurationRequestItemBuilder withLabel(String label) { + this.label = label; + return this; + } + + public ConfigurationRequestItemBuilder withKeys(List keys) { + this.keys = keys; + return this; + } + + public ConfigurationRequestItemBuilder withMetadata(Map metadata) { + this.metadata = metadata; + return this; + } + + /** + * Builds a request object. + * + * @return Request object. + */ + public ConfigurationRequestItem build() { + ConfigurationRequestItem request = new ConfigurationRequestItem(); + request.setStoreName(this.storeName); + request.setAppId(this.appId); + request.setGroup(this.group); + request.setLabel(this.label); + request.setKeys(this.keys); + 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-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SaveConfigurationRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SaveConfigurationRequest.java new file mode 100644 index 0000000..09ab8f9 --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SaveConfigurationRequest.java @@ -0,0 +1,72 @@ +/* + * 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.configuration; + +import java.util.List; +import java.util.Map; + +public class SaveConfigurationRequest { + + /** + * The name of configuration store. + */ + private String storeName; + /** + * The application id which + * Only used for admin, Ignored and reset for normal client + */ + 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; + /** + * The metadata which will be sent to configuration store components. + */ + private Map metadata; + + public String getStoreName() { + return storeName; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public Map getMetadata() { + return metadata; + } + + public void setMetadata(Map metadata) { + this.metadata = metadata; + } +} diff --git a/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SubConfigurationResp.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SubConfigurationResp.java new file mode 100644 index 0000000..19b9be8 --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/configuration/SubConfigurationResp.java @@ -0,0 +1,68 @@ +/* + * 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.configuration; + +import java.util.List; + +public class SubConfigurationResp { + + /** + * The name of configuration store. + */ + private String storeName; + /** + * The application id which + * Only used for admin, Ignored and reset for normal client + */ + 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; + + public String getStoreName() { + return storeName; + } + + public void setStoreName(String storeName) { + this.storeName = storeName; + } + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public List getItems() { + return 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-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/HttpExtension.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/HttpExtension.java new file mode 100644 index 0000000..9c0f38d --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/HttpExtension.java @@ -0,0 +1,138 @@ +/* + * 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.invocation; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +/** + * HTTP Extension class. + * This class is only needed if the app you are calling is listening on HTTP. + * It contains properties that represent data that may be populated for an HTTP receiver. + */ +public final class HttpExtension { + + /** + * Convenience HttpExtension object for {@link HttpMethods#NONE} with empty queryString. + */ + public static final HttpExtension NONE = new HttpExtension(HttpMethods.NONE); + /** + * Convenience HttpExtension object for the {@link HttpMethods#GET} Verb with empty queryString. + */ + public static final HttpExtension GET = new HttpExtension(HttpMethods.GET); + /** + * Convenience HttpExtension object for the {@link HttpMethods#PUT} Verb with empty queryString. + */ + public static final HttpExtension PUT = new HttpExtension(HttpMethods.PUT); + /** + * Convenience HttpExtension object for the {@link HttpMethods#POST} Verb with empty queryString. + */ + public static final HttpExtension POST = new HttpExtension(HttpMethods.POST); + /** + * Convenience HttpExtension object for the {@link HttpMethods#DELETE} Verb with empty queryString. + */ + public static final HttpExtension DELETE = new HttpExtension(HttpMethods.DELETE); + /** + * Convenience HttpExtension object for the {@link HttpMethods#HEAD} Verb with empty queryString. + */ + public static final HttpExtension HEAD = new HttpExtension(HttpMethods.HEAD); + /** + * Convenience HttpExtension object for the {@link HttpMethods#CONNECT} Verb with empty queryString. + */ + public static final HttpExtension CONNECT = new HttpExtension(HttpMethods.CONNECT); + /** + * Convenience HttpExtension object for the {@link HttpMethods#OPTIONS} Verb with empty queryString. + */ + public static final HttpExtension OPTIONS = new HttpExtension(HttpMethods.OPTIONS); + /** + * Convenience HttpExtension object for the {@link HttpMethods#TRACE} Verb with empty queryString. + */ + public static final HttpExtension TRACE = new HttpExtension(HttpMethods.TRACE); + + /** + * HTTP verb. + */ + private HttpMethods method; + + /** + * HTTP query params. + */ + private Map> queryParams; + + /** + * HTTP headers. + */ + private Map headers; + + /** + * Construct a HttpExtension object. + * + * @param method Required value denoting the HttpMethod. + * @param queryParams map for the query parameters the HTTP call. + * @param headers map to set HTTP headers. + * @throws IllegalArgumentException on null method or queryString. + * @see HttpMethods for supported methods. + */ + public HttpExtension(HttpMethods method, + Map> queryParams, + Map headers) { + if (method == null) { + throw new IllegalArgumentException("HttpExtension method cannot be null"); + } + + this.method = method; + this.queryParams = Collections.unmodifiableMap(queryParams == null ? Collections.emptyMap() : queryParams); + this.headers = Collections.unmodifiableMap(headers == null ? Collections.emptyMap() : headers); + } + + /** + * Construct a HttpExtension object. + * + * @param method Required value denoting the HttpMethod. + * @throws IllegalArgumentException on null method or queryString. + * @see HttpMethods for supported methods. + */ + public HttpExtension(HttpMethods method) { + this(method, null, null); + } + + public HttpMethods getMethod() { + return method; + } + + public Map> getQueryParams() { + return queryParams; + } + + public Map getHeaders() { + return headers; + } + + /** + * HTTP Methods supported. + */ + public enum HttpMethods { + NONE, + GET, + PUT, + POST, + DELETE, + HEAD, + CONNECT, + OPTIONS, + TRACE + } +} diff --git a/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeMethodRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeMethodRequest.java new file mode 100644 index 0000000..aa69737 --- /dev/null +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/InvokeMethodRequest.java @@ -0,0 +1,95 @@ +/* + * 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.invocation; + +import java.util.Map; + +/** + * A request to invoke a service. + */ +public class InvokeMethodRequest { + + private final String appId; + + private final String method; + + private Object body; + + private HttpExtension httpExtension; + + private String contentType; + + private Map metadata; + + public InvokeMethodRequest(String appId, String method) { + this.appId = appId; + this.method = method; + } + + public String getAppId() { + return appId; + } + + public String getMethod() { + return method; + } + + public Object getBody() { + return body; + } + + public InvokeMethodRequest setBody(Object body) { + this.body = body; + return this; + } + + public HttpExtension getHttpExtension() { + return httpExtension; + } + + public InvokeMethodRequest setHttpExtension(HttpExtension httpExtension) { + this.httpExtension = httpExtension; + return this; + } + + public String getContentType() { + return contentType; + } + + public InvokeMethodRequest setContentType(String contentType) { + this.contentType = contentType; + return this; + } + + public Map getMetadata() { + return metadata; + } + + 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/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockRequest.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/invocation/Metadata.java similarity index 66% 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/invocation/Metadata.java index 9dcfbc5..268bc45 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/invocation/Metadata.java @@ -12,11 +12,17 @@ * 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.invocation; -public class TryLockRequest { - public String storeName; - public String resourceId; - public String lockOwner; - public int expire; -} \ No newline at end of file +/** + * Enumerates commonly used metadata attributes. + */ +public final class Metadata { + + public static final String CONTENT_TYPE = "content-type"; + + public static final String TTL_IN_SECONDS = "ttlInSeconds"; + + private Metadata() { + } +} 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/TryLockResponse.java b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java similarity index 70% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java index 30a4dbb..3f4a6e7 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/lock/TryLockResponse.java @@ -15,5 +15,21 @@ package spec.sdk.runtime.v1.domain.lock; public class TryLockResponse { + public boolean success; + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + @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/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 similarity index 52% 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/UnlockResponse.java index a12f819..ea67658 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/UnlockResponse.java @@ -14,18 +14,40 @@ */ 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; - - UnlockResponseStatus(int value) { - this.value = value; - } -} - 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/UnlockRequest.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/UnlockRequest.java rename to sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/package-info.java index 49458e6..97d0b69 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/lock/UnlockRequest.java +++ b/sdk-domain/src/main/java/spec/sdk/runtime/v1/domain/package-info.java @@ -12,10 +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 UnlockRequest { - public String storeName; - public String resourceId; - public String lockOwner; -} +/** + * 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..31e3c31 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 NullPointerException(); + } + if (value == null) { + throw new 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 84% 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..b9e754c 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 NullPointerException(); + } + if (value == null) { + throw new 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 85% 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..8c7354e 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 NullPointerException(); + } + if (value == null) { + throw new 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 83% 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..ea63157 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 NullPointerException(); + } + if (value == null) { + throw new 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 86% 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..aba6f09 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 @@ -51,11 +51,19 @@ public Map getMetadata() { public void putMetadata(String key, String value) { if (key == null) { - throw new java.lang.NullPointerException(); + throw new NullPointerException(); } if (value == null) { - throw new java.lang.NullPointerException(); + throw new NullPointerException(); } metadata.put(key, value); } + + @Override + public String toString() { + return "TransactionalStateRequest{" + + "operations=" + operations + + ", metadata=" + metadata + + '}'; + } } diff --git a/sdk-infrastructure/pom.xml b/sdk-infrastructure/pom.xml new file mode 100644 index 0000000..8d381b4 --- /dev/null +++ b/sdk-infrastructure/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + + runtime-sdk-parent + io.mosn.layotto + 1.1.0-SNAPSHOT + + + runtime-sdk-infrastructure + runtime-sdk-infrastructure + infrastructure for Runtime + jar + + + + + com.alibaba + fastjson + + + + \ 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/config/RuntimeProperties.java similarity index 96% rename from sdk/src/main/java/io/mosn/layotto/v1/config/RuntimeProperties.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/config/RuntimeProperties.java index 4f09bad..2155150 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/config/RuntimeProperties.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/config/RuntimeProperties.java @@ -14,7 +14,7 @@ */ package io.mosn.layotto.v1.config; -import io.mosn.layotto.v1.domain.ApiProtocol; +import io.mosn.layotto.v1.value.ApiProtocol; public class RuntimeProperties { @@ -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/exceptions/RuntimeClientException.java similarity index 100% rename from sdk/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeClientException.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeClientException.java diff --git a/sdk/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeError.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeError.java similarity index 100% rename from sdk/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeError.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/exceptions/RuntimeError.java diff --git a/sdk/src/main/java/spec/sdk/runtime/v1/domain/ConfigurationRuntime.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/package-info.java similarity index 88% rename from sdk/src/main/java/spec/sdk/runtime/v1/domain/ConfigurationRuntime.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/package-info.java index 89ba2c7..6b34863 100644 --- a/sdk/src/main/java/spec/sdk/runtime/v1/domain/ConfigurationRuntime.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/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; \ 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/serializer/AbstractSerializer.java similarity index 100% rename from sdk/src/main/java/io/mosn/layotto/v1/serializer/AbstractSerializer.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/serializer/AbstractSerializer.java index ad1da68..7d33a32 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/serializer/AbstractSerializer.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/serializer/AbstractSerializer.java @@ -17,6 +17,7 @@ import java.io.IOException; public abstract class AbstractSerializer implements ObjectSerializer { + /** * {@inheritDoc} */ @@ -55,5 +56,4 @@ public T deserialize(byte[] data, Class clazz) throws IOException { } protected abstract T doDeserialize(byte[] data, Class clazz) throws IOException; - } \ No newline at end of file diff --git a/sdk/src/main/java/io/mosn/layotto/v1/serializer/JSONSerializer.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/serializer/JSONSerializer.java similarity index 100% rename from sdk/src/main/java/io/mosn/layotto/v1/serializer/JSONSerializer.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/serializer/JSONSerializer.java diff --git a/sdk/src/main/java/io/mosn/layotto/v1/serializer/ObjectSerializer.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/serializer/ObjectSerializer.java similarity index 100% rename from sdk/src/main/java/io/mosn/layotto/v1/serializer/ObjectSerializer.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/serializer/ObjectSerializer.java diff --git a/sdk/src/main/java/io/mosn/layotto/v1/domain/ApiProtocol.java b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/value/ApiProtocol.java similarity index 95% rename from sdk/src/main/java/io/mosn/layotto/v1/domain/ApiProtocol.java rename to sdk-infrastructure/src/main/java/io/mosn/layotto/v1/value/ApiProtocol.java index a194d33..54d7089 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/domain/ApiProtocol.java +++ b/sdk-infrastructure/src/main/java/io/mosn/layotto/v1/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.value; /** * Transport protocol for Runtime API. diff --git a/sdk/pom.xml b/sdk/pom.xml index 792b2e7..7a9266e 100644 --- a/sdk/pom.xml +++ b/sdk/pom.xml @@ -20,10 +20,9 @@ io.mosn.layotto runtime-spec-pb - - com.alibaba - fastjson + io.mosn.layotto + runtime-sdk-domain @@ -31,11 +30,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..dd62d52 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/AbstractRuntimeClient.java +++ b/sdk/src/main/java/io/mosn/layotto/v1/AbstractRuntimeClient.java @@ -121,7 +121,7 @@ public State getState(String storeName, String key, StateOptions options, */ @Override public State getState(GetStateRequest request, Class clazz) { - return getState(request, clazz, getTimeoutMs()); + return this.getState(request, clazz, getTimeoutMs()); } @Override @@ -182,7 +182,7 @@ public void deleteState(String storeName, String key, String etag, StateOptions */ @Override public void deleteState(DeleteStateRequest request) { - deleteState(request, getTimeoutMs()); + this.deleteState(request, this.getTimeoutMs()); } /** @@ -219,7 +219,7 @@ public void saveBulkState(String storeName, List> states) { */ @Override public void saveBulkState(SaveStateRequest request) { - saveBulkState(request, getTimeoutMs()); + this.saveBulkState(request, getTimeoutMs()); } /** @@ -243,7 +243,7 @@ public List> getBulkState(String storeName, List keys, Clas @Override public List> getBulkState(GetBulkStateRequest request, Class clazz) { - return getBulkState(request, clazz, getTimeoutMs()); + return this.getBulkState(request, clazz, getTimeoutMs()); } @Override @@ -268,7 +268,7 @@ public List> getBulkState(GetBulkStateRequest request, Class cla try { // 2. invoke - List> bulkState = doGetBulkState(request, timeoutMs); + List> bulkState = this.doGetBulkState(request, timeoutMs); // 3. deserialize List> result = new ArrayList<>(bulkState.size()); for (State state : bulkState) { 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..50860bc 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientBuilder.java +++ b/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientBuilder.java @@ -18,7 +18,7 @@ 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.value.ApiProtocol; import io.mosn.layotto.v1.grpc.GrpcRuntimeClient; import io.mosn.layotto.v1.grpc.stub.PooledStubManager; import io.mosn.layotto.v1.grpc.stub.SingleStubManager; @@ -172,8 +172,8 @@ public GrpcRuntimeClient buildGrpcWithExistingChannel(ManagedChannel channel) { throw new IllegalArgumentException("Invalid port."); } // 2. construct stubManager - StubManager stubManager = new SingleStubManager( - channel, new StubCreatorImpl()); + StubManager stubManager = + new SingleStubManager(channel, new StubCreatorImpl()); // 3. construct client return new RuntimeClientGrpc( logger, 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..9a87a66 100644 --- a/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientGrpc.java +++ b/sdk/src/main/java/io/mosn/layotto/v1/RuntimeClientGrpc.java @@ -65,6 +65,7 @@ public class RuntimeClientGrpc extends AbstractRuntimeClient implements GrpcRuntimeClient { private static final String TIMEOUT_KEY = "timeout"; + private final StubManager stubManager; RuntimeClientGrpc(Logger logger, @@ -86,8 +87,7 @@ public String sayHello(String name, int timeoutMillisecond) { // 2. invoke RuntimeProto.SayHelloResponse response = stubManager.getBlockingStub() - .withDeadlineAfter(timeoutMillisecond, - TimeUnit.MILLISECONDS) + .withDeadlineAfter(timeoutMillisecond, TimeUnit.MILLISECONDS) .sayHello(req); // 3. parse result @@ -510,7 +510,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. @@ -530,22 +530,24 @@ public void shutdown() { @Override public PutFileResponse putFile(PutFileRequest request, int timeoutMs) throws Exception { - checkParamOfPutFile(request); PutFileFuture putFuture = new PutFileFuture(request.getFileName()); StreamObserver observer = createPutFileObserver(putFuture, timeoutMs); - observer.onNext(buildPutFileMetaDataRequest(request.getStoreName(), request.getFileName(), - request.getMetaData())); + RuntimeProto.PutFileRequest putFileRequest = buildPutFileMetaDataRequest( + request.getStoreName(), + request.getFileName(), + request.getMetaData()); + observer.onNext(putFileRequest); byte[] buf = new byte[4096]; for (int size = request.getIn().read(buf); size > 0; size = request.getIn().read(buf)) { - observer.onNext(buildPutFileDataRequest(buf, size)); + RuntimeProto.PutFileRequest fileRequest = buildPutFileDataRequest(buf, size); + observer.onNext(fileRequest); } observer.onCompleted(); - putFuture.awaitDone(timeoutMs); return new PutFileResponse(); @@ -553,72 +555,64 @@ public PutFileResponse putFile(PutFileRequest request, int timeoutMs) throws Exc @Override public GetFileResponse getFile(GetFileRequest request, int timeoutMs) throws Exception { - checkParamOfGetFile(request); GetFilePipe pipe = new GetFilePipe(request.getFileName()); - stubManager. - getAsyncStub(). - getFile( - buildGetFileRequest( - request.getStoreName(), - request.getFileName(), - request.getMetaData()), - pipe); + RuntimeProto.GetFileRequest getFileRequest = buildGetFileRequest( + request.getStoreName(), + request.getFileName(), + request.getMetaData()); + stubManager.getAsyncStub() + .getFile(getFileRequest, pipe); return new GetFileResponse(pipe.getReader()); } @Override public ListFileResponse listFile(ListFileRequest request, int timeoutMs) throws Exception { - checkParamOfListFile(request); - RuntimeProto.ListFileResp response = stubManager. - getBlockingStub(). - withDeadlineAfter(timeoutMs, TimeUnit.MILLISECONDS). - listFile( - buildListFileRequest( - request.getStoreName(), - request.getName(), - request.getMarker(), - request.getPageSize(), - request.getMetaData())); + RuntimeProto.ListFileRequest listFileRequest = buildListFileRequest( + request.getStoreName(), + request.getName(), + request.getMarker(), + request.getPageSize(), + request.getMetaData()); + RuntimeProto.ListFileResp response = stubManager.getBlockingStub() + .withDeadlineAfter(timeoutMs, TimeUnit.MILLISECONDS) + .listFile(listFileRequest); return buildListFileResponse(response); } @Override public DelFileResponse delFile(DelFileRequest request, int timeoutMs) throws Exception { - checkParamOfDeleteFile(request); - stubManager. - getBlockingStub(). - withDeadlineAfter(timeoutMs, TimeUnit.MILLISECONDS). - delFile( - buildDelFileRequest(request.getStoreName(), request.getFileName(), request.getMetaData())); + RuntimeProto.DelFileRequest delFileRequest = buildDelFileRequest(request.getStoreName(), request.getFileName(), + request.getMetaData()); + stubManager.getBlockingStub() + .withDeadlineAfter(timeoutMs, TimeUnit.MILLISECONDS) + .delFile(delFileRequest); return new DelFileResponse(); } @Override public GetMeteResponse getFileMeta(GetMetaRequest request, int timeoutMs) throws Exception { - checkParamOfGetFileMeta(request); - RuntimeProto.GetFileMetaResponse resp = stubManager. - getBlockingStub(). - withDeadlineAfter(timeoutMs, TimeUnit.MILLISECONDS). - getFileMeta( - buildGetFileMetaRequest(request.getStoreName(), request.getFileName(), request.getMetaData())); + RuntimeProto.GetFileMetaRequest getFileMetaRequest = buildGetFileMetaRequest(request.getStoreName(), + request.getFileName(), request.getMetaData()); + RuntimeProto.GetFileMetaResponse resp = stubManager.getBlockingStub() + .withDeadlineAfter(timeoutMs, TimeUnit.MILLISECONDS) + .getFileMeta(getFileMetaRequest); return buildGetFileMetaResponse(resp); } private void checkParamOfGetFile(GetFileRequest request) { - // check request if (request == null) { throw new IllegalArgumentException("miss request"); @@ -636,7 +630,6 @@ private void checkParamOfGetFile(GetFileRequest request) { } private void checkParamOfPutFile(PutFileRequest request) { - // check request if (request == null) { throw new IllegalArgumentException("miss request"); @@ -659,7 +652,6 @@ private void checkParamOfPutFile(PutFileRequest request) { } private void checkParamOfListFile(ListFileRequest request) { - // check request if (request == null) { throw new IllegalArgumentException("miss request"); @@ -672,7 +664,6 @@ private void checkParamOfListFile(ListFileRequest request) { } private void checkParamOfDeleteFile(DelFileRequest request) { - // check request if (request == null) { throw new IllegalArgumentException("miss request"); @@ -690,7 +681,6 @@ private void checkParamOfDeleteFile(DelFileRequest request) { } private void checkParamOfGetFileMeta(GetMetaRequest request) { - // check request if (request == null) { throw new IllegalArgumentException("miss request"); @@ -738,7 +728,6 @@ public void onCompleted() { } public void awaitDone(int timeoutMs) throws Exception { - boolean finished = latch.await(timeoutMs, TimeUnit.MILLISECONDS); if (!finished) { String tip = String.format("put file timeout, file=%s", fileName); @@ -767,7 +756,6 @@ private class PipeFileInputStream extends PipedInputStream { @Override public synchronized int read() throws IOException { - checkCause(); return super.read(); @@ -775,7 +763,6 @@ public synchronized int read() throws IOException { @Override public int read(byte[] b) throws IOException { - checkCause(); return super.read(b); @@ -783,7 +770,6 @@ public int read(byte[] b) throws IOException { @Override public synchronized int read(byte[] b, int off, int len) throws IOException { - checkCause(); return super.read(b, off, len); @@ -815,7 +801,6 @@ private class GetFilePipe implements StreamObserver createPutFileObserver( StreamObserver callBackObserver, int timeoutMs) { - return stubManager. - getAsyncStub(). - withDeadlineAfter(timeoutMs, TimeUnit.MILLISECONDS). - putFile(callBackObserver); + return stubManager.getAsyncStub() + .withDeadlineAfter(timeoutMs, TimeUnit.MILLISECONDS) + .putFile(callBackObserver); } private RuntimeProto.PutFileRequest buildPutFileMetaDataRequest(String storeName, String fileName, Map meta) { - return RuntimeProto.PutFileRequest. - newBuilder(). - setStoreName(storeName). - setName(fileName). - putAllMetadata(meta). - build(); + return RuntimeProto.PutFileRequest + .newBuilder() + .setStoreName(storeName) + .setName(fileName) + .putAllMetadata(meta) + .build(); } private RuntimeProto.PutFileRequest buildPutFileDataRequest(byte[] bytes, int size) { - - return RuntimeProto.PutFileRequest. - newBuilder(). - setData(ByteString.copyFrom(bytes, 0, size)). - build(); + return RuntimeProto.PutFileRequest + .newBuilder() + .setData(ByteString.copyFrom(bytes, 0, size)) + .build(); } private RuntimeProto.GetFileRequest buildGetFileRequest(String storeName, String fileName, Map meta) { - - return RuntimeProto.GetFileRequest. - newBuilder(). - setStoreName(storeName). - setName(fileName). - putAllMetadata(meta). - build(); + return RuntimeProto.GetFileRequest + .newBuilder() + .setStoreName(storeName) + .setName(fileName) + .putAllMetadata(meta) + .build(); } private RuntimeProto.ListFileRequest buildListFileRequest(String storeName, String name, String marker, int pageSize, Map meta) { + RuntimeProto.FileRequest fileRequest = RuntimeProto.FileRequest + .newBuilder() + .setStoreName(storeName) + .setName(name) + .putAllMetadata(meta) + .build(); - RuntimeProto.FileRequest fileRequest = RuntimeProto.FileRequest. - newBuilder(). - setStoreName(storeName). - setName(name). - putAllMetadata(meta). - build(); - - return RuntimeProto.ListFileRequest. - newBuilder(). - setRequest(fileRequest). - setMarker(marker). - setPageSize(pageSize). - build(); + return RuntimeProto.ListFileRequest + .newBuilder() + .setRequest(fileRequest) + .setMarker(marker) + .setPageSize(pageSize) + .build(); } private RuntimeProto.DelFileRequest buildDelFileRequest(String storeName, String fileName, Map meta) { + RuntimeProto.FileRequest fileRequest = RuntimeProto.FileRequest + .newBuilder() + .setStoreName(storeName) + .setName(fileName) + .putAllMetadata(meta) + .build(); - RuntimeProto.FileRequest fileRequest = RuntimeProto.FileRequest. - newBuilder(). - setStoreName(storeName). - setName(fileName). - putAllMetadata(meta). - build(); - - return RuntimeProto.DelFileRequest. - newBuilder(). - setRequest(fileRequest). - build(); + return RuntimeProto.DelFileRequest + .newBuilder() + .setRequest(fileRequest) + .build(); } private RuntimeProto.GetFileMetaRequest buildGetFileMetaRequest(String storeName, String fileName, Map meta) { + RuntimeProto.FileRequest fileRequest = RuntimeProto.FileRequest + .newBuilder() + .setStoreName(storeName) + .setName(fileName) + .putAllMetadata(meta) + .build(); - RuntimeProto.FileRequest fileRequest = RuntimeProto.FileRequest. - newBuilder(). - setStoreName(storeName). - setName(fileName). - putAllMetadata(meta). - build(); - - return RuntimeProto.GetFileMetaRequest. - newBuilder(). - setRequest(fileRequest). - build(); + return RuntimeProto.GetFileMetaRequest + .newBuilder() + .setRequest(fileRequest) + .build(); } private GetMeteResponse buildGetFileMetaResponse(RuntimeProto.GetFileMetaResponse resp) { - Map metas = new HashMap<>(); - resp.getResponse(). - getMetadataMap(). - forEach( - (s, fileMetaValue) -> - metas.put(s, fileMetaValue.getValueList().toArray(new String[0]))); + resp.getResponse() + .getMetadataMap() + .forEach((s, fileMetaValue) -> + metas.put(s, fileMetaValue.getValueList().toArray(new String[0]))); GetMeteResponse result = new GetMeteResponse(); result.setSize(resp.getSize()); @@ -971,16 +946,13 @@ private GetMeteResponse buildGetFileMetaResponse(RuntimeProto.GetFileMetaRespons } private ListFileResponse buildListFileResponse(RuntimeProto.ListFileResp resp) { - - FileInfo[] files = resp.getFilesList(). - stream(). - map( - fileInfo -> - new FileInfo( - fileInfo.getFileName(), - fileInfo.getSize(), - fileInfo.getLastModified(), - fileInfo.getMetadataMap())). + FileInfo[] files = resp.getFilesList() + .stream() + .map(fileInfo -> new FileInfo( + fileInfo.getFileName(), + fileInfo.getSize(), + fileInfo.getLastModified(), + fileInfo.getMetadataMap())). toArray(FileInfo[]::new); ListFileResponse result = new ListFileResponse(); 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..711a738 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/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