@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+112 -9
+41 -2
src/applications/diffusion/controller/DiffusionRepositoryCreateController.php
··· 20 20 // the latter two cases, we show only a few of the pages. 21 21 22 22 $repository = null; 23 + $service = null; 23 24 switch ($this->edit) { 24 25 case 'remote': 25 26 case 'policy': ··· 40 41 $this->requireApplicationCapability( 41 42 DiffusionCreateRepositoriesCapability::CAPABILITY); 42 43 44 + // Pick a random open service to allocate this repository on, if any 45 + // exist. If there are no services, we aren't in cluster mode and 46 + // will allocate locally. If there are services but none permit 47 + // allocations, we fail. 48 + $services = id(new AlmanacServiceQuery()) 49 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 50 + ->withServiceClasses( 51 + array( 52 + 'AlmanacClusterRepositoryServiceType', 53 + )) 54 + ->execute(); 55 + if ($services) { 56 + // Filter out services which do not permit new allocations. 57 + foreach ($services as $key => $possible_service) { 58 + if ($possible_service->getAlmanacPropertyValue('closed')) { 59 + unset($services[$key]); 60 + } 61 + } 62 + 63 + if (!$services) { 64 + throw new Exception( 65 + pht( 66 + 'This install is configured in cluster mode, but all '. 67 + 'available repository cluster services are closed to new '. 68 + 'allocations. At least one service must be open to allow '. 69 + 'new allocations to take place.')); 70 + } 71 + 72 + shuffle($services); 73 + $service = head($services); 74 + } 75 + 43 76 $cancel_uri = $this->getApplicationURI('new/'); 44 77 break; 45 78 default: ··· 110 143 $type_view = PhabricatorTransactions::TYPE_VIEW_POLICY; 111 144 $type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY; 112 145 $type_push = PhabricatorRepositoryTransaction::TYPE_PUSH_POLICY; 146 + $type_service = PhabricatorRepositoryTransaction::TYPE_SERVICE; 113 147 114 148 $xactions = array(); 115 149 ··· 141 175 ->getControl('activate')->getValue(); 142 176 $xactions[] = id(clone $template) 143 177 ->setTransactionType($type_activate) 144 - ->setNewValue( 145 - ($activate == 'start')); 178 + ->setNewValue(($activate == 'start')); 179 + 180 + if ($service) { 181 + $xactions[] = id(clone $template) 182 + ->setTransactionType($type_service) 183 + ->setNewValue($service->getPHID()); 184 + } 146 185 147 186 $default_local_path = PhabricatorEnv::getEnvConfig( 148 187 'repository.default-local-path');
+15
src/applications/diffusion/controller/DiffusionRepositoryEditMainController.php
··· 575 575 ->setUser($viewer) 576 576 ->setActionList($actions); 577 577 578 + $service_phid = $repository->getAlmanacServicePHID(); 579 + if ($service_phid) { 580 + $handles = $this->loadViewerHandles(array($service_phid)); 581 + $v_service = $handles[$service_phid]->renderLink(); 582 + } else { 583 + $v_service = phutil_tag( 584 + 'em', 585 + array(), 586 + pht('Local')); 587 + } 588 + 589 + $view->addProperty( 590 + pht('Storage Service'), 591 + $v_service); 592 + 578 593 $view->addProperty( 579 594 pht('Storage Path'), 580 595 $repository->getHumanReadableDetail('local-path'));
+20 -5
src/applications/diffusion/controller/DiffusionRepositoryEditStorageController.php
··· 33 33 34 34 $title = pht('Edit %s', $repository->getName()); 35 35 36 + $service_phid = $repository->getAlmanacServicePHID(); 37 + if ($service_phid) { 38 + $handles = $this->loadViewerHandles(array($service_phid)); 39 + $v_service = $handles[$service_phid]->renderLink(); 40 + } else { 41 + $v_service = phutil_tag( 42 + 'em', 43 + array(), 44 + pht('Local')); 45 + } 46 + 36 47 $form = id(new AphrontFormView()) 37 48 ->setUser($user) 49 + ->appendChild( 50 + id(new AphrontFormMarkupControl()) 51 + ->setLabel(pht('Storage Service')) 52 + ->setValue($v_service)) 53 + ->appendChild( 54 + id(new AphrontFormMarkupControl()) 55 + ->setName('local') 56 + ->setLabel(pht('Storage Path')) 57 + ->setValue($v_local)) 38 58 ->appendRemarkupInstructions( 39 59 pht( 40 60 "You can not adjust the local path for this repository from the ". ··· 42 62 " phabricator/ $ ./bin/repository edit %s --as %s --local-path ...", 43 63 $repository->getCallsign(), 44 64 $user->getUsername())) 45 - ->appendChild( 46 - id(new AphrontFormMarkupControl()) 47 - ->setName('local') 48 - ->setLabel(pht('Local Path')) 49 - ->setValue($v_local)) 50 65 ->appendChild( 51 66 id(new AphrontFormSubmitControl()) 52 67 ->addCancelButton($edit_uri, pht('Done')));
+8
src/applications/repository/editor/PhabricatorRepositoryEditor.php
··· 40 40 $types[] = PhabricatorRepositoryTransaction::TYPE_CREDENTIAL; 41 41 $types[] = PhabricatorRepositoryTransaction::TYPE_DANGEROUS; 42 42 $types[] = PhabricatorRepositoryTransaction::TYPE_CLONE_NAME; 43 + $types[] = PhabricatorRepositoryTransaction::TYPE_SERVICE; 43 44 44 45 $types[] = PhabricatorTransactions::TYPE_EDGE; 45 46 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; ··· 95 96 return $object->shouldAllowDangerousChanges(); 96 97 case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME: 97 98 return $object->getDetail('clone-name'); 99 + case PhabricatorRepositoryTransaction::TYPE_SERVICE: 100 + return $object->getAlmanacServicePHID(); 98 101 } 99 102 } 100 103 ··· 127 130 case PhabricatorRepositoryTransaction::TYPE_CREDENTIAL: 128 131 case PhabricatorRepositoryTransaction::TYPE_DANGEROUS: 129 132 case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME: 133 + case PhabricatorRepositoryTransaction::TYPE_SERVICE: 130 134 return $xaction->getNewValue(); 131 135 case PhabricatorRepositoryTransaction::TYPE_NOTIFY: 132 136 case PhabricatorRepositoryTransaction::TYPE_AUTOCLOSE: ··· 198 202 case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME: 199 203 $object->setDetail('clone-name', $xaction->getNewValue()); 200 204 return; 205 + case PhabricatorRepositoryTransaction::TYPE_SERVICE: 206 + $object->setAlmanacServicePHID($xaction->getNewValue()); 207 + return; 201 208 case PhabricatorRepositoryTransaction::TYPE_ENCODING: 202 209 // Make sure the encoding is valid by converting to UTF-8. This tests 203 210 // that the user has mbstring installed, and also that they didn't type ··· 306 313 case PhabricatorRepositoryTransaction::TYPE_CREDENTIAL: 307 314 case PhabricatorRepositoryTransaction::TYPE_DANGEROUS: 308 315 case PhabricatorRepositoryTransaction::TYPE_CLONE_NAME: 316 + case PhabricatorRepositoryTransaction::TYPE_SERVICE: 309 317 PhabricatorPolicyFilter::requireCapability( 310 318 $this->requireActor(), 311 319 $object,
+28 -2
src/applications/repository/storage/PhabricatorRepositoryTransaction.php
··· 24 24 const TYPE_CREDENTIAL = 'repo:credential'; 25 25 const TYPE_DANGEROUS = 'repo:dangerous'; 26 26 const TYPE_CLONE_NAME = 'repo:clone-name'; 27 + const TYPE_SERVICE = 'repo:service'; 27 28 28 29 // TODO: Clean up these legacy transaction types. 29 30 const TYPE_SSH_LOGIN = 'repo:ssh-login'; ··· 52 53 53 54 switch ($this->getTransactionType()) { 54 55 case self::TYPE_PUSH_POLICY: 55 - $phids[] = $old; 56 - $phids[] = $new; 56 + case self::TYPE_SERVICE: 57 + if ($old) { 58 + $phids[] = $old; 59 + } 60 + if ($new) { 61 + $phids[] = $new; 62 + } 57 63 break; 58 64 } 59 65 ··· 366 372 $this->renderHandleLink($author_phid), 367 373 $old, 368 374 $new); 375 + } 376 + case self::TYPE_SERVICE: 377 + if (strlen($old) && !strlen($new)) { 378 + return pht( 379 + '%s moved storage for this repository from %s to local.', 380 + $this->renderHandleLink($author_phid), 381 + $this->renderHandleLink($old)); 382 + } else if (!strlen($old) && strlen($new)) { 383 + // TODO: Possibly, we should distinguish between automatic assignment 384 + // on creation vs explicit adjustment. 385 + return pht( 386 + '%s set storage for this repository to %s.', 387 + $this->renderHandleLink($author_phid), 388 + $this->renderHandleLink($new)); 389 + } else { 390 + return pht( 391 + '%s moved storage for this repository from %s to %s.', 392 + $this->renderHandleLink($author_phid), 393 + $this->renderHandleLink($old), 394 + $this->renderHandleLink($new)); 369 395 } 370 396 } 371 397