Skip to content

Commit

Permalink
Convert most @Autowired fields to constructor (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Graff committed Dec 18, 2017
1 parent e07ea90 commit c2044f6
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class BackendUpdater {
// is likely safe enough.
private boolean succeededAtLeastOnce = false;

public boolean run(RetrofitClientFactory retrofitClientFactory, ObjectMapper objectMapper, OkHttpClient okHttpClient) {
boolean run(RetrofitClientFactory retrofitClientFactory, ObjectMapper objectMapper, OkHttpClient okHttpClient) {
RemoteService remoteService = new RemoteService();
remoteService.setBaseUrl(uri);
BackendsRemoteService backendsRemoteService = retrofitClientFactory.createClient(BackendsRemoteService.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
@EnableConfigurationProperties
@ConditionalOnProperty("kayenta.atlas.enabled")
public class BackendUpdaterService extends AbstractHealthIndicator {
@Autowired
private RetrofitClientFactory retrofitClientFactory;

@Autowired
private ObjectMapper objectMapper;

@Autowired
private OkHttpClient okHttpClient;

private final RetrofitClientFactory retrofitClientFactory;
private final ObjectMapper objectMapper;
private final OkHttpClient okHttpClient;
private final List<BackendUpdater> backendUpdaters = new ArrayList<>();
private int checksCompleted = 0;

@Autowired
public BackendUpdaterService(RetrofitClientFactory retrofitClientFactory, ObjectMapper objectMapper, OkHttpClient okHttpClient) {
this.retrofitClientFactory = retrofitClientFactory;
this.objectMapper = objectMapper;
this.okHttpClient = okHttpClient;
}

@Scheduled(initialDelay = 2000, fixedDelay=122000)
public synchronized void run() {
// TODO: this will fetch the same uri even if they share the same URI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
@Slf4j
public class AtlasConfiguration {

private final BackendUpdaterService backendUpdaterService;

@Autowired
BackendUpdaterService backendUpdaterService;
public AtlasConfiguration(BackendUpdaterService backendUpdaterService) {
this.backendUpdaterService = backendUpdaterService;
}

@Bean
@ConfigurationProperties("kayenta.atlas")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ public class AtlasSSEConverter implements Converter {

private static final List<String> EXPECTED_RESULTS_TYPE_LIST = Arrays.asList("timeseries", "close");

private final ObjectMapper kayentaObjectMapper;

@Autowired
ObjectMapper kayentaObjectMapper;
public AtlasSSEConverter(ObjectMapper kayentaObjectMapper) {
this.kayentaObjectMapper = kayentaObjectMapper;
}

@Override
public List<AtlasResults> fromBody(TypedInput body, Type type) throws ConversionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
Expand All @@ -47,17 +48,18 @@
@Component
public class CanaryJudgeTask implements RetryableTask {

@Autowired
AccountCredentialsRepository accountCredentialsRepository;

@Autowired
StorageServiceRepository storageServiceRepository;
private final AccountCredentialsRepository accountCredentialsRepository;
private final StorageServiceRepository storageServiceRepository;
private final List<CanaryJudge> canaryJudges;
private final ObjectMapper objectMapper;

@Autowired
List<CanaryJudge> canaryJudges;

@Autowired
ObjectMapper objectMapper;
public CanaryJudgeTask(AccountCredentialsRepository accountCredentialsRepository, StorageServiceRepository storageServiceRepository, List<CanaryJudge> canaryJudges, ObjectMapper objectMapper) {
this.accountCredentialsRepository = accountCredentialsRepository;
this.storageServiceRepository = storageServiceRepository;
this.canaryJudges = canaryJudges;
this.objectMapper = objectMapper;
}

@Override
public long getBackoffPeriod() {
Expand All @@ -71,8 +73,9 @@ public long getTimeout() {
return Duration.ofMinutes(2).toMillis();
}

@Nonnull
@Override
public TaskResult execute(Stage stage) {
public TaskResult execute(@Nonnull Stage stage) {
Map<String, Object> context = stage.getContext();
String storageAccountName = (String)context.get("storageAccountName");
String resolvedStorageAccountName = CredentialsHelper.resolveAccountByNameOrType(storageAccountName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@
@Component
public class SetupCanaryTask implements RetryableTask {

@Autowired
private AccountCredentialsRepository accountCredentialsRepository;
private final AccountCredentialsRepository accountCredentialsRepository;
private final StorageServiceRepository storageServiceRepository;

@Autowired
private StorageServiceRepository storageServiceRepository;
public SetupCanaryTask(AccountCredentialsRepository accountCredentialsRepository, StorageServiceRepository storageServiceRepository) {
this.accountCredentialsRepository = accountCredentialsRepository;
this.storageServiceRepository = storageServiceRepository;
}

@Override
public long getBackoffPeriod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
@RequestMapping("/judges")
public class CanaryJudgesController {

private final List<CanaryJudge> canaryJudges;

@Autowired
List<CanaryJudge> canaryJudges;
public CanaryJudgesController(List<CanaryJudge> canaryJudges) {
this.canaryJudges = canaryJudges;
}

@ApiOperation(value = "Retrieve a list of all configured canary judges")
@RequestMapping(method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;

@Component
public class MetricSetMixerServiceStage {

@Bean
StageDefinitionBuilder metricSetMixerStageBuilder(){
return new StageDefinitionBuilder() {
@Override
public void taskGraph(Stage stage, TaskNode.Builder builder) {
public void taskGraph(@Nonnull Stage stage, @Nonnull TaskNode.Builder builder) {
builder.withTask("metricSetMixer", MetricSetMixerServiceTask.class);
}

@Nonnull
@Override
public String getType() {
return "metricSetMixer";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.time.Duration;
import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -65,8 +66,9 @@ public long getTimeout() {
return Duration.ofMinutes(2).toMillis();
}

@Nonnull
@Override
public TaskResult execute(Stage stage) {
public TaskResult execute(@Nonnull Stage stage) {
Map<String, Object> context = stage.getContext();
String storageAccountName = (String)context.get("storageAccountName");
List<String> controlMetricSetListIds = getMetricSetListIds(stage.getExecution(), (String)context.get("controlRefidPrefix"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@
public class GcsStorageService implements StorageService {

@Autowired
ObjectMapper kayentaObjectMapper;
private ObjectMapper kayentaObjectMapper;

@NotNull
@Singular
@Getter
private List<String> accountNames;

@Autowired
AccountCredentialsRepository accountCredentialsRepository;
private AccountCredentialsRepository accountCredentialsRepository;

@Autowired
CanaryConfigIndex canaryConfigIndex;
private CanaryConfigIndex canaryConfigIndex;

@Override
public boolean servicesAccount(String accountName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
@Slf4j
public class ConfigBinStorageService implements StorageService {

@Autowired
ObjectMapper kayentaObjectMapper;

@NotNull
@Singular
@Getter
private List<String> accountNames;

@Autowired
ObjectMapper kayentaObjectMapper;

@Autowired
AccountCredentialsRepository accountCredentialsRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@
@RequestMapping("/admin/orca")
public class AdminController {

private final ApplicationEventPublisher publisher;

@Autowired
ApplicationEventPublisher publisher;
public AdminController(ApplicationEventPublisher publisher) {
this.publisher = publisher;
}

@RequestMapping(value = "/instance/enabled", consumes = "application/json", method = RequestMethod.POST)
void setInstanceEnabled(@RequestBody Map<String, Boolean> enabledWrapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,24 @@
@Slf4j
public class PipelineController {

@Autowired
ExecutionLauncher executionLauncher;

@Autowired
ExecutionRepository executionRepository;

@Autowired
ExecutionLogRepository executionLogRepository;

@Autowired
ObjectMapper kayentaObjectMapper;

@Autowired
ConfigurableApplicationContext context;
private final ExecutionLauncher executionLauncher;
private final ExecutionRepository executionRepository;
private final ExecutionLogRepository executionLogRepository;
private final ObjectMapper kayentaObjectMapper;
private final ConfigurableApplicationContext context;
private final HealthEndpoint healthEndpoint;
private final ScheduledAnnotationBeanPostProcessor postProcessor;

@Autowired
HealthEndpoint healthEndpoint;

@Autowired
ScheduledAnnotationBeanPostProcessor postProcessor;
public PipelineController(ExecutionLauncher executionLauncher, ExecutionRepository executionRepository, ExecutionLogRepository executionLogRepository, ObjectMapper kayentaObjectMapper, ConfigurableApplicationContext context, HealthEndpoint healthEndpoint, ScheduledAnnotationBeanPostProcessor postProcessor) {
this.executionLauncher = executionLauncher;
this.executionRepository = executionRepository;
this.executionLogRepository = executionLogRepository;
this.kayentaObjectMapper = kayentaObjectMapper;
this.context = context;
this.healthEndpoint = healthEndpoint;
this.postProcessor = postProcessor;
}

// TODO(duftler): Expose /inservice and /outofservice endpoints.
@Scheduled(initialDelay = 10000, fixedDelay = 5000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@
@Slf4j
public class PrometheusResponseConverter implements Converter {

private final ObjectMapper kayentaObjectMapper;

@Autowired
ObjectMapper kayentaObjectMapper;
public PrometheusResponseConverter(ObjectMapper kayentaObjectMapper) {
this.kayentaObjectMapper = kayentaObjectMapper;
}

@Override
public List<PrometheusResults> fromBody(TypedInput body, Type type) throws ConversionException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ public class CanaryConfigController {

private static Pattern canaryConfigNamePattern = Pattern.compile("[A-Z,a-z,0-9,\\-,\\_]*");

@Autowired
AccountCredentialsRepository accountCredentialsRepository;
private final AccountCredentialsRepository accountCredentialsRepository;
private final StorageServiceRepository storageServiceRepository;

@Autowired
StorageServiceRepository storageServiceRepository;
public CanaryConfigController(AccountCredentialsRepository accountCredentialsRepository, StorageServiceRepository storageServiceRepository) {
this.accountCredentialsRepository = accountCredentialsRepository;
this.storageServiceRepository = storageServiceRepository;
}

@ApiOperation(value = "Retrieve a canary config from object storage")
@RequestMapping(value = "/{canaryConfigId:.+}", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@
@Slf4j
public class CanaryJudgeResultController {

@Autowired
AccountCredentialsRepository accountCredentialsRepository;
private final AccountCredentialsRepository accountCredentialsRepository;
private final StorageServiceRepository storageServiceRepository;

@Autowired
StorageServiceRepository storageServiceRepository;
public CanaryJudgeResultController(AccountCredentialsRepository accountCredentialsRepository, StorageServiceRepository storageServiceRepository) {
this.accountCredentialsRepository = accountCredentialsRepository;
this.storageServiceRepository = storageServiceRepository;
}

@ApiOperation(value = "Retrieve a canary judge result from object storage")
@RequestMapping(value = "/{canaryJudgeResultId:.+}", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@
@RequestMapping("/credentials")
public class CredentialsController {

private final AccountCredentialsRepository accountCredentialsRepository;

@Autowired
AccountCredentialsRepository accountCredentialsRepository;
public CredentialsController(AccountCredentialsRepository accountCredentialsRepository) {
this.accountCredentialsRepository = accountCredentialsRepository;
}

@ApiOperation(value = "Retrieve a list of all configured credentials")
@RequestMapping(method = RequestMethod.GET)
Set<? extends AccountCredentials> list() {
return accountCredentialsRepository.getAll();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@
@Slf4j
public class MetricSetListController {

@Autowired
AccountCredentialsRepository accountCredentialsRepository;
private final AccountCredentialsRepository accountCredentialsRepository;
private final StorageServiceRepository storageServiceRepository;

@Autowired
StorageServiceRepository storageServiceRepository;
public MetricSetListController(AccountCredentialsRepository accountCredentialsRepository, StorageServiceRepository storageServiceRepository) {
this.accountCredentialsRepository = accountCredentialsRepository;
this.storageServiceRepository = storageServiceRepository;
}

@ApiOperation(value = "Retrieve a metric set list from object storage")
@RequestMapping(value = "/{metricSetListId:.+}", method = RequestMethod.GET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@
@Slf4j
public class MetricSetPairListController {

@Autowired
AccountCredentialsRepository accountCredentialsRepository;
private final AccountCredentialsRepository accountCredentialsRepository;
private final StorageServiceRepository storageServiceRepository;

@Autowired
StorageServiceRepository storageServiceRepository;
public MetricSetPairListController(AccountCredentialsRepository accountCredentialsRepository, StorageServiceRepository storageServiceRepository) {
this.accountCredentialsRepository = accountCredentialsRepository;
this.storageServiceRepository = storageServiceRepository;
}

@ApiOperation(value = "Retrieve a metric set pair list from object storage")
@RequestMapping(value = "/{metricSetPairListId:.+}", method = RequestMethod.GET)
Expand Down

0 comments on commit c2044f6

Please sign in to comment.