@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.

Allow "bin/drydock lease" to acquire many identical leases with "--count N"

Summary: Ref T13676. This makes it easier to create resource pressure without juggling a big pile of terminals.

Test Plan: Used `bin/drydock lease --count 5 ...` to acquire 5 leases.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13676

Differential Revision: https://secure.phabricator.com/D21800

+88 -46
+88 -46
src/applications/drydock/management/DrydockManagementLeaseWorkflow.php
··· 26 26 'JSON file with lease attributes. Use "-" to read attributes '. 27 27 'from stdin.'), 28 28 ), 29 + array( 30 + 'name' => 'count', 31 + 'param' => 'N', 32 + 'default' => 1, 33 + 'help' => pht('Lease a given number of identical resources.'), 34 + ), 29 35 )); 30 36 } 31 37 ··· 33 39 $viewer = $this->getViewer(); 34 40 35 41 $resource_type = $args->getArg('type'); 36 - if (!$resource_type) { 42 + if (!phutil_nonempty_string($resource_type)) { 37 43 throw new PhutilArgumentUsageException( 38 44 pht( 39 - 'Specify a resource type with `%s`.', 40 - '--type')); 45 + 'Specify a resource type with "--type".')); 41 46 } 42 47 43 48 $until = $args->getArg('until'); ··· 46 51 if ($until <= 0) { 47 52 throw new PhutilArgumentUsageException( 48 53 pht( 49 - 'Unable to parse argument to "%s".', 50 - '--until')); 54 + 'Unable to parse argument to "--until".')); 51 55 } 52 56 } 53 57 58 + $count = $args->getArgAsInteger('count'); 59 + if ($count < 1) { 60 + throw new PhutilArgumentUsageException( 61 + pht( 62 + 'Value provided to "--count" must be a nonzero, positive '. 63 + 'number.')); 64 + } 65 + 54 66 $attributes_file = $args->getArg('attributes'); 55 67 if (phutil_nonempty_string($attributes_file)) { 56 68 if ($attributes_file == '-') { 57 69 echo tsprintf( 58 70 "%s\n", 59 - 'Reading JSON attributes from stdin...'); 71 + pht('Reading JSON attributes from stdin...')); 60 72 $data = file_get_contents('php://stdin'); 61 73 } else { 62 74 $data = Filesystem::readFile($attributes_file); ··· 67 79 $attributes = array(); 68 80 } 69 81 70 - $lease = id(new DrydockLease()) 71 - ->setResourceType($resource_type); 82 + $leases = array(); 83 + for ($idx = 0; $idx < $count; $idx++) { 84 + $lease = id(new DrydockLease()) 85 + ->setResourceType($resource_type); 72 86 73 - $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID(); 74 - $lease->setAuthorizingPHID($drydock_phid); 87 + $drydock_phid = id(new PhabricatorDrydockApplication())->getPHID(); 88 + $lease->setAuthorizingPHID($drydock_phid); 75 89 76 - if ($attributes) { 77 - $lease->setAttributes($attributes); 78 - } 90 + if ($attributes) { 91 + $lease->setAttributes($attributes); 92 + } 79 93 80 - // TODO: This is not hugely scalable, although this is a debugging workflow 81 - // so maybe it's fine. Do we even need `bin/drydock lease` in the long run? 82 - $all_blueprints = id(new DrydockBlueprintQuery()) 83 - ->setViewer($viewer) 84 - ->execute(); 85 - $allowed_phids = mpull($all_blueprints, 'getPHID'); 86 - if (!$allowed_phids) { 87 - throw new Exception( 88 - pht( 89 - 'No blueprints exist which can plausibly allocate resources to '. 90 - 'satisfy the requested lease.')); 91 - } 92 - $lease->setAllowedBlueprintPHIDs($allowed_phids); 94 + // TODO: This is not hugely scalable, although this is a debugging 95 + // workflow so maybe it's fine. Do we even need `bin/drydock lease` in 96 + // the long run? 97 + $all_blueprints = id(new DrydockBlueprintQuery()) 98 + ->setViewer($viewer) 99 + ->execute(); 100 + $allowed_phids = mpull($all_blueprints, 'getPHID'); 101 + if (!$allowed_phids) { 102 + throw new Exception( 103 + pht( 104 + 'No blueprints exist which can plausibly allocate resources to '. 105 + 'satisfy the requested lease.')); 106 + } 107 + $lease->setAllowedBlueprintPHIDs($allowed_phids); 93 108 94 - if ($until) { 95 - $lease->setUntil($until); 109 + if ($until) { 110 + $lease->setUntil($until); 111 + } 112 + 113 + // If something fatals or the user interrupts the process (for example, 114 + // with "^C"), release the lease. We'll cancel this below, if the lease 115 + // actually activates. 116 + $lease->setReleaseOnDestruction(true); 117 + 118 + $leases[] = $lease; 96 119 } 97 - 98 - // If something fatals or the user interrupts the process (for example, 99 - // with "^C"), release the lease. We'll cancel this below, if the lease 100 - // actually activates. 101 - $lease->setReleaseOnDestruction(true); 102 120 103 121 // TODO: This would probably be better handled with PhutilSignalRouter, 104 122 // but it currently doesn't route SIGINT. We're initializing it to setup ··· 107 125 pcntl_signal(SIGINT, array($this, 'didReceiveInterrupt')); 108 126 109 127 $t_start = microtime(true); 110 - $lease->queueForActivation(); 128 + 129 + 130 + echo tsprintf( 131 + "%s\n\n", 132 + pht('Leases queued for activation:')); 133 + 134 + foreach ($leases as $lease) { 135 + $lease->queueForActivation(); 136 + 137 + echo tsprintf( 138 + " __%s__\n", 139 + PhabricatorEnv::getProductionURI($lease->getURI())); 140 + } 111 141 112 142 echo tsprintf( 113 - "%s\n\n __%s__\n\n%s\n", 114 - pht('Queued lease for activation:'), 115 - PhabricatorEnv::getProductionURI($lease->getURI()), 116 - pht('Waiting for daemons to activate lease...')); 143 + "\n%s\n\n", 144 + pht('Waiting for daemons to activate leases...')); 117 145 118 - $this->waitUntilActive($lease); 146 + foreach ($leases as $lease) { 147 + $this->waitUntilActive($lease); 148 + } 119 149 120 150 // Now that we've survived activation and the lease is good, make it 121 151 // durable. 122 - $lease->setReleaseOnDestruction(false); 152 + foreach ($leases as $lease) { 153 + $lease->setReleaseOnDestruction(false); 154 + } 155 + 123 156 $t_end = microtime(true); 124 157 125 158 echo tsprintf( 126 - "%s\n\n %s\n\n%s\n", 159 + "\n%s\n\n", 127 160 pht( 128 - 'Activation complete. This lease is permanent until manually '. 129 - 'released with:'), 130 - pht('$ ./bin/drydock release-lease --id %d', $lease->getID()), 161 + 'Activation complete. Leases are permanent until manually '. 162 + 'released with:')); 163 + 164 + foreach ($leases as $lease) { 165 + echo tsprintf( 166 + " %s\n", 167 + pht('$ ./bin/drydock release-lease --id %d', $lease->getID())); 168 + } 169 + 170 + echo tsprintf( 171 + "\n%s\n", 131 172 pht( 132 - 'Lease activated in %sms.', 173 + 'Leases activated in %sms.', 133 174 new PhutilNumber((int)(($t_end - $t_start) * 1000)))); 134 175 135 176 return 0; ··· 183 224 } 184 225 185 226 echo tsprintf( 186 - "<%s> %B\n", 227 + "(Lease #%d) <%s> %B\n", 228 + $lease->getID(), 187 229 $type, 188 230 $data); 189 231 }