Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORG-1480: Upgrade to Spring Boot 3 #1145

Merged
merged 8 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions apps/backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.10</version>
<version>3.1.3</version>
</parent>

<groupId>no.nav.data</groupId>
Expand All @@ -18,19 +18,17 @@
<java.version>17</java.version>

<springdoc-openapi-ui.version>1.6.14</springdoc-openapi-ui.version>
<hypersistence-utils-hibernate-55.version>3.2.0</hypersistence-utils-hibernate-55.version>
<hypersistence-utils-hibernate-62.version>3.5.1</hypersistence-utils-hibernate-62.version>
<nav-vault-jdbc.version>1.3.10</nav-vault-jdbc.version>
<logstash-logback-encoder.version>7.3</logstash-logback-encoder.version>

<docx4j.version>11.3.2</docx4j.version> <!-- Nyere versjoner 11.4.x feiler med JAXB?.. -->
<docx4j.version>11.4.9</docx4j.version>
<lucene.version>8.11.2</lucene.version>
<shedlock.version>4.44.0</shedlock.version>
<commons-collections4.version>4.4</commons-collections4.version>

<microsoft-graph.version>5.47.0</microsoft-graph.version>
<msal4j.version>1.13.4</msal4j.version>

<spring-graphql.version>1.0.3</spring-graphql.version>
<msal4j.version>1.13.10</msal4j.version>

<postgresql.version>42.5.4</postgresql.version>

Expand All @@ -54,7 +52,7 @@
<testcontainers.version>1.17.6</testcontainers.version>
<wiremock.version>2.27.2</wiremock.version>
<scala.version>2.13.10</scala.version>
<graphql-codegen.version>5.5.0</graphql-codegen.version>
<graphql-codegen.version>5.8.0</graphql-codegen.version>

<!-- maven plugin -->
<maven.dependency.plugin-version>3.3.0</maven.dependency.plugin-version>
Expand Down Expand Up @@ -154,6 +152,14 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<exclusions>
<!-- Dependency convergence error -> spring-security-oauth2-client -->
<exclusion>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
</exclusion>

</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.woodstox</groupId>
Expand Down Expand Up @@ -184,12 +190,9 @@
<version>${nav-vault-jdbc.version}</version>
</dependency>
<dependency>
<!-- previously named com.vladmihalcea:hibernate-types-55 -->
<!-- now https://github.com/vladmihalcea/hypersistence-utils -->
<!-- TODO: Migrate to hypersistence-utils-hibernate-60 when upgrading to spring boot 3.0 -->
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-55</artifactId>
<version>${hypersistence-utils-hibernate-55.version}</version>
<artifactId>hypersistence-utils-hibernate-62</artifactId>
<version>${hypersistence-utils-hibernate-62.version}</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
Expand Down Expand Up @@ -602,6 +605,8 @@
<generateToString>true</generateToString>
<generateParameterizedFieldsResolvers>false</generateParameterizedFieldsResolvers>
<useOptionalForNullableReturnTypes>true</useOptionalForNullableReturnTypes>
<!-- Use @NotNull annotations compatible with Spring Boot 3 -->
<modelValidationAnnotation>jakarta.validation.constraints.NotNull</modelValidationAnnotation>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.client.RestTemplate;


import javax.sql.DataSource;

import static java.util.Collections.emptyList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import com.fasterxml.jackson.databind.ser.PropertyWriter;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import jakarta.persistence.Entity;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreRemove;
import jakarta.persistence.PreUpdate;
import lombok.extern.slf4j.Slf4j;
import no.nav.data.common.auditing.domain.Action;
import no.nav.data.common.auditing.domain.AuditVersion;
Expand All @@ -24,10 +28,6 @@

import java.util.Optional;
import java.util.UUID;
import javax.persistence.Entity;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;

import static no.nav.data.common.storage.domain.TypeRegistration.isAudited;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nav.data.common.auditing.domain;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -13,17 +14,11 @@
import no.nav.data.common.utils.JsonUtils;
import no.nav.data.team.po.domain.ProductArea;
import no.nav.data.team.team.domain.Team;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.type.SqlTypes;

