Ejemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = $this->get('config');
     $projectName = $config->get('[project][name]');
     $services = $config->get('[project][public_services]');
     $em = $this->get('entity_manager');
     $projectRepository = $em->getRepository('Mindgruve\\Gruver\\Entity\\Project');
     $serviceRepository = $em->getRepository('Mindgruve\\Gruver\\Entity\\Service');
     $project = $projectRepository->loadProjectByName($projectName);
     if (!$project) {
         $output->writeln('<info>Adding PROJECT: ' . $projectName);
         $project = new Project();
         $project->setName($projectName);
         $project->setStatus(StatusInterface::STATUS_ENABLED);
         $em->persist($project);
         $em->flush();
     }
     foreach ($services as $item) {
         $serviceName = $item['name'];
         $hosts = $item['hosts'];
         $ports = $item['ports'];
         $haproxyBackend = isset($item['haproxy_append']['backend']) ? implode("\n    ", $item['haproxy_append']['backend']) : '';
         /**
          * @todo open up so more flexible
          */
         if ($hosts == array()) {
             throw new \Exception('Each service must have a host right now');
         }
         if ($ports != array(80)) {
             throw new \Exception('Only port 80 is supported right now');
         }
         $service = $serviceRepository->findOneBy(array('name' => $serviceName, 'project' => $project));
         if (!$service) {
             $output->writeln('<info>Adding SERVICE: ' . $serviceName);
             $service = new Service();
             $service->setStatus(StatusInterface::STATUS_ENABLED);
             if ($ports != array(80)) {
                 throw new \Exception('Only port 80 is supported at this time.');
             }
             $service->setName($serviceName);
             $service->setProject($project);
             $project->addService($service);
             $em->persist($service);
         }
         if ($service->getPublicHosts() != $hosts) {
             $service->setPublicHosts($hosts);
             $output->writeln('<info>Modifying hosts for SERVICE: ' . $serviceName . '</info>');
         }
         if ($service->getPublicPorts() != $ports) {
             $service->setPublicPorts($ports);
             $output->writeln('<info>Modifying ports for SERVICE: ' . $serviceName . '</info>');
         }
         if ($service->getHAProxyBackend() != $haproxyBackend) {
             $service->setHAProxyBackend($haproxyBackend);
             $output->writeln('<info>Modifying haproxy_backend for SERVICE: ' . $serviceName . '</info>');
         }
         $project->setConfigHash($config->getConfigHash());
         $em->flush();
     }
 }
Ejemplo n.º 2
0
 protected function checkConfigHash(Project $project, InputInterface $input, OutputInterface $output)
 {
     $config = $this->get('config');
     $helper = $this->getHelper('question');
     if ($project->getConfigHash() != $config->getConfigHash()) {
         $question = new ConfirmationQuestion('Load new gruver config? <info>(y/n)</info>  ', false);
         $loadConfig = $helper->ask($input, $output, $question);
         if ($loadConfig) {
             $command = $this->getApplication()->find('load-config');
             $code = $command->run(new ArrayInput(array()), $output);
             if (!$code) {
                 exit;
             }
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function updateTimestamps()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'updateTimestamps', []);
     return parent::updateTimestamps();
 }