getCluster() public method

Returns the current cluster.
public getCluster ( ) : Cluster
return Cluster Cluster object
コード例 #1
0
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $table = new Console\Helper\TableHelper();
     $output->writeln('Cluster overview:');
     $output->writeln('');
     $output->writeln('Nodes:');
     $cluster = $this->elastica->getCluster();
     $table->setHeaders(['name', 'documents', 'node', 'ip', 'port', 'hostname', 'version', 'transport address', 'http address']);
     $nodes = $cluster->getNodes();
     foreach ($nodes as $node) {
         $name = $node->getName();
         $ip = $node->getInfo()->getIp();
         $data = $node->getInfo()->getData();
         $port = $node->getInfo()->getPort();
         $stats = $node->getStats()->get();
         //dump($stats->get());exit;
         $table->addRow([$data['name'], $stats['indices']['docs']['count'], $name, $ip, $port, $data['hostname'], $data['version'], $data['transport_address'], $data['http_address']]);
     }
     $table->render($output);
     $table->setRows([]);
     /* INFO */
     $info = $this->elastica->request('', 'GET')->getData();
     $table->setHeaders(['name', 'version', 'status', 'ok']);
     $table->addRow([$info['name'], $info['version']['number'], $info['status'], $info['ok']]);
     $table->render($output);
     $table->setRows([]);
     $output->writeln('');
 }
コード例 #2
0
ファイル: NodeTest.php プロジェクト: kskod/Elastica
 /**
  * Shuts one of two nodes down (if two available)
  */
 public function testShutdown()
 {
     $client = $this->_getClient();
     $nodes = $client->getCluster()->getNodes();
     $count = count($nodes);
     if ($count < 2) {
         $this->markTestSkipped('At least two nodes have to be running, because 1 node is shutdown');
     }
     // Store node info of node with port 9200 for later
     foreach ($nodes as $key => $node) {
         if ($node->getInfo()->getPort() == 9200) {
             $info = $node->getInfo();
             unset($nodes[$key]);
         }
     }
     // Select one of the not port 9200 nodes and shut it down
     $node = array_shift($nodes);
     $node->shutdown('2s');
     // Wait until node is shutdown
     sleep(5);
     // Use still existing node
     $client = new Client(array('host' => $info->getIp(), 'port' => $info->getPort()));
     $names = $client->getCluster()->getNodeNames();
     // One node less ...
     $this->assertEquals($count - 1, count($names));
 }
コード例 #3
0
ファイル: Reindexator.php プロジェクト: legendik/DwarfSearch
 /**
  * @param string $newIndexName
  * @throws IndexAlreadyExistsException
  * @throws IndexDoesNotExistsException
  */
 public function reindex($newIndexName)
 {
     $newIndex = $this->getIndex($newIndexName);
     if ($newIndex->exists()) {
         throw new IndexAlreadyExistsException("Index '{$newIndexName}' already exists!");
     }
     if (count($this->client->getCluster()->getIndexNames()) < 1) {
         throw new IndexDoesNotExistsException('Old index was not found in Elastic!');
     }
     $this->createNewIndexMapping($newIndexName);
     $oldIndexEntity = $this->findNewestIndex();
     $oldIndex = $this->getIndex($oldIndexEntity->getName());
     if (!$oldIndex->exists()) {
         throw new IndexDoesNotExistsException('Old index was not found in Elastic!');
     }
     $this->onBeforeReindex($newIndex, $oldIndex);
     $this->moveDataBetweenIndices($oldIndex, $newIndex);
     $this->onAfterReindex($newIndex, $oldIndex);
     $this->onBeforeChangingAlias($oldIndex, $newIndex);
     $this->moveAliasBetweenIndices($oldIndex, $newIndex);
     $this->onAfterChangingAlias($oldIndex, $newIndex);
     $oldIndex->delete();
     $this->onFinish($newIndex);
 }