/** * Take care of all mapping actions and handles all for elastic sid * * @param RestoreJob $job * @param JobStats $jobStats * @param OutputInterface $output * @throws \Exception * @author Daniel Wendlandt */ private function handleMappings(RestoreJob $job, JobStats $jobStats, OutputInterface $output) { $memoryAtSection = memory_get_usage(); $timeStartSection = microtime(true); $output->writeln('<info>*** Start handling mappings ***</info>' . PHP_EOL); /** @var Index $index */ foreach ($job->getMappings()->getIndices() as $index) { /** @var Type $type */ foreach ($index->getTypes() as $type) { $mappingAction = $job->getStrategy()->getMapping($index->getName(), $type->getName()); if (null === $mappingAction) { throw new \Exception('Mapping action missing for "' . $index->getName() . '/' . $type->getName() . '"'); } if (RestoreStrategy::STRATEGY_RESET === $mappingAction->getStrategy()) { $schema = array($mappingAction->getTargetType() => $type->getSchema()); $this->elastic->createMapping($mappingAction->getTargetIndex(), $mappingAction->getTargetType(), $schema, $job->getHost(), $job->getPort()); $output->writeln('<comment> - Created mapping from ' . $index->getName() . '/' . $type->getName() . ' to ' . $mappingAction->getTargetIndex() . '/' . $mappingAction->getTargetType() . '</comment>'); } else { $output->writeln('<comment> - No Action for ' . $index->getName() . '/' . $type->getName() . '</comment>'); } } } $output->writeln(''); $jobStats->setRestoreHandleMappings(microtime(true) - $timeStartSection, memory_get_usage(), memory_get_usage() - $memoryAtSection); }
public function testCreateMapping() { $version = '1.6.0'; $serverInfoData = $this->getServerInfoData($version); $index = 'my-index'; $type = 'my-type'; $schema = ['my' => 'schema']; $deleteIndexRequest = $this->getMockBuilder('Elastification\\Client\\Request\\V1x\\Index\\DeleteIndexRequest')->disableOriginalConstructor()->getMock(); $createIndexRequest = $this->getMockBuilder('Elastification\\Client\\Request\\V1x\\Index\\CreateIndexRequest')->disableOriginalConstructor()->getMock(); $this->serverInfoResponse->expects($this->exactly(3))->method('getData')->willReturn($serverInfoData); $this->request->expects($this->once())->method('setBody')->with($this->equalTo($schema)); $this->requestFactory->expects($this->exactly(3))->method('create')->withConsecutive(array('Index\\DeleteIndexRequest', $version, $index, $type, $this->serializer), array('Index\\CreateIndexRequest', $version, $index, null, $this->serializer), array('Index\\CreateMappingRequest', $version, $index, $type, $this->serializer))->willReturnOnConsecutiveCalls($deleteIndexRequest, $createIndexRequest, $this->request); $this->client->expects($this->exactly(4))->method('send')->withConsecutive($this->isInstanceOf('Elastification\\Client\\Request\\V1x\\NodeInfoRequest'), $this->isInstanceOf('Elastification\\Client\\Request\\V1x\\Index\\DeleteIndexRequest'), $this->isInstanceOf('Elastification\\Client\\Request\\V1x\\Index\\CreateIndexRequest'), $this->isInstanceOf('Elastification\\Client\\Request\\V1x\\Index\\CreateMappingRequest'))->willReturnOnConsecutiveCalls($this->serverInfoResponse); $this->repository->createMapping($index, $type, $schema, self::HOST, self::PORT); }