Search in sources :

Example 16 with ComponentManager

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

the class JobTest method defaultKeyProvider.

@Test
void defaultKeyProvider(final TestInfo info, final TemporaryFolder temporaryFolder) throws IOException {
    final String testName = info.getTestMethod().get().getName();
    final String plugin = testName + ".jar";
    final File jar = pluginGenerator.createChainPlugin(temporaryFolder.getRoot(), plugin);
    final File out = new File(temporaryFolder.getRoot(), testName + "-out.txt");
    try (final ComponentManager manager = new ComponentManager(new File("target/fake-m2"), "TALEND-INF/dependencies.txt", null) {

        {
            CONTEXTUAL_INSTANCE.set(this);
            addPlugin(jar.getAbsolutePath());
        }

        @Override
        public void close() {
            super.close();
            CONTEXTUAL_INSTANCE.set(null);
        }
    }) {
        Job.components().component("users", "db://input?__version=1&tableName=users").component("address", "db://input?__version=1&tableName=address").component("salary", "db://input?__version=1&tableName=salary").component("concat", "processor://concat?__version=1").component("concat_2", "processor://concat?__version=1").component("outFile", "file://out?__version=1&file=" + encode(out.getAbsolutePath(), "utf-8")).connections().from("users").to("concat", "str1").from("address").to("concat", "str2").from("concat").to("concat_2", "str1").from("salary").to("concat_2", "str2").from("concat_2").to("outFile").build().run();
        assertTrue(out.isFile());
        assertEquals(asList("sophia paris 1900", "emma nantes 3055", "liam strasbourg 2600.30", "ava lyon 2000.5"), Files.readAllLines(out.toPath()));
    }
}
Also used : ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 17 with ComponentManager

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

the class JobTest method contextualKeyProvider.

@Test
void contextualKeyProvider(final TestInfo info, final TemporaryFolder temporaryFolder) throws IOException {
    final String testName = info.getTestMethod().get().getName();
    final String plugin = testName + ".jar";
    final File jar = pluginGenerator.createChainPlugin(temporaryFolder.getRoot(), plugin);
    final File out = new File(temporaryFolder.getRoot(), testName + "-out.txt");
    try (final ComponentManager manager = new ComponentManager(new File("target/fake-m2"), "TALEND-INF/dependencies.txt", null) {

        {
            CONTEXTUAL_INSTANCE.set(this);
            addPlugin(jar.getAbsolutePath());
        }

        @Override
        public void close() {
            super.close();
            CONTEXTUAL_INSTANCE.set(null);
        }
    }) {
        final GroupKeyProvider foreignKeyProvider = (GroupKeyProvider) context -> context.getData().getString("userId");
        Job.components().component("users", "db://input?__version=1&tableName=users").property(GroupKeyProvider.class.getName(), (GroupKeyProvider) context -> context.getData().getString("id")).component("address", "db://input?__version=1&tableName=address").property(GroupKeyProvider.class.getName(), foreignKeyProvider).component("salary", "db://input?__version=1&tableName=salary").property(GroupKeyProvider.class.getName(), foreignKeyProvider).component("concat", "processor://concat?__version=1").property(GroupKeyProvider.class.getName(), foreignKeyProvider).component("concat_2", "processor://concat?__version=1").component("outFile", "file://out?__version=1&file=" + encode(out.getAbsolutePath(), "utf-8")).connections().from("users").to("concat", "str1").from("address").to("concat", "str2").from("concat").to("concat_2", "str1").from("salary").to("concat_2", "str2").from("concat_2").to("outFile").build().run();
        assertTrue(out.isFile());
        assertEquals(asList("emma strasbourg 1900", "sophia nantes 2000.5", "liam lyon 3055", "ava paris 2600.30"), Files.readAllLines(out.toPath()));
    }
}
Also used : ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 18 with ComponentManager

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

the class ComponentMetadataMojo method doWork.

