Commit 6698804e by lepdou

add miss envs

parent 536eb044
...@@ -27,5 +27,4 @@ public class API { ...@@ -27,5 +27,4 @@ public class API {
public String getAdminServiceHost(Env env) { public String getAdminServiceHost(Env env) {
return serviceLocator.getAdminService(env).getHomepageUrl(); return serviceLocator.getAdminService(env).getHomepageUrl();
} }
} }
...@@ -12,6 +12,7 @@ import com.ctrip.apollo.core.dto.AppDTO; ...@@ -12,6 +12,7 @@ import com.ctrip.apollo.core.dto.AppDTO;
import com.ctrip.apollo.core.enums.Env; import com.ctrip.apollo.core.enums.Env;
import com.ctrip.apollo.core.exception.BadRequestException; import com.ctrip.apollo.core.exception.BadRequestException;
import com.ctrip.apollo.core.utils.StringUtils; import com.ctrip.apollo.core.utils.StringUtils;
import com.ctrip.apollo.portal.entity.AppInfoVO;
import com.ctrip.apollo.portal.entity.ClusterNavTree; import com.ctrip.apollo.portal.entity.ClusterNavTree;
import com.ctrip.apollo.portal.service.AppService; import com.ctrip.apollo.portal.service.AppService;
...@@ -25,7 +26,7 @@ public class AppController { ...@@ -25,7 +26,7 @@ public class AppController {
private AppService appService; private AppService appService;
@RequestMapping("/env/{env}") @RequestMapping("/envs/{env}")
public List<AppDTO> findAllApp(@PathVariable String env){ public List<AppDTO> findAllApp(@PathVariable String env){
if (StringUtils.isEmpty(env)){ if (StringUtils.isEmpty(env)){
throw new BadRequestException("env can not be empty"); throw new BadRequestException("env can not be empty");
...@@ -42,17 +43,21 @@ public class AppController { ...@@ -42,17 +43,21 @@ public class AppController {
return appService.buildClusterNavTree(appId); return appService.buildClusterNavTree(appId);
} }
@RequestMapping(value = "", method = RequestMethod.POST, consumes = {"application/json"}) @RequestMapping(value = "/envs/{env}", method = RequestMethod.POST, consumes = {"application/json"})
public ResponseEntity<Void> create(@RequestBody AppDTO app) { public ResponseEntity<Void> create(@PathVariable String env, @RequestBody AppDTO app) {
if (isInvalidApp(app)){ if (isInvalidApp(app)){
throw new BadRequestException("request payload contains empty"); throw new BadRequestException("request payload contains empty");
} }
appService.save(app); if ("ALL".equals(env)){
appService.save(app);
} else {
appService.save(Env.valueOf(env), app);
}
return ResponseEntity.ok().build(); return ResponseEntity.ok().build();
} }
@RequestMapping(value = "/{appId}", method = RequestMethod.GET) @RequestMapping(value = "/{appId}", method = RequestMethod.GET)
public AppDTO load(@PathVariable String appId){ public AppInfoVO load(@PathVariable String appId){
if (StringUtils.isEmpty(appId)){ if (StringUtils.isEmpty(appId)){
throw new BadRequestException("app id can not be empty."); throw new BadRequestException("app id can not be empty.");
} }
......
package com.ctrip.apollo.portal.entity;
import com.ctrip.apollo.core.dto.AppDTO;
import com.ctrip.apollo.core.enums.Env;
import java.util.List;
public class AppInfoVO {
private AppDTO app;
/**
* 在创建app的时候可能在某些环境下创建失败
*/
private List<Env> missEnvs;
public AppDTO getApp() {
return app;
}
public void setApp(AppDTO app) {
this.app = app;
}
public List<Env> getMissEnvs() {
return missEnvs;
}
public void setMissEnvs(List<Env> missEnvs) {
this.missEnvs = missEnvs;
}
}
package com.ctrip.apollo.portal.service; package com.ctrip.apollo.portal.service;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -17,6 +19,7 @@ import com.ctrip.apollo.core.exception.BadRequestException; ...@@ -17,6 +19,7 @@ import com.ctrip.apollo.core.exception.BadRequestException;
import com.ctrip.apollo.core.exception.ServiceException; import com.ctrip.apollo.core.exception.ServiceException;
import com.ctrip.apollo.portal.PortalSettings; import com.ctrip.apollo.portal.PortalSettings;
import com.ctrip.apollo.portal.api.AdminServiceAPI; import com.ctrip.apollo.portal.api.AdminServiceAPI;
import com.ctrip.apollo.portal.entity.AppInfoVO;
import com.ctrip.apollo.portal.entity.ClusterNavTree; import com.ctrip.apollo.portal.entity.ClusterNavTree;
@Service @Service
...@@ -37,16 +40,19 @@ public class AppService { ...@@ -37,16 +40,19 @@ public class AppService {
return appAPI.findApps(env); return appAPI.findApps(env);
} }
public AppDTO load(String appId) { public AppInfoVO load(String appId) {
//轮询环境直到能找到此app的信息 //轮询环境直到能找到此app的信息
AppDTO app = null; AppDTO app = null;
List<Env> missEnvs = new LinkedList<>();
for (Env env : portalSettings.getEnvs()) { for (Env env : portalSettings.getEnvs()) {
try { try {
app = appAPI.loadApp(env, appId); app = appAPI.loadApp(env, appId);
break;
} catch (HttpClientErrorException e) { } catch (HttpClientErrorException e) {
//not exist maybe because create app fail. //not exist maybe because create app fail.
if (e.getStatusCode() == HttpStatus.NOT_FOUND) { if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
missEnvs.add(env);
logger.warn("app:{} in {} not exist", appId, env); logger.warn("app:{} in {} not exist", appId, env);
} else { } else {
logger.error("load app info({}) from env:{} error.", appId, env); logger.error("load app info({}) from env:{} error.", appId, env);
...@@ -54,11 +60,15 @@ public class AppService { ...@@ -54,11 +60,15 @@ public class AppService {
} }
} }
} }
if (app == null){ if (app == null) {
throw new BadRequestException(String.format("invalid app id %s", appId)); throw new BadRequestException(String.format("invalid app id %s", appId));
} }
return app; AppInfoVO appInfo = new AppInfoVO();
appInfo.setApp(app);
appInfo.setMissEnvs(missEnvs);
return appInfo;
} }
...@@ -86,4 +96,13 @@ public class AppService { ...@@ -86,4 +96,13 @@ public class AppService {
} }
} }
public void save(Env env, AppDTO app) {
try {
appAPI.save(env, app);
} catch (HttpStatusCodeException e) {
logger.error(ExceptionUtils.toString(e));
throw e;
}
}
} }
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
<script type="application/javascript" src="scripts/app.js"></script> <script type="application/javascript" src="scripts/app.js"></script>
<script type="application/javascript" src="scripts/services/AppService.js"></script> <script type="application/javascript" src="scripts/services/AppService.js"></script>
<script type="application/javascript" src="scripts/services/EnvService.js"></script> <script type="application/javascript" src="scripts/services/EnvService.js"></script>
<script type="application/javascript" src="scripts/AppUtils.js"></script>
<script type="application/javascript" src="scripts/controller/IndexController.js"></script> <script type="application/javascript" src="scripts/controller/IndexController.js"></script>
</body> </body>
</html> </html>
appUtil.service('AppUtil', [function () {
return {
errorMsg: function (response) {
var msg = "Code:" + response.status;
if (response.data.message != null){
msg += " Msg:" + response.data.message;
}
return msg;
}
}
}]);
/**service module 定义*/ /**service module 定义*/
var appService = angular.module('app.service', ['ngResource']); var appService = angular.module('app.service', ['ngResource']);
/**utils*/
var appUtil = angular.module('app.util', []);
/** page module 定义*/ /** page module 定义*/
// 首页 // 首页
var index_module = angular.module('index', ['toastr', 'app.service', 'angular-loading-bar']); var index_module = angular.module('index', ['toastr', 'app.service', 'app.util', 'angular-loading-bar']);
//项目主页 //项目主页
var application_module = angular.module('application', ['app.service', 'toastr', 'angular-loading-bar']); var application_module = angular.module('application', ['app.service', 'app.util', 'toastr', 'angular-loading-bar']);
//创建项目页面 //创建项目页面
var create_app_module = angular.module('create_app', ['ngResource', 'toastr', 'app.service', 'angular-loading-bar']); var create_app_module = angular.module('create_app', ['ngResource', 'toastr', 'app.service', 'app.util', 'angular-loading-bar']);
......
create_app_module.controller('CreateAppController', ['$scope', '$window', 'toastr', 'AppService', create_app_module.controller('CreateAppController', ['$scope', '$window', 'toastr', 'AppService', 'AppUtil',
function ($scope, $window, toastr, AppService) { function ($scope, $window, toastr, AppService, AppUtil) {
$scope.save = function () { $scope.create = function () {
AppService.add($scope.app).then(function (result) { AppService.create('ALL', $scope.app).then(function (result) {
toastr.success('添加成功!'); toastr.success('添加成功!');
setInterval(function () { setInterval(function () {
$window.location.href = '/views/app.html?#appid=' + result.appId; $window.location.href = '/views/app.html?#appid=' + result.appId;
}, 1000); }, 1000);
}, function (result) { }, function (result) {
toastr.error(result.status + result.data.message, '添加失败!'); toastr.error(AppUtil.errorMsg(result), '添加失败!');
}); });
}; };
......
index_module.controller('IndexController', ['$scope', '$window', 'toastr', 'AppService', 'EnvService', index_module.controller('IndexController', ['$scope', '$window', 'toastr', 'AppService', 'AppUtil', 'EnvService',
function ($scope, $window, toastr, AppService, EnvService) { function ($scope, $window, toastr, AppService, AppUtil, EnvService) {
$scope.envs = []; $scope.envs = [];
$scope.selectedEnv = ''; $scope.selectedEnv = '';
...@@ -8,7 +8,7 @@ index_module.controller('IndexController', ['$scope', '$window', 'toastr', 'AppS ...@@ -8,7 +8,7 @@ index_module.controller('IndexController', ['$scope', '$window', 'toastr', 'AppS
//default select first env //default select first env
$scope.switchEnv($scope.envs[0]); $scope.switchEnv($scope.envs[0]);
}, function (result) { }, function (result) {
toastr.error(result.status + result.data.message, "load env error"); toastr.error(AppUtil.errorMsg(result), "load env error");
}); });
var apps = []; var apps = [];
...@@ -25,7 +25,7 @@ index_module.controller('IndexController', ['$scope', '$window', 'toastr', 'AppS ...@@ -25,7 +25,7 @@ index_module.controller('IndexController', ['$scope', '$window', 'toastr', 'AppS
$scope.appsCount = apps.length; $scope.appsCount = apps.length;
$scope.selectedEnv = env; $scope.selectedEnv = env;
}, function (result) { }, function (result) {
toastr.error(result.status + result.data.message, "load apps error"); toastr.error(AppUtil.errorMsg(result), "load apps error");
}); });
}; };
......
application_module.controller("AppConfigController", application_module.controller("AppConfigController",
['$scope', '$location', 'toastr', 'AppService', 'ConfigService', ['$scope', '$location', 'toastr', 'AppService', 'AppUtil', 'ConfigService',
function ($scope, $location, toastr, AppService, ConfigService) { function ($scope, $location, toastr, AppService, AppUtil, ConfigService) {
var appId = $location.$$url.split("=")[1]; var appId = $location.$$url.split("=")[1];
var currentUser = 'test_user'; var currentUser = 'test_user';
...@@ -12,7 +12,7 @@ application_module.controller("AppConfigController", ...@@ -12,7 +12,7 @@ application_module.controller("AppConfigController",
$scope.pageContext = pageContext; $scope.pageContext = pageContext;
///////////// load cluster nav tree ///////// ////// load cluster nav tree //////
AppService.load_nav_tree($scope.pageContext.appId).then(function (result) { AppService.load_nav_tree($scope.pageContext.appId).then(function (result) {
var navTree = []; var navTree = [];
...@@ -58,18 +58,20 @@ application_module.controller("AppConfigController", ...@@ -58,18 +58,20 @@ application_module.controller("AppConfigController",
} }
}); });
}, function (result) { }, function (result) {
toastr.error(result.status + result.data.message, "加载导航出错"); toastr.error(AppUtil.errorMsg(result), "加载导航出错");
}); });
/////////// app info //////////// ////// app info //////
AppService.load($scope.pageContext.appId).then(function (result) { AppService.load($scope.pageContext.appId).then(function (result) {
$scope.appInfo = result; $scope.appBaseInfo = result.app;
$scope.missEnvs = result.missEnvs;
$scope.selectedEnvs = angular.copy($scope.missEnvs);
},function (result) { },function (result) {
toastr.error(result.status + result.data.message, "加载App信息出错"); toastr.error(AppUtil.errorMsg(result), "加载App信息出错");
}); });
/////////// namespace //////////// ////// namespace //////
var namespace_view_type = { var namespace_view_type = {
TEXT:'text', TEXT:'text',
...@@ -103,11 +105,11 @@ application_module.controller("AppConfigController", ...@@ -103,11 +105,11 @@ application_module.controller("AppConfigController",
} }
}, function (result) { }, function (result) {
toastr.error(result.status + result.data.message, "加载配置信息出错"); toastr.error(AppUtil.errorMsg(result), "加载配置信息出错");
}); });
} }
////////////global view oper ///////////// ////// global view oper //////
$scope.switchView = function (namespace, viewType) { $scope.switchView = function (namespace, viewType) {
...@@ -138,7 +140,7 @@ application_module.controller("AppConfigController", ...@@ -138,7 +140,7 @@ application_module.controller("AppConfigController",
return result; return result;
} }
////////// text view oper ///////// ////// text view oper //////
$scope.draft = {}; $scope.draft = {};
//保存草稿 //保存草稿
...@@ -161,7 +163,7 @@ application_module.controller("AppConfigController", ...@@ -161,7 +163,7 @@ application_module.controller("AppConfigController",
$scope.toggleTextEditStatus($scope.draft); $scope.toggleTextEditStatus($scope.draft);
}, function (result) { }, function (result) {
toastr.error(result.status + result.data.message, "更新失败"); toastr.error(AppUtil.errorMsg(result), "更新失败");
} }
); );
...@@ -169,6 +171,7 @@ application_module.controller("AppConfigController", ...@@ -169,6 +171,7 @@ application_module.controller("AppConfigController",
$scope.isItemsViewOpened = true; $scope.isItemsViewOpened = true;
$scope.toggleItemView = function (isOpened) { $scope.toggleItemView = function (isOpened) {
$scope.isItemsViewOpened = isOpened; $scope.isItemsViewOpened = isOpened;
}; };
...@@ -185,7 +188,7 @@ application_module.controller("AppConfigController", ...@@ -185,7 +188,7 @@ application_module.controller("AppConfigController",
} }
}; };
////////// table view oper ///////// ////// table view oper //////
//查看旧值 //查看旧值
$scope.queryOldValue = function (key, oldValue) { $scope.queryOldValue = function (key, oldValue) {
...@@ -215,11 +218,47 @@ application_module.controller("AppConfigController", ...@@ -215,11 +218,47 @@ application_module.controller("AppConfigController",
refreshNamespaces(); refreshNamespaces();
}, function (result) { }, function (result) {
toastr.error(result.status + result.data.message, "发布失败"); toastr.error(AppUtil.errorMsg(result), "发布失败");
} }
); );
} }
////// create env //////
$scope.toggleSelection = function toggleSelection(env) {
var idx = $scope.selectedEnvs.indexOf(env);
// is currently selected
if (idx > -1) {
$scope.selectedEnvs.splice(idx, 1);
}
// is newly selected
else {
$scope.selectedEnvs.push(env);
}
};
$scope.createEnvs = function () {
var count = 0;
$scope.selectedEnvs.forEach(function (env) {
AppService.create(env, $scope.appBaseInfo).then(function (result) {
toastr.success(env, '创建成功');
count ++;
if (count == $scope.selectedEnvs){
$route.reload();
}
}, function (result) {
toastr.error(AppUtil.errorMsg(result), '创建失败:' + env);
count ++;
if (count == $scope.selectedEnvs){
$route.reload();
}
});
});
};
}]); }]);
...@@ -3,7 +3,7 @@ appService.service('AppService', ['$resource', '$q', function ($resource, $q) { ...@@ -3,7 +3,7 @@ appService.service('AppService', ['$resource', '$q', function ($resource, $q) {
find_all_app:{ find_all_app:{
method: 'GET', method: 'GET',
isArray: true, isArray: true,
url:'/apps/env/:env' url:'/apps/envs/:env'
}, },
load_navtree:{ load_navtree:{
methode: 'GET', methode: 'GET',
...@@ -14,9 +14,9 @@ appService.service('AppService', ['$resource', '$q', function ($resource, $q) { ...@@ -14,9 +14,9 @@ appService.service('AppService', ['$resource', '$q', function ($resource, $q) {
method: 'GET', method: 'GET',
isArray: false isArray: false
}, },
add_app: { create_app: {
method: 'POST', method: 'POST',
url: '/apps' url: '/apps/envs/:env'
} }
}); });
return { return {
...@@ -42,9 +42,9 @@ appService.service('AppService', ['$resource', '$q', function ($resource, $q) { ...@@ -42,9 +42,9 @@ appService.service('AppService', ['$resource', '$q', function ($resource, $q) {
}); });
return d.promise; return d.promise;
}, },
add: function (app) { create: function (env, app) {
var d = $q.defer(); var d = $q.defer();
app_resource.add_app({}, app, function (result) { app_resource.create_app({env:env}, app, function (result) {
d.resolve(result); d.resolve(result);
}, function (result) { }, function (result) {
d.reject(result); d.reject(result);
......
...@@ -16,6 +16,21 @@ a { ...@@ -16,6 +16,21 @@ a {
cursor: pointer; cursor: pointer;
} }
.i-20{
height: 20px;
width: 20px;
}
.i-25-20{
height: 20px;
width: 25px;
}
.i-15{
height: 15px;
width: 15px;
}
.apollo-container { .apollo-container {
min-height: 90%; min-height: 90%;
} }
...@@ -122,6 +137,12 @@ table th { ...@@ -122,6 +137,12 @@ table th {
font-weight: 300; font-weight: 300;
} }
.project-info th {
text-align: right;
padding: 4px 6px;
white-space: nowrap;
}
.project-info td { .project-info td {
word-wrap: break-word; word-wrap: break-word;
word-break: break-all; word-break: break-all;
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</header> </header>
<div class="panel-body"> <div class="panel-body">
<form class="form-horizontal" ng-controller="CreateAppController" ng-submit="save()"> <form class="form-horizontal" ng-controller="CreateAppController" ng-submit="create()">
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label"><font style="color: red">*</font> 应用ID</label> <label class="col-sm-2 control-label"><font style="color: red">*</font> 应用ID</label>
<div class="col-sm-3"> <div class="col-sm-3">
...@@ -81,6 +81,8 @@ ...@@ -81,6 +81,8 @@
<script type="application/javascript" src="../scripts/app.js"></script> <script type="application/javascript" src="../scripts/app.js"></script>
<script type="application/javascript" src="../scripts/services/AppService.js"></script> <script type="application/javascript" src="../scripts/services/AppService.js"></script>
<script type="application/javascript" src="../scripts/AppUtils.js"></script>
<script type="application/javascript" src="../scripts/controller/CreateAppController.js"></script> <script type="application/javascript" src="../scripts/controller/CreateAppController.js"></script>
</body> </body>
</html> </html>
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