Search in sources :

Example 1 with IndexingServiceException

use of alien4cloud.exception.IndexingServiceException in project alien4cloud by alien4cloud.

the class ESIndexMapper method initIndices.

/**
 * Create if not exist indices.
 * A TTL can be defined for all indices under this index (ESearch TTL notation)
 *
 * @param indexName The index to initialize
 * @param classes An array of classes to map to this index.
 */
@SneakyThrows({ IOException.class, IntrospectionException.class })
public void initIndices(String indexName, String ttl, Class<?>... classes) {
    if (indexExist(indexName)) {
        addToMappedClasses(indexName, classes);
    } else {
        // create the index and add the mapping
        CreateIndexRequestBuilder createIndexRequestBuilder = esClient.getClient().admin().indices().prepareCreate(indexName);
        for (Class<?> clazz : classes) {
            String typeName = addToMappedClasses(indexName, clazz);
            if (Modifier.isAbstract(clazz.getModifiers())) {
                // no mapping to register for abstract classes.
                continue;
            }
            String typeMapping = mappingBuilder.getMapping(clazz);
            Map<String, Object> typesMap = JsonUtil.toMap(typeMapping);
            addAlienScore(typesMap);
            addTTL(typesMap, ttl);
            Field generatedIdField = ReflectionUtil.getDeclaredField(clazz, EsGeneratedId.class);
            if (generatedIdField != null) {
                generatedIdField.setAccessible(true);
                classTogeneratedIdFields.put(clazz, generatedIdField);
            }
            String mapping = jsonMapper.writeValueAsString(typesMap);
            createIndexRequestBuilder.addMapping(typeName, mapping);
            // add settings if any (including analysers definitions)
            String indexSettings = mappingBuilder.getIndexSettings(clazz);
            if (StringUtils.isNotBlank(indexSettings)) {
                createIndexRequestBuilder.setSettings(indexSettings);
            }
        }
        try {
            final CreateIndexResponse createResponse = createIndexRequestBuilder.execute().actionGet();
            if (!createResponse.isAcknowledged()) {
                throw new IndexingServiceException("Failed to create index <" + indexName + ">");
            }
        } catch (Exception e) {
            log.warn("Not able to init indice for index {}, maybe it has been created elsewhere", indexName);
        }
    }
}
Also used : Field(java.lang.reflect.Field) IndexingServiceException(alien4cloud.exception.IndexingServiceException) CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) IndexingServiceException(alien4cloud.exception.IndexingServiceException) IOException(java.io.IOException) IntrospectionException(java.beans.IntrospectionException) ExecutionException(java.util.concurrent.ExecutionException) SneakyThrows(lombok.SneakyThrows)

Example 2 with IndexingServiceException

use of alien4cloud.exception.IndexingServiceException in project alien4cloud by alien4cloud.

the class ElasticSearchUserDao method initEnvironment.

@PostConstruct
public void initEnvironment() {
    // init ES annotation scanning
    try {
        mappingBuilder.initialize(User.class.getPackage().getName());
    } catch (IntrospectionException | IOException e) {
        throw new IndexingServiceException("Could not initialize elastic search mapping builder", e);
    }
    // init indexes and mapped classes
    initIndices(User.class.getSimpleName().toLowerCase(), null, new Class<?>[] { User.class });
    initCompleted();
}
Also used : IndexingServiceException(alien4cloud.exception.IndexingServiceException) IntrospectionException(java.beans.IntrospectionException) IOException(java.io.IOException) PostConstruct(javax.annotation.PostConstruct)

Example 3 with IndexingServiceException

use of alien4cloud.exception.IndexingServiceException in project alien4cloud by alien4cloud.

the class MonitorESDAO method initEnvironment.

/**
 * Initialize the dao after being loaded by spring (Create the indexes).
 */
@PostConstruct
public void initEnvironment() {
    // init ES annotation scanning
    try {
        getMappingBuilder().initialize("alien4cloud.paas.model");
    } catch (IntrospectionException | IOException e) {
        throw new IndexingServiceException("Could not initialize elastic search mapping builder", e);
    }
    // init indices and mapped classes
    setJsonMapper(ElasticSearchMapper.getInstance());
    Class<?>[] classes = new Class<?>[] { AbstractMonitorEvent.class, PaaSDeploymentStatusMonitorEvent.class, PaaSInstanceStateMonitorEvent.class, PaaSMessageMonitorEvent.class, PaaSInstancePersistentResourceMonitorEvent.class, PaaSWorkflowStepMonitorEvent.class, PaaSWorkflowMonitorEvent.class };
    initIndices("deployedtopologies", null, DeploymentTopology.class);
    initIndices("deploymentmonitorevents", eventMonitoringTtl, classes);
    initIndices(PaaSDeploymentLog.class.getSimpleName().toLowerCase(), eventMonitoringTtl, PaaSDeploymentLog.class);
    initCompleted();
}
Also used : IndexingServiceException(alien4cloud.exception.IndexingServiceException) IntrospectionException(java.beans.IntrospectionException) IOException(java.io.IOException) PostConstruct(javax.annotation.PostConstruct)

