提交 afa2a683 编写于 作者: J Jason Song

code reformat

上级 7b7d753f
......@@ -81,6 +81,7 @@ public class Consumer extends BaseEntity {
this.ownerName = ownerName;
}
@Override
public String toString() {
return toStringHelper().add("name", name).add("appId", appId)
.add("orgId", orgId)
......
......@@ -38,4 +38,9 @@ public class ConsumerRole extends BaseEntity {
public void setRoleId(long roleId) {
this.roleId = roleId;
}
@Override
public String toString() {
return toStringHelper().add("consumerId", consumerId).add("roleId", roleId).toString();
}
}
......@@ -51,4 +51,10 @@ public class ConsumerToken extends BaseEntity {
public void setExpires(Date expires) {
this.expires = expires;
}
@Override
public String toString() {
return toStringHelper().add("consumerId", consumerId).add("token", token)
.add("expires", expires).toString();
}
}
......@@ -42,11 +42,11 @@ public class ReleaseController {
HttpServletRequest request) {
checkModel(model != null);
RequestPrecondition.checkArguments(!StringUtils.isContainEmpty(model.getReleaseBy(), model
RequestPrecondition.checkArguments(!StringUtils.isContainEmpty(model.getReleasedBy(), model
.getReleaseTitle()),
"releaseTitle and releaseBy can not be empty");
if (userService.findByUserId(model.getReleaseBy()) == null) {
if (userService.findByUserId(model.getReleasedBy()) == null) {
throw new BadRequestException("用户不存在.");
}
......
package com.ctrip.framework.apollo.portal;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import com.ctrip.framework.apollo.portal.service.ServerConfigService;
......@@ -67,11 +66,11 @@ public class PortalSettings {
healthCheckService
.scheduleWithFixedDelay(new HealthCheckTask(applicationContext), 1000, HEALTH_CHECK_INTERVAL,
TimeUnit.MILLISECONDS);
TimeUnit.MILLISECONDS);
}
public List<Env> getAllEnvs(){
public List<Env> getAllEnvs() {
return allEnvs;
}
......
package com.ctrip.framework.apollo.portal.api;
import com.ctrip.framework.apollo.common.dto.AppNamespaceDTO;
import com.ctrip.framework.apollo.common.dto.CommitDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceLockDTO;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.dto.AppNamespaceDTO;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.dto.CommitDTO;
import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceLockDTO;
import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import com.ctrip.framework.apollo.core.enums.Env;
import org.springframework.boot.actuate.health.Health;
import org.springframework.http.HttpEntity;
......@@ -53,8 +53,8 @@ public class AdminServiceAPI {
public List<NamespaceDTO> findNamespaceByCluster(String appId, Env env, String clusterName) {
NamespaceDTO[] namespaceDTOs = restTemplate.get(env, "apps/{appId}/clusters/{clusterName}/namespaces",
NamespaceDTO[].class, appId,
clusterName);
NamespaceDTO[].class, appId,
clusterName);
return Arrays.asList(namespaceDTOs);
}
......@@ -62,7 +62,7 @@ public class AdminServiceAPI {
String namespaceName) {
NamespaceDTO dto =
restTemplate.get(env, "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}",
NamespaceDTO.class, appId, clusterName, namespaceName);
NamespaceDTO.class, appId, clusterName, namespaceName);
return dto;
}
......@@ -70,7 +70,7 @@ public class AdminServiceAPI {
public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) {
return restTemplate
.post(env, "apps/{appId}/clusters/{clusterName}/namespaces", namespace, NamespaceDTO.class,
namespace.getAppId(), namespace.getClusterName());
namespace.getAppId(), namespace.getClusterName());
}
public AppNamespaceDTO createAppNamespace(Env env, AppNamespaceDTO appNamespace) {
......@@ -86,7 +86,7 @@ public class AdminServiceAPI {
public List<ItemDTO> findItems(String appId, Env env, String clusterName, String namespaceName) {
ItemDTO[] itemDTOs =
restTemplate.get(env, "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items",
ItemDTO[].class, appId, clusterName, namespaceName);
ItemDTO[].class, appId, clusterName, namespaceName);
return Arrays.asList(itemDTOs);
}
......@@ -97,18 +97,18 @@ public class AdminServiceAPI {
public void updateItemsByChangeSet(String appId, Env env, String clusterName, String namespace,
ItemChangeSets changeSets) {
restTemplate.post(env, "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset",
changeSets, Void.class, appId, clusterName, namespace);
changeSets, Void.class, appId, clusterName, namespace);
}
public void updateItem(String appId, Env env, String clusterName, String namespace, long itemId, ItemDTO item) {
restTemplate.put(env, "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}",
item, appId, clusterName, namespace, itemId);
item, appId, clusterName, namespace, itemId);
}
public ItemDTO createItem(String appId, Env env, String clusterName, String namespace, ItemDTO item) {
return restTemplate.post(env, "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items",
item, ItemDTO.class, appId, clusterName, namespace);
item, ItemDTO.class, appId, clusterName, namespace);
}
public void deleteItem(Env env, long itemId, String operator) {
......@@ -122,25 +122,25 @@ public class AdminServiceAPI {
public List<ClusterDTO> findClustersByApp(String appId, Env env) {
ClusterDTO[] clusterDTOs = restTemplate.get(env, "apps/{appId}/clusters", ClusterDTO[].class,
appId);
appId);
return Arrays.asList(clusterDTOs);
}
public ClusterDTO loadCluster(String appId, Env env, String clusterName) {
return restTemplate.get(env, "apps/{appId}/clusters/{clusterName}", ClusterDTO.class,
appId, clusterName);
appId, clusterName);
}
public boolean isClusterUnique(String appId, Env env, String clusterName) {
return restTemplate
.get(env, "apps/{appId}/cluster/{clusterName}/unique", Boolean.class,
appId, clusterName);
appId, clusterName);
}
public ClusterDTO create(Env env, ClusterDTO cluster) {
return restTemplate.post(env, "apps/{appId}/clusters", cluster, ClusterDTO.class,
cluster.getAppId());
cluster.getAppId());
}
}
......@@ -174,7 +174,7 @@ public class AdminServiceAPI {
String namespace) {
ReleaseDTO releaseDTO = restTemplate
.get(env, "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest",
ReleaseDTO.class, appId, clusterName, namespace);
ReleaseDTO.class, appId, clusterName, namespace);
return releaseDTO;
}
......@@ -197,8 +197,8 @@ public class AdminServiceAPI {
public void rollback(Env env, long releaseId, String operator) {
restTemplate.put(env,
"releases/{releaseId}/rollback?operator={operator}",
null, releaseId, operator);
"releases/{releaseId}/rollback?operator={operator}",
null, releaseId, operator);
}
}
......@@ -208,9 +208,9 @@ public class AdminServiceAPI {
public List<CommitDTO> find(String appId, Env env, String clusterName, String namespaceName, int page, int size) {
CommitDTO[] commitDTOs = restTemplate.get(env,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}",
CommitDTO[].class,
appId, clusterName, namespaceName, page, size);
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}",
CommitDTO[].class,
appId, clusterName, namespaceName, page, size);
return Arrays.asList(commitDTOs);
}
......@@ -221,8 +221,8 @@ public class AdminServiceAPI {
public NamespaceLockDTO getNamespaceLockOwner(String appId, Env env, String clusterName, String namespaceName) {
return restTemplate.get(env, "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock",
NamespaceLockDTO.class,
appId, clusterName, namespaceName);
NamespaceLockDTO.class,
appId, clusterName, namespaceName);
}
}
......
package com.ctrip.framework.apollo.portal.api;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import com.ctrip.framework.apollo.portal.constant.CatEventType;
import com.dianping.cat.Cat;
import com.dianping.cat.message.Message;
......@@ -66,7 +66,7 @@ public class RetryableRestTemplate {
private <T> T execute(HttpMethod method, Env env, String path, Object request, Class<T> responseType,
Object... uriVariables) {
if (path.startsWith("/")){
if (path.startsWith("/")) {
path = path.substring(1, path.length());
}
......@@ -143,11 +143,11 @@ public class RetryableRestTemplate {
Throwable nestedException = e.getCause();
if (method == HttpMethod.GET) {
return nestedException instanceof SocketTimeoutException
|| nestedException instanceof HttpHostConnectException
|| nestedException instanceof ConnectTimeoutException;
|| nestedException instanceof HttpHostConnectException
|| nestedException instanceof ConnectTimeoutException;
} else {
return nestedException instanceof HttpHostConnectException
|| nestedException instanceof ConnectTimeoutException;
|| nestedException instanceof ConnectTimeoutException;
}
}
......
......@@ -18,42 +18,42 @@ public class PermissionValidator {
public boolean hasModifyNamespacePermission(String appId, String namespaceName) {
return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(),
PermissionType.MODIFY_NAMESPACE,
RoleUtils.buildNamespaceTargetId(appId, namespaceName));
PermissionType.MODIFY_NAMESPACE,
RoleUtils.buildNamespaceTargetId(appId, namespaceName));
}
public boolean hasReleaseNamespacePermission(String appId, String namespaceName) {
return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(),
PermissionType.RELEASE_NAMESPACE,
RoleUtils.buildNamespaceTargetId(appId, namespaceName));
PermissionType.RELEASE_NAMESPACE,
RoleUtils.buildNamespaceTargetId(appId, namespaceName));
}
public boolean hasAssignRolePermission(String appId) {
return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(),
PermissionType.ASSIGN_ROLE,
appId);
PermissionType.ASSIGN_ROLE,
appId);
}
public boolean hasCreateNamespacePermission(String appId) {
return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(),
PermissionType.CREATE_NAMESPACE,
appId);
PermissionType.CREATE_NAMESPACE,
appId);
}
public boolean hasCreateClusterPermission(String appId) {
return rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(),
PermissionType.CREATE_CLUSTER,
appId);
PermissionType.CREATE_CLUSTER,
appId);
}
public boolean hasCreateAppNamespacePermission(String appId, AppNamespace appNamespace) {
boolean isPublicAppNamespace = appNamespace.isPublic();
if (isPublicAppNamespace){
if (isPublicAppNamespace) {
return hasCreateNamespacePermission(appId);
}else {
} else {
return rolePermissionService.isSuperAdmin(userInfoHolder.getUser().getUserId());
}
}
......
......@@ -14,7 +14,6 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;
......@@ -62,7 +61,7 @@ public class CtripUserService implements UserService {
}
@Override
public List<UserInfo> searchUsers(String keyword, int offset, int limit) {
public List<UserInfo> searchUsers(String keyword, int offset, int limit) {
UserServiceRequest request = assembleSearchUserRequest(keyword, offset, limit);
HttpEntity<UserServiceRequest> entity = new HttpEntity<>(request);
......
......@@ -9,7 +9,7 @@ import com.ctrip.framework.apollo.portal.entity.po.UserInfo;
public class DefaultUserInfoHolder implements UserInfoHolder {
public DefaultUserInfoHolder(){
public DefaultUserInfoHolder() {
}
......
......@@ -6,7 +6,6 @@ import com.ctrip.framework.apollo.portal.entity.po.UserInfo;
import com.ctrip.framework.apollo.portal.service.UserService;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
......
......@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.portal.configuration;
import com.google.common.collect.Maps;
import com.ctrip.framework.apollo.openapi.filter.ConsumerAuthenticationFilter;
import com.ctrip.framework.apollo.openapi.service.ConsumerService;
import com.ctrip.framework.apollo.openapi.util.ConsumerAuthUtil;
import com.ctrip.framework.apollo.portal.auth.LogoutHandler;
import com.ctrip.framework.apollo.portal.auth.SsoHeartbeatHandler;
......@@ -28,7 +27,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import java.util.EventListener;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.Filter;
......
......@@ -36,11 +36,11 @@ public class WebContextConfiguration {
String loggingServerPort = serverConfigService.getValue("loggingServerPort");
String credisServiceUrl = serverConfigService.getValue("credisServiceUrl");
servletContext.setInitParameter("loggingServerIP",
Strings.isNullOrEmpty(loggingServerIP) ? "" : loggingServerIP);
Strings.isNullOrEmpty(loggingServerIP) ? "" : loggingServerIP);
servletContext.setInitParameter("loggingServerPort",
Strings.isNullOrEmpty(loggingServerPort) ? "" : loggingServerPort);
Strings.isNullOrEmpty(loggingServerPort) ? "" : loggingServerPort);
servletContext.setInitParameter("credisServiceUrl",
Strings.isNullOrEmpty(credisServiceUrl) ? "" : credisServiceUrl);
Strings.isNullOrEmpty(credisServiceUrl) ? "" : credisServiceUrl);
}
};
}
......
......@@ -2,7 +2,9 @@ package com.ctrip.framework.apollo.portal.constant;
public interface PermissionType {
/** APP level permission */
/**
* APP level permission
*/
String CREATE_NAMESPACE = "CreateNamespace";
......@@ -13,7 +15,9 @@ public interface PermissionType {
*/
String ASSIGN_ROLE = "AssignRole";
/** namespace level permission*/
/**
* namespace level permission
*/
String MODIFY_NAMESPACE = "ModifyNamespace";
......
......@@ -2,12 +2,12 @@ package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.http.MultiResponseEntity;
import com.ctrip.framework.apollo.common.http.RichResponseEntity;
import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.common.utils.RequestPrecondition;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.portal.PortalSettings;
import com.ctrip.framework.apollo.portal.entity.po.UserInfo;
import com.ctrip.framework.apollo.portal.entity.vo.EnvClusterInfo;
......@@ -76,13 +76,13 @@ public class AppController {
public ResponseEntity<Void> create(@RequestBody App app) {
RequestPrecondition.checkArgumentsNotEmpty(app.getName(), app.getAppId(), app.getOwnerName(),
app.getOrgId(), app.getOrgName());
app.getOrgId(), app.getOrgName());
if (!InputValidator.isValidClusterNamespace(app.getAppId())) {
throw new BadRequestException(String.format("AppId格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
}
UserInfo userInfo = userService.findByUserId(app.getOwnerName());
if (userInfo == null){
if (userInfo == null) {
throw new BadRequestException("应用负责人不存在");
}
app.setOwnerEmail(userInfo.getEmail());
......@@ -99,7 +99,7 @@ public class AppController {
public ResponseEntity<Void> create(@PathVariable String env, @RequestBody App app) {
RequestPrecondition.checkArgumentsNotEmpty(app.getName(), app.getAppId(), app.getOwnerEmail(), app.getOwnerName(),
app.getOrgId(), app.getOrgName());
app.getOrgId(), app.getOrgName());
if (!InputValidator.isValidClusterNamespace(app.getAppId())) {
throw new BadRequestException(InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE);
}
......
package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.common.utils.RequestPrecondition;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.portal.auth.UserInfoHolder;
import com.ctrip.framework.apollo.portal.service.ClusterService;
......@@ -29,7 +29,7 @@ public class ClusterController {
@PreAuthorize(value = "@permissionValidator.hasCreateClusterPermission(#appId)")
@RequestMapping(value = "apps/{appId}/envs/{env}/clusters", method = RequestMethod.POST)
public ClusterDTO createCluster(@PathVariable String appId, @PathVariable String env,
@RequestBody ClusterDTO cluster){
@RequestBody ClusterDTO cluster) {
checkModel(cluster != null);
RequestPrecondition.checkArgumentsNotEmpty(cluster.getAppId(), cluster.getName());
......
package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.utils.RequestPrecondition;
import com.ctrip.framework.apollo.common.dto.CommitDTO;
import com.ctrip.framework.apollo.common.utils.RequestPrecondition;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.service.CommitService;
......@@ -23,7 +23,7 @@ public class CommitController {
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/commits")
public List<CommitDTO> find(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size){
@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
RequestPrecondition.checkNumberPositive(size);
RequestPrecondition.checkNumberNotNegative(page);
......
......@@ -18,7 +18,7 @@ public class EnvController {
private PortalSettings portalSettings;
@RequestMapping(value = "", method = RequestMethod.GET)
public List<Env> envs(){
public List<Env> envs() {
return portalSettings.getActiveEnvs();
}
......
package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.portal.auth.UserInfoHolder;
import com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs;
import com.ctrip.framework.apollo.portal.entity.form.NamespaceSyncModel;
import com.ctrip.framework.apollo.portal.entity.form.NamespaceTextModel;
import com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs;
import com.ctrip.framework.apollo.portal.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -38,8 +38,8 @@ public class ItemController {
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items", method = RequestMethod.PUT, consumes = {
"application/json"})
public void modifyItemsByText(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody NamespaceTextModel model) {
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody NamespaceTextModel model) {
checkModel(model != null);
......@@ -55,7 +55,7 @@ public class ItemController {
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/item", method = RequestMethod.POST)
public ItemDTO createItem(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody ItemDTO item){
@RequestBody ItemDTO item) {
checkModel(isValidItem(item));
return configService.createItem(appId, Env.valueOf(env), clusterName, namespaceName, item);
......@@ -64,8 +64,8 @@ public class ItemController {
@PreAuthorize(value = "@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName)")
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/item", method = RequestMethod.PUT)
public void updateItem(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody ItemDTO item){
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody ItemDTO item) {
checkModel(isValidItem(item));
configService.updateItem(appId, Env.valueOf(env), clusterName, namespaceName, item);
......@@ -76,27 +76,26 @@ public class ItemController {
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}", method = RequestMethod.DELETE)
public void deleteItem(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@PathVariable long itemId){
if (itemId <= 0){
@PathVariable long itemId) {
if (itemId <= 0) {
throw new BadRequestException("item id invalid");
}
configService.deleteItem(Env.valueOf(env), itemId, userInfoHolder.getUser().getUserId());
}
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items")
public List<ItemDTO> findItems(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestParam(defaultValue = "lineNum") String orderBy){
@RequestParam(defaultValue = "lineNum") String orderBy) {
List<ItemDTO> items = configService.findItems(appId, Env.valueOf(env), clusterName, namespaceName);
if ("lastModifiedTime".equals(orderBy)){
if ("lastModifiedTime".equals(orderBy)) {
Collections.sort(items, (o1, o2) -> {
if (o1.getDataChangeLastModifiedTime().after(o2.getDataChangeLastModifiedTime())){
if (o1.getDataChangeLastModifiedTime().after(o2.getDataChangeLastModifiedTime())) {
return -1;
}
if (o1.getDataChangeLastModifiedTime().before(o2.getDataChangeLastModifiedTime())){
if (o1.getDataChangeLastModifiedTime().before(o2.getDataChangeLastModifiedTime())) {
return 1;
}
return 0;
......@@ -107,7 +106,7 @@ public class ItemController {
@RequestMapping(value = "/namespaces/{namespaceName}/diff", method = RequestMethod.POST, consumes = {
"application/json"})
public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model){
public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model) {
checkModel(model != null && !model.isInvalid());
return configService.compare(model.getSyncToNamespaces(), model.getSyncItems());
......@@ -117,14 +116,14 @@ public class ItemController {
@RequestMapping(value = "/apps/{appId}/namespaces/{namespaceName}/items", method = RequestMethod.PUT, consumes = {
"application/json"})
public ResponseEntity<Void> update(@PathVariable String appId, @PathVariable String namespaceName,
@RequestBody NamespaceSyncModel model){
@RequestBody NamespaceSyncModel model) {
checkModel(model != null && !model.isInvalid());
configService.syncItems(model.getSyncToNamespaces(), model.getSyncItems());
return ResponseEntity.status(HttpStatus.OK).build();
}
private boolean isValidItem(ItemDTO item){
private boolean isValidItem(ItemDTO item) {
return item != null && !StringUtils.isContainEmpty(item.getKey());
}
......
package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.utils.RequestPrecondition;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.portal.auth.UserInfoHolder;
import com.ctrip.framework.apollo.portal.entity.form.NamespaceCreationModel;
......@@ -93,8 +93,8 @@ public class NamespaceController {
RequestPrecondition.checkArgumentsNotEmpty(appNamespace.getAppId(), appNamespace.getName());
if (!InputValidator.isValidAppNamespace(appNamespace.getName())) {
throw new BadRequestException(String.format("Namespace格式错误: %s",
InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE + " & "
+ InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE));
InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE + " & "
+ InputValidator.INVALID_NAMESPACE_NAMESPACE_MESSAGE));
}
//add app org id as prefix
......
......@@ -17,9 +17,9 @@ public class NamespaceLockController {
@RequestMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/lock")
public NamespaceLockDTO getNamespaceLock(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName){
@PathVariable String clusterName, @PathVariable String namespaceName) {
return namespaceLockService.getNamespaceLock(appId, Env.valueOf(env), clusterName, namespaceName);
return namespaceLockService.getNamespaceLock(appId, Env.valueOf(env), clusterName, namespaceName);
}
}
......@@ -28,7 +28,6 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.Set;
@RestController
public class PermissionController {
......@@ -56,13 +55,13 @@ public class PermissionController {
permissionCondition.setHasPermission(
rolePermissionService.userHasPermission(userInfoHolder.getUser().getUserId(), permissionType,
RoleUtils.buildNamespaceTargetId(appId, namespaceName)));
RoleUtils.buildNamespaceTargetId(appId, namespaceName)));
return ResponseEntity.ok().body(permissionCondition);
}
@RequestMapping("/permissions/root")
public ResponseEntity<PermissionCondition> hasRootPermission(){
public ResponseEntity<PermissionCondition> hasRootPermission() {
PermissionCondition permissionCondition = new PermissionCondition();
permissionCondition.setHasPermission(rolePermissionService.isSuperAdmin(userInfoHolder.getUser().getUserId()));
......@@ -72,7 +71,7 @@ public class PermissionController {
@RequestMapping("/apps/{appId}/namespaces/{namespaceName}/role_users")
public NamespaceRolesAssignedUsers getNamespaceRoles(@PathVariable String appId, @PathVariable String namespaceName){
public NamespaceRolesAssignedUsers getNamespaceRoles(@PathVariable String appId, @PathVariable String namespaceName) {
NamespaceRolesAssignedUsers assignedUsers = new NamespaceRolesAssignedUsers();
assignedUsers.setNamespaceName(namespaceName);
......@@ -92,16 +91,16 @@ public class PermissionController {
@PreAuthorize(value = "@permissionValidator.hasAssignRolePermission(#appId)")
@RequestMapping(value = "/apps/{appId}/namespaces/{namespaceName}/roles/{roleType}", method = RequestMethod.POST)
public ResponseEntity<Void> assignNamespaceRoleToUser(@PathVariable String appId, @PathVariable String namespaceName,
@PathVariable String roleType, @RequestBody String user){
@PathVariable String roleType, @RequestBody String user) {
checkUserExists(user);
RequestPrecondition.checkArgumentsNotEmpty(user);
if (!RoleType.isValidRoleType(roleType)){
if (!RoleType.isValidRoleType(roleType)) {
throw new BadRequestException("role type is illegal");
}
Set<String> assignedUser = rolePermissionService.assignRoleToUsers(RoleUtils.buildNamespaceRoleName(appId, namespaceName, roleType),
Sets.newHashSet(user), userInfoHolder.getUser().getUserId());
if (CollectionUtils.isEmpty(assignedUser)){
Sets.newHashSet(user), userInfoHolder.getUser().getUserId());
if (CollectionUtils.isEmpty(assignedUser)) {
throw new BadRequestException(user + "已授权");
}
......@@ -111,19 +110,19 @@ public class PermissionController {
@PreAuthorize(value = "@permissionValidator.hasAssignRolePermission(#appId)")
@RequestMapping(value = "/apps/{appId}/namespaces/{namespaceName}/roles/{roleType}", method = RequestMethod.DELETE)
public ResponseEntity<Void> removeNamespaceRoleFromUser(@PathVariable String appId, @PathVariable String namespaceName,
@PathVariable String roleType, @RequestParam String user){
@PathVariable String roleType, @RequestParam String user) {
RequestPrecondition.checkArgumentsNotEmpty(user);
if (!RoleType.isValidRoleType(roleType)){
if (!RoleType.isValidRoleType(roleType)) {
throw new BadRequestException("role type is illegal");
}
rolePermissionService.removeRoleFromUsers(RoleUtils.buildNamespaceRoleName(appId, namespaceName, roleType),
Sets.newHashSet(user), userInfoHolder.getUser().getUserId());
Sets.newHashSet(user), userInfoHolder.getUser().getUserId());
return ResponseEntity.ok().build();
}
@RequestMapping(value = "/apps/{appId}/role_users")
public AppRolesAssignedUsers getAppRoles(@PathVariable String appId){
public AppRolesAssignedUsers getAppRoles(@PathVariable String appId) {
AppRolesAssignedUsers users = new AppRolesAssignedUsers();
users.setAppId(appId);
......@@ -136,16 +135,16 @@ public class PermissionController {
@PreAuthorize(value = "@permissionValidator.hasAssignRolePermission(#appId)")
@RequestMapping(value = "/apps/{appId}/roles/{roleType}", method = RequestMethod.POST)
public ResponseEntity<Void> assignAppRoleToUser(@PathVariable String appId, @PathVariable String roleType,
@RequestBody String user){
@RequestBody String user) {
checkUserExists(user);
RequestPrecondition.checkArgumentsNotEmpty(user);
if (!RoleType.isValidRoleType(roleType)){
if (!RoleType.isValidRoleType(roleType)) {
throw new BadRequestException("role type is illegal");
}
Set<String> assignedUsers = rolePermissionService.assignRoleToUsers(RoleUtils.buildAppRoleName(appId, roleType),
Sets.newHashSet(user), userInfoHolder.getUser().getUserId());
if (CollectionUtils.isEmpty(assignedUsers)){
Sets.newHashSet(user), userInfoHolder.getUser().getUserId());
if (CollectionUtils.isEmpty(assignedUsers)) {
throw new BadRequestException(user + "已授权");
}
......@@ -155,14 +154,14 @@ public class PermissionController {
@PreAuthorize(value = "@permissionValidator.hasAssignRolePermission(#appId)")
@RequestMapping(value = "/apps/{appId}/roles/{roleType}", method = RequestMethod.DELETE)
public ResponseEntity<Void> removeAppRoleFromUser(@PathVariable String appId, @PathVariable String roleType,
@RequestParam String user){
@RequestParam String user) {
RequestPrecondition.checkArgumentsNotEmpty(user);
if (!RoleType.isValidRoleType(roleType)){
if (!RoleType.isValidRoleType(roleType)) {
throw new BadRequestException("role type is illegal");
}
rolePermissionService.removeRoleFromUsers(RoleUtils.buildAppRoleName(appId, roleType),
Sets.newHashSet(user), userInfoHolder.getUser().getUserId());
Sets.newHashSet(user), userInfoHolder.getUser().getUserId());
return ResponseEntity.ok().build();
}
......
package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.utils.RequestPrecondition;
import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import com.ctrip.framework.apollo.common.utils.RequestPrecondition;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.entity.form.NamespaceReleaseModel;
import com.ctrip.framework.apollo.portal.entity.vo.ReleaseCompareResult;
......
......@@ -30,7 +30,7 @@ public class UserInfoController {
@RequestMapping("/user")
public UserInfo getCurrentUserName() {
return userInfoHolder.getUser();
return userInfoHolder.getUser();
}
@RequestMapping("/user/logout")
......
......@@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
@Component
@Profile("ctrip")
public class BizLoggingCustomizer extends LoggingCustomizer{
public class BizLoggingCustomizer extends LoggingCustomizer {
private static final String CLOGGING_SERVER_URL_KEY = "clogging.server.url";
private static final String CLOGGING_SERVER_PORT_KEY = "clogging.server.port";
......@@ -22,7 +22,7 @@ public class BizLoggingCustomizer extends LoggingCustomizer{
@Override
protected String cloggingUrl() {
if (cloggingUrl == null){
if (cloggingUrl == null) {
cloggingUrl = serverConfigService.getValue(CLOGGING_SERVER_URL_KEY);
}
return cloggingUrl;
......@@ -30,7 +30,7 @@ public class BizLoggingCustomizer extends LoggingCustomizer{
@Override
protected String cloggingPort() {
if (cloggingPort == null){
if (cloggingPort == null) {
cloggingPort = serverConfigService.getValue(CLOGGING_SERVER_PORT_KEY);
}
return cloggingPort;
......
......@@ -12,7 +12,7 @@ public class NamespaceReleaseModel implements Verifiable {
private String namespaceName;
private String releaseTitle;
private String releaseComment;
private String releaseBy;
private String releasedBy;
@Override
public boolean isInvalid() {
......@@ -67,11 +67,11 @@ public class NamespaceReleaseModel implements Verifiable {
this.releaseComment = releaseComment;
}
public String getReleaseBy() {
return releaseBy;
public String getReleasedBy() {
return releasedBy;
}
public void setReleaseBy(String releaseBy) {
this.releaseBy = releaseBy;
public void setReleasedBy(String releasedBy) {
this.releasedBy = releasedBy;
}
}
......@@ -14,11 +14,11 @@ public class NamespaceSyncModel implements Verifiable {
@Override
public boolean isInvalid() {
if (CollectionUtils.isEmpty(syncToNamespaces) || CollectionUtils.isEmpty(syncItems)){
if (CollectionUtils.isEmpty(syncToNamespaces) || CollectionUtils.isEmpty(syncItems)) {
return true;
}
for (NamespaceIdentifier namespaceIdentifier : syncToNamespaces){
if (namespaceIdentifier.isInvalid()){
for (NamespaceIdentifier namespaceIdentifier : syncToNamespaces) {
if (namespaceIdentifier.isInvalid()) {
return true;
}
}
......
......@@ -17,9 +17,10 @@ public class NamespaceTextModel implements Verifiable {
@Override
public boolean isInvalid(){
public boolean isInvalid() {
return StringUtils.isContainEmpty(appId, env, clusterName, namespaceName) || namespaceId <= 0;
}
public String getAppId() {
return appId;
}
......
......@@ -9,7 +9,7 @@ public class EnvClusterInfo {
private Env env;
private List<ClusterDTO> clusters;
public EnvClusterInfo(Env env){
public EnvClusterInfo(Env env) {
this.env = env;
}
......
......@@ -7,9 +7,10 @@ public class ItemDiffs {
private ItemChangeSets diffs;
private String extInfo;
public ItemDiffs(NamespaceIdentifier namespace){
public ItemDiffs(NamespaceIdentifier namespace) {
this.namespace = namespace;
}
public NamespaceIdentifier getNamespace() {
return namespace;
}
......
......@@ -51,10 +51,10 @@ public class NamespaceIdentifier implements Verifiable {
@Override
public String toString() {
return "NamespaceIdentifer{" +
"appId='" + appId + '\'' +
", env='" + env + '\'' +
", clusterName='" + clusterName + '\'' +
", namespaceName='" + namespaceName + '\'' +
'}';
"appId='" + appId + '\'' +
", env='" + env + '\'' +
", clusterName='" + clusterName + '\'' +
", namespaceName='" + namespaceName + '\'' +
'}';
}
}
package com.ctrip.framework.apollo.portal.entity.vo;
import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
......@@ -70,7 +71,7 @@ public class NamespaceVO {
this.comment = comment;
}
public static class ItemVO{
public static class ItemVO {
private ItemDTO item;
private boolean isModified;
private boolean isDeleted;
......@@ -118,7 +119,6 @@ public class NamespaceVO {
}
}
}
package com.ctrip.framework.apollo.portal.enums;
public enum ChangeType {
public enum ChangeType {
ADDED, MODIFIED, DELETED
}
package com.ctrip.framework.apollo.portal.listener;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.dto.AppNamespaceDTO;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.PortalSettings;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
......@@ -43,7 +43,7 @@ public class CreationListener {
}
@EventListener
public void onAppNamespaceCreationEvent(AppNamespaceCreationEvent event){
public void onAppNamespaceCreationEvent(AppNamespaceCreationEvent event) {
AppNamespaceDTO appNamespace = BeanUtils.transfrom(AppNamespaceDTO.class, event.getAppNamespace());
List<Env> envs = portalSettings.getActiveEnvs();
for (Env env : envs) {
......
......@@ -6,7 +6,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface AppNamespaceRepository extends PagingAndSortingRepository<AppNamespace, Long>{
public interface AppNamespaceRepository extends PagingAndSortingRepository<AppNamespace, Long> {
AppNamespace findByAppIdAndName(String appId, String namespaceName);
......
......@@ -18,10 +18,7 @@ public interface PermissionRepository extends PagingAndSortingRepository<Permiss
/**
* find permissions by permission types and targetId
* @param permissionTypes
* @param targetId
* @return
*/
List<Permission> findByPermissionTypeInAndTargetId(Collection<String> permissionTypes,
String targetId);
String targetId);
}
......@@ -10,8 +10,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
public interface RoleRepository extends PagingAndSortingRepository<Role, Long> {
/**
* find role by role name
* @param roleName
* @return
*/
Role findTopByRoleName(String roleName);
}
......@@ -6,7 +6,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* @author Jason Song(song_s@ctrip.com)
......@@ -14,23 +13,16 @@ import java.util.Set;
public interface UserRoleRepository extends PagingAndSortingRepository<UserRole, Long> {
/**
* find user roles by userId
* @param userId
* @return
*/
List<UserRole> findByUserId(String userId);
/**
* find user roles by roleId
* @param roleId
* @return
*/
List<UserRole> findByRoleId(long roleId);
/**
* find user roles by userIds and roleId
* @param userId
* @param roleId
* @return
*/
List<UserRole> findByUserIdInAndRoleId(Collection<String> userId, long roleId);
}
package com.ctrip.framework.apollo.portal.service;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.ServiceException;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.portal.auth.UserInfoHolder;
import com.ctrip.framework.apollo.portal.repository.AppNamespaceRepository;
......
......@@ -2,22 +2,12 @@ package com.ctrip.framework.apollo.portal.service;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.HttpStatusCodeException;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.ExceptionUtils;
import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import com.ctrip.framework.apollo.portal.auth.UserInfoHolder;
import com.ctrip.framework.apollo.portal.constant.CatEventType;
......@@ -25,6 +15,16 @@ import com.ctrip.framework.apollo.portal.entity.vo.EnvClusterInfo;
import com.ctrip.framework.apollo.portal.repository.AppRepository;
import com.dianping.cat.Cat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.HttpStatusCodeException;
import java.util.Collections;
import java.util.List;
@Service
public class AppService {
......@@ -56,7 +56,7 @@ public class AppService {
public App load(String appId) {
App app = appRepository.findByAppId(appId);
if (app == null){
if (app == null) {
throw new BadRequestException(String.format("app %s cant found.", appId));
}
return app;
......
package com.ctrip.framework.apollo.portal.service;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.common.dto.ClusterDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import com.ctrip.framework.apollo.portal.constant.CatEventType;
import com.dianping.cat.Cat;
......@@ -18,12 +18,12 @@ public class ClusterService {
@Autowired
private AdminServiceAPI.ClusterAPI clusterAPI;
public List<ClusterDTO> findClusters(Env env, String appId){
public List<ClusterDTO> findClusters(Env env, String appId) {
return clusterAPI.findClustersByApp(appId, env);
}
public ClusterDTO createCluster(Env env, ClusterDTO cluster){
if (!clusterAPI.isClusterUnique(cluster.getAppId(), env, cluster.getName())){
public ClusterDTO createCluster(Env env, ClusterDTO cluster) {
if (!clusterAPI.isClusterUnique(cluster.getAppId(), env, cluster.getName())) {
throw new BadRequestException(String.format("cluster %s already exists.", cluster.getName()));
}
ClusterDTO clusterDTO = clusterAPI.create(env, cluster);
......
......@@ -16,7 +16,7 @@ public class CommitService {
@Autowired
private AdminServiceAPI.CommitAPI commitAPI;
public List<CommitDTO> find(String appId, Env env, String clusterName, String namespaceName, int page, int size){
public List<CommitDTO> find(String appId, Env env, String clusterName, String namespaceName, int page, int size) {
return commitAPI.find(appId, env, clusterName, namespaceName, page, size);
}
......
package com.ctrip.framework.apollo.portal.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.HttpClientErrorException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import com.ctrip.framework.apollo.portal.auth.UserInfoHolder;
import com.ctrip.framework.apollo.portal.constant.CatEventType;
import com.ctrip.framework.apollo.portal.entity.form.NamespaceTextModel;
import com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs;
import com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier;
import com.ctrip.framework.apollo.portal.entity.form.NamespaceTextModel;
import com.ctrip.framework.apollo.portal.service.txtresolver.ConfigTextResolver;
import com.dianping.cat.Cat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.HttpClientErrorException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
......@@ -65,7 +65,7 @@ public class ItemService {
model.getFormat() == ConfigFileFormat.Properties ? propertyResolver : fileTextResolver;
ItemChangeSets changeSets = resolver.resolve(namespaceId, configText,
itemAPI.findItems(appId, env, clusterName, namespaceName));
itemAPI.findItems(appId, env, clusterName, namespaceName));
if (changeSets.isEmpty()) {
return;
}
......@@ -74,7 +74,7 @@ public class ItemService {
itemAPI.updateItemsByChangeSet(appId, env, clusterName, namespaceName, changeSets);
Cat.logEvent(CatEventType.MODIFY_NAMESPACE_BY_TEXT,
String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName));
String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName));
Cat.logEvent(CatEventType.MODIFY_NAMESPACE, String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName));
}
......@@ -87,7 +87,7 @@ public class ItemService {
}
item.setNamespaceId(namespace.getId());
if (StringUtils.isEmpty(item.getDataChangeCreatedBy())){
if (StringUtils.isEmpty(item.getDataChangeCreatedBy())) {
String username = userInfoHolder.getUser().getUserId();
item.setDataChangeCreatedBy(username);
item.setDataChangeLastModifiedBy(username);
......@@ -99,7 +99,7 @@ public class ItemService {
}
public void updateItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item) {
if (StringUtils.isEmpty(item.getDataChangeLastModifiedBy())){
if (StringUtils.isEmpty(item.getDataChangeLastModifiedBy())) {
String username = userInfoHolder.getUser().getUserId();
item.setDataChangeLastModifiedBy(username);
}
......@@ -114,7 +114,7 @@ public class ItemService {
return itemAPI.findItems(appId, env, clusterName, namespaceName);
}
public ItemDTO loadItem(Env env, long itemId){
public ItemDTO loadItem(Env env, long itemId) {
return itemAPI.loadItem(env, itemId);
}
......@@ -178,7 +178,7 @@ public class ItemService {
List<ItemDTO>
targetItems =
itemAPI.findItems(namespace.getAppId(), namespace.getEnv(),
namespace.getClusterName(), namespace.getNamespaceName());
namespace.getClusterName(), namespace.getNamespaceName());
long namespaceId = getNamespaceId(namespace);
......@@ -203,7 +203,7 @@ public class ItemService {
changeSets.addCreateItem(buildItem(namespaceId, ++maxLineNum, sourceItem));
} else if (isModified(sourceValue, targetItem.getValue(), sourceComment,
targetItem.getComment())) {//modified items
targetItem.getComment())) {//modified items
targetItem.setValue(sourceValue);
targetItem.setComment(sourceComment);
changeSets.addUpdateItem(targetItem);
......
......@@ -13,7 +13,7 @@ public class NamespaceLockService {
@Autowired
private AdminServiceAPI.NamespaceLockAPI namespaceLockAPI;
public NamespaceLockDTO getNamespaceLock(String appId, Env env, String clusterName, String namespaceName){
public NamespaceLockDTO getNamespaceLock(String appId, Env env, String clusterName, String namespaceName) {
return namespaceLockAPI.getNamespaceLockOwner(appId, env, clusterName, namespaceName);
}
......
......@@ -2,12 +2,12 @@ package com.ctrip.framework.apollo.portal.service;
import com.google.gson.Gson;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.dto.NamespaceDTO;
import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.utils.StringUtils;
......@@ -53,15 +53,15 @@ public class NamespaceService {
NamespaceDTO createdNamespace = namespaceAPI.createNamespace(env, namespace);
Cat.logEvent(CatEventType.CREATE_NAMESPACE,
String.format("%s+%s+%s+%s", namespace.getAppId(), env, namespace.getClusterName(),
namespace.getNamespaceName()));
String.format("%s+%s+%s+%s", namespace.getAppId(), env, namespace.getClusterName(),
namespace.getNamespaceName()));
return createdNamespace;
}
public NamespaceDTO loadNamespaceBaseInfo(String appId, Env env, String clusterName, String namespaceName){
public NamespaceDTO loadNamespaceBaseInfo(String appId, Env env, String clusterName, String namespaceName) {
NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
if (namespace == null){
throw new BadRequestException("namespaces not existed");
if (namespace == null) {
throw new BadRequestException("namespaces not exist");
}
return namespace;
}
......@@ -73,7 +73,7 @@ public class NamespaceService {
List<NamespaceDTO> namespaces = namespaceAPI.findNamespaceByCluster(appId, env, clusterName);
if (namespaces == null || namespaces.size() == 0) {
throw new BadRequestException("namespaces not existed");
throw new BadRequestException("namespaces not exist");
}
List<NamespaceVO> namespaceVOs = new LinkedList<>();
......@@ -85,7 +85,7 @@ public class NamespaceService {
namespaceVOs.add(namespaceVO);
} catch (Exception e) {
logger.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}",
appId, env, clusterName, namespace.getNamespaceName(), e);
appId, env, clusterName, namespace.getNamespaceName(), e);
throw e;
}
}
......@@ -93,10 +93,10 @@ public class NamespaceService {
return namespaceVOs;
}
public NamespaceVO loadNamespace(String appId, Env env, String clusterName, String namespaceName){
public NamespaceVO loadNamespace(String appId, Env env, String clusterName, String namespaceName) {
NamespaceDTO namespace = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
if (namespace == null){
throw new BadRequestException("namespaces not existed");
if (namespace == null) {
throw new BadRequestException("namespaces not exist");
}
return parseNamespace(appId, env, clusterName, namespace);
}
......
......@@ -31,109 +31,109 @@ import java.util.Set;
@Service
public class ReleaseService {
private static final Gson gson = new Gson();
private static final Type configurationTypeReference =
new TypeToken<Map<String, String>>() {
}.getType();
@Autowired
private UserInfoHolder userInfoHolder;
@Autowired
private AdminServiceAPI.ReleaseAPI releaseAPI;
public ReleaseDTO createRelease(NamespaceReleaseModel model) {
String appId = model.getAppId();
Env env = model.getEnv();
String clusterName = model.getClusterName();
String namespaceName = model.getNamespaceName();
String releaseBy =
StringUtils.isEmpty(model.getReleaseBy()) ? userInfoHolder.getUser().getUserId() : model.getReleaseBy();
ReleaseDTO releaseDTO = releaseAPI
.createRelease(appId, env, clusterName, namespaceName, model.getReleaseTitle(), model.getReleaseComment()
, releaseBy);
Cat.logEvent(CatEventType.RELEASE_NAMESPACE, String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName));
return releaseDTO;
}
public List<ReleaseVO> findAllReleases(String appId, Env env, String clusterName, String namespaceName, int page,
int size) {
List<ReleaseDTO> releaseDTOs = releaseAPI.findAllReleases(appId, env, clusterName, namespaceName, page, size);
if (CollectionUtils.isEmpty(releaseDTOs)) {
return Collections.emptyList();
}
List<ReleaseVO> releases = new LinkedList<>();
for (ReleaseDTO releaseDTO : releaseDTOs) {
ReleaseVO release = new ReleaseVO();
release.setBaseInfo(releaseDTO);
Set<KVEntity> kvEntities = new LinkedHashSet<>();
Map<String, String> configurations = gson.fromJson(releaseDTO.getConfigurations(), configurationTypeReference);
Set<Map.Entry<String, String>> entries = configurations.entrySet();
for (Map.Entry<String, String> entry : entries) {
kvEntities.add(new KVEntity(entry.getKey(), entry.getValue()));
}
release.setItems(kvEntities);
//为了减少数据量
releaseDTO.setConfigurations("");
releases.add(release);
}
return releases;
}
public List<ReleaseDTO> findActiveReleases(String appId, Env env, String clusterName, String namespaceName, int page,
int size) {
return releaseAPI.findActiveReleases(appId, env, clusterName, namespaceName, page, size);
}
public ReleaseDTO loadLatestRelease(String appId, Env env, String clusterName, String namespaceName){
return releaseAPI.loadLatestRelease(appId, env, clusterName, namespaceName);
}
public void rollback(Env env, long releaseId) {
releaseAPI.rollback(env, releaseId, userInfoHolder.getUser().getUserId());
}
public ReleaseCompareResult compare(Env env, long firstReleaseId, long secondReleaseId) {
ReleaseDTO firstRelease = releaseAPI.loadRelease(env, firstReleaseId);
ReleaseDTO secondRelease = releaseAPI.loadRelease(env, secondReleaseId);
Map<String, String> firstItems = gson.fromJson(firstRelease.getConfigurations(), configurationTypeReference);
Map<String, String> secondItems = gson.fromJson(secondRelease.getConfigurations(), configurationTypeReference);
ReleaseCompareResult compareResult = new ReleaseCompareResult();
//added and modified in firstRelease
for (Map.Entry<String, String> entry : firstItems.entrySet()) {
String key = entry.getKey();
String firstValue = entry.getValue();
String secondValue = secondItems.get(key);
//added
if (secondValue == null) {
compareResult.addEntityPair(ChangeType.DELETED, new KVEntity(key, firstValue),
new KVEntity(key, secondValue));
} else if (!Objects.equal(firstValue, secondValue)) {
compareResult.addEntityPair(ChangeType.MODIFIED, new KVEntity(key, firstValue),
new KVEntity(key, secondValue));
}
}
//deleted in firstRelease
for (Map.Entry<String, String> entry : secondItems.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (firstItems.get(key) == null) {
compareResult
.addEntityPair(ChangeType.ADDED, new KVEntity(key, ""), new KVEntity(key, value));
}
}
return compareResult;
}
private static final Gson gson = new Gson();
private static final Type configurationTypeReference =
new TypeToken<Map<String, String>>() {
}.getType();
@Autowired
private UserInfoHolder userInfoHolder;
@Autowired
private AdminServiceAPI.ReleaseAPI releaseAPI;
public ReleaseDTO createRelease(NamespaceReleaseModel model) {
String appId = model.getAppId();
Env env = model.getEnv();
String clusterName = model.getClusterName();
String namespaceName = model.getNamespaceName();
String releaseBy =
StringUtils.isEmpty(model.getReleasedBy()) ? userInfoHolder.getUser().getUserId() : model.getReleasedBy();
ReleaseDTO releaseDTO = releaseAPI
.createRelease(appId, env, clusterName, namespaceName, model.getReleaseTitle(), model.getReleaseComment()
, releaseBy);
Cat.logEvent(CatEventType.RELEASE_NAMESPACE, String.format("%s+%s+%s+%s", appId, env, clusterName, namespaceName));
return releaseDTO;
}
public List<ReleaseVO> findAllReleases(String appId, Env env, String clusterName, String namespaceName, int page,
int size) {
List<ReleaseDTO> releaseDTOs = releaseAPI.findAllReleases(appId, env, clusterName, namespaceName, page, size);
if (CollectionUtils.isEmpty(releaseDTOs)) {
return Collections.emptyList();
}
List<ReleaseVO> releases = new LinkedList<>();
for (ReleaseDTO releaseDTO : releaseDTOs) {
ReleaseVO release = new ReleaseVO();
release.setBaseInfo(releaseDTO);
Set<KVEntity> kvEntities = new LinkedHashSet<>();
Map<String, String> configurations = gson.fromJson(releaseDTO.getConfigurations(), configurationTypeReference);
Set<Map.Entry<String, String>> entries = configurations.entrySet();
for (Map.Entry<String, String> entry : entries) {
kvEntities.add(new KVEntity(entry.getKey(), entry.getValue()));
}
release.setItems(kvEntities);
//为了减少数据量
releaseDTO.setConfigurations("");
releases.add(release);
}
return releases;
}
public List<ReleaseDTO> findActiveReleases(String appId, Env env, String clusterName, String namespaceName, int page,
int size) {
return releaseAPI.findActiveReleases(appId, env, clusterName, namespaceName, page, size);
}
public ReleaseDTO loadLatestRelease(String appId, Env env, String clusterName, String namespaceName) {
return releaseAPI.loadLatestRelease(appId, env, clusterName, namespaceName);
}
public void rollback(Env env, long releaseId) {
releaseAPI.rollback(env, releaseId, userInfoHolder.getUser().getUserId());
}
public ReleaseCompareResult compare(Env env, long firstReleaseId, long secondReleaseId) {
ReleaseDTO firstRelease = releaseAPI.loadRelease(env, firstReleaseId);
ReleaseDTO secondRelease = releaseAPI.loadRelease(env, secondReleaseId);
Map<String, String> firstItems = gson.fromJson(firstRelease.getConfigurations(), configurationTypeReference);
Map<String, String> secondItems = gson.fromJson(secondRelease.getConfigurations(), configurationTypeReference);
ReleaseCompareResult compareResult = new ReleaseCompareResult();
//added and modified in firstRelease
for (Map.Entry<String, String> entry : firstItems.entrySet()) {
String key = entry.getKey();
String firstValue = entry.getValue();
String secondValue = secondItems.get(key);
//added
if (secondValue == null) {
compareResult.addEntityPair(ChangeType.DELETED, new KVEntity(key, firstValue),
new KVEntity(key, secondValue));
} else if (!Objects.equal(firstValue, secondValue)) {
compareResult.addEntityPair(ChangeType.MODIFIED, new KVEntity(key, firstValue),
new KVEntity(key, secondValue));
}
}
//deleted in firstRelease
for (Map.Entry<String, String> entry : secondItems.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (firstItems.get(key) == null) {
compareResult
.addEntityPair(ChangeType.ADDED, new KVEntity(key, ""), new KVEntity(key, value));
}
}
return compareResult;
}
}
......@@ -33,7 +33,7 @@ public class RoleInitializationService {
String appMasterRoleName = RoleUtils.buildAppMasterRoleName(appId);
//has created before
if (rolePermissionService.findRoleByRoleName(appMasterRoleName) != null){
if (rolePermissionService.findRoleByRoleName(appMasterRoleName) != null) {
return;
}
String operaterUserId = userInfoHolder.getUser().getUserId();
......@@ -43,7 +43,7 @@ public class RoleInitializationService {
//assign master role to user
rolePermissionService
.assignRoleToUsers(RoleUtils.buildAppMasterRoleName(appId), Sets.newHashSet(app.getOwnerName()),
operaterUserId);
operaterUserId);
initNamespaceRoles(appId, ConfigConsts.NAMESPACE_APPLICATION);
......@@ -55,13 +55,13 @@ public class RoleInitializationService {
String modifyNamespaceRoleName = RoleUtils.buildModifyNamespaceRoleName(appId, namespaceName);
if (rolePermissionService.findRoleByRoleName(modifyNamespaceRoleName) == null) {
createDefaultNamespaceRole(appId, namespaceName, PermissionType.MODIFY_NAMESPACE,
RoleUtils.buildModifyNamespaceRoleName(appId, namespaceName));
RoleUtils.buildModifyNamespaceRoleName(appId, namespaceName));
}
String releaseNamespaceRoleName = RoleUtils.buildReleaseNamespaceRoleName(appId, namespaceName);
if (rolePermissionService.findRoleByRoleName(releaseNamespaceRoleName) == null) {
createDefaultNamespaceRole(appId, namespaceName, PermissionType.RELEASE_NAMESPACE,
RoleUtils.buildReleaseNamespaceRoleName(appId, namespaceName));
RoleUtils.buildReleaseNamespaceRoleName(appId, namespaceName));
}
}
......
package com.ctrip.framework.apollo.portal.service.txtresolver;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import org.springframework.stereotype.Component;
......
......@@ -35,7 +35,7 @@ public class PropertyResolver implements ConfigTextResolver {
String[] newItems = configText.split(ITEM_SEPARATOR);
if (isHasRepeatKey(newItems)){
if (isHasRepeatKey(newItems)) {
throw new BadRequestException("config text has repeat key please check.");
}
......@@ -71,27 +71,27 @@ public class PropertyResolver implements ConfigTextResolver {
return changeSets;
}
private boolean isHasRepeatKey(String[] newItems){
private boolean isHasRepeatKey(String[] newItems) {
Set<String> keys = new HashSet<>();
int lineCounter = 1;
int keyCount = 0;
for (String item: newItems){
if (!isCommentItem(item) && !isBlankItem(item)){
for (String item : newItems) {
if (!isCommentItem(item) && !isBlankItem(item)) {
keyCount++;
String[] kv = parseKeyValueFromItem(item);
if (kv != null) {
keys.add(kv[0]);
}else {
} else {
throw new BadRequestException("line:" + lineCounter + " key value must separate by '='");
}
}
lineCounter ++;
lineCounter++;
}
return keyCount > keys.size();
}
private String[] parseKeyValueFromItem(String item){
private String[] parseKeyValueFromItem(String item) {
int kvSeparator = item.indexOf(KV_SEPARATOR);
if (kvSeparator == -1) {
return null;
......@@ -118,7 +118,7 @@ public class PropertyResolver implements ConfigTextResolver {
}
private void handleNormalLine(Long namespaceId, Map<String, ItemDTO> keyMapOldItem, String newItem,
int lineCounter, ItemChangeSets changeSets) {
int lineCounter, ItemChangeSets changeSets) {
String[] kv = parseKeyValueFromItem(newItem);
......@@ -133,17 +133,17 @@ public class PropertyResolver implements ConfigTextResolver {
if (oldItem == null) {//new item
changeSets.addCreateItem(buildNormalItem(0l, namespaceId, newKey, newValue, "", lineCounter));
} else if (!newValue.equals(oldItem.getValue()) || lineCounter != oldItem.getLineNum()){//update item
} else if (!newValue.equals(oldItem.getValue()) || lineCounter != oldItem.getLineNum()) {//update item
changeSets.addUpdateItem(
buildNormalItem(oldItem.getId(), namespaceId, newKey, newValue, oldItem.getComment(),
lineCounter));
lineCounter));
}
keyMapOldItem.remove(newKey);
}
private boolean isCommentItem(ItemDTO item) {
return item != null && "".equals(item.getKey())
&& (item.getComment().startsWith("#") || item.getComment().startsWith("!"));
&& (item.getComment().startsWith("#") || item.getComment().startsWith("!"));
}
private boolean isCommentItem(String line) {
......
......@@ -9,38 +9,39 @@ public class RoleUtils {
private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR);
public static String buildAppMasterRoleName(String appId){
public static String buildAppMasterRoleName(String appId) {
return STRING_JOINER.join(RoleType.MASTER, appId);
}
public static String buildAppRoleName(String appId, String roleType){
public static String buildAppRoleName(String appId, String roleType) {
return STRING_JOINER.join(roleType, appId);
}
public static String buildModifyNamespaceRoleName(String appId, String namespaceName){
public static String buildModifyNamespaceRoleName(String appId, String namespaceName) {
return STRING_JOINER.join(RoleType.MODIFY_NAMESPACE, appId, namespaceName);
}
public static String buildModifyDefaultNamespaceRoleName(String appId){
public static String buildModifyDefaultNamespaceRoleName(String appId) {
return STRING_JOINER.join(RoleType.MODIFY_NAMESPACE, appId, ConfigConsts.NAMESPACE_APPLICATION);
}
public static String buildReleaseNamespaceRoleName(String appId, String namespaceName){
public static String buildReleaseNamespaceRoleName(String appId, String namespaceName) {
return STRING_JOINER.join(RoleType.RELEASE_NAMESPACE, appId, namespaceName);
}
public static String buildNamespaceRoleName(String appId, String namespaceName, String roleType){
public static String buildNamespaceRoleName(String appId, String namespaceName, String roleType) {
return STRING_JOINER.join(roleType, appId, namespaceName);
}
public static String buildReleaseDefaultNamespaceRoleName(String appId){
public static String buildReleaseDefaultNamespaceRoleName(String appId) {
return STRING_JOINER.join(RoleType.RELEASE_NAMESPACE, appId, ConfigConsts.NAMESPACE_APPLICATION);
}
public static String buildNamespaceTargetId(String appId, String namespaceName){
public static String buildNamespaceTargetId(String appId, String namespaceName) {
return STRING_JOINER.join(appId, namespaceName);
}
public static String buildDefaultNamespaceTargetId(String appId){
public static String buildDefaultNamespaceTargetId(String appId) {
return STRING_JOINER.join(appId, ConfigConsts.NAMESPACE_APPLICATION);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册