-
Notifications
You must be signed in to change notification settings - Fork 970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for group attribute in update pipeline config api #7155
Added support for group attribute in update pipeline config api #7155
Conversation
- group attribute is mandatory for a PUT request - if the group name is different, a move operation will be performed
group
in update pipeline config apiif (!StringUtils.equalsIgnoreCase(group, updatedGroupName)) { | ||
PipelineConfigs group = cruiseConfig.findGroup(this.group); | ||
group.remove(pipelineConfig); | ||
cruiseConfig.getGroups().addPipeline(updatedGroupName, pipelineConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this might be a little troublesome. The config save flow for entity enters a synchronized block in https://github.com/gocd/gocd/blob/master/server/src/main/java/com/thoughtworks/go/config/GoConfigDao.java#L88, which means that a group might be deleted before the thread for this request acquires the write lock.
Another thing is that the addPipeline
method creates a group if the group name is not found. Is that intentional behaviour? If so, please add a test for the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config save flow for entity enters a synchronized block in https://github.com/gocd/gocd/blob/master/server/src/main/java/com/thoughtworks/go/config/GoConfigDao.java#L88, which means that a group might be deleted before the thread for this request acquires the write lock.
That is a case I missed. Would adding a group existence check in canContinue
handle it or would I need to add a check over here itself?
Update: there is a check of canEditPipeline
in UpdatePipelineConfigCommand#canContinue
which will blow up if the pipeline group does not exist.
Another thing is that the addPipeline method creates a group if the group name is not found. Is that intentional behaviour? If so, please add a test for the same.
Yes, it is intentional (the same happens in CREATE
). I have added a test UpdatePipelineConfigCommandTest.java#shouldUpdateThePipelineGroupIfDifferent
. Probably would rename it better (Edit: renamed to shouldAddGroupWithPipelineAndRemoveItFromPreviousIfTheSpecifiedGroupDoesNotExist
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a case I missed. Would adding a group existence check in canContinue handle it or would I need to add a check over here itself?
Update: there is a check of canEditPipeline in UpdatePipelineConfigCommand#canContinue which will blow up if the pipeline group does not exist.
I suggest moving this block to the update method in UpdatePipelineConfigCommand.java
. Anything that updates the cruise config is best added in the entity command's update method. Similar to how CreatePipelineConfigCommand#update
does it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to shouldAddGroupWithPipelineAndRemoveItFromPreviousIfTheSpecifiedGroupDoesNotExist
Assert on group not being there before the update and assert on group being created after the update. That makes it clear that this behaviour is intentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@varshavaradarajan I took a deeper look into how the Update pipeline config and delete pipeline group works. As far as I understood, if a group is deleted that means it is an empty group and therefore the pipeline in it would have been either deleted or moved to some other group.
In the 1st case, a RecordNotFoundException
would be thrown by the controller. For the 2nd case, the etag comparison should fail. So, I think we are in safe place over here to directly access the group.
WDYT?
cc:\ @maheshp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kritika-singh3 - Depends actually. You're considering just a delete pipeline group request -
Supposing there's a create pipeline group request that is scheduled to be served right after this operation occurs. And suppose that the group name is the same as the new group name used in the update pipeline config API, then the create call (even though it enters the synchronized block before the update pipeline config API request), will error out because a group with that name already exists.
There are always such unforeseen situations when updating the cruise config without acquiring the write lock. So, it is better to perform anything related to updating the cruise config in the entity's update command.
Edit: I see you have updated the update method. Thanks! Sorry.
@@ -74,11 +82,11 @@ public boolean canContinue(CruiseConfig cruiseConfig) { | |||
} | |||
|
|||
private boolean canEditPipeline() { | |||
return goConfigService.canEditPipeline(pipelineConfig.name().toString(), currentUser, result, getPipelineGroup()); | |||
return goConfigService.canEditPipeline(pipelineConfig.name().toString(), currentUser, result, getExistingPipelineGroupName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check if user is admin of the new group to add the pipeline right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we need to do. Will add that in the update
method of the Command.
…e supplied (if different from the existing one)
group
attribute is mandatory for aPUT
request