Skip to content

Commit 14a94c8

Browse files
xuhuijingxuhuijing
authored andcommitted
reliaze rpc invoke in app mesh about aws to aws
1 parent 2b376ac commit 14a94c8

File tree

10 files changed

+450
-54
lines changed

10 files changed

+450
-54
lines changed

capa-spi-aws-config/src/main/java/group/rxcloud/capa/spi/aws/config/AwsCapaConfiguration.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,19 @@
1717
package group.rxcloud.capa.spi.aws.config;
1818

1919
import group.rxcloud.capa.component.configstore.CapaConfigStore;
20+
import group.rxcloud.capa.component.configstore.ConfigurationItem;
21+
import group.rxcloud.capa.component.configstore.GetRequest;
22+
import group.rxcloud.capa.component.configstore.StoreConfig;
23+
import group.rxcloud.capa.component.configstore.SubscribeReq;
24+
import group.rxcloud.capa.component.configstore.SubscribeResp;
2025
import group.rxcloud.capa.infrastructure.serializer.CapaObjectSerializer;
26+
import group.rxcloud.cloudruntimes.utils.TypeRef;
27+
import reactor.core.publisher.Flux;
28+
import reactor.core.publisher.Mono;
2129
import software.amazon.awssdk.services.appconfig.AppConfigAsyncClient;
2230

31+
import java.util.List;
32+
2333
/**
2434
* TODO load aws client from spi
2535
*/
@@ -37,6 +47,36 @@ public AwsCapaConfiguration(CapaObjectSerializer objectSerializer) {
3747
appConfigAsyncClient = AppConfigAsyncClient.create();
3848
}
3949

