use of org.talend.sdk.component.container.Container in project component-runtime by Talend.
the class ComponentResource method getDetail.
/**
* Returns the set of metadata about a few components identified by their 'id'.
*
* @param language the language for display names/placeholders/....
* @param ids the component identifiers to request.
* @return the list of details for the requested components.
*/
// TODO: max ids.length
@GET
// bulk mode to avoid to fetch components one by one when reloading a pipeline/job
@Path("details")
public ComponentDetailList getDetail(@QueryParam("language") @DefaultValue("en") final String language, @QueryParam("identifiers") final String[] ids) {
if (ids == null || ids.length == 0) {
return new ComponentDetailList(emptyList());
}
final Map<String, ErrorPayload> errors = new HashMap<>();
final List<ComponentDetail> details = Stream.of(ids).map(id -> ofNullable(componentDao.findById(id)).orElseGet(() -> {
errors.put(id, new ErrorPayload(COMPONENT_MISSING, "No component '" + id + "'"));
return null;
})).filter(Objects::nonNull).map(meta -> {
final Optional<Container> plugin = manager.findPlugin(meta.getParent().getPlugin());
if (!plugin.isPresent()) {
errors.put(meta.getId(), new ErrorPayload(PLUGIN_MISSING, "No plugin '" + meta.getParent().getPlugin() + "'"));
return null;
}
final Container container = plugin.get();
final Optional<DesignModel> model = ofNullable(meta.get(DesignModel.class));
if (!model.isPresent()) {
errors.put(meta.getId(), new ErrorPayload(DESIGN_MODEL_MISSING, "No design model '" + meta.getId() + "'"));
return null;
}
final Locale locale = localeMapper.mapLocale(language);
final ComponentDetail componentDetail = new ComponentDetail();
componentDetail.setLinks(emptyList());
componentDetail.setId(createMetaId(container, meta));
componentDetail.setVersion(meta.getVersion());
componentDetail.setIcon(meta.getIcon());
componentDetail.setInputFlows(model.get().getInputFlows());
componentDetail.setOutputFlows(model.get().getOutputFlows());
componentDetail.setType(ComponentFamilyMeta.ProcessorMeta.class.isInstance(meta) ? "processor" : "input");
componentDetail.setDisplayName(meta.findBundle(container.getLoader(), locale).displayName().orElse(meta.getName()));
componentDetail.setProperties(propertiesService.buildProperties(meta.getParameterMetas(), container.getLoader(), locale, null).collect(toList()));
componentDetail.setActions(actionsService.findActions(meta.getParent().getName(), container, locale, meta));
return componentDetail;
}).filter(Objects::nonNull).collect(toList());
if (!errors.isEmpty()) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(errors).build());
}
return new ComponentDetailList(details);
}
use of org.talend.sdk.component.container.Container in project component-runtime by Talend.
the class ComponentResource method familyIcon.
/**
* Returns a particular family icon in raw bytes.
*
* @param id the family identifier.
* @return the family icon in binary form.
*/
@GET
@Path("icon/family/{id}")
public Response familyIcon(@PathParam("id") final String id) {
// todo: add caching if SvgIconResolver becomes used a lot - not the case ATM
final ComponentFamilyMeta meta = componentFamilyDao.findById(id);
if (meta == null) {
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorPayload(ErrorDictionary.COMPONENT_MISSING, "No family for identifier: " + id)).type(APPLICATION_JSON_TYPE).build();
}
final Optional<Container> plugin = manager.findPlugin(meta.getPlugin());
if (!plugin.isPresent()) {
return Response.status(Response.Status.NOT_FOUND).entity(new ErrorPayload(ErrorDictionary.PLUGIN_MISSING, "No plugin '" + meta.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 family identifier: " + id)).type(APPLICATION_JSON_TYPE).build();
}
return Response.ok(iconContent.getBytes()).type(iconContent.getType()).build();
}
use of org.talend.sdk.component.container.Container in project component-runtime by Talend.
the class ComponentManagerTest method doCheckRegistry.
private void doCheckRegistry(final File plugin1, final File plugin2, final ComponentManager manager) throws Exception {
Stream.of(plugin1, plugin2).map(File::getAbsolutePath).forEach(manager::addPlugin);
final List<ContainerComponentRegistry> registries = manager.find(c -> Stream.of(c.get(ContainerComponentRegistry.class))).collect(toList());
// we saw both plugin
assertEquals(2, registries.size());
registries.forEach(registry -> {
final Container container = manager.find(c -> registry == c.get(ContainerComponentRegistry.class) ? Stream.of(c) : Stream.empty()).findFirst().get();
assertEquals(1, registry.getServices().size());
assertNotNull(registry.getServices().iterator().next().getInstance());
final Collection<ServiceMeta.ActionMeta> actions = registry.getServices().iterator().next().getActions();
assertEquals(1, actions.size());
assertEquals(pluginGenerator.toPackage(container.getId()) + ".AModel", actions.iterator().next().getInvoker().apply(null).getClass().getName());
assertEquals(1, registry.getComponents().size());
registry.getComponents().forEach((name, component) -> {
assertEquals("comp", name);
assertEquals(name, component.getName());
assertEquals(singletonList("Misc"), component.getCategories());
assertEquals(1, component.getProcessors().size());
component.getProcessors().forEach((procName, processorMeta) -> {
assertEquals("proc", procName);
assertEquals("default", processorMeta.getIcon());
final String packageName = pluginGenerator.toPackage(container.getId());
final Processor processor = processorMeta.getInstantiator().apply(emptyMap());
assertNotNull(processor);
final Object model;
try {
final String className = packageName + ".AModel";
model = container.getLoader().loadClass(className).getConstructor().newInstance();
} catch (final Exception e) {
fail(e.getMessage());
throw new IllegalArgumentException(e);
}
runProcessorLifecycle(model, processor);
});
});
});
// now try to execute the processor outside the correct TCCL and ensure it still
// works
final Container container = manager.find(Stream::of).findFirst().get();
final String packageName = pluginGenerator.toPackage(container.getId());
final ContainerComponentRegistry registry = container.get(ContainerComponentRegistry.class);
final ComponentFamilyMeta componentFamilyMeta = registry.getComponents().values().iterator().next();
final ComponentFamilyMeta.ProcessorMeta processorMeta = componentFamilyMeta.getProcessors().values().iterator().next();
final Processor processor = processorMeta.getInstantiator().apply(emptyMap());
final Object aModel = container.getLoader().loadClass(packageName + ".AModel").getConstructor().newInstance();
runProcessorLifecycle(aModel, processor);
// finally ensure it is serializable
DynamicContainerFinder.LOADERS.clear();
manager.find(Stream::of).forEach(c -> DynamicContainerFinder.LOADERS.put(c.getId(), c.getLoader()));
runProcessorLifecycle(aModel, copy(processor, container.getLoader()));
}
use of org.talend.sdk.component.container.Container in project component-runtime by Talend.
the class StandaloneContainerFinder method find.
// IMPORTANT: don't abuse of lambdas here, it is on the runtime codepath
@Override
public LightContainer find(final String plugin) {
final ComponentManager manager = ComponentManager.instance();
Optional<Container> optionalContainer = manager.findPlugin(plugin);
if (!optionalContainer.isPresent()) {
log.info("Didn't find plugin " + plugin + ", had: " + manager.availablePlugins());
// nested in current jar.
try {
optionalContainer = manager.findPlugin(manager.addPlugin(plugin));
} catch (final IllegalArgumentException iae) {
// concurrent request?
optionalContainer = manager.findPlugin(plugin);
}
}
if (optionalContainer.isPresent()) {
final LightContainer lightContainer = optionalContainer.get().get(LightContainer.class);
if (lightContainer != null) {
return lightContainer;
}
}
// TCCL
return super.find(plugin);
}
use of org.talend.sdk.component.container.Container in project component-runtime by Talend.
the class ContainerManagerTest method autoContainerId.
@Test
void autoContainerId(final TempJars jars) {
Stream.of("ziplock-7.00.3.jar", "ziplock-7.3.jar", "ziplock-7.3-SNAPSHOT.jar", "ziplock-7.3.0-SNAPSHOT.jar").forEach(jarName -> {
try (final ContainerManager manager = createDefaultManager()) {
final File module = createZiplockJar(jars);
final File jar = new File(module.getParentFile(), jarName);
assertTrue(module.renameTo(jar));
final Container container = manager.builder(jar.getAbsolutePath()).create();
assertEquals("ziplock", /* no version, no .jar */
container.getId());
}
});
}
Aggregations