Modernize file storage engine selection

Summary:
Fixes T5843. File storage engines use a very old "selector" mechanism which makes them difficult to extend.

This mechanism predates widespread use of `PhutilSymbolLoader` to discover available implementations at runtime. Runtime discovery has generally proven more flexible and easier to use than explicit selection (although it sometimes needs more UI to support it in cases where order or enabled/disabled flags can not be directly determined).

Use a modern runtime discovery mechanism instead of an explicit selector. This might break any installs which subclassed the `Selector`, but I believe almost no such installs exist, and they'll receive a meaningful exception upon upgrading (any custom engines will no longer implement all of the required methods).

Looking forward, this modernizes infrastructure to prepare for new "virtual" chunked-storage engines, with the eventual goal of supporting very large file uploads and data import into the Phacility cluster.

This uses D12051 to add UI to make it easier to understand the state of storage engines.

Test Plan:
Used new UI panel to assess storage engines:

{F336270}

  - Uploaded a small file, saw it go to MySQL engine.
  - Uploaded a larger file, saw it go to S3 engine.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5843

Differential Revision: https://secure.phabricator.com/D12053
This commit is contained in:
epriestley
2015-03-12 13:28:53 -07:00
parent 973079a7da
commit e2296a0ff7
15 changed files with 422 additions and 247 deletions

View File

@@ -0,0 +1,100 @@
<?php
final class PhabricatorFilesApplicationStorageEnginePanel
extends PhabricatorApplicationConfigurationPanel {
public function getPanelKey() {
return 'storage';
}
public function shouldShowForApplication(
PhabricatorApplication $application) {
return ($application instanceof PhabricatorFilesApplication);
}
public function buildConfigurationPagePanel() {
$viewer = $this->getViewer();
$application = $this->getApplication();
$engines = PhabricatorFileStorageEngine::loadAllEngines();
$writable_engines = PhabricatorFileStorageEngine::loadWritableEngines();
$yes = pht('Yes');
$no = pht('No');
$rows = array();
$rowc = array();
foreach ($engines as $key => $engine) {
$limited = $no;
$limit = null;
if ($engine->hasFilesizeLimit()) {
$limited = $yes;
$limit = phutil_format_bytes($engine->getFilesizeLimit());
}
if ($engine->canWriteFiles()) {
$writable = $yes;
} else {
$writable = $no;
}
if ($engine->isTestEngine()) {
$test = $yes;
} else {
$test = $no;
}
if (isset($writable_engines[$key])) {
$rowc[] = 'highlighted';
} else {
$rowc[] = null;
}
$rows[] = array(
$key,
get_class($engine),
$test,
$writable,
$limited,
$limit,
);
}
$table =
$table = id(new AphrontTableView($rows))
->setNoDataString(pht('No storage engines available.'))
->setHeaders(
array(
pht('Key'),
pht('Class'),
pht('Unit Test'),
pht('Writable'),
pht('Has Limit'),
pht('Limit'),
))
->setRowClasses($rowc)
->setColumnClasses(
array(
'',
'wide',
'',
'',
'',
'n',
));
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Storage Engines'))
->appendChild($table);
return $box;
}
public function handlePanelRequest(
AphrontRequest $request,
PhabricatorController $controller) {
return new Aphront404Response();
}
}