Search in sources :

Example 36 with MetaStoreException

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

the class Spoon method setRepository.

public void setRepository(Repository rep) {
    this.rep = rep;
    this.repositoryName = rep != null ? rep.getName() : null;
    try {
        // 
        if (metaStore.getMetaStoreList().size() > 1) {
            metaStore.getMetaStoreList().remove(0);
            metaStore.setActiveMetaStoreName(metaStore.getMetaStoreList().get(0).getName());
        }
        if (rep != null) {
            this.capabilities = rep.getRepositoryMeta().getRepositoryCapabilities();
            // add a wrapper metastore to the delegation
            // 
            IMetaStore repositoryMetaStore = rep.getMetaStore();
            if (repositoryMetaStore != null) {
                // first priority for explicitly connected repositories.
                metaStore.addMetaStore(0, repositoryMetaStore);
                metaStore.setActiveMetaStoreName(repositoryMetaStore.getName());
                log.logBasic("Connected to metastore : " + repositoryMetaStore.getName() + ", added to delegating metastore");
            } else {
                log.logBasic("No metastore found in the repository : " + rep.getName() + ", connected? " + rep.isConnected());
            }
        }
    } catch (MetaStoreException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorAddingRepositoryMetaStore.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorReadingSharedObjects.Message"), e);
    }
    // Registering the UI Support classes
    UISupportRegistery.getInstance().registerUISupport(RepositorySecurityProvider.class, BaseRepositoryExplorerUISupport.class);
    UISupportRegistery.getInstance().registerUISupport(RepositorySecurityManager.class, ManageUserUISupport.class);
    if (rep != null) {
        SpoonPluginManager.getInstance().notifyLifecycleListeners(SpoonLifeCycleEvent.REPOSITORY_CHANGED);
    }
    delegates.update(this);
    enableMenus();
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) IMetaStore(org.pentaho.metastore.api.IMetaStore)

Example 37 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException 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)

Example 38 with MetaStoreException

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

the class PurRepositoryMetaStore method validateElementTypeRepositoryFolder.

protected RepositoryFile validateElementTypeRepositoryFolder(String namespace, IMetaStoreElementType elementType) throws MetaStoreException {
    // The element type needs to be known in this repository, we need to have a match by ID
    // 
    RepositoryFile elementTypeFolder = pur.getFileById(elementType.getId());
    if (elementTypeFolder == null) {
        StringBuilder builder = new StringBuilder();
        builder.append(namespacesFolder.getPath()).append(Const.CR);
        String available = getMetaStoreFolders(builder, namespacesFolder, 0);
        throw new MetaStoreException("The element type with name '" + elementType.getName() + " doesn't exist in namespace '" + namespace + "'." + Const.CR + "Available nodes:" + Const.CR + available);
    }
    return elementTypeFolder;
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 39 with MetaStoreException

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

the class KettleMetaStoreTestBase method testFunctionality.

public void testFunctionality(IMetaStore metaStore) throws MetaStoreException {
    if (!metaStore.namespaceExists(namespace)) {
        metaStore.createNamespace(namespace);
    }
    List<String> namespaces = metaStore.getNamespaces();
    assertEquals(1, namespaces.size());
    IMetaStoreElementType elementType = metaStore.newElementType(namespace);
    elementType.setName(SHARED_DIMENSION_NAME);
    elementType.setDescription(SHARED_DIMENSION_DESCRIPTION);
    metaStore.createElementType(namespace, elementType);
    assertNotNull(elementType.getId());
    List<IMetaStoreElementType> elementTypes = metaStore.getElementTypes(namespace);
    assertEquals(1, elementTypes.size());
    try {
        metaStore.createElementType(namespace, elementType);
        fail("Duplicate creation error expected!");
    } catch (MetaStoreElementTypeExistsException e) {
    // OK!
    } catch (MetaStoreException e) {
        e.printStackTrace();
        fail("Create exception needs to be MetaStoreDataTypesExistException");
    }
    // 
    try {
        metaStore.deleteNamespace(namespace);
        fail("Expected error while deleting namespace with content!");
    } catch (MetaStoreDependenciesExistsException e) {
        // OK!
        List<String> dependencies = e.getDependencies();
        assertNotNull(dependencies);
        assertEquals(1, dependencies.size());
        assertEquals(elementType.getId(), dependencies.get(0));
    }
    IMetaStoreElement customerDimension = generateCustomerDimensionElement(metaStore, elementType);
    IMetaStoreElementOwner elementOwner = customerDimension.getOwner();
    assertNotNull(elementOwner);
    assertEquals("joe", elementOwner.getName());
    assertEquals(MetaStoreElementOwnerType.USER, elementOwner.getOwnerType());
    metaStore.createElement(namespace, elementType, customerDimension);
    assertNotNull(customerDimension.getId());
    List<IMetaStoreElement> elements = metaStore.getElements(namespace, elementType);
    assertEquals(1, elements.size());
    assertNotNull(elements.get(0));
    assertEquals(CUSTOMER_DIMENSION_NAME, elements.get(0).getName());
    // 
    try {
        metaStore.deleteElementType(namespace, elementType);
        fail("Expected error while deleting data type with content!");
    } catch (MetaStoreDependenciesExistsException e) {
        // OK!
        List<String> dependencies = e.getDependencies();
        assertNotNull(dependencies);
        assertEquals(1, dependencies.size());
        assertEquals(customerDimension.getId(), dependencies.get(0));
    }
    // Some lookup-by-name tests...
    // 
    assertNotNull(metaStore.getElementTypeByName(namespace, SHARED_DIMENSION_NAME));
    assertNotNull(metaStore.getElementByName(namespace, elementType, CUSTOMER_DIMENSION_NAME));
    // Clean up shop!
    // 
    metaStore.deleteElement(namespace, elementType, customerDimension.getId());
    elements = metaStore.getElements(namespace, elementType);
    assertEquals(0, elements.size());
    metaStore.deleteElementType(namespace, elementType);
    elementTypes = metaStore.getElementTypes(namespace);
    assertEquals(0, elementTypes.size());
    metaStore.deleteNamespace(namespace);
    namespaces = metaStore.getNamespaces();
    assertEquals(0, namespaces.size());
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) MetaStoreElementTypeExistsException(org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException) IMetaStoreElementOwner(org.pentaho.metastore.api.security.IMetaStoreElementOwner) List(java.util.List) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) MetaStoreDependenciesExistsException(org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)

