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