diff --git a/create_oc_testdata/data/test_video.mkv b/create_oc_testdata/data/test_video.mkv new file mode 100644 index 0000000..bd40486 Binary files /dev/null and b/create_oc_testdata/data/test_video.mkv differ diff --git a/create_oc_testdata/duplicate_events/README.md b/create_oc_testdata/duplicate_events/README.md new file mode 100644 index 0000000..0a992cc --- /dev/null +++ b/create_oc_testdata/duplicate_events/README.md @@ -0,0 +1,42 @@ +# Script for duplicating events on an Opencast system + +This script duplicates the specified Events on the Opencast system. + +## How to Use + +### Configuration + +The script can be configured by editing the values in `config.py`: + +| Configuration Key | Description | Default/Example | +| :------------------------ | :------------------------------------------- | :---------------------------------------- | +| `target_url` | The server URL of the target tenant | http://localhost:8080 | +| `yaml_file_path` | The path to the yaml file with the event IDs | ../create_oc_testdata/data/event_ids.yaml | +| `number_of_duplicates` | The number of duplicates per event | 2 | +| `digest_user` | The user name of the digest user | opencast_system_account | +| `digest_pw` | The password of the digest user | CHANGE_ME | + + +The configured digest user needs to exist on the specified Opencast system. + +### Usage + +The script can be called with the following parameters (all parameters in brackets are optional): + +`python main.py [-t TARGET_URL ] [-n NUMBER_OF_DUPLICATES ] [-f YAML_FILE_PATH]` + +| Short Option | Long Option | Description | +| :----------: | :---------- | :----------------------------------------------- | +| `-t` | `--target` | The target url of the Opencast system | +| `-n` | `--number` | The number of duplicates to be created | +| `-f` | `--file` | The path to the file containing the event IDs | + +#### Usage example + +`python main.py -t localhost:8080 -n 2 -f data/event_ids.yaml` + +## Requirements + +This script was written for Python 3.8. + +It uses modules contained in the _lib_ directory. diff --git a/create_oc_testdata/duplicate_events/config.py b/create_oc_testdata/duplicate_events/config.py new file mode 100644 index 0000000..7f8a0eb --- /dev/null +++ b/create_oc_testdata/duplicate_events/config.py @@ -0,0 +1,14 @@ +# Configuration + +# default target url for the Opencast system +target_url = "http://localhost:8080" + +# default path to the .yaml file containing the event IDs +yaml_file_path = '../create_oc_testdata/data/event_ids.yaml' + +# default value for the number of copies per event to be created +number_of_duplicates = 2 + +# digest login +digest_user = "opencast_system_account" +digest_pw = "CHANGE_ME" diff --git a/create_oc_testdata/duplicate_events/main.py b/create_oc_testdata/duplicate_events/main.py new file mode 100644 index 0000000..ecc00fc --- /dev/null +++ b/create_oc_testdata/duplicate_events/main.py @@ -0,0 +1,75 @@ +import os +import sys + +sys.path.append(os.path.join(os.path.abspath('..'), "lib")) + +import config +from rest_requests.request import get_request, post_request, big_post_request +from parse_args import parse_args +from args.digest_login import DigestLogin +import yaml + + +def main(): + """ + Duplicate the events on a specified Opencast system + """ + + # create digest login + digest_login = DigestLogin(user=config.digest_user, password=config.digest_pw) + + # parse args + target_url, number_of_events, file_path = parse_args() + target_url = target_url if target_url else config.target_url + number_of_duplicates = number_of_events if number_of_events else config.number_of_duplicates + file_path = file_path if file_path else config.yaml_file_path + + print("Starting duplication process.") + + # test API connection + url = f'{target_url}/api/info/me' + try: + get_request(url, digest_login, "events") + except: + __abort_script("Something went wrong. No Connection to API. Stopping script. ") + + # read IDs from file + event_ids = read_event_ids(file_path) + + # duplicate events + url = f'{target_url}/api/workflows/' + + for id in event_ids: + print(id) + data = { + 'event_identifier': id, + 'workflow_definition_identifier': 'duplicate-event', + 'configuration': '{"numberOfEvents":"' + str(number_of_duplicates) + '"}' + } + try: + response = post_request(url, digest_login, "events", data=data) + print(response) + except Exception as e: + print(str(e)) + __abort_script("Something went wrong. Could not duplicate event. Stopping script") + + print("Done.") + + +def read_event_ids(path): + with open(path, 'r') as f: + data = yaml.safe_load(f) + return data['event-IDs'] + + +def __abort_script(message): + print(message) + sys.exit() + + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + print("\nAborting process.") + sys.exit(0) diff --git a/create_oc_testdata/duplicate_events/parse_args.py b/create_oc_testdata/duplicate_events/parse_args.py new file mode 100644 index 0000000..aed0e46 --- /dev/null +++ b/create_oc_testdata/duplicate_events/parse_args.py @@ -0,0 +1,29 @@ +from args.args_parser import get_args_parser +from args.args_error import args_error + + +MAX_NUMBER_OF_DUPLICATES = 20 + + +def parse_args(): + """ + Parse the arguments and check them for correctness + + :return: target_url and number of events to be created if given + :rtype: str, int + """ + parser, optional_args, required_args = get_args_parser() + + optional_args.add_argument("-t", "--target_url", type=str, nargs='+', help="URL of target system") + optional_args.add_argument("-n", "--number", type=int, nargs='+', help="number of duplicates per event") + optional_args.add_argument("-f", "--file", type=str, nargs='+', help="path to yaml file containing the event IDs") + + args = parser.parse_args() + + args.target_url = args.target_url if args.target_url else [None] + args.number = args.number if args.number else [None] + if args.number[0] and args.number[0] > MAX_NUMBER_OF_DUPLICATES: + args_error(parser, "too many duplicates ...") + args.file = args.file if args.file else [None] + + return args.target_url[0], args.number[0], args.file[0] diff --git a/create_oc_testdata/generate_events/README.md b/create_oc_testdata/generate_events/README.md new file mode 100644 index 0000000..9d5735c --- /dev/null +++ b/create_oc_testdata/generate_events/README.md @@ -0,0 +1,44 @@ +# Script for populating an Opencast system with test data + +This script creates random samples of Events (and Series) on the specified Opencast system. + +## How to Use + +### Configuration + +The script is configured by editing the values in `config.py`: + +| Configuration Key | Description | Default/Example | +| :----------------- | :------------------------------------------ | :---------------------------------------- | +| `target_url` | The server URL of the target tenant | http://localhost:8080 | +| `test_video_path` | The path to a test video to be used | ../create_oc_testdata/data/test_video.mkv | +| `yaml_file_path` | The path to the file to store the ecent IDs | ../create_oc_testdata/data/event_ids.yaml | +| `number_of_events` | The number of Events to be created | 4 | +| `number_of_series` | The number of Series to be created | 2 | +| `digest_user` | The user name of the digest user | opencast_system_account | +| `digest_pw` | The password of the digest user | CHANGE_ME | + + +The configured digest user needs to exist on the specified Opencast system. + +### Usage + +The script can be called with the following parameters (all parameters in brackets are optional): + +`python main.py [-t TARGET_URL ] [-n NUMBER_OF_EVENTS ] [-f TEST_VIDEO_PATH]` + +| Short Option | Long Option | Description | +| :----------: | :---------- | :----------------------------------------- | +| `-t` | `--target` | The target url of the Opencast system | +| `-n` | `--number` | The number of Events to be created | +| `-f` | `--file` | The path to a test video | + +#### Usage example + +`python main.py -t localhost:8080 -n 10 -f home/test/video.mp3` + +## Requirements + +This script was written for Python 3.8. + +It uses modules contained in the _lib_ directory. diff --git a/create_oc_testdata/generate_events/config.py b/create_oc_testdata/generate_events/config.py new file mode 100644 index 0000000..147c6b6 --- /dev/null +++ b/create_oc_testdata/generate_events/config.py @@ -0,0 +1,18 @@ +# Configuration + +# default target url for the Opencast system +target_url = "http://localhost:8080" + +# default path to a test video +test_video_path = '../create_oc_testdata/data/test_video.mkv' +# default path where to store the event IDs +yaml_file_path = '../create_oc_testdata/data/event_ids.yaml' + +# default value for the number of events to be created +number_of_events = 4 +# default value for the number of series to be created +number_of_series = 2 + +# digest login +digest_user = "opencast_system_account" +digest_pw = "CHANGE_ME" diff --git a/create_oc_testdata/generate_events/main.py b/create_oc_testdata/generate_events/main.py new file mode 100644 index 0000000..3e89ce2 --- /dev/null +++ b/create_oc_testdata/generate_events/main.py @@ -0,0 +1,121 @@ +import os +import sys + +sys.path.append(os.path.join(os.path.abspath('..'), "lib")) + +import config +from rest_requests.request import get_request, post_request, big_post_request +from parse_args import parse_args +from args.digest_login import DigestLogin +import yaml +import string +import random + + +def main(): + """ + Populate the specified Opencast system with random sample events + """ + + # create digest login + digest_login = DigestLogin(user=config.digest_user, password=config.digest_pw) + + # parse args + target_url, number_of_events, file_path = parse_args() + target_url = target_url if target_url else config.target_url + number_of_events = number_of_events if number_of_events else config.number_of_events + file_path = file_path if file_path else config.test_video_path + + print("Starting population process.") + + # test API connection + url = f'{target_url}/api/info/me' + try: + get_request(url, digest_login, "events") + except: + __abort_script("Something went wrong. No Connection to API. Stopping script. ") + + # Serien erstellen + series_ids = [] + for i in range(config.number_of_series): + url = f'{target_url}/series/' + series_id = "Series-ID-" + __generate_random_name() + series_ids.append(series_id) + data = { + 'identifier': series_id, + 'publisher': __generate_random_name(), + 'title': __generate_random_name(), + 'acl': '{"acl": {"ace": [' + '{"allow": true,"role": "ROLE_ANONYMOUS","action": "write"}, ' + '{"allow": true,"role": "ROLE_ADMIN","action": "read"}' + ']}}' + } + try: + print(post_request(url, digest_login, "series", data=data)) + except Exception as e: + print(str(e)) + __abort_script("Something went wrong. Could not create series. Stopping script") + + # Events erstellen + event_ids = [] + url = f'{target_url}/ingest/addMediaPackage' + files = [file_path] + for i in range(number_of_events): + event_id = "ID-" + __generate_random_name(length=5) + event_ids.append(event_id) + data = { + 'creator': __generate_random_name(), + 'title': __generate_random_name(), + 'flavor': 'presentation/source', + 'description': 'This is a test description. This Event is only for testing purposes. ', + 'identifier': event_id, + 'spatial': __generate_random_name(), + 'isPartOf': random.choice(series_ids), + 'acl': '{"acl": {"ace": [' + '{"allow": true,"role": "ROLE_ADMIN","action": "read"}, ' + '{"allow": true,"role": "ROLE_ADMIN","action": "write"}' + ']}}' + } + try: + print(big_post_request(url, digest_login, "events", data=data, files=files)) + except Exception as e: + print(str(e)) + __abort_script("Something went wrong. Could not create event. Stopping script") + + # write event IDs to yaml file + with open(config.yaml_file_path, 'w') as file: + yaml.dump({'event-IDs': event_ids}, file) + + print("Done.") + + +def __create_alphabet(): + alphabet = list(string.ascii_letters) + # for i in range(10): + # alphabet.append(str(i)) + # for c in ['Ä', 'Ö', 'Ü', 'ä', 'ö', 'ü']: + # alphabet.append(c) + return alphabet + +alphabet = __create_alphabet() + + +def __generate_random_name(length=False): + name = '' + length = length if length else random.randint(1, 30) + for i in range(length): + name += random.choice(alphabet) + return name + + +def __abort_script(message): + print(message) + sys.exit() + + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + print("\nAborting process.") + sys.exit(0) diff --git a/create_oc_testdata/generate_events/parse_args.py b/create_oc_testdata/generate_events/parse_args.py new file mode 100644 index 0000000..1c4e2b7 --- /dev/null +++ b/create_oc_testdata/generate_events/parse_args.py @@ -0,0 +1,29 @@ +from args.args_parser import get_args_parser +from args.args_error import args_error + + +MAX_NUMBER_OF_EVENTS = 2000 + + +def parse_args(): + """ + Parse the arguments and check them for correctness + + :return: target_url and number of events to be created if given + :rtype: str, int + """ + parser, optional_args, required_args = get_args_parser() + + optional_args.add_argument("-t", "--target_url", type=str, nargs='+', help="URL of target system") + optional_args.add_argument("-n", "--number", type=int, nargs='+', help="number of events") + optional_args.add_argument("-f", "--file", type=str, nargs='+', help="path to test file") + + args = parser.parse_args() + + args.target_url = args.target_url if args.target_url else [None] + args.number = args.number if args.number else [None] + if args.number[0] and args.number[0] > MAX_NUMBER_OF_EVENTS: + args_error(parser, "too many events ...") + args.file = args.file if args.file else [None] + + return args.target_url[0], args.number[0], args.file[0]