Search in sources :

Example 16 with VDBKey

use of org.teiid.vdb.runtime.VDBKey in project teiid by teiid.

the class VDBRepository method finishDeployment.

public void finishDeployment(String name, String version) {
    VDBKey key = new VDBKey(name, version);
    CompositeVDB v = this.vdbRepo.get(key);
    if (v == null) {
        return;
    }
    VDBMetaData metadataAwareVDB = v.getVDB();
    if (v.getOriginalVDB().getStatus() == Status.FAILED) {
        if (v.getOriginalVDB() != metadataAwareVDB && metadataAwareVDB.getStatus() == Status.LOADING) {
            metadataAwareVDB.setStatus(Status.FAILED);
        }
        return;
    }
    synchronized (metadataAwareVDB) {
        try {
            try {
                v.metadataLoadFinished(allowEnv);
            } catch (MetadataException e) {
                // $NON-NLS-1$
                LogManager.logWarning(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version, e.getMessage()));
                if (!metadataAwareVDB.isPreview()) {
                    ValidatorReport report = new ValidatorReport();
                    report.addItem(new ValidatorFailure(e.getMessage()));
                    if (!processMetadataValidatorReport(key, report)) {
                        metadataAwareVDB.setStatus(Status.FAILED);
                        notifyFinished(name, version, v);
                        return;
                    }
                }
            }
            MetadataStore store = metadataAwareVDB.removeAttachment(MetadataStore.class);
            ValidatorReport report = new MetadataValidator(store.getDatatypes(), QueryParser.getQueryParser()).validate(metadataAwareVDB, store);
            if (report.hasItems()) {
                LogManager.logWarning(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version, report.getItems().iterator().next()));
                if (!metadataAwareVDB.isPreview() && !processMetadataValidatorReport(key, report)) {
                    metadataAwareVDB.setStatus(Status.FAILED);
                    notifyFinished(name, version, v);
                    return;
                }
            }
            validateDataSources(metadataAwareVDB);
            metadataAwareVDB.setStatus(Status.ACTIVE);
            // for  replication of events, temp tables and mat views
            GlobalTableStore gts = CompositeGlobalTableStore.createInstance(v, this.bufferManager, this.objectReplictor);
            metadataAwareVDB.addAttchment(GlobalTableStore.class, gts);
            if (this.databaseStore != null) {
                metadataAwareVDB.addAttchment(DatabaseStore.class, this.databaseStore);
            }
            notifyFinished(name, version, v);
        } finally {
            if (metadataAwareVDB.getStatus() != Status.ACTIVE && metadataAwareVDB.getStatus() != Status.FAILED) {
                // guard against an unexpected exception - probably bad validation logic
                metadataAwareVDB.setStatus(Status.FAILED);
                notifyFinished(name, version, v);
            }
        }
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBKey(org.teiid.vdb.runtime.VDBKey) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) FunctionMetadataValidator(org.teiid.query.function.metadata.FunctionMetadataValidator) MetadataValidator(org.teiid.query.metadata.MetadataValidator) MetadataException(org.teiid.metadata.MetadataException) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 17 with VDBKey

use of org.teiid.vdb.runtime.VDBKey in project teiid by teiid.

the class CompositeVDB method buildCompositeState.

