Search in sources :

Example 16 with SandboxedInstance

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

the class SalesforceModuleListProperties method afterFormFinishMain.

public ValidationResult afterFormFinishMain(Repository<Properties> repo) throws Exception {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS, USE_CURRENT_JVM_PROPS)) {
        SalesforceRuntimeSourceOrSink ss = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        ss.initialize(null, this);
        ValidationResult vr = ss.validate(null);
        if (vr.getStatus() != ValidationResult.Result.OK) {
            return vr;
        }
        String connRepLocation = repo.storeProperties(connection, connection.name.getValue(), repositoryLocation, null);
        for (NamedThing nl : selectedModuleNames.getValue()) {
            String moduleId = nl.getName();
            SalesforceModuleProperties modProps = new SalesforceModuleProperties(moduleId);
            modProps.connection = connection;
            modProps.init();
            Schema schema = ss.getEndpointSchema(null, moduleId);
            modProps.moduleName.setValue(moduleId);
            modProps.main.schema.setValue(schema);
            repo.storeProperties(modProps, nl.getName(), connRepLocation, "main.schema");
        }
        return ValidationResult.OK;
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) Schema(org.apache.avro.Schema) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink) ValidationResult(org.talend.daikon.properties.ValidationResult) NamedThing(org.talend.daikon.NamedThing)

Example 17 with SandboxedInstance

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

the class TSalesforceInputProperties method validateGuessQuery.

public ValidationResult validateGuessQuery() {
    ValidationResultMutable validationResult = new ValidationResultMutable();
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS)) {
        SalesforceRuntimeSourceOrSink salesforceSourceOrSink = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        salesforceSourceOrSink.initialize(null, this);
        Schema schema = module.main.schema.getValue();
        String moduleName = module.moduleName.getValue();
        if (!schema.getFields().isEmpty()) {
            String soqlQuery = ((SalesforceSchemaHelper<Schema>) salesforceSourceOrSink).guessQuery(schema, moduleName);
            query.setValue(soqlQuery);
            validationResult.setStatus(ValidationResult.Result.OK);
        } else {
            String errorMessage = getI18nMessage("errorMessage.validateGuessQueryError");
            validationResult.setStatus(ValidationResult.Result.ERROR).setMessage(errorMessage);
            query.setValue("");
        }
    } catch (TalendRuntimeException tre) {
        validationResult.setStatus(ValidationResult.Result.ERROR);
        validationResult.setMessage(getI18nMessage("errorMessage.validateGuessQuerySoqlError", tre.getMessage()));
    }
    return validationResult;
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) SalesforceSchemaHelper(org.talend.components.salesforce.schema.SalesforceSchemaHelper) Schema(org.apache.avro.Schema) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink)

Example 18 with SandboxedInstance

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

the class SalesforceDatasetProperties method runtimeTask.

private void runtimeTask(Consumer task) throws IOException {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(DATAPREP_SOURCE_CLASS)) {
        SalesforceRuntimeSourceOrSink runtime = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        SalesforceInputProperties properties = new SalesforceInputProperties("model");
        properties.setDatasetProperties(this);
        throwExceptionIfValidationResultIsError(runtime.initialize(null, properties));
        throwExceptionIfValidationResultIsError(runtime.validate(null));
        task.accept(runtime);
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink) SalesforceInputProperties(org.talend.components.salesforce.dataprep.SalesforceInputProperties)

Example 19 with SandboxedInstance

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

the class JDBCConnectionTestIT method testDynamicLibLoad.

// we want to test the dynamic library loading with the field driverPath, but fail, so seems that no way to test it
// now
@Ignore
@Test
public void testDynamicLibLoad() {
    TJDBCConnectionDefinition definition = new TJDBCConnectionDefinition();
    TJDBCConnectionProperties properties = DBTestUtils.createCommonJDBCConnectionProperties(allSetting, definition);
    // the maven path below is a library at my local repository, you can change it to any jdbc driver which exists in your
    // maven repository for running the test. I can't use derby for test as i have added the derby dependency in the pom file.
    properties.connection.driverTable.drivers.setValue(Arrays.asList("mvn:org.talend.libraries/mysql-connector-java-5.1.30-bin/6.0.0"));
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(ExecutionEngine.DI, properties, ConnectorTopology.NONE);
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, definition.getClass().getClassLoader())) {
        sandboxedInstance.getInstance();
        Class.forName("org.gjt.mm.mysql.Driver");
    } catch (ClassNotFoundException e) {
        Assert.fail("can't find the jdbc driver class, fail to load the library");
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) TJDBCConnectionProperties(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) TJDBCConnectionDefinition(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 20 with SandboxedInstance

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

the class JdbcInputOutputRuntimeTest method testBasic.

@Test
public void testBasic() {
    JDBCInputProperties inputProperties = new JDBCInputProperties("input");
    inputProperties.init();
    inputProperties.setDatasetProperties(JdbcDatasetRuntimeTest.createDatasetProperties());
    JDBCInputDefinition inputDefinition = new JDBCInputDefinition();
    RuntimeInfo inputRI = inputDefinition.getRuntimeInfo(ExecutionEngine.BEAM, inputProperties, ConnectorTopology.OUTGOING);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(inputRI, getClass().getClassLoader())) {
        assertThat(si.getInstance().getClass().getCanonicalName(), is(JDBCInputDefinition.BEAM_RUNTIME));
    }
    inputRI = inputDefinition.getRuntimeInfo(ExecutionEngine.DI, inputProperties, ConnectorTopology.OUTGOING);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(inputRI, getClass().getClassLoader())) {
        assertThat(si.getInstance().getClass().getCanonicalName(), is(JDBCInputDefinition.DI_RUNTIME));
    }
    JDBCOutputProperties outputProperties = new JDBCOutputProperties("output");
    outputProperties.init();
    outputProperties.setDatasetProperties(JdbcDatasetRuntimeTest.createDatasetProperties());
    JDBCOutputDefinition outputDefinition = new JDBCOutputDefinition();
    RuntimeInfo outputRI = outputDefinition.getRuntimeInfo(ExecutionEngine.BEAM, outputProperties, ConnectorTopology.INCOMING);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(outputRI, getClass().getClassLoader())) {
        assertThat(si.getInstance().getClass().getCanonicalName(), is(JDBCOutputDefinition.BEAM_RUNTIME));
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) JDBCInputDefinition(org.talend.components.jdbc.dataprep.JDBCInputDefinition) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) JDBCOutputProperties(org.talend.components.jdbc.datastream.JDBCOutputProperties) JDBCInputProperties(org.talend.components.jdbc.dataprep.JDBCInputProperties) JDBCOutputDefinition(org.talend.components.jdbc.datastream.JDBCOutputDefinition) 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