Skip to content

Commit

Permalink
chore(upgrade): Prepare major version 2 by removing all the dead code (
Browse files Browse the repository at this point in the history
…#196)

Following the merge of Elastica 8, we drop OpenSearch.

Also it's time to remove the deprecated features.
  • Loading branch information
damienalexandre authored Nov 13, 2024
1 parent cbe1ea8 commit 1bbd506
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 253 deletions.
79 changes: 5 additions & 74 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,27 @@ jobs:
- php-version: "8.0"
symfony-version: "5.4.*"
composer-flags: "--prefer-lowest"
es-version: "7.17.3"
es-version: "7.17.25"
# Every lowest supported version && Symfony 6
- php-version: "8.1"
symfony-version: "6.2.*"
composer-flags: ""
es-version: "7.17.3"
es-version: "7.17.25"
# PHP 8.1, latest SF 6, ES 7
- php-version: "8.1"
symfony-version: "6.*"
composer-flags: ""
es-version: "7.17.3"
es-version: "7.17.25"
# PHP 8.2, latest SF 6, ES 8
- php-version: "8.2"
symfony-version: "6.*"
composer-flags: ""
es-version: "8.2.0"
es-version: "8.16.0"
# PHP 8.3, latest SF 7, ES 8
- php-version: "8.3"
symfony-version: "7.*"
composer-flags: ""
es-version: "8.2.0"
es-version: "8.16.0"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -115,72 +115,3 @@ jobs:
- name: Run Tests
run: make test

tests_opensearch:
name: Test PHP ${{ matrix.php-version }} & Symfony ${{ matrix.symfony-version }} ${{ matrix.composer-flags }} & OpenSearch ${{ matrix.os-version }}
runs-on: ubuntu-latest
env:
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}
strategy:
fail-fast: false
matrix:
include:
- php-version: "8.3"
symfony-version: "6.*"
composer-flags: ""
os-version: 1.3.6
os-image: opensearchproject/opensearch:1.3.6
- php-version: "8.3"
symfony-version: "6.*"
composer-flags: ""
os-version: 2.3.0
os-image: opensearchproject/opensearch:2.3.0
- php-version: "8.3"
symfony-version: "7.*"
composer-flags: ""
os-version: 2.3.0
os-image: opensearchproject/opensearch:2.3.0
services:
search-server:
image: ${{ matrix.os-image }}
ports:
- 9999:9999
env:
discovery.type: single-node
plugins.security.disabled: true
http.port: 9999
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

# We need Flex to enfore Symfony version with `SYMFONY_REQUIRE` env var
- name: Install Symfony Flex
run: composer global require --no-progress --no-scripts --no-plugins symfony/flex

- name: Enable Symfony Flex
run: composer global config --no-plugins allow-plugins.symfony/flex true

- name: Install Composer dependencies
run: composer update --prefer-dist --no-interaction --no-ansi ${{ matrix.composer-flags }}

- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144
- name: Wait for OpenSearch to be ready
run: |
while ! curl -s -X GET http://127.0.0.1:9999/_cluster/health\?wait_for_status\=green\&timeout\=60s | grep -q '"status":"green"'
do
echo "==> Waiting for cluster green status" && sleep 1
done
- name: Run Tests
run: make test
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## 2.0.0

Massive release with added support for Elastica 8 and all deprecated code removed.

### Added

- Updated `ruflin/elastica` to v8 (Breaking Change)
- Upgraded `ruflin/elastica` to v8 (Breaking Change)

### Removed

- Dropped OpenSearch support (Breaking Change)
- Dropped `HttpClientTransport` (Breaking Change)
- All depreacted code from 1.x, see [UPGRADE.md](UPGRADE.md) for the full list

## 1.9.1

Expand Down
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
test: ## Run test suite
./vendor/bin/simple-phpunit

start: ## Start testing tools (Elasticsearch)
docker run --rm -d --name "elastically_es" -p 9999:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e "action.destructive_requires_name=false" -it -m 1GB docker.elastic.co/elasticsearch/elasticsearch:8.14.2
start_7: ## Start testing tools (Elasticsearch 7)
docker run --rm -d --name "elastically_es" -p 9999:9200 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.17.25

start_opensearch: ## Start testing tools (OpenSearch)
docker run --rm -d --name "elastically_es" -p 9999:9200 -e "discovery.type=single-node" -e "plugins.security.disabled=true" opensearchproject/opensearch:2.3.0
start: ## Start testing tools (Elasticsearch 8)
docker run --rm -d --name "elastically_es" -p 9999:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e "action.destructive_requires_name=false" -it -m 1GB docker.elastic.co/elasticsearch/elasticsearch:8.16.0

