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