Search in sources :

Example 91 with ModelMetaData

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

the class VDBStatusChecker method dataSourceRemoved.

/**
 * @param dataSourceName
 * @param vdbKey which cannot be null
 */
public void dataSourceRemoved(String dataSourceName, VDBKey vdbKey) {
    dataSourceName = stripContext(dataSourceName);
    CompositeVDB cvdb = getVDBRepository().getCompositeVDB(vdbKey);
    if (cvdb == null) {
        return;
    }
    VDBMetaData vdb = cvdb.getVDB();
    if (vdb.getStatus() == Status.FAILED) {
        return;
    }
    synchronized (vdb) {
        ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
        for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
            String sourceName = getSourceName(dataSourceName, model);
            if (sourceName == null) {
                continue;
            }
            Severity severity = Severity.WARNING;
            ConnectorManager cm = cmr.getConnectorManager(sourceName);
            if (cm.getExecutionFactory().isSourceRequired() && vdb.getStatus() == Status.ACTIVE) {
                severity = Severity.ERROR;
            }
            String msg = RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40012, vdb.getName(), vdb.getVersion(), dataSourceName);
            model.addRuntimeMessage(severity, msg);
            LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
        }
    }
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Severity(org.teiid.adminapi.impl.ModelMetaData.Message.Severity) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 92 with ModelMetaData

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

the class MaterializationManager method nodeDropped.

