public function execute()
{
$end = microtime(true) + 60;
while (true) {
try {
$health = new \Elastica\Cluster\Health($this->getConnection()->getClient());
$status = $health->getStatus();
$this->output("Elasticsearch status: {$status}\n");
if ($status === 'green') {
break;
}
} catch (\Elastica\Exception\Connection\HttpException $e) {
if ($e->getError() === CURLE_COULDNT_CONNECT) {
$this->output("Elasticsearch not up.\n");
$this->getConnection()->destroyClient();
} else {
// The two exit code here makes puppet fail with an error.
$this->error('Connection error: ' . $e->getMessage(), 2);
}
}
if ($end < microtime(true)) {
$this->error('Elasticsearch was not ready in time.', 1);
}
sleep(1);
}
foreach ($this->getConnection()->getAllIndexTypes() as $indexType) {
try {
$count = $this->getConnection()->getPageType(wfWikiId(), $indexType)->count();
} catch (\Elastica\Exception\ResponseException $e) {
$this->output("{$indexType} doesn't exist.\n");
$this->error("true");
exit(0);
}
if ($indexType === 'content' && $count === 0) {
$this->output("No pages in the content index. Indexes were probably wiped.\n");
exit(0);
}
$this->output("Page count in {$indexType}: {$count}\n");
}
// The 1 exit code here makes puppet decide that it needs to run whatever is gated by this.
exit(1);
}