private void buildCompositeState(VDBRepository vdbRepository) throws VirtualDatabaseException {
    if (vdb.getVDBImports().isEmpty()) {
        this.vdb.addAttchment(ConnectorManagerRepository.class, this.cmr);
        return;
    }
    VDBMetaData newMergedVDB = this.vdb.clone();
    ConnectorManagerRepository mergedRepo = this.cmr;
    if (!this.cmr.isShared()) {
        mergedRepo = new ConnectorManagerRepository();
        mergedRepo.getConnectorManagers().putAll(this.cmr.getConnectorManagers());
    }
    newMergedVDB.addAttchment(ConnectorManagerRepository.class, mergedRepo);
    ClassLoader[] toSearch = new ClassLoader[vdb.getVDBImports().size() + 1];
    toSearch[0] = this.vdb.getAttachment(ClassLoader.class);
    this.children = new LinkedHashMap<VDBKey, CompositeVDB>();
    newMergedVDB.setImportedModels(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER));
    int i = 1;
    for (VDBImport vdbImport : vdb.getVDBImports()) {
        VDBKey key = new VDBKey(vdbImport.getName(), vdbImport.getVersion());
        if (key.isAtMost()) {
            // TODO: could allow partial versions
            throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40144, vdbKey, key));
        }
        CompositeVDB importedVDB = vdbRepository.getCompositeVDB(key);
        if (importedVDB == null) {
            throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40083, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40083, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion()));
        }
        VDBMetaData childVDB = importedVDB.getVDB();
        newMergedVDB.getVisibilityOverrides().putAll(childVDB.getVisibilityOverrides());
        toSearch[i++] = childVDB.getAttachment(ClassLoader.class);
        this.children.put(importedVDB.getVDBKey(), importedVDB);
        if (vdbImport.isImportDataPolicies()) {
            for (DataPolicy dp : importedVDB.getVDB().getDataPolicies()) {
                DataPolicyMetadata role = (DataPolicyMetadata) dp;
                if (newMergedVDB.addDataPolicy(role) != null) {
                    throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40084, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40084, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), role.getName()));
                }
                if (role.isGrantAll()) {
                    role.setSchemas(childVDB.getModelMetaDatas().keySet());
                }
            }
        }
        // add models
        for (ModelMetaData m : childVDB.getModelMetaDatas().values()) {
            if (newMergedVDB.addModel(m) != null) {
                throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40085, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40085, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), m.getName()));
            }
            newMergedVDB.getImportedModels().add(m.getName());
            // $NON-NLS-1$
            String visibilityOverride = newMergedVDB.getPropertyValue(m.getName() + ".visible");
            if (visibilityOverride != null) {
                boolean visible = Boolean.valueOf(visibilityOverride);
                newMergedVDB.setVisibilityOverride(m.getName(), visible);
            }
        }
        ConnectorManagerRepository childCmr = childVDB.getAttachment(ConnectorManagerRepository.class);
        if (childCmr == null) {
            // $NON-NLS-1$
            throw new AssertionError("childVdb does not have a connector manager repository");
        }
        if (!this.cmr.isShared()) {
            for (Map.Entry<String, ConnectorManager> entry : childCmr.getConnectorManagers().entrySet()) {
                if (mergedRepo.getConnectorManagers().put(entry.getKey(), entry.getValue()) != null) {
                    throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40086, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40086, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), entry.getKey()));
                }
            }
        }
    }
    if (toSearch[0] != null) {
        CombinedClassLoader ccl = new CombinedClassLoader(toSearch[0].getParent(), toSearch);
        this.mergedVDB.addAttchment(ClassLoader.class, ccl);
    }
    this.mergedVDB = newMergedVDB;
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) VDBKey(org.teiid.vdb.runtime.VDBKey) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBImport(org.teiid.adminapi.VDBImport) DataPolicy(org.teiid.adminapi.DataPolicy) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 18 with VDBKey

use of org.teiid.vdb.runtime.VDBKey in project teiid by teiid.

the class TestVDBRepository method testVDBRespositoryGetActive.

@Test
public void testVDBRespositoryGetActive() throws Exception {
    VDBRepository repo = new VDBRepository();
    CompositeVDB mock1 = Mockito.mock(CompositeVDB.class);
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName("name");
    vdb.setVersion(1);
    vdb.setConnectionType(ConnectionType.NONE);
    Mockito.stub(mock1.getVDB()).toReturn(vdb);
    repo.getVdbRepo().put(new VDBKey("name", 1), mock1);
    CompositeVDB mock2 = Mockito.mock(CompositeVDB.class);
    VDBMetaData vdb2 = new VDBMetaData();
    vdb2.setName("name");
    vdb2.setVersion(2);
    vdb2.setConnectionType(ConnectionType.NONE);
    Mockito.stub(mock2.getVDB()).toReturn(vdb2);
    repo.getVdbRepo().put(new VDBKey("name", 2), mock2);
    VDBMetaData live = repo.getLiveVDB("name");
    assertEquals("2", live.getVersion());
}
Also used : VDBKey(org.teiid.vdb.runtime.VDBKey) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Test(org.junit.Test)

Aggregations

VDBKey (org.teiid.vdb.runtime.VDBKey)18 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)7 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)5 MetadataStore (org.teiid.metadata.MetadataStore)5 Schema (org.teiid.metadata.Schema)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 VDBImport (org.teiid.adminapi.VDBImport)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 NavigableMap (java.util.NavigableMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1