Search in sources :

Example 1 with PurRepositoryMetaStore

use of org.pentaho.di.repository.pur.metastore.PurRepositoryMetaStore in project pentaho-kettle by pentaho.

the class PurRepository method connect.

@Override
public void connect(final String username, final String password) throws KettleException {
    connected = false;
    if (isTest()) {
        connected = true;
        purRepositoryServiceRegistry.registerService(IRevisionService.class, new UnifiedRepositoryRevisionService(pur, getRootRef()));
        purRepositoryServiceRegistry.registerService(ILockService.class, new UnifiedRepositoryLockService(pur));
        purRepositoryServiceRegistry.registerService(IAclService.class, new UnifiedRepositoryConnectionAclService(pur));
        metaStore = new PurRepositoryMetaStore(this);
        try {
            metaStore.createNamespace(PentahoDefaults.NAMESPACE);
        } catch (MetaStoreException e) {
            log.logError(BaseMessages.getString(PKG, "PurRepositoryMetastore.NamespaceCreateException.Message", PentahoDefaults.NAMESPACE), e);
        }
        this.user = new EEUserInfo(username, password, username, "test user", true);
        this.jobDelegate = new JobDelegate(this, pur);
        this.transDelegate = new TransDelegate(this, pur);
        this.unifiedRepositoryLockService = new UnifiedRepositoryLockService(pur);
        return;
    }
    try {
        if (log != null && purRepositoryConnector != null && purRepositoryConnector.getLog() != null) {
            purRepositoryConnector.getLog().setLogLevel(log.getLogLevel());
        }
        RepositoryConnectResult result = purRepositoryConnector.connect(username, password);
        this.user = result.getUser();
        this.connected = result.isSuccess();
        this.securityProvider = result.getSecurityProvider();
        this.securityManager = result.getSecurityManager();
        IUnifiedRepository r = result.getUnifiedRepository();
        try {
            this.pur = (IUnifiedRepository) Proxy.newProxyInstance(r.getClass().getClassLoader(), new Class<?>[] { IUnifiedRepository.class }, new UnifiedRepositoryInvocationHandler<IUnifiedRepository>(r));
            if (this.securityProvider != null) {
                this.securityProvider = (RepositorySecurityProvider) Proxy.newProxyInstance(this.securityProvider.getClass().getClassLoader(), new Class<?>[] { RepositorySecurityProvider.class }, new UnifiedRepositoryInvocationHandler<RepositorySecurityProvider>(this.securityProvider));
            }
        } catch (Throwable th) {
            if (log.isError()) {
                log.logError("Failed to setup repository connection", th);
            }
            connected = false;
        }
        this.unifiedRepositoryLockService = new UnifiedRepositoryLockService(pur);
        this.connectMessage = result.getConnectMessage();
        this.purRepositoryServiceRegistry = result.repositoryServiceRegistry();
        this.transDelegate = new TransDelegate(this, pur);
        this.jobDelegate = new JobDelegate(this, pur);
    } finally {
        if (connected) {
            if (log.isBasic()) {
                log.logBasic(BaseMessages.getString(PKG, "PurRepositoryMetastore.Create.Message"));
            }
            metaStore = new PurRepositoryMetaStore(this);
            // Create the default Pentaho namespace if it does not exist
            try {
                metaStore.createNamespace(PentahoDefaults.NAMESPACE);
                if (log.isBasic()) {
                    log.logBasic(BaseMessages.getString(PKG, "PurRepositoryMetastore.NamespaceCreateSuccess.Message", PentahoDefaults.NAMESPACE));
                }
            } catch (MetaStoreNamespaceExistsException e) {
            // Ignore this exception, we only use it to save a call to check if the namespace exists, as the
            // createNamespace()
            // call will do the check for us and throw this exception.
            } catch (MetaStoreException e) {
                log.logError(BaseMessages.getString(PKG, "PurRepositoryMetastore.NamespaceCreateException.Message", PentahoDefaults.NAMESPACE), e);
            }
            if (log.isBasic()) {
                log.logBasic(BaseMessages.getString(PKG, "PurRepository.ConnectSuccess.Message"));
            }
        }
    }
}
Also used : EEUserInfo(org.pentaho.di.repository.pur.model.EEUserInfo) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) RepositorySecurityProvider(org.pentaho.di.repository.RepositorySecurityProvider) PurRepositoryMetaStore(org.pentaho.di.repository.pur.metastore.PurRepositoryMetaStore) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Aggregations

RepositorySecurityProvider (org.pentaho.di.repository.RepositorySecurityProvider)1 PurRepositoryMetaStore (org.pentaho.di.repository.pur.metastore.PurRepositoryMetaStore)1 EEUserInfo (org.pentaho.di.repository.pur.model.EEUserInfo)1 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)1 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)1 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)1