Search in sources :

Example 1 with DatastoreRuntime

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

Example 2 with DatastoreRuntime

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());
        }
    }
}
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 3 with DatastoreRuntime

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());
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatastoreRuntime(org.talend.components.common.datastore.runtime.DatastoreRuntime) Iterator(java.util.Iterator) ElasticsearchDatastoreProperties(org.talend.components.elasticsearch.ElasticsearchDatastoreProperties) Test(org.junit.Test)

Example 4 with DatastoreRuntime

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;
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) DatastoreRuntime(org.talend.components.common.datastore.runtime.DatastoreRuntime) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable) ValidationResult(org.talend.daikon.properties.ValidationResult)

Aggregations

DatastoreRuntime (org.talend.components.common.datastore.runtime.DatastoreRuntime)4 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)4 ValidationResult (org.talend.daikon.properties.ValidationResult)3 Test (org.junit.Test)2 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)2 Iterator (java.util.Iterator)1 HttpStatus (org.springframework.http.HttpStatus)1 ResponseEntity (org.springframework.http.ResponseEntity)1 DatastoreProperties (org.talend.components.common.datastore.DatastoreProperties)1 ElasticsearchDatastoreProperties (org.talend.components.elasticsearch.ElasticsearchDatastoreProperties)1 KinesisDatastoreProperties (org.talend.components.kinesis.KinesisDatastoreProperties)1 ValidationResultsDto (org.talend.components.service.rest.dto.ValidationResultsDto)1 ValidationResultMutable (org.talend.daikon.properties.ValidationResultMutable)1