/** * Sequentially execute the stages for each node, so first all nodes will go through the initialize stage and * then the next stage will be executed until the final stage is reached and the workflow is finished. * * A rollback will be done for all nodes as long as the stage switch was not completed. * * @param Deployment $deployment * @return void */ public function run(Deployment $deployment) { parent::run($deployment); $nodes = $deployment->getNodes(); foreach ($this->stages as $stage) { $deployment->getLogger()->log('====== Stage ' . $stage . ' ======', LOG_DEBUG); foreach ($nodes as $node) { $deployment->getLogger()->log('**** Node ' . $node->getName() . ' ****', LOG_DEBUG); foreach ($deployment->getApplications() as $application) { if (!$application->hasNode($node)) { continue; } $deployment->getLogger()->log('* Application ' . $application->getName() . ' *', LOG_DEBUG); try { $this->executeStage($stage, $node, $application, $deployment); } catch (\Exception $exception) { $deployment->setStatus(Deployment::STATUS_FAILED); if ($this->enableRollback) { if (array_search($stage, $this->stages) <= array_search('switch', $this->stages)) { $deployment->getLogger()->log('Got exception "' . $exception->getMessage() . '" rolling back.', LOG_ERR); $this->taskManager->rollback(); } else { $deployment->getLogger()->log('Got exception "' . $exception->getMessage() . '" but after switch stage, no rollback necessary.', LOG_ERR); $this->taskManager->reset(); } } else { $deployment->getLogger()->log('Got exception "' . $exception->getMessage() . '" but rollback disabled. Stopping.', LOG_ERR); } return; } } } } if ($deployment->getStatus() === Deployment::STATUS_UNKNOWN) { $deployment->setStatus(Deployment::STATUS_SUCCESS); } }
/** * Simulate this deployment without executing tasks * * @return void */ public function simulate() { $this->setDryRun(TRUE); $this->logger->log('Simulating ' . $this->name); $this->workflow->run($this); }