Skip to content
This repository has been archived by the owner on Mar 19, 2022. It is now read-only.

Commit

Permalink
Redpoint custom patches
Browse files Browse the repository at this point in the history
- Harbormaster / Drydock supports Windows
- Phragment bug fixes / workarounds
- Repository build status dashboard panel
  • Loading branch information
hach-que authored and Phabricator Build Server committed Aug 27, 2016
1 parent 067d12d commit 55ded7a
Show file tree
Hide file tree
Showing 23 changed files with 1,096 additions and 28 deletions.
16 changes: 16 additions & 0 deletions src/__phutil_library_map__.php
Expand Up @@ -955,6 +955,7 @@
'DrydockDefaultViewCapability' => 'applications/drydock/capability/DrydockDefaultViewCapability.php',
'DrydockFilesystemInterface' => 'applications/drydock/interface/filesystem/DrydockFilesystemInterface.php',
'DrydockInterface' => 'applications/drydock/interface/DrydockInterface.php',
'DrydockKVMVirtualMachineShutdownException' => 'applications/drydock/exception/DrydockKVMVirtualMachineShutdownException.php',
'DrydockLandRepositoryOperation' => 'applications/drydock/operation/DrydockLandRepositoryOperation.php',
'DrydockLease' => 'applications/drydock/storage/DrydockLease.php',
'DrydockLeaseAcquiredLogType' => 'applications/drydock/logtype/DrydockLeaseAcquiredLogType.php',
Expand Down Expand Up @@ -990,6 +991,7 @@
'DrydockManagementCommandWorkflow' => 'applications/drydock/management/DrydockManagementCommandWorkflow.php',
'DrydockManagementLeaseWorkflow' => 'applications/drydock/management/DrydockManagementLeaseWorkflow.php',
'DrydockManagementReclaimWorkflow' => 'applications/drydock/management/DrydockManagementReclaimWorkflow.php',
'DrydockManagementReleaseAllResourcesWorkflow' => 'applications/drydock/management/DrydockManagementReleaseAllResourcesWorkflow.php',
'DrydockManagementReleaseLeaseWorkflow' => 'applications/drydock/management/DrydockManagementReleaseLeaseWorkflow.php',
'DrydockManagementReleaseResourceWorkflow' => 'applications/drydock/management/DrydockManagementReleaseResourceWorkflow.php',
'DrydockManagementUpdateLeaseWorkflow' => 'applications/drydock/management/DrydockManagementUpdateLeaseWorkflow.php',
Expand Down Expand Up @@ -1027,11 +1029,13 @@
'DrydockSFTPFilesystemInterface' => 'applications/drydock/interface/filesystem/DrydockSFTPFilesystemInterface.php',
'DrydockSSHCommandInterface' => 'applications/drydock/interface/command/DrydockSSHCommandInterface.php',
'DrydockSchemaSpec' => 'applications/drydock/storage/DrydockSchemaSpec.php',
'DrydockSetupCheckWinRM' => 'applications/drydock/check/DrydockSetupCheckWinRM.php',
'DrydockSlotLock' => 'applications/drydock/storage/DrydockSlotLock.php',
'DrydockSlotLockException' => 'applications/drydock/exception/DrydockSlotLockException.php',
'DrydockSlotLockFailureLogType' => 'applications/drydock/logtype/DrydockSlotLockFailureLogType.php',
'DrydockTestRepositoryOperation' => 'applications/drydock/operation/DrydockTestRepositoryOperation.php',
'DrydockWebrootInterface' => 'applications/drydock/interface/webroot/DrydockWebrootInterface.php',
'DrydockWinRMCommandInterface' => 'applications/drydock/interface/command/DrydockWinRMCommandInterface.php',
'DrydockWorker' => 'applications/drydock/worker/DrydockWorker.php',
'DrydockWorkingCopyBlueprintImplementation' => 'applications/drydock/blueprint/DrydockWorkingCopyBlueprintImplementation.php',
'FeedConduitAPIMethod' => 'applications/feed/conduit/FeedConduitAPIMethod.php',
Expand Down Expand Up @@ -1207,6 +1211,7 @@
'HarbormasterQueryBuildsConduitAPIMethod' => 'applications/harbormaster/conduit/HarbormasterQueryBuildsConduitAPIMethod.php',
'HarbormasterQueryBuildsSearchEngineAttachment' => 'applications/harbormaster/engineextension/HarbormasterQueryBuildsSearchEngineAttachment.php',
'HarbormasterRemarkupRule' => 'applications/harbormaster/remarkup/HarbormasterRemarkupRule.php',
'HarbormasterRunBuildPlanBuildImplementation' => 'applications/harbormaster/step/HarbormasterRunBuildPlanBuildImplementation.php',
'HarbormasterRunBuildPlansHeraldAction' => 'applications/harbormaster/herald/HarbormasterRunBuildPlansHeraldAction.php',
'HarbormasterSchemaSpec' => 'applications/harbormaster/storage/HarbormasterSchemaSpec.php',
'HarbormasterScratchTable' => 'applications/harbormaster/storage/HarbormasterScratchTable.php',
Expand Down Expand Up @@ -2318,6 +2323,7 @@
'PhabricatorDashboardDashboardHasPanelEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardDashboardHasPanelEdgeType.php',
'PhabricatorDashboardDashboardPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardDashboardPHIDType.php',
'PhabricatorDashboardEditController' => 'applications/dashboard/controller/PhabricatorDashboardEditController.php',
'PhabricatorDashboardHarbormasterRepositoryStatusPanelType' => 'applications/harbormaster/paneltype/PhabricatorDashboardHarbormasterRepositoryStatusPanelType.php',
'PhabricatorDashboardInstall' => 'applications/dashboard/storage/PhabricatorDashboardInstall.php',
'PhabricatorDashboardInstallController' => 'applications/dashboard/controller/PhabricatorDashboardInstallController.php',
'PhabricatorDashboardLayoutConfig' => 'applications/dashboard/layoutconfig/PhabricatorDashboardLayoutConfig.php',
Expand Down Expand Up @@ -3649,6 +3655,7 @@
'PhabricatorStandardCustomFieldRemarkup' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php',
'PhabricatorStandardCustomFieldSelect' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php',
'PhabricatorStandardCustomFieldText' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php',
'PhabricatorStandardCustomFieldTextarea' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldTextarea.php',
'PhabricatorStandardCustomFieldTokenizer' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldTokenizer.php',
'PhabricatorStandardCustomFieldUsers' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldUsers.php',
'PhabricatorStandardPageView' => 'view/page/PhabricatorStandardPageView.php',
Expand Down Expand Up @@ -4367,6 +4374,7 @@
'ReleephWorkRecordConduitAPIMethod' => 'applications/releeph/conduit/work/ReleephWorkRecordConduitAPIMethod.php',
'ReleephWorkRecordPickStatusConduitAPIMethod' => 'applications/releeph/conduit/work/ReleephWorkRecordPickStatusConduitAPIMethod.php',
'RemarkupProcessConduitAPIMethod' => 'applications/remarkup/conduit/RemarkupProcessConduitAPIMethod.php',
'RemoteTempFile' => 'applications/drydock/interface/command/RemoteTempFile.php',
'RepositoryConduitAPIMethod' => 'applications/repository/conduit/RepositoryConduitAPIMethod.php',
'RepositoryQueryConduitAPIMethod' => 'applications/repository/conduit/RepositoryQueryConduitAPIMethod.php',
'ShellLogView' => 'applications/harbormaster/view/ShellLogView.php',
Expand Down Expand Up @@ -5483,6 +5491,7 @@
'DrydockDefaultViewCapability' => 'PhabricatorPolicyCapability',
'DrydockFilesystemInterface' => 'DrydockInterface',
'DrydockInterface' => 'Phobject',
'DrydockKVMVirtualMachineShutdownException' => 'PhabricatorWorkerYieldException',
'DrydockLandRepositoryOperation' => 'DrydockRepositoryOperationType',
'DrydockLease' => array(
'DrydockDAO',
Expand Down Expand Up @@ -5524,6 +5533,7 @@
'DrydockManagementCommandWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementLeaseWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementReclaimWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementReleaseAllResourcesWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementReleaseLeaseWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementReleaseResourceWorkflow' => 'DrydockManagementWorkflow',
'DrydockManagementUpdateLeaseWorkflow' => 'DrydockManagementWorkflow',
Expand Down Expand Up @@ -5567,11 +5577,13 @@
'DrydockSFTPFilesystemInterface' => 'DrydockFilesystemInterface',
'DrydockSSHCommandInterface' => 'DrydockCommandInterface',
'DrydockSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'DrydockSetupCheckWinRM' => 'PhabricatorSetupCheck',
'DrydockSlotLock' => 'DrydockDAO',
'DrydockSlotLockException' => 'Exception',
'DrydockSlotLockFailureLogType' => 'DrydockLogType',
'DrydockTestRepositoryOperation' => 'DrydockRepositoryOperationType',
'DrydockWebrootInterface' => 'DrydockInterface',
'DrydockWinRMCommandInterface' => 'DrydockCommandInterface',
'DrydockWorker' => 'PhabricatorWorker',
'DrydockWorkingCopyBlueprintImplementation' => 'DrydockBlueprintImplementation',
'FeedConduitAPIMethod' => 'ConduitAPIMethod',
Expand Down Expand Up @@ -5796,6 +5808,7 @@
'HarbormasterQueryBuildsConduitAPIMethod' => 'HarbormasterConduitAPIMethod',
'HarbormasterQueryBuildsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
'HarbormasterRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'HarbormasterRunBuildPlanBuildImplementation' => 'HarbormasterBuildStepImplementation',
'HarbormasterRunBuildPlansHeraldAction' => 'HeraldAction',
'HarbormasterSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'HarbormasterScratchTable' => 'HarbormasterDAO',
Expand Down Expand Up @@ -7083,6 +7096,7 @@
'PhabricatorDashboardDashboardHasPanelEdgeType' => 'PhabricatorEdgeType',
'PhabricatorDashboardDashboardPHIDType' => 'PhabricatorPHIDType',
'PhabricatorDashboardEditController' => 'PhabricatorDashboardController',
'PhabricatorDashboardHarbormasterRepositoryStatusPanelType' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardInstall' => 'PhabricatorDashboardDAO',
'PhabricatorDashboardInstallController' => 'PhabricatorDashboardController',
'PhabricatorDashboardLayoutConfig' => 'Phobject',
Expand Down Expand Up @@ -8661,6 +8675,7 @@
'PhabricatorStandardCustomFieldRemarkup' => 'PhabricatorStandardCustomField',
'PhabricatorStandardCustomFieldSelect' => 'PhabricatorStandardCustomField',
'PhabricatorStandardCustomFieldText' => 'PhabricatorStandardCustomField',
'PhabricatorStandardCustomFieldTextarea' => 'PhabricatorStandardCustomField',
'PhabricatorStandardCustomFieldTokenizer' => 'PhabricatorStandardCustomFieldPHIDs',
'PhabricatorStandardCustomFieldUsers' => 'PhabricatorStandardCustomFieldTokenizer',
'PhabricatorStandardPageView' => array(
Expand Down Expand Up @@ -9555,6 +9570,7 @@
'ReleephWorkRecordConduitAPIMethod' => 'ReleephConduitAPIMethod',
'ReleephWorkRecordPickStatusConduitAPIMethod' => 'ReleephConduitAPIMethod',
'RemarkupProcessConduitAPIMethod' => 'ConduitAPIMethod',
'RemoteTempFile' => 'Phobject',
'RepositoryConduitAPIMethod' => 'ConduitAPIMethod',
'RepositoryQueryConduitAPIMethod' => 'RepositoryConduitAPIMethod',
'ShellLogView' => 'AphrontView',
Expand Down
Expand Up @@ -339,6 +339,9 @@ private function getDetailsForDataType($data_type) {
case 'ipaddress':
$column_type = 'varbinary(64)';
break;
case 'path':
$column_type = 'varbinary(254)';
break;
case 'bytes64':
$column_type = 'binary(64)';
break;
Expand Down
Expand Up @@ -158,6 +158,9 @@ public function getInterface(

switch ($type) {
case DrydockCommandInterface::INTERFACE_TYPE:
case DrydockCommandInterface::INTERFACE_TYPE.'-'.PhutilCommandString::MODE_POWERSHELL:
case DrydockCommandInterface::INTERFACE_TYPE.'-'.PhutilCommandString::MODE_WINDOWSCMD:
case DrydockCommandInterface::INTERFACE_TYPE.'-'.PhutilCommandString::MODE_BASH:
$credential_phid = $blueprint->getFieldValue('credentialPHID');
$binding_phid = $resource->getAttribute('almanacBindingPHID');

Expand All @@ -174,12 +177,54 @@ public function getInterface(

$interface = $binding->getInterface();

return id(new DrydockSSHCommandInterface())
->setConfig('credentialPHID', $credential_phid)
->setConfig('host', $interface->getAddress())
->setConfig('port', $interface->getPort());
return $this->getCommandInterfaceWithExplicitHost(
$blueprint,
$resource,
$interface,
$type);
}
}

private function getCommandInterfaceWithExplicitHost(
DrydockBlueprint $blueprint,
DrydockResource $resource,
AlmanacInterface $almanacInterface,
$type) {

$interface = new DrydockSSHCommandInterface();
if ($blueprint->getFieldValue('platform') === 'windows') {
$interface = new DrydockWinRMCommandInterface();
}

switch ($type) {
case DrydockCommandInterface::INTERFACE_TYPE:
case DrydockCommandInterface::INTERFACE_TYPE.'-'.PhutilCommandString::MODE_POWERSHELL:
$interface->setEscapingMode(PhutilCommandString::MODE_POWERSHELL);
break;
case DrydockCommandInterface::INTERFACE_TYPE.'-'.PhutilCommandString::MODE_WINDOWSCMD:
$interface->setEscapingMode(PhutilCommandString::MODE_WINDOWSCMD);
break;
case DrydockCommandInterface::INTERFACE_TYPE.'-'.PhutilCommandString::MODE_BASH:
$interface->setEscapingMode(PhutilCommandString::MODE_BASH);
break;
}

$interface
->setConfig('host', $almanacInterface->getAddress())
->setConfig('port', $almanacInterface->getPort())
->setConfig('platform', $blueprint->getFieldValue('platform'));

if ($blueprint->getFieldValue('platform') === 'windows') {
$interface
->setConfig('credentialPHID', $blueprint->getFieldValue('winrmAuthPHID'));
} else {
$interface
->setConfig('credentialPHID', $blueprint->getFieldValue('credentialPHID'));
}

return $interface;
}


protected function getCustomFieldSpecifications() {
return array(
Expand All @@ -200,6 +245,22 @@ protected function getCustomFieldSpecifications() {
'credential.type' =>
PassphraseSSHPrivateKeyTextCredentialType::CREDENTIAL_TYPE,
),
'winrmAuthPHID' => array(
'name' => pht('WinRM Credentials'),
'type' => 'credential',
'credential.provides' =>
PassphrasePasswordCredentialType::PROVIDES_TYPE,
'credential.type' =>
PassphrasePasswordCredentialType::CREDENTIAL_TYPE,
),
'platform' => array(
'name' => pht('Platform'),
'type' => 'select',
'options' => array(
'linux' => pht('Linux or other UNIX'),
'windows' => pht('Windows'),
),
),
);
}

Expand Down
Expand Up @@ -108,6 +108,18 @@ public function acquireLease(
DrydockResource $resource,
DrydockLease $lease) {

$host_lease = id(new DrydockLeaseQuery())
->setViewer(PhabricatorUser::getOmnipotentUser())
->withPHIDs(array($resource->getAttribute('host.leasePHID')))
->executeOne();
if ($host_lease === null || !$host_lease->isActive()) {
$resource->setStatus(DrydockResourceStatus::STATUS_BROKEN);
$resource->save();
$resource->scheduleUpdate();

throw new Exception('Host lease is no longer active');
}

$lease
->needSlotLock($this->getLeaseSlotLock($resource))
->acquireOnResource($resource);
Expand Down Expand Up @@ -169,7 +181,7 @@ public function activateResource(

// TODO: Make this configurable.
$resource_id = $resource->getID();
$root = "/var/drydock/workingcopy-{$resource_id}";
$root = $blueprint->getFieldValue('path')."/workingcopy-{$resource_id}";

$map = $resource->getAttribute('repositories.map');

Expand All @@ -182,6 +194,7 @@ public function activateResource(
$path = "{$root}/repo/{$directory}/";

// TODO: Run these in parallel?
$interface->enableConnectionDebugging();
$interface->execx(
'git clone -- %s %s',
(string)$repository->getCloneURIObject(),
Expand All @@ -193,6 +206,16 @@ public function activateResource(
->activateResource();
}


public function getFieldSpecifications() {
return parent::getFieldSpecifications() + array(
'path' => array(
'name' => pht('Storage Path'),
'type' => 'text',
),
);
}

public function destroyResource(
DrydockBlueprint $blueprint,
DrydockResource $resource) {
Expand All @@ -209,14 +232,30 @@ public function destroyResource(
$lease->releaseOnDestruction();

if ($lease->isActive()) {
// Destroy the working copy on disk.
$command_type = DrydockCommandInterface::INTERFACE_TYPE;
$interface = $lease->getInterface($command_type);

$root_key = 'workingcopy.root';
$root = $resource->getAttribute($root_key);
if (strlen($root)) {
$interface->execx('rm -rf -- %s', $root);
if ($lease->getResource()->getAttribute('platform') === 'windows') {
// Destroy the working copy on disk.
$command_type = DrydockCommandInterface::INTERFACE_TYPE.'-'.PhutilCommandString::MODE_POWERSHELL;
$interface = $lease->getInterface($command_type);

$root_key = 'workingcopy.root';
$root = $resource->getAttribute($root_key);
if (strlen($root)) {
try {
$interface->execx('rm -Recurse -Force %s', $root);
} catch (Exception $ex) {
// Ignore for now.
}
}
} else {
// Destroy the working copy on disk.
$command_type = DrydockCommandInterface::INTERFACE_TYPE;
$interface = $lease->getInterface($command_type);

$root_key = 'workingcopy.root';
$root = $resource->getAttribute($root_key);
if (strlen($root)) {
$interface->execx('rm -rf -- %s', $root);
}
}
}
}
Expand Down Expand Up @@ -247,8 +286,9 @@ public function activateLease(
$cmd = array();
$arg = array();

$cmd[] = 'git clean -d --force';
$cmd[] = 'git clean -x -d --force --force';
$cmd[] = 'git fetch';
$cmd[] = 'git fetch origin refs/temp/*:refs/temp/*';

$commit = idx($spec, 'commit');
$branch = idx($spec, 'branch');
Expand All @@ -270,7 +310,7 @@ public function activateLease(
$arg[] = $branch;
}

$this->execxv($interface, $cmd, $arg);
$this->execxv($host_lease, $interface, $cmd, $arg);

if (idx($spec, 'default')) {
$default = $directory;
Expand All @@ -294,7 +334,7 @@ public function activateLease(
$arg[] = $ref_ref;

try {
$this->execxv($interface, $cmd, $arg);
$this->execxv($host_lease, $interface, $cmd, $arg);
} catch (CommandException $ex) {
$display_command = csprintf(
'git fetch %R %R',
Expand Down Expand Up @@ -365,6 +405,9 @@ public function getInterface(

switch ($type) {
case DrydockCommandInterface::INTERFACE_TYPE:
case DrydockCommandInterface::INTERFACE_TYPE.'-'.PhutilCommandString::MODE_POWERSHELL:
case DrydockCommandInterface::INTERFACE_TYPE.'-'.PhutilCommandString::MODE_WINDOWSCMD:
case DrydockCommandInterface::INTERFACE_TYPE.'-'.PhutilCommandString::MODE_BASH:
$host_lease = $this->loadHostLease($resource);
$command_interface = $host_lease->getInterface($type);

Expand Down Expand Up @@ -505,11 +548,17 @@ public function getCommandError(DrydockLease $lease) {
}

private function execxv(
DrydockLease $host_lease,
DrydockCommandInterface $interface,
array $commands,
array $arguments) {

$commands = implode(' && ', $commands);
if ($host_lease->getResource()->getBlueprint()->getFieldValue('platform') === 'windows') {
$commands = implode('; if ($LastExitCode -ne 0) { exit 1; };', $commands);
} else {
$commands = implode(' && ', $commands);
}

$argv = array_merge(array($commands), $arguments);

return call_user_func_array(array($interface, 'execx'), $argv);
Expand Down

0 comments on commit 55ded7a

Please sign in to comment.