Skip to content

Commit 6491883

Browse files
authored
Merge pull request #392 from Baltic-RCC/dev
Dev
2 parents 853d642 + 9a86e2c commit 6491883

File tree

9 files changed

+404
-29
lines changed

9 files changed

+404
-29
lines changed

config/cgm_worker/merger.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ OUTPUT_MINIO_FOLDER = EMFOS/RMM
88
MERGE_REPORT_ELK_INDEX = emfos-merge-reports
99
OPDE_MODELS_ELK_INDEX = emfos-opde-models
1010
ENABLE_DYNAMIC_MERGE_SETTINGS = True
11-
MERGE_LOAD_FLOW_SETTINGS = CGM_DEFAULT
11+
MERGE_LOAD_FLOW_SETTINGS = EU_DEFAULT
1212
MERGE_LOAD_FLOW_SETTINGS_PRIORITY = EU_DEFAULT,EU_RELAXED
1313
REMOVE_GENERATORS_FROM_SLACK_DISTRIBUTION = True
1414
QAS_EIC = QAS_EIC
15-
QAS_MSG_TYPE = QAS_MSG_TYPE
15+
QAS_MSG_TYPE = QAS_MSG_TYPE
16+
SEND_TYPE = FS/SOAP

config/integrations/opdm.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ OPDM_USERNAME = None
44
OPDM_PASSWORD = None
55

66
WEBDAV_SERVER = access_url
7+
WEBDAV_SERVER_PUT = access_url
78
WEBDAV_USERNAME = None
8-
WEBDAV_PASSWORD = None
9+
WEBDAV_PASSWORD = None

config/model_retriever/model_retriever.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ ELK_ID_HASHING = True
55
MINIO_BUCKET = opdm-data
66
INPUT_RMQ_QUEUE = object-storage.models.opdm-metadata
77
OUTPUT_RMQ_QUEUE = object-storage.models.validation
8-
RETRY_DELAY = 10
8+
RETRY_DELAY = 10
9+
PROCESS_PARTY = TSO1,TSO2,TSO3
10+
PROCESS_TH = 1D,2D

emf/common/integrations/opdm.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,74 @@ def get_file(self, file_id):
9999
logger.warning(f"Status Code {response.status_code}; Message: {response.content}")
100100
return None
101101

102+
103+
def put_file(self, file_id, file_content):
104+
logger.info(f"Uploading file to OPDM local storage with ID -> {file_id}")
105+
106+
url = f"{WEBDAV_SERVER_PUT.rstrip('/')}/{str(file_id).lstrip('/')}"
107+
auth = (WEBDAV_USERNAME, WEBDAV_PASSWORD)
108+
109+
headers = {"Content-Type": "application/octet-stream"}
110+
111+
# Normalize data + content-length to avoid chunked transfer
112+
data = None
113+
try:
114+
if isinstance(file_content, (bytes, bytearray)):
115+
data = file_content
116+
headers["Content-Length"] = str(len(data))
117+
elif hasattr(file_content, "read"):
118+
# It's a file-like object
119+
try:
120+
file_content.seek(0)
121+
except Exception:
122+
pass
123+
data = file_content
124+
# Best-effort content-length from fileno(); falls back to reading into memory
125+
size = None
126+
if hasattr(file_content, "fileno"):
127+
try:
128+
import os
129+
size = os.fstat(file_content.fileno()).st_size
130+
except Exception:
131+
size = None
132+
if size is None:
133+
# As a last resort, read to bytes to ensure a Content-Length
134+
buf = file_content.read()
135+
if hasattr(file_content, "seek"):
136+
try:
137+
file_content.seek(0)
138+
except Exception:
139+
pass
140+
data = buf
141+
headers["Content-Length"] = str(len(buf))
142+
else:
143+
headers["Content-Length"] = str(size)
144+
else:
145+
raise TypeError("file_content must be bytes/bytearray or a file-like object")
146+
except Exception as prep_err:
147+
logger.error(f"Failed preparing payload for {file_id}: {prep_err}")
148+
return False
149+
150+
try:
151+
response = requests.put(
152+
url,
153+
data=data,
154+
headers=headers,
155+
auth=auth,
156+
verify=False, # consider True + proper CA in production
157+
timeout=120,
158+
)
159+
if response.status_code in (200, 201, 204):
160+
logger.info(f"Successfully uploaded file with ID -> {file_id}")
161+
return True
162+
else:
163+
logger.warning(f"Failed to upload file with ID -> {file_id}")
164+
logger.warning(f"Status Code {response.status_code}; Message: {response.content}")
165+
return False
166+
except Exception as e:
167+
logger.error(f"Exception while uploading file with ID -> {file_id}: {e}")
168+
return False
169+
102170
def get_latest_models_and_download(self, time_horizon, scenario_date, tso=None):
103171

104172
meta = {'pmd:scenarioDate': scenario_date, 'pmd:timeHorizon': time_horizon}

emf/common/integrations/rabbit.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -388,19 +388,20 @@ def _process_messages(self, basic_deliver, properties, body):
388388
# self.stop()
389389

390390
if self.message_handlers:
391-
392-
for message_handler in self.message_handlers:
393-
try:
391+
try:
392+
for message_handler in self.message_handlers:
394393
logger.info(f"Handling message with handler: {message_handler.__class__.__name__}")
395394
body, properties = message_handler.handle(body, properties=properties, channel=self._channel)
396-
except Exception as error:
397-
logger.error(f"Message handling failed: {error}", exc_info=True)
398-
ack = False
399-
self._channel.basic_reject(basic_deliver.delivery_tag, requeue=True)
400-
logger.error(f"Message rejected due to handler error")
401-
break
402-
# self.connection.close()
403-
# self.stop()
395+
396+
except Exception as error:
397+
logger.error(f"Message handling failed: {error}", exc_info=True)
398+
ack = False
399+
self._channel.basic_reject(basic_deliver.delivery_tag, requeue=True)
400+
logger.error(f"Message rejected due to handler error")
401+
402+
# self.connection.close()
403+
# self.stop()
404+
404405

405406
# Process message acknowledgment
406407
if ack:

emf/common/loadflow_tool/loadflow_settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
# Prepare pypowsybl loadflow parameters classes
211211
## Used for CGM main merging process
212212
IGM_VALIDATION = pypowsybl.loadflow.Parameters(
213-
#voltage_init_mode=pypowsybl._pypowsybl.VoltageInitMode.UNIFORM_VALUES, # cim:PowerFlowSettings.flatStart "true"
213+
voltage_init_mode=pypowsybl._pypowsybl.VoltageInitMode.UNIFORM_VALUES, # cim:PowerFlowSettings.flatStart "true"
214214
transformer_voltage_control_on=True, # cim:PowerFlowSettings.transformerRatioTapControlPriority "1"
215215
use_reactive_limits=True, # cim:PowerFlowSettings.respectReactivePowerLimits "true"
216216
phase_shifter_regulation_on=False, # cim:PowerFlowSettings.transformerPhaseTapControlPriority "1"
@@ -227,7 +227,7 @@
227227
)
228228

229229
EU_DEFAULT = pypowsybl.loadflow.Parameters(
230-
#voltage_init_mode=pypowsybl._pypowsybl.VoltageInitMode.UNIFORM_VALUES, # cim:PowerFlowSettings.flatStart "true"
230+
voltage_init_mode=pypowsybl._pypowsybl.VoltageInitMode.UNIFORM_VALUES, # cim:PowerFlowSettings.flatStart "true"
231231
transformer_voltage_control_on=True, # @cim:PowerFlowSettings.transformerRatioTapControlPriority": "1"
232232
use_reactive_limits=True, # cim:PowerFlowSettings.respectReactivePowerLimits "true"
233233
phase_shifter_regulation_on=True, # cim:PowerFlowSettings.transformerPhaseTapControlPriority "1"
@@ -244,7 +244,7 @@
244244
)
245245

246246
EU_RELAXED = pypowsybl.loadflow.Parameters(
247-
#voltage_init_mode=pypowsybl._pypowsybl.VoltageInitMode.UNIFORM_VALUES, # cim:PowerFlowSettings.flatStart "true"
247+
voltage_init_mode=pypowsybl._pypowsybl.VoltageInitMode.UNIFORM_VALUES, # cim:PowerFlowSettings.flatStart "true"
248248
transformer_voltage_control_on=True, # cim:PowerFlowSettings.transformerRatioTapControlPriority "0"
249249
use_reactive_limits=False, # cim:PowerFlowSettings.respectReactivePowerLimits "false"
250250
phase_shifter_regulation_on=True, # cim:PowerFlowSettings.transformerPhaseTapControlPriority "0"

0 commit comments

Comments
 (0)