Search in sources :

Example 86 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore 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

IMetaStore (org.pentaho.metastore.api.IMetaStore)86 Test (org.junit.Test)62 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)25 Repository (org.pentaho.di.repository.Repository)25 SQL (org.pentaho.di.core.sql.SQL)17 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)12 TransMeta (org.pentaho.di.trans.TransMeta)12 Matchers.anyString (org.mockito.Matchers.anyString)11 StepMeta (org.pentaho.di.trans.step.StepMeta)11 KettleException (org.pentaho.di.core.exception.KettleException)10 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)10 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)10 ArrayList (java.util.ArrayList)9 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)9 Node (org.w3c.dom.Node)9 Variables (org.pentaho.di.core.variables.Variables)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)7 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)6 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)6