Skip to content

Commit 93df22b

Browse files
authored
Merge pull request #98 from magento-commerce/develop
MCLOUD-9275: Cloud Tools Release
2 parents 2a2cf2e + 78d05b7 commit 93df22b

File tree

8 files changed

+109
-17
lines changed

8 files changed

+109
-17
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento/ece-tools",
33
"description": "Provides tools to build and deploy Magento 2 Enterprise Edition",
44
"type": "magento2-component",
5-
"version": "2002.1.11",
5+
"version": "2002.1.12",
66
"license": "OSL-3.0",
77
"repositories": {
88
"repo.magento.com": {

src/Config/Database/DbConfig.php

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class DbConfig implements ConfigInterface
3535
const KEY_ENGINE = 'engine';
3636
const KEY_INIT_STATEMENTS = 'initStatements';
3737
const KEY_ACTIVE = 'active';
38+
const KEY_SYNCHRONOUS_REPLICATION = 'synchronous_replication';
3839

3940
/**
4041
* Names of connections
@@ -195,6 +196,7 @@ private function collectEnvConfig(array $customDbConfig): array
195196
}
196197
$mageConnectionConfig = $this->convertToMageFormat($slaveConnectionData, true);
197198
$config[self::KEY_SLAVE_CONNECTION][$mageConnectionName] = $mageConnectionConfig;
199+
$config[self::KEY_SLAVE_CONNECTION][$mageConnectionName][self::KEY_SYNCHRONOUS_REPLICATION] = true;
198200
}
199201
return $config;
200202
}

src/Service/OpenSearch.php

+29
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
namespace Magento\MagentoCloud\Service;
99

10+
use Magento\MagentoCloud\Config\Environment;
11+
use Magento\MagentoCloud\Http\ClientFactory;
1012
use Magento\MagentoCloud\Service\Search\AbstractService;
13+
use Magento\MagentoCloud\Package\MagentoVersion;
14+
use Psr\Log\LoggerInterface;
1115

1216
/**
1317
* Returns OpenSearch service configurations.
@@ -18,6 +22,27 @@ class OpenSearch extends AbstractService implements ServiceInterface
1822
protected const ENGINE_SHORT_NAME = 'OS';
1923
public const ENGINE_NAME = 'opensearch';
2024

25+
/**
26+
* @var MagentoVersion
27+
*/
28+
private $magentoVersion;
29+
30+
/**
31+
* @param Environment $environment
32+
* @param ClientFactory $clientFactory
33+
* @param LoggerInterface $logger
34+
* @param MagentoVersion $magentoVersion
35+
*/
36+
public function __construct(
37+
Environment $environment,
38+
ClientFactory $clientFactory,
39+
LoggerInterface $logger,
40+
MagentoVersion $magentoVersion
41+
) {
42+
$this->magentoVersion = $magentoVersion;
43+
parent::__construct($environment, $clientFactory, $logger);
44+
}
45+
2146
/**
2247
* Return full engine name.
2348
*
@@ -26,6 +51,10 @@ class OpenSearch extends AbstractService implements ServiceInterface
2651
*/
2752
public function getFullEngineName(): string
2853
{
54+
if ($this->magentoVersion->isGreaterOrEqual('2.4.6')) {
55+
return static::ENGINE_NAME;
56+
}
57+
2958
return 'elasticsearch7';
3059
}
3160
}

src/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactory.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* Generates command for magento installation
3030
*
3131
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
32+
* @SuppressWarnings(PHPMD.NPathComplexity)
3233
*/
3334
class InstallCommandFactory
3435
{
@@ -256,6 +257,8 @@ private function getEsOptions(): array
256257
);
257258
}
258259

260+
$enginePrefixName = 'elasticsearch';
261+
259262
if ($this->openSearch->isInstalled()
260263
&& $this->magentoVersion->satisfies('>=2.3.7-p3 <2.4.0 || >=2.4.3-p2')
261264
) {
@@ -264,6 +267,10 @@ private function getEsOptions(): array
264267
$port = $this->openSearch->getPort();
265268
$configuration = $this->openSearch->getConfiguration();
266269
$isAuthEnabled = $this->openSearch->isAuthEnabled();
270+
271+
if ($this->magentoVersion->isGreaterOrEqual('2.4.6')) {
272+
$enginePrefixName = 'opensearch';
273+
}
267274
} else {
268275
$engine = $this->elasticSearch->getFullEngineName();
269276
$host = $this->elasticSearch->getHost();
@@ -273,17 +280,17 @@ private function getEsOptions(): array
273280
}
274281

