本文整理汇总了PHP中Elastica\Client::getCluster方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getCluster方法的具体用法?PHP Client::getCluster怎么用?PHP Client::getCluster使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Client
的用法示例。
在下文中一共展示了Client::getCluster方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
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: testShutdown
/**
* 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: reindex
/**
* @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);
}