Skip to content

Commit

Permalink
Merge branch 'steve-community:master' into ApiRemoteStartStop
Browse files Browse the repository at this point in the history
  • Loading branch information
fnkbsi authored Feb 25, 2025
2 parents cae35e5 + f3110e1 commit 967ee83
Show file tree
Hide file tree
Showing 34 changed files with 700 additions and 425 deletions.
24 changes: 12 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
<java.version>17</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<jooq.version>3.19.16</jooq.version>
<flyway.version>11.1.0</flyway.version>
<jooq.version>3.19.18</jooq.version>
<flyway.version>11.3.3</flyway.version>
<cxf.version>4.1.0</cxf.version>
<spring.version>6.2.0</spring.version>
<spring.security.version>6.4.2</spring.security.version>
<mysql.jdbc.version>9.1.0</mysql.jdbc.version>
<spring.security.version>6.4.3</spring.security.version>
<mysql.jdbc.version>9.2.0</mysql.jdbc.version>
<jetty.version>12.0.16</jetty.version>
<lombok.version>1.18.36</lombok.version>
<jackson.version>2.18.2</jackson.version>
Expand Down Expand Up @@ -177,7 +177,7 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<version>3.14.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
Expand Down Expand Up @@ -212,7 +212,7 @@
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.8.6.6</version>
<version>4.9.1.0</version>
<configuration>
<failOnError>false</failOnError>
<onlyAnalyze>de.rwth.idsg.steve.-</onlyAnalyze>
Expand Down Expand Up @@ -507,7 +507,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.4</version>
<version>5.12.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -525,7 +525,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.0</version>
<version>2.8.5</version>
</dependency>

<dependency>
Expand All @@ -546,7 +546,7 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>26.0.1</version>
<version>26.0.2</version>
<scope>compile</scope>
</dependency>

Expand All @@ -559,7 +559,7 @@
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.13.0</version>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
Expand Down Expand Up @@ -595,7 +595,7 @@
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.4.1</version>
<version>5.4.2</version>
</dependency>
<dependency>
<groupId>jakarta.websocket</groupId>
Expand Down Expand Up @@ -793,7 +793,7 @@
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.15.11</version>
<version>1.17.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springdoc.core.configuration.SpringDocConfiguration;
import org.springdoc.core.properties.SwaggerUiConfigProperties;
import org.springdoc.core.properties.SwaggerUiOAuthProperties;
Expand All @@ -36,6 +37,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import java.util.List;

/**
* https://stackoverflow.com/a/65557714
*
Expand Down Expand Up @@ -87,6 +90,8 @@ public OpenAPI apiDocs() {
)
.version(SteveConfiguration.CONFIG.getSteveVersion())
)
// https://stackoverflow.com/a/68185254
.servers(List.of(new Server().url("/").description("Default Server URL")))
// define a security schema
.components(new Components().addSecuritySchemes(securityName, securityScheme))
// and activate it for all endpoints
Expand Down
61 changes: 23 additions & 38 deletions src/main/java/de/rwth/idsg/steve/config/BeanConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.mysql.cj.conf.PropertyKey;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
Expand All @@ -45,6 +44,8 @@
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
Expand All @@ -55,16 +56,10 @@
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import jakarta.annotation.PreDestroy;
import jakarta.validation.Validator;

import javax.sql.DataSource;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

import static de.rwth.idsg.steve.SteveConfiguration.CONFIG;

Expand All @@ -81,8 +76,6 @@
@ComponentScan("de.rwth.idsg.steve")
public class BeanConfiguration implements WebMvcConfigurer {

private ScheduledThreadPoolExecutor executor;

/**
* https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
*/
Expand Down Expand Up @@ -144,13 +137,28 @@ public DSLContext dslContext(DataSource dataSource) {
return DSL.using(conf);
}

@Bean
public ScheduledExecutorService scheduledExecutorService() {
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("SteVe-Executor-%d")
.build();
@Bean(destroyMethod = "close")
public DelegatingTaskScheduler asyncTaskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(5);
scheduler.setThreadNamePrefix("SteVe-TaskScheduler-");
scheduler.setWaitForTasksToCompleteOnShutdown(true);
scheduler.setAwaitTerminationSeconds(30);
scheduler.initialize();

executor = new ScheduledThreadPoolExecutor(5, threadFactory);
return executor;
return new DelegatingTaskScheduler(scheduler);
}

@Bean(destroyMethod = "close")
public DelegatingTaskExecutor asyncTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(5);
executor.setThreadNamePrefix("SteVe-TaskExecutor-");
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setAwaitTerminationSeconds(30);
executor.initialize();

