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