From e9a3194702d7526422c27c92b19b498de40691fe Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Fri, 18 May 2018 13:56:20 -0600 Subject: [PATCH 01/17] add debug log --- Console/Command/UpdateVclCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Command/UpdateVclCommand.php b/Console/Command/UpdateVclCommand.php index 2be5c90..5bf17f9 100644 --- a/Console/Command/UpdateVclCommand.php +++ b/Console/Command/UpdateVclCommand.php @@ -60,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $application_id = $this->state->getApplicationId(); $environment_name = $this->state->getEnvironmentName(); $proxy_name = $this->state->getProxyName(); - + error_log(print_r($proxy_name, TRUE)); if (!$account_id) { throw new \Exception('account_id has not been set, please run sectionio:setup'); } From 8bca34a22e281f032a3db082401933d6961940d5 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Fri, 18 May 2018 14:25:24 -0600 Subject: [PATCH 02/17] update logging parameters --- Console/Command/UpdateVclCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Command/UpdateVclCommand.php b/Console/Command/UpdateVclCommand.php index 5bf17f9..ade9ba7 100644 --- a/Console/Command/UpdateVclCommand.php +++ b/Console/Command/UpdateVclCommand.php @@ -60,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $application_id = $this->state->getApplicationId(); $environment_name = $this->state->getEnvironmentName(); $proxy_name = $this->state->getProxyName(); - error_log(print_r($proxy_name, TRUE)); + error_log(print_r($proxy_name, TRUE),0); if (!$account_id) { throw new \Exception('account_id has not been set, please run sectionio:setup'); } From 55a7c18e7556bc7327403c5445e9f7e3110857fa Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Fri, 18 May 2018 14:56:06 -0600 Subject: [PATCH 03/17] Update variable reporting method --- Console/Command/UpdateVclCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Console/Command/UpdateVclCommand.php b/Console/Command/UpdateVclCommand.php index ade9ba7..c294fb4 100644 --- a/Console/Command/UpdateVclCommand.php +++ b/Console/Command/UpdateVclCommand.php @@ -60,7 +60,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $application_id = $this->state->getApplicationId(); $environment_name = $this->state->getEnvironmentName(); $proxy_name = $this->state->getProxyName(); - error_log(print_r($proxy_name, TRUE),0); + $output->writeln('Proxy Name is ' . $proxy_name); + if (!$account_id) { throw new \Exception('account_id has not been set, please run sectionio:setup'); } From 03092a1a34d48a8b9772011d3647037705ffa6f8 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sat, 19 May 2018 14:46:49 -0600 Subject: [PATCH 04/17] Change Varnish 4 to 5 as test --- Console/Command/UpdateVclCommand.php | 6 ++++-- Helper/State.php | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Console/Command/UpdateVclCommand.php b/Console/Command/UpdateVclCommand.php index c294fb4..7a45811 100644 --- a/Console/Command/UpdateVclCommand.php +++ b/Console/Command/UpdateVclCommand.php @@ -60,7 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $application_id = $this->state->getApplicationId(); $environment_name = $this->state->getEnvironmentName(); $proxy_name = $this->state->getProxyName(); - $output->writeln('Proxy Name is ' . $proxy_name); + $proxy_image = $this->state->getProxyImage(); if (!$account_id) { throw new \Exception('account_id has not been set, please run sectionio:setup'); @@ -77,9 +77,11 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$proxy_name) { throw new \Exception('proxy_name has not been set, please run sectionio:setup'); } + /** Extract the generated Varnish 4 VCL code */ - $vcl = $this->pageCacheConfig->getVclFile(\Magento\PageCache\Model\Config::VARNISH_4_CONFIGURATION_PATH); + + $vcl = $this->pageCacheConfig->getVclFile(\Magento\PageCache\Model\Config::VARNISH_5_CONFIGURATION_PATH); $result = $this->aperture->updateProxyConfiguration($account_id, $application_id, $environment_name, $proxy_name, $vcl, 'MagentoTurpentine'); if ($result['http_code'] == 200) { diff --git a/Helper/State.php b/Helper/State.php index a87df67..f031815 100644 --- a/Helper/State.php +++ b/Helper/State.php @@ -96,4 +96,9 @@ public function getProxyName() { return 'varnish'; } + + public function getProxyImage() + { + + } } From 373f5a934aa52d353655057c8e02e9ccf0148de2 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sat, 19 May 2018 16:35:45 -0600 Subject: [PATCH 05/17] Change Varnish 4 to 5 as test --- Controller/Adminhtml/Report/Save.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Controller/Adminhtml/Report/Save.php b/Controller/Adminhtml/Report/Save.php index 96bf4a9..cc6d8f1 100644 --- a/Controller/Adminhtml/Report/Save.php +++ b/Controller/Adminhtml/Report/Save.php @@ -204,7 +204,7 @@ public function updateVarnishConfiguration() $environment_name = $this->state->getEnvironmentName(); /** Extract the generated Varnish 4 VCL code */ - $vcl = $this->pageCacheConfig->getVclFile(\Magento\PageCache\Model\Config::VARNISH_4_CONFIGURATION_PATH); + $vcl = $this->pageCacheConfig->getVclFile(\Magento\PageCache\Model\Config::VARNISH_5_CONFIGURATION_PATH); $result = $this->aperture->updateProxyConfiguration($account_id, $application_id, $environment_name, 'varnish', $vcl, 'MagentoTurpentine'); if ($result['http_code'] == 200) { From 38820f6ddbfe8d211e0f82f5f0b29c97ebb0ef50 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sun, 20 May 2018 15:11:40 -0600 Subject: [PATCH 06/17] Pull proxy name from aperture and send VCL based on varnish version --- Console/Command/UpdateVclCommand.php | 1 - Controller/Adminhtml/Report/Save.php | 11 +++++++++-- Helper/Data.php | 12 ++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Console/Command/UpdateVclCommand.php b/Console/Command/UpdateVclCommand.php index 7a45811..f4313d3 100644 --- a/Console/Command/UpdateVclCommand.php +++ b/Console/Command/UpdateVclCommand.php @@ -60,7 +60,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $application_id = $this->state->getApplicationId(); $environment_name = $this->state->getEnvironmentName(); $proxy_name = $this->state->getProxyName(); - $proxy_image = $this->state->getProxyImage(); if (!$account_id) { throw new \Exception('account_id has not been set, please run sectionio:setup'); diff --git a/Controller/Adminhtml/Report/Save.php b/Controller/Adminhtml/Report/Save.php index cc6d8f1..41b41d4 100644 --- a/Controller/Adminhtml/Report/Save.php +++ b/Controller/Adminhtml/Report/Save.php @@ -202,9 +202,16 @@ public function updateVarnishConfiguration() $application_id = $this->state->getApplicationId(); /** @var string $environment_name */ $environment_name = $this->state->getEnvironmentName(); + /** @var string $proxy_image*/ + $proxy_image = $this->data->getProxyImage($account_id, $application_id); + + /** Extract the generated VCL code appropriate for their version*/ + if (strpos($proxy_image, "4" !== false)){ + $vcl = $this->pageCacheConfig->getVclFile(\Magento\PageCache\Model\Config::VARNISH_4_CONFIGURATION_PATH); + } else { + $vcl = $this->pageCacheConfig->getVclFile(\Magento\PageCache\Model\Config::VARNISH_5_CONFIGURATION_PATH); + } - /** Extract the generated Varnish 4 VCL code */ - $vcl = $this->pageCacheConfig->getVclFile(\Magento\PageCache\Model\Config::VARNISH_5_CONFIGURATION_PATH); $result = $this->aperture->updateProxyConfiguration($account_id, $application_id, $environment_name, 'varnish', $vcl, 'MagentoTurpentine'); if ($result['http_code'] == 200) { diff --git a/Helper/Data.php b/Helper/Data.php index e7e6000..f84a073 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -580,4 +580,16 @@ public function clearDefaultApplication() $applicationFactory->save(); } } + + public function getProxyImage($account_id, $application_id) + { + $parameters = array("accountId"=>$account_id, "applicationId"=>$application_id, "environmentName"=>"Production"); + $url = $this->generateApertureUrl($parameters); + $json_response = $this->performCurl($url); + /** return response as an associative array */ + $response = json_decode($json_response); + /** grab the proxy image */ + $full_image = $response[0]->image; + return explode(".", $full_image)[0]; + } } From a38ece24aadadf189a0f138b18ebb1d977a0e4e4 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sun, 20 May 2018 18:06:29 -0600 Subject: [PATCH 07/17] Update extension to check env's varnish version before deploying vcl --- Console/Command/UpdateVclCommand.php | 15 +++++++++++---- Controller/Adminhtml/Report/Save.php | 2 +- Helper/Data.php | 11 ++++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Console/Command/UpdateVclCommand.php b/Console/Command/UpdateVclCommand.php index f4313d3..8ad4ac2 100644 --- a/Console/Command/UpdateVclCommand.php +++ b/Console/Command/UpdateVclCommand.php @@ -23,6 +23,8 @@ class UpdateVclCommand extends Command protected $state; /** @var \Magento\PageCache\Model\Config\PageCache $pageCacheConfig */ protected $pageCacheConfig; + /** @var \Sectionio\Metrics\Helper\Data $helper */ + protected $helper; /** * @param \Sectionio\Metrics\Helper\Aperture $aperture @@ -60,6 +62,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $application_id = $this->state->getApplicationId(); $environment_name = $this->state->getEnvironmentName(); $proxy_name = $this->state->getProxyName(); + /** @var string $proxy_image*/ + $proxy_image = $this->helper->getProxyImage($account_id, $application_id); if (!$account_id) { throw new \Exception('account_id has not been set, please run sectionio:setup'); @@ -76,11 +80,14 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!$proxy_name) { throw new \Exception('proxy_name has not been set, please run sectionio:setup'); } - - /** Extract the generated Varnish 4 VCL code */ - - $vcl = $this->pageCacheConfig->getVclFile(\Magento\PageCache\Model\Config::VARNISH_5_CONFIGURATION_PATH); + /** Extract the generated VCL code appropriate for their version*/ + if (strpos($proxy_image, "4" !== false)){ + $vcl = $this->pageCacheConfig->getVclFile(\Magento\PageCache\Model\Config::VARNISH_4_CONFIGURATION_PATH); + } else { + $vcl = $this->pageCacheConfig->getVclFile(\Magento\PageCache\Model\Config::VARNISH_5_CONFIGURATION_PATH); + } + $result = $this->aperture->updateProxyConfiguration($account_id, $application_id, $environment_name, $proxy_name, $vcl, 'MagentoTurpentine'); if ($result['http_code'] == 200) { diff --git a/Controller/Adminhtml/Report/Save.php b/Controller/Adminhtml/Report/Save.php index 41b41d4..c2fcb20 100644 --- a/Controller/Adminhtml/Report/Save.php +++ b/Controller/Adminhtml/Report/Save.php @@ -203,7 +203,7 @@ public function updateVarnishConfiguration() /** @var string $environment_name */ $environment_name = $this->state->getEnvironmentName(); /** @var string $proxy_image*/ - $proxy_image = $this->data->getProxyImage($account_id, $application_id); + $proxy_image = $this->helper->getProxyImage($account_id, $application_id); /** Extract the generated VCL code appropriate for their version*/ if (strpos($proxy_image, "4" !== false)){ diff --git a/Helper/Data.php b/Helper/Data.php index f84a073..2e6ce10 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -588,8 +588,13 @@ public function getProxyImage($account_id, $application_id) $json_response = $this->performCurl($url); /** return response as an associative array */ $response = json_decode($json_response); - /** grab the proxy image */ - $full_image = $response[0]->image; - return explode(".", $full_image)[0]; + /** find object with name=varnish */ + $image; + foreach($response as $proxy){ + if ($proxy->name == "varnish") { + $image = $proxy->image; + } + } + return explode(".", $image)[0]; } } From dc73f4f01a40bd12fa7b89f14d9f0606ee4c24bb Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sun, 20 May 2018 18:24:24 -0600 Subject: [PATCH 08/17] wip --- Helper/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 2e6ce10..3eea9f1 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -585,9 +585,9 @@ public function getProxyImage($account_id, $application_id) { $parameters = array("accountId"=>$account_id, "applicationId"=>$application_id, "environmentName"=>"Production"); $url = $this->generateApertureUrl($parameters); - $json_response = $this->performCurl($url); + $response = $this->performCurl($url); /** return response as an associative array */ - $response = json_decode($json_response); + /** $response = json_decode($json_response); */ /** find object with name=varnish */ $image; foreach($response as $proxy){ From 8d375fbb9f7ba62d35d58ec1f5f09427737e7ca2 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sun, 20 May 2018 18:39:09 -0600 Subject: [PATCH 09/17] wip --- Helper/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 3eea9f1..d763bbd 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -585,9 +585,9 @@ public function getProxyImage($account_id, $application_id) { $parameters = array("accountId"=>$account_id, "applicationId"=>$application_id, "environmentName"=>"Production"); $url = $this->generateApertureUrl($parameters); - $response = $this->performCurl($url); + $curl_response = $this->performCurl($url); /** return response as an associative array */ - /** $response = json_decode($json_response); */ + $response = json_decode($curl_response['body_content'], true); /** find object with name=varnish */ $image; foreach($response as $proxy){ From 50ab715209add5e7834ccf2ec3cde09149eeba5a Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sun, 20 May 2018 18:59:43 -0600 Subject: [PATCH 10/17] wip --- Helper/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index d763bbd..fb82cae 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -591,8 +591,8 @@ public function getProxyImage($account_id, $application_id) /** find object with name=varnish */ $image; foreach($response as $proxy){ - if ($proxy->name == "varnish") { - $image = $proxy->image; + if ($proxy["name"] == "varnish") { + $image = $proxy["image"]; } } return explode(".", $image)[0]; From c266560d92414770ca0f30b1932c7223d91a7303 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sun, 20 May 2018 19:10:33 -0600 Subject: [PATCH 11/17] Change to single quotes --- Helper/Data.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index fb82cae..723acda 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -591,8 +591,8 @@ public function getProxyImage($account_id, $application_id) /** find object with name=varnish */ $image; foreach($response as $proxy){ - if ($proxy["name"] == "varnish") { - $image = $proxy["image"]; + if ($proxy['name'] == 'varnish') { + $image = $proxy['image']; } } return explode(".", $image)[0]; From 5d53fad45014fc3ecc7a164920a808ee05c09fb4 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sun, 20 May 2018 19:21:24 -0600 Subject: [PATCH 12/17] add error log --- Helper/Data.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Helper/Data.php b/Helper/Data.php index 723acda..8459e86 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -589,6 +589,7 @@ public function getProxyImage($account_id, $application_id) /** return response as an associative array */ $response = json_decode($curl_response['body_content'], true); /** find object with name=varnish */ + error_log(print_r($response,true)); $image; foreach($response as $proxy){ if ($proxy['name'] == 'varnish') { From d3e035e731dd05e7bb092267ae3128c498e5692a Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sun, 20 May 2018 20:05:01 -0600 Subject: [PATCH 13/17] wip debug --- Helper/Data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper/Data.php b/Helper/Data.php index 8459e86..5100833 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -589,7 +589,7 @@ public function getProxyImage($account_id, $application_id) /** return response as an associative array */ $response = json_decode($curl_response['body_content'], true); /** find object with name=varnish */ - error_log(print_r($response,true)); + error_log(print_r($curl_response,true)); $image; foreach($response as $proxy){ if ($proxy['name'] == 'varnish') { From 46fef0ace68b9d42613b066eedce11db8a815d7f Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sun, 20 May 2018 20:21:06 -0600 Subject: [PATCH 14/17] wip debug --- Helper/Data.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 5100833..4fcaeb0 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -584,10 +584,11 @@ public function clearDefaultApplication() public function getProxyImage($account_id, $application_id) { $parameters = array("accountId"=>$account_id, "applicationId"=>$application_id, "environmentName"=>"Production"); - $url = $this->generateApertureUrl($parameters); + $partial_url = $this->generateApertureUrl($parameters); + $url = $partial_url . "/stack"; $curl_response = $this->performCurl($url); /** return response as an associative array */ - $response = json_decode($curl_response['body_content'], true); + $response = json_decode($curl_response[' body_content'], true); /** find object with name=varnish */ error_log(print_r($curl_response,true)); $image; From 2817b194d84f6b74d2b89940854c491e25aa4f56 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Sun, 20 May 2018 20:24:28 -0600 Subject: [PATCH 15/17] wip debug --- Helper/Data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Helper/Data.php b/Helper/Data.php index 4fcaeb0..b502a9a 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -588,7 +588,7 @@ public function getProxyImage($account_id, $application_id) $url = $partial_url . "/stack"; $curl_response = $this->performCurl($url); /** return response as an associative array */ - $response = json_decode($curl_response[' body_content'], true); + $response = json_decode($curl_response['body_content'], true); /** find object with name=varnish */ error_log(print_r($curl_response,true)); $image; From be4d584ebfbbcc5da3385dcdf3105e4a9f39a1b9 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Mon, 21 May 2018 09:55:54 -0600 Subject: [PATCH 16/17] fix object bug --- Console/Command/UpdateVclCommand.php | 3 +++ Helper/Data.php | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Console/Command/UpdateVclCommand.php b/Console/Command/UpdateVclCommand.php index 8ad4ac2..1aac714 100644 --- a/Console/Command/UpdateVclCommand.php +++ b/Console/Command/UpdateVclCommand.php @@ -29,17 +29,20 @@ class UpdateVclCommand extends Command /** * @param \Sectionio\Metrics\Helper\Aperture $aperture * @param \Sectionio\Metrics\Helper\State $state + * @param \Sectionio\Metrics\Helper\Data $helper * @param \Magento\PageCache\Model\Config $pageCacheConfig */ public function __construct( \Sectionio\Metrics\Helper\Aperture $aperture, \Sectionio\Metrics\Helper\State $state, + \Sectionio\Metrics\Helper\Data $helper, \Magento\PageCache\Model\Config $pageCacheConfig ) { parent::__construct(); $this->aperture = $aperture; $this->state = $state; $this->pageCacheConfig = $pageCacheConfig; + $this->helper = $helper } /** diff --git a/Helper/Data.php b/Helper/Data.php index b502a9a..b9205ee 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -583,14 +583,18 @@ public function clearDefaultApplication() public function getProxyImage($account_id, $application_id) { + /**generateApertureUrl takes an associative array */ $parameters = array("accountId"=>$account_id, "applicationId"=>$application_id, "environmentName"=>"Production"); + + /** build the account url */ $partial_url = $this->generateApertureUrl($parameters); $url = $partial_url . "/stack"; + $curl_response = $this->performCurl($url); /** return response as an associative array */ $response = json_decode($curl_response['body_content'], true); - /** find object with name=varnish */ - error_log(print_r($curl_response,true)); + /** find object with name=varnish, grab the image */ + $image; foreach($response as $proxy){ if ($proxy['name'] == 'varnish') { From 4b82e6023b25f9cd06ebf098b15517ec2861ecd1 Mon Sep 17 00:00:00 2001 From: Aaron Schreck Date: Mon, 21 May 2018 10:00:14 -0600 Subject: [PATCH 17/17] syntax error --- Console/Command/UpdateVclCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Console/Command/UpdateVclCommand.php b/Console/Command/UpdateVclCommand.php index 1aac714..9d4e616 100644 --- a/Console/Command/UpdateVclCommand.php +++ b/Console/Command/UpdateVclCommand.php @@ -42,7 +42,7 @@ public function __construct( $this->aperture = $aperture; $this->state = $state; $this->pageCacheConfig = $pageCacheConfig; - $this->helper = $helper + $this->helper = $helper; } /**