Search in sources :

Example 11 with ConnectorManagerRepository

use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.

the class TestCompositeVDB method testImportErrors.

@Test(expected = VirtualDatabaseException.class)
public void testImportErrors() throws Exception {
    VDBRepository repo = new VDBRepository();
    repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
    repo.setSystemFunctionManager(RealMetadataFactory.SFM);
    MetadataStore metadataStore = RealMetadataFactory.exampleBQTCached().getMetadataStore();
    VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
    vdb = createVDBMetadata(metadataStore, "bqt1");
    VDBImportMetadata vdbImport = new VDBImportMetadata();
    vdbImport.setName("foo");
    vdb.getVDBImports().add(vdbImport);
    try {
        // foo does not exist
        repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
        fail();
    } catch (VirtualDatabaseException e) {
    }
    vdb = createVDBMetadata(metadataStore, "bqt1");
    vdbImport.setName("bqt");
    vdb.getVDBImports().add(vdbImport);
    // model conflict
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Test(org.junit.Test)

Example 12 with ConnectorManagerRepository

use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.

the class DataTierManagerImpl method registerRequest.

public TupleSource registerRequest(CommandContext context, Command command, String modelName, final RegisterRequestParameter parameterObject) throws TeiidComponentException, TeiidProcessingException {
    RequestWorkItem workItem = context.getWorkItem();
    Assertion.isNotNull(workItem);
    if (CoreConstants.SYSTEM_MODEL.equals(modelName) || CoreConstants.SYSTEM_ADMIN_MODEL.equals(modelName)) {
        return processSystemQuery(context, command, workItem.getDqpWorkContext());
    }
    AtomicRequestMessage aqr = createRequest(workItem, command, modelName, parameterObject.connectorBindingId, parameterObject.nodeID);
    aqr.setCommandContext(context);
    if (parameterObject.fetchSize > 0) {
        aqr.setFetchSize(2 * parameterObject.fetchSize);
    }
    if (parameterObject.limit > 0) {
        aqr.setFetchSize(Math.min(parameterObject.limit, aqr.getFetchSize()));
    }
    aqr.setCopyStreamingLobs(parameterObject.copyStreamingLobs);
    Collection<GroupSymbol> accessedGroups = null;
    if (context.getDataObjects() != null) {
        QueryMetadataInterface metadata = context.getMetadata();
        accessedGroups = GroupCollectorVisitor.getGroupsIgnoreInlineViews(command, false);
        boolean usedModel = false;
        for (GroupSymbol gs : accessedGroups) {
            context.accessedDataObject(gs.getMetadataID());
            // check the source/tables/procs for determinism level
            Object mid = gs.getMetadataID();
            if (mid instanceof TempMetadataID) {
                TempMetadataID tid = (TempMetadataID) mid;
                if (tid.getOriginalMetadataID() != null) {
                    mid = tid.getOriginalMetadataID();
                }
            }
            String specificProp = metadata.getExtensionProperty(mid, AbstractMetadataRecord.RELATIONAL_URI + DDLConstants.DETERMINISM, false);
            if (specificProp == null) {
                if (!usedModel) {
                    Object modelId = metadata.getModelID(mid);
                    String prop = metadata.getExtensionProperty(modelId, AbstractMetadataRecord.RELATIONAL_URI + DDLConstants.DETERMINISM, false);
                    if (prop != null) {
                        usedModel = true;
                        // set model property
                        context.setDeterminismLevel(Determinism.valueOf(prop.toUpperCase()));
                    }
                }
                continue;
            }
            context.setDeterminismLevel(Determinism.valueOf(specificProp.toUpperCase()));
        }
    }
    ConnectorManagerRepository cmr = workItem.getDqpWorkContext().getVDB().getAttachment(ConnectorManagerRepository.class);
    ConnectorManager connectorManager = cmr.getConnectorManager(aqr.getConnectorName());
    if (connectorManager == null) {
        // can happen if sources are removed
        if (RelationalNodeUtil.hasOutputParams(command)) {
            // $NON-NLS-1$
            throw new AssertionError("A source is required to execute a procedure returning parameters");
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        LogManager.logDetail(LogConstants.CTX_DQP, "source", aqr.getConnectorName(), "no longer exists, returning dummy results");
        return CollectionTupleSource.createNullTupleSource();
    }
    ConnectorWork work = connectorManager.registerRequest(aqr);
    if (!work.isForkable()) {
        aqr.setSerial(true);
    }
    CacheID cid = null;
    CacheDirective cd = null;
    if (workItem.getRsCache() != null && command.areResultsCachable()) {
        CachableVisitor cv = new CachableVisitor();
        PreOrPostOrderNavigator.doVisit(command, cv, PreOrPostOrderNavigator.PRE_ORDER, true);
        if (cv.cacheable) {
            try {
                cd = work.getCacheDirective();
            } catch (TranslatorException e) {
                // $NON-NLS-1$
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID30504, e, aqr.getConnectorName() + ": " + e.getMessage());
            }
            if (cd != null) {
                if (cd.getScope() == Scope.NONE) {
                    parameterObject.doNotCache = true;
                } else {
                    String cmdString = command.toString();
                    if (cmdString.length() < 100000) {
                        // TODO: this check won't be needed if keys aren't exclusively held in memory
                        cid = new CacheID(workItem.getDqpWorkContext(), ParseInfo.DEFAULT_INSTANCE, cmdString);
                        cid.setParameters(cv.parameters);
                        if (cd.getInvalidation() == null || cd.getInvalidation() == Invalidation.NONE) {
                            CachedResults cr = workItem.getRsCache().get(cid);
                            if (cr != null && (cr.getRowLimit() == 0 || (parameterObject.limit > 0 && cr.getRowLimit() >= parameterObject.limit))) {
                                parameterObject.doNotCache = true;
                                // $NON-NLS-1$
                                LogManager.logDetail(LogConstants.CTX_DQP, "Using cache entry for", cid);
                                work.close();
                                return cr.getResults().createIndexedTupleSource();
                            }
                        } else if (cd.getInvalidation() == Invalidation.IMMEDIATE) {
                            workItem.getRsCache().remove(cid, CachingTupleSource.getDeterminismLevel(cd.getScope()));
                        }
                    }
                }
            } else {
                // $NON-NLS-1$
                LogManager.logTrace(LogConstants.CTX_DQP, aqr.getAtomicRequestID(), "no cache directive");
            }
        } else {
            // $NON-NLS-1$
            LogManager.logTrace(LogConstants.CTX_DQP, aqr.getAtomicRequestID(), "command not cachable");
        }
    }
    DataTierTupleSource dtts = new DataTierTupleSource(aqr, workItem, work, this, parameterObject.limit);
    TupleSource result = dtts;
    TupleBuffer tb = null;
    if (cid != null) {
        tb = getBufferManager().createTupleBuffer(aqr.getCommand().getProjectedSymbols(), aqr.getCommandContext().getConnectionId(), TupleSourceType.PROCESSOR);
        result = new CachingTupleSource(this, tb, (DataTierTupleSource) result, cid, parameterObject, cd, accessedGroups, workItem);
    }
    if (work.isThreadBound()) {
        result = handleThreadBound(workItem, aqr, work, cid, result, dtts, tb);
    } else if (!aqr.isSerial()) {
        dtts.addWork();
    }
    return result;
}
Also used : CachableVisitor(org.teiid.dqp.internal.process.TupleSourceCache.CachableVisitor) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) TempMetadataID(org.teiid.query.metadata.TempMetadataID) TupleBuffer(org.teiid.common.buffer.TupleBuffer) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) TeiidProcessingException(org.teiid.core.TeiidProcessingException) CacheDirective(org.teiid.translator.CacheDirective) CacheID(org.teiid.dqp.internal.process.SessionAwareCache.CacheID) CopyOnReadTupleSource(org.teiid.dqp.internal.process.TupleSourceCache.CopyOnReadTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TranslatorException(org.teiid.translator.TranslatorException) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) ConnectorWork(org.teiid.dqp.internal.datamgr.ConnectorWork) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage)

