+++ b/modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php
@@ -163,7 +163,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
+ if ($updated !== FALSE) {
@@ -342,7 +330,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
+ if ($updated !== FALSE) {
@@ -392,7 +374,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
+ if ($updated !== FALSE) {
@@ -508,7 +473,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
+ if ($updated !== FALSE) {
@@ -558,7 +517,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
+ if ($updated !== FALSE) {
@@ -609,7 +562,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
+ if ($updated !== FALSE) {
+++ b/modules/cloud_service_providers/aws_cloud/src/Controller/Vpc/ApiController.php
@@ -118,7 +115,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
+ if ($updated !== FALSE) {
@@ -169,7 +160,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
+ if ($updated !== FALSE) {
@@ -220,7 +205,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
+ if ($updated !== FALSE) {
+++ b/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2Service.php
@@ -3200,4 +3216,96 @@ class Ec2Service extends CloudServiceBase implements Ec2ServiceInterface {
+ if ($updated !== FALSE) {
...
+ if ($updated !== FALSE) {
...
+ if ($updated !== FALSE) {
Is there any reason why you didn't use $updated === TRUE here?
+++ b/modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php
@@ -177,9 +183,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
public function updateAllInstanceList() {
@@ -356,29 +350,17 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
public function updateAllSecurityGroupList() {
@@ -406,9 +394,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
public function updateAllNetworkInterfaceList() {
@@ -456,44 +448,17 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
public function updateAllElasticIpList() {
@@ -522,29 +493,17 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
public function updateAllKeyPairList() {
@@ -572,29 +537,17 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
public function updateAllVolumeList() {
@@ -623,9 +582,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
public function updateAllSnapshotList() {
+++ b/modules/cloud_service_providers/aws_cloud/src/Controller/Vpc/ApiController.php
@@ -132,29 +135,17 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
public function updateAllVpcList() {
@@ -183,29 +180,17 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
public function updateAllVpcPeeringConnectionList() {
@@ -234,9 +225,13 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
public function updateAllSubnetList() {
Can you refactor to aggregate those updateAll*List() methods to e.g. updateAllResourceList()?
+++ b/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2Service.php
@@ -3200,4 +3216,96 @@ class Ec2Service extends CloudServiceBase implements Ec2ServiceInterface {
+ public function updateEntityMessage($entity_type, $cloud_context, $cloud_config, $updated) {
Can you refactor the logic in the method to even simpler? (Reducing or aggregating if-statement)
+++ b/src/Entity/CloudConfig.php
@@ -340,6 +340,29 @@ class CloudConfig extends CloudContentEntityBase implements CloudConfigInterface
+ public function getResourceLink($plural_label, $entity_type, $cloud_context) {
Do we need the parameter $cloud_context? Because this is CloudConfig entity, so it should hold the $cloud_context inside the instance. (Can we use getCloudContext() in getResourceLink()?)
Since we have to support a custom case for aws_elastic_ips, how about we use a "switch" statement, where the default case is the code inside if ($entity_type_name !== 'aws_cloud_image)?
We can then have switch cases for 'aws_cloud_image' and 'aws_cloud_elastic_ips'..etc...
+++ b/src/Entity/CloudConfig.php
@@ -340,6 +340,27 @@ class CloudConfig extends CloudContentEntityBase implements CloudConfigInterface
+ public function getResourceLink($plural_label, $entity_type) {
If this is a public method, please add a definition in CloudConfigInterface
1. Ec2Service::clearCacheValue(); is used for update*List() not for updateAll*List() method. $this->clearCacheValue(); is used for updateAll*List() so both are using for different methods.
I moved $this->clearCacheValue(); into updateAllResourceList() instead of updateEntityMessage().
2. Moved Elastic Ip logic into updateAllResourceList() with status messages from updateEntityMessage().
3. I initialized $account_id to NULL.
4. We can not declare it as private as it is used in ApiController. I added updateAllResourceList() in Ec2ServiceInterface.
5. Converted the logic into switch case.
6. Added getResourceLink() in CloudConfigInterface.
Comments
Comment #2
jigish.addweb commentedComment #3
jigish.addweb commentedComment #4
yasIs there any reason why you didn't use
$updated === TRUEhere?Can you refactor to aggregate those
updateAll*List()methods to e.g.updateAllResourceList()?Can you refactor the logic in the method to even simpler? (Reducing or aggregating
if-statement)Do we need the parameter $cloud_context? Because this is CloudConfig entity, so it should hold the $cloud_context inside the instance. (Can we use
getCloudContext()ingetResourceLink()?)Comment #5
jigish.addweb commentedComment #6
jigish.addweb commented@yas
Thank you for your review.
1. There was a condition for FALSE (i.e.
$updated !== FALSE) so that I had followed that code but now, I have changed it to$updated === TRUE.2. Refactored the code of
updateAll*List()methods and added common methodupdateAllResourceList().3. Reduced if-statements as much as possible.
4. Removed
$cloud_contextparameter and usedgetCloudContext()instead of$cloud_context.Please review updated patch.
Thanks
Comment #7
yas@jigishaddweb
Thank you for the update.
Can we refactor as follows?
FROM:
TO:
Comment #8
jigish.addweb commentedComment #9
jigish.addweb commented@yas
I have done changes as per your comment. Please review updated patch.
Thanks
Comment #10
jigish.addweb commented@yas
I have added permission to each AWS entity. Please review this updated patch.
Thanks
Comment #11
yas@jigishaddweb
Thank you for the update.
Let's reduce the if-statement nest and adding
!empty():FROM:
TO:
@xiaohua-guan, @baldwinloue
What do you think in the other portion?
Comment #12
jigish.addweb commentedComment #13
jigish.addweb commented@yas
I did changes as per your comment. Please review the new patch.
Thanks
Comment #14
baldwinlouie commented@jigishaddweb, Thank you for the updated patch. I have the following comments.
clearCacheValue()can potentially be called twice per API operation. Once inside theupdate*List()and once inside theupdateEntityMessagemethod.Please choose one place to call the cache clear.
I think it should be in the
APIControllercode and not insideupdateEntityMessage.updateEntityMessageshould only be for setting messages.When an Elastic Ip is updated, there is code that updates the NetworkInterfaces as well. This code needs to be moved to
updateAllResourceListas well.Please initialize
$account_idto something. There is a chance $account_id can be returned uninitialized.If this is a public method, please put this in
ApiControllerInterface. If it is only meant to be a helper method, please make this private.This method should also catch the following exceptions:
Since we have to support a custom case for aws_elastic_ips, how about we use a "switch" statement, where the default case is the code inside
if ($entity_type_name !== 'aws_cloud_image)?We can then have switch cases for 'aws_cloud_image' and 'aws_cloud_elastic_ips'..etc...
If this is a public method, please add a definition in
CloudConfigInterfaceComment #15
jigish.addweb commentedComment #16
jigish.addweb commented@baldwinlouie
Thank you for reviewing the patch.
1.
Ec2Service::clearCacheValue();is used forupdate*List()not forupdateAll*List()method.$this->clearCacheValue();is used forupdateAll*List()so both are using for different methods.I moved
$this->clearCacheValue();intoupdateAllResourceList()instead ofupdateEntityMessage().2. Moved Elastic Ip logic into
updateAllResourceList()with status messages fromupdateEntityMessage().3. I initialized
$account_idto NULL.4. We can not declare it as private as it is used in
ApiController. I addedupdateAllResourceList()inEc2ServiceInterface.5. Converted the logic into switch case.
6. Added
getResourceLink()inCloudConfigInterface.Please review the updated patch.
Thanks
Comment #17
baldwinlouie commented@jigishaddweb, thank you for the updated patch. Please see my comments below.
I think it is better to catch the exceptions in the method and display an error message.
The methods that call
updateallResourceListdo not catch the exceptions. Thus, there is a chance we get a White Screen due to a 500 error.I think you can get rid of
$account = $this->currentUser()and useSince we are not using
$accountagain.Comment #18
jigish.addweb commentedComment #19
jigish.addweb commented@baldwinlouie
I did changes as per your comment. Please review the new patch.
Thanks
Comment #20
baldwinlouie commented@jigishaddweb, thank you for the patch. It looks good now!
Comment #21
yas@baldwinlouie
Thank you for your review. I'll merge the patch to
8.x-1.x,8.x-2.xand3.xand close this issue asFixed.Comment #25
yas