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);
}
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);
}
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);
}
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);
}
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();
}
}
}
Aggregations