use of org.talend.components.common.datastore.runtime.DatastoreRuntime 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);
}
}
use of org.talend.components.common.datastore.runtime.DatastoreRuntime 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());
}
}
}
use of org.talend.components.common.datastore.runtime.DatastoreRuntime 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());
}
}
use of org.talend.components.common.datastore.runtime.DatastoreRuntime in project components by Talend.
the class MarkLogicConnectionProperties method validateTestConnection.
public ValidationResult validateTestConnection() {
ValidationResult vr;
try (SandboxedInstance sandbox = SandboxInstanceFactory.createSandboxedInstance(RuntimeInfoProvider.getCommonRuntimeInfo(MarkLogicDatastoreDefinition.DATASTORE_RUNTIME), MarkLogicConnectionProperties.class.getClassLoader(), false)) {
DatastoreRuntime<MarkLogicConnectionProperties> datastoreRuntime = (DatastoreRuntime<MarkLogicConnectionProperties>) sandbox.getInstance();
datastoreRuntime.initialize(null, this);
ValidationResultMutable vrm = new ValidationResultMutable(datastoreRuntime.doHealthChecks(null).iterator().next());
if (vrm.getStatus() == ValidationResult.Result.OK) {
vrm.setMessage(getI18nMessage("messages.connectionSuccessful"));
getForm(WIZARD).setAllowFinish(true);
} else {
getForm(WIZARD).setAllowFinish(false);
}
vr = vrm;
} catch (Exception e) {
vr = new ValidationResult(Result.ERROR, e.getMessage());
}
return vr;
}
Aggregations