use of org.teiid.deployers.VirtualDatabaseException in project teiid by teiid.
the class TestEmbeddedServer method testValidationOrder.
@Test
public void testValidationOrder() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setUseDisk(false);
es.start(ec);
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("b");
mmd1.setModelType(Type.VIRTUAL);
mmd1.setSchemaSourceType("ddl");
mmd1.setSchemaText("create view v as select 1");
ModelMetaData mmd2 = new ModelMetaData();
mmd2.setName("a");
mmd2.setModelType(Type.VIRTUAL);
mmd2.setSchemaSourceType("ddl");
mmd2.setSchemaText("create view v1 as select * from v");
// We need mmd1 to validate before mmd2, reversing the order will result in an exception
es.deployVDB("test", mmd1, mmd2);
try {
es.deployVDB("test2", mmd2, mmd1);
fail();
} catch (VirtualDatabaseException e) {
}
}
use of org.teiid.deployers.VirtualDatabaseException in project teiid by teiid.
the class AbstractVDBDeployer method processVDBDDL.
private void processVDBDDL(final VDBMetaData vdb, final MetadataStore vdbMetadataStore, final ConnectorManagerRepository cmr, final VDBResources vdbResources) {
if (vdb.getStatus() == Status.FAILED) {
return;
}
String ddl = vdb.getPropertyValue(VDBMetaData.TEIID_DDL);
if (ddl != null) {
final Database database = DatabaseUtil.convert(vdb, vdbMetadataStore);
CompositeMetadataStore compositeStore = new CompositeMetadataStore(vdbMetadataStore);
final TransformationMetadata metadata = new TransformationMetadata(vdb, compositeStore, null, getVDBRepository().getSystemFunctionManager().getSystemFunctions(), null);
DeploymentBasedDatabaseStore deploymentStore = new DeploymentBasedDatabaseStore(getVDBRepository()) {
@Override
protected TransformationMetadata getTransformationMetadata() {
return metadata;
}
@Override
public void importSchema(String schemaName, String serverType, String serverName, String foreignSchemaName, List<String> includeTables, List<String> excludeTables, Map<String, String> properties) {
ModelMetaData model = vdb.getModel(schemaName);
MetadataFactory factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
factory.getModelProperties().putAll(model.getPropertiesMap());
factory.getModelProperties().putAll(properties);
if (!includeTables.isEmpty()) {
// $NON-NLS-1$
factory.getModelProperties().put("importer.includeTables", StringUtil.join(includeTables, ","));
}
if (!excludeTables.isEmpty()) {
// $NON-NLS-1$
factory.getModelProperties().put("importer.excludeTables", StringUtil.join(excludeTables, ","));
}
factory.setParser(new QueryParser());
if (vdbResources != null) {
factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
}
MetadataRepository baseRepo = model.getAttachment(MetadataRepository.class);
MetadataRepository metadataRepository;
try {
metadataRepository = getMetadataRepository(serverType);
if (metadataRepository == null) {
throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), serverType));
}
} catch (VirtualDatabaseException e1) {
throw new MetadataException(e1);
}
metadataRepository = new ChainingMetadataRepository(Arrays.asList(new MetadataRepositoryWrapper(metadataRepository, null), baseRepo));
ExecutionFactory ef = null;
Object cf = null;
Exception te = null;
for (ConnectorManager cm : getConnectorManagers(model, cmr)) {
if (te != null) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, te, "Failed to get metadata, trying next source.");
te = null;
}
try {
if (cm != null) {
ef = cm.getExecutionFactory();
cf = cm.getConnectionFactory();
}
} catch (TranslatorException e) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, e, "Failed to get a connection factory for metadata load.");
}
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_RUNTIME, MessageLevel.TRACE)) {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "CREATE SCHEMA", factory.getSchema().getName(), ";\n", DDLStringVisitor.getDDLString(factory.getSchema(), null, null));
}
try {
metadataRepository.loadMetadata(factory, ef, cf);
break;
} catch (Exception e) {
te = e;
factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
factory.getModelProperties().putAll(model.getPropertiesMap());
factory.getModelProperties().putAll(properties);
factory.setParser(new QueryParser());
if (vdbResources != null) {
factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
}
}
}
if (te != null) {
if (te instanceof RuntimeException) {
throw (RuntimeException) te;
}
throw new MetadataException(te);
}
}
};
deploymentStore.startEditing(false);
deploymentStore.databaseCreated(database);
deploymentStore.databaseSwitched(database.getName(), database.getVersion());
deploymentStore.setMode(Mode.SCHEMA);
try {
QueryParser.getQueryParser().parseDDL(deploymentStore, new StringReader(ddl));
} finally {
deploymentStore.stopEditing();
}
DatabaseUtil.copyDatabaseGrantsAndRoles(database, vdb);
}
}
use of org.teiid.deployers.VirtualDatabaseException in project teiid by teiid.
the class AbstractVDBDeployer method getMetadataRepository.
private MetadataRepository<?, ?> getMetadataRepository(VDBMetaData vdb, ModelMetaData model, MetadataRepository<?, ?> defaultRepo) throws VirtualDatabaseException {
if (model.getSourceMetadataType().isEmpty()) {
if (defaultRepo != null) {
return defaultRepo;
}
if (model.isSource()) {
return new ChainingMetadataRepository(Arrays.asList(new NativeMetadataRepository(), new DirectQueryMetadataRepository()));
}
throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), null));
}
List<MetadataRepository<?, ?>> repos = new ArrayList<MetadataRepository<?, ?>>(2);
for (int i = 0; i < model.getSourceMetadataType().size(); i++) {
String schemaTypes = model.getSourceMetadataType().get(i);
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(schemaTypes, ",");
while (st.hasMoreTokens()) {
String repoType = st.nextToken().trim();
MetadataRepository<?, ?> current = getMetadataRepository(repoType);
if (current == null) {
throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), repoType));
}
if (model.getSourceMetadataText().size() > i) {
current = new MetadataRepositoryWrapper(current, model.getSourceMetadataText().get(i));
}
repos.add(current);
}
}
if (model.getModelType() == ModelMetaData.Type.PHYSICAL) {
repos.add(new DirectQueryMetadataRepository());
}
if (model.getModelType() == ModelMetaData.Type.VIRTUAL) {
repos.add(new MaterializationMetadataRepository());
}
if (repos.size() == 1) {
return repos.get(0);
}
return new ChainingMetadataRepository(repos);
}
use of org.teiid.deployers.VirtualDatabaseException in project teiid by teiid.
the class AbstractVDBDeployer method assignMetadataRepositories.
protected void assignMetadataRepositories(VDBMetaData deployment, MetadataRepository<?, ?> defaultRepo) throws VirtualDatabaseException {
for (ModelMetaData model : deployment.getModelMetaDatas().values()) {
if (model.getModelType() != Type.OTHER && (model.getName() == null || model.getName().indexOf('.') >= 0) || model.getName().equalsIgnoreCase(CoreConstants.SYSTEM_MODEL) || model.getName().equalsIgnoreCase(CoreConstants.SYSTEM_ADMIN_MODEL) || model.getName().equalsIgnoreCase(CoreConstants.ODBC_MODEL)) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40121, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40121, model.getName(), deployment.getName(), deployment.getVersion()));
}
if (model.isSource() && model.getSourceNames().isEmpty()) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40093, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40093, model.getName(), deployment.getName(), deployment.getVersion()));
}
if (model.getModelType() == Type.FUNCTION || model.getModelType() == Type.OTHER) {
continue;
}
MetadataRepository<?, ?> repo = getMetadataRepository(deployment, model, defaultRepo);
// handle multi-source column creation
if (model.isSupportsMultiSourceBindings() && Boolean.valueOf(model.getPropertyValue("multisource.addColumn"))) {
// $NON-NLS-1$
List<MetadataRepository<?, ?>> repos = new ArrayList<MetadataRepository<?, ?>>(2);
repos.add(repo);
String columnName = model.getPropertyValue(MultiSourceMetadataWrapper.MULTISOURCE_COLUMN_NAME);
repos.add(new MultiSourceMetadataRepository(columnName == null ? MultiSourceElement.DEFAULT_MULTI_SOURCE_ELEMENT_NAME : columnName));
repo = new ChainingMetadataRepository(repos);
}
model.addAttchment(MetadataRepository.class, repo);
}
}
use of org.teiid.deployers.VirtualDatabaseException in project teiid by teiid.
the class FakeServer method deployVDB.
public void deployVDB(String vdbName, MetadataStore metadata, DeployVDBParameter parameterObject) {
VDBMetaData vdbMetaData = null;
try {
if (parameterObject.vdbResources != null && parameterObject.useVdbXml) {
VDBResource resource = parameterObject.vdbResources.get("/META-INF/vdb.xml");
if (resource != null) {
vdbMetaData = VDBMetadataParser.unmarshell(resource.openStream());
}
}
if (vdbMetaData == null) {
vdbMetaData = new VDBMetaData();
vdbMetaData.setName(vdbName);
for (Schema schema : metadata.getSchemas().values()) {
ModelMetaData model = addModel(vdbMetaData, schema);
if (parameterObject.metadataRepo != null) {
model.addAttchment(MetadataRepository.class, parameterObject.metadataRepo);
// fakeserver does not load through the repository framework, so call load after the fact here.
MetadataFactory mf = createMetadataFactory(vdbMetaData, metadata, model, parameterObject.vdbResources);
mf.setSchema(schema);
try {
parameterObject.metadataRepo.loadMetadata(mf, null, null);
} catch (TranslatorException e) {
throw new TeiidRuntimeException(e);
}
}
}
} else {
if (!parameterObject.useDataRoles) {
vdbMetaData.setDataPolicies(Collections.EMPTY_LIST);
}
cmr.createConnectorManagers(vdbMetaData, this);
}
UDFMetaData udfMetaData = null;
if (parameterObject.udfs != null) {
udfMetaData = new UDFMetaData();
for (Map.Entry<String, Collection<FunctionMethod>> entry : parameterObject.udfs.entrySet()) {
udfMetaData.addFunctions(entry.getKey(), entry.getValue());
}
}
if (parameterObject.vdbImports != null) {
for (VDBImportMetadata vdbImport : parameterObject.vdbImports) {
vdbMetaData.getVDBImports().add(vdbImport);
}
}
vdbMetaData.setStatus(VDB.Status.ACTIVE);
this.repo.addVDB(vdbMetaData, metadata, parameterObject.vdbResources, udfMetaData, cmr);
this.repo.finishDeployment(vdbMetaData.getName(), vdbMetaData.getVersion());
this.repo.getLiveVDB(vdbMetaData.getName(), vdbMetaData.getVersion()).setStatus(VDB.Status.ACTIVE);
} catch (VirtualDatabaseException e) {
throw new RuntimeException(e);
} catch (ConnectorManagerException e) {
throw new RuntimeException(e);
} catch (XMLStreamException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations