Skip to content
Snippets Groups Projects

Issue #3186932: Use ruflin/Elastica instead of nodespark/des-connector

22 files
+ 1994
901
Compare changes
  • Side-by-side
  • Inline
Files
22
@@ -7,9 +7,11 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;
// use Drupal\elasticsearch_connector\ElasticSearch\ClientManager;
use Drupal\elasticsearch_connector\ElasticSearch\ClientManagerInterface;
use Drupal\elasticsearch_connector\Entity\Cluster;
use Drupal\elasticsearch_connector\Entity\Index;
use Elastica\Exception\ConnectionException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -81,7 +83,7 @@ class ClusterListBuilder extends ConfigEntityListBuilder {
* itself an array with the cluster and any indices as values.
* - lone_indexes: Array of indices without a cluster.
*/
public function group() {
public function group(): array {
/** @var \Drupal\elasticsearch_connector\Entity\Cluster[] $clusters */
$clusters = $this->storage->loadMultiple();
/** @var \Drupal\elasticsearch_connector\Entity\Index[] $indices */
@@ -95,10 +97,10 @@ class ClusterListBuilder extends ConfigEntityListBuilder {
];
foreach ($indices as $index) {
if ($index->server == $cluster->cluster_id) {
if ($index->server === $cluster->cluster_id) {
$cluster_group['index.' . $index->index_id] = $index;
}
elseif ($index->server == NULL) {
elseif ($index->server === NULL) {
$lone_indices['index.' . $index->index_id] = $index;
}
}
@@ -115,7 +117,7 @@ class ClusterListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
public function buildHeader(): array {
return [
'type' => $this->t('Type'),
'title' => $this->t('Name'),
@@ -128,13 +130,14 @@ class ClusterListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
public function buildRow(EntityInterface $entity): array {
if ($entity instanceof Cluster) {
$client_connector = $this->clientManager->getClientForCluster($entity);
$client = $this->clientManager->getClient($entity);
}
elseif ($entity instanceof Index) {
/** @var \Drupal\elasticsearch_connector\Entity\Cluster $cluster */
$cluster = $this->clusterStorage->load($entity->server);
$client_connector = $this->clientManager->getClientForCluster($cluster);
$client = $this->clientManager->getClient($cluster);
}
else {
throw new NotFoundHttpException();
@@ -145,15 +148,20 @@ class ClusterListBuilder extends ConfigEntityListBuilder {
$status = NULL;
if (isset($entity->cluster_id)) {
$cluster = $this->clusterStorage->load($entity->cluster_id);
if ($client_connector->isClusterOk()) {
$cluster_health = $client_connector->cluster()->health();
$version_number = $client_connector->getServerVersion();
$status = $cluster_health['status'];
$status = $this->t('Not available');
$version_number = $this->t('Unknown version');
try {
if ($client->hasConnection()) {
$version_number = $client->getVersion();
$status = $client->getCluster()->getHealth()->getStatus();
}
}
else {
$status = $this->t('Not available');
$version_number = $this->t('Unknown version');
catch (ConnectionException $e) {
$this->messenger()->addError(
$this->t('Elasticsearch connection failed due to: @error', [
'@error' => $e->getMessage(),
])
);
}
$result = [
'data' => [
@@ -218,7 +226,7 @@ class ClusterListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
public function getDefaultOperations(EntityInterface $entity): array {
$operations = [];
if (isset($entity->cluster_id)) {
Loading