use of org.teiid.adminapi.impl.SourceMappingMetadata in project teiid by teiid.
the class DatabaseUtil method convert.
public static Database convert(VDBMetaData vdb, MetadataStore metadataStore) {
Database db = new Database(vdb.getName(), vdb.getVersion());
db.setProperties(vdb.getPropertiesMap());
if (vdb.getDescription() != null) {
db.setAnnotation(vdb.getDescription());
}
db.setProperty("connection-type", vdb.getConnectionType().name());
db.getMetadataStore().addDataTypes(metadataStore.getDatatypes());
// override translators
List<Translator> translators = vdb.getOverrideTranslators();
for (Translator t : translators) {
// add the base
if (db.getDataWrapper(t.getType()) == null) {
DataWrapper dw = new DataWrapper(t.getType());
db.addDataWrapper(dw);
}
// add override with properties
if (db.getDataWrapper(t.getName()) == null) {
DataWrapper dw = new DataWrapper(t.getName());
dw.setType(t.getType());
for (final String key : t.getProperties().stringPropertyNames()) {
dw.setProperty(key, t.getPropertyValue(key));
}
if (t.getDescription() != null) {
dw.setAnnotation(t.getDescription());
}
db.addDataWrapper(dw);
}
}
Collection<ModelMetaData> models = vdb.getModelMetaDatas().values();
for (ModelMetaData m : models) {
Schema schema = metadataStore.getSchema(m.getName());
// add servers
if (m.isSource()) {
Collection<SourceMappingMetadata> sources = m.getSourceMappings();
for (SourceMappingMetadata s : sources) {
// add translators, that are not override
if (db.getDataWrapper(s.getTranslatorName()) == null) {
DataWrapper dw = new DataWrapper(s.getTranslatorName());
db.addDataWrapper(dw);
}
// add servers
Server server = new Server(s.getName());
server.setJndiName(s.getConnectionJndiName());
server.setDataWrapper(s.getTranslatorName());
// no need to add duplicate definitions.
if (db.getServer(s.getName()) == null) {
db.addServer(server);
schema.addServer(server);
}
}
}
db.addSchema(schema);
}
for (String key : vdb.getDataPolicyMap().keySet()) {
DataPolicyMetadata dpm = vdb.getDataPolicyMap().get(key);
Role role = new Role(dpm.getName());
if (dpm.getMappedRoleNames() != null && !dpm.getMappedRoleNames().isEmpty()) {
role.setJaasRoles(dpm.getMappedRoleNames());
}
if (dpm.isAnyAuthenticated()) {
role.setAnyAuthenticated(true);
}
Grant grant = null;
if (dpm.isGrantAll()) {
if (grant == null) {
grant = new Grant();
grant.setRole(role.getName());
}
Permission permission = new Permission();
permission.setAllowAllPrivileges(true);
permission.setResourceType(ResourceType.DATABASE);
grant.addPermission(permission);
}
if (dpm.isAllowCreateTemporaryTables() != null && dpm.isAllowCreateTemporaryTables()) {
if (grant == null) {
grant = new Grant();
grant.setRole(role.getName());
}
Permission permission = new Permission();
permission.setAllowTemporyTables(true);
permission.setResourceType(ResourceType.DATABASE);
grant.addPermission(permission);
}
for (DataPolicy.DataPermission dp : dpm.getPermissions()) {
if (grant == null) {
grant = new Grant();
grant.setRole(role.getName());
}
Permission permission = convert(dp);
grant.addPermission(permission);
}
db.addRole(role);
db.addGrant(grant);
}
return db;
}
use of org.teiid.adminapi.impl.SourceMappingMetadata in project teiid by teiid.
the class TestASTQueries method setUp.
@BeforeClass
public static void setUp() throws Exception {
server = new EmbeddedServer();
server.start(new EmbeddedConfiguration());
LoopbackExecutionFactory loopy = new LoopbackExecutionFactory();
loopy.setRowCount(10);
loopy.start();
server.addTranslator("l", loopy);
String DDL = "CREATE FOREIGN TABLE G1 (e1 string, e2 integer);";
ModelMetaData model = new ModelMetaData();
model.setName("PM1");
model.setModelType(Model.Type.PHYSICAL);
model.setSchemaSourceType("DDL");
model.setSchemaText(DDL);
SourceMappingMetadata sm = new SourceMappingMetadata();
sm.setName("loopy");
sm.setTranslatorName("l");
model.addSourceMapping(sm);
server.deployVDB("test", model);
}
use of org.teiid.adminapi.impl.SourceMappingMetadata in project teiid by teiid.
the class EmbeddedAdminImpl method updateSource.
@Override
public void updateSource(String vdbName, String vdbVersion, String sourceName, String translatorName, String dsName) throws AdminException {
VDBMetaData vdb = checkVDB(vdbName, vdbVersion);
synchronized (vdb) {
for (ModelMetaData m : vdb.getModelMetaDatas().values()) {
SourceMappingMetadata mapping = m.getSourceMapping(sourceName);
if (mapping != null) {
mapping.setTranslatorName(translatorName);
mapping.setConnectionJndiName(dsName);
}
}
}
}
use of org.teiid.adminapi.impl.SourceMappingMetadata in project teiid by teiid.
the class RuntimeVDB method removeSource.
public ReplaceResult removeSource(String modelName, String sourceName) throws AdminProcessingException {
synchronized (this.vdb) {
ModelMetaData model = this.vdb.getModel(modelName);
if (model == null) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40090, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40090, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
if (!model.isSupportsMultiSourceBindings()) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40108, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40108, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
if (model.getSources().size() == 1) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40109, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40109, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
SourceMappingMetadata source = model.getSources().remove(sourceName);
if (source == null) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40091, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40091, sourceName, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
if (model.getSources().size() == 1) {
// we default to multi-source with multiple sources, so now we need to explicitly set to true
model.setSupportsMultiSourceBindings(true);
}
String previousDsName = source.getConnectionJndiName();
boolean success = false;
try {
this.listener.dataSourceChanged(modelName, sourceName, null, null);
ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
// detect if the ConnectorManager is still used
boolean exists = false;
for (ModelMetaData m : this.vdb.getModelMetaDatas().values()) {
if (m == model) {
continue;
}
if (m.getSourceMapping(sourceName) != null) {
exists = true;
break;
}
}
if (!exists) {
cmr.removeConnectorManager(sourceName);
}
ReplaceResult rr = new ReplaceResult();
if (!dsExists(previousDsName, cmr)) {
rr.removedDs = previousDsName;
}
success = true;
return rr;
} finally {
if (!success) {
// TODO: this means that the order has changed
model.addSourceMapping(source);
}
}
}
}
use of org.teiid.adminapi.impl.SourceMappingMetadata in project teiid by teiid.
the class VDBRepository method validateDataSources.
void validateDataSources(VDBMetaData vdb) {
ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
if (model.isSource()) {
Collection<SourceMappingMetadata> mappings = model.getSourceMappings();
for (SourceMappingMetadata mapping : mappings) {
ConnectorManager cm = cmr.getConnectorManager(mapping.getName());
if (cm != null) {
String msg = cm.getStausMessage();
if (msg != null && msg.length() > 0) {
model.addRuntimeError(msg);
model.setMetadataStatus(Model.MetadataStatus.FAILED);
LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
}
}
}
}
}
}
Aggregations