Skip to content

Commit f83fe18

Browse files
Merge pull request #128 from glo72880/MCLOUD-10167
MCLOUD-10167: Skip ElasticSearch & OpenSearch error when LiveSearch enabled
2 parents 1d7be97 + 4e8b350 commit f83fe18

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

src/Config/Validator/Deploy/ElasticSearchIntegrity.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\MagentoCloud\Config\Validator\Deploy;
99

1010
use Magento\MagentoCloud\App\Error;
11+
use Magento\MagentoCloud\Config\Magento\Shared\Reader;
1112
use Magento\MagentoCloud\Config\Validator;
1213
use Magento\MagentoCloud\Config\ValidatorException;
1314
use Magento\MagentoCloud\Config\ValidatorInterface;
@@ -42,22 +43,30 @@ class ElasticSearchIntegrity implements ValidatorInterface
4243
*/
4344
private $openSearch;
4445

46+
/**
47+
* @var Reader
48+
*/
49+
private $reader;
50+
4551
/**
4652
* @param MagentoVersion $magentoVersion
4753
* @param Validator\ResultFactory $resultFactory
4854
* @param ElasticSearch $elasticSearch
4955
* @param OpenSearch $openSearch
56+
* @param Reader $reader
5057
*/
5158
public function __construct(
5259
MagentoVersion $magentoVersion,
5360
Validator\ResultFactory $resultFactory,
5461
ElasticSearch $elasticSearch,
55-
OpenSearch $openSearch
62+
OpenSearch $openSearch,
63+
Reader $reader
5664
) {
5765
$this->magentoVersion = $magentoVersion;
5866
$this->resultFactory = $resultFactory;
5967
$this->elasticsearch = $elasticSearch;
6068
$this->openSearch = $openSearch;
69+
$this->reader = $reader;
6170
}
6271

6372
/**
@@ -70,8 +79,11 @@ public function validate(): Validator\ResultInterface
7079
return $this->resultFactory->success();
7180
}
7281

82+
$modules = $this->reader->read()['modules'] ?? [];
83+
$liveSearchEnabled = $modules['Magento_LiveSearchAdapter'] ?? false;
84+
7385
if ($this->magentoVersion->isGreaterOrEqual('2.4.0')
74-
&& !$this->elasticsearch->isInstalled()
86+
&& !$this->elasticsearch->isInstalled() && !$liveSearchEnabled
7587
) {
7688
return $this->resultFactory->errorByCode(Error::DEPLOY_ES_SERVICE_NOT_INSTALLED);
7789
}

src/Config/Validator/Deploy/OpenSearchIntegrity.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\MagentoCloud\Config\Validator\Deploy;
99

1010
use Magento\MagentoCloud\App\Error;
11+
use Magento\MagentoCloud\Config\Magento\Shared\Reader;
1112
use Magento\MagentoCloud\App\GenericException;
1213
use Magento\MagentoCloud\Config\Validator;
1314
use Magento\MagentoCloud\Config\ValidatorException;
@@ -43,22 +44,30 @@ class OpenSearchIntegrity implements ValidatorInterface
4344
*/
4445
private $openSearch;
4546

47+
/**
48+
* @var Reader
49+
*/
50+
private $reader;
51+
4652
/**
4753
* @param MagentoVersion $magentoVersion
4854
* @param Validator\ResultFactory $resultFactory
4955
* @param ElasticSearch $elasticSearch
5056
* @param OpenSearch $openSearch
57+
* @param Reader $reader
5158
*/
5259
public function __construct(
5360
MagentoVersion $magentoVersion,
5461
Validator\ResultFactory $resultFactory,
5562
ElasticSearch $elasticSearch,
56-
OpenSearch $openSearch
63+
OpenSearch $openSearch,
64+
Reader $reader
5765
) {
5866
$this->magentoVersion = $magentoVersion;
5967
$this->resultFactory = $resultFactory;
6068
$this->elasticsearch = $elasticSearch;
6169
$this->openSearch = $openSearch;
70+
$this->reader = $reader;
6271
}
6372

