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