Skip to content

Commit

Permalink
[#noissue] Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Aug 10, 2021
1 parent aea8589 commit be5a28d
Show file tree
Hide file tree
Showing 146 changed files with 370 additions and 490 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

Expand All @@ -36,7 +35,6 @@ public class Subscriber {
private org.eclipse.paho.mqttv5.client.MqttAsyncClient v5Client;
private org.eclipse.paho.client.mqttv3.MqttAsyncClient v3Client;

@Autowired
public Subscriber(@Value("${mqtt.v3.broker.url}") String v3BrokerUrl, @Value("${mqtt.v3.topic}") String v3Topic,
@Value("${mqtt.v5.broker.url}") String v5BrokerUrl, @Value("${mqtt.v5.topic}") String v5Topic)
throws org.eclipse.paho.mqttv5.common.MqttException, org.eclipse.paho.client.mqttv3.MqttException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

package com.navercorp.pinpoint.batch.alarm.collector;

import com.navercorp.pinpoint.common.util.CollectionUtils;
import com.navercorp.pinpoint.web.alarm.DataCollectorCategory;
import com.navercorp.pinpoint.batch.alarm.vo.DataSourceAlarmVO;
import com.navercorp.pinpoint.batch.util.ListUtils;
import com.navercorp.pinpoint.common.server.bo.stat.DataSourceBo;
import com.navercorp.pinpoint.common.server.bo.stat.DataSourceListBo;
import com.navercorp.pinpoint.common.util.CollectionUtils;
import com.navercorp.pinpoint.web.dao.ApplicationIndexDao;
import com.navercorp.pinpoint.web.dao.stat.AgentStatDao;
import com.navercorp.pinpoint.web.vo.Application;
Expand Down Expand Up @@ -86,8 +85,7 @@ public void collect() {
.mapToInt(DataSourceBo::getMaxConnectionSize)
.average()
.orElse(-1);

DataSourceBo dataSourceBo = ListUtils.getFirst(dataSourceBoList);
DataSourceBo dataSourceBo = org.springframework.util.CollectionUtils.firstElement(dataSourceBoList);
DataSourceAlarmVO dataSourceAlarmVO = new DataSourceAlarmVO(dataSourceBo.getId(), dataSourceBo.getDatabaseName(),
(int) Math.floor(activeConnectionAvg), new Double(Math.floor(maxConnectionAvg)).intValue());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.batch.core.configuration.JobLocator;
import org.springframework.batch.core.launch.JobLauncher;

import javax.annotation.PostConstruct;
import java.util.Date;

/**
Expand All @@ -34,15 +34,11 @@ public class BatchJobLauncher extends JobLaunchSupport {

public static final String CLEANUP_INACTIVE_AGENTS_JOB_NAME = "cleanupInactiveAgentsJob";

@Autowired
private BatchConfiguration batchConfiguration;
private final boolean enableCleanupInactiveAgentsJob;

private boolean enableCleanupInactiveAgentsJob;

@PostConstruct
private void setup() {
boolean enableCleanupInactiveAgents = batchConfiguration.isEnableCleanupInactiveAgents();
this.enableCleanupInactiveAgentsJob = enableCleanupInactiveAgents;
public BatchJobLauncher(JobLocator locator, JobLauncher launcher, BatchConfiguration batchConfiguration) {
super(locator, launcher);
this.enableCleanupInactiveAgentsJob = batchConfiguration.isEnableCleanupInactiveAgents();
}

public void alarmJob() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Optional;

/**
* @author minwoo.jung<[email protected]>
*/
public class JobFailListener implements JobExecutionListener {

@Autowired(required = false)
private JobFailMessageSender jobFailMessageSender = new EmptyJobFailMessageSender();
private final JobFailMessageSender jobFailMessageSender;

public JobFailListener() {
public JobFailListener(Optional<JobFailMessageSender> jobFailMessageSender) {
this.jobFailMessageSender = jobFailMessageSender.orElseGet(EmptyJobFailMessageSender::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.springframework.batch.core.configuration.JobLocator;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Objects;

Expand All @@ -32,12 +31,13 @@
*/
public class JobLaunchSupport implements InitializingBean {

@Autowired
private BatchConfiguration batchConfiguration;
@Autowired
private JobLocator locator;
@Autowired
private JobLauncher launcher;
private final JobLocator locator;
private final JobLauncher launcher;

public JobLaunchSupport(JobLocator locator, JobLauncher launcher) {
this.locator = Objects.requireNonNull(locator, "locator");
this.launcher = Objects.requireNonNull(launcher, "launcher");
}

public JobExecution run(String jobName, JobParameters params) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -32,6 +31,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* @author minwoo.jung
Expand All @@ -43,15 +43,18 @@ public class HealthCheckTasklet implements Tasklet {
private final static String URL_FORMAT = "http://%s:8081/joboverview";
private final List<String> jobNameList;

@Autowired
private RestTemplate restTemplate;
private final RestTemplate restTemplate;

@Autowired
private BatchConfiguration batchConfiguration;
private final BatchConfiguration batchConfiguration;

public HealthCheckTasklet() {

public HealthCheckTasklet(BatchConfiguration batchConfiguration, RestTemplate restTemplate) {
this.jobNameList = new ArrayList<>(1);
jobNameList.add("Aggregation Stat Data");

this.batchConfiguration = Objects.requireNonNull(batchConfiguration, "batchConfiguration");
this.restTemplate = Objects.requireNonNull(restTemplate, "restTemplate");

}

@Override
Expand All @@ -62,7 +65,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon
return RepeatStatus.FINISHED;
}

Map<String, Boolean> jobExecuteStatus = createjobExecuteStatus();
Map<String, Boolean> jobExecuteStatus = createJobExecuteStatus();

for (String url : urlList) {
try {
Expand Down Expand Up @@ -123,7 +126,7 @@ private List<String> generatedFlinkManagerServerApi() {
return urlList;
}

public Map<String, Boolean> createjobExecuteStatus() {
public Map<String, Boolean> createJobExecuteStatus() {
Map<String, Boolean> jobExecuteStatus = new HashMap<>();

for (String jobName : jobNameList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -32,6 +31,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* @author minwoo.jung
Expand All @@ -45,15 +45,16 @@ public class HealthCheckTaskletV2 implements Tasklet {
private final static String RUNNING = "RUNNING";
private final List<String> jobNameList;

@Autowired
private RestTemplate restTemplate;
private final RestTemplate restTemplate;

@Autowired
private BatchConfiguration batchConfiguration;
private final BatchConfiguration batchConfiguration;

public HealthCheckTaskletV2() {
public HealthCheckTaskletV2(BatchConfiguration batchConfiguration, RestTemplate restTemplate) {
this.jobNameList = new ArrayList<>(1);
jobNameList.add("Aggregation Stat Data");

this.batchConfiguration = Objects.requireNonNull(batchConfiguration, "batchConfiguration");
this.restTemplate = Objects.requireNonNull(restTemplate, "restTemplate");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import com.navercorp.pinpoint.batch.common.Divider;
import org.springframework.batch.core.partition.support.Partitioner;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.Map;
import java.util.Optional;

/**
* @author minwoo.jung
Expand All @@ -31,9 +31,11 @@ public class AgentCountPartitioner implements Partitioner {
private static final String PARTITION_NAME_PREFIX = "agent_count_partition_number_";
private static final String BATCH_NAME = "agent_count_batch";

@Autowired(required = false)
@Qualifier("divider")
private Divider divider = new DefaultDivider();
private final Divider divider;

public AgentCountPartitioner(@Qualifier("divider") Optional<Divider> divider) {
this.divider = divider.orElseGet(DefaultDivider::new);
}

@Override
public Map<String, ExecutionContext> partition(int gridSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.LinkedList;
import java.util.Objects;
import java.util.Queue;

/**
* @author Taejin Koo
*/
public class AgentCountReader implements ItemReader<ApplicationAgentsList>, StepExecutionListener {

@Autowired
private AgentInfoService agentInfoService;
private final AgentInfoService agentInfoService;

private final Queue<ApplicationAgentsList> queue = new LinkedList<>();

public AgentCountReader(AgentInfoService agentInfoService) {
this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService");
}

@Override
public void beforeStep(StepExecution stepExecution) {
long timestamp = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
import com.navercorp.pinpoint.web.vo.AgentCountStatistics;
import org.springframework.batch.core.JobExecutionException;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Objects;

/**
* @author Taejin Koo
*/
public class AgentCountWriter implements ItemWriter<AgentCountStatistics> {

@Autowired
AgentStatisticsDao agentStatisticsDao;
private final AgentStatisticsDao agentStatisticsDao;

public AgentCountWriter(AgentStatisticsDao agentStatisticsDao) {
this.agentStatisticsDao = Objects.requireNonNull(agentStatisticsDao, "agentStatisticsDao");
}

@Override
public void write(List<? extends AgentCountStatistics> items) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.util.Objects;

/**
* @author Taejin Koo
Expand All @@ -35,19 +34,14 @@ public class CleanupInactiveAgentsTasklet implements Tasklet {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

@Autowired
private BatchConfiguration batchConfiguration;
private final int durationDays;

private int durationDays;
private final AdminService adminService;

@Autowired
private AdminService adminService;


@PostConstruct
public void setup() {
int cleanupInactiveAgentsDurationDays = batchConfiguration.getCleanupInactiveAgentsDurationDays();
this.durationDays = cleanupInactiveAgentsDurationDays;
public CleanupInactiveAgentsTasklet(BatchConfiguration batchConfiguration, AdminService adminService) {
Objects.requireNonNull(batchConfiguration, "batchConfiguration");
this.durationDays = batchConfiguration.getCleanupInactiveAgentsDurationDays();
this.adminService = Objects.requireNonNull(adminService, "adminService");
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.batch.item.ExecutionContext;

import java.util.Map;
import java.util.Optional;

import static org.junit.Assert.assertEquals;

Expand All @@ -30,7 +31,7 @@ public class AgentCountPartitionerTest {

@Test
public void partition() throws Exception {
AgentCountPartitioner partitioner = new AgentCountPartitioner();
AgentCountPartitioner partitioner = new AgentCountPartitioner(Optional.empty());
Map<String, ExecutionContext> partition = partitioner.partition(0);
assertEquals(1, partition.size());
}
Expand Down
Loading

0 comments on commit be5a28d

Please sign in to comment.