6473
/**
@@ -77,8 +86,11 @@ public function validate(): Validator\ResultInterface
7786
return $this->resultFactory->errorByCode(Error::DEPLOY_MAGENTO_VERSION_DOES_NOT_SUPPORT_OS);
7887
}
7988

89+
$modules = $this->reader->read()['modules'] ?? [];
90+
$liveSearchEnabled = $modules['Magento_LiveSearchAdapter'] ?? false;
91+
8092
if ($this->magentoVersion->isGreaterOrEqual('2.4.3-p2')
81-
&& !$this->openSearch->isInstalled()
93+
&& !$this->openSearch->isInstalled() && !$liveSearchEnabled
8294
) {
8395
return $this->resultFactory->errorByCode(Error::DEPLOY_OS_SERVICE_NOT_INSTALLED);
8496
}

src/Test/Unit/Config/Validator/Deploy/ElasticsearchIntegrityTest.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\MagentoCloud\Test\Unit\Config\Validator\Deploy;
99

1010
use Magento\MagentoCloud\App\Error;
11+
use Magento\MagentoCloud\Config\Magento\Shared\Reader;
1112
use Magento\MagentoCloud\Config\Validator\Deploy\ElasticSearchIntegrity;
1213
use Magento\MagentoCloud\Config\Validator\ResultFactory;
1314
use Magento\MagentoCloud\Config\ValidatorException;
@@ -47,6 +48,11 @@ class ElasticsearchIntegrityTest extends TestCase
4748
*/
4849
private $openSearchMock;
4950

51+
/**
52+
* @var Reader|MockObject
53+
*/
54+
private $readerMock;
55+
5056
/**
5157
* @inheritDoc
5258
*/
@@ -56,12 +62,14 @@ protected function setUp(): void
5662
$this->resultFactoryMock = $this->createMock(ResultFactory::class);
5763
$this->elasticSearchMock = $this->createMock(ElasticSearch::class);
5864
$this->openSearchMock = $this->createMock(OpenSearch::class);
65+
$this->readerMock = $this->createMock(Reader::class);
5966

6067
$this->validator = new ElasticSearchIntegrity(
6168
$this->magentoVersionMock,
6269
$this->resultFactoryMock,
6370
$this->elasticSearchMock,
64-
$this->openSearchMock
71+
$this->openSearchMock,
72+
$this->readerMock
6573
);
6674
}
6775

@@ -208,4 +216,34 @@ public function testValidateNoElasticSearchWithOpenSearch240(): void
208216

209217
$this->validator->validate();
210218
}
219+
220+
/**
221+
* @throws ValidatorException
222+
*/
223+
public function testValidateNoElasticSearchAndNoOpenSearchWithLiveSearchEnabledMagentoGreater244(): void
224+
{
225+
$this->magentoVersionMock->expects($this->once())
226+
->method('satisfies')
227+
->with('>=2.4.3-p2')
228+
->willReturn(true);
229+
$this->magentoVersionMock->expects($this->once())
230+
->method('isGreaterOrEqual')
231+
->with('2.4.0')
232+
->willReturn(true);
233+
$this->openSearchMock->expects($this->once())
234+
->method('isInstalled')
235+
->willReturn(false);
236+
$this->elasticSearchMock->expects($this->once())
237+
->method('isInstalled')
238+
->willReturn(false);
239+
240+
$this->readerMock->expects($this->once())
241+
->method('read')
242+
->willReturn(['modules' => ['Magento_LiveSearchAdapter' => 1]]);
243+
244+
$this->resultFactoryMock->expects($this->once())
245+
->method('success');
246+
247+
$this->validator->validate();
248+
}
211249
}

src/Test/Unit/Http/TransferStatsHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testStatHandlerTransferTime()
9696
$stats = new TransferStats($mockRequest, null, 3.1415926);
9797

9898
$mockRequest->method('getUri')
99-
->wilLReturn('/');
99+
->wilLReturn($mockUriInterface);
100100
$this->loggerMock->expects($this->once())
101101
->method('debug')
102102
->with('cURL stats are missing from the request; using total transfer time');

src/Test/Unit/Service/ValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function testValidateNonexistentService()
110110
*
111111
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
112112
*/
113-
protected function validateVersionsDataProvider(): array
113+
public function validateVersionsDataProvider(): array
114114
{
115115
return [
116116
[

0 commit comments

Comments
 (0)