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()));
}
}
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()));
}
}
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());
}
}
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());
}
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());
}
Aggregations