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 AlmanacBindingViewController
|
|
|
|
extends AlmanacServiceController {
|
|
|
|
|
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
|
|
|
|
$binding = id(new AlmanacBindingQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
|
|
|
->executeOne();
|
|
|
|
if (!$binding) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$service = $binding->getService();
|
|
|
|
$service_uri = $service->getURI();
|
|
|
|
|
|
|
|
$title = pht('Binding %s', $binding->getID());
|
|
|
|
|
|
|
|
$property_list = $this->buildPropertyList($binding);
|
|
|
|
$action_list = $this->buildActionList($binding);
|
|
|
|
$property_list->setActionList($action_list);
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setHeader($title)
|
|
|
|
->setPolicyObject($binding);
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->addPropertyList($property_list);
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addTextCrumb($service->getName(), $service_uri);
|
|
|
|
$crumbs->addTextCrumb($title);
|
|
|
|
|
|
|
|
$xactions = id(new AlmanacBindingTransactionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withObjectPHIDs(array($binding->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$xaction_view = id(new PhabricatorApplicationTransactionView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setObjectPHID($binding->getPHID())
|
|
|
|
->setTransactions($xactions)
|
|
|
|
->setShouldTerminate(true);
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$box,
|
2014-11-06 00:28:36 +01:00
|
|
|
$this->buildAlmanacPropertiesTable($binding),
|
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
|
|
|
$xaction_view,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertyList(AlmanacBinding $binding) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$properties = id(new PHUIPropertyListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$handles = $this->loadViewerHandles(
|
|
|
|
array(
|
|
|
|
$binding->getServicePHID(),
|
|
|
|
$binding->getDevicePHID(),
|
|
|
|
$binding->getInterface()->getNetworkPHID(),
|
|
|
|
));
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Service'),
|
|
|
|
$handles[$binding->getServicePHID()]->renderLink());
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Device'),
|
|
|
|
$handles[$binding->getDevicePHID()]->renderLink());
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Network'),
|
|
|
|
$handles[$binding->getInterface()->getNetworkPHID()]->renderLink());
|
|
|
|
|
|
|
|
$properties->addProperty(
|
|
|
|
pht('Interface'),
|
|
|
|
$binding->getInterface()->renderDisplayAddress());
|
|
|
|
|
|
|
|
return $properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildActionList(AlmanacBinding $binding) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$id = $binding->getID();
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$binding,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('fa-pencil')
|
|
|
|
->setName(pht('Edit Binding'))
|
|
|
|
->setHref($this->getApplicationURI("binding/edit/{$id}/"))
|
|
|
|
->setWorkflow(!$can_edit)
|
|
|
|
->setDisabled(!$can_edit));
|
|
|
|
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|