Skip to content

Commit

Permalink
[PDI-15856] Store NamedCluster information with HadoopFileOutputStep
Browse files Browse the repository at this point in the history
  • Loading branch information
tkafalas committed Mar 21, 2017
1 parent 47dfa13 commit 12882c6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
18 changes: 17 additions & 1 deletion core/src/org/pentaho/di/metastore/MetaStoreConst.java
Expand Up @@ -29,6 +29,7 @@
import org.pentaho.metastore.api.IMetaStore;
import org.pentaho.metastore.api.exceptions.MetaStoreException;
import org.pentaho.metastore.stores.xml.XmlMetaStore;
import org.pentaho.metastore.stores.xml.XmlUtil;

public class MetaStoreConst {

Expand All @@ -43,6 +44,7 @@ public class MetaStoreConst {
public static final String DB_ATTR_ID_SERVERNAME = "server_name";
public static final String DB_ATTR_ID_DATA_TABLESPACE = "data_tablespace";
public static final String DB_ATTR_ID_INDEX_TABLESPACE = "index_tablespace";
public static boolean disableMetaStore; // Used for testing only

// Extra information for 3rd party tools, not used by Kettle
//
Expand All @@ -56,16 +58,30 @@ public static final String getDefaultPentahoMetaStoreLocation() {
}

public static IMetaStore openLocalPentahoMetaStore() throws MetaStoreException {
return MetaStoreConst.openLocalPentahoMetaStore( true );
}

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 );
metaStore.setName( Const.PENTAHO_METASTORE_NAME );
if ( allowCreate ) {
metaStore.setName( Const.PENTAHO_METASTORE_NAME );
}
return metaStore;
}
}
45 changes: 45 additions & 0 deletions core/test-src/org/pentaho/di/metastore/MetaStoreConstTest.java
@@ -0,0 +1,45 @@
package org.pentaho.di.metastore;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.pentaho.di.core.Const;
import org.pentaho.metastore.stores.xml.XmlUtil;

import com.google.common.io.Files;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class MetaStoreConstTest {

@Test
public void testOpenLocalPentahoMetaStore() throws Exception {
MetaStoreConst.disableMetaStore = false;
File tempDir = Files.createTempDir();
String tempPath = tempDir.getAbsolutePath();
System.setProperty( Const.PENTAHO_METASTORE_FOLDER, tempPath );
String metaFolder = tempPath + File.separator + XmlUtil.META_FOLDER_NAME;

// Create a metastore
assertNotNull( MetaStoreConst.openLocalPentahoMetaStore() );
assertTrue( ( new File( metaFolder ) ).exists() );

// Check existing while disabling the metastore ( used for tests )
MetaStoreConst.disableMetaStore = true;
assertNull( MetaStoreConst.openLocalPentahoMetaStore() );

// Check existing metastore
MetaStoreConst.disableMetaStore = false;
assertNotNull( MetaStoreConst.openLocalPentahoMetaStore( false ) );

// Try to read a metastore that does not exist with allowCreate = false
FileUtils.deleteDirectory( new File( metaFolder ) );
assertNull( MetaStoreConst.openLocalPentahoMetaStore( false ) );
assertFalse( ( new File( metaFolder ) ).exists() );
}

}

0 comments on commit 12882c6

Please sign in to comment.