50+
@Override
51+
protected void doInit(StoreConfig storeConfig) {
52+
53+
}
54+
55+
@Override
56+
public <T> Mono<List<ConfigurationItem<T>>> get(GetRequest getRequest, TypeRef<T> typeRef) {
57+
return null;
58+
}
59+
60+
@Override
61+
public <T> Flux<SubscribeResp<T>> subscribe(SubscribeReq subscribeReq, TypeRef<T> typeRef) {
62+
return null;
63+
}
64+
65+
@Override
66+
public String stopSubscribe() {
67+
return null;
68+
}
69+
70+
@Override
71+
public String getDefaultGroup() {
72+
return null;
73+
}
74+
75+
@Override
76+
public String getDefaultLabel() {
77+
return null;
78+
}
79+
4080
@Override
4181
public void close() throws Exception {
4282

capa-spi-aws-mesh/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,22 @@
2929
<artifactId>capa-spi-aws-mesh</artifactId>
3030
<name>capa-skd-spi-aws-appmesh</name>
3131

32+
<properties>
33+
<capa-serialzer.version>1.0.0.RELEASE</capa-serialzer.version>
34+
</properties>
35+
3236
<dependencies>
3337
<dependency>
3438
<groupId>group.rxcloud</groupId>
3539
<artifactId>capa-spi-aws-infrastructure</artifactId>
3640
</dependency>
3741

42+
<dependency>
43+
<groupId>group.rxcloud</groupId>
44+
<artifactId>capa-serialzer</artifactId>
45+
<version>${capa-serialzer.version}</version>
46+
</dependency>
47+
3848
<dependency>
3949
<groupId>software.amazon.awssdk</groupId>
4050
<artifactId>appmesh</artifactId>

capa-spi-aws-mesh/src/main/java/group/rxcloud/capa/spi/aws/mesh/config/AwsRpcServiceOptions.java

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ public class AwsRpcServiceOptions implements RpcServiceOptions {
3030
* Unique rpc service ID
3131
*/
3232
private final String appId;
33+
34+
/**
35+
* The rpc invoke mode
36+
*/
3337
private final ServiceRpcInvokeMode rpcInvokeMode;
3438

35-
/*
36-
* Optional options
39+
/**
40+
* Optional options of Aws to Aws
3741
*/
3842
private AwsToAwsServiceOptions awsToAwsServiceOptions;
3943

@@ -55,30 +59,27 @@ public enum ServiceRpcInvokeMode {
5559
/**
5660
* AWS to AWS
5761
*/
58-
AWS_TO_AWS,
59-
;
62+
AWS_TO_AWS;
6063
}
6164

62-
// -- Properties Defined
63-
6465
/**
6566
* Properties required when calling the Aws service
6667
*/
6768
public interface ToAwsServiceOptions {
6869

6970
/**
70-
* SOA ServiceCode
71+
* ServiceId
7172
*
72-
* @return the service code
73+
* @return the service id
7374
*/
74-
String getServiceCode();
75+
String getServiceId();
7576

7677
/**
77-
* SOA ServiceName
78+
* ServicePort
7879
*
79-
* @return the service name
80+
* @return the service port
8081
*/
81-
String getServiceName();
82+
int getServicePort();
8283
}
8384

8485
/**
@@ -94,47 +95,43 @@ public interface AwsServiceOptions {
9495
CapaEnvironment.DeployVpcEnvironment getServiceEnv();
9596
}
9697

97-
// Specific Properties Impl
98-
9998
/**
10099
* The service deployed on Aws calls the service of Aws
101100
*/
102101
public static class AwsToAwsServiceOptions implements AwsServiceOptions, ToAwsServiceOptions {
103102

104-
private final String serviceCode;
105-
private final String serviceName;
103+
private final String serviceId;
104+
private final int servicePort;
106105
private final CapaEnvironment.DeployVpcEnvironment serviceEnv;
107106

108107
/**
109-
* Instantiates a new Aws to aws service options.
110-
*
111-
* @param serviceCode the service code
112-
* @param serviceName the service name
108+
* @param serviceId the service id
109+
* @param servicePort the service port
113110
* @param serviceEnv the service env
114111
*/
115-
public AwsToAwsServiceOptions(String serviceCode, String serviceName, CapaEnvironment.DeployVpcEnvironment serviceEnv) {
116-
this.serviceCode = serviceCode;
117-
this.serviceName = serviceName;
112+
public AwsToAwsServiceOptions(String serviceId, int servicePort,
113+
CapaEnvironment.DeployVpcEnvironment serviceEnv) {
114+
this.serviceId = serviceId;
115+
this.servicePort = servicePort;
118116
this.serviceEnv = serviceEnv;
119117
}
120118

121119
@Override
122-
public String getServiceCode() {
123-
return serviceCode;
120+
public String getServiceId() {
121+
return serviceId;
124122
}
125123

126124
@Override
127-
public String getServiceName() {
128-
return serviceName;
125+
public int getServicePort() {
126+
return servicePort;
129127
}
130128

131129
@Override
132130
public CapaEnvironment.DeployVpcEnvironment getServiceEnv() {
133131
return serviceEnv;
134132
}
135-
}
136133

137-
// -- Getter and Setter
134+
}
138135

139136
/**
140137
* Gets app id.
@@ -155,7 +152,7 @@ public ServiceRpcInvokeMode getRpcInvokeMode() {
155152
}
156153

157154
/**
158-
* Gets aws to aws service options.
155+
* Gets Aws to Aws service options.
159156
*
160157
* @return the aws to aws service options
161158
*/
@@ -164,9 +161,9 @@ public AwsToAwsServiceOptions getAwsToAwsServiceOptions() {
164161
}
165162

166163
/**
167-
* Sets aws to aws service options.
164+
* Sets Aws to Aws service options.
168165
*
169-
* @param awsToAwsServiceOptions the aws to aws service options
166+
* @param awsToAwsServiceOptions the Aws to Aws service options
170167
*/
171168
public void setAwsToAwsServiceOptions(AwsToAwsServiceOptions awsToAwsServiceOptions) {
172169
this.awsToAwsServiceOptions = awsToAwsServiceOptions;

capa-spi-aws-mesh/src/main/java/group/rxcloud/capa/spi/aws/mesh/config/AwsSpiOptionsLoader.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package group.rxcloud.capa.spi.aws.mesh.config;
1818

1919
import group.rxcloud.capa.infrastructure.env.CapaEnvironment;
20+
import group.rxcloud.capa.spi.aws.mesh.env.AwsRpcEnvironment;
2021
import group.rxcloud.capa.spi.config.CapaSpiOptionsLoader;
2122

2223
import java.util.Objects;
@@ -26,11 +27,21 @@ public class AwsSpiOptionsLoader implements CapaSpiOptionsLoader<AwsRpcServiceOp
2627
@Override
2728
public AwsRpcServiceOptions loadRpcServiceOptions(String appId) {
2829
Objects.requireNonNull(appId, "appId");
29-
AwsRpcServiceOptions rpcServiceOptions = new AwsRpcServiceOptions(appId, AwsRpcServiceOptions.ServiceRpcInvokeMode.AWS_TO_AWS);
30+
31+
// generate AwsRpcServiceOptions
32+
AwsRpcServiceOptions rpcServiceOptions = new AwsRpcServiceOptions(appId,
33+
AwsRpcServiceOptions.ServiceRpcInvokeMode.AWS_TO_AWS);
34+
35+
// get variable
3036
CapaEnvironment.DeployVpcEnvironment deployVpcEnvironment = CapaEnvironment.getDeployVpcEnvironment();
31-
AwsRpcServiceOptions.AwsToAwsServiceOptions awsToAwsServiceOptions =
32-
new AwsRpcServiceOptions.AwsToAwsServiceOptions("", "", deployVpcEnvironment);
37+
int servicePort = AwsRpcEnvironment.getServicePort();
38+
39+
// generate awsToAwsServiceOptions
40+
// appid is serviceId
41+
AwsRpcServiceOptions.AwsToAwsServiceOptions awsToAwsServiceOptions
42+
= new AwsRpcServiceOptions.AwsToAwsServiceOptions(appId, servicePort, deployVpcEnvironment);
3343
rpcServiceOptions.setAwsToAwsServiceOptions(awsToAwsServiceOptions);
44+
3445
return rpcServiceOptions;
3546
}
3647
}

capa-spi-aws-mesh/src/main/java/group/rxcloud/capa/spi/aws/mesh/config/AwsClientProviderLoader.java renamed to capa-spi-aws-mesh/src/main/java/group/rxcloud/capa/spi/aws/mesh/constants/AwsRpcConstants.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package group.rxcloud.capa.spi.aws.mesh.config;
17+
package group.rxcloud.capa.spi.aws.mesh.constants;
1818

19-
import group.rxcloud.cloudruntimes.utils.TypeRef;
20-
import software.amazon.awssdk.core.SdkClient;
2119

22-
import java.util.Map;
20+
public interface AwsRpcConstants {
2321

24-
/**
25-
* TODO load class from spi
26-
*/
27-
public abstract class AwsClientProviderLoader {
22+
interface Environments {
23+
24+
String AWS_RPC_APP_MESH_DEFAULT_PORT = "AWS_RPC_APP_MESH_DEFAULT_PORT";
25+
26+
}
27+
28+
interface RpcProperties {
2829

29-
static Map<String, AwsClientProvider> clientProviders;
30+
/**
31+
* The aws app mesh http url template
32+
* {serviceId}.svc.cluster.local is virtual service name (https://docs.aws.amazon.com/zh_cn/zh_cn/app-mesh/latest/userguide/virtual_services.html)
33+
*/
34+
String AWS_APP_MESH_TEMPLATE = "http://{serviceId}.svc.cluster.local:{servicePort}/{operation}";
3035

31-
public static <T extends SdkClient> T load(TypeRef<T> typeRef) {
32-
AwsClientProvider provider = clientProviders.get(typeRef.getClass().getSimpleName());
33-
SdkClient sdkClient = provider.provideAwsClient();
34-
return (T) sdkClient;
3536
}
3637

37-
interface AwsClientProvider<T extends SdkClient> {
38+
interface SerializerProperties {
39+
40+
String AWS_RPC_APP_MESH_SERIALIZER = "AWS_RPC_APP_MESH_SERIALIZER";
3841

39-
T provideAwsClient();
4042
}
4143
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package group.rxcloud.capa.spi.aws.mesh.env;
18+
19+
import group.rxcloud.capa.infrastructure.exceptions.CapaErrorContext;
20+
import group.rxcloud.capa.infrastructure.exceptions.CapaException;
21+
import software.amazon.awssdk.utils.StringUtils;
22+
23+
import java.util.Objects;
24+
25+
import static group.rxcloud.capa.spi.aws.mesh.constants.AwsRpcConstants.Environments.AWS_RPC_APP_MESH_DEFAULT_PORT;
26+
import static group.rxcloud.capa.spi.aws.mesh.constants.AwsRpcConstants.SerializerProperties.AWS_RPC_APP_MESH_SERIALIZER;
27+
28+
/**
29+
* Rpc System Environment Properties In Aws.
30+
*/
31+
public abstract class AwsRpcEnvironment {
32+
33+
/**
34+
* The port of app mesh
35+
*/
36+
private static int servicePort;
37+
38+
/**
39+
* The serializer
40+
*/
41+
private static String serializer;
42+
43+
static {
44+
// setup server port
45+
String awsRpcAppMeshPort = System.getProperty(AWS_RPC_APP_MESH_DEFAULT_PORT);
46+
if (StringUtils.isBlank(awsRpcAppMeshPort)) {
47+
awsRpcAppMeshPort = "8080";
48+
}
49+
try {
50+
servicePort = Integer.valueOf(awsRpcAppMeshPort);
51+
} catch (Exception e) {
52+
new CapaException(CapaErrorContext.PARAMETER_ERROR, "Rpc Port: " + awsRpcAppMeshPort);
53+
}
54+
55+
// setup serializer
56+
String awsRpcAppMeshSerializer = System.getProperty(AWS_RPC_APP_MESH_SERIALIZER);
57+
if (StringUtils.isBlank(awsRpcAppMeshSerializer)) {
58+
awsRpcAppMeshSerializer = "baiji";
59+
}
60+
serializer = awsRpcAppMeshSerializer;
61+
}
62+
63+
public static int getServicePort() {
64+
return Objects.requireNonNull(servicePort, "Capa Rpc App Mesh Port");
65+
}
66+
67+
public static String getSerializer() {
68+
return Objects.requireNonNull(serializer, "Capa Serializer");
69+
}
70+
71+
}

0 commit comments

Comments
 (0)