Search in sources :

Example 1 with SandboxedInstance

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

the class TFilterRowDefinitionTest method testGetRuntime.

/**
 * Check {@link TFilterRowDefinition#getRuntime()} returns instance of {@link JiraSource}
 */
@Test
public void testGetRuntime() {
    TFilterRowDefinition definition = new TFilterRowDefinition();
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(ExecutionEngine.DI, null, ConnectorTopology.INCOMING_AND_OUTGOING);
    SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, definition.getClass().getClassLoader());
    Sink source = (Sink) sandboxedInstance.getInstance();
    assertThat(source, is(instanceOf(TFilterRowSink.class)));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Sink(org.talend.components.api.component.runtime.Sink) TFilterRowSink(org.talend.components.filterrow.runtime.TFilterRowSink) Test(org.junit.Test)

Example 2 with SandboxedInstance

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

the class SalesforceSourceOrSinkTestIT method testIsolatedClassLoader.

@Test
public void testIsolatedClassLoader() {
    ClassLoader classLoader = SalesforceDefinition.class.getClassLoader();
    RuntimeInfo runtimeInfo = SalesforceDefinition.getCommonRuntimeInfo(SalesforceSourceOrSink.class.getCanonicalName());
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClassWithCurrentJVMProperties(runtimeInfo, classLoader)) {
        sandboxedInstance.getInstance();
        System.setProperty("key", "value");
    }
    Assert.assertNull("The system property should not exist, but not", System.getProperty("key"));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Test(org.junit.Test)

Example 3 with SandboxedInstance

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

the class SalesforceSourceOrSink method getSchema.

public static Schema getSchema(RuntimeContainer container, SalesforceProvideConnectionProperties properties, String module) throws IOException {
    ClassLoader classLoader = SalesforceSourceOrSink.class.getClassLoader();
    // org.talend.components.salesforce.runtime.common.SalesforceRuntimeCommon.enableTLSv11AndTLSv12ForJava7()
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClassWithCurrentJVMProperties(getStaticRuntimeInfo(), classLoader)) {
        SalesforceSourceOrSink ss = (SalesforceSourceOrSink) sandboxedInstance.getInstance();
        ss.initialize(null, (ComponentProperties) properties);
        PartnerConnection connection = null;
        try {
            connection = ss.connect(container).connection;
        } catch (IOException ex) {
            throw new ComponentException(SalesforceRuntimeCommon.exceptionToValidationResult(ex));
        }
        return ss.getSchema(connection, module);
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) PartnerConnection(com.sforce.soap.partner.PartnerConnection) ComponentException(org.talend.components.api.exception.ComponentException) IOException(java.io.IOException)

Example 4 with SandboxedInstance

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

the class RuntimeControllerImpl method useDatasetRuntime.

private <// 
T> // 
T useDatasetRuntime(// 
final DatasetDefinition<DatasetProperties<DatastoreProperties>> datasetDefinition, // 
DatasetProperties datasetProperties, Function<DatasetRuntime<DatasetProperties<DatastoreProperties>>, T> consumer) {
    try (SandboxedInstance instance = RuntimeUtil.createRuntimeClass(datasetDefinition.getRuntimeInfo(datasetProperties), datasetProperties.getClass().getClassLoader())) {
        DatasetRuntime<DatasetProperties<DatastoreProperties>> datasetRuntimeInstance = (DatasetRuntime<DatasetProperties<DatastoreProperties>>) instance.getInstance();
        datasetRuntimeInstance.initialize(null, datasetProperties);
        return consumer.apply(datasetRuntimeInstance);
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) DatastoreProperties(org.talend.components.common.datastore.DatastoreProperties) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) DatasetProperties(org.talend.components.common.dataset.DatasetProperties)

Example 5 with SandboxedInstance

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

the class RuntimeControllerImpl method doValidateDatastoreConnection.

private ResponseEntity<ValidationResultsDto> doValidateDatastoreConnection(DatastoreProperties properties) {
    DatastoreDefinition<DatastoreProperties> definition = propertiesHelpers.getFirstDefinitionFromProperties(properties);
    try (SandboxedInstance instance = RuntimeUtil.createRuntimeClass(definition.getRuntimeInfo(properties), properties.getClass().getClassLoader())) {
        DatastoreRuntime<DatastoreProperties> datastoreRuntime = (DatastoreRuntime) instance.getInstance();
        datastoreRuntime.initialize(null, properties);
        Iterable<ValidationResult> healthChecks = datastoreRuntime.doHealthChecks(null);
        ValidationResultsDto response = new ValidationResultsDto(healthChecks == null ? emptyList() : newArrayList(healthChecks));
        HttpStatus httpStatus = response.getStatus() == ValidationResult.Result.OK ? HttpStatus.OK : HttpStatus.BAD_REQUEST;
        return new ResponseEntity<>(response, httpStatus);
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) DatastoreProperties(org.talend.components.common.datastore.DatastoreProperties) ResponseEntity(org.springframework.http.ResponseEntity) HttpStatus(org.springframework.http.HttpStatus) DatastoreRuntime(org.talend.components.common.datastore.runtime.DatastoreRuntime) ValidationResultsDto(org.talend.components.service.rest.dto.ValidationResultsDto) ValidationResult(org.talend.daikon.properties.ValidationResult)

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