@Override
protected void doWork(final ComponentManager manager, final Container container, final ContainerComponentRegistry registry) throws MojoExecutionException, MojoFailureException {
    final File output = new File(classes, location);
    if (!output.getParentFile().exists() && !output.getParentFile().mkdirs()) {
        throw new MojoExecutionException("Can't create " + output);
    }
    final Collection<Component> components = registry.getComponents().values().stream().flatMap(c -> Stream.concat(c.getPartitionMappers().values().stream().map(p -> new Component(p.getParent().getCategories(), p.getParent().getName(), p.getName(), p.findBundle(container.getLoader(), Locale.ENGLISH).displayName().orElse(p.getName()), p.getIcon(), emptyList(), singletonList("MAIN"))), c.getProcessors().values().stream().map(p -> {
        final Method listener = p.getListener();
        return new Component(p.getParent().getCategories(), p.getParent().getName(), p.getName(), p.findBundle(container.getLoader(), Locale.ENGLISH).displayName().orElse(p.getName()), p.getIcon(), getDesignModel(p).getInputFlows(), getDesignModel(p).getOutputFlows());
    }))).collect(toList());
    try (final Jsonb mapper = inPluginContext(JsonbBuilder::newBuilder).withConfig(new JsonbConfig().setProperty("johnzon.cdi.activated", false).setProperty("johnzon.attributeOrder", String.CASE_INSENSITIVE_ORDER)).build()) {
        container.execute(() -> {
            try {
                mapper.toJson(new ComponentContainer(components), new FileOutputStream(output));
            } catch (final FileNotFoundException e) {
                throw new IllegalStateException(e);
            }
            getLog().info("Created " + output);
            return null;
        });
    } catch (final Exception e) {
        throw new MojoExecutionException(e.getMessage());
    }
}
Also used : JsonbBuilder(javax.json.bind.JsonbBuilder) ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Container(org.talend.sdk.component.container.Container) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) FileOutputStream(java.io.FileOutputStream) Parameter(org.apache.maven.plugins.annotations.Parameter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JsonbConfig(javax.json.bind.JsonbConfig) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Collections.singletonList(java.util.Collections.singletonList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Mojo(org.apache.maven.plugins.annotations.Mojo) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Locale(java.util.Locale) PROCESS_CLASSES(org.apache.maven.plugins.annotations.LifecyclePhase.PROCESS_CLASSES) Data(lombok.Data) Jsonb(javax.json.bind.Jsonb) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) COMPILE_PLUS_RUNTIME(org.apache.maven.plugins.annotations.ResolutionScope.COMPILE_PLUS_RUNTIME) AllArgsConstructor(lombok.AllArgsConstructor) Method(java.lang.reflect.Method) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JsonbBuilder(javax.json.bind.JsonbBuilder) FileNotFoundException(java.io.FileNotFoundException) Method(java.lang.reflect.Method) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Jsonb(javax.json.bind.Jsonb) JsonbConfig(javax.json.bind.JsonbConfig) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 19 with ComponentManager

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

the class DIBatchSimulationTest method fromBeamToBeam.

@Test
void fromBeamToBeam() {
    final ComponentManager manager = ComponentManager.instance();
    final Collection<Object> sourceData = new ArrayList<>();
    final Collection<Object> processorData = new ArrayList<>();
    To.RECORDS.clear();
    doDi(manager, sourceData, processorData, manager.findProcessor("DIBatchSimulationTest", "to", 1, new HashMap<>()).map(p -> {
        assertTrue(QueueOutput.class.isInstance(p), p.getClass().getName());
        return p;
    }), manager.findMapper("DIBatchSimulationTest", "from", 1, singletonMap("count", "1000")));
    assertEquals(1000, sourceData.size());
    assertEquals(1000, processorData.size());
    assertEquals(1000, To.RECORDS.size());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) IntStream(java.util.stream.IntStream) PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) Producer(org.talend.sdk.component.api.input.Producer) SerializableCoder(org.apache.beam.sdk.coders.SerializableCoder) PBegin(org.apache.beam.sdk.values.PBegin) AutoChunkProcessor(org.talend.sdk.component.runtime.di.AutoChunkProcessor) Getter(lombok.Getter) HashMap(java.util.HashMap) Option(org.talend.sdk.component.api.configuration.Option) OutputFactory(org.talend.sdk.component.runtime.output.OutputFactory) ArrayList(java.util.ArrayList) PTransform(org.apache.beam.sdk.transforms.PTransform) Create(org.apache.beam.sdk.transforms.Create) ElementListener(org.talend.sdk.component.api.processor.ElementListener) InputFactory(org.talend.sdk.component.runtime.output.InputFactory) Map(java.util.Map) ToString(lombok.ToString) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Input(org.talend.sdk.component.runtime.input.Input) JobStateAware(org.talend.sdk.component.runtime.di.JobStateAware) DoFn(org.apache.beam.sdk.transforms.DoFn) Emitter(org.talend.sdk.component.api.input.Emitter) JsonObject(javax.json.JsonObject) PDone(org.apache.beam.sdk.values.PDone) Collection(java.util.Collection) OutputsHandler(org.talend.sdk.component.runtime.di.OutputsHandler) PCollection(org.apache.beam.sdk.values.PCollection) ChainedMapper(org.talend.sdk.component.runtime.manager.chain.ChainedMapper) Processor(org.talend.sdk.component.runtime.output.Processor) Serializable(java.io.Serializable) PrimitiveIterator(java.util.PrimitiveIterator) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Mapper(org.talend.sdk.component.runtime.input.Mapper) Branches(org.talend.sdk.component.runtime.output.Branches) InputsHandler(org.talend.sdk.component.runtime.di.InputsHandler) ParDo(org.apache.beam.sdk.transforms.ParDo) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Data(lombok.Data) Optional(java.util.Optional) Jsonb(javax.json.bind.Jsonb) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) AllArgsConstructor(lombok.AllArgsConstructor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NoArgsConstructor(lombok.NoArgsConstructor) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) JsonObject(javax.json.JsonObject) Test(org.junit.jupiter.api.Test)

