diff --git a/README.md b/README.md index 5e29f4f..e2b05ad 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ This is the Capa SDK for Java, including the following features: + Service Invocation(RPC) + Configuration Centor(Configuration) -+ Application Metrics(Metrics) + Publish/Subscribe(Pub/Sub) + State Management(State) ++ Application Metrics(Metrics) + 参考项目: @@ -43,7 +43,7 @@ API设计和社区保持同步,请参考Dapr/Layotto等开源项目的设计 目前API定义在: [cloud-runtimes](https://github.com/reactivegroup/cloud-runtimes-jvm) 中 -#### [RPC API design]() +#### SDK层次设计 module划分主要为以下几个部分: * sdk @@ -57,6 +57,8 @@ module划分主要为以下几个部分: 在运行前,会将具体的SPI实现包引入进去,作为统一编程API的具体实现。 +#### 举例:[RPC API design]() + ## Getting Started #### Importing Capa's Java SDK @@ -80,7 +82,7 @@ For a Maven project, add the following to your pom.xml file: ``` - +Sample implementation library: ```xml @@ -90,7 +92,7 @@ For a Maven project, add the following to your pom.xml file: group.rxcloud - capa-sdk-spi-aws + capa-sdk-spi-demo 1.0.1.RELEASE ... @@ -103,8 +105,9 @@ For a Maven project, add the following to your pom.xml file: Try the following examples to learn more about Capa's Java SDK: -* [RPC]() -* ... +* [capa-demo](https://github.com/reactivegroup/capa/tree/master/sdk-spi-demo) +* [capa-aws](https://github.com/reactivegroup/capa-aws) +* [capa-alibaba](https://github.com/reactivegroup/capa-alibaba) #### Reactor API diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/bindings/InputBinding.java b/sdk-component/src/main/java/group/rxcloud/capa/component/bindings/InputBinding.java new file mode 100644 index 0000000..83264de --- /dev/null +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/bindings/InputBinding.java @@ -0,0 +1,4 @@ +package group.rxcloud.capa.component.bindings; + +public abstract class InputBinding { +} diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/bindings/OutputBinding.java b/sdk-component/src/main/java/group/rxcloud/capa/component/bindings/OutputBinding.java new file mode 100644 index 0000000..d4c7e2a --- /dev/null +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/bindings/OutputBinding.java @@ -0,0 +1,4 @@ +package group.rxcloud.capa.component.bindings; + +public abstract class OutputBinding { +} diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/pubsub/PubSub.java b/sdk-component/src/main/java/group/rxcloud/capa/component/pubsub/PubSub.java new file mode 100644 index 0000000..6f6d775 --- /dev/null +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/pubsub/PubSub.java @@ -0,0 +1,4 @@ +package group.rxcloud.capa.component.pubsub; + +public abstract class PubSub { +} diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/state/Store.java b/sdk-component/src/main/java/group/rxcloud/capa/component/state/Store.java new file mode 100644 index 0000000..a2db41d --- /dev/null +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/state/Store.java @@ -0,0 +1,4 @@ +package group.rxcloud.capa.component.state; + +public abstract class Store { +} diff --git a/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/config/DemoRpcServiceOptions.java b/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/config/DemoRpcServiceOptions.java index 0055637..e17d6d5 100644 --- a/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/config/DemoRpcServiceOptions.java +++ b/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/config/DemoRpcServiceOptions.java @@ -1,13 +1,9 @@ package group.rxcloud.capa.spi.demo.config; -import group.rxcloud.capa.infrastructure.env.CapaEnvironment; import group.rxcloud.capa.spi.config.RpcServiceOptions; -import java.util.Objects; - /** * RPC service options. Define for AppId. - * TODO load by spi class */ public class DemoRpcServiceOptions implements RpcServiceOptions { @@ -15,379 +11,13 @@ public class DemoRpcServiceOptions implements RpcServiceOptions { * Unique rpc service ID */ private final String appId; - private final ServiceRpcInvokeMode rpcInvokeMode; - - /* - * Optional options - */ - private CtripToCtripServiceOptions ctripToCtripServiceOptions; - private CtripToAwsServiceOptions ctripToAwsServiceOptions; - private AwsToCtripServiceOptions awsToCtripServiceOptions; - private AwsToAwsServiceOptions awsToAwsServiceOptions; /** * Instantiates a new Capa rpc service options. * - * @param appId the app id - * @param rpcInvokeMode the rpc invoke mode + * @param appId the app id */ - public DemoRpcServiceOptions(String appId, ServiceRpcInvokeMode rpcInvokeMode) { + public DemoRpcServiceOptions(String appId) { this.appId = appId; - this.rpcInvokeMode = rpcInvokeMode; - } - - /** - * RPC service invoke mode - */ - public enum ServiceRpcInvokeMode { - /** - * Ctrip → Ctrip - */ - CTRIP_TO_CTRIP, - /** - * Ctrip → AWS - */ - CTRIP_TO_AWS, - /** - * AWS → Ctrip - */ - AWS_TO_CTRIP, - /** - * AWS → AWS - */ - AWS_TO_AWS, - ; - } - - // -- Properties Defined - - /** - * Properties required when calling the Ctrip service - */ - public interface ToCtripServiceOptions { - - /** - * SOA ServiceCode - * - * @return the service code - */ - String getServiceCode(); - - /** - * SOA ServiceName - * - * @return the service name - */ - String getServiceName(); - } - - /** - * Properties required when calling the AWS service - */ - public interface ToAwsServiceOptions { - - /** - * App Mesh Host name - * - * @return the host name - */ - String getHostName(); - - /** - * App Mesh Host port - * - * @return the host port - */ - String getHostPort(); - } - - /** - * Properties available when deployed on Ctrip - */ - public interface CtripServiceOptions { - - /** - * Ctrip deployment environment - * - * @return the service env - */ - CapaEnvironment.DeployVpcEnvironment getServiceEnv(); - } - - /** - * Properties available when deployed on AWS - */ - public interface AwsServiceOptions { - - /** - * AWS deployment environment - * - * @return the service env - */ - CapaEnvironment.DeployVpcEnvironment getServiceEnv(); - } - - // Specific Properties Impl - - /** - * The service deployed on Ctrip calls the service of Ctrip - */ - public static class CtripToCtripServiceOptions implements CtripServiceOptions, ToCtripServiceOptions { - - private final String serviceCode; - private final String serviceName; - private final CapaEnvironment.DeployVpcEnvironment serviceEnv; - - /** - * Instantiates a new Ctrip to ctrip service options. - * - * @param serviceCode the service code - * @param serviceName the service name - * @param serviceEnv the service env - */ - public CtripToCtripServiceOptions(String serviceCode, String serviceName, CapaEnvironment.DeployVpcEnvironment serviceEnv) { - this.serviceCode = serviceCode; - this.serviceName = serviceName; - this.serviceEnv = serviceEnv; - } - - @Override - public String getServiceCode() { - return serviceCode; - } - - @Override - public String getServiceName() { - return serviceName; - } - - @Override - public CapaEnvironment.DeployVpcEnvironment getServiceEnv() { - return serviceEnv; - } - } - - /** - * TODO The service deployed on Ctrip calls the service of AWS - */ - public static class CtripToAwsServiceOptions implements CtripServiceOptions { - - private final CapaEnvironment.DeployVpcEnvironment serviceEnv; - - /** - * Instantiates a new Ctrip to aws service options. - * - * @param serviceEnv the service env - */ - public CtripToAwsServiceOptions(CapaEnvironment.DeployVpcEnvironment serviceEnv) { - this.serviceEnv = serviceEnv; - } - - @Override - public CapaEnvironment.DeployVpcEnvironment getServiceEnv() { - return serviceEnv; - } - } - - /** - * The service deployed on AWS calls the service of Ctrip - */ - public static class AwsToCtripServiceOptions implements AwsServiceOptions, ToCtripServiceOptions { - - private final String serviceCode; - private final String serviceName; - private final CapaEnvironment.DeployVpcEnvironment serviceEnv; - - /** - * Instantiates a new Aws to ctrip service options. - * - * @param serviceCode the service code - * @param serviceName the service name - * @param serviceEnv the service env - */ - public AwsToCtripServiceOptions(String serviceCode, String serviceName, CapaEnvironment.DeployVpcEnvironment serviceEnv) { - this.serviceCode = serviceCode; - this.serviceName = serviceName; - this.serviceEnv = serviceEnv; - } - - @Override - public String getServiceCode() { - return serviceCode; - } - - @Override - public String getServiceName() { - return serviceName; - } - - @Override - public CapaEnvironment.DeployVpcEnvironment getServiceEnv() { - return serviceEnv; - } - } - - /** - * The service deployed on AWS calls the service of AWS - */ - public static class AwsToAwsServiceOptions implements AwsServiceOptions, ToAwsServiceOptions { - - private final String hostName; - private final String hostPort; - private final CapaEnvironment.DeployVpcEnvironment serviceEnv; - - /** - * Instantiates a new Aws to aws service options. - * - * @param hostName the host name - * @param hostPort the host port - * @param serviceEnv the service env - */ - public AwsToAwsServiceOptions(String hostName, String hostPort, CapaEnvironment.DeployVpcEnvironment serviceEnv) { - this.hostName = hostName; - this.hostPort = hostPort; - this.serviceEnv = serviceEnv; - } - - @Override - public CapaEnvironment.DeployVpcEnvironment getServiceEnv() { - return serviceEnv; - } - - @Override - public String getHostName() { - return hostName; - } - - @Override - public String getHostPort() { - return hostPort; - } - } - - // -- Getter and Setter - - /** - * Gets app id. - * - * @return the app id - */ - public String getAppId() { - return appId; - } - - /** - * Gets rpc invoke mode. - * - * @return the rpc invoke mode - */ - public ServiceRpcInvokeMode getRpcInvokeMode() { - return rpcInvokeMode; - } - - /** - * Gets ctrip to ctrip service options. - * - * @return the ctrip to ctrip service options - */ - public CtripToCtripServiceOptions getCtripToCtripServiceOptions() { - return ctripToCtripServiceOptions; - } - - /** - * Sets ctrip to ctrip service options. - * - * @param ctripToCtripServiceOptions the ctrip to ctrip service options - */ - public void setCtripToCtripServiceOptions(CtripToCtripServiceOptions ctripToCtripServiceOptions) { - this.ctripToCtripServiceOptions = ctripToCtripServiceOptions; - } - - /** - * Gets ctrip to aws service options. - * - * @return the ctrip to aws service options - */ - public CtripToAwsServiceOptions getCtripToAwsServiceOptions() { - return ctripToAwsServiceOptions; - } - - /** - * Sets ctrip to aws service options. - * - * @param ctripToAwsServiceOptions the ctrip to aws service options - */ - public void setCtripToAwsServiceOptions(CtripToAwsServiceOptions ctripToAwsServiceOptions) { - this.ctripToAwsServiceOptions = ctripToAwsServiceOptions; - } - - /** - * Gets aws to ctrip service options. - * - * @return the aws to ctrip service options - */ - public AwsToCtripServiceOptions getAwsToCtripServiceOptions() { - return awsToCtripServiceOptions; - } - - /** - * Sets aws to ctrip service options. - * - * @param awsToCtripServiceOptions the aws to ctrip service options - */ - public void setAwsToCtripServiceOptions(AwsToCtripServiceOptions awsToCtripServiceOptions) { - this.awsToCtripServiceOptions = awsToCtripServiceOptions; - } - - /** - * Gets aws to aws service options. - * - * @return the aws to aws service options - */ - public AwsToAwsServiceOptions getAwsToAwsServiceOptions() { - return awsToAwsServiceOptions; - } - - /** - * Sets aws to aws service options. - * - * @param awsToAwsServiceOptions the aws to aws service options - */ - public void setAwsToAwsServiceOptions(AwsToAwsServiceOptions awsToAwsServiceOptions) { - this.awsToAwsServiceOptions = awsToAwsServiceOptions; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof DemoRpcServiceOptions)) { - return false; - } - DemoRpcServiceOptions that = (DemoRpcServiceOptions) o; - return Objects.equals(appId, that.appId) - && rpcInvokeMode == that.rpcInvokeMode - && Objects.equals(ctripToCtripServiceOptions, that.ctripToCtripServiceOptions) - && Objects.equals(ctripToAwsServiceOptions, that.ctripToAwsServiceOptions) - && Objects.equals(awsToCtripServiceOptions, that.awsToCtripServiceOptions) - && Objects.equals(awsToAwsServiceOptions, that.awsToAwsServiceOptions); - } - - @Override - public int hashCode() { - return Objects.hash(appId, rpcInvokeMode, ctripToCtripServiceOptions, ctripToAwsServiceOptions, awsToCtripServiceOptions, awsToAwsServiceOptions); - } - - @Override - public String toString() { - return "DemoRpcServiceOptions{" + - "appId='" + appId + '\'' + - ", rpcInvokeMode=" + rpcInvokeMode + - ", ctripToCtripServiceOptions=" + ctripToCtripServiceOptions + - ", ctripToAwsServiceOptions=" + ctripToAwsServiceOptions + - ", awsToCtripServiceOptions=" + awsToCtripServiceOptions + - ", awsToAwsServiceOptions=" + awsToAwsServiceOptions + - '}'; } } \ No newline at end of file diff --git a/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/config/DemoSpiOptionsLoader.java b/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/config/DemoSpiOptionsLoader.java index 622a199..59e8ee1 100644 --- a/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/config/DemoSpiOptionsLoader.java +++ b/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/config/DemoSpiOptionsLoader.java @@ -1,51 +1,14 @@ package group.rxcloud.capa.spi.demo.config; -import group.rxcloud.capa.infrastructure.env.CapaEnvironment; import group.rxcloud.capa.spi.config.CapaSpiOptionsLoader; import java.util.Objects; public class DemoSpiOptionsLoader implements CapaSpiOptionsLoader { - /** - * TestService - */ - private static final String TEST_SERVICE_CODE = "22687"; - private static final String TEST_SERVICE_NAME = "TestSOAService"; - private static final String TEST_HOST_NAME = "hello-world-service.app-namespace.svc.cluster.local"; - private static final String TEST_HOST_PORT = "8888"; - @Override public DemoRpcServiceOptions loadRpcServiceOptions(String appId) { Objects.requireNonNull(appId, "appId"); - CapaEnvironment.DeployCloudEnvironment deployCloudEnvironment = CapaEnvironment.getDeployCloudEnvironment(); - CapaEnvironment.DeployVpcEnvironment deployVpcEnvironment = CapaEnvironment.getDeployVpcEnvironment(); - DemoRpcServiceOptions rpcServiceOptions = null; - switch (deployCloudEnvironment) { - case CTRIP_IDC: { - // ctirp -> ctrip - String serviceCode; - serviceCode = TEST_SERVICE_CODE; - String serviceName; - serviceName = TEST_SERVICE_NAME; - rpcServiceOptions = new DemoRpcServiceOptions(appId, DemoRpcServiceOptions.ServiceRpcInvokeMode.CTRIP_TO_CTRIP); - DemoRpcServiceOptions.CtripToCtripServiceOptions ctripToCtripServiceOptions = - new DemoRpcServiceOptions.CtripToCtripServiceOptions(serviceCode, serviceName, deployVpcEnvironment); - rpcServiceOptions.setCtripToCtripServiceOptions(ctripToCtripServiceOptions); - break; - } - case AWS_CLOUD: { - // aws -> aws - String hostName; - hostName = TEST_HOST_NAME; - String hostPort; - hostPort = TEST_HOST_PORT; - rpcServiceOptions = new DemoRpcServiceOptions(appId, DemoRpcServiceOptions.ServiceRpcInvokeMode.AWS_TO_AWS); - DemoRpcServiceOptions.AwsToAwsServiceOptions awsToAwsServiceOptions = - new DemoRpcServiceOptions.AwsToAwsServiceOptions(hostName, hostPort, deployVpcEnvironment); - rpcServiceOptions.setAwsToAwsServiceOptions(awsToAwsServiceOptions); - } - } - return rpcServiceOptions; + return new DemoRpcServiceOptions(appId); } } diff --git a/sdk-spi/src/main/java/group/rxcloud/capa/spi/http/CapaHttpSpi.java b/sdk-spi/src/main/java/group/rxcloud/capa/spi/http/CapaHttpSpi.java index efe01d9..e747fcd 100644 --- a/sdk-spi/src/main/java/group/rxcloud/capa/spi/http/CapaHttpSpi.java +++ b/sdk-spi/src/main/java/group/rxcloud/capa/spi/http/CapaHttpSpi.java @@ -3,8 +3,8 @@ import group.rxcloud.capa.component.http.CapaHttp; import group.rxcloud.capa.component.http.HttpResponse; import group.rxcloud.capa.infrastructure.serializer.CapaObjectSerializer; -import group.rxcloud.capa.spi.config.CapaSpiProperties; import group.rxcloud.capa.spi.config.CapaSpiOptionsLoader; +import group.rxcloud.capa.spi.config.CapaSpiProperties; import group.rxcloud.capa.spi.config.RpcServiceOptions; import group.rxcloud.cloudruntimes.utils.TypeRef; import okhttp3.OkHttpClient; diff --git a/sdk/src/main/java/group/rxcloud/capa/configuration/CapaConfigurationClient.java b/sdk/src/main/java/group/rxcloud/capa/configuration/CapaConfigurationClient.java index e241b47..192c718 100644 --- a/sdk/src/main/java/group/rxcloud/capa/configuration/CapaConfigurationClient.java +++ b/sdk/src/main/java/group/rxcloud/capa/configuration/CapaConfigurationClient.java @@ -27,4 +27,12 @@ public interface CapaConfigurationClient extends DefaultCloudRuntimesClient { @Override Flux> subscribeConfiguration(ConfigurationRequestItem configurationRequestItem, TypeRef type); + + @Override + default Mono shutdown() { + return Mono.empty(); + } + + @Override + void close(); } diff --git a/sdk/src/main/java/group/rxcloud/capa/metrics/CapaMetricsClient.java b/sdk/src/main/java/group/rxcloud/capa/metrics/CapaMetricsClient.java new file mode 100644 index 0000000..206e062 --- /dev/null +++ b/sdk/src/main/java/group/rxcloud/capa/metrics/CapaMetricsClient.java @@ -0,0 +1,15 @@ +package group.rxcloud.capa.metrics; + +import group.rxcloud.cloudruntimes.client.DefaultCloudRuntimesClient; +import reactor.core.publisher.Mono; + +public interface CapaMetricsClient extends DefaultCloudRuntimesClient { + + @Override + default Mono shutdown() { + return Mono.empty(); + } + + @Override + void close(); +} diff --git a/sdk/src/main/java/group/rxcloud/capa/pubsub/CapaPubSubClient.java b/sdk/src/main/java/group/rxcloud/capa/pubsub/CapaPubSubClient.java new file mode 100644 index 0000000..cdba481 --- /dev/null +++ b/sdk/src/main/java/group/rxcloud/capa/pubsub/CapaPubSubClient.java @@ -0,0 +1,50 @@ +package group.rxcloud.capa.pubsub; + +import group.rxcloud.cloudruntimes.client.DefaultCloudRuntimesClient; +import group.rxcloud.cloudruntimes.domain.core.binding.InvokeBindingRequest; +import group.rxcloud.cloudruntimes.domain.core.pubsub.PublishEventRequest; +import group.rxcloud.cloudruntimes.utils.TypeRef; +import reactor.core.publisher.Mono; + +import java.util.Map; + +public interface CapaPubSubClient extends DefaultCloudRuntimesClient { + + @Override + Mono invokeBinding(String bindingName, String operation, Object data); + + @Override + Mono invokeBinding(String bindingName, String operation, byte[] data, Map metadata); + + @Override + Mono invokeBinding(String bindingName, String operation, Object data, TypeRef type); + + @Override + Mono invokeBinding(String bindingName, String operation, Object data, Class clazz); + + @Override + Mono invokeBinding(String bindingName, String operation, Object data, Map metadata, TypeRef type); + + @Override + Mono invokeBinding(String bindingName, String operation, Object data, Map metadata, Class clazz); + + @Override + Mono invokeBinding(InvokeBindingRequest request, TypeRef type); + + @Override + Mono publishEvent(String pubsubName, String topicName, Object data); + + @Override + Mono publishEvent(String pubsubName, String topicName, Object data, Map metadata); + + @Override + Mono publishEvent(PublishEventRequest request); + + @Override + default Mono shutdown() { + return Mono.empty(); + } + + @Override + void close(); +} diff --git a/sdk/src/main/java/group/rxcloud/capa/rpc/CapaRpcClient.java b/sdk/src/main/java/group/rxcloud/capa/rpc/CapaRpcClient.java index 4ffaa1e..d3175b0 100644 --- a/sdk/src/main/java/group/rxcloud/capa/rpc/CapaRpcClient.java +++ b/sdk/src/main/java/group/rxcloud/capa/rpc/CapaRpcClient.java @@ -46,6 +46,11 @@ public interface CapaRpcClient extends DefaultCloudRuntimesClient { @Override Mono invokeMethod(InvokeMethodRequest invokeMethodRequest, TypeRef type); + @Override + default Mono shutdown() { + return Mono.empty(); + } + @Override void close(); } diff --git a/sdk/src/main/java/group/rxcloud/capa/state/CapaStateClient.java b/sdk/src/main/java/group/rxcloud/capa/state/CapaStateClient.java new file mode 100644 index 0000000..119c9ae --- /dev/null +++ b/sdk/src/main/java/group/rxcloud/capa/state/CapaStateClient.java @@ -0,0 +1,76 @@ +package group.rxcloud.capa.state; + +import group.rxcloud.cloudruntimes.client.DefaultCloudRuntimesClient; +import group.rxcloud.cloudruntimes.domain.core.state.*; +import group.rxcloud.cloudruntimes.utils.TypeRef; +import reactor.core.publisher.Mono; + +import java.util.List; + +public interface CapaStateClient extends DefaultCloudRuntimesClient { + + @Override + Mono> getState(String storeName, State state, TypeRef type); + + @Override + Mono> getState(String storeName, State state, Class clazz); + + @Override + Mono> getState(String storeName, String key, TypeRef type); + + @Override + Mono> getState(String storeName, String key, Class clazz); + + @Override + Mono> getState(String storeName, String key, StateOptions options, TypeRef type); + + @Override + Mono> getState(String storeName, String key, StateOptions options, Class clazz); + + @Override + Mono> getState(GetStateRequest request, TypeRef type); + + @Override + Mono>> getBulkState(String storeName, List keys, TypeRef type); + + @Override + Mono>> getBulkState(String storeName, List keys, Class clazz); + + @Override + Mono>> getBulkState(GetBulkStateRequest request, TypeRef type); + + @Override + Mono executeStateTransaction(String storeName, List> operations); + + @Override + Mono executeStateTransaction(ExecuteStateTransactionRequest request); + + @Override + Mono saveBulkState(String storeName, List> states); + + @Override + Mono saveBulkState(SaveStateRequest request); + + @Override + Mono saveState(String storeName, String key, Object value); + + @Override + Mono saveState(String storeName, String key, String etag, Object value, StateOptions options); + + @Override + Mono deleteState(String storeName, String key); + + @Override + Mono deleteState(String storeName, String key, String etag, StateOptions options); + + @Override + Mono deleteState(DeleteStateRequest request); + + @Override + default Mono shutdown() { + return Mono.empty(); + } + + @Override + void close(); +}