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 AlmanacBindingEditController
|
|
|
|
extends AlmanacServiceController {
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
if ($id) {
|
|
|
|
$binding = id(new AlmanacBindingQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$binding) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$service = $binding->getService();
|
|
|
|
$is_new = false;
|
|
|
|
|
|
|
|
$service_uri = $service->getURI();
|
|
|
|
$cancel_uri = $binding->getURI();
|
|
|
|
$title = pht('Edit Binding');
|
|
|
|
$save_button = pht('Save Changes');
|
|
|
|
} else {
|
|
|
|
$service = id(new AlmanacServiceQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($request->getStr('serviceID')))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
$binding = AlmanacBinding::initializeNewBinding($service);
|
|
|
|
$is_new = true;
|
|
|
|
|
|
|
|
$service_uri = $service->getURI();
|
|
|
|
$cancel_uri = $service_uri;
|
|
|
|
$title = pht('Create Binding');
|
|
|
|
$save_button = pht('Create Binding');
|
|
|
|
}
|
|
|
|
|
|
|
|
$v_interface = array();
|
|
|
|
if ($binding->getInterfacePHID()) {
|
|
|
|
$v_interface = array($binding->getInterfacePHID());
|
|
|
|
}
|
|
|
|
$e_interface = true;
|
|
|
|
|
|
|
|
$validation_exception = null;
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$v_interface = $request->getArr('interfacePHIDs');
|
|
|
|
|
|
|
|
$type_interface = AlmanacBindingTransaction::TYPE_INTERFACE;
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
$xactions[] = id(new AlmanacBindingTransaction())
|
|
|
|
->setTransactionType($type_interface)
|
|
|
|
->setNewValue(head($v_interface));
|
|
|
|
|
|
|
|
$editor = id(new AlmanacBindingEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$editor->applyTransactions($binding, $xactions);
|
|
|
|
|
|
|
|
$binding_uri = $binding->getURI();
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($binding_uri);
|
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
$validation_exception = $ex;
|
|
|
|
$e_interface = $ex->getShortMessage($type_interface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer)
|
2015-03-31 23:10:32 +02:00
|
|
|
->appendControl(
|
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
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setName('interfacePHIDs')
|
2015-06-09 15:06:52 +02:00
|
|
|
->setLabel(pht('Interface'))
|
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
|
|
|
->setLimit(1)
|
|
|
|
->setDatasource(new AlmanacInterfaceDatasource())
|
2015-03-31 23:10:32 +02:00
|
|
|
->setValue($v_interface)
|
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
|
|
|
->setError($e_interface))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->addCancelButton($cancel_uri)
|
|
|
|
->setValue($save_button));
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setValidationException($validation_exception)
|
|
|
|
->setHeaderText($title)
|
|
|
|
->appendChild($form);
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addTextCrumb($service->getName(), $service_uri);
|
|
|
|
if ($is_new) {
|
|
|
|
$crumbs->addTextCrumb(pht('Create Binding'));
|
|
|
|
} else {
|
|
|
|
$crumbs->addTextCrumb(pht('Edit Binding'));
|
|
|
|
}
|
|
|
|
|
2015-11-28 23:46:19 +01:00
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild(
|
|
|
|
array(
|
|
|
|
$box,
|
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
|
|
|
));
|
2015-11-28 23:46:19 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|