This README provides a guide to set up and run the TA3 ITM server application.
Ensure you have Python 3.10 installed on your system. If you don't have it installed, you can download it from the official Python website.
- First, we need to setup a Python virtual environment. Navigate to the directory where you cloned the repository and run the following command to create a new virtual environment:
python -m venv venv
- Activate the newly created virtual environment with:
source venv/bin/activate
On Windows, the method to activate depends on the shell:
- Git Bash:
source venv/Scripts/activate - PowerShell:
venv\Scripts\Activate.ps1 - cmd.exe:
venv\Scripts\activate.bat
Rename the config.ini.template file from your target domain to config.ini, and move it into the swagger_server folder. Ensure that the scenarios referenced by SCENARIO_DIRECTORY exist. If they do not, obtain the scenarios files from another developer. Create the directory referenced by SCENARIO_DIRECTORY if necessary, then copy the scenarios here.
The default values are configured for the production server, so you will likely want to update SOARTECH_URL and ADEPT_URL to use the local defaults instead (these should be commented out in the template). Also, you may want to set SAVE_HISTORY and SAVE_HISTORY_TO_S3 to False.
See the template for likely values.
The following properties can be configured:
EVALUATION_TYPE- default is
phase1butdryrunandmetricsare also supported
- default is
SCENARIO_DIRECTORY- default is
swagger_server/itm/data/%(EVALUATION_TYPE)s/scenarios/
- default is
DEFAULT_DOMAIN- default is
p2triage
- default is
SUPPORTED_DOMAINS- default is
p2triage
- default is
SOARTECH_URL- default is
http://10.216.38.25:8084
- default is
ADEPT_URL- default is
http://10.216.38.101:8080
- default is
SAVE_HISTORY- default is
True
- default is
HISTORY_DIRECTORY- default is
itm_history_output
- default is
SAVE_HISTORY_TO_S3- default is
True
- default is
HISTORY_S3_BUCKET- default is
itm-ui-assets
- default is
ALL_TA1_NAMES- default is
adept,soartech
- default is
- A variety of ADEPT and SoarTech properties for filenames, scenario IDs, and alignment target IDs
NOTE: the trailing s in .../data/%(EVALUATION_TYPE)s/... is needed for string interpolation to work properly.
Scenario files should be named in the following format (without punctuation except the indicated hyphens). This was the convention used in the (Phase 1) Dry Run evaluation:
<EVALUATION_TYPE>-<ta1name>-[eval|train]-<id>.yamlAt runtime, however, the server will look for the filenames as specified by the*_FILENAMESconfiguration variables.
Please note:
EVALUATION_TYPEis the value of the configuration variable defined inconfig.ini;ta1nameis one of the values from theALL_TA1_NAMESconfiguration variable;- Use
evalfor evaluation scenarios andtrainfor training scenarios; and - The
idshould be derived from the scenario ID in the YAML file, although it isn't required, e.g.,qol,MJ2,urban, etc.
Once setup and configuration are complete, to install the server, simply run:
pip3 install -r requirements.txt
To run the server, please execute from the root directory with the following usage:
usage: python -m swagger_server [-h] [-t] [-c CONFIG_GROUP] [-f CONFIG_FILE] [-p PORT]
options:
-h, --help show this help message and exit
-c CONFIG_GROUP, --config_group CONFIG_GROUP
Specify the configuration group in `config.ini` used to launch the Swagger server (default = DEFAULT)
-f CONFIG_FILE, --config_file CONFIG_FILE
Specify the configuration file (within ./swagger_server) used to launch the Swagger server (default = config.ini)
-p PORT, --port PORT Specify the port the Swagger server will listen on (default = 8080)
-t, --testing Put the server in test mode which will run standalone and not connect to TA1.
--max_sessions MAX_SESSIONS Hard maximum for number of simultaneous active sessions (default 100)
--timeout SESSION_TIMEOUT Number of minutes an ADM can be inactive before it's subject to being recycled (default 60)
You can browse the API at:
http://localhost:8080/ui/
Your Swagger definition lives here:
http://localhost:8080/swagger.json
To launch the integration tests, use tox:
sudo pip install tox
tox
To run the server on a Docker container, please execute the following from the root directory:
# Build and run the image with the default domain, port, configuration file, and configuration group
docker build --no-cache -t swagger_server .
docker run -p 8080:8080 swagger_server
# Build the image with the specified domain, port, configuration file, and configuration group
./gradle -Pdomain=<my_domain>
docker build --no-cache --build-arg domain=<my_domain> config=<my_config_file> -t swagger_server .
docker run -p <my_port>:<my_port> -e "TA3_PORT=<my_port>" -e "CONFIG_GROUP=<MY_CONFIG_GROUP>" swagger_serverThis requires JDK 8 or higher to run the gradle tool.
The models in swagger_server/models are generated from the following files:
swagger/base_swagger.yamlswagger/domain_swagger.yaml
domain_swagger.yaml is generated from (<domain_name>_swagger.yaml) as part of a Gradle task. If base_swagger.yaml or <domain_name>_swagger.yaml is updated, then the models and combined swagger.yaml will need to be re-generated from these files and checked in. Run ./gradlew -Pdomain=<domain_name> to do this. If you are building the models for the default domain (as defined in build.gradle), then the -P option isn't required.
To add a domain, you'll need to:
- Create a domain-specific YAML file for your domain;
- Implement a domain-specific version of certain ITM server classes;
- Create domain-specific tests;
- Create and update configuration; and
- Document your domain actions in the
itm-evaluation-clientrepository.
Determine a one-word name for your domain and create the file swagger/<domain_name>_swagger.yaml. This file contains certain domain-specific versions of the model and define nested state. Modify the definitions of the domain-specific versions of various state objects (i.e., the model), namely:
DomainState: high-level, domain-specific state relevant to a scenario or a scene thereinDomainCharacter: domain-specific attributes of the characters in the scenarioDomainDemographics: domain-specific demographic attributes of the characters in the scenarioDomainConditionsdomain-specific conditions that specify whether to transition to the next scene or send a probe responseDomainThreatTypeEnum: domain-specific type or nature of the risk or threat to the characters in the scenario, or to the decision-makerDomainCharacterRoleEnum: domain-specific primary roles a character may have in the sceneDomainActionTypeEnum: domain-specific (string) action types supported in the serverEntityTypeEnum: domain-specific enumeration of available entity types; can be a subject or object of aMESSAGEaction
Add YAML definitions for any nested objects defined in the above state objects. If any other model objects require domain-specific content, then create both a Base and Domain version of each object, and change the current object to include both of these versions with the allOf keyword. This may also entail other server code changes. All YAML changes should be made to the swagger/swagger.yaml file, and used by your client ADM. Note that the hope is to move all domain-specific state to a separate file, but this isn't supported cross-platform with our current dependencies.
NOTE: Certain enums would ideally be extensible so we can define basic values in base_swagger.yaml and domain-specific extensions in <domain_name>_swagger.yaml. Until this is supported in the OpenAPI spec and OpenAPI Generator, the enums from three domain-specific enums will need to be replicated in the domain-specific swagger file:
DomainActionTypeEnumvalues should be replicated inActionTypeEnum;DomainThreatTypeEnumvalues should be replicated inThreatTypeEnum; andDomainCharacterRoleEnumvalues should be replicated inCharacterRoleTypeEnum.
See this OpenAPI issue for background info.
Create a directory, swagger_server/itm/domains/<domain_name>, and implement the following classes:
<Domain>Config, which implements theITMDomainConfigprotocol, which defines factory-like methods for creating domain objects<Domain>ActionHandler(a subclass ofITMActionHandler), with:validate_domain_actionfor validating domain-specific actionsprocess_domain_actionfor the core business logic of handling a domain-specific actionload_action_times: for loading a mapping of domain-specific action types and simulated elapsed time for processing the action
<Domain>Scenario(a subclass ofITMScenario), with:merge_statefor merging domain-specific state from a new scene into the current stateclear_hidden_datain case any state data should be hidden at scene start
<Domain>ScenarioReader(a subclass ofITMScenarioReader), with the methodsgenerate_state,convert_to_itmscene, and, if there are any domain-specific conditions,generate_conditions<Domain>Scene(a subclass ofITMScene), with:evaluate_domain_conditionsif there are any domain-specific conditionsget_valid_action_typesif there are conditions where non-restricted domain-specific actions should NOT be added as available actions
Create a directory, swagger_server/itm/data/domains/<domain_name>/test and add domain-specific tests, and/or domain-specific variants of existing tests.
Make the following changes to configuration (config.ini.template, replicated in config.ini):
- Create a file,
swagger_server/itm/data/domains/<domain_name>/config.ini.templatewith whatever configuration is suitable for your domain. To run an evaluation, though, you will need the following keywords:EVALUATION_TYPE,SCENARIO_DIRECTORY,DEFAULT_DOMAIN,SUPPORTED_DOMAINS,SAVE_HISTORY,SAVE_HISTORY_TO_S3,ALL_TA1_NAMES,HISTORY_DIRECTORY,HISTORY_S3_BUCKET,EVAL_NAME,EVAL_NUMBER, andREQUIRED_CONFIG.
- Add a
REQUIRED_CONFIGkeyword in theDEFAULTconfiguration that contains all required configuration for your domain. - Create secondary configurations, if desired, that overrides the
DEFAULTconfiguration. - Create a file,
<domain_name>ActionTimes.json>inswagger_server/itm/data/domains/<domain_name>/with a dictionary of domain-specific action types and simulated time (in seconds) for a given action to be performed. - To start using your new domain, copy your new
config.ini.templatetoswagger_server/config.ini.
You should document your domain for multiple audiences, including scenario writers and TA2 ADMs. Some suggestions:
- In the TA3 client repository, create a new file at the root level,
README-<domain_name>.md, a Markdown file with a description of domain-specific actions and FAQs. The audience is primarily ADM writers. - Consider writing a document like this that documents every property in the domain-specific state, including controlled vocabulary, data type, and how to use each field.
- If the domain uses a wide variety of controlled vocabulary, consider writing a glossary that documents each property and possible value.
To add a TA1, you'll need to create and update configuration and implement a domain-specific version of certain ITM server classes. You'll also have to update the TA3 client repository if you want to be able to use its sample clients. See its README for details.
Make the following changes to relevant configurations (swagger_server/itm/data/domains/<domain_name>/config.ini.template, replicated in swagger_server/config.ini):
- Add a new all-lowercase ta1 name to
ALL_TA1_NAMES. - Define the following variables in the
DEFAULTand any other configuration group:<TA1>_EVAL_FILENAMES,<TA1>_TRAIN_FILENAMES- For each KDMA, define
<TA1>_EVAL_<KDMA>_SCENARIOS,<TA1>_TRAIN_<KDMA>_SCENARIOS, and<TA1>_<KDMA>_ALIGNMENT_TARGETS.
In the directory swagger_server/itm/ta1, create a child class <TA1name>Ta1Controller of ITMTa1Controller, and implement all abstract methods (e.g., get_ta1name, get_alignment_ids_path, and new_session, among others). Override any ITMTa1Controller methods as necessary.
Add code to get the configuration values defined above (see current TA1 controllers for examples). Depending how extensive/different your TA1 server is from current cases, you may need to make changes to ITMTa1Controller.