2014-10-17 05:01:57 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AlmanacServiceViewController
|
|
|
|
extends AlmanacServiceController {
|
|
|
|
|
|
|
|
public function shouldAllowPublic() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
|
|
|
|
$name = $request->getURIData('name');
|
|
|
|
|
|
|
|
$service = id(new AlmanacServiceQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withNames(array($name))
|
|
|
|
->executeOne();
|
|
|
|
if (!$service) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$title = pht('Service %s', $service->getName());
|
|
|
|
|
|
|
|
$property_list = $this->buildPropertyList($service);
|
|
|
|
$action_list = $this->buildActionList($service);
|
|
|
|
$property_list->setActionList($action_list);
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setHeader($service->getName())
|
|
|
|
->setPolicyObject($service);
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->addPropertyList($property_list);
|
|
|
|
|
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 13:39:36 -07:00
|
|
|
$bindings = $this->buildBindingList($service);
|
|
|
|
|
2014-10-17 05:01:57 -07:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addTextCrumb($service->getName());
|
|
|
|
|
Transactions - deploy buildTransactionTimeline against a few more applications
Summary:
Ref T4712. Thus far, it seems that most "non-standard" things can be done pretty easily in the controller. Aside from deploying, this diff had to fix a few bugs / missing implementations of stuff.
(Notably, PhabricatorAuthProviderConfig, HeraldRule, PhabricatorSlowvotePoll, and AlmanacNetwork needed to implement PhabricatorApplicationTransactionInterface, PhabricatorAuthAuthProviderPHIDType had to be added, and a rendering bug in transactions of type PhabricatorOAuth2AuthProvider had to be fixed.)
Test Plan: Almanac - looked at binding, device, network, and service view controllers and verified timeline displayed properly. Herald - looked at a rule and verified timeline. Slowvote - looked at a vote and verified timeline. Auth - looked at an auth provider (Facebook) and verified proper display of transactions within timeline.
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T4712
Differential Revision: https://secure.phabricator.com/D10921
2014-12-02 14:33:59 -08:00
|
|
|
$timeline = $this->buildTransactionTimeline(
|
|
|
|
$service,
|
|
|
|
new AlmanacServiceTransactionQuery());
|
|
|
|
$timeline->setShouldTerminate(true);
|
2014-10-17 05:01:57 -07:00
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$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 13:39:36 -07:00
|
|
|
$bindings,
|
Give Almanac generic, custom-field-based properties
Summary:
Ref T5833. Currently, we have an `AlmanacDeviceProperty`, but it doesn't use CustomFields and is specific to devices. Make this more generic:
- Reuse most of the CustomField infrastructure (so we can eventually get easy support for nice editor UIs, etc).
- Make properties more generic so Services, Bindings and Devices can all have them.
The major difference between this implementation and existing CustomField implementations is that all other implementations are application-authoritative: the application code determines what the available list of fields is.
I want Almanac to be a bit more freeform (basically: you can write whatever properties you want, and we'll put nice UIs on them if we have a nice UI available). For example, we might have some sort of "ServiceTemplate" that says "a database binding should usually have the fields 'writable', 'active', 'credential'", which would do things like offer these as options and put a nice UI on them, but you should also be able to write whatever other properties you want and add services without building a specific service template for them.
This involves a little bit of rule bending, but ends up pretty clean. We can adjust CustomField to accommodate this a bit more gracefully later on if it makes sense.
Test Plan: {F229172}
Reviewers: btrahan
Reviewed By: btrahan
Subscribers: epriestley
Maniphest Tasks: T5833
Differential Revision: https://secure.phabricator.com/D10777
2014-11-05 15:27:16 -08:00
|
|
|
$this->buildAlmanacPropertiesTable($service),
|
Transactions - deploy buildTransactionTimeline against a few more applications
Summary:
Ref T4712. Thus far, it seems that most "non-standard" things can be done pretty easily in the controller. Aside from deploying, this diff had to fix a few bugs / missing implementations of stuff.
(Notably, PhabricatorAuthProviderConfig, HeraldRule, PhabricatorSlowvotePoll, and AlmanacNetwork needed to implement PhabricatorApplicationTransactionInterface, PhabricatorAuthAuthProviderPHIDType had to be added, and a rendering bug in transactions of type PhabricatorOAuth2AuthProvider had to be fixed.)
Test Plan: Almanac - looked at binding, device, network, and service view controllers and verified timeline displayed properly. Herald - looked at a rule and verified timeline. Slowvote - looked at a vote and verified timeline. Auth - looked at an auth provider (Facebook) and verified proper display of transactions within timeline.
Reviewers: epriestley
Reviewed By: epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T4712
Differential Revision: https://secure.phabricator.com/D10921
2014-12-02 14:33:59 -08:00
|
|
|
$timeline,
|
2014-10-17 05:01:57 -07:00
|
|
|
),
|
|
|
|
array(
|
|
|
|
'title' => $title,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildPropertyList(AlmanacService $service) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
|
|
|
|
$properties = id(new PHUIPropertyListView())
|
2014-11-05 15:30:00 -08:00
|
|
|
->setUser($viewer)
|
|
|
|
->setObject($service);
|
2014-10-17 05:01:57 -07:00
|
|
|
|
2014-12-17 11:10:27 -08:00
|
|
|
$properties->addProperty(
|
|
|
|
pht('Service Type'),
|
|
|
|
$service->getServiceType()->getServiceTypeShortName());
|
|
|
|
|
2014-10-17 05:01:57 -07:00
|
|
|
return $properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildActionList(AlmanacService $service) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$id = $service->getID();
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$service,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$actions = id(new PhabricatorActionListView())
|
|
|
|
->setUser($viewer);
|
|
|
|
|
|
|
|
$actions->addAction(
|
|
|
|
id(new PhabricatorActionView())
|
|
|
|
->setIcon('fa-pencil')
|
|
|
|
->setName(pht('Edit Service'))
|
|
|
|
->setHref($this->getApplicationURI("service/edit/{$id}/"))
|
|
|
|
->setWorkflow(!$can_edit)
|
|
|
|
->setDisabled(!$can_edit));
|
|
|
|
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
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 13:39:36 -07:00
|
|
|
private function buildBindingList(AlmanacService $service) {
|
|
|
|
$viewer = $this->getViewer();
|
|
|
|
$id = $service->getID();
|
|
|
|
|
|
|
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
|
|
|
$viewer,
|
|
|
|
$service,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT);
|
|
|
|
|
|
|
|
$bindings = id(new AlmanacBindingQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withServicePHIDs(array($service->getPHID()))
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$phids = array();
|
|
|
|
foreach ($bindings as $binding) {
|
|
|
|
$phids[] = $binding->getServicePHID();
|
|
|
|
$phids[] = $binding->getDevicePHID();
|
|
|
|
$phids[] = $binding->getInterface()->getNetworkPHID();
|
|
|
|
}
|
|
|
|
$handles = $this->loadViewerHandles($phids);
|
|
|
|
|
|
|
|
$table = id(new AlmanacBindingTableView())
|
|
|
|
->setNoDataString(
|
|
|
|
pht('This service has not been bound to any device interfaces yet.'))
|
|
|
|
->setUser($viewer)
|
|
|
|
->setBindings($bindings)
|
|
|
|
->setHandles($handles);
|
|
|
|
|
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('Service Bindings'))
|
|
|
|
->addActionLink(
|
|
|
|
id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setHref($this->getApplicationURI("binding/edit/?serviceID={$id}"))
|
|
|
|
->setWorkflow(!$can_edit)
|
|
|
|
->setDisabled(!$can_edit)
|
|
|
|
->setText(pht('Add Binding'))
|
|
|
|
->setIcon(
|
|
|
|
id(new PHUIIconView())
|
|
|
|
->setIconFont('fa-plus')));
|
|
|
|
|
|
|
|
return id(new PHUIObjectBoxView())
|
|
|
|
->setHeader($header)
|
|
|
|
->appendChild($table);
|
|
|
|
}
|
|
|
|
|
2014-10-17 05:01:57 -07:00
|
|
|
}
|