1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

When repository services are available, use them when creating a new repository

Summary:
Ref T2783. When creating a new repository, test for cluster services. If cluster services are available, allocate on a random open service.

Show the service that repositories are allocated on.

Test Plan: Created a new repository, saw it allocate onto an available cluster service.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2783

Differential Revision: https://secure.phabricator.com/D11003
This commit is contained in:
epriestley 2014-12-18 14:31:22 -08:00
parent 10f2cfec5b
commit cd6f67ef95
5 changed files with 112 additions and 9 deletions

View file

@ -20,6 +20,7 @@ final class DiffusionRepositoryCreateController
// the latter two cases, we show only a few of the pages. // the latter two cases, we show only a few of the pages.
$repository = null; $repository = null;
$service = null;
switch ($this->edit) { switch ($this->edit) {
case 'remote': case 'remote':
case 'policy': case 'policy':
@ -40,6 +41,38 @@ final class DiffusionRepositoryCreateController
$this->requireApplicationCapability( $this->requireApplicationCapability(
DiffusionCreateRepositoriesCapability::CAPABILITY); DiffusionCreateRepositoriesCapability::CAPABILITY);
// Pick a random open service to allocate this repository on, if any
// exist. If there are no services, we aren't in cluster mode and
// will allocate locally. If there are services but none permit
// allocations, we fail.
$services = id(new AlmanacServiceQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withServiceClasses(
array(
'AlmanacClusterRepositoryServiceType',
))
->execute();
if ($services) {
// Filter out services which do not permit new allocations.
foreach ($services as $key => $possible_service) {
if ($possible_service->getAlmanacPropertyValue('closed')) {
unset($services[$key]);
}
}
if (!$services) {
throw new Exception(
pht(
'This install is configured in cluster mode, but all '.
'available repository cluster services are closed to new '.
'allocations. At least one service must be open to allow '.
'new allocations to take place.'));
}
shuffle($services);
$service = head($services);
}
$cancel_uri = $this->getApplicationURI('new/'); $cancel_uri = $this->getApplicationURI('new/');
break; break;
default: default:
@ -110,6 +143,7 @@ final class DiffusionRepositoryCreateController
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
$type_push = PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY; $type_push = PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY;
$type_service = PhabricatorRepositoryTransaction::TYPE_SERVICE;
$xactions = array(); $xactions = array();
@ -141,8 +175,13 @@ final class DiffusionRepositoryCreateController
->getControl('activate')->getValue(); ->getControl('activate')->getValue();
$xactions[] = id(clone $template) $xactions[] = id(clone $template)
->setTransactionType($type_activate) ->setTransactionType($type_activate)
->setNewValue( ->setNewValue(($activate == 'start'));
($activate == 'start'));
if ($service) {
$xactions[] = id(clone $template)
->setTransactionType($type_service)
->setNewValue($service->getPHID());
}
$default_local_path = PhabricatorEnv::getEnvConfig( $default_local_path = PhabricatorEnv::getEnvConfig(
'repository.default-local-path'); 'repository.default-local-path');

View file

@ -575,6 +575,21 @@ final class DiffusionRepositoryEditMainController
->setUser($viewer) ->setUser($viewer)
->setActionList($actions); ->setActionList($actions);
$service_phid = $repository->getAlmanacServicePHID();
if ($service_phid) {
$handles = $this->loadViewerHandles(array($service_phid));
$v_service = $handles[$service_phid]->renderLink();
} else {
$v_service = phutil_tag(
'em',
array(),
pht('Local'));
}
$view->addProperty(
pht('Storage Service'),
$v_service);
$view->addProperty( $view->addProperty(
pht('Storage Path'), pht('Storage Path'),
$repository->getHumanReadableDetail('local-path')); $repository->getHumanReadableDetail('local-path'));

View file

@ -33,8 +33,28 @@ final class DiffusionRepositoryEditStorageController
$title = pht('Edit %s', $repository->getName()); $title = pht('Edit %s', $repository->getName());
$service_phid = $repository->getAlmanacServicePHID();
if ($service_phid) {
$handles = $this->loadViewerHandles(array($service_phid));
$v_service = $handles[$service_phid]->renderLink();
} else {
$v_service = phutil_tag(
'em',
array(),
pht('Local'));
}
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($user) ->setUser($user)
->appendChild(
id(new AphrontFormMarkupControl())
->setLabel(pht('Storage Service'))
->setValue($v_service))
->appendChild(
id(new AphrontFormMarkupControl())
->setName('local')
->setLabel(pht('Storage Path'))
->setValue($v_local))
->appendRemarkupInstructions( ->appendRemarkupInstructions(
pht( pht(
"You can not adjust the local path for this repository from the ". "You can not adjust the local path for this repository from the ".
@ -42,11 +62,6 @@ final class DiffusionRepositoryEditStorageController
" phabricator/ $ ./bin/repository edit %s --as %s --local-path ...", " phabricator/ $ ./bin/repository edit %s --as %s --local-path ...",
$repository->getCallsign(), $repository->getCallsign(),
$user->getUsername())) $user->getUsername()))
->appendChild(
id(new AphrontFormMarkupControl())
->setName('local')
->setLabel(pht('Local Path'))
->setValue($v_local))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->addCancelButton($edit_uri, pht('Done'))); ->addCancelButton($edit_uri, pht('Done')));

View file

@ -40,6 +40,7 @@ final class PhabricatorRepositoryEditor
$types[] = PhabricatorRepositoryTransaction::TYPE_CREDENTIAL; $types[] = PhabricatorRepositoryTransaction::TYPE_CREDENTIAL;
$types[] = PhabricatorRepositoryTransaction::TYPE_DANGEROUS; $types[] = PhabricatorRepositoryTransaction::TYPE_DANGEROUS;
$types[] = PhabricatorRepositoryTransaction::TYPE_CLONE_NAME; $types[] = PhabricatorRepositoryTransaction::TYPE_CLONE_NAME;
$types[] = PhabricatorRepositoryTransaction::TYPE_SERVICE;
$types[] = PhabricatorTransactions::TYPE_EDGE; $types[] = PhabricatorTransactions::TYPE_EDGE;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
@ -95,6 +96,8 @@ final class PhabricatorRepositoryEditor
return $object->shouldAllowDangerousChanges(); return $object->shouldAllowDangerousChanges();
case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME: case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME:
return $object->getDetail('clone-name'); return $object->getDetail('clone-name');
case PhabricatorRepositoryTransaction::TYPE_SERVICE:
return $object->getAlmanacServicePHID();
} }
} }
@ -127,6 +130,7 @@ final class PhabricatorRepositoryEditor
case PhabricatorRepositoryTransaction::TYPE_CREDENTIAL: case PhabricatorRepositoryTransaction::TYPE_CREDENTIAL:
case PhabricatorRepositoryTransaction::TYPE_DANGEROUS: case PhabricatorRepositoryTransaction::TYPE_DANGEROUS:
case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME: case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME:
case PhabricatorRepositoryTransaction::TYPE_SERVICE:
return $xaction->getNewValue(); return $xaction->getNewValue();
case PhabricatorRepositoryTransaction::TYPE_NOTIFY: case PhabricatorRepositoryTransaction::TYPE_NOTIFY:
case PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE: case PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE:
@ -198,6 +202,9 @@ final class PhabricatorRepositoryEditor
case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME: case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME:
$object->setDetail('clone-name', $xaction->getNewValue()); $object->setDetail('clone-name', $xaction->getNewValue());
return; return;
case PhabricatorRepositoryTransaction::TYPE_SERVICE:
$object->setAlmanacServicePHID($xaction->getNewValue());
return;
case PhabricatorRepositoryTransaction::TYPE_ENCODING: case PhabricatorRepositoryTransaction::TYPE_ENCODING:
// Make sure the encoding is valid by converting to UTF-8. This tests // Make sure the encoding is valid by converting to UTF-8. This tests
// that the user has mbstring installed, and also that they didn't type // that the user has mbstring installed, and also that they didn't type
@ -306,6 +313,7 @@ final class PhabricatorRepositoryEditor
case PhabricatorRepositoryTransaction::TYPE_CREDENTIAL: case PhabricatorRepositoryTransaction::TYPE_CREDENTIAL:
case PhabricatorRepositoryTransaction::TYPE_DANGEROUS: case PhabricatorRepositoryTransaction::TYPE_DANGEROUS:
case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME: case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME:
case PhabricatorRepositoryTransaction::TYPE_SERVICE:
PhabricatorPolicyFilter::requireCapability( PhabricatorPolicyFilter::requireCapability(
$this->requireActor(), $this->requireActor(),
$object, $object,

View file

@ -24,6 +24,7 @@ final class PhabricatorRepositoryTransaction
const TYPE_CREDENTIAL = 'repo:credential'; const TYPE_CREDENTIAL = 'repo:credential';
const TYPE_DANGEROUS = 'repo:dangerous'; const TYPE_DANGEROUS = 'repo:dangerous';
const TYPE_CLONE_NAME = 'repo:clone-name'; const TYPE_CLONE_NAME = 'repo:clone-name';
const TYPE_SERVICE = 'repo:service';
// TODO: Clean up these legacy transaction types. // TODO: Clean up these legacy transaction types.
const TYPE_SSH_LOGIN = 'repo:ssh-login'; const TYPE_SSH_LOGIN = 'repo:ssh-login';
@ -52,8 +53,13 @@ final class PhabricatorRepositoryTransaction
switch ($this->getTransactionType()) { switch ($this->getTransactionType()) {
case self::TYPE_PUSH_POLICY: case self::TYPE_PUSH_POLICY:
$phids[] = $old; case self::TYPE_SERVICE:
$phids[] = $new; if ($old) {
$phids[] = $old;
}
if ($new) {
$phids[] = $new;
}
break; break;
} }
@ -367,6 +373,26 @@ final class PhabricatorRepositoryTransaction
$old, $old,
$new); $new);
} }
case self::TYPE_SERVICE:
if (strlen($old) && !strlen($new)) {
return pht(
'%s moved storage for this repository from %s to local.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($old));
} else if (!strlen($old) && strlen($new)) {
// TODO: Possibly, we should distinguish between automatic assignment
// on creation vs explicit adjustment.
return pht(
'%s set storage for this repository to %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($new));
} else {
return pht(
'%s moved storage for this repository from %s to %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($old),
$this->renderHandleLink($new));
}
} }
return parent::getTitle(); return parent::getTitle();