提交 fed39e80 编写于 作者: Y Yiming Liu

Merge pull request #120 from lepdou/lepdou_master

commit log service & create app 表单优化
package com.ctrip.apollo.biz.entity;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "commit")
@SQLDelete(sql = "Update commit set isDeleted = 1 where id = ?")
@Where(clause = "isDeleted = 0")
public class Commit extends BaseEntity{
@Column(name = "ChangeSets", nullable = false)
private String changeSets;
@Column(name = "AppId", nullable = false)
private String appId;
@Column(name = "ClusterName", nullable = false)
private String clusterName;
@Column(name = "NamespaceName", nullable = false)
private String namespaceName;
@Column(name = "Comment")
private String comment;
public String getChangeSets() {
return changeSets;
}
public void setChangeSets(String changeSets) {
this.changeSets = changeSets;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public String getNamespaceName() {
return namespaceName;
}
public void setNamespaceName(String namespaceName) {
this.namespaceName = namespaceName;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
@Override
public String toString() {
return toStringHelper().add("changeSets", changeSets).add("appId", appId).add("clusterName", clusterName)
.add("namespaceName", namespaceName).add("comment", comment).toString();
}
}
package com.ctrip.apollo.biz.repository;
import com.ctrip.apollo.biz.entity.Commit;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface CommitRepository extends PagingAndSortingRepository<Commit, Long> {
List<Commit> findByAppIdAndClusterNameAndNamespaceName(String appId, String clusterName,
String namespaceName);
}
package com.ctrip.apollo.biz.service;
import com.ctrip.apollo.biz.entity.Commit;
import com.ctrip.apollo.biz.repository.CommitRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service
public class CommitService {
@Autowired
private CommitRepository commitRepository;
public void save(Commit commit, String user){
commit.setDataChangeCreatedBy(user);
commit.setDataChangeCreatedTime(new Date());
commitRepository.save(commit);
}
}
......@@ -11,6 +11,8 @@ import com.ctrip.apollo.common.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ItemChangeSets;
import com.ctrip.apollo.core.dto.ItemDTO;
import java.util.Date;
@Service
public class ItemSetService {
......@@ -25,6 +27,7 @@ public class ItemSetService {
if (changeSet.getCreateItems() != null) {
for (ItemDTO item : changeSet.getCreateItems()) {
Item entity = BeanUtils.transfrom(Item.class, item);
entity.setDataChangeCreatedTime(new Date());
entity.setDataChangeCreatedBy(owner);
entity.setDataChangeLastModifiedBy(owner);
itemRepository.save(entity);
......
package com.ctrip.apollo.core.dto;
import com.ctrip.apollo.core.enums.Env;
import java.util.LinkedList;
import java.util.List;
public class AppConfigVO {
private String appId;
private Env env;
/**
* latest version if version is zero, or is release version
*/
private long versionId;
/**
* default cluster and app self’s configs
*/
private List<ItemDTO> defaultClusterConfigs;
/**
* default cluster and override other app configs
*/
private List<OverrideAppConfig> overrideAppConfigs;
/**
* configs in different cluster maybe different.
* overrideClusterConfigs only save diff configs from default cluster.
* For example:
* default cluster has 3 configs:
* {a -> A, b -> B, c -> C}
*
* cluster1 has 1 config
* {b -> D}
*
* if client read cluster1 configs will return {a -> A, b -> D, c -> C}
*/
private List<OverrideClusterConfig> overrideClusterConfigs;
public AppConfigVO() {
}
public static AppConfigVO newInstance(String appId, long versionId) {
AppConfigVO instance = new AppConfigVO();
instance.setAppId(appId);
instance.setVersionId(versionId);
instance.setDefaultClusterConfigs(new LinkedList<>());
instance.setOverrideAppConfigs(new LinkedList<>());
instance.setOverrideClusterConfigs(new LinkedList<>());
return instance;
}
public boolean isLatestVersion() {
return versionId == 0;
}
public static class OverrideAppConfig {
private String appId;
private List<ItemDTO> configs;
public OverrideAppConfig() {
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public List<ItemDTO> getConfigs() {
return configs;
}
public void setConfigs(List<ItemDTO> configs) {
this.configs = configs;
}
public void addConfig(ItemDTO config) {
if (configs == null) {
configs = new LinkedList<>();
}
configs.add(config);
}
}
public static class OverrideClusterConfig {
private String clusterName;
private List<ItemDTO> configs;
public OverrideClusterConfig() {
}
public String getClusterName() {
return clusterName;
}
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public List<ItemDTO> getConfigs() {
return configs;
}
public void setConfigs(List<ItemDTO> configs) {
this.configs = configs;
}
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public Env getEnv() {
return env;
}
public void setEnv(Env env) {
this.env = env;
}
public long getVersionId() {
return versionId;
}
public void setVersionId(long versionId) {
this.versionId = versionId;
}
public List<ItemDTO> getDefaultClusterConfigs() {
return defaultClusterConfigs;
}
public void setDefaultClusterConfigs(List<ItemDTO> defaultClusterConfigs) {
this.defaultClusterConfigs = defaultClusterConfigs;
}
public List<OverrideAppConfig> getOverrideAppConfigs() {
return overrideAppConfigs;
}
public void setOverrideAppConfigs(List<OverrideAppConfig> overrideAppConfigs) {
this.overrideAppConfigs = overrideAppConfigs;
}
public List<OverrideClusterConfig> getOverrideClusterConfigs() {
return overrideClusterConfigs;
}
public void setOverrideClusterConfigs(List<OverrideClusterConfig> overrideClusterConfigs) {
this.overrideClusterConfigs = overrideClusterConfigs;
}
@Override
public String toString() {
return "Config4PortalDTO{" +
"appId=" + appId +
", env=" + env +
", versionId=" + versionId +
", defaultClusterConfigs=" + defaultClusterConfigs +
", overrideAppConfigs=" + overrideAppConfigs +
", overrideClusterConfigs=" + overrideClusterConfigs +
'}';
}
}
package com.ctrip.apollo.core.dto;
import java.util.Date;
public class AppDTO {
private long id;
private String name;
private String appId;
......@@ -14,20 +12,18 @@ public class AppDTO {
private String ownerEmail;
private String dataChangeCreatedBy;
private Date dataChangeCreatedTime;
public long getId() {
return id;
}
private String dataChangeLastModifiedBy;
public void setId(long id) {
this.id = id;
}
public String getAppId() {
return appId;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
......@@ -44,10 +40,6 @@ public class AppDTO {
this.appId = appId;
}
public void setId(long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
......@@ -60,27 +52,4 @@ public class AppDTO {
this.ownerName = ownerName;
}
public String getDataChangeCreatedBy() {
return dataChangeCreatedBy;
}
public void setDataChangeCreatedBy(String dataChangeCreatedBy) {
this.dataChangeCreatedBy = dataChangeCreatedBy;
}
public Date getDataChangeCreatedTime() {
return dataChangeCreatedTime;
}
public void setDataChangeCreatedTime(Date dataChangeCreatedTime) {
this.dataChangeCreatedTime = dataChangeCreatedTime;
}
public String getDataChangeLastModifiedBy() {
return dataChangeLastModifiedBy;
}
public void setDataChangeLastModifiedBy(String dataChangeLastModifiedBy) {
this.dataChangeLastModifiedBy = dataChangeLastModifiedBy;
}
}
......@@ -24,6 +24,10 @@ public class ItemChangeSets {
deleteItems.add(item);
}
public boolean isEmpty(){
return createItems.isEmpty() && updateItems.isEmpty() && deleteItems.isEmpty();
}
public List<ItemDTO> getCreateItems() {
return createItems;
}
......
package com.ctrip.apollo.core.dto;
import java.util.Date;
public class ItemDTO{
public class ItemDTO {
private long id;
......@@ -16,14 +14,6 @@ public class ItemDTO{
private int lineNum;
private String dataChangeCreatedBy;
private Date dataChangeCreatedTime;
private String dataChangeLastModifiedBy;
private Date dataChangeLastModifiedTime;
public ItemDTO() {
}
......@@ -35,14 +25,18 @@ public class ItemDTO{
this.lineNum = lineNum;
}
public String getComment() {
return comment;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getComment() {
return comment;
}
public String getKey() {
return key;
}
......@@ -59,10 +53,6 @@ public class ItemDTO{
this.comment = comment;
}
public void setId(long id) {
this.id = id;
}
public void setKey(String key) {
this.key = key;
}
......@@ -83,37 +73,6 @@ public class ItemDTO{
this.lineNum = lineNum;
}
public String getDataChangeLastModifiedBy() {
return dataChangeLastModifiedBy;
}
public void setDataChangeLastModifiedBy(String dataChangeLastModifiedBy) {
this.dataChangeLastModifiedBy = dataChangeLastModifiedBy;
}
public Date getDataChangeLastModifiedTime() {
return dataChangeLastModifiedTime;
}
public void setDataChangeLastModifiedTime(Date dataChangeLastModifiedTime) {
this.dataChangeLastModifiedTime = dataChangeLastModifiedTime;
}
public String getDataChangeCreatedBy() {
return dataChangeCreatedBy;
}
public void setDataChangeCreatedBy(String dataChangeCreatedBy) {
this.dataChangeCreatedBy = dataChangeCreatedBy;
}
public Date getDataChangeCreatedTime() {
return dataChangeCreatedTime;
}
public void setDataChangeCreatedTime(Date dataChangeCreatedTime) {
this.dataChangeCreatedTime = dataChangeCreatedTime;
}
@Override
public String toString() {
......@@ -124,10 +83,6 @@ public class ItemDTO{
", value='" + value + '\'' +
", comment='" + comment + '\'' +
", lineNum=" + lineNum +
", dataChangeCreatedBy='" + dataChangeCreatedBy + '\'' +
", dataChangeCreatedTime=" + dataChangeCreatedTime +
", dataChangeLastModifiedBy='" + dataChangeLastModifiedBy + '\'' +
", dataChangeLastModifiedTime=" + dataChangeLastModifiedTime +
'}';
}
}
package com.ctrip.apollo.core.dto;
public class NamespaceDTO {
public class NamespaceDTO{
private long id;
private String appId;
private String clusterName;
private String namespaceName;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getAppId() {
return appId;
}
......@@ -18,10 +25,6 @@ public class NamespaceDTO {
return clusterName;
}
public long getId() {
return id;
}
public String getNamespaceName() {
return namespaceName;
}
......@@ -34,10 +37,6 @@ public class NamespaceDTO {
this.clusterName = clusterName;
}
public void setId(long id) {
this.id = id;
}
public void setNamespaceName(String namespaceName) {
this.namespaceName = namespaceName;
}
......
package com.ctrip.apollo.core.dto;
public class ReleaseDTO {
public class ReleaseDTO{
private long id;
private String name;
......@@ -16,6 +15,14 @@ public class ReleaseDTO {
private String comment;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getAppId() {
return appId;
}
......@@ -32,10 +39,6 @@ public class ReleaseDTO {
return configurations;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
......@@ -60,10 +63,6 @@ public class ReleaseDTO {
this.configurations = configurations;
}
public void setId(long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
......
......@@ -157,15 +157,15 @@ public class AdminServiceAPI {
HttpEntity<MultiValueMap<String, String>> entity =
new HttpEntity<MultiValueMap<String, String>>(parameters, null);
ResponseEntity<ReleaseDTO> response = restTemplate.postForEntity(getAdminServiceHost(env) + String.
format("apps/%s/clusters/%s/namespaces/%s/releases", appId, clusterName, namespace),
entity, ReleaseDTO.class);
format("apps/%s/clusters/%s/namespaces/%s/releases", appId, clusterName, namespace),
entity, ReleaseDTO.class);
if (response != null && response.getStatusCode() == HttpStatus.OK){
return response.getBody();
}else {
logger.error("createRelease fail.id:{}, env:{}, clusterName:{}, namespace:{},releaseBy{}",
appId, env, clusterName, namespace, releaseBy);
throw new ServiceException("call create createRelease api error.");
throw new ServiceException(" call create createRelease api error.");
}
}
}
......
......@@ -13,6 +13,7 @@ public class NamespaceTextModel implements FormModel{
private int namespaceId;
private String configText;
private String modifyBy;
private String comment;
@Override
public boolean isInvalid(){
......@@ -73,4 +74,12 @@ public class NamespaceTextModel implements FormModel{
public void setModifyBy(String modifyBy) {
this.modifyBy = modifyBy;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}
......@@ -146,22 +146,19 @@ public class ConfigService {
ItemChangeSets changeSets = resolver.resolve(namespaceId, configText,
itemAPI.findItems(appId, env, clusterName, namespaceName));
if (changeSets.isEmpty()){
return;
}
try {
enrichChangeSetBaseInfo(changeSets);
itemAPI.updateItems(appId, env, clusterName, namespaceName, changeSets);
} catch (Exception e) {
logger.error("itemAPI.updateItems error. appId{},env:{},clusterName:{},namespaceName:{}", appId, env, clusterName,
namespaceName);
throw new ServiceException("oops! call admin service config error. ");
throw new ServiceException(e.getMessage());
}
}
private void enrichChangeSetBaseInfo(ItemChangeSets changeSets) {
for (ItemDTO item : changeSets.getCreateItems()) {
item.setDataChangeCreatedTime(new Date());
}
}
/**
* createRelease config items
......
......@@ -8,11 +8,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
$window.location.href = '/views/app.html?#appid=' + result.appId;
}, 1000);
}, function (result) {
if (result.status == 400){
toastr.error('params error','添加失败!');
}else {
toastr.error('server error','添加失败!');
}
toastr.error(result.status + result.data.message, '添加失败!');
});
};
......
......@@ -3,7 +3,7 @@ application_module.controller("AppConfigController",
function ($scope, $location, toastr, AppService, ConfigService) {
var appId = $location.$$url.split("=")[1];
var currentUser = 'lepdou';
var currentUser = 'test_user';
var pageContext = {
appId: appId,
env: 'LOCAL',
......@@ -49,7 +49,7 @@ application_module.controller("AppConfigController",
}
});
}, function (result) {
toastr.error("加载导航出错:" + result);
toastr.error(result.status + result.data.message, "加载导航出错");
});
/////////// namespace ////////////
......@@ -84,7 +84,7 @@ application_module.controller("AppConfigController",
}
}, function (result) {
toastr.error("加载配置信息出错");
toastr.error(result.status + result.data.message, "加载配置信息出错");
});
}
......@@ -127,11 +127,12 @@ application_module.controller("AppConfigController",
$scope.draft = namespace;
};
$scope.commitComment = '';
//更新配置
$scope.commitChange = function () {
ConfigService.modify_items($scope.pageContext.appId, $scope.pageContext.env, $scope.pageContext.clusterName,
$scope.draft.namespace.namespaceName, $scope.draft.text,
$scope.draft.namespace.id, 'lepdou').then(
$scope.draft.namespace.id, $scope.commitComment, currentUser).then(
function (result) {
toastr.success("更新成功");
//refresh all namespace items
......@@ -141,7 +142,7 @@ application_module.controller("AppConfigController",
$scope.toggleTextEditStatus($scope.draft);
}, function (result) {
toastr.error(result.data.message, "更新失败");
toastr.error(result.status + result.data.message, "更新失败");
}
);
......@@ -189,7 +190,7 @@ application_module.controller("AppConfigController",
refreshNamespaces();
}, function (result) {
toastr.error(result.data.message, "发布失败");
toastr.error(result.status + result.data.message, "发布失败");
}
);
......
......@@ -30,7 +30,7 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
return d.promise;
},
modify_items: function (appId, env, clusterName, namespaceName, configText, namespaceId, modifyBy) {
modify_items: function (appId, env, clusterName, namespaceName, configText, namespaceId, comment, modifyBy) {
var d = $q.defer();
config_source.modify_items({
appId: appId,
......@@ -41,6 +41,7 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
{
configText: configText,
namespaceId: namespaceId,
comment:comment,
modifyBy: modifyBy
}, function (result) {
d.resolve(result);
......
......@@ -241,7 +241,7 @@
<h4 class="modal-title" id="myModalLabel2">Commit changes</h4>
</div>
<div class="modal-body">
<textarea rows="4" class="form-control" style="width:570px;" placeholder="input change log...."></textarea>
<textarea rows="4" class="form-control" style="width:570px;" placeholder="input change log...." ng-model="commitComment"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal" ng-click="commitChange()">提交</button>
......
......@@ -38,17 +38,16 @@
<input type="text" class="form-control" name="appName" ng-model="app.name" required>
</div>
</div>
<!--接入sso之后将会去除-->
<div class="form-group">
<label class="col-sm-2 control-label">Owner</label>
<label class="col-sm-2 control-label"><font style="color: red">*</font>应用Owner</label>
<div class="col-sm-3">
<input type="text" class="form-control" name="appOwner" ng-model="app.ownerName">
<input type="text" class="form-control" name="appOwner" ng-model="app.ownerName" required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"> 邮箱地址</label>
<label class="col-sm-2 control-label"><font style="color: red">*</font>邮箱地址</label>
<div class="col-sm-4">
<input type="email" class="form-control" ng-model="app.ownerEmail">
<input type="email" class="form-control" ng-model="app.ownerEmail" required>
</div>
</div>
......
......@@ -5,7 +5,6 @@ import com.ctrip.apollo.core.dto.ItemDTO;
import com.ctrip.apollo.core.dto.NamespaceDTO;
import com.ctrip.apollo.core.dto.ReleaseDTO;
import com.ctrip.apollo.core.enums.Env;
import com.ctrip.apollo.core.exception.ServiceException;
import com.ctrip.apollo.portal.api.AdminServiceAPI;
import com.ctrip.apollo.portal.entity.NamespaceVO;
import com.ctrip.apollo.portal.entity.form.NamespaceTextModel;
......@@ -101,22 +100,18 @@ public class ConfigServiceTest extends AbstractPortalTest{
model.setNamespaceName(namespaceName);
model.setClusterName(clusterName);
model.setAppId(appId);
model.setConfigText("a=b\nb=c\nc=d");
model.setConfigText("a=b\nb=c\nc=d\nd=e");
List<ItemDTO> itemDTOs = mockBaseItemHas3Key();
ItemChangeSets changeSets = new ItemChangeSets();
changeSets.addCreateItem(new ItemDTO("d", "c", "", 4));
when(itemAPI.findItems(appId, Env.DEV, clusterName, namespaceName)).thenReturn(itemDTOs);
when(resolver.resolve(0, model.getConfigText(), itemDTOs)).thenReturn(changeSets);
try {
// 调用itemAPI.updateConfig 会抛出ServiceException.
// itemAPI.updateConfig ut 放在admin service.
// 所以只要在调用itemAPI.updateConfig前全部通过,此ut应该通过.
configService.updateConfigItemByText(model);
}catch (Exception e){
Assert.assertTrue(e instanceof ServiceException);
Assert.fail();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册