Example 4 with IndexingServiceException

use of alien4cloud.exception.IndexingServiceException in project alien4cloud by alien4cloud.

the class ElasticSearchDAO method initEnvironment.

/**
 * Initialize the dao after being loaded by spring (Create the indexes).
 */
@PostConstruct
public void initEnvironment() {
    // init ES annotation scanning
    try {
        getMappingBuilder().initialize("alien4cloud");
        getMappingBuilder().initialize("org.alien4cloud");
        getMappingBuilder().parseClassAnnotations(AbstractToscaType.class, "");
    } catch (IntrospectionException | IOException e) {
        throw new IndexingServiceException("Could not initialize elastic search mapping builder", e);
    }
    // init indices and mapped classes
    setJsonMapper(ElasticSearchMapper.getInstance());
    initIndices(TOSCA_ELEMENT_INDEX, null, CapabilityType.class, ArtifactType.class, RelationshipType.class, NodeType.class, DataType.class, PrimitiveDataType.class, PolicyType.class);
    initIndices(TOSCA_ELEMENT_INDEX, null, AbstractInstantiableToscaType.class, AbstractToscaType.class);
    initIndice(Application.class);
    initIndice(ApplicationVersion.class);
    initIndice(ApplicationEnvironment.class);
    initIndice(Topology.class);
    initIndice(Csar.class);
    initIndice(Repository.class);
    initIndice(ServiceResource.class);
    initIndice(Plugin.class);
    initIndice(PluginConfiguration.class);
    initIndice(MetaPropConfiguration.class);
    initIndice(Orchestrator.class);
    initIndice(OrchestratorConfiguration.class);
    initIndice(Location.class);
    initIndices(LocationResourceTemplate.class.getSimpleName().toLowerCase(), null, LocationResourceTemplate.class, PolicyLocationResourceTemplate.class, AbstractLocationResourceTemplate.class);
    initIndice(Deployment.class);
    initIndice(CsarGitRepository.class);
    initIndice(DeploymentInputs.class);
    initIndice(DeploymentMatchingConfiguration.class);
    initIndice(OrchestratorDeploymentProperties.class);
    initIndice(DataObjectVersion.class);
    initIndice(MaintenanceModeState.class);
    initIndice(GitLocation.class);
    initIndices(SUGGESTION_INDEX, null, AbstractSuggestionEntry.class, SuggestionEntry.class, SimpleSuggestionEntry.class);
    initCompleted();
}
Also used : IndexingServiceException(alien4cloud.exception.IndexingServiceException) IntrospectionException(java.beans.IntrospectionException) IOException(java.io.IOException) PostConstruct(javax.annotation.PostConstruct)

Example 5 with IndexingServiceException

use of alien4cloud.exception.IndexingServiceException in project alien4cloud by alien4cloud.

the class ImageDAO method initEnvironment.

@PostConstruct
public void initEnvironment() {
    // init ES annotation scanning
    try {
        mappingBuilder.initialize(ImageData.class.getPackage().getName());
    } catch (IntrospectionException | IOException e) {
        throw new IndexingServiceException("Could not initialize elastic search mapping builder", e);
    }
    // init indexes and mapped classes
    initIndices(ImageData.class.getSimpleName().toLowerCase(), null, ImageData.class);
    initCompleted();
}
Also used : IndexingServiceException(alien4cloud.exception.IndexingServiceException) IntrospectionException(java.beans.IntrospectionException) IOException(java.io.IOException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

IndexingServiceException (alien4cloud.exception.IndexingServiceException)8 IntrospectionException (java.beans.IntrospectionException)7 IOException (java.io.IOException)7 PostConstruct (javax.annotation.PostConstruct)6 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 SneakyThrows (lombok.SneakyThrows)1 AbstractInheritableToscaType (org.alien4cloud.tosca.model.types.AbstractInheritableToscaType)1 CreateIndexRequestBuilder (org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1