Search in sources :

Example 6 with Container

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());
}
Also used : Container(org.talend.sdk.component.container.Container) ContainerManager(org.talend.sdk.component.container.ContainerManager) ArrayList(java.util.ArrayList) ContainerListener(org.talend.sdk.component.container.ContainerListener) Test(org.junit.jupiter.api.Test)

Example 7 with Container

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());
    }
}
Also used : Container(org.talend.sdk.component.container.Container) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) RepositoryModel(org.talend.sdk.component.design.extension.RepositoryModel) File(java.io.File) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 8 with Container

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));
}
Also used : ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Container(org.talend.sdk.component.container.Container) ComponentContexts(org.talend.sdk.component.runtime.manager.extension.ComponentContexts) Optional.ofNullable(java.util.Optional.ofNullable) Collection(java.util.Collection) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) Stream(java.util.stream.Stream) FlowsFactory(org.talend.sdk.component.design.extension.flows.FlowsFactory) RepositoryModelBuilder(org.talend.sdk.component.design.extension.repository.RepositoryModelBuilder) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) MigrationHandlerFactory(org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory) ContainerListenerExtension(org.talend.sdk.component.runtime.manager.spi.ContainerListenerExtension) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension) ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) FlowsFactory(org.talend.sdk.component.design.extension.flows.FlowsFactory) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension)

Example 9 with Container

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);
    }
}
Also used : ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Container(org.talend.sdk.component.container.Container) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager)

Example 10 with Container

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();
}
Also used : ErrorPayload(org.talend.sdk.component.server.front.model.error.ErrorPayload) Container(org.talend.sdk.component.container.Container) IconResolver(org.talend.sdk.component.server.service.IconResolver) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

Container (org.talend.sdk.component.container.Container)13 ComponentManager (org.talend.sdk.component.runtime.manager.ComponentManager)6 File (java.io.File)4 Stream (java.util.stream.Stream)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 Test (org.junit.jupiter.api.Test)4 ErrorPayload (org.talend.sdk.component.server.front.model.error.ErrorPayload)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 Locale (java.util.Locale)3 Optional.ofNullable (java.util.Optional.ofNullable)3 ComponentFamilyMeta (org.talend.sdk.component.runtime.manager.ComponentFamilyMeta)3 Collections.singletonList (java.util.Collections.singletonList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Collectors.toList (java.util.stream.Collectors.toList)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Data (lombok.Data)2 ContainerManager (org.talend.sdk.component.container.ContainerManager)2 ContainerComponentRegistry (org.talend.sdk.component.runtime.manager.ContainerComponentRegistry)2