return new DelegatingTaskExecutor(executor);
}

@Bean
Expand All @@ -173,29 +181,6 @@ public ReleaseCheckService releaseCheckService() {
}
}

@PreDestroy
public void shutDown() {
if (executor != null) {
gracefulShutDown(executor);
}
}

private void gracefulShutDown(ExecutorService executor) {
try {
executor.shutdown();
executor.awaitTermination(30, TimeUnit.SECONDS);

} catch (InterruptedException e) {
log.error("Termination interrupted", e);

} finally {
if (!executor.isTerminated()) {
log.warn("Killing non-finished tasks");
}
executor.shutdownNow();
}
}

// -------------------------------------------------------------------------
// Web config
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,33 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.rwth.idsg.steve.service.dto;
package de.rwth.idsg.steve.config;

import de.rwth.idsg.steve.repository.dto.ChargePointSelect;
import de.rwth.idsg.steve.repository.dto.ChargingProfile;
import de.rwth.idsg.steve.web.dto.ocpp.ChargePointSelection;
import de.rwth.idsg.steve.web.dto.ocpp.SetChargingProfileParams;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.List;
import java.io.Closeable;
import java.io.IOException;

/**
* @author Sevket Goekay <sevketgokay@gmail.com>
* @since 12.11.2018
* @since 02.02.2025
*/
@Getter
@Slf4j
@RequiredArgsConstructor
public class EnhancedSetChargingProfileParams implements ChargePointSelection {
public class DelegatingTaskExecutor implements Closeable {

private final SetChargingProfileParams delegate;
private final ChargingProfile.Details details;
private final ThreadPoolTaskExecutor delegate;

@Override
public List<ChargePointSelect> getChargePointSelectList() {
return delegate.getChargePointSelectList();
public void close() throws IOException {
log.info("Shutting down");
delegate.shutdown();
}

public void execute(Runnable task) {
delegate.execute(task);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SteVe - SteckdosenVerwaltung - https://github.com/steve-community/steve
* Copyright (C) 2013-2025 SteVe Community Team
* All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.rwth.idsg.steve.config;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import java.io.Closeable;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.concurrent.ScheduledFuture;

/**
* @author Sevket Goekay <sevketgokay@gmail.com>
* @since 02.02.2025
*/
@Slf4j
@RequiredArgsConstructor
public class DelegatingTaskScheduler implements Closeable {

private final ThreadPoolTaskScheduler delegate;

@Override
public void close() throws IOException {
log.info("Shutting down");
delegate.shutdown();
}

public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Instant startTime, Duration period) {
return delegate.scheduleAtFixedRate(task, startTime, period);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class WebSocketConfiguration implements WebSocketConfigurer {
@Autowired private Ocpp16WebSocketEndpoint ocpp16WebSocketEndpoint;

public static final String PATH_INFIX = "/websocket/CentralSystemService/";
public static final long PING_INTERVAL = TimeUnit.MINUTES.toMinutes(15);
public static final Duration PING_INTERVAL = Duration.ofMinutes(15);
public static final Duration IDLE_TIMEOUT = Duration.ofHours(2);
public static final int MAX_MSG_SIZE = 8_388_608; // 8 MB for max message size

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package de.rwth.idsg.steve.ocpp.soap;

import de.rwth.idsg.steve.config.DelegatingTaskExecutor;
import de.rwth.idsg.steve.ocpp.OcppProtocol;
import de.rwth.idsg.steve.repository.OcppServerRepository;
import de.rwth.idsg.steve.repository.impl.ChargePointRepositoryImpl;
Expand All @@ -41,7 +42,6 @@

import javax.xml.namespace.QName;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;

import static org.apache.cxf.ws.addressing.JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND;

Expand All @@ -62,7 +62,7 @@ public class MessageHeaderInterceptor extends AbstractPhaseInterceptor<Message>

@Autowired private OcppServerRepository ocppServerRepository;
@Autowired private ChargePointHelperService chargePointHelperService;
@Autowired private ScheduledExecutorService executorService;
@Autowired private DelegatingTaskExecutor asyncTaskExecutor;

private static final String BOOT_OPERATION_NAME = "BootNotification";
private static final String CHARGEBOX_ID_HEADER = "ChargeBoxIdentity";
Expand Down Expand Up @@ -93,7 +93,7 @@ public void handleMessage(Message message) throws Fault {
// 2. update endpoint
// -------------------------------------------------------------------------

executorService.execute(() -> {
asyncTaskExecutor.execute(() -> {
try {
String endpointAddress = getEndpointAddress(message);
if (endpointAddress != null) {
Expand Down
Loading

0 comments on commit 967ee83

Please sign in to comment.