Example 13 with ConnectorManagerRepository

use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.

the class TestConnectorCapabilitiesFinder method testFind.

@Test
public void testFind() throws Exception {
    // $NON-NLS-1$
    String modelName = "model";
    // $NON-NLS-1$
    String functionName = "fakeFunction";
    BasicSourceCapabilities caps = new BasicSourceCapabilities();
    // $NON-NLS-1$
    caps.setFunctionSupport("fakeFunction", true);
    ArrayList<String> bindings = new ArrayList<String>();
    bindings.add(modelName);
    VDBMetaData vdb = Mockito.mock(VDBMetaData.class);
    ModelMetaData model = Mockito.mock(ModelMetaData.class);
    Mockito.stub(vdb.getModel(modelName)).toReturn(model);
    Mockito.stub(model.getSourceNames()).toReturn(bindings);
    BasicSourceCapabilities basicSourceCapabilities = new BasicSourceCapabilities();
    basicSourceCapabilities.setFunctionSupport(functionName, true);
    ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
    ConnectorManager cm = Mockito.mock(ConnectorManager.class);
    Mockito.stub(cm.getCapabilities()).toReturn(basicSourceCapabilities);
    Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(cm);
    CachedFinder finder = new CachedFinder(repo, vdb);
    // Test
    SourceCapabilities actual = finder.findCapabilities(modelName);
    // $NON-NLS-1$
    assertEquals("Did not get expected capabilities", true, actual.supportsFunction(functionName));
    assertTrue(finder.isValid(modelName));
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ArrayList(java.util.ArrayList) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) SourceCapabilities(org.teiid.query.optimizer.capabilities.SourceCapabilities) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 14 with ConnectorManagerRepository

use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.

the class TestDQPCore method setUp.

