Search in sources :

Example 66 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)

Example 67 with IMetaStore

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

the class PentahoPlatformExporterTest method testExportMetaStore.

@Test
public void testExportMetaStore() throws Exception {
    exporterSpy.zos = mock(ZipOutputStream.class);
    IMetaStore metastore = mock(IMetaStore.class);
    exporterSpy.setRepoMetaStore(metastore);
    ExportManifest manifest = mock(ExportManifest.class);
    exporterSpy.setExportManifest(manifest);
    exporterSpy.exportMetastore();
    verify(exporterSpy.zos).putNextEntry(any(ZipEntry.class));
    verify(manifest).setMetaStore(any(ExportManifestMetaStore.class));
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) IMetaStore(org.pentaho.metastore.api.IMetaStore) ExportManifest(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifest) ExportManifestMetaStore(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetaStore) Test(org.junit.Test)

Example 68 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testWaitInterruptedException.

@Test(expected = RuntimeException.class)
public void testWaitInterruptedException() throws Exception {
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    when(serviceTrans.getTransMeta().listParameters()).thenReturn(new String[0]);
    when(sqlTransGenerator.getSql()).thenReturn(sql);
    PushDownOptimizationMeta optimization = mock(PushDownOptimizationMeta.class);
    when(optimization.isEnabled()).thenReturn(true);
    dataService.getPushDownOptimizationMeta().add(optimization);
    dataService.setStreaming(true);
    IMetaStore metastore = mock(IMetaStore.class);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).windowMode(IDataServiceClientService.StreamingMode.ROW_BASED).windowSize(1).windowEvery(0).windowLimit(0).build();
    doThrow(InterruptedException.class).when(genTrans).isFinishedOrStopped();
    executor.waitUntilFinished();
}
Also used : PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 69 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testBuilderBuildServiceServiceTransNotNull.

@Test
public void testBuilderBuildServiceServiceTransNotNull() throws Exception {
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    RowMeta rowMeta = new RowMeta();
    ValueMetaInterface vm = new ValueMetaString("aBinaryStoredString");
    vm.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
    vm.setStorageMetadata(new ValueMetaString());
    rowMeta.addValueMeta(vm);
    when(serviceTrans.getTransMeta()).thenReturn(serviceTransMeta);
    when(serviceTransMeta.realClone(false)).thenReturn(serviceTransMeta);
    when(serviceTransMeta.listVariables()).thenReturn(new String[] {});
    when(serviceTransMeta.listParameters()).thenReturn(new String[] {});
    when(serviceTransMeta.getStepFields(DATA_SERVICE_STEP)).thenReturn(rowMeta);
    dataService.setServiceTrans(serviceTrans.getTransMeta());
    dataService.setStreaming(true);
    IMetaStore metastore = mock(IMetaStore.class);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).enableMetrics(false).normalizeConditions(false).rowLimit(50).build();
    assertSame(dataService.getServiceTrans(), serviceTrans.getTransMeta());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 70 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testExecuteStreamQuery.

@Test
public void testExecuteStreamQuery() throws Exception {
    when(genTrans.isFinishedOrStopped()).thenReturn(true);
    SQL sql = new SQL("SELECT * FROM " + DATA_SERVICE_NAME);
    when(serviceTrans.getTransMeta().listParameters()).thenReturn(new String[0]);
    when(sqlTransGenerator.getSql()).thenReturn(sql);
    PushDownOptimizationMeta optimization = mock(PushDownOptimizationMeta.class);
    when(optimization.isEnabled()).thenReturn(true);
    dataService.getPushDownOptimizationMeta().add(optimization);
    dataService.setStreaming(true);
    IMetaStore metastore = mock(IMetaStore.class);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(sql, dataService, context).serviceTrans(serviceTrans).sqlTransGenerator(sqlTransGenerator).genTrans(genTrans).metastore(metastore).windowMode(IDataServiceClientService.StreamingMode.ROW_BASED).windowSize(1).windowEvery(0).windowLimit(0).build();
    ArgumentCaptor<String> objectIds = ArgumentCaptor.forClass(String.class);
    verify(serviceTrans).setContainerObjectId(objectIds.capture());
    when(serviceTrans.getContainerObjectId()).thenReturn(objectIds.getValue());
    verify(genTrans).setContainerObjectId(objectIds.capture());
    when(genTrans.getContainerObjectId()).thenReturn(objectIds.getValue());
    verify(serviceTrans).setMetaStore(metastore);
    verify(genTrans).setMetaStore(metastore);
    RowProducer sqlTransRowProducer = mock(RowProducer.class);
    when(genTrans.addRowProducer(INJECTOR_STEP_NAME, 0)).thenReturn(sqlTransRowProducer);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    // Start Execution
    executor.executeQuery(new DataOutputStream(outputStream));
    // Check header was written
    assertThat(outputStream.size(), greaterThan(0));
    outputStream.reset();
    executor.waitUntilFinished();
    verify(serviceTrans, times(0)).waitUntilFinished();
    verify(genTrans).waitUntilFinished();
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) DataOutputStream(java.io.DataOutputStream) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Matchers.anyString(org.mockito.Matchers.anyString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Aggregations

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