Search in sources :

Example 1 with AbstractRepository

use of org.pentaho.di.repository.AbstractRepository in project pentaho-kettle by pentaho.

the class RepositoryConnectController method createRepository.

public boolean createRepository(String id, Map<String, Object> items) {
    try {
        RepositoryMeta repositoryMeta = pluginRegistry.loadClass(RepositoryPluginType.class, id, RepositoryMeta.class);
        repositoryMeta.populate(items, repositoriesMeta);
        if (repositoryMeta.getName() != null) {
            Repository repository = pluginRegistry.loadClass(RepositoryPluginType.class, repositoryMeta.getId(), Repository.class);
            repository.init(repositoryMeta);
            repositoriesMeta.addRepository(repositoryMeta);
            repositoriesMeta.writeData();
            if (!testRepository(repository)) {
                return false;
            }
            ((AbstractRepository) repository).create();
        }
    } catch (KettleException ke) {
        log.logError("Unable to load repository type", ke);
        return false;
    }
    return true;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) ReconnectableRepository(org.pentaho.di.repository.ReconnectableRepository) AbstractRepository(org.pentaho.di.repository.AbstractRepository) Repository(org.pentaho.di.repository.Repository) AbstractRepository(org.pentaho.di.repository.AbstractRepository)

Example 2 with AbstractRepository

use of org.pentaho.di.repository.AbstractRepository in project pentaho-kettle by pentaho.

the class RepositoryConnectController method testRepository.

private boolean testRepository(Repository repository) {
    ExecutorService executorService = ExecutorUtil.getExecutor();
    Future<Boolean> future = executorService.submit(() -> {
        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(Trans.class.getClassLoader());
            return ((AbstractRepository) repository).test();
        } finally {
            Thread.currentThread().setContextClassLoader(currentClassLoader);
        }
    });
    try {
        return future.get();
    } catch (InterruptedException | ExecutionException e) {
        return false;
    }
}
Also used : AbstractRepository(org.pentaho.di.repository.AbstractRepository) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) Trans(org.pentaho.di.trans.Trans)

Aggregations

AbstractRepository (org.pentaho.di.repository.AbstractRepository)2 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 KettleException (org.pentaho.di.core.exception.KettleException)1 ReconnectableRepository (org.pentaho.di.repository.ReconnectableRepository)1 Repository (org.pentaho.di.repository.Repository)1 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)1 Trans (org.pentaho.di.trans.Trans)1