#start_opensearch: ## Start testing tools (OpenSearch)
# docker run --rm -d --name "elastically_es" -p 9999:9200 -e "discovery.type=single-node" -e "DISABLE_SECURITY_PLUGIN=true" opensearchproject/opensearch:2

stop: ## Stop testing tools
docker stop "elastically_es"

kibana: ## Start debug tools (Kibana)
docker run -e "ELASTICSEARCH_HOSTS=http://127.0.0.1:9999/" --network host docker.elastic.co/kibana/kibana-oss:7.8.0
docker run -e "ELASTICSEARCH_HOSTS=http://127.0.0.1:9999/" --network host docker.elastic.co/kibana/kibana:7.17.25

cs: ## Fix PHP CS
./vendor/bin/php-cs-fixer fix --verbose
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Elastically, **Elastica** based framework

Opinionated [Elastica](https://github.com/ruflin/Elastica) based framework to bootstrap PHP and Elasticsearch / OpenSearch implementations.
Opinionated [Elastica](https://github.com/ruflin/Elastica) based framework to bootstrap PHP and Elasticsearch implementations.

Main features:

Expand All @@ -17,11 +17,11 @@ Main features:
- Symfony Messenger Handler support (with or without spool);

> [!IMPORTANT]
> Require PHP 8.0+ and Elasticsearch 7+.
> Require PHP 8.0+ and Elasticsearch 8+.
Works with **Elasticsearch 8+** but is not officially supported by Elastica yet. Use with caution.
Works with **Elasticsearch 7** as well but is not officially supported by Elastica 8. Use with caution.

Works with **OpenSearch 1 and 2**.
Version 2+ does not work with **OpenSearch** anymore due to restrictions added by Elastic on their client.

You can check the [changelog](CHANGELOG.md) and the [upgrade](UPGRADE.md) documents.

Expand Down Expand Up @@ -252,7 +252,6 @@ elastically:
default:
client:
host: '%env(ELASTICSEARCH_HOST)%'
# If you want to use the Symfony HttpClient (you MUST create this service)
# Path to the mapping directory (in YAML)
mapping_directory: '%kernel.project_dir%/config/elasticsearch'
Expand Down Expand Up @@ -339,10 +338,12 @@ JoliCode\Elastically\Client:
arguments:
$config:
host: '%env(ELASTICSEARCH_HOST)%'
transport: 'JoliCode\Elastically\Transport\HttpClientTransport'
# ...
transport_client:
client: '@my_custom_psr18_client' # An instance of Symfony\Component\HttpClient\Psr18Client (Or any PSR 18 compliant one)
```

See the [official documentation on how to get a PSR-18 client](https://symfony.com/doc/current/http_client.html#psr-18-and-psr-17).

#### Reference

You can run the following command to get the default configuration reference:
Expand Down
26 changes: 25 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## From v1.9.0 to v2.0.0

HttpClientTransport has been removed:
HttpClientTransport has been removed, you must replace it with [a PSR-18 client](https://symfony.com/doc/current/http_client.html#psr-18-and-psr-17):

```diff
JoliCode\Elastically\Client:
arguments:
Expand All @@ -14,6 +15,29 @@ HttpClientTransport has been removed:
+ client: '@my_custom_psr18_client' # An instance of Symfony\Component\HttpClient\Psr18Client (Or any PSR 18 compliant one)
```

Code has been cleaned of deprecations:

- Removed `\JoliCode\Elastically\Index::getBuilder` method, use `\JoliCode\Elastically\Factory::buildIndexBuilder` if needed
- Removed all const in `\JoliCode\Elastically\Client`, use the one in `\JoliCode\Elastically\Factory` instead:
- `\JoliCode\Elastically\Client::CONFIG_MAPPINGS_DIRECTORY` => `\JoliCode\Elastically\Factory::CONFIG_MAPPINGS_DIRECTORY`
- `\JoliCode\Elastically\Client::CONFIG_SERIALIZER_CONTEXT_PER_CLASS` => `\JoliCode\Elastically\Factory::CONFIG_SERIALIZER_CONTEXT_PER_CLASS`
- `\JoliCode\Elastically\Client::CONFIG_SERIALIZER` => `\JoliCode\Elastically\Factory::CONFIG_SERIALIZER`
- `\JoliCode\Elastically\Client::CONFIG_BULK_SIZE` => `\JoliCode\Elastically\Factory::CONFIG_BULK_SIZE`
- `\JoliCode\Elastically\Client::CONFIG_INDEX_PREFIX` => `\JoliCode\Elastically\Factory::CONFIG_INDEX_PREFIX`
- `\JoliCode\Elastically\Client::CONFIG_INDEX_CLASS_MAPPING` => `\JoliCode\Elastically\Factory::CONFIG_INDEX_CLASS_MAPPING`
- `\JoliCode\Elastically\Client::__construct` now requires ResultSetBuilder and IndexNameMapper, use dependency injection
- Removed `\JoliCode\Elastically\Client::getPrefixedIndex`, use `\JoliCode\Elastically\IndexNameMapper::getPrefixedIndex`
- Removed `\JoliCode\Elastically\Client::getIndexNameFromClass`, use `\JoliCode\Elastically\IndexNameMapper::getIndexNameFromClass`
- Removed `\JoliCode\Elastically\Client::getClassFromIndexName`, use `\JoliCode\Elastically\IndexNameMapper::getClassFromIndexName`
- Removed `\JoliCode\Elastically\Client::getPureIndexName`, use `\JoliCode\Elastically\IndexNameMapper::getPureIndexName`
- Removed `\JoliCode\Elastically\Client::getIndexBuilder`, use the Factory (`\JoliCode\Elastically\Factory`) or DIC
- Removed `\JoliCode\Elastically\Client::getIndexer`, use the Factory (`\JoliCode\Elastically\Factory`) or DIC
- Removed `\JoliCode\Elastically\Client::getBuilder`, use the Factory (`\JoliCode\Elastically\Factory`) or DIC
- Removed `\JoliCode\Elastically\Client::getSerializer`, use the Factory (`\JoliCode\Elastically\Factory`) or DIC
- Removed `\JoliCode\Elastically\Client::getDenormalizer`, use the Factory (`\JoliCode\Elastically\Factory`) or DIC
- Removed `\JoliCode\Elastically\Client::getSerializerContext`, use the Factory (`\JoliCode\Elastically\Factory`) or DIC
- Using `\Elastica\Document::setData` to store your DTO will not work anymore, you must use `\JoliCode\Elastically\Model\Document` instead
-
## From v1.3.0 to v1.4.0

If you're using Symfony, here are the changes to apply:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"symfony/deprecation-contracts": "^2.4 || ^3.0",
"symfony/property-access": "^5.4 || ^6.0 || ^7.0",
"symfony/property-info": "^5.4 || ^6.0 || ^7.0",
"symfony/psr-http-message-bridge": "^7.1",
"symfony/psr-http-message-bridge": "^2.3 || ^6.0 || ^7.0",
"symfony/serializer": "^5.4 || ^6.0 || ^7.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0"
},
Expand All @@ -32,7 +32,7 @@
"jane-php/json-schema": "^7.4",
"jane-php/json-schema-runtime": "^7.4",
"phpstan/phpstan": "^1.9",
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/browser-kit": "^5.4 || ^6.0 || ^7.0",
"symfony/framework-bundle": "^5.4.17 || ^6.0 || ^7.0",
"symfony/http-client": "^5.4 || ^6.0 || ^7.0",
"symfony/http-foundation": "^5.4 || ^6.0 || ^7.0",
Expand Down
109 changes: 9 additions & 100 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,30 @@
namespace JoliCode\Elastically;

use Elastica\Client as ElasticaClient;
use Elastica\Exception\ExceptionInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface;

class Client extends ElasticaClient
{
// Elastically config keys // BC Layer, to remove in 2.0
public const CONFIG_MAPPINGS_DIRECTORY = Factory::CONFIG_MAPPINGS_DIRECTORY;
public const CONFIG_SERIALIZER_CONTEXT_PER_CLASS = Factory::CONFIG_SERIALIZER_CONTEXT_PER_CLASS;
public const CONFIG_SERIALIZER = Factory::CONFIG_SERIALIZER;
public const CONFIG_BULK_SIZE = Factory::CONFIG_BULK_SIZE;
public const CONFIG_INDEX_PREFIX = Factory::CONFIG_INDEX_PREFIX;
public const CONFIG_INDEX_CLASS_MAPPING = Factory::CONFIG_INDEX_CLASS_MAPPING;

private Factory $factory;
private ResultSetBuilder $resultSetBuilder;
private IndexNameMapper $indexNameMapper;

/**
* @see \JoliCode\Elastically\Factory::buildClient
*/
public function __construct($config = [], ?LoggerInterface $logger = null, ?ResultSetBuilder $resultSetBuilder = null, ?IndexNameMapper $indexNameMapper = null)
{
parent::__construct($config, $logger);

// BC Layer, to remove in 2.0
$this->factory = new Factory($config);
$this->factory->setClient($this);
if (!$resultSetBuilder) {
trigger_deprecation('jolicode/elastically', '1.4.0', 'Passing null as #4 argument of %s() is deprecated. Inject a %s instance instead.', __METHOD__, ResultSetBuilder::class);
}
$this->resultSetBuilder = $resultSetBuilder ?? $this->factory->buildBuilder();
if (!$indexNameMapper) {
trigger_deprecation('jolicode/elastically', '1.4.0', 'Passing null as #5 argument of %s() is deprecated. Inject a %s instance instead.', __METHOD__, IndexNameMapper::class);
if (!$resultSetBuilder || !$indexNameMapper) {
throw new \InvalidArgumentException('Missing argument "resultSetBuilder" and "indexNameMapper", use `\JoliCode\Elastically\Factory::buildClient` to create this Client.');
}
$this->indexNameMapper = $indexNameMapper ?? $this->factory->buildIndexNameMapper();
// End of BC Layer

$this->resultSetBuilder = $resultSetBuilder;
$this->indexNameMapper = $indexNameMapper;
}

/**
* Return an elastically index.
* Return an Elastically index.
*
* @return Index
*/
Expand All @@ -60,80 +45,4 @@ public function getIndex(string $name): \Elastica\Index

return new Index($this, $name, $this->resultSetBuilder);
}

public function getPrefixedIndex(string $name): string
{
trigger_deprecation('jolicode/elastically', '1.4.0', 'Method %s() is deprecated. Use %s::%s() instead.', __METHOD__, IndexNameMapper::class, __FUNCTION__);

return $this->indexNameMapper->getPrefixedIndex($name);
}

/**
* @throws ExceptionInterface
*/
public function getIndexNameFromClass(string $className): string
{
trigger_deprecation('jolicode/elastically', '1.4.0', 'Method %s() is deprecated. Use %s::%s() instead.', __METHOD__, IndexNameMapper::class, __FUNCTION__);

return $this->indexNameMapper->getIndexNameFromClass($className);
}

/**
* @throws ExceptionInterface
*/
public function getClassFromIndexName(string $indexName): string
{
trigger_deprecation('jolicode/elastically', '1.4.0', 'Method %s() is deprecated. Use %s::%s() instead.', __METHOD__, IndexNameMapper::class, __FUNCTION__);

return $this->indexNameMapper->getClassFromIndexName($indexName);
}

public function getPureIndexName(string $fullIndexName): string
{
trigger_deprecation('jolicode/elastically', '1.4.0', 'Method %s() is deprecated. Use %s::%s() instead.', __METHOD__, IndexNameMapper::class, __FUNCTION__);

return $this->indexNameMapper->getPureIndexName($fullIndexName);
}

public function getIndexBuilder(): IndexBuilder
{
trigger_deprecation('jolicode/elastically', '1.4.0', 'Method %s() is deprecated. Inject a IndexBuilder instance in your code directly using dependency injection or call the %s.', __METHOD__, Factory::class);

return $this->factory->buildIndexBuilder();
}

public function getIndexer(): Indexer
{
trigger_deprecation('jolicode/elastically', '1.4.0', 'Method %s() is deprecated. Inject a Indexer instance in your code directly using dependency injection or call the %s.', __METHOD__, Factory::class);

return $this->factory->buildIndexer();
}

public function getBuilder(): ResultSetBuilder
{
trigger_deprecation('jolicode/elastically', '1.4.0', 'Method %s() is deprecated. Inject a ResultSetBuilder instance in your code directly using dependency injection or call the %s.', __METHOD__, Factory::class);

return $this->factory->buildBuilder();
}

public function getSerializer(): SerializerInterface
{
trigger_deprecation('jolicode/elastically', '1.4.0', 'Method %s() is deprecated. Inject a SerializerInterface instance in your code directly using dependency injection or call the %s.', __METHOD__, Factory::class);

return $this->factory->buildSerializer();
}

public function getDenormalizer(): DenormalizerInterface
{
trigger_deprecation('jolicode/elastically', '1.4.0', 'Method %s() is deprecated. Inject a DenormalizerInterface instance in your code directly using dependency injection or call the %s.', __METHOD__, Factory::class);

return $this->factory->buildDenormalizer();
}

public function getSerializerContext(string $class): array
{
trigger_deprecation('jolicode/elastically', '1.4.0', 'Method %s() is deprecated. Inject a ContextBuilderInterface instance in your code directly using dependency injection or call the %s.', __METHOD__, Factory::class);

return $this->factory->buildSerializerContext($class);
}
}
Loading

1 comment on commit 1bbd506

@damienalexandre
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Friendly ping to the monsieurbiz/SyliusSearchPlugin team @maximehuran, @welcoMattic, would you like to test Elastically dev-master with Elastica 8.x on your Plugin? 🙏

Please sign in to comment.