mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-18 18:51:12 +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',
|
'PhabricatorProjectInterface',
|
||||||
'PhabricatorSSHPublicKeyInterface',
|
'PhabricatorSSHPublicKeyInterface',
|
||||||
'AlmanacPropertyInterface',
|
'AlmanacPropertyInterface',
|
||||||
|
'PhabricatorDestructibleInterface',
|
||||||
),
|
),
|
||||||
'AlmanacDeviceController' => 'AlmanacController',
|
'AlmanacDeviceController' => 'AlmanacController',
|
||||||
'AlmanacDeviceEditController' => 'AlmanacDeviceController',
|
'AlmanacDeviceEditController' => 'AlmanacDeviceController',
|
||||||
|
@ -3066,6 +3067,7 @@ phutil_register_library_map(array(
|
||||||
'AlmanacInterface' => array(
|
'AlmanacInterface' => array(
|
||||||
'AlmanacDAO',
|
'AlmanacDAO',
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
|
'PhabricatorDestructibleInterface',
|
||||||
),
|
),
|
||||||
'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource',
|
'AlmanacInterfaceDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||||
'AlmanacInterfaceEditController' => 'AlmanacDeviceController',
|
'AlmanacInterfaceEditController' => 'AlmanacDeviceController',
|
||||||
|
@ -3083,6 +3085,7 @@ phutil_register_library_map(array(
|
||||||
'AlmanacDAO',
|
'AlmanacDAO',
|
||||||
'PhabricatorApplicationTransactionInterface',
|
'PhabricatorApplicationTransactionInterface',
|
||||||
'PhabricatorPolicyInterface',
|
'PhabricatorPolicyInterface',
|
||||||
|
'PhabricatorDestructibleInterface',
|
||||||
),
|
),
|
||||||
'AlmanacNetworkController' => 'AlmanacController',
|
'AlmanacNetworkController' => 'AlmanacController',
|
||||||
'AlmanacNetworkEditController' => 'AlmanacNetworkController',
|
'AlmanacNetworkEditController' => 'AlmanacNetworkController',
|
||||||
|
@ -3112,6 +3115,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorApplicationTransactionInterface',
|
'PhabricatorApplicationTransactionInterface',
|
||||||
'PhabricatorProjectInterface',
|
'PhabricatorProjectInterface',
|
||||||
'AlmanacPropertyInterface',
|
'AlmanacPropertyInterface',
|
||||||
|
'PhabricatorDestructibleInterface',
|
||||||
),
|
),
|
||||||
'AlmanacServiceController' => 'AlmanacController',
|
'AlmanacServiceController' => 'AlmanacController',
|
||||||
'AlmanacServiceDatasource' => 'PhabricatorTypeaheadDatasource',
|
'AlmanacServiceDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||||
|
|
|
@ -94,8 +94,13 @@ final class AlmanacDeviceEditor
|
||||||
$interface
|
$interface
|
||||||
->setNetworkPHID($new['networkPHID'])
|
->setNetworkPHID($new['networkPHID'])
|
||||||
->setAddress($new['address'])
|
->setAddress($new['address'])
|
||||||
->setPort((int)$new['port'])
|
->setPort((int)$new['port']);
|
||||||
->save();
|
|
||||||
|
if (idx($new, 'phid')) {
|
||||||
|
$interface->setPHID($new['phid']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$interface->save();
|
||||||
} else {
|
} else {
|
||||||
$interface->delete();
|
$interface->delete();
|
||||||
}
|
}
|
||||||
|
@ -210,6 +215,21 @@ final class AlmanacDeviceEditor
|
||||||
$xaction);
|
$xaction);
|
||||||
$errors[] = $error;
|
$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 $ids;
|
||||||
private $phids;
|
private $phids;
|
||||||
private $names;
|
private $names;
|
||||||
private $datasourceQuery;
|
private $namePrefix;
|
||||||
|
private $nameSuffix;
|
||||||
|
|
||||||
public function withIDs(array $ids) {
|
public function withIDs(array $ids) {
|
||||||
$this->ids = $ids;
|
$this->ids = $ids;
|
||||||
|
@ -23,8 +24,13 @@ final class AlmanacDeviceQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function withDatasourceQuery($query) {
|
public function withNamePrefix($prefix) {
|
||||||
$this->datasourceQuery = $query;
|
$this->namePrefix = $prefix;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function withNameSuffix($suffix) {
|
||||||
|
$this->nameSuffix = $suffix;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,11 +77,18 @@ final class AlmanacDeviceQuery
|
||||||
$hashes);
|
$hashes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->datasourceQuery !== null) {
|
if ($this->namePrefix !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
'name LIKE %>',
|
'name LIKE %>',
|
||||||
$this->datasourceQuery);
|
$this->namePrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->nameSuffix !== null) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'name LIKE %<',
|
||||||
|
$this->nameSuffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = $this->buildPagingClause($conn_r);
|
$where[] = $this->buildPagingClause($conn_r);
|
||||||
|
|
|
@ -8,7 +8,8 @@ final class AlmanacDevice
|
||||||
PhabricatorApplicationTransactionInterface,
|
PhabricatorApplicationTransactionInterface,
|
||||||
PhabricatorProjectInterface,
|
PhabricatorProjectInterface,
|
||||||
PhabricatorSSHPublicKeyInterface,
|
PhabricatorSSHPublicKeyInterface,
|
||||||
AlmanacPropertyInterface {
|
AlmanacPropertyInterface,
|
||||||
|
PhabricatorDestructibleInterface {
|
||||||
|
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $nameIndex;
|
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
|
final class AlmanacInterface
|
||||||
extends AlmanacDAO
|
extends AlmanacDAO
|
||||||
implements PhabricatorPolicyInterface {
|
implements
|
||||||
|
PhabricatorPolicyInterface,
|
||||||
|
PhabricatorDestructibleInterface {
|
||||||
|
|
||||||
protected $devicePHID;
|
protected $devicePHID;
|
||||||
protected $networkPHID;
|
protected $networkPHID;
|
||||||
|
@ -109,4 +111,22 @@ final class AlmanacInterface
|
||||||
return $notes;
|
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
|
extends AlmanacDAO
|
||||||
implements
|
implements
|
||||||
PhabricatorApplicationTransactionInterface,
|
PhabricatorApplicationTransactionInterface,
|
||||||
PhabricatorPolicyInterface {
|
PhabricatorPolicyInterface,
|
||||||
|
PhabricatorDestructibleInterface {
|
||||||
|
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $mailKey;
|
protected $mailKey;
|
||||||
|
@ -94,4 +95,23 @@ final class AlmanacNetwork
|
||||||
return null;
|
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,
|
PhabricatorCustomFieldInterface,
|
||||||
PhabricatorApplicationTransactionInterface,
|
PhabricatorApplicationTransactionInterface,
|
||||||
PhabricatorProjectInterface,
|
PhabricatorProjectInterface,
|
||||||
AlmanacPropertyInterface {
|
AlmanacPropertyInterface,
|
||||||
|
PhabricatorDestructibleInterface {
|
||||||
|
|
||||||
protected $name;
|
protected $name;
|
||||||
protected $nameIndex;
|
protected $nameIndex;
|
||||||
|
@ -212,4 +213,22 @@ final class AlmanacService
|
||||||
return $timeline;
|
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())
|
$devices = id(new AlmanacDeviceQuery())
|
||||||
->setViewer($viewer)
|
->setViewer($viewer)
|
||||||
->withDatasourceQuery($raw_query)
|
->withNamePrefix($raw_query)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
if ($devices) {
|
if ($devices) {
|
||||||
|
|
Loading…
Reference in a new issue