Search in sources :

Example 6 with VDBImportMetadata

use of org.teiid.adminapi.impl.VDBImportMetadata in project teiid by teiid.

the class TestCompositeVDB method testRoleInherit.

@Test
public void testRoleInherit() throws Exception {
    VDBRepository repo = new VDBRepository();
    repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
    repo.setSystemFunctionManager(RealMetadataFactory.SFM);
    MetadataStore metadataStore = new MetadataStore();
    RealMetadataFactory.createPhysicalModel("x", metadataStore);
    VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
    DataPolicyMetadata dpm = new DataPolicyMetadata();
    dpm.setName("x");
    dpm.setGrantAll(true);
    vdb.addDataPolicy(dpm);
    ConnectorManagerRepository cmr = new ConnectorManagerRepository();
    cmr.addConnectorManager("x", new ConnectorManager("y", "z"));
    repo.addVDB(vdb, metadataStore, null, null, cmr);
    metadataStore = new MetadataStore();
    RealMetadataFactory.createPhysicalModel("y", metadataStore);
    vdb = createVDBMetadata(metadataStore, "ex");
    VDBImportMetadata vdbImport = new VDBImportMetadata();
    vdbImport.setName("bqt");
    vdbImport.setVersion("1");
    vdbImport.setImportDataPolicies(true);
    vdb.getVDBImports().add(vdbImport);
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
    vdb = repo.getLiveVDB("ex");
    assertEquals(1, vdb.getDataPolicyMap().get("x").getSchemas().size());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) Test(org.junit.Test)

Example 7 with VDBImportMetadata

use of org.teiid.adminapi.impl.VDBImportMetadata in project teiid by teiid.

the class TestCompositeVDB method testDeepNesting.

@Test
public void testDeepNesting() throws Exception {
    VDBRepository repo = new VDBRepository();
    repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
    repo.setSystemFunctionManager(RealMetadataFactory.SFM);
    MetadataStore metadataStore = new MetadataStore();
    RealMetadataFactory.createPhysicalModel("x", metadataStore);
    VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
    ConnectorManagerRepository cmr = new ConnectorManagerRepository();
    cmr.addConnectorManager("x", new ConnectorManager("y", "z"));
    repo.addVDB(vdb, metadataStore, null, null, cmr);
    metadataStore = new MetadataStore();
    RealMetadataFactory.createPhysicalModel("y", metadataStore);
    vdb = createVDBMetadata(metadataStore, "ex");
    VDBImportMetadata vdbImport = new VDBImportMetadata();
    vdbImport.setName("bqt");
    vdbImport.setVersion("1");
    vdb.getVDBImports().add(vdbImport);
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
    VDBMetaData vdbInstance = repo.getVDB("ex", "1");
    assertTrue(!vdbInstance.getAttachment(ConnectorManagerRepository.class).getConnectorManagers().isEmpty());
    metadataStore = new MetadataStore();
    RealMetadataFactory.createPhysicalModel("z", metadataStore);
    vdb = createVDBMetadata(metadataStore, "ex1");
    vdbImport = new VDBImportMetadata();
    vdbImport.setName("ex");
    vdbImport.setVersion("1");
    vdb.getVDBImports().add(vdbImport);
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
    vdbInstance = repo.getVDB("ex1", "1");
    assertTrue(!vdbInstance.getAttachment(ConnectorManagerRepository.class).getConnectorManagers().isEmpty());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) Test(org.junit.Test)

Example 8 with VDBImportMetadata

use of org.teiid.adminapi.impl.VDBImportMetadata in project teiid by teiid.

the class TestCompositeVDB method testImportErrors.

@Test(expected = VirtualDatabaseException.class)
public void testImportErrors() throws Exception {
    VDBRepository repo = new VDBRepository();
    repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
    repo.setSystemFunctionManager(RealMetadataFactory.SFM);
    MetadataStore metadataStore = RealMetadataFactory.exampleBQTCached().getMetadataStore();
    VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
    vdb = createVDBMetadata(metadataStore, "bqt1");
    VDBImportMetadata vdbImport = new VDBImportMetadata();
    vdbImport.setName("foo");
    vdb.getVDBImports().add(vdbImport);
    try {
        // foo does not exist
        repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
        fail();
    } catch (VirtualDatabaseException e) {
    }
    vdb = createVDBMetadata(metadataStore, "bqt1");
    vdbImport.setName("bqt");
    vdb.getVDBImports().add(vdbImport);
    // model conflict
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Test(org.junit.Test)

Example 9 with VDBImportMetadata

use of org.teiid.adminapi.impl.VDBImportMetadata in project teiid by teiid.

the class TestCompositeVDB method testImportVisibility.

@Test
public void testImportVisibility() throws Exception {
    VDBRepository repo = new VDBRepository();
    repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
    repo.setSystemFunctionManager(RealMetadataFactory.SFM);
    MetadataStore metadataStore = RealMetadataFactory.exampleBQTCached().getMetadataStore();
    VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
    vdb = createVDBMetadata(RealMetadataFactory.exampleBusObjStore(), "example1");
    vdb.addProperty("BQT1.visible", "false");
    VDBImportMetadata vdbImport = new VDBImportMetadata();
    vdbImport.setName("bqt");
    vdbImport.setVersion("1");
    vdb.getVDBImports().add(vdbImport);
    repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
    assertTrue(vdb.isVisible("BQT1"));
    vdb = repo.getLiveVDB("example1");
    assertFalse(vdb.isVisible("BQT1"));
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Test(org.junit.Test)

Example 10 with VDBImportMetadata

use of org.teiid.adminapi.impl.VDBImportMetadata 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);
    }
}
Also used : VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) VDBResource(org.teiid.metadata.VDBResource) Schema(org.teiid.metadata.Schema) UDFMetaData(org.teiid.deployers.UDFMetaData) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) IOException(java.io.IOException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) MetadataFactory(org.teiid.metadata.MetadataFactory) VDBMetadataFactory(org.teiid.metadata.index.VDBMetadataFactory) XMLStreamException(javax.xml.stream.XMLStreamException) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Collection(java.util.Collection) TranslatorException(org.teiid.translator.TranslatorException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

VDBImportMetadata (org.teiid.adminapi.impl.VDBImportMetadata)11 Test (org.junit.Test)8 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)8 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)4 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)4 MetadataStore (org.teiid.metadata.MetadataStore)4 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)2 DeployVDBParameter (org.teiid.jdbc.FakeServer.DeployVDBParameter)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 CallableStatement (java.sql.CallableStatement)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)1