-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE #10734] Implement grpc server interceptor and grpc param extra…
…ctors (#10745) * For #10734,Implement grpc server interceptor and grpc param extractors * For #10734,add unit test for grpc server interceptor and grpc param extractors * For #10734,alter the test case * For #10734,delete the ConnectionSetupRequestParamExtractor
- Loading branch information
Showing
20 changed files
with
829 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../main/java/com/alibaba/nacos/core/paramcheck/impl/BatchInstanceRequestParamExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.nacos.core.paramcheck.impl; | ||
|
||
import com.alibaba.nacos.api.naming.pojo.Instance; | ||
import com.alibaba.nacos.api.naming.remote.request.BatchInstanceRequest; | ||
import com.alibaba.nacos.api.remote.request.Request; | ||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils; | ||
import com.alibaba.nacos.common.paramcheck.ParamInfo; | ||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Param Extractor and check for grpc batch instance request{@link BatchInstanceRequest}. | ||
* | ||
* @author zhuoguang | ||
*/ | ||
public class BatchInstanceRequestParamExtractor extends AbstractRpcParamExtractor { | ||
|
||
@Override | ||
public void init() { | ||
addTargetRequest(BatchInstanceRequest.class.getSimpleName()); | ||
} | ||
|
||
@Override | ||
public void extractParamAndCheck(Request request) throws Exception { | ||
BatchInstanceRequest req = (BatchInstanceRequest) request; | ||
ParamInfo paramInfo = new ParamInfo(); | ||
paramInfo.setNamespaceId(req.getNamespace()); | ||
paramInfo.setServiceName(req.getServiceName()); | ||
paramInfo.setGroup(req.getGroupName()); | ||
ParamCheckUtils.checkParamInfoFormat(paramInfo); | ||
List<Instance> instanceList = req.getInstances(); | ||
if (instanceList == null) { | ||
return; | ||
} | ||
for (Instance instance : instanceList) { | ||
ParamInfo instanceParamInfo = new ParamInfo(); | ||
instanceParamInfo.setIp(instance.getIp()); | ||
instanceParamInfo.setPort(String.valueOf(instance.getPort())); | ||
instanceParamInfo.setServiceName(instance.getServiceName()); | ||
instanceParamInfo.setCluster(instance.getClusterName()); | ||
instanceParamInfo.setMetadata(instance.getMetadata()); | ||
ParamCheckUtils.checkParamInfoFormat(instanceParamInfo); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...n/java/com/alibaba/nacos/core/paramcheck/impl/ConfigBatchListenRequestParamExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.nacos.core.paramcheck.impl; | ||
|
||
import com.alibaba.nacos.api.config.remote.request.ConfigBatchListenRequest; | ||
import com.alibaba.nacos.api.remote.request.Request; | ||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils; | ||
import com.alibaba.nacos.common.paramcheck.ParamInfo; | ||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Param extractor and checker for grpc config batch listen request{@link ConfigBatchListenRequest}. | ||
* | ||
* @author zhuoguang | ||
*/ | ||
public class ConfigBatchListenRequestParamExtractor extends AbstractRpcParamExtractor { | ||
|
||
@Override | ||
public void init() { | ||
addTargetRequest(ConfigBatchListenRequest.class.getSimpleName()); | ||
} | ||
|
||
@Override | ||
public void extractParamAndCheck(Request request) throws Exception { | ||
ConfigBatchListenRequest req = (ConfigBatchListenRequest) request; | ||
List<ConfigBatchListenRequest.ConfigListenContext> configListenContextList = req.getConfigListenContexts(); | ||
if (configListenContextList == null) { | ||
return; | ||
} | ||
for (ConfigBatchListenRequest.ConfigListenContext configListenContext : configListenContextList) { | ||
ParamInfo configListContextParamInfo = new ParamInfo(); | ||
configListContextParamInfo.setNamespaceId(configListenContext.getTenant()); | ||
configListContextParamInfo.setGroup(configListenContext.getGroup()); | ||
configListContextParamInfo.setDataId(configListenContext.getDataId()); | ||
ParamCheckUtils.checkParamInfoFormat(configListContextParamInfo); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
core/src/main/java/com/alibaba/nacos/core/paramcheck/impl/ConfigRequestParamExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.nacos.core.paramcheck.impl; | ||
|
||
import com.alibaba.nacos.api.config.remote.request.AbstractConfigRequest; | ||
import com.alibaba.nacos.api.config.remote.request.ConfigPublishRequest; | ||
import com.alibaba.nacos.api.config.remote.request.ConfigQueryRequest; | ||
import com.alibaba.nacos.api.config.remote.request.ConfigRemoveRequest; | ||
import com.alibaba.nacos.api.config.remote.request.cluster.ConfigChangeClusterSyncRequest; | ||
import com.alibaba.nacos.api.remote.request.Request; | ||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils; | ||
import com.alibaba.nacos.common.paramcheck.ParamInfo; | ||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor; | ||
|
||
/** | ||
* The type Config request param extractor {@link AbstractConfigRequest}. | ||
* | ||
* @author zhuoguang | ||
*/ | ||
public class ConfigRequestParamExtractor extends AbstractRpcParamExtractor { | ||
|
||
@Override | ||
public void init() { | ||
addTargetRequest(ConfigRemoveRequest.class.getSimpleName()); | ||
addTargetRequest(ConfigQueryRequest.class.getSimpleName()); | ||
addTargetRequest(ConfigPublishRequest.class.getSimpleName()); | ||
addTargetRequest(ConfigChangeClusterSyncRequest.class.getSimpleName()); | ||
} | ||
|
||
@Override | ||
public void extractParamAndCheck(Request request) throws Exception { | ||
AbstractConfigRequest req = (AbstractConfigRequest) request; | ||
ParamInfo paramInfo = new ParamInfo(); | ||
paramInfo.setDataId(req.getDataId()); | ||
paramInfo.setGroup(req.getGroup()); | ||
paramInfo.setNamespaceId(req.getTenant()); | ||
ParamCheckUtils.checkParamInfoFormat(paramInfo); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
core/src/main/java/com/alibaba/nacos/core/paramcheck/impl/InstanceRequestParamExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.nacos.core.paramcheck.impl; | ||
|
||
import com.alibaba.nacos.api.naming.pojo.Instance; | ||
import com.alibaba.nacos.api.naming.remote.request.InstanceRequest; | ||
import com.alibaba.nacos.api.remote.request.Request; | ||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils; | ||
import com.alibaba.nacos.common.paramcheck.ParamInfo; | ||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor; | ||
|
||
/** | ||
* Param extractor for {@link InstanceRequest}. | ||
* | ||
* @author zhuoguang | ||
*/ | ||
public class InstanceRequestParamExtractor extends AbstractRpcParamExtractor { | ||
|
||
@Override | ||
public void init() { | ||
addTargetRequest(InstanceRequest.class.getSimpleName()); | ||
} | ||
|
||
@Override | ||
public void extractParamAndCheck(Request request) throws Exception { | ||
InstanceRequest req = (InstanceRequest) request; | ||
ParamInfo paramInfo = new ParamInfo(); | ||
paramInfo.setNamespaceId(req.getNamespace()); | ||
paramInfo.setServiceName(req.getServiceName()); | ||
paramInfo.setGroup(req.getGroupName()); | ||
Instance instance = req.getInstance(); | ||
if (instance == null) { | ||
return; | ||
} | ||
paramInfo.setIp(instance.getIp()); | ||
paramInfo.setPort(String.valueOf(instance.getPort())); | ||
paramInfo.setCluster(instance.getClusterName()); | ||
paramInfo.setMetadata(instance.getMetadata()); | ||
ParamCheckUtils.checkParamInfoFormat(paramInfo); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...rc/main/java/com/alibaba/nacos/core/paramcheck/impl/ServiceListRequestParamExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.nacos.core.paramcheck.impl; | ||
|
||
import com.alibaba.nacos.api.naming.remote.request.ServiceListRequest; | ||
import com.alibaba.nacos.api.remote.request.Request; | ||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils; | ||
import com.alibaba.nacos.common.paramcheck.ParamInfo; | ||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor; | ||
|
||
/** | ||
* Param extractor for {@link ServiceListRequest}. | ||
* | ||
* @author zhuoguang | ||
*/ | ||
public class ServiceListRequestParamExtractor extends AbstractRpcParamExtractor { | ||
|
||
@Override | ||
public void init() { | ||
addTargetRequest(ServiceListRequest.class.getSimpleName()); | ||
} | ||
|
||
@Override | ||
public void extractParamAndCheck(Request request) throws Exception { | ||
ServiceListRequest req = (ServiceListRequest) request; | ||
ParamInfo paramInfo = new ParamInfo(); | ||
paramInfo.setNamespaceId(req.getNamespace()); | ||
paramInfo.setServiceName(req.getServiceName()); | ||
paramInfo.setGroup(req.getGroupName()); | ||
ParamCheckUtils.checkParamInfoFormat(paramInfo); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...c/main/java/com/alibaba/nacos/core/paramcheck/impl/ServiceQueryRequestParamExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 1999-2023 Alibaba Group Holding Ltd. | ||
* | ||
* 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 com.alibaba.nacos.core.paramcheck.impl; | ||
|
||
import com.alibaba.nacos.api.naming.remote.request.ServiceQueryRequest; | ||
import com.alibaba.nacos.api.remote.request.Request; | ||
import com.alibaba.nacos.common.paramcheck.ParamCheckUtils; | ||
import com.alibaba.nacos.common.paramcheck.ParamInfo; | ||
import com.alibaba.nacos.common.utils.StringUtils; | ||
import com.alibaba.nacos.core.paramcheck.AbstractRpcParamExtractor; | ||
|
||
/** | ||
* Param extractor for {@link ServiceQueryRequest}. | ||
* | ||
* @author zhuoguang | ||
*/ | ||
public class ServiceQueryRequestParamExtractor extends AbstractRpcParamExtractor { | ||
|
||
@Override | ||
public void init() { | ||
addTargetRequest(ServiceQueryRequest.class.getSimpleName()); | ||
} | ||
|
||
@Override | ||
public void extractParamAndCheck(Request request) throws Exception { | ||
ServiceQueryRequest req = (ServiceQueryRequest) request; | ||
ParamInfo paramInfo = new ParamInfo(); | ||
paramInfo.setNamespaceId(req.getNamespace()); | ||
paramInfo.setServiceName(req.getServiceName()); | ||
paramInfo.setGroup(req.getGroupName()); | ||
paramInfo.setPort(String.valueOf(req.getUdpPort())); | ||
ParamCheckUtils.checkParamInfoFormat(paramInfo); | ||
String clusterString = req.getCluster(); | ||
if (StringUtils.isNotBlank(clusterString)) { | ||
String[] clusters = clusterString.split(","); | ||
for (String cluster : clusters) { | ||
ParamCheckUtils.checkClusterFormat(cluster); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.