5e6ac6d88bab86bc9ba2288f647e169eb6391d56
[integration.git] / test / mocks / datafilecollector-testharness / mr-sim / README.md
1 #MR-simulator 
2 This readme contains:
3
4 **Introduction**
5
6 **Building and running**
7
8 **Configuration**
9
10 ###Introduction###
11 The MR-sim is a python script delivering batches of events including one or more fileReady for one or more PNFs.
12 It is possible to configure number of events, PNFs, consumer groups, exising or missing files, file prefixes and change identifier.
13 In addition, MR sim can be configured to deliver file url for up to 5 FTP servers (simulating the PNFs).
14
15 ###Building and running###
16 It is possible build and run MR-sim manually as a container if needed. In addition MR-sim can be executed as python script, see instuctions further down.
17 Otherwise it is recommended to use the test scripts in the auto-test dir or run all simulators in one go using scripts in the simulator-group dir.
18
19 To build and run manually as a docker container:
20 1. Build docker container with ```docker build -t mrsim:latest .```
21 2. Run the container ```docker-compose up```
22
23 ###Configuration###
24 The event pattern, called TC, of the MR-sim is controlled with a arg to python script. See section TC info for available patterns.
25 All other configuration is done via envrionment variables.
26 The simulator listens to port 2222.
27
28 The following envrionment vaiables are used:
29 **FTPS_SIMS** - A comma-separated list of hostname:port for the FTP servers to generate ftps file urls for. If not set MR sim will assume 'localhost:21'. Minimum 1 and maximum 5 host-port pairs can be given.
30 **SFTP_SIMS** - A comma-separated list of hostname:port for the FTP servers to generate sftp file urls for. If not set MR sim will assume 'localhost:1022'. Minimum 1 and maximum 5 host-port pairs can be given.
31 **NUM_FTP_SERVERS** - Number of FTP servers to use out of those specified in the envrioment variables above. The number shall be in the range 1-5.
32 **MR_GROUPS** - A comma-separated list of consummer-group:changeId[:changeId]*. Defines which change identifier that should be used for each consumer gropu. If not set the MR-sim will assume 'OpenDcae-c12:PM_MEAS_FILES'.
33 **MR_FILE_PREFIX_MAPPING** - A comma-separated list of changeId:filePrefix. Defines which file prefix to use for each change identifier, needed to distinguish files for each change identifiers. If not set the MR-sim will assume 'PM_MEAS_FILES:A
34
35
36
37 ###Statistics read-out and commands###
38 The simulator can be queried for statistics  and  started/stopped (use curl from cmd line or open in browser, curl used below):
39
40 `curl localhost:2222` - Just returns 'Hello World'.
41
42 `curl localhost:2222/groups` - Return a comma-separated list of configured consumer groups..
43
44 `curl localhost:2222/changeids` - Return a commar-separated list of configured change id sets, where each set is a list of colon-separated change for each configured consumer group.
45
46 `curl localhost:2222/fileprefixes` - Return the setting of env var MR_FILE_PREFIX_MAPPING.
47
48 `curl localhost:2222/ctr_requests`   - return an integer of the number of get request to the event poll path
49
50 `curl localhost:2222/groups/ctr_requests`   - return an integer of the number of get requests, for all consumer groups, to the event poll path
51
52 `curl localhost:2222/ctr_requests/<consumer-group>`   - return an integer of the number of get requests, for the specified consumer group, to the event poll path
53
54
55
56
57
58
59
60 `curl localhost:2222/ctr_responses`  - return an integer of the number of get responses to the event poll path
61
62 `curl localhost:2222/ctr_files` - returns an integer or the number files.  
63
64 `curl localhost:2222/ctr_unique_files` - returns an integer or the number of unique files. A unique file is the combination of node+file_sequence_number 
65
66 `curl localhost:2222/tc_info` - returns the tc string (as given on the cmd line)
67
68 `curl localhost:2222/ctr_events` - returns the total number of events
69
70 `curl localhost:2222/execution_time` - returns the execution time in mm:ss
71
72 `curl localhost:2222/exe_time_first_poll` - returns the execution time in mm:ss from the first poll
73
74 `curl localhost:2222/ctr_unique_PNFs` - return the number of unique PNFS in alla events.
75
76 `curl localhost:2222/start` - start event delivery (default status).
77
78 `curl localhost:2222/stop` - stop event delivery.
79
80 `curl localhost:2222/status` - Return the started or stopped status.
81
82
83 #Alternative to running python (as described below) on your machine, use the docker files.
84 1. Build docker container with ```docker build -t mrsim:latest .```
85 2. Run the container ```docker-compose up```
86 The behavior can be changed by argument to the python script in the docker-compose.yml
87
88 The simulator can be queried for statistics  and  started/stopped (use curl from cmd line or open in browser, curl used below):
89
90 `curl localhost:2222/ctr_requests`   - return an integer of the number of get request to the event poll path
91
92 `curl localhost:2222/ctr_responses`  - return an integer of the number of get responses to the event poll path
93
94 `curl localhost:2222/ctr_files` - returns an integer or the number files.  
95
96 `curl localhost:2222/ctr_unique_files` - returns an integer or the number of unique files. A unique file is the combination of node+file_sequence_number 
97
98 `curl localhost:2222/tc_info` - returns the tc string (as given on the cmd line)
99
100 `curl localhost:2222/ctr_events` - returns the total number of events
101
102 `curl localhost:2222/execution_time` - returns the execution time in mm:ss
103
104 `curl localhost:2222/exe_time_first_poll` - returns the execution time in mm:ss from the first poll
105
106 `curl localhost:2222/ctr_unique_PNFs` - return the number of unique PNFS in alla events.
107
108 `curl localhost:2222/start` - start event delivery (default status).
109
110 `curl localhost:2222/stop` - stop event delivery.
111
112 `curl localhost:2222/status` - Return the started or stopped status.
113
114 ##Common TC info
115 File names for 1MB, 5MB and 50MB files
116 Files in the format: <size-in-mb>MB_<sequence-number>.tar.gz    Ex. for 5MB file with sequence number 12:  5MB_12.tar.gz
117 The sequence numbers are stepped so that all files have unique names
118 Missing files (files that are not expected to be found in the ftp server. Format: MissingFile_<sequence-number>.tar.gz
119
120 Limited event streams
121 When the number of events are exhausted, empty replies are returned '[]'
122
123 TC100 - One ME, SFTP, 1 1MB file, 1 event
124
125 TC101 - One ME, SFTP, 1 5MB file, 1 event
126
127 TC102 - One ME, SFTP, 1 50MB file, 1 event
128
129 TC110 - One ME, SFTP, 1MB files, 1 file per event, 100 events, 1 event per poll.
130
131 TC111 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll.
132
133 TC112 - One ME, SFTP, 5MB files, 100 files per event, 100 events, 1 event per poll.
134
135 TC113 - One ME, SFTP, 1MB files, 100 files per event, 100 events. All events in one poll.
136
137
138 TC120 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll. 10% of replies each: no response, empty message, slow response, 404-error, malformed json
139
140 TC121 - One ME, SFTP, 1MB files, 100 files per event, 100 events, 1 event per poll. 10% missing files
141
142 TC122 - One ME, SFTP, 1MB files, 100 files per event, 100 events. 1 event per poll. All files with identical name. 
143
144 TC510 - 700 MEs, SFTP, 1MB files, 1 file per event, 3500 events, 700 event per poll.
145
146 TC200-TC202 same as TC100-TC102 but with FTPS
147
148 TC210-TC213 same as TC110-TC113 but with FTPS
149
150 TC2000-TC2001 same as TC1000-TC1001 but with FTPS
151
152 TC610 same as TC510 but with FTPS
153
154
155 Endless event streams
156
157 TC1000 - One ME, SFTP, 1MB files, 100 files per event, endless number of events, 1 event per poll
158
159 TC1001 - One ME, SFTP, 5MB files, 100 files per event, endless number of events, 1 event per poll
160
161
162 ## Developer workflow
163
164 1. ```sudo apt install python3-venv```
165 2. ```source .env/bin/activate/```
166 3. ```pip3 install "anypackage"```      #also include in source code
167 4. ```pip3 freeze | grep -v "pkg-resources" > requirements.txt```   #to create a req file
168 5. ```FLASK_APP=mr-sim.py flask run```
169
170     or
171
172    ```python3 mr-sim.py ```
173
174 6. Check/lint/format the code before commit/amed by ```autopep8 --in-place --aggressive --aggressive mr-sim.py```
175
176
177 ## User workflow on *NIX
178
179
180 When cloning/fetching from the repository first time:
181 1. `git clone`
182 2. `cd "..." `          #navigate to this folder
183 3. `source setup.sh `   #setting up virtualenv and install requirements
184
185     you'll get a sourced virtualenv shell here, check prompt
186 4. `(env) $ python3 mr-sim.py --help`
187
188     alternatively
189
190     `(env) $ python3 mr-sim.py --tc1`
191
192 Every time you run the script, you'll need to step into the virtualenv by following step 3 first.
193
194 ## User workflow on Windows
195
196 When cloning/fetching from the repository first time:
197
198 1. 'git clone'
199 2. then step into the folder
200 3. 'pip3 install virtualenv'
201 4. 'pip3 install virtualenvwrapper-win'
202 5. 'mkvirtualenv env'
203 6. 'workon env'
204 7. 'pip3 install -r requirements.txt'   #this will install in the local environment then
205 8. 'python3 dfc-sim.py'
206
207 Every time you run the script, you'll need to step into the virtualenv by step 2+6.