You are here

protected function SolrDiskUsageSensorPlugin::getSolrServerIfAvailable in Monitoring 8

Returns the Solr server if available.

Return value

\Drupal\search_api\ServerInterface|null Returns the Solr server if available otherwise NULL.

Throws

\RuntimeException Thrown when the Solr is not configured the server does not exist or its not available.

1 call to SolrDiskUsageSensorPlugin::getSolrServerIfAvailable()
SolrDiskUsageSensorPlugin::getSolrServer in src/Plugin/monitoring/SensorPlugin/SolrDiskUsageSensorPlugin.php
Returns the Solr server.

File

src/Plugin/monitoring/SensorPlugin/SolrDiskUsageSensorPlugin.php, line 278

Class

SolrDiskUsageSensorPlugin
Monitors the Solr disk usage.

Namespace

Drupal\monitoring\Plugin\monitoring\SensorPlugin

Code

protected function getSolrServerIfAvailable() {
  if (!($server_name = $this->sensorConfig
    ->getSetting('server'))) {
    throw new \RuntimeException($this
      ->t('Solr server is not configured.'));
  }
  if (!($server = $this->entityTypeManager
    ->getStorage('search_api_server')
    ->load($server_name))) {
    throw new \RuntimeException($this
      ->t("Solr server doesn't exist."));
  }
  $solr_connector = $server
    ->getBackend()
    ->getSolrConnector();
  if (!$solr_connector
    ->pingServer()) {
    throw new \RuntimeException($this
      ->t('Server is not available.'));
  }
  if (!$solr_connector
    ->pingCore()) {
    throw new \RuntimeException($this
      ->t('Core is not available.'));
  }
  return $server;
}