Search in sources :

Example 1 with ExecutionEngine

use of org.talend.components.api.component.runtime.ExecutionEngine in project components by Talend.

the class RuntimeControllerImpl method writeData.

@Override
public void writeData(InputStream rawPayload) throws IOException {
    // 1) Read payload (with data as a stream of course)
    DatasetWritePayload payload = DatasetWritePayload.readData(rawPayload, mapper);
    String definitionName = payload.getConfiguration().getDefinitionName();
    // 2) Create properties
    Properties properties = propertiesHelpers.propertiesFromDto(payload.getConfiguration());
    if (properties instanceof ComponentProperties) {
        ComponentProperties componentProperties = (ComponentProperties) properties;
        // 3) Retrieve component definition to be able to create the runtime
        final ComponentDefinition definition = propertiesHelpers.getDefinition(ComponentDefinition.class, definitionName);
        // 4) Get the execution engine
        ExecutionEngine executionEngine;
        if (definition.isSupportingExecutionEngines(DI)) {
            executionEngine = DI;
            // 5) Create the sandbox
            try (SandboxedInstance instance = RuntimeUtil.createRuntimeClass(definition.getRuntimeInfo(executionEngine, componentProperties, INCOMING), definition.getClass().getClassLoader())) {
                Sink datasetRuntimeInstance = (Sink) instance.getInstance();
                datasetRuntimeInstance.initialize(null, componentProperties);
                Iterator<IndexedRecord> data = payload.getData();
                WriteOperation writeOperation = datasetRuntimeInstance.createWriteOperation();
                // Supplier return null to signify end of data stream => see WriterDataSupplier.writeData
                WriterDataSupplier<?, IndexedRecord> stringWriterDataSupplier = new WriterDataSupplier<Object, IndexedRecord>(writeOperation, () -> data.hasNext() ? data.next() : null, null);
                stringWriterDataSupplier.writeData();
            }
        } else if (definition.isSupportingExecutionEngines(BEAM)) {
            throw new UnsupportedOperationException("Beam runtime is not available for dataset write through HTTP API.");
        } else {
            throw new TalendRuntimeException(CommonErrorCodes.UNREGISTERED_DEFINITION);
        }
    } else if (properties instanceof DatasetProperties) {
        throw new UnsupportedOperationException("HTTP API is only able to write using component implementations. Not " + properties.getClass());
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) DatasetProperties(org.talend.components.common.dataset.DatasetProperties) DatasetProperties(org.talend.components.common.dataset.DatasetProperties) DatastoreProperties(org.talend.components.common.datastore.DatastoreProperties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) Properties(org.talend.daikon.properties.Properties) SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) ExecutionEngine(org.talend.components.api.component.runtime.ExecutionEngine) Sink(org.talend.components.api.component.runtime.Sink) WriteOperation(org.talend.components.api.component.runtime.WriteOperation) WriterDataSupplier(org.talend.components.api.component.runtime.WriterDataSupplier) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Example 2 with ExecutionEngine

use of org.talend.components.api.component.runtime.ExecutionEngine in project components by Talend.

the class DefinitionsControllerTest method shouldFilterComponentsByTypologyAndExecutionEngine.

