Skip to content

Show network name in exception message#4396

Merged
yadvr merged 2 commits into
apache:4.15from
ravening:display-message
Feb 19, 2021
Merged

Show network name in exception message#4396
yadvr merged 2 commits into
apache:4.15from
ravening:display-message

Conversation

@ravening

Copy link
Copy Markdown
Member

Description

Display network name in exception message instead of network object

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • 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)

Screenshots (if appropriate):

How Has This Been Tested?

if (hostNames.contains(hostName)) {
throw new InvalidParameterValueException("The vm with hostName " + hostName + " already exists in the network domain: " + ntwkDomain.getKey() + "; network="
+ _networkModel.getNetwork(ntwkId));
+ _networkModel.getNetwork(ntwkId).getName());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might yield an NPE hiding the original problem, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no problem in adding an if checking for a non-null name. However, a network can only be created with a name.

If the network is a non-null Object then I don't see how the name would be null. Unless manual queries have been executed on DB (messing with networks) or there are some bugs on the network removal/update process.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaanHoogland @GabrielBrascher most of the time the network name will be nonnull but there is no harm adding an extra if check. I will modify the code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am talking about the model returning a network in the first place. the namer being null will probably just print "<null>", @ravening @GabrielBrascher

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaanHoogland we are iterating over the list of networks which got populated earlier and it contains only valid existing networks. so networkmodel shouldnt return null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaanHoogland we are iterating over the list of networks which got populated earlier and it contains only valid existing networks. so networkmodel shouldnt return null

Maybe so @ravening, i trust your judgement on that. But it didn't happen in this method, so there is no telling what future generations will make of it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ravening How about just adding the network name to the NetworkVO toString(), so this remains the same, and we get to see the network's name along with other details like networkId, traffic type, etc?

@Pearl1594 should we all those detail in exception message? It makes sense to add entire networkVO object tostring in log message

It actually depends, we may not want to show the network Id (i.e, DB id) to users, so maybe replace id with name in the toString()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ravening How about just adding the network name to the NetworkVO toString(), so this remains the same, and we get to see the network's name along with other details like networkId, traffic type, etc?

@Pearl1594 should we all those detail in exception message? It makes sense to add entire networkVO object tostring in log message

It actually depends, we may not want to show the network Id (i.e, DB id) to users, so maybe replace id with name in the toString()

That will involve extra code changes which I want to avoid

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ravening while it does make sense to show the network name, we do not ensure uniqueness in network names in CloudStack - so would it lead to ambiguity just showing the name?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ravening while it does make sense to show the network name, we do not ensure uniqueness in network names in CloudStack - so would it lead to ambiguity just showing the name?

@Pearl1594 this exception is thrown when we are trying to create second VM with same in same network. So I would assume, user will know in which network he is creating the VM. Also even if the network name is not unique, it's better than displaying VO object right which won't make sense anyway

@GabrielBrascher GabrielBrascher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @ravening.

I am +1 on adding the network's name on exception. I did not add a looks good for this PR in respect to Daan's comment.

if (hostNames.contains(hostName)) {
throw new InvalidParameterValueException("The vm with hostName " + hostName + " already exists in the network domain: " + ntwkDomain.getKey() + "; network="
+ _networkModel.getNetwork(ntwkId));
+ _networkModel.getNetwork(ntwkId).getName());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no problem in adding an if checking for a non-null name. However, a network can only be created with a name.

If the network is a non-null Object then I don't see how the name would be null. Unless manual queries have been executed on DB (messing with networks) or there are some bugs on the network removal/update process.

Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
@ravening

Copy link
Copy Markdown
Member Author

Thanks for the PR @ravening.

I am +1 on adding the network's name on exception. I did not add a looks good for this PR in respect to Daan's comment.

@GabrielBrascher Daan was mentioning about networkmodel retuning a null rather than network name being null. So i think this should be fine and no need for extra if check

@GabrielBrascher GabrielBrascher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhtyd suggested implementing NetworkVO toString(). The toString() sounds like a good plan.

Either way, I am OK with both approaches. Code LGTM.

@davidjumani davidjumani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yadvr

yadvr commented Oct 28, 2020

Copy link
Copy Markdown
Member

@ravening can you fix the conflict?

@ravening

Copy link
Copy Markdown
Member Author

@ravening can you fix the conflict?

@rhtyd done

@yadvr

yadvr commented Oct 28, 2020

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result: ✔centos7 ✔centos8 ✔debian. JID-2296

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

Trillian test result (tid-3097)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 31757 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4396-t3097-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_privategw_acl.py
Smoke tests completed. 85 look OK, 1 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_04_rvpc_privategw_static_routes Failure 869.32 test_privategw_acl.py

@DaanHoogland DaanHoogland added this to the 4.16.0.0 milestone Oct 29, 2020
@yadvr
yadvr requested a review from DaanHoogland February 12, 2021 07:09
@yadvr
yadvr changed the base branch from master to 4.15 February 15, 2021 08:35
@yadvr yadvr modified the milestones: 4.16.0.0, 4.15.1.0 Feb 15, 2021
Co-authored-by: dahn <daan.hoogland@gmail.com>
@yadvr
yadvr merged commit fd49efa into apache:4.15 Feb 19, 2021
@weizhouapache

Copy link
Copy Markdown
Member

@rhtyd @ravening
build failed due to a missing ")" at the end of line.

@weizhouapache

Copy link
Copy Markdown
Member
                 // * verify that there are no duplicates
                 if (hostNames.contains(hostName)) {
                     throw new InvalidParameterValueException("The vm with hostName " + hostName + " already exists in the network domain: " + ntwkDomain.getKey() + "; network="
-                            + (_networkModel.getNetwork(ntwkId) != null) ? _networkModel.getNetwork(ntwkId).getName()) : "<unknown>";
+                            + (_networkModel.getNetwork(ntwkId) != null) ? _networkModel.getNetwork(ntwkId).getName() : "<unknown>");
                 }
             }
         }

@weizhouapache

Copy link
Copy Markdown
Member

good it has been fixed by @rhtyd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants