Differential D21796 Diff 51965 src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | public function allocateResource( | ||||
$host_lease = $this->newLease($blueprint) | $host_lease = $this->newLease($blueprint) | ||||
->setResourceType('host') | ->setResourceType('host') | ||||
->setOwnerPHID($resource_phid) | ->setOwnerPHID($resource_phid) | ||||
->setAttribute('workingcopy.resourcePHID', $resource_phid) | ->setAttribute('workingcopy.resourcePHID', $resource_phid) | ||||
->setAllowedBlueprintPHIDs($blueprint_phids); | ->setAllowedBlueprintPHIDs($blueprint_phids); | ||||
$resource->setAttribute('host.leasePHID', $host_lease->getPHID()); | $resource->setAttribute('host.leasePHID', $host_lease->getPHID()); | ||||
$map = $lease->getAttribute('repositories.map'); | $map = $this->getWorkingCopyRepositoryMap($lease); | ||||
foreach ($map as $key => $value) { | |||||
$map[$key] = array_select_keys( | |||||
$value, | |||||
array( | |||||
'phid', | |||||
)); | |||||
} | |||||
$resource->setAttribute('repositories.map', $map); | $resource->setAttribute('repositories.map', $map); | ||||
$slot_lock = $this->getConcurrentResourceLimitSlotLock($blueprint); | $slot_lock = $this->getConcurrentResourceLimitSlotLock($blueprint); | ||||
if ($slot_lock !== null) { | if ($slot_lock !== null) { | ||||
$resource->needSlotLock($slot_lock); | $resource->needSlotLock($slot_lock); | ||||
} | } | ||||
$resource->allocateResource(); | $resource->allocateResource(); | ||||
$host_lease->queueForActivation(); | $host_lease->queueForActivation(); | ||||
return $resource; | return $resource; | ||||
} | } | ||||
private function getWorkingCopyRepositoryMap(DrydockLease $lease) { | |||||
$attribute = 'repositories.map'; | |||||
$map = $lease->getAttribute($attribute); | |||||
// TODO: Leases should validate their attributes more formally. | |||||
if (!is_array($map) || !$map) { | |||||
$message = array(); | |||||
if ($map === null) { | |||||
$message[] = pht( | |||||
'Working copy lease is missing required attribute "%s".', | |||||
$attribute); | |||||
} else { | |||||
$message[] = pht( | |||||
'Working copy lease has invalid attribute "%s".', | |||||
$attribute); | |||||
} | |||||
$message[] = pht( | |||||
'Attribute "repositories.map" should be a map of repository '. | |||||
'specifications.'); | |||||
$message = implode("\n\n", $message); | |||||
throw new Exception($message); | |||||
} | |||||
foreach ($map as $key => $value) { | |||||
$map[$key] = array_select_keys( | |||||
$value, | |||||
array( | |||||
'phid', | |||||
)); | |||||
} | |||||
return $map; | |||||
} | |||||
public function activateResource( | public function activateResource( | ||||
DrydockBlueprint $blueprint, | DrydockBlueprint $blueprint, | ||||
DrydockResource $resource) { | DrydockResource $resource) { | ||||
$lease = $this->loadHostLease($resource); | $lease = $this->loadHostLease($resource); | ||||
$this->requireActiveLease($lease); | $this->requireActiveLease($lease); | ||||
$command_type = DrydockCommandInterface::INTERFACE_TYPE; | $command_type = DrydockCommandInterface::INTERFACE_TYPE; | ||||
▲ Show 20 Lines • Show All 375 Lines • Show Last 20 Lines |