Search in sources :

Example 1 with SourceMappingMetadata

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;
}
Also used : ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) Translator(org.teiid.adminapi.Translator) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) DataPermission(org.teiid.adminapi.DataPolicy.DataPermission) DataPermission(org.teiid.adminapi.DataPolicy.DataPermission) Permission(org.teiid.metadata.Grant.Permission) DataPolicy(org.teiid.adminapi.DataPolicy)

Example 2 with SourceMappingMetadata

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);
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) EmbeddedServer(org.teiid.runtime.EmbeddedServer) LoopbackExecutionFactory(org.teiid.translator.loopback.LoopbackExecutionFactory) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) BeforeClass(org.junit.BeforeClass)

Example 3 with SourceMappingMetadata

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);
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 4 with SourceMappingMetadata

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);
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 5 with SourceMappingMetadata

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);
                    }
                }
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Aggregations

SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)13 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)11 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)5 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)4 AdminProcessingException (org.teiid.adminapi.AdminProcessingException)3 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)3 ArrayList (java.util.ArrayList)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 DataPolicy (org.teiid.adminapi.DataPolicy)1 DataPermission (org.teiid.adminapi.DataPolicy.DataPermission)1 Translator (org.teiid.adminapi.Translator)1 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)1 InvalidServiceNameException (org.teiid.jboss.TeiidServiceNames.InvalidServiceNameException)1 Permission (org.teiid.metadata.Grant.Permission)1 EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)1 EmbeddedServer (org.teiid.runtime.EmbeddedServer)1 LoopbackExecutionFactory (org.teiid.translator.loopback.LoopbackExecutionFactory)1