fix: ensure UI server remains active at simulator stop
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 30 Nov 2023 15:38:10 +0000 (16:38 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 30 Nov 2023 15:38:10 +0000 (16:38 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/Bootstrap.ts
src/charging-station/ChargingStation.ts
src/charging-station/Helpers.ts

index 6620764559974d12e6ca8a89cf7ccae497937e22..503dfb0b7301f3f9e553e21c2a03a3f0ed34ad73 100644 (file)
@@ -195,7 +195,6 @@ export class Bootstrap extends EventEmitter {
         await this.workerImplementation?.stop();
         delete this.workerImplementation;
         this.removeAllListeners();
-        this.uiServer?.stop();
         await this.storage?.close();
         delete this.storage;
         this.resetCounters();
@@ -212,6 +211,8 @@ export class Bootstrap extends EventEmitter {
 
   public async restart(stopChargingStations?: boolean): Promise<void> {
     await this.stop(stopChargingStations);
+    Configuration.getConfigurationSection<UIServerConfiguration>(ConfigurationSection.uiServer)
+      .enabled === false && this.uiServer?.stop();
     await this.start();
   }
 
@@ -407,6 +408,7 @@ export class Bootstrap extends EventEmitter {
     this.stop()
       .then(() => {
         console.info(`${chalk.green('Graceful shutdown')}`);
+        this.uiServer?.stop();
         // stop() asks for charging stations to stop by default
         this.waitChargingStationsStopped()
           .then(() => {
index 6acd40182fee333100b9a3985726a93d0e3c811e..aa251e395be27922cea3bb87bedeec384b12701e 100644 (file)
@@ -22,6 +22,7 @@ import {
 import {
   buildConnectorsMap,
   checkChargingStation,
+  checkConfiguration,
   checkConnectorsConfiguration,
   checkStationInfoConnectorStatus,
   checkTemplate,
@@ -1201,6 +1202,7 @@ export class ChargingStation extends EventEmitter {
       // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
       (stationConfiguration?.connectorsStatus || stationConfiguration?.evsesStatus)
     ) {
+      checkConfiguration(stationConfiguration, this.logPrefix(), this.configurationFile);
       this.initializeConnectorsOrEvsesFromFile(stationConfiguration);
     } else {
       this.initializeConnectorsOrEvsesFromTemplate(stationTemplate);
index 13721bd6cd04975c601c25a229ffb3a1bd98d199..f31ee7f0cccb3f9e798e46dbcf418569fccbfc65 100644 (file)
@@ -33,6 +33,7 @@ import {
   ChargingProfileKindType,
   ChargingRateUnitType,
   type ChargingSchedulePeriod,
+  type ChargingStationConfiguration,
   type ChargingStationInfo,
   type ChargingStationTemplate,
   ChargingStationWorkerMessageEvents,
@@ -253,6 +254,23 @@ export const checkTemplate = (
   }
 };
 
+export const checkConfiguration = (
+  stationConfiguration: ChargingStationConfiguration | undefined,
+  logPrefix: string,
+  configurationFile: string,
+): void => {
+  if (isNullOrUndefined(stationConfiguration)) {
+    const errorMsg = `Failed to read charging station configuration file ${configurationFile}`;
+    logger.error(`${logPrefix} ${errorMsg}`);
+    throw new BaseError(errorMsg);
+  }
+  if (isEmptyObject(stationConfiguration!)) {
+    const errorMsg = `Empty charging station configuration from file ${configurationFile}`;
+    logger.error(`${logPrefix} ${errorMsg}`);
+    throw new BaseError(errorMsg);
+  }
+};
+
 export const checkConnectorsConfiguration = (
   stationTemplate: ChargingStationTemplate,
   logPrefix: string,