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