Search in sources :

Example 6 with MetastoreLocator

use of org.pentaho.osgi.metastore.locator.api.MetastoreLocator in project pentaho-kettle by pentaho.

the class RunConfigurationManagerTest method testOrdering.

@Test
public void testOrdering() {
    MemoryMetaStore memoryMetaStore = new MemoryMetaStore();
    MetastoreLocator metastoreLocator = createMetastoreLocator(memoryMetaStore);
    DefaultRunConfigurationProvider defaultRunConfigurationProvider = new DefaultRunConfigurationProvider(metastoreLocator, defaultRunConfigurationExecutor);
    SparkRunConfigurationExecutor sparkRunConfigurationExecutor = new SparkRunConfigurationExecutor(null);
    SparkRunConfigurationProvider sparkRunConfigurationProvider = new SparkRunConfigurationProvider(metastoreLocator, sparkRunConfigurationExecutor);
    List<RunConfigurationProvider> runConfigurationProviders = new ArrayList<>();
    runConfigurationProviders.add(sparkRunConfigurationProvider);
    executionConfigurationManager = new RunConfigurationManager(runConfigurationProviders);
    executionConfigurationManager.setDefaultRunConfigurationProvider(defaultRunConfigurationProvider);
    DefaultRunConfiguration defaultRunConfiguration1 = new DefaultRunConfiguration();
    defaultRunConfiguration1.setName("z");
    executionConfigurationManager.save(defaultRunConfiguration1);
    DefaultRunConfiguration defaultRunConfiguration2 = new DefaultRunConfiguration();
    defaultRunConfiguration2.setName("f");
    executionConfigurationManager.save(defaultRunConfiguration2);
    DefaultRunConfiguration defaultRunConfiguration3 = new DefaultRunConfiguration();
    defaultRunConfiguration3.setName("x");
    executionConfigurationManager.save(defaultRunConfiguration3);
    SparkRunConfiguration sparkRunConfiguration = new SparkRunConfiguration();
    sparkRunConfiguration.setName("d");
    executionConfigurationManager.save(sparkRunConfiguration);
    DefaultRunConfiguration defaultRunConfiguration5 = new DefaultRunConfiguration();
    defaultRunConfiguration5.setName("a");
    executionConfigurationManager.save(defaultRunConfiguration5);
    List<RunConfiguration> runConfigurations = executionConfigurationManager.load();
    assertEquals(runConfigurations.get(0).getName(), DefaultRunConfigurationProvider.DEFAULT_CONFIG_NAME);
    assertEquals(runConfigurations.get(1).getName(), "a");
    assertEquals(runConfigurations.get(2).getName(), "d");
    assertEquals(runConfigurations.get(3).getName(), "f");
    assertEquals(runConfigurations.get(4).getName(), "x");
    assertEquals(runConfigurations.get(5).getName(), "z");
    List<String> names = executionConfigurationManager.getNames();
    assertEquals(names.get(0), DefaultRunConfigurationProvider.DEFAULT_CONFIG_NAME);
    assertEquals(names.get(1), "a");
    assertEquals(names.get(2), "d");
    assertEquals(names.get(3), "f");
    assertEquals(names.get(4), "x");
    assertEquals(names.get(5), "z");
}
Also used : DefaultRunConfigurationProvider(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfigurationProvider) SparkRunConfiguration(org.pentaho.di.engine.configuration.impl.spark.SparkRunConfiguration) ArrayList(java.util.ArrayList) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) MemoryMetaStore(org.pentaho.metastore.stores.memory.MemoryMetaStore) SparkRunConfigurationProvider(org.pentaho.di.engine.configuration.impl.spark.SparkRunConfigurationProvider) RunConfiguration(org.pentaho.di.engine.configuration.api.RunConfiguration) DefaultRunConfiguration(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfiguration) SparkRunConfiguration(org.pentaho.di.engine.configuration.impl.spark.SparkRunConfiguration) SparkRunConfigurationExecutor(org.pentaho.di.engine.configuration.impl.spark.SparkRunConfigurationExecutor) DefaultRunConfiguration(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfiguration) SparkRunConfigurationProvider(org.pentaho.di.engine.configuration.impl.spark.SparkRunConfigurationProvider) RunConfigurationProvider(org.pentaho.di.engine.configuration.api.RunConfigurationProvider) DefaultRunConfigurationProvider(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfigurationProvider) Test(org.junit.Test)

Example 7 with MetastoreLocator

use of org.pentaho.osgi.metastore.locator.api.MetastoreLocator in project pdi-dataservice-server-plugin by pentaho.

the class AnnotationsQueryServiceTest method testLogsExceptionOnWriteEror.

