diff --git a/README.md b/README.md index c4e0639291cafbeb71bd66b9f6ea103df2e0b4e5..92b3b9b4ee61aa00abef0d43a4deb5a2e7c816e5 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,20 @@ The prometheus collects the metrics from all 4 microservices. The UI runs at the Grafana runs at http://localhost:3000. To Log in, use the username `admin` and the password `admin`. There is already one minimalistic dashboard imported. However, feel free to experiment and visualize another attributes. +## Scenarios + +### Run scenarios +Firstly run the app + $ cd locust-scenarios + $ locust Admin BasicUser +Open internet browser +Type http://localhost:8089 +Set: + - Number of users 2 + - Spawn rate 1 + - Host http://localhost + + ## Usage ### Used ports + Authorization - port 8083 diff --git a/locust-scenarios/locustfile.py b/locust-scenarios/locustfile.py new file mode 100644 index 0000000000000000000000000000000000000000..4c9665f114e8bf1ed6487af92c137e2774e4df79 --- /dev/null +++ b/locust-scenarios/locustfile.py @@ -0,0 +1,139 @@ +from locust import HttpUser, task + + +class Admin(HttpUser): + auth_header = {'Authorization': 'Bearer eyJraWQiOiJyc2ExIiwidHlwIjoiYXQrand0IiwiYWxnIjoiUlMyNTYifQ.eyJhdWQiOiI3ZTAyYTBhOS00NDZhLTQxMmQtYWQyYi05MGFkZDQ3YjBmZGQiLCJzdWIiOiI0OTMyMzdAbXVuaS5jeiIsImFjciI6Imh0dHBzOi8vcmVmZWRzLm9yZy9wcm9maWxlL3NmYSIsInNjb3BlIjoidGVzdF80IHRlc3RfMyB0ZXN0XzIgdGVzdF8xIHRlc3RfcmVhZCBvcGVuaWQgcHJvZmlsZSBlZHVwZXJzb25fc2NvcGVkX2FmZmlsaWF0aW9uIHRlc3Rfd3JpdGUgZW1haWwgdGVzdF81IiwiYXV0aF90aW1lIjoxNjgzNDk1NDgwLCJpc3MiOiJodHRwczovL29pZGMubXVuaS5jei9vaWRjLyIsImV4cCI6MTY4MzQ5OTEzOSwiaWF0IjoxNjgzNDk1NTM5LCJjbGllbnRfaWQiOiI3ZTAyYTBhOS00NDZhLTQxMmQtYWQyYi05MGFkZDQ3YjBmZGQiLCJqdGkiOiIzMjgxZmJiYy01MWYxLTQ0ZGEtOGMzNi1hY2Q5OTM1N2QxYzUifQ.BVLruvROGTvJh6CmhtjKIhURSheMCOVPADKgI6P-qhTmbhi_jTT4gvnLHsAwImGehmwDvo2seLAGahRdv84iM3iYJ7WTblPTGhu9CI5SAE-59ROlGtUaA-3q8zL2xdOVtF5in_KjF8lrk2gI8uY4i3iRE-PZnm9EyK4qmgzcCXIiu9K3TAPnDtKPs8sileFj7_V6Xq4qmjq7g1dr_jGOcelesUgnq6fQlDLvb2guUwWHFTkWZQSnS-cEAX6ZkROkuzPi7d53YlQaPSVngjMYpd81y_DypDcUqbrzNYK28y5cBLbLZ2y2CWKqKyE4ENryc237AH_UcaVdFWwf6Vh2gQ'} + def on_start(self): + + #create airplane type - just once because creating airplane type more times would report fail due to not unique name + self.client.post(":8080/api/airplaneTypes", json= + { + "name": "PráškovaÄŤ 2000" + }, + headers = self.auth_header) + + response = self.client.get(":8080/api/airplaneTypes/1") + + if response.status_code == 200: + self.client.post(":8080/api/airplanes", json= + { + "name": "Prášek", + "capacity": 2, + "typeId": 1 + }, + headers = self.auth_header) + + self.client.post(":8080/api/countries", json= + { + "name": "Slovensko" + }, + headers = self.auth_header) + self.client.post(":8080/api/cities", json= + { + "name": "HolĂÄŤ" + }, + headers = self.auth_header) + self.client.post(":8080/api/cities", json= + { + "name": "Senica" + }, + headers = self.auth_header) + self.client.post(":8080/api/cities/1/countries/1", json= + { + "name": "Senica" + }, + headers = self.auth_header) + self.client.post(":8080/api/cities/2/countries/1", json= + { + "name": "Senica" + }, + headers = self.auth_header) + #create 2 airports - just once because airport need to have unique code + self.client.post(":8080/api/airports", json= + { + "name": "Travnik Holic", + "code": "THL", + "location": { + "latitude": 41.40338, + "longitude": 2.17403 + } + }, + headers = self.auth_header) + self.client.post(":8080/api/airports", json= + { + "name": "Hliniste Senica", + "code": "HSL", + "location": { + "latitude": 41.40338, + "longitude": 2.17403 + } + }, + headers = self.auth_header) + + @task + def create_steward(self): + self.client.post(":8080/api/stewards", json= + { + "firstName": "John", + "lastName": "Doe" + }, + headers = self.auth_header) + + @task + def create_flight(self): + self.client.post(":8080/api/flights", json= + { + "departureTime": "2023-12-22T12:04:04.493908908+01:00", + "arrivalTime": "2023-12-22T12:04:04.493908908+01:00", + "airplaneId": 1 + }, + headers = self.auth_header) + + @task + def assign_steward_flight(self): + response_steward = self.client.get(":8080/api/stewards/1", headers = self.auth_header) + response_flight = self.client.get(":8080/api/flights/1", headers = self.auth_header) + + if response_steward.status_code == 200 and response_flight.status_code == 200: + self.client.post(":8080/api/stewards/1/flights/1", headers = self.auth_header) + self.client.delete(":8080/api/stewards/1/flights/1", headers = self.auth_header) + + @task + def assign_airport_flight(self): + response_airport1 = self.client.get(":8080/api/airports/1", headers = self.auth_header) + response_airport2 = self.client.get(":8080/api/airports/2", headers = self.auth_header) + response_flight = self.client.get(":8080/api/flights/1", headers = self.auth_header) + + if response_airport1.status_code == 200 and response_flight.status_code == 200 and response_airport2.status_code == 200: + self.client.post(":8080/api/airports/1/departingFlights/1", headers = self.auth_header) + self.client.post(":8080/api/airports/2/arrivingFlights/1", headers = self.auth_header) + self.client.delete(":8080/api/airports/1/departingFlights/1", headers = self.auth_header) + self.client.delete(":8080/api/airports/2/arrivingFlights/1", headers = self.auth_header) + + +class BasicUser(HttpUser): + min_wait = 5000 + max_wait = 15000 + auth_header = {'Authorization': 'Bearer eyJraWQiOiJyc2ExIiwidHlwIjoiYXQrand0IiwiYWxnIjoiUlMyNTYifQ.eyJhdWQiOiI3ZTAyYTBhOS00NDZhLTQxMmQtYWQyYi05MGFkZDQ3YjBmZGQiLCJzdWIiOiI0OTMyMzdAbXVuaS5jeiIsImFjciI6Imh0dHBzOi8vcmVmZWRzLm9yZy9wcm9maWxlL3NmYSIsInNjb3BlIjoidGVzdF80IHRlc3RfMyB0ZXN0XzIgdGVzdF8xIHRlc3RfcmVhZCBvcGVuaWQgcHJvZmlsZSBlZHVwZXJzb25fc2NvcGVkX2FmZmlsaWF0aW9uIHRlc3Rfd3JpdGUgZW1haWwgdGVzdF81IiwiYXV0aF90aW1lIjoxNjgzNDk1NDgwLCJpc3MiOiJodHRwczovL29pZGMubXVuaS5jei9vaWRjLyIsImV4cCI6MTY4MzQ5OTEzOSwiaWF0IjoxNjgzNDk1NTM5LCJjbGllbnRfaWQiOiI3ZTAyYTBhOS00NDZhLTQxMmQtYWQyYi05MGFkZDQ3YjBmZGQiLCJqdGkiOiIzMjgxZmJiYy01MWYxLTQ0ZGEtOGMzNi1hY2Q5OTM1N2QxYzUifQ.BVLruvROGTvJh6CmhtjKIhURSheMCOVPADKgI6P-qhTmbhi_jTT4gvnLHsAwImGehmwDvo2seLAGahRdv84iM3iYJ7WTblPTGhu9CI5SAE-59ROlGtUaA-3q8zL2xdOVtF5in_KjF8lrk2gI8uY4i3iRE-PZnm9EyK4qmgzcCXIiu9K3TAPnDtKPs8sileFj7_V6Xq4qmjq7g1dr_jGOcelesUgnq6fQlDLvb2guUwWHFTkWZQSnS-cEAX6ZkROkuzPi7d53YlQaPSVngjMYpd81y_DypDcUqbrzNYK28y5cBLbLZ2y2CWKqKyE4ENryc237AH_UcaVdFWwf6Vh2gQ'} + + @task + def get_airplane(self): + self.client.get(":8080/api/airplanes", headers = self.auth_header) + @task + def get_stewards(self): + self.client.get(":8080/api/stewards", headers = self.auth_header) + @task + def get_airports(self): + self.client.get(":8080/api/airports", headers = self.auth_header) + @task + def get_flights(self): + self.client.get(":8080/api/flights", headers = self.auth_header) + @task + def generate_airplane_report(self): + self.client.get(":8085/api/reports/airplane/1", headers = self.auth_header) + @task + def generate_airport_report(self): + self.client.get(":8085/api/reports/airport/1", headers = self.auth_header) + @task + def generate_flight_report(self): + self.client.get(":8085/api/reports/flight/1", headers = self.auth_header) diff --git a/report/src/main/java/cz/muni/fi/pa165/report/server/rest/ReportController.java b/report/src/main/java/cz/muni/fi/pa165/report/server/rest/ReportController.java index ab7d60cad11b47739bce4c3ba0f2f955fcdf2cdb..2cf3b9ee7f7b7f7828ce61b7df68dc1c1a6ed810 100644 --- a/report/src/main/java/cz/muni/fi/pa165/report/server/rest/ReportController.java +++ b/report/src/main/java/cz/muni/fi/pa165/report/server/rest/ReportController.java @@ -18,6 +18,7 @@ public class ReportController implements ReportApiDelegate{ } HttpHeaders headers = new HttpHeaders(); private HttpHeaders initializeHeaders(){ + headers.clear(); headers.add("Content-Type", "application/pdf"); headers.add("Content-Disposition", "attachment; filename=report.pdf"); return headers;