From f828f6365e3b169fb6a01b0c474b334fdbcaf2e7 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 24 Jul 2018 19:19:44 +0300 Subject: Add: dummy controller for profiling --- dummy_controller.py | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 dummy_controller.py diff --git a/dummy_controller.py b/dummy_controller.py new file mode 100644 index 0000000..430a2c9 --- /dev/null +++ b/dummy_controller.py @@ -0,0 +1,103 @@ +#!/usr/bin/python3 +# Copyright (C) 2018 Lars Wirzenius +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +import cProfile +import json +import os +import sys + +import ick2 + + +def new_project(i): + return { + 'project': 'project-{}'.format(i), + 'pipelines': [], + 'parameters': {}, + } + + +def main(): + iters = int(sys.argv[1]) + num_projects = int(sys.argv[2]) + statedir = sys.argv[3] + + os.mkdir(statedir) + state = ick2.FilePersistentState() + state.set_directory(statedir) + + apis = { + '/builds': ick2.BuildsAPI, + '/logs': ick2.LogAPI, + '/pipelines': ick2.PipelineAPI, + '/projects': ick2.ProjectAPI, + '/workers': ick2.WorkerAPI, + } + + for path in apis: + apis[path] = apis[path](state) + + + projects = [new_project(i) for i in range(num_projects)] + + for i in range(iters): + for project in projects: + reqs = [ + { + 'method': 'POST', + 'path': '/projects', + 'body': project, + }, + { + 'method': 'PUT', + 'path': '/projects/{}'.format(project['project']), + 'body': project, + } + ] + + for req in reqs: + method = req['method'] + path = req['path'] + body = req.get('body') + + if len(path.split('/')) == 2: + toplevel = path + name = None + else: + toplevel = os.path.dirname(path) + name = os.path.basename(path) + + api = apis[toplevel] + try: + if method == 'POST': + api.create(body) + elif method == 'PUT': + api.update(body, name) + elif method == 'DELETE': + api.delete(body, name) + elif method == 'LIST': + api.list() + elif method == 'SHOW': + api.show(name) + else: + raise Exception('Unknown method: {}'.format(method)) + except ick2.IckException: + pass + + +if __name__ == '__main__': + cProfile.run('main()', 'dummy.prof') -- cgit v1.2.1