Search in sources :

Example 1 with XmlMetaStore

use of org.pentaho.metastore.stores.xml.XmlMetaStore in project pentaho-kettle by pentaho.

the class MetaStoreConst method openLocalPentahoMetaStore.

public static IMetaStore openLocalPentahoMetaStore(boolean allowCreate) throws MetaStoreException {
    if (disableMetaStore) {
        return null;
    }
    String rootFolder = System.getProperty(Const.PENTAHO_METASTORE_FOLDER);
    if (Utils.isEmpty(rootFolder)) {
        rootFolder = getDefaultPentahoMetaStoreLocation();
    }
    File rootFolderFile = new File(rootFolder);
    File metaFolder = new File(rootFolder + File.separator + XmlUtil.META_FOLDER_NAME);
    if (!allowCreate && !metaFolder.exists()) {
        return null;
    }
    if (!rootFolderFile.exists()) {
        rootFolderFile.mkdirs();
    }
    XmlMetaStore metaStore = new XmlMetaStore(rootFolder);
    if (allowCreate) {
        metaStore.setName(Const.PENTAHO_METASTORE_NAME);
    }
    return metaStore;
}
Also used : XmlMetaStore(org.pentaho.metastore.stores.xml.XmlMetaStore) File(java.io.File)

Example 2 with XmlMetaStore

use of org.pentaho.metastore.stores.xml.XmlMetaStore in project pentaho-kettle by pentaho.

the class KettleFileRepository method connect.

@Override
public void connect(String username, String password) throws KettleException {
    try {
        String metaStoreRootFolder = this.repositoryMeta.getBaseDirectory() + File.separator + ".meta";
        File metaStoreRootFolderFile = new File(this.repositoryMeta.getBaseDirectory() + File.separator + ".meta");
        if (!metaStoreRootFolderFile.exists()) {
            if (this.repositoryMeta.isReadOnly()) {
                this.metaStore = null;
            } else {
                if (metaStoreRootFolderFile.mkdirs()) {
                    this.metaStore = new XmlMetaStore(metaStoreRootFolder);
                } else {
                    this.metaStore = null;
                }
            }
        } else {
            this.metaStore = new XmlMetaStore(metaStoreRootFolder);
        }
    } catch (Exception e) {
        throw new KettleException(e);
    }
    if (this.metaStore != null) {
        this.metaStore.setName(this.repositoryMeta.getName());
        this.metaStore.setDescription(this.repositoryMeta.getDescription());
    }
    connected = true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) XmlMetaStore(org.pentaho.metastore.stores.xml.XmlMetaStore) File(java.io.File) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException)

Example 3 with XmlMetaStore

use of org.pentaho.metastore.stores.xml.XmlMetaStore 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)

Example 4 with XmlMetaStore

use of org.pentaho.metastore.stores.xml.XmlMetaStore in project pentaho-platform by pentaho.

the class PentahoPlatformExporter method exportMetastore.

protected void exportMetastore() throws IOException {
    log.debug("export the metastore");
    try {
        Path tempDirectory = Files.createTempDirectory(METASTORE);
        IMetaStore xmlMetaStore = new XmlMetaStore(tempDirectory.toString());
        MetaStoreUtil.copy(getRepoMetaStore(), xmlMetaStore);
        File zippedMetastore = Files.createTempFile(METASTORE, EXPORT_TEMP_FILENAME_EXT).toFile();
        ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zippedMetastore));
        zipFolder(tempDirectory.toFile(), zipOutputStream, tempDirectory.toString());
        zipOutputStream.close();
        // now that we have the zipped content of an xml metastore, we need to write that to the export bundle
        FileInputStream zis = new FileInputStream(zippedMetastore);
        String zipFileLocation = METASTORE + METASTORE_BACKUP_EXT;
        ZipEntry metastoreZipFileZipEntry = new ZipEntry(zipFileLocation);
        zos.putNextEntry(metastoreZipFileZipEntry);
        try {
            IOUtils.copy(zis, zos);
        } catch (IOException e) {
            throw e;
        } finally {
            zis.close();
            zos.closeEntry();
        }
        // add an ExportManifest entry for the metastore.
        ExportManifestMetaStore exportManifestMetaStore = new ExportManifestMetaStore(zipFileLocation, getRepoMetaStore().getName(), getRepoMetaStore().getDescription());
        getExportManifest().setMetaStore(exportManifestMetaStore);
        zippedMetastore.deleteOnExit();
        tempDirectory.toFile().deleteOnExit();
    } catch (Exception e) {
        log.error(Messages.getInstance().getString("PentahoPlatformExporter.ERROR.ExportingMetaStore"));
        log.debug(Messages.getInstance().getString("PentahoPlatformExporter.ERROR.ExportingMetaStore"), e);
    }
}
Also used : Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) XmlMetaStore(org.pentaho.metastore.stores.xml.XmlMetaStore) IMetaStore(org.pentaho.metastore.api.IMetaStore) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) FileInputStream(java.io.FileInputStream) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) FileNotFoundException(java.io.FileNotFoundException) KettleException(org.pentaho.di.core.exception.KettleException) ExportException(org.pentaho.platform.plugin.services.importexport.ExportException) IOException(java.io.IOException) ExportManifestMetaStore(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetaStore)

Aggregations

File (java.io.File)4 XmlMetaStore (org.pentaho.metastore.stores.xml.XmlMetaStore)4 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ZipEntry (java.util.zip.ZipEntry)2 KettleException (org.pentaho.di.core.exception.KettleException)2 IMetaStore (org.pentaho.metastore.api.IMetaStore)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 ZipInputStream (java.util.zip.ZipInputStream)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 KettleFileException (org.pentaho.di.core.exception.KettleFileException)1 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)1 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)1 ExportException (org.pentaho.platform.plugin.services.importexport.ExportException)1