@Override
public void nodeDropped(String nodeName) {
    for (VDBMetaData vdb : getVDBRepository().getVDBs()) {
        TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class);
        if (metadata == null) {
            continue;
        }
        for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
            if (vdb.getImportedModels().contains(model.getName())) {
                continue;
            }
            MetadataStore store = metadata.getMetadataStore();
            Schema schema = store.getSchema(model.getName());
            for (Table t : schema.getTables().values()) {
                if (t.isVirtual() && t.isMaterialized() && t.getMaterializedTable() != null) {
                    String allow = t.getProperty(MaterializationMetadataRepository.ALLOW_MATVIEW_MANAGEMENT, false);
                    if (allow == null || !Boolean.valueOf(allow)) {
                        continue;
                    }
                    // reset the pending job if there is one.
                    int update = resetPendingJob(vdb, t, nodeName);
                    if (update > 0) {
                        String ttlStr = t.getProperty(MaterializationMetadataRepository.MATVIEW_TTL, false);
                        if (ttlStr == null) {
                            ttlStr = String.valueOf(Long.MAX_VALUE);
                        }
                        if (ttlStr != null) {
                            long ttl = Long.parseLong(ttlStr);
                            if (ttl > 0) {
                                // run the job
                                CompositeVDB cvdb = getVDBRepository().getCompositeVDB(new VDBKey(vdb.getName(), vdb.getVersion()));
                                scheduleSnapshotJob(cvdb, t, ttl, 0L, true);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) VDBKey(org.teiid.vdb.runtime.VDBKey) CompositeVDB(org.teiid.deployers.CompositeVDB) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Schema(org.teiid.metadata.Schema) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 93 with ModelMetaData

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

the class RestASMBasedWebArchiveBuilder method getContent.

@Override
public byte[] getContent(VDBMetaData vdb) throws IOException {
    MetadataStore metadataStore = vdb.getAttachment(TransformationMetadata.class).getMetadataStore();
    Properties props = new Properties();
    String fullName = vdb.getName() + "_" + vdb.getVersion();
    props.setProperty("${context-name}", fullName);
    props.setProperty("${vdb-name}", vdb.getName());
    props.setProperty("${vdb-version}", String.valueOf(vdb.getVersion()));
    props.setProperty("${api-page-title}", fullName + " API");
    String securityType = vdb.getPropertyValue(REST_NAMESPACE + "security-type");
    String securityDomain = vdb.getPropertyValue(REST_NAMESPACE + "security-domain");
    String securityRole = vdb.getPropertyValue(REST_NAMESPACE + "security-role");
    props.setProperty("${security-role}", ((securityRole == null) ? "rest" : securityRole));
    props.setProperty("${security-domain}", ((securityDomain == null) ? "teiid-security" : securityDomain));
    if (securityType == null) {
        securityType = "httpbasic";
    }
    if (securityType.equalsIgnoreCase("none")) {
        props.setProperty("${security-content}", "");
    } else if (securityType.equalsIgnoreCase("httpbasic")) {
        props.setProperty("${security-content}", replaceTemplates(getFileContents("rest-war/httpbasic.xml"), props));
    }
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    ZipOutputStream out = new ZipOutputStream(byteStream);
    writeEntry("WEB-INF/web.xml", out, replaceTemplates(getFileContents("rest-war/web.xml"), props).getBytes());
    writeEntry("WEB-INF/jboss-web.xml", out, replaceTemplates(getFileContents("rest-war/jboss-web.xml"), props).getBytes());
    writeEntry("api.html", out, replaceTemplates(getFileContents("rest-war/api.html"), props).getBytes());
    writeDirectoryEntry(out, "swagger-ui-2.1.1.zip");
    String version = vdb.getVersion();
    VDBKey vdbKey = new VDBKey(vdb.getName(), vdb.getVersion());
    ArrayList<String> applicationViews = new ArrayList<String>();
    for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
        Schema schema = metadataStore.getSchema(model.getName());
        if (schema == null) {
            // OTHER type, which does not have a corresponding Teiid schema
            continue;
        }
        byte[] viewContents = getViewClass(vdb.getName(), version, model.getName(), schema, true);
        if (viewContents != null) {
            writeEntry("WEB-INF/classes/org/teiid/jboss/rest/" + model.getName() + ".class", out, viewContents);
            applicationViews.add(schema.getName());
        }
    }
    writeEntry("WEB-INF/classes/org/teiid/jboss/rest/TeiidRestApplication.class", out, getApplicationClass(applicationViews));
    writeEntry("META-INF/MANIFEST.MF", out, getFileContents("rest-war/MANIFEST.MF").getBytes());
    byte[] bytes = getBootstrapServletClass(vdb.getName(), vdb.getDescription() == null ? vdb.getName() : vdb.getDescription(), vdbKey.getSemanticVersion(), new String[] { "http" }, File.separator + props.getProperty("${context-name}"), "org.teiid.jboss.rest", true);
    writeEntry("WEB-INF/classes/org/teiid/jboss/rest/Bootstrap.class", out, bytes);
    writeEntry("images/teiid_logo_450px.png", out, getBinaryFileContents("rest-war/teiid_logo_450px.png"));
    out.close();
    return byteStream.toByteArray();
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) VDBKey(org.teiid.vdb.runtime.VDBKey) ZipOutputStream(java.util.zip.ZipOutputStream) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 94 with ModelMetaData

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

the class TestRestWebArchiveBuilder method testOtherModels.

@Test
public void testOtherModels() throws Exception {
    MetadataStore ms = new MetadataStore();
    CompositeVDB vdb = TestCompositeVDB.createCompositeVDB(ms, "x");
    vdb.getVDB().addProperty("{http://teiid.org/rest}auto-generate", "true");
    ModelMetaData model = new ModelMetaData();
    model.setName("other");
    model.setModelType(Type.OTHER);
    vdb.getVDB().addModel(model);
    RestASMBasedWebArchiveBuilder builder = new RestASMBasedWebArchiveBuilder();
    builder.getContent(vdb.getVDB());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) CompositeVDB(org.teiid.deployers.CompositeVDB) TestCompositeVDB(org.teiid.deployers.TestCompositeVDB) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 95 with ModelMetaData

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

the class DeploymentBasedDatabaseStore method getVDBMetadata.

public VDBMetaData getVDBMetadata(String contents) {
    StringReader reader = new StringReader(contents);
    try {
        startEditing(false);
        this.setMode(Mode.DATABASE_STRUCTURE);
        QueryParser.getQueryParser().parseDDL(this, new BufferedReader(reader));
    } finally {
        reader.close();
        stopEditing();
    }
    Database database = getDatabases().get(0);
    VDBMetaData vdb = DatabaseUtil.convert(database);
    for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
        // $NON-NLS-1$
        model.addSourceMetadata("DDL", null);
    }
    for (VDBImportMetadata vid : this.importedVDBs) {
        vdb.getVDBImports().add(vid);
    }
    vdb.addProperty(VDBMetaData.TEIID_DDL, contents);
    return vdb;
}
Also used : VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) Database(org.teiid.metadata.Database) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Aggregations

ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)191 Test (org.junit.Test)131 Properties (java.util.Properties)50 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)45 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)43 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)36 Connection (java.sql.Connection)23 MetadataFactory (org.teiid.metadata.MetadataFactory)21 Statement (java.sql.Statement)19 ResultSet (java.sql.ResultSet)18 CallableStatement (java.sql.CallableStatement)16 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)15 ArrayList (java.util.ArrayList)13 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)11 SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)11 Table (org.teiid.metadata.Table)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 List (java.util.List)9 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)9 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)9