Alona Kaplan has posted comments on this change. Change subject: engine: Introduce network attachments command ......................................................................
Patch Set 21: (9 comments) https://gerrit.ovirt.org/#/c/34971/21/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddNetworkAttachmentCommand.java File backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddNetworkAttachmentCommand.java: Line 38: @Override Line 39: protected boolean canDoAction() { Line 40: VDS host = getVds(); Line 41: Line 42: if (host == null) { I guess you have the same check for update and remove. Why isn't part of a validation class? Line 43: return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_HOST_NOT_EXIST); Line 44: } Line 45: Line 46: if (!HostSetupNetworksCommand.SUPPORTED_HOST_STATUSES.contains(host.getStatus())) { Line 42: if (host == null) { Line 43: return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_HOST_NOT_EXIST); Line 44: } Line 45: Line 46: if (!HostSetupNetworksCommand.SUPPORTED_HOST_STATUSES.contains(host.getStatus())) { same Line 47: addCanDoActionMessage(VdcBllMessages.VAR__HOST_STATUS__UP_MAINTENANCE_OR_NON_OPERATIONAL); Line 48: return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VDS_STATUS_ILLEGAL); Line 49: } Line 50: Line 50: Line 51: NetworkAttachmentCompleter completer = new NetworkAttachmentCompleter(getHostInterfaces()); Line 52: completer.completeNicName(getParameters().getNetworkAttachment()); Line 53: Line 54: return validateNetworkAttachment() && validateHostInterface() && validateCrossAttachments(); I don't think you need any of these extra validations. Actually, I don't think this command needs any canDoAction validations at all. This command invokes a HostSetupNetworksCommand which already has all the relevant validations. I would avoid this duplication. You have to make sure these command is not invoked as multiple action for 2 reasons- 1. when invoking a command as a multiple action the result is returned to the ui immediately after invoking all the candos. It means that if you propagate a can do from an internel executed action. The cando won't be caught by the ui. 2. Two or more setup-networks commands cannot run simultaneously on the host. Blocking a command from being run as multiple action is done via the MultipleActionsRunnersFactory. You can see- UpdateNetworkOnCluster for an example. Line 55: } Line 56: Line 57: @Override Line 58: protected void executeCommand() { Line 70: String configuredNicName = getParameters().getNetworkAttachment().getNicName(); Line 71: VdsNetworkInterface configuredNic = Entities.entitiesByName(getHostInterfaces()).get(configuredNicName); Line 72: List<NetworkAttachment> attachmentsOnNic = Line 73: getDbFacade().getNetworkAttachmentDao().getAllForNic(configuredNic.getId()); Line 74: for (NetworkAttachment attachment : attachmentsOnNic) { You can use- Linq.firstOrNul(..), I think it is more readable. Line 75: if (attachment.getNetworkId().equals(getParameters().getNetworkAttachment().getNetworkId())) { Line 76: createdAttachmentId = attachment.getId(); Line 77: } Line 78: } https://gerrit.ovirt.org/#/c/34971/21/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/RemoveNetworkAttachmentCommand.java File backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/RemoveNetworkAttachmentCommand.java: Line 27: } Line 28: Line 29: @Override Line 30: protected boolean canDoAction() { Line 31: VDS host = getVds(); Please see the canDoAction related comment in- AddNetworkAttachmentCommand. Line 32: Line 33: if (host == null) { Line 34: return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_HOST_NOT_EXIST); Line 35: } Line 52: protected void executeCommand() { Line 53: HostSetupNetworksParameters params = new HostSetupNetworksParameters(getParameters().getVdsId()); Line 54: NetworkAttachment networkAttachmentForRemove = Line 55: getDbFacade().getNetworkAttachmentDao().get(getParameters().getNetworkAttachment().getId()); Line 56: params.getRemovedNetworkAttachments().add(networkAttachmentForRemove.getId()); You're querying the networkAttachment by id from the db just to get the id? (I mean- the db query is redundant). Line 57: VdcReturnValueBase returnValue = runInternalAction(VdcActionType.HostSetupNetworks, params); Line 58: propagateFailure(returnValue); Line 59: setSucceeded(returnValue.getSucceeded()); Line 60: } https://gerrit.ovirt.org/#/c/34971/21/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/UpdateNetworkAttachmentCommand.java File backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/UpdateNetworkAttachmentCommand.java: Line 36: addValidationGroup(UpdateEntity.class); Line 37: } Line 38: Line 39: @Override Line 40: protected boolean canDoAction() { Please see the canDoAction related comment in- AddNetworkAttachmentCommand. Line 41: VDS host = getVds(); Line 42: Line 43: if (host == null) { Line 44: return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_HOST_NOT_EXIST); Line 54: && validateHostInterface() Line 55: && validateCrossAttachments(); Line 56: } Line 57: Line 58: private NetworkAttachmentCompleter getNetworkAttachmentCompleter() { Why do you need this getter? Do you use the completer anywhere but the canDoAction()? Line 59: if (completer == null) { Line 60: completer = new NetworkAttachmentCompleter(getHostInterfaces()); Line 61: } Line 62: Line 63: return completer; Line 64: } Line 65: Line 66: @Override Line 67: protected void executeCommand() { Since add and update has the same api to the HostSetupNetworks command (and IMO, the canDo is redundant), I think you can remove one of them. Line 68: HostSetupNetworksParameters params = new HostSetupNetworksParameters(getParameters().getVdsId()); Line 69: params.getNetworkAttachments().add(getParameters().getNetworkAttachment()); Line 70: VdcReturnValueBase returnValue = runInternalAction(VdcActionType.HostSetupNetworks, params); Line 71: propagateFailure(returnValue); -- To view, visit https://gerrit.ovirt.org/34971 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: comment Gerrit-Change-Id: I3c1b7a4e0b5ceacf6ea436c4ede84e414817dbdd Gerrit-PatchSet: 21 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <masa...@redhat.com> Gerrit-Reviewer: Alona Kaplan <alkap...@redhat.com> Gerrit-Reviewer: Jenkins CI Gerrit-Reviewer: Martin Mucha <mmu...@redhat.com> Gerrit-Reviewer: automat...@ovirt.org Gerrit-HasComments: Yes _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches