Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration Panel: Add Timeouts for AspenConsumer #1199

Closed
boverhof opened this issue Mar 5, 2024 · 6 comments · Fixed by #1239 or #1243
Closed

Configuration Panel: Add Timeouts for AspenConsumer #1199

boverhof opened this issue Mar 5, 2024 · 6 comments · Fixed by #1239 or #1243
Assignees
Labels
Priority:Normal Normal Priority Issue or PR

Comments

@boverhof
Copy link
Member

boverhof commented Mar 5, 2024

Description

The AspenConsumer executes and manages AspenPlus and ACM flowsheets and is configured to kill the AspenEngine when a time out value is exceeded. This parameter is modifiable in an XML configuration file. The purpose of this issue is to expose these configuration parameters in the FOQUS configuration UI ( screen shot below ). Should read and edit the AspenSinterConsumerConsole.xml, display the values in this UI and allow the user to edit it which may require a restart of FOQUS.

web API Timeouts

  • these monitor the Web API in a loop
  • if the "status" doesn't change eventually it sends a "Kill"

AspenSinterCosumerConsole Timeouts

  • \Program Files (x86)\Turbine\Lite\Consumers\AspenSinterConsumerConsole.xml
Screenshot 2024-03-05 at 12 54 21 PM
@boverhof boverhof self-assigned this Mar 5, 2024
@ksbeattie ksbeattie added the Priority:Normal Normal Priority Issue or PR label Mar 12, 2024
@sotorrio1
Copy link
Member

@boverhof basically it would be adding another section under "Settings" called for example "Aspen Configuration Parameters" where the user can specify the path to the XML file and edit the parameters in the UI.

I would need the possible paths to this file and a copy of an example file.

Thanks!

@sotorrio1
Copy link
Member

something like this...

Screenshot 2024-07-16 at 4 12 57 PM

@boverhof
Copy link
Member Author

boverhof commented Aug 6, 2024

@sotorrio1 This is the "template" that gets converted to the XML file:

App.config

@sotorrio1
Copy link
Member

@boverhof Thanks!

@boverhof
Copy link
Member Author

boverhof commented Aug 6, 2024

There is a complication with the Windows Software, it expects XML namespaces to be declared as the default namespace. I tried using element tree to rewrite the XML Configuration but it declares namespaces with prefixes and the Windows software doesn't understand that.

Unhandled Exception: System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized attribute 'xmlns:ns0'. Note that attribute names are case-sensitive.
# -*- coding: utf-8 -*-
"""
"""
import os
from shutil import copyfile
import time
import xml.etree.ElementTree as ET

DIR='\Program Files\Turbine\Lite\Clients'
XML_CONFIG = os.path.join(DIR,  'AspenSinterConsumerConsole.exe.config')
COPY_XML_CONFIG = XML_CONFIG + '-backup-' +  str(time.time())

def main():
    assert os.path.isdir(DIR)
    assert os.path.isfile(XML_CONFIG)
    copyfile(XML_CONFIG, COPY_XML_CONFIG)
    tree = ET.parse(XML_CONFIG)
    root = tree.getroot()
    print(root)
    node = root.find("./userSettings/Turbine.Console.Properties.Settings/setting[@name='TimeOutIterations']/value")
    assert node is not None
    print("TEXT: %s" %(node.text))
    val = int(node.text)
    
    # Double the Timeout value
    val *= 2
    print("NEW VALUE: %d" %(val))
    node.text = str(val)
    
    tree.write(XML_CONFIG)
    

if __name__ == '__main__': main()

@sotorrio1
Copy link
Member

@boverhof Can you try if modifying the file like this would work with Aspen?

import os
from shutil import copyfile
import time
import re

# Specify the file path
DIR = '\Program Files\Turbine\Lite\Clients'
XML_CONFIG = os.path.join(DIR, 'AspenSinterConsumerConsole.exe.config')
COPY_XML_CONFIG = XML_CONFIG + '-backup-' + str(time.time())


def main():
    # Assert directory and file exist
    assert os.path.isdir(DIR)
    assert os.path.isfile(XML_CONFIG)

    # Backup current XML file
    copyfile(XML_CONFIG, COPY_XML_CONFIG)
    print(f"File '{XML_CONFIG}' successfully backed up in '{COPY_XML_CONFIG}'")

    # Define the specific text to find
    specific_text = '<setting name="TimeOutIterations" serializeAs="String">'

    # Define the regex pattern to find <value>...</value> tags after the specific text
    pattern = re.compile(rf"{re.escape(specific_text)}\s*<value>(.*?)</value>")

    try:
        # Read the entire content of the file
        with open(XML_CONFIG, 'r', encoding='utf-8') as file:
            content = file.read()

        # Find all matches of the pattern in the content
        matches = pattern.finditer(content)

        # Process each match
        for match in matches:
            value_text = match.group(1)
            start_index = match.start(1)
            end_index = match.end(1)
            print(f"Found <value>{value_text}</value> after '{specific_text}' at index {start_index} to {end_index}")
            current_val = content[start_index:end_index]
            print(f"Current Timeout: {current_val}")

        # Double timeout value
        new_val = int(current_val) * 2
        print(f"New Timeout: {new_val}")

        # Perform the replacement
        if 0 <= start_index < len(content):
            # Insert new_text at start_index
            content = content[:start_index] + str(new_val) + content[start_index + len(str(new_val)):]

            # Write the modified content back to the file
            with open(XML_CONFIG, 'w', encoding='utf-8') as file:
                file.write(content)

            print(f"Successfully replaced text at index {start_index} with '{str(new_val)}'.")
        else:
            print("Index out of range.")

        if not matches:
            print(f"No <value>...</value> tags found after '{specific_text}'")

    except Exception as e:
        print(f"Error: {e}")


if __name__ == '__main__':
    main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Normal Normal Priority Issue or PR
Projects
None yet
3 participants