public function testIsVersionAllowed() { $this->assertTrue(VersionHelper::isVersionAllowed('1.7.3')); $this->assertFalse(VersionHelper::isVersionAllowed('0.90.3')); $this->assertFalse(VersionHelper::isVersionAllowed('2.0.3')); $this->assertFalse(VersionHelper::isVersionAllowed('v1.0.3')); }
/** * Creates a backup job * * @param string $source * @param string $host * @param int $port * @return RestoreJob * @throws \Exception * @author Daniel Wendlandt */ public function createJob($source, $host, $port = 9200) { $restoreJob = new RestoreJob(); $restoreJob->setHost($host); $restoreJob->setPort($port); $restoreJob->setSource(dirname($source)); $restoreJob->setName(basename($source)); $restoreJob->setServerInfo($this->elastic->getServerInfo($host, $port)); $restoreJob->setMappings($this->filesystem->loadMappings($restoreJob->getPath())); if (!VersionHelper::isVersionAllowed($restoreJob->getServerInfo()->version)) { throw new \Exception('Elasticsearch version ' . $restoreJob->getServerInfo()->version . ' is not supported by this tool'); } return $restoreJob; }
/** * Creates a backup job * * @param string $target * @param string $host * @param int $port * @param array $mappings * @return BackupJob * @throws \Exception * @author Daniel Wendlandt */ public function createJob($target, $host, $port = 9200, array $mappings = array()) { $backupJob = new BackupJob(); $backupJob->setHost($host); $backupJob->setPort($port); $backupJob->setTarget($target); $backupJob->setServerInfo($this->elastic->getServerInfo($host, $port)); $backupJob->setMappings($this->elastic->getAllMappings($host, $port)); if (!empty($mappings)) { $backupJob->getMappings()->reduceIndices($mappings); } if (!VersionHelper::isVersionAllowed($backupJob->getServerInfo()->version)) { throw new \Exception('Elasticsearch version ' . $backupJob->getServerInfo()->version . ' is not supported by this tool'); } return $backupJob; }
/** * Checks if server info is set. If not it fetches the server info again. * Also a verison check is done, if elasticsearch version is supported by this software * * @param string $host * @param int $port * @throws \Exception * @author Daniel Wendlandt */ private function checkServerInfo($host, $port = 9200) { if (null === $this->serverInfo) { $this->getServerInfo($host, $port); } if (!VersionHelper::isVersionAllowed($this->serverInfo->version)) { throw new \Exception('Elasticsearch version ' . $this->serverInfo->version . ' is not supported by this tool'); } }