Example 40 with MetaStoreException

use of org.pentaho.metastore.api.exceptions.MetaStoreException in project pentaho-platform by pentaho.

the class MetaStoreImportHandler method importFile.

@Override
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
    InputStream inputStream = bundle.getInputStream();
    Path path = Files.createTempDirectory(METASTORE);
    path.toFile().deleteOnExit();
    // get the zipped metastore from the export bundle
    ZipInputStream zis = new ZipInputStream(inputStream);
    ZipEntry entry;
    while ((entry = zis.getNextEntry()) != null) {
        try {
            String filePath = path.toString() + File.separator + entry.getName();
            if (entry.isDirectory()) {
                File dir = new File(filePath);
                dir.mkdir();
            } else {
                File file = new File(filePath);
                file.getParentFile().mkdirs();
                FileOutputStream fos = new FileOutputStream(filePath);
                IOUtils.copy(zis, fos);
                IOUtils.closeQuietly(fos);
            }
        } finally {
            zis.closeEntry();
        }
    }
    IOUtils.closeQuietly(zis);
    // get a hold of the metastore to import into
    IMetaStore metastore = getRepoMetaStore();
    if (metastore != null) {
        // copy the exported metastore to where it needs to go
        try {
            if (tmpXmlMetaStore == null) {
                tmpXmlMetaStore = new XmlMetaStore(path.toString());
            } else {
                // we are re-using an existing object, make sure the root folder is pointed at the new location on disk
                tmpXmlMetaStore.setRootFolder(path.toString() + File.separator + METASTORE);
            }
            tmpXmlMetaStore.setName(bundle.getName());
            String desc = bundle.getProperty("description") == null ? null : bundle.getProperty("description").toString();
            tmpXmlMetaStore.setDescription(desc);
            MetaStoreUtil.copy(tmpXmlMetaStore, metastore, bundle.overwriteInRepository());
        } catch (MetaStoreException e) {
            log.error("Could not restore the MetaStore");
            log.debug("Error restoring the MetaStore", e);
        }
    }
}
Also used : Path(java.nio.file.Path) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) XmlMetaStore(org.pentaho.metastore.stores.xml.XmlMetaStore) File(java.io.File) IMetaStore(org.pentaho.metastore.api.IMetaStore)

Aggregations

MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)43 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)18 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)18 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)17 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)17 LongObjectId (org.pentaho.di.repository.LongObjectId)12 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)11 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)9 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)8 StringObjectId (org.pentaho.di.repository.StringObjectId)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ObjectId (org.pentaho.di.repository.ObjectId)5 IMetaStore (org.pentaho.metastore.api.IMetaStore)5 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)4 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)4 List (java.util.List)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 NamedClusterOsgi (org.pentaho.di.core.osgi.api.NamedClusterOsgi)2