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);
}
}
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());
}
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");
}
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"));
}
}
}
}
Aggregations