Search in sources :

Example 61 with IMetaStore

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

the class JobExecutionConfigurationTest method testGetUsedArguments.

@Test
public void testGetUsedArguments() throws KettleException {
    JobExecutionConfiguration executionConfiguration = new JobExecutionConfiguration();
    JobMeta jobMeta = new JobMeta();
    jobMeta.jobcopies = new ArrayList<>();
    String[] commandLineArguments = new String[0];
    IMetaStore metaStore = mock(IMetaStore.class);
    JobEntryCopy jobEntryCopy0 = new JobEntryCopy();
    TransMeta transMeta0 = mock(TransMeta.class);
    Map<String, String> map0 = new HashMap<>();
    map0.put("arg0", "argument0");
    when(transMeta0.getUsedArguments(commandLineArguments)).thenReturn(map0);
    JobEntryInterface jobEntryInterface0 = mock(JobEntryInterface.class);
    when(jobEntryInterface0.isTransformation()).thenReturn(false);
    jobEntryCopy0.setEntry(jobEntryInterface0);
    jobMeta.jobcopies.add(jobEntryCopy0);
    JobEntryCopy jobEntryCopy1 = new JobEntryCopy();
    TransMeta transMeta1 = mock(TransMeta.class);
    Map<String, String> map1 = new HashMap<>();
    map1.put("arg1", "argument1");
    when(transMeta1.getUsedArguments(commandLineArguments)).thenReturn(map1);
    JobEntryTrans jobEntryTrans1 = mock(JobEntryTrans.class);
    when(jobEntryTrans1.isTransformation()).thenReturn(true);
    when(jobEntryTrans1.getTransMeta(executionConfiguration.getRepository(), metaStore, jobMeta)).thenReturn(transMeta1);
    jobEntryCopy1.setEntry(jobEntryTrans1);
    jobMeta.jobcopies.add(jobEntryCopy1);
    JobEntryCopy jobEntryCopy2 = new JobEntryCopy();
    TransMeta transMeta2 = mock(TransMeta.class);
    Map<String, String> map2 = new HashMap<>();
    map2.put("arg1", "argument1");
    map2.put("arg2", "argument2");
    when(transMeta2.getUsedArguments(commandLineArguments)).thenReturn(map2);
    JobEntryTrans jobEntryTrans2 = mock(JobEntryTrans.class);
    when(jobEntryTrans2.isTransformation()).thenReturn(true);
    when(jobEntryTrans2.getTransMeta(executionConfiguration.getRepository(), metaStore, jobMeta)).thenReturn(transMeta2);
    jobEntryCopy2.setEntry(jobEntryTrans2);
    jobMeta.jobcopies.add(jobEntryCopy2);
    executionConfiguration.getUsedArguments(jobMeta, commandLineArguments, metaStore);
    assertEquals(2, executionConfiguration.getArguments().size());
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) HashMap(java.util.HashMap) JobEntryTrans(org.pentaho.di.job.entries.trans.JobEntryTrans) TransMeta(org.pentaho.di.trans.TransMeta) Matchers.anyString(org.mockito.Matchers.anyString) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 62 with IMetaStore

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

the class CombinationLookupIT method testUseDefaultSchemaName.

public void testUseDefaultSchemaName() throws Exception {
    String schemaName = "";
    String tableName = "tableName";
    String schemaTable = "default.tableName";
    String technicalKeyField = "technicalKeyField";
    DatabaseMeta databaseMeta = spy(new DatabaseMeta(databasesXML[0]) {

        @Override
        public String getFieldDefinition(ValueMetaInterface v, String tk, String pk, boolean use_autoinc) {
            return "someValue";
        }
    });
    when(databaseMeta.getQuotedSchemaTableCombination(schemaName, tableName)).thenReturn(schemaTable);
    CombinationLookupMeta clm = new CombinationLookupMeta();
    clm.setTechnicalKeyField(technicalKeyField);
    clm.setKeyLookup(new String[] { "keyLookup1", "keyLookup2" });
    clm.setDatabaseMeta(databaseMeta);
    clm.setTablename(tableName);
    clm.setSchemaName(schemaName);
    StepMeta stepMeta = mock(StepMeta.class);
    RowMetaInterface rowMetaInterface = mock(RowMetaInterface.class);
    when(rowMetaInterface.size()).thenReturn(1);
    Repository repository = mock(Repository.class);
    IMetaStore metaStore = mock(IMetaStore.class);
    SQLStatement sqlStatement = clm.getSQLStatements(new TransMeta(), stepMeta, rowMetaInterface, repository, metaStore);
    String sql = sqlStatement.getSQL();
    Assert.assertTrue(StringUtils.countMatches(sql, schemaTable) == 3);
}
Also used : Repository(org.pentaho.di.repository.Repository) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 63 with IMetaStore

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

the class JobEntryJobTest method testJobEntry.

@SuppressWarnings("unchecked")
private void testJobEntry(Repository rep, boolean includeJobName, ObjectLocationSpecificationMethod method, ObjectLocationSpecificationMethod expectedMethod) throws KettleXMLException, ParserConfigurationException, SAXException, IOException {
    List<DatabaseMeta> databases = mock(List.class);
    List<SlaveServer> slaveServers = mock(List.class);
    IMetaStore metaStore = mock(IMetaStore.class);
    JobEntryJob jobEntryJob = getJobEntryJob();
    jobEntryJob.loadXML(getEntryNode(includeJobName, method), databases, slaveServers, rep, metaStore);
    assertEquals("If we connect to repository then we use rep_name method", expectedMethod, jobEntryJob.getSpecificationMethod());
}
Also used : SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore)

Example 64 with IMetaStore

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

the class JobEntryTransTest method testJobEntry.

@SuppressWarnings("unchecked")
private void testJobEntry(Repository rep, boolean includeJobName, ObjectLocationSpecificationMethod method, ObjectLocationSpecificationMethod expectedMethod) throws KettleXMLException, ParserConfigurationException, SAXException, IOException {
    List<DatabaseMeta> databases = mock(List.class);
    List<SlaveServer> slaveServers = mock(List.class);
    IMetaStore metaStore = mock(IMetaStore.class);
    JobEntryTrans jobEntryTrans = getJobEntryTrans();
    jobEntryTrans.loadXML(getEntryNode(includeJobName, method), databases, slaveServers, rep, metaStore);
    assertEquals("If we connect to repository then we use rep_name method", expectedMethod, jobEntryTrans.getSpecificationMethod());
}
Also used : SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore)

Example 65 with IMetaStore

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

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