private function waitForGreen($timeout = 600)
 {
     $this->output("Waiting for the index to go green...\n");
     // Wait for the index to go green ( default 10 min)
     if (!$this->utils->waitForGreen($this->getIndex()->getName(), $timeout)) {
         $this->error("Failed to wait for green... please check config and delete the {$this->getIndex()->getName()} index if it was created.", 1);
     }
 }
 public function execute()
 {
     global $wgCirrusSearchMaintenanceTimeout;
     $this->indexType = $this->getOption('indexType');
     $this->indexBaseName = $this->getOption('baseName', wfWikiId());
     $reindexChunkSize = $this->getOption('reindexChunkSize', 100);
     $reindexRetryAttempts = $this->getOption('reindexRetryAttempts', 5);
     $targetCluster = $this->getOption('targetCluster');
     $processes = $this->getOption('processes', 1);
     $sourceConnection = $this->getConnection();
     $targetConnection = $this->getConnection($targetCluster);
     if ($sourceConnection->getClusterName() == $targetConnection->getClusterName()) {
         $this->error("Target cluster should be different from current cluster.", 1);
     }
     $config = ConfigFactory::getDefaultInstance()->makeConfig('CirrusSearch');
     $clusterSettings = new ClusterSettings($config, $targetConnection->getClusterName());
     $targetIndexName = $targetConnection->getIndexName($this->indexBaseName, $this->indexType);
     $utils = new ConfigUtils($targetConnection->getClient(), $this);
     $indexIdentifier = $utils->pickIndexIdentifierFromOption($this->getOption('indexIdentifier', 'current'), $targetIndexName);
     $reindexer = new Reindexer($sourceConnection, $targetConnection, array($targetConnection->getIndex($this->indexBaseName, $this->indexType, $indexIdentifier)->getType(Connection::PAGE_TYPE_NAME)), array($this->getConnection()->getPageType($this->indexBaseName, $this->indexType)), $clusterSettings->getShardCount($this->indexType), $clusterSettings->getReplicaCount($this->indexType), $wgCirrusSearchMaintenanceTimeout, $this->getMergeSettings(), $this->getMappingConfig(), $this);
     $reindexer->reindex($processes, 1, $reindexRetryAttempts, $reindexChunkSize);
     $reindexer->optimize();
     $reindexer->waitForShards();
 }
 public function execute()
 {
     global $wgPoolCounterConf, $wgLanguageCode, $wgCirrusSearchPhraseSuggestUseText, $wgCirrusSearchPrefixSearchStartsWithAnyWord, $wgCirrusSearchBannedPlugins, $wgCirrusSearchOptimizeIndexForExperimentalHighlighter, $wgCirrusSearchMaxShardsPerNode, $wgCirrusSearchRefreshInterval;
     // Make sure we don't flood the pool counter
     unset($wgPoolCounterConf['CirrusSearch-Search']);
     // Set the timeout for maintenance actions
     $this->setConnectionTimeout();
     $utils = new ConfigUtils($this->getConnection()->getClient(), $this);
     $this->indexType = $this->getOption('indexType');
     $this->startOver = $this->getOption('startOver', false);
     $this->indexBaseName = $this->getOption('baseName', wfWikiId());
     $this->reindexAndRemoveOk = $this->getOption('reindexAndRemoveOk', false);
     $this->reindexProcesses = $this->getOption('reindexProcesses', wfIsWindows() ? 1 : 5);
     $this->reindexAcceptableCountDeviation = Util::parsePotentialPercent($this->getOption('reindexAcceptableCountDeviation', '5%'));
     $this->reindexChunkSize = $this->getOption('reindexChunkSize', 100);
     $this->reindexRetryAttempts = $this->getOption('reindexRetryAttempts', 5);
     $this->printDebugCheckConfig = $this->getOption('debugCheckConfig', false);
     $this->langCode = $wgLanguageCode;
     $this->prefixSearchStartsWithAny = $wgCirrusSearchPrefixSearchStartsWithAnyWord;
     $this->phraseSuggestUseText = $wgCirrusSearchPhraseSuggestUseText;
     $this->bannedPlugins = $wgCirrusSearchBannedPlugins;
     $this->optimizeIndexForExperimentalHighlighter = $wgCirrusSearchOptimizeIndexForExperimentalHighlighter;
     $this->maxShardsPerNode = isset($wgCirrusSearchMaxShardsPerNode[$this->indexType]) ? $wgCirrusSearchMaxShardsPerNode[$this->indexType] : 'unlimited';
     $this->refreshInterval = $wgCirrusSearchRefreshInterval;
     try {
         $indexTypes = $this->getConnection()->getAllIndexTypes();
         if (!in_array($this->indexType, $indexTypes)) {
             $this->error('indexType option must be one of ' . implode(', ', $indexTypes), 1);
         }
         $utils->checkElasticsearchVersion();
         $this->availablePlugins = $utils->scanAvailablePlugins($this->bannedPlugins);
         if ($this->getOption('justCacheWarmers', false)) {
             $this->validateCacheWarmers();
             return;
         }
         if ($this->getOption('justAllocation', false)) {
             $this->validateShardAllocation();
             return;
         }
         $this->indexIdentifier = $utils->pickIndexIdentifierFromOption($this->getOption('indexIdentifier', 'current'), $this->getIndexTypeName());
         $this->analysisConfigBuilder = $this->pickAnalyzer($this->langCode, $this->availablePlugins);
         $this->validateIndex();
         $this->validateAnalyzers();
         $this->validateMapping();
         $this->validateCacheWarmers();
         $this->validateAlias();
         $this->updateVersions();
         $this->indexNamespaces();
     } catch (\Elastica\Exception\Connection\HttpException $e) {
         $message = $e->getMessage();
         $this->output("\nUnexpected Elasticsearch failure.\n");
         $this->error("Http error communicating with Elasticsearch:  {$message}.\n", 1);
     } catch (\Elastica\Exception\ExceptionInterface $e) {
         $type = get_class($e);
         $message = ElasticsearchIntermediary::extractMessage($e);
         $trace = $e->getTraceAsString();
         $this->output("\nUnexpected Elasticsearch failure.\n");
         $this->error("Elasticsearch failed in an unexpected way.  This is always a bug in CirrusSearch.\n" . "Error type: {$type}\n" . "Message: {$message}\n" . "Trace:\n" . $trace, 1);
     }
 }
 public function execute()
 {
     // Make sure we don't flood the pool counter
     global $wgPoolCounterConf;
     unset($wgPoolCounterConf['Flow-Search']);
     // Sets all of this class' properties that will be passed to validators
     $this->setProperties();
     // Set the timeout for maintenance actions
     $this->setConnectionTimeout();
     try {
         $indexTypes = $this->getAllIndices();
         if (!in_array($this->indexType, $indexTypes)) {
             $this->error('indexType option must be one of ' . implode(', ', $indexTypes), 1);
         }
         $this->utils->checkElasticsearchVersion();
         $validators = $this->getValidators();
         foreach ($validators as $validator) {
             $status = $validator->validate();
             if (!$status->isOK()) {
                 $this->error($status->getMessage()->text(), 1);
             }
         }
         //			$this->updateVersions(); // @todo: might need this some day? (see CirrusSearch's UpdateOneSearchIndexConfig::updateVersions)
     } catch (\Elastica\Exception\Connection\HttpException $e) {
         $message = $e->getMessage();
         $this->output("\nUnexpected Elasticsearch failure.\n");
         $this->error("Http error communicating with Elasticsearch:  {$message}.\n", 1);
     } catch (\Elastica\Exception\ExceptionInterface $e) {
         $type = get_class($e);
         $message = ElasticsearchIntermediary::extractMessage($e);
         $trace = $e->getTraceAsString();
         $this->output("\nUnexpected Elasticsearch failure.\n");
         $this->error("Elasticsearch failed in an unexpected way.  This is always a bug in FlowSearch.\n" . "Error type: {$type}\n" . "Message: {$message}\n" . "Trace:\n" . $trace, 1);
     }
 }
 public function execute()
 {
     global $wgLanguageCode, $wgCirrusSearchBannedPlugins, $wgCirrusSearchRefreshInterval, $wgPoolCounterConf;
     $this->indexTypeName = Connection::TITLE_SUGGEST_TYPE;
     // Make sure we don't flood the pool counter
     unset($wgPoolCounterConf['CirrusSearch-Search']);
     // Set the timeout for maintenance actions
     $this->setConnectionTimeout();
     $this->indexBaseName = $this->getOption('baseName', wfWikiId());
     $this->indexChunkSize = $this->getOption('indexChunkSize', 100);
     $this->indexRetryAttempts = $this->getOption('reindexRetryAttempts', 5);
     $this->optimizeIndex = $this->getOption('optimize', false);
     $this->withGeo = $this->getOption('with-geo', false);
     $utils = new ConfigUtils($this->getClient(), $this);
     $this->langCode = $wgLanguageCode;
     $this->bannedPlugins = $wgCirrusSearchBannedPlugins;
     $utils->checkElasticsearchVersion();
     $this->maxShardsPerNode = isset($wgCirrusSearchMaxShardsPerNode[$this->indexTypeName]) ? $wgCirrusSearchMaxShardsPerNode[$this->indexTypeName] : 'unlimited';
     $this->refreshInterval = $wgCirrusSearchRefreshInterval;
     try {
         $oldIndexIdentifier = $utils->pickIndexIdentifierFromOption('current', $this->getIndexTypeName());
         $this->oldIndex = $this->getConnection()->getIndex($this->indexBaseName, $this->indexTypeName, $oldIndexIdentifier);
         $this->indexIdentifier = $utils->pickIndexIdentifierFromOption('now', $this->getIndexTypeName());
         $this->availablePlugins = $utils->scanAvailablePlugins($this->bannedPlugins);
         $this->analysisConfigBuilder = $this->pickAnalyzer($this->langCode, $this->availablePlugins);
         $this->createIndex();
         $this->validateAnalyzers();
         $this->createMapping();
         $this->indexData();
         if ($this->optimizeIndex) {
             $this->optimize();
         }
         $this->validateAlias();
         $this->updateVersions();
         $this->deleteOldIndex();
         $this->output("done.\n");
     } catch (\Elastica\Exception\Connection\HttpException $e) {
         $message = $e->getMessage();
         $this->output("\nUnexpected Elasticsearch failure.\n");
         $this->error("Http error communicating with Elasticsearch:  {$message}.\n", 1);
     } catch (\Elastica\Exception\ExceptionInterface $e) {
         $type = get_class($e);
         $message = ElasticsearchIntermediary::extractMessage($e);
         $trace = $e->getTraceAsString();
         $this->output("\nUnexpected Elasticsearch failure.\n");
         $this->error("Elasticsearch failed in an unexpected way.  This is always a bug in CirrusSearch.\n" . "Error type: {$type}\n" . "Message: {$message}\n" . "Trace:\n" . $trace, 1);
     }
     $this->getIndex()->refresh();
 }