diff --git a/src/Elasticsearch/Namespaces/IndicesNamespace.php b/src/Elasticsearch/Namespaces/IndicesNamespace.php index d2312d44c..348510295 100644 --- a/src/Elasticsearch/Namespaces/IndicesNamespace.php +++ b/src/Elasticsearch/Namespaces/IndicesNamespace.php @@ -416,6 +416,17 @@ public function getAlias(array $params = []) return $this->performRequest($endpoint); } + + /** + * Proxy to getAlias() + * + * @see https://github.com/elastic/elasticsearch-php/issues/1112 + */ + public function getAliases(array $params = []) + { + return $this->getAlias($params); + } + /** * $params['index'] = (list) A comma-separated list of index names * $params['type'] = (list) A comma-separated list of document types diff --git a/src/Elasticsearch/Transport.php b/src/Elasticsearch/Transport.php index f436b0bf3..e27d9fdbd 100644 --- a/src/Elasticsearch/Transport.php +++ b/src/Elasticsearch/Transport.php @@ -129,8 +129,9 @@ function ($response) { }, //onFailure function ($response) { + $code = $response->getCode(); // Ignore 400 level errors, as that means the server responded just fine - if (!(isset($response['code']) && $response['code'] >=400 && $response['code'] < 500)) { + if ($code < 400 || $code >= 500) { // Otherwise schedule a check $this->connectionPool->scheduleCheck(); } diff --git a/src/autoload.php b/src/autoload.php index 5da69d117..ec80ccc85 100644 --- a/src/autoload.php +++ b/src/autoload.php @@ -19,47 +19,50 @@ * @see https://github.com/elastic/elasticsearch-php/issues/967 */ -$classesToAlias = [ - '\Elasticsearch\Endpoints\Nodes\HotThreads' => '\Elasticsearch\Endpoints\Cluster\Nodes\HotThreads', - '\Elasticsearch\Endpoints\Nodes\Info' => '\Elasticsearch\Endpoints\Cluster\Nodes\Info', - '\Elasticsearch\Endpoints\Nodes\ReloadSecureSettings' => '\Elasticsearch\Endpoints\Cluster\Nodes\ReloadSecureSettings', - '\Elasticsearch\Endpoints\Nodes\Stats' => '\Elasticsearch\Endpoints\Cluster\Nodes\Stats', - '\Elasticsearch\Endpoints\Cluster\GetSettings' => '\Elasticsearch\Endpoints\Cluster\Settings\Get', - '\Elasticsearch\Endpoints\Cluster\PutSettings' => '\Elasticsearch\Endpoints\Cluster\Settings\Put', - '\Elasticsearch\Endpoints\Indices\DeleteAlias' => '\Elasticsearch\Endpoints\Indices\Alias\Delete', - '\Elasticsearch\Endpoints\Indices\ExistsAlias' => '\Elasticsearch\Endpoints\Indices\Alias\Exists', - '\Elasticsearch\Endpoints\Indices\GetAlias' => '\Elasticsearch\Endpoints\Indices\Alias\Get', - '\Elasticsearch\Endpoints\Indices\PutAlias' => '\Elasticsearch\Endpoints\Indices\Alias\Put', - '\Elasticsearch\Endpoints\Indices\ClearCache' => '\Elasticsearch\Endpoints\Indices\Cache\Clear', - '\Elasticsearch\Endpoints\Indices\GetMapping' => '\Elasticsearch\Endpoints\Indices\Mapping\Get', - '\Elasticsearch\Endpoints\Indices\GetFieldMapping' => '\Elasticsearch\Endpoints\Indices\Mapping\GetField', - '\Elasticsearch\Endpoints\Indices\PutMapping' => '\Elasticsearch\Endpoints\Indices\Mapping\Put', - '\Elasticsearch\Endpoints\Indices\GetSettings' => '\Elasticsearch\Endpoints\Indices\Settings\Get', - '\Elasticsearch\Endpoints\Indices\PutSettings' => '\Elasticsearch\Endpoints\Indices\Settings\Put', - '\Elasticsearch\Endpoints\Indices\GetTemplate' => '\Elasticsearch\Endpoints\Indices\Template\Get', - '\Elasticsearch\Endpoints\Indices\PutTemplate' => '\Elasticsearch\Endpoints\Indices\Template\Put', - '\Elasticsearch\Endpoints\Indices\ExistsTemplate' => '\Elasticsearch\Endpoints\Indices\Template\Exists', - '\Elasticsearch\Endpoints\Indices\DeleteTemplate' => '\Elasticsearch\Endpoints\Indices\Template\Delete', - '\Elasticsearch\Endpoints\Indices\ExistsType' => '\Elasticsearch\Endpoints\Indices\Type\Exists', - '\Elasticsearch\Endpoints\Indices\GetUpgrade' => '\Elasticsearch\Endpoints\Indices\Upgrade\Get', - '\Elasticsearch\Endpoints\Indices\Upgrade' => '\Elasticsearch\Endpoints\Indices\Upgrade\Post', - '\Elasticsearch\Endpoints\Indices\ValidateQuery' => '\Elasticsearch\Endpoints\Indices\Validate\Query', - '\Elasticsearch\Endpoints\Ingest\DeletePipeline' => '\Elasticsearch\Endpoints\Ingest\Pipeline\Delete', - '\Elasticsearch\Endpoints\Ingest\GetPipeline' => '\Elasticsearch\Endpoints\Ingest\Pipeline\Get', - '\Elasticsearch\Endpoints\Ingest\PutPipeline' => '\Elasticsearch\Endpoints\Ingest\Pipeline\Put', - '\Elasticsearch\Endpoints\Ingest\ProcessorGrok' => '\Elasticsearch\Endpoints\Ingest\Pipeline\ProcessorGrok', - '\Elasticsearch\Endpoints\GetScript' => '\Elasticsearch\Endpoints\Script\Get', - '\Elasticsearch\Endpoints\PutScript' => '\Elasticsearch\Endpoints\Script\Put', - '\Elasticsearch\Endpoints\DeleteScript' => '\Elasticsearch\Endpoints\Script\Delete', - '\Elasticsearch\Endpoints\Snapshot\CreateRepository' => '\Elasticsearch\Endpoints\Snapshot\Repository\Create', - '\Elasticsearch\Endpoints\Snapshot\DeleteRepository' => '\Elasticsearch\Endpoints\Snapshot\Repository\Delete', - '\Elasticsearch\Endpoints\Snapshot\GetRepository' => '\Elasticsearch\Endpoints\Snapshot\Repository\Get', - '\Elasticsearch\Endpoints\Snapshot\VerifyRepository' => '\Elasticsearch\Endpoints\Snapshot\Repository\Verify', - '\Elasticsearch\Endpoints\GetSource' => '\Elasticsearch\Endpoints\Source\Get', - '\Elasticsearch\Endpoints\Tasks\ListTasks' => '\Elasticsearch\Endpoints\Tasks\TasksList' +$aliasToClass = [ + '\Elasticsearch\Endpoints\Cluster\Nodes\HotThreads' => '\Elasticsearch\Endpoints\Nodes\HotThreads', + '\Elasticsearch\Endpoints\Cluster\Nodes\Info' => '\Elasticsearch\Endpoints\Nodes\Info' , + '\Elasticsearch\Endpoints\Cluster\Nodes\ReloadSecureSettings' => '\Elasticsearch\Endpoints\Nodes\ReloadSecureSettings', + '\Elasticsearch\Endpoints\Cluster\Nodes\Stats' => '\Elasticsearch\Endpoints\Nodes\Stats', + '\Elasticsearch\Endpoints\Cluster\Settings\Get' => '\Elasticsearch\Endpoints\Cluster\GetSettings', + '\Elasticsearch\Endpoints\Cluster\Settings\Put' => '\Elasticsearch\Endpoints\Cluster\PutSettings', + '\Elasticsearch\Endpoints\Indices\Alias\Delete' => '\Elasticsearch\Endpoints\Indices\DeleteAlias', + '\Elasticsearch\Endpoints\Indices\Alias\Exists' => '\Elasticsearch\Endpoints\Indices\ExistsAlias', + '\Elasticsearch\Endpoints\Indices\Alias\Get' => '\Elasticsearch\Endpoints\Indices\GetAlias', + '\Elasticsearch\Endpoints\Indices\Alias\Put' => '\Elasticsearch\Endpoints\Indices\PutAlias', + '\Elasticsearch\Endpoints\Indices\Aliases\Update' => '\Elasticsearch\Endpoints\Indices\UpdateAliases', + '\Elasticsearch\Endpoints\Indices\Cache\Clear' => '\Elasticsearch\Endpoints\Indices\ClearCache', + '\Elasticsearch\Endpoints\Indices\Exists\Types' => '\Elasticsearch\Endpoints\Indices\ExistsType', + '\Elasticsearch\Endpoints\Indices\Type\Exists' => '\Elasticsearch\Endpoints\Indices\ExistsType', + '\Elasticsearch\Endpoints\Indices\Field\Get' => '\Elasticsearch\Endpoints\Indices\GetFieldMapping', + '\Elasticsearch\Endpoints\Indices\Mapping\GetField' => '\Elasticsearch\Endpoints\Indices\GetFieldMapping', + '\Elasticsearch\Endpoints\Indices\Mapping\Get' => '\Elasticsearch\Endpoints\Indices\GetMapping', + '\Elasticsearch\Endpoints\Indices\Mapping\Put' => '\Elasticsearch\Endpoints\Indices\PutMapping', + '\Elasticsearch\Endpoints\Indices\Settings\Get' => '\Elasticsearch\Endpoints\Indices\GetSettings', + '\Elasticsearch\Endpoints\Indices\Settings\Put' => '\Elasticsearch\Endpoints\Indices\PutSettings', + '\Elasticsearch\Endpoints\Indices\Template\Get' => '\Elasticsearch\Endpoints\Indices\GetTemplate', + '\Elasticsearch\Endpoints\Indices\Template\Put' => '\Elasticsearch\Endpoints\Indices\PutTemplate', + '\Elasticsearch\Endpoints\Indices\Template\Exists' => '\Elasticsearch\Endpoints\Indices\ExistsTemplate', + '\Elasticsearch\Endpoints\Indices\Template\Delete' => '\Elasticsearch\Endpoints\Indices\DeleteTemplate', + '\Elasticsearch\Endpoints\Indices\Upgrade\Get' => '\Elasticsearch\Endpoints\Indices\GetUpgrade', + '\Elasticsearch\Endpoints\Indices\Upgrade\Post' => '\Elasticsearch\Endpoints\Indices\Upgrade', + '\Elasticsearch\Endpoints\Indices\Validate\Query' => '\Elasticsearch\Endpoints\Indices\ValidateQuery', + '\Elasticsearch\Endpoints\Ingest\Pipeline\Delete' => '\Elasticsearch\Endpoints\Ingest\DeletePipeline', + '\Elasticsearch\Endpoints\Ingest\Pipeline\Get' => '\Elasticsearch\Endpoints\Ingest\GetPipeline', + '\Elasticsearch\Endpoints\Ingest\Pipeline\Put' => '\Elasticsearch\Endpoints\Ingest\PutPipeline', + '\Elasticsearch\Endpoints\Ingest\Pipeline\ProcessorGrok' => '\Elasticsearch\Endpoints\Ingest\ProcessorGrok', + '\Elasticsearch\Endpoints\Script\Get' => '\Elasticsearch\Endpoints\GetScript', + '\Elasticsearch\Endpoints\Script\Put' => '\Elasticsearch\Endpoints\PutScript', + '\Elasticsearch\Endpoints\Script\Delete' => '\Elasticsearch\Endpoints\DeleteScript', + '\Elasticsearch\Endpoints\Snapshot\Repository\Create' => '\Elasticsearch\Endpoints\Snapshot\CreateRepository', + '\Elasticsearch\Endpoints\Snapshot\Repository\Delete' => '\Elasticsearch\Endpoints\Snapshot\DeleteRepository', + '\Elasticsearch\Endpoints\Snapshot\Repository\Get' => '\Elasticsearch\Endpoints\Snapshot\GetRepository', + '\Elasticsearch\Endpoints\Snapshot\Repository\Verify' => '\Elasticsearch\Endpoints\Snapshot\VerifyRepository', + '\Elasticsearch\Endpoints\Source\Get' => '\Elasticsearch\Endpoints\GetSource', + '\Elasticsearch\Endpoints\Tasks\TasksList' => '\Elasticsearch\Endpoints\Tasks\ListTasks' ]; -foreach ($classesToAlias as $original => $alias) { +foreach ($aliasToClass as $alias => $original) { if (!class_exists($alias, false)) { class_alias($original, $alias); } diff --git a/tests/Elasticsearch/Tests/BackwardCompatibleTest.php b/tests/Elasticsearch/Tests/BackwardCompatibleTest.php index a247dd257..d1678612e 100644 --- a/tests/Elasticsearch/Tests/BackwardCompatibleTest.php +++ b/tests/Elasticsearch/Tests/BackwardCompatibleTest.php @@ -17,6 +17,8 @@ namespace Elasticsearch\Tests; +use Elasticsearch\Namespaces\IndicesNamespace; + /** * Class BackwardCompatibleTest * @@ -30,14 +32,12 @@ class BackwardCompatibleTest extends \PHPUnit\Framework\TestCase public function getClasses() { return [ - //['Elasticsearch\Endpoints\TermVectors'], ['Elasticsearch\Endpoints\Delete'], ['Elasticsearch\Endpoints\ScriptsPainlessExecute'], ['Elasticsearch\Endpoints\Create'], ['Elasticsearch\Endpoints\Exists'], ['Elasticsearch\Endpoints\Get'], ['Elasticsearch\Endpoints\Explain'], - //['Elasticsearch\Endpoints\MTermVectors'], ['Elasticsearch\Endpoints\Search'], ['Elasticsearch\Endpoints\FieldCaps'], ['Elasticsearch\Endpoints\Msearch'], @@ -90,6 +90,9 @@ public function getClasses() ['Elasticsearch\Endpoints\Indices\Alias\Exists'], ['Elasticsearch\Endpoints\Indices\Alias\Get'], ['Elasticsearch\Endpoints\Indices\Alias\Put'], + ['Elasticsearch\Endpoints\Indices\Aliases\Update'], + ['Elasticsearch\Endpoints\Indices\Exists\Types'], + ['Elasticsearch\Endpoints\Indices\Field\Get'], ['Elasticsearch\Endpoints\Indices\Settings\Get'], ['Elasticsearch\Endpoints\Indices\Settings\Put'], ['Elasticsearch\Endpoints\Indices\Upgrade\Get'], @@ -155,4 +158,12 @@ public function testOldClassNamespacesPreviousTo67($class) { $this->assertTrue(class_exists($class, true), sprintf("Class %s does not exist", $class)); } + + /** + * @see https://github.com/elastic/elasticsearch-php/issues/1112 + */ + public function testGetAliasesExistsInIndicesNamespace() + { + $this->assertTrue(method_exists(IndicesNamespace::class, 'getAliases')); + } } diff --git a/tests/Elasticsearch/Tests/TransportTest.php b/tests/Elasticsearch/Tests/TransportTest.php new file mode 100644 index 000000000..84923c167 --- /dev/null +++ b/tests/Elasticsearch/Tests/TransportTest.php @@ -0,0 +1,84 @@ +logger = $this->createMock(LoggerInterface::class); + $this->trace = $this->createMock(LoggerInterface::class); + $this->serializer = $this->createMock(SerializerInterface::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); + } +}