-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reload core during schema update (#191)
--------- Co-authored-by: Brian Weaver <[email protected]> Co-authored-by: Kevin Porras <[email protected]> Co-authored-by: Tom Stovall <[email protected]>
- Loading branch information
Showing
17 changed files
with
289 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ | |
.idea | ||
.DS_Store | ||
docs/Badge.confluence | ||
|
||
.envrc |
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @pantheon-systems/site-experience |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
apiVersion: backstage.io/v1alpha1 | ||
kind: Component | ||
metadata: | ||
name: search_api_pantheon | ||
description: Auto-generated catalog info for pantheon-systems/search_api_pantheon | ||
annotations: | ||
backstage.io/techdocs-ref: dir:docs/ | ||
spec: | ||
type: library | ||
lifecycle: mature | ||
owner: site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Drupal\search_api_pantheon\Commands; | ||
|
||
use Drupal\Core\Logger\LoggerChannelFactoryInterface; | ||
use Drupal\Core\Logger\LoggerChannelTrait; | ||
use Drupal\search_api_pantheon\Services\PantheonGuzzle; | ||
use Drupal\search_api_pantheon\Services\SchemaPoster; | ||
use Drush\Commands\DrushCommands; | ||
|
||
/** | ||
* Drush Search Api Pantheon Schema Commands. | ||
*/ | ||
class Reload extends DrushCommands { | ||
use LoggerChannelTrait; | ||
|
||
/** | ||
* Configured pantheon-solr-specific guzzle client. | ||
* | ||
* @var \Drupal\search_api_pantheon\Services\PantheonGuzzle | ||
*/ | ||
private PantheonGuzzle $pantheonGuzzle; | ||
|
||
/** | ||
* Configured pantheon-solr-specific schema poster class. | ||
* | ||
* @var \Drupal\search_api_pantheon\Services\SchemaPoster | ||
*/ | ||
private SchemaPoster $schemaPoster; | ||
|
||
/** | ||
* Class constructor. | ||
* | ||
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactory | ||
* Injected by container. | ||
* @param \Drupal\search_api_pantheon\Services\PantheonGuzzle $pantheonGuzzle | ||
* Injected by container. | ||
* @param \Drupal\search_api_pantheon\Services\SchemaPoster $schemaPoster | ||
* Injected by Container. | ||
*/ | ||
public function __construct( | ||
LoggerChannelFactoryInterface $loggerChannelFactory, | ||
PantheonGuzzle $pantheonGuzzle, | ||
SchemaPoster $schemaPoster | ||
) { | ||
$this->logger = $loggerChannelFactory->get('SearchAPIPantheon Drush'); | ||
$this->pantheonGuzzle = $pantheonGuzzle; | ||
$this->schemaPoster = $schemaPoster; | ||
} | ||
|
||
/** | ||
* Search_api_pantheon:reloadSchema. | ||
* | ||
* @usage search-api-pantheon:reloadSchema | ||
* Reload the latest schema | ||
* | ||
* @command search-api-pantheon:reloadSchema | ||
*/ | ||
public function reloadSchema() { | ||
try { | ||
$this->schemaPoster->reloadServer(); | ||
} | ||
catch (\Exception $e) { | ||
$this->logger->error((string) $e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Drupal\search_api_pantheon\Services; | ||
|
||
use Drupal\Core\Logger\LoggerChannelFactoryInterface; | ||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Uri; | ||
use Psr\Log\LoggerAwareInterface; | ||
use Psr\Log\LoggerAwareTrait; | ||
|
||
class Reload implements LoggerAwareInterface { | ||
use LoggerAwareTrait; | ||
|
||
/** | ||
* @var \Drupal\search_api_pantheon\Services\Reload | ||
*/ | ||
protected $configuration; | ||
/** | ||
* @var \Drupal\search_api_pantheon\Services\Reload | ||
*/ | ||
protected $logger_factory; | ||
|
||
/** | ||
* @var \Drupal\search_api_pantheon\Services\PantheonGuzzle | ||
*/ | ||
protected PantheonGuzzle $client; | ||
|
||
/** | ||
* Class Constructor. | ||
*/ | ||
public function __construct( | ||
LoggerChannelFactoryInterface $logger_factory, | ||
PantheonGuzzle $client, | ||
) { | ||
$this->setLogger($logger_factory->get('reload_service')); | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* Reload the server after schema upload. | ||
* | ||
* @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException | ||
*/ | ||
public function reloadServer(): bool { | ||
// Schema upload URL. | ||
$uri = new Uri( | ||
$this->getClient() | ||
->getEndpoint() | ||
->getReloadUri() | ||
); | ||
|
||
$this->logger->debug('Reload url: ' . (string) $uri); | ||
|
||
// Send the request. | ||
$request = new Request( | ||
'POST', | ||
$uri, | ||
[ | ||
'Accept' => 'application/json', | ||
'Content-Type' => 'application/json', | ||
] | ||
); | ||
$response = $this->getClient()->sendRequest($request); | ||
|
||
$status_code = $response->getStatusCode(); | ||
$reload_logger_content = [ | ||
'status_code' => $status_code, | ||
'reason' => $response->getReasonPhrase(), | ||
]; | ||
if ($status_code >= 200 && $status_code < 300) { | ||
$this->logger->info('Server reloaded: {status_code} {reason}', $reload_logger_content); | ||
return TRUE; | ||
} | ||
$this->logger->error('Server not reloaded: {status_code} {reason}', $reload_logger_content); | ||
return FALSE; | ||
} | ||
|
||
public function getClient(): PantheonGuzzle { | ||
return $this->client; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.