Search in sources :

Example 11 with ComponentManager

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

the class RecordBranchFilterTest method test.

@Test
public void test() {
    final ComponentManager instance = ComponentManager.instance();
    final JsonBuilderFactory factory = instance.getJsonpBuilderFactory();
    PAssert.that(buildBaseJsonPipeline(pipeline, factory).apply(RecordBranchFilter.of(null, "b1"))).satisfies(values -> {
        final List<JsonObject> items = StreamSupport.stream(values.spliterator(), false).collect(toList());
        assertEquals(2, items.size());
        items.forEach(item -> {
            assertTrue(item.containsKey("b1"));
            assertNotNull(item.getJsonArray("b1").getJsonObject(0).getString("foo"));
            assertFalse(item.containsKey("b2"));
        });
        return null;
    });
    assertEquals(PipelineResult.State.DONE, pipeline.run().waitUntilFinish());
}
Also used : JsonBuilderFactory(javax.json.JsonBuilderFactory) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 12 with ComponentManager

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

the class RecordBranchMapperTest method test.

@Test
public void test() {
    final ComponentManager instance = ComponentManager.instance();
    final JsonBuilderFactory factory = instance.getJsonpBuilderFactory();
    PAssert.that(buildBaseJsonPipeline(pipeline, factory).apply(RecordBranchMapper.of(null, "b1", "other"))).satisfies(values -> {
        final List<JsonObject> items = StreamSupport.stream(values.spliterator(), false).collect(toList());
        assertEquals(2, items.size());
        items.forEach(item -> {
            assertTrue(item.containsKey("other"));
            assertNotNull(item.getJsonArray("other").getJsonObject(0).getString("foo"));
            assertFalse(item.containsKey("b1"));
            assertTrue(item.containsKey("b2"));
            assertNotNull(item.getJsonArray("b2").getJsonObject(0).getString("bar"));
        });
        return null;
    });
    assertEquals(PipelineResult.State.DONE, pipeline.run().waitUntilFinish());
}
Also used : JsonBuilderFactory(javax.json.JsonBuilderFactory) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 13 with ComponentManager

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

the class RecordBranchUnwrapperTest method test.

@Test
public void test() {
    final ComponentManager instance = ComponentManager.instance();
    final JsonBuilderFactory factory = instance.getJsonpBuilderFactory();
    PAssert.that(buildBaseJsonPipeline(pipeline, factory).apply(RecordBranchMapper.of(null, "b1", "other"))).satisfies(values -> {
        final List<JsonObject> items = StreamSupport.stream(values.spliterator(), false).collect(toList());
        assertEquals(2, items.size());
        items.forEach(item -> {
            assertTrue(item.containsKey("other"));
            assertNotNull(item.getJsonArray("other").getJsonObject(0).getString("foo"));
            assertFalse(item.containsKey("b1"));
            assertTrue(item.containsKey("b2"));
            assertNotNull(item.getJsonArray("b2").getJsonObject(0).getString("bar"));
        });
        return null;
    });
    assertEquals(PipelineResult.State.DONE, pipeline.run().waitUntilFinish());
}
Also used : JsonBuilderFactory(javax.json.JsonBuilderFactory) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) JsonObject(javax.json.JsonObject) Test(org.junit.Test)

Example 14 with ComponentManager

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

the class ComponentManagerBasedMojo method doExecute.

@Override
protected void doExecute() throws MojoExecutionException, MojoFailureException {
    if (!classes.exists()) {
        throw new MojoExecutionException("No " + classes);
    }
    try (final ComponentManager manager = new ComponentManager(repository, "TALEND-INF/dependencies.txt", "org.talend.sdk.component:type=component,value=%s") {

        {
            addPlugin(artifactId, classes.getAbsolutePath());
        }
    }) {
        final Container container = manager.findPlugin(artifactId).get();
        final ContainerComponentRegistry registry = container.get(ContainerComponentRegistry.class);
        registry.getComponents().values().forEach(c -> {
            c.getPartitionMappers().forEach((k, p) -> getLog().info("Found component " + c.getName() + "#" + p.getName()));
            c.getProcessors().forEach((k, p) -> getLog().info("Found component " + c.getName() + "#" + p.getName()));
        });
        doWork(manager, container, registry);
    }
}
Also used : ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Container(org.talend.sdk.component.container.Container) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager)

Example 15 with ComponentManager

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

the class Main method main.

public static void main(final String[] args) throws IOException {
    final Config options = PipelineOptionsFactory.fromArgs(args).as(Config.class);
    final Pipeline pipeline = Pipeline.create(options);
    try (final FileWriter writer = new FileWriter(options.getInputFile())) {
        writer.write("normal;6\nmarilyn;36");
    }
    final ComponentManager manager = ComponentManager.instance();
    pipeline.apply(TalendIO.read(manager.findMapper("sample", "reader", 1, new HashMap<String, String>() {

        {
            // will be migrated to "file" with the migration handler
            put("old_file", options.getInputFile());
        }
    }).orElseThrow(() -> new IllegalArgumentException("No reader sample#reader, existing: " + manager.availablePlugins())))).apply(new ViewsMappingTransform(emptyMap(), "sample")).apply(TalendFn.asFn(manager.findProcessor("sample", "mapper", 1, emptyMap()).orElseThrow(() -> new IllegalStateException("didn't find the processor")))).apply(ParDo.of(new ToStringFn())).apply(TextIO.write().to(ValueProvider.StaticValueProvider.of(options.getOutputFile())));
    final PipelineResult.State state = pipeline.run().waitUntilFinish();
    System.out.println(state);
}
Also used : HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) PipelineResult(org.apache.beam.sdk.PipelineResult) ViewsMappingTransform(org.talend.sdk.component.runtime.beam.transform.ViewsMappingTransform) Pipeline(org.apache.beam.sdk.Pipeline)

Aggregations

ComponentManager (org.talend.sdk.component.runtime.manager.ComponentManager)21 Test (org.junit.jupiter.api.Test)12 File (java.io.File)8 JsonObject (javax.json.JsonObject)8 List (java.util.List)7 Collectors.toList (java.util.stream.Collectors.toList)7 Collection (java.util.Collection)6 HashMap (java.util.HashMap)6 Jsonb (javax.json.bind.Jsonb)6 AllArgsConstructor (lombok.AllArgsConstructor)6 Data (lombok.Data)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Serializable (java.io.Serializable)5 ArrayList (java.util.ArrayList)5 Collections.singletonMap (java.util.Collections.singletonMap)5 Map (java.util.Map)5 Optional (java.util.Optional)5 PrimitiveIterator (java.util.PrimitiveIterator)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 IntStream (java.util.stream.IntStream)5