Skip to content

Commit

Permalink
Merge pull request #111 from entur/java-17-spring-boot-update
Browse files Browse the repository at this point in the history
Java 17 spring boot update
  • Loading branch information
assadriaz authored Jan 4, 2024
2 parents 172de6b + 5cd0661 commit 736cae2
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ aliases:
jobs:
build:
docker:
- image: cimg/openjdk:11.0
- image: cimg/openjdk:17.0
environment:
MAVEN_OPTS: -Xmx3G
steps:
Expand Down
16 changes: 13 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
FROM adoptopenjdk/openjdk11:alpine-jre
FROM bellsoft/liberica-openjdk-alpine:17.0.9-11 AS builder
COPY target/kakka-*-SNAPSHOT.jar application.jar
RUN java -Djarmode=layertools -jar application.jar extract

FROM bellsoft/liberica-openjdk-alpine:17.0.8-7
RUN apk update && apk upgrade && apk add --no-cache tini
WORKDIR /deployments
COPY target/kakka-*-SNAPSHOT.jar kakka.jar
RUN addgroup appuser && adduser --disabled-password appuser --ingroup appuser
USER appuser
CMD java $JAVA_OPTIONS -jar kakka.jar
RUN mkdir -p /home/appuser/.ssh \
&& touch /home/appuser/.ssh/known_hosts
COPY --from=builder dependencies/ ./
COPY --from=builder snapshot-dependencies/ ./
COPY --from=builder spring-boot-loader/ ./
COPY --from=builder application/ ./
ENTRYPOINT [ "/sbin/tini", "--", "java", "org.springframework.boot.loader.JarLauncher" ]
26 changes: 18 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.entur.ror</groupId>
<artifactId>superpom</artifactId>
<version>1.53</version>
<version>1.68</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand All @@ -22,15 +22,15 @@
<developerConnection>scm:git:ssh://[email protected]:entur/kakka.git</developerConnection>
</scm>
<properties>

<camel.version>3.18.5</camel.version>
<java.version>17</java.version>
<camel.version>3.20.0</camel.version>

<wololo.version>0.14.3</wololo.version>
<jskdata.version>1.0.15</jskdata.version>

<auth0.version>1.26.0</auth0.version>
<netex-java-model.version>1.0.12-SNAPSHOT</netex-java-model.version>
<entur.helpers.version>1.85</entur.helpers.version>
<entur.helpers.version>1.97</entur.helpers.version>
<guava.version>31.1-jre</guava.version>

<entur.google.pubsub.emulator.download.skip>false</entur.google.pubsub.emulator.download.skip>
Expand All @@ -47,6 +47,9 @@
<commons-text.version>1.8</commons-text.version>
<sosi-reader-impl.version>1.25</sosi-reader-impl.version>
<osmosis-osm-binary.version>0.47.3</osmosis-osm-binary.version>
<kubernetes-server-mock.version>6.3.1</kubernetes-server-mock.version>
<argLine/>
<spring-webmvc.version>5.3.28</spring-webmvc.version>
</properties>

