Search in sources :

Example 1 with MetaStoreNamespaceExistsException

use of org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryMetaStore method createNamespace.

@Override
public void createNamespace(String namespace) throws MetaStoreException, MetaStoreNamespaceExistsException {
    try {
        ObjectId namespaceId = delegate.getNamespaceId(namespace);
        if (namespaceId != null) {
            throw new MetaStoreNamespaceExistsException("Namespace with name '" + namespace + "' already exists");
        }
        // insert namespace into R_NAMESPACE
        // 
        delegate.insertNamespace(namespace);
        repository.commit();
    } catch (Exception e) {
        repository.rollback();
        throw new MetaStoreException(e);
    }
}
Also used : MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)

Example 2 with MetaStoreNamespaceExistsException

use of org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException in project pentaho-kettle by pentaho.

the class PurRepositoryIT method testMetaStoreNamespaces.

@Test
public void testMetaStoreNamespaces() throws MetaStoreException {
    IMetaStore metaStore = repository.getMetaStore();
    assertNotNull(metaStore);
    // We start with a clean slate, only the pentaho namespace
    // 
    assertEquals(1, metaStore.getNamespaces().size());
    String ns = PentahoDefaults.NAMESPACE;
    assertEquals(true, metaStore.namespaceExists(ns));
    metaStore.deleteNamespace(ns);
    assertEquals(false, metaStore.namespaceExists(ns));
    assertEquals(0, metaStore.getNamespaces().size());
    metaStore.createNamespace(ns);
    assertEquals(true, metaStore.namespaceExists(ns));
    List<String> namespaces = metaStore.getNamespaces();
    assertEquals(1, namespaces.size());
    assertEquals(ns, namespaces.get(0));
    try {
        metaStore.createNamespace(ns);
        fail("Exception expected when a namespace already exists and where we try to create it again");
    } catch (MetaStoreNamespaceExistsException e) {
    // OK, we expected this.
    }
    metaStore.deleteNamespace(ns);
    assertEquals(false, metaStore.namespaceExists(ns));
    assertEquals(0, metaStore.getNamespaces().size());
}
Also used : MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) Matchers.anyString(org.mockito.Matchers.anyString) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 3 with MetaStoreNamespaceExistsException

use of org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException in project pentaho-kettle by pentaho.

the class PurRepositoryMetaStore method createNamespace.

// The namespaces
@Override
public void createNamespace(String namespace) throws MetaStoreException {
    if (namespaceExists(namespace)) {
        throw new MetaStoreNamespaceExistsException("Namespace '" + namespace + "' can not be created, it already exists");
    }
    RepositoryFile namespaceFolder = new RepositoryFile.Builder(namespace).folder(true).versioned(false).build();
    pur.createFolder(namespacesFolder.getId(), namespaceFolder, "Created namespace");
}
Also used : MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 4 with MetaStoreNamespaceExistsException

use of org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException 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.user.setAdmin(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.isDetailed()) {
                log.logDetailed(BaseMessages.getString(PKG, "PurRepositoryMetastore.Create.Message"));
            }
            metaStore = new PurRepositoryMetaStore(this);
            IMetaStore activeMetaStore = metaStore;
            if (activeMetaStore != null) {
                final IMetaStore connectedMetaStore = activeMetaStore;
                connectionManager.setMetastoreSupplier(() -> connectedMetaStore);
            }
            // Create the default Pentaho namespace if it does not exist
            try {
                metaStore.createNamespace(PentahoDefaults.NAMESPACE);
                if (log.isDetailed()) {
                    log.logDetailed(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.isDetailed()) {
                log.logDetailed(BaseMessages.getString(PKG, "PurRepository.ConnectSuccess.Message"));
            }
        }
    }
}
Also used : EEUserInfo(org.pentaho.di.repository.pur.model.EEUserInfo) IMetaStore(org.pentaho.metastore.api.IMetaStore) 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

MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)4 IMetaStore (org.pentaho.metastore.api.IMetaStore)2 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)2 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 LongObjectId (org.pentaho.di.repository.LongObjectId)1 ObjectId (org.pentaho.di.repository.ObjectId)1 RepositorySecurityProvider (org.pentaho.di.repository.RepositorySecurityProvider)1 StringObjectId (org.pentaho.di.repository.StringObjectId)1 PurRepositoryMetaStore (org.pentaho.di.repository.pur.metastore.PurRepositoryMetaStore)1 EEUserInfo (org.pentaho.di.repository.pur.model.EEUserInfo)1 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)1 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)1 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)1 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1