275282
$options['--search-engine'] = $engine;
276-
$options['--elasticsearch-host'] = $host;
277-
$options['--elasticsearch-port'] = $port;
283+
$options['--' . $enginePrefixName . '-host'] = $host;
284+
$options['--' . $enginePrefixName . '-port'] = $port;
278285

279286
if ($isAuthEnabled) {
280-
$options['--elasticsearch-enable-auth'] = '1';
281-
$options['--elasticsearch-username'] = $configuration['username'];
282-
$options['--elasticsearch-password'] = $configuration['password'];
287+
$options['--' . $enginePrefixName . '-enable-auth'] = '1';
288+
$options['--' . $enginePrefixName . '-username'] = $configuration['username'];
289+
$options['--' . $enginePrefixName . '-password'] = $configuration['password'];
283290
}
284291

285292
if (isset($configuration['query']['index'])) {
286-
$options['--elasticsearch-index-prefix'] = $configuration['query']['index'];
293+
$options['--' . $enginePrefixName . '-index-prefix'] = $configuration['query']['index'];
287294
}
288295
}
289296

src/Test/Unit/Config/Database/DbConfigTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ public function getDataProvider()
317317
'engine' => 'innodb',
318318
'initStatements' => 'SET NAMES utf8;',
319319
'active' => '1',
320+
'synchronous_replication' => true,
320321
],
321322
],
322323
],
@@ -342,6 +343,7 @@ public function getDataProvider()
342343
'engine' => 'innodb',
343344
'initStatements' => 'SET NAMES utf8;',
344345
'active' => '1',
346+
'synchronous_replication' => true,
345347
],
346348
],
347349
],
@@ -495,6 +497,7 @@ public function getDataProvider()
495497
'engine' => 'innodb',
496498
'initStatements' => 'SET NAMES utf8;',
497499
'active' => '1',
500+
'synchronous_replication' => true,
498501
],
499502
],
500503
],
@@ -616,6 +619,7 @@ public function getDataProvider()
616619
'engine' => 'innodb',
617620
'initStatements' => 'SET NAMES utf8;',
618621
'active' => '1',
622+
'synchronous_replication' => true,
619623
],
620624
],
621625
],
@@ -759,6 +763,7 @@ public function getDataProvider()
759763
'engine' => 'innodb',
760764
'initStatements' => 'SET NAMES utf8;',
761765
'active' => '1',
766+
'synchronous_replication' => true,
762767
],
763768
'checkout' => [
764769
'host' => 'some_host_quote_slave:3310',
@@ -769,6 +774,7 @@ public function getDataProvider()
769774
'engine' => 'innodb',
770775
'initStatements' => 'SET NAMES utf8;',
771776
'active' => '1',
777+
'synchronous_replication' => true,
772778
],
773779
'sales' => [
774780
'host' => 'some_host_sales_slave:3311',
@@ -779,6 +785,7 @@ public function getDataProvider()
779785
'engine' => 'innodb',
780786
'initStatements' => 'SET NAMES utf8;',
781787
'active' => '1',
788+
'synchronous_replication' => true,
782789
],
783790
],
784791
],
@@ -977,6 +984,7 @@ public function getDataProvider()
977984
'engine' => 'innodb',
978985
'initStatements' => 'SET NAMES utf8;',
979986
'active' => '1',
987+
'synchronous_replication' => true,
980988
],
981989
'sales' => ['host' => 'some_host_sales_slave:3311',
982990
'username' => 'some_username_sales_slave',
@@ -986,6 +994,7 @@ public function getDataProvider()
986994
'engine' => 'innodb',
987995
'initStatements' => 'SET NAMES utf8;',
988996
'active' => '1',
997+
'synchronous_replication' => true,
989998
],
990999
],
9911000
],

