mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-18 02:31:10 +01:00
Almanac: forced interface PHIDs, prefix/suffix device query, DestructibleInterface
Summary: Ref T5833. Ref T6238. These are general capabilities which are particularly useful for synchronizing cluster specifications to instances. Test Plan: - Synchronized networks, devices, interfaces, services, bindings and properties to a managed instance. - Used typeahead. - Destroyed networks, devices, and services. Saw interfaces and bindings destroyed. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6238, T5833 Differential Revision: https://secure.phabricator.com/D11024
This commit is contained in:
parent
e76499bbbb
commit
340373f7bb
8 changed files with 126 additions and 12 deletions
|
@ -3052,6 +3052,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorProjectInterface',
|
||||
'PhabricatorSSHPublicKeyInterface',
|
||||
'AlmanacPropertyInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
),
|
||||
'AlmanacDeviceController' => 'AlmanacController',
|
||||
'AlmanacDeviceEditController' => 'AlmanacDeviceController',
|
||||
|
@ -3066,6 +3067,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacInterface' => array(
|
||||
'AlmanacDAO',
|
||||
'PhabricatorPolicyInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
),
|
||||
'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'AlmanacInterfaceEditController' => 'AlmanacDeviceController',
|
||||
|
@ -3083,6 +3085,7 @@ phutil_register_library_map(array(
|
|||
'AlmanacDAO',
|
||||
'PhabricatorApplicationTransactionInterface',
|
||||
'PhabricatorPolicyInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
),
|
||||
'AlmanacNetworkController' => 'AlmanacController',
|
||||
'AlmanacNetworkEditController' => 'AlmanacNetworkController',
|
||||
|
@ -3112,6 +3115,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationTransactionInterface',
|
||||
'PhabricatorProjectInterface',
|
||||
'AlmanacPropertyInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
),
|
||||
'AlmanacServiceController' => 'AlmanacController',
|
||||
'AlmanacServiceDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
|
|
|
@ -94,8 +94,13 @@ final class AlmanacDeviceEditor
|
|||
$interface
|
||||
->setNetworkPHID($new['networkPHID'])
|
||||
->setAddress($new['address'])
|
||||
->setPort((int)$new['port'])
|
||||
->save();
|
||||
->setPort((int)$new['port']);
|
||||
|
||||
if (idx($new, 'phid')) {
|
||||
$interface->setPHID($new['phid']);
|
||||
}
|
||||
|
||||
$interface->save();
|
||||
} else {
|
||||
$interface->delete();
|
||||
}
|
||||
|
@ -210,6 +215,21 @@ final class AlmanacDeviceEditor
|
|||
$xaction);
|
||||
$errors[] = $error;
|
||||
}
|
||||
|
||||
$phid = idx($new, 'phid');
|
||||
if ($phid) {
|
||||
$interface_phid_type = AlmanacInterfacePHIDType::TYPECONST;
|
||||
if (phid_get_type($phid) !== $interface_phid_type) {
|
||||
$error = new PhabricatorApplicationTransactionValidationError(
|
||||
$type,
|
||||
pht('Invalid'),
|
||||
pht(
|
||||
'Precomputed interface PHIDs must be of type '.
|
||||
'AlmanacInterfacePHIDType.'),
|
||||
$xaction);
|
||||
$errors[] = $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ final class AlmanacDeviceQuery
|
|||
private $ids;
|
||||
private $phids;
|
||||
private $names;
|
||||
private $datasourceQuery;
|
||||
private $namePrefix;
|
||||
private $nameSuffix;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
|
@ -23,8 +24,13 @@ final class AlmanacDeviceQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withDatasourceQuery($query) {
|
||||
$this->datasourceQuery = $query;
|
||||
public function withNamePrefix($prefix) {
|
||||
$this->namePrefix = $prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withNameSuffix($suffix) {
|
||||
$this->nameSuffix = $suffix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -71,11 +77,18 @@ final class AlmanacDeviceQuery
|
|||
$hashes);
|
||||
}
|
||||
|
||||
if ($this->datasourceQuery !== null) {
|
||||
if ($this->namePrefix !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'name LIKE %>',
|
||||
$this->datasourceQuery);
|
||||
$this->namePrefix);
|
||||
}
|
||||
|
||||
if ($this->nameSuffix !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'name LIKE %<',
|
||||
$this->nameSuffix);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
|
|
|
@ -8,7 +8,8 @@ final class AlmanacDevice
|
|||
PhabricatorApplicationTransactionInterface,
|
||||
PhabricatorProjectInterface,
|
||||
PhabricatorSSHPublicKeyInterface,
|
||||
AlmanacPropertyInterface {
|
||||
AlmanacPropertyInterface,
|
||||
PhabricatorDestructibleInterface {
|
||||
|
||||
protected $name;
|
||||
protected $nameIndex;
|
||||
|
@ -232,4 +233,21 @@ final class AlmanacDevice
|
|||
}
|
||||
|
||||
|
||||
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
||||
|
||||
|
||||
public function destroyObjectPermanently(
|
||||
PhabricatorDestructionEngine $engine) {
|
||||
|
||||
$interfaces = id(new AlmanacInterfaceQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withDevicePHIDs(array($this->getPHID()))
|
||||
->execute();
|
||||
foreach ($interfaces as $interface) {
|
||||
$engine->destroyObject($interface);
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
final class AlmanacInterface
|
||||
extends AlmanacDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
implements
|
||||
PhabricatorPolicyInterface,
|
||||
PhabricatorDestructibleInterface {
|
||||
|
||||
protected $devicePHID;
|
||||
protected $networkPHID;
|
||||
|
@ -109,4 +111,22 @@ final class AlmanacInterface
|
|||
return $notes;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
||||
|
||||
|
||||
public function destroyObjectPermanently(
|
||||
PhabricatorDestructionEngine $engine) {
|
||||
|
||||
$bindings = id(new AlmanacBindingQuery())
|
||||
->setViewer($this->getViewer())
|
||||
->withInterfacePHIDs(array($this->getPHID()))
|
||||
->execute();
|
||||
foreach ($bindings as $binding) {
|
||||
$engine->destroyObject($binding);
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ final class AlmanacNetwork
|
|||
extends AlmanacDAO
|
||||
implements
|
||||
PhabricatorApplicationTransactionInterface,
|
||||
PhabricatorPolicyInterface {
|
||||
PhabricatorPolicyInterface,
|
||||
PhabricatorDestructibleInterface {
|
||||
|
||||
protected $name;
|
||||
protected $mailKey;
|
||||
|
@ -94,4 +95,23 @@ final class AlmanacNetwork
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
||||
|
||||
|
||||
public function destroyObjectPermanently(
|
||||
PhabricatorDestructionEngine $engine) {
|
||||
|
||||
$interfaces = id(new AlmanacInterfaceQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withNetworkPHIDs(array($this->getPHID()))
|
||||
->execute();
|
||||
|
||||
foreach ($interfaces as $interface) {
|
||||
$engine->destroyObject($interface);
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ final class AlmanacService
|
|||
PhabricatorCustomFieldInterface,
|
||||
PhabricatorApplicationTransactionInterface,
|
||||
PhabricatorProjectInterface,
|
||||
AlmanacPropertyInterface {
|
||||
AlmanacPropertyInterface,
|
||||
PhabricatorDestructibleInterface {
|
||||
|
||||
protected $name;
|
||||
protected $nameIndex;
|
||||
|
@ -212,4 +213,22 @@ final class AlmanacService
|
|||
return $timeline;
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
||||
|
||||
|
||||
public function destroyObjectPermanently(
|
||||
PhabricatorDestructionEngine $engine) {
|
||||
|
||||
$bindings = id(new AlmanacBindingQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withServicePHIDs(array($this->getPHID()))
|
||||
->execute();
|
||||
foreach ($bindings as $binding) {
|
||||
$engine->destroyObject($binding);
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ final class AlmanacInterfaceDatasource
|
|||
|
||||
$devices = id(new AlmanacDeviceQuery())
|
||||
->setViewer($viewer)
|
||||
->withDatasourceQuery($raw_query)
|
||||
->withNamePrefix($raw_query)
|
||||
->execute();
|
||||
|
||||
if ($devices) {
|
||||
|
|
Loading…
Reference in a new issue