Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PUT command to update experiments #46

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tsp/tsp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,33 @@ def fetch_experiment(self, uuid):
print("get trace failed: {0}".format(response.status_code))
return TspClientResponse(None, response.status_code, response.text)

def update_experiment(self, uuid, name, traces):
'''
Update an experiment on the server
:param uuid: Experiment UUID to update
:param name: New experiment name or None
:param traces: New list of trace UUIDs or None
:rtype: The created experiment
'''
api_url = '{0}experiments/{1}'.format(self.base_url, uuid)

my_parameters = {}
if name is not None:
my_parameters['name'] = name
if traces is not None:
my_parameters['traces'] = name

parameters = {'parameters': my_parameters}

response = requests.put(api_url, json=parameters, headers=headers)

if response.status_code == 200:
return TspClientResponse(Experiment(json.loads(response.content.decode('utf-8'))),
response.status_code, response.text)
# pragma: no cover
print("put experiment failed: {0}".format(response.status_code))
return TspClientResponse(None, response.status_code, response.text)

def delete_experiment(self, uuid):
'''
Delete a specific experiment
Expand Down
25 changes: 25 additions & 0 deletions tsp_cli_client
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ if __name__ == "__main__":
help="Get details on the given experiment", metavar="UUID")
parser.add_argument("--list-experiments", dest="list_experiments",
action='store_true', help="List all open experiments on the server")
parser.add_argument("--update-experiment", dest="update_experiment",
help="Update experiment on the server", metavar="EXP_NAME")
parser.add_argument("--delete-experiment", dest="delete_experiment",
help="Delete an experiment on the server", metavar="UUID")
parser.add_argument("--list-outputs", dest="list_outputs",
Expand Down Expand Up @@ -146,6 +148,7 @@ if __name__ == "__main__":
parser.add_argument("--delete-extension", dest="delete_extension",
help="Delete an extension", metavar="EXTENSION_NAME")


argcomplete.autocomplete(parser)
options = parser.parse_args()

Expand Down Expand Up @@ -246,6 +249,28 @@ if __name__ == "__main__":
else:
sys.exit(1)

trace_uuids = None
name = None
if options.update_experiment:

if ((options.uuids is None) and (options.name is None)):
print("Provide at least one of the follwing options: --name, --uuids")
sys.exit(1)

if options.uuids is not None:
trace_uuids = options.uuids
elif options.name is not None:
name = options.name

response = tsp_client.update_experiment(
options.update_experiment, name, trace_uuids)
if response.status_code == 200:
res = response.model
__print_experiment(res)
sys.exit(0)
else:
sys.exit(1)

if options.delete_experiment:
response = tsp_client.delete_experiment(options.delete_experiment)
if response.status_code == 200:
Expand Down