From d8cd3b4058627620dab728ead0d3d21276c174f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sun, 1 Jan 2017 01:33:34 -0300 Subject: [PATCH] [Nostromo] Revert RuntimeInterface --- src/Mage/Command/AbstractCommand.php | 8 +- src/Mage/Command/BuiltIn/DeployCommand.php | 12 +- src/Mage/Runtime/Runtime.php | 32 +-- src/Mage/Runtime/RuntimeInterface.php | 234 --------------------- src/Mage/Task/AbstractTask.php | 8 +- src/Mage/Task/TaskFactory.php | 8 +- src/Mage/Tests/Runtime/RuntimeMockup.php | 3 +- src/Mage/Utils.php | 12 +- 8 files changed, 44 insertions(+), 273 deletions(-) delete mode 100644 src/Mage/Runtime/RuntimeInterface.php diff --git a/src/Mage/Command/AbstractCommand.php b/src/Mage/Command/AbstractCommand.php index 7be29d3..7a1ea7d 100644 --- a/src/Mage/Command/AbstractCommand.php +++ b/src/Mage/Command/AbstractCommand.php @@ -10,7 +10,7 @@ namespace Mage\Command; -use Mage\Runtime\RuntimeInterface; +use Mage\Runtime\Runtime; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; use Symfony\Component\Console\Command\Command; @@ -23,17 +23,17 @@ use Symfony\Component\Console\Command\Command; abstract class AbstractCommand extends Command { /** - * @var RuntimeInterface Current Runtime instance + * @var Runtime Current Runtime instance */ protected $runtime; /** * Set the Runtime configuration * - * @param RuntimeInterface $runtime Runtime container + * @param Runtime $runtime Runtime container * @return AbstractCommand */ - public function setRuntime(RuntimeInterface $runtime) + public function setRuntime(Runtime $runtime) { $this->runtime = $runtime; diff --git a/src/Mage/Command/BuiltIn/DeployCommand.php b/src/Mage/Command/BuiltIn/DeployCommand.php index 5a10e0f..368d8a0 100644 --- a/src/Mage/Command/BuiltIn/DeployCommand.php +++ b/src/Mage/Command/BuiltIn/DeployCommand.php @@ -13,7 +13,7 @@ namespace Mage\Command\BuiltIn; use Mage\Runtime\Exception\DeploymentException; use Mage\Runtime\Exception\InvalidEnvironmentException; use Mage\Runtime\Exception\RuntimeException; -use Mage\Runtime\RuntimeInterface; +use Mage\Runtime\Runtime; use Mage\Task\ErrorException; use Mage\Task\ExecuteOnRollbackInterface; use Mage\Task\AbstractTask; @@ -105,7 +105,7 @@ class DeployCommand extends AbstractCommand protected function runDeployment(OutputInterface $output) { // Run Pre Deploy Tasks - $this->runtime->setStage(RuntimeInterface::PRE_DEPLOY); + $this->runtime->setStage(Runtime::PRE_DEPLOY); $preDeployTasks = $this->runtime->getTasks(); if ($this->runtime->getEnvironmentConfig('branch', false) && !$this->runtime->inRollback()) { @@ -130,7 +130,7 @@ class DeployCommand extends AbstractCommand $output->writeln(' No hosts defined, skipping On Deploy tasks'); $output->writeln(''); } else { - $this->runtime->setStage(RuntimeInterface::ON_DEPLOY); + $this->runtime->setStage(Runtime::ON_DEPLOY); $onDeployTasks = $this->runtime->getTasks(); if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) { @@ -164,7 +164,7 @@ class DeployCommand extends AbstractCommand $output->writeln(' No hosts defined, skipping On Release tasks'); $output->writeln(''); } else { - $this->runtime->setStage(RuntimeInterface::ON_RELEASE); + $this->runtime->setStage(Runtime::ON_RELEASE); $onReleaseTasks = $this->runtime->getTasks(); if ($this->runtime->getEnvironmentConfig('releases', false)) { @@ -188,7 +188,7 @@ class DeployCommand extends AbstractCommand $output->writeln(' No hosts defined, skipping Post Release tasks'); $output->writeln(''); } else { - $this->runtime->setStage(RuntimeInterface::POST_RELEASE); + $this->runtime->setStage(Runtime::POST_RELEASE); $postReleaseTasks = $this->runtime->getTasks(); if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) { @@ -207,7 +207,7 @@ class DeployCommand extends AbstractCommand } // Run Post Deploy Tasks - $this->runtime->setStage(RuntimeInterface::POST_DEPLOY); + $this->runtime->setStage(Runtime::POST_DEPLOY); $postDeployTasks = $this->runtime->getTasks(); if ($this->runtime->getEnvironmentConfig('releases', false) && !$this->runtime->inRollback()) { if (!in_array('deploy/targz/cleanup', $postDeployTasks)) { diff --git a/src/Mage/Runtime/Runtime.php b/src/Mage/Runtime/Runtime.php index 0f9f371..5de34de 100644 --- a/src/Mage/Runtime/Runtime.php +++ b/src/Mage/Runtime/Runtime.php @@ -20,8 +20,14 @@ use Mage\Runtime\Exception\InvalidEnvironmentException; * * @author Andrés Montañez */ -class Runtime implements RuntimeInterface +class Runtime { + const PRE_DEPLOY = 'pre-deploy'; + const ON_DEPLOY = 'on-deploy'; + const POST_DEPLOY = 'post-deploy'; + const ON_RELEASE = 'on-release'; + const POST_RELEASE = 'post-release'; + /** * @var array Magallanes configuration */ @@ -65,7 +71,7 @@ class Runtime implements RuntimeInterface /** * Generate the Release ID * - * @return RuntimeInterface + * @return Runtime */ public function generateReleaseId() { @@ -77,7 +83,7 @@ class Runtime implements RuntimeInterface * Sets the Release ID * * @param string $releaseId Release ID - * @return RuntimeInterface + * @return Runtime */ public function setReleaseId($releaseId) { @@ -99,7 +105,7 @@ class Runtime implements RuntimeInterface * Sets the Runtime in Rollback mode On or Off * * @param bool $inRollback - * @return RuntimeInterface + * @return Runtime */ public function setRollback($inRollback) { @@ -122,7 +128,7 @@ class Runtime implements RuntimeInterface * * @param mixed $key Variable name * @param mixed $value Variable value - * @return RuntimeInterface + * @return Runtime */ public function setVar($key, $value) { @@ -150,7 +156,7 @@ class Runtime implements RuntimeInterface * Sets the Logger instance * * @param LoggerInterface $logger Logger instance - * @return RuntimeInterface + * @return Runtime */ public function setLogger(LoggerInterface $logger = null) { @@ -162,7 +168,7 @@ class Runtime implements RuntimeInterface * Sets the Magallanes Configuration to the Runtime * * @param array $configuration Configuration - * @return RuntimeInterface + * @return Runtime */ public function setConfiguration($configuration) { @@ -228,7 +234,7 @@ class Runtime implements RuntimeInterface * Sets the working Environment * * @param string $environment Environment name - * @return RuntimeInterface + * @return Runtime * @throws InvalidEnvironmentException */ public function setEnvironment($environment) @@ -255,7 +261,7 @@ class Runtime implements RuntimeInterface * Sets the working stage * * @param string $stage Stage code - * @return RuntimeInterface + * @return Runtime */ public function setStage($stage) { @@ -295,7 +301,7 @@ class Runtime implements RuntimeInterface * Sets the working Host * * @param string $host Host name - * @return RuntimeInterface + * @return Runtime */ public function setWorkingHost($host) { @@ -336,9 +342,9 @@ class Runtime implements RuntimeInterface public function runCommand($cmd, $timeout = 120) { switch ($this->getStage()) { - case RuntimeInterface::ON_DEPLOY: - case RuntimeInterface::ON_RELEASE: - case RuntimeInterface::POST_RELEASE: + case self::ON_DEPLOY: + case self::ON_RELEASE: + case self::POST_RELEASE: return $this->runRemoteCommand($cmd, true, $timeout); break; default: diff --git a/src/Mage/Runtime/RuntimeInterface.php b/src/Mage/Runtime/RuntimeInterface.php deleted file mode 100644 index 9814ad5..0000000 --- a/src/Mage/Runtime/RuntimeInterface.php +++ /dev/null @@ -1,234 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Mage\Runtime; - -use Psr\Log\LoggerInterface; -use Psr\Log\LogLevel; -use Symfony\Component\Process\Process; -use Mage\Runtime\Exception\InvalidEnvironmentException; - -/** - * Interface for the Runtime container - * - * @author Andrés Montañez - */ -interface RuntimeInterface -{ - const PRE_DEPLOY = 'pre-deploy'; - const ON_DEPLOY = 'on-deploy'; - const POST_DEPLOY = 'post-deploy'; - const ON_RELEASE = 'on-release'; - const POST_RELEASE = 'post-release'; - - /** - * Generate the Release ID - * - * @return RuntimeInterface - */ - public function generateReleaseId(); - - /** - * Sets the Release ID - * - * @param string $releaseId Release ID - * @return RuntimeInterface - */ - public function setReleaseId($releaseId); - - /** - * Retrieve the current Release ID - * - * @return null|string Release ID - */ - public function getReleaseId(); - - /** - * Sets the Runtime in Rollback mode On or Off - * - * @param bool $inRollback - * @return RuntimeInterface - */ - public function setRollback($inRollback); - - /** - * Indicates if Runtime is in rollback - * - * @return bool - */ - public function inRollback(); - - /** - * Sets a value in the Vars bag - * - * @param mixed $key Variable name - * @param mixed $value Variable value - * @return RuntimeInterface - */ - public function setVar($key, $value); - - /** - * Retrieve a value from the Vars bag - * - * @param mixed $key Variable name - * @param mixed $default Variable default value, returned if not found - * @return mixed - */ - public function getVar($key, $default = null); - - /** - * Sets the Logger instance - * - * @param LoggerInterface $logger Logger instance - * @return RuntimeInterface - */ - public function setLogger(LoggerInterface $logger = null); - - /** - * Sets the Magallanes Configuration to the Runtime - * - * @param array $configuration Configuration - * @return RuntimeInterface - */ - public function setConfiguration($configuration); - - /** - * Retrieve the Configuration - * - * @return array - */ - public function getConfiguration(); - - /** - * Retrieves the Configuration options for a specific section in the configuration - * - * @param mixed $key Section name - * @param mixed $default Default value - * @return mixed - */ - public function getConfigOptions($key, $default = null); - - /** - * Returns the configuration for the current Environment - * If $key is provided, it will be returned only that section, if not found the default value will be returned, - * if $key is not provided, the whole Environment's configuration will be returned - * - * @param mixed $key Section name - * @param mixed $default Default value - * @return mixed - * @throws InvalidEnvironmentException - */ - public function getEnvironmentConfig($key = null, $default = null); - - /** - * Sets the working Environment - * - * @param string $environment Environment name - * @return RuntimeInterface - * @throws InvalidEnvironmentException - */ - public function setEnvironment($environment); - - /** - * Returns the current working Environment - * - * @return null|string - */ - public function getEnvironment(); - - /** - * Sets the working stage - * - * @param string $stage Stage code - * @return RuntimeInterface - */ - public function setStage($stage); - - /** - * Retrieve the current wokring Stage - * - * @return string - */ - public function getStage(); - - /** - * Retrieve the defined Tasks for the current Environment and Stage - * - * @return array - * @throws InvalidEnvironmentException - */ - public function getTasks(); - - /** - * Sets the working Host - * - * @param string $host Host name - * @return RuntimeInterface - */ - public function setWorkingHost($host); - - /** - * Retrieve the working Host - * - * @return null|string - */ - public function getWorkingHost(); - - /** - * Logs a Message into the Logger - * - * @param string $message Log message - * @param string $level Log Level - */ - public function log($message, $level = LogLevel::DEBUG); - - /** - * Executes a command, it will be run Locally or Remotely based on the working Stage - * - * @param string $cmd Command to execute - * @param int $timeout Seconds to wait - * @return Process - */ - public function runCommand($cmd, $timeout = 120); - - /** - * Execute a command locally - * - * @param string $cmd Command to execute - * @param int $timeout Seconds to wait - * @return Process - */ - public function runLocalCommand($cmd, $timeout = 120); - - /** - * Executes a command remotely, if jail is true, it will run inside the Host Path and the Release (if available) - * - * @param string $cmd Command to execute - * @param bool $jail Jail the command - * @param int $timeout Seconds to wait - * @return Process - * @throws InvalidEnvironmentException - */ - public function runRemoteCommand($cmd, $jail = true, $timeout = 120); - - /** - * Get the SSH configuration based on the environment - * - * @return array - */ - public function getSSHConfig(); - - /** - * Gets a Temporal File name - * - * @return string - */ - public function getTempFile(); -} diff --git a/src/Mage/Task/AbstractTask.php b/src/Mage/Task/AbstractTask.php index 6cad351..0ee7c2f 100644 --- a/src/Mage/Task/AbstractTask.php +++ b/src/Mage/Task/AbstractTask.php @@ -10,7 +10,7 @@ namespace Mage\Task; -use Mage\Runtime\RuntimeInterface; +use Mage\Runtime\Runtime; /** * Abstract base class for Magallanes Tasks @@ -25,7 +25,7 @@ abstract class AbstractTask protected $options = []; /** - * @var RuntimeInterface + * @var Runtime */ protected $runtime; @@ -68,10 +68,10 @@ abstract class AbstractTask /** * Set the Runtime instance * - * @param RuntimeInterface $runtime + * @param Runtime $runtime * @return AbstractTask */ - public function setRuntime(RuntimeInterface $runtime) + public function setRuntime(Runtime $runtime) { $this->runtime = $runtime; return $this; diff --git a/src/Mage/Task/TaskFactory.php b/src/Mage/Task/TaskFactory.php index e046436..d1d7af4 100644 --- a/src/Mage/Task/TaskFactory.php +++ b/src/Mage/Task/TaskFactory.php @@ -10,7 +10,7 @@ namespace Mage\Task; -use Mage\Runtime\RuntimeInterface; +use Mage\Runtime\Runtime; use Mage\Runtime\Exception\RuntimeException; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; @@ -23,7 +23,7 @@ use Symfony\Component\Finder\SplFileInfo; class TaskFactory { /** - * @var RuntimeInterface + * @var Runtime */ protected $runtime; @@ -35,9 +35,9 @@ class TaskFactory /** * Constructor * - * @param RuntimeInterface $runtime + * @param Runtime $runtime */ - public function __construct(RuntimeInterface $runtime) + public function __construct(Runtime $runtime) { $this->runtime = $runtime; $this->loadBuiltInTasks(); diff --git a/src/Mage/Tests/Runtime/RuntimeMockup.php b/src/Mage/Tests/Runtime/RuntimeMockup.php index aa82305..b80a4c0 100644 --- a/src/Mage/Tests/Runtime/RuntimeMockup.php +++ b/src/Mage/Tests/Runtime/RuntimeMockup.php @@ -2,7 +2,6 @@ namespace Mage\Tests\Runtime; use Mage\Runtime\Runtime; -use Mage\Runtime\RuntimeInterface; use Symfony\Component\Process\Process; class RuntimeMockup extends Runtime @@ -17,7 +16,7 @@ class RuntimeMockup extends Runtime /** * Generate the Release ID * - * @return RuntimeInterface + * @return Runtime */ public function generateReleaseId() { diff --git a/src/Mage/Utils.php b/src/Mage/Utils.php index 6c1bd9a..e82dc44 100644 --- a/src/Mage/Utils.php +++ b/src/Mage/Utils.php @@ -10,7 +10,7 @@ namespace Mage; -use Mage\Runtime\RuntimeInterface; +use Mage\Runtime\Runtime; use DateTime; /** @@ -29,23 +29,23 @@ class Utils public static function getStageName($stage) { switch ($stage) { - case RuntimeInterface::PRE_DEPLOY: + case Runtime::PRE_DEPLOY: return 'Pre Deployment'; break; - case RuntimeInterface::ON_DEPLOY: + case Runtime::ON_DEPLOY: return 'On Deployment'; break; - case RuntimeInterface::POST_DEPLOY: + case Runtime::POST_DEPLOY: return 'Post Deployment'; break; - case RuntimeInterface::ON_RELEASE: + case Runtime::ON_RELEASE: return 'On Release'; break; - case RuntimeInterface::POST_RELEASE: + case Runtime::POST_RELEASE: return 'Post Release'; break; }