Search in sources :

Example 1 with MigrationHandlerFactory

use of org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory in project component-runtime by Talend.

the class DesignContainerListener method onCreate.

/**
 * Enriches {@link Container} with {@link DesignModel} and
 * {@link RepositoryModel} It depends on Updater listener which adds
 * {@link ContainerComponentRegistry} class to {@link Container}
 */
@Override
public void onCreate(final Container container) {
    final ContainerComponentRegistry componentRegistry = container.get(ContainerComponentRegistry.class);
    if (componentRegistry == null) {
        throw new IllegalArgumentException("container doesn't contain ContainerComponentRegistry");
    }
    final Collection<ComponentFamilyMeta> componentFamilyMetas = componentRegistry.getComponents().values();
    // Create Design Model
    componentFamilyMetas.stream().flatMap(family -> Stream.concat(family.getPartitionMappers().values().stream(), family.getProcessors().values().stream())).forEach(meta -> {
        final ComponentExtension.ComponentContext context = container.get(ComponentContexts.class).getContexts().get(meta.getType());
        final ComponentExtension owningExtension = context.owningExtension();
        meta.set(DesignModel.class, ofNullable(owningExtension).map(e -> e.unwrap(FlowsFactory.class, meta)).map(e -> new DesignModel(meta.getId(), e.getInputFlows(), e.getOutputFlows())).orElseGet(() -> {
            final FlowsFactory factory = FlowsFactory.get(meta);
            return new DesignModel(meta.getId(), factory.getInputFlows(), factory.getOutputFlows());
        }));
    });
    // Create Repository Model
    container.set(RepositoryModel.class, repositoryModelBuilder.create(container.get(ComponentManager.AllServices.class), componentFamilyMetas, migrationHandlerFactory));
}
Also used : ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Container(org.talend.sdk.component.container.Container) ComponentContexts(org.talend.sdk.component.runtime.manager.extension.ComponentContexts) Optional.ofNullable(java.util.Optional.ofNullable) Collection(java.util.Collection) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) Stream(java.util.stream.Stream) FlowsFactory(org.talend.sdk.component.design.extension.flows.FlowsFactory) RepositoryModelBuilder(org.talend.sdk.component.design.extension.repository.RepositoryModelBuilder) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) MigrationHandlerFactory(org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory) ContainerListenerExtension(org.talend.sdk.component.runtime.manager.spi.ContainerListenerExtension) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension) ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) FlowsFactory(org.talend.sdk.component.design.extension.flows.FlowsFactory) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension)

Example 2 with MigrationHandlerFactory

use of org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory in project component-runtime by Talend.

the class RepositoryModelBuilderTest method notRootConfig.

@Test
void notRootConfig() {
    final RepositoryModel model = new RepositoryModelBuilder().create(new ComponentManager.AllServices(emptyMap()), singleton(new ComponentFamilyMeta("test", emptyList(), "noicon", "test", "test") {

        {
            final ParameterMeta store = new ParameterMeta(null, DataStore1.class, ParameterMeta.Type.OBJECT, "config.store", "store", new String[0], emptyList(), emptyList(), new HashMap<String, String>() {

                {
                    put("tcomp::configurationtype::type", "datastore");
                    put("tcomp::configurationtype::name", "testDatastore");
                }
            });
            final ParameterMeta wrapper = new ParameterMeta(null, WrappingStore.class, ParameterMeta.Type.OBJECT, "config", "config", new String[0], singletonList(store), emptyList(), emptyMap());
            getPartitionMappers().put("test", new PartitionMapperMeta(this, "mapper", "noicon", 1, PartitionMapper1.class, singletonList(wrapper), m -> null, (a, b) -> null, true) {
            });
        }
    }), new MigrationHandlerFactory(new ReflectionService(new ParameterModelService())));
    final List<Config> configs = model.getFamilies().stream().flatMap(f -> f.getConfigs().stream()).collect(toList());
    assertEquals(1, configs.size());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) HashMap(java.util.HashMap) ClassReader(org.apache.xbean.asm6.ClassReader) Collections.singletonList(java.util.Collections.singletonList) DataStore1(org.talend.test.DataStore1) JarEntry(java.util.jar.JarEntry) Collections.singleton(java.util.Collections.singleton) ClassRemapper(org.apache.xbean.asm6.commons.ClassRemapper) WithTemporaryFolder(org.talend.sdk.component.junit.base.junit5.WithTemporaryFolder) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EXPAND_FRAMES(org.apache.xbean.asm6.ClassReader.EXPAND_FRAMES) JarOutputStream(java.util.jar.JarOutputStream) Remapper(org.apache.xbean.asm6.commons.Remapper) ParameterMeta(org.talend.sdk.component.runtime.manager.ParameterMeta) Collections.emptyMap(java.util.Collections.emptyMap) COMPUTE_FRAMES(org.apache.xbean.asm6.ClassWriter.COMPUTE_FRAMES) Container(org.talend.sdk.component.container.Container) Collections.emptyList(java.util.Collections.emptyList) Optional.ofNullable(java.util.Optional.ofNullable) FileOutputStream(java.io.FileOutputStream) WrappingStore(org.talend.test.WrappingStore) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IdGenerator(org.talend.sdk.component.runtime.manager.util.IdGenerator) File(java.io.File) TestInfo(org.junit.jupiter.api.TestInfo) RepositoryModel(org.talend.sdk.component.design.extension.RepositoryModel) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) TemporaryFolder(org.talend.sdk.component.junit.base.junit5.TemporaryFolder) JarLocation.jarLocation(org.apache.ziplock.JarLocation.jarLocation) ClassWriter(org.apache.xbean.asm6.ClassWriter) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) MigrationHandlerFactory(org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory) ReflectionService(org.talend.sdk.component.runtime.manager.reflect.ReflectionService) InputStream(java.io.InputStream) PartitionMapper1(org.talend.test.PartitionMapper1) RepositoryModel(org.talend.sdk.component.design.extension.RepositoryModel) ReflectionService(org.talend.sdk.component.runtime.manager.reflect.ReflectionService) PartitionMapper1(org.talend.test.PartitionMapper1) ParameterMeta(org.talend.sdk.component.runtime.manager.ParameterMeta) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) ParameterModelService(org.talend.sdk.component.runtime.manager.reflect.ParameterModelService) MigrationHandlerFactory(org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory) Test(org.junit.jupiter.api.Test)

Aggregations

Optional.ofNullable (java.util.Optional.ofNullable)2 Stream (java.util.stream.Stream)2 Container (org.talend.sdk.component.container.Container)2 ComponentFamilyMeta (org.talend.sdk.component.runtime.manager.ComponentFamilyMeta)2 ComponentManager (org.talend.sdk.component.runtime.manager.ComponentManager)2 MigrationHandlerFactory (org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singleton (java.util.Collections.singleton)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 JarEntry (java.util.jar.JarEntry)1 JarOutputStream (java.util.jar.JarOutputStream)1