Skip to content

Commit

Permalink
Remove usage of flask_api HTTP constants and fix versions of requirem…
Browse files Browse the repository at this point in the history
…ents. (#3)

* radon-h2020/radon-ctt#99 Remove usage of flask_api HTTP constants and fix versions of requirements.

* radon-h2020/radon-ctt#99 Updated requirements for datapipeline with fixed module versions.
  • Loading branch information
duelle authored May 12, 2021
1 parent 1960855 commit 913d258
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 45 deletions.
29 changes: 14 additions & 15 deletions datapipeline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

# Module imports
from flask import Blueprint, current_app, jsonify, request, send_file
from flask_api import status

name = 'DataPipeline'
prefix = 'datapipeline'
Expand Down Expand Up @@ -160,7 +159,7 @@ def register(app, plugin_storage_path=None):

@plugin.route('/')
def index():
return f'This is the Radon CTT Agent Data Pipeline Plugin.', status.HTTP_200_OK
return f'This is the Radon CTT Agent Data Pipeline Plugin.', 200

############# Data Ppeline Testing Plugin #############

Expand Down Expand Up @@ -237,7 +236,7 @@ def configuration_create():
res_zip.extractall(resources_extract_dir)

else:
return 'No resources archive location provided.', status.HTTP_400_BAD_REQUEST
return 'No resources archive location provided.', 400


persistence['configuration'][configuration_uuid] = config_instance
Expand All @@ -249,7 +248,7 @@ def configuration_create():
}
}

return jsonify(return_json), status.HTTP_201_CREATED
return jsonify(return_json), 201


# Get/Delete Configuration
Expand All @@ -263,15 +262,15 @@ def configuration_get_delete(config_uuid):
'entry': persistence['configuration'][config_uuid]
}
}
return jsonify(return_json), status.HTTP_200_OK
return jsonify(return_json), 200

if request.method == 'DELETE':
del persistence['configuration'][config_uuid]
shutil.rmtree(os.path.join(storage_path, config_uuid))
return 'Successfully deleted ' + config_uuid + '.', status.HTTP_200_OK
return 'Successfully deleted ' + config_uuid + '.', 200

else:
return "No configuration with that ID found", status.HTTP_404_NOT_FOUND
return "No configuration with that ID found", 404


# Run load test (param: configuration uuid)
Expand Down Expand Up @@ -299,25 +298,25 @@ def execution():
target_host = config_entry['host']
current_app.logger.info(f'Setting host to {target_host}')
else:
return "Configuration does not contain a host value.", status.HTTP_404_NOT_FOUND
return "Configuration does not contain a host value.", 404

if 'test_duration_sec' in config_entry:
test_duration_sec = config_entry['test_duration_sec']
current_app.logger.info(f'Setting test_duration_sec to {test_duration_sec}')
else:
return "Configuration does not contain a test_duration_sec value.", status.HTTP_404_NOT_FOUND
return "Configuration does not contain a test_duration_sec value.", 404

if 'velocity_per_minute' in config_entry:
velocity_per_minute = config_entry['velocity_per_minute']
current_app.logger.info(f'Setting velocity_per_minute to {velocity_per_minute}')
else:
return "Configuration does not contain a test_duration_sec value.", status.HTTP_404_NOT_FOUND
return "Configuration does not contain a test_duration_sec value.", 404

if 'host' in config_entry:
target_host = config_entry['host']
current_app.logger.info(f'Setting host to {target_host}')
else:
return "Configuration does not contain a host value.", status.HTTP_404_NOT_FOUND
return "Configuration does not contain a host value.", 404


os.mkdir(execution_path)
Expand Down Expand Up @@ -380,10 +379,10 @@ def execution():

persistence['execution'][execution_uuid] = execution_instance

return jsonify(execution_instance), status.HTTP_201_CREATED
return jsonify(execution_instance), 201

else:
return "No configuration with that ID found.", jsonify(persistence), status.HTTP_404_NOT_FOUND
return "No configuration with that ID found.", jsonify(persistence), 404


# Get load test results
Expand All @@ -392,11 +391,11 @@ def execution_results(exec_uuid):
try:
config_uuid = persistence.get('execution').get(exec_uuid).get('config').get('uuid')
except AttributeError:
return "No execution found with that ID.", status.HTTP_404_NOT_FOUND
return "No execution found with that ID.", 404

results_zip_path = os.path.join(storage_path, config_uuid, exec_uuid, result_zip_file_name)
if os.path.isfile(results_zip_path):
return send_file(results_zip_path)
else:
return "No results available (yet).", status.HTTP_404_NOT_FOUND
return "No results available (yet).", 404

5 changes: 2 additions & 3 deletions datapipeline/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
flask
flask_api
requests
flask==2.0
requests==2.25.1
17 changes: 8 additions & 9 deletions http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import uuid

from flask import Blueprint, current_app, jsonify, request, send_file
from flask_api import status


name = 'HTTP'
Expand Down Expand Up @@ -35,7 +34,7 @@ def register(app, plugin_storage_path=None):

@plugin.route('/')
def index():
return f'This is the Radon CTT Agent HTTP Plugin.', status.HTTP_200_OK
return f'This is the Radon CTT Agent HTTP Plugin.', 200


@plugin.route('/configuration/', methods=['POST'])
Expand Down Expand Up @@ -91,11 +90,11 @@ def configuration_create():

if is_required and param not in config_instance:
current_app.logger.error(f"Required parameter {param} not provided.")
return f'Required parameter {param} not provided.', status.HTTP_400_BAD_REQUEST
return f'Required parameter {param} not provided.', 400

