Commit 261b382c by Jason Song Committed by GitHub

Merge pull request #376 from lepdou/open

add envclusters interface
parents 450548f0 9670438e
package com.ctrip.framework.apollo.openapi.dto;
import java.util.Set;
public class OpenEnvClusterDTO {
private String env;
private Set<String> clusters;
public String getEnv() {
return env;
}
public void setEnv(String env) {
this.env = env;
}
public Set<String> getClusters() {
return clusters;
}
public void setClusters(Set<String> clusters) {
this.clusters = clusters;
}
}
package com.ctrip.framework.apollo.openapi.v1.controller;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.openapi.dto.OpenEnvClusterDTO;
import com.ctrip.framework.apollo.portal.PortalSettings;
import com.ctrip.framework.apollo.portal.service.ClusterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.LinkedList;
import java.util.List;
@RestController("openapiAppController")
@RequestMapping("/openapi/v1")
public class AppController {
@Autowired
private PortalSettings portalSettings;
@Autowired
private ClusterService clusterService;
@RequestMapping("/apps/{appId}/envclusters")
public List<OpenEnvClusterDTO> loadEnvClusterInfo(@PathVariable String appId){
List<OpenEnvClusterDTO> envClusters = new LinkedList<>();
List<Env> envs = portalSettings.getActiveEnvs();
for (Env env : envs) {
OpenEnvClusterDTO envCluster = new OpenEnvClusterDTO();
envCluster.setEnv(env.name());
List<ClusterDTO> clusterDTOs = clusterService.findClusters(env, appId);
envCluster.setClusters(BeanUtils.toPropertySet("name", clusterDTOs));
envClusters.add(envCluster);
}
return envClusters;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment