Commit afa2a683 authored by Jason Song's avatar Jason Song

code reformat

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