use of org.talend.sdk.component.container.Container in project component-runtime by Talend.
the class ContainerManagerTest method listeners.
@Test
void listeners(final TempJars jars) {
final Collection<String> states = new ArrayList<>();
final ContainerListener listener = new ContainerListener() {
@Override
public void onCreate(final Container container) {
states.add("deploy #" + container.getId());
}
@Override
public void onClose(final Container container) {
states.add("undeploy #" + container.getId());
}
};
try (final ContainerManager manager = createDefaultManager().registerListener(listener)) {
assertEquals(emptyList(), states);
try (final Container container = manager.builder(createZiplockJar(jars).getAbsolutePath()).create()) {
assertEquals(1, states.size());
}
assertEquals(2, states.size());
manager.unregisterListener(listener);
try (final Container container = manager.builder(createZiplockJar(jars).getAbsolutePath()).create()) {
assertEquals(2, states.size());
}
assertEquals(2, states.size());
}
assertEquals(2, states.size());
}
use of org.talend.sdk.component.container.Container in project component-runtime by Talend.
the class RepositoryModelBuilderTest method test.
@Test
void test(final TemporaryFolder temporaryFolder, final TestInfo testInfo) throws Exception {
final String pluginName = testInfo.getTestMethod().get().getName() + ".jar";
final File pluginJar = createChainPlugin(temporaryFolder.getRoot(), pluginName);
try (final ComponentManager manager = new ComponentManager(new File("target/fake-m2"), "TALEND-INF/dependencies.txt", null)) {
manager.addPlugin(pluginJar.getAbsolutePath());
Container pluginContainer = manager.findPlugin(pluginName).orElseThrow(() -> new Exception("test plugin don't exist"));
assertNotNull(pluginContainer);
RepositoryModel rm = pluginContainer.get(RepositoryModel.class);
assertNotNull(rm);
assertEquals(1, rm.getFamilies().size());
Family family = rm.getFamilies().get(0);
String ds1Id = IdGenerator.get("family1", "datastore", "dataStore1");
Config dataStore1Config = family.getConfigs().stream().filter(c -> c.getId().equals(ds1Id)).findFirst().get();
assertNotNull(dataStore1Config);
assertEquals(1, dataStore1Config.getChildConfigs().size());
assertEquals("configuration1", dataStore1Config.getChildConfigs().get(0).getMeta().getName());
String ds2Id = IdGenerator.get("family1", "datastore", "dataStore2");
Config dataStore2Config = family.getConfigs().stream().filter(c -> c.getId().equals(ds2Id)).findFirst().get();
assertNotNull(dataStore2Config);
assertEquals(1, dataStore2Config.getChildConfigs().size());
assertEquals("configuration2", dataStore2Config.getChildConfigs().get(0).getMeta().getName());
}
}
use of org.talend.sdk.component.container.Container 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));
}
use of org.talend.sdk.component.container.Container 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.container.Container in project component-runtime by Talend.
the class ComponentResource method icon.
/**
* Returns a particular component icon in raw bytes.
*
* @param id the component identifier.
* @return the component icon in binary form.
*/
@GET
@Path("icon/{id}")
public Response icon(@PathParam("id") final String id) {
// todo: add caching if SvgIconResolver becomes used a lot - not the case ATM
final ComponentFamilyMeta.BaseMeta<Object> meta = componentDao.findById(id);
if (meta == null) {
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorPayload(ErrorDictionary.COMPONENT_MISSING, "No component for identifier: " + id)).type(APPLICATION_JSON_TYPE).build();
}
final Optional<Container> plugin = manager.findPlugin(meta.getParent().getPlugin());
if (!plugin.isPresent()) {
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorPayload(ErrorDictionary.PLUGIN_MISSING, "No plugin '" + meta.getParent().getPlugin() + "' for identifier: " + id)).type(APPLICATION_JSON_TYPE).build();
}
final IconResolver.Icon iconContent = iconResolver.resolve(plugin.get().getLoader(), meta.getIcon());
if (iconContent == null) {
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorPayload(ErrorDictionary.ICON_MISSING, "No icon for identifier: " + id)).type(APPLICATION_JSON_TYPE).build();
}
return Response.ok(iconContent.getBytes()).type(iconContent.getType()).build();
}
Aggregations