@Before
public void setUp() throws Exception {
    agds = new AutoGenDataService();
    DQPWorkContext context = RealMetadataFactory.buildWorkContext(RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.exampleBQTCached().getMetadataStore(), "bqt"));
    // $NON-NLS-1$
    context.getVDB().getModel("BQT3").setVisible(false);
    // $NON-NLS-1$
    context.getVDB().getModel("VQT").setVisible(false);
    HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
    policies.put("foo", new DataPolicyMetadata());
    context.setPolicies(policies);
    ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
    context.getVDB().addAttchment(ConnectorManagerRepository.class, repo);
    Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(agds);
    BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
    bm.setInlineLobs(false);
    FakeBufferService bs = new FakeBufferService(bm, bm);
    core = new DQPCore();
    core.setBufferManager(bs.getBufferManager());
    core.setResultsetCache(new SessionAwareCache<CachedResults>("resultset", new DefaultCacheFactory(new CacheConfiguration()), SessionAwareCache.Type.RESULTSET, 0));
    core.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>("preparedplan", new DefaultCacheFactory(new CacheConfiguration()), SessionAwareCache.Type.PREPAREDPLAN, 0));
    core.setTransactionService(new FakeTransactionService());
    config = new DQPConfiguration();
    config.setMaxActivePlans(1);
    config.setUserRequestSourceConcurrency(2);
    DefaultAuthorizationValidator daa = new DefaultAuthorizationValidator();
    daa.setPolicyDecider(new DataRolePolicyDecider());
    config.setAuthorizationValidator(daa);
    core.start(config);
    core.getPrepPlanCache().setModTime(1);
    core.getRsCache().setTupleBufferCache(bs.getBufferManager());
}
Also used : BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) HashMap(java.util.HashMap) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) DefaultCacheFactory(org.teiid.cache.DefaultCacheFactory) FakeBufferService(org.teiid.dqp.service.FakeBufferService) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) DataPolicy(org.teiid.adminapi.DataPolicy) FakeTransactionService(org.teiid.dqp.internal.datamgr.FakeTransactionService) AutoGenDataService(org.teiid.dqp.service.AutoGenDataService) CacheConfiguration(org.teiid.cache.CacheConfiguration) Before(org.junit.Before)

Example 15 with ConnectorManagerRepository

use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.

the class TestPreparedStatement method helpGetProcessorPlan.

static PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List<?> values, CapabilitiesFinder capFinder, QueryMetadataInterface metadata, SessionAwareCache<PreparedPlan> prepPlanCache, int conn, boolean callableStatement, boolean limitResults, VDBMetaData vdb) throws TeiidComponentException, TeiidProcessingException {
    // Create Request
    RequestMessage request = new RequestMessage(preparedSql);
    if (callableStatement) {
        request.setStatementType(StatementType.CALLABLE);
    } else {
        request.setStatementType(StatementType.PREPARED);
    }
    request.setParameterValues(values);
    if (values != null && values.size() > 0 && values.get(0) instanceof List) {
        request.setBatchedUpdate(true);
    }
    if (limitResults) {
        request.setRowLimit(1);
    }
    DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(metadata, vdb);
    workContext.getSession().setSessionId(String.valueOf(conn));
    PreparedStatementRequest serverRequest = new PreparedStatementRequest(prepPlanCache);
    ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
    Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(new AutoGenDataService());
    serverRequest.initialize(request, BufferManagerFactory.getStandaloneBufferManager(), null, new FakeTransactionService(), null, workContext, prepPlanCache);
    serverRequest.setMetadata(capFinder, metadata);
    DefaultAuthorizationValidator drav = new DefaultAuthorizationValidator();
    serverRequest.setAuthorizationValidator(drav);
    serverRequest.processRequest();
    assertNotNull(serverRequest.processPlan);
    return serverRequest;
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) RequestMessage(org.teiid.client.RequestMessage) ArrayList(java.util.ArrayList) List(java.util.List) FakeTransactionService(org.teiid.dqp.internal.datamgr.FakeTransactionService) AutoGenDataService(org.teiid.dqp.service.AutoGenDataService)

Aggregations

ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)30 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)15 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)14 Test (org.junit.Test)9 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)9 MetadataStore (org.teiid.metadata.MetadataStore)8 ArrayList (java.util.ArrayList)5 ExecutionFactory (org.teiid.translator.ExecutionFactory)5 TranslatorException (org.teiid.translator.TranslatorException)5 AdminProcessingException (org.teiid.adminapi.AdminProcessingException)4 SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)4 FakeTransactionService (org.teiid.dqp.internal.datamgr.FakeTransactionService)4 AutoGenDataService (org.teiid.dqp.service.AutoGenDataService)4 HashMap (java.util.HashMap)3 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)3 VDBImportMetadata (org.teiid.adminapi.impl.VDBImportMetadata)3 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)3 List (java.util.List)2 BeforeClass (org.junit.BeforeClass)2 DataPolicy (org.teiid.adminapi.DataPolicy)2