-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,718 additions
and
311 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
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
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
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
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
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 |
---|---|---|
|
@@ -16,21 +16,17 @@ | |
*/ | ||
package com.ctrip.framework.apollo.portal.controller; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.common.base.Splitter; | ||
|
||
import com.ctrip.framework.apollo.common.exception.ServiceException; | ||
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; | ||
import com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO; | ||
import com.ctrip.framework.apollo.portal.environment.Env; | ||
import com.ctrip.framework.apollo.portal.service.ConfigsExportService; | ||
import com.ctrip.framework.apollo.portal.service.NamespaceService; | ||
import com.ctrip.framework.apollo.portal.util.NamespaceBOUtils; | ||
import com.google.common.base.Joiner; | ||
import com.google.common.base.Splitter; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.Date; | ||
import java.util.List; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.apache.commons.lang.time.DateFormatUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -39,15 +35,26 @@ | |
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* jian.tan | ||
*/ | ||
@RestController | ||
public class ConfigsExportController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ConfigsExportController.class); | ||
private static final Logger logger = LoggerFactory.getLogger(ConfigsExportController.class); | ||
private static final String ENV_SEPARATOR = ","; | ||
|
||
private final ConfigsExportService configsExportService; | ||
|
||
|
@@ -74,12 +81,17 @@ public ConfigsExportController( | |
@PreAuthorize(value = "[email protected](#appId, #env, #namespaceName)") | ||
@GetMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items/export") | ||
public void exportItems(@PathVariable String appId, @PathVariable String env, | ||
@PathVariable String clusterName, @PathVariable String namespaceName, | ||
HttpServletResponse res) { | ||
@PathVariable String clusterName, @PathVariable String namespaceName, | ||
HttpServletResponse res) { | ||
List<String> fileNameSplit = Splitter.on(".").splitToList(namespaceName); | ||
|
||
String fileName = fileNameSplit.size() <= 1 ? Joiner.on(".") | ||
.join(namespaceName, ConfigFileFormat.Properties.getValue()) : namespaceName; | ||
String fileName = namespaceName; | ||
|
||
//properties file or public namespace has not suffix (.properties) | ||
if (fileNameSplit.size() <= 1 || !ConfigFileFormat.isValidFormat(fileNameSplit.get(fileNameSplit.size() - 1))) { | ||
fileName = Joiner.on(".").join(namespaceName, ConfigFileFormat.Properties.getValue()); | ||
} | ||
|
||
NamespaceBO namespaceBO = namespaceService.loadNamespaceBO(appId, Env.valueOf | ||
(env), clusterName, namespaceName); | ||
|
||
|
@@ -96,21 +108,26 @@ public void exportItems(@PathVariable String appId, @PathVariable String env, | |
} | ||
|
||
/** | ||
* Export all configs in a compressed file. | ||
* Just export namespace which current exists read permission. | ||
* The permission check in service. | ||
* Export all configs in a compressed file. Just export namespace which current exists read permission. The permission | ||
* check in service. | ||
*/ | ||
@GetMapping("/export") | ||
public void exportAll(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
@GetMapping("/configs/export") | ||
public void exportAll(@RequestParam(value = "envs") String envs, | ||
HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
// filename must contain the information of time | ||
final String filename = "apollo_config_export_" + DateFormatUtils.format(new Date(), "yyyy_MMdd_HH_mm_ss") + ".zip"; | ||
// log who download the configs | ||
logger.info("Download configs, remote addr [{}], remote host [{}]. Filename is [{}]", request.getRemoteAddr(), request.getRemoteHost(), filename); | ||
logger.info("Download configs, remote addr [{}], remote host [{}]. Filename is [{}]", request.getRemoteAddr(), | ||
request.getRemoteHost(), filename); | ||
// set downloaded filename | ||
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + filename); | ||
|
||
List<Env> | ||
exportEnvs = | ||
Splitter.on(ENV_SEPARATOR).splitToList(envs).stream().map(env -> Env.valueOf(env)).collect(Collectors.toList()); | ||
|
||
try (OutputStream outputStream = response.getOutputStream()) { | ||
configsExportService.exportAllTo(outputStream); | ||
configsExportService.exportData(outputStream, exportEnvs); | ||
} | ||
} | ||
|
||
|
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
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
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
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
Oops, something went wrong.