Updated Task to the latests snapshot of Micrometer

Updated to handle the batch changes

Removing aot execution from sample apps

Remove snapshot version and rely on bom

Signed-off-by: Glenn Renfro <grenfro@vmware.com>
This commit is contained in:
Glenn Renfro
2022-10-03 10:55:37 -04:00
parent b7b7de5337
commit 2ef93291fc
22 changed files with 57 additions and 147 deletions

View File

@@ -197,10 +197,10 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
}
private JobParameters removeNonIdentifying(JobParameters parameters) {
Map<String, JobParameter> parameterMap = parameters.getParameters();
HashMap<String, JobParameter> copy = new HashMap<>();
Map<String, JobParameter<?>> parameterMap = parameters.getParameters();
HashMap<String, JobParameter<?>> copy = new HashMap<>();
for (Map.Entry<String, JobParameter> parameter : parameterMap.entrySet()) {
for (Map.Entry<String, JobParameter<?>> parameter : parameterMap.entrySet()) {
if (parameter.getValue().isIdentifying()) {
copy.put(parameter.getKey(), parameter.getValue());
}
@@ -215,7 +215,7 @@ public class TaskJobLauncherApplicationRunner extends JobLauncherApplicationRunn
}
private JobParameters merge(JobParameters parameters, JobParameters additionals) {
Map<String, JobParameter> merged = new HashMap<>();
Map<String, JobParameter<?>> merged = new HashMap<>();
merged.putAll(parameters.getParameters());
merged.putAll(additionals.getParameters());
return new JobParameters(merged);

View File

@@ -19,9 +19,9 @@ package org.springframework.cloud.task.configuration.observation;
import io.micrometer.common.docs.KeyName;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationConvention;
import io.micrometer.observation.docs.DocumentedObservation;
import io.micrometer.observation.docs.ObservationDocumentation;
enum TaskDocumentedObservation implements DocumentedObservation {
enum TaskDocumentedObservation implements ObservationDocumentation {
/**
* Observation created when a task runner is executed.

View File

@@ -16,6 +16,8 @@
package org.springframework.cloud.task.configuration.observation;
import java.util.function.Supplier;
import io.micrometer.observation.Observation;
/**
@@ -24,7 +26,7 @@ import io.micrometer.observation.Observation;
* @author Marcin Grzejszczak
* @since 3.0.0
*/
public class TaskObservationContext extends Observation.Context {
public class TaskObservationContext extends Observation.Context implements Supplier<TaskObservationContext> {
private final String beanName;
@@ -36,4 +38,9 @@ public class TaskObservationContext extends Observation.Context {
return beanName;
}
@Override
public TaskObservationContext get() {
return this;
}
}

View File

@@ -19,7 +19,7 @@ package org.springframework.cloud.task.listener;
import io.micrometer.common.docs.KeyName;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationConvention;
import io.micrometer.observation.docs.DocumentedObservation;
import io.micrometer.observation.docs.ObservationDocumentation;
/**
* Enumeration for task execution observations.
@@ -27,7 +27,7 @@ import io.micrometer.observation.docs.DocumentedObservation;
* @author Glenn Renfro
* @since 3.0.0
*/
public enum TaskExecutionObservation implements DocumentedObservation {
public enum TaskExecutionObservation implements ObservationDocumentation {
/**
* Metrics created around a task execution.

View File

@@ -16,6 +16,8 @@
package org.springframework.cloud.task.listener;
import java.util.function.Supplier;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationHandler;
@@ -27,7 +29,8 @@ import org.springframework.cloud.task.repository.TaskExecution;
* @author Glenn Renfro
* @since 3.0.0
*/
public class TaskExecutionObservationContext extends Observation.Context {
public class TaskExecutionObservationContext extends Observation.Context
implements Supplier<TaskExecutionObservationContext> {
private final TaskExecution taskExecution;
@@ -59,4 +62,9 @@ public class TaskExecutionObservationContext extends Observation.Context {
this.status = status;
}
@Override
public TaskExecutionObservationContext get() {
return this;
}
}

View File

@@ -51,6 +51,9 @@ import static org.springframework.cloud.task.listener.TaskObservations.UNKNOWN;
*/
public class TaskObservationsTests {
/**
* Prefix for the spring cloud task project.
*/
public static final String PREFIX = "spring.cloud.task";
private TaskObservations taskObservations;

View File

@@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>
@@ -96,14 +96,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>
@@ -109,14 +109,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>
@@ -111,14 +111,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>
@@ -116,14 +116,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -12,7 +12,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>

View File

@@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>

View File

@@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>
@@ -69,14 +69,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -16,7 +16,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>

View File

@@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>
@@ -122,14 +122,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>
@@ -81,14 +81,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0-M5</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath />
</parent>
@@ -127,14 +127,6 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-aot</id>
<goals>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.task.batch.listener.support;
import java.util.Date;
import java.util.Objects;
import org.springframework.batch.core.JobParameter;
@@ -31,8 +32,6 @@ public class JobParameterEvent {
private Object parameter;
private JobParameterEvent.ParameterType parameterType;
private boolean identifying;
public JobParameterEvent() {
@@ -40,7 +39,6 @@ public class JobParameterEvent {
public JobParameterEvent(JobParameter jobParameter) {
this.parameter = jobParameter.getValue();
this.parameterType = ParameterType.convert(jobParameter.getType());
this.identifying = jobParameter.isIdentifying();
}
@@ -61,13 +59,6 @@ public class JobParameterEvent {
}
}
/**
* @return a ParameterType representing the type of this parameter.
*/
public JobParameterEvent.ParameterType getType() {
return this.parameterType;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof JobParameterEvent)) {
@@ -79,51 +70,19 @@ public class JobParameterEvent {
}
JobParameterEvent rhs = (JobParameterEvent) obj;
return this.parameter == null ? rhs.parameter == null && this.parameterType == rhs.parameterType
: this.parameter.equals(rhs.parameter);
return Objects.equals(this.parameter, rhs.parameter);
}
@Override
public String toString() {
return this.parameter == null ? null : (this.parameterType == JobParameterEvent.ParameterType.DATE
? "" + ((Date) this.parameter).getTime() : this.parameter.toString());
return this.parameter == null ? null : this.parameter.toString();
}
@Override
public int hashCode() {
final int BASE_HASH = 7;
final int MULTIPLIER_HASH = 21;
return BASE_HASH + MULTIPLIER_HASH
* (this.parameter == null ? this.parameterType.hashCode() : this.parameter.hashCode());
}
/**
* Enumeration representing the type of a JobParameter.
*/
public enum ParameterType {
// @checkstyle:off
STRING, DATE, LONG, DOUBLE;
// @checkstyle:on
public static ParameterType convert(JobParameter.ParameterType type) {
if (JobParameter.ParameterType.DATE.equals(type)) {
return DATE;
}
else if (JobParameter.ParameterType.DOUBLE.equals(type)) {
return DOUBLE;
}
else if (JobParameter.ParameterType.LONG.equals(type)) {
return LONG;
}
else if (JobParameter.ParameterType.STRING.equals(type)) {
return STRING;
}
else {
throw new IllegalArgumentException("Unable to convert type");
}
}
return BASE_HASH + MULTIPLIER_HASH * this.parameter.hashCode();
}
}

View File

@@ -38,9 +38,9 @@ public class JobParametersEvent {
this.parameters = new LinkedHashMap<>();
}
public JobParametersEvent(Map<String, JobParameter> jobParameters) {
public JobParametersEvent(Map<String, JobParameter<?>> jobParameters) {
this.parameters = new LinkedHashMap<>();
for (Map.Entry<String, JobParameter> entry : jobParameters.entrySet()) {
for (Map.Entry<String, JobParameter<?>> entry : jobParameters.entrySet()) {
if (entry.getValue().getValue() instanceof String) {
this.parameters.put(entry.getKey(), new JobParameterEvent(entry.getValue()));
}

View File

@@ -99,10 +99,10 @@ public class JobExecutionEventTests {
public void testJobParameters() {
String[] JOB_PARAM_KEYS = { "A", "B", "C", "D" };
Date testDate = new Date();
JobParameter[] PARAMETERS = { new JobParameter("FOO", true), new JobParameter(1L, true),
new JobParameter(1D, true), new JobParameter(testDate, false) };
JobParameter[] PARAMETERS = { new JobParameter("FOO", String.class), new JobParameter(1L, Long.class),
new JobParameter(1D, Double.class), new JobParameter(testDate, Date.class) };
Map<String, JobParameter> jobParamMap = new LinkedHashMap<>();
Map<String, JobParameter<?>> jobParamMap = new LinkedHashMap<>();
for (int paramCount = 0; paramCount < JOB_PARAM_KEYS.length; paramCount++) {
jobParamMap.put(JOB_PARAM_KEYS[paramCount], PARAMETERS[paramCount]);
}

View File

@@ -34,7 +34,6 @@ public class JobParameterEventTests {
public void testDefaultConstructor() {
JobParameterEvent jobParameterEvent = new JobParameterEvent();
assertThat(jobParameterEvent.getValue()).isNull();
assertThat(jobParameterEvent.getType()).isNull();
assertThat(jobParameterEvent.isIdentifying()).isFalse();
assertThat(jobParameterEvent).isEqualTo(new JobParameterEvent());
}
@@ -43,16 +42,14 @@ public class JobParameterEventTests {
public void testConstructor() {
final String EXPECTED_VALUE = "FOO";
final Date EXPECTED_DATE_VALUE = new Date();
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true);
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, String.class);
JobParameterEvent jobParameterEvent = new JobParameterEvent(jobParameter);
assertThat(jobParameterEvent.getValue()).isEqualTo(EXPECTED_VALUE);
assertThat(jobParameterEvent.getType()).isEqualTo(JobParameterEvent.ParameterType.STRING);
assertThat(jobParameterEvent.isIdentifying()).isTrue();
jobParameter = new JobParameter(EXPECTED_DATE_VALUE, true);
jobParameter = new JobParameter(EXPECTED_DATE_VALUE, Date.class);
jobParameterEvent = new JobParameterEvent(jobParameter);
assertThat(jobParameterEvent.getValue()).isEqualTo(EXPECTED_DATE_VALUE);
assertThat(jobParameterEvent.getType()).isEqualTo(JobParameterEvent.ParameterType.DATE);
assertThat(jobParameterEvent.isIdentifying()).isTrue();
assertThat(new JobParameterEvent(jobParameter).equals(jobParameterEvent)).isTrue();
}
@@ -60,7 +57,7 @@ public class JobParameterEventTests {
@Test
public void testEquals() {
final String EXPECTED_VALUE = "FOO";
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true);
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, String.class);
JobParameterEvent jobParameterEvent = new JobParameterEvent(jobParameter);
JobParameterEvent anotherJobParameterEvent = new JobParameterEvent(jobParameter);
@@ -72,7 +69,7 @@ public class JobParameterEventTests {
@Test
public void testValidHashCode() {
final String EXPECTED_VALUE = "FOO";
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, true);
JobParameter jobParameter = new JobParameter(EXPECTED_VALUE, String.class);
JobParameterEvent jobParameterEvent = new JobParameterEvent(jobParameter);
assertThat(jobParameterEvent.hashCode()).isNotNull();
}

View File

@@ -33,13 +33,13 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class JobParametersEventTests {
private final static JobParameter STRING_PARAM = new JobParameter("FOO", true);
private final static JobParameter STRING_PARAM = new JobParameter("FOO", String.class);
private final static JobParameter DATE_PARAM = new JobParameter(new Date(), true);
private final static JobParameter DATE_PARAM = new JobParameter(new Date(), Date.class);
private final static JobParameter LONG_PARAM = new JobParameter(1L, true);
private final static JobParameter LONG_PARAM = new JobParameter(1L, Long.class);
private final static JobParameter DOUBLE_PARAM = new JobParameter(2D, true);
private final static JobParameter DOUBLE_PARAM = new JobParameter(2D, Double.class);
private final static String DATE_KEY = "DATE_KEY";
@@ -120,7 +120,7 @@ public class JobParametersEventTests {
}
public JobParametersEvent getPopulatedParametersEvent() {
Map<String, JobParameter> jobParameters = new HashMap<>();
Map<String, JobParameter<?>> jobParameters = new HashMap<>();
jobParameters.put(DATE_KEY, DATE_PARAM);
jobParameters.put(STRING_KEY, STRING_PARAM);
jobParameters.put(LONG_KEY, LONG_PARAM);