diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalSettings.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalSettings.java index d30427735835fb98567beea9e48a4b340d71e26a..b1238e74cb18b28fc7dddeb1c2612c194a8a6b07 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalSettings.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalSettings.java @@ -1,6 +1,5 @@ package com.ctrip.framework.apollo.portal; -import com.google.common.collect.Lists; import java.util.ArrayList; import java.util.Arrays; @@ -58,8 +57,7 @@ public class PortalSettings { //初始化portal支持操作的环境集合,线上的portal可能支持所有的环境操作,而线下环境则支持一部分. // 每个环境的portal支持哪些环境配置在数据库里 ServerConfig serverConfig = serverConfigRepository.findByKey("apollo.portal.envs"); - // TODO: 16/5/24 线上环境暂时从本地配置里拿,之后也放在数据库上并提供界面可操作 - if (serverConfig != null){//如果db有配置则从db里取 + if (serverConfig != null){ String[] configedEnvs = serverConfig.getValue().split(","); allStrEnvs = Arrays.asList(configedEnvs); } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PortalServerConfigController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PortalServerConfigController.java new file mode 100644 index 0000000000000000000000000000000000000000..cb1922e252311b2f2b57d4c9c786cc105e494f21 --- /dev/null +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PortalServerConfigController.java @@ -0,0 +1,51 @@ +package com.ctrip.framework.apollo.portal.controller; + + +import com.ctrip.framework.apollo.common.utils.BeanUtils; +import com.ctrip.framework.apollo.core.exception.BadRequestException; +import com.ctrip.framework.apollo.core.utils.StringUtils; +import com.ctrip.framework.apollo.portal.entity.po.ServerConfig; +import com.ctrip.framework.apollo.portal.repository.ServerConfigRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +/** + * 配置中心本身需要一些配置,这些配置放在数据库里面 + */ +@RestController +public class PortalServerConfigController { + + @Autowired + private ServerConfigRepository serverConfigRepository; + + @RequestMapping(value = "/server/config", method = RequestMethod.POST) + public ServerConfig createOrUpdate(@RequestBody ServerConfig serverConfig) { + + if (serverConfig == null || StringUtils.isContainEmpty(serverConfig.getKey(), serverConfig.getValue())) { + throw new BadRequestException("request payload contains empty"); + } + + // TODO: 16/6/2 接入sso之后改成当前登录用户 + String modifiedBy = "admin"; + + ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey()); + + if (storedConfig == null) {//create + serverConfig.setDataChangeCreatedBy(modifiedBy); + serverConfig.setDataChangeLastModifiedBy(modifiedBy); + return serverConfigRepository.save(serverConfig); + } else {//update + BeanUtils.copyEntityProperties(serverConfig, storedConfig); + storedConfig.setDataChangeLastModifiedBy(modifiedBy); + return serverConfigRepository.save(storedConfig); + } + + + } + + +} diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/ServerConfigRepository.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/ServerConfigRepository.java index 8ac30f366c7e5fd833e4c87b450f97be1b7e529d..a32a34bfc5071cb0bd7607c9f0a7b0d8cc4f382f 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/ServerConfigRepository.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/ServerConfigRepository.java @@ -5,9 +5,6 @@ import com.ctrip.framework.apollo.portal.entity.po.ServerConfig; import org.springframework.data.repository.PagingAndSortingRepository; -/** - * @author Jason Song(song_s@ctrip.com) - */ public interface ServerConfigRepository extends PagingAndSortingRepository { ServerConfig findByKey(String key); } diff --git a/apollo-portal/src/main/resources/static/scripts/app.js b/apollo-portal/src/main/resources/static/scripts/app.js index 2b3227f015393e85f3cd31597b9a55ac14b1173e..1e74dfdc589a4be25fe03b2c1d76b58fcf2fbc4c 100644 --- a/apollo-portal/src/main/resources/static/scripts/app.js +++ b/apollo-portal/src/main/resources/static/scripts/app.js @@ -13,12 +13,13 @@ var index_module = angular.module('index', ['toastr', 'app.service', 'app.util', //项目主页 var application_module = angular.module('application', ['app.service', 'apollo.directive', 'app.util', 'toastr', 'angular-loading-bar']); //创建项目页面 -var create_app_module = angular.module('create_app', ['ngResource', 'apollo.directive', 'toastr', 'app.service', 'app.util', 'angular-loading-bar']); +var create_app_module = angular.module('create_app', ['apollo.directive', 'toastr', 'app.service', 'app.util', 'angular-loading-bar']); //配置同步页面 var sync_item_module = angular.module('sync_item', ['app.service', 'apollo.directive', 'app.util', 'toastr', 'angular-loading-bar']); //namespace var namespace_module = angular.module('namespace', ['app.service', 'apollo.directive', 'app.util', 'toastr', 'angular-loading-bar']); - +//server config +var server_config_module = angular.module('server_config', ['app.service', 'apollo.directive', 'app.util', 'toastr', 'angular-loading-bar']); diff --git a/apollo-portal/src/main/resources/static/scripts/controller/ServerConfigController.js b/apollo-portal/src/main/resources/static/scripts/controller/ServerConfigController.js new file mode 100644 index 0000000000000000000000000000000000000000..f7699c961d2994567de0a0f14988efd78b71e702 --- /dev/null +++ b/apollo-portal/src/main/resources/static/scripts/controller/ServerConfigController.js @@ -0,0 +1,15 @@ +server_config_module.controller('ServerConfigController', + ['$scope', '$window', 'toastr', 'ServerConfigService', 'AppUtil', + function ($scope, $window, toastr, ServerConfigService, AppUtil) { + + $scope.serverConfig = {}; + + $scope.create = function () { + ServerConfigService.create($scope.serverConfig).then(function (result) { + toastr.success("添加成功"); + }, function (result) { + toastr.error(AppUtil.errorMsg(result), "添加失败"); + }); + }; + + }]); diff --git a/apollo-portal/src/main/resources/static/scripts/services/ServerConfigService.js b/apollo-portal/src/main/resources/static/scripts/services/ServerConfigService.js new file mode 100644 index 0000000000000000000000000000000000000000..d43f93d497e5182c47eac8b3929807b94c2083a7 --- /dev/null +++ b/apollo-portal/src/main/resources/static/scripts/services/ServerConfigService.js @@ -0,0 +1,19 @@ +appService.service('ServerConfigService', ['$resource', '$q', function ($resource, $q) { + var server_config_resource = $resource('', {}, { + create_server_config: { + method: 'POST', + url:'/server/config' + } + }); + return { + create: function (serverConfig) { + var d = $q.defer(); + server_config_resource.create_server_config({}, serverConfig, function (result) { + d.resolve(result); + }, function (result) { + d.reject(result); + }); + return d.promise; + } + } +}]); diff --git a/apollo-portal/src/main/resources/static/server_config.html b/apollo-portal/src/main/resources/static/server_config.html new file mode 100644 index 0000000000000000000000000000000000000000..42b8d3d8a3da404271b30dc3d73d348717ea9625 --- /dev/null +++ b/apollo-portal/src/main/resources/static/server_config.html @@ -0,0 +1,90 @@ + + + + + + + + + + 应用配置 + + + + + +
+ +
+
+
+
+ 应用配置 +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+ + +
+
+
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +