Search in sources :

Example 41 with SandboxedInstance

use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.

the class AbstractMultiRuntimeComponentTests method testMultiRuntimeComponentRuntime.

@Test
public void testMultiRuntimeComponentRuntime() throws Exception {
    MultiRuntimeComponentDefinition def = (MultiRuntimeComponentDefinition) getComponentService().getComponentDefinition(MultiRuntimeComponentDefinition.COMPONENT_NAME);
    MultiRuntimeComponentProperties props = (MultiRuntimeComponentProperties) getComponentService().getComponentProperties(MultiRuntimeComponentDefinition.COMPONENT_NAME);
    props.version.setValue(Version.VERSION_0_1);
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(def.getRuntimeInfo(ExecutionEngine.DI, props, ConnectorTopology.OUTGOING), props.getClass().getClassLoader())) {
        Source source = (Source) sandboxedInstance.getInstance();
        source.initialize(null, props);
        assertEquals("Me", source.validate(null).getMessage());
    }
    props.version.setValue(Version.VERSION_0_2);
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(def.getRuntimeInfo(ExecutionEngine.DI, props, ConnectorTopology.OUTGOING), props.getClass().getClassLoader())) {
        Source source2 = (Source) sandboxedInstance.getInstance();
        source2.initialize(null, props);
        assertEquals("AnotherMe", source2.validate(null).getMessage());
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) Source(org.talend.components.api.component.runtime.Source) Test(org.junit.Test) AbstractComponentTest(org.talend.components.api.test.AbstractComponentTest)

Example 42 with SandboxedInstance

use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.

the class BigQueryDatasetProperties method beforeBqDataset.

public ValidationResult beforeBqDataset() {
    BigQueryDatasetDefinition definition = new BigQueryDatasetDefinition();
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
        IBigQueryDatasetRuntime runtime = (IBigQueryDatasetRuntime) sandboxedInstance.getInstance();
        runtime.initialize(null, this);
        List<NamedThing> datasets = new ArrayList<>();
        for (String dataset : runtime.listDatasets()) {
            datasets.add(new SimpleNamedThing(dataset, dataset));
        }
        bqDataset.setPossibleValues(datasets);
        return ValidationResult.OK;
    } catch (Exception e) {
        return new ValidationResult(new ComponentException(e));
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) IBigQueryDatasetRuntime(org.talend.components.bigquery.runtime.IBigQueryDatasetRuntime) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ValidationResult(org.talend.daikon.properties.ValidationResult) ComponentException(org.talend.components.api.exception.ComponentException) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException)

Example 43 with SandboxedInstance

use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.

the class BigQueryDatasetProperties method beforeTableName.

public void beforeTableName() {
    BigQueryDatasetDefinition definition = new BigQueryDatasetDefinition();
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(this);
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, getClass().getClassLoader())) {
        IBigQueryDatasetRuntime runtime = (IBigQueryDatasetRuntime) sandboxedInstance.getInstance();
        runtime.initialize(null, this);
        List<NamedThing> tables = new ArrayList<>();
        for (String table : runtime.listTables()) {
            tables.add(new SimpleNamedThing(table, table));
        }
        this.tableName.setPossibleValues(tables);
    } catch (Exception e) {
        TalendRuntimeException.build(CommonErrorCodes.UNEXPECTED_EXCEPTION).setAndThrow(e.getMessage());
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) IBigQueryDatasetRuntime(org.talend.components.bigquery.runtime.IBigQueryDatasetRuntime) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ArrayList(java.util.ArrayList) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) ComponentException(org.talend.components.api.exception.ComponentException) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException)

Example 44 with SandboxedInstance

use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.

the class ElasticsearchDatastoreTestIT method testBasic.

@Test
public void testBasic() throws Exception {
    ElasticsearchDatastoreProperties props = createDatastoreProperties();
    RuntimeInfo ri = def.getRuntimeInfo(props);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        DatastoreRuntime runtime = (DatastoreRuntime) si.getInstance();
        runtime.initialize(null, props);
        assertThat(runtime, not(nullValue()));
        Iterator iterator = runtime.doHealthChecks(null).iterator();
        assertTrue(iterator.hasNext());
        assertEquals(ValidationResult.OK, iterator.next());
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatastoreRuntime(org.talend.components.common.datastore.runtime.DatastoreRuntime) Iterator(java.util.Iterator) ElasticsearchDatastoreProperties(org.talend.components.elasticsearch.ElasticsearchDatastoreProperties) Test(org.junit.Test)

Example 45 with SandboxedInstance

use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.

the class BigQueryDatasetTestIT method testBasic.

@Test
public void testBasic() throws Exception {
    BigQueryDatasetProperties props = createDatasetProperties();
    props.sourceType.setValue(SourceType.QUERY);
    props.query.setValue("SELECT * FROM [bigquery-public-data:samples.shakespeare] LIMIT 1");
    props.useLegacySql.setValue(true);
    final List<IndexedRecord> consumed = new ArrayList<>();
    RuntimeInfo ri = def.getRuntimeInfo(props);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        DatasetRuntime runtime = (DatasetRuntime) si.getInstance();
        runtime.initialize(null, props);
        assertThat(runtime, not(nullValue()));
        Schema s = runtime.getSchema();
        assertThat(s, not(nullValue()));
        runtime.getSample(100, new Consumer<IndexedRecord>() {

            @Override
            public void accept(IndexedRecord ir) {
                consumed.add(ir);
            }
        });
    }
    assertThat(consumed, hasSize(1));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) IndexedRecord(org.apache.avro.generic.IndexedRecord) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) BigQueryDatasetProperties(org.talend.components.bigquery.BigQueryDatasetProperties) Test(org.junit.Test)

Aggregations

SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)66 Test (org.junit.Test)30 ValidationResult (org.talend.daikon.properties.ValidationResult)30 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)28 Schema (org.apache.avro.Schema)20 IndexedRecord (org.apache.avro.generic.IndexedRecord)18 ArrayList (java.util.ArrayList)12 ComponentException (org.talend.components.api.exception.ComponentException)12 TJDBCRowDefinition (org.talend.components.jdbc.tjdbcrow.TJDBCRowDefinition)10 TJDBCRowProperties (org.talend.components.jdbc.tjdbcrow.TJDBCRowProperties)10 NamedThing (org.talend.daikon.NamedThing)9 DatasetRuntime (org.talend.components.common.dataset.runtime.DatasetRuntime)8 SalesforceDefinition.getSandboxedInstance (org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance)8 SalesforceRuntimeSourceOrSink (org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink)8 ValidationResultMutable (org.talend.daikon.properties.ValidationResultMutable)8 TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)7 IOException (java.io.IOException)6 MarketoComponentDefinition.getSandboxedInstance (org.talend.components.marketo.MarketoComponentDefinition.getSandboxedInstance)6 MarketoSourceOrSinkRuntime (org.talend.components.marketo.runtime.MarketoSourceOrSinkRuntime)6 WriteOperation (org.talend.components.api.component.runtime.WriteOperation)5