Example 20 with ComponentManager

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

the class DIBatchSimulationTest method fromEmptyBeam.

@Test
void fromEmptyBeam() {
    final ComponentManager manager = ComponentManager.instance();
    final Collection<Object> sourceData = new ArrayList<>();
    doDi(manager, sourceData, new ArrayList<>(), manager.findProcessor("DIBatchSimulationTest", "passthroughoutput", 1, new HashMap<>()), manager.findMapper("DIBatchSimulationTest", "from", 1, singletonMap("count", "0")).map(m -> {
        assertTrue(QueueMapper.class.isInstance(m), m.getClass().getName());
        return m;
    }));
    assertEquals(0, sourceData.size());
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) IntStream(java.util.stream.IntStream) PartitionMapper(org.talend.sdk.component.api.input.PartitionMapper) Producer(org.talend.sdk.component.api.input.Producer) SerializableCoder(org.apache.beam.sdk.coders.SerializableCoder) PBegin(org.apache.beam.sdk.values.PBegin) AutoChunkProcessor(org.talend.sdk.component.runtime.di.AutoChunkProcessor) Getter(lombok.Getter) HashMap(java.util.HashMap) Option(org.talend.sdk.component.api.configuration.Option) OutputFactory(org.talend.sdk.component.runtime.output.OutputFactory) ArrayList(java.util.ArrayList) PTransform(org.apache.beam.sdk.transforms.PTransform) Create(org.apache.beam.sdk.transforms.Create) ElementListener(org.talend.sdk.component.api.processor.ElementListener) InputFactory(org.talend.sdk.component.runtime.output.InputFactory) Map(java.util.Map) ToString(lombok.ToString) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Input(org.talend.sdk.component.runtime.input.Input) JobStateAware(org.talend.sdk.component.runtime.di.JobStateAware) DoFn(org.apache.beam.sdk.transforms.DoFn) Emitter(org.talend.sdk.component.api.input.Emitter) JsonObject(javax.json.JsonObject) PDone(org.apache.beam.sdk.values.PDone) Collection(java.util.Collection) OutputsHandler(org.talend.sdk.component.runtime.di.OutputsHandler) PCollection(org.apache.beam.sdk.values.PCollection) ChainedMapper(org.talend.sdk.component.runtime.manager.chain.ChainedMapper) Processor(org.talend.sdk.component.runtime.output.Processor) Serializable(java.io.Serializable) PrimitiveIterator(java.util.PrimitiveIterator) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Mapper(org.talend.sdk.component.runtime.input.Mapper) Branches(org.talend.sdk.component.runtime.output.Branches) InputsHandler(org.talend.sdk.component.runtime.di.InputsHandler) ParDo(org.apache.beam.sdk.transforms.ParDo) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Data(lombok.Data) Optional(java.util.Optional) Jsonb(javax.json.bind.Jsonb) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) AllArgsConstructor(lombok.AllArgsConstructor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NoArgsConstructor(lombok.NoArgsConstructor) HashMap(java.util.HashMap) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) JsonObject(javax.json.JsonObject) Test(org.junit.jupiter.api.Test)

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