Search in sources :

Example 6 with IndexingServiceException

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

the class IndexedModelUtils method orderByDerivedFromHierarchy.

/**
 * This utility method returns an ordered {@link AbstractInheritableToscaType} collection. The parent elements will be before
 * the children elements
 * This utility method returns an ordered {@link AbstractInheritableToscaType} collection. The parent elements will be before the children elements
 *
 * @param elementsByIdMap map of {@link AbstractInheritableToscaType} by id
 * @return
 */
public static <T extends AbstractInheritableToscaType> List<T> orderByDerivedFromHierarchy(final Map<String, T> elementsByIdMap) {
    if (elementsByIdMap == null) {
        return null;
    }
    List<T> orderedElements = new ArrayList<T>(elementsByIdMap.values());
    final Map<String, Integer> elementsLevelMap = Maps.newHashMap();
    for (AbstractInheritableToscaType element : orderedElements) {
        AbstractInheritableToscaType parent = element;
        int levelCount = 0;
        while (true) {
            if (parent.getDerivedFrom() == null || parent.getDerivedFrom().isEmpty()) {
                break;
            }
            AbstractInheritableToscaType oldParent = parent;
            parent = elementsByIdMap.get(parent.getDerivedFrom().get(0));
            if (parent == null) {
                break;
            }
            if (oldParent.equals(parent)) {
                // This error must have been normally detected in the validation phase and so here it means that it's a bug in our code of validation
                throw new IndexingServiceException(parent.getElementId() + " is parent of it-self, bug in csar validation service");
            }
            levelCount++;
        }
        elementsLevelMap.put(element.getElementId(), levelCount);
    }
    Collections.sort(orderedElements, (left, right) -> elementsLevelMap.get(left.getElementId()).compareTo(elementsLevelMap.get(right.getElementId())));
    return orderedElements;
}
Also used : IndexingServiceException(alien4cloud.exception.IndexingServiceException) ArrayList(java.util.ArrayList) AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType)

Example 7 with IndexingServiceException

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

the class AuditESDAO method init.

@PostConstruct
public void init() {
    try {
        getMappingBuilder().initialize("alien4cloud.audit.model");
    } catch (IntrospectionException | IOException e) {
        throw new IndexingServiceException("Could not initialize elastic search mapping builder", e);
    }
    // Audit trace index
    initIndices(ALIEN_AUDIT_INDEX, auditTtl, AuditTrace.class, AuditConfiguration.class);
    initCompleted();
}
Also used : IndexingServiceException(alien4cloud.exception.IndexingServiceException) IntrospectionException(java.beans.IntrospectionException) IOException(java.io.IOException) PostConstruct(javax.annotation.PostConstruct)

Example 8 with IndexingServiceException

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

the class ElasticSearchGroupDao method initEnvironment.

@PostConstruct
public void initEnvironment() {
    // init ES annotation scanning
    try {
        mappingBuilder.initialize(Group.class.getPackage().getName());
    } catch (IntrospectionException | IOException e) {
        throw new IndexingServiceException("Could not initialize elastic search mapping builder", e);
    }
    // init indexes and mapped classes
    initIndices(Group.class.getSimpleName().toLowerCase(), null, new Class<?>[] { Group.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