Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: refactor sdk layer #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
<url>https://github.com/mosn/layotto</url>

<modules>
<module>sdk</module>
<module>examples</module>
<module>sdk-reactor</module>
<module>sdk</module>
<module>spec</module>
<module>sdk-domain</module>
<module>sdk-infrastructure</module>
</modules>

<properties>
Expand All @@ -41,6 +43,17 @@
<artifactId>runtime-spec-pb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.mosn.layotto</groupId>
<artifactId>runtime-sdk-domain</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.mosn.layotto</groupId>
<artifactId>runtime-sdk-infrastructure</artifactId>
<version>${project.version}</version>
</dependency>

<!-- json -->
<dependency>
<groupId>com.alibaba</groupId>
Expand Down Expand Up @@ -76,6 +89,7 @@
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>

<!-- unit test -->
<dependency>
<groupId>org.mockito</groupId>
Expand Down Expand Up @@ -260,4 +274,5 @@
</distributionManagement>
</profile>
</profiles>

</project>
25 changes: 25 additions & 0 deletions sdk-domain/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>runtime-sdk-parent</artifactId>
<groupId>io.mosn.layotto</groupId>
<version>1.1.0-SNAPSHOT</version>
</parent>

<artifactId>runtime-sdk-domain</artifactId>
<name>runtime-sdk-domain</name>
<description>Domain definition for Runtime</description>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>io.mosn.layotto</groupId>
<artifactId>runtime-sdk-infrastructure</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -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<ConfigurationItem> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte[]> invokeMethod(String appId, String methodName, byte[] data, Map<String, String> 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<byte[]> invokeMethod(String appId, String methodName, byte[] data, Map<String, String> header,
int timeoutMs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -49,4 +52,10 @@ public interface PubSubRuntime {

void publishEvent(String pubsubName, String topicName, byte[] data, String contentType, Map<String, String> metadata);

/**
* Publish an event.
*
* @param request the request for the publish event.
*/
// void publishEvent(PublishEventRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> The Type of the return.
* @return
* @return the requested State.
*/
<T> State<T> getState(GetStateRequest request, Class<T> clazz, int timeoutMs);

Expand Down Expand Up @@ -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<TransactionalStateOperation<?>> operations);
void executeStateTransaction(String storeName, List<TransactionalStateOperation<?>> operations);

/**
* Execute a transaction.
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<String, String> tags;
/**
* The metadata which will be passed to configuration store component.
*/
private Map<String, String> 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<String, String> getTags() {
return tags;
}

public void setTags(Map<String, String> tags) {
this.tags = tags;
}

public Map<String, String> getMetadata() {
return metadata;
}

public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata;
}

@Override
public String toString() {
return "ConfigurationItem{" +
"key='" + key + '\'' +
", content=" + content +
", group='" + group + '\'' +
", label='" + label + '\'' +
", tags=" + tags +
", metadata=" + metadata +
'}';
}
}
Loading