Browse Source

Minor changing for CertificateReloadManager

pull/15301/head
Andrii Landiak 6 months ago
parent
commit
c2a8f79edd
  1. 2
      common/coap-server/src/main/java/org/thingsboard/server/coapserver/DefaultCoapServerService.java
  2. 5
      common/data/src/main/java/org/thingsboard/server/common/data/ResourceUtils.java
  3. 9
      common/data/src/test/java/org/thingsboard/server/common/data/ResourceUtilsTest.java
  4. 2
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/LwM2MTransportBootstrapService.java
  5. 4
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/DefaultLwM2mTransportService.java
  6. 3
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/config/ssl/SslCredentialsWebServerCustomizer.java
  7. 12
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/CertificateReloadManager.java

2
common/coap-server/src/main/java/org/thingsboard/server/coapserver/DefaultCoapServerService.java

@ -214,12 +214,12 @@ public class DefaultCoapServerService implements CoapServerService, SmartInitial
if (oldDtlsEndpoint != null) { if (oldDtlsEndpoint != null) {
log.info("Stopping old DTLS endpoint..."); log.info("Stopping old DTLS endpoint...");
server.getEndpoints().remove(oldDtlsEndpoint);
oldDtlsEndpoint.stop(); oldDtlsEndpoint.stop();
if (oldDtlsConnector != null) { if (oldDtlsConnector != null) {
oldDtlsConnector.destroy(); oldDtlsConnector.destroy();
} }
oldDtlsEndpoint.destroy(); oldDtlsEndpoint.destroy();
server.getEndpoints().remove(oldDtlsEndpoint);
log.info("Old DTLS endpoint stopped and destroyed."); log.info("Old DTLS endpoint stopped and destroyed.");
} }
} }

5
common/data/src/main/java/org/thingsboard/server/common/data/ResourceUtils.java

@ -111,7 +111,10 @@ public class ResourceUtils {
return resourceFile.getAbsolutePath(); return resourceFile.getAbsolutePath();
} else { } else {
URL url = classLoader.getResource(filePath); URL url = classLoader.getResource(filePath);
return url != null ? url.toURI().toString() : null; if (url == null) {
throw new RuntimeException("Unable to find resource: " + filePath);
}
return url.toURI().toString();
} }
} catch (Exception e) { } catch (Exception e) {
if (e instanceof NullPointerException) { if (e instanceof NullPointerException) {

9
common/data/src/test/java/org/thingsboard/server/common/data/ResourceUtilsTest.java

@ -18,14 +18,15 @@ package org.thingsboard.server.common.data;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
class ResourceUtilsTest { class ResourceUtilsTest {
@Test @Test
public void givenNonExistentResource_whenGetUri_thenReturnsNull() { public void givenNonExistentResource_whenGetUri_thenThrowsRuntimeException() {
String result = ResourceUtils.getUri(ResourceUtilsTest.class.getClassLoader(), "non/existent/resource/path.txt"); assertThatThrownBy(() -> ResourceUtils.getUri(ResourceUtilsTest.class.getClassLoader(), "non/existent/resource/path.txt"))
.isInstanceOf(RuntimeException.class)
assertThat(result).isNull(); .hasMessageContaining("Unable to find resource");
} }
@Test @Test

2
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/LwM2MTransportBootstrapService.java

@ -64,7 +64,7 @@ public class LwM2MTransportBootstrapService implements SmartInitializingSingleto
private final LwM2MInMemoryBootstrapConfigStore lwM2MInMemoryBootstrapConfigStore; private final LwM2MInMemoryBootstrapConfigStore lwM2MInMemoryBootstrapConfigStore;
private final TransportService transportService; private final TransportService transportService;
private final TbLwM2MDtlsBootstrapCertificateVerifier certificateVerifier; private final TbLwM2MDtlsBootstrapCertificateVerifier certificateVerifier;
private LeshanBootstrapServer server; private volatile LeshanBootstrapServer server;
@Override @Override
public void afterSingletonsInstantiated() { public void afterSingletonsInstantiated() {

4
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/DefaultLwM2mTransportService.java

@ -84,8 +84,8 @@ public class DefaultLwM2mTransportService implements LwM2MTransportService, Smar
private final TbLwM2MAuthorizer authorizer; private final TbLwM2MAuthorizer authorizer;
private final LwM2mVersionedModelProvider modelProvider; private final LwM2mVersionedModelProvider modelProvider;
private LeshanServer server; private volatile LeshanServer server;
private LwM2mServerListener serverListener; private volatile LwM2mServerListener serverListener;
@Override @Override
public void afterSingletonsInstantiated() { public void afterSingletonsInstantiated() {

3
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/config/ssl/SslCredentialsWebServerCustomizer.java

@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.ssl.NoSuchSslBundleException;
import org.springframework.boot.ssl.SslBundle; import org.springframework.boot.ssl.SslBundle;
import org.springframework.boot.ssl.SslBundles; import org.springframework.boot.ssl.SslBundles;
import org.springframework.boot.ssl.SslStoreBundle; import org.springframework.boot.ssl.SslStoreBundle;
@ -125,7 +126,7 @@ public class SslCredentialsWebServerCustomizer implements WebServerFactoryCustom
@Override @Override
public SslBundle getBundle(String name) { public SslBundle getBundle(String name) {
if (!DEFAULT_BUNDLE_NAME.equals(name)) { if (!DEFAULT_BUNDLE_NAME.equals(name)) {
throw new IllegalArgumentException("Unknown SSL bundle: " + name); throw new NoSuchSslBundleException(name, "Unknown SSL bundle: " + name);
} }
return createSslBundle(); return createSslBundle();
} }

12
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/CertificateReloadManager.java

@ -196,14 +196,20 @@ public class CertificateReloadManager implements SmartInitializingSingleton, Dis
for (Path path : paths) { for (Path path : paths) {
String checksum = calculateChecksum(path); String checksum = calculateChecksum(path);
currentChecksums.put(path, checksum); currentChecksums.put(path, checksum);
combined.append(checksum); if (!combined.isEmpty()) {
combined.append("|");
}
combined.append(path).append("=").append(checksum);
} }
String combinedChecksum = combined.toString(); String combinedChecksum = combined.toString();
// Build old combined checksum for comparison // Build old combined checksum for comparison
StringBuilder oldCombined = new StringBuilder(); StringBuilder oldCombined = new StringBuilder();
for (Path path : paths) { for (Path path : paths) {
oldCombined.append(lastChecksumMap.getOrDefault(path, "")); if (!oldCombined.isEmpty()) {
oldCombined.append("|");
}
oldCombined.append(path).append("=").append(lastChecksumMap.getOrDefault(path, ""));
} }
String oldCombinedChecksum = oldCombined.toString(); String oldCombinedChecksum = oldCombined.toString();
@ -216,7 +222,7 @@ public class CertificateReloadManager implements SmartInitializingSingleton, Dis
} }
if (!combinedChecksum.equals(failedCombinedChecksum) && consecutiveFailures > 0) { if (!combinedChecksum.equals(failedCombinedChecksum) && consecutiveFailures > 0) {
// File content changed since last failure — reset and retry // File content has changed since the last failure - reset and retry
consecutiveFailures = 0; consecutiveFailures = 0;
failedCombinedChecksum = null; failedCombinedChecksum = null;
} }

Loading…
Cancel
Save