public void shouldFilterComponentsByTypologyAndExecutionEngine(ConnectorTypology wantedTypology, ExecutionEngine executionEngine, int expectedResults) throws IOException {
    // given
    Map<String, ComponentDefinition> definitions = getComponentsDefinitions();
    // 
    BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)).willReturn(definitions);
    // when
    final Response response = when().get(getVersionPrefix() + "/definitions/components?typology=" + wantedTypology + "&executionEngine=" + executionEngine.name()).andReturn();
    // then
    assertEquals(OK.value(), response.getStatusCode());
    List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
    });
    assertEquals(expectedResults, actual.size());
    assertEquals(expectedResults, actual.stream().filter(dto -> dto.getTypologies().contains(wantedTypology.name())).filter(dto -> dto.getExecutionEngines().contains(executionEngine.name())).count());
}
Also used : Response(com.jayway.restassured.response.Response) DefinitionsController(org.talend.components.service.rest.DefinitionsController) MockComponentDefinition(org.talend.components.service.rest.mock.MockComponentDefinition) Autowired(org.springframework.beans.factory.annotation.Autowired) DATA_STORE(org.talend.components.service.rest.DefinitionType.DATA_STORE) HashMap(java.util.HashMap) Definition(org.talend.daikon.definition.Definition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition) NONE(org.talend.components.api.component.ConnectorTopology.NONE) Function(java.util.function.Function) ExecutionEngine(org.talend.components.api.component.runtime.ExecutionEngine) Response(com.jayway.restassured.response.Response) OUTGOING(org.talend.components.api.component.ConnectorTopology.OUTGOING) TRANSFORMER(org.talend.components.service.rest.dto.ConnectorTypology.TRANSFORMER) SOURCE(org.talend.components.service.rest.dto.ConnectorTypology.SOURCE) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Matchers.hasSize(org.hamcrest.Matchers.hasSize) INCOMING_AND_OUTGOING(org.talend.components.api.component.ConnectorTopology.INCOMING_AND_OUTGOING) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonParseException(com.fasterxml.jackson.core.JsonParseException) RestAssured.when(com.jayway.restassured.RestAssured.when) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) BDDMockito(org.mockito.BDDMockito) List(java.util.List) DatastoreDefinition(org.talend.components.common.datastore.DatastoreDefinition) MockDatastoreDefinition(org.talend.components.service.rest.mock.MockDatastoreDefinition) CONFIGURATION(org.talend.components.service.rest.dto.ConnectorTypology.CONFIGURATION) COMPONENT(org.talend.components.service.rest.DefinitionType.COMPONENT) ServiceConstants(org.talend.components.service.rest.ServiceConstants) AbstractSpringIntegrationTests(org.talend.components.service.rest.AbstractSpringIntegrationTests) INCOMING(org.talend.components.api.component.ConnectorTopology.INCOMING) SINK(org.talend.components.service.rest.dto.ConnectorTypology.SINK) ConnectorTypology(org.talend.components.service.rest.dto.ConnectorTypology) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) OK(org.springframework.http.HttpStatus.OK) DefinitionType(org.talend.components.service.rest.DefinitionType) Assert.assertEquals(org.junit.Assert.assertEquals) DefinitionDTO(org.talend.components.service.rest.dto.DefinitionDTO) Arrays.asList(java.util.Arrays.asList) List(java.util.List) MockComponentDefinition(org.talend.components.service.rest.mock.MockComponentDefinition) ComponentDefinition(org.talend.components.api.component.ComponentDefinition)

Example 3 with ExecutionEngine

use of org.talend.components.api.component.runtime.ExecutionEngine in project components by Talend.

the class TJDBCRowDefinitionTest method testGetRuntimeInfo.

/**
 * Run the RuntimeInfo getRuntimeInfo(ExecutionEngine,ComponentProperties,ConnectorTopology) method test.
 *
 * @throws Exception
 *
 * @generatedBy CodePro at 17-6-20 PM3:14
 */
