/**
  * {@inheritdoc}
  */
 public function install($version, $stage = null)
 {
     $successfulInstall = true;
     $hosts = $this->configuration->getHosts();
     if ($stage !== null) {
         $hosts = $this->configuration->getHostsByStage($stage);
     }
     foreach ($hosts as $host) {
         $exception = null;
         $title = new Title($this->logger->getOutput(), sprintf('Installing release "%s" to "%s":', $version, $host->getHostname()));
         $title->render();
         try {
             $this->eventDispatcher->dispatch(AccompliEvents::CREATE_CONNECTION, new HostEvent($host));
             $workspaceEvent = new WorkspaceEvent($host);
             $this->eventDispatcher->dispatch(AccompliEvents::PREPARE_WORKSPACE, $workspaceEvent);
             $workspace = $workspaceEvent->getWorkspace();
             if ($workspace instanceof Workspace) {
                 $prepareReleaseEvent = new PrepareReleaseEvent($workspace, $version);
                 $this->eventDispatcher->dispatch(AccompliEvents::PREPARE_RELEASE, $prepareReleaseEvent);
                 $release = $prepareReleaseEvent->getRelease();
                 if ($release instanceof Release) {
                     $installReleaseEvent = new InstallReleaseEvent($release);
                     $this->eventDispatcher->dispatch(AccompliEvents::INSTALL_RELEASE, $installReleaseEvent);
                     $this->eventDispatcher->dispatch(AccompliEvents::INSTALL_RELEASE_COMPLETE, $installReleaseEvent);
                     continue;
                 }
             }
         } catch (Exception $exception) {
         }
         $successfulInstall = false;
         $failedEvent = new FailedEvent($this->eventDispatcher->getLastDispatchedEventName(), $this->eventDispatcher->getLastDispatchedEvent(), $exception);
         $this->eventDispatcher->dispatch(AccompliEvents::INSTALL_RELEASE_FAILED, $failedEvent);
     }
     return $successfulInstall;
 }
 /**
  * {@inheritdoc}
  */
 public function deploy($version, $stage)
 {
     $successfulDeploy = true;
     $hosts = $this->configuration->getHostsByStage($stage);
     foreach ($hosts as $host) {
         $exception = null;
         $deployEventName = AccompliEvents::DEPLOY_RELEASE;
         $deployCompleteEventName = AccompliEvents::DEPLOY_RELEASE_COMPLETE;
         $deployFailedEventName = AccompliEvents::DEPLOY_RELEASE_FAILED;
         $title = new Title($this->logger->getOutput(), sprintf('Deploying release "%s" to "%s":', $version, $host->getHostname()));
         $title->render();
         try {
             $this->eventDispatcher->dispatch(AccompliEvents::CREATE_CONNECTION, new HostEvent($host));
             $workspaceEvent = new WorkspaceEvent($host);
             $this->eventDispatcher->dispatch(AccompliEvents::GET_WORKSPACE, $workspaceEvent);
             $workspace = $workspaceEvent->getWorkspace();
             if ($workspace instanceof Workspace) {
                 $prepareDeployReleaseEvent = new PrepareDeployReleaseEvent($workspace, $version);
                 $this->eventDispatcher->dispatch(AccompliEvents::PREPARE_DEPLOY_RELEASE, $prepareDeployReleaseEvent);
                 $release = $prepareDeployReleaseEvent->getRelease();
                 if ($release instanceof Release) {
                     $currentRelease = $prepareDeployReleaseEvent->getCurrentRelease();
                     if ($currentRelease instanceof Release && Comparator::lessThan($release->getVersion(), $currentRelease->getVersion())) {
                         $deployEventName = AccompliEvents::ROLLBACK_RELEASE;
                         $deployCompleteEventName = AccompliEvents::ROLLBACK_RELEASE_COMPLETE;
                         $deployFailedEventName = AccompliEvents::ROLLBACK_RELEASE_FAILED;
                     }
                     $deployReleaseEvent = new DeployReleaseEvent($release, $currentRelease);
                     $this->eventDispatcher->dispatch($deployEventName, $deployReleaseEvent);
                     $this->eventDispatcher->dispatch($deployCompleteEventName, $deployReleaseEvent);
                     continue;
                 }
                 throw new RuntimeException(sprintf('No task configured to initialize release version "%s" for deployment.', $version));
             }
             throw new RuntimeException('No task configured to initialize the workspace.');
         } catch (Exception $exception) {
         }
         $successfulDeploy = false;
         $failedEvent = new FailedEvent($this->eventDispatcher->getLastDispatchedEventName(), $this->eventDispatcher->getLastDispatchedEvent(), $exception);
         $this->eventDispatcher->dispatch($deployFailedEventName, $failedEvent);
     }
     return $successfulDeploy;
 }
Example #3
0
 /**
  * Constructs a new TitleBlock instance.
  *
  * @param OutputInterface $output
  * @param string          $message
  * @param string          $style
  */
 public function __construct(OutputInterface $output, $message, $style)
 {
     parent::__construct($output, $message);
     $this->style = $style;
 }