use of com.ctrip.framework.apollo.portal.environment.Env in project apollo by ctripcorp.
the class ConfigsExportController method exportAll.
/**
* Export all configs in a compressed file. Just export namespace which current exists read permission. The permission
* check in service.
*/
@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);
// 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.exportData(outputStream, exportEnvs);
}
}
use of com.ctrip.framework.apollo.portal.environment.Env in project apollo by ctripcorp.
the class ItemController method update.
@PutMapping(value = "/apps/{appId}/namespaces/{namespaceName}/items", consumes = { "application/json" })
public ResponseEntity<Void> update(@PathVariable String appId, @PathVariable String namespaceName, @RequestBody NamespaceSyncModel model) {
checkModel(!model.isInvalid());
boolean hasPermission = permissionValidator.hasModifyNamespacePermission(appId, namespaceName);
Env envNoPermission = null;
// if uses has ModifyNamespace permission then he has permission
if (!hasPermission) {
// else check if user has every env's ModifyNamespace permission
hasPermission = true;
for (NamespaceIdentifier namespaceIdentifier : model.getSyncToNamespaces()) {
// once user has not one of the env's ModifyNamespace permission, then break the loop
hasPermission &= permissionValidator.hasModifyNamespacePermission(namespaceIdentifier.getAppId(), namespaceIdentifier.getNamespaceName(), namespaceIdentifier.getEnv().toString());
if (!hasPermission) {
envNoPermission = namespaceIdentifier.getEnv();
break;
}
}
}
if (hasPermission) {
configService.syncItems(model.getSyncToNamespaces(), model.getSyncItems());
return ResponseEntity.status(HttpStatus.OK).build();
}
throw new AccessDeniedException(String.format("You don't have the permission to modify environment: %s", envNoPermission));
}
use of com.ctrip.framework.apollo.portal.environment.Env in project apollo by ctripcorp.
the class PortalSettings method postConstruct.
@PostConstruct
private void postConstruct() {
allEnvs = portalConfig.portalSupportedEnvs();
for (Env env : allEnvs) {
envStatusMark.put(env, true);
}
ScheduledExecutorService healthCheckService = Executors.newScheduledThreadPool(1, ApolloThreadFactory.create("EnvHealthChecker", true));
healthCheckService.scheduleWithFixedDelay(new HealthCheckTask(applicationContext), 1000, HEALTH_CHECK_INTERVAL, TimeUnit.MILLISECONDS);
}
use of com.ctrip.framework.apollo.portal.environment.Env in project apollo by ctripcorp.
the class SearchController method searchByItem.
private PageDTO<App> searchByItem(String itemKey, Pageable pageable) {
List<App> result = Lists.newLinkedList();
if (StringUtils.isEmpty(itemKey)) {
return new PageDTO<>(result, pageable, 0);
}
// use the env witch has the most namespace as page index.
final AtomicLong maxTotal = new AtomicLong(0);
List<Env> activeEnvs = portalSettings.getActiveEnvs();
activeEnvs.forEach(env -> {
PageDTO<NamespaceDTO> namespacePage = namespaceService.findNamespacesByItem(env, itemKey, pageable);
if (!namespacePage.hasContent()) {
return;
}
long currentEnvNSTotal = namespacePage.getTotal();
if (currentEnvNSTotal > maxTotal.get()) {
maxTotal.set(namespacePage.getTotal());
}
List<NamespaceDTO> namespaceDTOS = namespacePage.getContent();
namespaceDTOS.forEach(namespaceDTO -> {
String cluster = namespaceDTO.getClusterName();
String namespaceName = namespaceDTO.getNamespaceName();
App app = new App();
app.setAppId(namespaceDTO.getAppId());
app.setName(env.getName() + " / " + cluster + " / " + namespaceName);
app.setOrgId(env.getName() + "+" + cluster + "+" + namespaceName);
app.setOrgName("SearchByItem" + "+" + itemKey);
result.add(app);
});
});
return new PageDTO<>(result, pageable, maxTotal.get());
}
use of com.ctrip.framework.apollo.portal.environment.Env in project apollo by ctripcorp.
the class ServerAppOpenApiService method getEnvClusterInfo.
@Override
public List<OpenEnvClusterDTO> getEnvClusterInfo(String appId) {
List<OpenEnvClusterDTO> envClusters = new LinkedList<>();
List<Env> envs = portalSettings.getActiveEnvs();
for (Env env : envs) {
OpenEnvClusterDTO envCluster = new OpenEnvClusterDTO();
envCluster.setEnv(env.getName());
List<ClusterDTO> clusterDTOs = clusterService.findClusters(env, appId);
envCluster.setClusters(BeanUtils.toPropertySet("name", clusterDTOs));
envClusters.add(envCluster);
}
return envClusters;
}
Aggregations