diff --git a/composer.json b/composer.json index f91b784606..7de06cbd9f 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "magento/ece-tools", "description": "Provides tools to build and deploy Magento 2 Enterprise Edition", "type": "magento2-component", - "version": "2002.1.11", + "version": "2002.1.12", "license": "OSL-3.0", "repositories": { "repo.magento.com": { diff --git a/src/Config/Database/DbConfig.php b/src/Config/Database/DbConfig.php index 0195cbd378..9dd2be19ce 100644 --- a/src/Config/Database/DbConfig.php +++ b/src/Config/Database/DbConfig.php @@ -35,6 +35,7 @@ class DbConfig implements ConfigInterface const KEY_ENGINE = 'engine'; const KEY_INIT_STATEMENTS = 'initStatements'; const KEY_ACTIVE = 'active'; + const KEY_SYNCHRONOUS_REPLICATION = 'synchronous_replication'; /** * Names of connections @@ -195,6 +196,7 @@ private function collectEnvConfig(array $customDbConfig): array } $mageConnectionConfig = $this->convertToMageFormat($slaveConnectionData, true); $config[self::KEY_SLAVE_CONNECTION][$mageConnectionName] = $mageConnectionConfig; + $config[self::KEY_SLAVE_CONNECTION][$mageConnectionName][self::KEY_SYNCHRONOUS_REPLICATION] = true; } return $config; } diff --git a/src/Service/OpenSearch.php b/src/Service/OpenSearch.php index f09dc11905..1da26c746a 100644 --- a/src/Service/OpenSearch.php +++ b/src/Service/OpenSearch.php @@ -7,7 +7,11 @@ namespace Magento\MagentoCloud\Service; +use Magento\MagentoCloud\Config\Environment; +use Magento\MagentoCloud\Http\ClientFactory; use Magento\MagentoCloud\Service\Search\AbstractService; +use Magento\MagentoCloud\Package\MagentoVersion; +use Psr\Log\LoggerInterface; /** * Returns OpenSearch service configurations. @@ -18,6 +22,27 @@ class OpenSearch extends AbstractService implements ServiceInterface protected const ENGINE_SHORT_NAME = 'OS'; public const ENGINE_NAME = 'opensearch'; + /** + * @var MagentoVersion + */ + private $magentoVersion; + + /** + * @param Environment $environment + * @param ClientFactory $clientFactory + * @param LoggerInterface $logger + * @param MagentoVersion $magentoVersion + */ + public function __construct( + Environment $environment, + ClientFactory $clientFactory, + LoggerInterface $logger, + MagentoVersion $magentoVersion + ) { + $this->magentoVersion = $magentoVersion; + parent::__construct($environment, $clientFactory, $logger); + } + /** * Return full engine name. * @@ -26,6 +51,10 @@ class OpenSearch extends AbstractService implements ServiceInterface */ public function getFullEngineName(): string { + if ($this->magentoVersion->isGreaterOrEqual('2.4.6')) { + return static::ENGINE_NAME; + } + return 'elasticsearch7'; } } diff --git a/src/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactory.php b/src/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactory.php index 2f35f6f7ca..df0e60fba6 100644 --- a/src/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactory.php +++ b/src/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactory.php @@ -29,6 +29,7 @@ * Generates command for magento installation * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.NPathComplexity) */ class InstallCommandFactory { @@ -256,6 +257,8 @@ private function getEsOptions(): array ); } + $enginePrefixName = 'elasticsearch'; + if ($this->openSearch->isInstalled() && $this->magentoVersion->satisfies('>=2.3.7-p3 <2.4.0 || >=2.4.3-p2') ) { @@ -264,6 +267,10 @@ private function getEsOptions(): array $port = $this->openSearch->getPort(); $configuration = $this->openSearch->getConfiguration(); $isAuthEnabled = $this->openSearch->isAuthEnabled(); + + if ($this->magentoVersion->isGreaterOrEqual('2.4.6')) { + $enginePrefixName = 'opensearch'; + } } else { $engine = $this->elasticSearch->getFullEngineName(); $host = $this->elasticSearch->getHost(); @@ -273,17 +280,17 @@ private function getEsOptions(): array } $options['--search-engine'] = $engine; - $options['--elasticsearch-host'] = $host; - $options['--elasticsearch-port'] = $port; + $options['--' . $enginePrefixName . '-host'] = $host; + $options['--' . $enginePrefixName . '-port'] = $port; if ($isAuthEnabled) { - $options['--elasticsearch-enable-auth'] = '1'; - $options['--elasticsearch-username'] = $configuration['username']; - $options['--elasticsearch-password'] = $configuration['password']; + $options['--' . $enginePrefixName . '-enable-auth'] = '1'; + $options['--' . $enginePrefixName . '-username'] = $configuration['username']; + $options['--' . $enginePrefixName . '-password'] = $configuration['password']; } if (isset($configuration['query']['index'])) { - $options['--elasticsearch-index-prefix'] = $configuration['query']['index']; + $options['--' . $enginePrefixName . '-index-prefix'] = $configuration['query']['index']; } } diff --git a/src/Test/Unit/Config/Database/DbConfigTest.php b/src/Test/Unit/Config/Database/DbConfigTest.php index bfd778737c..50948bd8d7 100644 --- a/src/Test/Unit/Config/Database/DbConfigTest.php +++ b/src/Test/Unit/Config/Database/DbConfigTest.php @@ -317,6 +317,7 @@ public function getDataProvider() 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', + 'synchronous_replication' => true, ], ], ], @@ -342,6 +343,7 @@ public function getDataProvider() 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', + 'synchronous_replication' => true, ], ], ], @@ -495,6 +497,7 @@ public function getDataProvider() 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', + 'synchronous_replication' => true, ], ], ], @@ -616,6 +619,7 @@ public function getDataProvider() 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', + 'synchronous_replication' => true, ], ], ], @@ -759,6 +763,7 @@ public function getDataProvider() 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', + 'synchronous_replication' => true, ], 'checkout' => [ 'host' => 'some_host_quote_slave:3310', @@ -769,6 +774,7 @@ public function getDataProvider() 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', + 'synchronous_replication' => true, ], 'sales' => [ 'host' => 'some_host_sales_slave:3311', @@ -779,6 +785,7 @@ public function getDataProvider() 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', + 'synchronous_replication' => true, ], ], ], @@ -977,6 +984,7 @@ public function getDataProvider() 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', + 'synchronous_replication' => true, ], 'sales' => ['host' => 'some_host_sales_slave:3311', 'username' => 'some_username_sales_slave', @@ -986,6 +994,7 @@ public function getDataProvider() 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1', + 'synchronous_replication' => true, ], ], ], diff --git a/src/Test/Unit/Service/ElasticSearchTest.php b/src/Test/Unit/Service/ElasticSearchTest.php index c965237190..336089fa03 100644 --- a/src/Test/Unit/Service/ElasticSearchTest.php +++ b/src/Test/Unit/Service/ElasticSearchTest.php @@ -208,7 +208,7 @@ public function getVersionFromTypeDataProvider() * * @dataProvider getFullVersionDataProvider */ - public function testGetFullVersion(string $version, string $expected): void + public function testGetFullEngineName(string $version, string $expected): void { $clientMock = $this->createPartialMock(Client::class, ['get']); $responseMock = $this->createMock(Response::class); diff --git a/src/Test/Unit/Service/OpenSearchTest.php b/src/Test/Unit/Service/OpenSearchTest.php index 7208f02eec..0ebf6b1055 100644 --- a/src/Test/Unit/Service/OpenSearchTest.php +++ b/src/Test/Unit/Service/OpenSearchTest.php @@ -14,6 +14,7 @@ use Magento\MagentoCloud\Http\ClientFactory; use Magento\MagentoCloud\Service\OpenSearch; use Magento\MagentoCloud\Service\ServiceException; +use Magento\MagentoCloud\Package\MagentoVersion; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Http\Message\StreamInterface; @@ -44,6 +45,11 @@ class OpenSearchTest extends TestCase */ private $clientFactoryMock; + /** + * @var MagentoVersion|MockObject + */ + private $magentoVersionMock; + /** * @inheritdoc */ @@ -52,11 +58,13 @@ public function setUp(): void $this->environmentMock = $this->createMock(Environment::class); $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class); $this->clientFactoryMock = $this->createMock(ClientFactory::class); + $this->magentoVersionMock = $this->createMock(MagentoVersion::class); $this->openSearch = new OpenSearch( $this->environmentMock, $this->clientFactoryMock, - $this->loggerMock + $this->loggerMock, + $this->magentoVersionMock ); } @@ -202,11 +210,28 @@ public function getVersionFromTypeDataProvider() } /** + * @param bool $greaterOrEqual + * @param string $expectedResult * @throws ServiceException + * @dataProvider getFullEngineNameDataProvider */ - public function testGetFullVersion(): void + public function testGetFullEngineName(bool $greaterOrEqual, string $expectedResult): void { - $this->assertSame('elasticsearch7', $this->openSearch->getFullEngineName()); + $this->magentoVersionMock->expects($this->once()) + ->method('isGreaterOrEqual') + ->willReturn($greaterOrEqual); + $this->assertSame($expectedResult, $this->openSearch->getFullEngineName()); + } + + /** + * @return array + */ + public function getFullEngineNameDataProvider() + { + return [ + [false, 'elasticsearch7'], + [true, 'opensearch'], + ]; } public function testGetVersionWithException(): void diff --git a/src/Test/Unit/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactoryTest.php b/src/Test/Unit/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactoryTest.php index b1c4cf9d3e..989468b91c 100644 --- a/src/Test/Unit/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactoryTest.php +++ b/src/Test/Unit/Step/Deploy/InstallUpdate/Install/Setup/InstallCommandFactoryTest.php @@ -486,14 +486,23 @@ public function testExecuteWithESauthOptions(): void self::assertStringContainsString("--elasticsearch-index-prefix='test'", $command); } - public function testExecuteWithOSauthOptions(): void - { + /** + * @param bool $greaterOrEqual + * @param string $enginePrefixName + * @throws ConfigException + * @dataProvider executeWithOSauthOptionsDataProvider + */ + public function testExecuteWithOSauthOptions( + bool $greaterOrEqual, + string $enginePrefixName + ): void { $this->mockBaseConfig('', '', '', '', '', ''); $this->magentoVersionMock->method('isGreaterOrEqual') ->willReturnMap([ ['2.4.0', true], ['2.4.2', true], ['2.4.4', true], + ['2.4.6', $greaterOrEqual], ]); $this->magentoVersionMock->expects($this->once()) ->method('satisfies') @@ -542,10 +551,21 @@ public function testExecuteWithOSauthOptions(): void $command = $this->installCommandFactory->create(); self::assertStringContainsString("--search-engine='opensearch1'", $command); - self::assertStringContainsString("--elasticsearch-enable-auth='1'", $command); - self::assertStringContainsString("--elasticsearch-username='user'", $command); - self::assertStringContainsString("--elasticsearch-password='secret'", $command); - self::assertStringContainsString("--elasticsearch-index-prefix='test'", $command); + self::assertStringContainsString("--" . $enginePrefixName . "-enable-auth='1'", $command); + self::assertStringContainsString("--" . $enginePrefixName . "-username='user'", $command); + self::assertStringContainsString("--" . $enginePrefixName . "-password='secret'", $command); + self::assertStringContainsString("--" . $enginePrefixName . "-index-prefix='test'", $command); + } + + /** + * @return array + */ + public function executeWithOSauthOptionsDataProvider() + { + return [ + [false, 'elasticsearch'], + [true, 'opensearch'], + ]; } /**