Search in sources :

Example 1 with ConfigurationUtil

use of org.apache.ignite.internal.configuration.util.ConfigurationUtil in project ignite-3 by apache.

the class ConfigurationRegistry method polymorphicExtensionsWithCheck.

/**
 * Get polymorphic extensions of configuration schemas with checks.
 *
 * @param allSchemas                  All configuration schemas.
 * @param polymorphicSchemaExtensions Polymorphic extensions ({@link PolymorphicConfigInstance}) of configuration schemas.
 * @return Mapping: polymorphic scheme -> extensions (instances) of polymorphic configuration.
 * @throws IllegalArgumentException If the schema extension is invalid.
 */
private Map<Class<?>, Set<Class<?>>> polymorphicExtensionsWithCheck(Set<Class<?>> allSchemas, Collection<Class<?>> polymorphicSchemaExtensions) {
    Map<Class<?>, Set<Class<?>>> polymorphicExtensionsByParent = polymorphicSchemaExtensions(polymorphicSchemaExtensions);
    Set<Class<?>> notInAllSchemas = difference(polymorphicExtensionsByParent.keySet(), allSchemas);
    if (!notInAllSchemas.isEmpty()) {
        throw new IllegalArgumentException("Polymorphic extensions for which no polymorphic configuration schemas were found: " + notInAllSchemas);
    }
    Collection<Class<?>> noPolymorphicExtensionsSchemas = allSchemas.stream().filter(ConfigurationUtil::isPolymorphicConfig).filter(not(polymorphicExtensionsByParent::containsKey)).collect(toList());
    if (!noPolymorphicExtensionsSchemas.isEmpty()) {
        throw new IllegalArgumentException("Polymorphic configuration schemas for which no extensions were found: " + noPolymorphicExtensionsSchemas);
    }
    checkPolymorphicConfigIds(polymorphicExtensionsByParent);
    for (Map.Entry<Class<?>, Set<Class<?>>> e : polymorphicExtensionsByParent.entrySet()) {
        Class<?> schemaClass = e.getKey();
        Field typeIdField = schemaFields(schemaClass).get(0);
        if (!isPolymorphicId(typeIdField)) {
            throw new IllegalArgumentException(String.format("First field in a polymorphic configuration schema must contain @%s: %s", PolymorphicId.class, schemaClass.getName()));
        }
    }
    return polymorphicExtensionsByParent;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ConfigurationUtil(org.apache.ignite.internal.configuration.util.ConfigurationUtil) Field(java.lang.reflect.Field) PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) ConfigurationUtil.isPolymorphicId(org.apache.ignite.internal.configuration.util.ConfigurationUtil.isPolymorphicId) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 PolymorphicId (org.apache.ignite.configuration.annotation.PolymorphicId)1 ConfigurationUtil (org.apache.ignite.internal.configuration.util.ConfigurationUtil)1 ConfigurationUtil.isPolymorphicId (org.apache.ignite.internal.configuration.util.ConfigurationUtil.isPolymorphicId)1