Search in sources :

Example 6 with VDBKey

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

the class EmbeddedServer method deployVDB.

/**
 * Deploy the given set of models as vdb name.1
 * @param name
 * @param models
 * @throws ConnectorManagerException
 * @throws VirtualDatabaseException
 * @throws TranslatorException
 */
public void deployVDB(String name, ModelMetaData... models) throws ConnectorManagerException, VirtualDatabaseException, TranslatorException {
    VDBMetaData vdb = new VDBMetaData();
    vdb.setXmlDeployment(true);
    VDBKey key = new VDBKey(name, null);
    vdb.setName(key.getName());
    if (key.isAtMost()) {
        if (name.endsWith(".")) {
        // error
        } else {
            // $NON-NLS-1$
            vdb.setVersion("1");
        }
    } else {
        vdb.setVersion(key.getVersion());
    }
    vdb.setModels(Arrays.asList(models));
    // TODO: the api should be hardened to prevent the creation of invalid metadata
    // missing source/translator names will cause issues
    deployVDB(vdb, null);
}
Also used : VDBKey(org.teiid.vdb.runtime.VDBKey) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData)

Example 7 with VDBKey

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

the class VDBRepository method addVDB.

public void addVDB(VDBMetaData vdb, MetadataStore metadataStore, LinkedHashMap<String, VDBResources.Resource> visibilityMap, UDFMetaData udf, ConnectorManagerRepository cmr) throws VirtualDatabaseException {
    // get the system VDB metadata store
    if (this.systemStore == null) {
        throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40022, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40022));
    }
    if (dataRolesRequired && vdb.getDataPolicyMap().isEmpty()) {
        throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40143, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40143, vdb));
    }
    boolean pgMetadataEnabled = ADD_PG_METADATA;
    String includePgMetadata = vdb.getPropertyValue("include-pg-metadata");
    if (includePgMetadata != null) {
        pgMetadataEnabled = Boolean.parseBoolean(includePgMetadata);
    }
    if (pgMetadataEnabled && odbcException != null) {
        throw odbcException;
    }
    MetadataStore[] stores = null;
    if (pgMetadataEnabled) {
        stores = new MetadataStore[] { this.systemStore, odbcStore };
    } else {
        stores = new MetadataStore[] { this.systemStore };
    }
    CompositeVDB cvdb = new CompositeVDB(vdb, metadataStore, visibilityMap, udf, this.systemFunctionManager.getSystemFunctions(), cmr, this, stores);
    lock.lock();
    try {
        VDBKey vdbKey = cvdb.getVDBKey();
        if (vdbKey.isAtMost()) {
            throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40145, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40145, vdbKey));
        }
        if (vdbRepo.containsKey(vdbKey)) {
            throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40035, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40035, vdb.getName(), vdb.getVersion()));
        }
        // canonicalize the version
        vdb.setVersion(vdbKey.getVersion());
        // save the key for comparisons
        vdb.addAttchment(VDBKey.class, vdbKey);
        vdb.setStatus(Status.LOADING);
        this.vdbRepo.put(vdbKey, cvdb);
        this.pendingDeployments.remove(vdbKey);
        vdbAdded.signalAll();
    } finally {
        lock.unlock();
    }
    notifyAdd(vdb.getName(), vdb.getVersion(), cvdb);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBKey(org.teiid.vdb.runtime.VDBKey)

Example 8 with VDBKey

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

the class VDBRepository method addPendingDeployment.

public void addPendingDeployment(VDBMetaData deployment) {
    deployment.setStatus(Status.LOADING);
    VDBKey key = new VDBKey(deployment.getName(), deployment.getVersion());
    this.pendingDeployments.put(key, deployment);
}
Also used : VDBKey(org.teiid.vdb.runtime.VDBKey)

Example 9 with VDBKey

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

the class VDBRepository method getVDB.

public VDBMetaData getVDB(String vdbName, Object vdbVersion) {
    VDBKey key = new VDBKey(vdbName, vdbVersion);
    CompositeVDB cvdb = this.vdbRepo.get(key);
    if (cvdb != null) {
        return cvdb.getVDB();
    }
    return this.pendingDeployments.get(key);
}
Also used : VDBKey(org.teiid.vdb.runtime.VDBKey)

Example 10 with VDBKey

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

the class VDBRepository method getLiveVDB.

/**
 * A live vdb may be loading or active
 * @param vdbName
 * @return
 */
public VDBMetaData getLiveVDB(String vdbName) {
    VDBMetaData result = null;
    VDBKey key = new VDBKey(vdbName, null);
    if (!key.isAtMost()) {
        CompositeVDB v = this.vdbRepo.get(key);
        if (v != null) {
            return v.getVDB();
        }
        return null;
    }
    for (Map.Entry<VDBKey, CompositeVDB> entry : this.vdbRepo.tailMap(key).entrySet()) {
        if (!key.acceptsVerion(entry.getKey())) {
            break;
        }
        VDBMetaData vdb = entry.getValue().getVDB();
        switch(vdb.getConnectionType()) {
            case ANY:
                result = vdb;
                break;
            case BY_VERSION:
            case NONE:
                if (result == null || result.getConnectionType() == ConnectionType.NONE) {
                    result = vdb;
                }
                break;
        }
    }
    return result;
}
Also used : VDBKey(org.teiid.vdb.runtime.VDBKey) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

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