Problem/Motivation
- Similar source code existed between the functions related to the REST API for AWS instances.
Proposed resolution
- Reduce source code for REST APIs by consolidating common processing.
Issue fork cloud-3228432
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
yasComment #3
yasComment #4
yasComment #6
Ryo Yamashita commented@yas
I have created a patch. Could you please check it?
note: Issue #3228270 and #3228276 are included in this patch.
If this patch is merged, will those two issues be closed as "won't fix"?
Comment #7
Ryo Yamashita commentedComment #8
Ryo Yamashita commented@yas
I have recreated a patch.
I created
Ec2OperationsServiceand modified the source code to use its methods inApiControllerandInstanceXxxFormclasses.Could you please check it?
Comment #9
xiaohua guan commented@yas @RyoYamashita
I posted my comment. Please check it.
Comment #10
Ryo Yamashita commented@xiaohua-guan @yas
I updated the source code based on your comment. Please check it.
Comment #11
xiaohua guan commented@ryo-yamashita
Please confirm the comment. And please confirm the operation after you modified the code.
Comment #12
xiaohua guan commentedComment #13
yas@ryo-yamashita
Thank you for the update. That version is exactly what I expected. I posted my comment above. Please check it. Thanks!
Comment #14
Ryo Yamashita commented@yas I tried to load
Ec2OperationsServiceInterfaceintoInstanceStartFormby DI.When I put it as the second argument, the value assigned to it during the DI was of
EntityRepositorytype.I guessed that the order of the arguments was important, and when I added it to the last argument, I got an error like "Wrong number of arguments".
From this, it is guessed that it is not possible to call
Ec2OperationsServiceInterfacewith DI.Comment #15
yas@ryo-yamashita
The
AwsDeleteForm::create()is the following as a super class ofInstanceStartForm,So that we need to override
AwsDeleteForm::create()asInstanceStartForm::create().The arguments in the
InstanceStartForm::create()method must be matched withInstanceStartForm::__construct()like those error messages.Comment #16
Ryo Yamashita commented@yas
As you pointed out, I created
InstanceStartForm::create()for overridingAwsDeleteForm::create().But now I get the following error. How else can I modify the code?Sorry, I forgot to add the use statement. I'll check the behavior as soon as I add it.
Comment #17
Ryo Yamashita commented@yas
Since the
OpenStackInstanceDeleteForminherits fromInstanceDeleteForm, when we extended the constructor ofInstanceDeleteForm, we found thatOpenStackInstanceDeleteFormwas also affected.If you call the constructor of
AwsDeleteUpdateEntityFormin the constructor ofOpenStackInstanceDeleteForm, there is no need to increase the arguments of the constructor ofOpenStackInstanceDeleteForm. However, in that case,OpenStackInstanceTestwill give an error.Therefore, we increased the arguments in the constructor of
OpenStackInstanceDeleteFormto make it pass all the tests. Please check it.Comment #18
yas@ryo-yamashita
Thank you for the update. It looks getting better. Please check my comments. Thanks!
Comment #19
Ryo Yamashita commented@yas
I reformatted the code as instructed.
However, for the logger method of
Ec2OperationsService, I changedreturn $this->getLogger($channel);toreturn CloudContentEntityTrait::logger($channel);. The following error occurred when I changed it.The following error also occurred when I changed
return $this->getLogger($channel);toreturn CloudContentEntityTrait::getLogger($channel);.For this reason, I''ll leave
return $this->getLogger($channel);here.Comment #20
Ryo Yamashita commentedComment #21
Ryo Yamashita commented@yas
I reformatted the source code and fix source code comments. Please check it.
Comment #22
yas@ryo-yamashita
Thank you for the update. I posted my comments. Thanks!
@xiaohua-guan @baldwinlouie
What do you think?
Comment #23
Ryo Yamashita commented@yas
> We don't have to add HTTP response code 200 here like 500 below?
// Add 200 explicitly here?JsonResponseisHTTP 200 OK.Based on these two points, I guessed that you wanted me to omit the ", 200" and made the correction.
However, if it is more appropriate not to omit it, I will revise the relevant part.
> Where did you try to use this Ec2OperationsService::logger() method? I couldn't find any place.
I checked the source code again. Since
Ec2OperationsServicecontainsuse CloudContentEntityTrait, we can already useinherits from
CloudServiceBase, which containsuse CloudContentEntityTrait. Therefore, it is possible to removeuse CloudContentEntityTrait;fromEc2OperationsService.Note: E
c2OperationsService::loggerwas created becauseEntityDeleteFormTraitrequired the implementation ofprotected function logger($channel). For the above reasons, we found that omitting it works fine.==========
The code with the above two fixes passed CI/CD (commit hash: 50b4a76b).
However, when I applied the latest changes to origin/4.x (commit hash: b899f653) and rebased it, it did not pass CI/CD (commit hash: 495931d1).
The erro occurs in
OpenStackInstanceTest, and the following error message is output.Comment #24
xiaohua guan commented@yas @ryo-yamashita
I posted my comments.
Comment #25
Ryo Yamashita commented@baldwinlouie
Regarding this part, the code before the fix (
InstanceStartForm#submitForm()in4.xbranch) also did not include$this->processOperationErrorStatus().Therefore, the code in the Issue (
Ec2OperationsService#startInstance()in the Issue branch) also did not include$this->processOperationErrorStatus().Comment #26
Ryo Yamashita commented@xiaohua-guan
Thank you for your advice. I have removed the unnecessary commas from the source code.
Comment #27
Ryo Yamashita commentedI think I may have found the cause of the error.
In
OpenStackInstanceDeleteForm#submitForm(), there is a process such as "Overwrite$this->ec2Service, and if its type isOpenStackEc2Service, then executeparent::submitForm()(InstanceDeleteForm::submitForm()) and exit.In this case, in the original
InstanceDeleteForm, the specification was to use the overwritten$this->ec2Serviceas is. However, in theInstanceDeleteFormin this issue, the$this->ec2Serviceheld byEc2OperationsServicewill be used to delete the instance.Therefore, it is necessary to prepare a class (e.g.
OpenStackOperationsService) that inheritsEc2OperationsServiceInterfaceas well asEc2OperationsService, and DI it toOpenStackInstanceDeleteForm.Note: This problem with
parent::submitForm()also exists inOpenStackInstanceStartForm,OpenStackInstanceStopForm, andOpenStackInstanceRebootForm.Comment #28
Ryo Yamashita commented@yas
I have created
Ec2OperationsServicefor OpenStack, which can be called by DI fromOpenStackInstanceXxxForm.This allows us to pass all CI/CD test. Please check this commit.
Comment #29
yas@ryo-yamashita
Thank you for the update. I posted my comments. Thanks!
Comment #30
Ryo Yamashita commented@yas
By inheriting from
Ec2OperationsService, the amount of source code has been reduced.Please check this commit.
Comment #31
yas@ryo-yamashita
Thank you for the update. I posted my comment. Also, could you please check @baldwinlouie's comments? Thanks!
Comment #32
Ryo Yamashita commented@yas @baldwinlouie
Thank you for pointing out by your comments. I fixed the relevant part of the source code. Please check it.
Comment #33
yas@ryo-yamashita
Thank you for the update.
@baldwinlouie @xiaohua-guan
Could you please give us your final review? Thanks!
Comment #34
xiaohua guan commented@yas @ryo-yamashita
The code looks good to me now. Thanks.
Comment #35
Ryo Yamashita commented@yas
I rebased from the latest
4.xbranch and also checked that it passed CI/CD. Please check it.Comment #36
baldwinlouie commented@ryo.yamashita and @yas, Thank you for the updated patch. It looks good to me.
Comment #37
yas@xiaohua-guan @baldwinlouie
Thank you for your review. I'll merge the patch to
4.xand close this issue as Fixed.Comment #40
yas