[issue-87][apollo-java]: Added a new feature to get instance count by namespace.#5381
Conversation
WalkthroughA new REST API endpoint has been introduced to provide the count of instances for a specific namespace within an application, cluster, and environment. This is achieved by adding a new controller class that exposes the endpoint and a corresponding service class that implements the required business logic. The controller receives HTTP GET requests, extracts the necessary parameters from the URL, and delegates the processing to the service, which interacts with the internal instance service to retrieve the instance count. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant InstanceController
participant ServerInstanceOpenApiService
participant InstanceService
Client->>InstanceController: GET /openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/instances
InstanceController->>ServerInstanceOpenApiService: getInstanceCountByNamespace(appId, env, clusterName, namespaceName)
ServerInstanceOpenApiService->>InstanceService: getInstanceCountByNamespace(appId, Env.valueOf(env), clusterName, namespaceName)
InstanceService-->>ServerInstanceOpenApiService: instance count
ServerInstanceOpenApiService-->>InstanceController: instance count
InstanceController-->>Client: instance count
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/InstanceController.java (1)
31-35: Endpoint implementation looks correctThe GET endpoint follows REST conventions and has appropriate path variables. The method signature matches the HTTP request structure and properly delegates to the service.
Consider adding API documentation using Swagger annotations to improve API discoverability:
+import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; @RestController("openapiInstanceController") @RequestMapping("/openapi/v1/envs/{env}") +@Api(tags = "Instance APIs") public class InstanceController { // ... + @ApiOperation("Get instance count by namespace") @GetMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/instances") public int getInstanceCountByNamespace( + @ApiParam("Application ID") @PathVariable String appId, + @ApiParam("Environment") @PathVariable String env, + @ApiParam("Cluster name") @PathVariable String clusterName, + @ApiParam("Namespace name") @PathVariable String namespaceName) { // ... } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerInstanceOpenApiService.java(1 hunks)apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/InstanceController.java(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerInstanceOpenApiService.java (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/environment/Env.java (1)
Env(34-237)
🪛 GitHub Actions: build
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerInstanceOpenApiService.java
[error] 19-25: Compilation error: cannot find symbol 'InstanceOpenApiService' in package 'com.ctrip.framework.apollo.openapi.api'.
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/InstanceController.java
[error] 19-27: Compilation error: cannot find symbol 'InstanceOpenApiService' in package 'com.ctrip.framework.apollo.openapi.api'.
🔇 Additional comments (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/InstanceController.java (1)
22-24: Controller name and request mapping look goodThe controller uses a bean name qualifier "openapiInstanceController" which helps avoid conflicts with other instance controllers. The request mapping follows the RESTful pattern of Apollo's OpenAPI.
|
I have read the CLA Document and I hereby sign the CLA |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
What's the purpose of this PR
Get instance count by namespaces
Which issue(s) this PR fixes:
For #87
Brief changelog
Added a new feature to get instance count by namespace.
Follow this checklist to help us incorporate your contribution quickly and easily:
mvn clean testto make sure this pull request doesn't break anything.CHANGESlog.Summary by CodeRabbit