Skip to content

Commit ff4cef9

Browse files
authored
Merge pull request #18 from Huijing-Xu/feature-mesh-template
feat: change aws app mesh template
2 parents d4cee96 + 1de4f0e commit ff4cef9

File tree

8 files changed

+58
-4
lines changed

8 files changed

+58
-4
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ public interface ToAwsServiceOptions {
8080
* @return the service port
8181
*/
8282
int getServicePort();
83+
84+
/**
85+
* Namespace
86+
*
87+
* @return the namespace
88+
*/
89+
String getNamespace();
8390
}
8491

8592
/**
@@ -102,17 +109,19 @@ public static class AwsToAwsServiceOptions implements AwsServiceOptions, ToAwsSe
102109

103110
private final String serviceId;
104111
private final int servicePort;
112+
private final String namespace;
105113
private final CapaEnvironment.DeployVpcEnvironment serviceEnv;
106114

107115
/**
108116
* @param serviceId the service id
109117
* @param servicePort the service port
110118
* @param serviceEnv the service env
111119
*/
112-
public AwsToAwsServiceOptions(String serviceId, int servicePort,
120+
public AwsToAwsServiceOptions(String serviceId, int servicePort, String namespace,
113121
CapaEnvironment.DeployVpcEnvironment serviceEnv) {
114122
this.serviceId = serviceId;
115123
this.servicePort = servicePort;
124+
this.namespace = namespace;
116125
this.serviceEnv = serviceEnv;
117126
}
118127

@@ -126,6 +135,11 @@ public int getServicePort() {
126135
return servicePort;
127136
}
128137

138+
@Override
139+
public String getNamespace() {
140+
return namespace;
141+
}
142+
129143
@Override
130144
public CapaEnvironment.DeployVpcEnvironment getServiceEnv() {
131145
return serviceEnv;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ public AwsRpcServiceOptions loadRpcServiceOptions(String appId) {
3535
// get variable
3636
CapaEnvironment.DeployVpcEnvironment deployVpcEnvironment = CapaEnvironment.getDeployVpcEnvironment();
3737
final int servicePort = AwsRpcEnvironment.getServicePort();
38+
final String namespace = AwsRpcEnvironment.getNamespace();
3839

3940
// generate awsToAwsServiceOptions
4041
// appid is serviceId
4142
AwsRpcServiceOptions.AwsToAwsServiceOptions awsToAwsServiceOptions
42-
= new AwsRpcServiceOptions.AwsToAwsServiceOptions(appId, servicePort, deployVpcEnvironment);
43+
= new AwsRpcServiceOptions.AwsToAwsServiceOptions(appId, servicePort, namespace, deployVpcEnvironment);
4344
rpcServiceOptions.setAwsToAwsServiceOptions(awsToAwsServiceOptions);
4445

4546
return rpcServiceOptions;

capa-spi-aws-mesh/src/main/java/group/rxcloud/capa/spi/aws/mesh/constants/AwsRpcConstants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ interface AppMeshProperties {
2727
* The aws app mesh http url template
2828
* {serviceId}.svc.cluster.local is virtual service name (https://docs.aws.amazon.com/zh_cn/zh_cn/app-mesh/latest/userguide/virtual_services.html)
2929
*/
30-
String AWS_APP_MESH_TEMPLATE = "http://{serviceId}.svc.cluster.local:{servicePort}/{operation}";
30+
String AWS_APP_MESH_TEMPLATE = "http://{serviceId}.{namespace}.svc.cluster.local:{servicePort}/{operation}";
3131

3232
String RPC_AWS_APP_MESH_DEFAULT_PORT = "8080";
3333

3434
String RPC_AWS_APP_MESH_PORT = "CAPA_RPC_AWS_APP_MESH_PORT";
35+
36+
String RPC_AWS_APP_MESH_NAMESPACE = "CAPA_RPC_AWS_APP_MESH_NAMESPACE";
37+
38+
String RPC_AWS_APP_MESH_DEFAULT_NAMESPACE = "FWS";
39+
3540
}
3641

3742
interface SerializerProperties {

capa-spi-aws-mesh/src/main/java/group/rxcloud/capa/spi/aws/mesh/env/AwsRpcEnvironment.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424

2525
import static group.rxcloud.capa.spi.aws.mesh.constants.AwsRpcConstants.AppMeshProperties.RPC_AWS_APP_MESH_DEFAULT_PORT;
2626
import static group.rxcloud.capa.spi.aws.mesh.constants.AwsRpcConstants.AppMeshProperties.RPC_AWS_APP_MESH_PORT;
27+
import static group.rxcloud.capa.spi.aws.mesh.constants.AwsRpcConstants.AppMeshProperties.RPC_AWS_APP_MESH_DEFAULT_NAMESPACE;
28+
import static group.rxcloud.capa.spi.aws.mesh.constants.AwsRpcConstants.AppMeshProperties.RPC_AWS_APP_MESH_NAMESPACE;
2729
import static group.rxcloud.capa.spi.aws.mesh.constants.AwsRpcConstants.SerializerProperties.RPC_AWS_APP_MESH_DEFAULT_SERIALIZER;
2830
import static group.rxcloud.capa.spi.aws.mesh.constants.AwsRpcConstants.SerializerProperties.RPC_AWS_APP_MESH_SERIALIZER;
2931

32+
3033
/**
3134
* Rpc System Environment Properties In Aws.
3235
*/
@@ -42,12 +45,20 @@ public abstract class AwsRpcEnvironment {
4245
*/
4346
private static String serializer;
4447

48+
/**
49+
* The namespace of app mesh
50+
*/
51+
private static String namespace;
52+
4553
static {
4654
// setup server port
4755
initPort();
4856

4957
// setup serializer
5058
initSerializer();
59+
60+
// setup namespace
61+
initNamespace();
5162
}
5263

5364
private static void initPort() {
@@ -70,11 +81,23 @@ private static void initSerializer() {
7081
serializer = awsRpcAppMeshSerializer;
7182
}
7283

84+
private static void initNamespace() {
85+
String awsRpcAppMeshNamespace = System.getProperty(RPC_AWS_APP_MESH_NAMESPACE);
86+
if (StringUtils.isBlank(awsRpcAppMeshNamespace)) {
87+
awsRpcAppMeshNamespace = RPC_AWS_APP_MESH_DEFAULT_NAMESPACE;
88+
}
89+
namespace = awsRpcAppMeshNamespace;
90+
}
91+
7392
public static int getServicePort() {
7493
return Objects.requireNonNull(servicePort, "Capa Rpc App Mesh Port");
7594
}
7695

7796
public static String getSerializer() {
7897
return Objects.requireNonNull(serializer, "Capa Serializer");
7998
}
99+
100+
public static String getNamespace() {
101+
return Objects.requireNonNull(namespace, "Capa Namespace");
102+
}
80103
}

capa-spi-aws-mesh/src/main/java/group/rxcloud/capa/spi/aws/mesh/http/AwsCapaHttp.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,27 @@ public <T> CompletableFuture<HttpResponse<T>> doInvokeSpiApi(String appId,
117117

118118
final String serviceId = awsToAwsServiceOptions.getServiceId();
119119
final int servicePort = awsToAwsServiceOptions.getServicePort();
120+
final String namespace = awsToAwsServiceOptions.getNamespace();
120121

121122
if (StringUtils.isBlank(serviceId)) {
122123
throw new CapaException(CapaErrorContext.PARAMETER_ERROR,
123124
"Aws appMesh no serviceId error.");
124125
}
125126

126-
return doAsyncInvoke(method, requestData, headers, type, serviceId, servicePort);
127+
return doAsyncInvoke(method, requestData, headers, type, serviceId, namespace, servicePort);
127128
}
128129

129130
private <T> CompletableFuture<HttpResponse<T>> doAsyncInvoke(String method,
130131
Object requestData,
131132
Map<String, String> headers,
132133
TypeRef<T> type,
133134
String serviceId,
135+
String namespace,
134136
int servicePort) {
135137
// generate app mesh http url
136138
final String appMeshHttpUrl = AWS_APP_MESH_TEMPLATE
137139
.replace("{serviceId}", serviceId)
140+
.replace("{namespace}", namespace)
138141
.replace("{servicePort}", String.valueOf(servicePort))
139142
.replace("{operation}", method);
140143

capa-spi-aws-mesh/src/test/java/group/rxcloud/capa/spi/aws/mesh/config/AwsRpcServiceOptionsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void setUp() {
3535
awsToAwsServiceOptions = new AwsRpcServiceOptions.AwsToAwsServiceOptions(
3636
"appId",
3737
8080,
38+
"FWS",
3839
CapaEnvironment.DeployVpcEnvironment.FWS);
3940
awsRpcServiceOptions.setAwsToAwsServiceOptions(awsToAwsServiceOptions);
4041
}
@@ -58,6 +59,7 @@ public void testGetAwsToAwsServiceOptions_Success() {
5859

5960
Assertions.assertEquals("appId", awsToAwsServiceOptions.getServiceId());
6061
Assertions.assertEquals(8080, awsToAwsServiceOptions.getServicePort());
62+
Assertions.assertEquals("FWS", awsToAwsServiceOptions.getNamespace());
6163
Assertions.assertEquals(CapaEnvironment.DeployVpcEnvironment.FWS, awsToAwsServiceOptions.getServiceEnv());
6264
}
6365

capa-spi-aws-mesh/src/test/java/group/rxcloud/capa/spi/aws/mesh/config/AwsSpiOptionsLoaderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public void testLoadRpcServiceOptions_Success() {
3434

3535
Assertions.assertEquals("appId", awsToAwsServiceOptions.getServiceId());
3636
Assertions.assertEquals(8080, awsToAwsServiceOptions.getServicePort());
37+
Assertions.assertEquals("FWS", awsToAwsServiceOptions.getNamespace());
3738
Assertions.assertEquals(CapaEnvironment.DeployVpcEnvironment.FWS, awsToAwsServiceOptions.getServiceEnv());
3839
}
3940

capa-spi-aws-mesh/src/test/java/group/rxcloud/capa/spi/aws/mesh/env/AwsRpcEnvironmentTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ public void testGetSerializer_SuccessWhenDefault() {
3333
Assertions.assertEquals("baiji", serializer);
3434
}
3535

36+
@Test
37+
public void testGetNamespace_SuccessWhenDefault() {
38+
String namespace = AwsRpcEnvironment.getNamespace();
39+
Assertions.assertEquals("FWS", namespace);
40+
}
3641
}

0 commit comments

Comments
 (0)