Commit 05fb4738 by lepdou

update item call new api

parent 66ca68f3
...@@ -101,13 +101,19 @@ public class AdminServiceAPI { ...@@ -101,13 +101,19 @@ public class AdminServiceAPI {
return Arrays.asList(itemDTOs); return Arrays.asList(itemDTOs);
} }
public void updateItems(String appId, Env env, String clusterName, String namespace, public void updateItemsByChangeSet(String appId, Env env, String clusterName, String namespace,
ItemChangeSets changeSets) { ItemChangeSets changeSets) {
restTemplate.postForEntity("{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset", restTemplate.postForEntity("{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset",
changeSets, Void.class, getAdminServiceHost(env), appId, clusterName, namespace); changeSets, Void.class, getAdminServiceHost(env), appId, clusterName, namespace);
} }
public ItemDTO createOrUpdateItem(String appId, Env env, String clusterName, String namespace, ItemDTO item) { public void updateItem(String appId, Env env, String clusterName, String namespace, ItemDTO item) {
restTemplate.put("{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items",
item, getAdminServiceHost(env), appId, clusterName, namespace);
}
public ItemDTO createItem(String appId, Env env, String clusterName, String namespace, ItemDTO item) {
return restTemplate.postForEntity("{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items", return restTemplate.postForEntity("{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items",
item, ItemDTO.class, getAdminServiceHost(env), appId, clusterName, namespace) item, ItemDTO.class, getAdminServiceHost(env), appId, clusterName, namespace)
.getBody(); .getBody();
......
...@@ -61,17 +61,17 @@ public class ConfigController { ...@@ -61,17 +61,17 @@ public class ConfigController {
@RequestBody ItemDTO item){ @RequestBody ItemDTO item){
checkModel(isValidItem(item)); checkModel(isValidItem(item));
return configService.createOrUpdateItem(appId, Env.valueOf(env), clusterName, namespaceName, item); return configService.createItem(appId, Env.valueOf(env), clusterName, namespaceName, item);
} }
@PreAuthorize(value = "@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName)") @PreAuthorize(value = "@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName)")
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/item", method = RequestMethod.PUT) @RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/item", method = RequestMethod.PUT)
public ItemDTO updateItem(@PathVariable String appId, @PathVariable String env, public void updateItem(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName, @PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody ItemDTO item){ @RequestBody ItemDTO item){
checkModel(isValidItem(item)); checkModel(isValidItem(item));
return configService.createOrUpdateItem(appId, Env.valueOf(env), clusterName, namespaceName, item); configService.updateItem(appId, Env.valueOf(env), clusterName, namespaceName, item);
} }
......
...@@ -72,7 +72,7 @@ public class NamespaceController { ...@@ -72,7 +72,7 @@ public class NamespaceController {
// TODO: 16/6/17 某些环境创建失败,统一处理这种场景 // TODO: 16/6/17 某些环境创建失败,统一处理这种场景
namespaceService.createNamespace(Env.valueOf(model.getEnv()), namespace); namespaceService.createNamespace(Env.valueOf(model.getEnv()), namespace);
} catch (Exception e) { } catch (Exception e) {
logger.error("create namespace error.", e); logger.error("createItem namespace error.", e);
} }
} }
return ResponseEntity.ok().build(); return ResponseEntity.ok().build();
......
...@@ -36,7 +36,7 @@ public class ServerConfigController { ...@@ -36,7 +36,7 @@ public class ServerConfigController {
ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey()); ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey());
if (storedConfig == null) {//create if (storedConfig == null) {//createItem
serverConfig.setDataChangeCreatedBy(modifiedBy); serverConfig.setDataChangeCreatedBy(modifiedBy);
serverConfig.setDataChangeLastModifiedBy(modifiedBy); serverConfig.setDataChangeLastModifiedBy(modifiedBy);
return serverConfigRepository.save(serverConfig); return serverConfigRepository.save(serverConfig);
......
...@@ -68,7 +68,9 @@ public class ConfigService { ...@@ -68,7 +68,9 @@ public class ConfigService {
long namespaceId = model.getNamespaceId(); long namespaceId = model.getNamespaceId();
String configText = model.getConfigText(); String configText = model.getConfigText();
ConfigTextResolver resolver = model.getFormat() == ConfigFileFormat.Properties ? propertyResolver : fileTextResolver; ConfigTextResolver
resolver =
model.getFormat() == ConfigFileFormat.Properties ? propertyResolver : fileTextResolver;
ItemChangeSets changeSets = resolver.resolve(namespaceId, configText, ItemChangeSets changeSets = resolver.resolve(namespaceId, configText,
itemAPI.findItems(appId, env, clusterName, namespaceName)); itemAPI.findItems(appId, env, clusterName, namespaceName));
if (changeSets.isEmpty()) { if (changeSets.isEmpty()) {
...@@ -76,23 +78,29 @@ public class ConfigService { ...@@ -76,23 +78,29 @@ public class ConfigService {
} }
changeSets.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId()); changeSets.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId());
itemAPI.updateItems(appId, env, clusterName, namespaceName, changeSets); itemAPI.updateItemsByChangeSet(appId, env, clusterName, namespaceName, changeSets);
} }
public ItemDTO createOrUpdateItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item) { public ItemDTO createItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item) {
NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName); NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
if (namespace == null) { if (namespace == null) {
throw new BadRequestException( throw new BadRequestException(
"namespace:" + namespaceName + " not exist in env:" + env + ", cluster:" + clusterName); "namespace:" + namespaceName + " not exist in env:" + env + ", cluster:" + clusterName);
} }
item.setNamespaceId(namespace.getId());
String username = userInfoHolder.getUser().getUserId(); String username = userInfoHolder.getUser().getUserId();
if (StringUtils.isEmpty(item.getDataChangeCreatedBy())) { item.setDataChangeCreatedBy(username);
item.setDataChangeCreatedBy(username);
}
item.setDataChangeLastModifiedBy(username); item.setDataChangeLastModifiedBy(username);
item.setNamespaceId(namespace.getId());
return itemAPI.createOrUpdateItem(appId, env, clusterName, namespaceName, item); return itemAPI.createItem(appId, env, clusterName, namespaceName, item);
}
public void updateItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item) {
String username = userInfoHolder.getUser().getUserId();
item.setDataChangeLastModifiedBy(username);
itemAPI.updateItem(appId, env, clusterName, namespaceName, item);
} }
public void deleteItem(Env env, long itemId) { public void deleteItem(Env env, long itemId) {
...@@ -120,9 +128,9 @@ public class ConfigService { ...@@ -120,9 +128,9 @@ public class ConfigService {
changeSets.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId()); changeSets.setDataChangeLastModifiedBy(userInfoHolder.getUser().getUserId());
try { try {
itemAPI itemAPI
.updateItems(namespaceIdentifer.getAppId(), namespaceIdentifer.getEnv(), .updateItemsByChangeSet(namespaceIdentifer.getAppId(), namespaceIdentifer.getEnv(),
namespaceIdentifer.getClusterName(), namespaceIdentifer.getClusterName(),
namespaceIdentifer.getNamespaceName(), changeSets); namespaceIdentifer.getNamespaceName(), changeSets);
} catch (HttpClientErrorException e) { } catch (HttpClientErrorException e) {
logger.error("sync items error. namespace:{}", namespaceIdentifer); logger.error("sync items error. namespace:{}", namespaceIdentifer);
throw new ServiceException(String.format("sync item error. env:%s, clusterName:%s", namespaceIdentifer.getEnv(), throw new ServiceException(String.format("sync item error. env:%s, clusterName:%s", namespaceIdentifer.getEnv(),
......
...@@ -37,7 +37,7 @@ public class RoleInitializationService { ...@@ -37,7 +37,7 @@ public class RoleInitializationService {
return; return;
} }
String operaterUserId = userInfoHolder.getUser().getUserId(); String operaterUserId = userInfoHolder.getUser().getUserId();
//create app permissions //createItem app permissions
createAppMasterRole(appId); createAppMasterRole(appId);
//assign master role to user //assign master role to user
...@@ -75,7 +75,7 @@ public class RoleInitializationService { ...@@ -75,7 +75,7 @@ public class RoleInitializationService {
appPermissionIds = appPermissionIds =
FluentIterable.from(createdAppPermissions).transform(permission -> permission.getId()).toSet(); FluentIterable.from(createdAppPermissions).transform(permission -> permission.getId()).toSet();
//create app master role //createItem app master role
Role appMasterRole = createRole(RoleUtils.buildAppMasterRoleName(appId)); Role appMasterRole = createRole(RoleUtils.buildAppMasterRoleName(appId));
rolePermissionService.createRoleWithPermissions(appMasterRole, appPermissionIds); rolePermissionService.createRoleWithPermissions(appMasterRole, appPermissionIds);
......
...@@ -15,7 +15,7 @@ import java.util.Set; ...@@ -15,7 +15,7 @@ import java.util.Set;
/** /**
* normal property file resolver. * normal property file resolver.
* update comment and blank item implement by create new item and delete old item. * update comment and blank item implement by createItem new item and delete old item.
* update normal key/value item implement by update. * update normal key/value item implement by update.
*/ */
@Component("propertyResolver") @Component("propertyResolver")
...@@ -105,7 +105,7 @@ public class PropertyResolver implements ConfigTextResolver { ...@@ -105,7 +105,7 @@ public class PropertyResolver implements ConfigTextResolver {
private void handleCommentLine(Long namespaceId, ItemDTO oldItemByLine, String newItem, int lineCounter, ItemChangeSets changeSets) { private void handleCommentLine(Long namespaceId, ItemDTO oldItemByLine, String newItem, int lineCounter, ItemChangeSets changeSets) {
String oldComment = oldItemByLine == null ? "" : oldItemByLine.getComment(); String oldComment = oldItemByLine == null ? "" : oldItemByLine.getComment();
//create comment. implement update comment by delete old comment and create new comment //createItem comment. implement update comment by delete old comment and createItem new comment
if (!(isCommentItem(oldItemByLine) && newItem.equals(oldComment))) { if (!(isCommentItem(oldItemByLine) && newItem.equals(oldComment))) {
changeSets.addCreateItem(buildCommentItem(0l, namespaceId, newItem, lineCounter)); changeSets.addCreateItem(buildCommentItem(0l, namespaceId, newItem, lineCounter));
} }
......
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