Skip to content

Commit

Permalink
Merge pull request #98 from magento-commerce/develop
Browse files Browse the repository at this point in the history
MCLOUD-9275: Cloud Tools Release
  • Loading branch information
BaDos authored Sep 9, 2022
2 parents 2a2cf2e + 78d05b7 commit 93df22b
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions src/Config/Database/DbConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
29 changes: 29 additions & 0 deletions src/Service/OpenSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*
Expand All @@ -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';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Generates command for magento installation
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
class InstallCommandFactory
{
Expand Down Expand Up @@ -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')
) {
Expand All @@ -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();
Expand All @@ -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'];
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/Test/Unit/Config/Database/DbConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public function getDataProvider()
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
'synchronous_replication' => true,
],
],
],
Expand All @@ -342,6 +343,7 @@ public function getDataProvider()
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
'synchronous_replication' => true,
],
],
],
Expand Down Expand Up @@ -495,6 +497,7 @@ public function getDataProvider()
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
'synchronous_replication' => true,
],
],
],
Expand Down Expand Up @@ -616,6 +619,7 @@ public function getDataProvider()
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
'synchronous_replication' => true,
],
],
],
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -779,6 +785,7 @@ public function getDataProvider()
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
'synchronous_replication' => true,
],
],
],
Expand Down Expand Up @@ -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',
Expand All @@ -986,6 +994,7 @@ public function getDataProvider()
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
'synchronous_replication' => true,
],
],
],
Expand Down
2 changes: 1 addition & 1 deletion src/Test/Unit/Service/ElasticSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
31 changes: 28 additions & 3 deletions src/Test/Unit/Service/OpenSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,11 @@ class OpenSearchTest extends TestCase
*/
private $clientFactoryMock;

/**
* @var MagentoVersion|MockObject
*/
private $magentoVersionMock;

/**
* @inheritdoc
*/
Expand All @@ -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
);
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'],
];
}

/**
Expand Down

0 comments on commit 93df22b

Please sign in to comment.