apache / cloudstack-cloudmonkey

Apache Cloudstack Cloudmonkey
Apache License 2.0
91 stars 60 forks source link

Allow for CTRL-C to break the current operation #126

Closed serverchief closed 5 months ago

serverchief commented 1 year ago

In large environments specific API calls take too long to respond because the query was not fine tuned. However - there is no way to terminate the existing running cmk command - as CTRL-C or CTRL-Z would not respond. In this case I launch another cmk instance or terminate the currently running one - but it's rather unnecessary.

Please consider adding a support for "break" to terminate the command running in session.

rohityadavcloud commented 1 year ago

I couldn't reproduce this with the QA server, http://qa.cloudstack.cloud/, using latest cmk for osx/darwin (arm64). I tried the listEvents and listAlerts APIs. Ctrl+C on API call, terminated the API call and cmk shell. However, it's possible to explore handling a Ctrl+C by a go-routine to terminate an on-going activity.

Which version of cmk are you using @serverchief

borisstoyanov commented 1 year ago

I've tested it out and it terminates the current cmk process (of course not in Cloudstack), it's hanging or being non-responsive in any way:

(localcloud) 🐱 > deploy virtualmachine templateid=3a679274-b810-11ed-94bb-1e00b200017a serviceofferingid=14820797-8235-414b-9df7-1c94c997c74d zoneid=26510f0c-a5ec-4d7e-aa78-e2fde4178ca0
⣯ 😹 polling for async API result ^C
[root@ref-trl-4577-k-Mr8-boris-stoyanov-mgmt1 ~]#

(localcloud) 🐱 > list events
^C
[root@ref-trl-4577-k-Mr8-boris-stoyanov-mgmt1 ~]#

The issue is that it kills cmk but not the api call, is this what you're after @serverchief ?

rohityadavcloud commented 1 year ago

Hi @serverchief any advise on how to reproduce this, can you confirm if you face this while using the latest cmk? cc @borisstoyanov @nvazquez

rohityadavcloud commented 6 months ago

Hi @serverchief I've added some changes (https://github.com/apache/cloudstack-cloudmonkey/commit/d1599eaa7ce19b856f3d471fc6241ccf4b6d5dc5) to allow breaking an long-running async job polling, for example:

(homecloud) 🐵 > deploy virtualmachine serviceofferingid=2dfe5044-bd0f-44b4-9090-29bda79af1a5 templateid=08d5308d-d571-4568-ba21-fde17053c2f9 zoneid=323a3a13-7758-4042-98fc-e165da1b139c
⣟ 😺 polling for async API result
🙈 Error: API job query interrupted

This only works to break async APIs such as deploy VMs. Does this address your issue?

rohityadavcloud commented 6 months ago

I've come up with a fix, which allows a current on-going http request to cancel and allow quick recovery to the prompt. I've tested both long-running list APIs and async APIs such as deploy VM command. This needs testing so reopening this.

Could you help test this @serverchief ? cc @borisstoyanov @mlsorensen

rohityadavcloud commented 5 months ago

Closing this, tested myself. Pl re-open if there are any issues.