@Test
public void testLogsExceptionOnWriteEror() throws Exception {
    final DataServiceDelegate dataServiceFactory = mock(DataServiceDelegate.class);
    final DataServiceContext dataServiceContext = mock(DataServiceContext.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(dataServiceContext.getDataServiceDelegate()).thenReturn(dataServiceFactory);
    when(metastoreLocator.getMetastore()).thenReturn(null);
    final AnnotationsQueryService queryService = new AnnotationsQueryService(metastoreLocator, dataServiceResolver);
    Query query = queryService.prepareQuery("show annotations from annotatedService", 0, Collections.<String, String>emptyMap());
    MetaStoreException metaStoreException = new MetaStoreException("Unable to load dataservice annotatedService");
    when(dataServiceResolver.getDataService("annotatedService")).thenReturn(null);
    try {
        query.writeTo(new ByteArrayOutputStream());
        fail("should have got exception");
    } catch (IOException e) {
        assertEquals("Error while executing 'show annotations from annotatedService'", e.getMessage());
    }
}
Also used : DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) DataServiceDelegate(org.pentaho.di.trans.dataservice.ui.DataServiceDelegate) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with MetastoreLocator

use of org.pentaho.osgi.metastore.locator.api.MetastoreLocator in project pdi-dataservice-server-plugin by pentaho.

the class ExecutorQueryServiceTest method testQueryBuildsWithMetastore.

@Test
public void testQueryBuildsWithMetastore() throws Exception {
    final DataServiceFactory factory = mock(DataServiceFactory.class);
    final DataServiceContext context = mock(DataServiceContext.class);
    final DataServiceResolver dataServiceResolver = mock(DataServiceResolver.class);
    final DataServiceExecutor dataServiceExecutor = mock(DataServiceExecutor.class);
    final Trans serviceTrans = mock(Trans.class);
    final Trans genTrans = mock(Trans.class);
    when(context.getMetaStoreUtil()).thenReturn(factory);
    DataServiceExecutor.Builder builder = mock(DataServiceExecutor.Builder.class);
    final IMetaStore metastore = mock(IMetaStore.class);
    final MetastoreLocator metastoreLocator = mock(MetastoreLocator.class);
    when(metastoreLocator.getMetastore()).thenReturn(metastore);
    SQL sql = new SQL("select field from table");
    HashMap<String, String> parameters = new HashMap<>();
    int rowLimit = 5432;
    ExecutorQueryService executorQueryService = new ExecutorQueryService(dataServiceResolver, metastoreLocator);
    when(dataServiceResolver.createBuilder(argThat(matchesSql(sql)))).thenReturn(builder);
    when(factory.getMetaStore()).thenReturn(metastore);
    when(builder.rowLimit(rowLimit)).thenReturn(builder);
    when(builder.parameters(parameters)).thenReturn(builder);
    when(builder.metastore(metastore)).thenReturn(builder);
    when(builder.windowMode(null)).thenReturn(builder);
    when(builder.windowSize(0)).thenReturn(builder);
    when(builder.windowEvery(0)).thenReturn(builder);
    when(builder.windowLimit(0)).thenReturn(builder);
    when(builder.build()).thenReturn(dataServiceExecutor);
    when(dataServiceExecutor.getServiceTrans()).thenReturn(serviceTrans);
    when(dataServiceExecutor.getGenTrans()).thenReturn(genTrans);
    Query result = executorQueryService.prepareQuery(sql.getSqlString(), rowLimit, parameters);
    assertEquals(ImmutableList.of(serviceTrans, genTrans), result.getTransList());
    verify(builder).rowLimit(rowLimit);
    verify(builder).parameters(parameters);
    verify(builder).metastore(metastore);
}
Also used : HashMap(java.util.HashMap) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) DataServiceResolver(org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver) MetastoreLocator(org.pentaho.osgi.metastore.locator.api.MetastoreLocator) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQL(org.pentaho.di.core.sql.SQL) DataServiceContext(org.pentaho.di.trans.dataservice.DataServiceContext) DataServiceFactory(org.pentaho.di.trans.dataservice.serialization.DataServiceFactory) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Aggregations

MetastoreLocator (org.pentaho.osgi.metastore.locator.api.MetastoreLocator)8 Test (org.junit.Test)7 DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)6 DataServiceResolver (org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DataServiceDelegate (org.pentaho.di.trans.dataservice.ui.DataServiceDelegate)5 TransMeta (org.pentaho.di.trans.TransMeta)4 DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)4 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)4 ModelAnnotationGroup (org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 CreateAttribute (org.pentaho.agilebi.modeler.models.annotations.CreateAttribute)2 RunConfigurationProvider (org.pentaho.di.engine.configuration.api.RunConfigurationProvider)2 DefaultRunConfiguration (org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfiguration)2 DefaultRunConfigurationProvider (org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfigurationProvider)2 SparkRunConfiguration (org.pentaho.di.engine.configuration.impl.spark.SparkRunConfiguration)2 SparkRunConfigurationExecutor (org.pentaho.di.engine.configuration.impl.spark.SparkRunConfigurationExecutor)2 SparkRunConfigurationProvider (org.pentaho.di.engine.configuration.impl.spark.SparkRunConfigurationProvider)2 Trans (org.pentaho.di.trans.Trans)2