diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ab5a6941..8309ae1f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,17 +5,13 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] ### Added ### Changed -- Moved duplicate health check workflow step to a shared action ([#366](https://github.com/opensearch-project/opensearch-php/pull/366)) -- Bump composer dependencies and add `--prefer-lowest` to the test matrix ([#367](https://github.com/opensearch-project/opensearch-php/pull/367)) -- Upgrade from phpunit v9 to v10 ([#371](https://github.com/opensearch-project/opensearch-php/pull/371)) -- Simplify logic for url param encoding ([#370](https://github.com/opensearch-project/opensearch-php/pull/370)) ### Deprecated ### Removed +- Removed deprecated code ### Fixed -- ID is being double encoded ([#360](https://github.com/opensearch-project/opensearch-php/issues/360)) ### Security ### Updated APIs -- Updated opensearch-php APIs to reflect [opensearch-api-specification@db59af1](https://github.com/opensearch-project/opensearch-api-specification/commit/db59af1556fced5193c61a768d7e5153976acd5d) +- Updated opensearch-php APIs to reflect [opensearch-api-specification@4d34d30](https://github.com/opensearch-project/opensearch-api-specification/commit/4d34d308450e8746b2a3df52d5479564bc75a48e) ## [2.4.6] ### Added diff --git a/composer.json b/composer.json index 82e7b155e..406e228c1 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,6 @@ "php": "^8.1", "ext-json": ">=1.3.7", "ext-curl": "*", - "ezimuel/ringphp": "^1.4.0", "php-http/discovery": "^1.20", "psr/http-client": "^1.0.3", "psr/http-client-implementation": "*", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c117c0986..f6f8b4a1b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,12 +1,5 @@ parameters: ignoreErrors: - - - message: """ - #^Instantiation of deprecated class OpenSearch\\\\Common\\\\Exceptions\\\\InvalidArgumentException\\: - in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\.$# - """ - count: 1 - path: src/OpenSearch/Endpoints/Monitoring/Bulk.php - message: """ @@ -56,14 +49,6 @@ parameters: count: 1 path: src/OpenSearch/Namespaces/MlNamespace.php - - - message: """ - #^Access to deprecated property \\$endpoints of class OpenSearch\\\\Namespaces\\\\AbstractNamespace\\: - in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\. Use \\$endpointFactory property instead\\.$# - """ - count: 1 - path: src/OpenSearch/Namespaces/SecurityNamespace.php - - message: "#^Call to an undefined method OpenSearch\\\\Client\\:\\:slm\\(\\)\\.$#" count: 2 diff --git a/src/OpenSearch/Client.php b/src/OpenSearch/Client.php index be75c2227..4da573216 100644 --- a/src/OpenSearch/Client.php +++ b/src/OpenSearch/Client.php @@ -24,12 +24,10 @@ use OpenSearch\Endpoints\AbstractEndpoint; use OpenSearch\Namespaces\BooleanRequestWrapper; use OpenSearch\Namespaces\NamespaceBuilderInterface; -use OpenSearch\Namespaces\AsyncSearchNamespace; use OpenSearch\Namespaces\AsynchronousSearchNamespace; use OpenSearch\Namespaces\CatNamespace; use OpenSearch\Namespaces\ClusterNamespace; use OpenSearch\Namespaces\DanglingIndicesNamespace; -use OpenSearch\Namespaces\DataFrameTransformDeprecatedNamespace; use OpenSearch\Namespaces\FlowFrameworkNamespace; use OpenSearch\Namespaces\GeospatialNamespace; use OpenSearch\Namespaces\IndicesNamespace; @@ -41,7 +39,6 @@ use OpenSearch\Namespaces\ListNamespace; use OpenSearch\Namespaces\LtrNamespace; use OpenSearch\Namespaces\MlNamespace; -use OpenSearch\Namespaces\MonitoringNamespace; use OpenSearch\Namespaces\NeuralNamespace; use OpenSearch\Namespaces\NodesNamespace; use OpenSearch\Namespaces\NotificationsNamespace; @@ -53,13 +50,11 @@ use OpenSearch\Namespaces\RollupsNamespace; use OpenSearch\Namespaces\SearchPipelineNamespace; use OpenSearch\Namespaces\SearchRelevanceNamespace; -use OpenSearch\Namespaces\SearchableSnapshotsNamespace; use OpenSearch\Namespaces\SecurityNamespace; use OpenSearch\Namespaces\SecurityAnalyticsNamespace; use OpenSearch\Namespaces\SmNamespace; use OpenSearch\Namespaces\SnapshotNamespace; use OpenSearch\Namespaces\SqlNamespace; -use OpenSearch\Namespaces\SslNamespace; use OpenSearch\Namespaces\TasksNamespace; use OpenSearch\Namespaces\TransformsNamespace; use OpenSearch\Namespaces\UbiNamespace; @@ -115,333 +110,134 @@ */ class Client { - public const VERSION = '2.4.7'; + public const VERSION = '3.x-dev'; /** - * @var Transport - * - * @deprecated in 2.4.0 and will be removed in 3.0.0. - */ - public $transport; - - private TransportInterface $httpTransport; - - /** - * @var array + * @var array */ - protected $params; + protected array $params; - private EndpointFactoryInterface $endpointFactory; - - /** - * @var callable - * - * @deprecated in 2.4.0 and will be removed in 3.0.0. - */ - protected $endpoints; + protected EndpointFactoryInterface $endpointFactory; /** * @var NamespaceBuilderInterface[] */ - protected $registeredNamespaces = []; + protected array $registeredNamespaces = []; - /** - * @var AsyncSearchNamespace - * - * @deprecated in 2.4.2 and will be removed in 3.0.0. - */ - protected $asyncSearch; + protected AsynchronousSearchNamespace $asynchronousSearch; - /** - * @var AsynchronousSearchNamespace - */ - protected $asynchronousSearch; + protected CatNamespace $cat; - /** - * @var CatNamespace - */ - protected $cat; + protected ClusterNamespace $cluster; - /** - * @var ClusterNamespace - */ - protected $cluster; + protected DanglingIndicesNamespace $danglingIndices; - /** - * @var DanglingIndicesNamespace - */ - protected $danglingIndices; + protected FlowFrameworkNamespace $flowFramework; - /** - * @var DataFrameTransformDeprecatedNamespace - * - * @deprecated in 2.4.2 and will be removed in 3.0.0. - */ - protected $dataFrameTransformDeprecated; + protected GeospatialNamespace $geospatial; - /** - * @var FlowFrameworkNamespace - */ - protected $flowFramework; + protected IndicesNamespace $indices; - /** - * @var GeospatialNamespace - */ - protected $geospatial; + protected IngestNamespace $ingest; - /** - * @var IndicesNamespace - */ - protected $indices; + protected IngestionNamespace $ingestion; - /** - * @var IngestNamespace - */ - protected $ingest; + protected InsightsNamespace $insights; - /** - * @var IngestionNamespace - */ - protected $ingestion; + protected IsmNamespace $ism; - /** - * @var InsightsNamespace - */ - protected $insights; + protected KnnNamespace $knn; - /** - * @var IsmNamespace - */ - protected $ism; + protected ListNamespace $list; - /** - * @var KnnNamespace - */ - protected $knn; + protected LtrNamespace $ltr; - /** - * @var ListNamespace - */ - protected $list; + protected MlNamespace $ml; - /** - * @var LtrNamespace - */ - protected $ltr; + protected NeuralNamespace $neural; - /** - * @var MlNamespace - */ - protected $ml; + protected NodesNamespace $nodes; - /** - * @var MonitoringNamespace - * - * @deprecated in 2.4.2 and will be removed in 3.0.0. - */ - protected $monitoring; + protected NotificationsNamespace $notifications; - /** - * @var NeuralNamespace - */ - protected $neural; + protected ObservabilityNamespace $observability; - /** - * @var NodesNamespace - */ - protected $nodes; - - /** - * @var NotificationsNamespace - */ - protected $notifications; - - /** - * @var ObservabilityNamespace - */ - protected $observability; - - /** - * @var PplNamespace - */ - protected $ppl; - - /** - * @var QueryNamespace - */ - protected $query; - - /** - * @var RemoteStoreNamespace - */ - protected $remoteStore; + protected PplNamespace $ppl; - /** - * @var ReplicationNamespace - */ - protected $replication; + protected QueryNamespace $query; - /** - * @var RollupsNamespace - */ - protected $rollups; + protected RemoteStoreNamespace $remoteStore; - /** - * @var SearchPipelineNamespace - */ - protected $searchPipeline; + protected ReplicationNamespace $replication; - /** - * @var SearchRelevanceNamespace - */ - protected $searchRelevance; + protected RollupsNamespace $rollups; - /** - * @var SearchableSnapshotsNamespace - * - * @deprecated in 2.4.2 and will be removed in 3.0.0. - */ - protected $searchableSnapshots; + protected SearchPipelineNamespace $searchPipeline; - /** - * @var SecurityNamespace - */ - protected $security; + protected SearchRelevanceNamespace $searchRelevance; - /** - * @var SecurityAnalyticsNamespace - */ - protected $securityAnalytics; + protected SecurityNamespace $security; - /** - * @var SmNamespace - */ - protected $sm; + protected SecurityAnalyticsNamespace $securityAnalytics; - /** - * @var SnapshotNamespace - */ - protected $snapshot; + protected SmNamespace $sm; - /** - * @var SqlNamespace - */ - protected $sql; + protected SnapshotNamespace $snapshot; - /** - * @var SslNamespace - * - * @deprecated in 2.4.2 and will be removed in 3.0.0. - */ - protected $ssl; + protected SqlNamespace $sql; - /** - * @var TasksNamespace - */ - protected $tasks; + protected TasksNamespace $tasks; - /** - * @var TransformsNamespace - */ - protected $transforms; + protected TransformsNamespace $transforms; - /** - * @var UbiNamespace - */ - protected $ubi; + protected UbiNamespace $ubi; - /** - * @var WlmNamespace - */ - protected $wlm; + protected WlmNamespace $wlm; - /** - * Client constructor - * - * @param TransportInterface|Transport $transport - * @param callable|EndpointFactoryInterface|null $endpointFactory - * @param NamespaceBuilderInterface[] $registeredNamespaces - * - * @phpstan-ignore parameter.deprecatedClass - */ public function __construct( - TransportInterface|Transport $transport, - callable|EndpointFactoryInterface|null $endpointFactory = null, + protected TransportInterface $httpTransport, + ?EndpointFactoryInterface $endpointFactory = null, array $registeredNamespaces = [], ) { - if (!$transport instanceof TransportInterface) { - @trigger_error('Passing an instance of \OpenSearch\Transport to ' . __METHOD__ . '() is deprecated in 2.4.0 and will be removed in 3.0.0. Pass an instance of \OpenSearch\TransportInterface instead.', E_USER_DEPRECATED); - // @phpstan-ignore property.deprecated - $this->transport = $transport; - // @phpstan-ignore new.deprecated - $this->httpTransport = new LegacyTransportWrapper($transport); - } else { - $this->httpTransport = $transport; + if ($endpointFactory === null) { + $endpointFactory = new EndpointFactory(); } - - if (is_callable($endpointFactory)) { - @trigger_error('Passing a callable as the $endpointFactory param in ' . __METHOD__ . ' is deprecated in 2.4.0 and will be removed in 3.0.0. Pass an instance of \OpenSearch\EndpointFactoryInterface instead.', E_USER_DEPRECATED); - $endpoints = $endpointFactory; - // @phpstan-ignore new.deprecated - $endpointFactory = new LegacyEndpointFactory($endpointFactory); - } else { - if ($endpointFactory === null) { - $endpointFactory = new EndpointFactory(); - } - $endpoints = function ($c) use ($endpointFactory) { - @trigger_error('The $endpoints property is deprecated in 2.4.0 and will be removed in 3.0.0.', E_USER_DEPRECATED); - return $endpointFactory->getEndpoint('OpenSearch\\Endpoints\\' . $c); - }; - } - - // @phpstan-ignore property.deprecated - $this->endpoints = $endpoints; $this->endpointFactory = $endpointFactory; - // @phpstan-ignore new.deprecated, property.deprecated - $this->asyncSearch = new AsyncSearchNamespace($transport, $this->endpointFactory); - $this->asynchronousSearch = new AsynchronousSearchNamespace($transport, $this->endpointFactory); - $this->cat = new CatNamespace($transport, $this->endpointFactory); - $this->cluster = new ClusterNamespace($transport, $this->endpointFactory); - $this->danglingIndices = new DanglingIndicesNamespace($transport, $this->endpointFactory); - // @phpstan-ignore new.deprecated, property.deprecated - $this->dataFrameTransformDeprecated = new DataFrameTransformDeprecatedNamespace($transport, $this->endpointFactory); - $this->flowFramework = new FlowFrameworkNamespace($transport, $this->endpointFactory); - $this->geospatial = new GeospatialNamespace($transport, $this->endpointFactory); - $this->indices = new IndicesNamespace($transport, $this->endpointFactory); - $this->ingest = new IngestNamespace($transport, $this->endpointFactory); - $this->ingestion = new IngestionNamespace($transport, $this->endpointFactory); - $this->insights = new InsightsNamespace($transport, $this->endpointFactory); - $this->ism = new IsmNamespace($transport, $this->endpointFactory); - $this->knn = new KnnNamespace($transport, $this->endpointFactory); - $this->list = new ListNamespace($transport, $this->endpointFactory); - $this->ltr = new LtrNamespace($transport, $this->endpointFactory); - $this->ml = new MlNamespace($transport, $this->endpointFactory); - // @phpstan-ignore new.deprecated, property.deprecated - $this->monitoring = new MonitoringNamespace($transport, $this->endpointFactory); - $this->neural = new NeuralNamespace($transport, $this->endpointFactory); - $this->nodes = new NodesNamespace($transport, $this->endpointFactory); - $this->notifications = new NotificationsNamespace($transport, $this->endpointFactory); - $this->observability = new ObservabilityNamespace($transport, $this->endpointFactory); - $this->ppl = new PplNamespace($transport, $this->endpointFactory); - $this->query = new QueryNamespace($transport, $this->endpointFactory); - $this->remoteStore = new RemoteStoreNamespace($transport, $this->endpointFactory); - $this->replication = new ReplicationNamespace($transport, $this->endpointFactory); - $this->rollups = new RollupsNamespace($transport, $this->endpointFactory); - $this->searchPipeline = new SearchPipelineNamespace($transport, $this->endpointFactory); - $this->searchRelevance = new SearchRelevanceNamespace($transport, $this->endpointFactory); - // @phpstan-ignore new.deprecated, property.deprecated - $this->searchableSnapshots = new SearchableSnapshotsNamespace($transport, $this->endpointFactory); - $this->security = new SecurityNamespace($transport, $this->endpointFactory); - $this->securityAnalytics = new SecurityAnalyticsNamespace($transport, $this->endpointFactory); - $this->sm = new SmNamespace($transport, $this->endpointFactory); - $this->snapshot = new SnapshotNamespace($transport, $this->endpointFactory); - $this->sql = new SqlNamespace($transport, $this->endpointFactory); - // @phpstan-ignore new.deprecated, property.deprecated - $this->ssl = new SslNamespace($transport, $this->endpointFactory); - $this->tasks = new TasksNamespace($transport, $this->endpointFactory); - $this->transforms = new TransformsNamespace($transport, $this->endpointFactory); - $this->ubi = new UbiNamespace($transport, $this->endpointFactory); - $this->wlm = new WlmNamespace($transport, $this->endpointFactory); + $this->asynchronousSearch = new AsynchronousSearchNamespace($this->httpTransport, $this->endpointFactory); + $this->cat = new CatNamespace($this->httpTransport, $this->endpointFactory); + $this->cluster = new ClusterNamespace($this->httpTransport, $this->endpointFactory); + $this->danglingIndices = new DanglingIndicesNamespace($this->httpTransport, $this->endpointFactory); + $this->flowFramework = new FlowFrameworkNamespace($this->httpTransport, $this->endpointFactory); + $this->geospatial = new GeospatialNamespace($this->httpTransport, $this->endpointFactory); + $this->indices = new IndicesNamespace($this->httpTransport, $this->endpointFactory); + $this->ingest = new IngestNamespace($this->httpTransport, $this->endpointFactory); + $this->ingestion = new IngestionNamespace($this->httpTransport, $this->endpointFactory); + $this->insights = new InsightsNamespace($this->httpTransport, $this->endpointFactory); + $this->ism = new IsmNamespace($this->httpTransport, $this->endpointFactory); + $this->knn = new KnnNamespace($this->httpTransport, $this->endpointFactory); + $this->list = new ListNamespace($this->httpTransport, $this->endpointFactory); + $this->ltr = new LtrNamespace($this->httpTransport, $this->endpointFactory); + $this->ml = new MlNamespace($this->httpTransport, $this->endpointFactory); + $this->neural = new NeuralNamespace($this->httpTransport, $this->endpointFactory); + $this->nodes = new NodesNamespace($this->httpTransport, $this->endpointFactory); + $this->notifications = new NotificationsNamespace($this->httpTransport, $this->endpointFactory); + $this->observability = new ObservabilityNamespace($this->httpTransport, $this->endpointFactory); + $this->ppl = new PplNamespace($this->httpTransport, $this->endpointFactory); + $this->query = new QueryNamespace($this->httpTransport, $this->endpointFactory); + $this->remoteStore = new RemoteStoreNamespace($this->httpTransport, $this->endpointFactory); + $this->replication = new ReplicationNamespace($this->httpTransport, $this->endpointFactory); + $this->rollups = new RollupsNamespace($this->httpTransport, $this->endpointFactory); + $this->searchPipeline = new SearchPipelineNamespace($this->httpTransport, $this->endpointFactory); + $this->searchRelevance = new SearchRelevanceNamespace($this->httpTransport, $this->endpointFactory); + $this->security = new SecurityNamespace($this->httpTransport, $this->endpointFactory); + $this->securityAnalytics = new SecurityAnalyticsNamespace($this->httpTransport, $this->endpointFactory); + $this->sm = new SmNamespace($this->httpTransport, $this->endpointFactory); + $this->snapshot = new SnapshotNamespace($this->httpTransport, $this->endpointFactory); + $this->sql = new SqlNamespace($this->httpTransport, $this->endpointFactory); + $this->tasks = new TasksNamespace($this->httpTransport, $this->endpointFactory); + $this->transforms = new TransformsNamespace($this->httpTransport, $this->endpointFactory); + $this->ubi = new UbiNamespace($this->httpTransport, $this->endpointFactory); + $this->wlm = new WlmNamespace($this->httpTransport, $this->endpointFactory); $this->registeredNamespaces = $registeredNamespaces; } @@ -469,7 +265,7 @@ public function __construct( * @param array $params Associative array of parameters * @return array */ - public function bulk(array $params = []) + public function bulk(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -507,7 +303,7 @@ public function bulk(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function bulkStream(array $params = []) + public function bulkStream(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -534,7 +330,7 @@ public function bulkStream(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function clearScroll(array $params = []) + public function clearScroll(array $params = []): iterable|string|null { $scroll_id = $this->extractArgument($params, 'scroll_id'); $body = $this->extractArgument($params, 'body'); @@ -575,7 +371,7 @@ public function clearScroll(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function count(array $params = []) + public function count(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -606,7 +402,7 @@ public function count(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createPit(array $params = []) + public function createPit(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -639,7 +435,7 @@ public function createPit(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function delete(array $params = []) + public function delete(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $index = $this->extractArgument($params, 'index'); @@ -664,7 +460,7 @@ public function delete(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteAllPits(array $params = []) + public function deleteAllPits(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(DeleteAllPits::class); $endpoint->setParams($params); @@ -719,7 +515,7 @@ public function deleteAllPits(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteByQuery(array $params = []) + public function deleteByQuery(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -746,7 +542,7 @@ public function deleteByQuery(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteByQueryRethrottle(array $params = []) + public function deleteByQueryRethrottle(array $params = []): iterable|string|null { $task_id = $this->extractArgument($params, 'task_id'); @@ -770,7 +566,7 @@ public function deleteByQueryRethrottle(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deletePit(array $params = []) + public function deletePit(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -797,7 +593,7 @@ public function deletePit(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteScript(array $params = []) + public function deleteScript(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -837,10 +633,6 @@ public function exists(array $params = []): bool $id = $this->extractArgument($params, 'id'); $index = $this->extractArgument($params, 'index'); - // Legacy option to manually make this verbose so we can check status code. - // @todo remove in 3.0.0 - $params['client']['verbose'] = true; - $endpoint = $this->endpointFactory->getEndpoint(Exists::class); $endpoint->setParams($params); $endpoint->setId($id); @@ -877,10 +669,6 @@ public function existsSource(array $params = []): bool $id = $this->extractArgument($params, 'id'); $index = $this->extractArgument($params, 'index'); - // Legacy option to manually make this verbose so we can check status code. - // @todo remove in 3.0.0 - $params['client']['verbose'] = true; - $endpoint = $this->endpointFactory->getEndpoint(ExistsSource::class); $endpoint->setParams($params); $endpoint->setId($id); @@ -916,7 +704,7 @@ public function existsSource(array $params = []): bool * @param array $params Associative array of parameters * @return array */ - public function explain(array $params = []) + public function explain(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $index = $this->extractArgument($params, 'index'); @@ -950,7 +738,7 @@ public function explain(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function fieldCaps(array $params = []) + public function fieldCaps(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -987,7 +775,7 @@ public function fieldCaps(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function get(array $params = []) + public function get(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $index = $this->extractArgument($params, 'index'); @@ -1012,7 +800,7 @@ public function get(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getAllPits(array $params = []) + public function getAllPits(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetAllPits::class); $endpoint->setParams($params); @@ -1035,7 +823,7 @@ public function getAllPits(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getScript(array $params = []) + public function getScript(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -1058,7 +846,7 @@ public function getScript(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getScriptContext(array $params = []) + public function getScriptContext(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetScriptContext::class); $endpoint->setParams($params); @@ -1078,7 +866,7 @@ public function getScriptContext(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getScriptLanguages(array $params = []) + public function getScriptLanguages(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetScriptLanguages::class); $endpoint->setParams($params); @@ -1109,7 +897,7 @@ public function getScriptLanguages(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getSource(array $params = []) + public function getSource(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $index = $this->extractArgument($params, 'index'); @@ -1148,7 +936,7 @@ public function getSource(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function index(array $params = []) + public function index(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $id = $this->extractArgument($params, 'id'); @@ -1175,7 +963,7 @@ public function index(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function info(array $params = []) + public function info(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Info::class); $endpoint->setParams($params); @@ -1205,7 +993,7 @@ public function info(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function mget(array $params = []) + public function mget(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1239,7 +1027,7 @@ public function mget(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function msearch(array $params = []) + public function msearch(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1271,7 +1059,7 @@ public function msearch(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function msearchTemplate(array $params = []) + public function msearchTemplate(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1310,7 +1098,7 @@ public function msearchTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function mtermvectors(array $params = []) + public function mtermvectors(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1337,10 +1125,6 @@ public function mtermvectors(array $params = []) */ public function ping(array $params = []): bool { - // Legacy option to manually make this verbose so we can check status code. - // @todo remove in 3.0.0 - $params['client']['verbose'] = true; - $endpoint = $this->endpointFactory->getEndpoint(Ping::class); $endpoint->setParams($params); @@ -1365,7 +1149,7 @@ public function ping(array $params = []): bool * @param array $params Associative array of parameters * @return array */ - public function putScript(array $params = []) + public function putScript(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $context = $this->extractArgument($params, 'context'); @@ -1398,7 +1182,7 @@ public function putScript(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function rankEval(array $params = []) + public function rankEval(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1433,7 +1217,7 @@ public function rankEval(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function reindex(array $params = []) + public function reindex(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1458,7 +1242,7 @@ public function reindex(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function reindexRethrottle(array $params = []) + public function reindexRethrottle(array $params = []): iterable|string|null { $task_id = $this->extractArgument($params, 'task_id'); @@ -1483,7 +1267,7 @@ public function reindexRethrottle(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function renderSearchTemplate(array $params = []) + public function renderSearchTemplate(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $body = $this->extractArgument($params, 'body'); @@ -1509,7 +1293,7 @@ public function renderSearchTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function scriptsPainlessExecute(array $params = []) + public function scriptsPainlessExecute(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1535,7 +1319,7 @@ public function scriptsPainlessExecute(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function scroll(array $params = []) + public function scroll(array $params = []): iterable|string|null { $scroll_id = $this->extractArgument($params, 'scroll_id'); $body = $this->extractArgument($params, 'body'); @@ -1609,7 +1393,7 @@ public function scroll(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function search(array $params = []) + public function search(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1641,7 +1425,7 @@ public function search(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchShards(array $params = []) + public function searchShards(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1683,7 +1467,7 @@ public function searchShards(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchTemplate(array $params = []) + public function searchTemplate(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1722,7 +1506,7 @@ public function searchTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function termvectors(array $params = []) + public function termvectors(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $id = $this->extractArgument($params, 'id'); @@ -1764,7 +1548,7 @@ public function termvectors(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function update(array $params = []) + public function update(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $index = $this->extractArgument($params, 'index'); @@ -1827,7 +1611,7 @@ public function update(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateByQuery(array $params = []) + public function updateByQuery(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1854,7 +1638,7 @@ public function updateByQuery(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateByQueryRethrottle(array $params = []) + public function updateByQueryRethrottle(array $params = []): iterable|string|null { $task_id = $this->extractArgument($params, 'task_id'); @@ -1919,16 +1703,6 @@ public function deletePointInTime(array $params = []) { return $this->deletePit($params); } - /** - * Returns the asyncSearch namespace - * - * @deprecated in 2.4.2 and will be removed in 3.0.0. - */ - public function asyncSearch(): AsyncSearchNamespace - { - @trigger_error(__METHOD__ . '() is deprecated since 2.4.2 and will be removed in 3.0.0.', E_USER_DEPRECATED); - return $this->asyncSearch; - } /** * Returns the asynchronousSearch namespace */ @@ -1957,16 +1731,6 @@ public function danglingIndices(): DanglingIndicesNamespace { return $this->danglingIndices; } - /** - * Returns the dataFrameTransformDeprecated namespace - * - * @deprecated in 2.4.2 and will be removed in 3.0.0. - */ - public function dataFrameTransformDeprecated(): DataFrameTransformDeprecatedNamespace - { - @trigger_error(__METHOD__ . '() is deprecated since 2.4.2 and will be removed in 3.0.0.', E_USER_DEPRECATED); - return $this->dataFrameTransformDeprecated; - } /** * Returns the flowFramework namespace */ @@ -2044,16 +1808,6 @@ public function ml(): MlNamespace { return $this->ml; } - /** - * Returns the monitoring namespace - * - * @deprecated in 2.4.2 and will be removed in 3.0.0. - */ - public function monitoring(): MonitoringNamespace - { - @trigger_error(__METHOD__ . '() is deprecated since 2.4.2 and will be removed in 3.0.0.', E_USER_DEPRECATED); - return $this->monitoring; - } /** * Returns the neural namespace */ @@ -2131,16 +1885,6 @@ public function searchRelevance(): SearchRelevanceNamespace { return $this->searchRelevance; } - /** - * Returns the searchableSnapshots namespace - * - * @deprecated in 2.4.2 and will be removed in 3.0.0. - */ - public function searchableSnapshots(): SearchableSnapshotsNamespace - { - @trigger_error(__METHOD__ . '() is deprecated since 2.4.2 and will be removed in 3.0.0.', E_USER_DEPRECATED); - return $this->searchableSnapshots; - } /** * Returns the security namespace */ @@ -2176,16 +1920,6 @@ public function sql(): SqlNamespace { return $this->sql; } - /** - * Returns the ssl namespace - * - * @deprecated in 2.4.2 and will be removed in 3.0.0. - */ - public function ssl(): SslNamespace - { - @trigger_error(__METHOD__ . '() is deprecated since 2.4.2 and will be removed in 3.0.0.', E_USER_DEPRECATED); - return $this->ssl; - } /** * Returns the tasks namespace */ @@ -2229,7 +1963,7 @@ protected function getEndpointFactory(): EndpointFactoryInterface * @return object * @throws \BadMethodCallException if the namespace cannot be found */ - public function __call(string $name, array $arguments) + public function __call(string $name, array $arguments): object { if (isset($this->registeredNamespaces[$name])) { return $this->registeredNamespaces[$name]; @@ -2242,18 +1976,17 @@ public function __call(string $name, array $arguments) * * @return null|mixed */ - public function extractArgument(array &$params, string $arg) + public function extractArgument(array &$params, string $arg): mixed { - if (array_key_exists($arg, $params) === true) { - $value = $params[$arg]; - $value = (is_object($value) && !is_iterable($value)) ? - (array) $value : - $value; - unset($params[$arg]); - return $value; - } else { + if (!array_key_exists($arg, $params)) { return null; } + $value = $params[$arg]; + $value = (is_object($value) && !is_iterable($value)) ? + (array) $value : + $value; + unset($params[$arg]); + return $value; } /** diff --git a/src/OpenSearch/ClientBuilder.php b/src/OpenSearch/ClientBuilder.php deleted file mode 100644 index e65fdbfda..000000000 --- a/src/OpenSearch/ClientBuilder.php +++ /dev/null @@ -1,861 +0,0 @@ - true - ]; - - /** - * @var array|null - */ - private $hosts; - - /** - * @var array - */ - private $connectionParams; - - /** - * @var int|null - */ - private $retries; - - /** - * @var null|callable - */ - private $sigV4CredentialProvider; - - /** - * @var null|string - */ - private $sigV4Region; - - /** - * @var null|string - */ - private $sigV4Service; - - /** - * @var bool - */ - private $sniffOnStart = false; - - /** - * @var null|array - */ - private $sslCert; - - /** - * @var null|array - */ - private $sslKey; - - /** - * @var null|bool|string - */ - private $sslVerification; - - /** - * @var bool - */ - private $includePortInHostHeader = false; - - /** - * @var string|null - */ - private $basicAuthentication = null; - - /** - * Create an instance of ClientBuilder - */ - public static function create(): ClientBuilder - { - return new self(); - } - - /** - * Can supply first param to Client::__construct() when invoking manually or with dependency injection - */ - public function getTransport(): Transport - { - return $this->transport; - } - - /** - * Can supply second param to Client::__construct() when invoking manually or with dependency injection - * - * @deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\ClientBuilder::getEndpointFactory() instead. - */ - public function getEndpoint(): callable - { - @trigger_error(__METHOD__ . '() is deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\ClientBuilder::getEndpointFactory() instead.', E_USER_DEPRECATED); - return fn ($c) => $this->endpointFactory->getEndpoint('OpenSearch\\Endpoints\\' . $c); - } - - /** - * Can supply third param to Client::__construct() when invoking manually or with dependency injection - * - * @return NamespaceBuilderInterface[] - */ - public function getRegisteredNamespacesBuilders(): array - { - return $this->registeredNamespacesBuilders; - } - - /** - * Build a new client from the provided config. Hash keys - * should correspond to the method name e.g. ['connectionPool'] - * corresponds to setConnectionPool(). - * - * Missing keys will use the default for that setting if applicable - * - * Unknown keys will throw an exception by default, but this can be silenced - * by setting `quiet` to true - * - * @param array $config - * @param bool $quiet False if unknown settings throw exception, true to silently - * ignore unknown settings - * @throws Common\Exceptions\RuntimeException - */ - public static function fromConfig(array $config, bool $quiet = false): Client - { - $builder = new self(); - foreach ($config as $key => $value) { - $method = in_array($key, self::ALLOWED_METHODS_FROM_CONFIG, true) ? $key : "set$key"; - $reflection = new ReflectionClass($builder); - if ($reflection->hasMethod($method)) { - $func = $reflection->getMethod($method); - if ($func->getNumberOfParameters() > 1) { - $builder->$method(...$value); - } else { - $builder->$method($value); - } - unset($config[$key]); - } - } - - if ($quiet === false && count($config) > 0) { - $unknown = implode(array_keys($config)); - throw new RuntimeException("Unknown parameters provided: $unknown"); - } - return $builder->build(); - } - - /** - * Get the default handler - * - * @param array $multiParams - * @param array $singleParams - * @throws \RuntimeException - */ - public static function defaultHandler(array $multiParams = [], array $singleParams = []): callable - { - $future = null; - if (extension_loaded('curl')) { - $config = array_merge([ 'mh' => curl_multi_init() ], $multiParams); - if (function_exists('curl_reset')) { - $default = new CurlHandler($singleParams); - $future = new CurlMultiHandler($config); - } else { - $default = new CurlMultiHandler($config); - } - } else { - throw new \RuntimeException('OpenSearch-PHP requires cURL, or a custom HTTP handler.'); - } - - return $future ? Middleware::wrapFuture($default, $future) : $default; - } - - /** - * Get the multi handler for async (CurlMultiHandler) - * - * @throws \RuntimeException - */ - public static function multiHandler(array $params = []): CurlMultiHandler - { - if (function_exists('curl_multi_init')) { - return new CurlMultiHandler(array_merge([ 'mh' => curl_multi_init() ], $params)); - } - - throw new \RuntimeException('CurlMulti handler requires cURL.'); - } - - /** - * Get the handler instance (CurlHandler) - * - * @throws \RuntimeException - */ - public static function singleHandler(): CurlHandler - { - if (function_exists('curl_reset')) { - return new CurlHandler(); - } - - throw new \RuntimeException('CurlSingle handler requires cURL.'); - } - - /** - * Set connection Factory - * - * @param ConnectionFactoryInterface $connectionFactory - */ - public function setConnectionFactory(ConnectionFactoryInterface $connectionFactory): ClientBuilder - { - $this->connectionFactory = $connectionFactory; - - return $this; - } - - /** - * Set the connection pool (default is StaticNoPingConnectionPool) - * - * @param AbstractConnectionPool|string $connectionPool - * @param array $args - * @throws \InvalidArgumentException - */ - public function setConnectionPool($connectionPool, array $args = []): ClientBuilder - { - if (is_string($connectionPool)) { - $this->connectionPool = $connectionPool; - $this->connectionPoolArgs = $args; - } elseif (is_object($connectionPool)) { - $this->connectionPool = $connectionPool; - } else { - throw new InvalidArgumentException("Serializer must be a class path or instantiated object extending AbstractConnectionPool"); - } - - return $this; - } - - /** - * Set the endpoint - * - * @param callable $endpoint - * - * @deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\ClientBuilder::setEndpointFactory() instead. - */ - public function setEndpoint(callable $endpoint): ClientBuilder - { - @trigger_error(__METHOD__ . '() is deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\ClientBuilder::setEndpointFactory() instead.', E_USER_DEPRECATED); - $this->endpointFactory = new LegacyEndpointFactory($endpoint); - - return $this; - } - - public function setEndpointFactory(EndpointFactoryInterface $endpointFactory): ClientBuilder - { - $this->endpointFactory = $endpointFactory; - return $this; - } - - /** - * Register namespace - * - * @param NamespaceBuilderInterface $namespaceBuilder - */ - public function registerNamespace(NamespaceBuilderInterface $namespaceBuilder): ClientBuilder - { - $this->registeredNamespacesBuilders[] = $namespaceBuilder; - - return $this; - } - - /** - * Set the transport - * - * @param Transport $transport - */ - public function setTransport(Transport $transport): ClientBuilder - { - $this->transport = $transport; - - return $this; - } - - /** - * Set the HTTP handler (cURL is default) - * - * @param mixed $handler - */ - public function setHandler($handler): ClientBuilder - { - $this->handler = $handler; - - return $this; - } - - /** - * Set the PSR-3 Logger - * - * @param LoggerInterface $logger - */ - public function setLogger(LoggerInterface $logger): ClientBuilder - { - $this->logger = $logger; - - return $this; - } - - /** - * Set the PSR-3 tracer - * - * @param LoggerInterface $tracer - */ - public function setTracer(LoggerInterface $tracer): ClientBuilder - { - $this->tracer = $tracer; - - return $this; - } - - /** - * Set the serializer - * - * @param \OpenSearch\Serializers\SerializerInterface|string $serializer - */ - public function setSerializer($serializer): ClientBuilder - { - $this->parseStringOrObject($serializer, $this->serializer, 'SerializerInterface'); - - return $this; - } - - /** - * Set the hosts (nodes) - * - * @param array $hosts - */ - public function setHosts(array $hosts): ClientBuilder - { - $this->hosts = $hosts; - - return $this; - } - - /** - * Set Basic access authentication - * - * @see https://en.wikipedia.org/wiki/Basic_access_authentication - * @param string $username - * @param string $password - * - * @throws AuthenticationConfigException - */ - public function setBasicAuthentication(string $username, string $password): ClientBuilder - { - $this->basicAuthentication = $username.':'.$password; - - return $this; - } - - /** - * Set connection parameters - * - * @param array $params - */ - public function setConnectionParams(array $params): ClientBuilder - { - $this->connectionParams = $params; - - return $this; - } - - /** - * Set number or retries (default is equal to number of nodes) - * - * @param int $retries - */ - public function setRetries(int $retries): ClientBuilder - { - $this->retries = $retries; - - return $this; - } - - /** - * Set the selector algorithm - * - * @param \OpenSearch\ConnectionPool\Selectors\SelectorInterface|string $selector - */ - public function setSelector($selector): ClientBuilder - { - $this->parseStringOrObject($selector, $this->selector, 'SelectorInterface'); - - return $this; - } - - /** - * Set the credential provider for SigV4 request signing. The value provider should be a - * callable object that will return - * - * @param callable|bool|array|CredentialsInterface|null $credentialProvider - */ - public function setSigV4CredentialProvider($credentialProvider): ClientBuilder - { - if ($credentialProvider !== null && $credentialProvider !== false) { - $this->sigV4CredentialProvider = $this->normalizeCredentialProvider($credentialProvider); - } - - return $this; - } - - /** - * Set the region for SigV4 signing. - * - * @param string|null $region - */ - public function setSigV4Region($region): ClientBuilder - { - $this->sigV4Region = $region; - - return $this; - } - - /** - * Set the service for SigV4 signing. - * - * @param string|null $service - */ - public function setSigV4Service($service): ClientBuilder - { - $this->sigV4Service = $service; - - return $this; - } - - /** - * Set sniff on start - * - * @param bool $sniffOnStart enable or disable sniff on start - */ - - public function setSniffOnStart(bool $sniffOnStart): ClientBuilder - { - $this->sniffOnStart = $sniffOnStart; - - return $this; - } - - /** - * Set SSL certificate - * - * @param string $cert The name of a file containing a PEM formatted certificate. - * @param string $password if the certificate requires a password - */ - public function setSSLCert(string $cert, ?string $password = null): ClientBuilder - { - $this->sslCert = [$cert, $password]; - - return $this; - } - - /** - * Set SSL key - * - * @param string $key The name of a file containing a private SSL key - * @param string $password if the private key requires a password - */ - public function setSSLKey(string $key, ?string $password = null): ClientBuilder - { - $this->sslKey = [$key, $password]; - - return $this; - } - - /** - * Set SSL verification - * - * @param bool|string $value - */ - public function setSSLVerification($value = true): ClientBuilder - { - $this->sslVerification = $value; - - return $this; - } - - /** - * Include the port in Host header - * - * @see https://github.com/elastic/elasticsearch-php/issues/993 - */ - public function includePortInHostHeader(bool $enable): ClientBuilder - { - $this->includePortInHostHeader = $enable; - - return $this; - } - - /** - * Build and returns the Client object - */ - public function build(): Client - { - $this->buildLoggers(); - - if (is_null($this->handler)) { - $this->handler = ClientBuilder::defaultHandler(); - } - - if (!is_null($this->sigV4CredentialProvider)) { - if (is_null($this->sigV4Region)) { - throw new RuntimeException("A region must be supplied for SigV4 request signing."); - } - - if (is_null($this->sigV4Service)) { - $this->setSigV4Service("es"); - } - - $this->handler = new SigV4Handler($this->sigV4Region, $this->sigV4Service, $this->sigV4CredentialProvider, $this->handler); - } - - $sslOptions = null; - if (isset($this->sslKey)) { - $sslOptions['ssl_key'] = $this->sslKey; - } - if (isset($this->sslCert)) { - $sslOptions['cert'] = $this->sslCert; - } - if (isset($this->sslVerification)) { - $sslOptions['verify'] = $this->sslVerification; - } - - if (!is_null($sslOptions)) { - $sslHandler = function (callable $handler, array $sslOptions) { - return function (array $request) use ($handler, $sslOptions) { - // Add our custom headers - foreach ($sslOptions as $key => $value) { - $request['client'][$key] = $value; - } - - // Send the request using the handler and return the response. - return $handler($request); - }; - }; - $this->handler = $sslHandler($this->handler, $sslOptions); - } - - if (is_null($this->serializer)) { - $this->serializer = new SmartSerializer(); - } elseif (is_string($this->serializer)) { - $this->serializer = new $this->serializer(); - } - - $this->connectionParams['client']['port_in_header'] = $this->includePortInHostHeader; - - if (! is_null($this->basicAuthentication)) { - if (isset($this->connectionParams['client']['curl']) === false) { - $this->connectionParams['client']['curl'] = []; - } - - $this->connectionParams['client']['curl'] += [ - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, - CURLOPT_USERPWD => $this->basicAuthentication - ]; - } - - if (is_null($this->connectionFactory)) { - // Make sure we are setting Content-Type and Accept (unless the user has explicitly - // overridden it - if (! isset($this->connectionParams['client']['headers'])) { - $this->connectionParams['client']['headers'] = []; - } - if (! isset($this->connectionParams['client']['headers']['Content-Type'])) { - $this->connectionParams['client']['headers']['Content-Type'] = ['application/json']; - } - if (! isset($this->connectionParams['client']['headers']['Accept'])) { - $this->connectionParams['client']['headers']['Accept'] = ['application/json']; - } - - $this->connectionFactory = new ConnectionFactory($this->handler, $this->connectionParams, $this->serializer, $this->logger, $this->tracer); - } - - if (is_null($this->hosts)) { - $this->hosts = $this->getDefaultHost(); - } - - if (is_null($this->selector)) { - $this->selector = new RoundRobinSelector(); - } elseif (is_string($this->selector)) { - $this->selector = new $this->selector(); - } - - $this->buildTransport(); - - if (is_null($this->endpointFactory)) { - $this->endpointFactory = new EndpointFactory($this->serializer); - } - - $registeredNamespaces = []; - foreach ($this->registeredNamespacesBuilders as $builder) { - /** - * @var NamespaceBuilderInterface $builder - */ - $registeredNamespaces[$builder->getName()] = $builder->getObject($this->transport, $this->serializer); - } - - return $this->instantiate($this->transport, $this->endpointFactory, $registeredNamespaces); - } - - protected function instantiate(Transport $transport, EndpointFactoryInterface $endpointFactory, array $registeredNamespaces): Client - { - return new Client($transport, $endpointFactory, $registeredNamespaces); - } - - private function buildLoggers(): void - { - if (is_null($this->logger)) { - $this->logger = new NullLogger(); - } - - if (is_null($this->tracer)) { - $this->tracer = new NullLogger(); - } - } - - private function buildTransport(): void - { - $connections = $this->buildConnectionsFromHosts($this->hosts); - - if (is_string($this->connectionPool)) { - $this->connectionPool = new $this->connectionPool( - $connections, - $this->selector, - $this->connectionFactory, - $this->connectionPoolArgs - ); - } - - if (is_null($this->retries)) { - $this->retries = count($connections); - } - - if (is_null($this->transport)) { - $this->transport = new Transport($this->retries, $this->connectionPool, $this->logger, $this->sniffOnStart); - } - } - - private function parseStringOrObject($arg, &$destination, $interface): void - { - if (is_string($arg)) { - $destination = new $arg(); - } elseif (is_object($arg)) { - $destination = $arg; - } else { - throw new InvalidArgumentException("Serializer must be a class path or instantiated object implementing $interface"); - } - } - - private function getDefaultHost(): array - { - return ['localhost:9200']; - } - - /** - * @return ConnectionInterface[] - * @throws RuntimeException - */ - private function buildConnectionsFromHosts(array $hosts): array - { - $connections = []; - foreach ($hosts as $host) { - if (is_string($host)) { - $host = $this->prependMissingScheme($host); - $host = $this->extractURIParts($host); - } elseif (is_array($host)) { - $host = $this->normalizeExtendedHost($host); - } else { - $this->logger->error("Could not parse host: ".print_r($host, true)); - throw new RuntimeException("Could not parse host: ".print_r($host, true)); - } - - $connections[] = $this->connectionFactory->create($host); - } - - return $connections; - } - - /** - * @throws RuntimeException - */ - private function normalizeExtendedHost(array $host): array - { - if (isset($host['host']) === false) { - $this->logger->error("Required 'host' was not defined in extended format: ".print_r($host, true)); - throw new RuntimeException("Required 'host' was not defined in extended format: ".print_r($host, true)); - } - - if (isset($host['scheme']) === false) { - $host['scheme'] = 'http'; - } - if (isset($host['port']) === false) { - $host['port'] = 9200; - } - return $host; - } - - /** - * @throws InvalidArgumentException - */ - private function extractURIParts(string $host): array - { - $parts = parse_url($host); - - if ($parts === false) { - throw new InvalidArgumentException(sprintf('Could not parse URI: "%s"', $host)); - } - - if (isset($parts['port']) !== true) { - $parts['port'] = 9200; - } - - return $parts; - } - - private function prependMissingScheme(string $host): string - { - if (!preg_match("/^https?:\/\//", $host)) { - $host = 'http://' . $host; - } - - return $host; - } - - private function normalizeCredentialProvider($provider): ?callable - { - if ($provider === null || $provider === false) { - return null; - } - - if (is_callable($provider)) { - return $provider; - } - - SigV4Handler::assertDependenciesInstalled(); - - if ($provider === true) { - return CredentialProvider::defaultProvider(); - } - - if ($provider instanceof CredentialsInterface) { - return CredentialProvider::fromCredentials($provider); - } elseif (is_array($provider) && isset($provider['key']) && isset($provider['secret'])) { - return CredentialProvider::fromCredentials( - new Credentials( - $provider['key'], - $provider['secret'], - isset($provider['token']) ? $provider['token'] : null, - isset($provider['expires']) ? $provider['expires'] : null - ) - ); - } - - throw new InvalidArgumentException('Credentials must be an instance of Aws\Credentials\CredentialsInterface, an' - . ' associative array that contains "key", "secret", and an optional "token" key-value pairs, a credentials' - . ' provider function, or true.'); - } -} diff --git a/src/OpenSearch/Common/EmptyLogger.php b/src/OpenSearch/Common/EmptyLogger.php deleted file mode 100644 index 84a3c2f19..000000000 --- a/src/OpenSearch/Common/EmptyLogger.php +++ /dev/null @@ -1,47 +0,0 @@ - - */ - protected $connectionPoolParams; - - /** - * @var ConnectionFactoryInterface - */ - protected $connectionFactory; - - /** - * Constructor - * - * @param ConnectionInterface[] $connections The Connections to choose from - * @param SelectorInterface $selector A Selector instance to perform the selection logic for the available connections - * @param ConnectionFactoryInterface $factory ConnectionFactory instance - * @param array $connectionPoolParams - */ - public function __construct(array $connections, SelectorInterface $selector, ConnectionFactoryInterface $factory, array $connectionPoolParams) - { - $paramList = array('connections', 'selector', 'connectionPoolParams'); - foreach ($paramList as $param) { - if (isset($$param) === false) { - throw new InvalidArgumentException('`' . $param . '` parameter must not be null'); - } - } - - if (isset($connectionPoolParams['randomizeHosts']) === true - && $connectionPoolParams['randomizeHosts'] === true - ) { - shuffle($connections); - } - - $this->connections = $connections; - $this->seedConnections = $connections; - $this->selector = $selector; - $this->connectionPoolParams = $connectionPoolParams; - $this->connectionFactory = $factory; - } - - abstract public function nextConnection(bool $force = false): ConnectionInterface; - - abstract public function scheduleCheck(): void; -} diff --git a/src/OpenSearch/ConnectionPool/ConnectionPoolInterface.php b/src/OpenSearch/ConnectionPool/ConnectionPoolInterface.php deleted file mode 100644 index 542c8b068..000000000 --- a/src/OpenSearch/ConnectionPool/ConnectionPoolInterface.php +++ /dev/null @@ -1,37 +0,0 @@ -current % count($connections)]; - - $this->current += 1; - - return $returnConnection; - } -} diff --git a/src/OpenSearch/ConnectionPool/Selectors/SelectorInterface.php b/src/OpenSearch/ConnectionPool/Selectors/SelectorInterface.php deleted file mode 100644 index 37a654ac3..000000000 --- a/src/OpenSearch/ConnectionPool/Selectors/SelectorInterface.php +++ /dev/null @@ -1,40 +0,0 @@ -current]->isAlive()) { - return $connections[$this->current]; - } - - $this->currentCounter += 1; - $this->current = $this->currentCounter % count($connections); - - return $connections[$this->current]; - } -} diff --git a/src/OpenSearch/ConnectionPool/SimpleConnectionPool.php b/src/OpenSearch/ConnectionPool/SimpleConnectionPool.php deleted file mode 100644 index fe59830d2..000000000 --- a/src/OpenSearch/ConnectionPool/SimpleConnectionPool.php +++ /dev/null @@ -1,55 +0,0 @@ - $connectionPoolParams - */ - public function __construct($connections, SelectorInterface $selector, ConnectionFactoryInterface $factory, $connectionPoolParams) - { - parent::__construct($connections, $selector, $factory, $connectionPoolParams); - } - - public function nextConnection(bool $force = false): ConnectionInterface - { - return $this->selector->select($this->connections); - } - - public function scheduleCheck(): void - { - } -} diff --git a/src/OpenSearch/ConnectionPool/SniffingConnectionPool.php b/src/OpenSearch/ConnectionPool/SniffingConnectionPool.php deleted file mode 100644 index 5c5d99da9..000000000 --- a/src/OpenSearch/ConnectionPool/SniffingConnectionPool.php +++ /dev/null @@ -1,189 +0,0 @@ - $connectionPoolParams - */ - public function __construct( - $connections, - SelectorInterface $selector, - ConnectionFactoryInterface $factory, - $connectionPoolParams - ) { - parent::__construct($connections, $selector, $factory, $connectionPoolParams); - - $this->setConnectionPoolParams($connectionPoolParams); - $this->nextSniff = time() + $this->sniffingInterval; - } - - public function nextConnection(bool $force = false): ConnectionInterface - { - $this->sniff($force); - - $size = count($this->connections); - while ($size--) { - /** - * @var Connection $connection - */ - $connection = $this->selector->select($this->connections); - if ($connection->isAlive() === true || $connection->ping() === true) { - return $connection; - } - } - - if ($force === true) { - throw new NoNodesAvailableException("No alive nodes found in your cluster"); - } - - return $this->nextConnection(true); - } - - public function scheduleCheck(): void - { - $this->nextSniff = -1; - } - - private function sniff(bool $force = false): void - { - if ($force === false && $this->nextSniff > time()) { - return; - } - - $total = count($this->connections); - - while ($total--) { - /** - * @var Connection $connection - */ - $connection = $this->selector->select($this->connections); - - if ($connection->isAlive() xor $force) { - continue; - } - - if ($this->sniffConnection($connection) === true) { - return; - } - } - - if ($force === true) { - return; - } - - foreach ($this->seedConnections as $connection) { - /** - * @var Connection $connection - */ - if ($this->sniffConnection($connection) === true) { - return; - } - } - } - - private function sniffConnection(Connection $connection): bool - { - try { - $response = $connection->sniff(); - } catch (OperationTimeoutException $exception) { - return false; - } - - $nodes = $this->parseClusterState($response); - - if (count($nodes) === 0) { - return false; - } - - $this->connections = []; - - foreach ($nodes as $node) { - $nodeDetails = [ - 'host' => $node['host'], - 'port' => $node['port'], - ]; - $this->connections[] = $this->connectionFactory->create($nodeDetails); - } - - $this->nextSniff = time() + $this->sniffingInterval; - - return true; - } - - /** - * @return list - */ - private function parseClusterState($nodeInfo): array - { - $pattern = '/([^:]*):(\d+)/'; - $hosts = []; - - foreach ($nodeInfo['nodes'] as $node) { - if (isset($node['http']) === true && isset($node['http']['publish_address']) === true) { - if (preg_match($pattern, $node['http']['publish_address'], $match) === 1) { - $hosts[] = [ - 'host' => $match[1], - 'port' => (int)$match[2], - ]; - } - } - } - - return $hosts; - } - - /** - * @param array $connectionPoolParams - */ - private function setConnectionPoolParams(array $connectionPoolParams): void - { - $this->sniffingInterval = (int)($connectionPoolParams['sniffingInterval'] ?? 300); - } -} diff --git a/src/OpenSearch/ConnectionPool/StaticConnectionPool.php b/src/OpenSearch/ConnectionPool/StaticConnectionPool.php deleted file mode 100644 index 9aa740ded..000000000 --- a/src/OpenSearch/ConnectionPool/StaticConnectionPool.php +++ /dev/null @@ -1,113 +0,0 @@ - $connectionPoolParams - */ - public function __construct($connections, SelectorInterface $selector, ConnectionFactoryInterface $factory, $connectionPoolParams) - { - parent::__construct($connections, $selector, $factory, $connectionPoolParams); - $this->scheduleCheck(); - } - - public function nextConnection(bool $force = false): ConnectionInterface - { - $skipped = []; - - $total = count($this->connections); - while ($total--) { - /** - * @var Connection $connection - */ - $connection = $this->selector->select($this->connections); - if ($connection->isAlive() === true) { - return $connection; - } - - if ($this->readyToRevive($connection) === true) { - if ($connection->ping() === true) { - return $connection; - } - } else { - $skipped[] = $connection; - } - } - - // All "alive" nodes failed, force pings on "dead" nodes - foreach ($skipped as $connection) { - if ($connection->ping() === true) { - return $connection; - } - } - - throw new NoNodesAvailableException("No alive nodes found in your cluster"); - } - - public function scheduleCheck(): void - { - foreach ($this->connections as $connection) { - $connection->markDead(); - } - } - - private function readyToRevive(Connection $connection): bool - { - $timeout = min( - $this->pingTimeout * pow(2, $connection->getPingFailures()), - $this->maxPingTimeout - ); - - if ($connection->getLastPing() + $timeout < time()) { - return true; - } else { - return false; - } - } -} diff --git a/src/OpenSearch/ConnectionPool/StaticNoPingConnectionPool.php b/src/OpenSearch/ConnectionPool/StaticNoPingConnectionPool.php deleted file mode 100644 index 42d634c7b..000000000 --- a/src/OpenSearch/ConnectionPool/StaticNoPingConnectionPool.php +++ /dev/null @@ -1,96 +0,0 @@ - $connectionPoolParams - */ - public function __construct($connections, SelectorInterface $selector, ConnectionFactoryInterface $factory, $connectionPoolParams) - { - parent::__construct($connections, $selector, $factory, $connectionPoolParams); - } - - public function nextConnection(bool $force = false): ConnectionInterface - { - $total = count($this->connections); - while ($total--) { - /** - * @var Connection $connection -*/ - $connection = $this->selector->select($this->connections); - if ($connection->isAlive() === true) { - return $connection; - } - - if ($this->readyToRevive($connection) === true) { - return $connection; - } - } - - throw new NoNodesAvailableException("No alive nodes found in your cluster"); - } - - public function scheduleCheck(): void - { - } - - private function readyToRevive(Connection $connection): bool - { - $timeout = min( - $this->pingTimeout * pow(2, $connection->getPingFailures()), - $this->maxPingTimeout - ); - - if ($connection->getLastPing() + $timeout < time()) { - return true; - } else { - return false; - } - } -} diff --git a/src/OpenSearch/Connections/Connection.php b/src/OpenSearch/Connections/Connection.php deleted file mode 100644 index 7deac7583..000000000 --- a/src/OpenSearch/Connections/Connection.php +++ /dev/null @@ -1,794 +0,0 @@ -> - */ - protected $headers = []; - - /** - * @var bool - */ - protected $isAlive = false; - - /** - * @var float - */ - private $pingTimeout = 1; //TODO expose this - - /** - * @var int - */ - private $lastPing = 0; - - /** - * @var int - */ - private $failedPings = 0; - - /** - * @var mixed[] - */ - private $lastRequest = array(); - - /** - * @var string - */ - private $OSVersion = null; - - /** - * @param array{host: string, port?: int, scheme?: string, user?: string, pass?: string, path?: string} $hostDetails - * @param array{client?: array{headers?: array>, curl?: array}} $connectionParams - */ - public function __construct( - callable $handler, - array $hostDetails, - array $connectionParams, - SerializerInterface $serializer, - LoggerInterface $log, - LoggerInterface $trace - ) { - if (isset($hostDetails['port']) !== true) { - $hostDetails['port'] = 9200; - } - - if (isset($hostDetails['scheme'])) { - $this->transportSchema = $hostDetails['scheme']; - } - - // Only Set the Basic if API Key is not set and setBasicAuthentication was not called prior - if (isset($connectionParams['client']['headers']['Authorization']) === false - && isset($connectionParams['client']['curl'][CURLOPT_HTTPAUTH]) === false - && isset($hostDetails['user']) - && isset($hostDetails['pass']) - ) { - $connectionParams['client']['curl'][CURLOPT_HTTPAUTH] = CURLAUTH_BASIC; - $connectionParams['client']['curl'][CURLOPT_USERPWD] = $hostDetails['user'].':'.$hostDetails['pass']; - } - - $connectionParams['client']['curl'][CURLOPT_PORT] = $hostDetails['port']; - - if (isset($connectionParams['client']['headers'])) { - $this->headers = $connectionParams['client']['headers']; - unset($connectionParams['client']['headers']); - } - - // Add the User-Agent using the format: / (metadata-values) - $this->headers['User-Agent'] = [sprintf( - 'opensearch-php/%s (%s %s; PHP %s)', - Client::VERSION, - PHP_OS, - $this->getOSVersion(), - PHP_VERSION - )]; - - $host = $hostDetails['host']; - $path = null; - if (isset($hostDetails['path']) === true) { - $path = $hostDetails['path']; - } - $port = $hostDetails['port']; - - $this->host = $host; - $this->path = $path; - $this->port = $port; - $this->log = $log; - $this->trace = $trace; - $this->connectionParams = $connectionParams; - $this->serializer = $serializer; - - $this->handler = $this->wrapHandler($handler); - } - - /** - * @param string $method - * @param string $uri - * @param null|array $params - * @param mixed $body - * @param array $options - * @param Transport|null $transport - * @return mixed - */ - public function performRequest(string $method, string $uri, ?array $params = [], $body = null, array $options = [], ?Transport $transport = null) - { - if ($body !== null) { - $body = $this->serializer->serialize($body); - } - - $headers = $this->headers; - if (isset($options['client']['headers']) && is_array($options['client']['headers'])) { - $headers = array_merge($this->headers, $options['client']['headers']); - } - - $host = $this->host; - if (isset($this->connectionParams['client']['port_in_header']) && $this->connectionParams['client']['port_in_header']) { - $host .= ':' . $this->port; - } - - $request = [ - 'http_method' => $method, - 'scheme' => $this->transportSchema, - 'uri' => $this->getURI($uri, $params), - 'body' => $body, - 'headers' => array_merge( - [ - 'Host' => [$host] - ], - $headers - ) - ]; - - $request = array_replace_recursive($request, $this->connectionParams, $options); - - // RingPHP does not like if client is empty - if (empty($request['client'])) { - unset($request['client']); - } - - $handler = $this->handler; - $future = $handler($request, $this, $transport, $options); - - return $future; - } - - public function getTransportSchema(): string - { - return $this->transportSchema; - } - - public function getLastRequestInfo(): array - { - return $this->lastRequest; - } - - private function wrapHandler(callable $handler): callable - { - return function (array $request, Connection $connection, ?Transport $transport, $options) use ($handler) { - $this->lastRequest = []; - $this->lastRequest['request'] = $request; - - // Send the request using the wrapped handler. - $response = Core::proxy( - $handler($request), - function ($response) use ($connection, $transport, $request, $options) { - $this->lastRequest['response'] = $response; - - if (isset($response['error']) === true) { - if ($response['error'] instanceof ConnectException || $response['error'] instanceof RingException) { - $this->log->warning("Curl exception encountered."); - - $exception = $this->getCurlRetryException($request, $response); - - $this->logRequestFail($request, $response, $exception); - - $node = $connection->getHost(); - $this->log->warning("Marking node $node dead."); - $connection->markDead(); - - // If the transport has not been set, we are inside a Ping or Sniff, - // so we don't want to retrigger retries anyway. - // - // TODO this could be handled better, but we are limited because connectionpools do not - // have access to Transport. Architecturally, all of this needs to be refactored - if (isset($transport) === true) { - $transport->connectionPool->scheduleCheck(); - - $neverRetry = isset($request['client']['never_retry']) ? $request['client']['never_retry'] : false; - $shouldRetry = $transport->shouldRetry($request); - $shouldRetryText = ($shouldRetry) ? 'true' : 'false'; - - $this->log->warning("Retries left? $shouldRetryText"); - if ($shouldRetry && !$neverRetry) { - return $transport->performRequest( - $request['http_method'], - $request['uri'], - [], - $request['body'], - $options - ); - } - } - - $this->log->warning("Out of retries, throwing exception from $node"); - // Only throw if we run out of retries - throw $exception; - } else { - // Something went seriously wrong, bail - $exception = new TransportException($response['error']->getMessage()); - $this->logRequestFail($request, $response, $exception); - throw $exception; - } - } else { - $connection->markAlive(); - - if (isset($response['headers']['Warning'])) { - $this->logWarning($request, $response); - } - if (isset($response['body']) === true) { - $response['body'] = stream_get_contents($response['body']); - $this->lastRequest['response']['body'] = $response['body']; - } - - if ($response['status'] >= 400 && $response['status'] < 500) { - $ignore = $request['client']['ignore'] ?? []; - // Skip 404 if succeeded true in the body (e.g. clear_scroll) - $body = $response['body'] ?? ''; - if (strpos($body, '"succeeded":true') !== false) { - $ignore[] = 404; - } - $this->process4xxError($request, $response, $ignore); - } elseif ($response['status'] >= 500) { - $ignore = $request['client']['ignore'] ?? []; - $this->process5xxError($request, $response, $ignore); - } - - // No error, deserialize - $response['body'] = $this->serializer->deserialize($response['body'], $response['transfer_stats']); - } - $this->logRequestSuccess($request, $response); - - return isset($request['client']['verbose']) && $request['client']['verbose'] === true ? $response : $response['body']; - } - ); - - return $response; - }; - } - - /** - * @param array|null $params - */ - private function getURI(string $uri, ?array $params): string - { - if (isset($params) === true && !empty($params)) { - $params = array_map( - function ($value) { - if ($value === true) { - return 'true'; - } elseif ($value === false) { - return 'false'; - } - - return $value; - }, - $params - ); - - $uri .= '?' . http_build_query($params); - } - - if ($this->path !== null) { - $uri = $this->path . $uri; - } - - return $uri; - } - - /** - * @return array> - */ - public function getHeaders(): array - { - return $this->headers; - } - - public function logWarning(array $request, array $response): void - { - $this->log->warning('Deprecation', $response['headers']['Warning']); - } - - /** - * Log a successful request - * - * @param array $request - * @param array $response - * @return void - */ - public function logRequestSuccess(array $request, array $response): void - { - $port = $request['client']['curl'][CURLOPT_PORT] ?? $response['transfer_stats']['primary_port'] ?? ''; - $uri = $this->addPortInUrl($response['effective_url'], (int) $port); - - $this->log->debug('Request Body', array($request['body'])); - $this->log->info( - 'Request Success:', - array( - 'method' => $request['http_method'], - 'uri' => $uri, - 'port' => $port, - 'headers' => $request['headers'], - 'HTTP code' => $response['status'], - 'duration' => $response['transfer_stats']['total_time'], - ) - ); - $this->log->debug('Response', array($response['body'])); - - // Build the curl command for Trace. - $curlCommand = $this->buildCurlCommand($request['http_method'], $uri, $request['body']); - $this->trace->info($curlCommand); - $this->trace->debug( - 'Response:', - array( - 'response' => $response['body'], - 'method' => $request['http_method'], - 'uri' => $uri, - 'port' => $port, - 'HTTP code' => $response['status'], - 'duration' => $response['transfer_stats']['total_time'], - ) - ); - } - - /** - * Log a failed request - * - * @param array $request - * @param array $response - * @param \Throwable $exception - * - * @return void - */ - public function logRequestFail(array $request, array $response, \Throwable $exception): void - { - $port = $request['client']['curl'][CURLOPT_PORT] ?? $response['transfer_stats']['primary_port'] ?? ''; - $uri = $this->addPortInUrl($response['effective_url'], (int) $port); - - $this->log->debug('Request Body', array($request['body'])); - $this->log->warning( - 'Request Failure:', - array( - 'method' => $request['http_method'], - 'uri' => $uri, - 'port' => $port, - 'headers' => $request['headers'], - 'HTTP code' => $response['status'], - 'duration' => $response['transfer_stats']['total_time'], - 'error' => $exception->getMessage(), - ) - ); - $this->log->warning('Response', array($response['body'])); - - // Build the curl command for Trace. - $curlCommand = $this->buildCurlCommand($request['http_method'], $uri, $request['body']); - $this->trace->info($curlCommand); - $this->trace->debug( - 'Response:', - array( - 'response' => $response, - 'method' => $request['http_method'], - 'uri' => $uri, - 'port' => $port, - 'HTTP code' => $response['status'], - 'duration' => $response['transfer_stats']['total_time'], - ) - ); - } - - public function ping(): bool - { - $options = [ - 'client' => [ - 'timeout' => $this->pingTimeout, - 'never_retry' => true, - 'verbose' => true - ] - ]; - try { - $response = $this->performRequest('HEAD', '/', null, null, $options); - $response = $response->wait(); - } catch (TransportException $exception) { - $this->markDead(); - - return false; - } - - if ($response['status'] === 200) { - $this->markAlive(); - - return true; - } else { - $this->markDead(); - - return false; - } - } - - /** - * @return array|\GuzzleHttp\Ring\Future\FutureArray - */ - public function sniff() - { - $options = [ - 'client' => [ - 'timeout' => $this->pingTimeout, - 'never_retry' => true - ] - ]; - - return $this->performRequest('GET', '/_nodes/', null, null, $options); - } - - public function isAlive(): bool - { - return $this->isAlive; - } - - public function markAlive(): void - { - $this->failedPings = 0; - $this->isAlive = true; - $this->lastPing = time(); - } - - public function markDead(): void - { - $this->isAlive = false; - $this->failedPings += 1; - $this->lastPing = time(); - } - - public function getLastPing(): int - { - return $this->lastPing; - } - - public function getPingFailures(): int - { - return $this->failedPings; - } - - public function getHost(): string - { - return $this->host; - } - - public function getUserPass(): ?string - { - return $this->connectionParams['client']['curl'][CURLOPT_USERPWD] ?? null; - } - - public function getPath(): ?string - { - return $this->path; - } - - /** - * @return int - */ - public function getPort() - { - return $this->port; - } - - protected function getCurlRetryException(array $request, array $response): OpenSearchException - { - $exception = null; - $message = $response['error']->getMessage(); - $exception = new MaxRetriesException($message); - switch ($response['curl']['errno']) { - case 6: - $exception = new CouldNotResolveHostException($message, 0, $exception); - break; - case 7: - $exception = new CouldNotConnectToHost($message, 0, $exception); - break; - case 28: - $exception = new OperationTimeoutException($message, 0, $exception); - break; - } - - return $exception; - } - - /** - * Get the OS version using php_uname if available - * otherwise it returns an empty string - * - * @see https://github.com/elastic/elasticsearch-php/issues/922 - */ - private function getOSVersion(): string - { - if ($this->OSVersion === null) { - $this->OSVersion = strpos(strtolower(ini_get('disable_functions')), 'php_uname') !== false - ? '' - : php_uname("r"); - } - return $this->OSVersion; - } - - /** - * Add the port value in the URL if not present - */ - private function addPortInUrl(string $uri, int $port): string - { - if (strpos($uri, ':', 7) !== false) { - return $uri; - } - return preg_replace('#([^/])/([^/])#', sprintf("$1:%s/$2", $port), $uri, 1); - } - - /** - * Construct a string cURL command - */ - private function buildCurlCommand(string $method, string $url, ?string $body): string - { - if (strpos($url, '?') === false) { - $url .= '?pretty=true'; - } else { - str_replace('?', '?pretty=true', $url); - } - - $curlCommand = 'curl -X' . strtoupper($method); - $curlCommand .= " '" . $url . "'"; - - if (isset($body) === true && $body !== '') { - $curlCommand .= " -d '" . $body . "'"; - } - - return $curlCommand; - } - - /** - * @throws OpenSearchException - */ - private function process4xxError(array $request, array $response, array $ignore): void - { - $statusCode = $response['status']; - - /** - * @var \Exception $exception - */ - $exception = $this->tryDeserialize400Error($response); - - if (array_search($response['status'], $ignore) !== false) { - return; - } - - $responseBody = $this->convertBodyToString($response['body'], $statusCode, $exception); - if ($statusCode === 401) { - $exception = new Unauthorized401Exception($responseBody); - } elseif ($statusCode === 403) { - $exception = new Forbidden403Exception($responseBody); - } elseif ($statusCode === 404) { - $exception = new Missing404Exception($responseBody); - } elseif ($statusCode === 409) { - $exception = new Conflict409Exception($responseBody, $statusCode); - } elseif ($statusCode === 400 && strpos($responseBody, 'script_lang not supported') !== false) { - $exception = new ScriptLangNotSupportedException($responseBody); - } elseif ($statusCode === 408) { - $exception = new RequestTimeout408Exception($responseBody); - } else { - $exception = new BadRequest400Exception($responseBody); - } - - $this->logRequestFail($request, $response, $exception); - - throw $exception; - } - - /** - * @throws OpenSearchException - */ - private function process5xxError(array $request, array $response, array $ignore): void - { - $statusCode = (int) $response['status']; - $responseBody = $response['body']; - - /** - * @var \Exception $exception - */ - $exception = $this->tryDeserialize500Error($response); - - $exceptionText = "[$statusCode Server Exception] ".$exception->getMessage(); - $this->log->error($exceptionText); - $this->log->error($exception->getTraceAsString()); - - if (array_search($statusCode, $ignore) !== false) { - return; - } - - if ($statusCode === 500 && strpos($responseBody, "RoutingMissingException") !== false) { - $exception = new RoutingMissingException($exception->getMessage(), [], 0, $exception); - } elseif ($statusCode === 500 && preg_match('/ActionRequestValidationException.+ no documents to get/', $responseBody) === 1) { - $exception = new NoDocumentsToGetException($exception->getMessage(), [], 0, $exception); - } elseif ($statusCode === 500 && strpos($responseBody, 'NoShardAvailableActionException') !== false) { - $exception = new NoShardAvailableException($exception->getMessage(), [], 0, $exception); - } else { - $exception = new ServerErrorResponseException( - $this->convertBodyToString($responseBody, $statusCode, $exception), - ); - } - - $this->logRequestFail($request, $response, $exception); - - throw $exception; - } - - private function convertBodyToString($body, int $statusCode, Exception $exception): string - { - if (empty($body)) { - return sprintf( - "Unknown %d error from OpenSearch %s", - $statusCode, - $exception->getMessage() - ); - } - // if body is not string, we convert it so it can be used as Exception message - if (!is_string($body)) { - return json_encode($body); - } - return $body; - } - - private function tryDeserialize400Error(array $response): OpenSearchException - { - return $this->tryDeserializeError($response, BadRequest400Exception::class); - } - - private function tryDeserialize500Error(array $response): OpenSearchException - { - return $this->tryDeserializeError($response, ServerErrorResponseException::class); - } - - private function tryDeserializeError(array $response, string $errorClass): OpenSearchException - { - $error = $this->serializer->deserialize($response['body'], $response['transfer_stats']); - if (is_array($error) === true) { - if (isset($error['error']) === false) { - // <2.0 "i just blew up" nonstructured exception - // $error is an array but we don't know the format, reuse the response body instead - // added json_encode to convert into a string - return new $errorClass(json_encode($response['body']), (int) $response['status']); - } - - // 2.0 structured exceptions - if (is_array($error['error']) && array_key_exists('reason', $error['error']) === true) { - // Try to use root cause first (only grabs the first root cause) - $info = $error['error']['root_cause'][0] ?? $error['error']; - $cause = $info['reason']; - $type = $info['type']; - // added json_encode to convert into a string - $original = new $errorClass(json_encode($response['body']), $response['status']); - - return new $errorClass("$type: $cause", (int) $response['status'], $original); - } - // <2.0 semi-structured exceptions - // added json_encode to convert into a string - $original = new $errorClass(json_encode($response['body']), $response['status']); - - $errorEncoded = $error['error']; - if (is_array($errorEncoded)) { - $errorEncoded = json_encode($errorEncoded); - } - return new $errorClass($errorEncoded, (int) $response['status'], $original); - } - - // if responseBody is not string, we convert it so it can be used as Exception message - $responseBody = $response['body']; - if (!is_string($responseBody)) { - $responseBody = json_encode($responseBody); - } - - // <2.0 "i just blew up" nonstructured exception - return new $errorClass($responseBody); - } -} diff --git a/src/OpenSearch/Connections/ConnectionFactory.php b/src/OpenSearch/Connections/ConnectionFactory.php deleted file mode 100644 index 7aff2ccc7..000000000 --- a/src/OpenSearch/Connections/ConnectionFactory.php +++ /dev/null @@ -1,87 +0,0 @@ ->, curl?: array}} $connectionParams - */ - public function __construct(callable $handler, array $connectionParams, SerializerInterface $serializer, LoggerInterface $logger, LoggerInterface $tracer) - { - $this->handler = $handler; - $this->connectionParams = $connectionParams; - $this->logger = $logger; - $this->tracer = $tracer; - $this->serializer = $serializer; - } - - public function create(array $hostDetails): ConnectionInterface - { - if (isset($hostDetails['path'])) { - $hostDetails['path'] = rtrim($hostDetails['path'], '/'); - } - - return new Connection( - $this->handler, - $hostDetails, - $this->connectionParams, - $this->serializer, - $this->logger, - $this->tracer - ); - } -} diff --git a/src/OpenSearch/Connections/ConnectionFactoryInterface.php b/src/OpenSearch/Connections/ConnectionFactoryInterface.php deleted file mode 100644 index 97b4f0470..000000000 --- a/src/OpenSearch/Connections/ConnectionFactoryInterface.php +++ /dev/null @@ -1,36 +0,0 @@ -|null $params - * @param mixed $body - * @return mixed - */ - public function performRequest(string $method, string $uri, ?array $params = [], $body = null, array $options = [], ?Transport $transport = null); -} diff --git a/src/OpenSearch/EndpointInterface.php b/src/OpenSearch/EndpointInterface.php index f29783dfc..6f14950ce 100644 --- a/src/OpenSearch/EndpointInterface.php +++ b/src/OpenSearch/EndpointInterface.php @@ -53,7 +53,7 @@ public function getIndex(): ?string; * * @return $this */ - public function setIndex(string|array|null $index): static; + public function setIndex(array|string|null $index): static; /** * Get the document ID. diff --git a/src/OpenSearch/Endpoints/AbstractEndpoint.php b/src/OpenSearch/Endpoints/AbstractEndpoint.php index cc17e31c5..d080e5c5f 100644 --- a/src/OpenSearch/Endpoints/AbstractEndpoint.php +++ b/src/OpenSearch/Endpoints/AbstractEndpoint.php @@ -30,39 +30,43 @@ abstract class AbstractEndpoint implements EndpointInterface { /** - * @var array + * The parameters for this endpoint. + * + * @var array The parameters for this endpoint */ - protected $params = []; + protected array $params = []; /** - * @var string|null + * The index name for this endpoint. */ - protected $index = null; + protected ?string $index = null; /** - * @var string|int|null + * The document ID for this endpoint. */ - protected $id = null; + protected string|int|null $id = null; /** - * @var string|null + * The HTTP method for this endpoint. */ - protected $method = null; + protected ?string $method = null; /** - * @var string|array|null + * The body content for this endpoint. */ - protected $body = null; + protected array|string|null $body = null; /** - * @var array + * The options for this endpoint. + * + * @var array */ - private $options = []; + private array $options = []; /** - * @var SerializerInterface + * The serializer instance. */ - protected $serializer; + protected SerializerInterface $serializer; /** * @return string[] @@ -117,7 +121,7 @@ public function getIndex(): ?string * * @return $this */ - public function setIndex($index): static + public function setIndex(array|string|null $index): static { if ($index === null) { return $this; @@ -173,11 +177,7 @@ protected function getOptionalURI(string $endpoint): string private function getOptionalIndex(): string { - if (isset($this->index) === true) { - return $this->index; - } else { - return '_all'; - } + return $this->index ?? '_all'; } /** @@ -185,7 +185,7 @@ private function getOptionalIndex(): string * * @throws UnexpectedValueException */ - private function checkUserParams(array $params) + private function checkUserParams(array $params): void { if (empty($params)) { return; //no params, just return. @@ -213,7 +213,7 @@ private function checkUserParams(array $params) /** * @param array $params Note: this is passed by-reference! */ - private function extractOptions(&$params) + private function extractOptions(array &$params): void { // Extract out client options, then start transforming if (isset($params['client']) === true) { @@ -229,7 +229,7 @@ private function extractOptions(&$params) $this->options['client'] = $params['client']; unset($params['client']); } - $ignore = isset($this->options['client']['ignore']) ? $this->options['client']['ignore'] : null; + $ignore = $this->options['client']['ignore'] ?? null; if (isset($ignore) === true) { if (is_string($ignore)) { $this->options['client']['ignore'] = explode(",", $ignore); diff --git a/src/OpenSearch/Endpoints/AsyncSearch/Delete.php b/src/OpenSearch/Endpoints/AsyncSearch/Delete.php deleted file mode 100644 index c8a6a1c15..000000000 --- a/src/OpenSearch/Endpoints/AsyncSearch/Delete.php +++ /dev/null @@ -1,48 +0,0 @@ -id ?? null; - - if (isset($id)) { - return "/_async_search/$id"; - } - throw new RuntimeException('Missing parameter for the endpoint async_search.delete'); - } - - public function getParamWhitelist(): array - { - return []; - } - - public function getMethod(): string - { - return 'DELETE'; - } -} diff --git a/src/OpenSearch/Endpoints/AsyncSearch/Get.php b/src/OpenSearch/Endpoints/AsyncSearch/Get.php deleted file mode 100644 index 3f6b86c0e..000000000 --- a/src/OpenSearch/Endpoints/AsyncSearch/Get.php +++ /dev/null @@ -1,52 +0,0 @@ -id ?? null; - - if (isset($id)) { - return "/_async_search/$id"; - } - throw new RuntimeException('Missing parameter for the endpoint async_search.get'); - } - - public function getParamWhitelist(): array - { - return [ - 'wait_for_completion_timeout', - 'keep_alive', - 'typed_keys' - ]; - } - - public function getMethod(): string - { - return 'GET'; - } -} diff --git a/src/OpenSearch/Endpoints/AsyncSearch/Submit.php b/src/OpenSearch/Endpoints/AsyncSearch/Submit.php deleted file mode 100644 index 21edf79a6..000000000 --- a/src/OpenSearch/Endpoints/AsyncSearch/Submit.php +++ /dev/null @@ -1,99 +0,0 @@ -index ?? null; - - if (isset($index)) { - return "/$index/_async_search"; - } - return "/_async_search"; - } - - public function getParamWhitelist(): array - { - return [ - 'wait_for_completion_timeout', - 'keep_on_completion', - 'keep_alive', - 'batched_reduce_size', - 'request_cache', - 'analyzer', - 'analyze_wildcard', - 'default_operator', - 'df', - 'explain', - 'stored_fields', - 'docvalue_fields', - 'from', - 'ignore_unavailable', - 'ignore_throttled', - 'allow_no_indices', - 'expand_wildcards', - 'lenient', - 'preference', - 'q', - 'routing', - 'search_type', - 'size', - 'sort', - '_source', - '_source_excludes', - '_source_includes', - 'terminate_after', - 'stats', - 'suggest_field', - 'suggest_mode', - 'suggest_size', - 'suggest_text', - 'timeout', - 'track_scores', - 'track_total_hits', - 'allow_partial_search_results', - 'typed_keys', - 'version', - 'seq_no_primary_term', - 'max_concurrent_shard_requests' - ]; - } - - public function getMethod(): string - { - return 'POST'; - } - - public function setBody($body): static - { - if (isset($body) !== true) { - return $this; - } - $this->body = $body; - - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/DeleteTransform.php b/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/DeleteTransform.php deleted file mode 100644 index 1efbb6c17..000000000 --- a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/DeleteTransform.php +++ /dev/null @@ -1,62 +0,0 @@ -transform_id ?? null; - - if (isset($transform_id)) { - return "/_data_frame/transforms/$transform_id"; - } - throw new RuntimeException('Missing parameter for the endpoint data_frame_transform_deprecated.delete_transform'); - } - - public function getParamWhitelist(): array - { - return [ - 'force' - ]; - } - - public function getMethod(): string - { - return 'DELETE'; - } - - public function setTransformId($transform_id): DeleteTransform - { - if (isset($transform_id) !== true) { - return $this; - } - $this->transform_id = $transform_id; - - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/GetTransform.php b/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/GetTransform.php deleted file mode 100644 index 98daa32d9..000000000 --- a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/GetTransform.php +++ /dev/null @@ -1,63 +0,0 @@ -transform_id ?? null; - - if (isset($transform_id)) { - return "/_data_frame/transforms/$transform_id"; - } - return "/_data_frame/transforms"; - } - - public function getParamWhitelist(): array - { - return [ - 'from', - 'size', - 'allow_no_match' - ]; - } - - public function getMethod(): string - { - return 'GET'; - } - - public function setTransformId($transform_id): GetTransform - { - if (isset($transform_id) !== true) { - return $this; - } - $this->transform_id = $transform_id; - - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/GetTransformStats.php b/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/GetTransformStats.php deleted file mode 100644 index 326c11662..000000000 --- a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/GetTransformStats.php +++ /dev/null @@ -1,64 +0,0 @@ -transform_id ?? null; - - if (isset($transform_id)) { - return "/_data_frame/transforms/$transform_id/_stats"; - } - throw new RuntimeException('Missing parameter for the endpoint data_frame_transform_deprecated.get_transform_stats'); - } - - public function getParamWhitelist(): array - { - return [ - 'from', - 'size', - 'allow_no_match' - ]; - } - - public function getMethod(): string - { - return 'GET'; - } - - public function setTransformId($transform_id): GetTransformStats - { - if (isset($transform_id) !== true) { - return $this; - } - $this->transform_id = $transform_id; - - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/PreviewTransform.php b/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/PreviewTransform.php deleted file mode 100644 index 3f949ea11..000000000 --- a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/PreviewTransform.php +++ /dev/null @@ -1,52 +0,0 @@ -body = $body; - - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/PutTransform.php b/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/PutTransform.php deleted file mode 100644 index 482e26087..000000000 --- a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/PutTransform.php +++ /dev/null @@ -1,72 +0,0 @@ -transform_id ?? null; - - if (isset($transform_id)) { - return "/_data_frame/transforms/$transform_id"; - } - throw new RuntimeException('Missing parameter for the endpoint data_frame_transform_deprecated.put_transform'); - } - - public function getParamWhitelist(): array - { - return [ - 'defer_validation' - ]; - } - - public function getMethod(): string - { - return 'PUT'; - } - - public function setBody($body): static - { - if (isset($body) !== true) { - return $this; - } - $this->body = $body; - - return $this; - } - - public function setTransformId($transform_id): PutTransform - { - if (isset($transform_id) !== true) { - return $this; - } - $this->transform_id = $transform_id; - - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/StartTransform.php b/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/StartTransform.php deleted file mode 100644 index 62d412fde..000000000 --- a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/StartTransform.php +++ /dev/null @@ -1,62 +0,0 @@ -transform_id ?? null; - - if (isset($transform_id)) { - return "/_data_frame/transforms/$transform_id/_start"; - } - throw new RuntimeException('Missing parameter for the endpoint data_frame_transform_deprecated.start_transform'); - } - - public function getParamWhitelist(): array - { - return [ - 'timeout' - ]; - } - - public function getMethod(): string - { - return 'POST'; - } - - public function setTransformId($transform_id): StartTransform - { - if (isset($transform_id) !== true) { - return $this; - } - $this->transform_id = $transform_id; - - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/StopTransform.php b/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/StopTransform.php deleted file mode 100644 index 9c38c62b1..000000000 --- a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/StopTransform.php +++ /dev/null @@ -1,64 +0,0 @@ -transform_id ?? null; - - if (isset($transform_id)) { - return "/_data_frame/transforms/$transform_id/_stop"; - } - throw new RuntimeException('Missing parameter for the endpoint data_frame_transform_deprecated.stop_transform'); - } - - public function getParamWhitelist(): array - { - return [ - 'wait_for_completion', - 'timeout', - 'allow_no_match' - ]; - } - - public function getMethod(): string - { - return 'POST'; - } - - public function setTransformId($transform_id): StopTransform - { - if (isset($transform_id) !== true) { - return $this; - } - $this->transform_id = $transform_id; - - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/UpdateTransform.php b/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/UpdateTransform.php deleted file mode 100644 index 6ba0aedd5..000000000 --- a/src/OpenSearch/Endpoints/DataFrameTransformDeprecated/UpdateTransform.php +++ /dev/null @@ -1,72 +0,0 @@ -transform_id ?? null; - - if (isset($transform_id)) { - return "/_data_frame/transforms/$transform_id/_update"; - } - throw new RuntimeException('Missing parameter for the endpoint data_frame_transform_deprecated.update_transform'); - } - - public function getParamWhitelist(): array - { - return [ - 'defer_validation' - ]; - } - - public function getMethod(): string - { - return 'POST'; - } - - public function setBody($body): static - { - if (isset($body) !== true) { - return $this; - } - $this->body = $body; - - return $this; - } - - public function setTransformId($transform_id): static - { - if (isset($transform_id) !== true) { - return $this; - } - $this->transform_id = $transform_id; - - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/Monitoring/Bulk.php b/src/OpenSearch/Endpoints/Monitoring/Bulk.php deleted file mode 100644 index 797a3f6b6..000000000 --- a/src/OpenSearch/Endpoints/Monitoring/Bulk.php +++ /dev/null @@ -1,74 +0,0 @@ -serializer = $serializer; - } - - public function getURI(): string - { - return "/_monitoring/bulk"; - } - - public function getParamWhitelist(): array - { - return [ - 'system_id', - 'system_api_version', - 'interval' - ]; - } - - public function getMethod(): string - { - return 'POST'; - } - - public function setBody($body): static - { - if (isset($body) !== true) { - return $this; - } - if (is_array($body) === true || $body instanceof Traversable) { - foreach ($body as $item) { - $this->body .= $this->serializer->serialize($item) . "\n"; - } - } elseif (is_string($body)) { - $this->body = $body; - if (substr($body, -1) != "\n") { - $this->body .= "\n"; - } - } else { - throw new InvalidArgumentException("Body must be an array, traversable object or string"); - } - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/SearchableSnapshots/ClearCache.php b/src/OpenSearch/Endpoints/SearchableSnapshots/ClearCache.php deleted file mode 100644 index 3933363a8..000000000 --- a/src/OpenSearch/Endpoints/SearchableSnapshots/ClearCache.php +++ /dev/null @@ -1,52 +0,0 @@ -index ?? null; - - if (isset($index)) { - return "/$index/_searchable_snapshots/cache/clear"; - } - return "/_searchable_snapshots/cache/clear"; - } - - public function getParamWhitelist(): array - { - return [ - 'ignore_unavailable', - 'allow_no_indices', - 'expand_wildcards', - 'index' - ]; - } - - public function getMethod(): string - { - return 'POST'; - } -} diff --git a/src/OpenSearch/Endpoints/SearchableSnapshots/Mount.php b/src/OpenSearch/Endpoints/SearchableSnapshots/Mount.php deleted file mode 100644 index 953b5969f..000000000 --- a/src/OpenSearch/Endpoints/SearchableSnapshots/Mount.php +++ /dev/null @@ -1,90 +0,0 @@ -repository ?? null; - $snapshot = $this->snapshot ?? null; - - if (isset($repository) && isset($snapshot)) { - return "/_snapshot/$repository/$snapshot/_mount"; - } - throw new RuntimeException('Missing parameter for the endpoint searchable_snapshots.mount'); - } - - public function getParamWhitelist(): array - { - return [ - 'master_timeout', - 'wait_for_completion', - 'cluster_manager_timeout' - ]; - } - - public function getMethod(): string - { - return 'POST'; - } - - public function setBody($body): static - { - if (isset($body) !== true) { - return $this; - } - $this->body = $body; - - return $this; - } - - public function setRepository($repository): static - { - if (isset($repository) !== true) { - return $this; - } - $this->repository = $repository; - - return $this; - } - - public function setSnapshot($snapshot): static - { - if (isset($snapshot) !== true) { - return $this; - } - $this->snapshot = $snapshot; - - return $this; - } - protected function getParamDeprecation(): array - { - return ['master_timeout' => 'cluster_manager_timeout']; - } -} diff --git a/src/OpenSearch/Endpoints/SearchableSnapshots/RepositoryStats.php b/src/OpenSearch/Endpoints/SearchableSnapshots/RepositoryStats.php deleted file mode 100644 index ec31d661d..000000000 --- a/src/OpenSearch/Endpoints/SearchableSnapshots/RepositoryStats.php +++ /dev/null @@ -1,60 +0,0 @@ -repository ?? null; - - if (isset($repository)) { - return "/_snapshot/$repository/_stats"; - } - throw new RuntimeException('Missing parameter for the endpoint searchable_snapshots.repository_stats'); - } - - public function getParamWhitelist(): array - { - return []; - } - - public function getMethod(): string - { - return 'GET'; - } - - public function setRepository($repository): RepositoryStats - { - if (isset($repository) !== true) { - return $this; - } - $this->repository = $repository; - - return $this; - } -} diff --git a/src/OpenSearch/Endpoints/SearchableSnapshots/Stats.php b/src/OpenSearch/Endpoints/SearchableSnapshots/Stats.php deleted file mode 100644 index 822b11742..000000000 --- a/src/OpenSearch/Endpoints/SearchableSnapshots/Stats.php +++ /dev/null @@ -1,47 +0,0 @@ -index ?? null; - - if (isset($index)) { - return "/$index/_searchable_snapshots/stats"; - } - return "/_searchable_snapshots/stats"; - } - - public function getParamWhitelist(): array - { - return []; - } - - public function getMethod(): string - { - return 'GET'; - } -} diff --git a/src/OpenSearch/Exception/BadMethodCallException.php b/src/OpenSearch/Exception/BadMethodCallException.php index 79198228d..966ce9c8b 100644 --- a/src/OpenSearch/Exception/BadMethodCallException.php +++ b/src/OpenSearch/Exception/BadMethodCallException.php @@ -4,13 +4,9 @@ namespace OpenSearch\Exception; -use OpenSearch\Common\Exceptions\OpenSearchException; - /** * An exception thrown when invalid arguments are passed to a method. - * - * @phpstan-ignore class.implementsDeprecatedInterface */ -class BadMethodCallException extends \BadMethodCallException implements OpenSearchException +class BadMethodCallException extends \BadMethodCallException { } diff --git a/src/OpenSearch/Exception/HttpException.php b/src/OpenSearch/Exception/HttpException.php index 0a2da9e60..c32741642 100644 --- a/src/OpenSearch/Exception/HttpException.php +++ b/src/OpenSearch/Exception/HttpException.php @@ -4,15 +4,12 @@ namespace OpenSearch\Exception; -use OpenSearch\Common\Exceptions\OpenSearchException; - /** * Exception thrown when an HTTP error occurs. * * @phpstan-consistent-constructor - * @phpstan-ignore class.implementsDeprecatedInterface */ -class HttpException extends \RuntimeException implements HttpExceptionInterface, OpenSearchException +class HttpException extends \RuntimeException implements HttpExceptionInterface { public function __construct( protected readonly int $statusCode, diff --git a/src/OpenSearch/Exception/JsonException.php b/src/OpenSearch/Exception/JsonException.php index c65851db5..ec73e20d7 100644 --- a/src/OpenSearch/Exception/JsonException.php +++ b/src/OpenSearch/Exception/JsonException.php @@ -4,14 +4,10 @@ namespace OpenSearch\Exception; -use OpenSearch\Common\Exceptions\OpenSearchException; - /** * Provides an exception for JSON errors. - * - * @phpstan-ignore class.implementsDeprecatedInterface */ -class JsonException extends \JsonException implements OpenSearchException +class JsonException extends \JsonException { public function __construct(int $code, private readonly ?string $data, ?\Throwable $previous = null) { diff --git a/src/OpenSearch/Exception/RuntimeException.php b/src/OpenSearch/Exception/RuntimeException.php index b96ea6e54..ca597e848 100644 --- a/src/OpenSearch/Exception/RuntimeException.php +++ b/src/OpenSearch/Exception/RuntimeException.php @@ -4,13 +4,9 @@ namespace OpenSearch\Exception; -use OpenSearch\Common\Exceptions\OpenSearchException; - /** * An exception thrown when a runtime error occurs. - * - * @phpstan-ignore class.implementsDeprecatedInterface */ -class RuntimeException extends \RuntimeException implements OpenSearchException +class RuntimeException extends \RuntimeException { } diff --git a/src/OpenSearch/Exception/UnexpectedValueException.php b/src/OpenSearch/Exception/UnexpectedValueException.php index 2a4cad139..55877d55d 100644 --- a/src/OpenSearch/Exception/UnexpectedValueException.php +++ b/src/OpenSearch/Exception/UnexpectedValueException.php @@ -4,13 +4,9 @@ namespace OpenSearch\Exception; -use OpenSearch\Common\Exceptions\OpenSearchException; - /** * An exception thrown when invalid arguments are passed to a method. - * - * @phpstan-ignore class.implementsDeprecatedInterface */ -class UnexpectedValueException extends \UnexpectedValueException implements OpenSearchException +class UnexpectedValueException extends \UnexpectedValueException { } diff --git a/src/OpenSearch/Handlers/SigV4Handler.php b/src/OpenSearch/Handlers/SigV4Handler.php deleted file mode 100644 index 70bd3bbf2..000000000 --- a/src/OpenSearch/Handlers/SigV4Handler.php +++ /dev/null @@ -1,156 +0,0 @@ ->, body: string|resource|null, client?: array} - * - * @deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\Aws\SigV4RequestFactory instead. - */ -class SigV4Handler -{ - /** - * @var SignatureV4 - */ - private $signer; - /** - * @var callable - */ - private $credentialProvider; - /** - * @var callable - */ - private $wrappedHandler; - - /** - * A handler that applies an AWS V4 signature before dispatching requests. - * - * @param string $region The region of your Amazon - * OpenSearch Service domain - * @param string $service The Service of your Amazon - * OpenSearch Service domain - * @param callable|null $credentialProvider A callable that returns a - * promise that is fulfilled - * with an instance of - * Aws\Credentials\Credentials - * @param callable|null $wrappedHandler A RingPHP handler - */ - public function __construct( - string $region, - string $service, - ?callable $credentialProvider = null, - ?callable $wrappedHandler = null - ) { - self::assertDependenciesInstalled(); - $this->signer = new SignatureV4($service, $region); - $this->wrappedHandler = $wrappedHandler - ?: ClientBuilder::defaultHandler(); - $this->credentialProvider = $credentialProvider - ?: CredentialProvider::defaultProvider(); - } - - /** - * @phpstan-param RingPhpRequest $request - */ - public function __invoke(array $request) - { - $creds = call_user_func($this->credentialProvider)->wait(); - - $psr7Request = $this->createPsr7Request($request); - $psr7Request = $psr7Request->withHeader('x-amz-content-sha256', Utils::hash($psr7Request->getBody(), 'sha256')); - $signedRequest = $this->signer - ->signRequest($psr7Request, $creds); - return call_user_func($this->wrappedHandler, $this->createRingRequest($signedRequest, $request)); - } - - public static function assertDependenciesInstalled(): void - { - if (!class_exists(SignatureV4::class)) { - throw new RuntimeException( - 'The AWS SDK for PHP must be installed in order to use the SigV4 signing handler' - ); - } - } - - /** - * @phpstan-param RingPhpRequest $ringPhpRequest - */ - private function createPsr7Request(array $ringPhpRequest): Request - { - // fix for uppercase 'Host' array key in elasticsearch-php 5.3.1 and backward compatible - // https://github.com/aws/aws-sdk-php/issues/1225 - $hostKey = isset($ringPhpRequest['headers']['Host']) ? 'Host' : 'host'; - - // Amazon ES/OS listens on standard ports (443 for HTTPS, 80 for HTTP). - // Consequently, the port should be stripped from the host header. - $parsedUrl = parse_url($ringPhpRequest['headers'][$hostKey][0]); - if (isset($parsedUrl['host'])) { - $ringPhpRequest['headers'][$hostKey][0] = $parsedUrl['host']; - } - - // Create a PSR-7 URI from the array passed to the handler - $uri = (new Uri($ringPhpRequest['uri'])) - ->withScheme($ringPhpRequest['scheme']) - ->withHost($ringPhpRequest['headers'][$hostKey][0]); - if (isset($ringPhpRequest['query_string'])) { - $uri = $uri->withQuery($ringPhpRequest['query_string']); - } - - // Create a PSR-7 request from the array passed to the handler - return new Request( - $ringPhpRequest['http_method'], - $uri, - $ringPhpRequest['headers'], - $ringPhpRequest['body'] - ); - } - - /** - * @phpstan-param RingPhpRequest $originalRequest - * - * @phpstan-return RingPhpRequest - */ - private function createRingRequest(RequestInterface $request, array $originalRequest): array - { - $uri = $request->getUri(); - $body = (string) $request->getBody(); - - // RingPHP currently expects empty message bodies to be null: - // https://github.com/guzzle/RingPHP/blob/4c8fe4c48a0fb7cc5e41ef529e43fecd6da4d539/src/Client/CurlFactory.php#L202 - if (empty($body)) { - $body = null; - } - - // Reset the explicit port in the URL - $client = $originalRequest['client']; - unset($client['curl'][CURLOPT_PORT]); - - $ringRequest = [ - 'http_method' => $request->getMethod(), - 'scheme' => $uri->getScheme(), - 'uri' => $uri->getPath(), - 'body' => $body, - 'headers' => $request->getHeaders(), - 'client' => $client - ]; - if ($uri->getQuery()) { - $ringRequest['query_string'] = $uri->getQuery(); - } - - return $ringRequest; - } -} diff --git a/src/OpenSearch/Helper/Iterators/SearchHitIterator.php b/src/OpenSearch/Helper/Iterators/SearchHitIterator.php deleted file mode 100644 index aa00504f8..000000000 --- a/src/OpenSearch/Helper/Iterators/SearchHitIterator.php +++ /dev/null @@ -1,171 +0,0 @@ -search_responses = $search_responses; - } - - /** - * Rewinds the internal SearchResponseIterator and itself - * - * @return void - * @see Iterator::rewind() - */ - public function rewind(): void - { - $this->current_key = 0; - $this->search_responses->rewind(); - - // The first page may be empty. In that case, the next page is fetched. - $current_page = $this->search_responses->current(); - if ($this->search_responses->valid() && empty($current_page['hits']['hits'])) { - $this->search_responses->next(); - } - - $this->count = 0; - if (isset($current_page['hits']) && isset($current_page['hits']['total'])) { - $this->count = $current_page['hits']['total']; - } - - $this->readPageData(); - } - - /** - * Advances pointer of the current hit to the next one in the current page. If there - * isn't a next hit in the current page, then it advances the current page and moves the - * pointer to the first hit in the page. - * - * @return void - * @see Iterator::next() - */ - public function next(): void - { - $this->current_key++; - $this->current_hit_index++; - $current_page = $this->search_responses->current(); - if (isset($current_page['hits']['hits'][$this->current_hit_index])) { - $this->current_hit_data = $current_page['hits']['hits'][$this->current_hit_index]; - } else { - $this->search_responses->next(); - $this->readPageData(); - } - } - - /** - * Returns a boolean indicating whether or not the current pointer has valid data - * - * @return bool - * @see Iterator::valid() - */ - public function valid(): bool - { - return is_array($this->current_hit_data); - } - - /** - * Returns the current hit - * - * @return array - * @see Iterator::current() - */ - public function current(): array - { - return $this->current_hit_data; - } - - /** - * Returns the current hit index. The hit index spans all pages. - * - * @return int - * @see Iterator::key() - */ - public function key(): int - { - return $this->current_key; - } - - /** - * Advances the internal SearchResponseIterator and resets the current_hit_index to 0 - * - * @internal - */ - private function readPageData(): void - { - if ($this->search_responses->valid()) { - $current_page = $this->search_responses->current(); - $this->current_hit_index = 0; - $this->current_hit_data = $current_page['hits']['hits'][$this->current_hit_index]; - } else { - $this->current_hit_data = null; - } - } - - /** - * {@inheritDoc} - */ - public function count(): int - { - return $this->count; - } -} diff --git a/src/OpenSearch/Helper/Iterators/SearchResponseIterator.php b/src/OpenSearch/Helper/Iterators/SearchResponseIterator.php deleted file mode 100644 index e339435ea..000000000 --- a/src/OpenSearch/Helper/Iterators/SearchResponseIterator.php +++ /dev/null @@ -1,188 +0,0 @@ -client = $client; - $this->params = $search_params; - - if (isset($search_params['scroll'])) { - $this->scroll_ttl = $search_params['scroll']; - } - } - - /** - * Destructor - */ - public function __destruct() - { - $this->clearScroll(); - } - - /** - * Sets the time to live duration of a scroll window - * - * @param string $time_to_live - * @return $this - */ - public function setScrollTimeout(string $time_to_live): SearchResponseIterator - { - $this->scroll_ttl = $time_to_live; - return $this; - } - - /** - * Clears the current scroll window if there is a scroll_id stored - * - * @return void - */ - private function clearScroll(): void - { - if (!empty($this->scroll_id)) { - $this->client->clearScroll( - array( - 'scroll_id' => $this->scroll_id, - 'client' => array( - 'ignore' => 404 - ) - ) - ); - $this->scroll_id = null; - } - } - - /** - * Rewinds the iterator by performing the initial search. - * - * @return void - * @see Iterator::rewind() - */ - public function rewind(): void - { - $this->clearScroll(); - $this->current_key = 0; - $this->current_scrolled_response = $this->client->search($this->params); - $this->scroll_id = $this->current_scrolled_response['_scroll_id']; - } - - /** - * Fetches every "page" after the first one using the lastest "scroll_id" - * - * @return void - * @see Iterator::next() - */ - public function next(): void - { - $this->current_scrolled_response = $this->client->scroll( - [ - 'scroll' => $this->scroll_ttl, - 'body' => [ - 'scroll_id' => $this->scroll_id, - ], - ] - ); - $this->scroll_id = $this->current_scrolled_response['_scroll_id']; - $this->current_key++; - } - - /** - * Returns a boolean value indicating if the current page is valid or not - * - * @return bool - * @see Iterator::valid() - */ - public function valid(): bool - { - return isset($this->current_scrolled_response['hits']['hits'][0]); - } - - /** - * Returns the current "page" - * - * @return array - * @see Iterator::current() - */ - public function current(): array - { - return $this->current_scrolled_response; - } - - /** - * Returns the current "page number" of the current "page" - * - * @return int - * @see Iterator::key() - */ - public function key(): int - { - return $this->current_key; - } -} diff --git a/src/OpenSearch/HttpClient/GuzzleRetryDecider.php b/src/OpenSearch/HttpClient/GuzzleRetryDecider.php index 59d0a1efc..c89b0b8d6 100644 --- a/src/OpenSearch/HttpClient/GuzzleRetryDecider.php +++ b/src/OpenSearch/HttpClient/GuzzleRetryDecider.php @@ -18,7 +18,7 @@ public function __construct( ) { } - public function __invoke(int $retries, ?RequestInterface $request, ?ResponseInterface $response, $exception): bool + public function __invoke(int $retries, ?RequestInterface $request, ?ResponseInterface $response, ?\Throwable $exception): bool { if ($retries >= $this->maxRetries) { return false; diff --git a/src/OpenSearch/HttpClient/HttpClientFactoryInterface.php b/src/OpenSearch/HttpClient/HttpClientFactoryInterface.php index cd1a78cfc..92159ce34 100644 --- a/src/OpenSearch/HttpClient/HttpClientFactoryInterface.php +++ b/src/OpenSearch/HttpClient/HttpClientFactoryInterface.php @@ -17,5 +17,4 @@ interface HttpClientFactoryInterface * @param array $options */ public function create(array $options): ClientInterface; - } diff --git a/src/OpenSearch/LegacyEndpointFactory.php b/src/OpenSearch/LegacyEndpointFactory.php deleted file mode 100644 index 843b89b24..000000000 --- a/src/OpenSearch/LegacyEndpointFactory.php +++ /dev/null @@ -1,42 +0,0 @@ -endpoints = $endpoints; - } - - /** - * {@inheritdoc} - */ - public function getEndpoint(string $class): AbstractEndpoint - { - // We need to strip the base namespace from the class name for BC. - $class = str_replace('OpenSearch\\Endpoints\\', '', $class); - $endpointBuilder = $this->endpoints; - return $endpointBuilder($class); - } - -} diff --git a/src/OpenSearch/LegacyTransportWrapper.php b/src/OpenSearch/LegacyTransportWrapper.php deleted file mode 100644 index eea0ca7d5..000000000 --- a/src/OpenSearch/LegacyTransportWrapper.php +++ /dev/null @@ -1,38 +0,0 @@ -transport->performRequest($method, $uri, $params, $body, $options); - return $this->transport->resultOrFuture($promise, $options); - } - -} diff --git a/src/OpenSearch/Namespaces/AbstractNamespace.php b/src/OpenSearch/Namespaces/AbstractNamespace.php index b20f17aa7..29b6fcadc 100644 --- a/src/OpenSearch/Namespaces/AbstractNamespace.php +++ b/src/OpenSearch/Namespaces/AbstractNamespace.php @@ -23,65 +23,20 @@ use OpenSearch\EndpointFactoryInterface; use OpenSearch\Endpoints\AbstractEndpoint; -use OpenSearch\LegacyEndpointFactory; -use OpenSearch\LegacyTransportWrapper; -use OpenSearch\Transport; use OpenSearch\TransportInterface; abstract class AbstractNamespace { - /** - * @var \OpenSearch\Transport - * - * @deprecated in 2.4.0 and will be removed in 3.0.0. Use $httpTransport property instead. - */ - protected $transport; - - protected TransportInterface $httpTransport; - - protected EndpointFactoryInterface $endpointFactory; - - /** - * @var callable - * - * @deprecated in 2.4.0 and will be removed in 3.0.0. Use $endpointFactory property instead. - */ - protected $endpoints; - - /** - * @phpstan-ignore parameter.deprecatedClass - */ - public function __construct(TransportInterface|Transport $transport, callable|EndpointFactoryInterface $endpointFactory) - { - if (!$transport instanceof TransportInterface) { - @trigger_error('Passing an instance of \OpenSearch\Transport to ' . __METHOD__ . '() is deprecated in 2.4.0 and will be removed in 3.0.0. Pass an instance of \OpenSearch\TransportInterface instead.', E_USER_DEPRECATED); - // @phpstan-ignore property.deprecated - $this->transport = $transport; - // @phpstan-ignore new.deprecated - $this->httpTransport = new LegacyTransportWrapper($transport); - } else { - $this->httpTransport = $transport; - } - if (is_callable($endpointFactory)) { - @trigger_error('Passing a callable as $endpointFactory param to ' . __METHOD__ . '() is deprecated in 2.4.0 and will be removed in 3.0.0. Pass an instance of \OpenSearch\EndpointFactoryInterface instead.', E_USER_DEPRECATED); - $endpoints = $endpointFactory; - // @phpstan-ignore new.deprecated - $endpointFactory = new LegacyEndpointFactory($endpointFactory); - } else { - $endpoints = function ($c) use ($endpointFactory) { - @trigger_error('The $endpoints property is deprecated in 2.4.0 and will be removed in 3.0.0.', E_USER_DEPRECATED); - return $endpointFactory->getEndpoint('OpenSearch\\Endpoints\\' . $c); - }; - } - // @phpstan-ignore property.deprecated - $this->endpoints = $endpoints; - $this->endpointFactory = $endpointFactory; + public function __construct( + protected TransportInterface $httpTransport, + protected EndpointFactoryInterface $endpointFactory + ) { } /** * @return null|mixed */ - public function extractArgument(array &$params, string $arg) + public function extractArgument(array &$params, string $arg): mixed { if (array_key_exists($arg, $params) === true) { $val = $params[$arg]; @@ -92,7 +47,7 @@ public function extractArgument(array &$params, string $arg) } } - protected function performRequest(AbstractEndpoint $endpoint) + protected function performRequest(AbstractEndpoint $endpoint): iterable|string|null { return $this->httpTransport->sendRequest( $endpoint->getMethod(), diff --git a/src/OpenSearch/Namespaces/AsyncSearchNamespace.php b/src/OpenSearch/Namespaces/AsyncSearchNamespace.php deleted file mode 100644 index 7b1c9f036..000000000 --- a/src/OpenSearch/Namespaces/AsyncSearchNamespace.php +++ /dev/null @@ -1,31 +0,0 @@ -extractArgument($params, 'id'); @@ -64,7 +64,7 @@ public function delete(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function get(array $params = []) + public function get(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -91,7 +91,7 @@ public function get(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function search(array $params = []) + public function search(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -114,7 +114,7 @@ public function search(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function stats(array $params = []) + public function stats(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Stats::class); $endpoint->setParams($params); diff --git a/src/OpenSearch/Namespaces/BooleanRequestWrapper.php b/src/OpenSearch/Namespaces/BooleanRequestWrapper.php index 575574e3f..44738d400 100644 --- a/src/OpenSearch/Namespaces/BooleanRequestWrapper.php +++ b/src/OpenSearch/Namespaces/BooleanRequestWrapper.php @@ -21,12 +21,8 @@ namespace OpenSearch\Namespaces; -use GuzzleHttp\Ring\Future\FutureArrayInterface; -use OpenSearch\Common\Exceptions\Missing404Exception; -use OpenSearch\Common\Exceptions\RoutingMissingException; use OpenSearch\Endpoints\AbstractEndpoint; use OpenSearch\Exception\NotFoundHttpException; -use OpenSearch\Transport; use OpenSearch\TransportInterface; abstract class BooleanRequestWrapper @@ -38,6 +34,7 @@ abstract class BooleanRequestWrapper * Returns FALSE for a 404 error, otherwise TRUE. * * @throws \Psr\Http\Client\ClientExceptionInterface + * @throws \OpenSearch\Exception\HttpExceptionInterface */ public static function sendRequest(AbstractEndpoint $endpoint, TransportInterface $transport): bool { @@ -50,50 +47,11 @@ public static function sendRequest(AbstractEndpoint $endpoint, TransportInterfac $endpoint->getOptions() ); - } catch (NotFoundHttpException|RoutingMissingException $e) { + } catch (NotFoundHttpException $e) { // Return false for 404 errors. return false; } return true; } - /** - * Perform Request - * - * @throws Missing404Exception - * @throws RoutingMissingException - * - * @deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\Namespaces\BooleanRequestWrapper::sendRequest() instead. - */ - public static function performRequest(AbstractEndpoint $endpoint, Transport $transport) - { - @trigger_error( - __METHOD__ . '() is deprecated in 2.4.0 and will be removed in 3.0.0. Use \OpenSearch\Namespaces\BooleanRequestWrapper::sendRequest() instead.' - ); - try { - $response = $transport->performRequest( - $endpoint->getMethod(), - $endpoint->getURI(), - $endpoint->getParams(), - $endpoint->getBody(), - $endpoint->getOptions() - ); - - $response = $transport->resultOrFuture($response, $endpoint->getOptions()); - if (!($response instanceof FutureArrayInterface)) { - if ($response['status'] === 200) { - return true; - } else { - return false; - } - } else { - // async mode, can't easily resolve this...punt to user - return $response; - } - } catch (Missing404Exception $exception) { - return false; - } catch (RoutingMissingException $exception) { - return false; - } - } } diff --git a/src/OpenSearch/Namespaces/CatNamespace.php b/src/OpenSearch/Namespaces/CatNamespace.php index 5cf1dbe40..96b317a1d 100644 --- a/src/OpenSearch/Namespaces/CatNamespace.php +++ b/src/OpenSearch/Namespaces/CatNamespace.php @@ -73,7 +73,7 @@ class CatNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function aliases(array $params = []) + public function aliases(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -102,7 +102,7 @@ public function aliases(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function allPitSegments(array $params = []) + public function allPitSegments(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(AllPitSegments::class); $endpoint->setParams($params); @@ -132,7 +132,7 @@ public function allPitSegments(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function allocation(array $params = []) + public function allocation(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); @@ -163,7 +163,7 @@ public function allocation(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function clusterManager(array $params = []) + public function clusterManager(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ClusterManager::class); $endpoint->setParams($params); @@ -189,7 +189,7 @@ public function clusterManager(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function count(array $params = []) + public function count(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -219,7 +219,7 @@ public function count(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function fielddata(array $params = []) + public function fielddata(array $params = []): iterable|string|null { $fields = $this->extractArgument($params, 'fields'); @@ -249,7 +249,7 @@ public function fielddata(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function health(array $params = []) + public function health(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Health::class); $endpoint->setParams($params); @@ -269,7 +269,7 @@ public function health(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function help(array $params = []) + public function help(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Help::class); $endpoint->setParams($params); @@ -304,7 +304,7 @@ public function help(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function indices(array $params = []) + public function indices(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -335,7 +335,7 @@ public function indices(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function master(array $params = []) + public function master(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Master::class); $endpoint->setParams($params); @@ -363,7 +363,7 @@ public function master(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function nodeattrs(array $params = []) + public function nodeattrs(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(NodeAttrs::class); $endpoint->setParams($params); @@ -394,7 +394,7 @@ public function nodeattrs(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function nodes(array $params = []) + public function nodes(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Nodes::class); $endpoint->setParams($params); @@ -423,7 +423,7 @@ public function nodes(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function pendingTasks(array $params = []) + public function pendingTasks(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(PendingTasks::class); $endpoint->setParams($params); @@ -449,7 +449,7 @@ public function pendingTasks(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function pitSegments(array $params = []) + public function pitSegments(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -480,7 +480,7 @@ public function pitSegments(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function plugins(array $params = []) + public function plugins(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Plugins::class); $endpoint->setParams($params); @@ -510,7 +510,7 @@ public function plugins(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function recovery(array $params = []) + public function recovery(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -541,7 +541,7 @@ public function recovery(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function repositories(array $params = []) + public function repositories(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Repositories::class); $endpoint->setParams($params); @@ -578,7 +578,7 @@ public function repositories(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function segmentReplication(array $params = []) + public function segmentReplication(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -610,7 +610,7 @@ public function segmentReplication(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function segments(array $params = []) + public function segments(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -644,7 +644,7 @@ public function segments(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function shards(array $params = []) + public function shards(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -677,7 +677,7 @@ public function shards(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function snapshots(array $params = []) + public function snapshots(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); @@ -710,7 +710,7 @@ public function snapshots(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function tasks(array $params = []) + public function tasks(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Tasks::class); $endpoint->setParams($params); @@ -739,7 +739,7 @@ public function tasks(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function templates(array $params = []) + public function templates(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -772,7 +772,7 @@ public function templates(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function threadPool(array $params = []) + public function threadPool(array $params = []): iterable|string|null { $thread_pool_patterns = $this->extractArgument($params, 'thread_pool_patterns'); diff --git a/src/OpenSearch/Namespaces/ClusterNamespace.php b/src/OpenSearch/Namespaces/ClusterNamespace.php index 2713ffabf..4090e1e76 100644 --- a/src/OpenSearch/Namespaces/ClusterNamespace.php +++ b/src/OpenSearch/Namespaces/ClusterNamespace.php @@ -65,7 +65,7 @@ class ClusterNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function allocationExplain(array $params = []) + public function allocationExplain(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -92,7 +92,7 @@ public function allocationExplain(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteComponentTemplate(array $params = []) + public function deleteComponentTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -115,7 +115,7 @@ public function deleteComponentTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteDecommissionAwareness(array $params = []) + public function deleteDecommissionAwareness(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(DeleteDecommissionAwareness::class); $endpoint->setParams($params); @@ -136,7 +136,7 @@ public function deleteDecommissionAwareness(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteVotingConfigExclusions(array $params = []) + public function deleteVotingConfigExclusions(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(DeleteVotingConfigExclusions::class); $endpoint->setParams($params); @@ -156,7 +156,7 @@ public function deleteVotingConfigExclusions(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteWeightedRouting(array $params = []) + public function deleteWeightedRouting(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -187,10 +187,6 @@ public function existsComponentTemplate(array $params = []): bool { $name = $this->extractArgument($params, 'name'); - // Legacy option to manually make this verbose so we can check status code. - // @todo remove in 3.0.0 - $params['client']['verbose'] = true; - $endpoint = $this->endpointFactory->getEndpoint(ExistsComponentTemplate::class); $endpoint->setParams($params); $endpoint->setName($name); @@ -215,7 +211,7 @@ public function existsComponentTemplate(array $params = []): bool * @param array $params Associative array of parameters * @return array */ - public function getComponentTemplate(array $params = []) + public function getComponentTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -239,7 +235,7 @@ public function getComponentTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getDecommissionAwareness(array $params = []) + public function getDecommissionAwareness(array $params = []): iterable|string|null { $awareness_attribute_name = $this->extractArgument($params, 'awareness_attribute_name'); @@ -267,7 +263,7 @@ public function getDecommissionAwareness(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getSettings(array $params = []) + public function getSettings(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetSettings::class); $endpoint->setParams($params); @@ -288,7 +284,7 @@ public function getSettings(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getWeightedRouting(array $params = []) + public function getWeightedRouting(array $params = []): iterable|string|null { $attribute = $this->extractArgument($params, 'attribute'); @@ -325,7 +321,7 @@ public function getWeightedRouting(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function health(array $params = []) + public function health(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -351,7 +347,7 @@ public function health(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function pendingTasks(array $params = []) + public function pendingTasks(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(PendingTasks::class); $endpoint->setParams($params); @@ -374,7 +370,7 @@ public function pendingTasks(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function postVotingConfigExclusions(array $params = []) + public function postVotingConfigExclusions(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(PostVotingConfigExclusions::class); $endpoint->setParams($params); @@ -400,7 +396,7 @@ public function postVotingConfigExclusions(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putComponentTemplate(array $params = []) + public function putComponentTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $body = $this->extractArgument($params, 'body'); @@ -427,7 +423,7 @@ public function putComponentTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putDecommissionAwareness(array $params = []) + public function putDecommissionAwareness(array $params = []): iterable|string|null { $awareness_attribute_name = $this->extractArgument($params, 'awareness_attribute_name'); $awareness_attribute_value = $this->extractArgument($params, 'awareness_attribute_value'); @@ -457,7 +453,7 @@ public function putDecommissionAwareness(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putSettings(array $params = []) + public function putSettings(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -481,7 +477,7 @@ public function putSettings(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putWeightedRouting(array $params = []) + public function putWeightedRouting(array $params = []): iterable|string|null { $attribute = $this->extractArgument($params, 'attribute'); $body = $this->extractArgument($params, 'body'); @@ -506,7 +502,7 @@ public function putWeightedRouting(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function remoteInfo(array $params = []) + public function remoteInfo(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(RemoteInfo::class); $endpoint->setParams($params); @@ -534,7 +530,7 @@ public function remoteInfo(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function reroute(array $params = []) + public function reroute(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -568,7 +564,7 @@ public function reroute(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function state(array $params = []) + public function state(array $params = []): iterable|string|null { $metric = $this->extractArgument($params, 'metric'); $index = $this->extractArgument($params, 'index'); @@ -598,7 +594,7 @@ public function state(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function stats(array $params = []) + public function stats(array $params = []): iterable|string|null { $index_metric = $this->extractArgument($params, 'index_metric'); $metric = $this->extractArgument($params, 'metric'); diff --git a/src/OpenSearch/Namespaces/DanglingIndicesNamespace.php b/src/OpenSearch/Namespaces/DanglingIndicesNamespace.php index 0d4565595..8019941e3 100644 --- a/src/OpenSearch/Namespaces/DanglingIndicesNamespace.php +++ b/src/OpenSearch/Namespaces/DanglingIndicesNamespace.php @@ -49,7 +49,7 @@ class DanglingIndicesNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function deleteDanglingIndex(array $params = []) + public function deleteDanglingIndex(array $params = []): iterable|string|null { $index_uuid = $this->extractArgument($params, 'index_uuid'); @@ -77,7 +77,7 @@ public function deleteDanglingIndex(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function importDanglingIndex(array $params = []) + public function importDanglingIndex(array $params = []): iterable|string|null { $index_uuid = $this->extractArgument($params, 'index_uuid'); @@ -100,7 +100,7 @@ public function importDanglingIndex(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function listDanglingIndices(array $params = []) + public function listDanglingIndices(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ListDanglingIndices::class); $endpoint->setParams($params); diff --git a/src/OpenSearch/Namespaces/DataFrameTransformDeprecatedNamespace.php b/src/OpenSearch/Namespaces/DataFrameTransformDeprecatedNamespace.php deleted file mode 100644 index b72b74330..000000000 --- a/src/OpenSearch/Namespaces/DataFrameTransformDeprecatedNamespace.php +++ /dev/null @@ -1,208 +0,0 @@ -extractArgument($params, 'transform_id'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('DataFrameTransformDeprecated\DeleteTransform'); - $endpoint->setParams($params); - $endpoint->setTransformId($transform_id); - - return $this->performRequest($endpoint); - } - /** - * $params['transform_id'] = (string) The id or comma delimited list of id expressions of the transforms to get, '_all' or '*' implies get all transforms - * $params['from'] = (int) skips a number of transform configs, defaults to 0 - * $params['size'] = (int) specifies a max number of transforms to get, defaults to 100 - * $params['allow_no_match'] = (boolean) Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified) - * - * @param array $params Associative array of parameters - * @return array - - * - * @note This API is BETA and may change in ways that are not backwards compatible - * - */ - public function getTransform(array $params = []) - { - $transform_id = $this->extractArgument($params, 'transform_id'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('DataFrameTransformDeprecated\GetTransform'); - $endpoint->setParams($params); - $endpoint->setTransformId($transform_id); - - return $this->performRequest($endpoint); - } - /** - * $params['transform_id'] = (string) The id of the transform for which to get stats. '_all' or '*' implies all transforms - * $params['from'] = (number) skips a number of transform stats, defaults to 0 - * $params['size'] = (number) specifies a max number of transform stats to get, defaults to 100 - * $params['allow_no_match'] = (boolean) Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified) - * - * @param array $params Associative array of parameters - * @return array - - * - * @note This API is BETA and may change in ways that are not backwards compatible - * - */ - public function getTransformStats(array $params = []) - { - $transform_id = $this->extractArgument($params, 'transform_id'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('DataFrameTransformDeprecated\GetTransformStats'); - $endpoint->setParams($params); - $endpoint->setTransformId($transform_id); - - return $this->performRequest($endpoint); - } - public function previewTransform(array $params = []) - { - $body = $this->extractArgument($params, 'body'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('DataFrameTransformDeprecated\PreviewTransform'); - $endpoint->setParams($params); - $endpoint->setBody($body); - - return $this->performRequest($endpoint); - } - /** - * $params['transform_id'] = (string) The id of the new transform. - * $params['defer_validation'] = (boolean) If validations should be deferred until transform starts, defaults to false. - * $params['body'] = (array) The transform definition (Required) - * - * @param array $params Associative array of parameters - * @return array - - * - * @note This API is BETA and may change in ways that are not backwards compatible - * - */ - public function putTransform(array $params = []) - { - $transform_id = $this->extractArgument($params, 'transform_id'); - $body = $this->extractArgument($params, 'body'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('DataFrameTransformDeprecated\PutTransform'); - $endpoint->setParams($params); - $endpoint->setTransformId($transform_id); - $endpoint->setBody($body); - - return $this->performRequest($endpoint); - } - /** - * $params['transform_id'] = (string) The id of the transform to start - * $params['timeout'] = (time) Controls the time to wait for the transform to start - * - * @param array $params Associative array of parameters - * @return array - - * - * @note This API is BETA and may change in ways that are not backwards compatible - * - */ - public function startTransform(array $params = []) - { - $transform_id = $this->extractArgument($params, 'transform_id'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('DataFrameTransformDeprecated\StartTransform'); - $endpoint->setParams($params); - $endpoint->setTransformId($transform_id); - - return $this->performRequest($endpoint); - } - /** - * $params['transform_id'] = (string) The id of the transform to stop - * $params['wait_for_completion'] = (boolean) Whether to wait for the transform to fully stop before returning or not. Default to false - * $params['timeout'] = (time) Controls the time to wait until the transform has stopped. Default to 30 seconds - * $params['allow_no_match'] = (boolean) Whether to ignore if a wildcard expression matches no transforms. (This includes `_all` string or when no transforms have been specified) - * - * @param array $params Associative array of parameters - * @return array - - * - * @note This API is BETA and may change in ways that are not backwards compatible - * - */ - public function stopTransform(array $params = []) - { - $transform_id = $this->extractArgument($params, 'transform_id'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('DataFrameTransformDeprecated\StopTransform'); - $endpoint->setParams($params); - $endpoint->setTransformId($transform_id); - - return $this->performRequest($endpoint); - } - /** - * $params['transform_id'] = (string) The id of the transform. - * $params['defer_validation'] = (boolean) If validations should be deferred until transform starts, defaults to false. - * $params['body'] = (array) The update transform definition (Required) - * - * @param array $params Associative array of parameters - * @return array - - * - * @note This API is BETA and may change in ways that are not backwards compatible - * - */ - public function updateTransform(array $params = []) - { - $transform_id = $this->extractArgument($params, 'transform_id'); - $body = $this->extractArgument($params, 'body'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('DataFrameTransformDeprecated\UpdateTransform'); - $endpoint->setParams($params); - $endpoint->setTransformId($transform_id); - $endpoint->setBody($body); - - return $this->performRequest($endpoint); - } -} diff --git a/src/OpenSearch/Namespaces/FlowFrameworkNamespace.php b/src/OpenSearch/Namespaces/FlowFrameworkNamespace.php index e578040d7..6d8d3164b 100644 --- a/src/OpenSearch/Namespaces/FlowFrameworkNamespace.php +++ b/src/OpenSearch/Namespaces/FlowFrameworkNamespace.php @@ -50,7 +50,7 @@ class FlowFrameworkNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function create(array $params = []) + public function create(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -75,7 +75,7 @@ public function create(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function delete(array $params = []) + public function delete(array $params = []): iterable|string|null { $workflow_id = $this->extractArgument($params, 'workflow_id'); @@ -100,7 +100,7 @@ public function delete(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deprovision(array $params = []) + public function deprovision(array $params = []): iterable|string|null { $workflow_id = $this->extractArgument($params, 'workflow_id'); @@ -124,7 +124,7 @@ public function deprovision(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function get(array $params = []) + public function get(array $params = []): iterable|string|null { $workflow_id = $this->extractArgument($params, 'workflow_id'); @@ -149,7 +149,7 @@ public function get(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getStatus(array $params = []) + public function getStatus(array $params = []): iterable|string|null { $workflow_id = $this->extractArgument($params, 'workflow_id'); @@ -173,7 +173,7 @@ public function getStatus(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getSteps(array $params = []) + public function getSteps(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetSteps::class); $endpoint->setParams($params); @@ -194,7 +194,7 @@ public function getSteps(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function provision(array $params = []) + public function provision(array $params = []): iterable|string|null { $workflow_id = $this->extractArgument($params, 'workflow_id'); $body = $this->extractArgument($params, 'body'); @@ -219,7 +219,7 @@ public function provision(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function search(array $params = []) + public function search(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -242,7 +242,7 @@ public function search(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchState(array $params = []) + public function searchState(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -271,7 +271,7 @@ public function searchState(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function update(array $params = []) + public function update(array $params = []): iterable|string|null { $workflow_id = $this->extractArgument($params, 'workflow_id'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/GeospatialNamespace.php b/src/OpenSearch/Namespaces/GeospatialNamespace.php index fe53a061f..97a705868 100644 --- a/src/OpenSearch/Namespaces/GeospatialNamespace.php +++ b/src/OpenSearch/Namespaces/GeospatialNamespace.php @@ -43,7 +43,7 @@ class GeospatialNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function deleteIp2geoDatasource(array $params = []) + public function deleteIp2geoDatasource(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -66,7 +66,7 @@ public function deleteIp2geoDatasource(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function geojsonUploadPost(array $params = []) + public function geojsonUploadPost(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -89,7 +89,7 @@ public function geojsonUploadPost(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function geojsonUploadPut(array $params = []) + public function geojsonUploadPut(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -113,7 +113,7 @@ public function geojsonUploadPut(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getIp2geoDatasource(array $params = []) + public function getIp2geoDatasource(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -136,7 +136,7 @@ public function getIp2geoDatasource(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getUploadStats(array $params = []) + public function getUploadStats(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetUploadStats::class); $endpoint->setParams($params); @@ -157,7 +157,7 @@ public function getUploadStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putIp2geoDatasource(array $params = []) + public function putIp2geoDatasource(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $body = $this->extractArgument($params, 'body'); @@ -183,7 +183,7 @@ public function putIp2geoDatasource(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putIp2geoDatasourceSettings(array $params = []) + public function putIp2geoDatasourceSettings(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/IndicesNamespace.php b/src/OpenSearch/Namespaces/IndicesNamespace.php index 2750a22bf..11fb5dcf1 100644 --- a/src/OpenSearch/Namespaces/IndicesNamespace.php +++ b/src/OpenSearch/Namespaces/IndicesNamespace.php @@ -98,7 +98,7 @@ class IndicesNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function addBlock(array $params = []) + public function addBlock(array $params = []): iterable|string|null { $block = $this->extractArgument($params, 'block'); $index = $this->extractArgument($params, 'index'); @@ -125,7 +125,7 @@ public function addBlock(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function analyze(array $params = []) + public function analyze(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -159,7 +159,7 @@ public function analyze(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function clearCache(array $params = []) + public function clearCache(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -191,7 +191,7 @@ public function clearCache(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function clone(array $params = []) + public function clone(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $target = $this->extractArgument($params, 'target'); @@ -226,7 +226,7 @@ public function clone(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function close(array $params = []) + public function close(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -255,7 +255,7 @@ public function close(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function create(array $params = []) + public function create(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -282,7 +282,7 @@ public function create(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createDataStream(array $params = []) + public function createDataStream(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $body = $this->extractArgument($params, 'body'); @@ -308,7 +308,7 @@ public function createDataStream(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function dataStreamsStats(array $params = []) + public function dataStreamsStats(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -338,7 +338,7 @@ public function dataStreamsStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function delete(array $params = []) + public function delete(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -366,7 +366,7 @@ public function delete(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteAlias(array $params = []) + public function deleteAlias(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $name = $this->extractArgument($params, 'name'); @@ -392,7 +392,7 @@ public function deleteAlias(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteDataStream(array $params = []) + public function deleteDataStream(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -419,7 +419,7 @@ public function deleteDataStream(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteIndexTemplate(array $params = []) + public function deleteIndexTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -446,7 +446,7 @@ public function deleteIndexTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteTemplate(array $params = []) + public function deleteTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -481,10 +481,6 @@ public function exists(array $params = []): bool { $index = $this->extractArgument($params, 'index'); - // Legacy option to manually make this verbose so we can check status code. - // @todo remove in 3.0.0 - $params['client']['verbose'] = true; - $endpoint = $this->endpointFactory->getEndpoint(Exists::class); $endpoint->setParams($params); $endpoint->setIndex($index); @@ -515,10 +511,6 @@ public function existsAlias(array $params = []): bool $name = $this->extractArgument($params, 'name'); $index = $this->extractArgument($params, 'index'); - // Legacy option to manually make this verbose so we can check status code. - // @todo remove in 3.0.0 - $params['client']['verbose'] = true; - $endpoint = $this->endpointFactory->getEndpoint(ExistsAlias::class); $endpoint->setParams($params); $endpoint->setName($name); @@ -548,10 +540,6 @@ public function existsIndexTemplate(array $params = []): bool { $name = $this->extractArgument($params, 'name'); - // Legacy option to manually make this verbose so we can check status code. - // @todo remove in 3.0.0 - $params['client']['verbose'] = true; - $endpoint = $this->endpointFactory->getEndpoint(ExistsIndexTemplate::class); $endpoint->setParams($params); $endpoint->setName($name); @@ -580,10 +568,6 @@ public function existsTemplate(array $params = []): bool { $name = $this->extractArgument($params, 'name'); - // Legacy option to manually make this verbose so we can check status code. - // @todo remove in 3.0.0 - $params['client']['verbose'] = true; - $endpoint = $this->endpointFactory->getEndpoint(ExistsTemplate::class); $endpoint->setParams($params); $endpoint->setName($name); @@ -609,7 +593,7 @@ public function existsTemplate(array $params = []): bool * @param array $params Associative array of parameters * @return array */ - public function flush(array $params = []) + public function flush(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -641,7 +625,7 @@ public function flush(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function forcemerge(array $params = []) + public function forcemerge(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -673,7 +657,7 @@ public function forcemerge(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function get(array $params = []) + public function get(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -702,7 +686,7 @@ public function get(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getAlias(array $params = []) + public function getAlias(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $index = $this->extractArgument($params, 'index'); @@ -728,7 +712,7 @@ public function getAlias(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getDataStream(array $params = []) + public function getDataStream(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -758,7 +742,7 @@ public function getDataStream(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getFieldMapping(array $params = []) + public function getFieldMapping(array $params = []): iterable|string|null { $fields = $this->extractArgument($params, 'fields'); $index = $this->extractArgument($params, 'index'); @@ -788,7 +772,7 @@ public function getFieldMapping(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getIndexTemplate(array $params = []) + public function getIndexTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -818,7 +802,7 @@ public function getIndexTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getMapping(array $params = []) + public function getMapping(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -851,7 +835,7 @@ public function getMapping(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getSettings(array $params = []) + public function getSettings(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $index = $this->extractArgument($params, 'index'); @@ -881,7 +865,7 @@ public function getSettings(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getTemplate(array $params = []) + public function getTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -908,7 +892,7 @@ public function getTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getUpgrade(array $params = []) + public function getUpgrade(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -941,7 +925,7 @@ public function getUpgrade(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function open(array $params = []) + public function open(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -970,7 +954,7 @@ public function open(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putAlias(array $params = []) + public function putAlias(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $index = $this->extractArgument($params, 'index'); @@ -1003,7 +987,7 @@ public function putAlias(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putIndexTemplate(array $params = []) + public function putIndexTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $body = $this->extractArgument($params, 'body'); @@ -1037,7 +1021,7 @@ public function putIndexTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putMapping(array $params = []) + public function putMapping(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1071,7 +1055,7 @@ public function putMapping(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putSettings(array $params = []) + public function putSettings(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -1102,7 +1086,7 @@ public function putSettings(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putTemplate(array $params = []) + public function putTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $body = $this->extractArgument($params, 'body'); @@ -1130,7 +1114,7 @@ public function putTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function recovery(array $params = []) + public function recovery(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -1157,7 +1141,7 @@ public function recovery(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function refresh(array $params = []) + public function refresh(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -1182,7 +1166,7 @@ public function refresh(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function resolveIndex(array $params = []) + public function resolveIndex(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -1213,7 +1197,7 @@ public function resolveIndex(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function rollover(array $params = []) + public function rollover(array $params = []): iterable|string|null { $alias = $this->extractArgument($params, 'alias'); $new_index = $this->extractArgument($params, 'new_index'); @@ -1245,7 +1229,7 @@ public function rollover(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function segments(array $params = []) + public function segments(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -1273,7 +1257,7 @@ public function segments(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function shardStores(array $params = []) + public function shardStores(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -1306,7 +1290,7 @@ public function shardStores(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function shrink(array $params = []) + public function shrink(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $target = $this->extractArgument($params, 'target'); @@ -1337,7 +1321,7 @@ public function shrink(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function simulateIndexTemplate(array $params = []) + public function simulateIndexTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $body = $this->extractArgument($params, 'body'); @@ -1367,7 +1351,7 @@ public function simulateIndexTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function simulateTemplate(array $params = []) + public function simulateTemplate(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $body = $this->extractArgument($params, 'body'); @@ -1402,7 +1386,7 @@ public function simulateTemplate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function split(array $params = []) + public function split(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $target = $this->extractArgument($params, 'target'); @@ -1440,7 +1424,7 @@ public function split(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function stats(array $params = []) + public function stats(array $params = []): iterable|string|null { $metric = $this->extractArgument($params, 'metric'); $index = $this->extractArgument($params, 'index'); @@ -1469,7 +1453,7 @@ public function stats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateAliases(array $params = []) + public function updateAliases(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1498,7 +1482,7 @@ public function updateAliases(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function upgrade(array $params = []) + public function upgrade(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -1535,7 +1519,7 @@ public function upgrade(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function validateQuery(array $params = []) + public function validateQuery(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/IngestNamespace.php b/src/OpenSearch/Namespaces/IngestNamespace.php index bb111f64c..5a125ad46 100644 --- a/src/OpenSearch/Namespaces/IngestNamespace.php +++ b/src/OpenSearch/Namespaces/IngestNamespace.php @@ -50,7 +50,7 @@ class IngestNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function deletePipeline(array $params = []) + public function deletePipeline(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -76,7 +76,7 @@ public function deletePipeline(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getPipeline(array $params = []) + public function getPipeline(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -100,7 +100,7 @@ public function getPipeline(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function processorGrok(array $params = []) + public function processorGrok(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ProcessorGrok::class); $endpoint->setParams($params); @@ -125,7 +125,7 @@ public function processorGrok(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putPipeline(array $params = []) + public function putPipeline(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $body = $this->extractArgument($params, 'body'); @@ -153,7 +153,7 @@ public function putPipeline(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function simulate(array $params = []) + public function simulate(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/IngestionNamespace.php b/src/OpenSearch/Namespaces/IngestionNamespace.php index 965e4c30f..fca5d5513 100644 --- a/src/OpenSearch/Namespaces/IngestionNamespace.php +++ b/src/OpenSearch/Namespaces/IngestionNamespace.php @@ -42,7 +42,7 @@ class IngestionNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function getState(array $params = []) + public function getState(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -68,7 +68,7 @@ public function getState(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function pause(array $params = []) + public function pause(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -94,7 +94,7 @@ public function pause(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function resume(array $params = []) + public function resume(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/InsightsNamespace.php b/src/OpenSearch/Namespaces/InsightsNamespace.php index e50eee0cd..9db070499 100644 --- a/src/OpenSearch/Namespaces/InsightsNamespace.php +++ b/src/OpenSearch/Namespaces/InsightsNamespace.php @@ -36,7 +36,7 @@ class InsightsNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function topQueries(array $params = []) + public function topQueries(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(TopQueries::class); $endpoint->setParams($params); diff --git a/src/OpenSearch/Namespaces/IsmNamespace.php b/src/OpenSearch/Namespaces/IsmNamespace.php index 7e44bc7d2..8f817ca85 100644 --- a/src/OpenSearch/Namespaces/IsmNamespace.php +++ b/src/OpenSearch/Namespaces/IsmNamespace.php @@ -48,7 +48,7 @@ class IsmNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function addPolicy(array $params = []) + public function addPolicy(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -74,7 +74,7 @@ public function addPolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function changePolicy(array $params = []) + public function changePolicy(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -100,7 +100,7 @@ public function changePolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deletePolicy(array $params = []) + public function deletePolicy(array $params = []): iterable|string|null { $policy_id = $this->extractArgument($params, 'policy_id'); @@ -128,10 +128,6 @@ public function existsPolicy(array $params = []): bool { $policy_id = $this->extractArgument($params, 'policy_id'); - // Legacy option to manually make this verbose so we can check status code. - // @todo remove in 3.0.0 - $params['client']['verbose'] = true; - $endpoint = $this->endpointFactory->getEndpoint(ExistsPolicy::class); $endpoint->setParams($params); $endpoint->setPolicyId($policy_id); @@ -152,7 +148,7 @@ public function existsPolicy(array $params = []): bool * @param array $params Associative array of parameters * @return array */ - public function explainPolicy(array $params = []) + public function explainPolicy(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -177,7 +173,7 @@ public function explainPolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getPolicies(array $params = []) + public function getPolicies(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetPolicies::class); $endpoint->setParams($params); @@ -198,7 +194,7 @@ public function getPolicies(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getPolicy(array $params = []) + public function getPolicy(array $params = []): iterable|string|null { $policy_id = $this->extractArgument($params, 'policy_id'); @@ -224,7 +220,7 @@ public function getPolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putPolicies(array $params = []) + public function putPolicies(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -250,7 +246,7 @@ public function putPolicies(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putPolicy(array $params = []) + public function putPolicy(array $params = []): iterable|string|null { $policy_id = $this->extractArgument($params, 'policy_id'); $body = $this->extractArgument($params, 'body'); @@ -276,7 +272,7 @@ public function putPolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function refreshSearchAnalyzers(array $params = []) + public function refreshSearchAnalyzers(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -300,7 +296,7 @@ public function refreshSearchAnalyzers(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function removePolicy(array $params = []) + public function removePolicy(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -324,7 +320,7 @@ public function removePolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function retryIndex(array $params = []) + public function retryIndex(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/KnnNamespace.php b/src/OpenSearch/Namespaces/KnnNamespace.php index 4257fe8ed..1a848c8e1 100644 --- a/src/OpenSearch/Namespaces/KnnNamespace.php +++ b/src/OpenSearch/Namespaces/KnnNamespace.php @@ -42,7 +42,7 @@ class KnnNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function deleteModel(array $params = []) + public function deleteModel(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); @@ -66,7 +66,7 @@ public function deleteModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getModel(array $params = []) + public function getModel(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); @@ -131,7 +131,7 @@ public function getModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchModels(array $params = []) + public function searchModels(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -157,7 +157,7 @@ public function searchModels(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function stats(array $params = []) + public function stats(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); $stat = $this->extractArgument($params, 'stat'); @@ -184,7 +184,7 @@ public function stats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function trainModel(array $params = []) + public function trainModel(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); $body = $this->extractArgument($params, 'body'); @@ -210,7 +210,7 @@ public function trainModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function warmup(array $params = []) + public function warmup(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); diff --git a/src/OpenSearch/Namespaces/ListNamespace.php b/src/OpenSearch/Namespaces/ListNamespace.php index 0b368a452..a94dbb3eb 100644 --- a/src/OpenSearch/Namespaces/ListNamespace.php +++ b/src/OpenSearch/Namespaces/ListNamespace.php @@ -38,7 +38,7 @@ class ListNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function help(array $params = []) + public function help(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Help::class); $endpoint->setParams($params); @@ -76,7 +76,7 @@ public function help(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function indices(array $params = []) + public function indices(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -113,7 +113,7 @@ public function indices(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function shards(array $params = []) + public function shards(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); diff --git a/src/OpenSearch/Namespaces/LtrNamespace.php b/src/OpenSearch/Namespaces/LtrNamespace.php index 1fb1452b2..f851bba1b 100644 --- a/src/OpenSearch/Namespaces/LtrNamespace.php +++ b/src/OpenSearch/Namespaces/LtrNamespace.php @@ -66,7 +66,7 @@ class LtrNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function addFeaturesToSet(array $params = []) + public function addFeaturesToSet(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $store = $this->extractArgument($params, 'store'); @@ -99,7 +99,7 @@ public function addFeaturesToSet(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function addFeaturesToSetByQuery(array $params = []) + public function addFeaturesToSetByQuery(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $query = $this->extractArgument($params, 'query'); @@ -126,7 +126,7 @@ public function addFeaturesToSetByQuery(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function cacheStats(array $params = []) + public function cacheStats(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(CacheStats::class); $endpoint->setParams($params); @@ -147,7 +147,7 @@ public function cacheStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function clearCache(array $params = []) + public function clearCache(array $params = []): iterable|string|null { $store = $this->extractArgument($params, 'store'); @@ -170,7 +170,7 @@ public function clearCache(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createDefaultStore(array $params = []) + public function createDefaultStore(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(CreateDefaultStore::class); $endpoint->setParams($params); @@ -193,7 +193,7 @@ public function createDefaultStore(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createFeature(array $params = []) + public function createFeature(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); @@ -223,7 +223,7 @@ public function createFeature(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createFeatureset(array $params = []) + public function createFeatureset(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); @@ -253,7 +253,7 @@ public function createFeatureset(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createModel(array $params = []) + public function createModel(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); @@ -283,7 +283,7 @@ public function createModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createModelFromSet(array $params = []) + public function createModelFromSet(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $store = $this->extractArgument($params, 'store'); @@ -311,7 +311,7 @@ public function createModelFromSet(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createStore(array $params = []) + public function createStore(array $params = []): iterable|string|null { $store = $this->extractArgument($params, 'store'); @@ -334,7 +334,7 @@ public function createStore(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteDefaultStore(array $params = []) + public function deleteDefaultStore(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(DeleteDefaultStore::class); $endpoint->setParams($params); @@ -356,7 +356,7 @@ public function deleteDefaultStore(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteFeature(array $params = []) + public function deleteFeature(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); @@ -383,7 +383,7 @@ public function deleteFeature(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteFeatureset(array $params = []) + public function deleteFeatureset(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); @@ -410,7 +410,7 @@ public function deleteFeatureset(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteModel(array $params = []) + public function deleteModel(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); @@ -436,7 +436,7 @@ public function deleteModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteStore(array $params = []) + public function deleteStore(array $params = []): iterable|string|null { $store = $this->extractArgument($params, 'store'); @@ -461,7 +461,7 @@ public function deleteStore(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getFeature(array $params = []) + public function getFeature(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); @@ -488,7 +488,7 @@ public function getFeature(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getFeatureset(array $params = []) + public function getFeatureset(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); @@ -515,7 +515,7 @@ public function getFeatureset(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getModel(array $params = []) + public function getModel(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); @@ -541,7 +541,7 @@ public function getModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getStore(array $params = []) + public function getStore(array $params = []): iterable|string|null { $store = $this->extractArgument($params, 'store'); @@ -564,7 +564,7 @@ public function getStore(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function listStores(array $params = []) + public function listStores(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ListStores::class); $endpoint->setParams($params); @@ -588,7 +588,7 @@ public function listStores(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchFeatures(array $params = []) + public function searchFeatures(array $params = []): iterable|string|null { $store = $this->extractArgument($params, 'store'); @@ -615,7 +615,7 @@ public function searchFeatures(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchFeaturesets(array $params = []) + public function searchFeaturesets(array $params = []): iterable|string|null { $store = $this->extractArgument($params, 'store'); @@ -642,7 +642,7 @@ public function searchFeaturesets(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchModels(array $params = []) + public function searchModels(array $params = []): iterable|string|null { $store = $this->extractArgument($params, 'store'); @@ -668,7 +668,7 @@ public function searchModels(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function stats(array $params = []) + public function stats(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); $stat = $this->extractArgument($params, 'stat'); @@ -696,7 +696,7 @@ public function stats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateFeature(array $params = []) + public function updateFeature(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); @@ -726,7 +726,7 @@ public function updateFeature(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateFeatureset(array $params = []) + public function updateFeatureset(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $store = $this->extractArgument($params, 'store'); diff --git a/src/OpenSearch/Namespaces/MlNamespace.php b/src/OpenSearch/Namespaces/MlNamespace.php index 07574ed24..01b181409 100644 --- a/src/OpenSearch/Namespaces/MlNamespace.php +++ b/src/OpenSearch/Namespaces/MlNamespace.php @@ -98,7 +98,7 @@ class MlNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function chunkModel(array $params = []) + public function chunkModel(array $params = []): iterable|string|null { $chunk_number = $this->extractArgument($params, 'chunk_number'); $model_id = $this->extractArgument($params, 'model_id'); @@ -126,7 +126,7 @@ public function chunkModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createController(array $params = []) + public function createController(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); $body = $this->extractArgument($params, 'body'); @@ -151,7 +151,7 @@ public function createController(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createMemory(array $params = []) + public function createMemory(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -175,7 +175,7 @@ public function createMemory(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createMessage(array $params = []) + public function createMessage(array $params = []): iterable|string|null { $memory_id = $this->extractArgument($params, 'memory_id'); $body = $this->extractArgument($params, 'body'); @@ -200,7 +200,7 @@ public function createMessage(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createModelMeta(array $params = []) + public function createModelMeta(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -224,7 +224,7 @@ public function createModelMeta(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteAgent(array $params = []) + public function deleteAgent(array $params = []): iterable|string|null { $agent_id = $this->extractArgument($params, 'agent_id'); @@ -248,7 +248,7 @@ public function deleteAgent(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteController(array $params = []) + public function deleteController(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); @@ -272,7 +272,7 @@ public function deleteController(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteMemory(array $params = []) + public function deleteMemory(array $params = []): iterable|string|null { $memory_id = $this->extractArgument($params, 'memory_id'); @@ -296,7 +296,7 @@ public function deleteMemory(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteModel(array $params = []) + public function deleteModel(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -320,7 +320,7 @@ public function deleteModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteModelGroup(array $params = []) + public function deleteModelGroup(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -344,7 +344,7 @@ public function deleteModelGroup(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteTask(array $params = []) + public function deleteTask(array $params = []): iterable|string|null { $task_id = $this->extractArgument($params, 'task_id'); @@ -368,7 +368,7 @@ public function deleteTask(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function executeAgent(array $params = []) + public function executeAgent(array $params = []): iterable|string|null { $agent_id = $this->extractArgument($params, 'agent_id'); $body = $this->extractArgument($params, 'body'); @@ -394,7 +394,7 @@ public function executeAgent(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function executeAlgorithm(array $params = []) + public function executeAlgorithm(array $params = []): iterable|string|null { $algorithm_name = $this->extractArgument($params, 'algorithm_name'); $body = $this->extractArgument($params, 'body'); @@ -420,7 +420,7 @@ public function executeAlgorithm(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getAgent(array $params = []) + public function getAgent(array $params = []): iterable|string|null { $agent_id = $this->extractArgument($params, 'agent_id'); @@ -445,7 +445,7 @@ public function getAgent(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getAllMemories(array $params = []) + public function getAllMemories(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetAllMemories::class); $endpoint->setParams($params); @@ -468,7 +468,7 @@ public function getAllMemories(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getAllMessages(array $params = []) + public function getAllMessages(array $params = []): iterable|string|null { $memory_id = $this->extractArgument($params, 'memory_id'); @@ -491,7 +491,7 @@ public function getAllMessages(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getAllTools(array $params = []) + public function getAllTools(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetAllTools::class); $endpoint->setParams($params); @@ -512,7 +512,7 @@ public function getAllTools(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getController(array $params = []) + public function getController(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); @@ -536,7 +536,7 @@ public function getController(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getMemory(array $params = []) + public function getMemory(array $params = []): iterable|string|null { $memory_id = $this->extractArgument($params, 'memory_id'); @@ -560,7 +560,7 @@ public function getMemory(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getMessage(array $params = []) + public function getMessage(array $params = []): iterable|string|null { $message_id = $this->extractArgument($params, 'message_id'); @@ -586,7 +586,7 @@ public function getMessage(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getMessageTraces(array $params = []) + public function getMessageTraces(array $params = []): iterable|string|null { $message_id = $this->extractArgument($params, 'message_id'); @@ -610,7 +610,7 @@ public function getMessageTraces(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getModelGroup(array $params = []) + public function getModelGroup(array $params = []): iterable|string|null { $model_group_id = $this->extractArgument($params, 'model_group_id'); @@ -633,7 +633,7 @@ public function getModelGroup(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getProfile(array $params = []) + public function getProfile(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -657,7 +657,7 @@ public function getProfile(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getProfileModels(array $params = []) + public function getProfileModels(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); $body = $this->extractArgument($params, 'body'); @@ -683,7 +683,7 @@ public function getProfileModels(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getProfileTasks(array $params = []) + public function getProfileTasks(array $params = []): iterable|string|null { $task_id = $this->extractArgument($params, 'task_id'); $body = $this->extractArgument($params, 'body'); @@ -710,7 +710,7 @@ public function getProfileTasks(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getStats(array $params = []) + public function getStats(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); $stat = $this->extractArgument($params, 'stat'); @@ -736,7 +736,7 @@ public function getStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getTask(array $params = []) + public function getTask(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -760,7 +760,7 @@ public function getTask(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getTool(array $params = []) + public function getTool(array $params = []): iterable|string|null { $tool_name = $this->extractArgument($params, 'tool_name'); @@ -784,7 +784,7 @@ public function getTool(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function loadModel(array $params = []) + public function loadModel(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); @@ -808,7 +808,7 @@ public function loadModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function predictModel(array $params = []) + public function predictModel(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); $body = $this->extractArgument($params, 'body'); @@ -833,7 +833,7 @@ public function predictModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function registerAgents(array $params = []) + public function registerAgents(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -856,7 +856,7 @@ public function registerAgents(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function registerModel(array $params = []) + public function registerModel(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -879,7 +879,7 @@ public function registerModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function registerModelGroup(array $params = []) + public function registerModelGroup(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -902,7 +902,7 @@ public function registerModelGroup(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function registerModelMeta(array $params = []) + public function registerModelMeta(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -925,7 +925,7 @@ public function registerModelMeta(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchAgents(array $params = []) + public function searchAgents(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -948,7 +948,7 @@ public function searchAgents(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchConnectors(array $params = []) + public function searchConnectors(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -971,7 +971,7 @@ public function searchConnectors(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchMemory(array $params = []) + public function searchMemory(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -995,7 +995,7 @@ public function searchMemory(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchMessage(array $params = []) + public function searchMessage(array $params = []): iterable|string|null { $memory_id = $this->extractArgument($params, 'memory_id'); $body = $this->extractArgument($params, 'body'); @@ -1020,7 +1020,7 @@ public function searchMessage(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchModelGroup(array $params = []) + public function searchModelGroup(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1043,7 +1043,7 @@ public function searchModelGroup(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchModels(array $params = []) + public function searchModels(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1066,7 +1066,7 @@ public function searchModels(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchTasks(array $params = []) + public function searchTasks(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1090,7 +1090,7 @@ public function searchTasks(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function train(array $params = []) + public function train(array $params = []): iterable|string|null { $algorithm_name = $this->extractArgument($params, 'algorithm_name'); $body = $this->extractArgument($params, 'body'); @@ -1116,7 +1116,7 @@ public function train(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function trainPredict(array $params = []) + public function trainPredict(array $params = []): iterable|string|null { $algorithm_name = $this->extractArgument($params, 'algorithm_name'); $body = $this->extractArgument($params, 'body'); @@ -1142,7 +1142,7 @@ public function trainPredict(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function unloadModel(array $params = []) + public function unloadModel(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); $body = $this->extractArgument($params, 'body'); @@ -1168,7 +1168,7 @@ public function unloadModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateConnector(array $params = []) + public function updateConnector(array $params = []): iterable|string|null { $connector_id = $this->extractArgument($params, 'connector_id'); $body = $this->extractArgument($params, 'body'); @@ -1194,7 +1194,7 @@ public function updateConnector(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateController(array $params = []) + public function updateController(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); $body = $this->extractArgument($params, 'body'); @@ -1220,7 +1220,7 @@ public function updateController(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateMemory(array $params = []) + public function updateMemory(array $params = []): iterable|string|null { $memory_id = $this->extractArgument($params, 'memory_id'); $body = $this->extractArgument($params, 'body'); @@ -1246,7 +1246,7 @@ public function updateMemory(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateMessage(array $params = []) + public function updateMessage(array $params = []): iterable|string|null { $message_id = $this->extractArgument($params, 'message_id'); $body = $this->extractArgument($params, 'body'); @@ -1272,7 +1272,7 @@ public function updateMessage(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateModel(array $params = []) + public function updateModel(array $params = []): iterable|string|null { $model_id = $this->extractArgument($params, 'model_id'); $body = $this->extractArgument($params, 'body'); @@ -1299,7 +1299,7 @@ public function updateModel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function uploadChunk(array $params = []) + public function uploadChunk(array $params = []): iterable|string|null { $chunk_number = $this->extractArgument($params, 'chunk_number'); $model_id = $this->extractArgument($params, 'model_id'); @@ -1326,7 +1326,7 @@ public function uploadChunk(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function uploadModel(array $params = []) + public function uploadModel(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/MonitoringNamespace.php b/src/OpenSearch/Namespaces/MonitoringNamespace.php deleted file mode 100644 index b4a8f042f..000000000 --- a/src/OpenSearch/Namespaces/MonitoringNamespace.php +++ /dev/null @@ -1,58 +0,0 @@ -extractArgument($params, 'type'); - $body = $this->extractArgument($params, 'body'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Monitoring\Bulk'); - $endpoint->setParams($params); - $endpoint->setType($type); - $endpoint->setBody($body); - - return $this->performRequest($endpoint); - } -} diff --git a/src/OpenSearch/Namespaces/NamespaceBuilderInterface.php b/src/OpenSearch/Namespaces/NamespaceBuilderInterface.php index 4c82be46d..0b25e917e 100644 --- a/src/OpenSearch/Namespaces/NamespaceBuilderInterface.php +++ b/src/OpenSearch/Namespaces/NamespaceBuilderInterface.php @@ -22,7 +22,6 @@ namespace OpenSearch\Namespaces; use OpenSearch\Serializers\SerializerInterface; -use OpenSearch\Transport; use OpenSearch\TransportInterface; interface NamespaceBuilderInterface @@ -37,12 +36,6 @@ public function getName(): string; * Returns the actual namespace object which contains your custom methods. The transport * and serializer objects are provided so that your namespace may do whatever custom * logic is required. - * - * @param Transport|TransportInterface $transport - * @param SerializerInterface $serializer - * @return Object - * - * @phpstan-ignore parameter.deprecatedClass */ - public function getObject(Transport|TransportInterface $transport, SerializerInterface $serializer); + public function getObject(TransportInterface $transport, SerializerInterface $serializer): object; } diff --git a/src/OpenSearch/Namespaces/NeuralNamespace.php b/src/OpenSearch/Namespaces/NeuralNamespace.php index 337857098..e4ee3d09e 100644 --- a/src/OpenSearch/Namespaces/NeuralNamespace.php +++ b/src/OpenSearch/Namespaces/NeuralNamespace.php @@ -43,7 +43,7 @@ class NeuralNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function stats(array $params = []) + public function stats(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); $stat = $this->extractArgument($params, 'stat'); diff --git a/src/OpenSearch/Namespaces/NodesNamespace.php b/src/OpenSearch/Namespaces/NodesNamespace.php index e4b1752a5..2b34719fe 100644 --- a/src/OpenSearch/Namespaces/NodesNamespace.php +++ b/src/OpenSearch/Namespaces/NodesNamespace.php @@ -53,7 +53,7 @@ class NodesNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function hotThreads(array $params = []) + public function hotThreads(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); @@ -81,7 +81,7 @@ public function hotThreads(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function info(array $params = []) + public function info(array $params = []): iterable|string|null { $node_id_or_metric = $this->extractArgument($params, 'node_id_or_metric'); $metric = $this->extractArgument($params, 'metric'); @@ -111,7 +111,7 @@ public function info(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function reloadSecureSettings(array $params = []) + public function reloadSecureSettings(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); $body = $this->extractArgument($params, 'body'); @@ -147,7 +147,7 @@ public function reloadSecureSettings(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function stats(array $params = []) + public function stats(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); $metric = $this->extractArgument($params, 'metric'); @@ -177,7 +177,7 @@ public function stats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function usage(array $params = []) + public function usage(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); $metric = $this->extractArgument($params, 'metric'); diff --git a/src/OpenSearch/Namespaces/NotificationsNamespace.php b/src/OpenSearch/Namespaces/NotificationsNamespace.php index fafce2f5c..177957e94 100644 --- a/src/OpenSearch/Namespaces/NotificationsNamespace.php +++ b/src/OpenSearch/Namespaces/NotificationsNamespace.php @@ -44,7 +44,7 @@ class NotificationsNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function createConfig(array $params = []) + public function createConfig(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -68,7 +68,7 @@ public function createConfig(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteConfig(array $params = []) + public function deleteConfig(array $params = []): iterable|string|null { $config_id = $this->extractArgument($params, 'config_id'); @@ -93,7 +93,7 @@ public function deleteConfig(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteConfigs(array $params = []) + public function deleteConfigs(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(DeleteConfigs::class); $endpoint->setParams($params); @@ -114,7 +114,7 @@ public function deleteConfigs(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getConfig(array $params = []) + public function getConfig(array $params = []): iterable|string|null { $config_id = $this->extractArgument($params, 'config_id'); @@ -177,7 +177,7 @@ public function getConfig(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getConfigs(array $params = []) + public function getConfigs(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -200,7 +200,7 @@ public function getConfigs(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function listChannels(array $params = []) + public function listChannels(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ListChannels::class); $endpoint->setParams($params); @@ -220,7 +220,7 @@ public function listChannels(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function listFeatures(array $params = []) + public function listFeatures(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ListFeatures::class); $endpoint->setParams($params); @@ -241,7 +241,7 @@ public function listFeatures(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function sendTest(array $params = []) + public function sendTest(array $params = []): iterable|string|null { $config_id = $this->extractArgument($params, 'config_id'); @@ -265,7 +265,7 @@ public function sendTest(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateConfig(array $params = []) + public function updateConfig(array $params = []): iterable|string|null { $config_id = $this->extractArgument($params, 'config_id'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/ObservabilityNamespace.php b/src/OpenSearch/Namespaces/ObservabilityNamespace.php index 03e274d7e..7676aadd6 100644 --- a/src/OpenSearch/Namespaces/ObservabilityNamespace.php +++ b/src/OpenSearch/Namespaces/ObservabilityNamespace.php @@ -42,7 +42,7 @@ class ObservabilityNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function createObject(array $params = []) + public function createObject(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -66,7 +66,7 @@ public function createObject(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteObject(array $params = []) + public function deleteObject(array $params = []): iterable|string|null { $object_id = $this->extractArgument($params, 'object_id'); @@ -91,7 +91,7 @@ public function deleteObject(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteObjects(array $params = []) + public function deleteObjects(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(DeleteObjects::class); $endpoint->setParams($params); @@ -111,7 +111,7 @@ public function deleteObjects(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getLocalstats(array $params = []) + public function getLocalstats(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetLocalstats::class); $endpoint->setParams($params); @@ -132,7 +132,7 @@ public function getLocalstats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getObject(array $params = []) + public function getObject(array $params = []): iterable|string|null { $object_id = $this->extractArgument($params, 'object_id'); @@ -155,7 +155,7 @@ public function getObject(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function listObjects(array $params = []) + public function listObjects(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ListObjects::class); $endpoint->setParams($params); @@ -176,7 +176,7 @@ public function listObjects(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateObject(array $params = []) + public function updateObject(array $params = []): iterable|string|null { $object_id = $this->extractArgument($params, 'object_id'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/PplNamespace.php b/src/OpenSearch/Namespaces/PplNamespace.php index c3bd317da..9dfc96db5 100644 --- a/src/OpenSearch/Namespaces/PplNamespace.php +++ b/src/OpenSearch/Namespaces/PplNamespace.php @@ -41,7 +41,7 @@ class PplNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function explain(array $params = []) + public function explain(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -66,7 +66,7 @@ public function explain(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getStats(array $params = []) + public function getStats(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetStats::class); $endpoint->setParams($params); @@ -88,7 +88,7 @@ public function getStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function postStats(array $params = []) + public function postStats(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -113,7 +113,7 @@ public function postStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function query(array $params = []) + public function query(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/QueryNamespace.php b/src/OpenSearch/Namespaces/QueryNamespace.php index 9c951714a..41d17aee7 100644 --- a/src/OpenSearch/Namespaces/QueryNamespace.php +++ b/src/OpenSearch/Namespaces/QueryNamespace.php @@ -41,7 +41,7 @@ class QueryNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function datasourceDelete(array $params = []) + public function datasourceDelete(array $params = []): iterable|string|null { $datasource_name = $this->extractArgument($params, 'datasource_name'); @@ -65,7 +65,7 @@ public function datasourceDelete(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function datasourceRetrieve(array $params = []) + public function datasourceRetrieve(array $params = []): iterable|string|null { $datasource_name = $this->extractArgument($params, 'datasource_name'); @@ -88,7 +88,7 @@ public function datasourceRetrieve(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function datasourcesCreate(array $params = []) + public function datasourcesCreate(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -111,7 +111,7 @@ public function datasourcesCreate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function datasourcesList(array $params = []) + public function datasourcesList(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(DatasourcesList::class); $endpoint->setParams($params); @@ -131,7 +131,7 @@ public function datasourcesList(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function datasourcesUpdate(array $params = []) + public function datasourcesUpdate(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/RemoteStoreNamespace.php b/src/OpenSearch/Namespaces/RemoteStoreNamespace.php index 2bcb3c6fd..6814e8f85 100644 --- a/src/OpenSearch/Namespaces/RemoteStoreNamespace.php +++ b/src/OpenSearch/Namespaces/RemoteStoreNamespace.php @@ -39,7 +39,7 @@ class RemoteStoreNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function restore(array $params = []) + public function restore(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/ReplicationNamespace.php b/src/OpenSearch/Namespaces/ReplicationNamespace.php index cc89819d9..854dd9b24 100644 --- a/src/OpenSearch/Namespaces/ReplicationNamespace.php +++ b/src/OpenSearch/Namespaces/ReplicationNamespace.php @@ -46,7 +46,7 @@ class ReplicationNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function autofollowStats(array $params = []) + public function autofollowStats(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(AutofollowStats::class); $endpoint->setParams($params); @@ -66,7 +66,7 @@ public function autofollowStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createReplicationRule(array $params = []) + public function createReplicationRule(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -89,7 +89,7 @@ public function createReplicationRule(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteReplicationRule(array $params = []) + public function deleteReplicationRule(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -112,7 +112,7 @@ public function deleteReplicationRule(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function followerStats(array $params = []) + public function followerStats(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(FollowerStats::class); $endpoint->setParams($params); @@ -132,7 +132,7 @@ public function followerStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function leaderStats(array $params = []) + public function leaderStats(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(LeaderStats::class); $endpoint->setParams($params); @@ -153,7 +153,7 @@ public function leaderStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function pause(array $params = []) + public function pause(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -179,7 +179,7 @@ public function pause(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function resume(array $params = []) + public function resume(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -205,7 +205,7 @@ public function resume(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function start(array $params = []) + public function start(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -231,7 +231,7 @@ public function start(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function status(array $params = []) + public function status(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); @@ -255,7 +255,7 @@ public function status(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function stop(array $params = []) + public function stop(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); @@ -281,7 +281,7 @@ public function stop(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateSettings(array $params = []) + public function updateSettings(array $params = []): iterable|string|null { $index = $this->extractArgument($params, 'index'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/RollupsNamespace.php b/src/OpenSearch/Namespaces/RollupsNamespace.php index 6af34ad21..d70d76e9b 100644 --- a/src/OpenSearch/Namespaces/RollupsNamespace.php +++ b/src/OpenSearch/Namespaces/RollupsNamespace.php @@ -42,7 +42,7 @@ class RollupsNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function delete(array $params = []) + public function delete(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -66,7 +66,7 @@ public function delete(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function explain(array $params = []) + public function explain(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -90,7 +90,7 @@ public function explain(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function get(array $params = []) + public function get(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -116,7 +116,7 @@ public function get(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function put(array $params = []) + public function put(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $body = $this->extractArgument($params, 'body'); @@ -142,7 +142,7 @@ public function put(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function start(array $params = []) + public function start(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -166,7 +166,7 @@ public function start(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function stop(array $params = []) + public function stop(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); diff --git a/src/OpenSearch/Namespaces/SearchPipelineNamespace.php b/src/OpenSearch/Namespaces/SearchPipelineNamespace.php index 528d0ebf0..749e2bb3d 100644 --- a/src/OpenSearch/Namespaces/SearchPipelineNamespace.php +++ b/src/OpenSearch/Namespaces/SearchPipelineNamespace.php @@ -41,7 +41,7 @@ class SearchPipelineNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function delete(array $params = []) + public function delete(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -66,7 +66,7 @@ public function delete(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function get(array $params = []) + public function get(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -92,7 +92,7 @@ public function get(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function put(array $params = []) + public function put(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/SearchRelevanceNamespace.php b/src/OpenSearch/Namespaces/SearchRelevanceNamespace.php index 2d062d3b6..9c63f9d39 100644 --- a/src/OpenSearch/Namespaces/SearchRelevanceNamespace.php +++ b/src/OpenSearch/Namespaces/SearchRelevanceNamespace.php @@ -51,7 +51,7 @@ class SearchRelevanceNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function deleteExperiments(array $params = []) + public function deleteExperiments(array $params = []): iterable|string|null { $experiment_id = $this->extractArgument($params, 'experiment_id'); @@ -75,7 +75,7 @@ public function deleteExperiments(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteJudgments(array $params = []) + public function deleteJudgments(array $params = []): iterable|string|null { $judgment_id = $this->extractArgument($params, 'judgment_id'); @@ -99,7 +99,7 @@ public function deleteJudgments(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteQuerySets(array $params = []) + public function deleteQuerySets(array $params = []): iterable|string|null { $query_set_id = $this->extractArgument($params, 'query_set_id'); @@ -123,7 +123,7 @@ public function deleteQuerySets(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteSearchConfigurations(array $params = []) + public function deleteSearchConfigurations(array $params = []): iterable|string|null { $search_configuration_id = $this->extractArgument($params, 'search_configuration_id'); @@ -147,7 +147,7 @@ public function deleteSearchConfigurations(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getExperiments(array $params = []) + public function getExperiments(array $params = []): iterable|string|null { $experiment_id = $this->extractArgument($params, 'experiment_id'); @@ -171,7 +171,7 @@ public function getExperiments(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getJudgments(array $params = []) + public function getJudgments(array $params = []): iterable|string|null { $judgment_id = $this->extractArgument($params, 'judgment_id'); @@ -201,7 +201,7 @@ public function getJudgments(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getNodeStats(array $params = []) + public function getNodeStats(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); $stat = $this->extractArgument($params, 'stat'); @@ -227,7 +227,7 @@ public function getNodeStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getQuerySets(array $params = []) + public function getQuerySets(array $params = []): iterable|string|null { $query_set_id = $this->extractArgument($params, 'query_set_id'); @@ -251,7 +251,7 @@ public function getQuerySets(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getSearchConfigurations(array $params = []) + public function getSearchConfigurations(array $params = []): iterable|string|null { $search_configuration_id = $this->extractArgument($params, 'search_configuration_id'); @@ -280,7 +280,7 @@ public function getSearchConfigurations(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getStats(array $params = []) + public function getStats(array $params = []): iterable|string|null { $stat = $this->extractArgument($params, 'stat'); @@ -303,7 +303,7 @@ public function getStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function postQuerySets(array $params = []) + public function postQuerySets(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -326,7 +326,7 @@ public function postQuerySets(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putExperiments(array $params = []) + public function putExperiments(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -349,7 +349,7 @@ public function putExperiments(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putJudgments(array $params = []) + public function putJudgments(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -372,7 +372,7 @@ public function putJudgments(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putQuerySets(array $params = []) + public function putQuerySets(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -395,7 +395,7 @@ public function putQuerySets(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function putSearchConfigurations(array $params = []) + public function putSearchConfigurations(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/SearchableSnapshotsNamespace.php b/src/OpenSearch/Namespaces/SearchableSnapshotsNamespace.php deleted file mode 100644 index e96c70ad5..000000000 --- a/src/OpenSearch/Namespaces/SearchableSnapshotsNamespace.php +++ /dev/null @@ -1,126 +0,0 @@ -extractArgument($params, 'index'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('SearchableSnapshots\ClearCache'); - $endpoint->setParams($params); - $endpoint->setIndex($index); - - return $this->performRequest($endpoint); - } - /** - * $params['repository'] = (string) The name of the repository containing the snapshot of the index to mount - * $params['snapshot'] = (string) The name of the snapshot of the index to mount - * $params['cluster_manager_timeout'] = (time) Explicit operation timeout for connection to cluster_manager node - * $params['wait_for_completion'] = (boolean) Should this request wait until the operation has completed before returning (Default = false) - * $params['body'] = (array) The restore configuration for mounting the snapshot as searchable (Required) - * - * @param array $params Associative array of parameters - * @return array - - * - * @note This API is EXPERIMENTAL and may be changed or removed completely in a future release - * - */ - public function mount(array $params = []) - { - $repository = $this->extractArgument($params, 'repository'); - $snapshot = $this->extractArgument($params, 'snapshot'); - $body = $this->extractArgument($params, 'body'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('SearchableSnapshots\Mount'); - $endpoint->setParams($params); - $endpoint->setRepository($repository); - $endpoint->setSnapshot($snapshot); - $endpoint->setBody($body); - - return $this->performRequest($endpoint); - } - /** - * $params['repository'] = (string) The repository for which to get the stats for - * - * @param array $params Associative array of parameters - * @return array - - * - * @note This API is EXPERIMENTAL and may be changed or removed completely in a future release - * - */ - public function repositoryStats(array $params = []) - { - $repository = $this->extractArgument($params, 'repository'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('SearchableSnapshots\RepositoryStats'); - $endpoint->setParams($params); - $endpoint->setRepository($repository); - - return $this->performRequest($endpoint); - } - /** - * $params['index'] = (list) A comma-separated list of index names - * - * @param array $params Associative array of parameters - * @return array - - * - * @note This API is EXPERIMENTAL and may be changed or removed completely in a future release - * - */ - public function stats(array $params = []) - { - $index = $this->extractArgument($params, 'index'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('SearchableSnapshots\Stats'); - $endpoint->setParams($params); - $endpoint->setIndex($index); - - return $this->performRequest($endpoint); - } -} diff --git a/src/OpenSearch/Namespaces/SecurityAnalyticsNamespace.php b/src/OpenSearch/Namespaces/SecurityAnalyticsNamespace.php index 8e4294ee4..54a815c39 100644 --- a/src/OpenSearch/Namespaces/SecurityAnalyticsNamespace.php +++ b/src/OpenSearch/Namespaces/SecurityAnalyticsNamespace.php @@ -50,7 +50,7 @@ class SecurityAnalyticsNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function getAlerts(array $params = []) + public function getAlerts(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetAlerts::class); $endpoint->setParams($params); @@ -83,7 +83,7 @@ public function getAlerts(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getFindings(array $params = []) + public function getFindings(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetFindings::class); $endpoint->setParams($params); @@ -107,7 +107,7 @@ public function getFindings(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function searchFindingCorrelations(array $params = []) + public function searchFindingCorrelations(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(SearchFindingCorrelations::class); $endpoint->setParams($params); diff --git a/src/OpenSearch/Namespaces/SecurityNamespace.php b/src/OpenSearch/Namespaces/SecurityNamespace.php index c6ee8ce17..a5a03404b 100644 --- a/src/OpenSearch/Namespaces/SecurityNamespace.php +++ b/src/OpenSearch/Namespaces/SecurityNamespace.php @@ -114,7 +114,7 @@ class SecurityNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function authinfo(array $params = []) + public function authinfo(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Authinfo::class); $endpoint->setParams($params); @@ -134,7 +134,7 @@ public function authinfo(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function authtoken(array $params = []) + public function authtoken(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Authtoken::class); $endpoint->setParams($params); @@ -154,7 +154,7 @@ public function authtoken(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function cache(array $params = []) + public function cache(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Cache::class); $endpoint->setParams($params); @@ -174,7 +174,7 @@ public function cache(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function configUpgradeCheck(array $params = []) + public function configUpgradeCheck(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ConfigUpgradeCheck::class); $endpoint->setParams($params); @@ -194,7 +194,7 @@ public function configUpgradeCheck(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function configUpgradePerform(array $params = []) + public function configUpgradePerform(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -217,7 +217,7 @@ public function configUpgradePerform(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createAllowlist(array $params = []) + public function createAllowlist(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -240,7 +240,7 @@ public function createAllowlist(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createUpdateTenancyConfig(array $params = []) + public function createUpdateTenancyConfig(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -264,7 +264,7 @@ public function createUpdateTenancyConfig(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createUserLegacy(array $params = []) + public function createUserLegacy(array $params = []): iterable|string|null { $username = $this->extractArgument($params, 'username'); $body = $this->extractArgument($params, 'body'); @@ -290,7 +290,7 @@ public function createUserLegacy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteActionGroup(array $params = []) + public function deleteActionGroup(array $params = []): iterable|string|null { $action_group = $this->extractArgument($params, 'action_group'); @@ -314,7 +314,7 @@ public function deleteActionGroup(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteDistinguishedName(array $params = []) + public function deleteDistinguishedName(array $params = []): iterable|string|null { $cluster_name = $this->extractArgument($params, 'cluster_name'); @@ -338,7 +338,7 @@ public function deleteDistinguishedName(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteRole(array $params = []) + public function deleteRole(array $params = []): iterable|string|null { $role = $this->extractArgument($params, 'role'); @@ -362,7 +362,7 @@ public function deleteRole(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteRoleMapping(array $params = []) + public function deleteRoleMapping(array $params = []): iterable|string|null { $role = $this->extractArgument($params, 'role'); @@ -386,7 +386,7 @@ public function deleteRoleMapping(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteTenant(array $params = []) + public function deleteTenant(array $params = []): iterable|string|null { $tenant = $this->extractArgument($params, 'tenant'); @@ -410,7 +410,7 @@ public function deleteTenant(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteUser(array $params = []) + public function deleteUser(array $params = []): iterable|string|null { $username = $this->extractArgument($params, 'username'); @@ -434,7 +434,7 @@ public function deleteUser(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteUserLegacy(array $params = []) + public function deleteUserLegacy(array $params = []): iterable|string|null { $username = $this->extractArgument($params, 'username'); @@ -457,7 +457,7 @@ public function deleteUserLegacy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function flushCache(array $params = []) + public function flushCache(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(FlushCache::class); $endpoint->setParams($params); @@ -477,7 +477,7 @@ public function flushCache(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function generateOboToken(array $params = []) + public function generateOboToken(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -501,7 +501,7 @@ public function generateOboToken(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function generateUserToken(array $params = []) + public function generateUserToken(array $params = []): iterable|string|null { $username = $this->extractArgument($params, 'username'); @@ -525,7 +525,7 @@ public function generateUserToken(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function generateUserTokenLegacy(array $params = []) + public function generateUserTokenLegacy(array $params = []): iterable|string|null { $username = $this->extractArgument($params, 'username'); @@ -548,7 +548,7 @@ public function generateUserTokenLegacy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getAccountDetails(array $params = []) + public function getAccountDetails(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetAccountDetails::class); $endpoint->setParams($params); @@ -569,7 +569,7 @@ public function getAccountDetails(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getActionGroup(array $params = []) + public function getActionGroup(array $params = []): iterable|string|null { $action_group = $this->extractArgument($params, 'action_group'); @@ -594,7 +594,7 @@ public function getActionGroup(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getAllCertificates(array $params = []) + public function getAllCertificates(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetAllCertificates::class); $endpoint->setParams($params); @@ -614,7 +614,7 @@ public function getAllCertificates(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getAllowlist(array $params = []) + public function getAllowlist(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetAllowlist::class); $endpoint->setParams($params); @@ -634,7 +634,7 @@ public function getAllowlist(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getAuditConfiguration(array $params = []) + public function getAuditConfiguration(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetAuditConfiguration::class); $endpoint->setParams($params); @@ -654,7 +654,7 @@ public function getAuditConfiguration(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getCertificates(array $params = []) + public function getCertificates(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetCertificates::class); $endpoint->setParams($params); @@ -674,7 +674,7 @@ public function getCertificates(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getConfiguration(array $params = []) + public function getConfiguration(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetConfiguration::class); $endpoint->setParams($params); @@ -694,7 +694,7 @@ public function getConfiguration(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getDashboardsInfo(array $params = []) + public function getDashboardsInfo(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetDashboardsInfo::class); $endpoint->setParams($params); @@ -716,7 +716,7 @@ public function getDashboardsInfo(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getDistinguishedName(array $params = []) + public function getDistinguishedName(array $params = []): iterable|string|null { $cluster_name = $this->extractArgument($params, 'cluster_name'); @@ -742,7 +742,7 @@ public function getDistinguishedName(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getNodeCertificates(array $params = []) + public function getNodeCertificates(array $params = []): iterable|string|null { $node_id = $this->extractArgument($params, 'node_id'); @@ -765,7 +765,7 @@ public function getNodeCertificates(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getPermissionsInfo(array $params = []) + public function getPermissionsInfo(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetPermissionsInfo::class); $endpoint->setParams($params); @@ -786,7 +786,7 @@ public function getPermissionsInfo(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getRole(array $params = []) + public function getRole(array $params = []): iterable|string|null { $role = $this->extractArgument($params, 'role'); @@ -810,7 +810,7 @@ public function getRole(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getRoleMapping(array $params = []) + public function getRoleMapping(array $params = []): iterable|string|null { $role = $this->extractArgument($params, 'role'); @@ -834,7 +834,7 @@ public function getRoleMapping(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getSslinfo(array $params = []) + public function getSslinfo(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetSslinfo::class); $endpoint->setParams($params); @@ -854,7 +854,7 @@ public function getSslinfo(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getTenancyConfig(array $params = []) + public function getTenancyConfig(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetTenancyConfig::class); $endpoint->setParams($params); @@ -875,7 +875,7 @@ public function getTenancyConfig(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getTenant(array $params = []) + public function getTenant(array $params = []): iterable|string|null { $tenant = $this->extractArgument($params, 'tenant'); @@ -899,7 +899,7 @@ public function getTenant(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getUser(array $params = []) + public function getUser(array $params = []): iterable|string|null { $username = $this->extractArgument($params, 'username'); @@ -923,7 +923,7 @@ public function getUser(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getUserLegacy(array $params = []) + public function getUserLegacy(array $params = []): iterable|string|null { $username = $this->extractArgument($params, 'username'); @@ -946,7 +946,7 @@ public function getUserLegacy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getUsersLegacy(array $params = []) + public function getUsersLegacy(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetUsersLegacy::class); $endpoint->setParams($params); @@ -967,7 +967,7 @@ public function getUsersLegacy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function health(array $params = []) + public function health(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Health::class); $endpoint->setParams($params); @@ -987,7 +987,7 @@ public function health(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function migrate(array $params = []) + public function migrate(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Migrate::class); $endpoint->setParams($params); @@ -1008,7 +1008,7 @@ public function migrate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function patchActionGroup(array $params = []) + public function patchActionGroup(array $params = []): iterable|string|null { $action_group = $this->extractArgument($params, 'action_group'); $body = $this->extractArgument($params, 'body'); @@ -1033,7 +1033,7 @@ public function patchActionGroup(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function patchAllowlist(array $params = []) + public function patchAllowlist(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1056,7 +1056,7 @@ public function patchAllowlist(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function patchAuditConfiguration(array $params = []) + public function patchAuditConfiguration(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1079,7 +1079,7 @@ public function patchAuditConfiguration(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function patchConfiguration(array $params = []) + public function patchConfiguration(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1103,7 +1103,7 @@ public function patchConfiguration(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function patchDistinguishedName(array $params = []) + public function patchDistinguishedName(array $params = []): iterable|string|null { $cluster_name = $this->extractArgument($params, 'cluster_name'); $body = $this->extractArgument($params, 'body'); @@ -1128,7 +1128,7 @@ public function patchDistinguishedName(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function patchDistinguishedNames(array $params = []) + public function patchDistinguishedNames(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1152,7 +1152,7 @@ public function patchDistinguishedNames(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function patchRole(array $params = []) + public function patchRole(array $params = []): iterable|string|null { $role = $this->extractArgument($params, 'role'); $body = $this->extractArgument($params, 'body'); @@ -1178,7 +1178,7 @@ public function patchRole(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function patchRoleMapping(array $params = []) + public function patchRoleMapping(array $params = []): iterable|string|null { $role = $this->extractArgument($params, 'role'); $body = $this->extractArgument($params, 'body'); @@ -1204,7 +1204,7 @@ public function patchRoleMapping(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function patchTenant(array $params = []) + public function patchTenant(array $params = []): iterable|string|null { $tenant = $this->extractArgument($params, 'tenant'); $body = $this->extractArgument($params, 'body'); @@ -1230,7 +1230,7 @@ public function patchTenant(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function patchUser(array $params = []) + public function patchUser(array $params = []): iterable|string|null { $username = $this->extractArgument($params, 'username'); $body = $this->extractArgument($params, 'body'); @@ -1255,7 +1255,7 @@ public function patchUser(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function postDashboardsInfo(array $params = []) + public function postDashboardsInfo(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(PostDashboardsInfo::class); $endpoint->setParams($params); @@ -1275,7 +1275,7 @@ public function postDashboardsInfo(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function reloadHttpCertificates(array $params = []) + public function reloadHttpCertificates(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ReloadHttpCertificates::class); $endpoint->setParams($params); @@ -1295,7 +1295,7 @@ public function reloadHttpCertificates(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function reloadTransportCertificates(array $params = []) + public function reloadTransportCertificates(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ReloadTransportCertificates::class); $endpoint->setParams($params); @@ -1315,7 +1315,7 @@ public function reloadTransportCertificates(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function tenantInfo(array $params = []) + public function tenantInfo(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(TenantInfo::class); $endpoint->setParams($params); @@ -1335,7 +1335,7 @@ public function tenantInfo(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateAuditConfiguration(array $params = []) + public function updateAuditConfiguration(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1358,7 +1358,7 @@ public function updateAuditConfiguration(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateConfiguration(array $params = []) + public function updateConfiguration(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -1382,7 +1382,7 @@ public function updateConfiguration(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateDistinguishedName(array $params = []) + public function updateDistinguishedName(array $params = []): iterable|string|null { $cluster_name = $this->extractArgument($params, 'cluster_name'); $body = $this->extractArgument($params, 'body'); @@ -1408,7 +1408,7 @@ public function updateDistinguishedName(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function validate(array $params = []) + public function validate(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Validate::class); $endpoint->setParams($params); @@ -1428,7 +1428,7 @@ public function validate(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function whoAmI(array $params = []) + public function whoAmI(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(WhoAmI::class); $endpoint->setParams($params); @@ -1448,7 +1448,7 @@ public function whoAmI(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function whoAmIProtected(array $params = []) + public function whoAmIProtected(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(WhoAmIProtected::class); $endpoint->setParams($params); @@ -1830,7 +1830,6 @@ public function getTenants(array $params = []) */ public function getUsers(array $params = []): array { - $endpointBuilder = $this->endpoints; if (isset($params['username'])) { $endpoint = $this->endpointFactory->getEndpoint(GetUser::class); diff --git a/src/OpenSearch/Namespaces/SmNamespace.php b/src/OpenSearch/Namespaces/SmNamespace.php index 1e37f67c4..17a40b14b 100644 --- a/src/OpenSearch/Namespaces/SmNamespace.php +++ b/src/OpenSearch/Namespaces/SmNamespace.php @@ -44,7 +44,7 @@ class SmNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function createPolicy(array $params = []) + public function createPolicy(array $params = []): iterable|string|null { $policy_name = $this->extractArgument($params, 'policy_name'); $body = $this->extractArgument($params, 'body'); @@ -70,7 +70,7 @@ public function createPolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deletePolicy(array $params = []) + public function deletePolicy(array $params = []): iterable|string|null { $policy_name = $this->extractArgument($params, 'policy_name'); @@ -94,7 +94,7 @@ public function deletePolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function explainPolicy(array $params = []) + public function explainPolicy(array $params = []): iterable|string|null { $policy_name = $this->extractArgument($params, 'policy_name'); @@ -122,7 +122,7 @@ public function explainPolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getPolicies(array $params = []) + public function getPolicies(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetPolicies::class); $endpoint->setParams($params); @@ -143,7 +143,7 @@ public function getPolicies(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getPolicy(array $params = []) + public function getPolicy(array $params = []): iterable|string|null { $policy_name = $this->extractArgument($params, 'policy_name'); @@ -167,7 +167,7 @@ public function getPolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function startPolicy(array $params = []) + public function startPolicy(array $params = []): iterable|string|null { $policy_name = $this->extractArgument($params, 'policy_name'); @@ -191,7 +191,7 @@ public function startPolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function stopPolicy(array $params = []) + public function stopPolicy(array $params = []): iterable|string|null { $policy_name = $this->extractArgument($params, 'policy_name'); @@ -217,7 +217,7 @@ public function stopPolicy(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updatePolicy(array $params = []) + public function updatePolicy(array $params = []): iterable|string|null { $policy_name = $this->extractArgument($params, 'policy_name'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/SnapshotNamespace.php b/src/OpenSearch/Namespaces/SnapshotNamespace.php index 7d0434bd8..9a8bf18ff 100644 --- a/src/OpenSearch/Namespaces/SnapshotNamespace.php +++ b/src/OpenSearch/Namespaces/SnapshotNamespace.php @@ -56,7 +56,7 @@ class SnapshotNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function cleanupRepository(array $params = []) + public function cleanupRepository(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); @@ -85,7 +85,7 @@ public function cleanupRepository(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function clone(array $params = []) + public function clone(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); $snapshot = $this->extractArgument($params, 'snapshot'); @@ -120,7 +120,7 @@ public function clone(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function create(array $params = []) + public function create(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); $snapshot = $this->extractArgument($params, 'snapshot'); @@ -153,7 +153,7 @@ public function create(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function createRepository(array $params = []) + public function createRepository(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); $body = $this->extractArgument($params, 'body'); @@ -182,7 +182,7 @@ public function createRepository(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function delete(array $params = []) + public function delete(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); $snapshot = $this->extractArgument($params, 'snapshot'); @@ -211,7 +211,7 @@ public function delete(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteRepository(array $params = []) + public function deleteRepository(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); @@ -240,7 +240,7 @@ public function deleteRepository(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function get(array $params = []) + public function get(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); $snapshot = $this->extractArgument($params, 'snapshot'); @@ -269,7 +269,7 @@ public function get(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getRepository(array $params = []) + public function getRepository(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); @@ -298,7 +298,7 @@ public function getRepository(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function restore(array $params = []) + public function restore(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); $snapshot = $this->extractArgument($params, 'snapshot'); @@ -330,7 +330,7 @@ public function restore(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function status(array $params = []) + public function status(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); $snapshot = $this->extractArgument($params, 'snapshot'); @@ -359,7 +359,7 @@ public function status(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function verifyRepository(array $params = []) + public function verifyRepository(array $params = []): iterable|string|null { $repository = $this->extractArgument($params, 'repository'); diff --git a/src/OpenSearch/Namespaces/SqlNamespace.php b/src/OpenSearch/Namespaces/SqlNamespace.php index 90960a7b0..7e8cfd8fe 100644 --- a/src/OpenSearch/Namespaces/SqlNamespace.php +++ b/src/OpenSearch/Namespaces/SqlNamespace.php @@ -43,7 +43,7 @@ class SqlNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function close(array $params = []) + public function close(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -68,7 +68,7 @@ public function close(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getStats(array $params = []) + public function getStats(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(GetStats::class); $endpoint->setParams($params); @@ -90,7 +90,7 @@ public function getStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function postStats(array $params = []) + public function postStats(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -114,7 +114,7 @@ public function postStats(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function settings(array $params = []) + public function settings(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Namespaces/TasksNamespace.php b/src/OpenSearch/Namespaces/TasksNamespace.php index e8741801d..05443388d 100644 --- a/src/OpenSearch/Namespaces/TasksNamespace.php +++ b/src/OpenSearch/Namespaces/TasksNamespace.php @@ -49,7 +49,7 @@ class TasksNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function cancel(array $params = []) + public function cancel(array $params = []): iterable|string|null { $task_id = $this->extractArgument($params, 'task_id'); @@ -75,7 +75,7 @@ public function cancel(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function get(array $params = []) + public function get(array $params = []): iterable|string|null { $task_id = $this->extractArgument($params, 'task_id'); @@ -105,7 +105,7 @@ public function get(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function list(array $params = []) + public function list(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(ListTasks::class); $endpoint->setParams($params); diff --git a/src/OpenSearch/Namespaces/TransformsNamespace.php b/src/OpenSearch/Namespaces/TransformsNamespace.php index c8dc70470..092c46953 100644 --- a/src/OpenSearch/Namespaces/TransformsNamespace.php +++ b/src/OpenSearch/Namespaces/TransformsNamespace.php @@ -44,7 +44,7 @@ class TransformsNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function delete(array $params = []) + public function delete(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -68,7 +68,7 @@ public function delete(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function explain(array $params = []) + public function explain(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -92,7 +92,7 @@ public function explain(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function get(array $params = []) + public function get(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -115,7 +115,7 @@ public function get(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function preview(array $params = []) + public function preview(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -141,7 +141,7 @@ public function preview(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function put(array $params = []) + public function put(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); $body = $this->extractArgument($params, 'body'); @@ -171,7 +171,7 @@ public function put(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function search(array $params = []) + public function search(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Search::class); $endpoint->setParams($params); @@ -192,7 +192,7 @@ public function search(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function start(array $params = []) + public function start(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); @@ -216,7 +216,7 @@ public function start(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function stop(array $params = []) + public function stop(array $params = []): iterable|string|null { $id = $this->extractArgument($params, 'id'); diff --git a/src/OpenSearch/Namespaces/UbiNamespace.php b/src/OpenSearch/Namespaces/UbiNamespace.php index 8184ce25c..7b0f8b67b 100644 --- a/src/OpenSearch/Namespaces/UbiNamespace.php +++ b/src/OpenSearch/Namespaces/UbiNamespace.php @@ -36,7 +36,7 @@ class UbiNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function initialize(array $params = []) + public function initialize(array $params = []): iterable|string|null { $endpoint = $this->endpointFactory->getEndpoint(Initialize::class); $endpoint->setParams($params); diff --git a/src/OpenSearch/Namespaces/WlmNamespace.php b/src/OpenSearch/Namespaces/WlmNamespace.php index 033f06344..a30d70422 100644 --- a/src/OpenSearch/Namespaces/WlmNamespace.php +++ b/src/OpenSearch/Namespaces/WlmNamespace.php @@ -39,7 +39,7 @@ class WlmNamespace extends AbstractNamespace * @param array $params Associative array of parameters * @return array */ - public function createQueryGroup(array $params = []) + public function createQueryGroup(array $params = []): iterable|string|null { $body = $this->extractArgument($params, 'body'); @@ -63,7 +63,7 @@ public function createQueryGroup(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function deleteQueryGroup(array $params = []) + public function deleteQueryGroup(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -87,7 +87,7 @@ public function deleteQueryGroup(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function getQueryGroup(array $params = []) + public function getQueryGroup(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); @@ -111,7 +111,7 @@ public function getQueryGroup(array $params = []) * @param array $params Associative array of parameters * @return array */ - public function updateQueryGroup(array $params = []) + public function updateQueryGroup(array $params = []): iterable|string|null { $name = $this->extractArgument($params, 'name'); $body = $this->extractArgument($params, 'body'); diff --git a/src/OpenSearch/Serializers/ArrayToJSONSerializer.php b/src/OpenSearch/Serializers/ArrayToJSONSerializer.php deleted file mode 100644 index 6237258fa..000000000 --- a/src/OpenSearch/Serializers/ArrayToJSONSerializer.php +++ /dev/null @@ -1,66 +0,0 @@ -isJson($headers)) { return $this->decode($data); diff --git a/src/OpenSearch/Transport.php b/src/OpenSearch/Transport.php deleted file mode 100644 index c4061ec4d..000000000 --- a/src/OpenSearch/Transport.php +++ /dev/null @@ -1,183 +0,0 @@ -log = $log; - $this->connectionPool = $connectionPool; - $this->retries = $retries; - - if ($sniffOnStart === true) { - $this->log->notice('Sniff on Start.'); - $this->connectionPool->scheduleCheck(); - } - } - - /** - * Returns a single connection from the connection pool - * Potentially performs a sniffing step before returning - */ - public function getConnection(): ConnectionInterface - { - return $this->connectionPool->nextConnection(); - } - - /** - * Perform a request to the Cluster - * - * @param string $method HTTP method to use - * @param string $uri HTTP URI to send request to - * @param array $params Optional query parameters - * @param mixed|null $body Optional query body - * @param array $options - * - * @throws Common\Exceptions\NoNodesAvailableException|\Exception - */ - public function performRequest(string $method, string $uri, array $params = [], $body = null, array $options = []): FutureArrayInterface - { - try { - $connection = $this->getConnection(); - } catch (Exceptions\NoNodesAvailableException $exception) { - $this->log->critical('No alive nodes found in cluster'); - throw $exception; - } - - $response = []; - $caughtException = null; - $this->lastConnection = $connection; - - $future = $connection->performRequest( - $method, - $uri, - $params, - $body, - $options, - $this - ); - - $future->promise()->then( - //onSuccess - function ($response) { - $this->retryAttempts = 0; - // Note, this could be a 4xx or 5xx error - }, - //onFailure - function ($response) { - $code = $response->getCode(); - // Ignore 400 level errors, as that means the server responded just fine - if ($code < 400 || $code >= 500) { - // Otherwise schedule a check - $this->connectionPool->scheduleCheck(); - } - } - ); - - return $future; - } - - /** - * @param FutureArrayInterface $result Response of a request (promise) - * @param array $options Options for transport - * - * @return callable|array - */ - public function resultOrFuture(FutureArrayInterface $result, array $options = []) - { - $response = null; - $async = isset($options['client']['future']) ? $options['client']['future'] : null; - if (is_null($async) || $async === false) { - do { - $result = $result->wait(); - } while ($result instanceof FutureArrayInterface); - } - return $result; - } - - public function shouldRetry(array $request): bool - { - if ($this->retryAttempts < $this->retries) { - $this->retryAttempts += 1; - - return true; - } - - return false; - } - - /** - * Returns the last used connection so that it may be inspected. Mainly - * for debugging/testing purposes. - */ - public function getLastConnection(): ConnectionInterface - { - return $this->lastConnection; - } -} diff --git a/tests/ClientBuilder/ArrayLogger.php b/tests/ClientBuilder/ArrayLogger.php deleted file mode 100644 index bd0b7f611..000000000 --- a/tests/ClientBuilder/ArrayLogger.php +++ /dev/null @@ -1,84 +0,0 @@ -log(LogLevel::EMERGENCY, $message, $context); - } - - public function alert($message, array $context = array()): void - { - $this->log(LogLevel::ALERT, $message, $context); - } - - public function critical($message, array $context = array()): void - { - $this->log(LogLevel::CRITICAL, $message, $context); - } - - public function error($message, array $context = array()): void - { - $this->log(LogLevel::ERROR, $message, $context); - } - - public function warning($message, array $context = array()): void - { - $this->log(LogLevel::WARNING, $message, $context); - } - - public function notice($message, array $context = array()): void - { - $this->log(LogLevel::NOTICE, $message, $context); - } - - public function info($message, array $context = array()): void - { - $this->log(LogLevel::INFO, $message, $context); - } - - public function debug($message, array $context = array()): void - { - $this->log(LogLevel::DEBUG, $message, $context); - } - - public function log($level, $message, array $context = array()): void - { - $this->output[] = sprintf("%s: %s %s", $level, $message, json_encode($context)); - } -} diff --git a/tests/ClientBuilderTest.php b/tests/ClientBuilderTest.php deleted file mode 100644 index 19f0280d9..000000000 --- a/tests/ClientBuilderTest.php +++ /dev/null @@ -1,224 +0,0 @@ - [ - 'verbose' => true - ] - ]; - $client = ClientBuilder::create() - ->setConnectionParams($params) - ->setHosts([$url]) - ->includePortInHostHeader(true) - ->build(); - - $this->assertInstanceOf(Client::class, $client); - - try { - $result = $client->info(); - } catch (OpenSearchException $e) { - $request = $client->transport->getLastConnection()->getLastRequestInfo(); - $this->assertTrue(isset($request['request']['headers']['Host'][0])); - $this->assertEquals($url, $request['request']['headers']['Host'][0]); - } - } - - /** - * @see https://github.com/elastic/elasticsearch-php/issues/993 - */ - public function testNotIncludePortInHostHeaderAsDefault() - { - $host = "localhost"; - $url = "$host:1234"; - $params = [ - 'client' => [ - 'verbose' => true - ] - ]; - $client = ClientBuilder::create() - ->setConnectionParams($params) - ->setHosts([$url]) - ->build(); - - $this->assertInstanceOf(Client::class, $client); - - try { - $result = $client->info(); - } catch (OpenSearchException $e) { - $request = $client->transport->getLastConnection()->getLastRequestInfo(); - $this->assertTrue(isset($request['request']['headers']['Host'][0])); - $this->assertEquals($host, $request['request']['headers']['Host'][0]); - } - } - - /** - * @see https://github.com/elastic/elasticsearch-php/issues/993 - */ - public function testNotIncludePortInHostHeader() - { - $host = "localhost"; - $url = "$host:1234"; - $params = [ - 'client' => [ - 'verbose' => true - ] - ]; - $client = ClientBuilder::create() - ->setConnectionParams($params) - ->setHosts([$url]) - ->includePortInHostHeader(false) - ->build(); - - $this->assertInstanceOf(Client::class, $client); - - try { - $result = $client->info(); - } catch (OpenSearchException $e) { - $request = $client->transport->getLastConnection()->getLastRequestInfo(); - $this->assertTrue(isset($request['request']['headers']['Host'][0])); - $this->assertEquals($host, $request['request']['headers']['Host'][0]); - } - } - - public static function getConfig() - { - return [ - [[ - 'hosts' => ['localhost:9200'] - ]], - [[ - 'hosts' => ['localhost:9200'], - 'basicAuthentication' => ['username-value', 'password-value'] - ]] - ]; - } - - /** - * @see https://github.com/elastic/elasticsearch-php/issues/1074 - */ - #[DataProvider('getConfig')] - public function testFromConfig(array $params) - { - $client = ClientBuilder::fromConfig($params); - $this->assertInstanceOf(Client::class, $client); - } - - public function testFromConfigQuiteTrueWithUnknownKey() - { - $client = ClientBuilder::fromConfig( - [ - 'hosts' => ['localhost:9200'], - 'foo' => 'bar' - ], - true - ); - } - - public function testFromConfigQuiteFalseWithUnknownKey() - { - $this->expectException(RuntimeException::class); - $client = ClientBuilder::fromConfig( - [ - 'hosts' => ['localhost:9200'], - 'foo' => 'bar' - ], - false - ); - } - - public function testFromConfigUsingBasicAuthentication() - { - $config = [ - 'basicAuthentication' => ["foo", "bar"], - 'connectionParams' => [], - ]; - $client = ClientBuilder::fromConfig($config); - - $this->assertEquals('foo:bar', $client->transport->getConnection()->getUserPass()); - } - - public function testCompatibilityHeaderDefaultIsOff() - { - $client = ClientBuilder::create() - ->build(); - - try { - $client->info(); - } catch (OpenSearchException $e) { - $request = $client->transport->getLastConnection()->getLastRequestInfo(); - $this->assertSame(['application/json'], $request['request']['headers']['Content-Type']); - $this->assertSame(['application/json'], $request['request']['headers']['Accept']); - } - } - - public function testFromConfigWithIncludePortInHostHeader() - { - $url = 'localhost:1234'; - $config = [ - 'hosts' => [$url], - 'includePortInHostHeader' => true, - 'connectionParams' => [ - 'client' => [ - 'verbose' => true - ] - ], - ]; - - $client = ClientBuilder::fromConfig($config); - - $this->assertInstanceOf(Client::class, $client); - - try { - $client->info(); - $this->fail('Exception was not thrown!'); - } catch (OpenSearchException $e) { - $request = $client->transport->getLastConnection()->getLastRequestInfo(); - $this->assertTrue(isset($request['request']['headers']['Host'][0])); - $this->assertEquals($url, $request['request']['headers']['Host'][0]); - } - } -} diff --git a/tests/ConnectionPool/ConnectionFactoryTest.php b/tests/ConnectionPool/ConnectionFactoryTest.php deleted file mode 100644 index 74945264a..000000000 --- a/tests/ConnectionPool/ConnectionFactoryTest.php +++ /dev/null @@ -1,71 +0,0 @@ -create(['host' => 'localhost']); - static::assertNull($connection->getPath()); - } - - #[DataProvider('pathDataProvider')] - public function testConnectionWithPath(string $path, string $expectedPath): void - { - $factory = new ConnectionFactory( - function () { - }, - [], - new ArrayToJSONSerializer(), - new NullLogger(), - new NullLogger() - ); - - $connection = $factory->create(['host' => 'localhost', 'path' => $path]); - static::assertSame($expectedPath, $connection->getPath()); - } - - public static function pathDataProvider(): array - { - return [ - ['/', ''], - ['/foo', '/foo'], - ['/foo/', '/foo'], - ]; - } -} diff --git a/tests/ConnectionPool/Selectors/RoundRobinSelectorTest.php b/tests/ConnectionPool/Selectors/RoundRobinSelectorTest.php deleted file mode 100644 index 9ccfd4ae2..000000000 --- a/tests/ConnectionPool/Selectors/RoundRobinSelectorTest.php +++ /dev/null @@ -1,112 +0,0 @@ -getMockBuilder(ConnectionInterface::class) - ->disableOriginalConstructor() - ->getMock(); - } - - // select ten - $this->assertSame($mockConnections[0], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[1], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[2], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[3], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[4], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[5], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[6], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[7], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[8], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[9], $roundRobin->select($mockConnections)); - - // select five - should start from the first one (index: 0) - $this->assertSame($mockConnections[0], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[1], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[2], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[3], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[4], $roundRobin->select($mockConnections)); - } - - /** - * Add Ten connections, select five, remove three, test another 10 to check - * that the round-robining works after removing connections - */ - public function testAddTenConnectionsTestFiveRemoveThreeTestTen() - { - $roundRobin = new OpenSearch\ConnectionPool\Selectors\RoundRobinSelector(); - - $mockConnections = []; - foreach (range(0, 9) as $index) { - $mockConnections[$index] = $this->getMockBuilder(ConnectionInterface::class) - ->disableOriginalConstructor() - ->getMock(); - } - - // select five - $this->assertSame($mockConnections[0], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[1], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[2], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[3], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[4], $roundRobin->select($mockConnections)); - - // remove three - unset($mockConnections[8]); - unset($mockConnections[9]); - - // select ten after removal - $this->assertSame($mockConnections[5], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[6], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[7], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[0], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[1], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[2], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[3], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[4], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[5], $roundRobin->select($mockConnections)); - $this->assertSame($mockConnections[6], $roundRobin->select($mockConnections)); - } -} diff --git a/tests/ConnectionPool/Selectors/StickyRoundRobinSelectorTest.php b/tests/ConnectionPool/Selectors/StickyRoundRobinSelectorTest.php deleted file mode 100644 index 84ac62c44..000000000 --- a/tests/ConnectionPool/Selectors/StickyRoundRobinSelectorTest.php +++ /dev/null @@ -1,86 +0,0 @@ -expects('isAlive')->times(16)->andReturns(true); - - $mockConnections[] = $mockConnection; - - foreach (range(0, 9) as $index) { - $mockConnections[] = m::mock(ConnectionInterface::class); - } - - foreach (range(0, 15) as $index) { - $retConnection = $roundRobin->select($mockConnections); - - $this->assertSame($mockConnections[0], $retConnection); - } - } - - public function testTenConnectionsFirstDies() - { - $roundRobin = new OpenSearch\ConnectionPool\Selectors\StickyRoundRobinSelector(); - - $mockConnections = []; - $mockConnectionNotAlive = m::mock(ConnectionInterface::class); - $mockConnectionNotAlive->expects('isAlive')->andReturns(false); - - $mockConnections[] = $mockConnectionNotAlive; - - $mockConnectionAlive = m::mock(ConnectionInterface::class); - $mockConnectionAlive->expects('isAlive')->times(15)->andReturns(true); - - $mockConnections[] = $mockConnectionAlive; - - foreach (range(0, 8) as $index) { - $mockConnections[] = m::mock(ConnectionInterface::class); - } - - foreach (range(0, 15) as $index) { - $retConnection = $roundRobin->select($mockConnections); - - $this->assertSame($mockConnections[1], $retConnection); - } - } -} diff --git a/tests/ConnectionPool/SniffingConnectionPoolIntegrationTest.php b/tests/ConnectionPool/SniffingConnectionPoolIntegrationTest.php deleted file mode 100644 index 673e9bf60..000000000 --- a/tests/ConnectionPool/SniffingConnectionPoolIntegrationTest.php +++ /dev/null @@ -1,54 +0,0 @@ -setHosts([Utility::getHost()]) - ->setConnectionPool(SniffingConnectionPool::class, ['sniffingInterval' => 10]) - ->setSSLVerification(false) - ->build(); - - $pinged = $client->ping(); - $this->assertTrue($pinged); - } -} diff --git a/tests/ConnectionPool/SniffingConnectionPoolTest.php b/tests/ConnectionPool/SniffingConnectionPoolTest.php deleted file mode 100644 index 93b1f5644..000000000 --- a/tests/ConnectionPool/SniffingConnectionPoolTest.php +++ /dev/null @@ -1,298 +0,0 @@ -clusterState(1); - $connection = $this->createMock(Connection::class); - $connection->method('isAlive')->willReturn(true); - $connection->method('sniff')->willReturn($clusterState); - $selector = new RoundRobinSelector(); - $connectionFactory = $this->createMock(ConnectionFactoryInterface::class); - $connectionFactory->method('create')->willReturn($connection); - - $connectionPool = new SniffingConnectionPool( - [$connection], - $selector, - $connectionFactory, - ['sniffingInterval' => 0] - ); - - $this->assertSame($connection, $connectionPool->nextConnection()); - } - - #[Test] - public function itShouldSniffNewConnectionsWhenPossible(): void - { - $clusterState = $this->clusterState(2); - $originalConnection = $this->createMock(Connection::class); - $originalConnection->method('isAlive')->willReturn(false); - $originalConnection->method('sniff')->willReturn($clusterState); - $discoveredConnection = $this->createMock(Connection::class); - $discoveredConnection->method('isAlive')->willReturn(true); - $selector = new RoundRobinSelector(); - $connectionFactory = $this->createMock(ConnectionFactoryInterface::class); - $connectionFactory->method('create')->willReturnOnConsecutiveCalls($originalConnection, $discoveredConnection); - - $connectionPool = new SniffingConnectionPool( - [$originalConnection], - $selector, - $connectionFactory, - ['sniffingInterval' => 0] - ); - - $actualConnection = $connectionPool->nextConnection(); - - $this->assertSame($discoveredConnection, $actualConnection); - } - - #[Test] - public function forceNextConnection(): void - { - $clusterState = $this->clusterState(2); - $firstConnection = $this->createMock(Connection::class); - $firstConnection->method('isAlive')->willReturn(true); - $firstConnection->method('sniff')->willReturn($clusterState); - $secondConnection = $this->createMock(Connection::class); - $secondConnection->method('isAlive')->willReturn(true); - $selector = new RoundRobinSelector(); - $connectionFactory = $this->createMock(ConnectionFactoryInterface::class); - $connectionFactory->method('create')->willReturnOnConsecutiveCalls($firstConnection, $secondConnection); - - $connectionPool = new SniffingConnectionPool( - [$firstConnection, $secondConnection], - $selector, - $connectionFactory, - ['sniffingInterval' => 0] - ); - - $this->assertSame($secondConnection, $connectionPool->nextConnection(true)); - } - - #[Test] - public function itShouldReturnFirstSeededConnectionIfAlive(): void - { - $clusterState = $this->clusterState(10); - $connections = []; - for ($i = 1; $i <= 10; $i++) { - $connection = $this->createMock(Connection::class); - $connection->method('isAlive')->willReturn(true); - $connection->method('sniff')->willReturn($clusterState); - $connections[] = $connection; - } - $selector = new RoundRobinSelector(); - $connectionFactory = $this->createMock(ConnectionFactoryInterface::class); - $connectionFactory->method('create')->willReturnOnConsecutiveCalls(...$connections); - - $connectionPool = new SniffingConnectionPool( - $connections, - $selector, - $connectionFactory, - ['sniffingInterval' => 0] - ); - - $this->assertSame($connections[0], $connectionPool->nextConnection()); - } - - #[Test] - public function itShouldReturnTheFirstAvailableConnection(): void - { - $clusterState = $this->clusterState(10); - $connections = []; - for ($i = 1; $i <= 10; $i++) { - $connection = $this->createMock(Connection::class); - $connection->method('isAlive')->willReturn(false); - $connection->method('sniff')->willReturn($clusterState); - $connections[] = $connection; - } - $randomLiveConnectionIndex = random_int(0, 9); - $connections[$randomLiveConnectionIndex] = $this->createMock(Connection::class); - $connections[$randomLiveConnectionIndex]->method('isAlive')->willReturn(true); - $selector = new RoundRobinSelector(); - $connectionFactory = $this->createMock(ConnectionFactoryInterface::class); - $connectionFactory->method('create')->willReturnOnConsecutiveCalls(...$connections); - - $connectionPool = new SniffingConnectionPool( - $connections, - $selector, - $connectionFactory, - ['sniffingInterval' => 0] - ); - - $this->assertSame($connections[$randomLiveConnectionIndex], $connectionPool->nextConnection()); - } - - #[Test] - public function itShouldFailIfAllNodesAreDown(): void - { - $clusterState = $this->clusterState(10); - $connections = []; - for ($i = 1; $i <= 10; $i++) { - $connection = $this->createMock(Connection::class); - $connection->method('isAlive')->willReturn(false); - $connection->method('sniff')->willReturn($clusterState); - $connections[] = $connection; - } - $selector = new RoundRobinSelector(); - $connectionFactory = $this->createMock(ConnectionFactoryInterface::class); - $connectionFactory->method('create')->willReturnOnConsecutiveCalls(...$connections); - - $connectionPool = new SniffingConnectionPool( - $connections, - $selector, - $connectionFactory, - ['sniffingInterval' => 0] - ); - - $this->expectException(NoNodesAvailableException::class); - - $connectionPool->nextConnection(); - } - - #[Test] - public function sniffShouldStopIfAllSniffRequestsFail(): void - { - $connection = $this->createMock(Connection::class); - $connection->method('isAlive')->willReturn(false); - $connection->method('sniff')->willThrowException(new OperationTimeoutException()); - $selector = new RoundRobinSelector(); - $connectionFactory = $this->createMock(ConnectionFactoryInterface::class); - - $connectionPool = new SniffingConnectionPool( - [$connection], - $selector, - $connectionFactory, - ['sniffingInterval' => 0] - ); - - $this->expectException(NoNodesAvailableException::class); - $connectionFactory->expects($this->never())->method('create'); - - $connectionPool->nextConnection(); - } - - #[Test] - public function sniffShouldStopIfNodesAreEmpty(): void - { - $clusterState = $this->clusterState(0); - $connection = $this->createMock(Connection::class); - $connection->method('isAlive')->willReturn(false); - $connection->method('sniff')->willReturn($clusterState); - $selector = new RoundRobinSelector(); - $connectionFactory = $this->createMock(ConnectionFactoryInterface::class); - - $connectionPool = new SniffingConnectionPool( - [$connection], - $selector, - $connectionFactory, - ['sniffingInterval' => 0] - ); - - $this->expectException(NoNodesAvailableException::class); - $connectionFactory->expects($this->never())->method('create'); - - $connectionPool->nextConnection(); - } - - #[Test] - public function itShouldNotSniffBeforeScheduledSniffTime(): void - { - $connection = $this->createMock(Connection::class); - $connection->method('isAlive')->willReturn(false); - $connection->method('sniff')->willReturn($this->clusterState(2)); - $selector = new RoundRobinSelector(); - $connectionFactory = $this->createMock(ConnectionFactoryInterface::class); - - $connectionPool = new SniffingConnectionPool( - [$connection], - $selector, - $connectionFactory, - ['sniffingInterval' => 300] - ); - - $connectionFactory->expects($this->never())->method('create'); - $this->expectException(NoNodesAvailableException::class); - - $connectionPool->nextConnection(); - } - - #[Test] - public function scheduleCheck(): void - { - $clusterState = $this->clusterState(2); - $firstConnection = $this->createMock(Connection::class); - $firstConnection->method('isAlive')->willReturn(true); - $firstConnection->method('sniff')->willReturn($clusterState); - $secondConnection = $this->createMock(Connection::class); - $secondConnection->method('isAlive')->willReturn(true); - $selector = $this->createMock(RoundRobinSelector::class); - $selector->expects($this->exactly(2))->method('select')->willReturnOnConsecutiveCalls( - $firstConnection, - $secondConnection - ); - $connectionFactory = $this->createMock(ConnectionFactoryInterface::class); - $connectionFactory->method('create')->willReturnOnConsecutiveCalls($firstConnection, $secondConnection); - - $connectionPool = new SniffingConnectionPool( - [$firstConnection], - $selector, - $connectionFactory, - ['sniffingInterval' => 300] - ); - - $connectionPool->scheduleCheck(); - - $this->assertSame($secondConnection, $connectionPool->nextConnection()); - } - - private function clusterState(int $numberOfNodes): array - { - $clusterState = ['nodes' => []]; - - for ($i = 1; $i <= $numberOfNodes; $i++) { - $clusterState['nodes']["node-$i"] = [ - 'http' => [ - 'publish_address' => "172.17.0.2:920$i", - ], - ]; - } - - return $clusterState; - } -} diff --git a/tests/ConnectionPool/StaticConnectionPoolIntegrationTest.php b/tests/ConnectionPool/StaticConnectionPoolIntegrationTest.php deleted file mode 100644 index b7591e39f..000000000 --- a/tests/ConnectionPool/StaticConnectionPoolIntegrationTest.php +++ /dev/null @@ -1,74 +0,0 @@ -host = Utility::getHost(); - } - - // Issue #636 - public function test404Liveness() - { - $client = ClientBuilder::create() - ->setHosts([$this->host]) - ->setConnectionPool(StaticConnectionPool::class) - ->setSSLVerification(false) - ->build(); - - $connection = $client->transport->getConnection(); - - // Ensure connection is dead - $connection->markDead(); - - // The index doesn't exist, but the server is up so this will return a 404 - $this->assertFalse($client->indices()->exists(['index' => 'not_existing_index'])); - - // But the node should be marked as alive since the server responded - $connection = $client->transport->getConnection(); - $this->assertTrue($connection->isAlive()); - } -} diff --git a/tests/ConnectionPool/StaticConnectionPoolTest.php b/tests/ConnectionPool/StaticConnectionPoolTest.php deleted file mode 100644 index a9ce45dfd..000000000 --- a/tests/ConnectionPool/StaticConnectionPoolTest.php +++ /dev/null @@ -1,229 +0,0 @@ -expects('isAlive')->andReturns(true); - $mockConnection->expects('markDead'); - - /** - * @var \OpenSearch\Connections\ConnectionInterface[]&\Mockery\MockInterface[] $connections - */ - $connections = [$mockConnection]; - - $selector = m::mock(SelectorInterface::class); - $selector->allows('select') - ->andReturns($connections[0]) - ->getMock(); - - $connectionFactory = m::mock(ConnectionFactory::class); - - $connectionPoolParams = [ - 'randomizeHosts' => false, - ]; - $connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); - - $retConnection = $connectionPool->nextConnection(); - - $this->assertSame($mockConnection, $retConnection); - } - - public function testAddMultipleHostsThenGetFirst() - { - $connections = []; - - foreach (range(1, 10) as $index) { - $mockConnection = m::mock(Connection::class); - $mockConnection->expects('isAlive')->between(0, 1)->andReturns(true); - $mockConnection->expects('markDead')->once(); - - $connections[] = $mockConnection; - } - - $selector = m::mock(SelectorInterface::class); - $selector->allows('select') - ->andReturns($connections[0]); - - $connectionFactory = m::mock(ConnectionFactory::class); - - $connectionPoolParams = [ - 'randomizeHosts' => false, - ]; - $connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); - - $retConnection = $connectionPool->nextConnection(); - - $this->assertSame($connections[0], $retConnection); - } - - public function testAllHostsFailPing() - { - $connections = []; - - foreach (range(1, 10) as $index) { - $mockConnection = m::mock(Connection::class); - $mockConnection->expects('ping')->andReturns(false); - $mockConnection->expects('isAlive')->andReturns(false); - $mockConnection->expects('markDead'); - $mockConnection->expects('getPingFailures')->andReturns(0); - $mockConnection->expects('getLastPing')->andReturns(time()); - - $connections[] = $mockConnection; - } - - $selector = m::mock(SelectorInterface::class); - $selector->allows('select')->andReturnValues($connections); - - $connectionFactory = m::mock(ConnectionFactory::class); - - $connectionPoolParams = [ - 'randomizeHosts' => false, - ]; - $connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); - - $this->expectException(NoNodesAvailableException::class); - $this->expectExceptionMessage('No alive nodes found in your cluster'); - - $connectionPool->nextConnection(); - } - - public function testAllExceptLastHostFailPingRevivesInSkip() - { - $connections = []; - - foreach (range(1, 9) as $index) { - $mockConnection = m::mock(Connection::class); - $mockConnection->expects('ping')->andReturns(false); - $mockConnection->expects('isAlive')->andReturns(false); - $mockConnection->expects('markDead'); - $mockConnection->expects('getPingFailures')->andReturns(0); - $mockConnection->expects('getLastPing')->andReturns(time()); - - $connections[] = $mockConnection; - } - - $goodConnection = m::mock(Connection::class); - $goodConnection->expects('ping')->andReturns(true); - $goodConnection->expects('isAlive')->andReturns(false); - $goodConnection->expects('markDead'); - $goodConnection->expects('getPingFailures')->andReturns(0); - $goodConnection->expects('getLastPing')->andReturns(time()); - - $connections[] = $goodConnection; - - $selector = m::mock(SelectorInterface::class); - $selector->allows('select')->andReturnValues($connections); - - $connectionFactory = m::mock(ConnectionFactory::class); - - $connectionPoolParams = [ - 'randomizeHosts' => false, - ]; - $connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); - - $ret = $connectionPool->nextConnection(); - $this->assertSame($goodConnection, $ret); - } - - public function testAllExceptLastHostFailPingRevivesPreSkip() - { - $connections = []; - - foreach (range(1, 9) as $index) { - $mockConnection = m::mock(Connection::class); - $mockConnection->expects('ping')->between(0, 1)->andReturns(false); - $mockConnection->expects('isAlive')->andReturns(false); - $mockConnection->expects('markDead'); - $mockConnection->expects('getPingFailures')->andReturns(0); - $mockConnection->expects('getLastPing')->andReturns(time()); - - $connections[] = $mockConnection; - } - - $goodConnection = m::mock(Connection::class); - $goodConnection->expects('ping')->andReturns(true); - $goodConnection->expects('isAlive')->andReturns(false); - $goodConnection->expects('markDead'); - $goodConnection->expects('getPingFailures')->andReturns(0); - $goodConnection->expects('getLastPing')->andReturns(time() - 10000); - - $connections[] = $goodConnection; - - $selector = m::mock(SelectorInterface::class); - $selector->allows('select')->andReturnValues($connections); - - $connectionFactory = m::mock(ConnectionFactory::class); - - $connectionPoolParams = [ - 'randomizeHosts' => false, - ]; - $connectionPool = new StaticConnectionPool($connections, $selector, $connectionFactory, $connectionPoolParams); - - $ret = $connectionPool->nextConnection(); - $this->assertSame($goodConnection, $ret); - } - - public function testCustomConnectionPoolIT() - { - $clientBuilder = ClientBuilder::create(); - $clientBuilder->setHosts(['localhost:1']); - $client = $clientBuilder - ->setRetries(0) - ->setConnectionPool(StaticConnectionPool::class, []) - ->build(); - - $this->expectException(NoNodesAvailableException::class); - $this->expectExceptionMessage('No alive nodes found in your cluster'); - - $client->search([]); - } -} diff --git a/tests/Connections/ConnectionTest.php b/tests/Connections/ConnectionTest.php deleted file mode 100644 index 4e1d59b10..000000000 --- a/tests/Connections/ConnectionTest.php +++ /dev/null @@ -1,500 +0,0 @@ -logger = $this->createMock(LoggerInterface::class); - $this->trace = $this->createMock(LoggerInterface::class); - $this->serializer = $this->createMock(SerializerInterface::class); - } - - public function testConstructor() - { - $host = [ - 'host' => 'localhost' - ]; - - $connection = new Connection( - function () { - }, - $host, - [], - $this->serializer, - $this->logger, - $this->trace - ); - - $this->assertInstanceOf(Connection::class, $connection); - } - - #[Depends('testConstructor')] - public function testGetHeadersContainUserAgent() - { - $params = []; - $host = [ - 'host' => 'localhost' - ]; - - $connection = new Connection( - function () { - }, - $host, - $params, - $this->serializer, - $this->logger, - $this->trace - ); - - $headers = $connection->getHeaders(); - - $this->assertArrayHasKey('User-Agent', $headers); - $this->assertStringContainsString('opensearch-php/'. Client::VERSION, $headers['User-Agent'][0]); - } - - #[Depends('testGetHeadersContainUserAgent')] - public function testUserAgentHeaderIsSent() - { - $params = []; - $host = [ - 'host' => 'localhost' - ]; - - $connection = new Connection( - ClientBuilder::defaultHandler(), - $host, - $params, - $this->serializer, - $this->logger, - $this->trace - ); - $result = $connection->performRequest('GET', '/'); - $request = $connection->getLastRequestInfo()['request']; - - $this->assertArrayHasKey('User-Agent', $request['headers']); - $this->assertStringContainsString('opensearch-php/'. Client::VERSION, $request['headers']['User-Agent'][0]); - } - - #[Depends('testConstructor')] - public function testGetHeadersContainsHostArrayConfig() - { - $host = [ - 'host' => 'localhost', - 'user' => 'foo', - 'pass' => 'bar', - ]; - - $connection = new Connection( - ClientBuilder::defaultHandler(), - $host, - [], - $this->serializer, - $this->logger, - $this->trace - ); - $result = $connection->performRequest('GET', '/'); - $request = $connection->getLastRequestInfo()['request']; - - $this->assertArrayHasKey(CURLOPT_HTTPAUTH, $request['client']['curl']); - $this->assertArrayHasKey(CURLOPT_USERPWD, $request['client']['curl']); - $this->assertArrayNotHasKey('Authorization', $request['headers']); - $this->assertStringContainsString('foo:bar', $request['client']['curl'][CURLOPT_USERPWD]); - } - - #[Depends('testGetHeadersContainsHostArrayConfig')] - public function testGetHeadersContainApiKeyAuth() - { - $params = ['client' => ['headers' => [ - 'Authorization' => [ - 'ApiKey ' . base64_encode(random_bytes(10)) - ] - ] ] ]; - $host = [ - 'host' => 'localhost' - ]; - - $connection = new Connection( - ClientBuilder::defaultHandler(), - $host, - $params, - $this->serializer, - $this->logger, - $this->trace - ); - $result = $connection->performRequest('GET', '/'); - $request = $connection->getLastRequestInfo()['request']; - - $this->assertArrayHasKey('Authorization', $request['headers']); - $this->assertArrayNotHasKey(CURLOPT_HTTPAUTH, $request['headers']); - $this->assertStringContainsString($params['client']['headers']['Authorization'][0], $request['headers']['Authorization'][0]); - } - - #[Depends('testGetHeadersContainApiKeyAuth')] - public function testGetHeadersContainApiKeyAuthOverHostArrayConfig() - { - $params = ['client' => ['headers' => [ - 'Authorization' => [ - 'ApiKey ' . base64_encode(random_bytes(10)) - ] - ] ] ]; - $host = [ - 'host' => 'localhost', - 'user' => 'foo', - 'pass' => 'bar', - ]; - - $connection = new Connection( - ClientBuilder::defaultHandler(), - $host, - $params, - $this->serializer, - $this->logger, - $this->trace - ); - $result = $connection->performRequest('GET', '/'); - $request = $connection->getLastRequestInfo()['request']; - - $this->assertArrayHasKey('Authorization', $request['headers']); - $this->assertArrayNotHasKey(CURLOPT_HTTPAUTH, $request['headers']); - $this->assertStringContainsString($params['client']['headers']['Authorization'][0], $request['headers']['Authorization'][0]); - } - - #[Depends('testGetHeadersContainsHostArrayConfig')] - public function testGetHeadersContainBasicAuth() - { - $params = ['client' => ['curl' => [ - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, - CURLOPT_USERPWD => 'username:password', - ] ] ]; - $host = [ - 'host' => 'localhost' - ]; - - $connection = new Connection( - ClientBuilder::defaultHandler(), - $host, - $params, - $this->serializer, - $this->logger, - $this->trace - ); - $result = $connection->performRequest('GET', '/'); - $request = $connection->getLastRequestInfo()['request']; - - $this->assertArrayHasKey(CURLOPT_HTTPAUTH, $request['client']['curl']); - $this->assertArrayHasKey(CURLOPT_USERPWD, $request['client']['curl']); - $this->assertArrayNotHasKey('Authorization', $request['headers']); - $this->assertStringContainsString($params['client']['curl'][CURLOPT_USERPWD], $request['client']['curl'][CURLOPT_USERPWD]); - } - - #[Depends('testGetHeadersContainBasicAuth')] - public function testGetHeadersContainBasicAuthOverHostArrayConfig() - { - $params = ['client' => ['curl' => [ - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, - CURLOPT_USERPWD => 'username:password', - ] ] ]; - $host = [ - 'host' => 'localhost', - 'user' => 'foo', - 'pass' => 'bar', - ]; - - $connection = new Connection( - ClientBuilder::defaultHandler(), - $host, - $params, - $this->serializer, - $this->logger, - $this->trace - ); - $connection->performRequest('GET', '/'); - $request = $connection->getLastRequestInfo()['request']; - - $this->assertArrayHasKey(CURLOPT_HTTPAUTH, $request['client']['curl']); - $this->assertArrayHasKey(CURLOPT_USERPWD, $request['client']['curl']); - $this->assertArrayNotHasKey('Authorization', $request['headers']); - $this->assertStringContainsString('username:password', $request['client']['curl'][CURLOPT_USERPWD]); - } - - /** - * @see https://github.com/elastic/elasticsearch-php/issues/977 - */ - public function testTryDeserializeErrorWithMasterNotDiscoveredException() - { - $host = [ - 'host' => 'localhost' - ]; - - $connection = new Connection( - function () { - }, - $host, - [], - new SmartSerializer(), - $this->logger, - $this->trace - ); - - $reflection = new ReflectionClass(Connection::class); - $tryDeserializeError = $reflection->getMethod('tryDeserializeError'); - $tryDeserializeError->setAccessible(true); - - $body = '{"error":{"root_cause":[{"type":"master_not_discovered_exception","reason":null}],"type":"master_not_discovered_exception","reason":null},"status":503}'; - $response = [ - 'transfer_stats' => [], - 'status' => 503, - 'body' => $body - ]; - - $result = $tryDeserializeError->invoke($connection, $response, ServerErrorResponseException::class); - $this->assertInstanceOf(ServerErrorResponseException::class, $result); - $this->assertStringContainsString('master_not_discovered_exception', $result->getMessage()); - } - - /** - * @see https://github.com/opensearch-project/opensearch-php/issues/167 - */ - public function testTryDeserializeErrorWith403Error() - { - $host = [ - 'host' => 'localhost' - ]; - - $connection = new Connection( - function () { - }, - $host, - [], - new SmartSerializer(), - $this->logger, - $this->trace - ); - - $reflection = new ReflectionClass(Connection::class); - $tryDeserializeError = $reflection->getMethod('tryDeserializeError'); - $tryDeserializeError->setAccessible(true); - - $body = '{"status":403,"error":{"reason":"403 Forbidden","type":"Forbidden"}}'; - $response = [ - 'transfer_stats' => [], - 'status' => 403, - 'body' => $body - ]; - - $result = $tryDeserializeError->invoke($connection, $response, ServerErrorResponseException::class); - $this->assertInstanceOf(ServerErrorResponseException::class, $result); - $this->assertStringContainsString('403 Forbidden', $result->getMessage()); - } - - public function testHeaderClientParamIsResetAfterSent() - { - $host = [ - 'host' => 'localhost' - ]; - - $connection = new Connection( - ClientBuilder::defaultHandler(), - $host, - [], - new SmartSerializer(), - $this->logger, - $this->trace - ); - - $options = [ - 'client' => [ - 'headers' => [ - 'Foo' => [ 'Bar' ] - ] - ] - ]; - - $headersBefore = $connection->getHeaders(); - $connection->performRequest('GET', '/', null, null, $options); - $headersAfter = $connection->getHeaders(); - $this->assertEquals($headersBefore, $headersAfter); - } - - public function testParametersAreSent() - { - $connectionParams = []; - $host = [ - 'host' => 'localhost' - ]; - $requestParams = [ - 'foo' => true, - 'baz' => false, - 'bar' => 'baz' - ]; - - $connection = new Connection( - ClientBuilder::defaultHandler(), - $host, - $connectionParams, - $this->serializer, - $this->logger, - $this->trace - ); - $connection->performRequest('GET', '/', $requestParams); - $request = $connection->getLastRequestInfo()['request']; - - $this->assertEquals('/?foo=true&baz=false&bar=baz', $request['uri']); - } - - public function testPortInUrlWhenLogRequestSuccess() - { - $logger = new ArrayLogger(); - $trace = new ArrayLogger(); - - $connection = new Connection( - ClientBuilder::defaultHandler(), - [ - 'host' => 'localhost', - 'port' => 9200, - 'scheme' => 'http', - 'path' => '/info' - ], - [], - $this->serializer, - $logger, - $trace - ); - $request = [ - 'body' => '{}', - 'http_method' => 'GET', - 'headers' => [ - 'User-Agent: Testing' - ] - ]; - $response = [ - 'effective_url' => 'http://localhost/info', - 'status' => 200, - 'transfer_stats' => [ - 'primary_port' => 9200, - 'total_time' => 1 - ], - 'body' => '{}' - ]; - $connection->logRequestSuccess($request, $response); - // Check for localhost:9200 in trace - foreach ($trace->output as $row) { - $this->assertStringContainsString('localhost:9200', $row); - } - // Check for localhost:9200 in logger - foreach ($logger->output as $row) { - if (false !== strpos('info: Request Success', $row)) { - $this->assertStringContainsString('localhost:9200', $row); - } - } - } - - public function testPortInLogUrlWhenLogRequestFail() - { - $logger = new ArrayLogger(); - $trace = new ArrayLogger(); - - $connection = new Connection( - ClientBuilder::defaultHandler(), - [ - 'host' => 'localhost', - 'port' => 9200, - 'scheme' => 'http', - 'path' => '/info' - ], - [], - $this->serializer, - $logger, - $trace - ); - $request = [ - 'body' => '{}', - 'http_method' => 'GET', - 'headers' => [ - 'User-Agent: Testing' - ] - ]; - $response = [ - 'effective_url' => 'http://localhost/info', - 'status' => 400, - 'transfer_stats' => [ - 'primary_port' => 9200, - 'total_time' => 1 - ], - 'body' => '{}' - ]; - $connection->logRequestFail($request, $response, new Exception()); - - // Check for localhost:9200 in trace - foreach ($trace->output as $row) { - $this->assertStringContainsString('localhost:9200', $row); - } - // Check for localhost:9200 in logger - foreach ($logger->output as $row) { - if (false !== strpos('warning: Request Failure:', $row)) { - $this->assertStringContainsString('localhost:9200', $row); - } - } - } -} diff --git a/tests/Handlers/SigV4HandlerTest.php b/tests/Handlers/SigV4HandlerTest.php deleted file mode 100644 index f787618fb..000000000 --- a/tests/Handlers/SigV4HandlerTest.php +++ /dev/null @@ -1,250 +0,0 @@ - - */ - private $envTemp = []; - - protected function setUp(): void - { - $this->envTemp = array_combine(self::ENV_KEYS_USED, array_map( - function ($envVarName) { - $current = getenv($envVarName); - putenv($envVarName); - return $current; - }, - self::ENV_KEYS_USED - )); - } - - protected function tearDown(): void - { - foreach ($this->envTemp as $key => $value) { - putenv("$key=$value"); - } - $this->envTemp = []; - } - - public function testSignsRequestsTheSdkDefaultCredentialProviderChain() - { - $key = 'foo'; - $toWrap = function (array $ringRequest) use ($key) { - $this->assertArrayHasKey('X-Amz-Date', $ringRequest['headers']); - $this->assertArrayHasKey('Authorization', $ringRequest['headers']); - $this->assertArrayHasKey('x-amz-content-sha256', $ringRequest['headers']); - $this->assertMatchesRegularExpression( - "~^AWS4-HMAC-SHA256 Credential=$key/\\d{8}/us-west-2/es/aws4_request~", - $ringRequest['headers']['Authorization'][0] - ); - - return $this->getGenericResponse(); - }; - putenv(CredentialProvider::ENV_KEY . "=$key"); - putenv(CredentialProvider::ENV_SECRET . '=bar'); - $client = ClientBuilder::create() - ->setHandler($toWrap) - ->setSigV4Region('us-west-2') - ->setSigV4CredentialProvider(true) - ->build(); - - $client->search([ - 'index' => 'index', - 'body' => [ - 'query' => [ 'match_all' => (object)[] ], - ], - ]); - } - - public function testSignsWithProvidedCredentials() - { - $toWrap = function (array $ringRequest) { - $this->assertArrayHasKey('X-Amz-Security-Token', $ringRequest['headers']); - $this->assertSame('baz', $ringRequest['headers']['X-Amz-Security-Token'][0]); - $this->assertArrayHasKey('x-amz-content-sha256', $ringRequest['headers']); - $this->assertMatchesRegularExpression( - '~^AWS4-HMAC-SHA256 Credential=foo/\d{8}/us-west-2/es/aws4_request~', - $ringRequest['headers']['Authorization'][0] - ); - - return $this->getGenericResponse(); - }; - - $client = ClientBuilder::create() - ->setHandler($toWrap) - ->setSigV4Region('us-west-2') - ->setSigV4CredentialProvider(new Credentials('foo', 'bar', 'baz')) - ->build(); - - $client->search([ - 'index' => 'index', - 'body' => [ - 'query' => [ 'match_all' => (object)[] ], - ], - ]); - } - - public function testSignsWithProvidedCredentialsAndService() - { - $toWrap = function (array $ringRequest) { - $this->assertArrayHasKey('X-Amz-Security-Token', $ringRequest['headers']); - $this->assertSame('baz', $ringRequest['headers']['X-Amz-Security-Token'][0]); - $this->assertArrayHasKey('x-amz-content-sha256', $ringRequest['headers']); - $this->assertMatchesRegularExpression( - '~^AWS4-HMAC-SHA256 Credential=foo/\d{8}/us-west-2/aoss/aws4_request~', - $ringRequest['headers']['Authorization'][0] - ); - - return $this->getGenericResponse(); - }; - - $client = ClientBuilder::create() - ->setHandler($toWrap) - ->setSigV4Region('us-west-2') - ->setSigV4Service('aoss') - ->setSigV4CredentialProvider(new Credentials('foo', 'bar', 'baz')) - ->build(); - - $client->search([ - 'index' => 'index', - 'body' => [ - 'query' => ['match_all' => (object)[]], - ], - ]); - } - - public function testEmptyBodyProducesCorrectSha256() - { - $toWrap = function (array $ringRequest) { - $this->assertArrayHasKey('X-Amz-Security-Token', $ringRequest['headers']); - $this->assertSame('baz', $ringRequest['headers']['X-Amz-Security-Token'][0]); - $this->assertArrayHasKey('x-amz-content-sha256', $ringRequest['headers']); - $this->assertSame($ringRequest['headers']['x-amz-content-sha256'][0], 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'); - $this->assertMatchesRegularExpression( - '~^AWS4-HMAC-SHA256 Credential=foo/\d{8}/us-west-2/aoss/aws4_request~', - $ringRequest['headers']['Authorization'][0] - ); - - return $this->getGenericResponse(); - }; - - $client = ClientBuilder::create() - ->setHandler($toWrap) - ->setSigV4Region('us-west-2') - ->setSigV4Service('aoss') - ->setSigV4CredentialProvider(new Credentials('foo', 'bar', 'baz')) - ->build(); - - $client->indices()->exists(['index' => 'index']); - } - - public function testEmptyRequestBodiesShouldBeNull() - { - $toWrap = function (array $ringRequest) { - $this->assertNull($ringRequest['body']); - - return $this->getGenericResponse(); - }; - - $client = ClientBuilder::create() - ->setHandler($toWrap) - ->setSigV4Region('us-west-2') - ->setSigV4CredentialProvider(new Credentials('foo', 'bar', 'baz')) - ->build(); - - $client->indices()->exists(['index' => 'index']); - } - - public function testNonEmptyRequestBodiesShouldNotBeNull() - { - $toWrap = function (array $ringRequest) { - $this->assertNotNull($ringRequest['body']); - - return $this->getGenericResponse(); - }; - - $client = ClientBuilder::create() - ->setHandler($toWrap) - ->setSigV4Region('us-west-2') - ->setSigV4CredentialProvider(new Credentials('foo', 'bar', 'baz')) - ->build(); - - $client->search([ - 'index' => 'index', - 'body' => [ - 'query' => [ 'match_all' => (object)[] ], - ], - ]); - } - - public function testClientParametersShouldBePassedToHandler() - { - $toWrap = function (array $ringRequest) { - $this->assertArrayHasKey('client', $ringRequest); - $this->assertArrayHasKey('timeout', $ringRequest['client']); - $this->assertArrayHasKey('connect_timeout', $ringRequest['client']); - - return $this->getGenericResponse(); - }; - - $client = ClientBuilder::create() - ->setHandler($toWrap) - ->setSigV4Region('us-west-2') - ->setSigV4CredentialProvider(new Credentials('foo', 'bar', 'baz')) - ->setConnectionParams(['client' => ['timeout' => 5, 'connect_timeout' => 5]]) - ->build(); - - $client->indices()->exists(['index' => 'index']); - } - - public function testClientPortDeterminedByURL() - { - $toWrap = function (array $ringRequest) { - $this->assertArrayNotHasKey(CURLOPT_PORT, $ringRequest['client']['curl']); - - return $this->getGenericResponse(); - }; - - $client = ClientBuilder::create() - ->setHandler($toWrap) - ->setHosts(['https://search--hgkaewb2ytci3t3y6yghh5m5vje.eu-central-1.es.amazonaws.com']) - ->setSigV4Region('us-west-2') - ->setSigV4CredentialProvider(new Credentials('foo', 'bar', 'baz')) - ->build(); - - $client->indices()->exists(['index' => 'index']); - } - - private function getGenericResponse(): CompletedFutureArray - { - return new CompletedFutureArray([ - 'status' => 200, - 'body' => fopen('php://memory', 'r'), - 'transfer_stats' => ['total_time' => 0], - 'effective_url' => 'https://www.example.com', - ]); - } -} diff --git a/tests/Helper/Iterators/SearchHitIteratorTest.php b/tests/Helper/Iterators/SearchHitIteratorTest.php deleted file mode 100644 index 846fd7a77..000000000 --- a/tests/Helper/Iterators/SearchHitIteratorTest.php +++ /dev/null @@ -1,140 +0,0 @@ -searchResponse = Mockery::mock(SearchResponseIterator::class); - } - - public function tearDown(): void - { - Mockery::close(); - } - - public function testWithNoResults() - { - $searchHit = new SearchHitIterator($this->searchResponse); - $this->assertCount(0, $searchHit); - } - - public function testWithHits() - { - $this->searchResponse->shouldReceive('rewind') - ->once() - ->ordered(); - - $this->searchResponse->shouldReceive('current') - ->andReturn( - [ - 'hits' => [ - 'hits' => [ - [ 'foo' => 'bar0' ], - [ 'foo' => 'bar1' ], - [ 'foo' => 'bar2' ] - ], - 'total' => 3 - ] - ], - [ - 'hits' => [ - 'hits' => [ - [ 'foo' => 'bar0' ], - [ 'foo' => 'bar1' ], - [ 'foo' => 'bar2' ] - ], - 'total' => 3 - ] - ], - [ - 'hits' => [ - 'hits' => [ - [ 'foo' => 'bar0' ], - [ 'foo' => 'bar1' ], - [ 'foo' => 'bar2' ] - ], - 'total' => 3 - ] - ], - [ - 'hits' => [ - 'hits' => [ - [ 'foo' => 'bar0' ], - [ 'foo' => 'bar1' ], - [ 'foo' => 'bar2' ] - ], - 'total' => 3 - ] - ], - [ - 'hits' => [ - 'hits' => [ - [ 'foo' => 'bar3' ], - [ 'foo' => 'bar4' ] - ], - 'total' => 2 - ] - ], - [ - 'hits' => [ - 'hits' => [ - [ 'foo' => 'bar3' ], - [ 'foo' => 'bar4' ] - ], - 'total' => 2 - ] - ] - ); - - $this->searchResponse->shouldReceive('valid') - ->andReturn(true, true, true, false); - - $this->searchResponse->shouldReceive('next') - ->times(2) - ->ordered(); - - $responses = new SearchHitIterator($this->searchResponse); - $i = 0; - foreach ($responses as $key => $value) { - $this->assertEquals($i, $key); - $this->assertEquals("bar$i", $value['foo']); - $i++; - } - } -} diff --git a/tests/Helper/Iterators/SearchResponseIteratorTest.php b/tests/Helper/Iterators/SearchResponseIteratorTest.php deleted file mode 100644 index e1a02c64d..000000000 --- a/tests/Helper/Iterators/SearchResponseIteratorTest.php +++ /dev/null @@ -1,196 +0,0 @@ - '5m', - 'index' => 'twitter', - 'size' => 1000, - 'body' => [ - 'query' => [ - 'match_all' => new stdClass() - ] - ] - ]; - - $mock_client = m::mock(Client::class); - - $mock_client->shouldReceive('search') - ->twice() - ->with($search_params) - ->andReturn(['_scroll_id' => 'scroll_id_01']); - - $mock_client->shouldReceive('clearScroll') - ->twice() - ->withAnyArgs(); - - $responses = new SearchResponseIterator($mock_client, $search_params); - - $this->assertCount(0, $responses); - } - - public function testWithHits() - { - $search_params = [ - 'scroll' => '5m', - 'index' => 'twitter', - 'size' => 1000, - 'body' => [ - 'query' => [ - 'match_all' => new stdClass() - ] - ] - ]; - - $mock_client = m::mock(Client::class); - - $mock_client->shouldReceive('search') - ->once() - ->ordered() - ->with($search_params) - ->andReturn( - [ - '_scroll_id' => 'scroll_id_01', - 'hits' => [ - 'hits' => [ - [ - 'foo' => 'bar' - ] - ] - ] - ] - ); - - $mock_client->shouldReceive('scroll') - ->once() - ->ordered() - ->with( - [ - 'scroll' => '5m', - 'body' => [ - 'scroll_id' => 'scroll_id_01', - ] - ] - ) - ->andReturn( - [ - '_scroll_id' => 'scroll_id_02', - 'hits' => [ - 'hits' => [ - [ - 'foo' => 'bar' - ] - ] - ] - ] - ); - - $mock_client->shouldReceive('scroll') - ->once() - ->ordered() - ->with( - [ - 'scroll' => '5m', - 'body' => [ - 'scroll_id' => 'scroll_id_02', - ] - ] - ) - ->andReturn( - [ - '_scroll_id' => 'scroll_id_03', - 'hits' => [ - 'hits' => [ - [ - 'foo' => 'bar' - ] - ] - ] - ] - ); - - $mock_client->shouldReceive('scroll') - ->once() - ->ordered() - ->with( - [ - 'scroll' => '5m', - 'body' => [ - 'scroll_id' => 'scroll_id_03', - ] - ] - ) - ->andReturn( - [ - '_scroll_id' => 'scroll_id_04', - 'hits' => [ - 'hits' => [] - ] - ] - ); - - $mock_client->shouldReceive('scroll') - ->never() - ->with( - [ - 'scroll' => '5m', - 'body' => [ - 'scroll_id' => 'scroll_id_04', - ] - ] - ); - - $mock_client->shouldReceive('clearScroll') - ->once() - ->ordered() - ->withAnyArgs(); - - $responses = new SearchResponseIterator($mock_client, $search_params); - $count = 0; - $i = 0; - foreach ($responses as $response) { - $count += count($response['hits']['hits']); - $this->assertEquals($response['_scroll_id'], sprintf("scroll_id_%02d", ++$i)); - } - $this->assertEquals(3, $count); - } -} diff --git a/tests/LegacyClientIntegrationTest.php b/tests/LegacyClientIntegrationTest.php deleted file mode 100644 index a192fd5fe..000000000 --- a/tests/LegacyClientIntegrationTest.php +++ /dev/null @@ -1,208 +0,0 @@ -host = Utility::getHost(); - $this->logger = new ArrayLogger(); - } - - private function getClient(): Client - { - $client = ClientBuilder::create() - ->setHosts([$this->host]) - ->setLogger($this->logger) - ->setSSLVerification(false); - - return $client->build(); - } - - public function testLogRequestSuccessHasInfoNotEmpty() - { - $client = $this->getClient(); - - $result = $client->info(); - - $this->assertNotEmpty($this->getLevelOutput(LogLevel::INFO, $this->logger->output)); - } - - public function testLogRequestSuccessHasPortInInfo() - { - $client = $this->getClient(); - - $result = $client->info(); - - $this->assertStringContainsString('"port"', $this->getLevelOutput(LogLevel::INFO, $this->logger->output)); - } - - public function testLogRequestFailHasWarning() - { - $this->expectException(Missing404Exception::class); - $this->expectExceptionMessage('no such index [foo]'); - - $client = $this->getClient(); - $client->get([ - 'index' => 'foo', - 'id' => 'bar', - ]); - - } - - public function testIndexCannotBeEmptyStringForDelete() - { - $client = $this->getClient(); - - $this->expectException(RuntimeException::class); - - $client->delete( - [ - 'index' => '', - 'id' => 'test', - ] - ); - } - - public function testIdCannotBeEmptyStringForDelete() - { - $client = $this->getClient(); - - $this->expectException(RuntimeException::class); - - $client->delete( - [ - 'index' => 'test', - 'id' => '', - ] - ); - } - - public function testIndexCannotBeArrayOfEmptyStringsForDelete() - { - $client = $this->getClient(); - - $this->expectException(RuntimeException::class); - - $client->delete( - [ - 'index' => ['', '', ''], - 'id' => 'test', - ] - ); - } - - public function testIndexCannotBeArrayOfNullsForDelete() - { - $client = $this->getClient(); - - $this->expectException(RuntimeException::class); - - $client->delete( - [ - 'index' => [null, null, null], - 'id' => 'test', - ] - ); - } - - #[Test] - public function sendRawRequest(): void - { - $client = $this->getClient(); - - $response = $client->request('GET', '/'); - - $this->assertIsArray($response); - $expectedKeys = ['name', 'cluster_name', 'cluster_uuid', 'version', 'tagline']; - foreach ($expectedKeys as $key) { - $this->assertArrayHasKey($key, $response); - } - } - - #[Test] - public function insertDocumentUsingRawRequest(): void - { - $client = $this->getClient(); - $randomIndex = 'test_index_' .time(); - - $response = $client->request('POST', "/$randomIndex/_doc", ['body' => ['field' => 'value']]); - - $this->assertIsArray($response); - $this->assertArrayHasKey('_index', $response); - $this->assertSame($randomIndex, $response['_index']); - $this->assertArrayHasKey('_id', $response); - $this->assertArrayHasKey('result', $response); - $this->assertSame('created', $response['result']); - } - - private function getLevelOutput(string $level, array $output): string - { - foreach ($output as $out) { - if (false !== strpos($out, $level)) { - return $out; - } - } - - return ''; - } - - /** - * Tests we ignore 404 when passed as an option. - */ - public function testIgnore404(): void - { - $result = $this->getClient()->indices()->getAlias(['name' => 'i_dont_exist', 'client' => ['ignore' => 404]]); - - $this->assertEquals(404, $result['status']); - - } -} diff --git a/tests/LegacyRegisteredNamespaceTest.php b/tests/LegacyRegisteredNamespaceTest.php deleted file mode 100644 index abe5bf5cc..000000000 --- a/tests/LegacyRegisteredNamespaceTest.php +++ /dev/null @@ -1,90 +0,0 @@ -registerNamespace($builder)->build(); - // @phpstan-ignore method.notFound - $this->assertSame("123", $client->foo()->fooMethod()); - } - - public function testNonExistingNamespace() - { - $builder = new FooNamespaceBuilder(); - $client = ClientBuilder::create()->registerNamespace($builder)->build(); - - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Namespace [bar] not found'); - - // @phpstan-ignore method.notFound - $client->bar()->fooMethod(); - } -} - -/** - * @codingStandardsIgnoreStart "Each class must be in a file by itself" - not worth the extra work here - * @deprecated in 2.4.0 and will be removed in 3.0.0. - */ -class FooNamespaceBuilder implements OpenSearch\Namespaces\NamespaceBuilderInterface -{ - public function getName(): string - { - return "foo"; - } - - public function getObject(Transport|OpenSearch\TransportInterface $transport, SerializerInterface $serializer) - { - return new FooNamespace(); - } -} - -class FooNamespace -{ - public function fooMethod() - { - return "123"; - } -} -// @codingStandardsIgnoreEnd diff --git a/tests/LegacyTransportTest.php b/tests/LegacyTransportTest.php deleted file mode 100644 index 948f1f883..000000000 --- a/tests/LegacyTransportTest.php +++ /dev/null @@ -1,105 +0,0 @@ -logger = $this->createMock(LoggerInterface::class); - $this->connectionPool = $this->createMock(AbstractConnectionPool::class); - $this->connection = $this->createMock(Connection::class); - } - - public function testPerformRequestWithServerErrorResponseException404Result() - { - $deferred = new Deferred(); - $deferred->reject(new ServerErrorResponseException('foo', 404)); - $future = new FutureArray($deferred->promise()); - - $this->connection->method('performRequest') - ->willReturn($future); - - $this->connectionPool->method('nextConnection') - ->willReturn($this->connection); - - $this->connectionPool->expects($this->never()) - ->method('scheduleCheck'); - - $transport = new Transport(1, $this->connectionPool, $this->logger); - - $result = $transport->performRequest('GET', '/'); - $this->assertInstanceOf(FutureArrayInterface::class, $result); - } - - public function testPerformRequestWithServerErrorResponseException500Result() - { - $deferred = new Deferred(); - $deferred->reject(new ServerErrorResponseException('foo', 500)); - $future = new FutureArray($deferred->promise()); - - $this->connection->method('performRequest') - ->willReturn($future); - - $this->connectionPool->method('nextConnection') - ->willReturn($this->connection); - - $this->connectionPool->expects($this->once()) - ->method('scheduleCheck'); - - $transport = new Transport(1, $this->connectionPool, $this->logger); - - $result = $transport->performRequest('GET', '/'); - $this->assertInstanceOf(FutureArrayInterface::class, $result); - } -} diff --git a/tests/LegacyTransportWrapperTest.php b/tests/LegacyTransportWrapperTest.php deleted file mode 100644 index f4aea65f5..000000000 --- a/tests/LegacyTransportWrapperTest.php +++ /dev/null @@ -1,64 +0,0 @@ -logger = $this->createMock(LoggerInterface::class); - $this->connectionPool = $this->createMock(AbstractConnectionPool::class); - $this->connection = $this->createMock(Connection::class); - } - - public function testSuccess(): void - { - $deferred = new Deferred(); - $deferred->resolve(['foo' => 'bar']); - $future = new FutureArray($deferred->promise()); - - $this->connection->method('performRequest') - ->willReturn($future); - - $this->connectionPool->method('nextConnection') - ->willReturn($this->connection); - - $transport = new Transport(1, $this->connectionPool, $this->logger); - - $wrapper = new LegacyTransportWrapper($transport); - - $response = $wrapper->sendRequest('GET', 'http://localhost:9200', [], null, []); - - $this->assertIsIterable($response); - - $this->assertEquals(['foo' => 'bar'], $response); - } - -} diff --git a/tests/Serializers/ArrayToJSONSerializerTest.php b/tests/Serializers/ArrayToJSONSerializerTest.php deleted file mode 100644 index de02aaae2..000000000 --- a/tests/Serializers/ArrayToJSONSerializerTest.php +++ /dev/null @@ -1,71 +0,0 @@ - 'field']; - - $ret = $serializer->serialize($body); - - $body = json_encode($body, JSON_PRESERVE_ZERO_FRACTION); - $this->assertSame($body, $ret); - } - - public function testSerializeString() - { - $serializer = new ArrayToJSONSerializer(); - $body = 'abc'; - - $ret = $serializer->serialize($body); - - $this->assertSame($body, $ret); - } - - public function testDeserializeJSON() - { - $serializer = new ArrayToJSONSerializer(); - $body = '{"field":"value"}'; - - $ret = $serializer->deserialize($body, []); - - $body = json_decode($body, true); - $this->assertSame($body, $ret); - } -} diff --git a/tests/Serializers/EverythingToJSONSerializerTest.php b/tests/Serializers/EverythingToJSONSerializerTest.php deleted file mode 100644 index d56b9d134..000000000 --- a/tests/Serializers/EverythingToJSONSerializerTest.php +++ /dev/null @@ -1,72 +0,0 @@ - 'field']; - - $ret = $serializer->serialize($body); - - $body = json_encode($body, JSON_PRESERVE_ZERO_FRACTION); - $this->assertSame($body, $ret); - } - - public function testSerializeString() - { - $serializer = new EverythingToJSONSerializer(); - $body = 'abc'; - - $ret = $serializer->serialize($body); - - $body = '"abc"'; - $this->assertSame($body, $ret); - } - - public function testDeserializeJSON() - { - $serializer = new EverythingToJSONSerializer(); - $body = '{"field":"value"}'; - - $ret = $serializer->deserialize($body, []); - - $body = json_decode($body, true); - $this->assertSame($body, $ret); - } -} diff --git a/tests/Utility.php b/tests/Utility.php index 4b22e60c2..31d05f1c9 100644 --- a/tests/Utility.php +++ b/tests/Utility.php @@ -23,8 +23,8 @@ use Exception; use OpenSearch\Client; -use OpenSearch\ClientBuilder; -use OpenSearch\Common\Exceptions\OpenSearchException; +use OpenSearch\Exception\OpenSearchExceptionInterface; +use OpenSearch\GuzzleClientFactory; class Utility { @@ -53,20 +53,11 @@ public static function getHost(): ?string */ public static function getClient(): Client { - // @phpstan-ignore staticMethod.deprecatedClass - $clientBuilder = ClientBuilder::create() - ->setHosts([self::getHost()]); - - $clientBuilder->setConnectionParams([ - 'client' => [ - 'headers' => [ - 'Accept' => [] - ] - ] + return (new GuzzleClientFactory())->create([ + 'base_uri' => 'http://localhost:9200', + 'auth' => ['admin', getenv('OPENSEARCH_INITIAL_ADMIN_PASSWORD')], + 'verify' => false, ]); - - $clientBuilder->setSSLVerification(false); - return $clientBuilder->build(); } /** @@ -131,7 +122,7 @@ private static function wipeCluster(Client $client): void $client->cluster()->deleteComponentTemplate([ 'name' => '*' ]); - } catch (OpenSearchException $e) { + } catch (OpenSearchExceptionInterface) { // We hit a version of ES that doesn't support index templates v2 yet, so it's safe to ignore } @@ -206,13 +197,13 @@ private static function wipeDataStreams(Client $client): void 'name' => '*', 'expand_wildcards' => 'all' ]); - } catch (OpenSearchException $e) { + } catch (OpenSearchExceptionInterface) { // We hit a version of ES that doesn't understand expand_wildcards, try again without it try { $client->indices()->deleteDataStream([ 'name' => '*' ]); - } catch (OpenSearchException $e) { + } catch (OpenSearchExceptionInterface) { // We hit a version of ES that doesn't serialize DeleteDataStreamAction.Request#wildcardExpressionsOriginallySpecified // field or that doesn't support data streams so it's safe to ignore } diff --git a/util/ClientEndpoint.php b/util/ClientEndpoint.php index b4bb8cdd9..cabe750ef 100644 --- a/util/ClientEndpoint.php +++ b/util/ClientEndpoint.php @@ -52,8 +52,7 @@ public function renderClass(): string $useNamespace = ''; // The following namespaces do not have OpenSearch API specifications - // @todo Remove these deprecated namespaces in 3.0.0 - $deprecatedNamespaces = ['async_search', 'searchable_snapshots', 'ssl', 'data_frame_transform_deprecated', 'monitoring']; + $deprecatedNamespaces = []; $this->namespace = array_unique(array_merge($this->namespace, $deprecatedNamespaces)); sort($this->namespace); diff --git a/util/Endpoint.php b/util/Endpoint.php index 0f24637d1..16f7f8912 100644 --- a/util/Endpoint.php +++ b/util/Endpoint.php @@ -54,15 +54,15 @@ class Endpoint 'Termvectors' => 'TermVectors' ]; - public $namespace; - public $name; - public $apiName; - protected $content; - protected $parts = []; - protected $requiredParts = []; - protected $useNamespace = []; - private $addedPartInDoc = []; - private $properties = []; + public string $namespace; + public string $name; + public string $apiName; + protected array $content; + protected array $parts = []; + protected array $requiredParts = []; + protected array $useNamespace = []; + private array $addedPartInDoc = []; + private array $properties = []; public function __construct( string $fileName, @@ -426,12 +426,11 @@ private function getSetPart(string $param): string private function getSetBulkBody(): string { $setPart = file_get_contents(self::SET_BULK_BODY_TEMPLATE); - $this->addNamespace('OpenSearch\Common\Exceptions\InvalidArgumentException'); return str_replace(':endpoint', $this->getClassName(), $setPart); } - protected function addProperty(string $name) + protected function addProperty(string $name): void { if (!in_array($name, ['body', 'type', 'index', 'id'])) { $this->properties[$name] = sprintf(" protected \$%s;", $name); diff --git a/util/EndpointProxies/security/getUsersProxy.php b/util/EndpointProxies/security/getUsersProxy.php index 35c9a2574..643ebeba1 100644 --- a/util/EndpointProxies/security/getUsersProxy.php +++ b/util/EndpointProxies/security/getUsersProxy.php @@ -18,7 +18,6 @@ */ public function getUsers(array $params = []): array { - $endpointBuilder = $this->endpoints; if (isset($params['username'])) { $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Security\GetUser::class); diff --git a/util/GenerateEndpoints.php b/util/GenerateEndpoints.php index 30f15d715..24aa1038c 100644 --- a/util/GenerateEndpoints.php +++ b/util/GenerateEndpoints.php @@ -543,11 +543,21 @@ function isValidPhpSyntax(string $filename): bool */ function Patch_Endpoints() { - $patchEndpoints = ['AsyncSearch', 'SearchableSnapshots', 'Ssl', 'Sql', - 'DataFrameTransformDeprecated', 'Monitoring', 'Indices/RefreshSearchAnalyzers', - 'Ml/CreateConnector', 'Ml/DeleteConnector', 'Ml/GetConnector', 'Ml/GetConnectors', - 'Ml/GetModelGroups', 'Ml/UpdateModelGroup', 'Ml/DeployModel', 'Ml/GetModel', 'Ml/Predict', - 'Ml/UndeployModel']; + $patchEndpoints = [ + 'Indices/RefreshSearchAnalyzers', + 'Ml/CreateConnector', + 'Ml/DeleteConnector', + 'Ml/DeployModel', + 'Ml/GetConnector', + 'Ml/GetConnectors', + 'Ml/GetModel', + 'Ml/GetModelGroups', + 'Ml/Predict', + 'Ml/UndeployModel', + 'Ml/UpdateModelGroup', + 'Sql', + 'Ssl', + ]; $outputDir = __DIR__ . "/output"; $destDir = __DIR__ . "/../src/OpenSearch"; diff --git a/util/template/client-class b/util/template/client-class index e45c28da0..5633276ec 100644 --- a/util/template/client-class +++ b/util/template/client-class @@ -34,79 +34,30 @@ use OpenSearch\Namespaces\NamespaceBuilderInterface; class Client { - const VERSION = '2.4.7'; + const VERSION = '3.x-dev'; /** - * @var Transport - * - * @deprecated in 2.4.0 and will be removed in 3.0.0. - */ - public $transport; - - private TransportInterface $httpTransport; - - /** - * @var array + * @var array */ - protected $params; - - private EndpointFactoryInterface $endpointFactory; + protected array $params; - /** - * @var callable - * - * @deprecated in 2.4.0 and will be removed in 3.0.0. - */ - protected $endpoints; + protected EndpointFactoryInterface $endpointFactory; /** * @var NamespaceBuilderInterface[] */ - protected $registeredNamespaces = []; + protected array $registeredNamespaces = []; :namespace_properties - /** - * Client constructor - * - * @param TransportInterface|Transport $transport - * @param callable|EndpointFactoryInterface|null $endpointFactory - * @param NamespaceBuilderInterface[] $registeredNamespaces - * - * @phpstan-ignore parameter.deprecatedClass - */ public function __construct( - TransportInterface|Transport $transport, - callable|EndpointFactoryInterface|null $endpointFactory = null, + protected TransportInterface $httpTransport, + ?EndpointFactoryInterface $endpointFactory = null, array $registeredNamespaces = [], ) { - if (!$transport instanceof TransportInterface) { - @trigger_error('Passing an instance of \OpenSearch\Transport to ' . __METHOD__ . '() is deprecated in 2.4.0 and will be removed in 3.0.0. Pass an instance of \OpenSearch\TransportInterface instead.', E_USER_DEPRECATED); - // @phpstan-ignore property.deprecated - $this->transport = $transport; - // @phpstan-ignore new.deprecated - $this->httpTransport = new LegacyTransportWrapper($transport); - } else { - $this->httpTransport = $transport; - } - - if (is_callable($endpointFactory)) { - @trigger_error('Passing a callable as the $endpointFactory param in ' . __METHOD__ . ' is deprecated in 2.4.0 and will be removed in 3.0.0. Pass an instance of \OpenSearch\EndpointFactoryInterface instead.', E_USER_DEPRECATED); - $endpoints = $endpointFactory; - // @phpstan-ignore new.deprecated - $endpointFactory = new LegacyEndpointFactory($endpointFactory); - } else { - if ($endpointFactory === null) { - $endpointFactory = new EndpointFactory(); - } - $endpoints = function ($c) use ($endpointFactory) { - @trigger_error('The $endpoints property is deprecated in 2.4.0 and will be removed in 3.0.0.', E_USER_DEPRECATED); - return $endpointFactory->getEndpoint('OpenSearch\\Endpoints\\' . $c); - }; + if ($endpointFactory === null) { + $endpointFactory = new EndpointFactory(); } - - // @phpstan-ignore property.deprecated - $this->endpoints = $endpoints; $this->endpointFactory = $endpointFactory; :new-namespaces $this->registeredNamespaces = $registeredNamespaces; @@ -127,7 +78,7 @@ class Client * @return object * @throws \BadMethodCallException if the namespace cannot be found */ - public function __call(string $name, array $arguments) + public function __call(string $name, array $arguments): object { if (isset($this->registeredNamespaces[$name])) { return $this->registeredNamespaces[$name]; @@ -140,18 +91,17 @@ class Client * * @return null|mixed */ - public function extractArgument(array &$params, string $arg) + public function extractArgument(array &$params, string $arg): mixed { - if (array_key_exists($arg, $params) === true) { - $value = $params[$arg]; - $value = (is_object($value) && !is_iterable($value)) ? - (array) $value : - $value; - unset($params[$arg]); - return $value; - } else { - return null; + if (!array_key_exists($arg, $params)) { + return null; } + $value = $params[$arg]; + $value = (is_object($value) && !is_iterable($value)) ? + (array) $value : + $value; + unset($params[$arg]); + return $value; } /** diff --git a/util/template/endpoint-function b/util/template/endpoint-function index a96c37c51..9f1ae1588 100644 --- a/util/template/endpoint-function +++ b/util/template/endpoint-function @@ -1,5 +1,5 @@ :apidoc - public function :endpoint(array $params = []) + public function :endpoint(array $params = []): iterable|string|null { :extract $endpoint = $this->endpointFactory->getEndpoint(:EndpointClass::class); diff --git a/util/template/endpoint-function-bool b/util/template/endpoint-function-bool index 56e060715..ed82ebb43 100644 --- a/util/template/endpoint-function-bool +++ b/util/template/endpoint-function-bool @@ -2,10 +2,6 @@ public function :endpoint(array $params = []): bool { :extract - // Legacy option to manually make this verbose so we can check status code. - // @todo remove in 3.0.0 - $params['client']['verbose'] = true; - $endpoint = $this->endpointFactory->getEndpoint(:EndpointClass::class); $endpoint->setParams($params); :setparam diff --git a/util/template/namespace-property b/util/template/namespace-property index c7ae3a274..96fce500b 100644 --- a/util/template/namespace-property +++ b/util/template/namespace-property @@ -1,4 +1 @@ - /** - * @var :namespaceNamespace - */ - protected $:var_namespace; + protected :namespaceNamespace $:var_namespace; diff --git a/util/template/namespace-property-deprecated b/util/template/namespace-property-deprecated index b0c340a9d..87a67e43e 100644 --- a/util/template/namespace-property-deprecated +++ b/util/template/namespace-property-deprecated @@ -1,6 +1,4 @@ /** - * @var :namespaceNamespace - * * @deprecated in 2.4.2 and will be removed in 3.0.0. */ - protected $:var_namespace; + protected :namespaceNamespace $:var_namespace; diff --git a/util/template/new-namespace b/util/template/new-namespace index 1a7bff8bd..013d06683 100644 --- a/util/template/new-namespace +++ b/util/template/new-namespace @@ -1 +1 @@ - $this->:name = new :namespace($transport, $this->endpointFactory); + $this->:name = new :namespace($this->httpTransport, $this->endpointFactory); diff --git a/util/template/new-namespace-deprecated b/util/template/new-namespace-deprecated index b25dccea7..362cc31cf 100644 --- a/util/template/new-namespace-deprecated +++ b/util/template/new-namespace-deprecated @@ -1,2 +1,2 @@ // @phpstan-ignore new.deprecated, property.deprecated - $this->:name = new :namespace($transport, $this->endpointFactory); + $this->:name = new :namespace($this->httpTransport, $this->endpointFactory);