src/Test/Unit/Service/ElasticSearchTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function getVersionFromTypeDataProvider()
208208
*
209209
* @dataProvider getFullVersionDataProvider
210210
*/
211-
public function testGetFullVersion(string $version, string $expected): void
211+
public function testGetFullEngineName(string $version, string $expected): void
212212
{
213213
$clientMock = $this->createPartialMock(Client::class, ['get']);
214214
$responseMock = $this->createMock(Response::class);

src/Test/Unit/Service/OpenSearchTest.php

+28-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\MagentoCloud\Http\ClientFactory;
1515
use Magento\MagentoCloud\Service\OpenSearch;
1616
use Magento\MagentoCloud\Service\ServiceException;
17+
use Magento\MagentoCloud\Package\MagentoVersion;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
1920
use Psr\Http\Message\StreamInterface;
@@ -44,6 +45,11 @@ class OpenSearchTest extends TestCase
4445
*/
4546
private $clientFactoryMock;
4647

48+
/**
49+
* @var MagentoVersion|MockObject
50+
*/
51+
private $magentoVersionMock;
52+
4753
/**
4854
* @inheritdoc
4955
*/
@@ -52,11 +58,13 @@ public function setUp(): void
5258
$this->environmentMock = $this->createMock(Environment::class);
5359
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
5460
$this->clientFactoryMock = $this->createMock(ClientFactory::class);
61+
$this->magentoVersionMock = $this->createMock(MagentoVersion::class);
5562

5663
$this->openSearch = new OpenSearch(
5764
$this->environmentMock,
5865
$this->clientFactoryMock,
59-
$this->loggerMock
66+
$this->loggerMock,
67+
$this->magentoVersionMock
6068
);
6169
}
6270

@@ -202,11 +210,28 @@ public function getVersionFromTypeDataProvider()
202210
}
203211

204212
/**
213+
* @param bool $greaterOrEqual
214+
* @param string $expectedResult
205215
* @throws ServiceException
216+
* @dataProvider getFullEngineNameDataProvider
206217
*/
207-
public function testGetFullVersion(): void
218+
public function testGetFullEngineName(bool $greaterOrEqual, string $expectedResult): void
208219
{
209-
$this->assertSame('elasticsearch7', $this->openSearch->getFullEngineName());
220+
$this->magentoVersionMock->expects($this->once())
221+
->method('isGreaterOrEqual')
222+
->willReturn($greaterOrEqual);
223+
$this->assertSame($expectedResult, $this->openSearch->getFullEngineName());
224+
}
225+
226+
/**
227+
* @return array
228+
*/
229+
public function getFullEngineNameDataProvider()
230+
{
231+
return [
232+
[false, 'elasticsearch7'],
233+
[true, 'opensearch'],
234+
];
210235
}
211236

212237
public function testGetVersionWithException(): void

src/Test/Unit/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactoryTest.php

+26-6
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,23 @@ public function testExecuteWithESauthOptions(): void
486486
self::assertStringContainsString("--elasticsearch-index-prefix='test'", $command);
487487
}
488488

489-
public function testExecuteWithOSauthOptions(): void
490-
{
489+
/**
490+
* @param bool $greaterOrEqual
491+
* @param string $enginePrefixName
492+
* @throws ConfigException
493+
* @dataProvider executeWithOSauthOptionsDataProvider
494+
*/
495+
public function testExecuteWithOSauthOptions(
496+
bool $greaterOrEqual,
497+
string $enginePrefixName
498+
): void {
491499
$this->mockBaseConfig('', '', '', '', '', '');
492500
$this->magentoVersionMock->method('isGreaterOrEqual')
493501
->willReturnMap([
494502
['2.4.0', true],
495503
['2.4.2', true],
496504
['2.4.4', true],
505+
['2.4.6', $greaterOrEqual],
497506
]);
498507
$this->magentoVersionMock->expects($this->once())
499508
->method('satisfies')
@@ -542,10 +551,21 @@ public function testExecuteWithOSauthOptions(): void
542551

543552
$command = $this->installCommandFactory->create();
544553
self::assertStringContainsString("--search-engine='opensearch1'", $command);
545-
self::assertStringContainsString("--elasticsearch-enable-auth='1'", $command);
546-
self::assertStringContainsString("--elasticsearch-username='user'", $command);
547-
self::assertStringContainsString("--elasticsearch-password='secret'", $command);
548-
self::assertStringContainsString("--elasticsearch-index-prefix='test'", $command);
554+
self::assertStringContainsString("--" . $enginePrefixName . "-enable-auth='1'", $command);
555+
self::assertStringContainsString("--" . $enginePrefixName . "-username='user'", $command);
556+
self::assertStringContainsString("--" . $enginePrefixName . "-password='secret'", $command);
557+
self::assertStringContainsString("--" . $enginePrefixName . "-index-prefix='test'", $command);
558+
}
559+
560+
/**
561+
* @return array
562+
*/
563+
public function executeWithOSauthOptionsDataProvider()
564+
{
565+
return [
566+
[false, 'elasticsearch'],
567+
[true, 'opensearch'],
568+
];
549569
}
550570

551571
/**

0 commit comments

Comments
 (0)