Add AlmanacBinding, to bind a service to an interface
Summary: Ref T5833. Allows you to bind a service (like `db.example.com`) to one or more interfaces (for example, to specify a pool with one read/write host and two read-only hosts). You can't configure which hosts have which properties yet, but you can add all the relevant interfaces to the service. Next diff will start supporting service, binding, and device properties like "is writable", "is active", etc., so that Almanac will be able to express operations like "change which database is writable", "disable writes", "bring a device down", etc.
Test Plan: See screenshots.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5833
Differential Revision: https://secure.phabricator.com/D10745
2014-10-27 21:39:36 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AlmanacBindingEditor
|
2016-02-22 15:35:30 +01:00
|
|
|
extends AlmanacEditor {
|
Add AlmanacBinding, to bind a service to an interface
Summary: Ref T5833. Allows you to bind a service (like `db.example.com`) to one or more interfaces (for example, to specify a pool with one read/write host and two read-only hosts). You can't configure which hosts have which properties yet, but you can add all the relevant interfaces to the service. Next diff will start supporting service, binding, and device properties like "is writable", "is active", etc., so that Almanac will be able to express operations like "change which database is writable", "disable writes", "bring a device down", etc.
Test Plan: See screenshots.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5833
Differential Revision: https://secure.phabricator.com/D10745
2014-10-27 21:39:36 +01:00
|
|
|
|
2016-02-24 01:23:40 +01:00
|
|
|
private $devicePHID;
|
|
|
|
|
Add AlmanacBinding, to bind a service to an interface
Summary: Ref T5833. Allows you to bind a service (like `db.example.com`) to one or more interfaces (for example, to specify a pool with one read/write host and two read-only hosts). You can't configure which hosts have which properties yet, but you can add all the relevant interfaces to the service. Next diff will start supporting service, binding, and device properties like "is writable", "is active", etc., so that Almanac will be able to express operations like "change which database is writable", "disable writes", "bring a device down", etc.
Test Plan: See screenshots.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5833
Differential Revision: https://secure.phabricator.com/D10745
2014-10-27 21:39:36 +01:00
|
|
|
public function getEditorObjectsDescription() {
|
|
|
|
return pht('Almanac Binding');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTransactionTypes() {
|
|
|
|
$types = parent::getTransactionTypes();
|
|
|
|
|
|
|
|
$types[] = AlmanacBindingTransaction::TYPE_INTERFACE;
|
2016-02-25 12:52:41 +01:00
|
|
|
$types[] = AlmanacBindingTransaction::TYPE_DISABLE;
|
Add AlmanacBinding, to bind a service to an interface
Summary: Ref T5833. Allows you to bind a service (like `db.example.com`) to one or more interfaces (for example, to specify a pool with one read/write host and two read-only hosts). You can't configure which hosts have which properties yet, but you can add all the relevant interfaces to the service. Next diff will start supporting service, binding, and device properties like "is writable", "is active", etc., so that Almanac will be able to express operations like "change which database is writable", "disable writes", "bring a device down", etc.
Test Plan: See screenshots.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5833
Differential Revision: https://secure.phabricator.com/D10745
2014-10-27 21:39:36 +01:00
|
|
|
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomTransactionOldValue(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case AlmanacBindingTransaction::TYPE_INTERFACE:
|
|
|
|
return $object->getInterfacePHID();
|
2016-02-25 12:52:41 +01:00
|
|
|
case AlmanacBindingTransaction::TYPE_DISABLE:
|
|
|
|
return $object->getIsDisabled();
|
Add AlmanacBinding, to bind a service to an interface
Summary: Ref T5833. Allows you to bind a service (like `db.example.com`) to one or more interfaces (for example, to specify a pool with one read/write host and two read-only hosts). You can't configure which hosts have which properties yet, but you can add all the relevant interfaces to the service. Next diff will start supporting service, binding, and device properties like "is writable", "is active", etc., so that Almanac will be able to express operations like "change which database is writable", "disable writes", "bring a device down", etc.
Test Plan: See screenshots.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5833
Differential Revision: https://secure.phabricator.com/D10745
2014-10-27 21:39:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getCustomTransactionOldValue($object, $xaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomTransactionNewValue(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case AlmanacBindingTransaction::TYPE_INTERFACE:
|
|
|
|
return $xaction->getNewValue();
|
2016-02-25 12:52:41 +01:00
|
|
|
case AlmanacBindingTransaction::TYPE_DISABLE:
|
|
|
|
return (int)$xaction->getNewValue();
|
Add AlmanacBinding, to bind a service to an interface
Summary: Ref T5833. Allows you to bind a service (like `db.example.com`) to one or more interfaces (for example, to specify a pool with one read/write host and two read-only hosts). You can't configure which hosts have which properties yet, but you can add all the relevant interfaces to the service. Next diff will start supporting service, binding, and device properties like "is writable", "is active", etc., so that Almanac will be able to express operations like "change which database is writable", "disable writes", "bring a device down", etc.
Test Plan: See screenshots.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5833
Differential Revision: https://secure.phabricator.com/D10745
2014-10-27 21:39:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::getCustomTransactionNewValue($object, $xaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function applyCustomInternalTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case AlmanacBindingTransaction::TYPE_INTERFACE:
|
|
|
|
$interface = id(new AlmanacInterfaceQuery())
|
|
|
|
->setViewer($this->requireActor())
|
|
|
|
->withPHIDs(array($xaction->getNewValue()))
|
|
|
|
->executeOne();
|
|
|
|
$object->setDevicePHID($interface->getDevicePHID());
|
|
|
|
$object->setInterfacePHID($interface->getPHID());
|
|
|
|
return;
|
2016-02-25 12:52:41 +01:00
|
|
|
case AlmanacBindingTransaction::TYPE_DISABLE:
|
|
|
|
$object->setIsDisabled($xaction->getNewValue());
|
|
|
|
return;
|
Add AlmanacBinding, to bind a service to an interface
Summary: Ref T5833. Allows you to bind a service (like `db.example.com`) to one or more interfaces (for example, to specify a pool with one read/write host and two read-only hosts). You can't configure which hosts have which properties yet, but you can add all the relevant interfaces to the service. Next diff will start supporting service, binding, and device properties like "is writable", "is active", etc., so that Almanac will be able to express operations like "change which database is writable", "disable writes", "bring a device down", etc.
Test Plan: See screenshots.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5833
Differential Revision: https://secure.phabricator.com/D10745
2014-10-27 21:39:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::applyCustomInternalTransaction($object, $xaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function applyCustomExternalTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
2016-02-25 12:52:41 +01:00
|
|
|
case AlmanacBindingTransaction::TYPE_DISABLE:
|
|
|
|
return;
|
Add AlmanacBinding, to bind a service to an interface
Summary: Ref T5833. Allows you to bind a service (like `db.example.com`) to one or more interfaces (for example, to specify a pool with one read/write host and two read-only hosts). You can't configure which hosts have which properties yet, but you can add all the relevant interfaces to the service. Next diff will start supporting service, binding, and device properties like "is writable", "is active", etc., so that Almanac will be able to express operations like "change which database is writable", "disable writes", "bring a device down", etc.
Test Plan: See screenshots.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5833
Differential Revision: https://secure.phabricator.com/D10745
2014-10-27 21:39:36 +01:00
|
|
|
case AlmanacBindingTransaction::TYPE_INTERFACE:
|
2016-02-24 01:23:40 +01:00
|
|
|
$interface_phids = array();
|
|
|
|
|
|
|
|
$interface_phids[] = $xaction->getOldValue();
|
|
|
|
$interface_phids[] = $xaction->getNewValue();
|
|
|
|
|
|
|
|
$interface_phids = array_filter($interface_phids);
|
|
|
|
$interface_phids = array_unique($interface_phids);
|
|
|
|
|
|
|
|
$interfaces = id(new AlmanacInterfaceQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withPHIDs($interface_phids)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$device_phids = array();
|
|
|
|
foreach ($interfaces as $interface) {
|
|
|
|
$device_phids[] = $interface->getDevicePHID();
|
|
|
|
}
|
|
|
|
|
|
|
|
$device_phids = array_unique($device_phids);
|
|
|
|
|
|
|
|
$devices = id(new AlmanacDeviceQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withPHIDs($device_phids)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
foreach ($devices as $device) {
|
|
|
|
$device->rebuildClusterBindingStatus();
|
|
|
|
}
|
Add AlmanacBinding, to bind a service to an interface
Summary: Ref T5833. Allows you to bind a service (like `db.example.com`) to one or more interfaces (for example, to specify a pool with one read/write host and two read-only hosts). You can't configure which hosts have which properties yet, but you can add all the relevant interfaces to the service. Next diff will start supporting service, binding, and device properties like "is writable", "is active", etc., so that Almanac will be able to express operations like "change which database is writable", "disable writes", "bring a device down", etc.
Test Plan: See screenshots.
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5833
Differential Revision: https://secure.phabricator.com/D10745
2014-10-27 21:39:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::applyCustomExternalTransaction($object, $xaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function validateTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
$type,
|
|
|
|
array $xactions) {
|
|
|
|
|
|
|
|
$errors = parent::validateTransaction($object, $type, $xactions);
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case AlmanacBindingTransaction::TYPE_INTERFACE:
|
|
|
|
$missing = $this->validateIsEmptyTextField(
|
|
|
|
$object->getInterfacePHID(),
|
|
|
|
$xactions);
|
|
|
|
if ($missing) {
|
|
|
|
$error = new PhabricatorApplicationTransactionValidationError(
|
|
|
|
$type,
|
|
|
|
pht('Required'),
|
|
|
|
pht('Bindings must specify an interface.'),
|
|
|
|
nonempty(last($xactions), null));
|
|
|
|
$error->setIsMissingFieldError(true);
|
|
|
|
$errors[] = $error;
|
|
|
|
} else if ($xactions) {
|
|
|
|
foreach ($xactions as $xaction) {
|
|
|
|
$interfaces = id(new AlmanacInterfaceQuery())
|
|
|
|
->setViewer($this->requireActor())
|
|
|
|
->withPHIDs(array($xaction->getNewValue()))
|
|
|
|
->execute();
|
|
|
|
if (!$interfaces) {
|
|
|
|
$error = new PhabricatorApplicationTransactionValidationError(
|
|
|
|
$type,
|
|
|
|
pht('Invalid'),
|
|
|
|
pht(
|
|
|
|
'You can not bind a service to an invalid or restricted '.
|
|
|
|
'interface.'),
|
|
|
|
$xaction);
|
|
|
|
$errors[] = $error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$final_value = last($xactions)->getNewValue();
|
|
|
|
|
|
|
|
$binding = id(new AlmanacBindingQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withServicePHIDs(array($object->getServicePHID()))
|
|
|
|
->withInterfacePHIDs(array($final_value))
|
|
|
|
->executeOne();
|
|
|
|
if ($binding && ($binding->getID() != $object->getID())) {
|
|
|
|
$error = new PhabricatorApplicationTransactionValidationError(
|
|
|
|
$type,
|
|
|
|
pht('Already Bound'),
|
|
|
|
pht(
|
|
|
|
'You can not bind a service to the same interface multiple '.
|
|
|
|
'times.'),
|
|
|
|
last($xactions));
|
|
|
|
$errors[] = $error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|