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