Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15576969
D13522.id32690.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13522.id32690.diff
View Options
Index: src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php
===================================================================
--- src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php
+++ src/applications/drydock/blueprint/DrydockAmazonEC2HostBlueprintImplementation.php
@@ -804,6 +804,115 @@
}
}
+ $resource->setAttribute(
+ 'aws-status',
+ pht('Waiting for lease path to appear'));
+ $resource->save();
+
+ $last_attempt = PhabricatorTime::getNow();
+
+ while (true) {
+ try {
+ $last_attempt = PhabricatorTime::getNow();
+
+ $this->log(pht(
+ 'Attempting to check lease path \'%s\' exists on \'%s\'',
+ $this->getDetail('storage-path'),
+ $instance_id));
+
+ $ssh_future = $ssh->getExecFuture(
+ 'ls "%s"',
+ $this->getDetail('storage-path'));
+ $ssh_future->resolvex();
+ if ($ssh_future->getWasKilledByTimeout()) {
+ throw new Exception(pht('%s execution timed out.', $protocol_name));
+ }
+
+ break;
+ } catch (Exception $ex) {
+
+ // Make sure the instance hasn't been terminated or shutdown while
+ // we've been trying to connect.
+ $result = $this->getAWSEC2Future()
+ ->setRawAWSQuery(
+ 'DescribeInstances',
+ array(
+ 'InstanceId.0' => $instance_id,
+ ))
+ ->resolve();
+
+ $reservation = $result->reservationSet->item[0];
+ $instance = $reservation->instancesSet->item[0];
+ $instance_state = (string)$instance->instanceState->name;
+
+ $this->log(pht(
+ 'Lease storage path "%s" not yet ready; instance is in '.
+ 'state \'%s\'',
+ $this->getDetail('storage-path'),
+ $instance_state));
+
+ if ($instance_state === 'shutting-down' ||
+ $instance_state === 'terminated') {
+
+ $this->log(pht(
+ 'Instance has ended up in state \'%s\' while waiting for lease '.
+ 'storage path to appear',
+ $instance_state));
+
+ // Deallocate and release the public IP address if we allocated one.
+ if ($resource->getAttribute('eip-allocated')) {
+ try {
+ $this->getAWSEC2Future()
+ ->setRawAWSQuery(
+ 'DisassociateAddress',
+ array(
+ 'AssociationId' =>
+ $resource->getAttribute('eip-association-id'),
+ ))
+ ->resolve();
+ } catch (PhutilAWSException $ex) {}
+
+ try {
+ $this->getAWSEC2Future()
+ ->setRawAWSQuery(
+ 'ReleaseAddress',
+ array(
+ 'AllocationId' =>
+ $resource->getAttribute('eip-allocation-id'),
+ ))
+ ->resolve();
+ } catch (PhutilAWSException $ex) {}
+
+ $resource->setAttribute(
+ 'eip-status',
+ 'Released');
+ $resource->save();
+ }
+
+ $resource->setAttribute(
+ 'aws-status',
+ 'Terminated');
+ $resource->save();
+
+ throw new Exception(
+ 'Allocated instance, but ended up in unexpected state \''.
+ $instance_state.'\'!');
+ } else {
+ $check_time = PhabricatorTime::getNow() - $last_attempt;
+ if ($check_time < 60) {
+ $this->log(pht(
+ '%s connection returned too quickly, manually sleeping '.
+ 'for %d seconds to avoid a large number of AWS calls.',
+ $protocol_name,
+ $check_time));
+ sleep($check_time);
+ }
+ }
+
+ continue;
+ }
+ }
+
// Update the resource into open status.
$resource->setStatus(DrydockResourceStatus::STATUS_OPEN);
$resource->setAttribute(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, May 7, 11:35 AM (35 m, 39 s ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7719966
Default Alt Text
D13522.id32690.diff (3 KB)
Attached To
Mode
D13522: [drydock/aws] Check for the presence of the storage path before finalizing allocation
Attached
Detach File
Event Timeline
Log In to Comment