<repositories>
Expand Down Expand Up @@ -123,6 +126,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- temporary Downgrade dependency -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-webmvc.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
Expand Down Expand Up @@ -340,7 +349,7 @@
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-server-mock</artifactId>
<version>5.12.0</version>
<version>${kubernetes-server-mock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -366,10 +375,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<argLine>-Xmx1G</argLine>
<runOrder>alphabetical</runOrder>
<argLine>@{argLine} -Xms500m -Xmx500m -Xss256k</argLine>
<systemPropertyVariables combine.children="override">
<spring.output.ansi.enabled>ALWAYS</spring.output.ansi.enabled>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
Expand Down
27 changes: 2 additions & 25 deletions src/main/java/no/entur/kakka/config/GcsStorageConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package no.entur.kakka.config;

import com.google.cloud.http.HttpTransportOptions;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import org.rutebanken.helper.gcp.BlobStoreHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand All @@ -29,8 +27,6 @@
@Profile("gcs-blobstore")
public class GcsStorageConfig {

private static final int CONNECT_AND_READ_TIMEOUT = 60000;

@Value("${blobstore.gcs.credential.path:#{null}}")
private String credentialPath;

Expand All @@ -44,9 +40,7 @@ public class GcsStorageConfig {
@Bean
public Storage storage() {
if (credentialPath == null || credentialPath.isEmpty()) {
// Use Default gcp credentials
//todo: update gcp-storage dependency to 1.83 and use BlobStoreHelper.getStorage(projectId)
return getStorage(projectId);
return BlobStoreHelper.getStorage(projectId);
} else {
return BlobStoreHelper.getStorage(credentialPath, projectId);
}
Expand All @@ -55,26 +49,9 @@ public Storage storage() {
@Bean
public Storage targetStorage() {
if (credentialPath == null || credentialPath.isEmpty()) {
// Use Default gcp credentials
//todo: update gcp-storage dependency to 1.83 and use BlobStoreHelper.getStorage(projectId)
return getStorage(projectId);
return BlobStoreHelper.getStorage(projectId);
} else {
return BlobStoreHelper.getStorage(credentialPath, targetProjectId);
}
}

private Storage getStorage(String projectId) {
try {
HttpTransportOptions transportOptions = StorageOptions.getDefaultHttpTransportOptions();
transportOptions = transportOptions.toBuilder().setConnectTimeout(CONNECT_AND_READ_TIMEOUT).setReadTimeout(CONNECT_AND_READ_TIMEOUT)
.build();

return StorageOptions.newBuilder()
.setProjectId(projectId)
.setTransportOptions(transportOptions)
.build().getService();
} catch (RuntimeException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package no.entur.kakka.geocoder;

import org.apache.camel.spring.spi.LegacyTransactionErrorHandlerBuilder;
import org.springframework.beans.factory.annotation.Value;


Expand All @@ -40,7 +39,7 @@ public abstract class TransactionalBaseRouteBuilder extends BaseRouteBuilder {

@Override
public void configure() throws Exception {
errorHandler(transactionErrorHandler()
errorHandler(springTransactionErrorHandler()
.redeliveryDelay(redeliveryDelay)
.maximumRedeliveries(maxRedelivery)
.onRedelivery(this::logRedelivery)
Expand All @@ -50,16 +49,4 @@ public void configure() throws Exception {
.logRetryStackTrace(true));

}

/**
* Creates a transaction error handler that will lookup in application context for
* an exiting transaction manager.
*
* @return the created error handler
*/
public LegacyTransactionErrorHandlerBuilder transactionErrorHandler() {
return new LegacyTransactionErrorHandlerBuilder();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ boolean isValid(ElasticsearchCommand command) {
gc.setStartingPosition(placeDirectPosition);
gc.setDestinationPosition(gospDirectPosition);
} catch (TransformException e) {
e.printStackTrace();
logger.warn(e.getMessage());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public PeliasDocument toPeliasDocument() {
PeliasDocument document = new PeliasDocument(getLayer(), feature.getId());

if (feature.getName() == null) {
//System.out.println("null name");
//document.setDefaultNameAndPhrase(feature.getAlternativeNames().entrySet().iterator().next().getValue());
document.setNameMap(feature.getAlternativeNames());
}
document.setDefaultNameAndPhrase(feature.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ public InputStream getBlob(String name) {

@Override
public void uploadBlob(String name, InputStream inputStream, boolean makePublic) {
BlobStoreHelper.uploadBlobWithRetry(storage, containerName, name, inputStream, makePublic);
BlobStoreHelper.createOrReplace(storage, containerName, name, inputStream, makePublic);
}

@Override
public void uploadBlob(String name, InputStream inputStream, boolean makePublic, String contentType) {
BlobStoreHelper.uploadBlobWithRetry(storage, containerName, name, inputStream, makePublic, contentType);
BlobStoreHelper.createOrReplace(storage, containerName, name, inputStream, makePublic, contentType);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.context.annotation.Profile;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.stereotype.Component;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
Expand All @@ -22,7 +22,7 @@
@Profile("!test")
@EnableWebSecurity
@Component
public class KakkaWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
public class KakkaWebSecurityConfigurerAdapter{

@Bean
CorsConfigurationSource corsConfigurationSource() {
Expand All @@ -35,8 +35,8 @@ CorsConfigurationSource corsConfigurationSource() {
return source;
}

@Override
public void configure(HttpSecurity http) throws Exception {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.cors(withDefaults())
.csrf().disable()
.authorizeRequests()
Expand All @@ -57,6 +57,8 @@ public void configure(HttpSecurity http) throws Exception {
.and()
.oauth2Client();

return http.build();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
import org.apache.camel.test.spring.junit5.UseAdviceWith;
import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
Expand All @@ -46,5 +47,9 @@ protected void replaceEndpoint(String routeId, String originalEndpoint, String r

}

@AfterEach
public void tearDown() throws Exception {
context.stop();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import io.fabric8.kubernetes.api.model.batch.v1.Job;
import io.fabric8.kubernetes.api.model.batch.v1.JobBuilder;
import io.fabric8.kubernetes.api.model.batch.v1.JobSpec;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import org.junit.Rule;
import org.junit.jupiter.api.Assertions;
Expand All @@ -32,7 +32,7 @@ class ExtendedKubernetesServiceTest {
@Rule
public KubernetesServer server = new KubernetesServer();

public KubernetesClient client = new DefaultKubernetesClient();
public KubernetesClient client = new KubernetesClientBuilder().build();


@Test
Expand Down
12 changes: 7 additions & 5 deletions src/test/java/no/entur/kakka/rest/AdminRestRouteBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.SecurityFilterChain;


@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = TestApp.class)
Expand All @@ -26,16 +27,17 @@ public void testGetPoiFilters() throws Exception {

@TestConfiguration
@EnableWebSecurity
static class AdminRestRouteBuilderTestContextConfiguration extends WebSecurityConfigurerAdapter {
static class AdminRestRouteBuilderTestContextConfiguration {

@Override
protected void configure(HttpSecurity http) throws Exception {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests(authorizeRequests ->
authorizeRequests
.anyRequest().permitAll()
);

return http.build();
}

}
}
Loading

0 comments on commit 736cae2

Please sign in to comment.