import java.time.LocalDateTime;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@Data
@Builder
Expand All @@ -38,7 +33,6 @@ public class AuditVersion {
public static final String PA_TYPE = TypeRegistration.typeOf(ProductArea.class);

@Id
@Type(type = "pg-uuid")
@Column(name = "AUDIT_ID")
@Builder.Default
private UUID id = UUID.randomUUID();
Expand All @@ -60,7 +54,7 @@ public class AuditVersion {
@Column(name = "USER_ID", nullable = false, updatable = false)
private String user;

@Type(type = "jsonb")
@JdbcTypeCode(SqlTypes.JSON)
@Column(name = "DATA", nullable = false, updatable = false)
private String data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package no.nav.data.common.auditing.domain;

import com.fasterxml.jackson.annotation.JsonFilter;
import jakarta.persistence.Column;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.FieldNameConstants;
Expand All @@ -13,9 +16,6 @@
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;

@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.data.common.jpa;

import io.prometheus.client.hibernate.HibernateStatisticsCollector;
import jakarta.persistence.EntityManagerFactory;
import lombok.extern.slf4j.Slf4j;
import no.nav.data.AppStarter;
import no.nav.data.common.auditing.AuditVersionListener;
Expand All @@ -17,7 +18,6 @@
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import javax.persistence.EntityManagerFactory;

import static no.nav.data.common.utils.MdcUtils.wrapAsync;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public KafkaMessageListenerContainer<String, String> nomRessursContainer(
containerProps.setPollTimeout(500);

var container = new KafkaMessageListenerContainer<>(consumerFactory, containerProps);
container.setBatchErrorHandler(new KafkaErrorHandler());
container.getContainerProperties().setAuthorizationExceptionRetryInterval(Duration.ofMinutes(5));
container.setCommonErrorHandler(new KafkaErrorHandler());
container.getContainerProperties().setAuthExceptionRetryInterval(Duration.ofMinutes(5));

return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.jetbrains.annotations.NotNull;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.kafka.listener.ContainerStoppingBatchErrorHandler;
import org.springframework.kafka.listener.CommonContainerStoppingErrorHandler;
import org.springframework.kafka.listener.MessageListenerContainer;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

@Slf4j
@Component
public class KafkaErrorHandler extends ContainerStoppingBatchErrorHandler {
public class KafkaErrorHandler extends CommonContainerStoppingErrorHandler {

private final Executor executor;

Expand All @@ -35,15 +36,15 @@ public KafkaErrorHandler() {
}

@Override
public void handle(Exception e, ConsumerRecords<?, ?> records, Consumer<?, ?> consumer, MessageListenerContainer container) {
public void handleRemaining(@NotNull Exception thrownException, List<ConsumerRecord<?, ?>> records, @NotNull Consumer<?, ?> consumer, @NotNull MessageListenerContainer container) {
var record = records.iterator().hasNext() ? records.iterator().next() : null;
Optional.ofNullable(record)
.map(ConsumerRecord::topic)
.ifPresent(topic -> scheduleRestart(e, records, consumer, container, topic));
.ifPresent(topic -> scheduleRestart(thrownException, records, consumer, container, topic));
}

@SuppressWarnings({"pmd:DoNotUseThreads", "fb-contrib:SEC_SIDE_EFFECT_CONSTRUCTOR"})
private void scheduleRestart(Exception e, ConsumerRecords<?, ?> records, Consumer<?, ?> consumer, MessageListenerContainer container, String topic) {
private void scheduleRestart(Exception thrownException, List<ConsumerRecord<?, ?>> records, Consumer<?, ?> consumer, MessageListenerContainer container, String topic) {
long now = System.currentTimeMillis();
if (now - lastError.getAndSet(now) > COUNTER_RESET_TIME) {
counter.set(0);
Expand All @@ -62,7 +63,7 @@ private void scheduleRestart(Exception e, ConsumerRecords<?, ?> records, Consume
});

log.warn("Stopping kafka container topic={} for {}", topic, Duration.ofMillis(stopTime).toString());
super.handle(e, records, consumer, container);
super.handleRemaining(thrownException, records, consumer, container);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.data.common.exceptions.TechnicalException;
Expand All @@ -27,9 +30,6 @@
import org.springframework.web.util.UriComponentsBuilder;

import java.io.IOException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static no.nav.data.common.security.SecurityConstants.COOKIE_NAME;
import static no.nav.data.common.utils.Constants.SESSION_LENGTH;
Expand Down Expand Up @@ -79,10 +79,10 @@ public void login(HttpServletRequest request, HttpServletResponse response,
@CrossOrigin
@PostMapping(OAUTH_2_CALLBACK_URL)
public void oidc(HttpServletRequest request, HttpServletResponse response,
@RequestParam(value = CODE, required = false) String code,
@RequestParam(value = ERROR, required = false) String error,
@RequestParam(value = ERROR_DESCRIPTION, required = false) String errorDesc,
@RequestParam(STATE) String stateJson
@RequestParam(value = CODE, required = false) String code,
@RequestParam(value = ERROR, required = false) String error,
@RequestParam(value = ERROR_DESCRIPTION, required = false) String errorDesc,
@RequestParam(STATE) String stateJson
) throws IOException {
log.debug("Request to auth");
OAuthState state;
Expand Down
Loading
Loading