/** * 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; }
public function testGetAllMappings() { $version = '1.6.0'; $serverInfoData = $this->getServerInfoData($version); $mappingData = ['my-index' => ['mappings' => ['my-type' => ['properties' => []]]]]; $this->serverInfoResponse->expects($this->exactly(3))->method('getData')->willReturn($serverInfoData); $this->response->expects($this->once())->method('getData')->willReturn($mappingData); $this->request->expects($this->never())->method('setBody'); $this->requestFactory->expects($this->once())->method('create')->with('Index\\GetMappingRequest', $version, null, null, $this->serializer)->willReturn($this->request); $this->client->expects($this->exactly(2))->method('send')->withConsecutive($this->isInstanceOf('Elastification\\Client\\Request\\V1x\\NodeInfoRequest'), $this->isInstanceOf('Elastification\\Client\\Request\\V1x\\Index\\GetMappingRequest'))->willReturnOnConsecutiveCalls($this->serverInfoResponse, $this->response); $result = $this->repository->getAllMappings(self::HOST, self::PORT); $this->assertInstanceOf('Elastification\\BackupRestore\\Entity\\Mappings', $result); $this->assertSame(1, $result->countIndices()); $this->assertSame(1, $result->countTypes()); $index = $result->getIndices()[0]; $this->assertSame('my-index', $index->getName()); $type = $index->getTypes()[0]; $this->assertSame('my-type', $type->getName()); $schema = $type->getSchema(); $this->assertTrue(isset($schema['properties'])); }
/** * Loads possible target mappings * * @param RestoreJob $job * @return \Elastification\BackupRestore\Entity\Mappings * @author Daniel Wendlandt */ public function getTargetMappings(RestoreJob $job) { return $this->elastic->getAllMappings($job->getHost(), $job->getPort()); }