GabrielBrascher opened a new pull request #4926:
URL: https://github.com/apache/cloudstack/pull/4926


   ### Description
   
   #### Proposal
   
   This PR proposes adding Exception UnavailableCommandException at the 
ExceptionErrorCodeMap.
   
   #### Why?
   
   When an API command is "blocked" due to the User's role not allowing it, an 
UnavailableCommandException is thrown. However, this leads to multiple logs 
such as:
   
    `Could not find exception: com.cloud.exception.UnavailableCommandException 
in error code list for exceptions`
   
   This escalates to a level that it gets hard to understand what is going on, 
especially if there have been multiple API commands refused (e.g. logging on UI 
with an User that has lots of API restrictions, thus failing many commands such 
as `list*`)
   
   ```
   ...
   ...
   2021-04-15 16:00:48,454 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,462 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,465 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,468 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,472 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,476 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,480 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,483 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,486 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,490 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,494 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,498 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,501 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,504 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,508 DEBUG [c.c.a.ApiServlet] 
(qtp477376212-15892:ctx-cb70c68d) (logid:5257d522) ===START===  <Just an IP> -- 
GET  
listAll=true&details=min&page=1&pageSize=500&command=listAndSwitchSamlAccount&response=json
   2021-04-15 16:00:48,509 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,509 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,515 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,520 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-29347:ctx-34fbeee5 ctx-ca7a23a4) (logid:f56ab770) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,521 INFO  [c.c.u.e.CSExceptionErrorCode] 
(qtp477376212-15892:ctx-cb70c68d ctx-3781f075) (logid:5257d522) Could not find 
exception: com.cloud.exception.UnavailableCommandException in error code list 
for exceptions
   2021-04-15 16:00:48,521 DEBUG [c.c.a.ApiServer] 
(qtp477376212-15892:ctx-cb70c68d ctx-3781f075) (logid:5257d522) The API 
listAndSwitchSamlAccount does not exist or is not available for this account.
   ...
   ...
   ```
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [X] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [X] Major
   - [ ] Minor
   - [ ] Trivial
   
   ### How Has This Been Tested?
   1. Build
   2. Upgrade test environment
   3. Place breakpoints and tail logs to verify `CSExceptionErrorCode`
   4. Assert that the INFO log is not printed:  `Could not find exception: 
com.cloud.exception.UnavailableCommandException in error code list for 
exceptions`
   
   Lines which were validated to be working as expected via remote debug at 
[CSExceptionErrorCode.java#L89](https://github.com/PCextreme/cloudstack/blob/6e020172e28e818c7f9866fcff2fe59eee3d7763/utils/src/main/java/com/cloud/utils/exception/CSExceptionErrorCode.java#L89):
   ```
       public static int getCSErrCode(String exceptionName) {
           if (ExceptionErrorCodeMap.containsKey(exceptionName)) {
    ->         return ExceptionErrorCodeMap.get(exceptionName); //  when 
exception matches  `UnavailableCommandException` code is 4555
           } else {
               s_logger.info("Could not find exception: " + exceptionName + " 
in error code list for exceptions");
    ->          return -1; // no occurrences happened on tests, as expected
           }
       }
   ```
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to