Search in sources :

Example 11 with SandboxedInstance

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

the class KinesisDatastoreRuntimeTestIT method doHealthChecks.

@Test
public void doHealthChecks() {
    KinesisDatastoreProperties props = getDatastore();
    RuntimeInfo ri = def.getRuntimeInfo(props);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        DatastoreRuntime runtime = (DatastoreRuntime) si.getInstance();
        runtime.initialize(null, props);
        Iterable<ValidationResult> validationResults = runtime.doHealthChecks(null);
        Assert.assertEquals(ValidationResult.OK, validationResults.iterator().next());
        // Wrong access key
        {
            KinesisDatastoreProperties wrongAccess = getDatastore();
            wrongAccess.accessKey.setValue("wrong");
            runtime.initialize(null, wrongAccess);
            validationResults = runtime.doHealthChecks(null);
            Assert.assertEquals(ValidationResult.Result.ERROR, validationResults.iterator().next().getStatus());
        }
        // Wrong screct key
        {
            KinesisDatastoreProperties wrongSecret = getDatastore();
            wrongSecret.secretKey.setValue("wrong");
            runtime.initialize(null, wrongSecret);
            validationResults = runtime.doHealthChecks(null);
            Assert.assertEquals(ValidationResult.Result.ERROR, validationResults.iterator().next().getStatus());
        }
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) KinesisDatastoreProperties(org.talend.components.kinesis.KinesisDatastoreProperties) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatastoreRuntime(org.talend.components.common.datastore.runtime.DatastoreRuntime) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Example 12 with SandboxedInstance

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

the class SalesforceBulkExecReaderTestIT method executeBulkInsert.

/**
 * Test runtime of tSalesforceOutputBulk
 */
private void executeBulkInsert(TSalesforceBulkExecProperties bulkExecProperties, String random, int count) throws Throwable {
    TSalesforceBulkExecDefinition definition = (TSalesforceBulkExecDefinition) getComponentService().getComponentDefinition(TSalesforceBulkExecDefinition.COMPONENT_NAME);
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(ExecutionEngine.DI, bulkExecProperties, ConnectorTopology.OUTGOING);
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, definition.getClass().getClassLoader())) {
        SalesforceSource boundedSource = (SalesforceSource) sandboxedInstance.getInstance();
        boundedSource.initialize(null, bulkExecProperties);
        BoundedReader boundedReader = boundedSource.createReader(null);
        try {
            boolean hasRecord = boundedReader.start();
            List<IndexedRecord> rows = new ArrayList<>();
            while (hasRecord) {
                rows.add((IndexedRecord) boundedReader.getCurrent());
                hasRecord = boundedReader.advance();
            }
            checkRows(random, rows, count);
        } finally {
            boundedReader.close();
        }
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) IndexedRecord(org.apache.avro.generic.IndexedRecord) TSalesforceBulkExecDefinition(org.talend.components.salesforce.tsalesforcebulkexec.TSalesforceBulkExecDefinition) ArrayList(java.util.ArrayList) BoundedReader(org.talend.components.api.component.runtime.BoundedReader)

Example 13 with SandboxedInstance

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

the class SalesforceModuleProperties method beforeModuleName.

// consider beforeActivate and beforeRender (change after to afterActivate)
public ValidationResult beforeModuleName() throws Exception {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS, USE_CURRENT_JVM_PROPS)) {
        SalesforceRuntimeSourceOrSink ss = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        ss.initialize(null, getEffectiveConnection());
        ValidationResult vr = ss.validate(null);
        if (vr.getStatus() == ValidationResult.Result.OK) {
            try {
                List<NamedThing> moduleNames = ss.getSchemaNames(null);
                moduleName.setPossibleNamedThingValues(moduleNames);
            } catch (Exception ex) {
                return ExceptionUtil.exceptionToValidationResult(ex);
            }
        } else {
            return vr;
        }
        return ValidationResult.OK;
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink) ValidationResult(org.talend.daikon.properties.ValidationResult) NamedThing(org.talend.daikon.NamedThing) ComponentException(org.talend.components.api.exception.ComponentException)

Example 14 with SandboxedInstance

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

the class SalesforceModuleProperties method afterModuleName.

public ValidationResult afterModuleName() throws Exception {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS, USE_CURRENT_JVM_PROPS)) {
        SalesforceRuntimeSourceOrSink ss = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        ss.initialize(null, getEffectiveConnection());
        ValidationResult vr = ss.validate(null);
        if (vr.getStatus() == ValidationResult.Result.OK) {
            try {
                Schema schema = ss.getEndpointSchema(null, moduleName.getStringValue());
                main.schema.setValue(schema);
                moduleName.setPossibleValues(Collections.emptyList());
            } catch (Exception ex) {
                throw new ComponentException(ExceptionUtil.exceptionToValidationResult(ex));
            }
        } else {
            throw new ComponentException(vr);
        }
        return ValidationResult.OK;
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) Schema(org.apache.avro.Schema) ComponentException(org.talend.components.api.exception.ComponentException) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink) ValidationResult(org.talend.daikon.properties.ValidationResult) ComponentException(org.talend.components.api.exception.ComponentException)

Example 15 with SandboxedInstance

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

the class SalesforceConnectionProperties method validateTestConnection.

public ValidationResult validateTestConnection() throws Exception {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS, USE_CURRENT_JVM_PROPS)) {
        SalesforceRuntimeSourceOrSink ss = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
        ss.initialize(null, SalesforceConnectionProperties.this);
        ValidationResultMutable vr = new ValidationResultMutable(ss.validate(null));
        if (vr.getStatus() == ValidationResult.Result.OK) {
            vr.setMessage(MESSAGES.getMessage("connection.success"));
            getForm(FORM_WIZARD).setAllowForward(true);
        } else {
            getForm(FORM_WIZARD).setAllowForward(false);
        }
        return vr;
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SalesforceDefinition.getSandboxedInstance(org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) SalesforceRuntimeSourceOrSink(org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink)

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