Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload after post for 8.1.x pre-release #191

Merged
merged 43 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
aa4f644
Update CODEOWNERS for new team names (#183)
greg-1-anderson Sep 5, 2024
e879586
Add or update catalog-info.yml
namespacebrian Sep 10, 2024
a14dfad
Merge pull request #185 from pantheon-systems/add-catalog-info-20240910
greg-1-anderson Sep 12, 2024
0e2b0fe
First attempt to reload core during post schema.
kporras07 Nov 8, 2024
2e324de
WIP
pwtyler Nov 12, 2024
23a7e20
fixup & lint
pwtyler Nov 12, 2024
fd2778c
lint
pwtyler Nov 12, 2024
21b9cfe
fixup
pwtyler Nov 12, 2024
5d42df6
Add reload path to diagnose debugging
pwtyler Nov 12, 2024
f9bbd8b
adjust path
pwtyler Nov 12, 2024
2ebc484
test adjust
pwtyler Nov 12, 2024
36552ec
back out partial test fix
pwtyler Nov 12, 2024
ada254e
Add new reload drush command
namespacebrian Nov 12, 2024
12320c0
Remove extra copypasta methods
namespacebrian Nov 12, 2024
eb252e7
Missing close brace
namespacebrian Nov 12, 2024
0c8ed65
fixup
pwtyler Nov 12, 2024
97684a7
Update tests/Unit/EndpointServiceTest.php
pwtyler Nov 12, 2024
9caa03f
update services yml
pwtyler Nov 12, 2024
55948c7
whitespace
pwtyler Nov 12, 2024
89fd4bc
lintfix
pwtyler Nov 12, 2024
a6b1488
toms hasily coded slapdash core reload.
stovak Nov 12, 2024
12cab2c
phpcbf
pwtyler Nov 13, 2024
7debd4b
linting
stovak Nov 13, 2024
6782f08
Update .gitignore
stovak Nov 13, 2024
e829f7c
Reload server, not reload core
pwtyler Nov 13, 2024
41de021
Revert "toms hasily coded slapdash core reload."
pwtyler Nov 13, 2024
c1ba151
restore docblock
pwtyler Nov 13, 2024
9031e50
restore line ending fix
pwtyler Nov 13, 2024
54ae001
Reapply "toms hasily coded slapdash core reload."
pwtyler Nov 13, 2024
1471742
new robo drush tests
pwtyler Nov 13, 2024
abbb048
Moving reload to it's own service
stovak Nov 13, 2024
b1e21d8
Attempt Drush call reload directly instead of through SchemaPoster
pwtyler Nov 13, 2024
0e0449f
lint
pwtyler Nov 13, 2024
2331ef2
Fixing logger factory
stovak Nov 13, 2024
03d8932
Add success output to Drush Schema Reload
pwtyler Nov 13, 2024
083de1e
Revert "Attempt Drush call reload directly instead of through SchemaP…
pwtyler Nov 13, 2024
7c209c8
solr admin module
pwtyler Nov 13, 2024
4ecb155
changes to solr connector
stovak Nov 13, 2024
c4383b0
phpcs
pwtyler Nov 13, 2024
1714e95
back out solr connector
pwtyler Nov 13, 2024
2d032c3
Revert "back out solr connector"
pwtyler Nov 14, 2024
02fa0d0
Reapply "back out solr connector"
pwtyler Nov 14, 2024
f89aa7c
restore reload_path
pwtyler Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export PANTHEON_INDEX_PORT=8983
export PANTHEON_INDEX_PATH=/solr
export PANTHEON_INDEX_CORE=${SOLR_CORE}
export PANTHEON_INDEX_SCHEME=http
export PANTHEON_INDEX_RELOAD_PATH=${SOLR_RELOAD_PATH}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
.idea
.DS_Store
docs/Badge.confluence

.envrc
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @pantheon-systems/site-experience
37 changes: 37 additions & 0 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public function testFull(int $drupal_version = 9, string $site_name = NULL) {
// Test creating Solr index.
$this->testSolrIndexCreate($site_name, 'dev');

// Test running the reload
$this->testPantheonSolrReload($site_name, 'dev');
$this->testSolrReload($site_name, 'dev');

// Test select query.
$this->testSolrSelect($site_name, 'dev');

Expand Down Expand Up @@ -573,6 +577,7 @@ public function testModuleEnable(string $site_name, string $env = 'dev') {
'--yes',
'search_api_pantheon',
'search_api_pantheon_admin',
'search_api_solr_admin'
)
->run();
$this->taskExec(static::$TERMINUS_EXE)
Expand Down Expand Up @@ -802,9 +807,41 @@ public function testSolrIndexCreate(string $site_name, string $env = 'dev') {
if (!$result->wasSuccessful()) {
exit(1);
}
}

public function testPantheonSolrReload(string $site_name, string $env = 'dev') {
$result = $this->taskExec( static::$TERMINUS_EXE )
->args(
'drush',
"$site_name.$env",
'--',
'search-api-pantheon:reloadSchema',
)
->run();
if (!$result->wasSuccessful()) {
exit(1);
}
}

public function testSolrReload(string $site_name, string $env = 'dev') {
$result = $this->taskExec( static::$TERMINUS_EXE )
->args(
'drush',
"$site_name.$env",
'--',
'search-api-solr:reload',
'pantheon_solr8'
)
->run();
if (!$result->wasSuccessful()) {
exit(1);
}
}





/**
* Use search-api-pantheon:select command to ensure both Drupal index and the actual Solr index have the same amount of items.
*
Expand Down
12 changes: 12 additions & 0 deletions catalog-info.yml
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
5 changes: 5 additions & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ services:
arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.endpoint", "@search_api_pantheon.solarium_client" ]
tags:
- { name: drush.command }
search_api_pantheon.drush_reload:
class: \Drupal\search_api_pantheon\Commands\Reload
arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ]
tags:
- { name: drush.command }
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<server name="PANTHEON_INDEX_PATH" value="${PANTHEON_INDEX_PATH}" />
<server name="PANTHEON_INDEX_CORE" value="${PANTHEON_INDEX_CORE}" />
<server name="PANTHEON_INDEX_SCHEMA" value="${PANTHEON_INDEX_SCHEMA}" />
<server name="PANTHEON_INDEX_RELOAD_PATH" value="${PANTHEON_INDEX_RELOAD_PATH}" />
</php>
<testsuites>
<testsuite name="unit">
Expand Down
3 changes: 3 additions & 0 deletions search_api_pantheon.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ services:
class: Drupal\search_api_pantheon\EventSubscriber\SearchApiPantheonSolrConfigFilesAlter
tags:
- { name: event_subscriber }
search_api_pantheon.reload:
class: Drupal\search_api_pantheon\Services\Reload
arguments: ['@logger.factory', '@search_api_pantheon.pantheon_guzzle']
3 changes: 3 additions & 0 deletions src/Commands/Diagnose.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public function diagnose() {
$this->logger->notice('Index PATH Value: {var}', [
'var' => $this->endpoint->getPath(),
]);
$this->logger->notice('Index RELOAD_PATH Value: {var}', [
'var' => $this->endpoint->getReloadPath(),
]);
$this->logger->notice('Testing bare Connection...');
$response = $this->pingSolrHost();
$this->logger->notice('Ping Received Response? {var}', [
Expand Down
68 changes: 68 additions & 0 deletions src/Commands/Reload.php
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);
}
}

}
1 change: 1 addition & 0 deletions src/Plugin/SolrConnector/PantheonSolrConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public static function getPlatformConfig() {
'path' => getenv('PANTHEON_INDEX_PATH'),
'core' => getenv('PANTHEON_INDEX_CORE'),
'schema' => getenv('PANTHEON_INDEX_SCHEMA'),
'reload_path' => getenv('PANTHEON_INDEX_RELOAD_PATH'),
];
}

Expand Down
29 changes: 29 additions & 0 deletions src/Services/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,35 @@ public function getSchemaUploadUri(): string {
);
}

/**
* Get URL in pantheon environment to POST reload requests.
*
* @return string
* URL of envrionment.
*/
public function getReloadUri(): string {
return vsprintf(
'%s://%s:%d/%s%s',
[
$this->getScheme(),
$this->getHost(),
$this->getPort(),
$this->getPath(),
$this->getReloadPath(),
]
);
}

/**
* Get the path for Schema Reloads.
*
* @return string
* The path for schema reloads
*/
public function getReloadPath(): string {
return $this->options['reload_path'];
}

/**
* Get the path for Schema Uploads.
*
Expand Down
10 changes: 8 additions & 2 deletions src/Services/PantheonGuzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ public function __construct(Endpoint $endpoint, LoggerChannelFactoryInterface $l
$config['cert'] = $cert;
}
parent::__construct($config);
$this->endpoint = $endpoint;
$this->logger = $logger_factory->get('PantheonGuzzle');
if (!$endpoint instanceof Endpoint) {
throw new \InvalidArgumentException('Endpoint must be an instance of Endpoint');
}
$this->setEndpoint($endpoint);
if ($logger_factory instanceof LoggerChannelFactoryInterface) {
$this->setLogger($logger_factory->get('PantheonGuzzle'));
}
$this->setLogger($logger_factory->get('PantheonGuzzle'));
}

/**
Expand Down
82 changes: 82 additions & 0 deletions src/Services/Reload.php
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;
}

}
24 changes: 24 additions & 0 deletions src/Services/SchemaPoster.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class SchemaPoster implements LoggerAwareInterface {
*/
protected $moduleExtensionList;

protected LoggerChannelFactoryInterface $loggerFactory;

/**
* Class Constructor.
*/
Expand All @@ -68,6 +70,7 @@ public function __construct(
ModuleExtensionList $module_extension_list
) {
$this->logger = $logger_factory->get('PantheonSearch');
$this->loggerFactory = $logger_factory;
$this->client = $client;
$this->entityTypeManager = $entity_type_manager;
$this->moduleExtensionList = $module_extension_list;
Expand Down Expand Up @@ -105,9 +108,30 @@ public function postSchema(string $server_id, $files = []): array {
throw new \Exception('Cannot post schema to environment url.');
}

$status_code = $response->getStatusCode();
$this->logger->info('Status code: ' . $status_code);
if ($status_code >= 200 && $status_code < 300) {
// @TODO Maybe we need to capture exception here??
// Call reload on the server.
$this->reloadServer();
}
$this->logger->info('After server reload?');

return $this->processResponse($response);
}

/**
* Reload the server after schema upload.
*
* @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException
*
* @return bool
*/
public function reloadServer(): bool {
$reload = new Reload($this->loggerFactory, $this->client);
return $reload->reloadServer();
}

/**
* Process response and return message to be shown to user.
*
Expand Down
Loading
Loading