Search in sources :

Example 41 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class EmbeddedServer method deployVDBZip.

/**
 * Deploy a vdb zip file.  The name and version will be derived from the xml.
 * @param url
 * @throws TranslatorException
 * @throws ConnectorManagerException
 * @throws VirtualDatabaseException
 * @throws URISyntaxException
 * @throws IOException
 */
public void deployVDBZip(URL url) throws VirtualDatabaseException, ConnectorManagerException, TranslatorException, IOException, URISyntaxException {
    VirtualFile root = PureZipFileSystem.mount(url);
    VDBMetaData metadata;
    // $NON-NLS-1$
    VirtualFile vdbMetadata = root.getChild("/META-INF/vdb.xml");
    if (vdbMetadata.exists()) {
        try {
            VDBMetadataParser.validate(vdbMetadata.openStream());
        } catch (SAXException e) {
            throw new VirtualDatabaseException(e);
        }
        InputStream is = vdbMetadata.openStream();
        try {
            metadata = VDBMetadataParser.unmarshell(is);
        } catch (XMLStreamException e) {
            throw new VirtualDatabaseException(e);
        }
    } else {
        // $NON-NLS-1$
        vdbMetadata = root.getChild("/META-INF/vdb.ddl");
        DeploymentBasedDatabaseStore store = new DeploymentBasedDatabaseStore(getVDBRepository());
        metadata = store.getVDBMetadata(ObjectConverterUtil.convertToString(vdbMetadata.openStream()));
    }
    VDBResources resources = new VDBResources(root, metadata);
    deployVDB(metadata, resources);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBResources(org.teiid.query.metadata.VDBResources) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) DeploymentBasedDatabaseStore(org.teiid.metadatastore.DeploymentBasedDatabaseStore) SAXException(org.xml.sax.SAXException)

Example 42 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData 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 43 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class EmbeddedServer method getSchemaDdl.

/**
 * Get the effective ddl text for the given schema
 * @param vdbName
 * @param schemaName
 * @return the ddl or null if the vdb/schema does not exist
 */
public String getSchemaDdl(String vdbName, String schemaName) {
    // $NON-NLS-1$
    VDBMetaData vdb = repo.getVDB(vdbName, "1");
    if (vdb == null) {
        return null;
    }
    TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class);
    if (metadata == null) {
        return null;
    }
    Schema schema = metadata.getMetadataStore().getSchema(schemaName);
    if (schema == null) {
        return null;
    }
    return DDLStringVisitor.getDDLString(schema, null, null);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Schema(org.teiid.metadata.Schema)

Example 44 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class EmbeddedServer method deployVDB.

/**
 * Deploy a vdb.xml file.  The name and version will be derived from the xml.
 * @param is, which will be closed by this deployment
 * @param ddl, true if the file contents are DDL
 * @throws TranslatorException
 * @throws ConnectorManagerException
 * @throws VirtualDatabaseException
 * @throws IOException
 */
public void deployVDB(InputStream is, boolean ddl) throws VirtualDatabaseException, ConnectorManagerException, TranslatorException, IOException {
    if (is == null) {
        return;
    }
    byte[] bytes = ObjectConverterUtil.convertToByteArray(is);
    VDBMetaData metadata = null;
    if (ddl) {
        DeploymentBasedDatabaseStore store = new DeploymentBasedDatabaseStore(getVDBRepository());
        metadata = store.getVDBMetadata(new String(bytes));
    } else {
        try {
            // TODO: find a way to do this off of the stream
            VDBMetadataParser.validate(new ByteArrayInputStream(bytes));
        } catch (SAXException e) {
            throw new VirtualDatabaseException(e);
        }
        try {
            metadata = VDBMetadataParser.unmarshell(new ByteArrayInputStream(bytes));
        } catch (XMLStreamException e) {
            throw new VirtualDatabaseException(e);
        }
    }
    metadata.setXmlDeployment(true);
    deployVDB(metadata, null);
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) DeploymentBasedDatabaseStore(org.teiid.metadatastore.DeploymentBasedDatabaseStore) SAXException(org.xml.sax.SAXException)

Example 45 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class VDBRepository method waitForFinished.

public void waitForFinished(VDBKey key, int timeOutMillis) throws ConnectionException {
    CompositeVDB cvdb = null;
    if (timeOutMillis < 0) {
        timeOutMillis = DEFAULT_TIMEOUT_MILLIS;
    }
    long timeOutNanos = TimeUnit.MILLISECONDS.toNanos(timeOutMillis);
    lock.lock();
    try {
        while ((cvdb = this.vdbRepo.get(key)) == null) {
            if (timeOutNanos <= 0) {
                throw new ConnectionException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40096, timeOutMillis, key.getName(), key.getVersion()));
            }
            timeOutNanos = this.vdbAdded.awaitNanos(timeOutNanos);
        }
    } catch (InterruptedException e) {
        return;
    } finally {
        lock.unlock();
    }
    VDBMetaData vdb = cvdb.getVDB();
    long finishNanos = System.nanoTime() + timeOutNanos;
    synchronized (vdb) {
        while (vdb.getStatus() != Status.ACTIVE) {
            long millis = timeOutNanos / 1000000;
            if (millis <= 0) {
                throw new ConnectionException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40097, timeOutMillis, key.getName(), key.getVersion(), vdb.getValidityErrors()));
            }
            try {
                vdb.wait(millis);
            } catch (InterruptedException e) {
                return;
            }
            timeOutNanos = finishNanos - System.nanoTime();
        }
    }
}
Also used : VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ConnectionException(org.teiid.net.ConnectionException)

Aggregations

VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)121 Test (org.junit.Test)48 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)36 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 MetadataStore (org.teiid.metadata.MetadataStore)15 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)14 VDBRepository (org.teiid.deployers.VDBRepository)12 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)9 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)9 Properties (java.util.Properties)8 XMLStreamException (javax.xml.stream.XMLStreamException)8 VDBImportMetadata (org.teiid.adminapi.impl.VDBImportMetadata)8 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)7 TeiidComponentException (org.teiid.core.TeiidComponentException)7 VDBKey (org.teiid.vdb.runtime.VDBKey)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)6 Schema (org.teiid.metadata.Schema)6 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)5