/**
  * @covers \Keboola\Syrup\Elasticsearch\ComponentIndex::buildMapping
  */
 public function testMapping()
 {
     $mapping = ComponentIndex::buildMapping(__DIR__ . '/../../../../app');
     $this->assertNotNull($mapping);
     $this->assertArrayHasKey('mappings', $mapping);
     $this->assertArrayHasKey('jobs', $mapping['mappings']);
     $this->assertArrayHasKey('properties', $mapping['mappings']['jobs']);
 }
Exemple #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $settings = null;
     $mapping = null;
     if (!$input->getOption('no-mapping')) {
         $mapping = ComponentIndex::buildMapping($this->getContainer()->get('kernel')->getRootDir());
         $settings = $mapping['settings'];
         $mapping = $mapping['mappings'];
     }
     /** @var ComponentIndex $index */
     $index = $this->getContainer()->get('syrup.elasticsearch.current_component_index');
     // try put mapping first
     try {
         $indexName = $index->putMapping($mapping);
         echo "Mapping {$indexName} updated successfuly" . PHP_EOL;
     } catch (\Exception $e) {
         echo "Can't updated mapping: " . $e->getMessage() . PHP_EOL;
         $indexName = $index->createIndex($settings, $mapping);
         echo "Created new index '" . $indexName . "'" . PHP_EOL;
     }
 }
Exemple #3
0
 protected function checkMappingParams($params)
 {
     $mapping = ComponentIndex::buildMapping($this->container->get('kernel')->getRootDir());
     if (isset($mapping['mappings']['jobs']['properties']['params']['properties'])) {
         $mappingParams = $mapping['mappings']['jobs']['properties']['params']['properties'];
         foreach (array_keys($params) as $paramKey) {
             if (!in_array($paramKey, array_keys($mappingParams))) {
                 throw new UserException(sprintf("Parameter '%s' is not allowed. Allowed params are '%s'", $paramKey, implode(',', array_keys($mappingParams))));
             }
         }
     }
 }
Exemple #4
0
 protected function fillEmptyKeys($jobData)
 {
     if ($this->rootDir == null) {
         throw new ApplicationException("rootDir must be set");
     }
     $mapping = ComponentIndex::buildMapping($this->rootDir);
     $properties = $mapping['mappings']['jobs']['properties'];
     foreach ($properties as $k => $v) {
         if (!isset($jobData[$k])) {
             if (isset($v['properties'])) {
                 foreach (array_keys($v['properties']) as $kk) {
                     $jobData[$k][$kk] = null;
                 }
             } else {
                 $jobData[$k] = null;
             }
         }
     }
     return $jobData;
 }