Commit d9275527 authored by kezhenxu94's avatar kezhenxu94 Committed by Jason Song

enhancement: use constructor injection instead of field injection (#1839)

* enhancement: use constructor injection instead of field injection

* remove unused field
parent 1dc461f0
package com.ctrip.framework.apollo.adminservice; package com.ctrip.framework.apollo.adminservice;
import com.ctrip.framework.apollo.biz.service.AppService; import com.ctrip.framework.apollo.biz.service.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
...@@ -11,8 +9,11 @@ import org.springframework.stereotype.Component; ...@@ -11,8 +9,11 @@ import org.springframework.stereotype.Component;
@Component @Component
public class AdminServiceHealthIndicator implements HealthIndicator { public class AdminServiceHealthIndicator implements HealthIndicator {
@Autowired private final AppService appService;
private AppService appService;
public AdminServiceHealthIndicator(final AppService appService) {
this.appService = appService;
}
@Override @Override
public Health health() { public Health health() {
......
...@@ -12,12 +12,10 @@ import com.ctrip.framework.apollo.common.dto.ItemChangeSets; ...@@ -12,12 +12,10 @@ 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.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 org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -31,15 +29,21 @@ import org.springframework.stereotype.Component; ...@@ -31,15 +29,21 @@ import org.springframework.stereotype.Component;
public class NamespaceAcquireLockAspect { public class NamespaceAcquireLockAspect {
private static final Logger logger = LoggerFactory.getLogger(NamespaceAcquireLockAspect.class); private static final Logger logger = LoggerFactory.getLogger(NamespaceAcquireLockAspect.class);
private final NamespaceLockService namespaceLockService;
@Autowired private final NamespaceService namespaceService;
private NamespaceLockService namespaceLockService; private final ItemService itemService;
@Autowired private final BizConfig bizConfig;
private NamespaceService namespaceService;
@Autowired public NamespaceAcquireLockAspect(
private ItemService itemService; final NamespaceLockService namespaceLockService,
@Autowired final NamespaceService namespaceService,
private BizConfig bizConfig; final ItemService itemService,
final BizConfig bizConfig) {
this.namespaceLockService = namespaceLockService;
this.namespaceService = namespaceService;
this.itemService = itemService;
this.bizConfig = bizConfig;
}
//create item //create item
......
package com.ctrip.framework.apollo.adminservice.aop; package com.ctrip.framework.apollo.adminservice.aop;
import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.ctrip.framework.apollo.biz.config.BizConfig; import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.entity.Item; import com.ctrip.framework.apollo.biz.entity.Item;
import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.entity.Namespace;
...@@ -18,10 +14,11 @@ import com.ctrip.framework.apollo.common.dto.ItemChangeSets; ...@@ -18,10 +14,11 @@ 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.exception.BadRequestException; 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.google.common.collect.MapDifference;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
...@@ -42,16 +39,24 @@ public class NamespaceUnlockAspect { ...@@ -42,16 +39,24 @@ public class NamespaceUnlockAspect {
private Gson gson = new Gson(); private Gson gson = new Gson();
@Autowired private final NamespaceLockService namespaceLockService;
private NamespaceLockService namespaceLockService; private final NamespaceService namespaceService;
@Autowired private final ItemService itemService;
private NamespaceService namespaceService; private final ReleaseService releaseService;
@Autowired private final BizConfig bizConfig;
private ItemService itemService;
@Autowired public NamespaceUnlockAspect(
private ReleaseService releaseService; final NamespaceLockService namespaceLockService,
@Autowired final NamespaceService namespaceService,
private BizConfig bizConfig; final ItemService itemService,
final ReleaseService releaseService,
final BizConfig bizConfig) {
this.namespaceLockService = namespaceLockService;
this.namespaceService = namespaceService;
this.itemService = itemService;
this.releaseService = releaseService;
this.bizConfig = bizConfig;
}
//create item //create item
......
...@@ -9,7 +9,6 @@ import com.ctrip.framework.apollo.common.exception.NotFoundException; ...@@ -9,7 +9,6 @@ import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.InputValidator; import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -26,11 +25,13 @@ import java.util.Objects; ...@@ -26,11 +25,13 @@ import java.util.Objects;
@RestController @RestController
public class AppController { public class AppController {
@Autowired private final AppService appService;
private AppService appService; private final AdminService adminService;
@Autowired public AppController(final AppService appService, final AdminService adminService) {
private AdminService adminService; this.appService = appService;
this.adminService = adminService;
}
@PostMapping("/apps") @PostMapping("/apps")
public AppDTO create(@RequestBody AppDTO dto) { public AppDTO create(@RequestBody AppDTO dto) {
......
...@@ -10,7 +10,6 @@ import com.ctrip.framework.apollo.common.exception.BadRequestException; ...@@ -10,7 +10,6 @@ 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.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -25,10 +24,15 @@ import java.util.List; ...@@ -25,10 +24,15 @@ import java.util.List;
@RestController @RestController
public class AppNamespaceController { public class AppNamespaceController {
@Autowired private final AppNamespaceService appNamespaceService;
private AppNamespaceService appNamespaceService; private final NamespaceService namespaceService;
@Autowired
private NamespaceService namespaceService; public AppNamespaceController(
final AppNamespaceService appNamespaceService,
final NamespaceService namespaceService) {
this.appNamespaceService = appNamespaceService;
this.namespaceService = namespaceService;
}
@PostMapping("/apps/{appId}/appnamespaces") @PostMapping("/apps/{appId}/appnamespaces")
public AppNamespaceDTO create(@RequestBody AppNamespaceDTO appNamespace, public AppNamespaceDTO create(@RequestBody AppNamespaceDTO appNamespace,
......
...@@ -8,7 +8,6 @@ import com.ctrip.framework.apollo.common.exception.NotFoundException; ...@@ -8,7 +8,6 @@ import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.InputValidator; import com.ctrip.framework.apollo.common.utils.InputValidator;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -22,8 +21,11 @@ import java.util.List; ...@@ -22,8 +21,11 @@ import java.util.List;
@RestController @RestController
public class ClusterController { public class ClusterController {
@Autowired private final ClusterService clusterService;
private ClusterService clusterService;
public ClusterController(final ClusterService clusterService) {
this.clusterService = clusterService;
}
@PostMapping("/apps/{appId}/clusters") @PostMapping("/apps/{appId}/clusters")
public ClusterDTO create(@PathVariable("appId") String appId, public ClusterDTO create(@PathVariable("appId") String appId,
......
...@@ -4,7 +4,6 @@ import com.ctrip.framework.apollo.biz.entity.Commit; ...@@ -4,7 +4,6 @@ import com.ctrip.framework.apollo.biz.entity.Commit;
import com.ctrip.framework.apollo.biz.service.CommitService; import com.ctrip.framework.apollo.biz.service.CommitService;
import com.ctrip.framework.apollo.common.dto.CommitDTO; import com.ctrip.framework.apollo.common.dto.CommitDTO;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -16,8 +15,11 @@ import java.util.List; ...@@ -16,8 +15,11 @@ import java.util.List;
@RestController @RestController
public class CommitController { public class CommitController {
@Autowired private final CommitService commitService;
private CommitService commitService;
public CommitController(final CommitService commitService) {
this.commitService = commitService;
}
@GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit") @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit")
public List<CommitDTO> find(@PathVariable String appId, @PathVariable String clusterName, public List<CommitDTO> find(@PathVariable String appId, @PathVariable String clusterName,
......
...@@ -17,7 +17,6 @@ import com.google.common.collect.HashMultimap; ...@@ -17,7 +17,6 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -42,10 +41,13 @@ import java.util.stream.Collectors; ...@@ -42,10 +41,13 @@ import java.util.stream.Collectors;
public class InstanceConfigController { public class InstanceConfigController {
private static final Splitter RELEASES_SPLITTER = Splitter.on(",").omitEmptyStrings() private static final Splitter RELEASES_SPLITTER = Splitter.on(",").omitEmptyStrings()
.trimResults(); .trimResults();
@Autowired private final ReleaseService releaseService;
private ReleaseService releaseService; private final InstanceService instanceService;
@Autowired
private InstanceService instanceService; public InstanceConfigController(final ReleaseService releaseService, final InstanceService instanceService) {
this.releaseService = releaseService;
this.instanceService = instanceService;
}
@GetMapping("/by-release") @GetMapping("/by-release")
public PageDTO<InstanceDTO> getByRelease(@RequestParam("releaseId") long releaseId, public PageDTO<InstanceDTO> getByRelease(@RequestParam("releaseId") long releaseId,
......
...@@ -12,7 +12,6 @@ import com.ctrip.framework.apollo.common.dto.ItemDTO; ...@@ -12,7 +12,6 @@ import com.ctrip.framework.apollo.common.dto.ItemDTO;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -27,12 +26,15 @@ import java.util.List; ...@@ -27,12 +26,15 @@ import java.util.List;
@RestController @RestController
public class ItemController { public class ItemController {
@Autowired private final ItemService itemService;
private ItemService itemService; private final NamespaceService namespaceService;
@Autowired private final CommitService commitService;
private NamespaceService namespaceService;
@Autowired public ItemController(final ItemService itemService, final NamespaceService namespaceService, final CommitService commitService) {
private CommitService commitService; this.itemService = itemService;
this.namespaceService = namespaceService;
this.commitService = commitService;
}
@PreAcquireNamespaceLock @PreAcquireNamespaceLock
@PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items") @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items")
......
...@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.adminservice.controller; ...@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.adminservice.controller;
import com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock; import com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock;
import com.ctrip.framework.apollo.biz.service.ItemSetService; import com.ctrip.framework.apollo.biz.service.ItemSetService;
import com.ctrip.framework.apollo.common.dto.ItemChangeSets; import com.ctrip.framework.apollo.common.dto.ItemChangeSets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -14,8 +13,11 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -14,8 +13,11 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class ItemSetController { public class ItemSetController {
@Autowired private final ItemSetService itemSetService;
private ItemSetService itemSetService;
public ItemSetController(final ItemSetService itemSetService) {
this.itemSetService = itemSetService;
}
@PreAcquireNamespaceLock @PreAcquireNamespaceLock
@PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset") @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset")
......
...@@ -13,7 +13,6 @@ import com.ctrip.framework.apollo.common.dto.NamespaceDTO; ...@@ -13,7 +13,6 @@ 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.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.GrayReleaseRuleItemTransformer; import com.ctrip.framework.apollo.common.utils.GrayReleaseRuleItemTransformer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -27,12 +26,18 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -27,12 +26,18 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class NamespaceBranchController { public class NamespaceBranchController {
@Autowired private final MessageSender messageSender;
private MessageSender messageSender; private final NamespaceBranchService namespaceBranchService;
@Autowired private final NamespaceService namespaceService;
private NamespaceBranchService namespaceBranchService;
@Autowired public NamespaceBranchController(
private NamespaceService namespaceService; final MessageSender messageSender,
final NamespaceBranchService namespaceBranchService,
final NamespaceService namespaceService) {
this.messageSender = messageSender;
this.namespaceBranchService = namespaceBranchService;
this.namespaceService = namespaceService;
}
@PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches") @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches")
......
...@@ -7,7 +7,6 @@ import com.ctrip.framework.apollo.common.exception.BadRequestException; ...@@ -7,7 +7,6 @@ import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.common.utils.InputValidator; import com.ctrip.framework.apollo.common.utils.InputValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -22,8 +21,11 @@ import java.util.Map; ...@@ -22,8 +21,11 @@ import java.util.Map;
@RestController @RestController
public class NamespaceController { public class NamespaceController {
@Autowired private final NamespaceService namespaceService;
private NamespaceService namespaceService;
public NamespaceController(final NamespaceService namespaceService) {
this.namespaceService = namespaceService;
}
@PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces") @PostMapping("/apps/{appId}/clusters/{clusterName}/namespaces")
public NamespaceDTO create(@PathVariable("appId") String appId, public NamespaceDTO create(@PathVariable("appId") String appId,
......
...@@ -8,7 +8,6 @@ import com.ctrip.framework.apollo.biz.service.NamespaceService; ...@@ -8,7 +8,6 @@ import com.ctrip.framework.apollo.biz.service.NamespaceService;
import com.ctrip.framework.apollo.common.dto.NamespaceLockDTO; import com.ctrip.framework.apollo.common.dto.NamespaceLockDTO;
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.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -16,13 +15,18 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -16,13 +15,18 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class NamespaceLockController { public class NamespaceLockController {
private final NamespaceLockService namespaceLockService;
@Autowired private final NamespaceService namespaceService;
private NamespaceLockService namespaceLockService; private final BizConfig bizConfig;
@Autowired
private NamespaceService namespaceService; public NamespaceLockController(
@Autowired final NamespaceLockService namespaceLockService,
private BizConfig bizConfig; final NamespaceService namespaceService,
final BizConfig bizConfig) {
this.namespaceLockService = namespaceLockService;
this.namespaceService = namespaceService;
this.bizConfig = bizConfig;
}
@GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock") @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock")
public NamespaceLockDTO getNamespaceLockOwner(@PathVariable String appId, @PathVariable String clusterName, public NamespaceLockDTO getNamespaceLockOwner(@PathVariable String appId, @PathVariable String clusterName,
......
...@@ -15,7 +15,6 @@ import com.ctrip.framework.apollo.common.dto.ReleaseDTO; ...@@ -15,7 +15,6 @@ import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -36,15 +35,21 @@ public class ReleaseController { ...@@ -36,15 +35,21 @@ public class ReleaseController {
private static final Splitter RELEASES_SPLITTER = Splitter.on(",").omitEmptyStrings() private static final Splitter RELEASES_SPLITTER = Splitter.on(",").omitEmptyStrings()
.trimResults(); .trimResults();
private final ReleaseService releaseService;
@Autowired private final NamespaceService namespaceService;
private ReleaseService releaseService; private final MessageSender messageSender;
@Autowired private final NamespaceBranchService namespaceBranchService;
private NamespaceService namespaceService;
@Autowired public ReleaseController(
private MessageSender messageSender; final ReleaseService releaseService,
@Autowired final NamespaceService namespaceService,
private NamespaceBranchService namespaceBranchService; final MessageSender messageSender,
final NamespaceBranchService namespaceBranchService) {
this.releaseService = releaseService;
this.namespaceService = namespaceService;
this.messageSender = messageSender;
this.namespaceBranchService = namespaceBranchService;
}
@GetMapping("/releases/{releaseId}") @GetMapping("/releases/{releaseId}")
......
...@@ -7,7 +7,6 @@ import com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO; ...@@ -7,7 +7,6 @@ import com.ctrip.framework.apollo.common.dto.ReleaseHistoryDTO;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -30,8 +29,11 @@ public class ReleaseHistoryController { ...@@ -30,8 +29,11 @@ public class ReleaseHistoryController {
private Type configurationTypeReference = new TypeToken<Map<String, Object>>() { private Type configurationTypeReference = new TypeToken<Map<String, Object>>() {
}.getType(); }.getType();
@Autowired private final ReleaseHistoryService releaseHistoryService;
private ReleaseHistoryService releaseHistoryService;
public ReleaseHistoryController(final ReleaseHistoryService releaseHistoryService) {
this.releaseHistoryService = releaseHistoryService;
}
@GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/histories") @GetMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/histories")
public PageDTO<ReleaseHistoryDTO> findReleaseHistoriesByNamespace( public PageDTO<ReleaseHistoryDTO> findReleaseHistoriesByNamespace(
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.ctrip.framework.apollo.biz.entity.Cluster; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.service.ClusterService; import com.ctrip.framework.apollo.biz.service.ClusterService;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
...@@ -13,7 +8,9 @@ import org.junit.Before; ...@@ -13,7 +8,9 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.springframework.test.util.ReflectionTestUtils;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
public class ClusterControllerTest { public class ClusterControllerTest {
private ClusterController clusterController; private ClusterController clusterController;
...@@ -23,10 +20,8 @@ public class ClusterControllerTest { ...@@ -23,10 +20,8 @@ public class ClusterControllerTest {
@Before @Before
public void setUp() { public void setUp() {
clusterController = new ClusterController();
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
clusterController = new ClusterController(clusterService);
ReflectionTestUtils.setField(clusterController, "clusterService", clusterService);
} }
......
...@@ -6,7 +6,6 @@ import com.ctrip.framework.apollo.common.dto.AppDTO; ...@@ -6,7 +6,6 @@ import com.ctrip.framework.apollo.common.dto.AppDTO;
import com.ctrip.framework.apollo.common.entity.App; import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.exception.ServiceException; import com.ctrip.framework.apollo.common.exception.ServiceException;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -15,7 +14,6 @@ import org.mockito.Mock; ...@@ -15,7 +14,6 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -36,9 +34,7 @@ public class ControllerExceptionTest { ...@@ -36,9 +34,7 @@ public class ControllerExceptionTest {
@Before @Before
public void setUp() { public void setUp() {
appController = new AppController(); appController = new AppController(appService, adminService);
ReflectionTestUtils.setField(appController, "appService", appService);
ReflectionTestUtils.setField(appController, "adminService", adminService);
} }
@Test(expected = NotFoundException.class) @Test(expected = NotFoundException.class)
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.ctrip.framework.apollo.biz.entity.Instance; import com.ctrip.framework.apollo.biz.entity.Instance;
import com.ctrip.framework.apollo.biz.entity.InstanceConfig; import com.ctrip.framework.apollo.biz.entity.InstanceConfig;
import com.ctrip.framework.apollo.biz.entity.Release; import com.ctrip.framework.apollo.biz.entity.Release;
...@@ -12,7 +8,9 @@ import com.ctrip.framework.apollo.biz.service.ReleaseService; ...@@ -12,7 +8,9 @@ import com.ctrip.framework.apollo.biz.service.ReleaseService;
import com.ctrip.framework.apollo.common.dto.InstanceDTO; import com.ctrip.framework.apollo.common.dto.InstanceDTO;
import com.ctrip.framework.apollo.common.dto.PageDTO; import com.ctrip.framework.apollo.common.dto.PageDTO;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -22,7 +20,6 @@ import org.springframework.data.domain.Page; ...@@ -22,7 +20,6 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
...@@ -52,9 +49,7 @@ public class InstanceConfigControllerTest { ...@@ -52,9 +49,7 @@ public class InstanceConfigControllerTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
instanceConfigController = new InstanceConfigController(); instanceConfigController = new InstanceConfigController(releaseService, instanceService);
ReflectionTestUtils.setField(instanceConfigController, "releaseService", releaseService);
ReflectionTestUtils.setField(instanceConfigController, "instanceService", instanceService);
pageable = PageRequest.of(0, 2); pageable = PageRequest.of(0, 2);
} }
......
package com.ctrip.framework.apollo.adminservice.controller; package com.ctrip.framework.apollo.adminservice.controller;
import com.google.common.base.Joiner;
import com.google.gson.Gson;
import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.message.MessageSender; import com.ctrip.framework.apollo.biz.message.MessageSender;
import com.ctrip.framework.apollo.biz.message.Topics; import com.ctrip.framework.apollo.biz.message.Topics;
...@@ -15,7 +12,8 @@ import com.ctrip.framework.apollo.common.dto.ItemDTO; ...@@ -15,7 +12,8 @@ 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.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.google.common.base.Joiner;
import com.google.gson.Gson;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -26,17 +24,13 @@ import org.springframework.http.MediaType; ...@@ -26,17 +24,13 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase; import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class ReleaseControllerTest extends AbstractControllerTest { public class ReleaseControllerTest extends AbstractControllerTest {
...@@ -112,10 +106,7 @@ public class ReleaseControllerTest extends AbstractControllerTest { ...@@ -112,10 +106,7 @@ public class ReleaseControllerTest extends AbstractControllerTest {
MessageSender someMessageSender = mock(MessageSender.class); MessageSender someMessageSender = mock(MessageSender.class);
Namespace someNamespace = mock(Namespace.class); Namespace someNamespace = mock(Namespace.class);
ReleaseController releaseController = new ReleaseController(); ReleaseController releaseController = new ReleaseController(someReleaseService, someNamespaceService, someMessageSender, null);
ReflectionTestUtils.setField(releaseController, "releaseService", someReleaseService);
ReflectionTestUtils.setField(releaseController, "namespaceService", someNamespaceService);
ReflectionTestUtils.setField(releaseController, "messageSender", someMessageSender);
when(someNamespaceService.findOne(someAppId, someCluster, someNamespaceName)) when(someNamespaceService.findOne(someAppId, someCluster, someNamespaceName))
.thenReturn(someNamespace); .thenReturn(someNamespace);
......
package com.ctrip.framework.apollo.biz.config; package com.ctrip.framework.apollo.biz.config;
import com.ctrip.framework.apollo.biz.service.BizDBPropertySource;
import com.ctrip.framework.apollo.common.config.RefreshableConfig;
import com.ctrip.framework.apollo.common.config.RefreshablePropertySource;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.ctrip.framework.apollo.biz.service.BizDBPropertySource;
import com.ctrip.framework.apollo.common.config.RefreshableConfig;
import com.ctrip.framework.apollo.common.config.RefreshablePropertySource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.lang.reflect.Type; import java.lang.reflect.Type;
...@@ -36,8 +33,11 @@ public class BizConfig extends RefreshableConfig { ...@@ -36,8 +33,11 @@ public class BizConfig extends RefreshableConfig {
new TypeToken<Map<Long, Integer>>() { new TypeToken<Map<Long, Integer>>() {
}.getType(); }.getType();
@Autowired private final BizDBPropertySource propertySource;
private BizDBPropertySource propertySource;
public BizConfig(final BizDBPropertySource propertySource) {
this.propertySource = propertySource;
}
@Override @Override
protected List<RefreshablePropertySource> getRefreshablePropertySources() { protected List<RefreshablePropertySource> getRefreshablePropertySources() {
......
...@@ -2,8 +2,6 @@ package com.ctrip.framework.apollo.biz.customize; ...@@ -2,8 +2,6 @@ package com.ctrip.framework.apollo.biz.customize;
import com.ctrip.framework.apollo.biz.config.BizConfig; import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.common.customize.LoggingCustomizer; import com.ctrip.framework.apollo.common.customize.LoggingCustomizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -11,10 +9,11 @@ import org.springframework.stereotype.Component; ...@@ -11,10 +9,11 @@ import org.springframework.stereotype.Component;
@Profile("ctrip") @Profile("ctrip")
public class BizLoggingCustomizer extends LoggingCustomizer{ public class BizLoggingCustomizer extends LoggingCustomizer{
private final BizConfig bizConfig;
@Autowired public BizLoggingCustomizer(final BizConfig bizConfig) {
private BizConfig bizConfig; this.bizConfig = bizConfig;
}
@Override @Override
protected String cloggingUrl() { protected String cloggingUrl() {
......
...@@ -2,8 +2,6 @@ package com.ctrip.framework.apollo.biz.eureka; ...@@ -2,8 +2,6 @@ package com.ctrip.framework.apollo.biz.eureka;
import com.ctrip.framework.apollo.biz.config.BizConfig; import com.ctrip.framework.apollo.biz.config.BizConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean; import org.springframework.cloud.netflix.eureka.EurekaClientConfigBean;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -15,8 +13,11 @@ import java.util.List; ...@@ -15,8 +13,11 @@ import java.util.List;
@Primary @Primary
public class ApolloEurekaClientConfig extends EurekaClientConfigBean { public class ApolloEurekaClientConfig extends EurekaClientConfigBean {
@Autowired private final BizConfig bizConfig;
private BizConfig bizConfig;
public ApolloEurekaClientConfig(final BizConfig bizConfig) {
this.bizConfig = bizConfig;
}
/** /**
* Assert only one zone: defaultZone, but multiple environments. * Assert only one zone: defaultZone, but multiple environments.
......
package com.ctrip.framework.apollo.biz.message; package com.ctrip.framework.apollo.biz.message;
import com.google.common.collect.Queues;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.tracer.Tracer; import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction; import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.google.common.collect.Queues;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
...@@ -22,8 +20,6 @@ import java.util.concurrent.Executors; ...@@ -22,8 +20,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.PostConstruct;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
...@@ -35,12 +31,12 @@ public class DatabaseMessageSender implements MessageSender { ...@@ -35,12 +31,12 @@ public class DatabaseMessageSender implements MessageSender {
private final ExecutorService cleanExecutorService; private final ExecutorService cleanExecutorService;
private final AtomicBoolean cleanStopped; private final AtomicBoolean cleanStopped;
@Autowired private final ReleaseMessageRepository releaseMessageRepository;
private ReleaseMessageRepository releaseMessageRepository;
public DatabaseMessageSender() { public DatabaseMessageSender(final ReleaseMessageRepository releaseMessageRepository) {
cleanExecutorService = Executors.newSingleThreadExecutor(ApolloThreadFactory.create("DatabaseMessageSender", true)); cleanExecutorService = Executors.newSingleThreadExecutor(ApolloThreadFactory.create("DatabaseMessageSender", true));
cleanStopped = new AtomicBoolean(false); cleanStopped = new AtomicBoolean(false);
this.releaseMessageRepository = releaseMessageRepository;
} }
@Override @Override
......
...@@ -3,10 +3,9 @@ package com.ctrip.framework.apollo.biz.service; ...@@ -3,10 +3,9 @@ package com.ctrip.framework.apollo.biz.service;
import com.ctrip.framework.apollo.biz.entity.Cluster; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.common.entity.App; import com.ctrip.framework.apollo.common.entity.App;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -15,18 +14,24 @@ import java.util.Objects; ...@@ -15,18 +14,24 @@ import java.util.Objects;
@Service @Service
public class AdminService { public class AdminService {
@Autowired
private AppService appService;
@Autowired
private AppNamespaceService appNamespaceService;
@Autowired
private ClusterService clusterService;
@Autowired
private NamespaceService namespaceService;
private final static Logger logger = LoggerFactory.getLogger(AdminService.class); private final static Logger logger = LoggerFactory.getLogger(AdminService.class);
private final AppService appService;
private final AppNamespaceService appNamespaceService;
private final ClusterService clusterService;
private final NamespaceService namespaceService;
public AdminService(
final AppService appService,
final @Lazy AppNamespaceService appNamespaceService,
final @Lazy ClusterService clusterService,
final @Lazy NamespaceService namespaceService) {
this.appService = appService;
this.appNamespaceService = appNamespaceService;
this.clusterService = clusterService;
this.namespaceService = namespaceService;
}
@Transactional @Transactional
public App createNewApp(App app) { public App createNewApp(App app) {
String createBy = app.getDataChangeCreatedBy(); String createBy = app.getDataChangeCreatedBy();
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Cluster; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.entity.Namespace;
...@@ -13,10 +10,11 @@ import com.ctrip.framework.apollo.common.utils.BeanUtils; ...@@ -13,10 +10,11 @@ import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -30,14 +28,21 @@ public class AppNamespaceService { ...@@ -30,14 +28,21 @@ public class AppNamespaceService {
private static final Logger logger = LoggerFactory.getLogger(AppNamespaceService.class); private static final Logger logger = LoggerFactory.getLogger(AppNamespaceService.class);
@Autowired private final AppNamespaceRepository appNamespaceRepository;
private AppNamespaceRepository appNamespaceRepository; private final NamespaceService namespaceService;
@Autowired private final ClusterService clusterService;
private NamespaceService namespaceService; private final AuditService auditService;
@Autowired
private ClusterService clusterService; public AppNamespaceService(
@Autowired final AppNamespaceRepository appNamespaceRepository,
private AuditService auditService; final @Lazy NamespaceService namespaceService,
final @Lazy ClusterService clusterService,
final AuditService auditService) {
this.appNamespaceRepository = appNamespaceRepository;
this.namespaceService = namespaceService;
this.clusterService = clusterService;
this.auditService = auditService;
}
public boolean isAppNamespaceNameUnique(String appId, String namespaceName) { public boolean isAppNamespaceNameUnique(String appId, String namespaceName) {
Objects.requireNonNull(appId, "AppId must not be null"); Objects.requireNonNull(appId, "AppId must not be null");
......
...@@ -5,8 +5,6 @@ import com.ctrip.framework.apollo.biz.repository.AppRepository; ...@@ -5,8 +5,6 @@ import com.ctrip.framework.apollo.biz.repository.AppRepository;
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.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.ServiceException; import com.ctrip.framework.apollo.common.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -18,17 +16,19 @@ import java.util.Objects; ...@@ -18,17 +16,19 @@ import java.util.Objects;
@Service @Service
public class AppService { public class AppService {
@Autowired private final AppRepository appRepository;
private AppRepository appRepository; private final AuditService auditService;
@Autowired public AppService(final AppRepository appRepository, final AuditService auditService) {
private AuditService auditService; this.appRepository = appRepository;
this.auditService = auditService;
}
public boolean isAppIdUnique(String appId) { public boolean isAppIdUnique(String appId) {
Objects.requireNonNull(appId, "AppId must not be null"); Objects.requireNonNull(appId, "AppId must not be null");
return Objects.isNull(appRepository.findByAppId(appId)); return Objects.isNull(appRepository.findByAppId(appId));
} }
@Transactional @Transactional
public void delete(long id, String operator) { public void delete(long id, String operator) {
App app = appRepository.findById(id).orElse(null); App app = appRepository.findById(id).orElse(null);
...@@ -63,10 +63,10 @@ public class AppService { ...@@ -63,10 +63,10 @@ public class AppService {
} }
entity.setId(0);//protection entity.setId(0);//protection
App app = appRepository.save(entity); App app = appRepository.save(entity);
auditService.audit(App.class.getSimpleName(), app.getId(), Audit.OP.INSERT, auditService.audit(App.class.getSimpleName(), app.getId(), Audit.OP.INSERT,
app.getDataChangeCreatedBy()); app.getDataChangeCreatedBy());
return app; return app;
} }
...@@ -87,9 +87,9 @@ public class AppService { ...@@ -87,9 +87,9 @@ public class AppService {
managedApp.setDataChangeLastModifiedBy(app.getDataChangeLastModifiedBy()); managedApp.setDataChangeLastModifiedBy(app.getDataChangeLastModifiedBy());
managedApp = appRepository.save(managedApp); managedApp = appRepository.save(managedApp);
auditService.audit(App.class.getSimpleName(), managedApp.getId(), Audit.OP.UPDATE, auditService.audit(App.class.getSimpleName(), managedApp.getId(), Audit.OP.UPDATE,
managedApp.getDataChangeLastModifiedBy()); managedApp.getDataChangeLastModifiedBy());
} }
} }
...@@ -2,8 +2,6 @@ package com.ctrip.framework.apollo.biz.service; ...@@ -2,8 +2,6 @@ package com.ctrip.framework.apollo.biz.service;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.repository.AuditRepository; import com.ctrip.framework.apollo.biz.repository.AuditRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -12,8 +10,11 @@ import java.util.List; ...@@ -12,8 +10,11 @@ import java.util.List;
@Service @Service
public class AuditService { public class AuditService {
@Autowired private final AuditRepository auditRepository;
private AuditRepository auditRepository;
public AuditService(final AuditRepository auditRepository) {
this.auditRepository = auditRepository;
}
List<Audit> findByOwner(String owner) { List<Audit> findByOwner(String owner) {
return auditRepository.findByOwner(owner); return auditRepository.findByOwner(owner);
...@@ -32,7 +33,7 @@ public class AuditService { ...@@ -32,7 +33,7 @@ public class AuditService {
audit.setDataChangeCreatedBy(owner); audit.setDataChangeCreatedBy(owner);
auditRepository.save(audit); auditRepository.save(audit);
} }
@Transactional @Transactional
void audit(Audit audit){ void audit(Audit audit){
auditRepository.save(audit); auditRepository.save(audit);
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.google.common.base.Strings;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Cluster; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.repository.ClusterRepository; import com.ctrip.framework.apollo.biz.repository.ClusterRepository;
...@@ -9,8 +7,8 @@ import com.ctrip.framework.apollo.common.exception.BadRequestException; ...@@ -9,8 +7,8 @@ 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.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.google.common.base.Strings;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -21,12 +19,18 @@ import java.util.Objects; ...@@ -21,12 +19,18 @@ import java.util.Objects;
@Service @Service
public class ClusterService { public class ClusterService {
@Autowired private final ClusterRepository clusterRepository;
private ClusterRepository clusterRepository; private final AuditService auditService;
@Autowired private final NamespaceService namespaceService;
private AuditService auditService;
@Autowired public ClusterService(
private NamespaceService namespaceService; final ClusterRepository clusterRepository,
final AuditService auditService,
final @Lazy NamespaceService namespaceService) {
this.clusterRepository = clusterRepository;
this.auditService = auditService;
this.namespaceService = namespaceService;
}
public boolean isClusterNameUnique(String appId, String clusterName) { public boolean isClusterNameUnique(String appId, String clusterName) {
......
...@@ -2,8 +2,6 @@ package com.ctrip.framework.apollo.biz.service; ...@@ -2,8 +2,6 @@ package com.ctrip.framework.apollo.biz.service;
import com.ctrip.framework.apollo.biz.entity.Commit; import com.ctrip.framework.apollo.biz.entity.Commit;
import com.ctrip.framework.apollo.biz.repository.CommitRepository; import com.ctrip.framework.apollo.biz.repository.CommitRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -13,8 +11,11 @@ import java.util.List; ...@@ -13,8 +11,11 @@ import java.util.List;
@Service @Service
public class CommitService { public class CommitService {
@Autowired private final CommitRepository commitRepository;
private CommitRepository commitRepository;
public CommitService(final CommitRepository commitRepository) {
this.commitRepository = commitRepository;
}
@Transactional @Transactional
public Commit save(Commit commit){ public Commit save(Commit commit){
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.ctrip.framework.apollo.biz.entity.Instance; import com.ctrip.framework.apollo.biz.entity.Instance;
import com.ctrip.framework.apollo.biz.entity.InstanceConfig; import com.ctrip.framework.apollo.biz.entity.InstanceConfig;
import com.ctrip.framework.apollo.biz.repository.InstanceConfigRepository; import com.ctrip.framework.apollo.biz.repository.InstanceConfigRepository;
import com.ctrip.framework.apollo.biz.repository.InstanceRepository; import com.ctrip.framework.apollo.biz.repository.InstanceRepository;
import com.google.common.base.Preconditions;
import org.springframework.beans.factory.annotation.Autowired; import com.google.common.collect.Lists;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -29,11 +26,15 @@ import java.util.stream.Collectors; ...@@ -29,11 +26,15 @@ import java.util.stream.Collectors;
*/ */
@Service @Service
public class InstanceService { public class InstanceService {
@Autowired private final InstanceRepository instanceRepository;
private InstanceRepository instanceRepository; private final InstanceConfigRepository instanceConfigRepository;
@Autowired public InstanceService(
private InstanceConfigRepository instanceConfigRepository; final InstanceRepository instanceRepository,
final InstanceConfigRepository instanceConfigRepository) {
this.instanceRepository = instanceRepository;
this.instanceConfigRepository = instanceConfigRepository;
}
public Instance findInstance(String appId, String clusterName, String dataCenter, String ip) { public Instance findInstance(String appId, String clusterName, String dataCenter, String ip) {
return instanceRepository.findByAppIdAndClusterNameAndDataCenterAndIp(appId, clusterName, return instanceRepository.findByAppIdAndClusterNameAndDataCenterAndIp(appId, clusterName,
......
...@@ -10,8 +10,7 @@ import com.ctrip.framework.apollo.common.exception.BadRequestException; ...@@ -10,8 +10,7 @@ import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -23,17 +22,21 @@ import java.util.Map; ...@@ -23,17 +22,21 @@ import java.util.Map;
@Service @Service
public class ItemService { public class ItemService {
@Autowired private final ItemRepository itemRepository;
private ItemRepository itemRepository; private final NamespaceService namespaceService;
private final AuditService auditService;
@Autowired private final BizConfig bizConfig;
private NamespaceService namespaceService;
public ItemService(
@Autowired final ItemRepository itemRepository,
private AuditService auditService; final @Lazy NamespaceService namespaceService,
final AuditService auditService,
@Autowired final BizConfig bizConfig) {
private BizConfig bizConfig; this.itemRepository = itemRepository;
this.namespaceService = namespaceService;
this.auditService = auditService;
this.bizConfig = bizConfig;
}
@Transactional @Transactional
......
...@@ -9,8 +9,6 @@ import com.ctrip.framework.apollo.common.dto.ItemChangeSets; ...@@ -9,8 +9,6 @@ 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.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -19,14 +17,18 @@ import org.springframework.util.CollectionUtils; ...@@ -19,14 +17,18 @@ import org.springframework.util.CollectionUtils;
@Service @Service
public class ItemSetService { public class ItemSetService {
@Autowired private final AuditService auditService;
private AuditService auditService; private final CommitService commitService;
private final ItemService itemService;
@Autowired
private CommitService commitService; public ItemSetService(
final AuditService auditService,
@Autowired final CommitService commitService,
private ItemService itemService; final ItemService itemService) {
this.auditService = auditService;
this.commitService = commitService;
this.itemService = itemService;
}
@Transactional @Transactional
public ItemChangeSets updateSet(Namespace namespace, ItemChangeSets changeSets){ public ItemChangeSets updateSet(Namespace namespace, ItemChangeSets changeSets){
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.google.common.collect.Maps;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Cluster; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.entity.GrayReleaseRule; import com.ctrip.framework.apollo.biz.entity.GrayReleaseRule;
...@@ -14,8 +12,8 @@ import com.ctrip.framework.apollo.common.constants.ReleaseOperationContext; ...@@ -14,8 +12,8 @@ import com.ctrip.framework.apollo.common.constants.ReleaseOperationContext;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.utils.GrayReleaseRuleItemTransformer; import com.ctrip.framework.apollo.common.utils.GrayReleaseRuleItemTransformer;
import com.ctrip.framework.apollo.common.utils.UniqueKeyGenerator; import com.ctrip.framework.apollo.common.utils.UniqueKeyGenerator;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -24,18 +22,27 @@ import java.util.Map; ...@@ -24,18 +22,27 @@ import java.util.Map;
@Service @Service
public class NamespaceBranchService { public class NamespaceBranchService {
@Autowired private final AuditService auditService;
private AuditService auditService; private final GrayReleaseRuleRepository grayReleaseRuleRepository;
@Autowired private final ClusterService clusterService;
private GrayReleaseRuleRepository grayReleaseRuleRepository; private final ReleaseService releaseService;
@Autowired private final NamespaceService namespaceService;
private ClusterService clusterService; private final ReleaseHistoryService releaseHistoryService;
@Autowired
private ReleaseService releaseService; public NamespaceBranchService(
@Autowired final AuditService auditService,
private NamespaceService namespaceService; final GrayReleaseRuleRepository grayReleaseRuleRepository,
@Autowired final ClusterService clusterService,
private ReleaseHistoryService releaseHistoryService; final @Lazy ReleaseService releaseService,
final NamespaceService namespaceService,
final ReleaseHistoryService releaseHistoryService) {
this.auditService = auditService;
this.grayReleaseRuleRepository = grayReleaseRuleRepository;
this.clusterService = clusterService;
this.releaseService = releaseService;
this.namespaceService = namespaceService;
this.releaseHistoryService = releaseHistoryService;
}
@Transactional @Transactional
public Namespace createBranch(String appId, String parentClusterName, String namespaceName, String operator){ public Namespace createBranch(String appId, String parentClusterName, String namespaceName, String operator){
......
...@@ -2,16 +2,17 @@ package com.ctrip.framework.apollo.biz.service; ...@@ -2,16 +2,17 @@ package com.ctrip.framework.apollo.biz.service;
import com.ctrip.framework.apollo.biz.entity.NamespaceLock; import com.ctrip.framework.apollo.biz.entity.NamespaceLock;
import com.ctrip.framework.apollo.biz.repository.NamespaceLockRepository; import com.ctrip.framework.apollo.biz.repository.NamespaceLockRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Service @Service
public class NamespaceLockService { public class NamespaceLockService {
@Autowired private final NamespaceLockRepository namespaceLockRepository;
private NamespaceLockRepository namespaceLockRepository;
public NamespaceLockService(final NamespaceLockRepository namespaceLockRepository) {
this.namespaceLockRepository = namespaceLockRepository;
}
public NamespaceLock findLock(Long namespaceId){ public NamespaceLock findLock(Long namespaceId){
return namespaceLockRepository.findByNamespaceId(namespaceId); return namespaceLockRepository.findByNamespaceId(namespaceId);
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.Cluster; import com.ctrip.framework.apollo.biz.entity.Cluster;
import com.ctrip.framework.apollo.biz.entity.Item; import com.ctrip.framework.apollo.biz.entity.Item;
...@@ -19,8 +16,9 @@ import com.ctrip.framework.apollo.common.exception.BadRequestException; ...@@ -19,8 +16,9 @@ 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.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired; import com.google.gson.Gson;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -40,30 +38,45 @@ public class NamespaceService { ...@@ -40,30 +38,45 @@ public class NamespaceService {
private Gson gson = new Gson(); private Gson gson = new Gson();
@Autowired private final NamespaceRepository namespaceRepository;
private NamespaceRepository namespaceRepository; private final AuditService auditService;
@Autowired private final AppNamespaceService appNamespaceService;
private AuditService auditService; private final ItemService itemService;
@Autowired private final CommitService commitService;
private AppNamespaceService appNamespaceService; private final ReleaseService releaseService;
@Autowired private final ClusterService clusterService;
private ItemService itemService; private final NamespaceBranchService namespaceBranchService;
@Autowired private final ReleaseHistoryService releaseHistoryService;
private CommitService commitService; private final NamespaceLockService namespaceLockService;
@Autowired private final InstanceService instanceService;
private ReleaseService releaseService; private final MessageSender messageSender;
@Autowired
private ClusterService clusterService; public NamespaceService(
@Autowired final ReleaseHistoryService releaseHistoryService,
private NamespaceBranchService namespaceBranchService; final NamespaceRepository namespaceRepository,
@Autowired final AuditService auditService,
private ReleaseHistoryService releaseHistoryService; final @Lazy AppNamespaceService appNamespaceService,
@Autowired final MessageSender messageSender,
private NamespaceLockService namespaceLockService; final @Lazy ItemService itemService,
@Autowired final CommitService commitService,
private InstanceService instanceService; final @Lazy ReleaseService releaseService,
@Autowired final @Lazy ClusterService clusterService,
private MessageSender messageSender; final @Lazy NamespaceBranchService namespaceBranchService,
final NamespaceLockService namespaceLockService,
final InstanceService instanceService) {
this.releaseHistoryService = releaseHistoryService;
this.namespaceRepository = namespaceRepository;
this.auditService = auditService;
this.appNamespaceService = appNamespaceService;
this.messageSender = messageSender;
this.itemService = itemService;
this.commitService = commitService;
this.releaseService = releaseService;
this.clusterService = clusterService;
this.namespaceBranchService = namespaceBranchService;
this.namespaceLockService = namespaceLockService;
this.instanceService = instanceService;
}
public Namespace findOne(Long namespaceId) { public Namespace findOne(Long namespaceId) {
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.google.gson.Gson;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.ReleaseHistory; import com.ctrip.framework.apollo.biz.entity.ReleaseHistory;
import com.ctrip.framework.apollo.biz.repository.ReleaseHistoryRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseHistoryRepository;
import com.google.gson.Gson;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -15,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -15,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -23,10 +20,15 @@ import java.util.Map; ...@@ -23,10 +20,15 @@ import java.util.Map;
public class ReleaseHistoryService { public class ReleaseHistoryService {
private Gson gson = new Gson(); private Gson gson = new Gson();
@Autowired private final ReleaseHistoryRepository releaseHistoryRepository;
private ReleaseHistoryRepository releaseHistoryRepository; private final AuditService auditService;
@Autowired
private AuditService auditService; public ReleaseHistoryService(
final ReleaseHistoryRepository releaseHistoryRepository,
final AuditService auditService) {
this.releaseHistoryRepository = releaseHistoryRepository;
this.auditService = auditService;
}
public Page<ReleaseHistory> findReleaseHistoriesByNamespace(String appId, String clusterName, public Page<ReleaseHistory> findReleaseHistoriesByNamespace(String appId, String clusterName,
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.google.common.collect.Lists;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository;
import com.ctrip.framework.apollo.tracer.Tracer; import com.ctrip.framework.apollo.tracer.Tracer;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -19,8 +16,11 @@ import java.util.List; ...@@ -19,8 +16,11 @@ import java.util.List;
*/ */
@Service @Service
public class ReleaseMessageService { public class ReleaseMessageService {
@Autowired private final ReleaseMessageRepository releaseMessageRepository;
private ReleaseMessageRepository releaseMessageRepository;
public ReleaseMessageService(final ReleaseMessageRepository releaseMessageRepository) {
this.releaseMessageRepository = releaseMessageRepository;
}
public ReleaseMessage findLatestReleaseMessageForMessages(Collection<String> messages) { public ReleaseMessage findLatestReleaseMessageForMessages(Collection<String> messages) {
if (CollectionUtils.isEmpty(messages)) { if (CollectionUtils.isEmpty(messages)) {
......
package com.ctrip.framework.apollo.biz.service; package com.ctrip.framework.apollo.biz.service;
import com.ctrip.framework.apollo.biz.entity.ReleaseHistory;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.ctrip.framework.apollo.biz.entity.Audit; import com.ctrip.framework.apollo.biz.entity.Audit;
import com.ctrip.framework.apollo.biz.entity.GrayReleaseRule; import com.ctrip.framework.apollo.biz.entity.GrayReleaseRule;
import com.ctrip.framework.apollo.biz.entity.Item; import com.ctrip.framework.apollo.biz.entity.Item;
import com.ctrip.framework.apollo.biz.entity.Namespace; import com.ctrip.framework.apollo.biz.entity.Namespace;
import com.ctrip.framework.apollo.biz.entity.NamespaceLock; import com.ctrip.framework.apollo.biz.entity.NamespaceLock;
import com.ctrip.framework.apollo.biz.entity.Release; import com.ctrip.framework.apollo.biz.entity.Release;
import com.ctrip.framework.apollo.biz.entity.ReleaseHistory;
import com.ctrip.framework.apollo.biz.repository.ReleaseRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseRepository;
import com.ctrip.framework.apollo.biz.utils.ReleaseKeyGenerator; import com.ctrip.framework.apollo.biz.utils.ReleaseKeyGenerator;
import com.ctrip.framework.apollo.common.constants.GsonType; import com.ctrip.framework.apollo.common.constants.GsonType;
...@@ -22,12 +17,12 @@ import com.ctrip.framework.apollo.common.exception.BadRequestException; ...@@ -22,12 +17,12 @@ import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.exception.NotFoundException; import com.ctrip.framework.apollo.common.exception.NotFoundException;
import com.ctrip.framework.apollo.common.utils.GrayReleaseRuleItemTransformer; import com.ctrip.framework.apollo.common.utils.GrayReleaseRuleItemTransformer;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.Collection;
import org.apache.commons.lang.time.FastDateFormat; import org.apache.commons.lang.time.FastDateFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -35,6 +30,8 @@ import org.springframework.stereotype.Service; ...@@ -35,6 +30,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
...@@ -57,22 +54,33 @@ public class ReleaseService { ...@@ -57,22 +54,33 @@ public class ReleaseService {
private static final Pageable FIRST_ITEM = PageRequest.of(0, 1); private static final Pageable FIRST_ITEM = PageRequest.of(0, 1);
private static final Type OPERATION_CONTEXT_TYPE_REFERENCE = new TypeToken<Map<String, Object>>() { }.getType(); private static final Type OPERATION_CONTEXT_TYPE_REFERENCE = new TypeToken<Map<String, Object>>() { }.getType();
@Autowired private final ReleaseRepository releaseRepository;
private ReleaseRepository releaseRepository; private final ItemService itemService;
@Autowired private final AuditService auditService;
private ItemService itemService; private final NamespaceLockService namespaceLockService;
@Autowired private final NamespaceService namespaceService;
private AuditService auditService; private final NamespaceBranchService namespaceBranchService;
@Autowired private final ReleaseHistoryService releaseHistoryService;
private NamespaceLockService namespaceLockService; private final ItemSetService itemSetService;
@Autowired
private NamespaceService namespaceService; public ReleaseService(
@Autowired final ReleaseRepository releaseRepository,
private NamespaceBranchService namespaceBranchService; final ItemService itemService,
@Autowired final AuditService auditService,
private ReleaseHistoryService releaseHistoryService; final NamespaceLockService namespaceLockService,
@Autowired final NamespaceService namespaceService,
private ItemSetService itemSetService; final NamespaceBranchService namespaceBranchService,
final ReleaseHistoryService releaseHistoryService,
final ItemSetService itemSetService) {
this.releaseRepository = releaseRepository;
this.itemService = itemService;
this.auditService = auditService;
this.namespaceLockService = namespaceLockService;
this.namespaceService = namespaceService;
this.namespaceBranchService = namespaceBranchService;
this.releaseHistoryService = releaseHistoryService;
this.itemSetService = itemSetService;
}
public Release findOne(long releaseId) { public Release findOne(long releaseId) {
return releaseRepository.findById(releaseId).orElse(null); return releaseRepository.findById(releaseId).orElse(null);
......
package com.ctrip.framework.apollo.biz.config; package com.ctrip.framework.apollo.biz.config;
import com.ctrip.framework.apollo.biz.service.BizDBPropertySource;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -24,7 +25,7 @@ public class BizConfigTest { ...@@ -24,7 +25,7 @@ public class BizConfigTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
bizConfig = new BizConfig(); bizConfig = new BizConfig(new BizDBPropertySource());
ReflectionTestUtils.setField(bizConfig, "environment", environment); ReflectionTestUtils.setField(bizConfig, "environment", environment);
} }
......
...@@ -3,20 +3,13 @@ package com.ctrip.framework.apollo.biz.message; ...@@ -3,20 +3,13 @@ package com.ctrip.framework.apollo.biz.message;
import com.ctrip.framework.apollo.biz.AbstractUnitTest; import com.ctrip.framework.apollo.biz.AbstractUnitTest;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.springframework.test.util.ReflectionTestUtils;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.any; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -28,8 +21,7 @@ public class DatabaseMessageSenderTest extends AbstractUnitTest{ ...@@ -28,8 +21,7 @@ public class DatabaseMessageSenderTest extends AbstractUnitTest{
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
messageSender = new DatabaseMessageSender(); messageSender = new DatabaseMessageSender(releaseMessageRepository);
ReflectionTestUtils.setField(messageSender, "releaseMessageRepository", releaseMessageRepository);
} }
@Test @Test
......
package com.ctrip.framework.apollo.common.datasource; package com.ctrip.framework.apollo.common.datasource;
import com.ctrip.framework.apollo.tracer.Tracer; import com.ctrip.framework.apollo.tracer.Tracer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.lang.reflect.Method;
@Component @Component
@Conditional(TitanCondition.class) @Conditional(TitanCondition.class)
public class TitanEntityManager { public class TitanEntityManager {
@Autowired private final TitanSettings settings;
private TitanSettings settings;
public TitanEntityManager(final TitanSettings settings) {
this.settings = settings;
}
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
@Bean @Bean
......
...@@ -7,11 +7,9 @@ import com.ctrip.framework.apollo.configservice.controller.ConfigFileController; ...@@ -7,11 +7,9 @@ import com.ctrip.framework.apollo.configservice.controller.ConfigFileController;
import com.ctrip.framework.apollo.configservice.controller.NotificationController; import com.ctrip.framework.apollo.configservice.controller.NotificationController;
import com.ctrip.framework.apollo.configservice.controller.NotificationControllerV2; import com.ctrip.framework.apollo.configservice.controller.NotificationControllerV2;
import com.ctrip.framework.apollo.configservice.service.ReleaseMessageServiceWithCache; import com.ctrip.framework.apollo.configservice.service.ReleaseMessageServiceWithCache;
import com.ctrip.framework.apollo.configservice.service.config.ConfigService; import com.ctrip.framework.apollo.configservice.service.config.ConfigService;
import com.ctrip.framework.apollo.configservice.service.config.ConfigServiceWithCache; import com.ctrip.framework.apollo.configservice.service.config.ConfigServiceWithCache;
import com.ctrip.framework.apollo.configservice.service.config.DefaultConfigService; import com.ctrip.framework.apollo.configservice.service.config.DefaultConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.NoOpPasswordEncoder; import org.springframework.security.crypto.password.NoOpPasswordEncoder;
...@@ -22,8 +20,11 @@ import org.springframework.security.crypto.password.NoOpPasswordEncoder; ...@@ -22,8 +20,11 @@ import org.springframework.security.crypto.password.NoOpPasswordEncoder;
@Configuration @Configuration
public class ConfigServiceAutoConfiguration { public class ConfigServiceAutoConfiguration {
@Autowired private final BizConfig bizConfig;
private BizConfig bizConfig;
public ConfigServiceAutoConfiguration(final BizConfig bizConfig) {
this.bizConfig = bizConfig;
}
@Bean @Bean
public GrayReleaseRulesHolder grayReleaseRulesHolder() { public GrayReleaseRulesHolder grayReleaseRulesHolder() {
...@@ -45,18 +46,27 @@ public class ConfigServiceAutoConfiguration { ...@@ -45,18 +46,27 @@ public class ConfigServiceAutoConfiguration {
@Configuration @Configuration
static class MessageScannerConfiguration { static class MessageScannerConfiguration {
@Autowired private final NotificationController notificationController;
private NotificationController notificationController; private final ConfigFileController configFileController;
@Autowired private final NotificationControllerV2 notificationControllerV2;
private ConfigFileController configFileController; private final GrayReleaseRulesHolder grayReleaseRulesHolder;
@Autowired private final ReleaseMessageServiceWithCache releaseMessageServiceWithCache;
private NotificationControllerV2 notificationControllerV2; private final ConfigService configService;
@Autowired
private GrayReleaseRulesHolder grayReleaseRulesHolder; public MessageScannerConfiguration(
@Autowired final NotificationController notificationController,
private ReleaseMessageServiceWithCache releaseMessageServiceWithCache; final ConfigFileController configFileController,
@Autowired final NotificationControllerV2 notificationControllerV2,
private ConfigService configService; final GrayReleaseRulesHolder grayReleaseRulesHolder,
final ReleaseMessageServiceWithCache releaseMessageServiceWithCache,
final ConfigService configService) {
this.notificationController = notificationController;
this.configFileController = configFileController;
this.notificationControllerV2 = notificationControllerV2;
this.grayReleaseRulesHolder = grayReleaseRulesHolder;
this.releaseMessageServiceWithCache = releaseMessageServiceWithCache;
this.configService = configService;
}
@Bean @Bean
public ReleaseMessageScanner releaseMessageScanner() { public ReleaseMessageScanner releaseMessageScanner() {
......
package com.ctrip.framework.apollo.configservice; package com.ctrip.framework.apollo.configservice;
import com.ctrip.framework.apollo.biz.service.AppService; import com.ctrip.framework.apollo.biz.service.AppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
...@@ -11,8 +9,11 @@ import org.springframework.stereotype.Component; ...@@ -11,8 +9,11 @@ import org.springframework.stereotype.Component;
@Component @Component
public class ConfigServiceHealthIndicator implements HealthIndicator { public class ConfigServiceHealthIndicator implements HealthIndicator {
@Autowired private final AppService appService;
private AppService appService;
public ConfigServiceHealthIndicator(final AppService appService) {
this.appService = appService;
}
@Override @Override
public Health health() { public Health health() {
......
...@@ -16,7 +16,6 @@ import com.google.common.collect.Lists; ...@@ -16,7 +16,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -40,20 +39,28 @@ import java.util.stream.Collectors; ...@@ -40,20 +39,28 @@ import java.util.stream.Collectors;
public class ConfigController { public class ConfigController {
private static final Splitter X_FORWARDED_FOR_SPLITTER = Splitter.on(",").omitEmptyStrings() private static final Splitter X_FORWARDED_FOR_SPLITTER = Splitter.on(",").omitEmptyStrings()
.trimResults(); .trimResults();
@Autowired private final ConfigService configService;
private ConfigService configService; private final AppNamespaceServiceWithCache appNamespaceService;
@Autowired private final NamespaceUtil namespaceUtil;
private AppNamespaceServiceWithCache appNamespaceService; private final InstanceConfigAuditUtil instanceConfigAuditUtil;
@Autowired private final Gson gson;
private NamespaceUtil namespaceUtil;
@Autowired
private InstanceConfigAuditUtil instanceConfigAuditUtil;
@Autowired
private Gson gson;
private static final Type configurationTypeReference = new TypeToken<Map<String, String>>() { private static final Type configurationTypeReference = new TypeToken<Map<String, String>>() {
}.getType(); }.getType();
public ConfigController(
final ConfigService configService,
final AppNamespaceServiceWithCache appNamespaceService,
final NamespaceUtil namespaceUtil,
final InstanceConfigAuditUtil instanceConfigAuditUtil,
final Gson gson) {
this.configService = configService;
this.appNamespaceService = appNamespaceService;
this.namespaceUtil = namespaceUtil;
this.instanceConfigAuditUtil = instanceConfigAuditUtil;
this.gson = gson;
}
@GetMapping(value = "/{appId}/{clusterName}/{namespace:.+}") @GetMapping(value = "/{appId}/{clusterName}/{namespace:.+}")
public ApolloConfig queryConfig(@PathVariable String appId, @PathVariable String clusterName, public ApolloConfig queryConfig(@PathVariable String appId, @PathVariable String clusterName,
@PathVariable String namespace, @PathVariable String namespace,
......
...@@ -25,7 +25,6 @@ import com.google.common.collect.Multimaps; ...@@ -25,7 +25,6 @@ import com.google.common.collect.Multimaps;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -66,19 +65,16 @@ public class ConfigFileController implements ReleaseMessageListener { ...@@ -66,19 +65,16 @@ public class ConfigFileController implements ReleaseMessageListener {
cacheKey2WatchedKeys = Multimaps.synchronizedSetMultimap(HashMultimap.create()); cacheKey2WatchedKeys = Multimaps.synchronizedSetMultimap(HashMultimap.create());
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
@Autowired private final ConfigController configController;
private ConfigController configController; private final NamespaceUtil namespaceUtil;
private final WatchKeysUtil watchKeysUtil;
private final GrayReleaseRulesHolder grayReleaseRulesHolder;
@Autowired public ConfigFileController(
private NamespaceUtil namespaceUtil; final ConfigController configController,
final NamespaceUtil namespaceUtil,
@Autowired final WatchKeysUtil watchKeysUtil,
private WatchKeysUtil watchKeysUtil; final GrayReleaseRulesHolder grayReleaseRulesHolder) {
@Autowired
private GrayReleaseRulesHolder grayReleaseRulesHolder;
public ConfigFileController() {
localCache = CacheBuilder.newBuilder() localCache = CacheBuilder.newBuilder()
.expireAfterWrite(EXPIRE_AFTER_WRITE, TimeUnit.MINUTES) .expireAfterWrite(EXPIRE_AFTER_WRITE, TimeUnit.MINUTES)
.weigher(new Weigher<String, String>() { .weigher(new Weigher<String, String>() {
...@@ -111,6 +107,10 @@ public class ConfigFileController implements ReleaseMessageListener { ...@@ -111,6 +107,10 @@ public class ConfigFileController implements ReleaseMessageListener {
jsonResponseHeaders = new HttpHeaders(); jsonResponseHeaders = new HttpHeaders();
jsonResponseHeaders.add("Content-Type", "application/json;charset=UTF-8"); jsonResponseHeaders.add("Content-Type", "application/json;charset=UTF-8");
NOT_FOUND_RESPONSE = new ResponseEntity<>(HttpStatus.NOT_FOUND); NOT_FOUND_RESPONSE = new ResponseEntity<>(HttpStatus.NOT_FOUND);
this.configController = configController;
this.namespaceUtil = namespaceUtil;
this.watchKeysUtil = watchKeysUtil;
this.grayReleaseRulesHolder = grayReleaseRulesHolder;
} }
@GetMapping(value = "/{appId}/{clusterName}/{namespace:.+}") @GetMapping(value = "/{appId}/{clusterName}/{namespace:.+}")
......
...@@ -18,7 +18,6 @@ import com.google.common.collect.Multimap; ...@@ -18,7 +18,6 @@ import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps; import com.google.common.collect.Multimaps;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -46,17 +45,21 @@ public class NotificationController implements ReleaseMessageListener { ...@@ -46,17 +45,21 @@ public class NotificationController implements ReleaseMessageListener {
private static final Splitter STRING_SPLITTER = private static final Splitter STRING_SPLITTER =
Splitter.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR).omitEmptyStrings(); Splitter.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR).omitEmptyStrings();
@Autowired private final WatchKeysUtil watchKeysUtil;
private WatchKeysUtil watchKeysUtil; private final ReleaseMessageServiceWithCache releaseMessageService;
private final EntityManagerUtil entityManagerUtil;
@Autowired private final NamespaceUtil namespaceUtil;
private ReleaseMessageServiceWithCache releaseMessageService;
public NotificationController(
@Autowired final WatchKeysUtil watchKeysUtil,
private EntityManagerUtil entityManagerUtil; final ReleaseMessageServiceWithCache releaseMessageService,
final EntityManagerUtil entityManagerUtil,
@Autowired final NamespaceUtil namespaceUtil) {
private NamespaceUtil namespaceUtil; this.watchKeysUtil = watchKeysUtil;
this.releaseMessageService = releaseMessageService;
this.entityManagerUtil = entityManagerUtil;
this.namespaceUtil = namespaceUtil;
}
/** /**
* For single namespace notification, reserved for older version of apollo clients * For single namespace notification, reserved for older version of apollo clients
......
...@@ -63,27 +63,29 @@ public class NotificationControllerV2 implements ReleaseMessageListener { ...@@ -63,27 +63,29 @@ public class NotificationControllerV2 implements ReleaseMessageListener {
private final ExecutorService largeNotificationBatchExecutorService; private final ExecutorService largeNotificationBatchExecutorService;
@Autowired private final WatchKeysUtil watchKeysUtil;
private WatchKeysUtil watchKeysUtil; private final ReleaseMessageServiceWithCache releaseMessageService;
private final EntityManagerUtil entityManagerUtil;
@Autowired private final NamespaceUtil namespaceUtil;
private ReleaseMessageServiceWithCache releaseMessageService; private final Gson gson;
private final BizConfig bizConfig;
@Autowired
private EntityManagerUtil entityManagerUtil;
@Autowired @Autowired
private NamespaceUtil namespaceUtil; public NotificationControllerV2(
final WatchKeysUtil watchKeysUtil,
@Autowired final ReleaseMessageServiceWithCache releaseMessageService,
private Gson gson; final EntityManagerUtil entityManagerUtil,
final NamespaceUtil namespaceUtil,
@Autowired final Gson gson,
private BizConfig bizConfig; final BizConfig bizConfig) {
public NotificationControllerV2() {
largeNotificationBatchExecutorService = Executors.newSingleThreadExecutor(ApolloThreadFactory.create largeNotificationBatchExecutorService = Executors.newSingleThreadExecutor(ApolloThreadFactory.create
("NotificationControllerV2", true)); ("NotificationControllerV2", true));
this.watchKeysUtil = watchKeysUtil;
this.releaseMessageService = releaseMessageService;
this.entityManagerUtil = entityManagerUtil;
this.namespaceUtil = namespaceUtil;
this.gson = gson;
this.bizConfig = bizConfig;
} }
@GetMapping @GetMapping
......
package com.ctrip.framework.apollo.configservice.service; package com.ctrip.framework.apollo.configservice.service;
import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.configservice.wrapper.CaseInsensitiveMapWrapper; import com.ctrip.framework.apollo.configservice.wrapper.CaseInsensitiveMapWrapper;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -40,11 +37,8 @@ public class AppNamespaceServiceWithCache implements InitializingBean { ...@@ -40,11 +37,8 @@ public class AppNamespaceServiceWithCache implements InitializingBean {
private static final Logger logger = LoggerFactory.getLogger(AppNamespaceServiceWithCache.class); private static final Logger logger = LoggerFactory.getLogger(AppNamespaceServiceWithCache.class);
private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR) private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR)
.skipNulls(); .skipNulls();
@Autowired private final AppNamespaceRepository appNamespaceRepository;
private AppNamespaceRepository appNamespaceRepository; private final BizConfig bizConfig;
@Autowired
private BizConfig bizConfig;
private int scanInterval; private int scanInterval;
private TimeUnit scanIntervalTimeUnit; private TimeUnit scanIntervalTimeUnit;
...@@ -62,7 +56,11 @@ public class AppNamespaceServiceWithCache implements InitializingBean { ...@@ -62,7 +56,11 @@ public class AppNamespaceServiceWithCache implements InitializingBean {
//store id -> AppNamespace //store id -> AppNamespace
private Map<Long, AppNamespace> appNamespaceIdCache; private Map<Long, AppNamespace> appNamespaceIdCache;
public AppNamespaceServiceWithCache() { public AppNamespaceServiceWithCache(
final AppNamespaceRepository appNamespaceRepository,
final BizConfig bizConfig) {
this.appNamespaceRepository = appNamespaceRepository;
this.bizConfig = bizConfig;
initialize(); initialize();
} }
......
package com.ctrip.framework.apollo.configservice.service; package com.ctrip.framework.apollo.configservice.service;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.ctrip.framework.apollo.biz.config.BizConfig; import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.message.ReleaseMessageListener; import com.ctrip.framework.apollo.biz.message.ReleaseMessageListener;
...@@ -12,11 +8,12 @@ import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository; ...@@ -12,11 +8,12 @@ import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.tracer.Tracer; import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction; import com.ctrip.framework.apollo.tracer.spi.Transaction;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -36,11 +33,8 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -36,11 +33,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class ReleaseMessageServiceWithCache implements ReleaseMessageListener, InitializingBean { public class ReleaseMessageServiceWithCache implements ReleaseMessageListener, InitializingBean {
private static final Logger logger = LoggerFactory.getLogger(ReleaseMessageServiceWithCache private static final Logger logger = LoggerFactory.getLogger(ReleaseMessageServiceWithCache
.class); .class);
@Autowired private final ReleaseMessageRepository releaseMessageRepository;
private ReleaseMessageRepository releaseMessageRepository; private final BizConfig bizConfig;
@Autowired
private BizConfig bizConfig;
private int scanInterval; private int scanInterval;
private TimeUnit scanIntervalTimeUnit; private TimeUnit scanIntervalTimeUnit;
...@@ -52,7 +46,11 @@ public class ReleaseMessageServiceWithCache implements ReleaseMessageListener, I ...@@ -52,7 +46,11 @@ public class ReleaseMessageServiceWithCache implements ReleaseMessageListener, I
private AtomicBoolean doScan; private AtomicBoolean doScan;
private ExecutorService executorService; private ExecutorService executorService;
public ReleaseMessageServiceWithCache() { public ReleaseMessageServiceWithCache(
final ReleaseMessageRepository releaseMessageRepository,
final BizConfig bizConfig) {
this.releaseMessageRepository = releaseMessageRepository;
this.bizConfig = bizConfig;
initialize(); initialize();
} }
......
...@@ -45,10 +45,10 @@ public class InstanceConfigAuditUtil implements InitializingBean { ...@@ -45,10 +45,10 @@ public class InstanceConfigAuditUtil implements InitializingBean {
private Cache<String, Long> instanceCache; private Cache<String, Long> instanceCache;
private Cache<String, String> instanceConfigReleaseKeyCache; private Cache<String, String> instanceConfigReleaseKeyCache;
@Autowired private final InstanceService instanceService;
private InstanceService instanceService;
public InstanceConfigAuditUtil() { public InstanceConfigAuditUtil(final InstanceService instanceService) {
this.instanceService = instanceService;
auditExecutorService = Executors.newSingleThreadExecutor( auditExecutorService = Executors.newSingleThreadExecutor(
ApolloThreadFactory.create("InstanceConfigAuditUtil", true)); ApolloThreadFactory.create("InstanceConfigAuditUtil", true));
auditStopped = new AtomicBoolean(false); auditStopped = new AtomicBoolean(false);
......
...@@ -2,8 +2,6 @@ package com.ctrip.framework.apollo.configservice.util; ...@@ -2,8 +2,6 @@ package com.ctrip.framework.apollo.configservice.util;
import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.configservice.service.AppNamespaceServiceWithCache; import com.ctrip.framework.apollo.configservice.service.AppNamespaceServiceWithCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
...@@ -12,8 +10,11 @@ import org.springframework.stereotype.Component; ...@@ -12,8 +10,11 @@ import org.springframework.stereotype.Component;
@Component @Component
public class NamespaceUtil { public class NamespaceUtil {
@Autowired private final AppNamespaceServiceWithCache appNamespaceServiceWithCache;
private AppNamespaceServiceWithCache appNamespaceServiceWithCache;
public NamespaceUtil(final AppNamespaceServiceWithCache appNamespaceServiceWithCache) {
this.appNamespaceServiceWithCache = appNamespaceServiceWithCache;
}
public String filterNamespaceName(String namespaceName) { public String filterNamespaceName(String namespaceName) {
if (namespaceName.toLowerCase().endsWith(".properties")) { if (namespaceName.toLowerCase().endsWith(".properties")) {
......
package com.ctrip.framework.apollo.configservice.util; package com.ctrip.framework.apollo.configservice.util;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.configservice.service.AppNamespaceServiceWithCache;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.ctrip.framework.apollo.configservice.service.AppNamespaceServiceWithCache;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.core.ConfigConsts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Collections; import java.util.Collections;
...@@ -25,8 +22,11 @@ import java.util.Set; ...@@ -25,8 +22,11 @@ import java.util.Set;
@Component @Component
public class WatchKeysUtil { public class WatchKeysUtil {
private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR); private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR);
@Autowired private final AppNamespaceServiceWithCache appNamespaceService;
private AppNamespaceServiceWithCache appNamespaceService;
public WatchKeysUtil(final AppNamespaceServiceWithCache appNamespaceService) {
this.appNamespaceService = appNamespaceService;
}
/** /**
* Assemble watch keys for the given appId, cluster, namespace, dataCenter combination * Assemble watch keys for the given appId, cluster, namespace, dataCenter combination
......
...@@ -3,8 +3,6 @@ package com.ctrip.framework.apollo.metaservice.controller; ...@@ -3,8 +3,6 @@ package com.ctrip.framework.apollo.metaservice.controller;
import com.ctrip.framework.apollo.core.dto.ServiceDTO; import com.ctrip.framework.apollo.core.dto.ServiceDTO;
import com.ctrip.framework.apollo.metaservice.service.DiscoveryService; import com.ctrip.framework.apollo.metaservice.service.DiscoveryService;
import com.netflix.appinfo.InstanceInfo; import com.netflix.appinfo.InstanceInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -17,8 +15,11 @@ import java.util.stream.Collectors; ...@@ -17,8 +15,11 @@ import java.util.stream.Collectors;
@RequestMapping("/services") @RequestMapping("/services")
public class ServiceController { public class ServiceController {
@Autowired private final DiscoveryService discoveryService;
private DiscoveryService discoveryService;
public ServiceController(final DiscoveryService discoveryService) {
this.discoveryService = discoveryService;
}
@RequestMapping("/meta") @RequestMapping("/meta")
......
...@@ -5,8 +5,6 @@ import com.ctrip.framework.apollo.tracer.Tracer; ...@@ -5,8 +5,6 @@ import com.ctrip.framework.apollo.tracer.Tracer;
import com.netflix.appinfo.InstanceInfo; import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient; import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.shared.Application; import com.netflix.discovery.shared.Application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collections; import java.util.Collections;
...@@ -15,8 +13,11 @@ import java.util.List; ...@@ -15,8 +13,11 @@ import java.util.List;
@Service @Service
public class DiscoveryService { public class DiscoveryService {
@Autowired private final EurekaClient eurekaClient;
private EurekaClient eurekaClient;
public DiscoveryService(final EurekaClient eurekaClient) {
this.eurekaClient = eurekaClient;
}
public List<InstanceInfo> getConfigServiceInstances() { public List<InstanceInfo> getConfigServiceInstances() {
Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_CONFIGSERVICE); Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_CONFIGSERVICE);
......
package com.ctrip.framework.apollo.configservice.controller; package com.ctrip.framework.apollo.configservice.controller;
import com.ctrip.framework.apollo.configservice.service.AppNamespaceServiceWithCache;
import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.ctrip.framework.apollo.biz.entity.Release; import com.ctrip.framework.apollo.biz.entity.Release;
import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.configservice.service.AppNamespaceServiceWithCache;
import com.ctrip.framework.apollo.configservice.service.config.ConfigService; import com.ctrip.framework.apollo.configservice.service.config.ConfigService;
import com.ctrip.framework.apollo.configservice.util.InstanceConfigAuditUtil; import com.ctrip.framework.apollo.configservice.util.InstanceConfigAuditUtil;
import com.ctrip.framework.apollo.configservice.util.NamespaceUtil; import com.ctrip.framework.apollo.configservice.util.NamespaceUtil;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.dto.ApolloConfig; import com.ctrip.framework.apollo.core.dto.ApolloConfig;
import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -73,12 +64,9 @@ public class ConfigControllerTest { ...@@ -73,12 +64,9 @@ public class ConfigControllerTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
configController = spy(new ConfigController()); configController = spy(new ConfigController(
ReflectionTestUtils.setField(configController, "configService", configService); configService, appNamespaceService, namespaceUtil, instanceConfigAuditUtil, gson
ReflectionTestUtils.setField(configController, "appNamespaceService", appNamespaceService); ));
ReflectionTestUtils.setField(configController, "namespaceUtil", namespaceUtil);
ReflectionTestUtils.setField(configController, "instanceConfigAuditUtil", instanceConfigAuditUtil);
ReflectionTestUtils.setField(configController, "gson", gson);
someAppId = "1"; someAppId = "1";
someClusterName = "someClusterName"; someClusterName = "someClusterName";
......
package com.ctrip.framework.apollo.configservice.controller; package com.ctrip.framework.apollo.configservice.controller;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.grayReleaseRule.GrayReleaseRulesHolder;
import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.configservice.util.NamespaceUtil;
import com.ctrip.framework.apollo.configservice.util.WatchKeysUtil;
import com.ctrip.framework.apollo.core.dto.ApolloConfig;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
...@@ -7,14 +13,6 @@ import com.google.common.collect.Multimap; ...@@ -7,14 +13,6 @@ import com.google.common.collect.Multimap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.grayReleaseRule.GrayReleaseRulesHolder;
import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.configservice.util.NamespaceUtil;
import com.ctrip.framework.apollo.configservice.util.WatchKeysUtil;
import com.ctrip.framework.apollo.core.dto.ApolloConfig;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -24,20 +22,16 @@ import org.springframework.http.HttpStatus; ...@@ -24,20 +22,16 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -67,11 +61,9 @@ public class ConfigFileControllerTest { ...@@ -67,11 +61,9 @@ public class ConfigFileControllerTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
configFileController = new ConfigFileController(); configFileController = new ConfigFileController(
ReflectionTestUtils.setField(configFileController, "configController", configController); configController, namespaceUtil, watchKeysUtil, grayReleaseRulesHolder
ReflectionTestUtils.setField(configFileController, "watchKeysUtil", watchKeysUtil); );
ReflectionTestUtils.setField(configFileController, "namespaceUtil", namespaceUtil);
ReflectionTestUtils.setField(configFileController, "grayReleaseRulesHolder", grayReleaseRulesHolder);
someAppId = "someAppId"; someAppId = "someAppId";
someClusterName = "someClusterName"; someClusterName = "someClusterName";
......
package com.ctrip.framework.apollo.configservice.controller; package com.ctrip.framework.apollo.configservice.controller;
import com.google.common.base.Joiner;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.message.Topics; import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.biz.utils.EntityManagerUtil; import com.ctrip.framework.apollo.biz.utils.EntityManagerUtil;
...@@ -12,7 +8,9 @@ import com.ctrip.framework.apollo.configservice.util.NamespaceUtil; ...@@ -12,7 +8,9 @@ import com.ctrip.framework.apollo.configservice.util.NamespaceUtil;
import com.ctrip.framework.apollo.configservice.util.WatchKeysUtil; import com.ctrip.framework.apollo.configservice.util.WatchKeysUtil;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification; import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.google.common.base.Joiner;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -58,11 +56,7 @@ public class NotificationControllerTest { ...@@ -58,11 +56,7 @@ public class NotificationControllerTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
controller = new NotificationController(); controller = new NotificationController(watchKeysUtil, releaseMessageService, entityManagerUtil, namespaceUtil);
ReflectionTestUtils.setField(controller, "releaseMessageService", releaseMessageService);
ReflectionTestUtils.setField(controller, "entityManagerUtil", entityManagerUtil);
ReflectionTestUtils.setField(controller, "namespaceUtil", namespaceUtil);
ReflectionTestUtils.setField(controller, "watchKeysUtil", watchKeysUtil);
someAppId = "someAppId"; someAppId = "someAppId";
someCluster = "someCluster"; someCluster = "someCluster";
......
package com.ctrip.framework.apollo.configservice.controller; package com.ctrip.framework.apollo.configservice.controller;
import com.ctrip.framework.apollo.configservice.wrapper.DeferredResultWrapper;
import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages;
import com.google.common.base.Joiner;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.ctrip.framework.apollo.biz.config.BizConfig; import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.message.Topics; import com.ctrip.framework.apollo.biz.message.Topics;
...@@ -16,9 +7,16 @@ import com.ctrip.framework.apollo.biz.utils.EntityManagerUtil; ...@@ -16,9 +7,16 @@ import com.ctrip.framework.apollo.biz.utils.EntityManagerUtil;
import com.ctrip.framework.apollo.configservice.service.ReleaseMessageServiceWithCache; import com.ctrip.framework.apollo.configservice.service.ReleaseMessageServiceWithCache;
import com.ctrip.framework.apollo.configservice.util.NamespaceUtil; import com.ctrip.framework.apollo.configservice.util.NamespaceUtil;
import com.ctrip.framework.apollo.configservice.util.WatchKeysUtil; import com.ctrip.framework.apollo.configservice.util.WatchKeysUtil;
import com.ctrip.framework.apollo.configservice.wrapper.DeferredResultWrapper;
import com.ctrip.framework.apollo.core.ConfigConsts; import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification; import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages;
import com.google.common.base.Joiner;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -34,13 +32,8 @@ import java.util.List; ...@@ -34,13 +32,8 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.*;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -73,19 +66,14 @@ public class NotificationControllerV2Test { ...@@ -73,19 +66,14 @@ public class NotificationControllerV2Test {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
controller = new NotificationControllerV2();
gson = new Gson(); gson = new Gson();
controller = new NotificationControllerV2(
watchKeysUtil, releaseMessageService, entityManagerUtil, namespaceUtil, gson, bizConfig
);
when(bizConfig.releaseMessageNotificationBatch()).thenReturn(100); when(bizConfig.releaseMessageNotificationBatch()).thenReturn(100);
when(bizConfig.releaseMessageNotificationBatchIntervalInMilli()).thenReturn(5); when(bizConfig.releaseMessageNotificationBatchIntervalInMilli()).thenReturn(5);
ReflectionTestUtils.setField(controller, "releaseMessageService", releaseMessageService);
ReflectionTestUtils.setField(controller, "entityManagerUtil", entityManagerUtil);
ReflectionTestUtils.setField(controller, "namespaceUtil", namespaceUtil);
ReflectionTestUtils.setField(controller, "watchKeysUtil", watchKeysUtil);
ReflectionTestUtils.setField(controller, "gson", gson);
ReflectionTestUtils.setField(controller, "bizConfig", bizConfig);
someAppId = "someAppId"; someAppId = "someAppId";
someCluster = "someCluster"; someCluster = "someCluster";
defaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT; defaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
......
package com.ctrip.framework.apollo.configservice.integration; package com.ctrip.framework.apollo.configservice.integration;
import com.ctrip.framework.apollo.biz.service.BizDBPropertySource;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.ctrip.framework.apollo.ConfigServiceTestConfiguration; import com.ctrip.framework.apollo.ConfigServiceTestConfiguration;
...@@ -63,8 +64,8 @@ public abstract class AbstractBaseIntegrationTest { ...@@ -63,8 +64,8 @@ public abstract class AbstractBaseIntegrationTest {
@Import(ConfigServiceTestConfiguration.class) @Import(ConfigServiceTestConfiguration.class)
protected static class TestConfiguration { protected static class TestConfiguration {
@Bean @Bean
public BizConfig bizConfig() { public BizConfig bizConfig(final BizDBPropertySource bizDBPropertySource) {
return new TestBizConfig(); return new TestBizConfig(bizDBPropertySource);
} }
} }
...@@ -111,6 +112,10 @@ public abstract class AbstractBaseIntegrationTest { ...@@ -111,6 +112,10 @@ public abstract class AbstractBaseIntegrationTest {
} }
private static class TestBizConfig extends BizConfig { private static class TestBizConfig extends BizConfig {
public TestBizConfig(final BizDBPropertySource propertySource) {
super(propertySource);
}
@Override @Override
public int appNamespaceCacheScanInterval() { public int appNamespaceCacheScanInterval() {
//should be short enough to update the AppNamespace cache in time //should be short enough to update the AppNamespace cache in time
......
package com.ctrip.framework.apollo.configservice.service; package com.ctrip.framework.apollo.configservice.service;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.ctrip.framework.apollo.biz.config.BizConfig; import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository; import com.ctrip.framework.apollo.biz.repository.AppNamespaceRepository;
import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collections; import java.util.Collections;
...@@ -22,9 +19,7 @@ import java.util.List; ...@@ -22,9 +19,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** /**
...@@ -46,10 +41,7 @@ public class AppNamespaceServiceWithCacheTest { ...@@ -46,10 +41,7 @@ public class AppNamespaceServiceWithCacheTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
appNamespaceServiceWithCache = new AppNamespaceServiceWithCache(); appNamespaceServiceWithCache = new AppNamespaceServiceWithCache(appNamespaceRepository, bizConfig);
ReflectionTestUtils.setField(appNamespaceServiceWithCache, "appNamespaceRepository",
appNamespaceRepository);
ReflectionTestUtils.setField(appNamespaceServiceWithCache, "bizConfig", bizConfig);
scanInterval = 50; scanInterval = 50;
scanIntervalTimeUnit = TimeUnit.MILLISECONDS; scanIntervalTimeUnit = TimeUnit.MILLISECONDS;
......
package com.ctrip.framework.apollo.configservice.service; package com.ctrip.framework.apollo.configservice.service;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.ctrip.framework.apollo.biz.config.BizConfig; import com.ctrip.framework.apollo.biz.config.BizConfig;
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; import com.ctrip.framework.apollo.biz.entity.ReleaseMessage;
import com.ctrip.framework.apollo.biz.message.Topics; import com.ctrip.framework.apollo.biz.message.Topics;
import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository; import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -23,9 +20,7 @@ import java.util.Set; ...@@ -23,9 +20,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -48,11 +43,9 @@ public class ReleaseMessageServiceWithCacheTest { ...@@ -48,11 +43,9 @@ public class ReleaseMessageServiceWithCacheTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
releaseMessageServiceWithCache = new ReleaseMessageServiceWithCache(); releaseMessageServiceWithCache = new ReleaseMessageServiceWithCache(
releaseMessageRepository, bizConfig
ReflectionTestUtils.setField(releaseMessageServiceWithCache, "releaseMessageRepository", );
releaseMessageRepository);
ReflectionTestUtils.setField(releaseMessageServiceWithCache, "bizConfig", bizConfig);
scanInterval = 10; scanInterval = 10;
scanIntervalTimeUnit = TimeUnit.MILLISECONDS; scanIntervalTimeUnit = TimeUnit.MILLISECONDS;
......
...@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.configservice.util; ...@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.configservice.util;
import com.ctrip.framework.apollo.biz.entity.Instance; import com.ctrip.framework.apollo.biz.entity.Instance;
import com.ctrip.framework.apollo.biz.entity.InstanceConfig; import com.ctrip.framework.apollo.biz.entity.InstanceConfig;
import com.ctrip.framework.apollo.biz.service.InstanceService; import com.ctrip.framework.apollo.biz.service.InstanceService;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -16,10 +15,7 @@ import java.util.concurrent.BlockingQueue; ...@@ -16,10 +15,7 @@ import java.util.concurrent.BlockingQueue;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -45,9 +41,7 @@ public class InstanceConfigAuditUtilTest { ...@@ -45,9 +41,7 @@ public class InstanceConfigAuditUtilTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
instanceConfigAuditUtil = new InstanceConfigAuditUtil(); instanceConfigAuditUtil = new InstanceConfigAuditUtil(instanceService);
ReflectionTestUtils.setField(instanceConfigAuditUtil, "instanceService", instanceService);
audits = (BlockingQueue<InstanceConfigAuditUtil.InstanceConfigAuditModel>) audits = (BlockingQueue<InstanceConfigAuditUtil.InstanceConfigAuditModel>)
ReflectionTestUtils.getField(instanceConfigAuditUtil, "audits"); ReflectionTestUtils.getField(instanceConfigAuditUtil, "audits");
......
...@@ -2,20 +2,14 @@ package com.ctrip.framework.apollo.configservice.util; ...@@ -2,20 +2,14 @@ package com.ctrip.framework.apollo.configservice.util;
import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.configservice.service.AppNamespaceServiceWithCache; import com.ctrip.framework.apollo.configservice.service.AppNamespaceServiceWithCache;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.*;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
...@@ -29,8 +23,7 @@ public class NamespaceUtilTest { ...@@ -29,8 +23,7 @@ public class NamespaceUtilTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
namespaceUtil = new NamespaceUtil(); namespaceUtil = new NamespaceUtil(appNamespaceServiceWithCache);
ReflectionTestUtils.setField(namespaceUtil, "appNamespaceServiceWithCache", appNamespaceServiceWithCache);
} }
@Test @Test
......
package com.ctrip.framework.apollo.configservice.util; package com.ctrip.framework.apollo.configservice.util;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.configservice.service.AppNamespaceServiceWithCache;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.ctrip.framework.apollo.configservice.service.AppNamespaceServiceWithCache;
import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.core.ConfigConsts;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
...@@ -48,7 +45,7 @@ public class WatchKeysUtilTest { ...@@ -48,7 +45,7 @@ public class WatchKeysUtilTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
watchKeysUtil = new WatchKeysUtil(); watchKeysUtil = new WatchKeysUtil(appNamespaceService);
someAppId = "someId"; someAppId = "someId";
someCluster = "someCluster"; someCluster = "someCluster";
...@@ -77,8 +74,6 @@ public class WatchKeysUtilTest { ...@@ -77,8 +74,6 @@ public class WatchKeysUtilTest {
.thenReturn(Lists.newArrayList(somePublicAppNamespace)); .thenReturn(Lists.newArrayList(somePublicAppNamespace));
when(appNamespaceService.findPublicNamespacesByNames(Sets.newHashSet(someNamespace, somePublicNamespace))) when(appNamespaceService.findPublicNamespacesByNames(Sets.newHashSet(someNamespace, somePublicNamespace)))
.thenReturn(Lists.newArrayList(somePublicAppNamespace)); .thenReturn(Lists.newArrayList(somePublicAppNamespace));
ReflectionTestUtils.setField(watchKeysUtil, "appNamespaceService", appNamespaceService);
} }
@Test @Test
......
package com.ctrip.framework.apollo.demo.spring.springBootDemo.refresh; package com.ctrip.framework.apollo.demo.spring.springBootDemo.refresh;
import com.ctrip.framework.apollo.demo.spring.springBootDemo.config.SampleRedisConfig;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.context.scope.refresh.RefreshScope; import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.ctrip.framework.apollo.demo.spring.springBootDemo.config.SampleRedisConfig;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
...@@ -19,11 +17,15 @@ import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener; ...@@ -19,11 +17,15 @@ import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
public class SpringBootApolloRefreshConfig { public class SpringBootApolloRefreshConfig {
private static final Logger logger = LoggerFactory.getLogger(SpringBootApolloRefreshConfig.class); private static final Logger logger = LoggerFactory.getLogger(SpringBootApolloRefreshConfig.class);
@Autowired private final SampleRedisConfig sampleRedisConfig;
private SampleRedisConfig sampleRedisConfig; private final RefreshScope refreshScope;
@Autowired public SpringBootApolloRefreshConfig(
private RefreshScope refreshScope; final SampleRedisConfig sampleRedisConfig,
final RefreshScope refreshScope) {
this.sampleRedisConfig = sampleRedisConfig;
this.refreshScope = refreshScope;
}
@ApolloConfigChangeListener @ApolloConfigChangeListener
public void onChange(ConfigChangeEvent changeEvent) { public void onChange(ConfigChangeEvent changeEvent) {
......
...@@ -4,8 +4,6 @@ import com.ctrip.framework.apollo.openapi.service.ConsumerRolePermissionService; ...@@ -4,8 +4,6 @@ import com.ctrip.framework.apollo.openapi.service.ConsumerRolePermissionService;
import com.ctrip.framework.apollo.openapi.util.ConsumerAuthUtil; import com.ctrip.framework.apollo.openapi.util.ConsumerAuthUtil;
import com.ctrip.framework.apollo.portal.constant.PermissionType; import com.ctrip.framework.apollo.portal.constant.PermissionType;
import com.ctrip.framework.apollo.portal.util.RoleUtils; import com.ctrip.framework.apollo.portal.util.RoleUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -13,10 +11,15 @@ import javax.servlet.http.HttpServletRequest; ...@@ -13,10 +11,15 @@ import javax.servlet.http.HttpServletRequest;
@Component @Component
public class ConsumerPermissionValidator { public class ConsumerPermissionValidator {
@Autowired private final ConsumerRolePermissionService permissionService;
private ConsumerRolePermissionService permissionService; private final ConsumerAuthUtil consumerAuthUtil;
@Autowired
private ConsumerAuthUtil consumerAuthUtil; public ConsumerPermissionValidator(
final ConsumerRolePermissionService permissionService,
final ConsumerAuthUtil consumerAuthUtil) {
this.permissionService = permissionService;
this.consumerAuthUtil = consumerAuthUtil;
}
public boolean hasModifyNamespacePermission(HttpServletRequest request, String appId, String namespaceName, public boolean hasModifyNamespacePermission(HttpServletRequest request, String appId, String namespaceName,
......
package com.ctrip.framework.apollo.openapi.service; package com.ctrip.framework.apollo.openapi.service;
import com.google.common.collect.FluentIterable;
import com.ctrip.framework.apollo.openapi.entity.ConsumerRole; import com.ctrip.framework.apollo.openapi.entity.ConsumerRole;
import com.ctrip.framework.apollo.openapi.repository.ConsumerRoleRepository; import com.ctrip.framework.apollo.openapi.repository.ConsumerRoleRepository;
import com.ctrip.framework.apollo.portal.entity.po.Permission; import com.ctrip.framework.apollo.portal.entity.po.Permission;
import com.ctrip.framework.apollo.portal.entity.po.RolePermission; import com.ctrip.framework.apollo.portal.entity.po.RolePermission;
import com.ctrip.framework.apollo.portal.repository.PermissionRepository; import com.ctrip.framework.apollo.portal.repository.PermissionRepository;
import com.ctrip.framework.apollo.portal.repository.RolePermissionRepository; import com.ctrip.framework.apollo.portal.repository.RolePermissionRepository;
import com.google.common.collect.FluentIterable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -21,12 +18,18 @@ import java.util.Set; ...@@ -21,12 +18,18 @@ import java.util.Set;
*/ */
@Service @Service
public class ConsumerRolePermissionService { public class ConsumerRolePermissionService {
@Autowired private final PermissionRepository permissionRepository;
private PermissionRepository permissionRepository; private final ConsumerRoleRepository consumerRoleRepository;
@Autowired private final RolePermissionRepository rolePermissionRepository;
private ConsumerRoleRepository consumerRoleRepository;
@Autowired public ConsumerRolePermissionService(
private RolePermissionRepository rolePermissionRepository; final PermissionRepository permissionRepository,
final ConsumerRoleRepository consumerRoleRepository,
final RolePermissionRepository rolePermissionRepository) {
this.permissionRepository = permissionRepository;
this.consumerRoleRepository = consumerRoleRepository;
this.rolePermissionRepository = rolePermissionRepository;
}
/** /**
* Check whether user has the permission * Check whether user has the permission
......
package com.ctrip.framework.apollo.openapi.service; package com.ctrip.framework.apollo.openapi.service;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.hash.Hashing;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.openapi.entity.Consumer; import com.ctrip.framework.apollo.openapi.entity.Consumer;
import com.ctrip.framework.apollo.openapi.entity.ConsumerAudit; import com.ctrip.framework.apollo.openapi.entity.ConsumerAudit;
...@@ -22,9 +16,12 @@ import com.ctrip.framework.apollo.portal.service.RolePermissionService; ...@@ -22,9 +16,12 @@ import com.ctrip.framework.apollo.portal.service.RolePermissionService;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.UserService; import com.ctrip.framework.apollo.portal.spi.UserService;
import com.ctrip.framework.apollo.portal.util.RoleUtils; import com.ctrip.framework.apollo.portal.util.RoleUtils;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.hash.Hashing;
import org.apache.commons.lang.time.FastDateFormat; import org.apache.commons.lang.time.FastDateFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -41,22 +38,33 @@ public class ConsumerService { ...@@ -41,22 +38,33 @@ public class ConsumerService {
private static final FastDateFormat TIMESTAMP_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss"); private static final FastDateFormat TIMESTAMP_FORMAT = FastDateFormat.getInstance("yyyyMMddHHmmss");
private static final Joiner KEY_JOINER = Joiner.on("|"); private static final Joiner KEY_JOINER = Joiner.on("|");
@Autowired private final UserInfoHolder userInfoHolder;
private UserInfoHolder userInfoHolder; private final ConsumerTokenRepository consumerTokenRepository;
@Autowired private final ConsumerRepository consumerRepository;
private ConsumerTokenRepository consumerTokenRepository; private final ConsumerAuditRepository consumerAuditRepository;
@Autowired private final ConsumerRoleRepository consumerRoleRepository;
private ConsumerRepository consumerRepository; private final PortalConfig portalConfig;
@Autowired private final RolePermissionService rolePermissionService;
private ConsumerAuditRepository consumerAuditRepository; private final UserService userService;
@Autowired
private ConsumerRoleRepository consumerRoleRepository; public ConsumerService(
@Autowired final UserInfoHolder userInfoHolder,
private PortalConfig portalConfig; final ConsumerTokenRepository consumerTokenRepository,
@Autowired final ConsumerRepository consumerRepository,
private RolePermissionService rolePermissionService; final ConsumerAuditRepository consumerAuditRepository,
@Autowired final ConsumerRoleRepository consumerRoleRepository,
private UserService userService; final PortalConfig portalConfig,
final RolePermissionService rolePermissionService,
final UserService userService) {
this.userInfoHolder = userInfoHolder;
this.consumerTokenRepository = consumerTokenRepository;
this.consumerRepository = consumerRepository;
this.consumerAuditRepository = consumerAuditRepository;
this.consumerRoleRepository = consumerRoleRepository;
this.portalConfig = portalConfig;
this.rolePermissionService = rolePermissionService;
this.userService = userService;
}
public Consumer createConsumer(Consumer consumer) { public Consumer createConsumer(Consumer consumer) {
......
package com.ctrip.framework.apollo.openapi.util; package com.ctrip.framework.apollo.openapi.util;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.openapi.entity.ConsumerAudit; import com.ctrip.framework.apollo.openapi.entity.ConsumerAudit;
import com.ctrip.framework.apollo.openapi.service.ConsumerService; import com.ctrip.framework.apollo.openapi.service.ConsumerService;
import com.ctrip.framework.apollo.tracer.Tracer; import com.ctrip.framework.apollo.tracer.Tracer;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
...@@ -21,8 +19,6 @@ import java.util.concurrent.Executors; ...@@ -21,8 +19,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.http.HttpServletRequest;
/** /**
* @author Jason Song(song_s@ctrip.com) * @author Jason Song(song_s@ctrip.com)
*/ */
...@@ -36,10 +32,10 @@ public class ConsumerAuditUtil implements InitializingBean { ...@@ -36,10 +32,10 @@ public class ConsumerAuditUtil implements InitializingBean {
private long BATCH_TIMEOUT = 5; private long BATCH_TIMEOUT = 5;
private TimeUnit BATCH_TIMEUNIT = TimeUnit.SECONDS; private TimeUnit BATCH_TIMEUNIT = TimeUnit.SECONDS;
@Autowired private final ConsumerService consumerService;
private ConsumerService consumerService;
public ConsumerAuditUtil() { public ConsumerAuditUtil(final ConsumerService consumerService) {
this.consumerService = consumerService;
auditExecutorService = Executors.newSingleThreadExecutor( auditExecutorService = Executors.newSingleThreadExecutor(
ApolloThreadFactory.create("ConsumerAuditUtil", true)); ApolloThreadFactory.create("ConsumerAuditUtil", true));
auditStopped = new AtomicBoolean(false); auditStopped = new AtomicBoolean(false);
......
package com.ctrip.framework.apollo.openapi.util; package com.ctrip.framework.apollo.openapi.util;
import com.ctrip.framework.apollo.openapi.service.ConsumerService; import com.ctrip.framework.apollo.openapi.service.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -13,8 +11,11 @@ import javax.servlet.http.HttpServletRequest; ...@@ -13,8 +11,11 @@ import javax.servlet.http.HttpServletRequest;
@Service @Service
public class ConsumerAuthUtil { public class ConsumerAuthUtil {
static final String CONSUMER_ID = "ApolloConsumerId"; static final String CONSUMER_ID = "ApolloConsumerId";
@Autowired private final ConsumerService consumerService;
private ConsumerService consumerService;
public ConsumerAuthUtil(final ConsumerService consumerService) {
this.consumerService = consumerService;
}
public Long getConsumerId(String token) { public Long getConsumerId(String token) {
return consumerService.getConsumerIdByToken(token); return consumerService.getConsumerIdByToken(token);
......
...@@ -6,7 +6,6 @@ import com.ctrip.framework.apollo.core.enums.Env; ...@@ -6,7 +6,6 @@ import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.openapi.dto.OpenEnvClusterDTO; import com.ctrip.framework.apollo.openapi.dto.OpenEnvClusterDTO;
import com.ctrip.framework.apollo.portal.component.PortalSettings; import com.ctrip.framework.apollo.portal.component.PortalSettings;
import com.ctrip.framework.apollo.portal.service.ClusterService; import com.ctrip.framework.apollo.portal.service.ClusterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -19,10 +18,13 @@ import java.util.List; ...@@ -19,10 +18,13 @@ import java.util.List;
@RequestMapping("/openapi/v1") @RequestMapping("/openapi/v1")
public class AppController { public class AppController {
@Autowired private final PortalSettings portalSettings;
private PortalSettings portalSettings; private final ClusterService clusterService;
@Autowired
private ClusterService clusterService; public AppController(final PortalSettings portalSettings, final ClusterService clusterService) {
this.portalSettings = portalSettings;
this.clusterService = clusterService;
}
@GetMapping(value = "/apps/{appId}/envclusters") @GetMapping(value = "/apps/{appId}/envclusters")
public List<OpenEnvClusterDTO> loadEnvClusterInfo(@PathVariable String appId){ public List<OpenEnvClusterDTO> loadEnvClusterInfo(@PathVariable String appId){
......
...@@ -9,7 +9,6 @@ import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO; ...@@ -9,7 +9,6 @@ import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;
import com.ctrip.framework.apollo.openapi.util.OpenApiBeanUtils; import com.ctrip.framework.apollo.openapi.util.OpenApiBeanUtils;
import com.ctrip.framework.apollo.portal.service.ItemService; import com.ctrip.framework.apollo.portal.service.ItemService;
import com.ctrip.framework.apollo.portal.spi.UserService; import com.ctrip.framework.apollo.portal.spi.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
...@@ -30,10 +29,13 @@ import javax.servlet.http.HttpServletRequest; ...@@ -30,10 +29,13 @@ import javax.servlet.http.HttpServletRequest;
@RequestMapping("/openapi/v1/envs/{env}") @RequestMapping("/openapi/v1/envs/{env}")
public class ItemController { public class ItemController {
@Autowired private final ItemService itemService;
private ItemService itemService; private final UserService userService;
@Autowired
private UserService userService; public ItemController(final ItemService itemService, final UserService userService) {
this.itemService = itemService;
this.userService = userService;
}
@GetMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{key:.+}") @GetMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{key:.+}")
public OpenItemDTO getItem(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName, public OpenItemDTO getItem(@PathVariable String appId, @PathVariable String env, @PathVariable String clusterName,
......
...@@ -19,10 +19,17 @@ import com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO; ...@@ -19,10 +19,17 @@ import com.ctrip.framework.apollo.portal.entity.bo.NamespaceBO;
import com.ctrip.framework.apollo.portal.service.NamespaceBranchService; import com.ctrip.framework.apollo.portal.service.NamespaceBranchService;
import com.ctrip.framework.apollo.portal.service.ReleaseService; import com.ctrip.framework.apollo.portal.service.ReleaseService;
import com.ctrip.framework.apollo.portal.spi.UserService; import com.ctrip.framework.apollo.portal.spi.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -30,14 +37,21 @@ import javax.servlet.http.HttpServletRequest; ...@@ -30,14 +37,21 @@ import javax.servlet.http.HttpServletRequest;
@RequestMapping("/openapi/v1/envs/{env}") @RequestMapping("/openapi/v1/envs/{env}")
public class NamespaceBranchController { public class NamespaceBranchController {
@Autowired private final ConsumerPermissionValidator consumerPermissionValidator;
private ConsumerPermissionValidator consumerPermissionValidator; private final ReleaseService releaseService;
@Autowired private final NamespaceBranchService namespaceBranchService;
private ReleaseService releaseService; private final UserService userService;
@Autowired
private NamespaceBranchService namespaceBranchService; public NamespaceBranchController(
@Autowired final ConsumerPermissionValidator consumerPermissionValidator,
private UserService userService; final ReleaseService releaseService,
final NamespaceBranchService namespaceBranchService,
final UserService userService) {
this.consumerPermissionValidator = consumerPermissionValidator;
this.releaseService = releaseService;
this.namespaceBranchService = namespaceBranchService;
this.userService = userService;
}
@GetMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches") @GetMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches")
public OpenNamespaceDTO findBranch(@PathVariable String appId, public OpenNamespaceDTO findBranch(@PathVariable String appId,
......
...@@ -19,7 +19,6 @@ import com.ctrip.framework.apollo.portal.service.AppNamespaceService; ...@@ -19,7 +19,6 @@ import com.ctrip.framework.apollo.portal.service.AppNamespaceService;
import com.ctrip.framework.apollo.portal.service.NamespaceLockService; import com.ctrip.framework.apollo.portal.service.NamespaceLockService;
import com.ctrip.framework.apollo.portal.service.NamespaceService; import com.ctrip.framework.apollo.portal.service.NamespaceService;
import com.ctrip.framework.apollo.portal.spi.UserService; import com.ctrip.framework.apollo.portal.spi.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -35,16 +34,24 @@ import java.util.Objects; ...@@ -35,16 +34,24 @@ import java.util.Objects;
@RestController("openapiNamespaceController") @RestController("openapiNamespaceController")
public class NamespaceController { public class NamespaceController {
@Autowired private final NamespaceLockService namespaceLockService;
private NamespaceLockService namespaceLockService; private final NamespaceService namespaceService;
@Autowired private final AppNamespaceService appNamespaceService;
private NamespaceService namespaceService; private final ApplicationEventPublisher publisher;
@Autowired private final UserService userService;
private AppNamespaceService appNamespaceService;
@Autowired public NamespaceController(
private ApplicationEventPublisher publisher; final NamespaceLockService namespaceLockService,
@Autowired final NamespaceService namespaceService,
private UserService userService; final AppNamespaceService appNamespaceService,
final ApplicationEventPublisher publisher,
final UserService userService) {
this.namespaceLockService = namespaceLockService;
this.namespaceService = namespaceService;
this.appNamespaceService = appNamespaceService;
this.publisher = publisher;
this.userService = userService;
}
@PreAuthorize(value = "@consumerPermissionValidator.hasCreateNamespacePermission(#request, #appId)") @PreAuthorize(value = "@consumerPermissionValidator.hasCreateNamespacePermission(#request, #appId)")
......
...@@ -15,7 +15,6 @@ import com.ctrip.framework.apollo.portal.entity.model.NamespaceReleaseModel; ...@@ -15,7 +15,6 @@ import com.ctrip.framework.apollo.portal.entity.model.NamespaceReleaseModel;
import com.ctrip.framework.apollo.portal.service.NamespaceBranchService; import com.ctrip.framework.apollo.portal.service.NamespaceBranchService;
import com.ctrip.framework.apollo.portal.service.ReleaseService; import com.ctrip.framework.apollo.portal.service.ReleaseService;
import com.ctrip.framework.apollo.portal.spi.UserService; import com.ctrip.framework.apollo.portal.spi.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -33,12 +32,18 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM ...@@ -33,12 +32,18 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM
@RequestMapping("/openapi/v1/envs/{env}") @RequestMapping("/openapi/v1/envs/{env}")
public class ReleaseController { public class ReleaseController {
@Autowired private final ReleaseService releaseService;
private ReleaseService releaseService; private final UserService userService;
@Autowired private final NamespaceBranchService namespaceBranchService;
private UserService userService;
@Autowired public ReleaseController(
private NamespaceBranchService namespaceBranchService; final ReleaseService releaseService,
final UserService userService,
final NamespaceBranchService namespaceBranchService) {
this.releaseService = releaseService;
this.userService = userService;
this.namespaceBranchService = namespaceBranchService;
}
@PreAuthorize(value = "@consumerPermissionValidator.hasReleaseNamespacePermission(#request, #appId, #namespaceName, #env)") @PreAuthorize(value = "@consumerPermissionValidator.hasReleaseNamespacePermission(#request, #appId, #namespaceName, #env)")
@PostMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases") @PostMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases")
......
package com.ctrip.framework.apollo.portal.component; package com.ctrip.framework.apollo.portal.component;
import com.google.common.collect.Lists;
import com.ctrip.framework.apollo.core.MetaDomainConsts; import com.ctrip.framework.apollo.core.MetaDomainConsts;
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.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.tracer.Tracer; import com.ctrip.framework.apollo.tracer.Tracer;
import com.google.common.collect.Lists;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters; import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -25,8 +23,6 @@ import java.util.concurrent.Executors; ...@@ -25,8 +23,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
@Component @Component
public class AdminServiceAddressLocator { public class AdminServiceAddressLocator {
...@@ -41,12 +37,16 @@ public class AdminServiceAddressLocator { ...@@ -41,12 +37,16 @@ public class AdminServiceAddressLocator {
private List<Env> allEnvs; private List<Env> allEnvs;
private Map<Env, List<ServiceDTO>> cache = new ConcurrentHashMap<>(); private Map<Env, List<ServiceDTO>> cache = new ConcurrentHashMap<>();
@Autowired private final PortalSettings portalSettings;
private HttpMessageConverters httpMessageConverters; private final RestTemplateFactory restTemplateFactory;
@Autowired
private PortalSettings portalSettings; public AdminServiceAddressLocator(
@Autowired final HttpMessageConverters httpMessageConverters,
private RestTemplateFactory restTemplateFactory; final PortalSettings portalSettings,
final RestTemplateFactory restTemplateFactory) {
this.portalSettings = portalSettings;
this.restTemplateFactory = restTemplateFactory;
}
@PostConstruct @PostConstruct
public void init() { public void init() {
......
...@@ -7,20 +7,26 @@ import com.ctrip.framework.apollo.portal.service.AppNamespaceService; ...@@ -7,20 +7,26 @@ import com.ctrip.framework.apollo.portal.service.AppNamespaceService;
import com.ctrip.framework.apollo.portal.service.RolePermissionService; import com.ctrip.framework.apollo.portal.service.RolePermissionService;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.util.RoleUtils; import com.ctrip.framework.apollo.portal.util.RoleUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component("permissionValidator") @Component("permissionValidator")
public class PermissionValidator { public class PermissionValidator {
@Autowired private final UserInfoHolder userInfoHolder;
private UserInfoHolder userInfoHolder; private final RolePermissionService rolePermissionService;
@Autowired private final PortalConfig portalConfig;
private RolePermissionService rolePermissionService; private final AppNamespaceService appNamespaceService;
@Autowired
private PortalConfig portalConfig; public PermissionValidator(
@Autowired final UserInfoHolder userInfoHolder,
private AppNamespaceService appNamespaceService; final RolePermissionService rolePermissionService,
final PortalConfig portalConfig,
final AppNamespaceService appNamespaceService) {
this.userInfoHolder = userInfoHolder;
this.rolePermissionService = rolePermissionService;
this.portalConfig = portalConfig;
this.appNamespaceService = appNamespaceService;
}
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(),
......
...@@ -6,14 +6,13 @@ import com.ctrip.framework.apollo.core.enums.Env; ...@@ -6,14 +6,13 @@ import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.portal.api.AdminServiceAPI; import com.ctrip.framework.apollo.portal.api.AdminServiceAPI;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig; import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Health;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -24,25 +23,25 @@ import java.util.concurrent.Executors; ...@@ -24,25 +23,25 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
@Component @Component
public class PortalSettings { public class PortalSettings {
private static final Logger logger = LoggerFactory.getLogger(PortalSettings.class); private static final Logger logger = LoggerFactory.getLogger(PortalSettings.class);
private static final int HEALTH_CHECK_INTERVAL = 10 * 1000; private static final int HEALTH_CHECK_INTERVAL = 10 * 1000;
@Autowired private final ApplicationContext applicationContext;
ApplicationContext applicationContext; private final PortalConfig portalConfig;
@Autowired
private PortalConfig portalConfig;
private List<Env> allEnvs = new ArrayList<>(); private List<Env> allEnvs = new ArrayList<>();
//mark env up or down //mark env up or down
private Map<Env, Boolean> envStatusMark = new ConcurrentHashMap<>(); private Map<Env, Boolean> envStatusMark = new ConcurrentHashMap<>();
public PortalSettings(final ApplicationContext applicationContext, final PortalConfig portalConfig) {
this.applicationContext = applicationContext;
this.portalConfig = portalConfig;
}
@PostConstruct @PostConstruct
private void postConstruct() { private void postConstruct() {
......
package com.ctrip.framework.apollo.portal.component; package com.ctrip.framework.apollo.portal.component;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig; import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
......
...@@ -7,12 +7,11 @@ import com.ctrip.framework.apollo.core.enums.Env; ...@@ -7,12 +7,11 @@ import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.constant.TracerEventType; import com.ctrip.framework.apollo.portal.constant.TracerEventType;
import com.ctrip.framework.apollo.tracer.Tracer; import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction; import com.ctrip.framework.apollo.tracer.spi.Transaction;
import org.apache.http.conn.ConnectTimeoutException; import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpHostConnectException; import org.apache.http.conn.HttpHostConnectException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy;
import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
...@@ -23,11 +22,10 @@ import org.springframework.web.client.RestTemplate; ...@@ -23,11 +22,10 @@ import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.DefaultUriBuilderFactory; import org.springframework.web.util.DefaultUriBuilderFactory;
import org.springframework.web.util.UriTemplateHandler; import org.springframework.web.util.UriTemplateHandler;
import javax.annotation.PostConstruct;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.util.List; import java.util.List;
import javax.annotation.PostConstruct;
/** /**
* 封装RestTemplate. admin server集群在某些机器宕机或者超时的情况下轮询重试 * 封装RestTemplate. admin server集群在某些机器宕机或者超时的情况下轮询重试
*/ */
...@@ -40,10 +38,15 @@ public class RetryableRestTemplate { ...@@ -40,10 +38,15 @@ public class RetryableRestTemplate {
private RestTemplate restTemplate; private RestTemplate restTemplate;
@Autowired private final RestTemplateFactory restTemplateFactory;
private RestTemplateFactory restTemplateFactory; private final AdminServiceAddressLocator adminServiceAddressLocator;
@Autowired
private AdminServiceAddressLocator adminServiceAddressLocator; public RetryableRestTemplate(
final @Lazy RestTemplateFactory restTemplateFactory,
final @Lazy AdminServiceAddressLocator adminServiceAddressLocator) {
this.restTemplateFactory = restTemplateFactory;
this.adminServiceAddressLocator = adminServiceAddressLocator;
}
@PostConstruct @PostConstruct
......
package com.ctrip.framework.apollo.portal.component.config; package com.ctrip.framework.apollo.portal.component.config;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ctrip.framework.apollo.common.config.RefreshableConfig; import com.ctrip.framework.apollo.common.config.RefreshableConfig;
import com.ctrip.framework.apollo.common.config.RefreshablePropertySource; import com.ctrip.framework.apollo.common.config.RefreshablePropertySource;
import com.ctrip.framework.apollo.core.enums.Env; import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.entity.vo.Organization; import com.ctrip.framework.apollo.portal.entity.vo.Organization;
import com.ctrip.framework.apollo.portal.service.PortalDBPropertySource; import com.ctrip.framework.apollo.portal.service.PortalDBPropertySource;
import com.google.common.base.Strings;
import org.springframework.beans.factory.annotation.Autowired; import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.lang.reflect.Type; import java.lang.reflect.Type;
...@@ -29,8 +26,11 @@ public class PortalConfig extends RefreshableConfig { ...@@ -29,8 +26,11 @@ public class PortalConfig extends RefreshableConfig {
private static final Type ORGANIZATION = new TypeToken<List<Organization>>() { private static final Type ORGANIZATION = new TypeToken<List<Organization>>() {
}.getType(); }.getType();
@Autowired private final PortalDBPropertySource portalDBPropertySource;
private PortalDBPropertySource portalDBPropertySource;
public PortalConfig(final PortalDBPropertySource portalDBPropertySource) {
this.portalDBPropertySource = portalDBPropertySource;
}
@Override @Override
public List<RefreshablePropertySource> getRefreshablePropertySources() { public List<RefreshablePropertySource> getRefreshablePropertySources() {
......
...@@ -22,7 +22,6 @@ import com.ctrip.framework.apollo.portal.service.RolePermissionService; ...@@ -22,7 +22,6 @@ import com.ctrip.framework.apollo.portal.service.RolePermissionService;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.util.RoleUtils; import com.ctrip.framework.apollo.portal.util.RoleUtils;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -50,18 +49,27 @@ import java.util.Set; ...@@ -50,18 +49,27 @@ import java.util.Set;
@RequestMapping("/apps") @RequestMapping("/apps")
public class AppController { public class AppController {
@Autowired private final UserInfoHolder userInfoHolder;
private UserInfoHolder userInfoHolder; private final AppService appService;
@Autowired private final PortalSettings portalSettings;
private AppService appService; private final ApplicationEventPublisher publisher;
@Autowired private final RolePermissionService rolePermissionService;
private PortalSettings portalSettings; private final RoleInitializationService roleInitializationService;
@Autowired
private ApplicationEventPublisher publisher; public AppController(
@Autowired final UserInfoHolder userInfoHolder,
private RolePermissionService rolePermissionService; final AppService appService,
@Autowired final PortalSettings portalSettings,
private RoleInitializationService roleInitializationService; final ApplicationEventPublisher publisher,
final RolePermissionService rolePermissionService,
final RoleInitializationService roleInitializationService) {
this.userInfoHolder = userInfoHolder;
this.appService = appService;
this.portalSettings = portalSettings;
this.publisher = publisher;
this.rolePermissionService = rolePermissionService;
this.roleInitializationService = roleInitializationService;
}
@GetMapping @GetMapping
public List<App> findApps(@RequestParam(value = "appIds", required = false) String appIds) { public List<App> findApps(@RequestParam(value = "appIds", required = false) String appIds) {
......
...@@ -7,7 +7,6 @@ import com.ctrip.framework.apollo.common.utils.RequestPrecondition; ...@@ -7,7 +7,6 @@ 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.ClusterService; import com.ctrip.framework.apollo.portal.service.ClusterService;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
...@@ -24,10 +23,13 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM ...@@ -24,10 +23,13 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM
@RestController @RestController
public class ClusterController { public class ClusterController {
@Autowired private final ClusterService clusterService;
private ClusterService clusterService; private final UserInfoHolder userInfoHolder;
@Autowired
private UserInfoHolder userInfoHolder; public ClusterController(final ClusterService clusterService, final UserInfoHolder userInfoHolder) {
this.clusterService = clusterService;
this.userInfoHolder = userInfoHolder;
}
@PreAuthorize(value = "@permissionValidator.hasCreateClusterPermission(#appId)") @PreAuthorize(value = "@permissionValidator.hasCreateClusterPermission(#appId)")
@PostMapping(value = "apps/{appId}/envs/{env}/clusters") @PostMapping(value = "apps/{appId}/envs/{env}/clusters")
......
...@@ -5,7 +5,6 @@ import com.ctrip.framework.apollo.common.utils.RequestPrecondition; ...@@ -5,7 +5,6 @@ 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.component.PermissionValidator; import com.ctrip.framework.apollo.portal.component.PermissionValidator;
import com.ctrip.framework.apollo.portal.service.CommitService; import com.ctrip.framework.apollo.portal.service.CommitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -18,11 +17,13 @@ import java.util.List; ...@@ -18,11 +17,13 @@ import java.util.List;
@RestController @RestController
public class CommitController { public class CommitController {
@Autowired private final CommitService commitService;
private CommitService commitService; private final PermissionValidator permissionValidator;
@Autowired public CommitController(final CommitService commitService, final PermissionValidator permissionValidator) {
private PermissionValidator permissionValidator; this.commitService = commitService;
this.permissionValidator = permissionValidator;
}
@GetMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/commits") @GetMapping("/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,
......
...@@ -13,7 +13,7 @@ import com.ctrip.framework.apollo.portal.service.NamespaceService; ...@@ -13,7 +13,7 @@ import com.ctrip.framework.apollo.portal.service.NamespaceService;
import com.ctrip.framework.apollo.portal.util.ConfigToFileUtils; import com.ctrip.framework.apollo.portal.util.ConfigToFileUtils;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -34,11 +34,16 @@ import java.util.stream.Collectors; ...@@ -34,11 +34,16 @@ import java.util.stream.Collectors;
@RestController @RestController
public class ConfigsExportController { public class ConfigsExportController {
@Autowired private final ItemService configService;
private ItemService configService;
@Autowired private final NamespaceService namespaceService;
private NamespaceService namespaceService;
public ConfigsExportController(
final ItemService configService,
final @Lazy NamespaceService namespaceService) {
this.configService = configService;
this.namespaceService = namespaceService;
}
@PostMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items/import") @PostMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items/import")
public void importConfigFile(@PathVariable String appId, @PathVariable String env, public void importConfigFile(@PathVariable String appId, @PathVariable String env,
......
...@@ -11,7 +11,6 @@ import com.ctrip.framework.apollo.openapi.entity.ConsumerToken; ...@@ -11,7 +11,6 @@ import com.ctrip.framework.apollo.openapi.entity.ConsumerToken;
import com.ctrip.framework.apollo.openapi.service.ConsumerService; import com.ctrip.framework.apollo.openapi.service.ConsumerService;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -38,8 +37,11 @@ public class ConsumerController { ...@@ -38,8 +37,11 @@ public class ConsumerController {
private static final Date DEFAULT_EXPIRES = new GregorianCalendar(2099, Calendar.JANUARY, 1).getTime(); private static final Date DEFAULT_EXPIRES = new GregorianCalendar(2099, Calendar.JANUARY, 1).getTime();
@Autowired private final ConsumerService consumerService;
private ConsumerService consumerService;
public ConsumerController(final ConsumerService consumerService) {
this.consumerService = consumerService;
}
@Transactional @Transactional
......
...@@ -2,7 +2,6 @@ package com.ctrip.framework.apollo.portal.controller; ...@@ -2,7 +2,6 @@ package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.core.enums.Env; import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.component.PortalSettings; import com.ctrip.framework.apollo.portal.component.PortalSettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -13,8 +12,11 @@ import java.util.List; ...@@ -13,8 +12,11 @@ import java.util.List;
@RequestMapping("/envs") @RequestMapping("/envs")
public class EnvController { public class EnvController {
@Autowired private final PortalSettings portalSettings;
private PortalSettings portalSettings;
public EnvController(final PortalSettings portalSettings) {
this.portalSettings = portalSettings;
}
@GetMapping @GetMapping
public List<Env> envs() { public List<Env> envs() {
......
...@@ -2,7 +2,6 @@ package com.ctrip.framework.apollo.portal.controller; ...@@ -2,7 +2,6 @@ package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.portal.entity.po.Favorite; import com.ctrip.framework.apollo.portal.entity.po.Favorite;
import com.ctrip.framework.apollo.portal.service.FavoriteService; import com.ctrip.framework.apollo.portal.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -18,8 +17,11 @@ import java.util.List; ...@@ -18,8 +17,11 @@ import java.util.List;
@RestController @RestController
public class FavoriteController { public class FavoriteController {
@Autowired private final FavoriteService favoriteService;
private FavoriteService favoriteService;
public FavoriteController(final FavoriteService favoriteService) {
this.favoriteService = favoriteService;
}
@PostMapping("/favorites") @PostMapping("/favorites")
......
...@@ -7,7 +7,6 @@ import com.ctrip.framework.apollo.core.enums.Env; ...@@ -7,7 +7,6 @@ import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.entity.vo.Number; import com.ctrip.framework.apollo.portal.entity.vo.Number;
import com.ctrip.framework.apollo.portal.service.InstanceService; import com.ctrip.framework.apollo.portal.service.InstanceService;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -25,8 +24,11 @@ public class InstanceController { ...@@ -25,8 +24,11 @@ public class InstanceController {
private static final Splitter RELEASES_SPLITTER = Splitter.on(",").omitEmptyStrings() private static final Splitter RELEASES_SPLITTER = Splitter.on(",").omitEmptyStrings()
.trimResults(); .trimResults();
@Autowired private final InstanceService instanceService;
private InstanceService instanceService;
public InstanceController(final InstanceService instanceService) {
this.instanceService = instanceService;
}
@GetMapping("/envs/{env}/instances/by-release") @GetMapping("/envs/{env}/instances/by-release")
public PageDTO<InstanceDTO> getByRelease(@PathVariable String env, @RequestParam long releaseId, public PageDTO<InstanceDTO> getByRelease(@PathVariable String env, @RequestParam long releaseId,
......
...@@ -12,7 +12,6 @@ import com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs; ...@@ -12,7 +12,6 @@ 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.service.ItemService; import com.ctrip.framework.apollo.portal.service.ItemService;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
...@@ -35,12 +34,15 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM ...@@ -35,12 +34,15 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM
@RestController @RestController
public class ItemController { public class ItemController {
@Autowired private final ItemService configService;
private ItemService configService; private final UserInfoHolder userInfoHolder;
@Autowired private final PermissionValidator permissionValidator;
private UserInfoHolder userInfoHolder;
@Autowired public ItemController(final ItemService configService, final UserInfoHolder userInfoHolder, final PermissionValidator permissionValidator) {
private PermissionValidator permissionValidator; this.configService = configService;
this.userInfoHolder = userInfoHolder;
this.permissionValidator = permissionValidator;
}
@PreAuthorize(value = "@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName, #env)") @PreAuthorize(value = "@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName, #env)")
@PutMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items", consumes = { @PutMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items", consumes = {
......
...@@ -12,7 +12,6 @@ import com.ctrip.framework.apollo.portal.entity.model.NamespaceReleaseModel; ...@@ -12,7 +12,6 @@ import com.ctrip.framework.apollo.portal.entity.model.NamespaceReleaseModel;
import com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent; import com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent;
import com.ctrip.framework.apollo.portal.service.NamespaceBranchService; import com.ctrip.framework.apollo.portal.service.NamespaceBranchService;
import com.ctrip.framework.apollo.portal.service.ReleaseService; import com.ctrip.framework.apollo.portal.service.ReleaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
...@@ -28,16 +27,24 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -28,16 +27,24 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class NamespaceBranchController { public class NamespaceBranchController {
@Autowired private final PermissionValidator permissionValidator;
private PermissionValidator permissionValidator; private final ReleaseService releaseService;
@Autowired private final NamespaceBranchService namespaceBranchService;
private ReleaseService releaseService; private final ApplicationEventPublisher publisher;
@Autowired private final PortalConfig portalConfig;
private NamespaceBranchService namespaceBranchService;
@Autowired public NamespaceBranchController(
private ApplicationEventPublisher publisher; final PermissionValidator permissionValidator,
@Autowired final ReleaseService releaseService,
private PortalConfig portalConfig; final NamespaceBranchService namespaceBranchService,
final ApplicationEventPublisher publisher,
final PortalConfig portalConfig) {
this.permissionValidator = permissionValidator;
this.releaseService = releaseService;
this.namespaceBranchService = namespaceBranchService;
this.publisher = publisher;
this.portalConfig = portalConfig;
}
@GetMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/branches") @GetMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/branches")
public NamespaceBO findBranch(@PathVariable String appId, public NamespaceBO findBranch(@PathVariable String appId,
......
...@@ -25,7 +25,6 @@ import com.ctrip.framework.apollo.tracer.Tracer; ...@@ -25,7 +25,6 @@ import com.ctrip.framework.apollo.tracer.Tracer;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
...@@ -50,22 +49,33 @@ public class NamespaceController { ...@@ -50,22 +49,33 @@ public class NamespaceController {
private static final Logger logger = LoggerFactory.getLogger(NamespaceController.class); private static final Logger logger = LoggerFactory.getLogger(NamespaceController.class);
@Autowired private final ApplicationEventPublisher publisher;
private ApplicationEventPublisher publisher; private final UserInfoHolder userInfoHolder;
@Autowired private final NamespaceService namespaceService;
private UserInfoHolder userInfoHolder; private final AppNamespaceService appNamespaceService;
@Autowired private final RoleInitializationService roleInitializationService;
private NamespaceService namespaceService; private final PortalConfig portalConfig;
@Autowired private final PermissionValidator permissionValidator;
private AppNamespaceService appNamespaceService; private final AdminServiceAPI.NamespaceAPI namespaceAPI;
@Autowired
private RoleInitializationService roleInitializationService; public NamespaceController(
@Autowired final ApplicationEventPublisher publisher,
private PortalConfig portalConfig; final UserInfoHolder userInfoHolder,
@Autowired final NamespaceService namespaceService,
private PermissionValidator permissionValidator; final AppNamespaceService appNamespaceService,
@Autowired final RoleInitializationService roleInitializationService,
private AdminServiceAPI.NamespaceAPI namespaceAPI; final PortalConfig portalConfig,
final PermissionValidator permissionValidator,
final AdminServiceAPI.NamespaceAPI namespaceAPI) {
this.publisher = publisher;
this.userInfoHolder = userInfoHolder;
this.namespaceService = namespaceService;
this.appNamespaceService = appNamespaceService;
this.roleInitializationService = roleInitializationService;
this.portalConfig = portalConfig;
this.permissionValidator = permissionValidator;
this.namespaceAPI = namespaceAPI;
}
@GetMapping("/appnamespaces/public") @GetMapping("/appnamespaces/public")
......
...@@ -4,7 +4,6 @@ import com.ctrip.framework.apollo.common.dto.NamespaceLockDTO; ...@@ -4,7 +4,6 @@ import com.ctrip.framework.apollo.common.dto.NamespaceLockDTO;
import com.ctrip.framework.apollo.core.enums.Env; import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.entity.vo.LockInfo; import com.ctrip.framework.apollo.portal.entity.vo.LockInfo;
import com.ctrip.framework.apollo.portal.service.NamespaceLockService; import com.ctrip.framework.apollo.portal.service.NamespaceLockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -12,8 +11,11 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -12,8 +11,11 @@ import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class NamespaceLockController { public class NamespaceLockController {
@Autowired private final NamespaceLockService namespaceLockService;
private NamespaceLockService namespaceLockService;
public NamespaceLockController(final NamespaceLockService namespaceLockService) {
this.namespaceLockService = namespaceLockService;
}
@Deprecated @Deprecated
@GetMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/lock") @GetMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/lock")
......
...@@ -3,8 +3,6 @@ package com.ctrip.framework.apollo.portal.controller; ...@@ -3,8 +3,6 @@ package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig; import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import com.ctrip.framework.apollo.portal.entity.vo.Organization; import com.ctrip.framework.apollo.portal.entity.vo.Organization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -17,8 +15,11 @@ import java.util.List; ...@@ -17,8 +15,11 @@ import java.util.List;
@RequestMapping("/organizations") @RequestMapping("/organizations")
public class OrganizationController { public class OrganizationController {
@Autowired private final PortalConfig portalConfig;
private PortalConfig portalConfig;
public OrganizationController(final PortalConfig portalConfig) {
this.portalConfig = portalConfig;
}
@RequestMapping @RequestMapping
......
...@@ -2,15 +2,17 @@ package com.ctrip.framework.apollo.portal.controller; ...@@ -2,15 +2,17 @@ package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.portal.component.config.PortalConfig; import com.ctrip.framework.apollo.portal.component.config.PortalConfig;
import com.ctrip.framework.apollo.portal.entity.vo.PageSetting; import com.ctrip.framework.apollo.portal.entity.vo.PageSetting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class PageSettingController { public class PageSettingController {
@Autowired private final PortalConfig portalConfig;
private PortalConfig portalConfig;
public PageSettingController(final PortalConfig portalConfig) {
this.portalConfig = portalConfig;
}
@GetMapping("/page-settings") @GetMapping("/page-settings")
public PageSetting getPageSetting() { public PageSetting getPageSetting() {
......
...@@ -16,7 +16,6 @@ import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; ...@@ -16,7 +16,6 @@ import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import com.ctrip.framework.apollo.portal.spi.UserService; import com.ctrip.framework.apollo.portal.spi.UserService;
import com.ctrip.framework.apollo.portal.util.RoleUtils; import com.ctrip.framework.apollo.portal.util.RoleUtils;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -34,14 +33,21 @@ import java.util.Set; ...@@ -34,14 +33,21 @@ import java.util.Set;
@RestController @RestController
public class PermissionController { public class PermissionController {
@Autowired private final UserInfoHolder userInfoHolder;
private UserInfoHolder userInfoHolder; private final RolePermissionService rolePermissionService;
@Autowired private final UserService userService;
private RolePermissionService rolePermissionService; private final RoleInitializationService roleInitializationService;
@Autowired
private UserService userService; public PermissionController(
@Autowired final UserInfoHolder userInfoHolder,
private RoleInitializationService roleInitializationService; final RolePermissionService rolePermissionService,
final UserService userService,
final RoleInitializationService roleInitializationService) {
this.userInfoHolder = userInfoHolder;
this.rolePermissionService = rolePermissionService;
this.userService = userService;
this.roleInitializationService = roleInitializationService;
}
@PostMapping("/apps/{appId}/initPermission") @PostMapping("/apps/{appId}/initPermission")
public ResponseEntity<Void> initAppPermission(@PathVariable String appId, @RequestBody String namespaceName) { public ResponseEntity<Void> initAppPermission(@PathVariable String appId, @RequestBody String namespaceName) {
......
...@@ -12,7 +12,6 @@ import com.ctrip.framework.apollo.portal.entity.model.NamespaceReleaseModel; ...@@ -12,7 +12,6 @@ import com.ctrip.framework.apollo.portal.entity.model.NamespaceReleaseModel;
import com.ctrip.framework.apollo.portal.entity.vo.ReleaseCompareResult; import com.ctrip.framework.apollo.portal.entity.vo.ReleaseCompareResult;
import com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent; import com.ctrip.framework.apollo.portal.listener.ConfigPublishEvent;
import com.ctrip.framework.apollo.portal.service.ReleaseService; import com.ctrip.framework.apollo.portal.service.ReleaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
...@@ -33,14 +32,21 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM ...@@ -33,14 +32,21 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM
@RestController @RestController
public class ReleaseController { public class ReleaseController {
@Autowired private final ReleaseService releaseService;
private ReleaseService releaseService; private final ApplicationEventPublisher publisher;
@Autowired private final PortalConfig portalConfig;
private ApplicationEventPublisher publisher; private final PermissionValidator permissionValidator;
@Autowired
private PortalConfig portalConfig; public ReleaseController(
@Autowired final ReleaseService releaseService,
private PermissionValidator permissionValidator; final ApplicationEventPublisher publisher,
final PortalConfig portalConfig,
final PermissionValidator permissionValidator) {
this.releaseService = releaseService;
this.publisher = publisher;
this.portalConfig = portalConfig;
this.permissionValidator = permissionValidator;
}
@PreAuthorize(value = "@permissionValidator.hasReleaseNamespacePermission(#appId, #namespaceName, #env)") @PreAuthorize(value = "@permissionValidator.hasReleaseNamespacePermission(#appId, #namespaceName, #env)")
@PostMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/releases") @PostMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/releases")
......
...@@ -5,7 +5,6 @@ import com.ctrip.framework.apollo.core.enums.Env; ...@@ -5,7 +5,6 @@ import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.portal.component.PermissionValidator; import com.ctrip.framework.apollo.portal.component.PermissionValidator;
import com.ctrip.framework.apollo.portal.entity.bo.ReleaseHistoryBO; import com.ctrip.framework.apollo.portal.entity.bo.ReleaseHistoryBO;
import com.ctrip.framework.apollo.portal.service.ReleaseHistoryService; import com.ctrip.framework.apollo.portal.service.ReleaseHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -17,10 +16,13 @@ import java.util.List; ...@@ -17,10 +16,13 @@ import java.util.List;
@RestController @RestController
public class ReleaseHistoryController { public class ReleaseHistoryController {
@Autowired private final ReleaseHistoryService releaseHistoryService;
private ReleaseHistoryService releaseHistoryService; private final PermissionValidator permissionValidator;
@Autowired
private PermissionValidator permissionValidator; public ReleaseHistoryController(final ReleaseHistoryService releaseHistoryService, final PermissionValidator permissionValidator) {
this.releaseHistoryService = releaseHistoryService;
this.permissionValidator = permissionValidator;
}
@GetMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/releases/histories") @GetMapping("/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/releases/histories")
public List<ReleaseHistoryBO> findReleaseHistoriesByNamespace(@PathVariable String appId, public List<ReleaseHistoryBO> findReleaseHistoriesByNamespace(@PathVariable String appId,
......
...@@ -6,7 +6,6 @@ import com.ctrip.framework.apollo.common.utils.RequestPrecondition; ...@@ -6,7 +6,6 @@ import com.ctrip.framework.apollo.common.utils.RequestPrecondition;
import com.ctrip.framework.apollo.portal.entity.po.ServerConfig; import com.ctrip.framework.apollo.portal.entity.po.ServerConfig;
import com.ctrip.framework.apollo.portal.repository.ServerConfigRepository; import com.ctrip.framework.apollo.portal.repository.ServerConfigRepository;
import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
...@@ -24,10 +23,13 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM ...@@ -24,10 +23,13 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM
@RestController @RestController
public class ServerConfigController { public class ServerConfigController {
@Autowired private final ServerConfigRepository serverConfigRepository;
private ServerConfigRepository serverConfigRepository; private final UserInfoHolder userInfoHolder;
@Autowired
private UserInfoHolder userInfoHolder; public ServerConfigController(final ServerConfigRepository serverConfigRepository, final UserInfoHolder userInfoHolder) {
this.serverConfigRepository = serverConfigRepository;
this.userInfoHolder = userInfoHolder;
}
@PreAuthorize(value = "@permissionValidator.isSuperAdmin()") @PreAuthorize(value = "@permissionValidator.isSuperAdmin()")
@PostMapping("/server/config") @PostMapping("/server/config")
......
package com.ctrip.framework.apollo.portal.controller; package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.portal.spi.SsoHeartbeatHandler; import com.ctrip.framework.apollo.portal.spi.SsoHeartbeatHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -18,8 +17,11 @@ import javax.servlet.http.HttpServletResponse; ...@@ -18,8 +17,11 @@ import javax.servlet.http.HttpServletResponse;
@Controller @Controller
@RequestMapping("/sso_heartbeat") @RequestMapping("/sso_heartbeat")
public class SsoHeartbeatController { public class SsoHeartbeatController {
@Autowired private final SsoHeartbeatHandler handler;
private SsoHeartbeatHandler handler;
public SsoHeartbeatController(final SsoHeartbeatHandler handler) {
this.handler = handler;
}
@GetMapping @GetMapping
public void heartbeat(HttpServletRequest request, HttpServletResponse response) { public void heartbeat(HttpServletRequest request, HttpServletResponse response) {
......
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