/**
  * @return VMConfig[]
  */
 protected function loadVMConfig()
 {
     if (null === $this->VMConfig) {
         $this->VMConfig = ConfigManager::loadVMConfig();
     }
     $result = [];
     foreach ($this->VMConfig as $config) {
         $result[$config->getName()] = $config;
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * @param string $name
  *
  * @return static
  */
 public static function init($name = null)
 {
     $config = ConfigManager::getConfig();
     $name = $name ?: $config->get('worker_manager.monitoring.node');
     return new static($config, $name);
 }
 /**
  * construct
  */
 public function __construct()
 {
     ConfigManager::register(dirname(__DIR__) . '/Resources/config');
     parent::__construct();
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $monitoring = WorkerMonitoring::init();
     $monitoring->updateAction(self::ACTION_MONITORING);
     $statusManager = $this->getStatusManager();
     $statusManager->setOptions(ConfigManager::getConfig()->get('worker_manager.options') ?: []);
     $updateManager = $this->getUpdateManager();
     $logger = $this->getLogger();
     list($workers, $VMConfigs) = $statusManager->initData();
     $output->writeln('Worker monitoring: <info>running</info>');
     $output->write('Balancing: ');
     if ($monitoring->isBalancing()) {
         $output->writeln('<info>yes</info>');
     } else {
         $output->writeln('<comment>no</comment>');
     }
     $output->writeln('Node name: <info>' . $monitoring->getName() . '</info>');
     $output->writeln('Node PID: <info>' . $monitoring->getPID() . '</info>');
     $output->write('Status: ');
     do {
         if ($monitoring->isMaster()) {
             $action = $monitoring->getAction();
             $output->write('<info>master[' . $action . ']</info> ');
             $statusManager->updateStatus($workers, $VMConfigs);
             switch ($action) {
                 case self::ACTION_MONITORING:
                     /** @var \WorkerManager\Model\WorkerConfig $worker */
                     foreach ($workers as $worker) {
                         $updateManager->update($worker);
                         if ($logger) {
                             $logger->logWorker($worker);
                         }
                     }
                     if ($logger) {
                         foreach ($VMConfigs as $VMConfig) {
                             $logger->logVM($VMConfig);
                         }
                     }
                     break;
                 case self::ACTION_RESTART:
                     $output->writeln('Restarting workers...');
                     /** @var \WorkerManager\Model\VMConfig $VMConfig */
                     foreach ($VMConfigs as $VMConfig) {
                         $output->writeln('Restart ' . $VMConfig->getName());
                         $updateManager->restartWorkers($VMConfig, function ($response) use($output) {
                             $output->writeln($response);
                         });
                     }
                     $monitoring->updateAction(static::ACTION_MONITORING);
                     break;
             }
         } else {
             $output->write('<comment>slave</comment> ');
         }
         $monitoring->wait();
     } while ($this->isAlive());
 }