use of org.teiid.deployers.VirtualDatabaseException in project teiid by teiid.
the class VDBService method start.
@Override
public void start(final StartContext context) throws StartException {
ConnectorManagerRepository cmr = new ConnectorManagerRepository();
TranslatorRepository repo = new TranslatorRepository();
this.vdb.addAttchment(TranslatorRepository.class, repo);
// check if this is a VDB with index files, if there are then build the TransformationMetadata
UDFMetaData udf = this.vdb.getAttachment(UDFMetaData.class);
// add required connector managers; if they are not already there
for (Translator t : this.vdb.getOverrideTranslators()) {
VDBTranslatorMetaData data = (VDBTranslatorMetaData) t;
String type = data.getType();
VDBTranslatorMetaData parent = getTranslatorRepository().getTranslatorMetaData(type);
data.setModuleName(parent.getModuleName());
data.addAttchment(ClassLoader.class, parent.getAttachment(ClassLoader.class));
data.setParent(parent);
repo.addTranslatorMetadata(data.getName(), data);
}
createConnectorManagers(cmr, repo, this.vdb);
final ServiceBuilder<Void> vdbService = addVDBFinishedService(context);
this.vdbListener = new VDBLifeCycleListener() {
@Override
public void added(String name, CompositeVDB cvdb) {
}
@Override
public void beforeRemove(String name, CompositeVDB cvdb) {
}
@Override
public void removed(String name, CompositeVDB cvdb) {
}
@Override
public void finishedDeployment(String name, CompositeVDB cvdb) {
if (!VDBService.this.vdbKey.equals(cvdb.getVDBKey())) {
return;
}
// clear out the indexmetadatarepository as it holds state that is no longer necessary
// $NON-NLS-1$
repositories.put("index", new IndexMetadataRepository());
VDBMetaData vdbInstance = cvdb.getVDB();
if (vdbInstance.getStatus().equals(Status.ACTIVE)) {
vdbService.install();
}
}
};
getVDBRepository().addListener(this.vdbListener);
MetadataStore store = new MetadataStore();
try {
// check to see if there is an index file. if there is then we assume
// that index is the default metadata repo
MetadataRepository<?, ?> defaultRepo = null;
for (String s : this.vdbResources.getEntriesPlusVisibilities().keySet()) {
if (s.endsWith(VDBResources.INDEX_EXT)) {
// $NON-NLS-1$
defaultRepo = super.getMetadataRepository("index");
break;
}
}
this.assignMetadataRepositories(vdb, defaultRepo);
// add transformation metadata to the repository.
getVDBRepository().addVDB(this.vdb, store, vdbResources.getEntriesPlusVisibilities(), udf, cmr);
} catch (VirtualDatabaseException e) {
cleanup(context);
throw new StartException(e);
}
this.vdb.removeAttachment(UDFMetaData.class);
try {
loadMetadata(this.vdb, cmr, store, this.vdbResources);
} catch (TranslatorException e) {
cleanup(context);
throw new StartException(e);
}
this.runtimeVDB = buildRuntimeVDB(this.vdb, context.getController().getServiceContainer());
}
use of org.teiid.deployers.VirtualDatabaseException in project teiid by teiid.
the class EmbeddedServer method deployVDB.
protected void deployVDB(VDBMetaData vdb, VDBResources resources) throws ConnectorManagerException, VirtualDatabaseException, TranslatorException {
checkStarted();
if (!vdb.getOverrideTranslators().isEmpty() && !allowOverrideTranslators()) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40106, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40106, vdb.getName()));
}
vdb.addAttchment(ClassLoader.class, Thread.currentThread().getContextClassLoader());
try {
createPreParser(vdb);
} catch (TeiidException e1) {
throw new VirtualDatabaseException(e1);
}
cmr.createConnectorManagers(vdb, this);
MetadataStore metadataStore = new MetadataStore();
UDFMetaData udfMetaData = new UDFMetaData();
udfMetaData.setFunctionClassLoader(Thread.currentThread().getContextClassLoader());
MetadataRepository<?, ?> defaultRepo = null;
LinkedHashMap<String, VDBResources.Resource> visibilityMap = null;
if (resources != null) {
// that index is the default metadata repo
for (String s : resources.getEntriesPlusVisibilities().keySet()) {
if (s.endsWith(VDBResources.INDEX_EXT)) {
defaultRepo = new IndexMetadataRepository();
break;
}
}
visibilityMap = resources.getEntriesPlusVisibilities();
} else {
visibilityMap = new LinkedHashMap<String, VDBResources.Resource>();
}
this.assignMetadataRepositories(vdb, defaultRepo);
repo.addVDB(vdb, metadataStore, visibilityMap, udfMetaData, cmr);
try {
this.loadMetadata(vdb, cmr, metadataStore, resources);
} catch (VDBValidationError e) {
throw new VirtualDatabaseException(RuntimePlugin.Event.valueOf(e.getCode()), e.getMessage());
}
}
use of org.teiid.deployers.VirtualDatabaseException 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.deployers.VirtualDatabaseException 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.deployers.VirtualDatabaseException in project teiid by teiid.
the class VDBService method getMetadataRepository.
/**
* Override for module based loading
*/
@SuppressWarnings("rawtypes")
@Override
protected MetadataRepository<?, ?> getMetadataRepository(String repoType) throws VirtualDatabaseException {
MetadataRepository<?, ?> repo = super.getMetadataRepository(repoType);
if (repo != null) {
return repo;
}
try {
repo = TeiidAdd.buildService(MetadataRepository.class, repoType);
} catch (OperationFailedException e) {
throw new VirtualDatabaseException(IntegrationPlugin.Event.TEIID50057, e, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50057, repoType));
}
MetadataRepository old = this.repositories.putIfAbsent(repoType, repo);
return old != null ? old : repo;
}
Aggregations