]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
fix: ensure UI server charging station templates cache is populated at
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 8 Oct 2025 16:50:38 +0000 (18:50 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 8 Oct 2025 16:50:38 +0000 (18:50 +0200)
restart

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/Bootstrap.ts
src/charging-station/ui-server/AbstractUIServer.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts

index 52abb18845f0a72714ac60089c2847d9a8187e3b..d7dcb1190df1a712738999ee8a05ab08047f1ea5 100644 (file)
@@ -223,6 +223,11 @@ export class Bootstrap extends EventEmitter {
           )
           await this.storage?.open()
         }
+        this.uiServer.setChargingStationTemplates(
+          Configuration.getStationTemplateUrls()?.map(stationTemplateUrl =>
+            buildTemplateName(stationTemplateUrl.file)
+          )
+        )
         if (
           !this.uiServerStarted &&
           Configuration.getConfigurationSection<UIServerConfiguration>(
@@ -358,7 +363,6 @@ export class Bootstrap extends EventEmitter {
           provisioned: stationTemplateUrl.provisionedNumberOfStations ?? 0,
           started: 0,
         })
-        this.uiServer.chargingStationTemplates.add(templateName)
       }
       if (this.templateStatistics.size !== stationTemplateUrls.length) {
         console.error(
@@ -509,7 +513,6 @@ export class Bootstrap extends EventEmitter {
       this.uiServer.stop()
       this.uiServerStarted = false
     }
-    this.initializeCounters()
     // FIXME: initialize worker implementation only if the worker section has changed
     this.initializeWorkerImplementation(
       Configuration.getConfigurationSection<WorkerConfiguration>(ConfigurationSection.worker)
index 7f0ff345ec2367b7930740a1c9936d0ef2f32a10..f9bd5575441fb4a5322d349964d514639d244a17 100644 (file)
@@ -26,9 +26,7 @@ import { getUsernameAndPasswordFromAuthorizationToken } from './UIServerUtils.js
 const moduleName = 'AbstractUIServer'
 
 export abstract class AbstractUIServer {
-  public readonly chargingStationTemplates: Set<string>
   protected readonly httpServer: Http2Server | Server
-
   protected readonly responseHandlers: Map<
     `${string}-${string}-${string}-${string}-${string}`,
     ServerResponse | WebSocket
@@ -37,6 +35,7 @@ export abstract class AbstractUIServer {
   protected readonly uiServices: Map<ProtocolVersion, AbstractUIService>
 
   private readonly chargingStations: Map<string, ChargingStationData>
+  private readonly chargingStationTemplates: Set<string>
 
   public constructor (protected readonly uiServerConfiguration: UIServerConfiguration) {
     this.chargingStations = new Map<string, ChargingStationData>()
@@ -93,10 +92,18 @@ export abstract class AbstractUIServer {
     return this.chargingStations.size
   }
 
+  public getChargingStationTemplates (): string[] {
+    return [...this.chargingStationTemplates.values()]
+  }
+
   public hasChargingStationData (hashId: string): boolean {
     return this.chargingStations.has(hashId)
   }
 
+  public hasChargingStationTemplates (template: string): boolean {
+    return this.chargingStationTemplates.has(template)
+  }
+
   public hasResponseHandler (uuid: `${string}-${string}-${string}-${string}-${string}`): boolean {
     return this.responseHandlers.has(uuid)
   }
@@ -126,6 +133,15 @@ export abstract class AbstractUIServer {
     }
   }
 
+  public setChargingStationTemplates (templates: string[] | undefined): void {
+    if (templates == null) {
+      return
+    }
+    for (const template of templates) {
+      this.chargingStationTemplates.add(template)
+    }
+  }
+
   public abstract start (): void
 
   public stop (): void {
index 789e7456615476c3eeca2469908ef41ebd986c9b..c67f21b3925f4bd7cdef91bf0de54db7986bfc5b 100644 (file)
@@ -241,7 +241,7 @@ export abstract class AbstractUIService {
         status: ResponseStatus.FAILURE,
       } satisfies ResponsePayload
     }
-    if (!this.uiServer.chargingStationTemplates.has(template)) {
+    if (!this.uiServer.hasChargingStationTemplates(template)) {
       return {
         errorMessage: `Template '${template}' not found`,
         status: ResponseStatus.FAILURE,
@@ -290,7 +290,7 @@ export abstract class AbstractUIService {
   private handleListTemplates (): ResponsePayload {
     return {
       status: ResponseStatus.SUCCESS,
-      templates: [...this.uiServer.chargingStationTemplates.values()],
+      templates: this.uiServer.getChargingStationTemplates(),
     } satisfies ResponsePayload
   }