Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Fix bug that causes DS requests to fulfill immediately while other requests are still open#3727

Merged
mitchell852 merged 4 commits intoapache:masterfrom
alexluckerman:tp-ds-requests-fulfill-immediately-fix
Jul 24, 2019
Merged

Fix bug that causes DS requests to fulfill immediately while other requests are still open#3727
mitchell852 merged 4 commits intoapache:masterfrom
alexluckerman:tp-ds-requests-fulfill-immediately-fix

Conversation

@alexluckerman
Copy link
Copy Markdown
Contributor

@alexluckerman alexluckerman commented Jul 15, 2019

I also made a small tweak to the DS requests TP test as it seemed to be failing locally for me because it wasn't waiting long enough for TP to change its URL

What does this PR (Pull Request) do?

Which Traffic Control components are affected by this PR?

  • Traffic Portal

This is a small bug that should not require documentation or a changelog entry

What is the best way to verify this PR?

Enable DS requests in TP and run the DS requests TP test, then manually verify that updating or deleting a DS while at least one DS request for that same DS is open fails

The following criteria are ALL met by this PR

  • This PR includes tests OR I have explained why tests are unnecessary
  • This PR includes documentation OR I have explained why documentation is unnecessary
  • This PR includes an update to CHANGELOG.md OR such an update is not necessary
  • This PR includes any and all required license headers
  • This PR ensures that database migration sequence is correct OR this PR does not include a database migration
  • This PR DOES NOT FIX A SERIOUS SECURITY VULNERABILITY (see the Apache Software Foundation's security guidelines for details)

@asfgit
Copy link
Copy Markdown
Contributor

asfgit commented Jul 15, 2019

Can one of the admins verify this patch?

@mitchell852 mitchell852 self-assigned this Jul 16, 2019
@mitchell852 mitchell852 added Traffic Portal v1 related to Traffic Portal version 1 bug something isn't working as intended labels Jul 16, 2019
function(dsRequests) {
// search all requests for those that are not completed and share the same deliveryservice id
angular.forEach(dsRequests, function(value) {
if (value.status != 'complete' && value.deliveryService.id == deliveryService.id) {
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.

you should short circuit this condition by putting this as the first check as it will fail in most instances and then the 2nd check is never evaluated (might get you a little performance for free)

if (value.deliveryService.id == deliveryService.id && value.status != 'complete') {

Copy link
Copy Markdown
Member

@mitchell852 mitchell852 Jul 16, 2019

Choose a reason for hiding this comment

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

also, if you rename the function something like hasOpenRequest and check for the statuses we know to be open (draft, submitted or pending), i think your other condition will read a little nicer

if (options.status.id == $scope.COMPLETE && !hasOpenRequest(deliveryService))

the reason i mention this is because this ds request code is a bit of a mess already as i'm sure you noticed, so easy to understand naming will make everyone's life easier.

not sure if that's a standard way in the industry to name boolean methods or if it's a java thing but i always thought it rolled off the tongue nicely - https://stackoverflow.com/questions/3874350/naming-conventions-for-java-methods-that-return-booleanno-question-mark

Copy link
Copy Markdown
Member

@mitchell852 mitchell852 Jul 17, 2019

Choose a reason for hiding this comment

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

so i've been thinking about this a bit more. the way you are performing this check is rather expensive. you are fetching all the DS requests (open or closed) and then looping thru them to determine if there is an open one for this ds when instead this problem could easily be solved by fixing the order of operations. check out the current code:

if (options.status.id == $scope.COMPLETE) {
	deliveryServiceService.updateDeliveryService(deliveryService).
		then(
			function() {
				$state.reload(); // reloads all the resolves for the view
				messageModel.setMessages([ { level: 'success', text: 'Delivery Service [ ' + deliveryService.xmlId + ' ] updated' } ], false);
				createDeliveryServiceUpdateRequest(dsRequest, options.comment, true);
			},
			function(fault) {
				$anchorScroll(); // scrolls window to top
				messageModel.setMessages(fault.data.alerts, false);
			}
		);
} else {
	createDeliveryServiceUpdateRequest(dsRequest, options.comment, false);
}

The order is simply backwards. Currently, it tries to update the ds (which succeeds) and THEN it tries to create a ds request (which fails because there is already one open).

So if you simply flip the order around and only make it update the ds IF the creation of the ds request succeeds, then problem solved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that makes things a lot easier

@@ -201,18 +197,16 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type,
// if the user chooses to complete/fulfill the update request immediately, the ds will be updated and behind the
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.

can you rewrite this comment? it's not true anymore.

@@ -61,44 +61,40 @@ var FormEditDeliveryServiceController = function(deliveryService, origin, type,

// if the user chooses to complete/fulfill the delete request immediately, the ds will be deleted and behind the
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.

can you update this comment as well. it's backwards.

@mitchell852
Copy link
Copy Markdown
Member

@alexluckerman - is this the command you are running to run the single ds request UI test?

protractor conf.js --specs DeliveryServiceRequests/delivery-service-requests-spec.js

because i'm getting

11 specs, 11 failures

@alexluckerman
Copy link
Copy Markdown
Contributor Author

@mitchell852 I've been using protractor conf-delivery-service-requests.js, I believe it's in a separate file since DS requests are an optional feature in TP

Copy link
Copy Markdown
Member

@mitchell852 mitchell852 left a comment

Choose a reason for hiding this comment

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

  • UI tests pass
  • Manually tested

@mitchell852 mitchell852 merged commit 1d2bc4a into apache:master Jul 24, 2019
@mitchell852
Copy link
Copy Markdown
Member

This change also fixed #3512

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

Labels

bug something isn't working as intended Traffic Portal v1 related to Traffic Portal version 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

trying to delete a ds that has an open ds request is successful

4 participants