@Test
public void testGetRuntimeInfo() throws Exception {
    AllSetting allSetting = Mockito.mock(AllSetting.class);
    Mockito.when(allSetting.getDriverClass()).thenReturn("anyDriverClass");
    TJDBCRowProperties properties = Mockito.mock(TJDBCRowProperties.class);
    Mockito.when(properties.getRuntimeSetting()).thenReturn(allSetting);
    TJDBCRowDefinition fixture = new TJDBCRowDefinition();
    ExecutionEngine engine = ExecutionEngine.DI;
    RuntimeInfo result = fixture.getRuntimeInfo(engine, properties, ConnectorTopology.INCOMING);
    assertNotNull(result);
    result = fixture.getRuntimeInfo(engine, properties, ConnectorTopology.OUTGOING);
    assertNotNull(result);
    result = fixture.getRuntimeInfo(engine, properties, ConnectorTopology.NONE);
    assertNotNull(result);
    result = fixture.getRuntimeInfo(engine, properties, ConnectorTopology.INCOMING_AND_OUTGOING);
    assertNotNull(result);
}
Also used : ExecutionEngine(org.talend.components.api.component.runtime.ExecutionEngine) AllSetting(org.talend.components.jdbc.runtime.setting.AllSetting) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Test(org.junit.Test)

Example 4 with ExecutionEngine

use of org.talend.components.api.component.runtime.ExecutionEngine in project components by Talend.

the class TJDBCOutputDefinitionTest method testGetRuntimeInfo.

/**
 * Run the RuntimeInfo getRuntimeInfo(ExecutionEngine,ComponentProperties,ConnectorTopology) method test.
 *
 * @throws Exception
 *
 * @generatedBy CodePro at 17-6-20 PM3:13
 */
@Test
public void testGetRuntimeInfo() throws Exception {
    AllSetting allSetting = Mockito.mock(AllSetting.class);
    Mockito.when(allSetting.getDriverClass()).thenReturn("anyDriverClass");
    TJDBCOutputProperties properties = Mockito.mock(TJDBCOutputProperties.class);
    Mockito.when(properties.getRuntimeSetting()).thenReturn(allSetting);
    TJDBCOutputDefinition fixture = new TJDBCOutputDefinition();
    ExecutionEngine engine = ExecutionEngine.DI;
    RuntimeInfo result = fixture.getRuntimeInfo(engine, properties, ConnectorTopology.INCOMING);
    assertNotNull(result);
    result = fixture.getRuntimeInfo(engine, properties, ConnectorTopology.INCOMING_AND_OUTGOING);
    assertNotNull(result);
    result = fixture.getRuntimeInfo(engine, properties, ConnectorTopology.NONE);
    assertNull(result);
    result = fixture.getRuntimeInfo(engine, properties, ConnectorTopology.OUTGOING);
    assertNull(result);
}
Also used : ExecutionEngine(org.talend.components.api.component.runtime.ExecutionEngine) AllSetting(org.talend.components.jdbc.runtime.setting.AllSetting) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Test(org.junit.Test)

Example 5 with ExecutionEngine

use of org.talend.components.api.component.runtime.ExecutionEngine in project components by Talend.

the class ComponentDefinitionTest method testAllExecutionEngine.

@Test
public void testAllExecutionEngine() {
    // A component that supports all execution engines.
    TestComponentDefinition cd = new TestComponentDefinition(true);
    for (ExecutionEngine engine : ExecutionEngine.values()) {
        assertThat(cd.getSupportedExecutionEngines(), hasItem(engine));
        assertTrue(cd.isSupportingExecutionEngines(engine));
        // Nothing is returned, but there isn't any exception.
        RuntimeInfo ri = cd.getRuntimeInfo(engine, null, null);
        assertThat(ri, nullValue());
    }
}
Also used : ExecutionEngine(org.talend.components.api.component.runtime.ExecutionEngine) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) TestComponentDefinition(org.talend.components.api.testcomponent.TestComponentDefinition) Test(org.junit.Test)

Aggregations

ExecutionEngine (org.talend.components.api.component.runtime.ExecutionEngine)10 Test (org.junit.Test)9 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)8 AllSetting (org.talend.components.jdbc.runtime.setting.AllSetting)7 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RestAssured.when (com.jayway.restassured.RestAssured.when)1 Response (com.jayway.restassured.response.Response)1 IOException (java.io.IOException)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 Matchers.hasSize (org.hamcrest.Matchers.hasSize)1 Assert.assertEquals (org.junit.Assert.assertEquals)1