Skip to content

Commit 722b42d

Browse files
committed
feat:#87 Get instance count
1 parent 362735d commit 722b42d

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2024 Apollo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.ctrip.framework.apollo.openapi.server.service;
18+
19+
import com.ctrip.framework.apollo.openapi.api.InstanceOpenApiService;
20+
import com.ctrip.framework.apollo.portal.environment.Env;
21+
import com.ctrip.framework.apollo.portal.service.InstanceService;
22+
import org.springframework.stereotype.Service;
23+
24+
@Service
25+
public class ServerInstanceOpenApiService implements InstanceOpenApiService {
26+
27+
private final InstanceService instanceService;
28+
29+
public ServerInstanceOpenApiService(InstanceService instanceService) {
30+
this.instanceService = instanceService;
31+
}
32+
33+
@Override
34+
public int getInstanceCountByNamespace(String appId, String env, String clusterName, String namespaceName) {
35+
return instanceService.getInstanceCountByNamespace(appId, Env.valueOf(env), clusterName, namespaceName);
36+
}
37+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2024 Apollo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.ctrip.framework.apollo.openapi.v1.controller;
18+
19+
import com.ctrip.framework.apollo.openapi.api.InstanceOpenApiService;
20+
import org.springframework.web.bind.annotation.*;
21+
22+
@RestController("openapiInstanceController")
23+
@RequestMapping("/openapi/v1/envs/{env}")
24+
public class InstanceController {
25+
private final InstanceOpenApiService instanceOpenApiService;
26+
27+
public InstanceController(InstanceOpenApiService instanceOpenApiService) {
28+
this.instanceOpenApiService = instanceOpenApiService;
29+
}
30+
31+
@GetMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/instances")
32+
public int getInstanceCountByNamespace(@PathVariable String appId, @PathVariable String env,
33+
@PathVariable String clusterName, @PathVariable String namespaceName) {
34+
return this.instanceOpenApiService.getInstanceCountByNamespace(appId, env, clusterName, namespaceName);
35+
}
36+
}

0 commit comments

Comments
 (0)