Search in sources :

Example 1 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceClient method getServiceInformation.

@Override
public List<IThinServiceInformation> getServiceInformation() throws SQLException {
    List<IThinServiceInformation> services = Lists.newArrayList();
    for (DataServiceMeta service : resolver.getDataServices(logErrors()::apply)) {
        TransMeta transMeta = service.getServiceTrans();
        try {
            transMeta.activateParameters();
            RowMetaInterface serviceFields = transMeta.getStepFields(service.getStepname());
            IThinServiceInformation serviceInformation = new ThinServiceInformation(service.getName(), service.isStreaming(), serviceFields);
            services.add(serviceInformation);
        } catch (Exception e) {
            String message = MessageFormat.format("Unable to get fields for service {0}, transformation: {1}", service.getName(), transMeta.getName());
            log.logError(message, e);
        }
    }
    return services;
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) IThinServiceInformation(org.pentaho.di.trans.dataservice.jdbc.api.IThinServiceInformation) ThinServiceInformation(org.pentaho.di.trans.dataservice.jdbc.ThinServiceInformation) IThinServiceInformation(org.pentaho.di.trans.dataservice.jdbc.api.IThinServiceInformation) KettleException(org.pentaho.di.core.exception.KettleException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 2 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceClient method getServiceInformation.

@Override
public ThinServiceInformation getServiceInformation(String name) throws SQLException {
    DataServiceMeta dataServiceMeta = resolver.getDataService(name);
    if (dataServiceMeta != null) {
        TransMeta transMeta = dataServiceMeta.getServiceTrans();
        try {
            transMeta.activateParameters();
            RowMetaInterface serviceFields = transMeta.getStepFields(dataServiceMeta.getStepname());
            return new ThinServiceInformation(dataServiceMeta.getName(), dataServiceMeta.isStreaming(), serviceFields);
        } catch (Exception e) {
            String message = MessageFormat.format("Unable to get fields for service {0}, transformation: {1}", dataServiceMeta.getName(), transMeta.getName());
            log.logError(message, e);
        }
    }
    return null;
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ThinServiceInformation(org.pentaho.di.trans.dataservice.jdbc.ThinServiceInformation) IThinServiceInformation(org.pentaho.di.trans.dataservice.jdbc.api.IThinServiceInformation) KettleException(org.pentaho.di.core.exception.KettleException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 3 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceMetaStoreUtil method getDataServiceByStepName.

public DataServiceMeta getDataServiceByStepName(TransMeta transMeta, String stepName) {
    Set<Integer> cacheKeys = createCacheKeys(transMeta, stepName);
    for (Map.Entry<Integer, String> entry : stepCache.getAll(cacheKeys).entrySet()) {
        String serviceName = entry.getValue();
        if (serviceName.isEmpty()) {
            // Step is marked as not having a Data Service
            return null;
        }
        // Check if Data Service is still valid
        DataServiceMeta dataServiceMeta;
        try {
            dataServiceMeta = getDataService(serviceName, transMeta);
        } catch (MetaStoreException e) {
            dataServiceMeta = null;
        }
        if (dataServiceMeta != null && dataServiceMeta.getStepname().equals(stepName)) {
            return dataServiceMeta;
        } else {
            stepCache.remove(entry.getKey(), serviceName);
        }
    }
    // Look up from embedded metastore
    for (DataServiceMeta dataServiceMeta : getDataServices(transMeta)) {
        if (dataServiceMeta.getStepname().equalsIgnoreCase(stepName)) {
            return dataServiceMeta;
        }
    }
    // Data service not found on step, store negative result in the cache
    stepCache.putAll(Maps.asMap(cacheKeys, Functions.constant("")));
    return null;
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) BaseMessages.getString(org.pentaho.di.i18n.BaseMessages.getString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class SynchronizationListener method contentSafe.

@Override
public void contentSafe(Object parentObject) {
    synchronizer.sync((TransMeta) parentObject, (e) -> {
        String message = e.getMessage();
        if (prompt) {
            if (e instanceof DataServiceAlreadyExistsException) {
                DataServiceMeta dataService = ((DataServiceAlreadyExistsException) e).getDataServiceMeta();
                delegate.syncExec(suggestEdit(dataService, message));
            }
            if (e instanceof UndefinedDataServiceException) {
                DataServiceMeta dataService = ((UndefinedDataServiceException) e).getDataServiceMeta();
                delegate.syncExec(suggestRemove(dataService, message));
            }
        }
        delegate.getLogChannel().logError(message, e);
        return null;
    });
}
Also used : DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta)

Example 5 with DataServiceMeta

use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceDialogTest method testBuilder.

@Test
public void testBuilder() throws Exception {
    final DataServiceDelegate mockDelegate = mock(DataServiceDelegate.class);
    final DataServiceDialog dialog = mock(DataServiceDialog.class);
    when(dialog.getController()).thenReturn(controller);
    // Intercept actual creation so we can inject our mock
    DataServiceDialog.Builder builder = new DataServiceDialog.Builder(model) {

        @Override
        protected DataServiceDialog createDialog(DataServiceDelegate delegate) {
            assertThat(delegate, sameInstance(mockDelegate));
            assertThat(super.createDialog(delegate), isA(DataServiceDialog.class));
            return dialog;
        }
    };
    builder.serviceStep("step");
    verify(model).setServiceStep("step");
    builder.serviceStep("");
    builder.serviceStep(null);
    verify(model, times(2)).setServiceStep("");
    DataServiceMeta dataService = mock(DataServiceMeta.class);
    when(dataService.getName()).thenReturn("Service");
    when(dataService.getStepname()).thenReturn("OUTPUT");
    ArrayList<PushDownOptimizationMeta> optimizations = Lists.newArrayList(mock(PushDownOptimizationMeta.class));
    when(dataService.getPushDownOptimizationMeta()).thenReturn(optimizations);
    builder.edit(dataService);
    verify(model).setServiceName("Service");
    verify(model).setServiceStep("OUTPUT");
    verify(model).setPushDownOptimizations(optimizations);
    Shell shell = mock(Shell.class);
    ArrayList<PushDownFactory> factories = Lists.newArrayList(mock(PushDownFactory.class));
    when(mockDelegate.getShell()).thenReturn(shell);
    when(mockDelegate.getPushDownFactories()).thenReturn(factories);
    assertThat(builder.build(mockDelegate), sameInstance(dialog));
    verify(controller).setDataService(dataService);
    verify(dialog).loadXul(same(shell), any(KettleXulLoader.class), any(SwtXulRunner.class));
    verify(dialog).initOptimizations(factories);
    Throwable xulException = new XulException();
    when(dialog.loadXul(same(shell), any(KettleXulLoader.class), any(SwtXulRunner.class))).thenThrow(xulException);
    try {
        builder.build(mockDelegate);
        fail("Expected exception was not thrown");
    } catch (KettleException e) {
        assertThat(e.getCause(), equalTo(xulException));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) KettleXulLoader(org.pentaho.di.ui.xul.KettleXulLoader) PushDownFactory(org.pentaho.di.trans.dataservice.optimization.PushDownFactory) Shell(org.eclipse.swt.widgets.Shell) XulException(org.pentaho.ui.xul.XulException) PushDownOptimizationMeta(org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta) SwtXulRunner(org.pentaho.ui.xul.swt.SwtXulRunner) Test(org.junit.Test)

Aggregations

DataServiceMeta (org.pentaho.di.trans.dataservice.DataServiceMeta)52 Test (org.junit.Test)29 TransMeta (org.pentaho.di.trans.TransMeta)16 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)9 KettleException (org.pentaho.di.core.exception.KettleException)8 DataServiceContext (org.pentaho.di.trans.dataservice.DataServiceContext)6 DataServiceDelegate (org.pentaho.di.trans.dataservice.ui.DataServiceDelegate)6 StepMeta (org.pentaho.di.trans.step.StepMeta)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Before (org.junit.Before)4 RowMeta (org.pentaho.di.core.row.RowMeta)4 DataServiceResolver (org.pentaho.di.trans.dataservice.resolvers.DataServiceResolver)4 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)4 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)4 MetastoreLocator (org.pentaho.osgi.metastore.locator.api.MetastoreLocator)4 ModelAnnotationGroup (org.pentaho.agilebi.modeler.models.annotations.ModelAnnotationGroup)3 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 File (java.io.File)2 IOException (java.io.IOException)2 URL (java.net.URL)2