persistence['configuration'][configuration_uuid] = config_instance
current_app.logger.info(f"Config: {config_instance}")
return jsonify(config_instance), status.HTTP_201_CREATED
return jsonify(config_instance), 201


@plugin.route('/execution/', methods=['POST'])
Expand Down Expand Up @@ -154,12 +153,12 @@ def execution():
shutil.copy2(tmp_zip_file, os.path.join(execution_results_dir, result_zip_file_name))

# Test was executed with any possible outcome
return jsonify(execution_instance), status.HTTP_200_OK
return jsonify(execution_instance), 200

else:
return "Required configuration parameters are missing.", jsonify(config_entry), status.HTTP_400_BAD_REQUEST
return "Required configuration parameters are missing.", jsonify(config_entry), 400
else:
return "No configuration with that ID found.", jsonify(persistence), status.HTTP_404_NOT_FOUND
return "No configuration with that ID found.", jsonify(persistence), 404


# Get execution results
Expand All @@ -168,10 +167,10 @@ def execution_results(exec_uuid):
try:
execution_uuid = persistence.get('execution').get(exec_uuid).get('uuid')
except AttributeError:
return "No execution found with that ID.", status.HTTP_404_NOT_FOUND
return "No execution found with that ID.", 404

results_zip_path = os.path.join(storage_path, execution_uuid, result_zip_file_name)
if os.path.isfile(results_zip_path):
return send_file(results_zip_path)
else:
return "No results available (yet).", status.HTTP_404_NOT_FOUND
return "No results available (yet).", 404
5 changes: 2 additions & 3 deletions http/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
flask
flask_api
requests
flask==2.0
requests==2.25.1
25 changes: 12 additions & 13 deletions jmeter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

# Module imports
from flask import Blueprint, current_app, jsonify, request, send_file
from flask_api import status

name = 'JMeter'
prefix = 'jmeter'
Expand All @@ -23,7 +22,7 @@ def register(app, plugin_storage_path=None):
app.register_blueprint(plugin, url_prefix=f'/{prefix}')
app.logger.info(f'{name} plugin registered.')
global storage_path
storage_path= plugin_storage_path
storage_path = plugin_storage_path


persistence = {
Expand Down Expand Up @@ -51,7 +50,7 @@ def register(app, plugin_storage_path=None):

@plugin.route('/')
def index():
return f'This is the Radon CTT Agent JMeter Plugin.', status.HTTP_200_OK
return f'This is the Radon CTT Agent JMeter Plugin.', 200


############# JMETER #############
Expand Down Expand Up @@ -119,7 +118,7 @@ def configuration_create():
elif 'jmx_file_name' not in request.form:
error_str = f'\'jmx_file_name\' could not be found in \'request.form\''
else:
error_str = f'No test resources and/or JMX file name provided.', status.HTTP_400_BAD_REQUEST
error_str = f'No test resources and/or JMX file name provided.', 400

current_app.logger.error(error_str)
raise FileNotFoundError(error_str)
Expand All @@ -141,7 +140,7 @@ def configuration_create():
}
}

return jsonify(return_json), status.HTTP_201_CREATED
return jsonify(return_json), 201


# Get/Delete Configuration
Expand All @@ -155,15 +154,15 @@ def configuration_get_delete(config_uuid):
'entry': persistence['configuration'][config_uuid]
}
}
return jsonify(return_json), status.HTTP_200_OK
return jsonify(return_json), 200

if request.method == 'DELETE':
del persistence['configuration'][config_uuid]
shutil.rmtree(os.path.join(storage_path, config_uuid))
return 'Successfully deleted ' + config_uuid + '.', status.HTTP_200_OK
return 'Successfully deleted ' + config_uuid + '.', 200

else:
return "No configuration with that ID found", status.HTTP_404_NOT_FOUND
return "No configuration with that ID found", 404


# Run load test (param: configuration uuid)
Expand Down Expand Up @@ -218,7 +217,7 @@ def execution():
jmeter_cli_call.append('-p ' + os.path.join(config_entry['properties_path']))

else:
return "Configuration does not contain a test plan.", status.HTTP_404_NOT_FOUND
return "Configuration does not contain a test plan.", 404

execution_instance['cli_call'] = jmeter_cli_call

Expand All @@ -237,10 +236,10 @@ def execution():

persistence['execution'][execution_uuid] = execution_instance

return jsonify(execution_instance), status.HTTP_201_CREATED
return jsonify(execution_instance), 201

else:
return "No configuration with that ID found.", jsonify(persistence), status.HTTP_404_NOT_FOUND
return "No configuration with that ID found.", jsonify(persistence), 404


# Get load test results
Expand All @@ -249,10 +248,10 @@ def execution_results(exec_uuid):
try:
config_uuid = persistence.get('execution').get(exec_uuid).get('config').get('uuid')
except AttributeError:
return "No execution found with that ID.", status.HTTP_404_NOT_FOUND
return "No execution found with that ID.", 404

results_zip_path = os.path.join(storage_path, config_uuid, exec_uuid, result_zip_file_name)
if os.path.isfile(results_zip_path):
return send_file(results_zip_path)
else:
return "No results available (yet).", status.HTTP_404_NOT_FOUND
return "No results available (yet).", 404
3 changes: 1 addition & 2 deletions jmeter/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
flask
flask_api
flask==2.0

0 comments on commit 913d258

Please sign in to comment.